Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Plot_BCAL_LED_Ratio_low_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  // figure out the name of the file
41  vector<string> tokens;
42  split(path_name, '/', tokens);
43  string filename = *(tokens.end()-1);
44  // download the file if it doesn't already exist
45  ifstream f(filename.c_str());
46  if(!f.good()) {
47  sprintf(command, "curl -O %s", ss_url.str().c_str());
48  gSystem->Exec(command);
49  } else {
50  f.close();
51  }
52 
53 
54  // open it and return
55  TFile *rootfile = new TFile(filename.c_str());
56 
57  // error check
58 
59  return rootfile;
60 }
61 
62 void Plot_BCAL_LED_Ratio_low_up(string infilename = "hd_root.root", int run = 20000)
63 {
64  cout << "Starting ploting" << "\n";
65  // #include <TRandom.h>
66 
67  //gROOT->Reset();
68 gStyle->SetPalette(1,0);
69 gStyle->SetOptStat(kFALSE);
70 // gStyle->SetOptStat(11111111);
71 gStyle->SetPadRightMargin(0.15);
72 gStyle->SetPadLeftMargin(0.15);
73 gStyle->SetPadBottomMargin(0.15);
74 //
75 
76  char string[256];
77  //char path[256];
78  Int_t j,k;
79  Int_t n;
80  Int_t errorbars = 0;
81 
82  TProfile *run1_low_up_1 = NULL;
83  TProfile *run1_low_up_2 = NULL;
84  TProfile *run1_low_up_3 = NULL;
85  TProfile *run1_low_up_4 = NULL;
86 
87  TProfile *run2_low_up_1 = NULL;
88  TProfile *run2_low_up_2 = NULL;
89  TProfile *run2_low_up_3 = NULL;
90  TProfile *run2_low_up_4 = NULL;
91 
92  TH1D *run1_high_up_1_hist=NULL;
93  TH1D *run1_high_up_2_hist=NULL;
94  TH1D *run1_high_up_3_hist=NULL;
95  TH1D *run1_high_up_4_hist=NULL;
96 
97  TH1D *run2_high_up_1_hist=NULL;
98  TH1D *run2_high_up_2_hist=NULL;
99  TH1D *run2_high_up_3_hist=NULL;
100  TH1D *run2_high_up_4_hist=NULL;
101 
102  TH1D *run1_low_up_1_hist = NULL;
103  TH1D *run1_low_up_2_hist = NULL;
104  TH1D *run1_low_up_3_hist = NULL;
105  TH1D *run1_low_up_4_hist = NULL;
106 
107  TH1D *run2_low_up_1_hist = NULL;
108  TH1D *run2_low_up_2_hist = NULL;
109  TH1D *run2_low_up_3_hist = NULL;
110  TH1D *run2_low_up_4_hist = NULL;
111 
112 // sprintf(string,"hd_root.root");
113 // sprintf(string,"0%03i/bcalled0%03i.root",runnumber1,runnumber1);
114  printf ("Histogram input filename=%s\n",infilename.c_str());
115  TFile *run1in = new TFile(infilename.c_str(),"read");
116 
117 
118 
119  run1_low_up_1 = (TProfile*)run1in->Get("bcalLED/low_bias_up_sector_1_peak_vchannel");
120  run1_low_up_2 = (TProfile*)run1in->Get("bcalLED/low_bias_up_sector_2_peak_vchannel");
121  run1_low_up_3 = (TProfile*)run1in->Get("bcalLED/low_bias_up_sector_3_peak_vchannel");
122  run1_low_up_4 = (TProfile*)run1in->Get("bcalLED/low_bias_up_sector_4_peak_vchannel");
123 
124  //sprintf(string,"BCAL_LED_Reference_Spring2016.root");
125  //printf ("Histogram input filename=%s\n",string);
126  //TFile *run2in = new TFile(string,"read");
127  TFile *run2in = GetReferenceFile(run);
128 
129  run2_low_up_1 = (TProfile*)run2in->Get("bcalLED/low_bias_up_sector_1_peak_vchannel");
130  run2_low_up_2 = (TProfile*)run2in->Get("bcalLED/low_bias_up_sector_2_peak_vchannel");
131  run2_low_up_3 = (TProfile*)run2in->Get("bcalLED/low_bias_up_sector_3_peak_vchannel");
132  run2_low_up_4 = (TProfile*)run2in->Get("bcalLED/low_bias_up_sector_4_peak_vchannel");
133 
134  cout << "input profiles, projecting into histograms" << "\n";
135 
136  run1_low_up_1_hist = run1_low_up_1->ProjectionX("run1_low_up_1_projectionx");
137  run1_low_up_2_hist = run1_low_up_2->ProjectionX("run1_low_up_2_projectionx");
138  run1_low_up_3_hist = run1_low_up_3->ProjectionX("run1_low_up_3_projectionx");
139  run1_low_up_4_hist = run1_low_up_4->ProjectionX("run1_low_up_4_projectionx");
140 
141  run2_low_up_1_hist = run2_low_up_1->ProjectionX("run2_low_up_1_projectionx");
142  run2_low_up_2_hist = run2_low_up_2->ProjectionX("run2_low_up_2_projectionx");
143  run2_low_up_3_hist = run2_low_up_3->ProjectionX("run2_low_up_3_projectionx");
144  run2_low_up_4_hist = run2_low_up_4->ProjectionX("run2_low_up_4_projectionx");
145 
146  cout << "profiles projected into histograms" << "\n";
147 
148  run1_low_up_1_hist->SetTitle("6v Upstream sector 1");
149  run1_low_up_2_hist->SetTitle("6v Upstream sector 2");
150  run1_low_up_3_hist->SetTitle("6v Upstream sector 3");
151  run1_low_up_4_hist->SetTitle("6v Upstream sector 4");
152 
153  cout << "Divideing histograms" << "\n";
154 
155  run1_low_up_1_hist->Divide(run2_low_up_1_hist);
156  run1_low_up_2_hist->Divide(run2_low_up_2_hist);
157  run1_low_up_3_hist->Divide(run2_low_up_3_hist);
158  run1_low_up_4_hist->Divide(run2_low_up_4_hist);
159 
160  cout << "Histograms divided" << "\n";
161  run1_low_up_1_hist->SetMinimum(0.8);
162  run1_low_up_1_hist->SetMaximum(1.2);
163  run1_low_up_2_hist->SetMinimum(0.8);
164  run1_low_up_2_hist->SetMaximum(1.2);
165  run1_low_up_3_hist->SetMinimum(0.8);
166  run1_low_up_3_hist->SetMaximum(1.2);
167  run1_low_up_4_hist->SetMinimum(0.8);
168  run1_low_up_4_hist->SetMaximum(1.2);
169 
170 
171 
172  TCanvas *c1 = new TCanvas("c1","c1 pedsubpeak ",200,10,1200,1200);
173  c1->Divide(2,2);
174 
175 ////////////////////////////////////////////////
176  TVirtualPad *c1_1 = c1->cd(1);
177  c1_1->SetBorderMode(0);
178  c1_1->SetFillColor(0);
179 
180  c1_1->SetGridx();
181  c1_1->SetGridy();
182  c1_1->SetBorderMode(0);
183  c1_1->SetFillColor(0);
184 
185  if (errorbars ==0) {run1_low_up_1_hist->Draw("hist p");}
186  else {run1_low_up_1_hist->Draw("E1 X0");}
187  run1_low_up_1_hist->SetMarkerColor(2);
188  run1_low_up_1_hist->SetMarkerStyle(2);
189 
190 
191  sprintf(string,"Run ratio to reference");
192 // sprintf(string,"Run %05d ratio to reference",runnumber1);
193  TLatex *t1 = new TLatex(0.15,0.92,string);
194  t1->SetNDC();
195  t1->SetTextSize(0.03);
196  t1->Draw();
197 
198 ///////////////////////////////////////////////////////////////////////////
199  TVirtualPad *c1_2 = c1->cd(2);
200  c1_2->SetBorderMode(0);
201  c1_2->SetFillColor(0);
202 
203  c1_2->SetGridx();
204  c1_2->SetGridy();
205  c1_2->SetBorderMode(0);
206  c1_2->SetFillColor(0);
207 
208  if (errorbars ==0) {run1_low_up_2_hist->Draw("hist p");}
209  else {run1_low_up_2_hist->Draw("E1 X0");}
210  run1_low_up_2_hist->SetMarkerColor(2);
211  run1_low_up_2_hist->SetMarkerStyle(2);
212 
213 ///////////////////////////////////////////////////////////////////////////
214  TVirtualPad *c1_3 = c1->cd(3);
215  c1_3->SetBorderMode(0);
216  c1_3->SetFillColor(0);
217 
218 
219  c1_3->SetGridx();
220  c1_3->SetGridy();
221  c1_3->SetBorderMode(0);
222  c1_3->SetFillColor(0);
223 
224  if (errorbars ==0) {run1_low_up_3_hist->Draw("hist p");}
225  else {run1_low_up_3_hist->Draw("E1 X0");}
226  run1_low_up_3_hist->SetMarkerColor(2);
227  run1_low_up_3_hist->SetMarkerStyle(2);
228 
229 
230  ///////////////////////////////////////////////////////////////////////////
231  TVirtualPad *c1_4 = c1->cd(4);
232  c1_4->SetBorderMode(0);
233  c1_4->SetFillColor(0);
234 
235  c1_4->SetGridx();
236  c1_4->SetGridy();
237  c1_4->SetBorderMode(0);
238  c1_4->SetFillColor(0);
239 
240  if (errorbars ==0) {run1_low_up_4_hist->Draw("hist p");}
241  else {run1_low_up_4_hist->Draw("E1 X0");}
242  run1_low_up_4_hist->SetMarkerColor(2);
243  run1_low_up_4_hist->SetMarkerStyle(2);
244 
245 ///////////////////////////////////////////////////////////////////////////
246 
247 // sprintf(string,"bcalled_lowup.pdf");
248 // c1->SaveAs(string);
249 
250 // sprintf(string,"bcalled_%05d_lowup.pdf",runnumber1);
251 // c1->SaveAs(string);
252 
253 //gApplication->Terminate();
254 }
255 
char string[256]
sprintf(text,"Post KinFit Cut")
TString filename
Double_t c1[2][NMODULES]
Definition: tw_corr.C:68
void Plot_BCAL_LED_Ratio_low_up(string infilename="hd_root.root", int run=20000)
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)
printf("string=%s", string)