]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/muon/PlotMuonQApp.C
Adding PWG4Base library
[u/mrichter/AliRoot.git] / PWG3 / muon / PlotMuonQApp.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 //  - libPWG3muon.so
12 //
13 // TString includePath = "-I${ALICE_ROOT}/PWG3/base/ ";  gSystem->SetIncludePath(includePath.Data());
14 //
15 // The macro reads results of the QA task and produce monitoring plots.
16 //
17 // Author: Philippe Pillot - SUBATECH Nantes
18 // Modified by Christophe Suire, Cynthia Hadjidakis - IPN Orsay
19 //--------------------------------------------------------------------------
20
21 #if !defined(__CINT__) || defined(__MAKECINT__)
22
23 #include <Riostream.h>
24
25 // ROOT includes
26 #include "TEnv.h"
27 #include "TMath.h"
28 #include "TGrid.h"
29 #include "TGridResult.h"
30 #include "THashList.h"
31 #include "TFile.h"
32 #include "TH1.h"
33 #include "TH2.h"
34 #include "TF1.h"
35 #include "TSystem.h"
36 #include "TStyle.h"
37 #include "TCanvas.h"
38 #include "TPad.h"
39 #include "TLegend.h"
40 #include "TObjArray.h"
41 #include "TObjString.h"
42
43 // ALIROOT includes
44 #include "AliCounterCollection.h"
45
46 #endif
47
48 TString GetRunList(const char *runList, TObjArray *runs, TObjArray *runs2);
49 //Bool_t GetTriggerLists(const char *triggerList, TObjArray *triggersB=0, TObjArray *triggersAC=0, TObjArray *triggersE=0);
50 Bool_t GetTriggerLists(const char *triggerList, TString listFromContainer, TObjArray *triggersB=0, TObjArray *triggersAC=0, TObjArray *triggersE=0);
51 void SetCanvas(TCanvas *canvas, Int_t logy=1);
52
53 TH1* ProcessHisto( AliCounterCollection* counter, TString variable, TString selection, TString hName="", TString xName="", TString yName="", Int_t color=1);
54 TH2* ProcessHisto2D( AliCounterCollection* counter, TString hVariable, TString hVariable2, TString hSelection, TString hName);
55
56 TCanvas *ProcessCanvasTriggerContent(TObjArray *array, TH1 **histo, TH1 **histo2, TString canvasName);
57 TCanvas *ProcessCanvasRelativeTriggerContent(TObjArray *array, TH1 **histo, TString canvasName, Int_t *colorTab);
58 TCanvas *ProcessCanvasPhysSelCut(TObjArray *triggersB, TObjArray *triggersAC, TObjArray *triggersE, TH1 **hBNoPS, TH1 **hACNoPS,TH1 **hENoPS, TH1 **hBWithPS, TString canvasName, Int_t *colorInd);
59 TCanvas *ProcessCanvasTracksoverTrigger(TObjArray *triggersB, TH1 **hB, TH1 **hTrackerB, TH1 **hTriggerB, TH1 **hMatchedB, TH1 **hAllTracksB, Int_t indTrigger, TString canvasName);
60 TCanvas *ProcessCanvasTrackMultB(TObjArray *triggersB, TH1 **hB, TH1 **hTrackerB, TH1 **hTriggerB, TH1 **hMatchedB, TH1 **hAllTracksB, Int_t indTrigger, TString canvasName);
61 TCanvas *ProcessCanvasRatioTrackB(TObjArray *triggersB, TH1 **hB, TH1 **hTrackerB, TH1 **hTriggerB, TH1 **hMatchedB, TH1 **hAllTracksB, Int_t indTrigger, TString canvasName);
62 TCanvas *ProcessCanvasAsymMatched(TObjArray *triggersB, TH1 **hPosMatchedB, TH1 **hNegMatchedB, TH1 **hAllMatchedB, Int_t indTrigger, TString canvasName);
63 TCanvas *ProcessCanvasHighPtMuons(TObjArray *triggersB, TH1 **hB, TH1 **hMatchedLowPtB, TH1 **hAllMatchedHightPtB, Int_t indTrigger, TString canvasName);
64 Bool_t IsTrigger(TObjArray *array, Int_t index, TString name);
65
66 //--------------------------------------------------------------------------
67 void PlotMuonQApp(const char* baseDir, const char* runList = 0x0, const char * triggerList = 0x0, Bool_t selectPhysics = kFALSE, const char *LHCPeriod = "LHC11c", const char *QAFileName = "QAresults.root") {
68         
69   /// Macro for QA monitoring.
70   /// Example: baseDir = "alien:///alice/cern.ch/user/p/ppillot/pp7TeV/LHC10d/MuonQA/pass1/results/".
71   /// If runList != 0x0: only the given runs will be used. Otherwise use all runs found in baseDir.
72   
73 #if defined(__CINT__) && !defined(__MAKECINT__)
74   gSystem->Load("libTree");
75   gSystem->Load("libGeom");
76   gSystem->Load("libVMC");
77   gSystem->Load("libPhysics");
78   gSystem->Load("libSTEERBase");
79   gSystem->Load("libESD");
80   gSystem->Load("libAOD");
81   gSystem->Load("libANALYSIS");
82   gSystem->Load("libANALYSISalice");
83   gSystem->Load("libCORRFW");
84   gSystem->Load("libPWG3base");
85   gSystem->Load("libPWG3muon");
86 #endif
87   
88   // Cosmetics and configuration
89   gStyle->SetFillColor(10);
90   gStyle->SetPadGridX(kTRUE);
91   gStyle->SetPadGridY(kTRUE);
92   gStyle->SetPadRightMargin(0.01);
93   
94   Int_t colorInd[10]={1,4,2,3,6,7,12};
95         
96   TString OutFileName = "QA_";  OutFileName += LHCPeriod;
97   TString OutFileNamePDF=  OutFileName.Data();  OutFileNamePDF+= ".pdf";
98   TString OutFileNamePDF_open = OutFileNamePDF.Data(); OutFileNamePDF_open += "[";  
99   TString OutFileNamePDF_close= OutFileNamePDF.Data(); OutFileNamePDF_close += "]";  
100   TString OutFileNameROOT=  OutFileName.Data();  OutFileNameROOT+= ".root";
101   
102   Int_t PRINTSTAT = 1;
103   Int_t kCMUS = 2;
104   if (0){ // Equivalent to the fast read option
105     gEnv->SetValue("XNet.ConnectTimeout",10);
106     gEnv->SetValue("XNet.RequestTimeout",10);
107     gEnv->SetValue("XNet.MaxRedirectCount",2);
108     gEnv->SetValue("XNet.ReconnectTimeout",10);
109     gEnv->SetValue("XNet.FirstConnectMaxCnt",1);
110   }
111   
112   TH1::AddDirectory(kFALSE);
113   
114   TString alienBaseDir = baseDir;
115   
116   if (alienBaseDir.Contains("alien:") && !TGrid::Connect("alien://")) {
117     Error("MergeQA","cannot connect to grid");
118     return;
119   }
120   
121
122   //---------------------------------- //
123   //          Run selection            //
124   //---------------------------------- //
125   
126   TObjArray *runs = new TObjArray();
127   runs->SetOwner(kTRUE);
128   TObjArray *runs2 = new TObjArray();
129   runs2->SetOwner(kTRUE);
130   TString selectRuns = GetRunList(runList,runs,runs2);
131                 
132   // physics selection
133   TString select = selectPhysics ? "selected:yes" : "";
134   
135
136         
137   cout<<"//---------------------------------- //"<<endl;
138   cout<<"//        Get global counter        //"<<endl;
139   cout<<"//---------------------------------- //"<<endl;
140   
141   TFile *globalFile = TFile::Open(Form("%s/%s", baseDir,QAFileName));
142   if (!globalFile || ! globalFile->IsOpen()) {
143     Error("PlotQA", "failed to open file: %s/%s", baseDir, QAFileName);
144     return;
145   }
146   globalFile->Cd("MUON_QA");
147   
148   TString selection;
149         
150   // get counters
151   AliCounterCollection* eventCounters = static_cast<AliCounterCollection*>(globalFile->FindObjectAny("eventCounters"));
152   AliCounterCollection* trackCounters = static_cast<AliCounterCollection*>(globalFile->FindObjectAny("trackCounters"));
153   if (!runList) selectRuns += trackCounters->GetKeyWords("run");
154         
155   
156   cout<<"//---------------------------------- //"<<endl;
157   cout<<"//        Trigger selection          //"<<endl;
158   cout<<"//---------------------------------- //"<<endl;
159
160   TObjArray *triggersB, *triggersAC, *triggersE;
161   triggersB = new TObjArray();
162   triggersB->SetOwner();
163   triggersAC = new TObjArray();
164   triggersAC->SetOwner();
165   triggersE = new TObjArray();
166   triggersE->SetOwner();
167         
168   TString listFromContainer = eventCounters->GetKeyWords("trigger");
169   Bool_t success = GetTriggerLists(triggerList, listFromContainer, triggersB, triggersAC, triggersE);
170   if(!success) return;
171   
172
173   cout<<"//---------------------------------- //"<<endl;
174   cout<<"//        Trigger plots              //"<<endl;
175   cout<<"//---------------------------------- //"<<endl;
176         
177   //plot all trigger from event counters
178   TString CanvasName = "cAll";
179   TCanvas *cAll = new TCanvas(CanvasName.Data(),CanvasName.Data());
180   cAll->cd();
181   //TH2* hAll = (TH2*) ProcessHisto2D(eventCounters, "trigger", "run", Form("run:any/%s",select.Data()) , "");
182   TH2* hAll = (TH2*) ProcessHisto2D(eventCounters, "trigger", "run", "run:any" , "");
183   hAll->Draw("TEXT");
184
185         
186   //declare a default canvas c1 
187   CanvasName = "c1";
188   TCanvas *c1 = new TCanvas(CanvasName.Data(),CanvasName.Data());
189   c1->cd();
190
191   TH1* hBNoPS[10]={}; 
192   TH1* hBWithPS[10]={};
193   TH1* hB[10]={};
194   TH1* hTriggerB[10], *hTrackerB[10], *hMatchedB[10], *hAllTracksB[10], *hMatchedLowPtB[10], *hMatchedHighPtB[10];
195   TH1* hMatchedLowPtBNoPS[10], *hMatchedHighPtBNoPS[10];
196   TH1* hPosMatchedB[10], *hNegMatchedB[10], *hAllMatchedB[10];
197   TH1 *hACWithPS[10]={}; 
198   TH1 *hACNoPS[10]={};
199   TH1 *hEWithPS[10]={};
200   TH1 *hENoPS[10]={};
201   
202   if(triggersB->GetEntriesFast()>=10){
203     cout<<"Too many triggers"<<endl;
204     return;
205   }
206         
207   //Loop on trigger (last is all triggers, then for each defined trigger)
208   for(Int_t i = 0; i < triggersB->GetEntriesFast(); i++){
209     
210     TString histoNameBase = "h_trig", histoName;
211     histoNameBase+= i+1;
212                 
213     TString triggerName = ( (TObjString*) triggersB->At(i) )->GetString();
214     // Histo trigger without Phys. Sel. 
215     selection = Form("trigger:%s/%s", triggerName.Data(), selectRuns.Data());           
216     cout<<selection<<endl;
217     histoName = histoNameBase;
218     histoName += "BNoPS";
219     hBNoPS[i] = (TH1*) ProcessHisto(eventCounters, "run", selection, histoName, "", "Trigger content w/o Phys. Sel.", colorInd[i]);
220     // Histo trigger with Phys. Sel. 
221     selection = Form("trigger:%s/%s/selected:yes", triggerName.Data(), selectRuns.Data());
222     histoName = histoNameBase;
223     histoName += "BWithPS";
224     hBWithPS[i] = (TH1*) ProcessHisto(eventCounters, "run", selection, histoName, "", "Trigger content w/ Phys. Sel.", colorInd[i]);
225     // Histo trigger : Phys. Sel.  is selected or not depending on the macro arguments
226     selection = Form("trigger:%s/%s/%s", triggerName.Data(), selectRuns.Data(), select.Data());
227     histoName = histoNameBase;
228     histoName += "B";
229     hB[i] = (TH1*) ProcessHisto(eventCounters, "run", selection, histoName);
230                 
231     TString triggerNameAC = ( (TObjString*) triggersAC->At(i) )->GetString();
232     // Histo trigger without Phys. Sel. AC
233     histoName = histoNameBase;
234     histoName += "ACNoPS";
235     selection = Form("trigger:%s/%s", triggerNameAC.Data(), selectRuns.Data());
236     hACNoPS[i] =  (TH1*) ProcessHisto(eventCounters, "run", selection, histoName);
237     // Histo trigger with Phys. Sel. AC
238     selection = Form("trigger:%s/%s/selected:yes", triggerNameAC.Data(), selectRuns.Data());
239     histoName = histoNameBase;
240     histoName += "ACWithPS";
241     hACWithPS[i] =  (TH1*) ProcessHisto(eventCounters, "run", selection, histoName);
242     
243     TString triggerNameE = ( (TObjString*) triggersE->At(i) )->GetString();
244     // Histo trigger without Phys. Sel. E
245     selection = Form("trigger:%s/%s", triggerNameE.Data(), selectRuns.Data());
246     histoName = histoNameBase;
247     histoName += "ENoPS";
248     hENoPS[i] =  (TH1*) ProcessHisto(eventCounters, "run", selection, histoName);
249     // Histo trigger with Phys. Sel. E
250     selection = Form("trigger:%s/%s/selected:yes", triggerNameE.Data(), selectRuns.Data());
251     histoName = histoNameBase;
252     histoName += "EWithPS";
253     hEWithPS[i] =  (TH1*) ProcessHisto(eventCounters, "run", selection, histoName);
254
255     // Histo tracking : Phys. Sel.  is selected or not depending on the macro arguments
256     selection = Form("track:triggeronly/trigger:%s/%s/%s", triggerName.Data(), selectRuns.Data(), select.Data());
257     hTriggerB[i] = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
258                 
259     selection = Form("track:trackeronly/trigger:%s/%s/%s", triggerName.Data(), selectRuns.Data(), select.Data());
260     hTrackerB[i] = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
261                 
262     selection = Form("track:matched/trigger:%s/%s/%s", triggerName.Data(), selectRuns.Data(), select.Data());
263     hMatchedB[i] = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
264                 
265     selection = Form("trigger:%s/%s/%s", triggerName.Data(), selectRuns.Data(), select.Data());
266     hAllTracksB[i] = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
267                 
268     selection = Form("track:matched/trigger:%s/%s/%s/pt:low/acc:in", triggerName.Data() ,selectRuns.Data(), select.Data());
269     hMatchedLowPtB[i] = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
270                 
271     selection = Form("track:matched/trigger:%s/%s/%s/pt:high/acc:in", triggerName.Data() ,selectRuns.Data(), select.Data());
272     hMatchedHighPtB[i] = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
273                 
274     selection = Form("track:matched/trigger:%s/%s/pt:low/acc:in", triggerName.Data() ,selectRuns.Data());
275     hMatchedLowPtBNoPS[i] = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
276                 
277     selection = Form("track:matched/trigger:%s/%s/pt:high/acc:in", triggerName.Data() ,selectRuns.Data());
278     hMatchedHighPtBNoPS[i] = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
279                 
280     selection = Form("track:matched/trigger:%s/%s/charge:pos/%s/acc:in",triggerName.Data(), select.Data(),selectRuns.Data());
281     hPosMatchedB[i] = (TH1*) ProcessHisto(trackCounters, "run", selection, "");
282     
283     selection = Form("track:matched/trigger:%s/%s/charge:neg/%s/acc:in",triggerName.Data(), select.Data(),selectRuns.Data());
284     hNegMatchedB[i] =  (TH1*) ProcessHisto(trackCounters, "run", selection, "");
285                 
286     selection = Form("track:matched/trigger:%s/%s/%s/acc:in",triggerName.Data(), select.Data(),selectRuns.Data());
287     hAllMatchedB[i] =  (TH1*) ProcessHisto(trackCounters, "run", selection, "");
288   }
289         
290   //if there is not B triggers just stop now
291   Int_t count_trigger=0;
292   for(Int_t i = 0; i < triggersB->GetEntriesFast(); i++){
293     count_trigger += hBNoPS[i]->GetEntries();
294   }
295   if(count_trigger<=0) return;
296         
297         
298   Int_t NumOfBNoPS[10];
299   Int_t NumOfBWithPS[10];
300   Int_t NumOfACNoPS[10];
301   Int_t NumOfENoPS[10];
302   Int_t NumOfACWithPS[10];
303   Int_t NumOfEWithPS[10];
304         
305   for(Int_t i = 0; i < triggersB->GetEntriesFast(); i++){
306     NumOfBNoPS[i] = hBNoPS[i]->Integral();
307     NumOfBWithPS[i] = hBWithPS[i]->Integral();
308     NumOfACNoPS[i] = hACNoPS[i]->Integral();
309     NumOfENoPS[i] = hENoPS[i]->Integral();
310     NumOfACWithPS[i] = hACWithPS[i]->Integral();
311     NumOfEWithPS[i] = hEWithPS[i]->Integral();
312   }
313         
314
315   cout<<"//==================================================================================="<<endl;
316   cout<<"// Put all plots in a ps file, easier to publish (Twiki)"<<endl;
317   cout<<"//==================================================================================="<<endl;
318   
319   c1->Print(OutFileNamePDF_open.Data());
320   TFile *rootFileOut = TFile::Open(OutFileNameROOT.Data(),"RECREATE");
321   cAll->Print(OutFileNamePDF.Data());
322   cAll->Write();
323         
324         
325   cout<<"//==================================================================================="<<endl;
326   cout<<"// new canvas with the total number of trigger with and without Phys. Sel."<<endl;
327   cout<<"//==================================================================================="<<endl;
328         
329   TCanvas *cTriggerContent = ProcessCanvasTriggerContent(triggersB, hBNoPS, hBWithPS, "TriggerContent");
330   cTriggerContent->Draw(); 
331   cTriggerContent->Print(OutFileNamePDF.Data());
332   cTriggerContent->Write();
333   
334   cout<<"//==================================================================================="<<endl;
335   cout<<"// new canvas with the relative content of each trigger w/o physics selection"<<endl;
336   cout<<"//==================================================================================="<<endl;
337         
338   TCanvas *cRelativeTriggerContent = ProcessCanvasRelativeTriggerContent(triggersB, hBNoPS, "RelativeTriggerContent", colorInd);
339   cRelativeTriggerContent->Draw();
340   cRelativeTriggerContent->Print(OutFileNamePDF.Data());
341   cRelativeTriggerContent->Write();
342         
343   cout<<"//==================================================================================="<<endl;
344   cout<<"// new canvas with effect from physics selection for each trigger and background trigger "<<endl;
345   cout<<"//==================================================================================="<<endl;
346         
347   TCanvas *cPhysSelCut = ProcessCanvasPhysSelCut(triggersB, triggersAC, triggersE, hBNoPS, hACNoPS, hENoPS, hBWithPS, "PhysSelCutOnCollTrigger", colorInd);
348   cPhysSelCut->Draw();
349   cPhysSelCut->Print(OutFileNamePDF.Data());
350   cPhysSelCut->Write();
351
352   cout<<"//==================================================================================="<<endl;
353   cout<<"// Ratio of tracks over trigger type (3 canvases) "<<endl;
354   cout<<"//==================================================================================="<<endl;
355
356   //Print a canvas per trigger type
357   TCanvas *cTracksoverTrigger[10];
358   TCanvas* cTrackMultB[10];
359   TCanvas* cRatioTrackB[10];
360         
361   //loop over trigger
362   Int_t k=0;
363   TString canvasName;
364   TString triggerName;
365   for(k = 0; k < triggersB->GetEntriesFast(); k++){
366     //skip sum of all triggers
367     if(k == (triggersB->GetEntriesFast()-1)) continue;
368     //skip some triggers
369     if( !IsTrigger(triggersB, k, "INT") && !IsTrigger(triggersB, k, "MUS" ) && !IsTrigger(triggersB, k, "ANY") && !IsTrigger(triggersB,k,"CMB") ) continue;
370                 
371     cTracksoverTrigger[k]= ProcessCanvasTracksoverTrigger(triggersB, hB, hTrackerB, hTriggerB, hMatchedB, hAllTracksB, k, "RatioTrackTypes");
372     cTracksoverTrigger[k]->Draw();
373     cTracksoverTrigger[k]->Print(OutFileNamePDF.Data());
374     cTracksoverTrigger[k]->Write();
375
376     cTrackMultB[k]= ProcessCanvasTrackMultB(triggersB, hB, hTrackerB, hTriggerB, hMatchedB, hAllTracksB, k, "TrackMult");
377     cTrackMultB[k]->Draw();
378     cTrackMultB[k]->Print(OutFileNamePDF.Data());
379     cTrackMultB[k]->Write();
380         
381     cRatioTrackB[k]= ProcessCanvasRatioTrackB(triggersB, hB, hTrackerB, hTriggerB, hMatchedB, hAllTracksB, k, "RatioTrackB");
382     cRatioTrackB[k]->Draw();
383     cRatioTrackB[k]->Print(OutFileNamePDF.Data());
384     cRatioTrackB[k]->Write();
385   }
386         
387
388   cout<<"//===================================================="<<endl;
389   cout<<"// Draw matched tracks asymmetry for mus type trigger "<<endl;
390   cout<<"//===================================================="<<endl;
391         
392   //Print a canvas per trigger type
393   TCanvas *cAsymMatched[10];
394         
395   //loop over trigger
396   for(k = 0; k < triggersB->GetEntriesFast(); k++){
397     //skip sum of all triggers
398     if(k == (triggersB->GetEntriesFast()-1)) continue;
399     //skip some triggers
400     if( !IsTrigger(triggersB, k, "MUS" ) ) continue;
401                 
402     cAsymMatched[k]= ProcessCanvasAsymMatched(triggersB, hPosMatchedB, hNegMatchedB, hAllMatchedB, k, "AsymMatched");
403     cAsymMatched[k]->Draw();
404     cAsymMatched[k]->Print(OutFileNamePDF.Data());
405     cAsymMatched[k]->Write();
406   }
407         
408   cout<<"//=================================================="<<endl;
409   cout<<"// Draw high pt tracks per trigger"<<endl;
410   cout<<"//=================================================="<<endl;
411
412   //Print a canvas per trigger type
413   TCanvas *cHighPtMuons[10];
414         
415   //loop over trigger
416   for(k = 0; k < triggersB->GetEntriesFast(); k++){
417     //skip sum of all triggers
418     if(k == (triggersB->GetEntriesFast()-1)) continue;
419     //skip some triggers
420     if( !IsTrigger(triggersB, k, "MUS" ) ) continue;
421                 
422     cHighPtMuons[k]= ProcessCanvasHighPtMuons(triggersB, hB, hMatchedLowPtB, hMatchedHighPtB, k, "HighPtMuons");
423     cHighPtMuons[k]->Draw();
424     cHighPtMuons[k]->Print(OutFileNamePDF.Data());
425     cHighPtMuons[k]->Write();
426   }
427         
428   // close merged file  
429   globalFile->Close();
430   
431   //===================================================================================
432   //Print out the number of trigger without and with Phys. Sel.
433   //===================================================================================
434   
435   cout << endl << endl;
436   //====================================================
437   if (PRINTSTAT){
438     // set the format to print labels
439     THashList* labels = hBWithPS[kCMUS]->GetXaxis()->GetLabels();
440     TString format(Form("\n%%%ds %%9d",0));
441     Int_t nRuns=0;
442     
443     // print value for each label
444     TObjString* label = 0x0;
445     TIter nextLabel(labels);
446     cout << "-------------------------------------------------" << endl;
447     cout << "Run Number" << "\t Number of "<< ( (TObjString*) triggersB->At(kCMUS) )->GetString()<<" after Phys. Sel. " << endl ;  
448     while ((label = static_cast<TObjString*>(nextLabel()))) {
449       nRuns++;
450       Int_t bin = (Int_t) label->GetUniqueID();
451       printf(format.Data(), label->String().Data(), (Int_t) hBWithPS[kCMUS]->GetBinContent(bin));
452     }
453     printf("\n========== Total #runs = %d ==============\n",nRuns);
454     printf("\n\n");
455     
456     
457     cout << "-------------------------------------------------" << endl;
458     cout << "Total statistic" << endl; 
459     cout << " " << endl ; 
460     
461     cout << "-------------------------------------------------------------------" << endl;
462     cout<<"Number of triggers w/o Phys. Sel./ w/ Phys. Sel (Phys. Sel. cut in %)"<<endl;
463     for(Int_t i = 0; i < triggersB->GetEntriesFast()-1; i++){
464       TString triggerNameB = ( (TObjString*) triggersB->At(i) )->GetString();
465       TString triggerNameAC = ( (TObjString*) triggersAC->At(i) )->GetString();
466       TString triggerNameE = ( (TObjString*) triggersE->At(i) )->GetString();
467                         
468       Int_t     cutinpercent    =       0;
469       printf("%10s %30s %30s\n",triggerNameB.Data(),triggerNameAC.Data(),triggerNameE.Data());
470       if(NumOfBNoPS[i]) cutinpercent = (Int_t) ((Double_t)(NumOfBNoPS[i]-NumOfBWithPS[i])/(NumOfBNoPS[i])*100.);
471       printf("%5.2e / %.2e (%d%%)", (Double_t) NumOfBNoPS[i],(Double_t) NumOfBWithPS[i],cutinpercent);
472       cutinpercent = 0;
473       if(NumOfACNoPS[i]) cutinpercent = (Int_t) ((Double_t)(NumOfACNoPS[i]-NumOfACWithPS[i])/(NumOfACNoPS[i])*100.);
474       printf("%15.2e / %.2e (%d%%)", (Double_t)NumOfACNoPS[i],(Double_t)NumOfACWithPS[i],cutinpercent);
475       cutinpercent = 0;
476       if(NumOfENoPS[i]) cutinpercent = (Int_t) ((Double_t)(NumOfENoPS[i]-NumOfEWithPS[i])/(NumOfENoPS[i])*100.);
477       printf("%15.2e  / %.2e (%d%%)\n", (Double_t)NumOfENoPS[i],(Double_t)NumOfEWithPS[i],cutinpercent);
478
479     }
480     
481   }
482   
483   
484   //return;
485          
486   
487   //--------------------------------------------- //
488   //        monitor quantities run per run        //
489   //--------------------------------------------- //
490   TH1F* hTriggerCutVsRun[2], *hTriggerCutWidthVsRun[2];
491   for ( Int_t ihisto=0; ihisto<2; ++ihisto ) {
492     TString cutName = ( ihisto == 0 ) ? "Lpt" : "Hpt";
493     hTriggerCutVsRun[ihisto] = new TH1F(Form("hTriggerCutVsRun%s", cutName.Data()), Form("Trigger %s cut per run", cutName.Data()), 10000,1,10000);
494     hTriggerCutWidthVsRun[ihisto] = (TH1F*)hTriggerCutVsRun[ihisto]->Clone(Form("hTriggerCutWidthVsRun%s", cutName.Data()));
495   }
496   TF1* fitMatchTrig = new TF1("fitMatchTrig","[3] + [0] * ( 1. + TMath::Erf((x - [1]) / [2]))", 0.1, 6.);       
497   TH1F* hNClustersPerTrackVsRun_Mean = new TH1F("hNClustersPerTrackVsRun_Mean", "averaged number of associated clusters per track;run;<n_{clusters}>",10000,1,10000);
498   TH1F* hNClustersPerTrackVsRun_Sigma = new TH1F("hNClustersPerTrackVsRun_Sigma", "dispersion of the number of associated clusters per track;run;#sigma_{n_{clusters}}",10000,1,10000);
499   TH1F* hNChamberHitPerTrack_Mean = new TH1F("hNChamberHitPerTrack_Mean", "averaged number of chambers hit per track;run;<n_{chamber hit}>",10000,1,10000);
500   TH1F* hNChamberHitPerTrack_Sigma = new TH1F("hNChamberHitPerTrack_Sigma", "dispersion of the number of chambers hit per track;run;#sigma_{n_{chamber hit}}",10000,1,10000);
501   TH1F* hChi2_Mean = new TH1F("hChi2_Mean", "averaged normalized #chi^{2} distribution;run;<#chi^{2} / ndf>",10000,1,10000);
502   TH1F* hChi2_Sigma = new TH1F("hChi2_Sigma", "dispersion of normalized #chi^{2} distribution;run;#sigma_{#chi^{2} / ndf}",10000,1,10000);
503   TH1F* hNClustersInCh[10];
504   for (Int_t ich=0; ich<10; ich++){
505     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);
506   }
507   TH1F* hClusterHitMapXInCh[10];
508   for (Int_t ich=0; ich<10; ich++){
509     hClusterHitMapXInCh[ich] = new TH1F(Form("hClusterHitMapXInCh%d",ich+1), Form("averaged cluster position distribution in chamber %d;X (cm)",ich+1),10000,1,10000);
510   }
511   TH1F* hClusterHitMapYInCh[10];
512   for (Int_t ich=0; ich<10; ich++){
513     hClusterHitMapYInCh[ich] = new TH1F(Form("hClusterHitMapYInCh%d",ich+1), Form("averaged cluster position distribution in chamber %d;Y (cm)",ich+1),10000,1,10000);
514   }
515   Int_t ibin = 1;
516   
517   // Are the runs stored locally or in alien?
518   Int_t isAlienFile = 0;
519   if(alienBaseDir.Contains("alien:")){
520     isAlienFile = 1;
521     alienBaseDir.ReplaceAll("alien://","");
522   }
523   cout<<"============================================================"<<endl;
524   cout<< "Monitoring quantities run per run: loop over "<<runs->GetEntriesFast()<<" runs."<<endl;
525   cout<<"  directory = "<<alienBaseDir.Data()<<endl;
526   cout<<"============================================================"<<endl;
527   // Loop over runs
528   for ( Int_t irun=0; irun<runs->GetEntriesFast(); irun++ ) {
529     
530     TString run = ((TObjString*)runs->UncheckedAt(irun))->GetString();
531     TString run2 = ((TObjString*)runs2->UncheckedAt(irun))->GetString();
532     // get the file (or list of files) to be analyzed
533     TString command;
534     TGridResult *res = 0;
535     TObjString *objs = 0;       
536     
537     if(isAlienFile){
538       command = Form("find %s/ %s/%s", alienBaseDir.Data(), run.Data(), QAFileName);
539       res = gGrid->Command(command);
540       if (!res) {
541         Error("PlotMUONQApp","no result for the command: %s",command.Data());
542         return;
543       }
544     }
545     else{
546       res = new TGridResult();  
547       
548       if(runList){
549         objs = new TObjString(Form("%s/%s/%s", alienBaseDir.Data(), run2.Data(), QAFileName));
550         res->Add(objs);
551       }
552       else {
553         //loop over the directory to find the root files
554         void *dir = gSystem->OpenDirectory(alienBaseDir.Data());
555         TString sDirFilename;
556         Int_t iEntry=0, iFile=0;
557         while(kTRUE){
558           iEntry++;
559           const char* dirFilename = gSystem->GetDirEntry(dir);
560           if(!dirFilename) break;
561           sDirFilename = dirFilename;
562           if(!sDirFilename.IsDigit()) continue;
563           iFile++;
564           objs = new TObjString(Form("%s/%s/%s", alienBaseDir.Data(), sDirFilename.Data(), QAFileName));
565           res->Add(objs);
566         }
567       }
568     }
569     
570     // Loop over 'find' results and get next LFN
571     TIter nextmap(res);
572     TMap *map = 0;
573     
574     //some checks
575     Int_t iLoop=0, iLoopMax=200;
576     while (kTRUE){
577       
578       // get the current file url
579       if(isAlienFile){
580         map=(TMap*)nextmap();
581         if(!map) break;
582         objs = dynamic_cast<TObjString*>(map->GetValue("turl"));
583       }
584       else{
585         objs=(TObjString*)nextmap();
586         if(!objs) break;
587       } 
588       //in case of infinite loop
589       iLoop++;
590       if(iLoop>iLoopMax) break;
591       
592       if (!objs || !objs->GetString().Length()) {
593         Error("PlotMUONQApp","turl/obj not found for the run %s... SKIPPING", run.Data());
594         continue;
595       }
596       
597       // open the outfile for this run
598       TFile *runFile = TFile::Open(objs->GetString());
599       if (!runFile || ! runFile->IsOpen()) {
600         Error("PlotMUONQApp","failed to open file: %s", objs->GetName());
601         continue;//return;
602       }
603       runFile->Cd("MUON_QA");
604       
605       // get interesting histos
606       TObjArray* general1 = static_cast<TObjArray*>(runFile->FindObjectAny("general1"));
607       TObjArray* general2 = static_cast<TObjArray*>(runFile->FindObjectAny("general2"));
608       TObjArray* expert = static_cast<TObjArray*>(runFile->FindObjectAny("expert"));
609       
610       if (!general1 || !general2 || !expert){
611         Error("PlotMUONQApp","All objects not here !!! ===> Skipping...for %s",objs->GetName());                
612         continue;
613       }
614       
615       TH1* hNClustersPerTrack = static_cast<TH1*>(general1->FindObject("hNClustersPerTrack"));
616       TH1* hNChamberHitPerTrack = static_cast<TH1*>(general1->FindObject("hNChamberHitPerTrack"));
617       TH1* hChi2 = static_cast<TH1*>(general1->FindObject("hChi2"));
618       TH1* hNClustersPerCh = static_cast<TH1*>(general2->FindObject("hNClustersPerCh"));
619       TH1* hPtDistrib = static_cast<TH1*>(general1->FindObject("hPt"));
620       TH1* hPtDistribLpt = static_cast<TH1*>(general1->FindObject("hPtMatchLpt"));
621       TH1* hPtDistribHpt = static_cast<TH1*>(general1->FindObject("hPtMatchHpt"));
622       if ( hPtDistrib && hPtDistribLpt && hPtDistribHpt ) {
623         if ( hPtDistrib->GetSumw2N() == 0 ) hPtDistrib->Sumw2();
624         TH1* histoMatch[2] = {hPtDistribLpt, hPtDistribHpt};
625         for ( Int_t ihisto=0; ihisto<2; ++ihisto ) {
626           if ( histoMatch[ihisto]->GetSumw2N() == 0 ) histoMatch[ihisto]->Sumw2();
627           if ( histoMatch[ihisto]->GetEntries() == 0 ) continue;
628           histoMatch[ihisto]->Divide(hPtDistrib);
629           Double_t minEff = 99999., maxEff = -1.;
630           Double_t ptMinFit = 0.1;
631           Double_t ptMaxFit = 6.;
632           Int_t ptBinLow = histoMatch[ihisto]->GetXaxis()->FindBin(ptMinFit);
633           Int_t ptBinHigh = histoMatch[ihisto]->GetXaxis()->FindBin(ptMaxFit);
634           for ( Int_t currBin=ptBinLow; currBin<=ptBinHigh; currBin++ ) {
635             Double_t currEff = histoMatch[ihisto]->GetBinContent(currBin);
636             Double_t currPt = histoMatch[ihisto]->GetXaxis()->GetBinCenter(currBin);
637             if ( currPt < 1.5 && minEff > currEff ) {
638               ptMinFit = currPt;
639               minEff = currEff;
640             }
641             if ( currPt > 0.5 && maxEff < currEff ) {
642               ptMaxFit = currPt;
643               maxEff = currEff;
644             }
645           } // loop on histo bins
646           fitMatchTrig->SetParameters(0.5, 0.5, 0.8, 0.2);
647           fitMatchTrig->SetParLimits(0,0.,1.);
648           fitMatchTrig->SetParLimits(1,0.,5.);
649           fitMatchTrig->SetParLimits(2,0.,5.);
650           fitMatchTrig->SetParLimits(3,0.,0.5);
651           histoMatch[ihisto]->Fit(fitMatchTrig,"RQ0","",ptMinFit,ptMaxFit);          
652           Double_t ptCut = fitMatchTrig->GetParameter(1);
653           Double_t ptCutErr = fitMatchTrig->GetParError(1);
654           Double_t ptCutWidth = fitMatchTrig->GetParameter(2);
655           if ( ptCut < 0 || ptCut > 10. ) {
656             ptCut = ptCutErr = ptCutWidth = 0.;
657           }
658           hTriggerCutVsRun[ihisto]->SetBinContent(ibin, ptCut);
659           hTriggerCutVsRun[ihisto]->SetBinError(ibin, ptCutErr);
660           hTriggerCutWidthVsRun[ihisto]->SetBinContent(ibin, ptCut);
661           hTriggerCutWidthVsRun[ihisto]->SetBinError(ibin, ptCutWidth);
662         } // loop on match histos
663       }                 
664       TH2* hClusterHitMapInCh[10];
665       for(Int_t ich=0; ich<10; ich++) hClusterHitMapInCh[ich] = static_cast<TH2*>(expert->FindObject(Form("hClusterHitMapInCh%d",ich+1)));
666       
667       // skip empty runs... not anymore ! cs !
668       if (!hNClustersPerCh) {
669         Warning("PlotMUONQApp","File: %s has empty histograms !", objs->GetName());
670         hNClustersPerTrackVsRun_Mean->SetBinContent(ibin, 0.);
671         hNClustersPerTrackVsRun_Mean->SetBinError(ibin, 1.);
672         hNClustersPerTrackVsRun_Sigma->SetBinContent(ibin, 0.);
673         hNClustersPerTrackVsRun_Sigma->SetBinError(ibin, 1.);
674         hNChamberHitPerTrack_Mean->SetBinContent(ibin, 0.);
675         hNChamberHitPerTrack_Mean->SetBinError(ibin, 1.);
676         hNChamberHitPerTrack_Sigma->SetBinContent(ibin, 0.);
677         hNChamberHitPerTrack_Sigma->SetBinError(ibin, 1.);
678         hChi2_Mean->SetBinContent(ibin, 0.);
679         hChi2_Mean->SetBinError(ibin, 1.);
680         hChi2_Sigma->SetBinContent(ibin, 0.);
681         hChi2_Sigma->SetBinError(ibin, 1.);
682         for (Int_t ich=0; ich<10; ich++) {
683           hNClustersInCh[ich]->SetBinContent(ibin,0.);
684           hNClustersInCh[ich]->SetBinError(ibin,1.);
685           hClusterHitMapXInCh[ich]->SetBinContent(ibin,0.);
686           hClusterHitMapXInCh[ich]->SetBinError(ibin,1.);
687           hClusterHitMapYInCh[ich]->SetBinContent(ibin,0.);
688           hClusterHitMapYInCh[ich]->SetBinError(ibin,1.);       
689         }
690         //runFile->Close();
691         //continue;
692       }
693       else {
694         // fill monitoring plots
695         hNClustersPerTrackVsRun_Mean->SetBinContent(ibin, hNClustersPerTrack->GetMean());
696         hNClustersPerTrackVsRun_Mean->SetBinError(ibin, hNClustersPerTrack->GetMeanError());
697         hNClustersPerTrackVsRun_Sigma->SetBinContent(ibin, hNClustersPerTrack->GetRMS());
698         hNClustersPerTrackVsRun_Sigma->SetBinError(ibin, hNClustersPerTrack->GetRMSError());
699         hNChamberHitPerTrack_Mean->SetBinContent(ibin, hNChamberHitPerTrack->GetMean());
700         hNChamberHitPerTrack_Mean->SetBinError(ibin, hNChamberHitPerTrack->GetMeanError());
701         hNChamberHitPerTrack_Sigma->SetBinContent(ibin, hNChamberHitPerTrack->GetRMS());
702         hNChamberHitPerTrack_Sigma->SetBinError(ibin, hNChamberHitPerTrack->GetRMSError());
703         hChi2_Mean->SetBinContent(ibin, hChi2->GetMean());
704         hChi2_Mean->SetBinError(ibin, hChi2->GetMeanError());
705         hChi2_Sigma->SetBinContent(ibin, hChi2->GetRMS());
706         hChi2_Sigma->SetBinError(ibin, hChi2->GetRMSError());
707         for (Int_t ich=0; ich<10; ich++) {
708           hNClustersInCh[ich]->SetBinContent(ibin,hNClustersPerCh->GetBinContent(ich+1));
709           hNClustersInCh[ich]->SetBinError(ibin,hNClustersPerCh->GetBinError(ich+1));
710           hClusterHitMapXInCh[ich]->SetBinContent(ibin,hClusterHitMapInCh[ich]->GetMean(1));
711           hClusterHitMapXInCh[ich]->SetBinError(ibin,hClusterHitMapInCh[ich]->GetMeanError(1));
712           hClusterHitMapYInCh[ich]->SetBinContent(ibin,hClusterHitMapInCh[ich]->GetMean(2));
713           hClusterHitMapYInCh[ich]->SetBinError(ibin,hClusterHitMapInCh[ich]->GetMeanError(2));   
714         }
715       }
716       
717       // set labels
718       run = objs->GetString();
719       run.ReplaceAll(Form("/%s",QAFileName), "");
720       run.ReplaceAll(alienBaseDir, "");
721       run.Remove(TString::kLeading, '/');
722       run.Remove(TString::kLeading, '0');
723       hNClustersPerTrackVsRun_Mean->GetXaxis()->SetBinLabel(ibin, run.Data());
724       hNClustersPerTrackVsRun_Sigma->GetXaxis()->SetBinLabel(ibin, run.Data());
725       hNChamberHitPerTrack_Mean->GetXaxis()->SetBinLabel(ibin, run.Data());
726       hNChamberHitPerTrack_Sigma->GetXaxis()->SetBinLabel(ibin, run.Data());
727       hChi2_Mean->GetXaxis()->SetBinLabel(ibin, run.Data());
728       hChi2_Sigma->GetXaxis()->SetBinLabel(ibin, run.Data());
729       for (Int_t ich=0; ich<10; ich++){
730         hNClustersInCh[ich]->GetXaxis()->SetBinLabel(ibin, run.Data());
731         hClusterHitMapXInCh[ich]->GetXaxis()->SetBinLabel(ibin, run.Data());
732         hClusterHitMapYInCh[ich]->GetXaxis()->SetBinLabel(ibin, run.Data());
733       }
734       
735       // close outfile for this run
736       runFile->Close();
737       ibin++;      
738     }
739     
740     delete res;
741   }
742   
743   //sort label
744   hNClustersPerTrackVsRun_Mean->LabelsOption("a");
745   hNClustersPerTrackVsRun_Sigma->LabelsOption("a");
746   hNChamberHitPerTrack_Mean->LabelsOption("a");
747   hNChamberHitPerTrack_Sigma->LabelsOption("a");
748   hChi2_Mean->LabelsOption("a");
749   hChi2_Sigma->LabelsOption("a");
750   
751   for(Int_t ich=0; ich<10; ich++){
752     hNClustersInCh[ich]->LabelsOption("a");
753     hClusterHitMapXInCh[ich]->LabelsOption("a");
754     hClusterHitMapYInCh[ich]->LabelsOption("a");
755   }
756
757   TString dirToGo =  OutFileNameROOT.Data(); dirToGo+=":/";
758   gDirectory->Cd(dirToGo.Data());
759   //==================================================
760   //Display Mean and Sigma of the number of associated clusters to a track 
761   TLegend *lNClusters = new TLegend(0.75,0.85,0.99,0.99);
762   lNClusters->AddEntry(hNClustersPerTrackVsRun_Mean,"clusters","PL");
763   lNClusters->AddEntry(hNChamberHitPerTrack_Mean,"chamber hit","PL");
764   
765   TCanvas* cNClusters = new TCanvas("cNClusters","cNClusters",1200,900);
766   cNClusters->Divide(1,2);
767   cNClusters->cd(1);
768   //hNClustersPerTrackVsRun_Mean->SetMaximum(11);
769   hNClustersPerTrackVsRun_Mean->SetMinimum(7);
770   hNClustersPerTrackVsRun_Mean->SetStats(kFALSE);
771   hNClustersPerTrackVsRun_Mean->GetXaxis()->SetRange(1,ibin-1);
772   hNClustersPerTrackVsRun_Mean->GetXaxis()->SetNdivisions(1,kFALSE);
773   //hNClustersPerTrackVsRun_Mean->LabelsOption("u");
774   hNClustersPerTrackVsRun_Mean->SetLabelSize(0.04);
775   hNClustersPerTrackVsRun_Mean->SetTitle("averaged number of associated clusters or of the number of chamber hit per track");
776   hNClustersPerTrackVsRun_Mean->SetLineWidth(2);
777   hNClustersPerTrackVsRun_Mean->Draw("e");
778   hNChamberHitPerTrack_Mean->SetLineColor(kRed);
779   hNChamberHitPerTrack_Mean->SetLineWidth(2);
780   hNChamberHitPerTrack_Mean->Draw("esame");
781   lNClusters->Draw("same");
782   
783   cNClusters->cd(2);
784   //hNClustersPerTrackVsRun_Sigma->SetMaximum(1.1);
785   hNClustersPerTrackVsRun_Sigma->SetMinimum(0.4);
786   hNClustersPerTrackVsRun_Sigma->SetStats(kFALSE);
787   hNClustersPerTrackVsRun_Sigma->GetXaxis()->SetRange(1,ibin-1);
788   hNClustersPerTrackVsRun_Sigma->GetXaxis()->SetNdivisions(1,kFALSE);
789   //hNClustersPerTrackVsRun_Sigma->LabelsOption("u");
790   hNClustersPerTrackVsRun_Sigma->SetLabelSize(0.04);
791   hNClustersPerTrackVsRun_Sigma->SetTitle("dispersion of the number of associated clusters or of the number of chamber hit per track");
792   hNClustersPerTrackVsRun_Sigma->SetLineWidth(2);
793   hNClustersPerTrackVsRun_Sigma->Draw("e");
794   hNChamberHitPerTrack_Sigma->SetLineWidth(2);
795   hNChamberHitPerTrack_Sigma->SetLineColor(kRed);
796   hNChamberHitPerTrack_Sigma->Draw("esame");
797   lNClusters->Draw("same");
798
799   cNClusters->Print(OutFileNamePDF.Data());
800   cNClusters->Write();
801
802
803   //==================================================
804   // Display average number of cluster per chamber
805   TLegend *lNClustersPerCh = new TLegend(0.92,0.45,0.99,0.99);
806   TCanvas* cNClustersPerCh = new TCanvas("cNClustersPerCh","cNClustersPerCh",1200,900);
807   cNClustersPerCh->cd();
808   cNClustersPerCh->SetRightMargin(0.1);
809   hNClustersInCh[0]->SetStats(kFALSE);
810   hNClustersInCh[0]->GetXaxis()->SetRange(1,ibin-1);
811   hNClustersInCh[0]->GetXaxis()->SetNdivisions(1,kFALSE);
812   //hNClustersInCh[0]->LabelsOption("u");
813   hNClustersInCh[0]->SetLabelSize(0.02);
814   hNClustersInCh[0]->SetTitle("averaged number of clusters in chamber i per track");
815   hNClustersInCh[0]->SetMaximum(1.2);
816   hNClustersInCh[0]->SetMinimum(0.01);
817   for (Int_t ich=0; ich<10; ich++) {
818     hNClustersInCh[ich]->SetLineColor(ich+1+ich/9);
819     hNClustersInCh[ich]->SetLineWidth(2);
820     if (ich == 0) hNClustersInCh[ich]->Draw("e");
821     else hNClustersInCh[ich]->Draw("esame");
822     lNClustersPerCh->AddEntry(hNClustersInCh[ich],Form("ch%d",ich+1),"PL");
823   }
824   lNClustersPerCh->Draw("same");
825   
826   cNClustersPerCh->Print(OutFileNamePDF.Data());
827   cNClustersPerCh->Write();
828
829   //==================================================
830   // Display average X and Y position of clusters per chamber
831   TLegend *lClusterHitMapPerCh = new TLegend(0.92,0.45,0.99,0.99);
832   TCanvas* cClusterHitMapPerCh = new TCanvas("cClusterHitMapPerCh","cClusterHitMapPerCh",1200,900);
833   cClusterHitMapPerCh->Divide(1,2);
834   cClusterHitMapPerCh->GetPad(1)->SetRightMargin(0.1);
835   cClusterHitMapPerCh->GetPad(2)->SetRightMargin(0.1);
836         
837   cClusterHitMapPerCh->cd(1);
838   hClusterHitMapXInCh[0]->SetStats(kFALSE);
839   hClusterHitMapXInCh[0]->GetXaxis()->SetRange(1,ibin-1);
840   hClusterHitMapXInCh[0]->GetXaxis()->SetNdivisions(1,kFALSE);
841   //hNClustersInCh[0]->LabelsOption("u");
842   hClusterHitMapXInCh[0]->SetLabelSize(0.04);
843   hClusterHitMapXInCh[0]->SetTitle("<X> of clusters - associated to a track - in chamber i");
844   hClusterHitMapXInCh[0]->SetMaximum(30);
845   hClusterHitMapXInCh[0]->SetMinimum(-30);
846   for (Int_t ich=0; ich<10; ich++) {
847     hClusterHitMapXInCh[ich]->SetLineColor(ich+1+ich/9);
848     hClusterHitMapXInCh[ich]->SetLineWidth(2);
849     if (ich == 0) hClusterHitMapXInCh[ich]->Draw("e");
850     else hClusterHitMapXInCh[ich]->Draw("esame");
851     
852     lClusterHitMapPerCh->AddEntry(hClusterHitMapXInCh[ich],Form("ch%d",ich+1),"PL");
853   }
854   lClusterHitMapPerCh->Draw("same");
855   
856   cClusterHitMapPerCh->cd(2);
857   hClusterHitMapYInCh[0]->SetStats(kFALSE);
858   hClusterHitMapYInCh[0]->GetXaxis()->SetRange(1,ibin-1);
859   hClusterHitMapYInCh[0]->GetXaxis()->SetNdivisions(1,kFALSE);
860   //hNClustersInCh[0]->LabelsOption("u");
861   hClusterHitMapYInCh[0]->SetLabelSize(0.04);
862   hClusterHitMapYInCh[0]->SetTitle("<Y> of clusters - associated to a track - in chamber i");
863   hClusterHitMapYInCh[0]->SetMaximum(30);
864   hClusterHitMapYInCh[0]->SetMinimum(-30);
865   for (Int_t ich=0; ich<10; ich++) {
866     hClusterHitMapYInCh[ich]->SetLineColor(ich+1+ich/9);
867     hClusterHitMapYInCh[ich]->SetLineWidth(2);
868     if (ich == 0) hClusterHitMapYInCh[ich]->Draw("e");
869     else hClusterHitMapYInCh[ich]->Draw("esame");
870   }
871   lClusterHitMapPerCh->Draw("same");
872
873   cClusterHitMapPerCh->Print(OutFileNamePDF.Data());
874   cClusterHitMapPerCh->Write();
875
876
877   //==================================================
878   // Display tracks ChiSquare 
879   TCanvas* cChi2 = new TCanvas("cChi2","cChi2",1200,900);
880   cChi2->Divide(1,2);
881   cChi2->cd(1);
882   hChi2_Mean->SetStats(kFALSE);
883   hChi2_Mean->GetXaxis()->SetRange(1,ibin-1);
884   hChi2_Mean->GetXaxis()->SetNdivisions(1,kFALSE);
885   //hChi2_Mean->LabelsOption("u");
886   hChi2_Mean->SetLabelSize(0.04);
887   hChi2_Mean->SetLineWidth(2);
888   hChi2_Mean->Draw("e");
889
890   cChi2->cd(2);
891   hChi2_Sigma->SetStats(kFALSE);
892   hChi2_Sigma->GetXaxis()->SetRange(1,ibin-1);
893   hChi2_Sigma->GetXaxis()->SetNdivisions(1,kFALSE);
894   //hChi2_Sigma->LabelsOption("u");
895   hChi2_Sigma->SetLabelSize(0.04);
896   hChi2_Sigma->SetLineWidth(2);
897   hChi2_Sigma->Draw("e");
898
899   cChi2->Print(OutFileNamePDF.Data());
900   cChi2->Write();
901
902   //==================================================
903   // Display track Lpt/Hpt 
904   if ( hTriggerCutVsRun[0] && hTriggerCutVsRun[1] ) {
905     TCanvas* cLptHpt = new TCanvas("cLptHpt","cLptHpt",1200,900);
906     cLptHpt->Divide(1,2);
907     TLegend* legLptHpt = new TLegend(0.72,0.7,0.9,0.85);
908     legLptHpt->SetBorderSize(1);
909     for ( Int_t ihisto=0; ihisto<2; ++ihisto) {
910       cLptHpt->cd(ihisto+1);
911       TH1* currHistos[2] = {hTriggerCutVsRun[ihisto], hTriggerCutWidthVsRun[ihisto]};
912       for ( Int_t jhisto=0; jhisto<2; jhisto++ ) {
913         currHistos[jhisto]->GetXaxis()->SetRange(1,ibin-1);
914         currHistos[jhisto]->GetYaxis()->SetRangeUser(0.,5.);
915         currHistos[jhisto]->LabelsOption("a");
916         currHistos[jhisto]->SetStats(kFALSE);
917         currHistos[jhisto]->GetXaxis()->SetLabelSize(0.04);
918         currHistos[jhisto]->SetLineWidth(2);
919       }
920       hTriggerCutWidthVsRun[ihisto]->SetLineColor(2);
921       hTriggerCutWidthVsRun[ihisto]->SetMarkerColor(2);
922       hTriggerCutWidthVsRun[ihisto]->SetFillColor(2);
923       hTriggerCutWidthVsRun[ihisto]->SetFillStyle(3001);
924       hTriggerCutWidthVsRun[ihisto]->Draw("e2");
925       hTriggerCutVsRun[ihisto]->Draw("esame");
926       if ( ihisto == 0 ) {
927         legLptHpt->AddEntry(hTriggerCutWidthVsRun[ihisto],"Fit width","f");
928         legLptHpt->AddEntry(hTriggerCutVsRun[ihisto],"pt cut from fit (stat error)","lp");
929         legLptHpt->Draw("same");
930       }
931     }
932     cLptHpt->Print(OutFileNamePDF.Data());
933     cLptHpt->Write();
934   }
935         
936         
937   // close the PDF file
938   c1->Print(OutFileNamePDF_close.Data());
939   rootFileOut->Close();
940                         
941                 
942         
943   delete runs;
944   delete runs2;
945   delete triggersB;
946   delete triggersAC;
947   delete triggersE;
948         
949   return;
950         
951 }
952
953 void SetCanvas(TCanvas *canvas, Int_t logy){
954
955   if(!canvas) return;
956   canvas->SetTopMargin(0.05);
957   canvas->SetRightMargin(0.01);
958   canvas->SetGridy(1);
959   canvas->SetLogy(logy);
960         
961   return;
962 }
963
964 Bool_t IsTrigger(TObjArray *array, Int_t index, TString name){
965         
966   Bool_t process = kFALSE;
967         
968   if( !array) return process;
969         
970   TString triggerName = (( (TObjString*) array->At(index) )->GetString());
971         
972   if( triggerName.Contains(name) ) process = kTRUE;
973         
974   return process;
975 }
976
977 TCanvas *ProcessCanvasTriggerContent(TObjArray *array, TH1 **hBNoPS, TH1 **hBWithPS, TString canvasName){
978  
979   if(!array || !hBNoPS || !hBWithPS) return 0x0;
980         
981   TString cName =  "c"; 
982   cName += canvasName; 
983   TCanvas *cTriggerContent = new TCanvas(canvasName,cName,1200,900);
984   SetCanvas(cTriggerContent);
985   cTriggerContent->cd();
986  
987   TLegend* legcTC = new TLegend(0.2,0.15,0.50,0.40);
988   legcTC->SetHeader("Physics Selection");
989   legcTC->AddEntry(".","applied :","");
990  
991   for(Int_t i = 0; i < array->GetEntriesFast(); i++){
992     //skip the sum of all triggers
993     if( i== (array->GetEntriesFast()-1) ) continue;
994     hBNoPS[i]->SetLineStyle(2);
995     if(i==0){
996       hBNoPS[i]->SetMinimum(1e-3);
997       hBNoPS[i]->Draw();
998       hBWithPS[i]->Draw("same");
999     }
1000     else{
1001       hBNoPS[i]->Draw("same");
1002       hBWithPS[i]->Draw("same");
1003     }
1004     legcTC->AddEntry(hBWithPS[i],(( (TObjString*) array->At(i) )->GetString()).Data(),"l");
1005   }
1006   legcTC->AddEntry(".","not applied :","");
1007         
1008   for(Int_t i = 0; i < array->GetEntriesFast(); i++){
1009     legcTC->AddEntry(hBNoPS[i],(( (TObjString*) array->At(i) )->GetString()).Data(),"l");        
1010   }
1011         
1012   legcTC->Draw("same");
1013  
1014   return cTriggerContent;
1015 }
1016
1017 TCanvas *ProcessCanvasRelativeTriggerContent(TObjArray *triggersB, TH1 **histo, TString canvasName, Int_t *colorInd){
1018         
1019   if(!triggersB || !histo || !colorInd) return 0x0;
1020         
1021   TString cName =  "c" ; 
1022   cName += canvasName;
1023   TCanvas *cRelativeTriggerContent = new TCanvas(canvasName,cName,1200,900);
1024   SetCanvas(cRelativeTriggerContent);
1025   cRelativeTriggerContent->cd();
1026         
1027   TH1* ratio[10];
1028   TLegend* legcRTC = new TLegend(0.2,0.15,0.50,0.40);
1029   legcRTC->SetHeader("Physics Selection");
1030         
1031   TString hName, hTriggerName;
1032   Int_t indAllTrig = triggersB->GetEntriesFast()-1;
1033   cout<<indAllTrig<<endl;
1034   for(Int_t i = 0; i < triggersB->GetEntriesFast()-1; i++){
1035     hName = "ratio";
1036     hName += ( (TObjString*) triggersB->At(i) )->GetString();
1037     ratio[i] = static_cast<TH1*> (histo[i]->Clone(hName));
1038     ratio[i]->Divide(histo[indAllTrig]);
1039     ratio[i]->SetLineWidth(2);
1040     ratio[i]->SetLineColor(colorInd[i]);
1041     if(i==0){
1042       ratio[i]->SetMaximum(1.5);
1043       ratio[i]->SetMinimum(0.001);
1044       ratio[i]->SetLabelSize(0.02);
1045       ratio[i]->GetYaxis()->SetTitle("Relative trigger content"); 
1046       ratio[i]->Draw("E");
1047     }
1048     else{
1049       ratio[i]->Draw("ESAME");
1050     }
1051   }
1052         
1053   legcRTC->AddEntry(".","not applied :","");
1054   for(Int_t i = 0; i < triggersB->GetEntriesFast()-1; i++){
1055     legcRTC->AddEntry(ratio[i],(( (TObjString*) triggersB->At(i) )->GetString()).Data(),"l");
1056   }
1057   legcRTC->Draw("same");
1058         
1059   return cRelativeTriggerContent;
1060 }
1061
1062 TCanvas *ProcessCanvasPhysSelCut(TObjArray *triggersB, TObjArray *triggersAC, TObjArray *triggersE, TH1 **hBNoPS, TH1 **hACNoPS, TH1 **hENoPS, TH1 **hBWithPS, TString canvasName, Int_t *colorInd){
1063         
1064   if(!triggersB || !triggersE || !triggersAC || !hBNoPS || !hACNoPS || !hENoPS || !hBWithPS || !colorInd) return 0x0;
1065         
1066   TString cName = "c";
1067   cName += canvasName;
1068   TCanvas *c1 = new TCanvas(canvasName,cName,1200,900);
1069   SetCanvas(c1);
1070   c1->cd();
1071          
1072   TH1* ratioB[10], *ratioBNoPS[10];
1073   TH1* ratioACNoPS[10];
1074   TH1* ratioENoPS[10];
1075   TLegend* legcRTC = new TLegend(0.2,0.15,0.50,0.40);
1076   legcRTC->SetHeader("Physics Selection");
1077          
1078   TString hName;
1079   for(Int_t i = 0; i < triggersB->GetEntriesFast()-1; i++){
1080     hName = "ratio";
1081     hName += ( (TObjString*) triggersB->At(i) )->GetString();
1082     ratioB[i] = static_cast<TH1*> (hBWithPS[i]->Clone(hName));
1083     ratioB[i]->Divide(hBNoPS[i]);
1084     ratioB[i]->SetLineWidth(2);
1085     ratioB[i]->SetLineColor(colorInd[i]);
1086     hName = "ratioNoPS";
1087     hName += ( (TObjString*) triggersB->At(i) )->GetString();
1088     ratioBNoPS[i] = static_cast<TH1*> (hBNoPS[i]->Clone(hName));
1089     ratioBNoPS[i]->Divide(hBNoPS[i]);
1090     ratioBNoPS[i]->SetLineWidth(0);
1091     ratioBNoPS[i]->SetLineStyle(1);
1092     ratioBNoPS[i]->SetMarkerStyle(24+i);
1093     ratioBNoPS[i]->SetMarkerSize(1);
1094     ratioBNoPS[i]->SetLineColor(colorInd[i]);
1095     ratioBNoPS[i]->SetMarkerColor(colorInd[i]);
1096                  
1097     hName = "ratioACNoPS";
1098     hName += ( (TObjString*) triggersAC->At(i) )->GetString();
1099     ratioACNoPS[i] = static_cast<TH1*> (hACNoPS[i]->Clone(hName));
1100     ratioACNoPS[i]->Divide(hBNoPS[i]);
1101     ratioACNoPS[i]->SetLineWidth(0);
1102     ratioACNoPS[i]->SetLineStyle(2);
1103     ratioACNoPS[i]->SetMarkerStyle(24+i);
1104     ratioACNoPS[i]->SetMarkerSize(1);
1105     ratioACNoPS[i]->SetLineColor(colorInd[i]);
1106     ratioACNoPS[i]->SetMarkerColor(colorInd[i]);
1107                  
1108                 
1109     hName = "ratioENoPS";
1110     hName += ( (TObjString*) triggersE->At(i) )->GetString();
1111     ratioENoPS[i] = static_cast<TH1*> (hENoPS[i]->Clone(hName));
1112     ratioENoPS[i]->Divide(hBNoPS[i]);
1113     ratioENoPS[i]->SetLineWidth(0);
1114     ratioENoPS[i]->SetLineStyle(3);
1115     ratioENoPS[i]->SetMarkerStyle(24+i);
1116     ratioENoPS[i]->SetMarkerSize(1);
1117     ratioENoPS[i]->SetLineColor(colorInd[i]);
1118     ratioENoPS[i]->SetMarkerColor(colorInd[i]);
1119                  
1120          
1121     if(i==0){
1122       ratioB[i]->SetMaximum(1.5);
1123       ratioB[i]->SetMinimum(0.001);
1124       ratioB[i]->SetLabelSize(0.02);
1125       ratioB[i]->GetYaxis()->SetTitle("Relative trigger content w/ and w/o Phys. Sel."); 
1126       ratioB[i]->Draw("E");
1127       //ratioBNoPS[i]->Draw("EPSAME");
1128       ratioACNoPS[i]->Draw("EPSAME");
1129       ratioENoPS[i]->Draw("EPSAME");
1130     }
1131     else{
1132       ratioB[i]->Draw("ESAME");
1133       //ratioBNoPS[i]->Draw("EPSAME");
1134       ratioACNoPS[i]->Draw("EPSAME");
1135       ratioENoPS[i]->Draw("EPSAME");
1136     }
1137   }
1138          
1139   legcRTC->AddEntry(".","applied :","");
1140   for(Int_t i = 0; i < triggersB->GetEntriesFast()-1; i++){
1141     legcRTC->AddEntry(ratioB[i],(( (TObjString*) triggersB->At(i) )->GetString()).Data(),"l");
1142   }
1143   legcRTC->AddEntry(".","not applied :","");
1144   for(Int_t i = 0; i < triggersB->GetEntriesFast()-1; i++){
1145     //legcRTC->AddEntry(ratioBNoPS[i],(( (TObjString*) triggersB->At(i) )->GetString()).Data(),"pl");
1146     legcRTC->AddEntry(ratioACNoPS[i],(( (TObjString*) triggersAC->At(i) )->GetString()).Data(),"pl");
1147     legcRTC->AddEntry(ratioENoPS[i],(( (TObjString*) triggersE->At(i) )->GetString()).Data(),"pl");
1148   }
1149   legcRTC->Draw("same");
1150         
1151         
1152   return c1;
1153 }       
1154
1155
1156 TCanvas *ProcessCanvasTracksoverTrigger(TObjArray *triggersB, TH1 **hB, TH1 **hTrackerB, TH1 **hTriggerB, TH1 **hMatchedB, TH1 **hAllTracksB, Int_t indTrigger, TString canvasName){
1157          
1158   if(!triggersB || !hB || !hTrackerB || !hTriggerB || !hMatchedB || !hAllTracksB || indTrigger<0 ) return 0x0;
1159         
1160   TH1 *hTrackerPerB, *hTriggerPerB, *hMatchedPerB, *hAllTracksPerB;
1161                  
1162   TString hName, hNameBase;
1163   hNameBase =( (TObjString*) triggersB->At(indTrigger) )->GetString();
1164                 
1165   hName = "hTrackerPer";
1166   hName += hNameBase;
1167   hTrackerPerB = static_cast<TH1*>(hTrackerB[indTrigger]->Clone(hName));
1168   hTrackerPerB->Divide(hB[indTrigger]);
1169   hTrackerPerB->SetLineWidth(2);
1170   hTrackerPerB->SetLineColor(kRed);
1171          
1172   hName = "hTriggerPer";
1173   hName += hNameBase;
1174   hTriggerPerB = static_cast<TH1*>(hTriggerB[indTrigger]->Clone(hName));
1175   hTriggerPerB->Divide(hB[indTrigger]);
1176   hTriggerPerB->SetLineWidth(2);
1177   hTriggerPerB->SetLineColor(kBlue);
1178          
1179   hName = "hMatchedPer";
1180   hName += hNameBase;
1181   hMatchedPerB = static_cast<TH1*>(hMatchedB[indTrigger]->Clone(hName));
1182   hMatchedPerB->Divide(hB[indTrigger]);
1183   hMatchedPerB->SetLineWidth(2);
1184   hMatchedPerB->SetLineColor(kViolet);
1185          
1186   hName = "hAllTracksPer";
1187   hName += hNameBase;
1188   hAllTracksPerB = static_cast<TH1*>(hAllTracksB[indTrigger]->Clone(hName));
1189   hAllTracksPerB->Divide(hB[indTrigger]);
1190   hAllTracksPerB->SetLineWidth(3);
1191   hAllTracksPerB->SetLineColor(kBlack);
1192   hAllTracksPerB->SetTitle(Form("Ratio (Number of Tracks)/%s",hNameBase.Data()));
1193   hAllTracksPerB->SetMinimum(0.0001);
1194   hAllTracksPerB->SetLabelSize(0.02);
1195         
1196
1197   TString cName = "c";
1198   cName += canvasName;
1199   hNameBase =( (TObjString*) triggersB->At(indTrigger) )->GetString();
1200   cName += hNameBase;   
1201   canvasName += indTrigger;
1202   TCanvas *cRatioTrackTypesB = new TCanvas(canvasName,cName,1200,900);
1203   SetCanvas(cRatioTrackTypesB,0);
1204   cRatioTrackTypesB->cd();
1205         
1206   TLegend* legcTTCINT1B; 
1207                  
1208   hAllTracksPerB->Draw("E");
1209   hTrackerPerB->Draw("Esame");
1210   hMatchedPerB->Draw("Esame");
1211   hTriggerPerB->Draw("Esame");
1212          
1213   legcTTCINT1B = new TLegend(0.70,0.5,0.90,0.70);
1214   legcTTCINT1B->AddEntry(hAllTracksPerB,"All tracks","l");
1215   legcTTCINT1B->AddEntry(hTrackerPerB,"Tracking (only) tracks","l");
1216   legcTTCINT1B->AddEntry(hMatchedPerB,"Matched tracks","l");
1217   legcTTCINT1B->AddEntry(hTriggerPerB,"Trigger (only) tracks","l");
1218   legcTTCINT1B->Draw("same");
1219
1220
1221         
1222   return cRatioTrackTypesB;
1223         
1224 }
1225
1226
1227 TCanvas *ProcessCanvasTrackMultB(TObjArray *triggersB, TH1 **hB, TH1 **hTrackerB, TH1 **hTriggerB, TH1 **hMatchedB, TH1 **hAllTracksB, Int_t indTrigger, TString canvasName){
1228         
1229   if(!triggersB || !hB || !hTrackerB || !hTriggerB || !hMatchedB || !hAllTracksB || indTrigger<0 ) return 0x0;
1230         
1231   TString cName = "c";
1232   cName += canvasName;
1233   TString hNameBase =( (TObjString*) triggersB->At(indTrigger) )->GetString();
1234   cName += hNameBase;   
1235   canvasName += indTrigger;
1236   TCanvas *cTrackMultB = new TCanvas(canvasName,cName,1200,900);
1237   SetCanvas(cTrackMultB,0);
1238
1239   cTrackMultB->Divide(1,2);
1240   cTrackMultB->cd(1);
1241         
1242         
1243   TH1* hSumTriggerOverB, *hSumTrackerOverB; 
1244
1245   TString hName; 
1246
1247   hName = Form("hSumTriggerOver%s",hNameBase.Data());
1248   hSumTriggerOverB = static_cast<TH1*>(hTriggerB[indTrigger]->Clone(hName));
1249   hSumTriggerOverB->Add(hMatchedB[indTrigger]);
1250   hSumTriggerOverB->Divide(hB[indTrigger]);
1251     
1252   hName = Form("Sum of trigger tracks (matched+trigger-only) / # events in %s",hNameBase.Data());
1253   hSumTriggerOverB->SetTitle(hName);
1254   hSumTriggerOverB->SetLabelSize(0.02);
1255   hSumTriggerOverB->SetLineWidth(2);
1256   hSumTriggerOverB->SetLineColor(kBlue);
1257   hName = Form("hSumTrackerOver%s",hNameBase.Data());
1258   hSumTrackerOverB = static_cast<TH1*>(hTrackerB[indTrigger]->Clone(hName));
1259   hSumTrackerOverB->Add(hMatchedB[indTrigger]);
1260   hSumTrackerOverB->Divide(hB[indTrigger]);
1261   hName = Form("Sum of tracker tracks (matched+tracker-only) / # events in %s",hNameBase.Data());
1262   hSumTrackerOverB->SetTitle(hName);
1263   //hSumTrackerOverCINT1B->LabelsOption("u");
1264   hSumTrackerOverB->SetLabelSize(0.02);
1265   hSumTrackerOverB->SetLineWidth(2);
1266   hSumTrackerOverB->SetLineColor(kBlue);
1267                 
1268         
1269         
1270   hSumTriggerOverB->Draw("e");
1271   cTrackMultB->cd(2);
1272   hSumTrackerOverB->Draw("e");
1273         
1274   return cTrackMultB;
1275         
1276 }
1277
1278 TCanvas *ProcessCanvasRatioTrackB(TObjArray *triggersB, TH1 **hB, TH1 **hTrackerB, TH1 **hTriggerB, TH1 **hMatchedB, TH1 **hAllTracksB, Int_t indTrigger, TString canvasName){
1279         
1280   if(!triggersB || !hB || !hTrackerB || !hTriggerB || !hMatchedB || !hAllTracksB || indTrigger<0 ) return 0x0;
1281         
1282   TString cName = "c";
1283   cName += canvasName;
1284   TString hNameBase =( (TObjString*) triggersB->At(indTrigger) )->GetString();
1285   cName += hNameBase;   
1286   canvasName += indTrigger;
1287   TCanvas *cRatioTrackB = new TCanvas(canvasName,cName,1200,900);
1288   SetCanvas(cRatioTrackB,0);
1289         
1290   TH1* hTrackerOverTriggerB, *hMatchedOverTriggerB, *hMatchedOverTrackerB;      
1291   
1292   TString hName = Form("hTrackerOverTrigger%s",hNameBase.Data());
1293   hTrackerOverTriggerB = static_cast<TH1*>(hTrackerB[indTrigger]->Clone(hName));
1294   hTrackerOverTriggerB->Divide(hTriggerB[indTrigger]);
1295   hName = Form("# tracker tracks / # trigger tracks in %s",hNameBase.Data());
1296   hTrackerOverTriggerB->SetTitle(hName);
1297   //hTrackerOverTriggerCINT1B->LabelsOption("u");
1298   hTrackerOverTriggerB->SetLabelSize(0.02);
1299   hTrackerOverTriggerB->SetLineWidth(2);
1300   hTrackerOverTriggerB->SetLineColor(kBlue);
1301     
1302   hName = Form("hMatchedOverTrigger%s",hNameBase.Data());       
1303   hMatchedOverTriggerB = static_cast<TH1*>(hMatchedB[indTrigger]->Clone(hName));
1304   hMatchedOverTriggerB->Divide(hTriggerB[indTrigger]);
1305    
1306   hName = Form("# matched tracks / # trigger tracks in %s",hNameBase.Data());
1307   hMatchedOverTriggerB->SetTitle(hName);
1308   //hMatchedOverTriggerCINT1B->LabelsOption("u");
1309   hMatchedOverTriggerB->SetLabelSize(0.02);
1310   hMatchedOverTriggerB->SetLineWidth(2);
1311   hMatchedOverTriggerB->SetLineColor(kBlue);
1312     
1313   hName = Form("hMatchedOverTracker%s",hNameBase.Data());
1314   hMatchedOverTrackerB = static_cast<TH1*>(hMatchedB[indTrigger]->Clone(hName));
1315   hMatchedOverTrackerB->Divide(hTrackerB[indTrigger]);
1316   hName = Form("# matched tracks / # tracker tracks in %s",hNameBase.Data());
1317   hMatchedOverTrackerB->SetTitle(hName);
1318   //hMatchedOverTrackerCINT1B->LabelsOption("u");
1319   hMatchedOverTrackerB->SetLabelSize(0.02);
1320   hMatchedOverTrackerB->SetLineWidth(2);
1321   hMatchedOverTrackerB->SetLineColor(kBlue);
1322   
1323         
1324   cRatioTrackB->Divide(1,3);
1325   cRatioTrackB->cd(1);
1326   hTrackerOverTriggerB->Draw("e");      
1327   cRatioTrackB->cd(2);
1328   hMatchedOverTriggerB->Draw("e");      
1329   cRatioTrackB->cd(3);
1330   hMatchedOverTrackerB->Draw("e");      
1331     
1332   return cRatioTrackB;
1333         
1334 }
1335
1336 TCanvas *ProcessCanvasAsymMatched(TObjArray *triggersB, TH1 **hPosMatchedB, TH1 **hNegMatchedB, TH1 **hAllMatchedB, Int_t indTrigger, TString canvasName){
1337         
1338   if(!triggersB || !hPosMatchedB || !hNegMatchedB || !hAllMatchedB || indTrigger<0 ) return 0x0;
1339
1340   TString hName, hNameBase = (( (TObjString*) triggersB->At(indTrigger) )->GetString());
1341         
1342   TString cName =       "c";    
1343   cName += canvasName;
1344   cName += hNameBase;   
1345   canvasName += indTrigger;
1346   TCanvas *cAsymMatched = new TCanvas(canvasName.Data(),cName,1200,900);
1347   SetCanvas(cAsymMatched,0);
1348   cAsymMatched->cd();
1349         
1350         
1351   TH1 *hDiffMatchedCMUS1B= static_cast<TH1*>(hPosMatchedB[indTrigger]->Clone("hDiffMatchedCMUS1B"));
1352   hDiffMatchedCMUS1B->Add(hNegMatchedB[indTrigger],-1);
1353   hDiffMatchedCMUS1B->Sumw2();
1354          
1355   TH1 *hAsymMatchedCMUS1B= static_cast<TH1*>(hDiffMatchedCMUS1B->Clone("hAsymMatchedCMUS1B"));
1356   hAsymMatchedCMUS1B->Divide(hAllMatchedB[indTrigger]);
1357   hAsymMatchedCMUS1B->SetLineColor(kRed);
1358   hAsymMatchedCMUS1B->SetLineWidth(2);
1359   hAsymMatchedCMUS1B->SetMinimum(-0.3);
1360   hAsymMatchedCMUS1B->SetMaximum(0.3);
1361   hAsymMatchedCMUS1B->SetLabelSize(0.02);
1362   hName = Form("Matched tracks asymmetry for %s with acc. cuts",hNameBase.Data());
1363   hAsymMatchedCMUS1B->SetTitle(hName);
1364          
1365   hAsymMatchedCMUS1B->GetYaxis()->SetTitle("Charged tracks asymmetry");  
1366   hAsymMatchedCMUS1B->Draw("EH");
1367         
1368   return cAsymMatched;
1369         
1370 }
1371
1372 TCanvas *ProcessCanvasHighPtMuons(TObjArray *triggersB, TH1 **hB, TH1 **hMatchedLowPtB, TH1 **hMatchedHighPtB, Int_t indTrigger, TString canvasName){
1373         
1374   if(!triggersB || !hB || !hMatchedLowPtB || !hMatchedHighPtB || indTrigger<0 ) return 0x0;
1375         
1376   TString hName, hNameBase = (( (TObjString*) triggersB->At(indTrigger) )->GetString());
1377         
1378   TString cName =       "c";    
1379   cName += canvasName;
1380   cName += hNameBase;   
1381   canvasName += indTrigger;
1382   TCanvas *cHighPtMuons = new TCanvas(canvasName.Data(),cName,1200,900);
1383   SetCanvas(cHighPtMuons,0);
1384   cHighPtMuons->cd();
1385         
1386   TLegend* legcHPM;
1387         
1388   TH1* hMatchedLowPtPerB, *hMatchedHighPtPerB;
1389   hName = Form("hMatchedLowPtPer%s ",hNameBase.Data());
1390   hMatchedLowPtPerB = static_cast<TH1*> (hMatchedLowPtB[indTrigger]->Clone(hName));
1391   hMatchedLowPtPerB->Sumw2();
1392   hMatchedLowPtPerB->Divide(hB[indTrigger]);
1393   hMatchedLowPtPerB->SetLineWidth(2);
1394   hMatchedLowPtPerB->SetLineColor(kBlue);
1395   hMatchedLowPtPerB->SetTitle("");
1396   hName = Form("Ratio per %s ",hNameBase.Data());
1397   hMatchedLowPtPerB->GetYaxis()->SetTitle(hName);
1398   //hMatchedLowPtPerB->SetMaximum(0.15);
1399   hMatchedLowPtPerB->SetMinimum(0.0001);
1400   hMatchedLowPtPerB->SetLabelSize(0.02);
1401          
1402   hName = Form("hMatchedHighPtPer%s ",hNameBase.Data());
1403   hMatchedHighPtPerB = static_cast<TH1*> (hMatchedHighPtB[indTrigger]->Clone(hName));
1404   hMatchedHighPtPerB->Sumw2();
1405   hMatchedHighPtPerB->Divide(hB[indTrigger]);
1406   hMatchedHighPtPerB->SetLineWidth(2);
1407   hMatchedHighPtPerB->SetLineColor(kRed);
1408                  
1409   hMatchedLowPtPerB->Draw("E");
1410   hMatchedHighPtPerB->Draw("Esame");
1411          
1412   legcHPM = new TLegend(0.60,0.45,0.98,0.65);
1413   hName = Form("Number of matched track per %s (include Vtx and R_{Abs} cuts)",hNameBase.Data());
1414   legcHPM->SetHeader(hName);
1415   legcHPM->AddEntry(".","Physics selection applied :","");      
1416   legcHPM->AddEntry(hMatchedLowPtPerB," p_{T} > 1 GeV/c ","l");
1417   legcHPM->AddEntry(hMatchedHighPtPerB," p_{T} >  2 GeV/c ","l");
1418   legcHPM->Draw("same");
1419         
1420   return cHighPtMuons;
1421         
1422         
1423 }
1424
1425 TH1* ProcessHisto( AliCounterCollection* counter, TString hVariable, TString hSelection, TString hName, TString xName, TString yName, Int_t color){
1426   
1427   
1428   TH1* h1 = 0x0;
1429   if( !counter ) return h1;
1430   
1431   h1 = (TH1*) counter->Draw(hVariable,hSelection);
1432   if ( !h1 ) h1 = new TH1D(hName,"",10,0,10);
1433   else {
1434     h1->Sumw2();
1435     h1->LabelsOption("a");
1436     if(hName.Sizeof()>1) h1->SetName(hName);
1437     if(xName.Sizeof()>1) h1->GetXaxis()->SetTitle(xName);
1438     if(yName.Sizeof()>1) h1->GetYaxis()->SetTitle(yName);
1439     if(color>0) h1->SetLineColor(color);
1440     
1441   }
1442   
1443   return h1;
1444 }
1445
1446 TH2* ProcessHisto2D( AliCounterCollection* counter, TString hVariable, TString hVariable2, TString hSelection, TString hName){
1447         
1448   
1449   TH2* h1 = 0x0;
1450   if( !counter ) return h1;
1451   Bool_t setName = kTRUE;
1452   
1453   if(hName.Sizeof()==1) setName = kFALSE;
1454   
1455   h1 = (TH2*) counter->Draw(hVariable,hVariable2,hSelection);
1456   if ( !h1 ) h1 = new TH2D(hName,"",10,0,10,10,0,10);
1457   else {
1458     h1->Sumw2();
1459     h1->LabelsOption("a");
1460     if(setName) h1->SetName(hName);
1461   }
1462   
1463   return h1;
1464 }
1465 Bool_t GetTriggerLists(const char* triggerList, TString listFromContainer, TObjArray *triggersB, TObjArray *triggersAC, TObjArray *triggersE){
1466         
1467   //Get the trigger list from a file
1468   //The file should consist of a line for each trigger with the following layout:
1469         //        triggernameB triggerNameAC triggerNameE
1470         //     or triggernameB triggerNameA,triggerNameC triggerNameE
1471         //     or triggernameB triggerNameACE notrigger
1472   //if filename is 0, then default trigger names (pp 2011) are used
1473         
1474   if( !triggersB || !triggersAC || !triggersE) return kFALSE;
1475   TObjArray* triggers[3] = {triggersB, triggersAC, triggersE};
1476   
1477   TString trigSuffix[3] = {"B", "AC", "E"};
1478   TString currTrigName = "";
1479   TObjArray* fullTriggerList[3];
1480         
1481   for ( Int_t ibeam=0; ibeam<3; ++ibeam ) {
1482     fullTriggerList[ibeam] = new TObjArray;
1483     fullTriggerList[ibeam]->SetOwner();
1484   }
1485   
1486   // Build trigger list (from file or default)
1487   if ( triggerList ) {
1488     // only the ones in the triggerList
1489     ifstream inFile(triggerList);
1490     if (!inFile.is_open()) {
1491       Error("PlotMUONQApp","unable to open file %s", triggerList);
1492       return kFALSE;
1493     }
1494     
1495     while ( !inFile.eof() ) {
1496       Bool_t isGoodB = kTRUE;
1497       for ( Int_t ibeam=0; ibeam<3; ++ibeam ) {
1498         currTrigName.ReadToken( inFile );
1499         if ( ! isGoodB ) continue;
1500         if ( currTrigName.IsNull() || ! currTrigName.IsAscii() ) {
1501           if ( ibeam == 0 ) {
1502             isGoodB = kFALSE;
1503             continue;
1504           }
1505           currTrigName = "notrigger";
1506         }
1507         fullTriggerList[ibeam]->AddLast(new TObjString(currTrigName));
1508       }
1509     }
1510     inFile.close();
1511   }
1512   else {
1513     TString baseTrigName[4] = {"CINT7", "CMUSH7", "CMUL7", "CMUU7"};
1514     for ( Int_t ibase=0; ibase<4; ++ibase ) {
1515       for ( Int_t ibeam=0; ibeam<3; ++ibeam ) {
1516         // by default all triggers from new period in LHC11c
1517         currTrigName = baseTrigName[ibase] + trigSuffix[ibeam];
1518         fullTriggerList[ibeam]->AddLast(new TObjString(currTrigName));
1519       }
1520     }
1521   }
1522   //
1523   // Select only existing triggers in container
1524   //
1525   TObjArray *triggersFromContainer = listFromContainer.Tokenize(",");
1526   TObjString* trigName = 0x0;
1527         
1528   TString selectAllTriggers[3] = {"", "", ""};
1529   for ( Int_t itrig=0; itrig<fullTriggerList[0]->GetEntries(); ++itrig ) {
1530     Bool_t isBadTrig = kFALSE;
1531     for ( Int_t ibeam=0; ibeam<3; ++ibeam ) {
1532       currTrigName = fullTriggerList[ibeam]->At(itrig)->GetName();
1533                         
1534       //condition on trigger name from trigger list
1535       if ( currTrigName.Contains("notrigger") ){
1536         isBadTrig = kTRUE;
1537         if ( ibeam == 0 ) break;
1538         currTrigName = " ";
1539       }
1540       //select only the existing triggers in the container 
1541       //note that the trigger in the trigger file can be a list of different trigger
1542       if ( triggersFromContainer ) {
1543         TIter nextTrigger( triggersFromContainer );
1544         isBadTrig = kTRUE;
1545         while ( ( trigName = static_cast<TObjString*>(nextTrigger()) ) ) {
1546           if ( currTrigName.Contains(trigName->GetString()) ){
1547             isBadTrig = kFALSE;
1548           }
1549         }
1550         if ( isBadTrig == kTRUE ){ 
1551           if ( ibeam == 0 ) break;
1552           currTrigName = " ";
1553         }
1554       }
1555       triggers[ibeam]->AddLast(new TObjString(currTrigName));
1556       if ( isBadTrig ) continue;
1557       if ( ! selectAllTriggers[ibeam].IsNull() ) selectAllTriggers[ibeam] += ",";
1558       selectAllTriggers[ibeam] += currTrigName;
1559     }
1560   }
1561   if(triggersFromContainer) delete triggersFromContainer;
1562   if(trigName) delete trigName;
1563         
1564         
1565   // Complete trigger list and print values
1566   cout<<" Nr of triggers read "<<triggers[0]->GetEntriesFast()<<endl;
1567   for ( Int_t ibeam=0; ibeam<3; ++ibeam ) {
1568     triggers[ibeam]->AddLast(new TObjString(selectAllTriggers[ibeam]));
1569     printf(" %s triggers:\n", trigSuffix[ibeam].Data());
1570     triggers[ibeam]->Print();
1571     delete fullTriggerList[ibeam];
1572   }
1573         
1574   return kTRUE;
1575 }
1576
1577 TString GetRunList(const char *runList, TObjArray *runs, TObjArray *runs2){
1578
1579   // list of runs to be analyzed
1580   TString selectRuns = "run:";
1581   
1582   if(runList) {
1583     // only the ones in the runList
1584     ifstream inFile(runList);
1585     if (!inFile.is_open()) {
1586       Error("PlotMUONQApp","unable to open file %s", runList);
1587       return selectRuns;
1588     }
1589     
1590     TString currRun;
1591     while (!inFile.eof()) {
1592       currRun.ReadLine(inFile, kTRUE);
1593       if (currRun.IsNull()) continue;
1594       if (!currRun.IsDigit()) {
1595         Error("PlotMUONQApp","invalid run number: %s", currRun.Data());
1596         return selectRuns;
1597       }
1598       if(runs) runs->AddLast(new TObjString(Form("%09d", currRun.Atoi())));
1599       if(runs2) runs2->AddLast(new TObjString(Form("%d", currRun.Atoi())));
1600       selectRuns += Form("%s,",currRun.Data());
1601     }
1602     selectRuns.Remove(TString::kTrailing, ',');
1603     inFile.close();
1604     
1605   } else {
1606     // all runs
1607     if(runs) runs->AddLast(new TObjString("*"));
1608     if(runs2) runs2->AddLast(new TObjString("*"));
1609   }
1610   
1611   return selectRuns;
1612 }