AliPhysics  d565ceb (d565ceb)
PlotEMCALQATrendingTree.C
Go to the documentation of this file.
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <TSystem.h>
3 #include <TStyle.h>
4 #include <TROOT.h>
5 #include <Riostream.h>
6 #include <TFile.h>
7 #include <TH1F.h>
8 #include <TCanvas.h>
9 #include <TGraphErrors.h>
10 #include <TLegend.h>
11 #include <TTree.h>
12 #include <TTreeFormula.h>
13 #include <TEventList.h>
14 #include <TObjString.h>
15 #include <TList.h>
16 #include <TCut.h>
17 #include <TError.h>
18 #include <TDatime.h>
19 #include <TPRegexp.h>
20 #include <TInterpreter.h>
21 #include <TGaxis.h>
22 #endif
23 
36 
37 
38 int PlotEMCALQATrendingTree(TTree* tree, const char* trig,TFile* fout,Bool_t SavePlots,TString expr);
39 TH1F* ZoomFromTree(TH1F* h, TTree* atree, Int_t n, const char* aVar, UShort_t aScaleFactor=1);
40 Double_t GetTreeMinimum(TTree* aTree, Int_t n, const char* columname);
41 Double_t GetTreeMaximum(TTree* aTree, Int_t n, const char* columname);
42 
45 
46 //--------------------------------------------------------------------------------------------------------------------
47 int NextInt(int newMax=0)
48 {
49 
50  static int N=0;
51  static int nMax=1;
52 
53  if(newMax) {nMax = newMax; N=0; return 0;}
54  if (N == nMax) N=0;
55  N = N +1;
56  return N;
57 
58 }
59 
60 //--------------------------------------------------------------------------------------------------------------------
61 int PlotEMCALQATrendingTree(const char* filename="trending.root",Bool_t SavePlots=0, TString expr ="", TString fTrigger="")
62 {
63 
64  QAPATH = TString(gSystem->Getenv("QAPATH"));
65  if(QAPATH.IsNull()) QAPATH = QAPATHF;
66 
67  Int_t ret=0;
68  TFile* f = TFile::Open(filename);
69  if(!f) { return -1;}
70  TTree* tree = (TTree*)f->Get("trending");
71  if (! tree) {Error("PlotEMCALQATrendingTree","No Tree found!"); return -1;}
72  TFile* fout = new TFile(Form("%s/trendingPlots.root",QAPATH.Data()),"RECREATE");
73 
74  TList* TriggersList = new TList();
75  if (fTrigger=="")
76  {
77  tree->Draw("fTrigger","","goff");
78  const char* obj;
79  for(Int_t i = 0 ; i < tree->GetSelectedRows() ; i++){
80  tree->GetEntry(i);
81  obj = tree->GetVar1()->PrintValue(0);
82  if(! TriggersList->FindObject(obj)) {TriggersList->Add(new TObjString(obj));}
83  }
84  }
85  else
86  {
87  if(!fTrigger.Contains("QA")) {fTrigger = "CaloQA_" + fTrigger;}
88  TriggersList->Add(new TObjString(fTrigger.Data()));
89  }
90  TIter next(TriggersList);
91  TObject* obj1;
92  while ((obj1 = next()))
93  {
94  ret = PlotEMCALQATrendingTree(tree,obj1->GetName(),fout,SavePlots,expr);
95  }
96 
97  f->Close();
98  return ret;
99 
100 }
101 
102 //--------------------------------------------------------------------------------------------------------------------
103 int PlotEMCALQATrendingTree(TTree* tree, const char* Trig, TFile* fout, Bool_t SavePlots,TString Expr)
104 {
105 
106  TCut trig = Form("fTrigger==\"%s\"",Trig);
107  TCut NotZero = TCut("Nevent>0.&&Npi0SM>0.");
108  TCut select = trig;
109 
110  if (Expr.Contains(".C"))
111  {
112  Info("PlotEMCALQATrendingTree",Form("Additional selections from %s: ", Expr.Data()));
113  gInterpreter->ExecuteMacro(Expr.Data());
114  select = trig + expr;
115  }
116 
117  if (! tree) {Error("PlotEMCALQATrendingTree","No Tree found!"); return -1;}
118  select.Print();
119  int CurN=0;
120  TString* fCalorimeter;
121  TString* period;
122  TString* pass;
123  TString* fTrigger;
124  TString* system;
125  TDatime* dtime;
126 
127  tree->SetBranchAddress("fDate",&dtime);
128  tree->SetBranchAddress("nSM",&CurN);
129  tree->SetBranchAddress("fCalorimeter",&fCalorimeter);
130  tree->SetBranchAddress("system",&system);
131  tree->SetBranchAddress("period",&period);
132  tree->SetBranchAddress("pass",&pass);
133  tree->SetBranchAddress("fTrigger",&fTrigger);
134 
135 
136  tree->SetEventList(0);
137  tree->Draw(">>elist",select);
138  tree->Draw(">>listNotZero",select+NotZero);
139  TEventList* listNotZero = (TEventList*)gDirectory->Get("listNotZero");
140  TEventList* elist = (TEventList*)gDirectory->Get("elist");
141  tree->SetEventList(elist);
142  if(! elist->GetN()) { Error("PlotEMCALQATrendingTree","The current selection doess not match any entry!"); return -2; }
143  CurN = tree->GetMinimum("nSM");
144  const Int_t n = CurN;
145  if(n<=12) const Int_t nEMCAL = n;
146  if(n>12) const Int_t nEMCAL = 12;
147  tree->GetEntry(elist->GetEntry(0));
148 
149  TGraphErrors* AverNclustersSM[n];
150  TGraph* TotNclustersSM[n];
151  TGraphErrors* AverNcellsPerClusterSM[n];
152  TGraphErrors* AverESM[n];
153  TGraphErrors* AverMeanSM[n];
154  TGraphErrors* AverWidthSM[n];
155  TGraphErrors* AverNpi0SM[n];
156 
157  // --------------------------------- plots ------------------------------
158 
159  TString base = QAPATH + period->Data() + "_" + pass->Data() + "_";
160  TPRegexp r("_\\w+");
161 
162  TString ClusterAverages; ClusterAverages = base + "ClAv" + (*fTrigger)(r) + ".png";
163  TString Entries; Entries = base + "Nentries" + (*fTrigger)(r) + ".png";
164  TString ClusterAveragesEnergy; ClusterAveragesEnergy = base + "ClAvEne" + (*fTrigger)(r) + ".png";
165  TString ClusterAveragesEnergyD; ClusterAveragesEnergyD = base + "ClAvEne" + (*fTrigger)(r) + "DCAL.png";
166  TString ClusterAveragesEnergy2; ClusterAveragesEnergy2 = base + "ClAvEne" + (*fTrigger)(r) + ".pdf";
167  TString ClusterAveragesEnergy2D; ClusterAveragesEnergy2D = base + "ClAvEne" + (*fTrigger)(r) + "DCAL.pdf";
168  TString ClusterAveragesEntries; ClusterAveragesEntries = base + "ClAvEnt" + (*fTrigger)(r) + ".png";
169  TString ClusterTotEntries; ClusterTotEntries = base + "ClTotEnt" + (*fTrigger)(r) + ".png";
170  TString ClusterTotEntries2; ClusterTotEntries2 = base + "ClTotEnt" + (*fTrigger)(r) + ".png";
171  TString ClusterTotEntriesD; ClusterTotEntries = base + "ClTotEnt" + (*fTrigger)(r) + ".png";
172  TString ClusterTotEntriesD2; ClusterTotEntries2 = base + "ClTotEnt" + (*fTrigger)(r) + ".png";
173  TString ClusterAveragesEntriesD; ClusterAveragesEntriesD = base + "ClAvEnt" + (*fTrigger)(r) + "DCAL.png";
174  TString ClusterAveragesEntries2; ClusterAveragesEntries2 = base + "ClAvEnt" + (*fTrigger)(r) + ".pdf";
175  TString ClusterAveragesEntries2D; ClusterAveragesEntries2D = base + "ClAvEnt" + (*fTrigger)(r) + "DCAL.pdf";
176  TString ClusterAveragesCells; ClusterAveragesCells = base + "ClAvCells" + (*fTrigger)(r) + ".png";
177  TString ClusterAveragesCells2; ClusterAveragesCells2 = base + "ClAvCells" + (*fTrigger)(r) + ".pdf";
178  TString ClusterChargedvsTot; ClusterChargedvsTot = base + "ClCharged" + (*fTrigger)(r) + ".png";
179  TString ClusterChargedvsTot2; ClusterChargedvsTot2 = base + "ClCharged" + (*fTrigger)(r) + ".pdf";
180  TString Pi0Entries; Pi0Entries = base + "Pi0Entries" + (*fTrigger)(r) + ".png";
181  TString Pi0Entries2; Pi0Entries2 = base + "Pi0Entries" + (*fTrigger)(r) + ".pdf";
182  TString Pi0Mass; Pi0Mass = base + "Pi0Mass" + (*fTrigger)(r) + ".png";
183  TString Pi0Mass2; Pi0Mass2 = base + "Pi0Mass" + (*fTrigger)(r) + ".pdf";
184  TString Pi0Width; Pi0Width = base + "Pi0Width" + (*fTrigger)(r) + ".png";
185  TString Pi0Width2; Pi0Width2 = base + "Pi0Width" + (*fTrigger)(r) + ".pdf";
186 
187 
188  int nEmptyRuns = tree->Draw("run","Nevent==0","goff");
189  if (nEmptyRuns && (nEmptyRuns != -1)) {
190  Info("PlotEMCALQATrendingTree",Form("The following %i runs are empty for trigger %s:",nEmptyRuns,Trig));
191  for(Int_t i = 0 ; i < nEmptyRuns ; i++){
192  cout<<tree->GetV1()[i]<<endl;
193  }
194  }
195 
196  int nNoEMCALRuns = tree->Draw("run","Nevent!=0&&EtotalMean==0","goff");
197  if (nNoEMCALRuns && (nNoEMCALRuns != -1)) {
198  Info("PlotEMCALQATrendingTree",Form("The following %i runs are without EMCAL for trigger %s:",nNoEMCALRuns,Trig));
199  for(Int_t i = 0 ; i < nNoEMCALRuns ; i++){
200  cout<<tree->GetV1()[i]<<endl;
201  }
202  }
203 
204  int nRun = tree->Draw("run","","goff");
205  NextInt(nRun);
206  TH1F* h1 = new TH1F("h1", "dummy", nRun, 0., nRun+0.5);
207  TGaxis::SetMaxDigits(3);
208  h1->SetTitle("") ;
209  h1->SetStats(kFALSE) ;
210  h1->SetAxisRange(0, nRun, "X") ;
211  h1->GetXaxis()->SetTitle("RUN Index");
212  h1->GetXaxis()->SetTitleOffset(1.86);
213  h1->GetXaxis()->SetTitleSize(0.03);
214 
215  for(Int_t i = 0 ; i < nRun ; i++){
216  TString label = " ";
217  label+=tree->GetV1()[i];
218  h1->GetXaxis()->SetBinLabel(i+1,label.Data());
219  h1->GetXaxis()->LabelsOption("v");
220  }
221 
222  //number of events
223  TCanvas* c1 = new TCanvas("Nevents","Nb of events", 1000, 500);
224  c1->SetFillColor(0);
225  c1->SetBorderSize(0);
226  c1->SetFrameBorderMode(0);
227  gStyle->SetOptStat(0);
228  gPad->SetLeftMargin(0.08);
229  gPad->SetRightMargin(0.02);
230  c1->SetGrid();
231  tree->Draw("NextInt():Nevent","","goff");
232  h1->GetYaxis()->SetTitle("N_{events}");
233  ZoomFromTree(h1,tree,n,"Nevent",2);
234  if (h1->GetMinimum() > 0.) {c1->SetLogy();}
235  h1->Draw();
236 
237  TGraph* Nevents = new TGraph(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2());
238  Nevents->SetMarkerStyle(20);
239  Nevents->SetMarkerColor(1);
240  Nevents->SetLineColor(2);
241  Nevents->Draw("same lp") ;
242 
243  c1->Update();
244  if(SavePlots) c1->SaveAs(Entries);
245 
246  TCanvas* c2 = new TCanvas("ClusterAveragesEvents", "Mean Nb of Cluster per Event", 1000, 500);
247  c2->SetFillColor(0);
248  c2->SetBorderSize(0);
249  c2->SetFrameBorderMode(0);
250  c2->SetGrid();
251 
252  gPad->SetLeftMargin(0.08);
253  gPad->SetRightMargin(0.02);
254  gPad->SetGrid();
255 
256  TH1F* h2 = (TH1F*)h1->Clone("");
257  h2->GetYaxis()->SetTitle("<N_{clusters}>/event");
258  ZoomFromTree(h2,tree,n,"ClusterMeanSM");
259  h2->GetXaxis()->SetTitle("RUN Index");
260  h2->GetXaxis()->SetTitleOffset(1.86);
261  h2->GetXaxis()->SetTitleSize(0.03);
262  h2->Draw();
263 
264  tree->Draw("NextInt():ClusterMean:xe:ClusterRMS","","goff");
265  TGraphErrors * AverNclusters = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(), tree->GetV4());
266  AverNclusters->SetMarkerStyle(20);
267  AverNclusters->SetMarkerColor(1);
268  AverNclusters->Draw("same P") ;
269 
270  for(Int_t ism = 0 ; ism < nEMCAL ; ism++){
271  tree->Draw(Form("NextInt():ClusterMeanSM[%i]:xe:ClusterRMSSM[%i]",ism,ism),"","goff");
272  AverNclustersSM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
273  if (ism !=8)AverNclustersSM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverNclustersSM[ism]->SetMarkerColor(7);
274  AverNclustersSM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10));
275 
276  AverNclustersSM[ism]->Draw("same P");
277  }
278  TLegend* l2 = new TLegend(0.123, 0.744, 0.933, 0.894);
279  l2->SetNColumns((n+1)/2.);
280  l2->SetFillColor(0);
281  l2->SetBorderSize(0);
282  l2->SetTextSize(0.04);
283  l2->SetHeader(Form("<# of clusters> in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data()));
284  l2->AddEntry(AverNclusters,"average", "p");
285  for(Int_t ism = 0; ism < nEMCAL ; ism++){
286  TString projname = Form("SM %d",ism);
287  l2->AddEntry(AverNclustersSM[ism],projname.Data(), "p");
288  }
289  l2->Draw("same");
290  c2->Update();
291  if(SavePlots) c2->SaveAs(ClusterAveragesEntries);
292  if(SavePlots==2) c2->SaveAs(ClusterAveragesEntries2);
293 
294  if(n>12)
295  {
296  TCanvas* c2D = new TCanvas("ClusterAveragesEventsD", "Mean Nb of Cluster per Event", 1000, 500);
297  c2D->SetFillColor(0);
298  c2D->SetBorderSize(0);
299  c2D->SetFrameBorderMode(0);
300  c2D->SetGrid();
301 
302  gPad->SetLeftMargin(0.08);
303  gPad->SetRightMargin(0.02);
304  gPad->SetGrid();
305 
306  TH1F* h2D = (TH1F*)h1->Clone("");
307  h2D->GetYaxis()->SetTitle("<N_{clusters}>/event");
308  ZoomFromTree(h2D,tree,n,"ClusterMeanSM");
309  h2D->GetXaxis()->SetTitle("RUN Index");
310  h2D->GetXaxis()->SetTitleOffset(1.86);
311  h2D->GetXaxis()->SetTitleSize(0.03);
312  h2D->Draw();
313 
314  tree->Draw("NextInt():ClusterMean:xe:ClusterRMS","","goff");
315  TGraphErrors * AverNclustersD = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(), tree->GetV4());
316  AverNclustersD->SetMarkerStyle(20);
317  AverNclustersD->SetMarkerColor(1);
318  AverNclustersD->Draw("same P") ;
319 
320  for(Int_t ism = 12 ; ism < n ; ism++){
321  tree->Draw(Form("NextInt():ClusterMeanSM[%i]:xe:ClusterRMSSM[%i]",ism,ism),"","goff");
322  AverNclustersSM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
323  if (ism !=8)AverNclustersSM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverNclustersSM[ism]->SetMarkerColor(7);
324  AverNclustersSM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10));
325 
326  AverNclustersSM[ism]->Draw("same P");
327  }
328 
329  TLegend* l2D = new TLegend(0.123, 0.744, 0.933, 0.894);
330  l2D->SetNColumns((n+1)/2.);
331  l2D->SetFillColor(0);
332  l2D->SetBorderSize(0);
333  l2D->SetTextSize(0.04);
334  l2D->SetHeader(Form("<# of clusters> in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data()));
335  l2D->AddEntry(AverNclusters,"average", "p");
336  for(Int_t ism = 12 ; ism < n ; ism++){
337  TString projname = Form("SM %d",ism);
338  l2D->AddEntry(AverNclustersSM[ism],projname.Data(), "p");
339  }
340  l2D->Draw("same");
341  c2D->Update();
342  if(SavePlots) c2D->SaveAs(ClusterAveragesEntriesD);
343  if(SavePlots==2) c2D->SaveAs(ClusterAveragesEntries2D);
344  }
345 
346  TCanvas* c2Tot = new TCanvas("ClusterTotEvents", "Tot Nb of Cluster per Event", 1000, 500);
347  c2Tot->SetFillColor(0);
348  c2Tot->SetBorderSize(0);
349  c2Tot->SetFrameBorderMode(0);
350  c2Tot->SetGrid();
351 
352  gPad->SetLeftMargin(0.08);
353  gPad->SetRightMargin(0.02);
354  gPad->SetGrid();
355 
356  TH1F* h2Tot = (TH1F*)h1->Clone("");
357  h2Tot->GetYaxis()->SetTitle("N_{clusters}/event");
358  ZoomFromTree(h2Tot,tree,n,"ClusterTotSM");
359  h2Tot->GetXaxis()->SetTitle("RUN Index");
360  h2Tot->GetXaxis()->SetTitleOffset(1.86);
361  h2Tot->GetXaxis()->SetTitleSize(0.03);
362  h2Tot->Draw();
363 
364 
365 
366  for(Int_t ism = 0 ; ism < nEMCAL ; ism++){
367  tree->Draw(Form("NextInt():ClusterTotSM[%i]",ism),"","goff");
368  TotNclustersSM[ism] = new TGraph(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2());
369  if (ism !=8)TotNclustersSM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else TotNclustersSM[ism]->SetMarkerColor(7);
370  TotNclustersSM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10));
371 
372  TotNclustersSM[ism]->Draw("same P");
373  }
374  TLegend* l2Tot = new TLegend(0.123, 0.744, 0.933, 0.894);
375  l2Tot->SetNColumns((n+1)/2.);
376  l2Tot->SetFillColor(0);
377  l2Tot->SetBorderSize(0);
378  l2Tot->SetTextSize(0.04);
379  l2Tot->SetHeader(Form("# of clusters in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data()));
380  //l2Tot->AddEntry(TotNclusters,"total", "p");
381  for(Int_t ism = 0; ism < nEMCAL ; ism++){
382  TString projname = Form("SM %d",ism);
383  l2Tot->AddEntry(TotNclustersSM[ism],projname.Data(), "p");
384  }
385  l2Tot->Draw("same");
386  c2Tot->Update();
387  if(SavePlots) c2Tot->SaveAs(ClusterTotEntries);
388  if(SavePlots==2) c2Tot->SaveAs(ClusterTotEntries2);
389 
390  if(n>12)
391  {
392  TCanvas* c2TotD = new TCanvas("ClusterTotEventsD", "Tot Nb of Cluster per Event in DCAL", 1000, 500);
393  c2TotD->SetFillColor(0);
394  c2TotD->SetBorderSize(0);
395  c2TotD->SetFrameBorderMode(0);
396  c2TotD->SetGrid();
397 
398  gPad->SetLeftMargin(0.08);
399  gPad->SetRightMargin(0.02);
400  gPad->SetGrid();
401 
402  TH1F* h2TotD = (TH1F*)h1->Clone("");
403  h2TotD->GetYaxis()->SetTitle("N_{clusters}/event");
404  ZoomFromTree(h2TotD,tree,n,"ClusterTotSM");
405  h2TotD->GetXaxis()->SetTitle("RUN Index");
406  h2TotD->GetXaxis()->SetTitleOffset(1.86);
407  h2TotD->GetXaxis()->SetTitleSize(0.03);
408  h2TotD->Draw();
409 
410 
411 
412  for(Int_t ism = 12 ; ism < n ; ism++){
413  tree->Draw(Form("NextInt():ClusterTotSM[%i]",ism),"","goff");
414  TotNclustersSM[ism] = new TGraph(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2());
415  if (ism !=8)TotNclustersSM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else TotNclustersSM[ism]->SetMarkerColor(7);
416  TotNclustersSM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10));
417 
418  TotNclustersSM[ism]->Draw("same P");
419  }
420  TLegend* l2TotD = new TLegend(0.123, 0.744, 0.933, 0.894);
421  l2TotD->SetNColumns((n+1)/2.);
422  l2TotD->SetFillColor(0);
423  l2TotD->SetBorderSize(0);
424  l2TotD->SetTextSize(0.04);
425  l2TotD->SetHeader(Form("# of clusters in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data()));
426  //l2Tot->AddEntry(TotNclusters,"total", "p");
427  for(Int_t ism = 12; ism < n ; ism++){
428  TString projname = Form("SM %d",ism);
429  l2TotD->AddEntry(TotNclustersSM[ism],projname.Data(), "p");
430  }
431  l2TotD->Draw("same");
432  c2TotD->Update();
433  if(SavePlots) c2TotD->SaveAs(ClusterTotEntriesD);
434  if(SavePlots==2) c2TotD->SaveAs(ClusterTotEntriesD2);
435 
436  }
437 
438 
439 
440  TCanvas* c3 = new TCanvas("ClusterAveragesEnergy", "Mean Cluster Energy", 1000, 500);
441  c3->SetFillColor(0);
442  c3->SetBorderSize(0);
443  c3->SetFrameBorderMode(0);
444  c3->SetGrid();
445 
446  gPad->SetLeftMargin(0.08);
447  gPad->SetRightMargin(0.02);
448  gPad->SetGrid();
449 
450  TH1F* h3 = (TH1F*)h1->Clone("");
451  h3->GetYaxis()->SetTitle("<E> (GeV)");
452  ZoomFromTree(h3,tree,n,"EtotalMeanSM");
453  h3->GetXaxis()->SetTitle("RUN Index");
454  h3->GetXaxis()->SetTitleOffset(1.86);
455  h3->GetXaxis()->SetTitleSize(0.03);
456  h3->Draw();
457 
458  tree->Draw("NextInt():EtotalMean:xe:EtotalRMS","","goff");
459  TGraphErrors * AverE = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
460  AverE->SetMarkerStyle(20);
461  AverE->SetMarkerColor(1);
462  AverE->Draw("same P");
463 
464  for(Int_t ism = 0 ; ism < n ; ism++){
465 
466  tree->Draw(Form("NextInt():EtotalMeanSM[%i]:xe:EtotalRMSSM[%i]",ism,ism),"","goff");
467  AverESM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
468  if (ism !=8)AverESM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverESM[ism]->SetMarkerColor(7);
469  AverESM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10));
470  AverESM[ism]->Draw("same P");
471 
472  }
473 
474  TLegend* l3 = new TLegend(0.123, 0.744, 0.933, 0.894);
475  l3->SetNColumns((n+1)/2.);
476  l3->SetFillColor(0);
477  l3->SetBorderSize(0);
478  l3->SetTextSize(0.04);
479  l3->SetHeader(Form("<E> in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data()));
480  l3->AddEntry(AverE,"average", "p");
481  for(Int_t ism = 0 ; ism < n ; ism++){
482  TString projname = Form("SM %d",ism);
483  l3->AddEntry(AverESM[ism],projname.Data(), "p");
484  }
485  l3->Draw("same");
486 
487  if(SavePlots) c3->SaveAs(ClusterAveragesEnergy);
488  if(SavePlots==2) c3->SaveAs(ClusterAveragesEnergy2);
489 
490  TCanvas* c4 = new TCanvas("ClusterAveragesCells", "Mean Nb of Cells per Cluster", 1000, 500);
491  c4->SetFillColor(0);
492  c4->SetBorderSize(0);
493  c4->SetFrameBorderMode(0);
494  c4->SetGrid();
495 
496  gPad->SetLeftMargin(0.08);
497  gPad->SetRightMargin(0.02);
498  gPad->SetGrid();
499 
500  TH1F* h4 = (TH1F*)h1->Clone("");
501  h4->GetYaxis()->SetTitle("<N_{CellsPerCluster}>");
502  ZoomFromTree(h4,tree,n,"CellPerClusterMeanSM");
503  h4->GetXaxis()->SetTitle("RUN Index");
504  h4->GetXaxis()->SetTitleOffset(1.86);
505  h4->GetXaxis()->SetTitleSize(0.03);
506  h4->Draw();
507 
508  //
509  tree->Draw("NextInt():CellPerClusterMean:xe:CellPerClusterRMS","","goff");
510  TGraphErrors * AverCellPerCluster = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
511  AverCellPerCluster->SetMarkerStyle(20);
512  AverCellPerCluster->SetMarkerColor(1);
513 
514  for(Int_t ism = 0 ; ism < n ; ism++){
515  tree->Draw(Form("NextInt():CellPerClusterMeanSM[%i]:xe:CellPerClusterRMSSM[%i]",ism,ism),"","goff");
516  AverNcellsPerClusterSM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
517  if (ism !=8)AverNcellsPerClusterSM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverNcellsPerClusterSM[ism]->SetMarkerColor(7);
518  AverNcellsPerClusterSM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10));
519  AverNcellsPerClusterSM[ism]->Draw("same P");
520 
521  }
522 
523  TLegend* l4 = new TLegend(0.123, 0.744, 0.933, 0.894);
524  l4->SetNColumns((n+1)/2.);
525  l4->SetFillColor(0);
526  l4->SetBorderSize(0);
527  l4->SetTextSize(0.04);
528  l4->SetHeader(Form("<# of cells per cluster> in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data()));
529  l4->AddEntry(AverCellPerCluster,"average", "p");
530  for(Int_t ism = 0 ; ism < n ; ism++){
531  TString projname = Form("SM %d",ism);
532  l4->AddEntry(AverNcellsPerClusterSM[ism],projname.Data(), "p");
533  }
534  l4->Draw("same");
535 
536  if(SavePlots) c4->SaveAs(ClusterAveragesCells);
537 
538  TCanvas* c8 = new TCanvas("NMatchClusters","x100 % of matched clusters", 1000, 500);
539  c8->SetFillColor(0);
540  c8->SetBorderSize(0);
541  c8->SetFrameBorderMode(0);
542  gStyle->SetOptStat(0);
543  gPad->SetLeftMargin(0.08);
544  gPad->SetRightMargin(0.02);
545  c8->SetGrid();
546 
547 
548  TH1F* h8 = (TH1F*)h1->Clone("");
549  h8->GetYaxis()->SetTitle("#frac{N_{match}}{N_{tot}}");
550  ZoomFromTree(h8,tree,n,"NMatchClustersP");
551  h8->GetXaxis()->SetTitle("RUN Index");
552  h8->GetXaxis()->SetTitleOffset(1.86);
553  h8->GetXaxis()->SetTitleSize(0.03);
554  h8->Draw();
555 
556  tree->Draw("NextInt():NMatchClustersP:xe:NMatchClustersPRMS","","goff");
557  TGraphErrors* NMatchCl = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(), tree->GetV3(), tree->GetV4());
558  NMatchCl->SetMarkerStyle(20);
559  NMatchCl->SetMarkerColor(1);
560  NMatchCl->Draw("same p") ;
561 
562  c8->Update();
563  if(SavePlots) c8->SaveAs(ClusterChargedvsTot);
564 
565 
566  TCanvas* c5 = new TCanvas("Pi0Position", "Mean Pi0 Mass", 1000, 500);
567  c5->SetFillColor(0);
568  c5->SetBorderSize(0);
569  c5->SetFrameBorderMode(0);
570  c5->SetGrid();
571 
572  gStyle->SetOptStat(0);
573 
574  gPad->SetLeftMargin(0.08);
575  gPad->SetRightMargin(0.02);
576  gPad->SetGrid();
577 
578 
579 
580  TLine* lUp = new TLine(0,148,nRun+0.5,148);
581  lUp->SetLineColor(kRed);
582 
583  TLine* lDown = new TLine(0,122,nRun+0.5,122);
584  lDown->SetLineColor(kRed);
585 
586  TH1F * h5 = (TH1F*)h1->Clone("");
587  ZoomFromTree(h5,tree,n,"MeanPosSM");
588  h5->GetXaxis()->SetTitle("RUN Index");
589  h5->GetXaxis()->SetTitleOffset(1.86);
590  h5->GetXaxis()->SetTitleSize(0.03);
591  h5->GetYaxis()->SetTitle("Mean_{#pi^{0}}");
592 
593  h5->Draw();
594 
595 
596  tree->Draw("NextInt():MeanPosEMCAL:xe:MeanPosEMCALErr","","goff");
597  TGraphErrors * AverMeanEMCAL = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
598  AverMeanEMCAL->SetMarkerStyle(20);
599  AverMeanEMCAL->SetMarkerColor(1);
600  AverMeanEMCAL->Draw("same P");
601 
602  if(n>12)
603  {
604  tree->Draw("NextInt():MeanPosDCAL:xe:MeanPosDCALErr","","goff");
605  TGraphErrors * AverMeanDCAL = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
606  AverMeanDCAL->SetMarkerStyle(20);
607  AverMeanDCAL->SetMarkerColor(2);
608  AverMeanDCAL->Draw("same P");
609  }
610  // // TLine lineLow(V1[0], 120., V1[GetSelectedRows()], 145.);
611  // // TLine lineUp(V1(1), y_0, x_1, y_1);
612  // lineLow->SetLineColor(2);
613  // // lineUp->SetLineColor(2);
614  // lineLow->Draw("same");
615  // // lineUp->Draw("same");
616 
617  for(Int_t ism = 0 ; ism < n ; ism++){
618 
619  tree->Draw(Form("NextInt():MeanPosSM[%i]:xe:MeanPosErrSM[%i]",ism,ism),"","goff");
620  AverMeanSM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
621  if (ism !=8)AverMeanSM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverMeanSM[ism]->SetMarkerColor(7);
622  AverMeanSM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10));
623  AverMeanSM[ism]->Draw("same P");
624  }
625 
626 
627  TLegend* l5 = new TLegend(0.123, 0.744, 0.933, 0.894);
628  l5->SetNColumns((n+1)/2.);
629  l5->SetFillColor(0);
630  l5->SetBorderSize(0);
631  l5->SetTextSize(0.04);
632  l5->SetHeader(Form("<M_{#pi^{0}}> (MeV) in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data()));
633  l5->AddEntry(AverMeanEMCAL,"average EMCAL", "p");
634  if(n>12) l5->AddEntry(AverMeanDCAL,"average DCAL", "p");
635  for(Int_t ism = 0 ; ism < n ; ism++){
636  TString projname = Form("SM %d",ism);
637  l5->AddEntry(AverMeanSM[ism],projname.Data(), "p");
638  }
639  l5->Draw("same");
640  lUp->Draw("same");
641  lDown->Draw("same");
642 
643  c5->Update();
644  if(SavePlots) c5->SaveAs(Pi0Mass);
645 
646 
647  TCanvas* c6 = new TCanvas("Pi0Width", "Mean Pi0 Width", 1000, 500);
648  c6->SetFillColor(0);
649  c6->SetBorderSize(0);
650  c6->SetFrameBorderMode(0);
651  c6->SetGrid();
652 
653  gPad->SetLeftMargin(0.08);
654  gPad->SetRightMargin(0.02);
655  gPad->SetGrid();
656 
657  TH1F* h6 = (TH1F*)h1->Clone("");
658  ZoomFromTree(h6,tree,n,"WidthSM");
659  h6->GetXaxis()->SetTitle("RUN Index");
660  h6->GetXaxis()->SetTitleOffset(1.86);
661  h6->GetXaxis()->SetTitleSize(0.03);
662  h6->GetYaxis()->SetTitle("#sigma_{#pi^{0}}");
663  h6->Draw();
664 
665  tree->Draw("NextInt():WidthEMCAL:xe:WidthEMCALErr","","goff");
666  TGraphErrors * AverWidthEMCAL = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
667  AverWidthEMCAL->SetMarkerStyle(20);
668  AverWidthEMCAL->SetMarkerColor(1);
669  AverWidthEMCAL->Draw("same P");
670 
671  if(n>12)
672  {
673  tree->Draw("NextInt():WidthDCAL:xe:WidthDCALErr","","goff");
674  TGraphErrors * AverWidthDCAL = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
675  AverWidthDCAL->SetMarkerStyle(20);
676  AverWidthDCAL->SetMarkerColor(2);
677  AverWidthDCAL->Draw("same P");
678  }
679 
680  for(Int_t ism = 0 ; ism < n ; ism++){
681  tree->Draw(Form("NextInt():WidthSM[%i]:xe:WidthErrSM[%i]",ism,ism),"","goff");
682  AverWidthSM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
683  if (ism !=8)AverWidthSM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverWidthSM[ism]->SetMarkerColor(7);
684  AverWidthSM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10));
685  AverWidthSM[ism]->Draw("same P");
686  }
687 
688 
689  TLegend* l6 = new TLegend(0.123, 0.744, 0.933, 0.894);
690  l6->SetNColumns((n+1)/2.);
691  l6->SetFillColor(0);
692  l6->SetBorderSize(0);
693  l6->SetTextSize(0.04);
694  l6->SetHeader(Form("#sigma_{#pi^{0}} in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data()));
695  l6->AddEntry(AverWidthEMCAL,"total EMCAL", "p");
696  if(n>12) l6->AddEntry(AverWidthDCAL,"total DCAL", "p");
697  for(Int_t ism = 0 ; ism < n ; ism++){
698  TString projname = Form("SM %d",ism);
699  l6->AddEntry(AverWidthSM[ism],projname.Data(), "p");
700  }
701  l6->Draw("same");
702  c6->Update();
703  if(SavePlots) c6->SaveAs(Pi0Width);
704 
705  TCanvas* c7 = new TCanvas("Npi0", "Mean Nb of Pi0", 1000, 500);
706  c7->SetFillColor(0);
707  c7->SetBorderSize(0);
708  c7->SetFrameBorderMode(0);
709  c7->SetGrid();
710 
711  gPad->SetLeftMargin(0.08);
712  gPad->SetRightMargin(0.02);
713  gPad->SetGrid();
714 
715  TH1F* h7 = (TH1F*)h1->Clone("");
716  ZoomFromTree(h7,tree,n,"Npi0SM");
717  if (h7->GetMinimum() > 0.) {c7->SetLogy();}
718  h7->GetXaxis()->SetTitle("RUN Index");
719  h7->GetXaxis()->SetTitleOffset(1.86);
720  h7->GetXaxis()->SetTitleSize(0.03);
721  h7->GetYaxis()->SetTitle("<N_{#pi^{0}}>/event");
722  h7->Draw();
723 
724  tree->Draw("NextInt():Npi0EMCAL:xe:Npi0EMCALErr","","goff");
725  if (tree->GetMinimum("Npi0EMCAL") > 1) c4->SetLogy();
726  TGraphErrors * AverNpi0EMCAL = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
727  AverNpi0EMCAL->SetMarkerStyle(20);
728  AverNpi0EMCAL->SetMarkerColor(1);
729  AverNpi0EMCAL->Draw("same P");
730 
731  if(n>12)
732  {
733  tree->Draw("NextInt():Npi0DCAL:xe:Npi0DCALErr","","goff");
734  if (tree->GetMinimum("Npi0DCAL") > 1) c4->SetLogy();
735  TGraphErrors * AverNpi0DCAL = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
736  AverNpi0DCAL->SetMarkerStyle(20);
737  AverNpi0DCAL->SetMarkerColor(2);
738  AverNpi0DCAL->Draw("same P");
739  }
740 
741  for(Int_t ism = 0 ; ism < n ; ism++){
742  tree->Draw(Form("NextInt():Npi0SM[%i]:xe:Npi0ErrSM[%i]",ism,ism),"","goff");
743  AverNpi0SM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4());
744  if (ism !=8)AverNpi0SM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverNpi0SM[ism]->SetMarkerColor(7);
745  AverNpi0SM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10));
746  AverNpi0SM[ism]->Draw("same P");
747  }
748 
749  TLegend* l7 = new TLegend(0.123, 0.744, 0.933, 0.894);
750  l7->SetNColumns((n+1)/2.);
751  l7->SetFillColor(0);
752  l7->SetBorderSize(0);
753  l7->SetTextSize(0.04);
754  l7->SetHeader(Form("<N_{#pi^{0}}>/event in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data()));
755  l7->AddEntry(AverNpi0EMCAL,"total EMCAL", "p");
756  if(n>12) l7->AddEntry(AverNpi0DCAL,"total DCAL", "p");
757  for(Int_t ism = 0 ; ism < n ; ism++){
758  TString projname = Form("SM %d",ism);
759  l7->AddEntry(AverNpi0SM[ism],projname.Data(), "p");
760  }
761  l7->Draw("same");
762  c7->Update();
763  if(SavePlots) c7->SaveAs(Pi0Entries);
764  if(SavePlots==2) c7->SaveAs(Pi0Entries2);
765 
766  fout->mkdir(Form("%s/%s/%s/%s",period->Data(),pass->Data(),"TrendingQA",fTrigger->Data()));
767  fout->cd();
768  fout->Cd(Form("%s/%s/%s/%s",period->Data(),pass->Data(),"TrendingQA",fTrigger->Data()));
769 
770  gROOT->GetListOfCanvases()->Write();
771  gROOT->GetListOfCanvases()->Delete();
772 
773  if((!Expr.IsNull()) && (!Expr.EndsWith(".root"))) elist->Write();
774  if(listNotZero) {listNotZero->Reset();}
775  if(elist) {elist->Reset();}
776  delete h1;
777 
778  return 0;
779 
780 }
781 
782 //---------------------------------------------------------------------------------------------
783 TH1F* ZoomFromTree(TH1F* h, TTree* atree, Int_t n, const char* aVar, UShort_t aScaleFactor)
784 {
785 
786  atree->SetEventList(0);
787  TEventList *listNotZero = (TEventList*)gDirectory->Get("listNotZero");
788  atree->SetEventList(listNotZero);
789 
790  double treeMin = GetTreeMinimum(atree,n,aVar);
791  double treeMax = GetTreeMaximum(atree,n,aVar);
792  double offset = 30*((treeMax - treeMin)/(100.*aScaleFactor));
793 
794  if(treeMin != -treeMax){
795  h->SetMinimum(TMath::Max(0.,treeMin-offset));
796  h->SetMaximum(treeMax+2*offset);
797  }
798 
799  atree->SetEventList(0);
800  TEventList *elist = (TEventList*)gDirectory->Get("elist");
801  atree->SetEventList(elist);
802 
803  return h;
804 
805 }
806 
807 //--------------------------------------------------------------------------------------------
808 Double_t GetTreeMinimum(TTree* aTree,Int_t n, const char* columname)
809 {
810 
811  TLeaf* leaf = aTree->GetLeaf(columname);
812  if (!leaf) {
813  return 0;
814  }
815  TBranch* branch = leaf->GetBranch();
816  Double_t cmin = 3.40282e+38;
817  for (Long64_t i = 0; i < aTree->GetEntries(); ++i) {
818  Long64_t entryNumber = aTree->GetEntryNumber(i);
819  if (entryNumber < 0) break;
820  branch->GetEntry(entryNumber);
821  for (Int_t j = 0;j < TMath::Min(leaf->GetLen(),n); ++j) {
822  Double_t val = leaf->GetValue(j);
823  if (val < cmin) {
824  cmin = val;
825  }
826  }
827  }
828 
829  return cmin;
830 
831 }
832 
833 //______________________________________________________________________________
834 Double_t GetTreeMaximum(TTree* aTree,Int_t n,const char* columname)
835 {
836 
837  TLeaf* leaf = aTree->GetLeaf(columname);
838  if (!leaf) {
839  return 0;
840  }
841  TBranch* branch = leaf->GetBranch();
842  Double_t cmax = - 3.40282e+38;
843  for (Long64_t i = 0; i < aTree->GetEntries(); ++i) {
844  Long64_t entryNumber = aTree->GetEntryNumber(i);
845  if (entryNumber < 0) break;
846  branch->GetEntry(entryNumber);
847  for (Int_t j = 0; j < TMath::Min(leaf->GetLen(),n); ++j) {
848  Double_t val = leaf->GetValue(j);
849  if (val > cmax) {
850  cmax = val;
851  }
852  }
853  }
854 
855  return cmax;
856 
857 }
858 
const char * filename
Definition: TestFCM.C:1
double Double_t
Definition: External.C:58
long long Long64_t
Definition: External.C:43
TSystem * gSystem
int Int_t
Definition: External.C:63
unsigned short UShort_t
Definition: External.C:28
bool Bool_t
Definition: External.C:53
TFile * fout
input train file