Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Plot_BCAL_LED_Ratio_high_up.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_up(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 
84  TProfile *run1_high_up_1 = NULL;
85  TProfile *run1_high_up_2 = NULL;
86  TProfile *run1_high_up_3 = NULL;
87  TProfile *run1_high_up_4 = NULL;
88 
89  TProfile *run2_high_up_1 = NULL;
90  TProfile *run2_high_up_2 = NULL;
91  TProfile *run2_high_up_3 = NULL;
92  TProfile *run2_high_up_4 = NULL;
93 
94  TH1D *run1_high_up_1_hist=NULL;
95  TH1D *run1_high_up_2_hist=NULL;
96  TH1D *run1_high_up_3_hist=NULL;
97  TH1D *run1_high_up_4_hist=NULL;
98 
99  TH1D *run2_high_up_1_hist=NULL;
100  TH1D *run2_high_up_2_hist=NULL;
101  TH1D *run2_high_up_3_hist=NULL;
102  TH1D *run2_high_up_4_hist=NULL;
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_up_1 = (TProfile*)run1in->Get("bcalLED/high_bias_up_sector_1_peak_vchannel");
112  run1_high_up_2 = (TProfile*)run1in->Get("bcalLED/high_bias_up_sector_2_peak_vchannel");
113  run1_high_up_3 = (TProfile*)run1in->Get("bcalLED/high_bias_up_sector_3_peak_vchannel");
114  run1_high_up_4 = (TProfile*)run1in->Get("bcalLED/high_bias_up_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_up_1 = (TProfile*)run2in->Get("bcalLED/high_bias_up_sector_1_peak_vchannel");
122  run2_high_up_2 = (TProfile*)run2in->Get("bcalLED/high_bias_up_sector_2_peak_vchannel");
123  run2_high_up_3 = (TProfile*)run2in->Get("bcalLED/high_bias_up_sector_3_peak_vchannel");
124  run2_high_up_4 = (TProfile*)run2in->Get("bcalLED/high_bias_up_sector_4_peak_vchannel");
125 
126  cout << "input profiles, projecting into histograms" << "\n";
127 
128  run1_high_up_1_hist = run1_high_up_1->ProjectionX("run1_high_up_1_projectionx");
129  run1_high_up_2_hist = run1_high_up_2->ProjectionX("run1_high_up_2_projectionx");
130  run1_high_up_3_hist = run1_high_up_3->ProjectionX("run1_high_up_3_projectionx");
131  run1_high_up_4_hist = run1_high_up_4->ProjectionX("run1_high_up_4_projectionx");
132 
133  run2_high_up_1_hist = run2_high_up_1->ProjectionX("run2_high_up_1_projectionx");
134  run2_high_up_2_hist = run2_high_up_2->ProjectionX("run2_high_up_2_projectionx");
135  run2_high_up_3_hist = run2_high_up_3->ProjectionX("run2_high_up_3_projectionx");
136  run2_high_up_4_hist = run2_high_up_4->ProjectionX("run2_high_up_4_projectionx");
137 
138  cout << "profiles projected into histograms" << "\n";
139 
140  run1_high_up_1_hist->SetTitle("6.25v Upstream sector 1");
141  run1_high_up_2_hist->SetTitle("6.25v Upstream sector 2");
142  run1_high_up_3_hist->SetTitle("6.25v Upstream sector 3");
143  run1_high_up_4_hist->SetTitle("6.25v Upstream sector 4");
144 
145  cout << "Divideing histograms" << "\n";
146 
147  run1_high_up_1_hist->Divide(run2_high_up_1_hist);
148  run1_high_up_2_hist->Divide(run2_high_up_2_hist);
149  run1_high_up_3_hist->Divide(run2_high_up_3_hist);
150  run1_high_up_4_hist->Divide(run2_high_up_4_hist);
151 
152  cout << "Histograms divided" << "\n";
153 
154  run1_high_up_1_hist->SetMinimum(0.8);
155  run1_high_up_1_hist->SetMaximum(1.2);
156  run1_high_up_2_hist->SetMinimum(0.8);
157  run1_high_up_2_hist->SetMaximum(1.2);
158  run1_high_up_3_hist->SetMinimum(0.8);
159  run1_high_up_3_hist->SetMaximum(1.2);
160  run1_high_up_4_hist->SetMinimum(0.8);
161  run1_high_up_4_hist->SetMaximum(1.2);
162 
163 
164 
165 ///////////////////////////////////////////////////////////////////////////
166  TCanvas *c3 = new TCanvas("c3","c3 pedsubpeak ",200,10,1200,1200);
167  c3->Divide(2,2);
168 
169 
170  TVirtualPad *c3_1 = c3->cd(1);
171  c3_1->SetBorderMode(0);
172  c3_1->SetFillColor(0);
173 
174  c3_1->SetGridx();
175  c3_1->SetGridy();
176  c3_1->SetBorderMode(0);
177  c3_1->SetFillColor(0);
178 
179  if (errorbars ==0) {run1_high_up_1_hist->Draw("hist p");}
180  else {run1_high_up_1_hist->Draw("E1 X0");}
181  run1_high_up_1_hist->SetMarkerColor(2);
182  run1_high_up_1_hist->SetMarkerStyle(2);
183 
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 *c3_2 = c3->cd(2);
195  c3_2->SetBorderMode(0);
196  c3_2->SetFillColor(0);
197 
198 
199  c3_2->SetGridx();
200  c3_2->SetGridy();
201  c3_2->SetBorderMode(0);
202  c3_2->SetFillColor(0);
203 
204 
205 
206  if (errorbars ==0) {run1_high_up_2_hist->Draw("hist p");}
207  else {run1_high_up_2_hist->Draw("E1 X0");}
208  run1_high_up_2_hist->SetMarkerColor(2);
209  run1_high_up_2_hist->SetMarkerStyle(2);
210 
211 ///////////////////////////////////////////////////////////////////////////
212  TVirtualPad *c3_3 = c3->cd(3);
213  c3_3->SetBorderMode(0);
214  c3_3->SetFillColor(0);
215 
216 
217  c3_3->SetGridx();
218  c3_3->SetGridy();
219  c3_3->SetBorderMode(0);
220  c3_3->SetFillColor(0);
221 
222 
223 
224  if (errorbars ==0) {run1_high_up_3_hist->Draw("hist p");}
225  else {run1_high_up_3_hist->Draw("E1 X0");}
226  run1_high_up_3_hist->SetMarkerColor(2);
227  run1_high_up_3_hist->SetMarkerStyle(2);
228 
229 
230 ///////////////////////////////////////////////////////////////////////////
231  TVirtualPad *c3_4 = c3->cd(4);
232  c3_4->SetBorderMode(0);
233  c3_4->SetFillColor(0);
234 
235  c3_4->SetGridx();
236  c3_4->SetGridy();
237  c3_4->SetBorderMode(0);
238  c3_4->SetFillColor(0);
239 
240 
241 
242  if (errorbars ==0) {run1_high_up_4_hist->Draw("hist p");}
243  else {run1_high_up_4_hist->Draw("E1 X0");}
244  run1_high_up_4_hist->SetMarkerColor(2);
245  run1_high_up_4_hist->SetMarkerStyle(2);
246 
247 
248  ///////////////////////////////////////////////////////////////////////////////////////////
249 
250 
251 
252 
253 // sprintf(string,"bcalled_highup.pdf");
254 // c3->SaveAs(string);
255 
256 
257 
258 // sprintf(string,"bcalled_%05d_highup.pdf",runnumber1);
259 // c3->SaveAs(string);
260 
261 //gApplication->Terminate();
262 }
263 
char string[256]
sprintf(text,"Post KinFit Cut")
TString filename
TF1 * f
Definition: FitGains.C:21
TLatex * t1
TFile * GetReferenceFile(Int_t run, TString variation="default")
void split(const std::string &s, char delim, std::vector< std::string > &elems)
void Plot_BCAL_LED_Ratio_high_up(string infilename="hd_root.root", int run=20000)
TCanvas * c3
printf("string=%s", string)