088e775b8af6018d30efb949b1e8ee590e82e214
[u/mrichter/AliRoot.git] / PWGPP / MUON / lite / PlotMuonQA.C
1 //--------------------------------------------------------------------------
2 // Macro for QA monitoring.
3 //
4 // In case it is not run with full aliroot, it needs the following libraries to compile:
5 //  - libSTEERBase.so
6 //  - libESD.so
7 //  - libAOD.so
8 //  - libANALYSIS.so
9 //  - libANALYSISalice.so
10 //  - libCORRFW.so
11 //  - libPWGmuon.so
12 //
13 // TString includePath = "-I${ALICE_ROOT}/PWGmuon ";  gSystem->SetIncludePath(includePath.Data());
14 //
15 // The macro reads results of the QA task and produce monitoring plots.
16 //
17 // Authors: Cynthia Hadjidakis - IPN Orsay
18 // QA histos from counters (event, track) and run per run histos
19 // To be done:
20 // - reorganize last part (reading and extracting info from run per run histos)
21 // - remove trigger selection when muon QA task modified (now a selection is done one triggers' name)
22 //--------------------------------------------------------------------------
23
24 #if !defined(__CINT__) || defined(__MAKECINT__)
25
26 #include <Riostream.h>
27 // ROOT includes
28 #include "TEnv.h"
29 #include "TMath.h"
30 #include "TGrid.h"
31 #include "TGridResult.h"
32 #include "THashList.h"
33 #include "TFile.h"
34 #include "TH1.h"
35 #include "TH2.h"
36 #include "TF1.h"
37 #include "TSystem.h"
38 #include "TStyle.h"
39 #include "TCanvas.h"
40 #include "TPad.h"
41 #include "TLegend.h"
42 #include "TObjArray.h"
43 #include "TObjString.h"
44 #include "TFileMerger.h"
45 // ALIROOT includes
46 #include "AliCounterCollection.h"
47 #endif
48
49 Int_t GetRunNumber(TString);
50 TString GetRunList(const char *runList, TObjArray *runs);
51 Bool_t MergeOutputs(const char*,const char*);
52 Bool_t GetTriggerLists(const char *triggerList, TString listFromContainer, TObjArray *triggersB=0, TObjArray *triggersShortName=0);
53 void SetCanvas(TCanvas *canvas, Int_t logy=1);
54 TH1* ProcessHisto( AliCounterCollection* counter, TString variable, TString selection, TString hName="", TString xName="", TString yName="", Int_t color=1);
55 TH2* ProcessHisto2D( AliCounterCollection* counter, TString hVariable, TString hVariable2, TString hSelection, TString hName);
56 Int_t GetIndex(TObjArray *triggersB, Int_t trigNr, Int_t centNr);
57 TCanvas *ProcessCanvasAllTrigger(AliCounterCollection *counter, TString canvasName);
58 TCanvas *ProcessCanvasTriggerContent(TObjArray *trigName, TObjArray trigNoPS, TObjArray trigWithPS, TString canvasName);
59 TCanvas *ProcessCanvasRelativeTriggerContent(TObjArray *array, TObjArray trigNoPS, TString canvasName);
60 TCanvas *ProcessCanvasPhysSelCut(TObjArray *triggersB, TObjArray trigNoPS, TObjArray trigWithPS, TString canvasName);
61 TCanvas *ProcessCanvasPhysSelCutCentrality(TObjArray *triggersB, TObjArray trigNoPS, TObjArray trigBWithPS, Int_t trigNr, TString canvasName, TString *legendHeader);
62 TCanvas *ProcessCanvasCentralityPercentile(TObjArray *triggersB, TObjArray trigNoPS, TObjArray trigWithPS, Int_t trigNr, TString canvasName, TString *legendHeader);
63 TCanvas *ProcessCanvasTracksoverTrigger(TObjArray *triggersB, TObjArray trigSel, TObjArray trackTracker, TObjArray trackTrigger, TObjArray trackMatched, TObjArray trackAll, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader=""); 
64 TCanvas *ProcessCanvasTrackMultB(TObjArray *triggersB, TObjArray trigSel, TObjArray trackTracker, TObjArray trackTrigger, TObjArray trackMatched, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader="");
65 TCanvas *ProcessCanvasRatioTrackB(TObjArray *triggersB, TObjArray trigSel, TObjArray trackTracker, TObjArray trackTrigger, TObjArray trackMatched, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader="");
66 TCanvas *ProcessCanvasAsymMatched(TObjArray *triggersB, TObjArray trackPosMatched, TObjArray trackNegMatched, TObjArray trackhAllMatched, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader="");
67 TCanvas *ProcessCanvasHighPtMuons(TObjArray *triggersB, TObjArray trigSel, TObjArray trackMatchedLowPt, TObjArray trackAllMatchedHightPt, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader="");
68 TCanvas *ProcessCanvasBeamGasMatched(TObjArray *triggersB, TObjArray trackBeamGasMatched, TObjArray trackBeamGasMatchedHighPt, TObjArray trackAllMatched, TObjArray trackMatchedHighPt, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader="");
69 Bool_t IsHeavyIonCollision(AliCounterCollection *eventCounters);
70
71 //loop on centrality
72 const Int_t kCentBinMax = 4;
73 TString kCentBinName[kCentBinMax] = {"v0mult:any/","v0mult:low,int,high/","v0mult:low/","v0mult:high/"};
74 TString kCentLegendName[kCentBinMax] ={"all collisions","[0-80%] from V0 amplitude","low mult. [60-80%] from V0 amplitude","high mult. [0-10%] from V0 amplitude"};
75 TString kCentLegendNameShort[kCentBinMax] ={"all","[0-80%]","[60-80%]","[0-10%]"};
76
77 //--------------------------------------------------------------------------
78 void PlotMuonQA(const char* baseDir, const char* runList = 0x0, const char * triggerList = 0x0, Bool_t selectPhysics = kFALSE, const char *LHCPeriod = "LHC11c", const char *QAFileName = "QAresults.root") {
79         
80   /// Macro for QA monitoring.
81   /// Example: baseDir = "alien:///alice/cern.ch/user/p/ppillot/pp7TeV/LHC10d/MuonQA/pass1/results/".
82   /// If runList != 0x0: only the given runs will be used. Otherwise use all runs found in baseDir.
83   /// If triggerList !=0x0: only the given triggers are displayed. Otherwise use the default list of triggers (see GetTriggerLists)
84         
85 #if defined(__CINT__) && !defined(__MAKECINT__)
86   gSystem->Load("libTree");
87   gSystem->Load("libGeom");
88   gSystem->Load("libVMC");
89   gSystem->Load("libPhysics");
90   gSystem->Load("libSTEERBase");
91   gSystem->Load("libESD");
92   gSystem->Load("libAOD");
93   gSystem->Load("libANALYSIS");
94   gSystem->Load("libANALYSISalice");
95   gSystem->Load("libCORRFW");
96   gSystem->Load("libPWGHFbase");
97   gSystem->Load("libPWGmuon");
98 #endif
99   
100   // Cosmetics and configuration
101   gStyle->SetFillColor(10);
102   gStyle->SetPadGridX(kTRUE);
103   gStyle->SetPadGridY(kTRUE);
104   gStyle->SetPadRightMargin(0.01);
105   
106   TString OutFileName = "QA_";  OutFileName += LHCPeriod;
107   TString OutFileNamePDF=  OutFileName.Data();  OutFileNamePDF+= ".pdf";
108   TString OutFileNamePDF_open = OutFileNamePDF.Data(); OutFileNamePDF_open += "[";  
109   TString OutFileNamePDF_close= OutFileNamePDF.Data(); OutFileNamePDF_close += "]";  
110   TString OutFileNameROOT=  OutFileName.Data();  OutFileNameROOT+= ".root";
111   
112   Int_t PRINTSTAT = 1;
113   Int_t kCMUS = 1;
114
115   if (0){ // Equivalent to the fast read option
116     gEnv->SetValue("XNet.ConnectTimeout",10);
117     gEnv->SetValue("XNet.RequestTimeout",10);
118     gEnv->SetValue("XNet.MaxRedirectCount",2);
119     gEnv->SetValue("XNet.ReconnectTimeout",10);
120     gEnv->SetValue("XNet.FirstConnectMaxCnt",1);
121   }
122   
123   TH1::AddDirectory(kFALSE);
124   
125   TString alienBaseDir = baseDir;
126   
127   if (alienBaseDir.Contains("alien:") && !TGrid::Connect("alien://")) {
128     Error("MergeQA","cannot connect to grid");
129     return;
130   }
131   
132   cout<<"//---------------------------------- //"<<endl;
133   cout<<"//          Run selection            //"<<endl;
134   cout<<"//---------------------------------- //"<<endl;
135   
136   TObjArray *runs = new TObjArray();
137   runs->SetOwner(kTRUE);
138   TString selectRuns = GetRunList(runList,runs);
139         
140   // physics selection
141   TString select = selectPhysics ? "selected:yes" : "";
142         
143   cout<<"//---------------------------------- //"<<endl;
144   cout<<"//        Get global counter        //"<<endl;
145   cout<<"//---------------------------------- //"<<endl;
146   
147   TString mergedFilename = Form("%s/%s", baseDir,QAFileName);
148   if (runList) MergeOutputs(runList, mergedFilename);
149
150   TFile *globalFile = TFile::Open(mergedFilename.Data());
151   if (!globalFile || ! globalFile->IsOpen()) {
152     Error("PlotQA", "failed to open file: %s", mergedFilename.Data());
153     return;
154   }
155   globalFile->Cd("MUON_QA");
156   
157   TString selection;
158         
159   // get counters
160   AliCounterCollection* eventCounters = static_cast<AliCounterCollection*>(globalFile->FindObjectAny("eventCounters"));
161   AliCounterCollection* trackCounters = static_cast<AliCounterCollection*>(globalFile->FindObjectAny("trackCounters"));
162
163   // run list from counters
164   if (!runList) selectRuns += trackCounters->GetKeyWords("run");
165         
166   cout<<"//---------------------------------- //"<<endl;
167   cout<<"//        Trigger selection          //"<<endl;
168   cout<<"//---------------------------------- //"<<endl;
169
170   TObjArray *triggersB, *triggersShortName;
171   triggersB = new TObjArray();
172   triggersB->SetOwner();
173   triggersShortName = new TObjArray();
174   triggersShortName->SetOwner();
175
176   TString listFromContainer = eventCounters->GetKeyWords("trigger");
177   Bool_t success = GetTriggerLists(triggerList, listFromContainer, triggersB, triggersShortName);
178   if(!success) return;
179         
180   cout<<"//---------------------------------- //"<<endl;
181   cout<<"//      Set collision type ?          //"<<endl;
182   cout<<"//---------------------------------- //"<<endl;
183
184   Bool_t isHeavyIon = kTRUE;
185   isHeavyIon = IsHeavyIonCollision(eventCounters);
186         
187   cout<<"//---------------------------------- //"<<endl;
188   cout<<"//        Trigger plots              //"<<endl;
189   cout<<"//---------------------------------- //"<<endl;
190         
191   //plot all trigger from event counters without any selection
192   TString CanvasName = "AllTriggers";
193   TCanvas *cAll = ProcessCanvasAllTrigger(eventCounters, CanvasName);
194
195   cout<<"//---------------------------------- //"<<endl;
196   cout<<"//   Processing event counters       //"<<endl;
197   cout<<"//---------------------------------- //"<<endl;
198
199   //declare a default canvas c1 
200   CanvasName = "c1";
201   TCanvas *c1 = new TCanvas(CanvasName.Data(),CanvasName.Data());
202   c1->cd();
203   
204   Int_t nCentBin = ( isHeavyIon ) ? kCentBinMax : 1;
205   TString selectionCent;
206                
207   Int_t *colorTab = new Int_t[triggersB->GetEntriesFast()];
208   Int_t const colorNrFirst = 8;
209   Int_t colorIndex = 0;
210   Int_t colorTabFirst[colorNrFirst] = {kGray+2,kRed,kBlue,kGreen,kOrange,kCyan,kMagenta,kYellow};
211   for ( Int_t i = 0; i < triggersB->GetEntriesFast(); i++ ) {
212     colorTab[i] = colorTabFirst[i] + colorIndex;
213     if ( i%colorNrFirst == 0 ) colorIndex++;
214   } 
215   TArrayI *colorInd = new TArrayI( triggersB->GetEntriesFast() );
216
217   for ( Int_t i = 0; i < triggersB->GetEntriesFast(); i++ ) colorInd->AddAt(colorTab[i],i); 
218   
219   Int_t nTrig = triggersB->GetEntriesFast();
220
221   TObjArray trigNoPS(nTrig*nCentBin);
222   TObjArray trigWithPS(nTrig*nCentBin);
223   TObjArray trigWithPST0Flag(nTrig*nCentBin);
224   TObjArray trigWithPST0SPDFlag(nTrig*nCentBin);
225
226   TObjArray trigSel;
227   TObjArray trackTrigger(nTrig*nCentBin); 
228   TObjArray trackTracker(nTrig*nCentBin); 
229   TObjArray trackMatched(nTrig*nCentBin);
230   TObjArray trackAll(nTrig*nCentBin); 
231
232   TObjArray trackAllMatched(nTrig*nCentBin); //matched tracks + additional geometrical cut
233   TObjArray trackMatchedLowPt(nTrig*nCentBin);
234   TObjArray trackMatchedHighPt(nTrig*nCentBin);
235
236   TObjArray trackPosMatched(nTrig*nCentBin);
237   TObjArray trackNegMatched(nTrig*nCentBin);
238
239   TObjArray trackBeamGasMatched(nTrig*nCentBin);
240   TObjArray trackBeamGasMatchedHighPt(nTrig*nCentBin);
241
242   cout<<Form("Processing for %d triggers...",triggersB->GetEntriesFast()-1)<<endl;
243     
244   //loop on centrality
245   for ( Int_t iCentBin = 0; iCentBin < nCentBin; iCentBin++){
246     selectionCent = kCentBinName[iCentBin];
247                 
248     //Loop on trigger (last is all triggers)
249     for(Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast(); iTrig++){
250     
251       TString histoNameBase = "h_trig", histoName;
252       histoNameBase+= iTrig+1;
253                 
254       Int_t index = GetIndex(triggersB,iTrig,iCentBin);
255
256       TH1* histo = 0;
257
258       TString triggerName = ( (TObjString*) triggersB->At(iTrig) )->GetString();
259       if(triggerName.EqualTo(" ")) continue;
260       // Histo trigger without Phys. Sel. 
261       selection = selectionCent; selection += Form("trigger:%s/%s", triggerName.Data(), selectRuns.Data());             
262       // cout<<selection<<endl;
263       histoName = histoNameBase;
264       histoName += "BNoPS";
265       histo = (TH1*) ProcessHisto(eventCounters, "run", selection, histoName, "", "Trigger content w/o Phys. Sel.", colorInd->At(iTrig));
266       trigNoPS.AddAt(histo,index);
267       // Histo trigger with Phys. Sel. 
268       selection = selectionCent; selection += Form("trigger:%s/%s/selected:yes", triggerName.Data(), selectRuns.Data());
269       histoName = histoNameBase;
270       histoName += "BWithPS";
271       histo = (TH1*) ProcessHisto(eventCounters, "run", selection, histoName, "", "Trigger content w/ Phys. Sel.", colorInd->At(iTrig));
272       trigWithPS.AddAt(histo,index);
273     // Histo trigger with Phys. Sel. and T0 pile up not flagged
274       selection = selectionCent; selection += Form("trigger:%s/%s/selected:yes/t0pileup:no", triggerName.Data(), selectRuns.Data());
275       histoName = histoNameBase;
276       histoName += "BWithPST0Flag";
277       histo = (TH1*) ProcessHisto(eventCounters, "run", selection, histoName, "", "Trigger content w/ Phys. Sel. and no pile up from T0 flag", colorInd->At(iTrig));
278       trigWithPST0Flag.AddAt(histo,index);
279     // Histo trigger with Phys. Sel. and T0 + SPD pile up not flagged
280       selection = selectionCent; selection += Form("trigger:%s/%s/selected:yes/t0pileup:no/spdpileup:no", triggerName.Data(), selectRuns.Data());
281       histoName = histoNameBase;
282       histoName += "BWithPST0SPDFlag";
283       histo = (TH1*) ProcessHisto(eventCounters, "run", selection, histoName, "", "Trigger content w/ Phys. Sel. and no pile up from T0 and SPD flag", colorInd->At(iTrig));
284       trigWithPST0SPDFlag.AddAt(histo,index);
285                 
286       // Histo tracking : Phys. Sel.  is selected or not depending on the macro arguments
287       selection = selectionCent; selection += Form("track:triggeronly/trigger:%s/%s/%s", triggerName.Data(), selectRuns.Data(), select.Data());
288       histo = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
289       trackTrigger.AddAt(histo,index);
290
291       selection = selectionCent; selection += Form("track:trackeronly/trigger:%s/%s/%s", triggerName.Data(), selectRuns.Data(), select.Data());
292       histo = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
293       trackTracker.AddAt(histo,index);
294
295       selection = selectionCent; selection += Form("track:matched/trigger:%s/%s/%s", triggerName.Data(), selectRuns.Data(), select.Data());
296       histo = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
297       trackMatched.AddAt(histo,index);
298                 
299       histo = (TH1*) ( (TH1*) trackTrigger.At(index))->Clone("");
300       histo->Add( (TH1*) trackTracker.At(index) );
301       histo->Add( (TH1*) trackMatched.At(index) );
302       trackAll.AddAt(histo,index);
303
304       //for the following, only integrated over centrality
305       if ( iCentBin > 0 ) continue;
306       
307       selection = selectionCent; selection += Form("track:matched/trigger:%s/%s/%s/pt:low/acc:in", triggerName.Data() ,selectRuns.Data(), select.Data());
308       histo = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
309       trackMatchedLowPt.AddAt(histo,index);
310
311       selection = selectionCent; selection += Form("track:matched/trigger:%s/%s/%s/pt:high/acc:in", triggerName.Data() ,selectRuns.Data(), select.Data());
312       histo = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
313       trackMatchedHighPt.AddAt(histo,index);
314
315       selection = selectionCent; selection += Form("track:matched/trigger:%s/%s/charge:pos/%s/acc:in",triggerName.Data(), select.Data(),selectRuns.Data());
316       histo = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
317       trackPosMatched.AddAt(histo,index);
318     
319       selection = selectionCent; selection += Form("track:matched/trigger:%s/%s/charge:neg/%s/acc:in",triggerName.Data(), select.Data(),selectRuns.Data());
320       histo =  (TH1*) ProcessHisto(trackCounters, "run", selection, "");
321       trackNegMatched.AddAt(histo,index);
322
323       selection = selectionCent; selection += Form("track:matched/trigger:%s/%s/%s/acc:in",triggerName.Data(), select.Data(),selectRuns.Data());
324       histo =  (TH1*) ProcessHisto(trackCounters, "run", selection, "");
325       trackAllMatched.AddAt(histo,index);
326
327       selection = selectionCent; selection += Form("track:matched/trigger:%s/%s/%s/acc:in/tagTrack:beamGas",triggerName.Data(), select.Data(),selectRuns.Data());
328       histo =  (TH1*) ProcessHisto(trackCounters, "run", selection, "");
329       trackBeamGasMatched.AddAt(histo,index);
330
331       selection = selectionCent; selection += Form("track:matched/trigger:%s/%s/%s/acc:in/tagTrack:beamGas/pt:high",triggerName.Data(), select.Data(),selectRuns.Data());
332       histo =  (TH1*) ProcessHisto(trackCounters, "run", selection, "");
333       trackBeamGasMatchedHighPt.AddAt(histo,index);
334     }
335   }
336
337   if ( selectPhysics) trigSel = trigWithPS;
338   else trigSel = trigNoPS;
339         
340   //if there is not Beam triggers just stop now
341   Int_t count_trigger=0;
342   for(Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast(); iTrig++){
343     Int_t centBinNr = 0;
344     Int_t index = GetIndex(triggersB,iTrig,centBinNr);
345     count_trigger += (static_cast<TH1*>(trigNoPS.At(index)))->GetEntries();
346   }
347   if(count_trigger<=0) return;
348         
349   Int_t *NumOfBNoPS = new Int_t[nCentBin*nTrig];
350   Int_t *NumOfBWithPS = new Int_t[nCentBin*nTrig];
351         
352   for ( Int_t iCentBin = 0; iCentBin < nCentBin; iCentBin++){
353     for ( Int_t iTrig = 0; iTrig < nTrig; iTrig++){
354       Int_t index = GetIndex(triggersB,iTrig,iCentBin);
355       NumOfBNoPS[index] = (static_cast<TH1*>(trigNoPS.At(index)))->Integral();
356       NumOfBWithPS[index] = (static_cast<TH1*>(trigWithPS.At(index)))->Integral();
357     }
358   }
359         
360   cout<<"//==================================================================================="<<endl;
361   cout<<"// Put all plots in a ps file, easier to publish (Twiki)"<<endl;
362   cout<<"//==================================================================================="<<endl;
363   
364   c1->Print(OutFileNamePDF_open.Data());
365   TFile *rootFileOut = TFile::Open(OutFileNameROOT.Data(),"RECREATE");
366   rootFileOut->cd();
367   TDirectoryFile *dirGlobal = new TDirectoryFile("Global","Global","",(TDirectory*)rootFileOut->GetMotherDir());
368   cout<<"dirGlobal mother "<<(dirGlobal->GetMotherDir())->GetName()<<endl;
369   //An array of TDirectoryFile
370   TObjArray *dirTrigger = new TObjArray();
371   dirTrigger->SetOwner();
372   TObjArray *dirCent = new TObjArray();
373   dirCent->SetOwner();
374   for ( Int_t i = 0; i < triggersB->GetEntriesFast()-1 ; i++) {
375     TString currTrigName = ( (TObjString*) triggersShortName->At(i) )->GetString();
376     TDirectoryFile *dirFile = new TDirectoryFile( currTrigName.Data(),currTrigName.Data(),"",(TDirectory*)rootFileOut->GetMotherDir() );
377     dirTrigger->AddLast( dirFile );
378     for( Int_t j = 0; j < nCentBin; j++) {
379       TString centName = kCentLegendNameShort[j];
380       TDirectoryFile *dirFileCent = new TDirectoryFile( centName.Data(),centName.Data(),"",dirFile );
381       dirCent->AddLast( dirFileCent );
382     }
383   }
384
385   cAll->Print(OutFileNamePDF.Data());
386   dirGlobal->cd();
387   cAll->Write();
388         
389   cout<<"//==================================================================================="<<endl;
390   cout<<"// new canvas with the total number of trigger with and without Phys. Sel."<<endl;
391   cout<<"//==================================================================================="<<endl;
392         
393   TCanvas *cTriggerContent = ProcessCanvasTriggerContent(triggersB, trigNoPS, trigWithPS, "TriggerContent");
394   cTriggerContent->Print(OutFileNamePDF.Data());
395   dirGlobal->cd();
396   cTriggerContent->Write();
397   cTriggerContent->Close();
398
399   cout<<"//==================================================================================="<<endl;
400   cout<<"// new canvas with the relative content of each trigger w/o physics selection"<<endl;
401   cout<<"//==================================================================================="<<endl;
402         
403   TCanvas *cRelativeTriggerContent = ProcessCanvasRelativeTriggerContent(triggersB, trigNoPS, "RelativeTriggerContent");
404   cRelativeTriggerContent->Print(OutFileNamePDF.Data());
405   dirGlobal->cd();
406   cRelativeTriggerContent->Write();
407   cRelativeTriggerContent->Close();
408   
409
410   cout<<"//==================================================================================="<<endl;
411   cout<<"// new canvas with effect from physics selection for each trigger "<<endl;
412   cout<<"//==================================================================================="<<endl;
413         
414   TCanvas *cPhysSelCut = 0x0;
415   cPhysSelCut = ProcessCanvasPhysSelCut(triggersB, trigNoPS, trigWithPS, "PhysSelCutOnCollTrigger");
416   cPhysSelCut->Print(OutFileNamePDF.Data());
417   dirGlobal->cd();
418   cPhysSelCut->Write();
419   cPhysSelCut->Close();
420   rootFileOut->cd();
421         
422   cout<<"//==================================================================================="<<endl;
423   cout<<"// new canvas with effect from T0 pile-up flag for each trigger "<<endl;
424   cout<<"//==================================================================================="<<endl;
425         
426   TCanvas *cPhysSelCutT0Flag = 0x0;
427   cPhysSelCutT0Flag = ProcessCanvasPhysSelCut(triggersB, trigNoPS, trigWithPST0Flag, "PhysSelCutOnCollTriggerT0Flag");
428   cPhysSelCutT0Flag->Print(OutFileNamePDF.Data());
429   dirGlobal->cd();
430   cPhysSelCutT0Flag->Write();
431   cPhysSelCutT0Flag->Close();
432   rootFileOut->cd();
433         
434
435  cout<<"//==================================================================================="<<endl;
436   cout<<"// new canvas with effect from T0 + SPD pile-up flag for each trigger "<<endl;
437   cout<<"//==================================================================================="<<endl;
438         
439   TCanvas *cPhysSelCutT0SPDFlag = 0x0;
440   cPhysSelCutT0SPDFlag = ProcessCanvasPhysSelCut(triggersB, trigNoPS, trigWithPST0SPDFlag, "PhysSelCutOnCollTriggerT0SPDFlag");
441   cPhysSelCutT0SPDFlag->Print(OutFileNamePDF.Data());
442   dirGlobal->cd();
443   cPhysSelCutT0SPDFlag->Write();
444   cPhysSelCutT0SPDFlag->Close();
445   rootFileOut->cd();
446
447   TString canvasName;
448   TString triggerName;  
449   TString legendHeader="";
450         
451   if ( isHeavyIon ){
452
453   cout<<"//==================================================================================="<<endl;
454   cout<<"// new canvas with effect from physics selection for each trigger and centrality bin (only in heavy-ion) "<<endl;
455   cout<<"//==================================================================================="<<endl;
456
457     TCanvas *cPhysSelCutCentrality;
458         
459     //loop over trigger
460     for( Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast(); iTrig++){
461       //skip sum of all triggers
462       if(iTrig == (triggersB->GetEntriesFast()-1)) continue;
463
464       canvasName = "PhysSel_trigger";
465       canvasName += ( (TObjString*) triggersShortName->At(iTrig) )->GetString();
466         
467       cPhysSelCutCentrality = ProcessCanvasPhysSelCutCentrality(triggersB, trigNoPS, trigWithPS, iTrig, canvasName, kCentLegendNameShort+1);
468       cPhysSelCutCentrality->Print(OutFileNamePDF.Data());
469       ( (TDirectoryFile*) dirTrigger->At(iTrig) )->cd();
470       cPhysSelCutCentrality->Write();           
471       cPhysSelCutCentrality->Close();           
472     }
473   }
474   rootFileOut->cd();
475         
476   if ( isHeavyIon ){
477     cout<<"//==================================================================================="<<endl;
478     cout<<"// new canvas for centrality percentile check (only in PbPb) "<<endl;
479     cout<<"//==================================================================================="<<endl;
480    
481     TCanvas *cCentralityCheck;
482                 
483     //loop over trigger
484     for ( Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast(); iTrig++){
485       //skip sum of all triggers
486       if ( iTrig == (triggersB->GetEntriesFast()-1) ) continue;
487                         
488       canvasName = "CentralityCheck_trigger";
489       canvasName += ( (TObjString*) triggersShortName->At(iTrig) )->GetString();
490                         
491       cCentralityCheck = ProcessCanvasCentralityPercentile(triggersB,trigNoPS,trigWithPS,iTrig,canvasName,kCentLegendNameShort);
492
493       cCentralityCheck->Print(OutFileNamePDF.Data());
494       ( (TDirectoryFile*) dirTrigger->At(iTrig) )->cd();
495       cCentralityCheck->Write();
496       cCentralityCheck->Close();
497     }
498   }
499   rootFileOut->cd();
500         
501
502   cout<<"//==================================================================================="<<endl;
503   cout<<"// Ratio of tracks over trigger type (2 canvases) "<<endl;
504   cout<<"//==================================================================================="<<endl;
505
506   //Print a canvas per trigger type
507   TCanvas *cTracksoverTrigger;
508   TCanvas* cTrackMultB;
509         
510   //loop over centrality bins
511   for ( Int_t iCentBin = 0; iCentBin < nCentBin; iCentBin++){
512     if ( isHeavyIon ){
513       legendHeader = "for ";
514       legendHeader += kCentLegendName[iCentBin];
515     }
516     else legendHeader ="";
517     //loop over triggers
518     for(Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast(); iTrig++){
519       //skip sum of all triggers
520       if( iTrig == (triggersB->GetEntriesFast()-1) ) continue;
521
522       ( (TDirectoryFile*) dirCent->At( iTrig*nCentBin+iCentBin ) )->cd();
523
524       canvasName = "RatioTrackTypes_cent";
525       canvasName += iCentBin;
526       canvasName +="trigger";
527       canvasName += ( (TObjString*) triggersShortName->At(iTrig) )->GetString();
528       cTracksoverTrigger = ProcessCanvasTracksoverTrigger(triggersB, trigSel, trackTracker, trackTrigger, trackMatched, trackAll, iTrig, iCentBin, canvasName,legendHeader);
529       cTracksoverTrigger->Print(OutFileNamePDF.Data());
530       cTracksoverTrigger->Write();
531       cTracksoverTrigger->Close();
532
533       canvasName = "TrackMult_cent";
534       canvasName += iCentBin;
535       canvasName +="trigger";
536       canvasName +=( (TObjString*) triggersShortName->At(iTrig) )->GetString();         
537       cTrackMultB= ProcessCanvasTrackMultB(triggersB, trigSel, trackTracker, trackTrigger, trackMatched, iTrig, iCentBin, canvasName, legendHeader);
538       cTrackMultB->Print(OutFileNamePDF.Data());
539       cTrackMultB->Write();
540       cTrackMultB->Close();
541     }
542   }
543   rootFileOut->cd();
544
545   cout<<"//===================================================="<<endl;
546   cout<<"// Draw matched tracks asymmetry for each trigger "<<endl;
547   cout<<"//===================================================="<<endl;
548         
549   //Print a canvas per trigger type
550   TCanvas *cAsymMatched;
551
552   legendHeader = "for all collisions";
553   for ( Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast(); iTrig++){
554     //skip sum of all triggers
555     if ( iTrig == (triggersB->GetEntriesFast()-1) ) continue;
556     
557     ( (TDirectoryFile*) dirTrigger->At( iTrig ) )->cd();
558     
559     canvasName = "AsymMatched";
560     canvasName +="trigger";
561     canvasName +=( (TObjString*) triggersShortName->At(iTrig) )->GetString();
562     Int_t iCentBin = 0;
563     cAsymMatched = ProcessCanvasAsymMatched(triggersB, trackPosMatched, trackNegMatched, trackAllMatched, iTrig, iCentBin, canvasName,legendHeader);
564     cAsymMatched->Print(OutFileNamePDF.Data());
565     cAsymMatched->Write();
566     cAsymMatched->Close();
567   }
568   rootFileOut->cd();
569   legendHeader = ""; 
570
571   cout<<"//===================================================================="<<endl;
572   cout<<"// Draw beam gas contribution to matched tracks for each trigger "<<endl;
573   cout<<"//===================================================================="<<endl;
574         
575   //Print a canvas per trigger type
576   TCanvas *cBeamGasMatched;
577
578   //loop over trigger
579   for ( Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast(); iTrig++){
580     //skip sum of all triggers
581     if ( iTrig == (triggersB->GetEntriesFast()-1)) continue;
582
583     ( (TDirectoryFile*) dirTrigger->At(iTrig) )->cd();
584     canvasName = "BeamGasMatched";
585     canvasName +="trigger";
586     canvasName +=( (TObjString*) triggersShortName->At(iTrig) )->GetString();
587     Int_t iCentBin = 0;
588     cBeamGasMatched= ProcessCanvasBeamGasMatched(triggersB, trackBeamGasMatched, trackBeamGasMatchedHighPt, trackAllMatched, trackMatchedHighPt, iTrig, iCentBin, canvasName,legendHeader);
589     cBeamGasMatched->Print(OutFileNamePDF.Data());
590     cBeamGasMatched->Write();
591     cBeamGasMatched->Close();
592   }
593   rootFileOut->cd();
594
595   cout<<"//=================================================="<<endl;
596   cout<<"// Draw high pt tracks per trigger"<<endl;
597   cout<<"//=================================================="<<endl;
598
599   //Print a canvas per trigger type
600   TCanvas *cHighPtMuons;
601   legendHeader = "for all collisions";
602   //loop over trigger
603   for ( Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast(); iTrig++){
604     //skip sum of all triggers
605     if( iTrig == (triggersB->GetEntriesFast()-1)) continue;
606     
607     ( (TDirectoryFile*) dirTrigger->At( iTrig ) )->cd();
608         
609     canvasName = "HighPtMuons";
610     canvasName +="trigger";
611     canvasName +=( (TObjString*) triggersShortName->At(iTrig) )->GetString();
612
613     Int_t iCentBin = 0;
614     cHighPtMuons = ProcessCanvasHighPtMuons(triggersB, trigSel, trackMatchedLowPt, trackMatchedHighPt, iTrig, iCentBin, canvasName,legendHeader);
615     cHighPtMuons->Print(OutFileNamePDF.Data());
616     cHighPtMuons->Write();
617     cHighPtMuons->Close();
618   }
619   rootFileOut->cd();
620         
621   // close merged file  
622   globalFile->Close();
623   
624   //===================================================================================
625   //Print out the number of trigger without and with Phys. Sel.
626   //===================================================================================
627   
628   cout << endl << endl;
629   //====================================================
630   if (PRINTSTAT){
631     if ( triggersB->At(kCMUS) ) { 
632     
633       // set the format to print labels
634       Int_t centBinNr = 0;
635       THashList* labels = (static_cast<TH1*>(trigWithPS.At(triggersB->GetEntriesFast()*centBinNr+kCMUS)))->GetXaxis()->GetLabels();
636       TString format(Form("\n%%%ds %%9d",0));
637       Int_t nRuns=0;
638     
639       // print value for each label
640       TObjString* label = 0x0;
641       TIter nextLabel(labels);
642       cout << "-------------------------------------------------" << endl;
643       cout << "Run Number" << "\t Number of "<< ( (TObjString*) triggersB->At(kCMUS) )->GetString()<<" after Phys. Sel. " << endl ;  
644       while ((label = static_cast<TObjString*>(nextLabel()))) {
645         nRuns++;
646         Int_t bin = (Int_t) label->GetUniqueID();
647         printf(format.Data(), label->String().Data(), (Int_t) (static_cast<TH1*>(trigWithPS.At(triggersB->GetEntriesFast()*centBinNr+kCMUS)))->GetBinContent(bin));
648       }
649       printf("\n========== Total #runs = %d ==============\n",nRuns);
650       printf("\n\n");
651     
652     
653       cout << "-------------------------------------------------" << endl;
654       cout << "Total statistic" << endl; 
655       cout << " " << endl ; 
656     
657       cout << "-------------------------------------------------------------------" << endl;
658       cout<<"Number of triggers w/o Phys. Sel./ w/ Phys. Sel (Phys. Sel. cut in %)"<<endl;
659       for(Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast()-1; iTrig++){
660         TString triggerNameB = ( (TObjString*) triggersB->At(iTrig) )->GetString();
661                         
662         Int_t   cutinpercent    =       0;
663         printf("%10s\t",triggerNameB.Data());
664         Int_t index = GetIndex(triggersB,iTrig,centBinNr);
665         if(NumOfBNoPS[index]) cutinpercent = (Int_t) ((Double_t)(NumOfBNoPS[index]-NumOfBWithPS[index])/(NumOfBNoPS[index])*100.);
666         printf("%5.2e / %.2e (%d%%)\n", (Double_t) NumOfBNoPS[index],(Double_t) NumOfBWithPS[index],cutinpercent);
667         cutinpercent = 0;
668       }
669     } 
670   }
671   
672   //temporary
673   //    return;
674
675   
676   //--------------------------------------------- //
677   //        monitor quantities run per run        //
678   //--------------------------------------------- //
679
680   //output histos
681   //const Int_t kNHistos =  100;
682   //TObjArray outHist(kNHistos);
683
684   Int_t const nMuonTriggerCase = 7;
685   TH1F *hMuonTrigger[nMuonTriggerCase];
686   TString muonTriggerName[nMuonTriggerCase] = {"Unlike-only","Like-only","Hpt-only","Unlike&Like","Unlike&Hpt","Like&Hpt","Unlike&Like&Hpt"};
687   for ( Int_t i = 0; i < nMuonTriggerCase; i++ ) {
688     hMuonTrigger[i] = new TH1F(Form("hMuonTrigger_%s", muonTriggerName[i].Data()),Form("Trigger %s per run",muonTriggerName[i].Data()),10000,1,10000);
689   }
690
691   TH1F* hTriggerCutVsRun[2], *hTriggerCutWidthVsRun[2];
692   for ( Int_t ihisto=0; ihisto<2; ++ihisto ) {
693     TString cutName = ( ihisto == 0 ) ? "Lpt" : "Hpt";
694     hTriggerCutVsRun[ihisto] = new TH1F(Form("hTriggerCutVsRun%s", cutName.Data()), Form("Trigger %s cut per run", cutName.Data()), 10000,1,10000);
695     hTriggerCutWidthVsRun[ihisto] = (TH1F*)hTriggerCutVsRun[ihisto]->Clone(Form("hTriggerCutWidthVsRun%s", cutName.Data()));
696   }
697   TF1* fitMatchTrig = new TF1("fitMatchTrig","[3] + [0] * ( 1. + TMath::Erf((x - [1]) / [2] / TMath::Sqrt(2.)))", 0.1, 6.);     
698   TH1F* hNClustersPerTrackVsRun_Mean = new TH1F("hNClustersPerTrackVsRun_Mean", "averaged number of associated clusters per track;run;<n_{clusters}>",10000,1,10000);
699   TH1F* hNClustersPerTrackVsRun_Sigma = new TH1F("hNClustersPerTrackVsRun_Sigma", "dispersion of the number of associated clusters per track;run;#sigma_{n_{clusters}}",10000,1,10000);
700   TH1F* hNChamberHitPerTrack_Mean = new TH1F("hNChamberHitPerTrack_Mean", "averaged number of chambers hit per track;run;<n_{chamber hit}>",10000,1,10000);
701   TH1F* hNChamberHitPerTrack_Sigma = new TH1F("hNChamberHitPerTrack_Sigma", "dispersion of the number of chambers hit per track;run;#sigma_{n_{chamber hit}}",10000,1,10000);
702   TH1F* hChi2_Mean = new TH1F("hChi2_Mean", "averaged normalized #chi^{2} distribution;run;<#chi^{2} / ndf>",10000,1,10000);
703   TH1F* hChi2_Sigma = new TH1F("hChi2_Sigma", "dispersion of normalized #chi^{2} distribution;run;#sigma_{#chi^{2} / ndf}",10000,1,10000);
704   TH1F* hNClustersInCh[10];
705   for (Int_t ich=0; ich<10; ich++){
706     hNClustersInCh[ich] = new TH1F(Form("hNClustersInCh%d",ich+1), Form("averaged number of clusters in chamber %d per track;run;<n_{clusters}>",ich+1),10000,1,10000);
707   }
708   TH1F* hClusterChargeMeanInCh[10], *hClusterChargeSigmaInCh[10];
709   for (Int_t ich=0; ich<10; ich++){
710     hClusterChargeMeanInCh[ich] = new TH1F(Form("hClusterChargeMeanInCh%d",ich+1), Form("averaged cluster charge -mean- per track in chamber %d",ich+1),10000,1,10000);
711     hClusterChargeSigmaInCh[ich] = new TH1F(Form("hClusterChargeSigmaInCh%d",ich+1), Form("averaged cluster charge -sigma- per track in chamber %d",ich+1),10000,1,10000);
712   }
713   TH1F* hClusterSizeMeanInCh[10], *hClusterSizeSigmaInCh[10];
714   for (Int_t ich=0; ich<10; ich++){
715     hClusterSizeMeanInCh[ich] = new TH1F(Form("hClusterSizeMeanInCh%d",ich+1), Form("averaged cluster size -mean- per track in chamber %d",ich+1),10000,1,10000);
716     hClusterSizeSigmaInCh[ich] = new TH1F(Form("hClusterSizeSigmaInCh%d",ich+1), Form("averaged cluster size -sigma- per track in chamber %d",ich+1),10000,1,10000);
717   }
718
719   TH1F* hClusterHitMapXInCh[10];
720   for (Int_t ich=0; ich<10; ich++){
721     hClusterHitMapXInCh[ich] = new TH1F(Form("hClusterHitMapXInCh%d",ich+1), Form("averaged cluster position distribution in chamber %d;X (cm)",ich+1),10000,1,10000);
722   }
723   TH1F* hClusterHitMapYInCh[10];
724   for (Int_t ich=0; ich<10; ich++){
725     hClusterHitMapYInCh[ich] = new TH1F(Form("hClusterHitMapYInCh%d",ich+1), Form("averaged cluster position distribution in chamber %d;Y (cm)",ich+1),10000,1,10000);
726   }
727
728
729   Int_t ibin = 1;
730   
731   // Are the runs stored locally or in alien?
732   Int_t isAlienFile = 0;
733   if(alienBaseDir.Contains("alien:")){
734     isAlienFile = 1;
735     alienBaseDir.ReplaceAll("alien://","");
736   }
737
738   cout<<"============================================================"<<endl;
739   cout<< "Monitoring quantities run per run: loop over "<<runs->GetEntriesFast()<<" runs."<<endl;
740   cout<<"  directory = "<<alienBaseDir.Data()<<endl;
741   cout<<"============================================================"<<endl;
742
743   // Loop over runs
744   for ( Int_t irun=0; irun<runs->GetEntriesFast(); irun++ ) {
745     
746     TString run = ((TObjString*)runs->UncheckedAt(irun))->GetString();
747
748     // get the file (or list of files) to be analyzed
749     TString command;
750     TGridResult *res = 0;
751     
752     if(isAlienFile){
753       command = Form("find %s/ %s/%s", alienBaseDir.Data(), run.Data(), QAFileName);
754       res = gGrid->Command(command);
755       if (!res) {
756         Error("PlotMuonQA","no result for the command: %s",command.Data());
757         return;
758       }
759     }
760     else{
761       res = new TGridResult();  
762       
763       command = Form("find %s/*%s/ -name %s | xargs", alienBaseDir.Data(), run.Data(), QAFileName);
764       TString foundFiles = gSystem->GetFromPipe(command.Data());
765       TObjArray* arr = foundFiles.Tokenize(" ");
766
767       for ( Int_t iarr=0; iarr<arr->GetEntries(); iarr++ ) {
768         res->Add(new TObjString(arr->At(iarr)->GetName()));
769       }
770       delete arr;
771     }
772     
773     // Loop over 'find' results and get next LFN
774     TIter nextmap(res);
775     TObjString *objs = 0;
776     TObject* currObj = 0x0;
777     Bool_t searchRunNr = kFALSE;
778     if ( !isAlienFile && run.Contains("*") ) searchRunNr = kTRUE;
779
780     //some checks
781     while ( ( currObj = nextmap() ) ){
782       
783       // get the current file url
784       if(isAlienFile){
785         objs = static_cast<TObjString*>(static_cast<TMap*>(currObj)->GetValue("turl"));
786       }
787       else{
788         objs=static_cast<TObjString*>(currObj);
789       }
790       
791       if (objs->GetString().IsNull()) {
792         Error("PlotMuonQA","turl/obj not found for the run %s... SKIPPING", run.Data());
793         continue;
794       }
795     
796       if ( searchRunNr ) {
797         Int_t runNr = GetRunNumber(objs->GetString());
798         if (runNr > 0) run = Form("%i",runNr);
799       }
800   
801       if ( run.IsDigit() && ! selectRuns.Contains(Form("%i",run.Atoi())) ) continue;
802       
803       // open the outfile for this run
804       TFile *runFile = TFile::Open(objs->GetString());
805       if (!runFile || ! runFile->IsOpen()) {
806         Error("PlotMuonQA","failed to open file: %s", objs->GetName());
807         continue;
808       }
809       runFile->Cd("MUON_QA");
810       
811       // get interesting histos
812       TObjArray* general1 = static_cast<TObjArray*>(runFile->FindObjectAny("general1"));
813       TObjArray* general2 = static_cast<TObjArray*>(runFile->FindObjectAny("general2"));
814       TObjArray* expert = static_cast<TObjArray*>(runFile->FindObjectAny("expert"));
815       
816       if (!general1 || !general2 || !expert){
817         Error("PlotMuonQA","All objects not here !!! ===> Skipping...for %s",objs->GetName());          
818         continue;
819       }
820       
821       TH1* hNClustersPerTrack = static_cast<TH1*>(general1->FindObject("hNClustersPerTrack"));
822       TH1* hNChamberHitPerTrack = static_cast<TH1*>(general1->FindObject("hNChamberHitPerTrack"));
823       TH1* hChi2 = static_cast<TH1*>(general1->FindObject("hChi2"));
824       TH1* hNClustersPerCh = static_cast<TH1*>(general2->FindObject("hNClustersPerCh"));
825       TH1 *hClusterChargePerChMean =static_cast<TH1*>(general2->FindObject("hClusterChargePerChMean")); 
826       TH1 *hClusterChargePerChSigma =static_cast<TH1*>(general2->FindObject("hClusterChargePerChSigma")); 
827       TH1 *hClusterSizePerChMean =static_cast<TH1*>(general2->FindObject("hClusterSizePerChMean")); 
828       TH1 *hClusterSizePerChSigma =static_cast<TH1*>(general2->FindObject("hClusterSizePerChSigma")); 
829       TH1* hMuonTriggers = static_cast<TH1*>(general1->FindObject("hMuonTriggers"));
830       for (Int_t ihisto=0; ihisto<nMuonTriggerCase; ihisto++){
831         Int_t val = 0;
832         if ( hMuonTriggers ) val = hMuonTriggers->GetBinContent(ihisto+2);
833         if ( hMuonTrigger[ihisto]->GetSumw2N() == 0 ) hMuonTrigger[ihisto]->Sumw2();
834         hMuonTrigger[ihisto]->SetBinContent(ibin,val);
835         hMuonTrigger[ihisto]->SetBinError(ibin,TMath::Sqrt(val));
836         hMuonTrigger[ihisto]->GetXaxis()->SetBinLabel(ibin,run.Data());
837       }
838       TH1* hPtDistrib = static_cast<TH1*>(general1->FindObject("hPt"));
839       TH1* hPtDistribLpt = static_cast<TH1*>(general1->FindObject("hPtMatchLpt"));
840       TH1* hPtDistribHpt = static_cast<TH1*>(general1->FindObject("hPtMatchHpt"));
841       if ( hPtDistrib && hPtDistribLpt && hPtDistribHpt ) {
842         if ( hPtDistrib->GetSumw2N() == 0 ) hPtDistrib->Sumw2();
843         TH1* histoMatch[2] = {hPtDistribLpt, hPtDistribHpt};
844         for ( Int_t ihisto=0; ihisto<2; ++ihisto ) {
845           if ( histoMatch[ihisto]->GetSumw2N() == 0 ) histoMatch[ihisto]->Sumw2();
846           if ( histoMatch[ihisto]->GetEntries() == 0 ) continue;
847           histoMatch[ihisto]->Divide(hPtDistrib);
848           Double_t minEff = 99999., maxEff = -1.;
849           Double_t ptMinFit = 0.1;
850           Double_t ptMaxFit = 6.;
851           Int_t ptBinLow = histoMatch[ihisto]->GetXaxis()->FindBin(ptMinFit);
852           Int_t ptBinHigh = histoMatch[ihisto]->GetXaxis()->FindBin(ptMaxFit);
853           for ( Int_t currBin=ptBinLow; currBin<=ptBinHigh; currBin++ ) {
854             Double_t currEff = histoMatch[ihisto]->GetBinContent(currBin);
855             Double_t currPt = histoMatch[ihisto]->GetXaxis()->GetBinCenter(currBin);
856             if ( currPt < 1.5 && minEff > currEff ) {
857               ptMinFit = currPt;
858               minEff = currEff;
859             }
860             if ( currPt > 0.5 && maxEff < currEff ) {
861               ptMaxFit = currPt;
862               maxEff = currEff;
863             }
864           } // loop on histo bins
865           fitMatchTrig->SetParameters(0.5, 0.5, 0.8, 0.2);
866           fitMatchTrig->SetParLimits(0,0.,1.);
867           fitMatchTrig->SetParLimits(1,0.,5.);
868           fitMatchTrig->SetParLimits(2,0.,5.);
869           fitMatchTrig->SetParLimits(3,0.,0.5);
870           histoMatch[ihisto]->Fit(fitMatchTrig,"RQ0","",ptMinFit,ptMaxFit);          
871           Double_t ptCut = fitMatchTrig->GetParameter(1);
872           Double_t ptCutErr = fitMatchTrig->GetParError(1);
873           Double_t ptCutWidth = fitMatchTrig->GetParameter(2);
874           if ( ptCut < 0 || ptCut > 10. ) {
875             ptCut = ptCutErr = ptCutWidth = 0.;
876           }
877           hTriggerCutVsRun[ihisto]->SetBinContent(ibin, ptCut);
878           hTriggerCutVsRun[ihisto]->SetBinError(ibin, ptCutErr);
879           hTriggerCutWidthVsRun[ihisto]->SetBinContent(ibin, ptCut);
880           hTriggerCutWidthVsRun[ihisto]->SetBinError(ibin, ptCutWidth);
881         } // loop on match histos
882       }                 
883       TH2* hClusterHitMapInCh[10];
884       for(Int_t ich=0; ich<10; ich++) hClusterHitMapInCh[ich] = static_cast<TH2*>(expert->FindObject(Form("hClusterHitMapInCh%d",ich+1)));
885       
886       if (!hNClustersPerCh) {
887         Warning("PlotMUONQA","File: %s has empty histograms !", objs->GetName());
888         hNClustersPerTrackVsRun_Mean->SetBinContent(ibin, 0.);
889         hNClustersPerTrackVsRun_Mean->SetBinError(ibin, 1.);
890         hNClustersPerTrackVsRun_Sigma->SetBinContent(ibin, 0.);
891         hNClustersPerTrackVsRun_Sigma->SetBinError(ibin, 1.);
892         hNChamberHitPerTrack_Mean->SetBinContent(ibin, 0.);
893         hNChamberHitPerTrack_Mean->SetBinError(ibin, 1.);
894         hNChamberHitPerTrack_Sigma->SetBinContent(ibin, 0.);
895         hNChamberHitPerTrack_Sigma->SetBinError(ibin, 1.);
896         hChi2_Mean->SetBinContent(ibin, 0.);
897         hChi2_Mean->SetBinError(ibin, 1.);
898         hChi2_Sigma->SetBinContent(ibin, 0.);
899         hChi2_Sigma->SetBinError(ibin, 1.);
900         for (Int_t ich=0; ich<10; ich++) {
901           hNClustersInCh[ich]->SetBinContent(ibin,0.);
902           hNClustersInCh[ich]->SetBinError(ibin,1.);
903           hClusterHitMapXInCh[ich]->SetBinContent(ibin,0.);
904           hClusterHitMapXInCh[ich]->SetBinError(ibin,1.);
905           hClusterHitMapYInCh[ich]->SetBinContent(ibin,0.);
906           hClusterHitMapYInCh[ich]->SetBinError(ibin,1.);       
907         }
908         //runFile->Close();
909         //continue;
910       }
911       else {
912         // fill monitoring plots
913         hNClustersPerTrackVsRun_Mean->SetBinContent(ibin, hNClustersPerTrack->GetMean());
914         hNClustersPerTrackVsRun_Mean->SetBinError(ibin, hNClustersPerTrack->GetMeanError());
915         hNClustersPerTrackVsRun_Sigma->SetBinContent(ibin, hNClustersPerTrack->GetRMS());
916         hNClustersPerTrackVsRun_Sigma->SetBinError(ibin, hNClustersPerTrack->GetRMSError());
917         hNChamberHitPerTrack_Mean->SetBinContent(ibin, hNChamberHitPerTrack->GetMean());
918         hNChamberHitPerTrack_Mean->SetBinError(ibin, hNChamberHitPerTrack->GetMeanError());
919         hNChamberHitPerTrack_Sigma->SetBinContent(ibin, hNChamberHitPerTrack->GetRMS());
920         hNChamberHitPerTrack_Sigma->SetBinError(ibin, hNChamberHitPerTrack->GetRMSError());
921         hChi2_Mean->SetBinContent(ibin, hChi2->GetMean());
922         hChi2_Mean->SetBinError(ibin, hChi2->GetMeanError());
923         hChi2_Sigma->SetBinContent(ibin, hChi2->GetRMS());
924         hChi2_Sigma->SetBinError(ibin, hChi2->GetRMSError());
925         for (Int_t ich=0; ich<10; ich++) {
926           hNClustersInCh[ich]->SetBinContent(ibin,hNClustersPerCh->GetBinContent(ich+1));
927           hNClustersInCh[ich]->SetBinError(ibin,hNClustersPerCh->GetBinError(ich+1));
928           hClusterChargeMeanInCh[ich]->SetBinContent(ibin,hClusterChargePerChMean->GetBinContent(ich+1));
929           hClusterChargeMeanInCh[ich]->SetBinError(ibin,hClusterChargePerChMean->GetBinError(ich+1));
930           hClusterChargeSigmaInCh[ich]->SetBinContent(ibin,hClusterChargePerChSigma->GetBinContent(ich+1));
931           hClusterChargeSigmaInCh[ich]->SetBinError(ibin,hClusterChargePerChSigma->GetBinError(ich+1));
932           hClusterSizeMeanInCh[ich]->SetBinContent(ibin,hClusterSizePerChMean->GetBinContent(ich+1));
933           hClusterSizeMeanInCh[ich]->SetBinError(ibin,hClusterSizePerChMean->GetBinError(ich+1));
934           hClusterSizeSigmaInCh[ich]->SetBinContent(ibin,hClusterSizePerChSigma->GetBinContent(ich+1));
935           hClusterSizeSigmaInCh[ich]->SetBinError(ibin,hClusterSizePerChSigma->GetBinError(ich+1));
936           hNClustersInCh[ich]->SetBinContent(ibin,hNClustersPerCh->GetBinContent(ich+1));
937           hNClustersInCh[ich]->SetBinError(ibin,hNClustersPerCh->GetBinError(ich+1));
938           hClusterHitMapXInCh[ich]->SetBinContent(ibin,hClusterHitMapInCh[ich]->GetMean(1));
939           hClusterHitMapXInCh[ich]->SetBinError(ibin,hClusterHitMapInCh[ich]->GetMeanError(1));
940           hClusterHitMapYInCh[ich]->SetBinContent(ibin,hClusterHitMapInCh[ich]->GetMean(2));
941           hClusterHitMapYInCh[ich]->SetBinError(ibin,hClusterHitMapInCh[ich]->GetMeanError(2));   
942         }
943       }
944       
945       // set labels
946       for ( Int_t ihisto=0; ihisto<2; ++ihisto ) {
947         hTriggerCutVsRun[ihisto]->GetXaxis()->SetBinLabel(ibin,run.Data());
948         hTriggerCutWidthVsRun[ihisto]->GetXaxis()->SetBinLabel(ibin,run.Data());
949       }
950       hNClustersPerTrackVsRun_Mean->GetXaxis()->SetBinLabel(ibin, run.Data());
951       hNClustersPerTrackVsRun_Sigma->GetXaxis()->SetBinLabel(ibin, run.Data());
952       hNChamberHitPerTrack_Mean->GetXaxis()->SetBinLabel(ibin, run.Data());
953       hNChamberHitPerTrack_Sigma->GetXaxis()->SetBinLabel(ibin, run.Data());
954       hChi2_Mean->GetXaxis()->SetBinLabel(ibin, run.Data());
955       hChi2_Sigma->GetXaxis()->SetBinLabel(ibin, run.Data());
956       for (Int_t ich=0; ich<10; ich++){
957         hNClustersInCh[ich]->GetXaxis()->SetBinLabel(ibin, run.Data());
958         hClusterChargeMeanInCh[ich]->GetXaxis()->SetBinLabel(ibin, run.Data());
959         hClusterChargeSigmaInCh[ich]->GetXaxis()->SetBinLabel(ibin, run.Data());
960         hClusterSizeMeanInCh[ich]->GetXaxis()->SetBinLabel(ibin, run.Data());
961         hClusterSizeSigmaInCh[ich]->GetXaxis()->SetBinLabel(ibin, run.Data());
962         hClusterHitMapXInCh[ich]->GetXaxis()->SetBinLabel(ibin, run.Data());
963         hClusterHitMapYInCh[ich]->GetXaxis()->SetBinLabel(ibin, run.Data());
964       }
965       
966       // close outfile for this run
967       runFile->Close();
968       ibin++;      
969     }
970     
971     delete res;
972   }//end loop over runs
973   
974   //sort label
975   hNClustersPerTrackVsRun_Mean->LabelsOption("a");
976   hNClustersPerTrackVsRun_Sigma->LabelsOption("a");
977   hNChamberHitPerTrack_Mean->LabelsOption("a");
978   hNChamberHitPerTrack_Sigma->LabelsOption("a");
979   hChi2_Mean->LabelsOption("a");
980   hChi2_Sigma->LabelsOption("a");
981   
982   for(Int_t ich=0; ich<10; ich++){
983     hNClustersInCh[ich]->LabelsOption("a");
984     hClusterChargeMeanInCh[ich]->LabelsOption("a");
985     hClusterChargeSigmaInCh[ich]->LabelsOption("a");
986     hClusterSizeMeanInCh[ich]->LabelsOption("a");
987     hClusterSizeSigmaInCh[ich]->LabelsOption("a");
988     hClusterHitMapXInCh[ich]->LabelsOption("a");
989     hClusterHitMapYInCh[ich]->LabelsOption("a");
990   }
991   
992   TString dirToGo =  OutFileNameROOT.Data(); dirToGo+=":/";
993   gDirectory->Cd(dirToGo.Data());
994   cout<<"=================================================="<<endl;
995   cout<<"Display Mean and Sigma of the number of associated clusters to a track "<<endl;
996   cout<<"=================================================="<<endl;
997   TLegend *lNClusters = new TLegend(0.75,0.85,0.99,0.99);
998   lNClusters->AddEntry(hNClustersPerTrackVsRun_Mean,"clusters","PL");
999   lNClusters->AddEntry(hNChamberHitPerTrack_Mean,"chamber hit","PL");
1000   
1001   TCanvas* cNClusters = new TCanvas("cNClusters","cNClusters",1200,900);
1002   cNClusters->Divide(1,2);
1003   cNClusters->cd(1);
1004   //hNClustersPerTrackVsRun_Mean->SetMaximum(11);
1005   hNClustersPerTrackVsRun_Mean->SetMinimum(7);
1006   hNClustersPerTrackVsRun_Mean->SetStats(kFALSE);
1007   hNClustersPerTrackVsRun_Mean->GetXaxis()->SetRange(1,ibin-1);
1008   hNClustersPerTrackVsRun_Mean->GetXaxis()->SetNdivisions(1,kFALSE);
1009   //hNClustersPerTrackVsRun_Mean->LabelsOption("u");
1010   hNClustersPerTrackVsRun_Mean->SetLabelSize(0.04);
1011   hNClustersPerTrackVsRun_Mean->SetTitle("averaged number of associated clusters or of the number of chamber hit per track");
1012   hNClustersPerTrackVsRun_Mean->SetLineWidth(2);
1013   hNClustersPerTrackVsRun_Mean->Draw("e");
1014   hNChamberHitPerTrack_Mean->SetLineColor(kRed);
1015   hNChamberHitPerTrack_Mean->SetLineWidth(2);
1016   hNChamberHitPerTrack_Mean->Draw("esame");
1017   lNClusters->Draw("same");
1018   
1019   cNClusters->cd(2);
1020   //hNClustersPerTrackVsRun_Sigma->SetMaximum(1.1);
1021   hNClustersPerTrackVsRun_Sigma->SetMinimum(0.4);
1022   hNClustersPerTrackVsRun_Sigma->SetStats(kFALSE);
1023   hNClustersPerTrackVsRun_Sigma->GetXaxis()->SetRange(1,ibin-1);
1024   hNClustersPerTrackVsRun_Sigma->GetXaxis()->SetNdivisions(1,kFALSE);
1025   //hNClustersPerTrackVsRun_Sigma->LabelsOption("u");
1026   hNClustersPerTrackVsRun_Sigma->SetLabelSize(0.04);
1027   hNClustersPerTrackVsRun_Sigma->SetTitle("dispersion of the number of associated clusters or of the number of chamber hit per track");
1028   hNClustersPerTrackVsRun_Sigma->SetLineWidth(2);
1029   hNClustersPerTrackVsRun_Sigma->Draw("e");
1030   hNChamberHitPerTrack_Sigma->SetLineWidth(2);
1031   hNChamberHitPerTrack_Sigma->SetLineColor(kRed);
1032   hNChamberHitPerTrack_Sigma->Draw("esame");
1033   lNClusters->Draw("same");
1034   
1035   cNClusters->Print(OutFileNamePDF.Data());
1036   dirGlobal->cd();
1037   cNClusters->Write();
1038   
1039   cout<<"=================================================="<<endl;
1040   cout<<" Display average number of cluster per chamber "<<endl;
1041   cout<<"=================================================="<<endl;
1042
1043   TLegend *lNClustersPerCh = new TLegend(0.92,0.45,0.99,0.99);
1044   TCanvas* cNClustersPerCh = new TCanvas("cNClustersPerCh","cNClustersPerCh",1200,900);
1045   cNClustersPerCh->cd();
1046   cNClustersPerCh->SetRightMargin(0.1);
1047   hNClustersInCh[0]->SetStats(kFALSE);
1048   hNClustersInCh[0]->GetXaxis()->SetRange(1,ibin-1);
1049   hNClustersInCh[0]->GetXaxis()->SetNdivisions(1,kFALSE);
1050   //hNClustersInCh[0]->LabelsOption("u");
1051   hNClustersInCh[0]->SetLabelSize(0.02);
1052   hNClustersInCh[0]->SetTitle("averaged number of clusters in chamber i per track");
1053   hNClustersInCh[0]->SetMaximum(1.2);
1054   hNClustersInCh[0]->SetMinimum(0.01);
1055   for (Int_t ich=0; ich<10; ich++) {
1056     hNClustersInCh[ich]->SetLineColor(ich+1+ich/9);
1057     hNClustersInCh[ich]->SetLineWidth(2);
1058     if (ich == 0) hNClustersInCh[ich]->Draw("e");
1059     else hNClustersInCh[ich]->Draw("esame");
1060     lNClustersPerCh->AddEntry(hNClustersInCh[ich],Form("ch%d",ich+1),"PL");
1061   }
1062   lNClustersPerCh->Draw("same");
1063   
1064   cNClustersPerCh->Print(OutFileNamePDF.Data());
1065   dirGlobal->cd();
1066   cNClustersPerCh->Write();
1067
1068   cout<<"=================================================="<<endl;
1069   cout<<" Display average cluster charge per chamber "<<endl;
1070   cout<<"=================================================="<<endl;                                                                   
1071        
1072   TLegend *lClusterChargePerCh = new TLegend(0.92,0.45,0.99,0.99);
1073   TCanvas* cClusterChargePerCh = new TCanvas("cClustersChargePerCh","cClustersChargePerCh",1200,900);
1074   cClusterChargePerCh->SetRightMargin(0.1);
1075   cClusterChargePerCh->Divide(1,2);
1076
1077   cClusterChargePerCh->cd(1);
1078   hClusterChargeMeanInCh[0]->SetStats(kFALSE);
1079   hClusterChargeMeanInCh[0]->GetXaxis()->SetRange(1,ibin-1);
1080   hClusterChargeMeanInCh[0]->GetXaxis()->SetNdivisions(1,kFALSE);
1081   //hClusterChargeInCh[0]->LabelsOption("u"); 
1082   hClusterChargeMeanInCh[0]->SetLabelSize(0.04);
1083   hClusterChargeMeanInCh[0]->SetTitle("Cluster charge mean (fC) per track in chamber i");
1084   hClusterChargeMeanInCh[0]->SetMaximum(150);
1085   hClusterChargeMeanInCh[0]->SetMinimum(30);
1086   for (Int_t ich=0; ich<10; ich++) {
1087     hClusterChargeMeanInCh[ich]->SetLineColor(ich+1+ich/9);
1088     hClusterChargeMeanInCh[ich]->SetLineWidth(2);
1089     if (ich == 0) hClusterChargeMeanInCh[ich]->Draw("e");
1090     else hClusterChargeMeanInCh[ich]->Draw("esame");
1091     lClusterChargePerCh->AddEntry(hClusterChargeMeanInCh[ich],Form("ch%d",ich+1),"PL");
1092   }
1093   lClusterChargePerCh->Draw("same");
1094
1095   cClusterChargePerCh->cd(2);
1096   hClusterChargeSigmaInCh[0]->SetStats(kFALSE);
1097   hClusterChargeSigmaInCh[0]->GetXaxis()->SetRange(1,ibin-1);
1098   hClusterChargeSigmaInCh[0]->GetXaxis()->SetNdivisions(1,kFALSE);
1099   //hClusterChargeInCh[0]->LabelsOption("u");                                                                               
1100   hClusterChargeSigmaInCh[0]->SetLabelSize(0.04);
1101   hClusterChargeSigmaInCh[0]->SetTitle("Cluster charge sigma per track in chamber i");
1102   hClusterChargeSigmaInCh[0]->SetMaximum(250);
1103   hClusterChargeSigmaInCh[0]->SetMinimum(50);
1104   for (Int_t ich=0; ich<10; ich++) {
1105     hClusterChargeSigmaInCh[ich]->SetLineColor(ich+1+ich/9);
1106     hClusterChargeSigmaInCh[ich]->SetLineWidth(2);
1107     if (ich == 0) hClusterChargeSigmaInCh[ich]->Draw("e");
1108     else hClusterChargeSigmaInCh[ich]->Draw("esame");
1109   }
1110   lClusterChargePerCh->Draw("same");
1111
1112   cClusterChargePerCh->Print(OutFileNamePDF.Data());
1113   dirGlobal->cd();
1114   cClusterChargePerCh->Write();
1115
1116   cout<<"=================================================="<<endl;
1117   cout<<" Display average cluster size per chamber     "<<endl;
1118   cout<<"=================================================="<<endl;
1119
1120   TLegend *lClusterSizePerCh = new TLegend(0.92,0.45,0.99,0.99);
1121   TCanvas* cClusterSizePerCh = new TCanvas("cClustersSizePerCh","cClustersSizePerCh",1200,900);
1122   cClusterSizePerCh->SetRightMargin(0.1);
1123   cClusterSizePerCh->Divide(1,2);
1124
1125   cClusterSizePerCh->cd(1);
1126   hClusterSizeMeanInCh[0]->SetStats(kFALSE);
1127   hClusterSizeMeanInCh[0]->GetXaxis()->SetRange(1,ibin-1);
1128   hClusterSizeMeanInCh[0]->GetXaxis()->SetNdivisions(1,kFALSE);
1129
1130   hClusterSizeMeanInCh[0]->SetLabelSize(0.04);
1131   hClusterSizeMeanInCh[0]->SetTitle("Cluster size mean (npads) per track in chamber i");
1132   hClusterSizeMeanInCh[0]->SetMaximum(18);
1133   hClusterSizeMeanInCh[0]->SetMinimum(0);
1134   for (Int_t ich=0; ich<10; ich++) {
1135     hClusterSizeMeanInCh[ich]->SetLineColor(ich+1+ich/9);
1136     hClusterSizeMeanInCh[ich]->SetLineWidth(2);
1137     if (ich == 0) hClusterSizeMeanInCh[ich]->Draw("e");
1138     else hClusterSizeMeanInCh[ich]->Draw("esame");
1139     lClusterSizePerCh->AddEntry(hClusterSizeMeanInCh[ich],Form("ch%d",ich+1),"PL");
1140   }
1141   lClusterSizePerCh->Draw("same");
1142
1143   cClusterSizePerCh->cd(2);
1144   hClusterSizeSigmaInCh[0]->SetStats(kFALSE);
1145   hClusterSizeSigmaInCh[0]->GetXaxis()->SetRange(1,ibin-1);
1146   hClusterSizeSigmaInCh[0]->GetXaxis()->SetNdivisions(1,kFALSE);
1147
1148   hClusterSizeSigmaInCh[0]->SetLabelSize(0.04);
1149   hClusterSizeSigmaInCh[0]->SetTitle("Cluster size sigma (npads) per track in chamber i");
1150   hClusterSizeSigmaInCh[0]->SetMaximum(7);
1151   hClusterSizeSigmaInCh[0]->SetMinimum(0);
1152   for (Int_t ich=0; ich<10; ich++) {
1153     hClusterSizeSigmaInCh[ich]->SetLineColor(ich+1+ich/9);
1154     hClusterSizeSigmaInCh[ich]->SetLineWidth(2);
1155     if (ich == 0) hClusterSizeSigmaInCh[ich]->Draw("e");
1156     else hClusterSizeSigmaInCh[ich]->Draw("esame");
1157   }
1158   lClusterSizePerCh->Draw("same");
1159
1160   cClusterSizePerCh->Print(OutFileNamePDF.Data());
1161   dirGlobal->cd();
1162   cClusterSizePerCh->Write();
1163
1164
1165   cout<<"=================================================="<<endl;
1166   cout<<"Display average X and Y position of clusters per chamber"<<endl;
1167   cout<<"=================================================="<<endl;
1168   TLegend *lClusterHitMapPerCh = new TLegend(0.92,0.45,0.99,0.99);
1169   TCanvas* cClusterHitMapPerCh = new TCanvas("cClusterHitMapPerCh","cClusterHitMapPerCh",1200,900);
1170   cClusterHitMapPerCh->Divide(1,2);
1171   cClusterHitMapPerCh->GetPad(1)->SetRightMargin(0.1);
1172   cClusterHitMapPerCh->GetPad(2)->SetRightMargin(0.1);
1173         
1174   cClusterHitMapPerCh->cd(1);
1175   hClusterHitMapXInCh[0]->SetStats(kFALSE);
1176   hClusterHitMapXInCh[0]->GetXaxis()->SetRange(1,ibin-1);
1177   hClusterHitMapXInCh[0]->GetXaxis()->SetNdivisions(1,kFALSE);
1178   //hNClustersInCh[0]->LabelsOption("u");
1179   hClusterHitMapXInCh[0]->SetLabelSize(0.04);
1180   hClusterHitMapXInCh[0]->SetTitle("<X> of clusters - associated to a track - in chamber i");
1181   hClusterHitMapXInCh[0]->SetMaximum(30);
1182   hClusterHitMapXInCh[0]->SetMinimum(-30);
1183   for (Int_t ich=0; ich<10; ich++) {
1184     hClusterHitMapXInCh[ich]->SetLineColor(ich+1+ich/9);
1185     hClusterHitMapXInCh[ich]->SetLineWidth(2);
1186     if (ich == 0) hClusterHitMapXInCh[ich]->Draw("e");
1187     else hClusterHitMapXInCh[ich]->Draw("esame");
1188     
1189     lClusterHitMapPerCh->AddEntry(hClusterHitMapXInCh[ich],Form("ch%d",ich+1),"PL");
1190   }
1191   lClusterHitMapPerCh->Draw("same");
1192   
1193   cClusterHitMapPerCh->cd(2);
1194   hClusterHitMapYInCh[0]->SetStats(kFALSE);
1195   hClusterHitMapYInCh[0]->GetXaxis()->SetRange(1,ibin-1);
1196   hClusterHitMapYInCh[0]->GetXaxis()->SetNdivisions(1,kFALSE);
1197   //hNClustersInCh[0]->LabelsOption("u");
1198   hClusterHitMapYInCh[0]->SetLabelSize(0.04);
1199   hClusterHitMapYInCh[0]->SetTitle("<Y> of clusters - associated to a track - in chamber i");
1200   hClusterHitMapYInCh[0]->SetMaximum(30);
1201   hClusterHitMapYInCh[0]->SetMinimum(-30);
1202   for (Int_t ich=0; ich<10; ich++) {
1203     hClusterHitMapYInCh[ich]->SetLineColor(ich+1+ich/9);
1204     hClusterHitMapYInCh[ich]->SetLineWidth(2);
1205     if (ich == 0) hClusterHitMapYInCh[ich]->Draw("e");
1206     else hClusterHitMapYInCh[ich]->Draw("esame");
1207   }
1208   lClusterHitMapPerCh->Draw("same");
1209
1210   cClusterHitMapPerCh->Print(OutFileNamePDF.Data());
1211   dirGlobal->cd();
1212   cClusterHitMapPerCh->Write();
1213
1214
1215   cout<<"=================================================="<<endl;
1216   cout<<" Display tracks ChiSquare "<<endl;
1217   cout<<"=================================================="<<endl;
1218   TCanvas* cChi2 = new TCanvas("cChi2","cChi2",1200,900);
1219   cChi2->Divide(1,2);
1220   cChi2->cd(1);
1221   hChi2_Mean->SetStats(kFALSE);
1222   hChi2_Mean->GetXaxis()->SetRange(1,ibin-1);
1223   hChi2_Mean->GetXaxis()->SetNdivisions(1,kFALSE);
1224   //hChi2_Mean->LabelsOption("u");
1225   hChi2_Mean->SetLabelSize(0.04);
1226   hChi2_Mean->SetLineWidth(2);
1227   hChi2_Mean->Draw("e");
1228
1229   cChi2->cd(2);
1230   hChi2_Sigma->SetStats(kFALSE);
1231   hChi2_Sigma->GetXaxis()->SetRange(1,ibin-1);
1232   hChi2_Sigma->GetXaxis()->SetNdivisions(1,kFALSE);
1233   //hChi2_Sigma->LabelsOption("u");
1234   hChi2_Sigma->SetLabelSize(0.04);
1235   hChi2_Sigma->SetLineWidth(2);
1236   hChi2_Sigma->Draw("e");
1237
1238   cChi2->Print(OutFileNamePDF.Data());
1239   dirGlobal->cd();
1240   cChi2->Write();
1241
1242   cout<<"=================================================="<<endl;
1243   cout<<" Display track Lpt/Hpt "<<endl;
1244   cout<<"=================================================="<<endl;
1245
1246   if ( hTriggerCutVsRun[0] && hTriggerCutVsRun[1] ) {
1247     TCanvas* cLptHpt = new TCanvas("cLptHpt","cLptHpt",1200,900);
1248     cLptHpt->Divide(1,2);
1249     TLegend* legLptHpt = new TLegend(0.72,0.7,0.9,0.85);
1250     legLptHpt->SetBorderSize(1);
1251     for ( Int_t ihisto=0; ihisto<2; ++ihisto) {
1252       cLptHpt->cd(ihisto+1);
1253       TH1* currHistos[2] = {hTriggerCutVsRun[ihisto], hTriggerCutWidthVsRun[ihisto]};
1254       for ( Int_t jhisto=0; jhisto<2; jhisto++ ) {
1255         currHistos[jhisto]->GetXaxis()->SetRange(1,ibin-1);
1256         currHistos[jhisto]->GetYaxis()->SetRangeUser(0.,5.);
1257         currHistos[jhisto]->LabelsOption("a");
1258         currHistos[jhisto]->SetStats(kFALSE);
1259         currHistos[jhisto]->GetXaxis()->SetLabelSize(0.04);
1260         currHistos[jhisto]->SetLineWidth(2);
1261       }
1262       hTriggerCutWidthVsRun[ihisto]->SetLineColor(2);
1263       hTriggerCutWidthVsRun[ihisto]->SetMarkerColor(2);
1264       hTriggerCutWidthVsRun[ihisto]->SetFillColor(2);
1265       hTriggerCutWidthVsRun[ihisto]->SetFillStyle(3001);
1266       hTriggerCutWidthVsRun[ihisto]->Draw("e2");
1267       hTriggerCutVsRun[ihisto]->Draw("esame");
1268       if ( ihisto == 0 ) {
1269         legLptHpt->AddEntry(hTriggerCutWidthVsRun[ihisto],"Fit width","f");
1270         legLptHpt->AddEntry(hTriggerCutVsRun[ihisto],"pt cut from fit (stat error)","lp");
1271         legLptHpt->Draw("same");
1272       }
1273     }
1274     cLptHpt->Print(OutFileNamePDF.Data());
1275     dirGlobal->cd();
1276     cLptHpt->Write();
1277  }
1278
1279
1280   cout<<"=================================================="<<endl;
1281   cout<<" Display muon trigger "<<endl;
1282   cout<<"=================================================="<<endl;
1283   
1284   TCanvas* cMuonTriggerUnlikeLike = new TCanvas("cMuonTriggerUnlikeLike","cMuonTriggerUnlikeLike",1200,900);
1285   TCanvas* cMuonTriggerHpt = new TCanvas("cMuonTriggerHpt","cMuonTriggerHpt",1200,900);
1286   cMuonTriggerHpt->Divide(1,2);
1287   
1288   Int_t const ntrig = 3;
1289   Int_t  const nhist = 3;
1290   TH1F *hRelMuonTrigger[ntrig], *hTot;
1291   
1292   //3 configurations (3x3 histos for 3 canvases)
1293   Int_t conf[ntrig][nhist]={{0,1,3},{0,2,4},{1,2,5}};
1294   TString sconf[ntrig][nhist]={{"hTriggerUnlikeOnly","hTriggerLikeOnly","hTriggerUnlikeAndLike"},{"hTriggerUnlikeOnly","hTriggerHptOnly","hTriggerUnlikeAndHpt"},{"hTriggerLikeOnly","hTriggerHptOnly","hTriggerLikeAndHpt"}};
1295   TString sname;
1296   
1297   for ( Int_t i=0; i < ntrig; i++ ) {
1298     for ( Int_t j=0; j < nhist; j++ ) {
1299       sname = sconf[i][j]; sname +=(i+1);
1300       hMuonTrigger[conf[i][j]]->GetXaxis()->SetRange(1,ibin-1);
1301       hRelMuonTrigger[j] = (TH1F*)hMuonTrigger[conf[i][j]]->Clone(sname);
1302       hRelMuonTrigger[j]->SetLineColor(j+1);
1303       hRelMuonTrigger[j]->SetStats(kFALSE);
1304       hRelMuonTrigger[j]->GetXaxis()->SetNdivisions(1,kFALSE);
1305       hRelMuonTrigger[j]->LabelsOption("a");                 
1306       hRelMuonTrigger[j]->SetLabelSize(0.02);
1307       //hRelMuonTrigger[j]->GetXaxis()->SetLabelSize(0.04);
1308       hRelMuonTrigger[j]->SetLineWidth(2);
1309       hRelMuonTrigger[j]->SetTitle("");
1310       
1311     }
1312     sname = "hTot";
1313     sname += (i+1);
1314     hTot = (TH1F*) hRelMuonTrigger[0]->Clone(sname);
1315     hTot->Add(hRelMuonTrigger[1]);
1316     hTot->Add(hRelMuonTrigger[2],-1);
1317     hRelMuonTrigger[0]->Add(hRelMuonTrigger[2],-1);
1318     hRelMuonTrigger[1]->Add(hRelMuonTrigger[2],-1);
1319     
1320     for(Int_t j=0; j < nhist; j++) hRelMuonTrigger[j]->Divide(hTot);
1321     
1322     if(i==0) cMuonTriggerUnlikeLike->cd();
1323     else cMuonTriggerHpt->cd(i);
1324     
1325     if (i==0) hRelMuonTrigger[i]->SetTitle("Relative muon triggers content");
1326     TLegend *leg = new TLegend(0.72,0.7,0.9,0.85);
1327     leg->SetBorderSize(1);
1328     
1329     for(Int_t j=0; j<nhist; j++){
1330      if(j==0){
1331        hRelMuonTrigger[j]->SetMaximum(1);
1332        hRelMuonTrigger[j]->SetMinimum(0);
1333        hRelMuonTrigger[j]->Draw("e");
1334      }
1335      else hRelMuonTrigger[j]->Draw("esame");
1336      sname = sconf[i][j];
1337      leg->AddEntry(hRelMuonTrigger[j],sname,"l");
1338     }
1339     leg->Draw("same");
1340   }
1341   cMuonTriggerUnlikeLike->Print(OutFileNamePDF.Data());
1342   dirGlobal->cd();
1343   cMuonTriggerUnlikeLike->Write();
1344   cMuonTriggerHpt->Print(OutFileNamePDF.Data());
1345   cMuonTriggerHpt->Write(); 
1346   
1347   // close the PDF file
1348  c1->Print(OutFileNamePDF_close.Data());
1349  c1->Close();
1350  //Note: closing the file delete all related TDirectoryFile (dirCent and dirTrigger)
1351  rootFileOut->Close(); 
1352  
1353
1354  delete runs;
1355  delete triggersB;
1356  delete colorInd;
1357
1358  return;
1359  
1360 }
1361
1362 void SetCanvas(TCanvas *canvas, Int_t logy){
1363   
1364   if(!canvas) return;
1365   canvas->SetTopMargin(0.05);
1366   canvas->SetRightMargin(0.01);
1367   canvas->SetGridy(1);
1368   canvas->SetLogy(logy);
1369         
1370   return;
1371 }
1372
1373 Bool_t IsHeavyIonCollision(AliCounterCollection *eventCounters){
1374         
1375   if(!eventCounters) return kFALSE;
1376         
1377   Double_t sum = eventCounters->GetSum("v0mult:low,int,high");
1378   Bool_t result = kTRUE;
1379   if(sum<=0) result = kFALSE;
1380         
1381   cout<<" Collision type is set to ";
1382   if( result == kFALSE) cout<<"p-p"<<endl;
1383   else cout<<"heavy-ion"<<endl;
1384         
1385   return result;
1386 }
1387
1388 TCanvas *ProcessCanvasAllTrigger( AliCounterCollection *eventCounters, TString canvasName) {
1389
1390   if ( !eventCounters ) return 0;
1391
1392   TString cName = Form("c%s",canvasName.Data());
1393   TCanvas *cAll = new TCanvas(canvasName.Data(),canvasName.Data());
1394   cAll->SetLeftMargin(0.18);
1395   cAll->SetRightMargin(0.18);
1396   cAll->SetLogz(1);
1397   cAll->cd();
1398
1399   TH2* hAll = (TH2*) ProcessHisto2D(eventCounters, "trigger", "run", "run:any" , "");
1400   for ( Int_t ibin=1; ibin <= hAll->GetYaxis()->GetNbins(); ++ibin ) {
1401     TString currLabel = hAll->GetYaxis()->GetBinLabel(ibin);
1402     TObjArray* labelArray = currLabel.Tokenize("-");
1403     labelArray->SetOwner();
1404     //cout<<currLabel<<endl;
1405     TString newLabel = labelArray->At(0)->GetName();
1406     if ( labelArray->GetEntries() >= 2 ) newLabel = Form("%s-%s", newLabel.Data(), labelArray->At(1)->GetName());
1407     hAll->GetYaxis()->SetBinLabel(ibin, newLabel.Data());
1408     delete labelArray;
1409   }
1410   hAll->Draw("COLZ");
1411
1412   return cAll;
1413 }
1414
1415 TCanvas *ProcessCanvasTriggerContent(TObjArray *array, TObjArray trigNoPS, TObjArray trigWithPS, TString canvasName){
1416  
1417   if(!array) return 0x0;
1418         
1419   TString cName =  "c"; 
1420   cName += canvasName; 
1421   TCanvas *cTriggerContent = new TCanvas(canvasName,cName,1200,900);
1422   SetCanvas(cTriggerContent);
1423   cTriggerContent->cd();
1424  
1425   TLegend* legcTC = new TLegend(0.2,0.15,0.50,0.40);
1426   legcTC->SetHeader("Physics Selection");
1427   legcTC->AddEntry(".","applied :","");
1428  
1429   for(Int_t iTrig = 0; iTrig < array->GetEntriesFast(); iTrig++){
1430     //skip the sum of all triggers
1431     if( iTrig == (array->GetEntriesFast()-1) ) continue;
1432     TH1* hNoPS = static_cast<TH1*>(trigNoPS.At(iTrig));
1433     TH1* hWithPS = static_cast<TH1*>(trigWithPS.At(iTrig));
1434     if (!hNoPS ||!hWithPS) continue;
1435     hNoPS->SetLineStyle(2);
1436     if(iTrig==0){
1437       hNoPS->SetMinimum(1e-3);
1438       hNoPS->Draw();
1439       hWithPS->Draw("same");
1440     }
1441     else{
1442       hNoPS->Draw("same");
1443       hWithPS->Draw("same");
1444     }
1445     legcTC->AddEntry(hWithPS,(( (TObjString*) array->At(iTrig) )->GetString()).Data(),"l");
1446   }
1447   legcTC->AddEntry(".","not applied :","");
1448         
1449   for(Int_t iTrig = 0; iTrig < array->GetEntriesFast(); iTrig++){
1450    if( iTrig == (array->GetEntriesFast()-1) ) continue;
1451     TH1* hNoPS = static_cast<TH1*>(trigNoPS.At(iTrig));
1452     if(hNoPS) legcTC->AddEntry(hNoPS,(( (TObjString*) array->At(iTrig) )->GetString()).Data(),"l");      
1453   }
1454         
1455   legcTC->Draw("same");
1456  
1457   return cTriggerContent;
1458 }
1459
1460 TCanvas *ProcessCanvasRelativeTriggerContent(TObjArray *triggersB, TObjArray trigNoPS, TString canvasName){
1461         
1462   if(!triggersB) return 0x0;
1463         
1464   TString cName =  "c" ; 
1465   cName += canvasName;
1466   TCanvas *cRelativeTriggerContent = new TCanvas(canvasName,cName,1200,900);
1467   SetCanvas(cRelativeTriggerContent);
1468   cRelativeTriggerContent->cd();
1469         
1470   TObjArray relTrigNoPS(triggersB->GetEntriesFast());
1471   TLegend* legcRTC = new TLegend(0.2,0.15,0.50,0.40);
1472         
1473   TString hName, hTriggerName;
1474   Int_t indAllTrig = triggersB->GetEntriesFast()-1;
1475   TH1* hAllTrig = static_cast<TH1*> (trigNoPS.At(indAllTrig));
1476   if(!hAllTrig) return 0;
1477
1478   for(Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast()-1; iTrig++){
1479     hName = "ratio";
1480     hName += ( (TObjString*) triggersB->At(iTrig) )->GetString();
1481     TH1* histo = static_cast<TH1*> (trigNoPS.At(iTrig));
1482     if(!histo) continue;
1483     TH1* hRatio = (TH1*) histo->Clone(hName);
1484     hRatio->Divide(hAllTrig);
1485     hRatio->SetLineStyle(1);
1486     if(iTrig==0){
1487       hRatio->SetMaximum(1.5);
1488       hRatio->SetMinimum(0.001);
1489       hRatio->SetLabelSize(0.04);
1490       hRatio->GetYaxis()->SetTitle("Relative trigger content"); 
1491       hRatio->Draw("E");
1492     }
1493     else{
1494       hRatio->Draw("ESAME");
1495     }
1496     relTrigNoPS.AddAt(hRatio,iTrig);
1497   }
1498
1499   legcRTC->SetHeader("Physics Selection not applied");  
1500   for(Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast()-1; iTrig++){
1501     TH1* hRatio = static_cast<TH1*>(relTrigNoPS.At(iTrig));
1502     if (!hRatio) continue;
1503     legcRTC->AddEntry(hRatio,(( (TObjString*) triggersB->At(iTrig) )->GetString()).Data(),"l");
1504   }
1505   legcRTC->Draw("same");
1506         
1507   return cRelativeTriggerContent;
1508 }
1509
1510 TCanvas *ProcessCanvasPhysSelCut(TObjArray *triggersB, TObjArray trigNoPS, TObjArray trigWithPS, TString canvasName){
1511         
1512   if(!triggersB) return 0x0;
1513
1514   TString cName = "c";
1515   cName += canvasName;
1516   TCanvas *c1 = new TCanvas(canvasName,cName,1200,900);
1517   SetCanvas(c1);
1518   c1->cd();
1519          
1520   TObjArray trigRatio(triggersB->GetEntriesFast());
1521   TLegend* legcRTC = new TLegend(0.2,0.15,0.50,0.40);
1522   TString header = "Physics Selection Cut on selected triggers:";
1523   if (canvasName.Contains("T0Flag")) header += " and T0 pile-up event selection"; 
1524   if (canvasName.Contains("T0SPDFlag")) header += " and T0, SPD pile-up event selection"; 
1525   legcRTC->SetHeader(header.Data());
1526
1527   TString hName;
1528   for(Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast()-1; iTrig++){
1529                 
1530     hName = "ratio";
1531     hName += ( (TObjString*) triggersB->At(iTrig) )->GetString();
1532     TH1 * hWithPS = (TH1*) (static_cast<TH1*> (trigWithPS.At(iTrig)));
1533     TH1 * hNoPS = (TH1*) (static_cast<TH1*> (trigNoPS.At(iTrig)));
1534     if (!hNoPS || !hWithPS) continue;
1535     TH1 *hRatio = (TH1*) hWithPS->Clone(hName);
1536     hRatio->Divide(hNoPS);
1537     hName = "ratioNoPS";
1538     hName += ( (TObjString*) triggersB->At(iTrig) )->GetString();
1539
1540     if(iTrig==0){
1541       hRatio->SetMaximum(1.5);
1542       hRatio->SetMinimum(0.05);
1543       hRatio->SetLabelSize(0.02);
1544       hRatio->GetYaxis()->SetTitle("Accepted / All from Phys. Sel."); 
1545       hRatio->SetTitle("Physics Selection Cut"); 
1546       hRatio->Draw("E");
1547     }
1548     else{
1549       hRatio->Draw("ESAME");
1550     }
1551     trigRatio.AddAt(hRatio,iTrig);
1552   }
1553          
1554   for(Int_t iTrig = 0; iTrig < triggersB->GetEntriesFast()-1; iTrig++){
1555     TH1 * histo = static_cast<TH1*> (trigRatio.At(iTrig));
1556     if (!histo) continue;
1557     legcRTC->AddEntry(histo,(( (TObjString*) triggersB->At(iTrig) )->GetString()).Data(),"l");
1558   }
1559   legcRTC->Draw("same");
1560                 
1561   return c1;
1562 }       
1563
1564 TCanvas *ProcessCanvasPhysSelCutCentrality(TObjArray *triggersB, TObjArray trigNoPS, TObjArray trigWithPS, Int_t trigNr, TString canvasName, TString *legendHeader){
1565         
1566   if(!triggersB || !legendHeader) return 0x0;
1567
1568   TString cName = "c";
1569   cName += canvasName;
1570   TCanvas *c1 = new TCanvas(canvasName,cName,1200,900);
1571   SetCanvas(c1);
1572   c1->cd();
1573         
1574   Int_t const centBinMaxi = kCentBinMax - 1;
1575   TObjArray trigWithPSRatio(centBinMaxi);
1576   TLegend* legcRTC = new TLegend(0.2,0.15,0.50,0.40);
1577   legcRTC->SetHeader("V0 amplitude bins:");
1578   Int_t colorTab[3] = {kBlack,kRed,kBlue};
1579   TArrayI colorInd(centBinMaxi);
1580   for (Int_t i = 0; i < centBinMaxi; i++ ) {
1581     if(i<3) colorInd.AddAt(colorTab[i],i);
1582     else colorInd.AddAt(colorTab[2]+i-2,i);
1583   }
1584
1585   TString hName;
1586         
1587   Float_t yMin = 0.05, yMax = 2;
1588         
1589   for(Int_t iCentBin = 0; iCentBin < centBinMaxi; iCentBin++){
1590
1591     Int_t index = GetIndex(triggersB,trigNr,iCentBin);
1592     TH1 *hWithPS = static_cast<TH1*> (trigWithPS.At(index));
1593     TH1 *hNoPS = static_cast<TH1*> (trigNoPS.At(index));
1594     if (!hNoPS || !hWithPS) continue;
1595                 
1596     hName = "ratio";
1597     hName += ( (TObjString*) triggersB->At(trigNr) )->GetString();
1598     TH1 *hRatio  = (TH1*) hWithPS->Clone(hName);
1599     hRatio->Divide(hNoPS);
1600     hRatio->SetLineColor(colorInd.At(iCentBin));
1601     if ( iCentBin == 0 ) {
1602       hRatio->SetMaximum(yMax);
1603       hRatio->SetMinimum(yMin);
1604       hRatio->SetLabelSize(0.02);
1605       hRatio->GetYaxis()->SetTitle("Accepted / All from Phys. Sel.");
1606       TString sTitle = "for ", sTitle2 = (( (TObjString*) triggersB->At(trigNr) )->GetString()).Data();
1607       if ( !sTitle2.IsNull() ) sTitle += sTitle2;
1608       else sTitle = "";
1609       hRatio->SetTitle(Form("Phys. Sel. %s - Multiplicity from V0 amplitude",sTitle.Data()));
1610       hRatio->Draw("E");
1611     }
1612     else{
1613       hRatio->Draw("ESAME");
1614     }
1615     trigWithPSRatio.AddAt(hRatio,iCentBin);
1616   }
1617         
1618   for ( Int_t centBin = 0; centBin < centBinMaxi; centBin++ ){
1619     TH1 *hRatio = static_cast<TH1*> (trigWithPSRatio.At(centBin));
1620     if ( !hRatio ) continue;
1621     legcRTC->AddEntry(hRatio,(legendHeader[centBin]).Data(),"l");
1622   }
1623   legcRTC->Draw("same");
1624         
1625         
1626   return c1;
1627 }       
1628
1629 TCanvas *ProcessCanvasCentralityPercentile(TObjArray *triggersB, TObjArray trigNoPS, TObjArray trigWithPS, Int_t trigNr, TString canvasName, TString *legendHeader){
1630         
1631   if(!triggersB || !legendHeader) return 0x0;
1632                 
1633   TString cName = "c";
1634   cName += canvasName;
1635   TCanvas *c1 = new TCanvas(canvasName,cName,1200,900);
1636   SetCanvas(c1,0);
1637   c1->cd();
1638         
1639   Int_t const centBinMaxi = 2;
1640   TObjArray trigRatio(centBinMaxi), trigRatioNoPS(centBinMaxi);
1641   TLegend* legcRTC = new TLegend(0.2,0.15,0.50,0.40);
1642   legcRTC->SetHeader("Physics Selection");
1643         
1644  Int_t colorTab[2] = {kRed,kBlue};
1645  TArrayI colorInd(centBinMaxi);
1646  for (Int_t i = 0; i < centBinMaxi; i++ ) {
1647    if(i<2) colorInd.AddAt(colorTab[i],i);
1648    else colorInd.AddAt(colorTab[1]+i-1,i);
1649  }
1650  
1651  TString hName;
1652  
1653  Float_t yMin = 0., yMax = 0.3;
1654  
1655  //process centrality bin 0-10% (centBin=3) and 60-80% (centBin=3) and compare it to 0-80% (centBin=1)  
1656  Int_t centBinMin = 2;
1657  TH1 *hWithPSAll = static_cast<TH1*> (trigWithPS.At(1*triggersB->GetEntriesFast()+trigNr));
1658  TH1 *hNoPSAll = static_cast<TH1*> (trigNoPS.At(1*triggersB->GetEntriesFast()+trigNr));
1659  if (!hNoPSAll || !hWithPSAll) return 0;
1660  
1661  for ( Int_t centBin = centBinMin; centBin < centBinMaxi+centBinMin; centBin++){
1662    
1663    if ( centBin > kCentBinMax ) continue;
1664    
1665    Int_t index = GetIndex(triggersB,trigNr,centBin);
1666    TH1 *hWithPS = static_cast<TH1*> (trigWithPS.At(index));
1667    TH1 *hNoPS = static_cast<TH1*> (trigNoPS.At(index));
1668    if (!hNoPS || !hWithPS) continue;
1669    
1670    hName = "ratio";
1671    hName += ( (TObjString*) triggersB->At(trigNr) )->GetString();
1672    TH1 *hRatio = (TH1*) hWithPS->Clone(hName);
1673    hRatio->Divide(hWithPSAll);
1674    hRatio->Scale(0.8);
1675    hRatio->SetLineColor(colorInd.At(centBin-centBinMin));
1676    hName = "ratioNoPS";
1677    hName += ( (TObjString*) triggersB->At(trigNr) )->GetString();
1678    TH1 *hRatioNoPS = (TH1*) (hNoPS->Clone(hName));
1679    hRatioNoPS->Divide(hNoPSAll);
1680    hRatioNoPS->Scale(0.8);
1681    hRatioNoPS->SetLineStyle(2);
1682    hRatioNoPS->SetLineColor(colorInd.At(centBin-centBinMin));
1683
1684    if ( centBin == centBinMin ){
1685      hRatio->SetMaximum(yMax);
1686      hRatio->SetMinimum(yMin);
1687      hRatio->SetLabelSize(0.02);
1688      hRatio->GetYaxis()->SetTitle("Centrality percentile check"); 
1689      TString sTitle = "for ", sTitle2 = (( (TObjString*) triggersB->At(trigNr) )->GetString()).Data();
1690      if ( !sTitle2.IsNull() ) sTitle += sTitle2;
1691      else sTitle = "";
1692      hRatio->SetTitle(Form("Centrality percentile check %s - Multiplicity from V0 amplitude",sTitle.Data()));
1693      hRatio->Draw("E");
1694      hRatioNoPS->Draw("EPSAME");
1695    }
1696    else{
1697      hRatio->Draw("ESAME");
1698      hRatioNoPS->Draw("EPSAME");
1699    }
1700    trigRatio.AddAt(hRatio,centBin-centBinMin);
1701    trigRatioNoPS.AddAt(hRatioNoPS,centBin-centBinMin);
1702  }
1703         
1704   legcRTC->AddEntry(".","applied :","");
1705   for(Int_t centBin = centBinMin; centBin < centBinMaxi+centBinMin; centBin++){
1706     TH1 *hRatio = static_cast<TH1*> (trigRatio.At(centBin-centBinMin));
1707     if (!hRatio) continue;
1708     legcRTC->AddEntry(hRatio,(legendHeader[centBin]).Data(),"l");
1709   }
1710   legcRTC->AddEntry(".","not applied :","");
1711   for(Int_t centBin = centBinMin; centBin < centBinMaxi+centBinMin; centBin++){
1712     TH1 *hRatioNoPS = static_cast<TH1*> (trigRatioNoPS.At(centBin-centBinMin));
1713     if (!hRatioNoPS) continue;
1714     legcRTC->AddEntry(hRatioNoPS,(legendHeader[centBin]).Data(),"l");
1715   }
1716   legcRTC->Draw("same");
1717         
1718         
1719   return c1;
1720 }       
1721
1722 TCanvas *ProcessCanvasTracksoverTrigger(TObjArray *triggersB, TObjArray trigSel, TObjArray trackTracker, TObjArray trackTrigger, TObjArray trackMatched, TObjArray trackAll, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader){
1723          
1724   if(!triggersB || trigNr<0 || centNr<0 ) return 0x0;
1725         
1726   Int_t index = GetIndex(triggersB,trigNr,centNr);
1727
1728   TH1 *hTrackerPerB, *hTriggerPerB, *hMatchedPerB, *hAllTracksPerB, *hTrigSel, *histo;
1729                  
1730   TString hName, hNameBase;
1731   hNameBase =( (TObjString*) triggersB->At(trigNr) )->GetString();
1732                 
1733   hTrigSel = static_cast<TH1*> (trigSel.At(index));
1734   if (!hTrigSel) return 0;
1735
1736   hName = Form("hTrackerPer%s",hNameBase.Data());
1737   histo = static_cast<TH1*> (trackTracker.At(index));
1738   if (!histo) return 0;
1739   hTrackerPerB = (TH1*) histo->Clone(hName);
1740   if ( hTrackerPerB->GetEntries() ) hTrackerPerB->Divide(hTrigSel);
1741   hTrackerPerB->SetLineColor(kRed);
1742          
1743   hName = Form("hTriggerPer%s",hNameBase.Data());
1744   histo = static_cast<TH1*> (trackTrigger.At(index));
1745   if (!histo) return 0;
1746   hTriggerPerB = (TH1*) histo->Clone(hName);
1747   if ( hTriggerPerB->GetEntries() > 0 ) hTriggerPerB->Divide(hTrigSel);
1748   hTriggerPerB->SetLineColor(kBlue);
1749          
1750   hName = Form("hMatchedPer%s",hNameBase.Data());
1751   histo = static_cast<TH1*> (trackMatched.At(index));
1752   if (!histo) return 0;
1753   hMatchedPerB = (TH1*) histo->Clone(hName);
1754   if ( hMatchedPerB->GetEntries() > 0 ) hMatchedPerB->Divide(hTrigSel);
1755   hMatchedPerB->SetLineColor(kViolet);
1756          
1757   hName = Form("hAllTracksPer%s",hNameBase.Data());
1758   histo = static_cast<TH1*> (trackAll.At(index));
1759   if (!histo) return 0;
1760   hAllTracksPerB = (TH1*) histo->Clone(hName);
1761   if ( hAllTracksPerB->GetEntries() > 0 ) hAllTracksPerB->Divide(hTrigSel);
1762  
1763   hAllTracksPerB->SetLineWidth(3);
1764   hAllTracksPerB->SetLineColor(kBlack);
1765   hAllTracksPerB->SetTitle(Form("Number of Tracks /%s %s",hNameBase.Data(),legendHeader.Data()));
1766   hAllTracksPerB->SetMinimum(0.0001);
1767   if ( hAllTracksPerB->GetEntries() == 0 ) hAllTracksPerB->SetMaximum(0.1);
1768   hAllTracksPerB->SetLabelSize(0.02);
1769         
1770   TString cName = "c";
1771   cName += canvasName;
1772   hNameBase = ( (TObjString*) triggersB->At(trigNr) )->GetString();
1773   cName += hNameBase;   
1774   TCanvas *cRatioTrackTypesB = new TCanvas(canvasName,cName,1200,900);
1775   SetCanvas(cRatioTrackTypesB,0);
1776   cRatioTrackTypesB->cd();
1777         
1778   TLegend* legcTTCINT1B; 
1779                  
1780   hAllTracksPerB->Draw("E");
1781   hTrackerPerB->Draw("Esame");
1782   hMatchedPerB->Draw("Esame");
1783   hTriggerPerB->Draw("Esame");
1784          
1785   legcTTCINT1B = new TLegend(0.70,0.5,0.90,0.70);
1786   legcTTCINT1B->AddEntry(hAllTracksPerB,"All tracks","l");
1787   legcTTCINT1B->AddEntry(hTrackerPerB,"Tracking (only) tracks","l");
1788   legcTTCINT1B->AddEntry(hMatchedPerB,"Matched tracks","l");
1789   legcTTCINT1B->AddEntry(hTriggerPerB,"Trigger (only) tracks","l");
1790   legcTTCINT1B->Draw("same");
1791         
1792   return cRatioTrackTypesB;
1793         
1794 }
1795
1796 TCanvas *ProcessCanvasTrackMultB(TObjArray *triggersB, TObjArray trigSel, TObjArray trackTracker, TObjArray trackTrigger, TObjArray trackMatched, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader){
1797
1798   if( !triggersB || centNr < 0 || trigNr < 0 ) return 0x0;
1799         
1800   Int_t index = GetIndex(triggersB,trigNr,centNr);
1801   TString hNameBase = ( (TObjString*) triggersB->At(trigNr) )->GetString();
1802
1803   TString cName = Form("c%s%s",canvasName.Data(),hNameBase.Data());
1804   TCanvas *cTrackMultB = new TCanvas(canvasName,cName,1200,900);
1805   SetCanvas(cTrackMultB,0);
1806   cTrackMultB->Divide(1,2);
1807   cTrackMultB->cd(1);
1808         
1809   TH1* hSumTriggerOverB, *hSumTrackerOverB, *hTrigSel, *hTracker, *hTrigger, *hMatched; 
1810   TString hName; 
1811
1812   hTrigSel = static_cast<TH1*> (trigSel.At(index));
1813   if (!hTrigSel) return 0;
1814   hTracker = static_cast<TH1*> (trackTracker.At(index));
1815   if (!hTracker) return 0;
1816   hTrigger = static_cast<TH1*> (trackTrigger.At(index));
1817   if (!hTrigger) return 0;
1818   hMatched = static_cast<TH1*> (trackMatched.At(index));
1819   if (!hMatched) return 0;
1820   
1821   hName = Form("hSumTriggerOver%s",hNameBase.Data());
1822   hSumTriggerOverB = (TH1*) hTrigger->Clone(hName);
1823   hSumTriggerOverB->Add(hMatched);
1824   hSumTriggerOverB->Divide(hTrigSel);
1825   hName = Form("Sum of trigger tracks (matched + trigger-only) / # events in %s %s",hNameBase.Data(),legendHeader.Data());
1826   hSumTriggerOverB->SetTitle(hName);
1827   hSumTriggerOverB->SetLabelSize(0.04);
1828   hSumTriggerOverB->SetLineColor(kBlue);
1829
1830   hName = Form("hSumTrackerOver%s",hNameBase.Data());
1831   hSumTrackerOverB = (TH1*) hTracker->Clone(hName);
1832   hSumTrackerOverB->Add(hMatched);
1833   hSumTrackerOverB->Divide(hTrigSel);
1834   hName = Form("Sum of tracker tracks (matched + tracker-only) / # events in %s %s",hNameBase.Data(),legendHeader.Data());
1835   hSumTrackerOverB->SetTitle(hName);
1836   //hSumTrackerOverCINT1B->LabelsOption("u");
1837   hSumTrackerOverB->SetLabelSize(0.04);
1838   hSumTrackerOverB->SetLineColor(kBlue);
1839         
1840   hSumTriggerOverB->Draw("e");
1841   cTrackMultB->cd(2);
1842   hSumTrackerOverB->Draw("e");
1843         
1844   return cTrackMultB;
1845         
1846 }
1847
1848 TCanvas *ProcessCanvasRatioTrackB(TObjArray *triggersB, TObjArray trigSel, TObjArray trackTracker, TObjArray trackTrigger, TObjArray trackMatched, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader) {
1849
1850   if(!triggersB || trigNr < 0 || centNr < 0 ) return 0x0;
1851   
1852   Int_t index = GetIndex(triggersB,trigNr,centNr);
1853   TString hNameBase =( (TObjString*) triggersB->At(trigNr) )->GetString();
1854   
1855   TString cName = Form("c%s%s",canvasName.Data(),hNameBase.Data());
1856   TCanvas *cRatioTrackB = new TCanvas(canvasName,cName,1200,900);
1857   SetCanvas(cRatioTrackB,0);
1858   
1859   TH1* hTrackerOverTriggerB, *hMatchedOverTriggerB, *hMatchedOverTrackerB, *hTrigSel, *hTracker, *hTrigger, *hMatched;  
1860   hTrigSel = static_cast<TH1*> (trigSel.At(index));
1861   if (!hTrigSel) return 0;
1862   hTracker = static_cast<TH1*> (trackTracker.At(index));
1863   if (!hTracker) return 0;
1864   hTrigger = static_cast<TH1*> (trackTrigger.At(index));
1865   if (!hTrigger) return 0;
1866   hMatched = static_cast<TH1*> (trackMatched.At(index));
1867   if (!hMatched) return 0;
1868   
1869   TString hName = Form("hTrackerOverTrigger%s",hNameBase.Data());
1870   hTrackerOverTriggerB = (TH1*) hTracker->Clone(hName);
1871   hTrackerOverTriggerB->Divide(hTrigger);
1872   hName = Form("# tracker tracks / # trigger tracks in %s %s",hNameBase.Data(),legendHeader.Data());
1873   hTrackerOverTriggerB->SetTitle(hName);
1874   //hTrackerOverTriggerCINT1B->LabelsOption("u");
1875   hTrackerOverTriggerB->SetLabelSize(0.02);
1876   hTrackerOverTriggerB->SetLineColor(kBlue);
1877     
1878   hName = Form("hMatchedOverTrigger%s",hNameBase.Data());       
1879   hMatchedOverTriggerB = (TH1*) hMatched->Clone(hName);
1880   hMatchedOverTriggerB->Divide(hTrigger);
1881   hName = Form("# matched tracks / # trigger tracks in %s %s",hNameBase.Data(),legendHeader.Data());
1882   hMatchedOverTriggerB->SetTitle(hName);
1883   //hMatchedOverTriggerCINT1B->LabelsOption("u");
1884   hMatchedOverTriggerB->SetLabelSize(0.02);
1885   hMatchedOverTriggerB->SetLineColor(kBlue);
1886     
1887   hName = Form("hMatchedOverTracker%s",hNameBase.Data());
1888   hMatchedOverTrackerB = (TH1*) hMatched->Clone(hName);
1889   hMatchedOverTrackerB->Divide(hTracker);
1890   hName = Form("# matched tracks / # tracker tracks in %s %s",hNameBase.Data(),legendHeader.Data());
1891   hMatchedOverTrackerB->SetTitle(hName);
1892   //hMatchedOverTrackerCINT1B->LabelsOption("u");
1893   hMatchedOverTrackerB->SetLabelSize(0.02);
1894   hMatchedOverTrackerB->SetLineColor(kBlue);
1895   
1896   cRatioTrackB->Divide(1,3);
1897   cRatioTrackB->cd(1);
1898   hTrackerOverTriggerB->Draw("e");      
1899   cRatioTrackB->cd(2);
1900   hMatchedOverTriggerB->Draw("e");      
1901   cRatioTrackB->cd(3);
1902   hMatchedOverTrackerB->Draw("e");      
1903     
1904   return cRatioTrackB;  
1905 }
1906
1907 TCanvas *ProcessCanvasAsymMatched(TObjArray *triggersB, TObjArray trackPosMatched, TObjArray trackNegMatched, TObjArray trackAllMatched, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader) {
1908
1909   if(!triggersB || trigNr < 0 || centNr < 0 ) return 0x0;
1910   
1911   Int_t index = GetIndex(triggersB,trigNr,centNr);
1912   TString hName, hNameBase = (( (TObjString*) triggersB->At(trigNr) )->GetString());
1913   
1914   TString cName = Form("c%s%s",canvasName.Data(),hNameBase.Data());     
1915   TCanvas *cAsymMatched = new TCanvas(canvasName.Data(),cName,1200,900);
1916   SetCanvas(cAsymMatched,0);
1917   cAsymMatched->cd();
1918         
1919   TH1* hPosMatched, *hNegMatched, *hAllMatched;
1920  
1921   hPosMatched = static_cast<TH1*> (trackPosMatched.At(index));
1922   if (!hPosMatched) return 0;
1923   hNegMatched = static_cast<TH1*> (trackNegMatched.At(index));
1924   if (!hNegMatched) return 0;
1925   hAllMatched = static_cast<TH1*> (trackAllMatched.At(index));
1926   if (!hAllMatched) return 0;
1927
1928   hName = Form("hAsyMatchedFor%s",hNameBase.Data());
1929   TH1 *hAsymMatched = (TH1*) hPosMatched->Clone(hName); 
1930   hAsymMatched->Add(hNegMatched,-1);
1931   hAsymMatched->Divide(hAllMatched);
1932   hAsymMatched->SetLineColor(kRed);
1933   hAsymMatched->SetMinimum(-0.3);
1934   hAsymMatched->SetMaximum(0.3);
1935   hAsymMatched->SetLabelSize(0.02);
1936   hName = Form("Matched tracks charge asymmetry for %s with acc. cuts %s",hNameBase.Data(),legendHeader.Data());
1937   hAsymMatched->SetTitle(hName);
1938   hAsymMatched->GetYaxis()->SetTitle("Charged tracks asymmetry");  
1939   hAsymMatched->Draw("EH");
1940         
1941   return cAsymMatched;
1942
1943 }
1944
1945 TCanvas *ProcessCanvasHighPtMuons(TObjArray *triggersB, TObjArray trigSel, TObjArray trackMatchedLowPt, TObjArray trackAllMatchedHighPt, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader) {
1946
1947   if ( !triggersB || trigNr < 0 || centNr < 0 ) return 0x0;
1948   
1949   Int_t index = GetIndex(triggersB,trigNr,centNr);
1950   TString hName, hNameBase = (( (TObjString*) triggersB->At(trigNr) )->GetString());
1951   
1952   TString cName = Form("c%s%s",canvasName.Data(),hNameBase.Data());     
1953   TCanvas *cHighPtMuons = new TCanvas(canvasName.Data(),cName,1200,900);
1954   SetCanvas(cHighPtMuons,0);
1955   cHighPtMuons->cd();
1956   TLegend* legcHPM;
1957   
1958   TH1* hRelMatchedLowPt, *hRelMatchedHighPt, *hTrigSel, *hMatchedLowPt, *hAllMatchedHighPt;  
1959   hTrigSel = static_cast<TH1*> (trigSel.At(index));
1960   if (!hTrigSel) return 0;
1961   hMatchedLowPt = static_cast<TH1*> (trackMatchedLowPt.At(index));
1962   if (!hMatchedLowPt) return 0;
1963   hAllMatchedHighPt = static_cast<TH1*> (trackAllMatchedHighPt.At(index));
1964   if (!hAllMatchedHighPt) return 0;
1965
1966   hName = Form("hMatchedLowPtPer%s ",hNameBase.Data());
1967   hRelMatchedLowPt = (TH1*) hMatchedLowPt->Clone(hName);
1968   hRelMatchedLowPt->Divide(hTrigSel);
1969   hRelMatchedLowPt->SetLineColor(kBlue);
1970   hRelMatchedLowPt->SetTitle("");
1971   hName = Form("Ratio per %s ",hNameBase.Data());
1972   hRelMatchedLowPt->GetYaxis()->SetTitle(hName);
1973   hRelMatchedLowPt->SetMinimum(0.0001);
1974   hRelMatchedLowPt->SetLabelSize(0.02);
1975          
1976   hName = Form("hMatchedHighPtPer%s ",hNameBase.Data());
1977   hRelMatchedHighPt = (TH1*) hAllMatchedHighPt->Clone(hName);
1978   hRelMatchedHighPt->Divide(hTrigSel);
1979   hRelMatchedHighPt->SetLineColor(kRed);
1980                  
1981   hName = Form("Number of matched track per %s (include Vtx and R_{Abs} cuts) %s",hNameBase.Data(),legendHeader.Data());
1982   hRelMatchedLowPt->SetTitle(hName);
1983   hRelMatchedLowPt->Draw("E");
1984   hRelMatchedHighPt->Draw("Esame");
1985          
1986   legcHPM = new TLegend(0.60,0.45,0.98,0.65);
1987   //legcHPM->SetHeader(hName);
1988   legcHPM->AddEntry(".","Physics selection applied :","");      
1989   legcHPM->AddEntry(hRelMatchedLowPt," p_{T} > 1 GeV/c ","l");
1990   legcHPM->AddEntry(hRelMatchedHighPt," p_{T} >  2 GeV/c ","l");
1991   legcHPM->Draw("same");
1992         
1993   return cHighPtMuons;
1994 }
1995
1996 TCanvas *ProcessCanvasBeamGasMatched ( TObjArray *triggersB, TObjArray trackBeamGasMatched, TObjArray trackBeamGasMatchedHighPt, TObjArray trackAllMatched, TObjArray trackMatchedHighPt, Int_t trigNr, Int_t centNr, TString canvasName,TString legendHeader) {
1997
1998   if(!triggersB || trigNr < 0 || centNr < 0 )    return 0x0;
1999
2000   Int_t index = GetIndex(triggersB,trigNr,centNr);
2001   TString hName, hNameBase = (( (TObjString*) triggersB->At(trigNr) )->GetString());
2002         
2003   TString cName = Form("c%s%s",canvasName.Data(),hNameBase.Data());     
2004   TCanvas *cBeamGasMatched = new TCanvas(canvasName.Data(),cName,1200,900);
2005   SetCanvas(cBeamGasMatched,0);
2006   cBeamGasMatched->cd();
2007                 
2008   TH1* hBeamGasMatched, *hBeamGasMatchedHighPt, *hAllMatched, *hMatchedHighPt;
2009
2010   hBeamGasMatched = static_cast<TH1*> (trackBeamGasMatched.At(index));
2011   if (!hBeamGasMatched) return 0;
2012   hBeamGasMatchedHighPt = static_cast<TH1*> (trackBeamGasMatchedHighPt.At(index));
2013   if (!hBeamGasMatchedHighPt) return 0;
2014   hAllMatched = static_cast<TH1*> (trackAllMatched.At(index));
2015   if (!hAllMatched) return 0;
2016   hMatchedHighPt = static_cast<TH1*> (trackMatchedHighPt.At(index));
2017   if (!hMatchedHighPt) return 0;
2018
2019   hName = Form("hBeamGasMatchedPer%s ",hNameBase.Data());
2020   TH1 *hRelBeamGasMatched = (TH1*) hBeamGasMatched->Clone(hName);
2021   hRelBeamGasMatched->Divide(hAllMatched);
2022   hRelBeamGasMatched->SetLineColor(kBlack);
2023   hRelBeamGasMatched->SetMinimum(0.0);
2024   hRelBeamGasMatched->SetMaximum(1.1);
2025   hRelBeamGasMatched->SetLabelSize(0.02);
2026   
2027   hName = Form("hBeamGasMatchedHightPtPer%s ",hNameBase.Data());
2028   TH1 *hRelBeamGasMatchedHighPt = (TH1*) hBeamGasMatchedHighPt->Clone(hName);
2029   hRelBeamGasMatchedHighPt->Divide(hMatchedHighPt);
2030   hRelBeamGasMatchedHighPt->SetLineColor(kRed);
2031
2032   hName = Form("Identified beam-gas tracks (pxDCA cuts) in matched tracks for %s",hNameBase.Data());
2033   if(!legendHeader.IsNull()) hName += Form(" %s",legendHeader.Data());
2034   hRelBeamGasMatched->SetTitle(hName);   
2035   hRelBeamGasMatched->GetYaxis()->SetTitle("Relative beam-gas tracks");  
2036   hRelBeamGasMatched->Draw("EH");
2037   hRelBeamGasMatchedHighPt->Draw("EHsame");
2038
2039   TLegend *leg = new TLegend(0.60,0.45,0.98,0.65);
2040   leg->AddEntry(".","Physics selection applied :","");  
2041   leg->AddEntry(hRelBeamGasMatched," All p_{T}","l");
2042   leg->AddEntry(hRelBeamGasMatchedHighPt," p_{T} >  2 GeV/c ","l");
2043   leg->Draw("same");
2044         
2045   return cBeamGasMatched;
2046 }
2047
2048 Int_t GetIndex( TObjArray *triggers, Int_t trigNr, Int_t centNr ) {
2049
2050   return ( centNr * triggers->GetEntriesFast() + trigNr );
2051 }
2052
2053 TH1* ProcessHisto( AliCounterCollection* counter, TString hVariable, TString hSelection, TString hName, TString xName, TString yName, Int_t color){
2054   
2055   
2056   TH1* h1 = 0x0;
2057   if( !counter ) return h1;
2058
2059   //cout<<"ProcessHisto selection "<<hSelection<<endl;
2060         
2061   if ( !hSelection.Contains("trigger: /") && !hSelection.Contains("trigger:/") ) h1 = (TH1*) counter->Draw(hVariable,hSelection);
2062   //cout<<"ProcessHisto selection2 "<<h1<<endl;
2063   if ( !h1 ) h1 = new TH1D(hName,"",10,0,10);
2064   else {
2065     if ( h1->GetSumw2N() == 0 ) h1->Sumw2();
2066     h1->LabelsOption("a");
2067     if(hName.Sizeof()>1) h1->SetName(hName);
2068     if(xName.Sizeof()>1) h1->GetXaxis()->SetTitle(xName);
2069     if(yName.Sizeof()>1) h1->GetYaxis()->SetTitle(yName);
2070     if(color>0) h1->SetLineColor(color);
2071     h1->SetLineWidth(2);
2072     
2073   }
2074   
2075   return h1;
2076 }
2077
2078 TH2* ProcessHisto2D( AliCounterCollection* counter, TString hVariable, TString hVariable2, TString hSelection, TString hName){
2079         
2080   
2081   TH2* h1 = 0x0;
2082   if( !counter ) return h1;
2083   Bool_t setName = kTRUE;
2084   
2085   if(hName.Sizeof()==1) setName = kFALSE;
2086   
2087   h1 = (TH2*) counter->Draw(hVariable,hVariable2,hSelection);
2088   if ( !h1 ) h1 = new TH2D(hName,"",10,0,10,10,0,10);
2089   else {
2090     if ( h1->GetSumw2N() == 0 ) h1->Sumw2();
2091     h1->LabelsOption("a");
2092     if(setName) h1->SetName(hName);
2093   }
2094   
2095   return h1;
2096 }
2097
2098 Bool_t GetTriggerLists(const char* triggerList, TString listFromContainer, TObjArray *triggersB, TObjArray *triggersShortName){
2099         
2100   //Get the trigger list from a file
2101   //The file should consist of a line for each trigger with the following layout:
2102   //        MB triggernameB 
2103   //     or MUONUNLIKE triggernameB 
2104   //     or NOSHOW triggernameB 
2105   //if filename is 0, then all the triggers stored are used     
2106   if( !triggersB || !triggersShortName) return kFALSE;
2107   Int_t const nColumn = 2;
2108   TObjArray* triggers[nColumn] = {triggersShortName, triggersB};
2109   
2110   TString trigSuffix[nColumn] = {"","B"};
2111   TString currTrigName = "";
2112   TObjArray* fullTriggerList[nColumn];
2113         
2114   for ( Int_t ibeam=0; ibeam<nColumn; ++ibeam ) {
2115     fullTriggerList[ibeam] = new TObjArray();
2116     fullTriggerList[ibeam]->SetOwner();
2117   }
2118   
2119   // Build trigger list (from file or use all trigger stored)
2120   if ( triggerList ) {
2121     // only the ones in the triggerList
2122     ifstream inFile(triggerList);
2123     if (!inFile.is_open()) {
2124       Error("PlotMuonQA","unable to open file %s", triggerList);
2125       return kFALSE;
2126     }
2127     
2128     while ( !inFile.eof() ) {
2129       Bool_t isGoodB = kTRUE;
2130       for ( Int_t ibeam=0; ibeam<nColumn; ++ibeam ) {
2131         currTrigName.ReadToken( inFile );
2132         if ( ! isGoodB ) continue;
2133         if ( currTrigName.IsNull() || ! currTrigName.IsAscii() ) {
2134           if ( ibeam==0 || ibeam == 1 ) {
2135             isGoodB = kFALSE;
2136             continue;
2137           }
2138           currTrigName = "notrigger";
2139         }
2140         fullTriggerList[ibeam]->AddLast(new TObjString(currTrigName));
2141       }
2142     }
2143     inFile.close();
2144   }
2145   else {
2146     TObjArray *triggersInContainer = listFromContainer.Tokenize(",");
2147     Int_t nTrig = 0;
2148     for ( Int_t iTrig = 0; iTrig < triggersInContainer->GetEntriesFast(); iTrig++ ) {
2149       currTrigName = triggersInContainer->At(iTrig)->GetName();
2150       Bool_t keep = kFALSE;
2151       if ( ( currTrigName.Contains("-B-") ||  currTrigName.Contains("-ABCE-") ) && 
2152            ( ! ((TString) currTrigName(0)).CompareTo("C") ) && !currTrigName.Contains("WU") && 
2153            !currTrigName.Contains("UP") && !currTrigName.Contains("SPI") && !currTrigName.Contains("PHI") && 
2154            !currTrigName.Contains("EMC") && !currTrigName.Contains("ZED") && !currTrigName.Contains("TRUE") && 
2155            !currTrigName.Contains("SHM")  && !currTrigName.Contains("TPC") && !currTrigName.Contains("BEAM") && 
2156            !currTrigName.Contains("1A") && !currTrigName.Contains("1C")) 
2157         keep = kTRUE;//cyn: to be removed once the trigger filtering is carried out in the analysis task
2158       if (!keep) continue;
2159       nTrig++;
2160       for (Int_t ibeam = 0; ibeam < nColumn; ibeam++) {
2161         fullTriggerList[ibeam]->AddLast( new TObjString(currTrigName) );
2162       }
2163     }
2164     //if no triggers are kept, then keep all of them
2165     if (nTrig == 0) {
2166       printf("INFO: no trigger selected over %d triggers: all triggers kept!!\n",
2167              triggersInContainer->GetEntriesFast());
2168       for ( Int_t iTrig = 0; iTrig < triggersInContainer->GetEntriesFast(); iTrig++ ) {
2169         currTrigName = triggersInContainer->At(iTrig)->GetName();
2170         for (Int_t ibeam = 0; ibeam < nColumn; ibeam++) {
2171           fullTriggerList[ibeam]->AddLast( new TObjString(currTrigName) );
2172         }
2173       }
2174     }
2175     if ( triggersInContainer ) delete triggersInContainer;
2176   }
2177
2178   //
2179   // Select only existing triggers in container
2180   //
2181   TObjArray *triggersFromContainer = listFromContainer.Tokenize(",");
2182   TObjString* trigName = 0x0;
2183         
2184   TString selectAllTriggers[nColumn];
2185   for ( Int_t ibeam=0; ibeam<nColumn; ++ibeam ) selectAllTriggers[ibeam]= "";
2186   
2187   for ( Int_t itrig=0; itrig<fullTriggerList[0]->GetEntries(); ++itrig ) {
2188     Bool_t isBadTrig = kFALSE;
2189     for ( Int_t ibeam=0; ibeam<nColumn; ++ibeam ) {
2190       currTrigName = fullTriggerList[ibeam]->At(itrig)->GetName();
2191       //condition on trigger name from trigger list
2192       if ( ibeam == 0 && currTrigName.Contains("NOSHOW") ) {
2193         break;
2194       }
2195       //select only the existing triggers in the container 
2196       //note that the trigger in the trigger file can be a list of different trigger
2197       if ( ibeam > 0 && triggersFromContainer ) {
2198         TIter nextTrigger( triggersFromContainer );
2199         isBadTrig = kTRUE;
2200         while ( ( trigName = static_cast<TObjString*>(nextTrigger()) ) ) {
2201           if ( currTrigName.Contains(trigName->GetString()) ){
2202             isBadTrig = kFALSE;
2203           }
2204         }
2205         if ( isBadTrig == kTRUE ){ 
2206           if ( ibeam == 1){
2207             if ( triggers[0]->GetLast() != (triggers[0]->LowerBound()-1) ) triggers[0]->RemoveAt(triggers[0]->GetLast());
2208             break;
2209           }
2210           currTrigName = " ";
2211         }
2212       }
2213       triggers[ibeam]->AddLast(new TObjString(currTrigName));
2214       if ( isBadTrig ) continue;
2215       if ( ! selectAllTriggers[ibeam].IsNull() ) selectAllTriggers[ibeam] += ",";
2216       selectAllTriggers[ibeam] += currTrigName;
2217     }
2218   }
2219   if(triggersFromContainer) delete triggersFromContainer;
2220   if(trigName) delete trigName;
2221         
2222         
2223   // Complete trigger list and print values
2224   cout<<" Nr of triggers read "<<triggers[0]->GetEntriesFast()<<endl;
2225   for ( Int_t ibeam=0; ibeam<nColumn; ++ibeam ) {
2226     triggers[ibeam]->AddLast(new TObjString(selectAllTriggers[ibeam]));
2227     printf(" %s triggers:\n", trigSuffix[ibeam].Data());
2228     triggers[ibeam]->Print();
2229     delete fullTriggerList[ibeam];
2230   }
2231         
2232   return kTRUE;
2233 }
2234
2235 Int_t GetRunNumber(TString filePath)
2236 {
2237   /// Get run number from file path
2238   TObjArray* array = filePath.Tokenize("/");
2239   array->SetOwner();
2240   TString auxString = "";
2241   Int_t runNum = -1;
2242   for ( Int_t ientry=0; ientry<array->GetEntries(); ientry++ ) {
2243     auxString = array->At(ientry)->GetName();
2244     if ( auxString.IsDigit() && auxString.Length()>=6 && auxString.Length()<=9 ) {
2245       runNum = auxString.Atoi();
2246       break;
2247     }
2248   }
2249   delete array;
2250
2251   if ( runNum < 0 ) {
2252     array = auxString.Tokenize("_");
2253     array->SetOwner();
2254     auxString = array->Last()->GetName();
2255     auxString.ReplaceAll(".root","");
2256     if ( auxString.IsDigit() ) runNum = auxString.Atoi();
2257     delete array;
2258   }
2259
2260   return runNum;
2261 }
2262
2263 TString GetRunList(const char *runList, TObjArray *runs){
2264
2265   // list of runs to be analyzed
2266   TString selectRuns = "run:";
2267   
2268   if(runList) {
2269     // only the ones in the runList
2270     ifstream inFile(runList);
2271     if (!inFile.is_open()) {
2272       Error("PlotMuonQA","unable to open file %s", runList);
2273       return selectRuns;
2274     }
2275     
2276     TString currLine;
2277     while (!inFile.eof()) {
2278       currLine.ReadLine(inFile);
2279       if ( currLine.IsNull() ) continue;
2280       Int_t currRun = GetRunNumber(currLine);
2281       if (currRun<0) {
2282         Warning("PlotMuonQA","invalid run number: %s", currLine.Data());
2283         continue;
2284       }
2285       if(runs) runs->AddLast(new TObjString(Form("%d", currRun)));
2286       selectRuns += Form("%i,",currRun);
2287     }
2288     selectRuns.Remove(TString::kTrailing, ',');
2289     inFile.close();
2290     
2291   } else {
2292     // all runs
2293     cout<<"runList is not set"<<endl;
2294     if(runs) runs->AddLast(new TObjString("*"));
2295   }
2296   
2297   printf("selected runs from runlist %s: %s\n",runList, selectRuns.Data());
2298         
2299   return selectRuns;
2300 }
2301
2302 Bool_t MergeOutputs(const char* inputList,const char* outFilename)
2303 {
2304   ifstream inFile(inputList);
2305   if ( ! inFile.is_open()) {
2306     printf("Error: cannot find inputList %s\n", inputList);
2307     return kFALSE;
2308   }
2309   TString currLine = "";
2310   TFileMerger fileMerger;
2311   Int_t mergeType = ( TFileMerger::kRegular | TFileMerger::kAll | TFileMerger::kOnlyListed );
2312   fileMerger.AddObjectNames("MUON_QA");
2313   while ( ! inFile.eof() ) {
2314     currLine.ReadLine(inFile);
2315     if ( ! currLine.EndsWith(".root") ) continue;
2316     fileMerger.AddFile(currLine.Data());
2317   }
2318   inFile.close();
2319   if ( fileMerger.GetMergeList()->GetEntries() == 0 ) return kFALSE;
2320   fileMerger.OutputFile(outFilename,kTRUE,1); // needed when merging single files for specific directories
2321   fileMerger.PartialMerge(mergeType);
2322
2323   return kTRUE;
2324 }