AliPhysics  v5-06-21-01 (1eac791)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
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 <TH2F.h>
11 #include <TCanvas.h>
12 #include <TGraphErrors.h>
13 #include <TLegend.h>
14 #include <TTree.h>
15 #include <TPRegexp.h>
16 #include <TList.h>
17 #include <TObjString.h>
18 #include <TDatime.h>
19 #include <TError.h>
20 #include <AliLog.h>
21 #endif
22 
36 
37 Int_t DrawOccupancy(Long_t run, TString period, TString pass, TString fTrigger, TString system, TFile* f, TFile* fout, AliEMCALGeometry* geom, Int_t SavePlots);
38 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);
39 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);
40 
41 TH2F* FormatRunHisto(TH2F* aHisto,const char* title,const char* YTitle="");
42 TH2F* HistoPerMod(TH2F* name,const char* title);
43 TH2F* AutoZoom(TH2F* H,Option_t* aType="all", Int_t EntryMin=0);
44 int FindNumberOfSM(TFile* f, TString fTrigger,TString period);
45 
46 TString QAPATH;
47 TString QAPATHF = "./";
48 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
50 {
51  const Int_t NRGBs = 5;
52  const Int_t NCont = 255;
53 
54  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
55  Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
56  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
57  Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
58  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
59  gStyle->SetNumberContours(NCont);
60 
61 }
62 
63 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
64 Double_t pi0massP2(Double_t *x, Double_t *par)
65 {
66  Double_t gaus;
67 
68  if (par[2] != 0.) gaus = par[0] * TMath::Exp( -(x[0]-par[1])*(x[0]-par[1]) / (2*par[2]*par[2]) );
69 
70  else gaus = 99999999.;
71 
72  Double_t back = par[3] + par[4]*x[0] + par[5]*x[0]*x[0];
73 
74  return gaus+back;
75 
76 }
77 
78 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
79 Double_t pi0massP1(Double_t *x, Double_t *par)
80 {
81  Double_t gaus = par[0] * TMath::Exp( -(x[0]-par[1])*(x[0]-par[1]) / (2*par[2]*par[2]) );
82 
83  Double_t back = par[3] + par[4]*x[0];
84 
85  return gaus+back;
86 
87 }
88 
89 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
90 Double_t fitE(Double_t *x, Double_t *par)
91 {
92 
93  Double_t levy;
94 
95  levy = par[0] * TMath::Exp( -par[1]/x[0]) * TMath::Power(x[0], -par[2]) ;
96 
97  return levy;
98 }
99 
100 //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
101 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")
102 {
103 
104  QAPATH = TString(gSystem->Getenv("QAPATH"));
105  if(QAPATH.IsNull()) QAPATH = QAPATHF;
106  if(! QAPATH.BeginsWith("./")) { QAPATH = QAPATH + RunId + "/";}
107 
108  AliLog::SetGlobalLogLevel(AliLog::kError);
109  TFile *f = new TFile(filename);
110  AliLog::SetGlobalLogLevel(AliLog::kInfo);
111 
112  if (f->IsZombie()) {Error(__FUNCTION__,Form("Error openning the input file %s",filename)); return -1;}
113 
114  TList* TriggersList = new TList();
115 
116  if (fTrigger=="")
117  {
118  TPMERegexp name_re("CaloQA_\\w+");
119  TObjLink* link = f->GetListOfKeys()->FirstLink();
120 
121  while (link)
122  {
123  TString name = link->GetObject()->GetName();
124  if (name_re.Match(name))
125  {
126  TriggersList->Add(link->GetObject());
127  if(TString(filename).Contains("barrel") && ! name.Contains("default")) TriggersList->Remove(link->GetObject());
128  if(TString(filename).Contains("outer") && ! name.Contains("EMC")) TriggersList->Remove(link->GetObject());
129  }
130  link = link->Next();
131  }
132  } else {TriggersList->Add(new TObjString(fTrigger.Data()));}
133 
134  if(!TriggersList->GetEntries()) {Error(__FUNCTION__,"No trigger found!"); return -2;}
135 
136  int nSM = FindNumberOfSM(f,((TObjString*)TriggersList->Last())->GetString(),period);
137  if (nSM<0) {Error(__FUNCTION__,"Could not find the number of super modules!"); return -3;}
138  Info(__FUNCTION__,Form("%i super modules were discuvered",nSM));
139  TString GeomName;
140  if (nSM <= 6) { nSM=6; GeomName = "EMCAL_FIRSTYEARv1";}
141  else if (nSM <= 10) { nSM=10; GeomName = "EMCAL_COMPLETEv1";}
142  else if (nSM <= 12) { nSM=12; GeomName = "EMCAL_COMPLETE12SMv1";}
143  else {nSM = 20; GeomName = "EMCAL_COMPLETE12SMv1_DCAL_8SM";}
144 
145  AliEMCALGeometry *geom = new AliEMCALGeometry(GeomName.Data(),"EMCAL");
146  Info(__FUNCTION__,Form("Using %i super modules and the Geometry %s",nSM,GeomName.Data()));
147 
148  TFile *fout = new TFile(TString( QAPATH + period+"_"+pass + fTrigger+"_"+ (Long_t)RunId.Atoi() +"_QAplots.root").Data(),"RECREATE");
149 
150  if((system.IsNull()) && (period.EndsWith("h"))) {system = "PbPb";}
151 
152  Int_t ret=0;
153  TIter next(TriggersList);
154  while (TObject *obj = next())
155  {
156  fTrigger= TString(obj->GetName());
157  ret -= DrawOccupancy(RunId.Atoi(),period,pass,fTrigger,system,f,fout,geom,SavePlots);
158  ret -= DrawRun(RunId.Atoi(),period,pass,fTrigger,f,fout,SavePlots,nSM,filter);
159  }
160  ret-= TrendingEMCALTree(RunId.Atoi(),fCalorimeter,system,period,pass,nSM,TriggersList,f,fout,SavePlots);
161 
162  f->Close();
163  fout->Close();
164  delete f;
165  delete geom;
166 
167  return ret;
168 }
169 
170 //----------------------------------------------------------------------------------------------------------------------------------------------------------
171 Int_t DrawOccupancy(Long_t run , TString period, TString pass, TString fTrigger,TString system, TFile* f,TFile* fout, AliEMCALGeometry* geom, Int_t SavePlots)
172 {
173 
174  set_plot_style();
175  gStyle->SetOptStat(0);
176  TH1::AddDirectory(kFALSE);
177  TH2D *hEnergyMapReal = new TH2D("hEnergyMapReal","",96,-48,48,120,-0,120);
178  TH2D *hOccupancyMapReal = new TH2D("hOccupancyMapReal","",96,-48,48,120,-0,120);
179  hEnergyMapReal->SetXTitle("eta (bin)");
180  hEnergyMapReal->SetYTitle("phi (bin)");
181  hEnergyMapReal->SetZTitle("E(GeV)/event");
182  hEnergyMapReal->GetYaxis()->SetTitleOffset(1.2);
183  hEnergyMapReal->GetZaxis()->SetLabelSize(0.02);
184  hEnergyMapReal->GetZaxis()->SetTitleOffset(1.36);
185 
186  hOccupancyMapReal->SetXTitle("eta (bin)");
187  hOccupancyMapReal->SetYTitle("phi (bin)");
188  hOccupancyMapReal->GetYaxis()->SetTitleOffset(1.2);
189  hOccupancyMapReal->GetZaxis()->SetLabelSize(0.02);
190 
191  Int_t nSupMod, nModule, nIphi, nIeta;
192  Int_t iphi, ieta;
193  Int_t realbineta=0;
194  Int_t realbinphi=0;
195 
196  //NO MASK
197  Int_t mask[1] = {2222222};
198 
199  TH2F *hCellAmplitude;
200  TH1F *hNEvents;
201  Int_t Events;
202  Int_t n=0;
203 
204  TString direct;
205  if(!fTrigger.Contains("QA")) {
206  direct = "CaloQA_";
207  }
208  direct += fTrigger;
209  Bool_t dirok = f->cd(direct);
210  if (!dirok) { Error(__FUNCTION__,Form("No input drectory %s",direct.Data())); return -1;}
211  TList *outputList = (TList*)gDirectory->Get(direct);
212  if(!outputList){ Error(__FUNCTION__,"No input list! "); return -1;}
213  outputList->SetOwner();
214 
215  fout->mkdir(Form("%s/%s/%ld/%s/%s",period.Data(),pass.Data(),run,"RunLevelQA",fTrigger.Data()));
216  fout->cd();
217  fout->Cd(Form("%s/%s/%ld/%s/%s",period.Data(),pass.Data(),run,"RunLevelQA",fTrigger.Data()));
218 
219  hNEvents =(TH1F *)outputList->FindObject("hNEvents");
220  if(!hNEvents){ Error(__FUNCTION__,Form("hNEvent histogram not found for trigger %s ",fTrigger.Data())); return -2;}
221  Events = (Int_t)hNEvents->GetEntries();
222  if(Events==0){ Error(__FUNCTION__,Form("No event in trigger %s",fTrigger.Data())); return -3;}
223 
224  Double_t Eth=1;
225  if(system=="PbPb"){
226  Eth = 5.;
227  if (fTrigger.Contains("EMC")) Eth=20.;
228  }
229  if(system=="pp"){
230  Eth = 1.;
231  if (fTrigger.Contains("EMC")) Eth=5.;
232  }
233 
234  hCellAmplitude =(TH2F *)outputList->FindObject("EMCAL_hAmpId");
235 
236  for(Int_t i = 0; i < geom->GetNCells() ; i++){
237  Double_t Esum = 0;
238  Double_t Nsum = 0;
239 
240  for (Int_t j = 1; j <= hCellAmplitude->GetNbinsX(); j++)
241  {
242  Double_t E = hCellAmplitude->GetXaxis()->GetBinCenter(j);
243  Double_t N = hCellAmplitude->GetBinContent(j, i+1);
244 
245  if (E < 0.3) continue;
246 
247  if (E <= Eth) {
248  Esum += E*N;
249  Nsum += N;
250  }
251  }
252 
253  Int_t absId = i;
254  if(n!=0) {if(mask[n]<=mask[n-1]) Warning(__FUNCTION__,"The list of bad cells is not sorted !!");}
255  if(i==mask[n]){n++ ; continue; } // skip bad cells
256 
257  geom->GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
258  geom->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
259 
260  realbinphi = 120-(nSupMod/2)*24 -iphi -1; //
261  if (nSupMod%2==0) realbineta= 48-ieta -1;
262  if (nSupMod%2==1) realbineta= -ieta -1;
263 
264  hEnergyMapReal->Fill(realbineta,realbinphi,Esum/(Double_t)Events);
265  hOccupancyMapReal->Fill(realbineta,realbinphi,Nsum/(Double_t)Events);
266  }
267 
268  cout <<" Run: " << run << " trigger: " << fTrigger << " N_events: "<<Events<<endl;
269 
270  TPMERegexp r("_\\w+");
271  TString Energy; Energy = QAPATH + "MapEnergy" + fTrigger(r) + ".pdf";
272  TString Energy2; Energy2 = QAPATH + "MapEnergy" + fTrigger(r) + ".png";
273  TString Entries; Entries = QAPATH + "MapEntries" + fTrigger(r) + ".pdf";
274  TString Entries2; Entries2 = QAPATH + "MapEntries" + fTrigger(r) + ".png";
275 
276  TCanvas *c1 = new TCanvas("Energymap","Energy Map",600,600);
277  c1->SetFillColor(0);
278  c1->SetGrid();
279  c1->SetRightMargin(0.14);
280  TString title = "run ";
281  title += run ;
282  if(fTrigger.Contains("EMC")) { title += " EMC ";} else {title += " MB ";}
283  title += " Summed energy map";
284  hEnergyMapReal->SetTitle(title);
285  hEnergyMapReal->DrawCopy("colz");
286  if(SavePlots==2) c1->SaveAs(Energy);
287  if(SavePlots) c1->SaveAs(Energy2);
288  c1->Write();
289  delete c1;
290 
291 
292  TCanvas *c2 = new TCanvas("Occupancy","Occupancy Map",600,600);
293  c2->SetFillColor(0);
294  c2->SetGrid();
295  c2->SetRightMargin(0.14);
296  TString title2 = "run ";
297  title2 += run ;
298  if(fTrigger.Contains("EMC")) { title2 += " EMC ";} else { title2 += " MB ";}
299  title2 += " Occupancy map";
300  hOccupancyMapReal->SetTitle(title2);
301  hOccupancyMapReal->DrawCopy("colz");
302  if(SavePlots==2) c2->SaveAs(Entries);
303  if(SavePlots) c2->SaveAs(Entries2);
304  c2->Write();
305  delete c2;
306 
307  if (outputList) {outputList->Delete();}
308 
309  delete hEnergyMapReal;
310  delete hOccupancyMapReal;
311 
312  return 0;
313 }
314 
315 //-----------------------------------------------------------------------------------------------------------------------
316 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)
317 {
318 
319  TString direct;
320  if(!fTrigger.Contains("QA")) {
321  direct = "CaloQA_";
322  }
323  direct += fTrigger;
324 
325  f->cd(direct);
326  if(!direct) { Error(__FUNCTION__,Form("No input directory %s",direct.Data())); return -1;}
327  TList *outputList = (TList*)gDirectory->Get(direct);
328  if(!outputList){ Error(__FUNCTION__,Form("No input list! %s",direct.Data())); return -2;}
329  outputList->SetOwner();
330  if (kFilter)
331  {
332  fout->mkdir(Form("%s/%s/%ld/%s",period.Data(),pass.Data(),run,fTrigger.Data()));
333  fout->cd();
334  fout->Cd(Form("%s/%s/%ld/%s",period.Data(),pass.Data(),run,fTrigger.Data()));
335  outputList->Write();
336  }
337  fout->cd();
338  fout->Cd(Form("%s/%s/%ld/%s/%s",period.Data(),pass.Data(),run,"RunLevelQA",fTrigger.Data()));
339 
340 
341  set_plot_style();
342  gStyle->SetPalette(1);
343  TH1::AddDirectory(kFALSE);
344  TString outfilename;
345  TString outfilename2;
346  const char* legend="";
347  TPMERegexp r("_\\w+");
348 
349  if (fTrigger.Contains("EMC")){ legend = Form(" Run %d EMC ",(int)run);}
350  else legend = Form(" Run %d MB ",(int)run);
351 
352  TH1F* hNEvents =(TH1F *)outputList->FindObject("hNEvents");
353  if(!hNEvents){ Error(__FUNCTION__,Form("hNEvent histogram not found for trigger %s ",fTrigger.Data())); return -3;}
354  Int_t Events = (Int_t)hNEvents->GetEntries();
355  if(Events==0){ Error(__FUNCTION__,Form("No event in trigger %s",fTrigger.Data())); return -4 ;}
356 
357  TCanvas* c1 = new TCanvas("TimeVsE", "Cluster Time Vs Energy", 600, 600);
358  c1->SetLogz();
359  c1->SetFillColor(0);
360  c1->SetBorderSize(0);
361  c1->SetFrameBorderMode(0);
362 
363  TH2F* hClusterTimeEnergy =(TH2F *)outputList->FindObject("EMCAL_hClusterTimeEnergy");
364  if(!hClusterTimeEnergy) { Error(__FUNCTION__,Form("EMCAL_hClusterTimeEnergy: Histogram for trigger %s not found!",fTrigger.Data())); return -5;}
365  FormatRunHisto(hClusterTimeEnergy,Form("Time Vs Energy%s",legend),"EMCAL ToF(ns)");
366 
367  AutoZoom(hClusterTimeEnergy,"maxx")->DrawCopy("colz");
368  outfilename = QAPATH + "TimeRun" + fTrigger(r) + ".pdf" ;
369  outfilename2 = QAPATH + "TimeRun" + fTrigger(r) + ".png" ;
370 
371  if(SavePlots==2) c1->SaveAs(outfilename);
372  if(SavePlots) c1->SaveAs(outfilename2);
373  c1->Write();
374  delete c1;
375 
376  TCanvas * c2 = new TCanvas("ClusterVsTrack ","Correlation calo Mult Vs Track Multiplicity", 600, 600);
377  c2->SetLogz();
378  c2->SetFillColor(0);
379  c2->SetBorderSize(0);
380  c2->SetFrameBorderMode(0);
381 
382  TH2F* hClusterVsTrack =(TH2F *)outputList->FindObject("EMCAL_hCaloTrackMNClusters");
383  FormatRunHisto(hClusterVsTrack,Form("N cluster Vs N track%s",legend));
384 
385  AutoZoom(hClusterVsTrack,"maxx,maxy",1)->DrawCopy("colz");
386  outfilename = QAPATH + "CaloTrackMult" + fTrigger(r) + ".pdf";
387  outfilename2 = QAPATH + "CaloTrackMult" + fTrigger(r) + ".png";
388  if(SavePlots==2) c2->SaveAs(outfilename);
389  if(SavePlots) c2->SaveAs(outfilename2);
390  c2->Write();
391  delete c2;
392 
393  TCanvas* c3 = new TCanvas("ClusterEVsTrack ","Correlation E calo Vs Track Multiplicity", 600, 600);
394  c3->SetLogz();
395  c3->SetFillColor(0);
396  c3->SetBorderSize(0);
397  c3->SetFrameBorderMode(0);
398 
399  TH2F* hClusterEVsTrack =(TH2F*)outputList->FindObject("EMCAL_hCaloTrackMEClusters");
400  FormatRunHisto(hClusterEVsTrack,Form("Sum E cluster Vs N track%s",legend));
401 
402  AutoZoom(hClusterEVsTrack,"maxx,maxy",1)->DrawCopy("colz");
403  outfilename = QAPATH + "ETrackMult" + fTrigger(r) + ".pdf";
404  outfilename2 = QAPATH + "ETrackMult" + fTrigger(r) + ".png";
405  if(SavePlots==2) c3->SaveAs(outfilename);
406  if(SavePlots) c3->SaveAs(outfilename2);
407  c3->Write();
408  delete c3;
409 
410  TCanvas* c4 = new TCanvas("ClusterEVsV0 ","Correlation E calo Vs V0 signal", 600, 600);
411  c4->SetLogz();
412  c4->SetFillColor(0);
413  c4->SetBorderSize(0);
414  c4->SetFrameBorderMode(0);
415 
416  TH2F* hClusterEVsV0S =(TH2F*)outputList->FindObject("EMCAL_hCaloV0SEClusters");
417  FormatRunHisto(hClusterEVsV0S,Form("Sum E cluster Vs V0 signal%s",legend));
418 
419  AutoZoom(hClusterEVsV0S,"maxx,maxy",1)->DrawCopy("colz");
420  outfilename = QAPATH +"EVsV0s" + fTrigger(r) + ".pdf";
421  outfilename2 = QAPATH +"EVsV0s" + fTrigger(r) + ".png";
422  if(SavePlots==2) c4->SaveAs(outfilename);
423  if(SavePlots) c4->SaveAs(outfilename2);
424  c4->Write();
425  delete c4;
426 
427  TCanvas* c5 = new TCanvas("CellsperCluster","Nb of cells per cluster for each SM", 600, 600);
428  c5->SetLogz();
429  c5->SetFillColor(0);
430  c5->SetBorderSize(0);
431  c5->SetFrameBorderMode(0);
432  Bool_t mod3=0; if (nSM%3) mod3=1;
433  c5->Divide(3,(nSM/3)+mod3);
434 
435  for (int ism = 0; ism < nSM; ism++)
436  {
437  c5->cd(ism+1);
438  gPad->SetLogz();
439  if(TString(Form("Nb of cells per cluster%s Mod %d",legend,ism)).Length() > 60) { Error(__FUNCTION__,"Title too long!"); return -6;}
440  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");
441  }
442 
443  outfilename = QAPATH + "CellsperClusterSM" + fTrigger(r) + ".pdf";
444  outfilename2 = QAPATH + "CellsperClusterSM" + fTrigger(r) + ".png";
445  if(SavePlots==2) c5->SaveAs(outfilename);
446  if(SavePlots) c5->SaveAs(outfilename2);
447  c5->Write();
448  delete c5;
449 
450  if (outputList) outputList->Delete();
451 
452  return 0;
453 }
454 
455 //----------------------------------------------------------------------------------------------------------------------------------
456 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)
457 {
458 
459  TString fTrigger="";
460  TString aCalorimeter;
461  if (n<=12) {aCalorimeter = fCalorimeter;} else {aCalorimeter = TString("EMCAL_and_DCAL");}
462  TDatime now;
463 
464  Double_t Nevent=0 ;
465  Double_t xe=0.5;
466 
467  Double_t CellMean=0;
468  Double_t CellRMS=0;
469  Double_t ClusterMean=0;
470  Double_t ClusterRMS=0;
471  Double_t EtotalMean=0;
472  Double_t EtotalRMS=0;
473 
474  Double_t CellPerClusterMean=0; //
475  Double_t CellPerClusterRMS=0; //
476 
477  Double_t mPDG = 134.9766;
478  Double_t Npi0=0;
479  Double_t Npi0Err=0;
480  Double_t MeanPos=0;
481  Double_t MeanPosErr=0;
482  Double_t Width=0;
483  Double_t WidthErr=0;
484  Double_t Chi2NdfPi0=0;
485  Double_t Ngg=0;
486  Double_t NggErr=0;
487  Double_t Signif=0; // !S/(S+B)
488  Double_t SignifErr=0; // !S/(S+B)
489 
490  TFile* ftree = new TFile(Form("%s/trending.root",QAPATH.Data()),"RECREATE");
491 
492  TTree *tree = new TTree("trending","Trending QA Tree");
493  tree->Branch("fDate",&now);
494  tree->Branch("fCalorimeter",&aCalorimeter);
495  tree->Branch("system",&system);
496  tree->Branch("period",&period);
497  tree->Branch("pass",&pass);
498  tree->Branch("fTrigger",&fTrigger);
499  tree->Branch("run",&RunId,"run/I");
500  tree->Branch("xe",&xe,"xe/D");
501 
502  tree->Branch("Nevent",&Nevent,"Nevent/D");
503  tree->Branch("CellMean",&CellMean,"CellMean/D");
504  tree->Branch("CellRMS",&CellRMS,"CellRMS/D");
505  tree->Branch("ClusterMean",&ClusterMean,"ClusterMean/D");
506  tree->Branch("ClusterRMS",&ClusterRMS,"ClusterRMS/D");
507  tree->Branch("EtotalMean",&EtotalMean,"EtotalMean/D");
508  tree->Branch("EtotalRMS",&EtotalRMS,"EtotalRMS/D");
509 
510  tree->Branch("CellPerClusterMean",&CellPerClusterMean,"CellPerClusterMean/D"); //
511  tree->Branch("CellPerClusterRMS",&CellPerClusterRMS,"CellPerClusterRMS/D"); //
512 
513  tree->Branch("Npi0",&Npi0,"Npi0/D");
514  tree->Branch("Npi0Err",&Npi0Err,"Npi0Err/D");
515  tree->Branch("MeanPos",&MeanPos,"MeanPos/D");
516  tree->Branch("MeanPosErr",&MeanPosErr,"MeanPosErr/D");
517  tree->Branch("Width",&Width,"Width/D");
518  tree->Branch("WidthErr",&WidthErr,"WidthErr/D");
519  tree->Branch("Chi2NdfPi0",&Chi2NdfPi0,"Chi2NdfPi0/D");
520  tree->Branch("Ngg",&Ngg,"Ngg/D");
521  tree->Branch("NggErr",&NggErr,"NggErr/D");
522  tree->Branch("Signif",&Signif,"Signif/D");
523  tree->Branch("SignifErr",&SignifErr,"SignifErr/D");
524 
525  tree->Branch("nSM",&n,"nSM/I");
526 
527  int nMax = 22;
528  Double_t CellMeanSM[nMax];
529  Double_t CellRMSSM[nMax];
530  Double_t ClusterMeanSM[nMax];
531  Double_t ClusterRMSSM[nMax];
532  Double_t EtotalMeanSM[nMax]; //mean total energy deposited per event
533  Double_t EtotalRMSSM[nMax];
534  Double_t CellPerClusterMeanSM[nMax];
535  Double_t CellPerClusterRMSSM[nMax];
536  Double_t ECell1MeanSM[nMax]; //total energy deposited per event without 1 cell clusters
537  Double_t ECell1RMSSM[nMax];
538 
539  Double_t MeanPosSM[nMax];
540  Double_t MeanPosErrSM[nMax];
541  Double_t WidthSM[nMax];
542  Double_t WidthErrSM[nMax];
543  Double_t Npi0SM[nMax];
544  Double_t Npi0ErrSM[nMax];
545 
546  tree->Branch("CellMeanSM",CellMeanSM,TString::Format("CellMeanSM[%i]/D",nMax));
547  tree->Branch("CellRMSSM",CellRMSSM,TString::Format("CellRMSSM[%i]/D",nMax));
548  tree->Branch("ClusterMeanSM",ClusterMeanSM,TString::Format("ClusterMeanSM[%i]/D",nMax));
549  tree->Branch("ClusterRMSSM",ClusterRMSSM,TString::Format("ClusterRMSSM[%i]/D",nMax));
550  tree->Branch("EtotalMeanSM",EtotalMeanSM,TString::Format("EtotalMeanSM[%i]/D",nMax));
551  tree->Branch("EtotalRMSSM",EtotalRMSSM,TString::Format("EtotalRMSSM[%i]/D",nMax));
552  tree->Branch("CellPerClusterMeanSM",CellPerClusterMeanSM,TString::Format("CellPerClusterMeanSM[%i]/D",nMax));
553  tree->Branch("CellPerClusterRMSSM",CellPerClusterRMSSM,TString::Format("CellPerClusterRMSSM[%i]/D",nMax));
554  tree->Branch("ECell1MeanSM",ECell1MeanSM,TString::Format("ECell1MeanSM[%i]/D",nMax));
555  tree->Branch("ECell1RMSSM",ECell1RMSSM,TString::Format("ECell1RMSSM[%i]/D",nMax));
556 
557  tree->Branch("MeanPosSM",MeanPosSM,TString::Format("MeanPosSM[%i]/D",nMax));
558  tree->Branch("MeanPosErrSM",MeanPosErrSM,TString::Format("MeanPosErrSM[%i]/D",nMax));
559  tree->Branch("WidthSM",WidthSM,TString::Format("WidthSM[%i]/D",nMax));
560  tree->Branch("WidthErrSM",WidthErrSM,TString::Format("WidthErrSM[%i]/D",nMax));
561  tree->Branch("Npi0SM",Npi0SM,TString::Format("Npi0SM[%i]/D",nMax));
562  tree->Branch("Npi0ErrSM",Npi0ErrSM,TString::Format("Npi0ErrSM[%i]/D",nMax));
563 
564  TF1* fitMass = new TF1("fitMass",pi0massP2,100,250,6);
565  fitMass->SetParName(0,"A");
566  fitMass->SetParName(1,"m_{0}");
567  fitMass->SetParName(2,"sigma");
568  fitMass->SetParName(3,"a_{0}");
569  fitMass->SetParName(4,"a_{1}");
570  fitMass->SetParName(5,"a_{2}");
571  fitMass->SetParLimits(0, 1.e-5,1.e5);
572  fitMass->SetParLimits(1, 0.11, 0.16); //
573  fitMass->SetParLimits(2, 0.001,0.06);
574 
575  TList* outputList;
576 
577  TH1F* fhNEvents;
578  TH1F* fhE;
579  TH1F* fhNClusters = 0x0;
580  TH1F* fhNCells = 0x0;
581 
582  TH1F* NCells[n];
583  TH1F* NClusters[n];
584  TH2F* NCellsPerCluster[n];
585  TH1F* E[n];
586 
587  TH2F* fhIM ;
588  TH1F* fhMgg;
589  TH2F* IM[n];
590  TH1F* MggSM[n];
591 
592  TPMERegexp r("_\\w+");
593  TIter next(TriggersList);
594  int ret = 0;
595  while (TObject *obj = next())
596  {
597  fTrigger= TString(obj->GetName());
598  TString namefile = QAPATH + period + "_" + pass + fTrigger(r).Data() + "_" + RunId + "_data.txt";
599  ofstream QAData(namefile, ios::app); // write checks at the end
600 
601  Npi0=0;
602  Npi0Err=0;
603  MeanPos=0;
604  MeanPosErr=0;
605  Width=0;
606  WidthErr=0;
607  Chi2NdfPi0=0;
608  Ngg=0;
609  NggErr=0;
610  Signif=0;
611  SignifErr=0;
612 
613  memset (CellMeanSM, 0, sizeof (Double_t) * nMax);
614  memset (CellRMSSM, 0, sizeof (Double_t) * nMax);
615  memset (ClusterMeanSM, 0, sizeof (Double_t) * nMax);
616  memset (ClusterRMSSM, 0, sizeof (Double_t) * nMax);
617  memset (EtotalMeanSM, 0, sizeof (Double_t) * nMax);
618  memset (EtotalRMSSM, 0, sizeof (Double_t) * nMax);
619  memset (CellPerClusterMeanSM, 0, sizeof (Double_t) * nMax);
620  memset (CellPerClusterRMSSM, 0, sizeof (Double_t) * nMax);
621  memset (ECell1MeanSM, 0, sizeof (Double_t) * nMax);
622  memset (ECell1RMSSM, 0, sizeof (Double_t) * nMax);
623 
624  memset (MeanPosSM, 0, sizeof (Double_t) * nMax);
625  memset (MeanPosErrSM, 0, sizeof (Double_t) * nMax);
626  memset (WidthSM, 0, sizeof (Double_t) * nMax);
627  memset (WidthErrSM, 0, sizeof (Double_t) * nMax);
628  memset (Npi0SM, 0, sizeof (Double_t) * nMax);
629  memset (Npi0ErrSM, 0, sizeof (Double_t) * nMax);
630 
631  TString dirname;
632  if(!fTrigger.Contains("QA")) {
633  dirname = "CaloQA_";
634  }
635  dirname += fTrigger;
636 
637  Bool_t dirok = f->cd(dirname);
638  if(!dirok) { Error(__FUNCTION__,Form("No input directory %s",dirname.Data())); tree->Fill(); ftree->cd(); tree->Write(); ret= -1; continue;}
639  outputList = (TList*)gDirectory->Get(dirname);
640  if(!outputList){ Error(__FUNCTION__,Form("No input list! %s",dirname.Data())); tree->Fill(); ftree->cd(); tree->Write(); ret=-2; continue;;}
641  outputList->SetOwner();
642 
643  // number of events
644  fhNEvents =(TH1F *)outputList->FindObject("hNEvents");
645  if(!fhNEvents){ Error(__FUNCTION__,Form("NEvent histogram not found for trigger %s",fTrigger.Data())); tree->Fill(); ftree->cd(); tree->Write(); ret=-3; continue;}
646  Nevent=fhNEvents->GetEntries();
647  if(Nevent==0) {Error(__FUNCTION__,Form("No event in trigger %s",fTrigger.Data())); tree->Fill(); ftree->cd(); tree->Write(); ret=-4; continue;}
648  if(Nevent<20) {Error(__FUNCTION__,Form("Less than 20 events in trigger %s",fTrigger.Data())); tree->Fill(); ftree->cd(); tree->Write(); ret=-5; continue;}
649 
650  // first do clusters trending
651  fhE = (TH1F *)outputList->FindObject(fCalorimeter+"_hE");
652  Double_t energy = 0. ;
653 
654  for(Int_t ibin = fhE->FindBin(0.6) ; ibin <fhE->FindBin(50.) ; ibin++){
655  energy+=fhE->GetBinCenter(ibin)*fhE->GetBinContent(ibin);
656  }
657  if(fhE->Integral(fhE->FindBin(0.6), fhE->FindBin(50.))==0){Error(__FUNCTION__,Form("Not enough events")); tree->Fill(); ftree->cd(); tree->Write(); ret=-6; continue;}
658  EtotalMean=energy/fhE->Integral(fhE->FindBin(0.6), fhE->FindBin(50.)) ;
659  EtotalRMS=fhE->GetMeanError();
660 
661  TString nameNCell = Form("%s_hNCells_Mod",fCalorimeter.Data());
662  TString nameNCluster = Form("%s_hNClusters_Mod",fCalorimeter.Data());
663  TString nameE = Form("%s_hE_Mod",fCalorimeter.Data());
664  TH2F* hNCellsMod= (TH2F*)outputList->FindObject(nameNCell.Data());
665  TH2F* hNClusterMod=(TH2F*)outputList->FindObject(nameNCluster.Data());
666  TH2F* hEMod=(TH2F*)outputList->FindObject(nameE.Data());
667 
668  if (!hNCellsMod || !hNClusterMod || !hEMod) {Error(__FUNCTION__,"A requiered histogram was not found (the imput QAresult.root might be too old)!"); tree->Fill(); ftree->cd(); tree->Write(); ret=-7; continue;}
669 
670  TCanvas* c1 = new TCanvas("Pi0InvMassSM","Pi0 Invariant Mass for each SM", 600, 600);
671  c1->SetFillColor(0);
672  c1->SetBorderSize(0);
673  c1->SetFrameBorderMode(0);
674  Bool_t mod3=0; if (n%3) mod3=1;
675  c1->Divide(3,n/3+mod3);
676 
677  //per sm trending
678  TString nameNCellPerCluster;
679  for(Int_t ism = 0 ; ism < n ; ism++){
680  cout << "#########################"<< endl;
681  cout << " Super Module " << ism << " Run " << RunId << endl;
682  // first do clusters trending
683  nameNCellPerCluster = Form("%s_hNCellsPerCluster_Mod%d",fCalorimeter.Data(),ism);
684  NCellsPerCluster[ism] = (TH2F*)outputList->FindObject(nameNCellPerCluster.Data());
685  if(! (TH2F*)outputList->FindObject(nameNCellPerCluster.Data()) ) { Error(__FUNCTION__,Form("NCellsPerCluster histogram not found for super module %i",ism));ret=-8; continue;}
686  NCellsPerCluster[ism] = (TH2F*)outputList->FindObject(nameNCellPerCluster.Data());
687 
688  NCells[ism] = (TH1F*)hNCellsMod->ProjectionX(Form("NCells%d",ism),ism+1,ism+2,"");
689  NClusters[ism] = (TH1F*)hNClusterMod->ProjectionX(Form("NClusters%d",ism),ism+1,ism+2,"");
690  E[ism] = (TH1F*)hEMod->ProjectionX(Form("E%d",ism),ism+1,ism+2,"");
691  CellMeanSM[ism]=NCells[ism]->GetMean();
692  CellRMSSM[ism]=NCells[ism]->GetMeanError();
693  ClusterMeanSM[ism]=NClusters[ism]->GetMean();
694  ClusterRMSSM[ism]=NClusters[ism]->GetMeanError();
695  CellPerClusterMeanSM[ism]=NCellsPerCluster[ism]->GetMean(2);
696  CellPerClusterRMSSM[ism]=NCellsPerCluster[ism]->GetMeanError(2);
697 
698  ECell1MeanSM[ism] =NCellsPerCluster[ism]->ProjectionX("",2,50,"")->Integral(5,50)/(Nevent);
699  ECell1RMSSM[ism] =NCellsPerCluster[ism]->ProjectionX("",2,50,"")->GetMeanError();
700  Double_t energySM = 0. ;
701  for(Int_t ibin = E[ism]->FindBin(0.6) ; ibin <E[ism]->FindBin(50.) ; ibin++){
702  energySM+=E[ism]->GetBinCenter(ibin)*(E[ism]->GetBinContent(ibin));
703  }
704  if(E[ism]->Integral(E[ism]->FindBin(0.6),E[ism]->FindBin(50.))==0){Error(__FUNCTION__,Form("Energy: Not enough events/SM")); continue;}
705  EtotalMeanSM[ism]=energySM/(E[ism]->Integral(E[ism]->FindBin(0.6),E[ism]->FindBin(50.)));
706 
707  EtotalRMSSM[ism]=E[ism]->GetMeanError();
708 
709  if(ism==0) {
710  fhNCells = (TH1F*)NCells[ism]->Clone("NCells");
711  fhNClusters = (TH1F*)NClusters[ism]->Clone("NClusters");
712  }
713  else {
714  fhNCells->Add(NCells[ism],1);
715  fhNClusters->Add(NClusters[ism],1);
716  }
717 
718  //Pi0
719  c1->cd(ism+1);
720  TString namePair = Form("%s_hIM_Mod%d",fCalorimeter.Data(),ism);
721  IM[ism] = (TH2F*)outputList->FindObject(namePair.Data());
722  IM[ism]->Sumw2();
723 
724  TString projname = Form("SM_%d",ism);
725  MggSM[ism] = (TH1F *)IM[ism]->ProjectionY(projname.Data(), 2, 150, "") ;
726 
727 
728  if(MggSM[ism]->GetEntries()>100) {
729  fitMass->SetParameter(0, MggSM[ism]->GetBinContent(MggSM[ism]->GetMaximumBin()));
730  fitMass->SetParameter(1, mPDG); //
731  fitMass->SetParameter(2, 15.); //
732  fitMass->SetParameter(3,0.);
733  fitMass->SetParameter(4,MggSM[ism]->GetBinContent(MggSM[ism]->FindBin(0.11)));
734  fitMass->SetParameter(5,MggSM[ism]->GetBinContent(MggSM[ism]->FindBin(0.20)));
735 
736  if(MggSM[ism]->GetEntries()<1000){ MggSM[ism]->Rebin(4);} else {MggSM[ism]->Rebin();}
737  MggSM[ism]->Fit("fitMass", "WL R +","",0.05, 0.30);
738  MggSM[ism]->SetTitle(Form("Pi0 Mass for super module %i",ism));
739  MggSM[ism]->SetTitleSize(0.1);
740  MggSM[ism]->SetXTitle("Pi0 Mass");
741  MggSM[ism]->SetYTitle("Nb of entries");
742  MggSM[ism]->GetXaxis()->SetLabelSize(0.05);
743  MggSM[ism]->GetXaxis()->SetTitleSize(0.07);
744  MggSM[ism]->GetXaxis()->SetTitleOffset(0.68);
745  MggSM[ism]->GetYaxis()->SetLabelSize(0.05);
746  MggSM[ism]->GetYaxis()->SetTitleSize(0.06);
747  MggSM[ism]->GetYaxis()->SetTitleOffset(0.78);
748 
749  MeanPosSM[ism] = MggSM[ism]->GetFunction("fitMass")->GetParameter(1)*1000;
750  MeanPosErrSM[ism] = MggSM[ism]->GetFunction("fitMass")->GetParError(1)*1000;
751  WidthSM[ism] = MggSM[ism]->GetFunction("fitMass")->GetParameter(2)*1000;
752  WidthErrSM[ism] = MggSM[ism]->GetFunction("fitMass")->GetParError(2)*1000;
753  Npi0SM[ism] = MggSM[ism]->GetFunction("fitMass")->GetParameter(0)*(MggSM[ism]->GetFunction("fitMass")->GetParameter(2))*TMath::Sqrt(2*TMath::Pi())/(Nevent*MggSM[ism]->GetBinWidth(1));
754  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))
755  +(MggSM[ism]->GetFunction("fitMass")->GetParError(2)/MggSM[ism]->GetFunction("fitMass")->GetParameter(2))*(MggSM[ism]->GetFunction("fitMass")->GetParError(2)/MggSM[ism]->GetFunction("fitMass")->GetParameter(2)));
756  Npi0ErrSM[ism] = 0.; //
757 
758  }// end if enough events for Pi0 fit and trending
759  else { Info(__FUNCTION__,Form("Not enough events for Pi0 fit and trending for super module %i",ism));} ;
760  } //per SM loop
761 
762  // Now Pi0 global trending
763  TCanvas* c2 = new TCanvas("Pi0InvMass","Pi0 Invariant Mass", 600, 600);
764  c2->SetFillColor(0);
765  c2->SetBorderSize(0);
766  c2->SetFrameBorderMode(0);
767 
768  fhIM = (TH2F *)outputList->FindObject(fCalorimeter+"_hIM");
769  fhIM->Sumw2();
770  fhMgg = (TH1F *)fhIM->ProjectionY("Mgg", 2, 150, "") ;
771  if(fhMgg->GetEntries()==0) {Error(__FUNCTION__,"The Pi0 histogram is empty !"); tree->Fill(); ret=-8; continue;}
772  fitMass->SetParameter(0, 4500);
773  fitMass->SetParameter(1, mPDG);
774  fitMass->SetParameter(2, 0.01);
775  fitMass->SetParameter(3,0.);
776  fitMass->SetParameter(4,fhMgg->GetBinContent(fhMgg->FindBin(0.11)));
777  fitMass->SetParameter(5,fhMgg->GetBinContent(fhMgg->FindBin(0.20)));
778 
779  if(fhMgg->GetEntries()<5000){
780  fhMgg->Rebin(4);}
781  else fhMgg->Rebin();
782 
783  fhMgg->Fit("fitMass", "L R +", "", 0.05, 0.20);
784 
785  fhMgg->SetTitle("Pi0 Mass");
786  fhMgg->SetTitleSize(0.1);
787  fhMgg->SetXTitle("Pi0 Mass");
788  fhMgg->SetYTitle("Nb of entries");
789  fhMgg->GetXaxis()->SetLabelSize(0.03);
790  fhMgg->GetXaxis()->SetTitleSize(0.03);
791  fhMgg->GetXaxis()->SetTitleOffset(1.3);
792  fhMgg->GetYaxis()->SetLabelSize(0.03);
793  fhMgg->GetYaxis()->SetTitleSize(0.03);
794  fhMgg->GetYaxis()->SetTitleOffset(1.3);
795 
796  MeanPos = fhMgg->GetFunction("fitMass")->GetParameter(1)*1000;
797  MeanPosErr = fhMgg->GetFunction("fitMass")->GetParError(1)*1000;
798  Width = fhMgg->GetFunction("fitMass")->GetParameter(2)*1000;
799  WidthErr = fhMgg->GetFunction("fitMass")->GetParError(2)*1000;
800  Chi2NdfPi0 = fhMgg->GetFunction("fitMass")->GetChisquare()/fhMgg->GetFunction("fitMass")->GetNDF();
801  Npi0 = fhMgg->GetFunction("fitMass")->GetParameter(0)*fhMgg->GetFunction("fitMass")->GetParameter(2)*TMath::Sqrt(2*TMath::Pi())/(Nevent*fhMgg->GetBinWidth(10));
802  Npi0Err = TMath::Sqrt((fhMgg->GetFunction("fitMass")->GetParError(0)/fhMgg->GetFunction("fitMass")->GetParameter(0))*(fhMgg->GetFunction("fitMass")->GetParError(0)/fhMgg->GetFunction("fitMass")->GetParameter(0))+(WidthErr/Width)*(WidthErr/Width));
803  Npi0Err = 0.; //
804  Ngg = fhMgg->GetFunction("fitMass")->Integral(0.11, 0.16)/(Nevent*fhMgg->GetBinWidth(10));
805  NggErr = fhMgg->GetFunction("fitMass")->IntegralError(0.11, 0.16)/(fhMgg->Integral()*fhMgg->GetBinWidth(10));
806  Signif = Npi0/Ngg;
807  SignifErr = TMath::Sqrt((Npi0Err/Npi0*(Npi0Err/Npi0)+(NggErr/Ngg*(NggErr/Ngg))));
808  SignifErr = Signif*SignifErr;
809 
810  cout<<"******************"<<endl;
811  //end of global trending
812 
813  ClusterMean=fhNClusters->GetMean();
814  ClusterRMS=fhNClusters->GetMeanError();
815  CellMean=fhNCells->GetMean();
816  CellRMS=fhNCells->GetMeanError();
817  tree->Fill();
818 
819  TString outfilename = QAPATH + "Pi0InvMass" + fTrigger(r) + ".pdf";
820  TString outfilename2 = QAPATH + "Pi0InvMass" + fTrigger(r) + ".png";
821  if(SavePlots==2) c2->SaveAs(outfilename);
822  if(SavePlots) c2->SaveAs(outfilename2);
823 
824  outfilename = QAPATH + "Pi0InvMassSM" + fTrigger(r) + ".pdf";
825  outfilename2 = QAPATH + "Pi0InvMassSM" + fTrigger(r) + ".png";
826  if(SavePlots==2) c1->SaveAs(outfilename);
827  if(SavePlots) c1->SaveAs(outfilename2);
828 
829  fout->cd();
830  fout->Cd(Form("%s/%s/%ld/%s/%s",period.Data(),pass.Data(),RunId,"RunLevelQA",fTrigger.Data()));
831  c2->Write();
832  c1->Write();
833  delete c1;
834  delete c2;
835  if (outputList) outputList->Delete() ;
836 
837  QAData << RunId<<" "<< Nevent
838  <<"\n";
839 
840  QAData.close();
841 
842  }
843 
844  ftree->cd();
845  tree->Write();
846  ftree->Close();
847 
848  return ret;
849 
850 }
851 
852 //-------------------------------------------------------------------------
853 TH2F* FormatRunHisto(TH2F* aHisto,const char* title,const char* YTitle)
854 {
855 
856  if(!aHisto) {Error(__FUNCTION__,Form("The histogram with title \"%s\" was not found!",title)); return new TH2F();}
857  aHisto->SetStats(kFALSE);
858  aHisto->SetTitle(title);
859  aHisto->SetStats(kFALSE);
860  aHisto->SetYTitle(YTitle);
861  aHisto->GetYaxis()->SetTitleOffset(1.2);
862  aHisto->GetYaxis()->SetLabelSize(0.03);
863  aHisto->GetZaxis()->SetLabelSize(0.02);
864 
865  return aHisto;
866 
867 }
868 
869 //--------------------------------------------------------------------------------------------------------------
870 TH2F* HistoPerMod(TH2F* hTmpPerMod,const char* title)
871 {
872 
873  if(!hTmpPerMod) {Error(__FUNCTION__,Form("The histogram with title \"%s\" was not found!",title)); return new TH2F();}
874  hTmpPerMod->SetStats(kFALSE);
875  hTmpPerMod->SetTitle(title);
876  hTmpPerMod->SetTitleSize(0.1);
877  hTmpPerMod->GetXaxis()->SetTitleOffset(1.1);
878  hTmpPerMod->GetXaxis()->SetTitleSize(0.05);
879  hTmpPerMod->GetXaxis()->SetLabelSize(0.06);
880  hTmpPerMod->GetYaxis()->SetTitleOffset(1.1);
881  hTmpPerMod->GetYaxis()->SetTitleSize(0.05);
882  hTmpPerMod->GetYaxis()->SetLabelSize(0.06);
883  hTmpPerMod->GetZaxis()->SetLabelSize(0.04);
884 
885  return hTmpPerMod;
886 
887 }
888 
889 //---------------------------------------------------------------------------------------------------
890 TH2F* AutoZoom(TH2F* H,Option_t* aType, Int_t EntryMin)
891 {
892 
893  Int_t shiftX = (Int_t)(H->GetNbinsX()/30.);
894  Int_t shiftY = (Int_t)(H->GetNbinsY()/30.);
895 
896  TString opt = aType;
897  opt.ToLower();
898 
899  int minX = 0;
900  int maxX = H->GetNbinsX();
901  int New_minX = minX;
902  int New_maxX = maxX;
903 
904  int minY = 0;
905  int maxY = H->GetNbinsY();
906  int New_minY = minY;
907  int New_maxY = maxY;
908 
909  if (opt.Contains("all")) opt = TString("minx,maxx,miny,maxy");
910 
911  if (opt.Contains("maxx"))
912  {
913 
914  for (New_maxX = maxX;New_maxX >=minX; New_maxX--)
915  { Stat_t c = 0;
916  for (int i_y = maxY; i_y >= minY;i_y--)
917  { c = H->GetBinContent(New_maxX,i_y); if (c>EntryMin) break;}
918  if (c>EntryMin) break;
919  }
920  }
921 
922  if (opt.Contains("maxy"))
923  {
924 
925  for (New_maxY = maxY;New_maxY >=minY;New_maxY--)
926  { Stat_t c = 0;
927  for (int i_x=maxX; i_x>=minX;i_x--)
928  { c = H->GetBinContent(i_x, New_maxY ); if (c>EntryMin) break;}
929  if (c>EntryMin) break;
930  }
931 
932  }
933 
934  if (opt.Contains("minx"))
935  {
936 
937  for (New_minX = minX;New_minX <=maxX; New_minX++)
938  { Stat_t c = 0;
939  for (int i_y = minY; i_y <= maxY;i_y++)
940  { c = H->GetBinContent(New_minX,i_y); if (c>EntryMin) break;}
941  if (c>EntryMin) break;
942  }
943  }
944 
945  if (opt.Contains("miny"))
946  {
947  for (New_minY = minY;New_minY <=maxY;New_minY++)
948  { Stat_t c = 0;
949  for (int i_x=minX; i_x<=maxX;i_x++)
950  { c = H->GetBinContent(i_x, New_minY ); if (c>EntryMin) break;}
951  if (c>EntryMin) break;
952  }
953  }
954 
955  if (New_maxX!=-1 && New_maxY!=-1) H->GetXaxis()->SetRange(New_minX - shiftX , New_maxX + shiftX);
956  if (New_maxX!=-1 && New_maxY!=-1) H->GetYaxis()->SetRange(New_minY - shiftY , New_maxY + shiftY);
957 
958  return H;
959 
960 }
961 
962 //----------------------------------------------------------------------------------------------------
963 int FindNumberOfSM(TFile* f, TString fTrigger, TString period)
964 {
965 
966  TString direct;
967  if(!fTrigger.Contains("QA")) {
968  direct = "CaloQA_";
969  }
970  direct += fTrigger;
971 
972  Int_t nSMt=-1;
973  Int_t year = 2000 + TString(period(3,2)).Atoi();
974  if ( year == 2010 ) { nSMt=6; }
975  else if ( year == 2011 || year == 2012 ) { nSMt=10; }
976  else if ( year == 2013 || year == 2014 ) { nSMt=12; }
977  else { nSMt=20; }
978 
979  TList *outputList;
980  Bool_t dirok = f->cd(direct);
981  if (!dirok) { Error(__FUNCTION__,Form("No input directory %s, the number SMs will be returned based on the year!",direct.Data()));}
982  else { outputList = (TList*)gDirectory->Get(direct);}
983  if(!outputList) { Error(__FUNCTION__,"No input list, the number SMs will be returned based on the year! ");}
984  else {
985  outputList->SetOwner();
986  TH2F* hNSM =(TH2F *)outputList->FindObject("EMCAL_hE_Mod");
987  if (!hNSM || (!hNSM->GetEntries())) { Error(__FUNCTION__,"hNSM Histogram not found or it is empty, the number SMs will be returned based on the year!");}
988  else {
989  nSMt = hNSM->GetYaxis()->GetBinUpEdge(hNSM->FindLastBinAbove(0,2));
990  }
991  }
992  if (outputList) {outputList->Delete();}
993 
994  return nSMt;
995 
996 }
TH2F * FormatRunHisto(TH2F *aHisto, const char *title, const char *YTitle="")
TString QAPATH
const char * title
Definition: MakeQAPdf.C:26
Int_t DrawOccupancy(Long_t run, TString period, TString pass, TString fTrigger, TString system, TFile *f, TFile *fout, AliEMCALGeometry *geom, Int_t SavePlots)
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)
TH2F * AutoZoom(TH2F *H, Option_t *aType="all", Int_t EntryMin=0)
TString QAPATHF
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)
void set_plot_style()
TH2F * HistoPerMod(TH2F *name, const char *title)
Double_t fitE(Double_t *x, Double_t *par)
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")