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