lowLevelPlots.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////
2 // //
3 // Los level plots: variable vs tricell hits //
4 // //
5 // Created by: Diana Patricia Mendez //
6 // 21/Dec/2015 <- Her birthday //
7 // //
8 // Output: cND_LowLevel_view.pdf //
9 // cND_LowLevel_cellX.pdf //
10 // cND_LowLevel_wX.pdf //
11 // cND_LowLevel_pathX.pdf //
12 // cND_LowLevel_totalTrackLengthX.pdf //
13 // cND_LowLevel_flightLengthX.pdf //
14 // cND_LowLevel_cellY.pdf //
15 // ... //
16 // //
17 ////////////////////////////////////////////////////////////////
18 
19 #include <iostream>
20 #include <TFile.h>
21 #include <TPad.h>
22 #include <TH1.h>
23 #include <TH2.h>
24 #include <TH2F.h>
25 #include <TH2D.h>
26 #include <TProfile2D.h>
27 #include <TH1D.h>
28 #include <TH1F.h>
29 #include <TH3D.h>
30 #include <TCanvas.h>
31 #include <TVector.h>
32 #include <TColor.h>
33 #include <TLegend.h>
34 #include <TF1.h>
35 #include <TLatex.h>
36 #include <TMath.h>
37 #include <TStyle.h>
38 #include <TROOT.h>
39 #include <TPad.h>
40 #include <TFile.h>
41 #include <TTree.h>
42 #include <TSystem.h>
43 #include <TColor.h>
44 #include "TChain.h"
45 
46 #include "Utilities/rootlogon.C"
47 
48 // canvas size
49 #define c1_x 700
50 #define c1_y 500
51 
52 #define c2_x 1000
53 #define c2_y 500
54 
55 
56 
57 double GetHistMax(TH1* h0, TH1* h1, TH1* h2, TH1* h3);
58 
59 int main(){
60 
61  gROOT->ForceStyle();
62 
63  std::cout << "Reading MC files " << std::endl;
64 
65  TChain* tNDMC = new TChain("muontrackhits/fTree");
66  tNDMC->Add("mc/*.root");
67 
68  double w_MC, path_MC, trackLength_MC, flightLength_MC;
69  int view_MC, cell_MC;
70 
71  double PECorr_MC, trueE_MC, x_MC;
72  double planes_MC, xplanes_MC, yplanes_MC;
73  int cont_MC, nhits_MC, hitId_MC;
74 
75  std::cout << "Setting MC branches " << std::endl;
76 
77  tNDMC->SetBranchAddress("w", &w_MC);
78  tNDMC->SetBranchAddress("path", &path_MC);
79  tNDMC->SetBranchAddress("TotalTrackLength", &trackLength_MC);
80  tNDMC->SetBranchAddress("FlightLength", &flightLength_MC);
81  tNDMC->SetBranchAddress("view", &view_MC);
82  tNDMC->SetBranchAddress("cell", &cell_MC);
83 
84  tNDMC->SetBranchAddress("PECorr", &PECorr_MC);
85  tNDMC->SetBranchAddress("path" , &path_MC);
86  tNDMC->SetBranchAddress("trueE" , &trueE_MC);
87  tNDMC->SetBranchAddress("x" , &x_MC);
88 
89  tNDMC->SetBranchAddress("totalPlanes", &planes_MC);
90  tNDMC->SetBranchAddress("xPlanes" , &xplanes_MC);
91  tNDMC->SetBranchAddress("yPlanes" , &yplanes_MC);
92  tNDMC->SetBranchAddress("continuity" , &cont_MC);
93  tNDMC->SetBranchAddress("nhits" , &nhits_MC);
94  tNDMC->SetBranchAddress("hitId" , &hitId_MC);
95 
96  std::cout << "Declaring MC histograms " << std::endl;
97 
98  TH1D* hMCND_view = new TH1D("hMCND_view", "hMCND_view", 2, 0, 2);
99  TH1D* hMCND_wX = new TH1D("hMCND_wX", "hMCND_wX", 40, -200, 200);
100  TH1D* hMCND_wY = new TH1D("hMCND_wY", "hMCND_wY", 40, -200, 200);
101  TH1D* hMCND_cellX = new TH1D("hMCND_cellX", "hMCND_cellX", 20, 0, 100);
102  TH1D* hMCND_cellY = new TH1D("hMCND_cellY", "hMCND_cellY", 20, 0, 100);
103  TH1D* hMCND_pathX = new TH1D("hMCND_pathX", "hMCND_pathX", 10, 0, 10);
104  TH1D* hMCND_pathY = new TH1D("hMCND_pathY", "hMCND_pathY", 10, 0, 10);
105  TH1D* hMCND_trackX = new TH1D("hMCND_trackX", "hMCND_trackX", 35, 0, 700);
106  TH1D* hMCND_trackY = new TH1D("hMCND_trackY", "hMCND_trackY", 35, 0, 700);
107  TH1D* hMCND_flightX = new TH1D("hMCND_flightX", "hMCND_flightX", 30, 0, 600);
108  TH1D* hMCND_flightY = new TH1D("hMCND_flight", "hMCND_flightY", 30, 0, 600);
109 
110 
111  unsigned int nEntries_MC = tNDMC->GetEntries();
112  std::cout << "nEntries_MC = " << nEntries_MC << std::endl;
113 
114  for(unsigned int i=0; i<nEntries_MC; i++){
115  tNDMC->GetEntry(i);
116 
117  if(hitId_MC!=2) continue;
118  if(x_MC<=100 || x_MC>=200) continue;
119  if(PECorr_MC<0 || trueE_MC<0) continue;
120 
121  hMCND_view->Fill(view_MC);
122 
123  if(view_MC==0){
124  hMCND_wX ->Fill(w_MC);
125  hMCND_cellX ->Fill(cell_MC);
126  hMCND_pathX ->Fill(path_MC);
127  hMCND_trackX ->Fill(trackLength_MC);
128  hMCND_flightX ->Fill(flightLength_MC);
129  }
130 
131  if(view_MC==1){
132  hMCND_wY ->Fill(w_MC);
133  hMCND_cellY ->Fill(cell_MC);
134  hMCND_pathY ->Fill(path_MC);
135  hMCND_trackY ->Fill(trackLength_MC);
136  hMCND_flightY ->Fill(flightLength_MC);
137  }
138 
139  }
140 
141 
142  std::cout << "Reading data files " << std::endl;
143 
144  TChain* tNDdata = new TChain("muontrackhits/fTree");
145  tNDdata->Add("data/*.root");
146 
147  double w_data, path_data, trackLength_data, flightLength_data;
148  int view_data, cell_data;
149 
150  double PECorr_data, trueE_data, x_data;
151  double planes_data, xplanes_data, yplanes_data;
152  int cont_data, nhits_data,hitId_data;
153 
154  std::cout << "Setting data branches " << std::endl;
155 
156  tNDdata->SetBranchAddress("w", &w_data);
157  tNDdata->SetBranchAddress("path", &path_data);
158  tNDdata->SetBranchAddress("TotalTrackLength", &trackLength_data);
159  tNDdata->SetBranchAddress("FlightLength", &flightLength_data);
160  tNDdata->SetBranchAddress("view", &view_data);
161  tNDdata->SetBranchAddress("cell", &cell_data);
162 
163  tNDdata->SetBranchAddress("PECorr", &PECorr_data);
164  tNDdata->SetBranchAddress("path" , &path_data);
165  tNDdata->SetBranchAddress("trueE" , &trueE_data);
166  tNDdata->SetBranchAddress("x" , &x_data);
167 
168  tNDdata->SetBranchAddress("totalPlanes", &planes_data);
169  tNDdata->SetBranchAddress("xPlanes" , &xplanes_data);
170  tNDdata->SetBranchAddress("yPlanes" , &yplanes_data);
171  tNDdata->SetBranchAddress("continuity" , &cont_data);
172  tNDdata->SetBranchAddress("nhits" , &nhits_data);
173 
174  std::cout << "Declaring data histos " << std::endl;
175 
176  TH1D* hdataND_view = new TH1D("hdataND_view", "hdataND_view", 2, 0, 2);
177  TH1D* hdataND_wX = new TH1D("hdataND_wX", "hdataND_wX", 40, -200, 200);
178  TH1D* hdataND_wY = new TH1D("hdataND_wY", "hdataND_wY", 40, -200, 200);
179  TH1D* hdataND_cellX = new TH1D("hdataND_cellX", "hdataND_cellX", 20, 0, 100);
180  TH1D* hdataND_cellY = new TH1D("hdataND_cellY", "hdataND_cellY", 20, 0, 100);
181  TH1D* hdataND_pathX = new TH1D("hdataND_pathX", "hdataND_pathX", 10, 0, 10);
182  TH1D* hdataND_pathY = new TH1D("hdataND_pathY", "hdataND_pathY", 10, 0, 10);
183  TH1D* hdataND_trackX = new TH1D("hdataND_trackX", "hdataND_trackX", 35, 0, 700);
184  TH1D* hdataND_trackY = new TH1D("hdataND_trackY", "hdataND_trackY", 35, 0, 700);
185  TH1D* hdataND_flightX = new TH1D("hdataND_flightX", "hdataND_flightX", 30, 0, 600);
186  TH1D* hdataND_flightY = new TH1D("hdataND_flightY", "hdataND_flightY", 30, 0, 600);
187 
188  unsigned int nEntries_data = tNDdata->GetEntries();
189  std::cout << "nEntries_data = " << nEntries_data << std::endl;
190 
191  for(unsigned int i=0; i<nEntries_data; i++){
192  tNDdata->GetEntry(i);
193 
194  if(hitId_data!=2) continue;
195  if(x_data<=100 || x_data>=200) continue;
196  if(PECorr_data<0 || trueE_data<0) continue;
197 
198  hdataND_view->Fill(view_data);
199 
200  if(view_data==0){
201  hdataND_wX ->Fill(w_data);
202  hdataND_cellX ->Fill(cell_data);
203  hdataND_pathX ->Fill(path_data);
204  hdataND_trackX ->Fill(trackLength_data);
205  hdataND_flightX ->Fill(flightLength_data);
206  }
207 
208  if(view_data==1){
209  hdataND_wY ->Fill(w_data);
210  hdataND_cellY ->Fill(cell_data);
211  hdataND_pathY ->Fill(path_data);
212  hdataND_trackY ->Fill(trackLength_data);
213  hdataND_flightY ->Fill(flightLength_data);
214  }
215 
216  }
217 
218 
219  //set mc lines to blue and data to black:
220  hMCND_view -> SetLineColor(kBlue);
221  hMCND_wX -> SetLineColor(kBlue);
222  hMCND_cellX -> SetLineColor(kBlue);
223  hMCND_pathX -> SetLineColor(kBlue);
224  hMCND_trackX -> SetLineColor(kBlue);
225  hMCND_flightX -> SetLineColor(kBlue);
226  hMCND_wY -> SetLineColor(kBlue);
227  hMCND_cellY -> SetLineColor(kBlue);
228  hMCND_pathY -> SetLineColor(kBlue);
229  hMCND_trackY -> SetLineColor(kBlue);
230  hMCND_flightY -> SetLineColor(kBlue);
231 
232  hdataND_view -> SetMarkerColor(1);
233  hdataND_wX -> SetMarkerColor(1);
234  hdataND_cellX -> SetMarkerColor(1);
235  hdataND_pathX -> SetMarkerColor(1);
236  hdataND_trackX -> SetMarkerColor(1);
237  hdataND_flightX -> SetMarkerColor(1);
238  hdataND_wY -> SetMarkerColor(1);
239  hdataND_cellY -> SetMarkerColor(1);
240  hdataND_pathY -> SetMarkerColor(1);
241  hdataND_trackY -> SetMarkerColor(1);
242  hdataND_flightY -> SetMarkerColor(1);
243 
244 
245 
246  //////////// plotting ///////////
247 
248  TCanvas *cNDview = new TCanvas("cNDview","cNDview",c1_x,c1_y);
249  cNDview->cd();
250  hdataND_view->SetTitle("");
251  hMCND_view ->SetTitle("");
252  hdataND_view->GetYaxis()->SetTitle("Tricells");
253  hdataND_view->GetXaxis()->SetTitle("View");
254  CenterTitles(hdataND_view);
255  hdataND_view->GetYaxis()->SetRangeUser(0, GetHistMax(hdataND_view, hdataND_view, hMCND_view, hMCND_view));
256  hdataND_view->Draw();
257  hMCND_view ->Draw("same");
258  Preliminary();
259 
260  cNDview->Print("cND_LowLevel_view.pdf");
261  cNDview->Print("cND_LowLevel_view.png");
262 
263 
264  TCanvas *cNDwX = new TCanvas("cNDwX","cNDwX",c1_x,c1_y);
265  cNDwX->cd();
266  hdataND_wX->SetTitle("");
267  hMCND_wX ->SetTitle("");
268  hdataND_wX->GetYaxis()->SetTitle("Tricells");
269  hdataND_wX->GetXaxis()->SetTitle("w, x-view (cm)");
270  CenterTitles(hdataND_wX);
271  hdataND_wX->GetYaxis()->SetRangeUser(0, GetHistMax(hdataND_wX, hdataND_wX, hMCND_wX, hMCND_wX));
272  hdataND_wX->Draw();
273  hMCND_wX ->Draw("same");
274  Preliminary();
275 
276  cNDwX->Print("cND_LowLevel_wX.pdf");
277  cNDwX->Print("cND_LowLevel_wX.png");
278 
279 
280  TCanvas *cNDwY = new TCanvas("cNDwY","cNDwY",c1_x,c1_y);
281  cNDwY->cd();
282  hdataND_wY->SetTitle("");
283  hMCND_wY ->SetTitle("");
284  hdataND_wY->GetYaxis()->SetTitle("Tricells");
285  hdataND_wY->GetXaxis()->SetTitle("w, y-view (cm)");
286  CenterTitles(hdataND_wY);
287  hdataND_wY->GetYaxis()->SetRangeUser(0, GetHistMax(hdataND_wY, hdataND_wY, hMCND_wY, hMCND_wY));
288  hdataND_wY->Draw();
289  hMCND_wY ->Draw("same");
290  Preliminary();
291 
292  cNDwY->Print("cND_LowLevel_wY.pdf");
293  cNDwY->Print("cND_LowLevel_wY.png");
294 
295 
296 
297 
298  TCanvas *cNDcellX = new TCanvas("cNDcellX","cNDcellX",c1_x,c1_y);
299  cNDcellX->cd();
300  hdataND_cellX->SetTitle("");
301  hMCND_cellX ->SetTitle("");
302  hdataND_cellX->GetYaxis()->SetTitle("Tricells");
303  hdataND_cellX->GetXaxis()->SetTitle("cell, x-view (cm)");
304  CenterTitles(hdataND_cellX);
305  hdataND_cellX->GetYaxis()->SetRangeUser(0, GetHistMax(hdataND_cellX, hdataND_cellX, hMCND_cellX, hMCND_cellX));
306  hdataND_cellX->Draw();
307  hMCND_cellX ->Draw("same");
308  Preliminary();
309 
310  cNDcellX->Print("cND_LowLevel_cellX.pdf");
311  cNDcellX->Print("cND_LowLevel_cellX.png");
312 
313 
314  TCanvas *cNDcellY = new TCanvas("cNDcellY","cNDcellY",c1_x,c1_y);
315  cNDcellY->cd();
316  hdataND_cellY->SetTitle("");
317  hMCND_cellY ->SetTitle("");
318  hdataND_cellY->GetYaxis()->SetTitle("Tricells");
319  hdataND_cellY->GetXaxis()->SetTitle("cell, y-view (cm)");
320  CenterTitles(hdataND_cellY);
321  hdataND_cellY->GetYaxis()->SetRangeUser(0, GetHistMax(hdataND_cellY, hdataND_cellY, hMCND_cellY, hMCND_cellY));
322  hdataND_cellY->Draw("hist");
323  hMCND_cellY ->Draw("hist same");
324  Preliminary();
325 
326  cNDcellY->Print("cND_LowLevel_cellY.pdf");
327  cNDcellY->Print("cND_LowLevel_cellY.png");
328 
329 
330 
331 
332  TCanvas *cNDpathX = new TCanvas("cNDpathX","cNDpathX",c1_x,c1_y);
333  cNDpathX->cd();
334  hdataND_pathX->SetTitle("");
335  hMCND_pathX ->SetTitle("");
336  hdataND_pathX->GetYaxis()->SetTitle("Tricells");
337  hdataND_pathX->GetXaxis()->SetTitle("path, x-view (cm)");
338  CenterTitles(hdataND_pathX);
339  hdataND_pathX->GetYaxis()->SetRangeUser(0, GetHistMax(hdataND_pathX, hdataND_pathX, hMCND_pathX, hMCND_pathX));
340  hdataND_pathX->Draw();
341  hMCND_pathX ->Draw("same");
342  Preliminary();
343 
344  cNDpathX->Print("cND_LowLevel_pathX.pdf");
345  cNDpathX->Print("cND_LowLevel_pathX.png");
346 
347 
348  TCanvas *cNDpathY = new TCanvas("cNDpathY","cNDpathY",c1_x,c1_y);
349  cNDpathY->cd();
350  hdataND_pathY->SetTitle("");
351  hMCND_pathY ->SetTitle("");
352  hdataND_pathY->GetYaxis()->SetTitle("Tricells");
353  hdataND_pathY->GetXaxis()->SetTitle("path, y-view (cm)");
354  CenterTitles(hdataND_pathY);
355  hdataND_pathY->GetYaxis()->SetRangeUser(0, GetHistMax(hdataND_pathY, hdataND_pathY, hMCND_pathY, hMCND_pathY));
356  hdataND_pathY->Draw();
357  hMCND_pathY ->Draw("same");
358  Preliminary();
359 
360  cNDpathY->Print("cND_LowLevel_pathY.pdf");
361  cNDpathY->Print("cND_LowLevel_pathY.png");
362 
363 
364 
365  TCanvas *cNDtrackX = new TCanvas("cNDtrackX","cNDtrackX",c1_x,c1_y);
366  cNDtrackX->cd();
367  hdataND_trackX->SetTitle("");
368  hMCND_trackX ->SetTitle("");
369  hdataND_trackX->GetYaxis()->SetTitle("Tricells");
370  hdataND_trackX->GetXaxis()->SetTitle("Track length, x-view (cm)");
371  CenterTitles(hdataND_trackX);
372  hdataND_trackX->GetYaxis()->SetRangeUser(0, GetHistMax(hdataND_trackX, hdataND_trackX, hMCND_trackX, hMCND_trackX));
373  hdataND_trackX->Draw();
374  hMCND_trackX ->Draw("same");
375  Preliminary();
376 
377  cNDtrackX->Print("cND_LowLevel_trackX.pdf");
378  cNDtrackX->Print("cND_LowLevel_trackX.png");
379 
380  TCanvas *cNDtrackY = new TCanvas("cNDtrackY","cNDtrackY",c1_x,c1_y);
381  cNDtrackY->cd();
382  hdataND_trackY->SetTitle("");
383  hMCND_trackY ->SetTitle("");
384  hdataND_trackY->GetYaxis()->SetTitle("Tricells");
385  hdataND_trackY->GetXaxis()->SetTitle("Track length, y-view (cm)");
386  CenterTitles(hdataND_trackY);
387  hdataND_trackY->GetYaxis()->SetRangeUser(0, GetHistMax(hdataND_trackY, hdataND_trackY, hMCND_trackY, hMCND_trackY));
388  hdataND_trackY->Draw("hist");
389  hMCND_trackY ->Draw("hist same");
390  Preliminary();
391 
392  cNDtrackY->Print("cND_LowLevel_trackY.pdf");
393  cNDtrackY->Print("cND_LowLevel_trackY.png");
394 
395 
396 
397  TCanvas *cNDflightX = new TCanvas("cNDflightX","cNDflightX",c1_x,c1_y);
398  cNDflightX->cd();
399  hdataND_flightX->SetTitle("");
400  hMCND_flightX ->SetTitle("");
401  hdataND_flightX->GetYaxis()->SetTitle("Tricells");
402  hdataND_flightX->GetXaxis()->SetTitle("Flight length, x-view (cm)");
403  CenterTitles(hdataND_flightX);
404  hdataND_flightX->GetYaxis()->SetRangeUser(0, GetHistMax(hdataND_flightX, hdataND_flightX, hMCND_flightX, hMCND_flightX));
405  hdataND_flightX->Draw();
406  hMCND_flightX ->Draw("same");
407  Preliminary();
408 
409  cNDflightX->Print("cND_LowLevel_flightX.pdf");
410  cNDflightX->Print("cND_LowLevel_flightX.png");
411 
412 
413  TCanvas *cNDflightY = new TCanvas("cNDflightY","cNDflightY",c1_x,c1_y);
414  cNDflightY->cd();
415  hdataND_flightY->SetTitle("");
416  hMCND_flightY ->SetTitle("");
417  hdataND_flightY->GetYaxis()->SetTitle("Tricells");
418  hdataND_flightY->GetXaxis()->SetTitle("Flight length, y-view (cm)");
419  CenterTitles(hdataND_flightY);
420  hdataND_flightY->GetYaxis()->SetRangeUser(0, GetHistMax(hdataND_flightY, hdataND_flightY, hMCND_flightY, hMCND_flightY));
421  hdataND_flightY->Draw();
422  hMCND_flightY ->Draw("same");
423  Preliminary();
424 
425  cNDflightY->Print("cND_LowLevel_flightY.pdf");
426  cNDflightY->Print("cND_LowLevel_flightY.png");
427 
428 
429 }
430 
431 
433  return main();
434 }
435 
436 double GetHistMax(TH1* h0, TH1* h1, TH1* h2, TH1* h3){
437  double max[4];
438  max[0] = h0->GetMaximum();
439  max[1] = h1->GetMaximum();
440  max[2] = h2->GetMaximum();
441  max[3] = h3->GetMaximum();
442 
443  double hiy = 0;
444  for(int i=1;i<4;i++){
445  if(max[i]>hiy)
446  hiy = max[i];
447  }
448  return (hiy * 1.1);
449 }
int FD_LowLevelPlots()
double GetHistMax(TH1 *h0, TH1 *h1, TH1 *h2, TH1 *h3)
TH1F * h3
Definition: berger.C:36
#define c1_y
int main()
void CenterTitles(TH1 *h)
hmean SetLineColor(4)
h1 SetMarkerColor(4)
void Preliminary()
OStream cout
Definition: OStream.cxx:6
TH1F * h2
Definition: plot.C:45
TH1F * h1
#define c1_x
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
enum BeamMode kBlue