Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Plot_BCAL_LED_Ratio_high_down.C
Go to the documentation of this file.
1 #include <unistd.h>
2 using namespace std;
3 
4 
5 void split(const std::string &s, char delim, std::vector<std::string> &elems) {
6  std::stringstream ss;
7  ss.str(s);
8  std::string item;
9  while (std::getline(ss, item, delim)) {
10  elems.push_back(item);
11  }
12 }
13 
14 TFile *GetReferenceFile(Int_t run, TString variation = "default"){
15  char command[1024];
16  // first get the location of the file
17  sprintf(command, "ccdb dump %s:%i:%s", "/BCAL/LED_monitoring/reference_file", run, variation.Data());
18  FILE* inputPipe = gSystem->OpenPipe(command, "r");
19  if(inputPipe == NULL)
20  return NULL;
21  //get the first (comment) line
22  char buff[1024];
23  if(fgets(buff, sizeof(buff), inputPipe) == NULL)
24  return NULL;
25  //get the actual data
26  if(fgets(buff, sizeof(buff), inputPipe) == NULL)
27  return NULL;
28  stringstream ss;
29  ss << buff;
30  char url_base[1024], path_name[1024];
31  ss >> url_base >> path_name;
32  //Close the pipe
33  gSystem->ClosePipe(inputPipe);
34 
35  // build URL of the location of the file
36  stringstream ss_url;
37  //cout << url_base << endl;
38  //cout << table_name << endl;
39  ss_url << url_base << "/" << path_name;
40 
41  // figure out the name of the file
42  vector<string> tokens;
43  split(path_name, '/', tokens);
44  string filename = *(tokens.end()-1);
45 
46  // download the file if it doesn't already exist
47  ifstream f(filename.c_str());
48  if(!f.good()) {
49  sprintf(command, "curl -O %s", ss_url.str().c_str());
50  gSystem->Exec(command);
51  } else {
52  f.close();
53  }
54 
55 
56  // open it and return
57  TFile *rootfile = new TFile(filename.c_str());
58 
59  // error check
60 
61  return rootfile;
62 }
63 
64 void Plot_BCAL_LED_Ratio_high_down(string infilename = "hd_root.root", int run = 20000)
65 {
66  // #include <TRandom.h>
67 
68  //gROOT->Reset();
69 gStyle->SetPalette(1,0);
70 gStyle->SetOptStat(kFALSE);
71 // gStyle->SetOptStat(11111111);
72 gStyle->SetPadRightMargin(0.15);
73 gStyle->SetPadLeftMargin(0.15);
74 gStyle->SetPadBottomMargin(0.15);
75 //
76 
77  char string[256];
78  //char path[256];
79  Int_t j,k;
80  Int_t n;
81  Int_t errorbars = 0;
82 
83  TProfile *run1_high_down_1 = NULL;
84  TProfile *run1_high_down_2 = NULL;
85  TProfile *run1_high_down_3 = NULL;
86  TProfile *run1_high_down_4 = NULL;
87 
88  TProfile *run2_high_down_1 = NULL;
89  TProfile *run2_high_down_2 = NULL;
90  TProfile *run2_high_down_3 = NULL;
91  TProfile *run2_high_down_4 = NULL;
92 
93  TH1D *run1_high_down_1_hist = NULL;
94  TH1D *run1_high_down_2_hist = NULL;
95  TH1D *run1_high_down_3_hist = NULL;
96  TH1D *run1_high_down_4_hist = NULL;
97 
98  TH1D *run2_high_down_1_hist = NULL;
99  TH1D *run2_high_down_2_hist = NULL;
100  TH1D *run2_high_down_3_hist = NULL;
101  TH1D *run2_high_down_4_hist = NULL;
102 
103 
104 // sprintf(string,"hd_root.root");
105 // sprintf(string,"0%03i/bcalled0%03i.root",runnumber1,runnumber1);
106  printf ("Histogram input filename=%s\n",infilename.c_str());
107  TFile *run1in = new TFile(infilename.c_str(),"read");
108 
109 
110 
111  run1_high_down_1 = (TProfile*)run1in->Get("bcalLED/high_bias_down_sector_1_peak_vchannel");
112  run1_high_down_2 = (TProfile*)run1in->Get("bcalLED/high_bias_down_sector_2_peak_vchannel");
113  run1_high_down_3 = (TProfile*)run1in->Get("bcalLED/high_bias_down_sector_3_peak_vchannel");
114  run1_high_down_4 = (TProfile*)run1in->Get("bcalLED/high_bias_down_sector_4_peak_vchannel");
115 
116  //sprintf(string,"BCAL_LED_Reference_Spring2016.root");
117  //printf ("Histogram input filename=%s\n",string);
118  //TFile *run2in = new TFile(string,"read");
119  TFile *run2in = GetReferenceFile(run);
120 
121  run2_high_down_1 = (TProfile*)run2in->Get("bcalLED/high_bias_down_sector_1_peak_vchannel");
122  run2_high_down_2 = (TProfile*)run2in->Get("bcalLED/high_bias_down_sector_2_peak_vchannel");
123  run2_high_down_3 = (TProfile*)run2in->Get("bcalLED/high_bias_down_sector_3_peak_vchannel");
124  run2_high_down_4 = (TProfile*)run2in->Get("bcalLED/high_bias_down_sector_4_peak_vchannel");
125 
126  cout << "input profiles, projecting into histograms" << "\n";
127 
128  run1_high_down_1_hist = run1_high_down_1->ProjectionX("run1_high_down_1_projectionx");
129  run1_high_down_2_hist = run1_high_down_2->ProjectionX("run1_high_down_2_projectionx");
130  run1_high_down_3_hist = run1_high_down_3->ProjectionX("run1_high_down_3_projectionx");
131  run1_high_down_4_hist = run1_high_down_4->ProjectionX("run1_high_down_4_projectionx");
132 
133  run2_high_down_1_hist = run2_high_down_1->ProjectionX("run2_high_down_1_projectionx");
134  run2_high_down_2_hist = run2_high_down_2->ProjectionX("run2_high_down_2_projectionx");
135  run2_high_down_3_hist = run2_high_down_3->ProjectionX("run2_high_down_3_projectionx");
136  run2_high_down_4_hist = run2_high_down_4->ProjectionX("run2_high_down_4_projectionx");
137 
138 
139  cout << "profiles projected into histograms" << "\n";
140 
141  run1_high_down_1_hist->SetTitle("6.25v Downstream sector 1");
142  run1_high_down_2_hist->SetTitle("6.25v Downstream sector 2");
143  run1_high_down_3_hist->SetTitle("6.25v Downstream sector 3");
144  run1_high_down_4_hist->SetTitle("6.25v Downstream sector 4");
145 
146  cout << "Divideing histograms" << "\n";
147 
148  run1_high_down_1_hist->Divide(run2_high_down_1_hist);
149  run1_high_down_2_hist->Divide(run2_high_down_2_hist);
150  run1_high_down_3_hist->Divide(run2_high_down_3_hist);
151  run1_high_down_4_hist->Divide(run2_high_down_4_hist);
152 
153  cout << "Histograms divided" << "\n";
154 
155  run1_high_down_1_hist->SetMinimum(0.8);
156  run1_high_down_1_hist->SetMaximum(1.2);
157  run1_high_down_2_hist->SetMinimum(0.8);
158  run1_high_down_2_hist->SetMaximum(1.2);
159  run1_high_down_3_hist->SetMinimum(0.8);
160  run1_high_down_3_hist->SetMaximum(1.2);
161  run1_high_down_4_hist->SetMinimum(0.8);
162  run1_high_down_4_hist->SetMaximum(1.2);
163 
164 
165 ///////////////////////////////////////////////////////////////////////////
166  TCanvas *c4 = new TCanvas("c4","c4 pedsubpeak ",200,10,1200,1200);
167  c4->Divide(2,2);
168 
169  TVirtualPad *c4_1 = c4->cd(1);
170  c4_1->SetBorderMode(0);
171  c4_1->SetFillColor(0);
172 
173  c4_1->SetGridx();
174  c4_1->SetGridy();
175  c4_1->SetBorderMode(0);
176  c4_1->SetFillColor(0);
177 
178 
179 
180  if (errorbars ==0) {run1_high_down_1_hist->Draw("hist p");}
181  else {run1_high_down_1_hist->Draw("E1 X0");}
182  run1_high_down_1_hist->SetMarkerColor(2);
183  run1_high_down_1_hist->SetMarkerStyle(2);
184 
185  sprintf(string,"Run ratio to reference");
186 // sprintf(string,"Run %05d ratio to reference",runnumber1);
187  TLatex *t1 = new TLatex(0.15,0.92,string);
188  t1->SetNDC();
189  t1->SetTextSize(0.03);
190  t1->Draw();
191 
192 
193 ///////////////////////////////////////////////////////////////////////////
194  TVirtualPad *c4_2 = c4->cd(2);
195  c4_2->SetBorderMode(0);
196  c4_2->SetFillColor(0);
197 
198  c4_2->SetGridx();
199  c4_2->SetGridy();
200  c4_2->SetBorderMode(0);
201  c4_2->SetFillColor(0);
202 
203 
204 
205  if (errorbars ==0) {run1_high_down_2_hist->Draw("hist p");}
206  else {run1_high_down_2_hist->Draw("E1 X0");}
207  run1_high_down_2_hist->SetMarkerColor(2);
208  run1_high_down_2_hist->SetMarkerStyle(2);
209 
210 ///////////////////////////////////////////////////////////////////////////
211  TVirtualPad *c4_3 = c4->cd(3);
212  c4_3->SetBorderMode(0);
213  c4_3->SetFillColor(0);
214 
215  c4_3->SetGridx();
216  c4_3->SetGridy();
217  c4_3->SetBorderMode(0);
218  c4_3->SetFillColor(0);
219 
220 
221 
222  if (errorbars ==0) {run1_high_down_3_hist->Draw("hist p");}
223  else {run1_high_down_3_hist->Draw("E1 X0");}
224  run1_high_down_3_hist->SetMarkerColor(2);
225  run1_high_down_3_hist->SetMarkerStyle(2);
226 
227 ///////////////////////////////////////////////////////////////////////////
228  TVirtualPad *c4_4 = c4->cd(4);
229  c4_4->SetBorderMode(0);
230  c4_4->SetFillColor(0);
231 
232 
233  c4_4->SetGridx();
234  c4_4->SetGridy();
235  c4_4->SetBorderMode(0);
236  c4_4->SetFillColor(0);
237 
238 
239 
240  if (errorbars ==0) {run1_high_down_4_hist->Draw("hist p");}
241  else {run1_high_down_4_hist->Draw("E1 X0");}
242  run1_high_down_4_hist->SetMarkerColor(2);
243  run1_high_down_4_hist->SetMarkerStyle(2);
244 
245 
246  ///////////////////////////////////////////////////////////////////////////////////////////
247 
248 
249 
250 
251 // sprintf(string,"bcalled_highdown.pdf");
252 // c4->SaveAs(string);
253 
254 // sprintf(string,"bcalled_%05d_highdown.pdf",runnumber1);
255 // c4->SaveAs(string);
256 
257 //gApplication->Terminate();
258 }
259 
char string[256]
sprintf(text,"Post KinFit Cut")
TString filename
TF1 * f
Definition: FitGains.C:21
void Plot_BCAL_LED_Ratio_high_down(string infilename="hd_root.root", int run=20000)
TLatex * t1
TFile * GetReferenceFile(Int_t run, TString variation="default")
void split(const std::string &s, char delim, std::vector< std::string > &elems)
TCanvas * c4
printf("string=%s", string)