AliPhysics  c7b8e89 (c7b8e89)
CreateEMCALRunQA.C
Go to the documentation of this file.
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <Riostream.h>
3 #include "AliEMCALGeometry.h"
4 #include <TColor.h>
5 #include <TStyle.h>
6 #include <TSystem.h>
7 #include <TDirectory.h>
8 #include <TF1.h>
9 #include <TFile.h>
10 #include <TH2.h>
11 #include <TH2D.h>
12 #include <TCanvas.h>
13 #include <TGraphErrors.h>
14 #include <TLegend.h>
15 #include <TTree.h>
16 #include <TPRegexp.h>
17 #include <TList.h>
18 #include <TObjString.h>
19 #include <TDatime.h>
20 #include <TError.h>
21 #include <AliLog.h>
22 #endif
23 
38 
39 Int_t DrawOccupancy(Long_t run, TString period, TString pass, TString fTrigger, TString system, TFile* f, TFile* fout, AliEMCALGeometry* geom, Int_t SavePlots);
40 Int_t DrawRun(Long_t run, TString period, TString pass, TString fTrigger, TFile *f, TFile* fout, Int_t SavePlots, Int_t nSM, Bool_t kFilter);
41 Int_t TrendingEMCALTree(Long_t RunId, TString fCalorimeter, TString system, TString period, TString pass, const int n, TList* TriggersList, TFile* f, TFile *fout, Int_t SavePlots);
42 
43 TH2F* FormatRunHisto(TH2F* aHisto, const char* title, const char* YTitle="");
44 TH2D* FormatRunHisto2D(TH2D* aHisto, const char* title, const char* YTitle="");
45 
46 TH2F* HistoPerMod(TH2F* name, const char* title);
47 TH2* AutoZoom(TH2* H, Option_t* aType="all", Int_t EntryMin=0);
48 int FindNumberOfSM(TFile* f, TString fTrigger, TString period);
49 
52 
53 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
55 
56  const Int_t NRGBs = 5;
57  const Int_t NCont = 255;
58 
59  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
60  Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
61  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
62  Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
63  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
64  gStyle->SetNumberContours(NCont);
65 
66 }
67 
68 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
70 
71  Double_t gaus;
72 
73  if(par[2] != 0.)
74  gaus = par[0] * TMath::Exp( -(x[0]-par[1])*(x[0]-par[1]) / (2*par[2]*par[2]) );
75  else
76  gaus = 99999999.;
77 
78  Double_t back = par[3] + par[4]*x[0] + par[5]*x[0]*x[0];
79 
80  return gaus+back;
81 
82 }
83 
84 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
86 
87  Double_t gaus = par[0] * TMath::Exp( -(x[0]-par[1])*(x[0]-par[1]) / (2*par[2]*par[2]) );
88  Double_t back = par[3] + par[4]*x[0];
89 
90  return gaus+back;
91 
92 }
93 
94 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
96 
97  Double_t levy;
98 
99  levy = par[0] * TMath::Exp( -par[1]/x[0]) * TMath::Power(x[0], -par[2]) ;
100 
101  return levy;
102 
103 }
104 
105 //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
106 int CreateEMCALRunQA(const char* filename, TString RunId, TString period, TString pass, Int_t SavePlots = 0, Bool_t filter=0, TString fTrigger = "", TString system = "", TString fCalorimeter = "EMCAL"){
107 
108  QAPATH = TString(gSystem->Getenv("QAPATH"));
109  if(QAPATH.IsNull())
110  QAPATH = QAPATHF;
111 
112  if(! QAPATH.BeginsWith("./"))
113  QAPATH = QAPATH + RunId + "/";
114 
115  AliLog::SetGlobalLogLevel(AliLog::kError);
116  TFile *f = new TFile(filename);
117  AliLog::SetGlobalLogLevel(AliLog::kInfo);
118 
119  if(f->IsZombie()){
120  Error(__FUNCTION__, Form("Error openning the input file %s", filename));
121  return -1;
122  }
123 
124  TList* TriggersList = new TList();
125 
126  if(fTrigger==""){
127  TPMERegexp name_re("CaloQA_\\w+");
128  TObjLink* link = f->GetListOfKeys()->FirstLink();
129 
130  while(link){
131  TString name = link->GetObject()->GetName();
132  if(name_re.Match(name)){
133  TriggersList->Add(link->GetObject());
134  if(TString(filename).Contains("barrel") && ! name.Contains("default")) TriggersList->Remove(link->GetObject());
135  if(TString(filename).Contains("outer") && ! name.Contains("EMC")) TriggersList->Remove(link->GetObject());
136  }
137  link = link->Next();
138  }
139  }
140  else{
141  TriggersList->Add(new TObjString(fTrigger.Data()));
142  }
143 
144  if(!TriggersList->GetEntries()){
145  Error(__FUNCTION__, "No trigger found!");
146  return -2;
147  }
148 
149  int nSM = FindNumberOfSM(f, ((TObjString*)TriggersList->Last())->GetString(), period);
150 
151  if(nSM<0){
152  Error(__FUNCTION__, "Could not find the number of super modules!");
153  return -3;
154  }
155  Info(__FUNCTION__, Form("%i super modules were discovered", nSM));
156 
157  TString GeomName;
158  if(nSM <= 4) { nSM = 4; GeomName = "EMCAL_FIRSTYEARv1"; }
159  else if(nSM <= 10){ nSM = 10; GeomName = "EMCAL_COMPLETEv1"; }
160  else if(nSM <= 12){ nSM = 12; GeomName = "EMCAL_COMPLETE12SMv1"; }
161  else { nSM = 20; GeomName = "EMCAL_COMPLETE12SMv1_DCAL_8SM";}
162 
163  AliEMCALGeometry *geom = new AliEMCALGeometry(GeomName.Data(), "EMCAL");
164  Info(__FUNCTION__, Form("Using %i super modules and the Geometry %s", nSM, GeomName.Data()));
165 
166  TFile *fout = new TFile(TString( QAPATH + period+"_"+pass + fTrigger+"_"+ (Long_t)RunId.Atoi() +"_QAplots.root").Data(), "RECREATE");
167 
168  if((system.IsNull()) && (period.EndsWith("h")))
169  system = "PbPb";
170 
171  Int_t ret=0;
172  TIter next(TriggersList);
173  while(TObject *obj = next()){
174  fTrigger= TString(obj->GetName());
175  ret -= DrawOccupancy(RunId.Atoi(), period, pass, fTrigger, system, f, fout, geom, SavePlots);
176  ret -= DrawRun(RunId.Atoi(), period, pass, fTrigger, f, fout, SavePlots, nSM, filter);
177  }
178  ret-= TrendingEMCALTree(RunId.Atoi(), fCalorimeter, system, period, pass, nSM, TriggersList, f, fout, SavePlots);
179 
180  f->Close();
181  fout->Close();
182  delete f;
183  delete geom;
184 
185  return ret;
186 }
187 
188 //----------------------------------------------------------------------------------------------------------------------------------------------------------
189 Int_t DrawOccupancy(Long_t run, TString period, TString pass, TString fTrigger, TString system, TFile* f, TFile* fout, AliEMCALGeometry* geom, Int_t SavePlots){
190 
191  set_plot_style();
192  gStyle->SetOptStat(0);
193 
194  TH1::AddDirectory(kFALSE);
195  TH2D *hEnergyMapReal = new TH2D("hEnergyMapReal", "", 96, -48, 48, 120, -0, 120);
196  TH2D *hOccupancyMapReal = new TH2D("hOccupancyMapReal", "", 96, -48, 48, 120, -0, 120);
197 
198  hEnergyMapReal->SetXTitle("#eta (bin)");
199  hEnergyMapReal->SetYTitle("#varphi (bin)");
200  hEnergyMapReal->SetZTitle("E (GeV)/event");
201  hEnergyMapReal->GetYaxis()->SetTitleOffset(1.2);
202  hEnergyMapReal->GetZaxis()->SetLabelSize(0.02);
203  hEnergyMapReal->GetZaxis()->SetTitleOffset(1.36);
204 
205  hOccupancyMapReal->SetXTitle("#eta (bin)");
206  hOccupancyMapReal->SetYTitle("#varphi (bin)");
207  hOccupancyMapReal->GetYaxis()->SetTitleOffset(1.2);
208  hOccupancyMapReal->GetZaxis()->SetLabelSize(0.02);
209 
210  Int_t nSupMod, nModule, nIphi, nIeta;
211  Int_t iphi, ieta;
212  Int_t realbineta=0;
213  Int_t realbinphi=0;
214 
215  // NO MASK
216  Int_t mask[1] = {2222222};
217 
218  TH2F *hCellAmplitude;
219  TH1F *hNEvents;
220  Int_t Events;
221  Int_t n=0;
222 
223  TString direct;
224  if(!fTrigger.Contains("QA")){
225  direct = "CaloQA_";
226  }
227  direct += fTrigger;
228 
229  Bool_t dirok = f->cd(direct);
230  if(!dirok){
231  Error(__FUNCTION__, Form("No input drectory %s", direct.Data()));
232  return -1;
233  }
234 
235  TList *outputList = (TList*)gDirectory->Get(direct);
236  if(!outputList){
237  Error(__FUNCTION__, "No input list! ");
238  return -1;
239  }
240  outputList->SetOwner();
241 
242  fout->mkdir(Form("%s/%s/%ld/%s/%s", period.Data(), pass.Data(), run, "RunLevelQA", fTrigger.Data()));
243  fout->cd();
244  fout->Cd(Form("%s/%s/%ld/%s/%s", period.Data(), pass.Data(), run, "RunLevelQA", fTrigger.Data()));
245 
246  hNEvents = (TH1F *)outputList->FindObject("hNEvents");
247  if(!hNEvents){
248  Error(__FUNCTION__, Form("hNEvent histogram not found for trigger %s ", fTrigger.Data()));
249  return -2;
250  }
251 
252  Events = (Int_t)hNEvents->GetEntries();
253  if(Events==0){
254  Error(__FUNCTION__, Form("No event in trigger %s", fTrigger.Data()));
255  return -3;
256  }
257 
258  TH1F* hE = (TH1F *)outputList->FindObject("EMCAL_hE");
259  if(!hE || (!hE->GetEntries())){
260  Error(__FUNCTION__, Form("hE Histogram not found or it is empty for trigger %s, EMCal was not in this run?", fTrigger.Data()));
261  return -4;
262  }
263 
264  Double_t Eth=1;
265  if(system=="PbPb"){
266  Eth = 5.;
267  if(fTrigger.Contains("EMC"))
268  Eth=20.;
269  }
270  if(system=="pp"){
271  Eth = 1.;
272  if(fTrigger.Contains("EMC"))
273  Eth=5.;
274  }
275 
276  hCellAmplitude = (TH2F *)outputList->FindObject("EMCAL_hAmpId");
277 
278  for(Int_t i = 0; i < geom->GetNCells() ; i++){
279  Double_t Esum = 0;
280  Double_t Nsum = 0;
281 
282  for(Int_t j = 1; j <= hCellAmplitude->GetNbinsX(); j++){
283  Double_t E = hCellAmplitude->GetXaxis()->GetBinCenter(j);
284  Double_t N = hCellAmplitude->GetBinContent(j, i+1);
285 
286  if(E < 0.3)
287  continue;
288 
289  if(E <= Eth){
290  Esum += E*N;
291  Nsum += N;
292  }
293  }
294 
295  Int_t absId = i;
296  if(n!=0){
297  if(mask[n]<=mask[n-1])
298  Warning(__FUNCTION__, "The list of bad cells is not sorted !!");
299  }
300 
301  if(i==mask[n]){
302  n++ ;
303  continue;
304  } // skip bad cells
305 
306  geom->GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
307  geom->GetCellPhiEtaIndexInSModule(nSupMod, nModule, nIphi, nIeta, iphi, ieta);
308 
309  realbinphi = 120-(nSupMod/2)*24 -iphi -1;
310  if(nSupMod%2==0)
311  realbineta= 48-ieta -1;
312  if(nSupMod%2==1)
313  realbineta= -ieta -1;
314 
315  hEnergyMapReal->Fill(realbineta, realbinphi, Esum/(Double_t)Events);
316  // hOccupancyMapReal->Fill(realbineta, realbinphi, Nsum/(Double_t)Events);
317  }
318 
319  cout <<" Run: " << run << " trigger: " << fTrigger << " N_events: "<<Events<<endl;
320 
321  TPMERegexp r("_\\w+");
322  // TString Energy; Energy = QAPATH + "MapEnergy" + fTrigger(r) + ".pdf";
323  // TString Energy2; Energy2 = QAPATH + "MapEnergy" + fTrigger(r) + ".png";
324  // TString Entries; Entries = QAPATH + "MapEntries" + fTrigger(r) + ".pdf";
325  // TString Entries2; Entries2 = QAPATH + "MapEntries" + fTrigger(r) + ".png";
326 
327  // TCanvas *c1 = new TCanvas("Energymap", "Energy Map", 600, 600);
328  // c1->SetFillColor(0);
329  // c1->SetGrid();
330  // c1->SetRightMargin(0.14);
331 
332  // TString title = "run ";
333  // title += run ;
334  // if(fTrigger.Contains("EMC"))
335  // title += " EMC ";
336  // else
337  // title += " MB ";
338  // title += " Summed energy map";
339 
340  // hEnergyMapReal->SetTitle(title);
341  // AutoZoom(hEnergyMapReal, "miny")->DrawCopy("colz");
342 
343  // if(nSupMod<=12){
344  // if(SavePlots==2)
345  // c1->SaveAs(Energy);
346  // if(SavePlots)
347  // c1->SaveAs(Energy2);
348  // c1->Write();
349  // }
350  // delete c1;
351 
352  // TCanvas *c2 = new TCanvas("Occupancy", "Occupancy Map", 600, 600);
353  // c2->SetFillColor(0);
354  // c2->SetGrid();
355  // c2->SetRightMargin(0.14);
356  // TString title2 = "run ";
357  // title2 += run ;
358  // if(fTrigger.Contains("EMC")){ title2 += " EMC ";} else{ title2 += " MB ";}
359  // title2 += " Occupancy map";
360  // hOccupancyMapReal->SetTitle(title2);
361  // AutoZoom(hOccupancyMapReal, "miny")->DrawCopy("colz");
362  // if(SavePlots==2) c2->SaveAs(Entries);
363  // if(SavePlots) c2->SaveAs(Entries2);
364  // c2->Write();
365  // delete c2;
366 
367  if(outputList)
368  outputList->Delete();
369  delete hEnergyMapReal;
370  delete hOccupancyMapReal;
371 
372  return 0;
373 }
374 
375 //-----------------------------------------------------------------------------------------------------------------------
376 Int_t DrawRun(const Long_t run, TString period, TString pass, TString fTrigger, TFile *f, TFile *fout, Int_t SavePlots, Int_t nSM, Bool_t kFilter){
377 
378  TString direct;
379  if(!fTrigger.Contains("QA")){
380  direct = "CaloQA_";
381  }
382  direct += fTrigger;
383 
384  f->cd(direct);
385  if(!direct){
386  Error(__FUNCTION__, Form("No input directory %s", direct.Data()));
387  return -1;
388  }
389 
390  TList *outputList = (TList*)gDirectory->Get(direct);
391  if(!outputList){
392  Error(__FUNCTION__, Form("No input list! %s", direct.Data()));
393  return -2;
394  }
395  outputList->SetOwner();
396 
397  if(kFilter){
398  fout->mkdir(Form("%s/%s/%ld/%s", period.Data(), pass.Data(), run, fTrigger.Data()));
399  fout->cd();
400  fout->Cd(Form("%s/%s/%ld/%s", period.Data(), pass.Data(), run, fTrigger.Data()));
401  outputList->Write();
402  }
403  fout->cd();
404  fout->Cd(Form("%s/%s/%ld/%s/%s", period.Data(), pass.Data(), run, "RunLevelQA", fTrigger.Data()));
405 
406  set_plot_style();
407  gStyle->SetPalette(1);
408  set_plot_style();
409  // gStyle->SetOptStat(1);
410 
411  TH1::AddDirectory(kFALSE);
412 
413 
414  TString mupass ="muon_calo";
415 
416  TString outfilename;
417  TString outfilename2;
418  const char* legend="";
419  TPMERegexp r("_\\w+");
420 
421  if(fTrigger.Contains("EMC"))
422  legend = Form(" Run %d EMC ", (int)run);
423  else
424  legend = Form(" Run %d MB ", (int)run);
425 
426  TH1F* hNEvents =(TH1F *)outputList->FindObject("hNEvents");
427  if(!hNEvents){
428  Error(__FUNCTION__, Form("hNEvent histogram not found for trigger %s ", fTrigger.Data()));
429  return -3;
430  }
431 
432  Int_t Events = (Int_t)hNEvents->GetEntries();
433  if(Events==0){
434  Error(__FUNCTION__, Form("No event in trigger %s", fTrigger.Data()));
435  return -4 ;
436  }
437 
438  TH1F* hE =(TH1F *)outputList->FindObject("EMCAL_hE");
439  if(!hE || (!hE->GetEntries())){
440  Error(__FUNCTION__, Form("hE Histogram not found or it is empty for trigger %s, EMCal was not in this run?", fTrigger.Data()));
441  return -4;
442  }
443 
444  TCanvas* c00 = new TCanvas("Occupancy map", "Occupancy", 600, 600);
445  c00->SetLogz();
446  c00->SetFillColor(0);
447  c00->SetBorderSize(0);
448  c00->SetFrameBorderMode(0);
449 
450  TH2F* hOccupancyMapReal =(TH2F *)outputList->FindObject("EMCAL_hEtaPhi");
451  if(!hOccupancyMapReal){
452  Error(__FUNCTION__, Form("EMCAL_hEtaPhi: Histogram for trigger %s not found!", fTrigger.Data()));
453  return -5;
454  }
455  FormatRunHisto(hOccupancyMapReal, Form("Occupancy%s", legend), "#varphi (bin)");
456  hOccupancyMapReal->SetXTitle("#eta (bin)");
457 
458  AutoZoom(hOccupancyMapReal, "all")->DrawCopy("colz");
459  outfilename = QAPATH + "OccupancyMap" + fTrigger(r) + ".pdf" ;
460  outfilename2 = QAPATH + "OccupancyMap" + fTrigger(r) + ".png" ;
461 
462  if(SavePlots==2)
463  c00->SaveAs(outfilename);
464  if(SavePlots)
465  c00->SaveAs(outfilename2);
466  c00->Write();
467  delete c00;
468 
469  TCanvas* c0 = new TCanvas("Grid Cell", "Occupancy from Grid Cells", 600, 600);
470  c0->SetLogz();
471  c0->SetFillColor(0);
472  c0->SetBorderSize(0);
473  c0->SetFrameBorderMode(0);
474 
475  TH2F* hGridCells =(TH2F *)outputList->FindObject("EMCAL_hGridCells");
476  if(!hGridCells){
477  Error(__FUNCTION__, Form("EMCAL_hGridCells: Histogram for trigger %s not found!", fTrigger.Data()));
478  return -5;
479  }
480  FormatRunHisto(hGridCells, Form("Occupancy from Grid Cells%s", legend), "#varphi row columns");
481  hGridCells->SetXTitle("#eta row columns");
482  AutoZoom(hGridCells, "all")->DrawCopy("colz");
483 
484  outfilename = QAPATH + "GridCells" + fTrigger(r) + ".pdf" ;
485  outfilename2 = QAPATH + "GridCells" + fTrigger(r) + ".png" ;
486 
487  if(SavePlots==2)
488  c0->SaveAs(outfilename);
489  if(SavePlots)
490  c0->SaveAs(outfilename2);
491  c0->Write();
492  delete c0;
493 
494  TCanvas* c1 = new TCanvas("TimeVsE", "Cluster Time vs. Energy", 600, 600);
495  c1->SetLogz();
496  c1->SetFillColor(0);
497  c1->SetBorderSize(0);
498  c1->SetFrameBorderMode(0);
499 
500  TH2F* hClusterTimeEnergy =(TH2F *)outputList->FindObject("EMCAL_hClusterTimeEnergy");
501  if(!hClusterTimeEnergy){
502  Error(__FUNCTION__, Form("EMCAL_hClusterTimeEnergy: Histogram for trigger %s not found!", fTrigger.Data()));
503  return -5;
504  }
505  FormatRunHisto(hClusterTimeEnergy, Form("Time vs. Energy%s", legend), "EMCal ToF (ns)");
506  AutoZoom(hClusterTimeEnergy, "maxx")->DrawCopy("colz");
507 
508  outfilename = QAPATH + "TimeRun" + fTrigger(r) + ".pdf" ;
509  outfilename2 = QAPATH + "TimeRun" + fTrigger(r) + ".png" ;
510 
511  if(SavePlots==2)
512  c1->SaveAs(outfilename);
513  if(SavePlots)
514  c1->SaveAs(outfilename2);
515  c1->Write();
516  delete c1;
517 
518  if((pass!="simu")||(pass!="passMC")){
519  TCanvas* c1a = new TCanvas("TimeVsAbsId", "Cell Id vs. time ", 600, 600);
520  c1a->SetLogz();
521  c1a->SetFillColor(0);
522  c1a->SetBorderSize(0);
523  c1a->SetFrameBorderMode(0);
524 
525  TH2F* hTimeAbsId =(TH2F *)outputList->FindObject("EMCAL_hTimeId");
526  if(!hTimeAbsId){
527  Error(__FUNCTION__, Form("EMCAL_hTimeId: Histogram for trigger %s not found!", fTrigger.Data()));
528  return -5;
529  }
530  FormatRunHisto(hTimeAbsId, Form("Cell ID vs. Time%s", legend), "Cell AbsID");
531  hTimeAbsId->RebinY(16);
532  hTimeAbsId->SetMinimum(32);
533  AutoZoom(hTimeAbsId, "maxx")->DrawCopy("colz");
534 
535  outfilename = QAPATH + "TimeAbsIdRun" + fTrigger(r) + ".pdf" ;
536  outfilename2 = QAPATH + "TimeAbsRun" + fTrigger(r) + ".png" ;
537 
538  if(SavePlots==2)
539  c1a->SaveAs(outfilename);
540  if(SavePlots)
541  c1a->SaveAs(outfilename2);
542  c1a->Write();
543  delete c1a;
544  }
545 
546  // TCanvas* c1aLG = new TCanvas("TimeVsAbsIdLG", "Cell Id vs. time LG ", 600, 600);
547  // c1aLG->SetLogz();
548  // c1aLG->SetFillColor(0);
549  // c1aLG->SetBorderSize(0);
550  // c1aLG->SetFrameBorderMode(0);
551 
552  // TH2F* hTimeAbsIdLG =(TH2F *)outputList->FindObject("EMCAL_hTimeIdLG");
553  // if(!hTimeAbsIdLG){
554  // Error(__FUNCTION__, Form("EMCAL_hTimeIdLG: Histogram for trigger %s not found!", fTrigger.Data()));
555  // return -5;
556  // }
557  // FormatRunHisto(hTimeAbsIdLG, Form("Cell ID vs. Time LG%s", legend), "cell AbsID");
558 
559  // AutoZoom(hTimeAbsIdLG, "maxx")->DrawCopy("colz");
560  // outfilename = QAPATH + "TimeAbsIdRunLG" + fTrigger(r) + ".pdf" ;
561  // outfilename2 = QAPATH + "TimeAbsRunLG" + fTrigger(r) + ".png" ;
562 
563  // if(SavePlots==2) c1a->SaveAs(outfilename);
564  // if(SavePlots) c1a->SaveAs(outfilename2);
565  // c1a->Write();
566  // delete c1a;
567 
568  TCanvas* c1b = new TCanvas("EVsAbsId", "Cell Id vs. Energy", 600, 600);
569  c1b->SetLogz();
570  c1b->SetFillColor(0);
571  c1b->SetBorderSize(0);
572  c1b->SetFrameBorderMode(0);
573 
574  TH2F* hEAbsId =(TH2F *)outputList->FindObject("EMCAL_hAmpId");
575  if(!hEAbsId){
576  Error(__FUNCTION__, Form("EMCAL_hAmpId: Histogram for trigger %s not found!", fTrigger.Data()));
577  return -5;
578  }
579  FormatRunHisto(hEAbsId, Form("Cell ID vs. Energy%s", legend), "Cell AbsID");
580  hEAbsId->RebinY(16);
581  hEAbsId->SetMinimum(32);
582  AutoZoom(hEAbsId, "maxx")->DrawCopy("colz");
583 
584  outfilename = QAPATH + "EAbsIdRun" + fTrigger(r) + ".pdf" ;
585  outfilename2 = QAPATH + "EAbsIdRun" + fTrigger(r) + ".png" ;
586 
587  if(SavePlots==2)
588  c1b->SaveAs(outfilename);
589  if(SavePlots)
590  c1b->SaveAs(outfilename2);
591  c1b->Write();
592  delete c1b;
593 
594  // TCanvas* c1bLG = new TCanvas("EVsAbsIdLG", "Cell Id vs. E LG", 600, 600);
595  // c1bLG->SetLogz();
596  // c1bLG->SetFillColor(0);
597  // c1bLG->SetBorderSize(0);
598  // c1bLG->SetFrameBorderMode(0);
599 
600  // TH2F* hEAbsIdLG =(TH2F *)outputList->FindObject("EMCAL_hAmpIdLG");
601  // if(!hEAbsIdLG){
602  // Error(__FUNCTION__, Form("EMCAL_hAmpIdLG: Histogram for trigger %s not found!", fTrigger.Data()));
603  // return -5;
604  // }
605  // FormatRunHisto(hEAbsIdLG, Form("Cell ID vs. Energy%s", legend), "Cell AbsID ");
606 
607  // AutoZoom(hEAbsIdLG, "maxx")->DrawCopy("colz");
608  // outfilename = QAPATH + "EAbsIdRunLG" + fTrigger(r) + ".pdf" ;
609  // outfilename2 = QAPATH + "EAbsIdRunLG" + fTrigger(r) + ".png" ;
610 
611  // if(SavePlots==2) c1bLG->SaveAs(outfilename);
612  // if(SavePlots) c1bLG->SaveAs(outfilename2);
613  // c1bLG->Write();
614  // delete c1bLG;
615 
616  if (!(pass.Contains("muon_calo"))){
617  // if(pass!="muon_calo_pass1"){
618  TCanvas * c2 = new TCanvas("ClusterVsTrack ", "Correlation calo Mult vs. Track Multiplicity", 600, 600);
619  c2->SetLogz();
620  c2->SetFillColor(0);
621  c2->SetBorderSize(0);
622  c2->SetFrameBorderMode(0);
623 
624  TH2F* hClusterVsTrack =(TH2F *)outputList->FindObject("EMCAL_hCaloTrackMNClusters");
625  FormatRunHisto(hClusterVsTrack, Form("#it{N} clusters vs. #it{N} tracks%s", legend), "#it{N} clusters");
626  AutoZoom(hClusterVsTrack, "maxx, maxy", 1)->DrawCopy("colz");
627 
628  outfilename = QAPATH + "CaloTrackMult" + fTrigger(r) + ".pdf";
629  outfilename2 = QAPATH + "CaloTrackMult" + fTrigger(r) + ".png";
630 
631  // if(pass!="muon_calo_pass1"){
632  if(SavePlots==2)
633  c2->SaveAs(outfilename);
634  if(SavePlots)
635  c2->SaveAs(outfilename2);
636  c2->Write();
637  delete c2;
638 
639  TCanvas* c3 = new TCanvas("ClusterEVsTrack ", "Correlation #it{E} calo vs. Track Multiplicity", 600, 600);
640  c3->SetLogz();
641  c3->SetFillColor(0);
642  c3->SetBorderSize(0);
643  c3->SetFrameBorderMode(0);
644 
645  TH2F* hClusterEVsTrack =(TH2F*)outputList->FindObject("EMCAL_hCaloTrackMEClusters");
646  FormatRunHisto(hClusterEVsTrack, Form("Sum #it{E} clusters vs. #it{N} tracks%s", legend), "#Sigma#it{E} clusters");
647  AutoZoom(hClusterEVsTrack, "maxx, maxy", 1)->DrawCopy("colz");
648 
649  outfilename = QAPATH + "ETrackMult" + fTrigger(r) + ".pdf";
650  outfilename2 = QAPATH + "ETrackMult" + fTrigger(r) + ".png";
651 
652  // if(pass!="muon_calo_pass1"){
653  if(SavePlots==2)
654  c3->SaveAs(outfilename);
655  if(SavePlots)
656  c3->SaveAs(outfilename2);
657  c3->Write();
658  // }
659  delete c3;
660  }
661 
662  TCanvas* c4 = new TCanvas("ClusterEVsV0 ", "Correlation #it{E} calo vs. V0 signal", 600, 600);
663  c4->SetLogz();
664  c4->SetFillColor(0);
665  c4->SetBorderSize(0);
666  c4->SetFrameBorderMode(0);
667 
668  TH2F* hClusterEVsV0S =(TH2F*)outputList->FindObject("EMCAL_hCaloV0SEClusters");
669  FormatRunHisto(hClusterEVsV0S, Form("Sum #it{E} clusters vs. V0 signal%s", legend), "#Sigma#it{E} clusters");
670  AutoZoom(hClusterEVsV0S, "maxx, maxy", 1)->DrawCopy("colz");
671 
672  outfilename = QAPATH +"EVsV0s" + fTrigger(r) + ".pdf";
673  outfilename2 = QAPATH +"EVsV0s" + fTrigger(r) + ".png";
674 
675  if(SavePlots==2)
676  c4->SaveAs(outfilename);
677  if(SavePlots)
678  c4->SaveAs(outfilename2);
679  c4->Write();
680  delete c4;
681 
682  TCanvas* c6 = new TCanvas("SumCellEvsSM", "sum cell energy vs. SM", 600, 600);
683  c6->SetLogz();
684  c6->SetFillColor(0);
685  c6->SetBorderSize(0);
686  c6->SetFrameBorderMode(0);
687 
688  TH2F* hSumCellEVsSM =(TH2F*)outputList->FindObject("EMCAL_hSumCellsAmp_Mod");
689  FormatRunHisto(hSumCellEVsSM, Form("Sum #it{E} cells vs. SM%s", legend), "SM number");
690  AutoZoom(hSumCellEVsSM, "maxx, maxy", 1)->DrawCopy("colz");
691 
692  outfilename = QAPATH +"SumCellEVsSM" + fTrigger(r) + ".pdf";
693  outfilename2 = QAPATH +"SumCellEVsSM" + fTrigger(r) + ".png";
694 
695  if(SavePlots==2)
696  c6->SaveAs(outfilename);
697  if(SavePlots)
698  c6->SaveAs(outfilename2);
699  c6->Write();
700  delete c6;
701 
702  TCanvas* c5 = new TCanvas("CellsperCluster", "Nb of cells per cluster for each SM", 600, 600);
703  c5->SetLogz();
704  c5->SetFillColor(0);
705  c5->SetBorderSize(0);
706  c5->SetFrameBorderMode(0);
707 
708  Bool_t mod3=0;
709  if(nSM%3)
710  mod3=1;
711  c5->Divide(3, (nSM/3)+mod3);
712 
713  for(int ism = 0; ism < nSM; ism++){
714  c5->cd(ism+1);
715  gPad->SetLogz();
716 
717  if(TString(Form("Nb cells per clus%s Mod %d", legend, ism)).Length() > 60){
718  Error(__FUNCTION__, "Title too long!");
719  return -6;
720  }
721 
722  AutoZoom(HistoPerMod((TH2F*)outputList->FindObject(Form("EMCAL_hNCellsPerCluster_Mod%i", ism)), Form("Nb of cells per cluster%s Mod %d", legend, ism)), "all", 1)->DrawCopy("colz");
723  }
724 
725  outfilename = QAPATH + "CellsperClusterSM" + fTrigger(r) + ".pdf";
726  outfilename2 = QAPATH + "CellsperClusterSM" + fTrigger(r) + ".png";
727 
728  if(SavePlots==2)
729  c5->SaveAs(outfilename);
730  if(SavePlots)
731  c5->SaveAs(outfilename2);
732  c5->Write();
733  delete c5;
734  if(outputList)
735  outputList->Delete();
736 
737  return 0;
738 }
739 
740 //----------------------------------------------------------------------------------------------------------------------------------
741 Int_t TrendingEMCALTree(Long_t RunId, TString fCalorimeter, TString system, TString period, TString pass, int n, TList* TriggersList, TFile* f, TFile *fout, Int_t SavePlots){
742 
743  TString fTrigger="";
744  TString aCalorimeter;
745  if(n<=12)
746  aCalorimeter = fCalorimeter;
747  else
748  aCalorimeter = TString("EMCAL_and_DCAL");
749 
750  TDatime now;
751 
752 
753 
754  Double_t Nevent=0 ;
755  Double_t NeventEGA1=0 ;
756  Double_t NeventEGA2=0 ;
757  Double_t NeventDGA1=0 ;
758  Double_t NeventDGA2=0 ;
759  Double_t NeventEJE1=0 ;
760  Double_t NeventEJE2=0 ;
761  Double_t NeventDJE1=0 ;
762  Double_t NeventDJE2=0 ;
763  Double_t xe=0.5;
764  Double_t NTClusters=0; // total number of clusters
765  Double_t NTClustersRMS=0;
766  Double_t NCClusters=0; // number of charged clusters
767  Double_t NCClustersRMS=0;
768  Double_t NMatchClustersP=0;
769  Double_t NMatchClustersPRMS=0;
770 
771  Double_t CellMean=0;
772  Double_t CellRMS=0;
773  Double_t ClusterMean=0;
774  Double_t ClusterRMS=0;
775  Double_t EtotalMean=0;
776  Double_t EtotalRMS=0;
777 
778  Double_t CellPerClusterMean=0;
779  Double_t CellPerClusterRMS=0;
780 
781  Double_t mPDG = 134.9766;
782  Double_t Npi0EMCAL=0;
783  Double_t Npi0EMCALErr=0;
784  Double_t MeanPosEMCAL=0;
785  Double_t MeanPosEMCALErr=0;
786  Double_t WidthEMCAL=0;
787  Double_t WidthEMCALErr=0;
788  Double_t Chi2NdfPi0EMCAL=0;
789  Double_t NggEMCAL=0;
790  Double_t NggEMCALErr=0;
791  Double_t SignifEMCAL=0; // !S/(S+B)
792  Double_t SignifEMCALErr=0; // !S/(S+B)
793 
794  Double_t Npi0DCAL=0;
795  Double_t Npi0DCALErr=0;
796  Double_t MeanPosDCAL=0;
797  Double_t MeanPosDCALErr=0;
798  Double_t WidthDCAL=0;
799  Double_t WidthDCALErr=0;
800  Double_t Chi2NdfPi0DCAL=0;
801  Double_t NggDCAL=0;
802  Double_t NggDCALErr=0;
803  Double_t SignifDCAL=0; // !S/(S+B)
804  Double_t SignifDCALErr=0; // !S/(S+B)
805 
806  TFile* ftree = new TFile(Form("%s/trending.root", QAPATH.Data()), "RECREATE");
807 
808  TTree *tree = new TTree("trending", "Trending QA Tree");
809  tree->Branch("fDate", &now);
810  tree->Branch("fCalorimeter", &aCalorimeter);
811  tree->Branch("system", &system);
812  tree->Branch("period", &period);
813  tree->Branch("pass", &pass);
814  tree->Branch("fTrigger", &fTrigger);
815  tree->Branch("run", &RunId, "run/I");
816  tree->Branch("xe", &xe, "xe/D");
817 
818  tree->Branch("Nevent", &Nevent, "Nevent/D");
819  tree->Branch("NeventEGA1", &NeventEGA1, "NeventEGA1/D");
820  tree->Branch("NeventEGA2", &NeventEGA2, "NeventEGA2/D");
821  tree->Branch("NeventDGA1", &NeventDGA1, "NeventDGA1/D");
822  tree->Branch("NeventDGA2", &NeventDGA2, "NeventDGA2/D");
823  tree->Branch("NeventEJE1", &NeventEJE1, "NeventEJE1/D");
824  tree->Branch("NeventEJE2", &NeventEJE2, "NeventEJE2/D");
825  tree->Branch("NeventDJE1", &NeventDJE1, "NeventDJE1/D");
826  tree->Branch("NeventDJE2", &NeventDJE2, "NeventDJE2/D");
827  tree->Branch("NMatchClustersP", &NMatchClustersP, "NMatchClustersP/D");
828  tree->Branch("NMatchClustersPRMS", &NMatchClustersPRMS, "NMatchClustersPRMS/D");
829  tree->Branch("CellMean", &CellMean, "CellMean/D");
830  tree->Branch("CellRMS", &CellRMS, "CellRMS/D");
831  tree->Branch("ClusterMean", &ClusterMean, "ClusterMean/D");
832  tree->Branch("ClusterRMS", &ClusterRMS, "ClusterRMS/D");
833  tree->Branch("EtotalMean", &EtotalMean, "EtotalMean/D");
834  tree->Branch("EtotalRMS", &EtotalRMS, "EtotalRMS/D");
835 
836  tree->Branch("CellPerClusterMean", &CellPerClusterMean, "CellPerClusterMean/D");
837  tree->Branch("CellPerClusterRMS", &CellPerClusterRMS, "CellPerClusterRMS/D");
838 
839  tree->Branch("Npi0EMCAL", &Npi0EMCAL, "Npi0EMCAL/D");
840  tree->Branch("Npi0EMCALErr", &Npi0EMCALErr, "Npi0EMCALErr/D");
841  tree->Branch("Npi0DCAL", &Npi0DCAL, "Npi0DCAL/D");
842  tree->Branch("Npi0DCALErr", &Npi0DCALErr, "Npi0DCALErr/D");
843  tree->Branch("MeanPosEMCAL", &MeanPosEMCAL, "MeanPosEMCAL/D");
844  tree->Branch("MeanPosEMCALErr", &MeanPosEMCALErr, "MeanPosEMCALErr/D");
845  tree->Branch("MeanPosDCAL", &MeanPosDCAL, "MeanPosDCAL/D");
846  tree->Branch("MeanPosDCALErr", &MeanPosDCALErr, "MeanPosDCALErr/D");
847  tree->Branch("WidthEMCAL", &WidthEMCAL, "WidthEMCAL/D");
848  tree->Branch("WidthEMCALErr", &WidthEMCALErr, "WidthEMCALErr/D");
849  tree->Branch("WidthDCAL", &WidthDCAL, "WidthDCAL/D");
850  tree->Branch("WidthDCALErr", &WidthDCALErr, "WidthDCALErr/D");
851  tree->Branch("Chi2NdfPi0EMCAL", &Chi2NdfPi0EMCAL, "Chi2NdfPi0EMCAL/D");
852  tree->Branch("Chi2NdfPi0DCAL", &Chi2NdfPi0DCAL, "Chi2NdfPi0DCAL/D");
853  tree->Branch("NggEMCAL", &NggEMCAL, "NggEMCAL/D");
854  tree->Branch("NggEMCALErr", &NggEMCALErr, "NggEMCALErr/D");
855  tree->Branch("NggDCAL", &NggDCAL, "NggDCAL/D");
856  tree->Branch("NggDCALErr", &NggDCALErr, "NggDCALErr/D");
857  tree->Branch("SignifEMCAL", &SignifEMCAL, "SignifEMCAL/D");
858  tree->Branch("SignifDCALErr", &SignifDCALErr, "SignifDCALErr/D");
859  tree->Branch("SignifEMCAL", &SignifEMCAL, "SignifEMCAL/D");
860  tree->Branch("SignifDCALErr", &SignifDCALErr, "SignifDCALErr/D");
861 
862  tree->Branch("nSM", &n, "nSM/I");
863 
864  int nMax = 22;
865  Double_t CellMeanSM[nMax];
866  Double_t CellRMSSM[nMax];
867  Double_t ClusterMeanSM[nMax];
868  Double_t ClusterTotSM[nMax];
869  Double_t ClusterRMSSM[nMax];
870  Double_t EtotalMeanSM[nMax]; // mean total energy deposited per event
871  Double_t EtotalRMSSM[nMax];
872  Double_t CellPerClusterMeanSM[nMax];
873  Double_t CellPerClusterRMSSM[nMax];
874  Double_t ECell1MeanSM[nMax]; // total energy deposited per event without 1-cell clusters
875  Double_t ECell1RMSSM[nMax];
876 
877  Double_t MeanPosSM[nMax];
878  Double_t MeanPosErrSM[nMax];
879  Double_t WidthSM[nMax];
880  Double_t WidthErrSM[nMax];
881  Double_t Npi0SM[nMax];
882  Double_t Npi0ErrSM[nMax];
883 
884  Int_t nTRIG=6;
885  Double_t ETrigMax[nTRIG];
886  Double_t DTrigMax[nTRIG];
887 
888 
889 
890 
891  tree->Branch("CellMeanSM", CellMeanSM, TString::Format("CellMeanSM[%i]/D", nMax));
892  tree->Branch("CellRMSSM", CellRMSSM, TString::Format("CellRMSSM[%i]/D", nMax));
893  tree->Branch("ClusterMeanSM", ClusterMeanSM, TString::Format("ClusterMeanSM[%i]/D", nMax));
894  tree->Branch("ClusterTotSM", ClusterTotSM, TString::Format("ClusterTotSM[%i]/D", nMax));
895  tree->Branch("ClusterRMSSM", ClusterRMSSM, TString::Format("ClusterRMSSM[%i]/D", nMax));
896  tree->Branch("EtotalMeanSM", EtotalMeanSM, TString::Format("EtotalMeanSM[%i]/D", nMax));
897  tree->Branch("EtotalRMSSM", EtotalRMSSM, TString::Format("EtotalRMSSM[%i]/D", nMax));
898  tree->Branch("CellPerClusterMeanSM", CellPerClusterMeanSM, TString::Format("CellPerClusterMeanSM[%i]/D", nMax));
899  tree->Branch("CellPerClusterRMSSM", CellPerClusterRMSSM, TString::Format("CellPerClusterRMSSM[%i]/D", nMax));
900  tree->Branch("ECell1MeanSM", ECell1MeanSM, TString::Format("ECell1MeanSM[%i]/D", nMax));
901  tree->Branch("ECell1RMSSM", ECell1RMSSM, TString::Format("ECell1RMSSM[%i]/D", nMax));
902 
903  tree->Branch("MeanPosSM", MeanPosSM, TString::Format("MeanPosSM[%i]/D", nMax));
904  tree->Branch("MeanPosErrSM", MeanPosErrSM, TString::Format("MeanPosErrSM[%i]/D", nMax));
905  tree->Branch("WidthSM", WidthSM, TString::Format("WidthSM[%i]/D", nMax));
906  tree->Branch("WidthErrSM", WidthErrSM, TString::Format("WidthErrSM[%i]/D", nMax));
907  tree->Branch("Npi0SM", Npi0SM, TString::Format("Npi0SM[%i]/D", nMax));
908  tree->Branch("Npi0ErrSM", Npi0ErrSM, TString::Format("Npi0ErrSM[%i]/D", nMax));
909  tree->Branch("ETrigMax", ETrigMax, TString::Format("EtrigMax[%i]/D", nTRIG));
910  tree->Branch("DTrigMax", DTrigMax, TString::Format("DtrigMax[%i]/D", nTRIG));
911 
912 
913  TF1* fitMass = new TF1("fitMass", pi0massP2, 100, 250, 6);
914  fitMass->SetParName(0, "A");
915  fitMass->SetParName(1, "m_{0}");
916  fitMass->SetParName(2, "sigma");
917  fitMass->SetParName(3, "a_{0}");
918  fitMass->SetParName(4, "a_{1}");
919  fitMass->SetParName(5, "a_{2}");
920  fitMass->SetParLimits(0, 1.e-5, 1.e5);
921  fitMass->SetParLimits(1, 0.11, 0.16);
922  fitMass->SetParLimits(2, 0.001, 0.06);
923 
924  TList* outputList;
925 
926  TH1F* fhNEvents;
927  TH1F* fhE;
928  TH1F* fhNClusters = 0x0;
929  TH1F* fhECharged;
930  TH1F* fhNCells = 0x0;
931 
932  TH1F* NCells[n];
933  TH1F* NClusters[n];
934  TH2F* NCellsPerCluster[n];
935  TH1F* E[n];
936  TH1D* hEGA2;
937  TH1D* hEGA1;
938  TH1D* hEJE2;
939  TH1D* hEJE1;
940  TH1D* hEMC7;
941  TH1D* hDGA2;
942  TH1D* hDGA1;
943  TH1D* hDJE1;
944  TH1D* hDJE2;
945  TH1D* hDMC7;
946 
947 
948  TH2D* hEGA2Map;
949  TH2D* hEGA1Map;
950  TH2D* hEJE2Map;
951  TH2D* hEJE1Map;
952  TH2D* hEMC7Map;
953  TH2D* hDGA2Map;
954  TH2D* hDGA1Map;
955  TH2D* hDJE1Map;
956  TH2D* hDJE2Map;
957  TH2D* hDMC7Map;
958 
959 
960 
961  TH2F* fhIM;
962  TH2F* fhIMDCAL;
963  TH1F* fhMggEMCAL;
964  TH1F* fhMggDCAL;
965  TH2F* IM[n];
966  TH1F* MggSM[n];
967 
968  TPMERegexp r("_\\w+");
969  TIter next(TriggersList);
970  int ret = 0;
971 
972  while(TObject *obj = next()){
973  fTrigger= TString(obj->GetName());
974  TString namefile = QAPATH + period + "_" + pass + fTrigger(r).Data() + "_" + RunId + "_data.txt";
975  ofstream QAData(namefile, ios::app); // write checks at the end
976 
977  NTClusters=0;
978  NTClustersRMS=0;
979  NCClusters=0;
980  NCClustersRMS=0;
981  NMatchClustersP=0;
982  NMatchClustersPRMS=0;
983  CellMean=0;
984  CellRMS=0;
985  ClusterMean=0;
986  ClusterRMS=0;
987  EtotalMean=0;
988  EtotalRMS=0;
989  CellPerClusterMean=0;
990  CellPerClusterRMS=0;
991 
992  // EMCal
993  Npi0EMCAL=0;
994  Npi0EMCALErr=0;
995  MeanPosEMCAL=0;
996  MeanPosEMCALErr=0;
997  WidthEMCAL=0;
998  WidthEMCALErr=0;
999  Chi2NdfPi0EMCAL=0;
1000  NggEMCAL=0;
1001  NggEMCALErr=0;
1002  SignifEMCAL=0;
1003  SignifEMCALErr=0;
1004 
1005  // DCal
1006  Npi0DCAL=0;
1007  Npi0DCALErr=0;
1008  MeanPosDCAL=0;
1009  MeanPosDCALErr=0;
1010  WidthDCAL=0;
1011  WidthDCALErr=0;
1012  Chi2NdfPi0DCAL=0;
1013  NggDCAL=0;
1014  NggDCALErr=0;
1015  SignifDCAL=0;
1016  SignifDCALErr=0;
1017 
1018  memset (CellMeanSM, 0, sizeof (Double_t) * nMax);
1019  memset (CellRMSSM, 0, sizeof (Double_t) * nMax);
1020  memset (ClusterMeanSM, 0, sizeof (Double_t) * nMax);
1021  memset (ClusterTotSM, 0, sizeof (Double_t) * nMax);
1022  memset (ClusterRMSSM, 0, sizeof (Double_t) * nMax);
1023  memset (EtotalMeanSM, 0, sizeof (Double_t) * nMax);
1024  memset (EtotalRMSSM, 0, sizeof (Double_t) * nMax);
1025  memset (CellPerClusterMeanSM, 0, sizeof (Double_t) * nMax);
1026  memset (CellPerClusterRMSSM, 0, sizeof (Double_t) * nMax);
1027  memset (ECell1MeanSM, 0, sizeof (Double_t) * nMax);
1028  memset (ECell1RMSSM, 0, sizeof (Double_t) * nMax);
1029 
1030  memset (MeanPosSM, 0, sizeof (Double_t) * nMax);
1031  memset (MeanPosErrSM, 0, sizeof (Double_t) * nMax);
1032  memset (WidthSM, 0, sizeof (Double_t) * nMax);
1033  memset (WidthErrSM, 0, sizeof (Double_t) * nMax);
1034  memset (Npi0SM, 0, sizeof (Double_t) * nMax);
1035  memset (Npi0ErrSM, 0, sizeof (Double_t) * nMax);
1036  memset (ETrigMax, 0, sizeof (Double_t) * nTRIG);
1037  memset (DTrigMax, 0, sizeof (Double_t) * nTRIG);
1038 
1039  TString dirname;
1040  if(!fTrigger.Contains("QA")){
1041  dirname = "CaloQA_";
1042  }
1043  dirname += fTrigger;
1044 
1045  Bool_t dirok = f->cd(dirname);
1046  if(!dirok){
1047  Error(__FUNCTION__, Form("No input directory %s", dirname.Data()));
1048  tree->Fill(); ftree->cd();
1049  tree->Write();
1050  ret= -1;
1051  continue;
1052  }
1053 
1054  outputList = (TList*)gDirectory->Get(dirname);
1055  if(!outputList){
1056  Error(__FUNCTION__, Form("No input list! %s", dirname.Data()));
1057  tree->Fill(); ftree->cd();
1058  tree->Write();
1059  ret=-2;
1060  continue;;
1061  }
1062  outputList->SetOwner();
1063 
1064  // number of events
1065  fhNEvents =(TH1F *)outputList->FindObject("hNEvents");
1066  if(!fhNEvents){
1067  Error(__FUNCTION__, Form("NEvent histogram not found for trigger %s", fTrigger.Data()));
1068  tree->Fill(); ftree->cd();
1069  tree->Write(); ret=-3;
1070  continue;
1071  }
1072 
1073  Nevent=fhNEvents->GetEntries();
1074 
1075  if(Nevent==0){
1076  Error(__FUNCTION__, Form("No event in trigger %s", fTrigger.Data()));
1077  tree->Fill(); ftree->cd();
1078  tree->Write();
1079  ret=-4;
1080  continue;
1081  }
1082  if(Nevent<20){
1083  Error(__FUNCTION__, Form("Less than 20 events in trigger %s", fTrigger.Data()));
1084  tree->Fill(); ftree->cd();
1085  tree->Write();
1086  ret=-5;
1087  continue;
1088  }
1089 
1090  TH1F* hE =(TH1F *)outputList->FindObject("EMCAL_hE");
1091  if(!hE || (!hE->GetEntries())){
1092  Error(__FUNCTION__, Form("hE Histogram not found or it is empty for trigger %s, EMCal was not in this run?", fTrigger.Data())); EtotalMean=0;
1093  tree->Fill(); ftree->cd();
1094  tree->Write();
1095  ret=-4;
1096  continue;
1097  }
1098 
1099  // first do clusters trending
1100  fhE = (TH1F *)outputList->FindObject(fCalorimeter+"_hE");
1101  fhECharged = (TH1F *)outputList->FindObject(fCalorimeter+"_hECharged");
1102 
1103  Double_t energy = 0. ;
1104 
1105  for(Int_t ibin = fhE->FindBin(0.6) ; ibin <fhE->FindBin(50.) ; ibin++){
1106  energy+=fhE->GetBinCenter(ibin)*fhE->GetBinContent(ibin);
1107  }
1108 
1109  if(fhE->Integral(fhE->FindBin(0.6), fhE->FindBin(50.))==0){
1110  Error(__FUNCTION__, Form("Not enough events"));
1111  tree->Fill(); ftree->cd();
1112  tree->Write();
1113  ret=-6;
1114  continue;
1115  }
1116 
1117  EtotalMean=energy/fhE->Integral(fhE->FindBin(0.6), fhE->FindBin(50.)) ;
1118  EtotalRMS=fhE->GetMeanError();
1119 
1120  TString nameNCell = Form("%s_hNCells_Mod", fCalorimeter.Data());
1121  TString nameNCluster = Form("%s_hNClusters_Mod", fCalorimeter.Data());
1122  TString nameE = Form("%s_hE_Mod", fCalorimeter.Data());
1123  TH2F* hNCellsMod= (TH2F*)outputList->FindObject(nameNCell.Data());
1124  TH2F* hNClusterMod=(TH2F*)outputList->FindObject(nameNCluster.Data());
1125  TH2F* hEMod=(TH2F*)outputList->FindObject(nameE.Data());
1126 
1127  if(!hNCellsMod || !hNClusterMod || !hEMod){
1128  Error(__FUNCTION__, "A requiered histogram was not found (the imput QAresult.root might be too old)!");
1129  tree->Fill(); ftree->cd();
1130  tree->Write();
1131  ret=-7;
1132  continue;
1133  }
1134 
1135  //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1136  // EM addition (Nov. 2016) to observe the PAR Time issue
1137  TString trig_title = "";
1138  if(fTrigger.Contains("EMC"))
1139  trig_title += "EMC";
1140  else
1141  trig_title += "MB";
1142 
1143  // BC/4 = 0
1144  TCanvas* c_TimeSM_BC0 = new TCanvas("TimeSM_BC0", "Cell Time (for BC/4=0) for each SM", 1200, 1200);
1145  c_TimeSM_BC0->SetFillColor(0);
1146  c_TimeSM_BC0->SetBorderSize(0);
1147  c_TimeSM_BC0->SetFrameBorderMode(0);
1148  Bool_t mod3_BC0=0;
1149  if(n%3)
1150  mod3_BC0=1;
1151  c_TimeSM_BC0->Divide(3, n/3+mod3_BC0);
1152 
1153  TH2F* hTimeSM_BC0 = (TH2F*)outputList->FindObject("EMCAL_hTimePerSM_BC0");
1154  TH1F* hTimeSM_BC0_proj[n];
1155  TString TimeSM_BC0_projName;
1156 
1157  if(hTimeSM_BC0){
1158  cout << "---------------------" << endl;
1159  cout << " BC/4=0 | Run " << RunId << endl;
1160  for(Int_t ism = 0 ; ism < n ; ism++){
1161  c_TimeSM_BC0->cd(ism+1);
1162  gPad->SetTopMargin(0.1);
1163  gPad->SetBottomMargin(0.15);
1164  // gPad->SetLogy();
1165 
1166  TimeSM_BC0_projName = Form("SM_%d", ism);
1167  hTimeSM_BC0_proj[ism] = (TH1F *)hTimeSM_BC0->ProjectionX(TimeSM_BC0_projName.Data(), ism+1, ism+1, "") ;
1168  hTimeSM_BC0_proj[ism]->Draw("hist");
1169 
1170  hTimeSM_BC0_proj[ism]->SetTitle(Form("#it{t}_{cell} for super module %i (BC/4=0) %s", ism, trig_title.Data()));
1171  hTimeSM_BC0_proj[ism]->SetTitleSize(0.1);
1172  hTimeSM_BC0_proj[ism]->SetXTitle("#it{t}_{cell} (ns)");
1173  hTimeSM_BC0_proj[ism]->SetYTitle("Nb of entries");
1174  hTimeSM_BC0_proj[ism]->SetStats(kTRUE);
1175 
1176  hTimeSM_BC0_proj[ism]->GetXaxis()->SetRangeUser(400, 900);
1177  hTimeSM_BC0_proj[ism]->GetXaxis()->SetLabelSize(0.05);
1178  hTimeSM_BC0_proj[ism]->GetXaxis()->SetLabelOffset(0.015);
1179  hTimeSM_BC0_proj[ism]->GetXaxis()->SetTitleSize(0.075);
1180  hTimeSM_BC0_proj[ism]->GetXaxis()->SetTitleOffset(0.9);
1181 
1182  hTimeSM_BC0_proj[ism]->GetYaxis()->SetLabelSize(0.05);
1183  hTimeSM_BC0_proj[ism]->GetYaxis()->SetTitleSize(0.06);
1184  hTimeSM_BC0_proj[ism]->GetYaxis()->SetTitleOffset(0.6);
1185  }
1186 
1187  TString outfilename_BC0 = QAPATH + "TimeSM_BC0" + fTrigger(r) + ".pdf";
1188  TString outfilename2_BC0 = QAPATH + "TimeSM_BC0" + fTrigger(r) + ".png";
1189  if(SavePlots==2)
1190  c_TimeSM_BC0->SaveAs(outfilename_BC0);
1191  if(SavePlots)
1192  c_TimeSM_BC0->SaveAs(outfilename2_BC0);
1193  }
1194 
1195  // BC/4 = 1
1196  TCanvas* c_TimeSM_BC1 = new TCanvas("TimeSM_BC1", "Cell Time (for BC/4=1) for each SM", 1200, 1200);
1197  c_TimeSM_BC1->SetFillColor(0);
1198  c_TimeSM_BC1->SetBorderSize(0);
1199  c_TimeSM_BC1->SetFrameBorderMode(0);
1200  Bool_t mod3_BC1=0;
1201  if(n%3)
1202  mod3_BC1=1;
1203  c_TimeSM_BC1->Divide(3, n/3+mod3_BC1);
1204 
1205  TH2F* hTimeSM_BC1 = (TH2F*)outputList->FindObject("EMCAL_hTimePerSM_BC1");
1206  TH1F* hTimeSM_BC1_proj[n];
1207  TString TimeSM_BC1_projName;
1208 
1209  if(hTimeSM_BC1){
1210  cout << "---------------------" << endl;
1211  cout << " BC/4=1 | Run " << RunId << endl;
1212  for(Int_t ism = 0 ; ism < n ; ism++){
1213  c_TimeSM_BC1->cd(ism+1);
1214  gPad->SetTopMargin(0.1);
1215  gPad->SetBottomMargin(0.15);
1216  // gPad->SetLogy();
1217 
1218  TimeSM_BC1_projName = Form("SM_%d", ism);
1219  hTimeSM_BC1_proj[ism] = (TH1F *)hTimeSM_BC1->ProjectionX(TimeSM_BC1_projName.Data(), ism+1, ism+1, "") ;
1220  hTimeSM_BC1_proj[ism]->Draw("hist");
1221 
1222  hTimeSM_BC1_proj[ism]->SetTitle(Form("#it{t}_{cell} for super module %i (BC/4=1) %s", ism, trig_title.Data()));
1223  hTimeSM_BC1_proj[ism]->SetTitleSize(0.1);
1224  hTimeSM_BC1_proj[ism]->SetXTitle("#it{t}_{cell} (ns)");
1225  hTimeSM_BC1_proj[ism]->SetYTitle("Nb of entries");
1226  hTimeSM_BC1_proj[ism]->SetStats(kTRUE);
1227 
1228  hTimeSM_BC1_proj[ism]->GetXaxis()->SetRangeUser(400, 900);
1229  hTimeSM_BC1_proj[ism]->GetXaxis()->SetLabelSize(0.05);
1230  hTimeSM_BC1_proj[ism]->GetXaxis()->SetLabelOffset(0.015);
1231  hTimeSM_BC1_proj[ism]->GetXaxis()->SetTitleSize(0.075);
1232  hTimeSM_BC1_proj[ism]->GetXaxis()->SetTitleOffset(0.9);
1233 
1234  hTimeSM_BC1_proj[ism]->GetYaxis()->SetLabelSize(0.05);
1235  hTimeSM_BC1_proj[ism]->GetYaxis()->SetTitleSize(0.06);
1236  hTimeSM_BC1_proj[ism]->GetYaxis()->SetTitleOffset(0.6);
1237  }
1238 
1239  TString outfilename_BC1 = QAPATH + "TimeSM_BC1" + fTrigger(r) + ".pdf";
1240  TString outfilename2_BC1 = QAPATH + "TimeSM_BC1" + fTrigger(r) + ".png";
1241  if(SavePlots==2)
1242  c_TimeSM_BC1->SaveAs(outfilename_BC1);
1243  if(SavePlots)
1244  c_TimeSM_BC1->SaveAs(outfilename2_BC1);
1245  }
1246 
1247  // BC/4 = 2
1248  TCanvas* c_TimeSM_BC2 = new TCanvas("TimeSM_BC2", "Cell Time (for BC/4=2) for each SM", 1200, 1200);
1249  c_TimeSM_BC2->SetFillColor(0);
1250  c_TimeSM_BC2->SetBorderSize(0);
1251  c_TimeSM_BC2->SetFrameBorderMode(0);
1252  Bool_t mod3_BC2=0;
1253  if(n%3)
1254  mod3_BC2=1;
1255  c_TimeSM_BC2->Divide(3, n/3+mod3_BC2);
1256 
1257  TH2F* hTimeSM_BC2 = (TH2F*)outputList->FindObject("EMCAL_hTimePerSM_BC2");
1258  TH1F* hTimeSM_BC2_proj[n];
1259  TString TimeSM_BC2_projName;
1260 
1261  if(hTimeSM_BC2){
1262  cout << "---------------------" << endl;
1263  cout << " BC/4=2 | Run " << RunId << endl;
1264  for(Int_t ism = 0 ; ism < n ; ism++){
1265  c_TimeSM_BC2->cd(ism+1);
1266  gPad->SetTopMargin(0.1);
1267  gPad->SetBottomMargin(0.15);
1268  // gPad->SetLogy();
1269 
1270  TimeSM_BC2_projName = Form("SM_%d", ism);
1271  hTimeSM_BC2_proj[ism] = (TH1F *)hTimeSM_BC2->ProjectionX(TimeSM_BC2_projName.Data(), ism+1, ism+1, "") ;
1272  hTimeSM_BC2_proj[ism]->Draw("hist");
1273 
1274  hTimeSM_BC2_proj[ism]->SetTitle(Form("#it{t}_{cell} for super module %i (BC/4=2) %s", ism, trig_title.Data()));
1275  hTimeSM_BC2_proj[ism]->SetTitleSize(0.1);
1276  hTimeSM_BC2_proj[ism]->SetXTitle("#it{t}_{cell} (ns)");
1277  hTimeSM_BC2_proj[ism]->SetYTitle("Nb of entries");
1278  hTimeSM_BC2_proj[ism]->SetStats(kTRUE);
1279 
1280  hTimeSM_BC2_proj[ism]->GetXaxis()->SetRangeUser(400, 900);
1281  hTimeSM_BC2_proj[ism]->GetXaxis()->SetLabelSize(0.05);
1282  hTimeSM_BC2_proj[ism]->GetXaxis()->SetLabelOffset(0.015);
1283  hTimeSM_BC2_proj[ism]->GetXaxis()->SetTitleSize(0.075);
1284  hTimeSM_BC2_proj[ism]->GetXaxis()->SetTitleOffset(0.9);
1285 
1286  hTimeSM_BC2_proj[ism]->GetYaxis()->SetLabelSize(0.05);
1287  hTimeSM_BC2_proj[ism]->GetYaxis()->SetTitleSize(0.06);
1288  hTimeSM_BC2_proj[ism]->GetYaxis()->SetTitleOffset(0.6);
1289  }
1290 
1291  TString outfilename_BC2 = QAPATH + "TimeSM_BC2" + fTrigger(r) + ".pdf";
1292  TString outfilename2_BC2 = QAPATH + "TimeSM_BC2" + fTrigger(r) + ".png";
1293  if(SavePlots==2)
1294  c_TimeSM_BC2->SaveAs(outfilename_BC2);
1295  if(SavePlots)
1296  c_TimeSM_BC2->SaveAs(outfilename2_BC2);
1297  }
1298 
1299  // BC/4 = 3
1300  TCanvas* c_TimeSM_BC3 = new TCanvas("TimeSM_BC3", "Cell Time (for BC/4=3) for each SM", 1200, 1200);
1301  c_TimeSM_BC3->SetFillColor(0);
1302  c_TimeSM_BC3->SetBorderSize(0);
1303  c_TimeSM_BC3->SetFrameBorderMode(0);
1304  Bool_t mod3_BC3=0;
1305  if(n%3)
1306  mod3_BC3=1;
1307  c_TimeSM_BC3->Divide(3, n/3+mod3_BC3);
1308 
1309  TH2F* hTimeSM_BC3 = (TH2F*)outputList->FindObject("EMCAL_hTimePerSM_BC3");
1310  TH1F* hTimeSM_BC3_proj[n];
1311  TString TimeSM_BC3_projName;
1312 
1313  if(hTimeSM_BC3){
1314  cout << "---------------------" << endl;
1315  cout << " BC/4=3 | Run " << RunId << endl;
1316  for(Int_t ism = 0 ; ism < n ; ism++){
1317  c_TimeSM_BC3->cd(ism+1);
1318  gPad->SetTopMargin(0.1);
1319  gPad->SetBottomMargin(0.15);
1320  // gPad->SetLogy();
1321 
1322  TimeSM_BC3_projName = Form("SM_%d", ism);
1323  hTimeSM_BC3_proj[ism] = (TH1F *)hTimeSM_BC3->ProjectionX(TimeSM_BC3_projName.Data(), ism+1, ism+1, "") ;
1324  hTimeSM_BC3_proj[ism]->Draw("hist");
1325 
1326  hTimeSM_BC3_proj[ism]->SetTitle(Form("#it{t}_{cell} for super module %i (BC/4=3) %s", ism, trig_title.Data()));
1327  hTimeSM_BC3_proj[ism]->SetTitleSize(0.1);
1328  hTimeSM_BC3_proj[ism]->SetXTitle("#it{t}_{cell} (ns)");
1329  hTimeSM_BC3_proj[ism]->SetYTitle("Nb of entries");
1330  hTimeSM_BC3_proj[ism]->SetStats(kTRUE);
1331 
1332  hTimeSM_BC3_proj[ism]->GetXaxis()->SetRangeUser(400, 900);
1333  hTimeSM_BC3_proj[ism]->GetXaxis()->SetLabelSize(0.05);
1334  hTimeSM_BC3_proj[ism]->GetXaxis()->SetLabelOffset(0.015);
1335  hTimeSM_BC3_proj[ism]->GetXaxis()->SetTitleSize(0.075);
1336  hTimeSM_BC3_proj[ism]->GetXaxis()->SetTitleOffset(0.9);
1337 
1338  hTimeSM_BC3_proj[ism]->GetYaxis()->SetLabelSize(0.05);
1339  hTimeSM_BC3_proj[ism]->GetYaxis()->SetTitleSize(0.06);
1340  hTimeSM_BC3_proj[ism]->GetYaxis()->SetTitleOffset(0.6);
1341  }
1342 
1343  TString outfilename_BC3 = QAPATH + "TimeSM_BC3" + fTrigger(r) + ".pdf";
1344  TString outfilename2_BC3 = QAPATH + "TimeSM_BC3" + fTrigger(r) + ".png";
1345  if(SavePlots==2)
1346  c_TimeSM_BC3->SaveAs(outfilename_BC3);
1347  if(SavePlots)
1348  c_TimeSM_BC3->SaveAs(outfilename2_BC3);
1349  }
1350 
1351  //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1352 
1353  TCanvas* c1 = new TCanvas("Pi0InvMassSM", "Pi0 Invariant Mass for each SM", 600, 600);
1354  gStyle->SetOptStat(1); // MG modif
1355  gStyle->SetOptFit(1); // MG modif
1356  c1->SetFillColor(0);
1357  c1->SetBorderSize(0);
1358  c1->SetFrameBorderMode(0);
1359  // c1->SetOptStat(1); // MG modif
1360 
1361  Bool_t mod3=0;
1362  if(n%3)
1363  mod3=1;
1364  c1->Divide(3, n/3+mod3);
1365 
1366  // per sm trending
1367  TString nameNCellPerCluster;
1368  for(Int_t ism = 0 ; ism < n ; ism++){
1369  cout << "#########################"<< endl;
1370  cout << " Super Module " << ism << " Run " << RunId << endl;
1371 
1372  // first do clusters trending
1373  nameNCellPerCluster = Form("%s_hNCellsPerCluster_Mod%d", fCalorimeter.Data(), ism);
1374  NCellsPerCluster[ism] = (TH2F*)outputList->FindObject(nameNCellPerCluster.Data());
1375 
1376  if(! (TH2F*)outputList->FindObject(nameNCellPerCluster.Data()) ){
1377  Error(__FUNCTION__, Form("NCellsPerCluster histogram not found for super module %i", ism));
1378  ret=-8;
1379  continue;
1380  }
1381 
1382  NCellsPerCluster[ism] = (TH2F*)outputList->FindObject(nameNCellPerCluster.Data());
1383  NCells[ism] = (TH1F*)hNCellsMod->ProjectionX(Form("NCells%d", ism), ism+1, ism+1, "");
1384  NClusters[ism] = (TH1F*)hNClusterMod->ProjectionX(Form("NClusters%d", ism), ism+1, ism+1, "");
1385  E[ism] = (TH1F*)hEMod->ProjectionX(Form("E%d", ism), ism+1, ism+1, "");
1386 
1387  CellMeanSM[ism]=NCells[ism]->GetMean();
1388  CellRMSSM[ism]=NCells[ism]->GetMeanError();
1389 
1390  Int_t binmax;
1391  binmax = NClusters[ism]->GetNbinsX();
1392  for(Int_t ibin = 1 ;ibin <=binmax ;ibin++){
1393  ClusterTotSM[ism]+=(NClusters[ism]->GetBinCenter(ibin))*(NClusters[ism]->GetBinContent(ibin));
1394  }
1395  if(NClusters[ism]->GetEntries()>0)
1396  ClusterTotSM[ism]= ClusterTotSM[ism]/NClusters[ism]->GetEntries();
1397 
1398  // ClusterTotSM[ism]=NClusters[ism]->GetMean();
1399  ClusterMeanSM[ism]=NClusters[ism]->GetMean();
1400  ClusterRMSSM[ism]=NClusters[ism]->GetMeanError();
1401  CellPerClusterMeanSM[ism]=NCellsPerCluster[ism]->GetMean(2);
1402  CellPerClusterRMSSM[ism]=NCellsPerCluster[ism]->GetMeanError(2);
1403 
1404  ECell1MeanSM[ism] =NCellsPerCluster[ism]->ProjectionX("", 2, 50, "")->Integral(5, 50)/(Nevent);
1405  ECell1RMSSM[ism] =NCellsPerCluster[ism]->ProjectionX("", 2, 50, "")->GetMeanError();
1406 
1407  Double_t energySM = 0. ;
1408  for(Int_t ibin = E[ism]->FindBin(0.6) ; ibin <E[ism]->FindBin(50.) ; ibin++){
1409  energySM+=E[ism]->GetBinCenter(ibin)*(E[ism]->GetBinContent(ibin));
1410  }
1411 
1412  if(E[ism]->Integral(E[ism]->FindBin(0.6), E[ism]->FindBin(50.))==0){
1413  Error(__FUNCTION__, Form("Energy: Not enough events/SM"));
1414  continue;
1415  }
1416 
1417  EtotalMeanSM[ism]=energySM/(E[ism]->Integral(E[ism]->FindBin(0.6), E[ism]->FindBin(50.)));
1418  EtotalRMSSM[ism]=E[ism]->GetMeanError();
1419 
1420  if(ism==0){
1421  fhNCells = (TH1F*)NCells[ism]->Clone("NCells");
1422  fhNClusters = (TH1F*)NClusters[ism]->Clone("NClusters");
1423  }
1424  else{
1425  fhNCells->Add(NCells[ism], 1);
1426  fhNClusters->Add(NClusters[ism], 1);
1427  }
1428 
1429  // Pi0
1430  c1->cd(ism+1);
1431  TString namePair = Form("%s_hIM_Mod%d", fCalorimeter.Data(), ism);
1432  IM[ism] = (TH2F*)outputList->FindObject(namePair.Data());
1433  IM[ism]->Sumw2();
1434 
1435  TString projname = Form("SM_%d", ism);
1436  MggSM[ism] = (TH1F *)IM[ism]->ProjectionY(projname.Data(), 10, 50, "") ; // MG modif
1437 
1438  if(MggSM[ism]->GetEntries()>100){
1439  fitMass->SetParameter(0, MggSM[ism]->GetBinContent(MggSM[ism]->GetMaximumBin()));
1440  fitMass->SetParameter(1, mPDG);
1441  fitMass->SetParameter(2, 15.);
1442  fitMass->SetParameter(3, 0.);
1443  fitMass->SetParameter(4, MggSM[ism]->GetBinContent(MggSM[ism]->FindBin(0.11)));
1444  fitMass->SetParameter(5, MggSM[ism]->GetBinContent(MggSM[ism]->FindBin(0.20)));
1445 
1446  if(MggSM[ism]->GetEntries()<1000)
1447  MggSM[ism]->Rebin(5);
1448  else
1449  MggSM[ism]->Rebin();
1450 
1451  MggSM[ism]->Fit("fitMass", "WL R +", "", 0.1, 0.30);
1452  MggSM[ism]->SetTitle(Form("Pi0 Mass for super module %i", ism));
1453  MggSM[ism]->SetTitleSize(0.1);
1454  MggSM[ism]->SetXTitle("Pi0 Mass");
1455  MggSM[ism]->SetYTitle("Nb of entries");
1456  MggSM[ism]->GetXaxis()->SetLabelSize(0.05);
1457  MggSM[ism]->GetXaxis()->SetTitleSize(0.07);
1458  MggSM[ism]->GetXaxis()->SetTitleOffset(0.68);
1459  MggSM[ism]->GetYaxis()->SetLabelSize(0.05);
1460  MggSM[ism]->GetYaxis()->SetTitleSize(0.06);
1461  MggSM[ism]->GetYaxis()->SetTitleOffset(0.78);
1462 
1463  MeanPosSM[ism] = MggSM[ism]->GetFunction("fitMass")->GetParameter(1)*1000;
1464  MeanPosErrSM[ism] = MggSM[ism]->GetFunction("fitMass")->GetParError(1)*1000;
1465  WidthSM[ism] = MggSM[ism]->GetFunction("fitMass")->GetParameter(2)*1000;
1466  WidthErrSM[ism] = MggSM[ism]->GetFunction("fitMass")->GetParError(2)*1000;
1467  Npi0SM[ism] = MggSM[ism]->GetFunction("fitMass")->GetParameter(0)*(MggSM[ism]->GetFunction("fitMass")->GetParameter(2))*TMath::Sqrt(2*TMath::Pi())/(Nevent*MggSM[ism]->GetBinWidth(1));
1468  Npi0ErrSM[ism] = TMath::Sqrt((MggSM[ism]->GetFunction("fitMass")->GetParError(0)/MggSM[ism]->GetFunction("fitMass")->GetParameter(0))*(MggSM[ism]->GetFunction("fitMass")->GetParError(0)/MggSM[ism]->GetFunction("fitMass")->GetParameter(0))
1469  +(MggSM[ism]->GetFunction("fitMass")->GetParError(2)/MggSM[ism]->GetFunction("fitMass")->GetParameter(2))*(MggSM[ism]->GetFunction("fitMass")->GetParError(2)/MggSM[ism]->GetFunction("fitMass")->GetParameter(2)));
1470  Npi0ErrSM[ism] = 0.;
1471 
1472  } // end if enough events for Pi0 fit and trending
1473  else
1474  Info(__FUNCTION__, Form("Not enough events for Pi0 fit and trending for super module %i", ism));
1475  } // per SM loop
1476 
1477  // Now Pi0 global trending in EMCAL
1478  TCanvas* c2 = new TCanvas("Pi0InvMassEMCAL", "Pi0 Invariant Mass in EMCal", 600, 600);
1479  c2->SetFillColor(0);
1480  c2->SetBorderSize(0);
1481  c2->SetFrameBorderMode(0);
1482  // c2->SetOptStat(1); // MG modif
1483 
1484  fhIM = (TH2F *)outputList->FindObject(fCalorimeter+"_hIM");
1485  fhIM->Sumw2();
1486  fhMggEMCAL = (TH1F *)fhIM->ProjectionY("MggEMCAL", 10, 50, "") ; // to modify projection range
1487 
1488  if(fhMggEMCAL->GetEntries()==0){
1489  Error(__FUNCTION__, "The Pi0 histogram in EMCal is empty !"); tree->Fill();
1490  ret=-8;
1491  continue;
1492  }
1493 
1494  fitMass->SetParameter(0, 4500);
1495  fitMass->SetParameter(1, mPDG);
1496  fitMass->SetParameter(2, 0.01);
1497  fitMass->SetParameter(3, 0.);
1498  fitMass->SetParameter(4, fhMggEMCAL->GetBinContent(fhMggEMCAL->FindBin(0.11)));
1499  fitMass->SetParameter(5, fhMggEMCAL->GetBinContent(fhMggEMCAL->FindBin(0.20)));
1500 
1501  if(fhMggEMCAL->GetEntries()<5000)
1502  fhMggEMCAL->Rebin(5); // MG modif
1503  else
1504  fhMggEMCAL->Rebin();
1505 
1506  fhMggEMCAL->Fit("fitMass", "L R +", "", 0.05, 0.20);
1507 
1508  fhMggEMCAL->SetTitle("Pi0 Mass in EMCal");
1509  fhMggEMCAL->SetTitleSize(0.1);
1510  fhMggEMCAL->SetXTitle("Pi0 Mass");
1511  fhMggEMCAL->SetYTitle("Nb of entries");
1512  fhMggEMCAL->GetXaxis()->SetLabelSize(0.03);
1513  fhMggEMCAL->GetXaxis()->SetTitleSize(0.03);
1514  fhMggEMCAL->GetXaxis()->SetTitleOffset(1.3);
1515  fhMggEMCAL->GetYaxis()->SetLabelSize(0.03);
1516  fhMggEMCAL->GetYaxis()->SetTitleSize(0.03);
1517  fhMggEMCAL->GetYaxis()->SetTitleOffset(1.3);
1518 
1519  MeanPosEMCAL = fhMggEMCAL->GetFunction("fitMass")->GetParameter(1)*1000;
1520  MeanPosEMCALErr = fhMggEMCAL->GetFunction("fitMass")->GetParError(1)*1000;
1521  WidthEMCAL = fhMggEMCAL->GetFunction("fitMass")->GetParameter(2)*1000;
1522  WidthEMCALErr = fhMggEMCAL->GetFunction("fitMass")->GetParError(2)*1000;
1523  Chi2NdfPi0EMCAL = fhMggEMCAL->GetFunction("fitMass")->GetChisquare()/fhMggEMCAL->GetFunction("fitMass")->GetNDF();
1524  Npi0EMCAL = fhMggEMCAL->GetFunction("fitMass")->GetParameter(0)*fhMggEMCAL->GetFunction("fitMass")->GetParameter(2)*TMath::Sqrt(2*TMath::Pi())/(Nevent*fhMggEMCAL->GetBinWidth(10));
1525  Npi0EMCALErr = TMath::Sqrt((fhMggEMCAL->GetFunction("fitMass")->GetParError(0)/fhMggEMCAL->GetFunction("fitMass")->GetParameter(0))*(fhMggEMCAL->GetFunction("fitMass")->GetParError(0)/fhMggEMCAL->GetFunction("fitMass")->GetParameter(0))+(WidthEMCALErr/WidthEMCAL)*(WidthEMCALErr/WidthEMCAL));
1526  Npi0EMCALErr = 0.;
1527  NggEMCAL = fhMggEMCAL->GetFunction("fitMass")->Integral(0.11, 0.16)/(Nevent*fhMggEMCAL->GetBinWidth(10));
1528  NggEMCALErr = fhMggEMCAL->GetFunction("fitMass")->IntegralError(0.11, 0.16)/(fhMggEMCAL->Integral()*fhMggEMCAL->GetBinWidth(10));
1529  SignifEMCAL = Npi0EMCAL/NggEMCAL;
1530  SignifEMCALErr = TMath::Sqrt((Npi0EMCALErr/Npi0EMCAL*(Npi0EMCALErr/Npi0EMCAL)+(NggEMCALErr/NggEMCAL*(NggEMCALErr/NggEMCAL))));
1531  SignifEMCALErr = SignifEMCAL*SignifEMCALErr;
1532 
1533  TCanvas* c3 = new TCanvas("Pi0InvMassDCAL", "Pi0 Invariant Mass in DCal", 600, 600);
1534  c3->SetFillColor(0);
1535  c3->SetBorderSize(0);
1536  c3->SetFrameBorderMode(0);
1537 
1538  fhIMDCAL = (TH2F *)outputList->FindObject(fCalorimeter+"_hIMDCAL");
1539  if(fhIMDCAL){
1540  // Now Pi0 global trending in DCal
1541  // TCanvas* c3 = new TCanvas("Pi0InvMassDCAL", "Pi0 Invariant Mass in DCal", 600, 600);
1542  // c3->SetFillColor(0);
1543  // c3->SetBorderSize(0);
1544  // c3->SetFrameBorderMode(0);
1545  // c2->SetOptStat(1); // MG modif
1546 
1547  // fhIMDCAL = (TH2F *)outputList->FindObject(fCalorimeter+"_hIMDCAL");
1548  // if(!fhIMDCAL) continue;
1549  fhIMDCAL->Sumw2();
1550 
1551  fhMggDCAL = (TH1F *)fhIMDCAL->ProjectionY("MggDCAL", 10, 50, "") ; // to modify projection range
1552  if(fhMggDCAL->GetEntries()==0){
1553  Error(__FUNCTION__, "The Pi0 histogram in DCal is empty !"); tree->Fill();
1554  ret=-8;
1555  continue;
1556  }
1557 
1558  fitMass->SetParameter(0, 4500);
1559  fitMass->SetParameter(1, mPDG);
1560  fitMass->SetParameter(2, 0.01);
1561  fitMass->SetParameter(3, 0.);
1562  fitMass->SetParameter(4, fhMggDCAL->GetBinContent(fhMggDCAL->FindBin(0.11)));
1563  fitMass->SetParameter(5, fhMggDCAL->GetBinContent(fhMggDCAL->FindBin(0.20)));
1564 
1565  if(fhMggDCAL->GetEntries()<5000)
1566  fhMggDCAL->Rebin(5); // MG modif
1567  else
1568  fhMggDCAL->Rebin();
1569 
1570  fhMggDCAL->Fit("fitMass", "L R +", "", 0.05, 0.20);
1571 
1572  fhMggDCAL->SetTitle("Pi0 Mass in DCal");
1573  fhMggDCAL->SetTitleSize(0.1);
1574  fhMggDCAL->SetXTitle("Pi0 Mass");
1575  fhMggDCAL->SetYTitle("Nb of entries");
1576  fhMggDCAL->GetXaxis()->SetLabelSize(0.03);
1577  fhMggDCAL->GetXaxis()->SetTitleSize(0.03);
1578  fhMggDCAL->GetXaxis()->SetTitleOffset(1.3);
1579  fhMggDCAL->GetYaxis()->SetLabelSize(0.03);
1580  fhMggDCAL->GetYaxis()->SetTitleSize(0.03);
1581  fhMggDCAL->GetYaxis()->SetTitleOffset(1.3);
1582 
1583  MeanPosDCAL = fhMggDCAL->GetFunction("fitMass")->GetParameter(1)*1000;
1584  MeanPosDCALErr = fhMggDCAL->GetFunction("fitMass")->GetParError(1)*1000;
1585  WidthDCAL = fhMggDCAL->GetFunction("fitMass")->GetParameter(2)*1000;
1586  WidthDCALErr = fhMggDCAL->GetFunction("fitMass")->GetParError(2)*1000;
1587  Chi2NdfPi0DCAL = fhMggDCAL->GetFunction("fitMass")->GetChisquare()/fhMggDCAL->GetFunction("fitMass")->GetNDF();
1588  Npi0DCAL = fhMggDCAL->GetFunction("fitMass")->GetParameter(0)*fhMggDCAL->GetFunction("fitMass")->GetParameter(2)*TMath::Sqrt(2*TMath::Pi())/(Nevent*fhMggDCAL->GetBinWidth(10));
1589  Npi0DCALErr = TMath::Sqrt((fhMggDCAL->GetFunction("fitMass")->GetParError(0)/fhMggDCAL->GetFunction("fitMass")->GetParameter(0))*(fhMggDCAL->GetFunction("fitMass")->GetParError(0)/fhMggDCAL->GetFunction("fitMass")->GetParameter(0))+(WidthDCALErr/WidthDCAL)*(WidthDCALErr/WidthDCAL));
1590  Npi0DCALErr = 0.;
1591  NggDCAL = fhMggDCAL->GetFunction("fitMass")->Integral(0.11, 0.16)/(Nevent*fhMggDCAL->GetBinWidth(10));
1592  NggDCALErr = fhMggDCAL->GetFunction("fitMass")->IntegralError(0.11, 0.16)/(fhMggDCAL->Integral()*fhMggDCAL->GetBinWidth(10));
1593  SignifDCAL = Npi0DCAL/NggDCAL;
1594  SignifDCALErr = TMath::Sqrt((Npi0DCALErr/Npi0DCAL*(Npi0DCALErr/Npi0DCAL)+(NggDCALErr/NggDCAL*(NggDCALErr/NggDCAL))));
1595  SignifDCALErr = SignifDCAL*SignifDCALErr;
1596  }
1597 
1598  // cout<<"******************"<<endl;
1599  // end of global trending
1600 
1601  // cout<<"********************************** Total number of clusters **********************************"<<endl;
1602 
1603  NTClusters=fhE->IntegralAndError(fhE->GetXaxis()->FindBin(0.), fhE->GetXaxis()->FindBin(200.), NTClustersRMS);
1604  NCClusters=fhECharged->IntegralAndError(fhECharged->GetXaxis()->FindBin(0.), fhECharged->GetXaxis()->FindBin(50.), NCClustersRMS);
1605 
1606  if(NTClusters!=0)
1607  NMatchClustersP = NCClusters/NTClusters;
1608  else
1609  NMatchClustersP=0;
1610  // cout<<" here is searched value "<<NMatchClustersP<<" "<<endl;
1611 
1612  if(NCClusters!=0)
1613  NMatchClustersPRMS = NMatchClustersP* TMath::Sqrt(TMath::Power(NCClustersRMS/NCClusters, 2)+TMath::Power(NTClustersRMS/NTClusters, 2));
1614  else
1615  NMatchClustersPRMS=1;
1616 
1617  ClusterMean=fhNClusters->GetMean();
1618  ClusterRMS=fhNClusters->GetMeanError();
1619  CellMean=fhNCells->GetMean();
1620  CellRMS=fhNCells->GetMeanError();
1621 
1622  if (fTrigger.Contains("default")){
1623  // if (fTrigger.Contains("default") && pass.Contains("muon_calo")){
1624 
1625  // specific triggerQA
1626 
1627  TList *outputListEG2 = (TList*)gDirectory->Get("AliEmcalTriggerQATask_EG2_histos");
1628 
1629  if(outputListEG2){ // here we test only the first list presence to check if triggerTask was activated
1630  TList *outputListEG2N = (TList*)outputListEG2->FindObject("histosAliEmcalTriggerQATask_EG2");
1631 
1632 
1633  TList *outputListEG1 = (TList*)gDirectory->Get("AliEmcalTriggerQATask_EG1_histos");
1634  TList *outputListEG1N = (TList*)outputListEG1->FindObject("histosAliEmcalTriggerQATask_EG1");
1635  TList *outputListEJ2 = (TList*)gDirectory->Get("AliEmcalTriggerQATask_EJ2_histos");
1636  TList *outputListEJ2N = (TList*)outputListEJ2->FindObject("histosAliEmcalTriggerQATask_EJ2");
1637 
1638  TList *outputListEJ1 = (TList*)gDirectory->Get("AliEmcalTriggerQATask_EJ1_histos");
1639  TList *outputListEJ1N = (TList*)outputListEJ1->FindObject("histosAliEmcalTriggerQATask_EJ1");
1640  TList *outputListINT7 = (TList*)gDirectory->Get("AliEmcalTriggerQATask_CINT7_histos");
1641  TList *outputListINT7N = (TList*)outputListINT7->FindObject("histosAliEmcalTriggerQATask_CINT7");
1642  TList *outputListEMC7 = (TList*)gDirectory->Get("AliEmcalTriggerQATask_CEMC7_histos");
1643  TList *outputListEMC7N = (TList*)outputListEMC7->FindObject("histosAliEmcalTriggerQATask_CEMC7");
1644 
1645  TList *outputListDG2 = (TList*)gDirectory->Get("AliEmcalTriggerQATask_DG2_histos");
1646  TList *outputListDG2N = (TList*)outputListDG2->FindObject("histosAliEmcalTriggerQATask_DG2");
1647 
1648 
1649  TList *outputListDG1 = (TList*)gDirectory->Get("AliEmcalTriggerQATask_DG1_histos");
1650  TList *outputListDG1N = (TList*)outputListDG1->FindObject("histosAliEmcalTriggerQATask_DG1");
1651  TList *outputListDJ2 = (TList*)gDirectory->Get("AliEmcalTriggerQATask_DJ2_histos");
1652  TList *outputListDJ2N = (TList*)outputListDJ2->FindObject("histosAliEmcalTriggerQATask_DJ2");
1653 
1654  TList *outputListDJ1 = (TList*)gDirectory->Get("AliEmcalTriggerQATask_DJ1_histos");
1655  TList *outputListDJ1N = (TList*)outputListDJ1->FindObject("histosAliEmcalTriggerQATask_DJ1");
1656  TList *outputListDMC7 = (TList*)gDirectory->Get("AliEmcalTriggerQATask_CDMC7_histos");
1657  TList *outputListDMC7N = (TList*)outputListDMC7->FindObject("histosAliEmcalTriggerQATask_CDMC7");
1658 
1659 
1660 
1661 
1662  if(!outputListEG2N) cout << "NO outputListEG2"<<endl;
1663  if(!outputListEG1N) cout << "NO outputListEG1"<<endl;
1664  if(!outputListEJ2N) cout << "NO outputListEJ2"<<endl;
1665  if(!outputListEJ1N) cout << "NO outputListEJ1"<<endl;
1666  if(!outputListDG2N) cout << "NO outputListEG2"<<endl;
1667  if(!outputListDG1N) cout << "NO outputListDG1"<<endl;
1668  if(!outputListDJ2N) cout << "NO outputListDJ2"<<endl;
1669  if(!outputListDJ1N) cout << "NO outputListDJ1"<<endl;
1670  if(!outputListINT7N) cout << "NO outputListINT7"<<endl;
1671  if(!outputListEMC7N) cout << "NO outputListEMC7"<<endl;
1672  if(!outputListDMC7N) cout << "NO outputListDMC7"<<endl;
1673 
1674 
1675 
1676 
1677 
1678  hEGA2 =(TH1D*)outputListEG2N->FindObject("EMCTRQA_histEMCalMaxPatchAmpEMCGAHRecalc");
1679  hEGA1 =(TH1D*)outputListEG1N->FindObject("EMCTRQA_histEMCalMaxPatchAmpEMCGAHRecalc");
1680 
1681  hDGA2 =(TH1D*)outputListDG2N->FindObject("EMCTRQA_histDCalMaxPatchAmpEMCGAHRecalc");
1682  hDGA1 =(TH1D*)outputListDG1N->FindObject("EMCTRQA_histDCalMaxPatchAmpEMCGAHRecalc");
1683  hEJE2 =(TH1D*)outputListEJ2N->FindObject("EMCTRQA_histEMCalMaxPatchAmpEMCJEHRecalc");
1684  hEJE1 =(TH1D*)outputListEJ1N->FindObject("EMCTRQA_histEMCalMaxPatchAmpEMCJEHRecalc");
1685  hDJE2 =(TH1D*)outputListDJ2N->FindObject("EMCTRQA_histDCalMaxPatchAmpEMCJEHRecalc");
1686  hDJE1 =(TH1D*)outputListDJ1N->FindObject("EMCTRQA_histDCalMaxPatchAmpEMCJEHRecalc");
1687  hEMC7 =(TH1D*)outputListEMC7N->FindObject("EMCTRQA_histEMCalMaxPatchAmpEMCL0Recalc");
1688  hDMC7 =(TH1D*)outputListDMC7N->FindObject("EMCTRQA_histDCalMaxPatchAmpEMCL0Recalc");
1689  //hINT7 =(TH1D*)outputListINT7N->FindObject("EMCTRQA_histEMCalMaxPatchAmpEMCL0HRecalc");
1690 
1691 
1692  // Trigger Occupancy plots
1693  hEGA2Map =(TH2D*)outputListEG2N->FindObject("EMCTRQA_histFastORL1AccumulatedAmplitude");
1694  hEGA1Map =(TH2D*)outputListEG1N->FindObject("EMCTRQA_histFastORL1AccumulatedAmplitude");
1695  hEJE2Map =(TH2D*)outputListEJ2N->FindObject("EMCTRQA_histFastORL1AccumulatedAmplitude");
1696  hEJE1Map =(TH2D*)outputListEJ1N->FindObject("EMCTRQA_histFastORL1AccumulatedAmplitude");
1697  hEMC7Map =(TH2D*)outputListEMC7N->FindObject("EMCTRQA_histFastORL0AccumulatedAmplitude");
1698  hDGA2Map =(TH2D*)outputListDG2N->FindObject("EMCTRQA_histFastORL1AccumulatedAmplitude");
1699  hDGA1Map =(TH2D*)outputListDG1N->FindObject("EMCTRQA_histFastORL1AccumulatedAmplitude");
1700  hDJE2Map =(TH2D*)outputListDJ2N->FindObject("EMCTRQA_histFastORL1AccumulatedAmplitude");
1701  hDJE1Map =(TH2D*)outputListDJ1N->FindObject("EMCTRQA_histFastORL1AccumulatedAmplitude");
1702  hDMC7Map =(TH2D*)outputListDMC7N->FindObject("EMCTRQA_histFastORL0AccumulatedAmplitude");
1703 
1704 
1705  TCanvas* c00T = new TCanvas("Occupancy map", "Occupancy", 1000, 1000);
1706  c00T->SetLogz();
1707  c00T->SetFillColor(0);
1708  c00T->SetBorderSize(0);
1709  c00T->SetFrameBorderMode(0);
1710  c00T->Divide(2,3);
1711 
1712  // TString namefile = QAPATH + period + "_" + pass + fTrigger(r).Data() + "_" + RunId + "_data.txt";
1713  //legend = "run "+RunId;
1714  const char* legend="";
1715  legend = Form(" Run %d ", (int)RunId);
1716  // // TPMERegexp r("_\\w+");
1717  // legend = Form(" Run %s ", RunId);
1718  // legend = "run "+RunId;
1719 
1720  c00T->cd(1);
1721  gPad->SetLogz();
1722 
1723  FormatRunHisto2D(hEGA2Map, Form("EGA2 FastORL1Amp %s", legend), "#varphi (bin)");
1724  hEGA2Map->SetXTitle("#eta (bin)");
1725 
1726  if(hEGA2Map->GetEntries()>10)hEGA2Map->Draw("colz");
1727 
1728 
1729 
1730  c00T->cd(2);
1731  gPad->SetLogz();
1732  FormatRunHisto2D(hEGA1Map, Form("EGA1 FastORL1Amp %s", legend), "#varphi (bin)");
1733  hEGA1Map->SetXTitle("#eta (bin)");
1734  if(hEGA1Map->GetEntries()>10)hEGA1Map->Draw("colz");
1735 
1736  c00T->cd(3);
1737  hEJE2Map->SetXTitle("#eta (bin)");
1738  gPad->SetLogz();
1739  FormatRunHisto2D(hEJE2Map, Form("EJE2 FastORL1Amp %s", legend), "#varphi (bin)");
1740  if(hEJE2Map->GetEntries()>10)hEJE2Map->Draw("colz");
1741 
1742  c00T->cd(4);
1743  gPad->SetLogz();
1744 
1745  hEJE1Map->SetXTitle("#eta (bin)");
1746  FormatRunHisto2D(hEJE1Map, Form("EJE1 FastORL1Amp %s", legend), "#varphi (bin)");
1747  if(hEJE1Map->GetEntries()>10)hEJE1Map->Draw("colz");
1748  c00T->cd(5);
1749 
1750  gPad->SetLogz();
1751  hEMC7Map->SetXTitle("#eta (bin)");
1752  FormatRunHisto2D(hEMC7Map, Form("EMC7 FastORL0Amp %s", legend), "#varphi (bin)");
1753  if(hEMC7Map->GetEntries()>10)hEMC7Map->Draw("colz");
1754  c00T->cd(6);
1755 
1756 
1757  TCanvas* c00TD = new TCanvas("Occupancy map DCAL", "Occupancy", 1000, 1000);
1758  // c00T->SetLogz();
1759  c00TD->SetFillColor(0);
1760  c00TD->SetBorderSize(0);
1761  c00TD->SetFrameBorderMode(0);
1762  c00TD->Divide(2,3);
1763 
1764  c00TD->cd(1);
1765  gPad->SetLogz();
1766 
1767  hDGA2Map->SetXTitle("#eta (bin)");
1768  hDGA2Map->SetTitle("DGA2FastORL1Accumulated ");
1769  FormatRunHisto2D(hDGA2Map, Form("DGA2 FastORL1Amp %s", legend), "#varphi (bin)");
1770  if(hDGA2Map->GetEntries()>10)hDGA2Map->Draw("colz");
1771 
1772 
1773  c00TD->cd(2);
1774  gPad->SetLogz();
1775  hDGA1Map->SetXTitle("#eta (bin)");
1776  hDGA1Map->SetTitle("DGA1 FastORL1Accumulated amplitudes");
1777  FormatRunHisto2D(hDGA1Map, Form("DGA1 FastORL1Amp %s", legend), "#varphi (bin)");
1778  if(hDGA1Map->GetEntries()>10)hDGA1Map->Draw("colz");
1779 
1780  c00TD->cd(3);
1781  gPad->SetLogz();
1782  hDJE2Map->SetXTitle("#eta (bin)");
1783  hDJE2Map->SetTitle("DJE2 FastORL1Accumulated amplitudes");
1784  FormatRunHisto2D(hDJE2Map, Form("DJE2 FastORL1Amp %s", legend), "#varphi (bin)");
1785  if(hDJE2Map->GetEntries()>10)hDJE2Map->Draw("colz");
1786 
1787  c00TD->cd(4);
1788  gPad->SetLogz();
1789  hDJE1Map->SetXTitle("#eta (bin)");
1790  hDJE1Map->SetTitle("DJE1 FastORL1Accumulated amplitudes");
1791  FormatRunHisto2D(hDJE1Map, Form("DJE1 FastORL1Amp %s", legend), "#varphi (bin)");
1792  if(hDJE1Map->GetEntries()>10)hDJE1Map->Draw("colz");
1793  c00TD->cd(5);
1794  gPad->SetLogz();
1795  hDMC7Map->SetXTitle("#eta (bin)");
1796  hDMC7Map->SetTitle("DMC7 FastORL1Accumulated amplitudes");
1797  FormatRunHisto2D(hDMC7Map, Form("DMC7 FastORL0Amp %s", legend), "#varphi (bin)");
1798  if(hDMC7Map->GetEntries()>10)hDMC7Map->Draw("colz");
1799 
1800 
1801 
1802 
1803  // hEMC7->Draw("same");
1804  // TLegend* lTM = new TLegend(0.123, 0.744, 0.933, 0.894);
1805  // lTM->SetNColumns((n+1)/2.);
1806  // lTM->SetFillColor(0);
1807  // lTM->SetBorderSize(0);
1808  // lTM->SetTextSize(0.04);
1809  // lTM->SetHeader(Form("Trigger in EMCAL %s (period %s) run %s",fCalorimeter.Data(),period.Data(),RunId));
1810 
1811  // lTM->Draw();
1812 
1813 
1814  // if(!hEGA2) {cout << "NO histo hEGA2"<<endl;
1815  // ret=-8;
1816  // continue;}
1817 
1818 
1819  Double_t EGA2;
1820 
1821  TCanvas* cT = new TCanvas("EMCTriggers", "EMCTriggers", 600, 600);
1822  cT->SetLogy();
1823  cT->SetFillColor(0);
1824  cT->SetBorderSize(0);
1825  cT->SetFrameBorderMode(0);
1826 
1827  hEGA2->SetLineColor(2);
1828  hEGA2->SetLineWidth(2);
1829  if(hEGA2->GetEntries()>0)hEGA2->Scale(1./hEGA2->GetEntries());
1830  hEGA2->GetXaxis()->SetTitle("(ADC counts)");
1831  hDGA2->GetXaxis()->SetTitle(" (ADC counts)");
1832 
1833  hEGA1->SetLineColor(3);
1834  hEGA1->SetLineWidth(2);
1835  if(hEGA1->GetEntries()>0)hEGA1->Scale(1./hEGA1->GetEntries());
1836  hEJE2->SetLineColor(4);
1837  hEJE2->SetLineWidth(2);
1838  if(hEJE2->GetEntries()>0) hEJE2->Scale(1./hEJE2->GetEntries());
1839  hEJE1->SetLineColor(7);
1840  hEJE1->SetLineWidth(2);
1841  if(hEJE1->GetEntries()>0) hEJE1->Scale(1./hEJE1->GetEntries());
1842  hEMC7->SetLineColor(6);
1843  hEMC7->SetLineWidth(2);
1844  if(hEMC7->GetEntries()>0) hEMC7->Scale(1./hEMC7->GetEntries());
1845 
1846  hDGA2->SetLineColor(2);
1847  hDGA2->SetLineWidth(2);
1848  if(hDGA2->GetEntries()>0)hDGA2->Scale(1./hDGA2->GetEntries());
1849  hDGA1->SetLineColor(3);
1850  hDGA1->SetLineWidth(2);
1851  if(hDGA1->GetEntries()>0) hDGA1->Scale(1./hDGA1->GetEntries());
1852  hDJE2->SetLineColor(4);
1853  hDJE2->SetLineWidth(2);
1854  if(hDJE2->GetEntries()>0) hDJE2->Scale(1./hDJE2->GetEntries());
1855  hDJE1->SetLineColor(7);
1856  hDJE1->SetLineWidth(2);
1857  if(hDJE1->GetEntries()>0) hDJE1->Scale(1./hDJE1->GetEntries());
1858  hDMC7->SetLineColor(6);
1859  hDMC7->SetLineWidth(2);
1860  if(hDMC7->GetEntries()>0) hDMC7->Scale(1./hDMC7->GetEntries());
1861 
1862  // FormatRunHisto(hClusterTimeEnergy, Form("Time vs. Energy%s", legend), "EMCal ToF (ns)");
1863  // AutoZoom(hClusterTimeEnergy, "maxx")->DrawCopy("colz");
1864 
1865  cT->Divide(1,2);
1866  cT->cd(1);
1867 
1868  const char* legend2="";
1869  legend2 = Form(" Run %d EMCalMaxPatchAmp ", (int)RunId);
1870  hEGA2->SetTitle(legend2);
1871  const char* legend3="";
1872 
1873  legend3 = Form(" Run %d DMCalMaxPatchAmp ", (int)RunId);
1874 
1875  hDGA2->SetTitle(legend3);
1876 
1877  hEGA2->GetXaxis()->SetRangeUser(0.,1000.);
1878  hEGA2->Draw();
1879  hEGA1->Draw("same");
1880  hEJE2->Draw("same");
1881  hEJE1->Draw("same");
1882  hEMC7->Draw("same");
1883  TLegend* lT = new TLegend(0.123, 0.744, 0.833, 0.894);
1884  lT->SetNColumns((n+1)/2.);
1885  lT->SetFillColor(0);
1886  lT->SetBorderSize(0);
1887  lT->SetTextSize(0.04);
1888  // lT->SetHeader(Form("Trigger in EMCAL (period %s) run %d",period.Data(),(int)run));
1889  lT->SetHeader(Form("Trigger in EMCAL (period %s)",period.Data()));
1890 
1891 
1892  lT->AddEntry(hEGA2," EGA2", "l");
1893  lT->AddEntry(hEGA1," EGA1", "l");
1894  lT->AddEntry(hEJE2," EJE2", "l");
1895  lT->AddEntry(hEJE1," EJE1", "l");
1896  lT->AddEntry(hEMC7," EMC7", "l");
1897  lT->Draw("same");
1898 
1899  cT->cd(2);
1900 
1901  hDGA2->GetXaxis()->SetRangeUser(0.,1000.);
1902  hDGA2->Draw();
1903  hDGA1->Draw("same");
1904  hDJE2->Draw("same");
1905  hDJE1->Draw("same");
1906  hDMC7->Draw("same");
1907  TLegend* lTD = new TLegend(0.123, 0.744, 0.833, 0.894);
1908  lTD->SetNColumns((n+1)/2.);
1909  lTD->SetFillColor(0);
1910  lTD->SetBorderSize(0);
1911  lTD->SetTextSize(0.04);
1912  lTD->SetHeader(Form("Trigger in DCAL (period %s)",period.Data()));
1913  //lTD->SetHeader(Form("Trigger in DCAL (period %s) run %d",period.Data(),(int)run));
1914 
1915 
1916  lTD->AddEntry(hDGA2," DGA2", "l");
1917  lTD->AddEntry(hDGA1," DGA1", "l");
1918  lTD->AddEntry(hDJE2," DJE2", "l");
1919  lTD->AddEntry(hDJE1," DJE1", "l");
1920  lTD->AddEntry(hDMC7," DMC7", "l");
1921  lTD->Draw("same");
1922 
1923 
1924 
1925  //
1926 
1927  // cout << "TTTTTTTTTTTTTTTTTTTTTTTTTTTTT TRIGGER TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" << endl;
1928  // EGA2 = hEGA2->GetMean();
1929 
1930  // cout << " EGA2 (ADC) " <<hEGA2->GetMaximum() << endl;
1931  // if(!hEGA2){
1932  if (hEGA2) ETrigMax[0] = hEGA2->GetMaximumBin()*16.;
1933  if (hEGA1) ETrigMax[1] = hEGA1->GetMaximumBin()*16.;
1934  if (hEJE2) ETrigMax[2] = hEJE2->GetMaximumBin()*16.;
1935  if (hEJE1) ETrigMax[3] = hEJE1->GetMaximumBin()*16.;
1936  if (hEMC7) ETrigMax[4] = hEMC7->GetMaximumBin()*16.;
1937 
1938  if (hDGA2) DTrigMax[0] = hDGA2->GetMaximumBin()*16.;
1939  if (hDGA1) DTrigMax[1] = hDGA1->GetMaximumBin()*16.;
1940  if (hDJE2) DTrigMax[2] = hDJE2->GetMaximumBin()*16.;
1941  if (hDJE1) DTrigMax[3] = hDJE1->GetMaximumBin()*16.;
1942  if (hDMC7) DTrigMax[4] = hDMC7->GetMaximumBin()*16.;
1943 
1944  TString outfilenameT = QAPATH + "Triggers" + fTrigger(r) + ".pdf" ;
1945  TString outfilename2T = QAPATH + "Triggers" + fTrigger(r) + ".png" ;
1946 
1947  if(SavePlots==2)
1948  cT->SaveAs(outfilenameT);
1949  if(SavePlots)
1950  cT->SaveAs(outfilename2T);
1951 
1952  fout->cd();
1953  fout->Cd(Form("%s/%s/%ld/%s/%s", period.Data(), pass.Data(), RunId, "RunLevelQA", fTrigger.Data()));
1954 
1955 
1956  cT->Write();
1957  delete cT;
1958 
1959  TString outfilename7 = QAPATH + "OccupancyMapTrigger" + fTrigger(r) + ".pdf" ;
1960  TString outfilename8= QAPATH + "OccupancyMapTrigger" + fTrigger(r) + ".png" ;
1961 
1962  if(SavePlots==2) c00T->SaveAs(outfilename7);
1963  if(SavePlots) c00T->SaveAs(outfilename8);
1964 
1965 
1966  TString outfilename5 = QAPATH + "OccupancyMapTriggerDCAL" + fTrigger(r) + ".pdf" ;
1967  TString outfilename6 = QAPATH + "OccupancyMapTriggerDCAL" + fTrigger(r) + ".png" ;
1968 
1969  if(SavePlots==2) c00TD->SaveAs(outfilename5);
1970  if(SavePlots) c00TD->SaveAs(outfilename6);
1971 
1972 
1973  }
1974  }
1975 
1976 
1977 
1978 
1979  tree->Fill();
1980 
1981  TString outfilename = QAPATH + "Pi0InvMassEMCAL" + fTrigger(r) + ".pdf";
1982  TString outfilename2 = QAPATH + "Pi0InvMassEMCAL" + fTrigger(r) + ".png";
1983  if(SavePlots==2)
1984  c2->SaveAs(outfilename);
1985  if(SavePlots)
1986  c2->SaveAs(outfilename2);
1987 
1988  outfilename = QAPATH + "Pi0InvMassSM" + fTrigger(r) + ".pdf";
1989  outfilename2 = QAPATH + "Pi0InvMassSM" + fTrigger(r) + ".png";
1990  if(SavePlots==2)
1991  c1->SaveAs(outfilename);
1992  if(SavePlots)
1993  c1->SaveAs(outfilename2);
1994  // cout<<"********************************** "<<n<<" **********************************"<<endl; // n = number of SMs
1995 
1996  if(fhIMDCAL){
1997  TString outfilename4 = QAPATH + "Pi0InvMassDCAL" + fTrigger(r) + ".pdf";
1998  TString outfilename5= QAPATH + "Pi0InvMassDCAL" + fTrigger(r) + ".png";
1999  if(SavePlots==2)
2000  c3->SaveAs(outfilename4);
2001  if(SavePlots)
2002  c3->SaveAs(outfilename5);
2003  }
2004 
2005  fout->cd();
2006  fout->Cd(Form("%s/%s/%ld/%s/%s", period.Data(), pass.Data(), RunId, "RunLevelQA", fTrigger.Data()));
2007 
2008  // Cell time distribution for each BC and SM
2009  if(hTimeSM_BC0) c_TimeSM_BC0->Write();
2010  if(hTimeSM_BC1) c_TimeSM_BC1->Write();
2011  if(hTimeSM_BC2) c_TimeSM_BC2->Write();
2012  if(hTimeSM_BC3) c_TimeSM_BC3->Write();
2013 
2014  // if ((pass.Contains("muon_calo")) && (fTrigger=="default")){
2015 
2016  cout << "ca marche la boucle !!!!!!!!!!!" << endl;
2017 
2018  // if(outputListEG2N){
2019  // c00T->Write();
2020  // c00TD->Write();
2021  // cT->Write();
2022  // }
2023  // }
2024 
2025 
2026  c2->Write();
2027  c1->Write();
2028  if(fhIMDCAL)c3->Write();
2029  // cT->Write();
2030 
2031  delete c1;
2032  delete c2;
2033 
2034  //delete c00T;
2035  // delete c00TD;
2036  // delete cT;
2037 
2038 
2039  if(fhIMDCAL) delete c3;
2040  if(hTimeSM_BC0) delete c_TimeSM_BC0;
2041  if(hTimeSM_BC1) delete c_TimeSM_BC1;
2042  if(hTimeSM_BC2) delete c_TimeSM_BC2;
2043  if(hTimeSM_BC3) delete c_TimeSM_BC3;
2044  if(outputList) outputList->Delete();
2045 
2046  QAData << RunId << " " << Nevent
2047  << "\n";
2048 
2049  QAData.close();
2050  }
2051 
2052  ftree->cd();
2053  tree->Write();
2054  ftree->Close();
2055 
2056  return ret;
2057 
2058 }
2059 
2060 //-------------------------------------------------------------------------
2061 TH2F* FormatRunHisto(TH2F* aHisto, const char* title, const char* YTitle){
2062 
2063  if(!aHisto){
2064  Error(__FUNCTION__, Form("The histogram with title \"%s\" was not found!", title));
2065  return new TH2F();
2066  }
2067 
2068  aHisto->SetStats(kFALSE);
2069  aHisto->SetTitle(title);
2070  aHisto->SetStats(kFALSE);
2071  aHisto->SetYTitle(YTitle);
2072  aHisto->GetYaxis()->SetTitleOffset(1.2);
2073  aHisto->GetYaxis()->SetLabelSize(0.03);
2074  aHisto->GetZaxis()->SetLabelSize(0.02);
2075 
2076  return aHisto;
2077 
2078 }
2079 //-------------------------------------------------------------------------
2080 TH2D* FormatRunHisto2D(TH2D* aHisto, const char* title, const char* YTitle){
2081 
2082  if(!aHisto){
2083  Error(__FUNCTION__, Form("The histogram with title \"%s\" was not found!", title));
2084  return new TH2D();
2085  }
2086 
2087  aHisto->SetStats(kFALSE);
2088  aHisto->SetTitle(title);
2089  aHisto->SetStats(kFALSE);
2090  aHisto->SetYTitle(YTitle);
2091  aHisto->GetYaxis()->SetTitleOffset(1.2);
2092  aHisto->GetYaxis()->SetLabelSize(0.03);
2093  aHisto->GetZaxis()->SetLabelSize(0.02);
2094 
2095  return aHisto;
2096 
2097 }
2098 
2099 //--------------------------------------------------------------------------------------------------------------
2100 TH2F* HistoPerMod(TH2F* hTmpPerMod, const char* title){
2101 
2102  if(!hTmpPerMod){
2103  Error(__FUNCTION__, Form("The histogram with title \"%s\" was not found!", title));
2104  return new TH2F();
2105  }
2106 
2107  hTmpPerMod->SetStats(kFALSE);
2108  hTmpPerMod->SetTitle(title);
2109  hTmpPerMod->SetTitleSize(0.1);
2110  hTmpPerMod->GetXaxis()->SetTitleOffset(1.1);
2111  hTmpPerMod->GetXaxis()->SetTitleSize(0.05);
2112  hTmpPerMod->GetXaxis()->SetLabelSize(0.06);
2113  hTmpPerMod->GetYaxis()->SetTitleOffset(1.1);
2114  hTmpPerMod->GetYaxis()->SetTitleSize(0.05);
2115  hTmpPerMod->GetYaxis()->SetLabelSize(0.06);
2116  hTmpPerMod->GetZaxis()->SetLabelSize(0.04);
2117 
2118  return hTmpPerMod;
2119 
2120 }
2121 
2122 //---------------------------------------------------------------------------------------------------
2123 TH2* AutoZoom(TH2* H, Option_t* aType, Int_t EntryMin){
2124 
2125  Int_t shiftX = (Int_t)(H->GetNbinsX()/30.);
2126  Int_t shiftY = (Int_t)(H->GetNbinsY()/30.);
2127 
2128  TString opt = aType;
2129  opt.ToLower();
2130 
2131  int minX = 0;
2132  int maxX = H->GetNbinsX();
2133  int New_minX = minX;
2134  int New_maxX = maxX;
2135 
2136  int minY = 0;
2137  int maxY = H->GetNbinsY();
2138  int New_minY = minY;
2139  int New_maxY = maxY;
2140 
2141  if(opt.Contains("all")) opt = TString("minx, maxx, miny, maxy");
2142 
2143  if(opt.Contains("maxx")){
2144  for(New_maxX = maxX;New_maxX >=minX; New_maxX--){
2145  Stat_t c = 0;
2146  for(int i_y = maxY; i_y >= minY;i_y--){
2147  c = H->GetBinContent(New_maxX, i_y);
2148  if(c>EntryMin)
2149  break;
2150  }
2151  if(c>EntryMin)
2152  break;
2153  }
2154  }
2155 
2156  if(opt.Contains("maxy")){
2157  for(New_maxY = maxY;New_maxY >=minY;New_maxY--){
2158  Stat_t c = 0;
2159  for(int i_x=maxX; i_x>=minX;i_x--){
2160  c = H->GetBinContent(i_x, New_maxY );
2161  if(c>EntryMin)
2162  break;
2163  }
2164  if(c>EntryMin)
2165  break;
2166  }
2167  }
2168 
2169  if(opt.Contains("minx")){
2170  for(New_minX = minX;New_minX <=maxX; New_minX++){
2171  Stat_t c = 0;
2172  for(int i_y = minY; i_y <= maxY;i_y++){
2173  c = H->GetBinContent(New_minX, i_y);
2174  if(c>EntryMin)
2175  break;
2176  }
2177  if(c>EntryMin)
2178  break;
2179  }
2180  }
2181 
2182  if(opt.Contains("miny")){
2183  for(New_minY = minY;New_minY <=maxY;New_minY++){
2184  Stat_t c = 0;
2185  for(int i_x=minX; i_x<=maxX;i_x++){
2186  c = H->GetBinContent(i_x, New_minY );
2187  if(c>EntryMin)
2188  break;
2189  }
2190  if(c>EntryMin)
2191  break;
2192  }
2193  }
2194 
2195  if(New_maxX!=-1 && New_maxY!=-1)
2196  H->GetXaxis()->SetRange(New_minX - shiftX, New_maxX + shiftX);
2197  if(New_maxX!=-1 && New_maxY!=-1)
2198  H->GetYaxis()->SetRange(New_minY - shiftY, New_maxY + shiftY);
2199 
2200  return H;
2201 
2202 }
2203 
2204 //----------------------------------------------------------------------------------------------------
2205 int FindNumberOfSM(TFile* f, TString fTrigger, TString period){
2206 
2207  TString direct;
2208  if(!fTrigger.Contains("QA")){
2209  direct = "CaloQA_";
2210  }
2211  direct += fTrigger;
2212 
2213  Int_t nSMt=-1;
2214  Int_t year = 2000 + TString(period(3, 2)).Atoi();
2215  if ( year == 2010 ) { nSMt=4; }
2216  else if( year == 2011 || year == 2012 ){ nSMt=10; }
2217  else if( year == 2013 || year == 2014 ){ nSMt=12; }
2218  else { nSMt=20; }
2219 
2220  TList *outputList;
2221  Bool_t dirok = f->cd(direct);
2222 
2223  // ////
2224  // cout << "==============================================================" << endl;
2225  // cout << "direct = " << direct << endl;
2226  // cout << "dirok = " << dirok << endl;
2227  // cout << "==============================================================" << endl;
2228  // ////
2229 
2230  if(!dirok)
2231  Error(__FUNCTION__, Form("No input directory %s, the number SMs will be returned based on the year!", direct.Data()));
2232  else
2233  outputList = (TList*)gDirectory->Get(direct);
2234 
2235  if(!outputList)
2236  Error(__FUNCTION__, "No input list, the number SMs will be returned based on the year! ");
2237  else{
2238  outputList->SetOwner();
2239  TH2F* hNSM =(TH2F *)outputList->FindObject("EMCAL_hE_Mod");
2240  if(!hNSM || (!hNSM->GetEntries()))
2241  Error(__FUNCTION__, "hNSM Histogram not found or it is empty, the number SMs will be returned based on the year!");
2242  else
2243  nSMt = hNSM->GetYaxis()->GetBinUpEdge(hNSM->FindLastBinAbove(0, 2));
2244  }
2245 
2246  if(outputList)
2247  outputList->Delete();
2248 
2249  return nSMt;
2250 
2251 }
TH2F * FormatRunHisto(TH2F *aHisto, const char *title, const char *YTitle="")
const char * filename
Definition: TestFCM.C:1
double Double_t
Definition: External.C:58
TString QAPATH
Definition: External.C:236
TH2D * FormatRunHisto2D(TH2D *aHisto, const char *title, const char *YTitle="")
const char * title
Definition: MakeQAPdf.C:27
energy
Definition: HFPtSpectrum.C:44
TSystem * gSystem
Int_t DrawOccupancy(Long_t run, TString period, TString pass, TString fTrigger, TString system, TFile *f, TFile *fout, AliEMCALGeometry *geom, Int_t SavePlots)
TCanvas * c
Definition: TestFitELoss.C:172
int FindNumberOfSM(TFile *f, TString fTrigger, TString period)
Double_t pi0massP1(Double_t *x, Double_t *par)
Double_t pi0massP2(Double_t *x, Double_t *par)
Int_t DrawRun(Long_t run, TString period, TString pass, TString fTrigger, TFile *f, TFile *fout, Int_t SavePlots, Int_t nSM, Bool_t kFilter)
TString QAPATHF
int Int_t
Definition: External.C:63
Int_t TrendingEMCALTree(Long_t RunId, TString fCalorimeter, TString system, TString period, TString pass, const int n, TList *TriggersList, TFile *f, TFile *fout, Int_t SavePlots)
Definition: External.C:228
Definition: External.C:212
TH2 * AutoZoom(TH2 *H, Option_t *aType="all", Int_t EntryMin=0)
void set_plot_style()
TH2F * HistoPerMod(TH2F *name, const char *title)
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
Definition: External.C:220
Double_t fitE(Double_t *x, Double_t *par)
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53
TFile * fout
input train file
int CreateEMCALRunQA(const char *filename, TString RunId, TString period, TString pass, Int_t SavePlots=0, Bool_t filter=0, TString fTrigger="", TString system="", TString fCalorimeter="EMCAL")