]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ESDCheck/AliTOFQATask.cxx
Added log outputs
[u/mrichter/AliRoot.git] / ESDCheck / AliTOFQATask.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 //_________________________________________________________________________
16 // An analysis task to check the TOF in simulated data
17 //
18 //*-- Silvia Arcelli
19 //-Distributions of the matching performance
20 //-TOF Time info and (TOF - expected time) plots
21 //-Summary Plots on TOF Pid
22 //////////////////////////////////////////////////////////////////////////////
23 #include <TChain.h>
24 #include <TFile.h> 
25 #include <TObject.h> 
26 #include <TCanvas.h>
27 #include <TStyle.h>
28 #include <TGaxis.h>
29 #include <TLatex.h>
30 #include <TPad.h>
31 #include <TSpectrum.h>
32 #include <TF1.h>
33 #include <TROOT.h>
34
35 #include "AliTOFQATask.h" 
36 #include "AliESD.h" 
37 #include "AliESDtrack.h" 
38 #include "AliLog.h"
39
40 //______________________________________________________________________________
41 AliTOFQATask::AliTOFQATask(const char *name) : 
42   AliAnalysisTask(name,""),  
43   fChain(0),
44   fESD(0), 
45   fOutputContainer(0), 
46   fhTOFMatch(0),
47   fhESDeffPhi(0),
48   fhESDeffTheta(0),
49   fhESDeffMom(0),
50   fhTOFeffPhi(0),
51   fhTOFeffTheta(0),
52   fhTOFeffMom(0),
53   fhTOFeffPhiMT(0),
54   fhTOFeffThetaMT(0),
55   fhTOFeffMomMT(0),
56   fhTOFsector(0),
57   fhTOFsectorMT(0),
58   fhTOFTime(0),
59   fhTOFDeltaTime(0),
60   fhTOFDeltaTimeMT(0),
61   fhTOFIDSpecies(0),
62   fhTOFMassVsMom(0),
63   fhTOFMass(0),
64   fmatchFracMin(0.15),
65   fmatchEffMin(0.28),
66   ftimePeakMax(0.05),
67   fmassPeakMax(0.05)
68 {
69   // Constructor.
70   // Input slot #0 works with an Ntuple
71   DefineInput(0, TChain::Class());
72   // Output slot #0 writes into a TH1 container
73   DefineOutput(0,  TObjArray::Class()) ; 
74 }
75
76 //______________________________________________________________________________
77 AliTOFQATask::AliTOFQATask(const AliTOFQATask &qatask) : 
78   AliAnalysisTask("AliTOFQATask",""),  
79   fChain(0),
80   fESD(0), 
81   fOutputContainer(0), 
82   fhTOFMatch(0),
83   fhESDeffPhi(0),
84   fhESDeffTheta(0),
85   fhESDeffMom(0),
86   fhTOFeffPhi(0),
87   fhTOFeffTheta(0),
88   fhTOFeffMom(0),
89   fhTOFeffPhiMT(0),
90   fhTOFeffThetaMT(0),
91   fhTOFeffMomMT(0),
92   fhTOFsector(0),
93   fhTOFsectorMT(0),
94   fhTOFTime(0),
95   fhTOFDeltaTime(0),
96   fhTOFDeltaTimeMT(0),
97   fhTOFIDSpecies(0),
98   fhTOFMassVsMom(0),
99   fhTOFMass(0),
100   fmatchFracMin(0.15),
101   fmatchEffMin(0.28),
102   ftimePeakMax(0.05),
103   fmassPeakMax(0.05)
104 {
105   // Copy Constructor.
106   fChain=qatask.fChain;
107   fESD=qatask.fESD; 
108   fOutputContainer=qatask.fOutputContainer; 
109   fhTOFMatch=qatask.fhTOFMatch;
110   fhESDeffPhi=qatask.fhESDeffPhi;
111   fhESDeffTheta=qatask.fhESDeffTheta;
112   fhESDeffMom=qatask.fhESDeffMom;
113   fhTOFeffPhi=qatask.fhTOFeffPhi;
114   fhTOFeffTheta=qatask.fhTOFeffTheta;
115   fhTOFeffMom=qatask.fhTOFeffMom;
116   fhTOFeffPhiMT=qatask.fhTOFeffPhiMT;
117   fhTOFeffThetaMT=qatask.fhTOFeffThetaMT;
118   fhTOFeffMomMT=qatask.fhTOFeffMomMT;
119   fhTOFsector=qatask.fhTOFsector;
120   fhTOFsectorMT=qatask.fhTOFsectorMT;
121   fhTOFTime=qatask.fhTOFTime;
122   fhTOFDeltaTime=qatask.fhTOFDeltaTime;
123   fhTOFDeltaTimeMT=qatask.fhTOFDeltaTimeMT;
124   fhTOFIDSpecies=qatask.fhTOFIDSpecies;
125   fhTOFMassVsMom=qatask.fhTOFMassVsMom;
126   fhTOFMass=qatask.fhTOFMass;
127   fmatchFracMin=qatask.fmatchFracMin;
128   fmatchEffMin=qatask.fmatchEffMin;
129   ftimePeakMax=qatask.ftimePeakMax;
130   fmassPeakMax=qatask.fmassPeakMax;
131 }
132 //______________________________________________________________________________
133 AliTOFQATask:: ~AliTOFQATask() 
134 {
135   delete fOutputContainer;
136   delete fhTOFMatch;
137   delete fhESDeffPhi;
138   delete fhESDeffTheta;
139   delete fhESDeffMom;
140   delete fhTOFeffPhi;
141   delete fhTOFeffTheta;
142   delete fhTOFeffMom;
143   delete fhTOFeffPhiMT;
144   delete fhTOFeffThetaMT;
145   delete fhTOFeffMomMT;
146   delete fhTOFsector;
147   delete fhTOFsectorMT;
148   delete fhTOFTime;
149   delete fhTOFDeltaTime;
150   delete fhTOFDeltaTimeMT;
151   delete fhTOFIDSpecies;
152   delete fhTOFMassVsMom;
153   delete fhTOFMass;
154   }
155 //______________________________________________________________________________
156 AliTOFQATask& AliTOFQATask::operator=(const AliTOFQATask &qatask)  
157
158    //assignment operator
159   this->fChain=qatask.fChain;
160   this->fESD=qatask.fESD; 
161   this->fOutputContainer=qatask.fOutputContainer; 
162   this->fhTOFMatch=qatask.fhTOFMatch;
163   this->fhESDeffPhi=qatask.fhESDeffPhi;
164   this->fhESDeffTheta=qatask.fhESDeffTheta;
165   this->fhESDeffMom=qatask.fhESDeffMom;
166   this->fhTOFeffPhi=qatask.fhTOFeffPhi;
167   this->fhTOFeffTheta=qatask.fhTOFeffTheta;
168   this->fhTOFeffMom=qatask.fhTOFeffMom;
169   this->fhTOFeffPhiMT=qatask.fhTOFeffPhiMT;
170   this->fhTOFeffThetaMT=qatask.fhTOFeffThetaMT;
171   this->fhTOFeffMomMT=qatask.fhTOFeffMomMT;
172   this->fhTOFsector=qatask.fhTOFsector;
173   this->fhTOFsectorMT=qatask.fhTOFsectorMT;
174   this->fhTOFTime=qatask.fhTOFTime;
175   this->fhTOFDeltaTime=qatask.fhTOFDeltaTime;
176   this->fhTOFDeltaTimeMT=qatask.fhTOFDeltaTimeMT;
177   this->fhTOFIDSpecies=qatask.fhTOFIDSpecies;
178   this->fhTOFMassVsMom=qatask.fhTOFMassVsMom;
179   this->fhTOFMass=qatask.fhTOFMass;
180   this->fmatchFracMin=qatask.fmatchFracMin;
181   this->fmatchEffMin=qatask.fmatchEffMin;
182   this->ftimePeakMax=qatask.ftimePeakMax;
183   this->fmassPeakMax=qatask.fmassPeakMax;
184   return *this;
185 }
186 //______________________________________________________________________________
187 void AliTOFQATask::ConnectInputData(const Option_t*)
188 {
189   // Initialisation of branch container and histograms 
190     
191   AliInfo(Form("*** Initialization of %s", GetName())) ; 
192   
193   // Get input data
194   fChain = dynamic_cast<TChain *>(GetInputData(0)) ;
195   if (!fChain) {
196     AliError(Form("Input 0 for %s not found\n", GetName()));
197     return ;
198   }
199   
200   // One should first check if the branch address was taken by some other task
201   char ** address = (char **)GetBranchAddress(0, "ESD") ;
202   if (address) 
203     fESD = (AliESD *)(*address) ; 
204   else {
205     fESD = new AliESD() ; 
206     SetBranchAddress(0, "ESD", &fESD) ;  
207   }
208 }
209
210 //______________________________________________________________________________
211 void AliTOFQATask::Exec(Option_t *) 
212 {
213
214 //******* The loop over events --------------------------------------------------
215
216   Int_t nselESD=0;
217   Int_t nmatchTOF=0;
218   Int_t npidok=0;
219   Int_t pisel=0,kasel=0,prsel=0,elsel=0,musel=0;
220   //Set equal a-priori weights (just charged hadrions)
221   const Int_t nCalinSec=8736;
222   Double_t c[5]={0, 0, 1, 1, 1};
223   // Processing of one event
224   Long64_t entry = fChain->GetReadEntry() ;  
225   if (!fESD) {
226     AliError("fESD is not connected to the input!") ; 
227     return ; 
228   }
229   
230   if ( !((entry-1)%100) ) 
231     AliInfo(Form("%s ----> Processing event # %lld",  (dynamic_cast<TChain *>(fChain))->GetFile()->GetName(), entry)) ; 
232   
233   // ************************  TOF *************************************
234
235
236   Int_t ntrk = fESD->GetNumberOfTracks() ;
237
238   while ( ntrk-- ) {
239     
240     AliESDtrack * t = fESD->GetTrack(ntrk) ;
241     if ( (t->GetStatus() & AliESDtrack::kTIME)==0 )continue;    
242
243     nselESD++;
244
245     Double_t mom   = t->GetP() ; 
246     Double_t phi   = TMath::ATan2(t->GetX(),t->GetY()) ; 
247     Double_t theta = TMath::ACos(t->GetZ()/
248     TMath::Sqrt(t->GetX()*t->GetX()+t->GetY()*t->GetY()+t->GetZ()*t->GetZ())); 
249     phi*=180/TMath::Pi();
250     theta*=180/TMath::Pi();
251
252     fhESDeffPhi->Fill(phi);
253     fhESDeffTheta->Fill(theta);
254     fhESDeffMom->Fill(mom);
255
256
257     if(t->GetTOFsignal()<0)continue;
258
259     nmatchTOF++;
260
261     Double_t time=t->GetTOFsignal();//TOF time in ps    
262     Int_t detid=t->GetTOFCalChannel();//which pad was hit
263     Int_t sector = detid/nCalinSec;
264     fhTOFTime->Fill(time*1.E-3);
265     fhTOFeffPhi->Fill(phi);
266     fhTOFeffTheta->Fill(theta);
267     fhTOFeffMom->Fill(mom);
268     fhTOFsector->Fill(sector);
269     //Well matched
270
271     Int_t label=TMath::Abs(t->GetLabel());
272     Int_t clab[3]; t->GetTOFLabel(clab);    
273     if(label==clab[0] || label==clab[1] || label==clab[2]) {
274       fhTOFeffPhiMT->Fill(phi);
275       fhTOFeffThetaMT->Fill(theta);
276       fhTOFeffMomMT->Fill(mom);
277       fhTOFsectorMT->Fill(sector);
278     }           
279
280     //Look at TOF PID 
281
282     UInt_t status=AliESDtrack::kESDpid;status|=AliESDtrack::kTOFpid; 
283     if (!((t->GetStatus()&status) == status))continue;
284     npidok++;
285     Double_t times[10];
286     t->GetIntegratedTimes(times);//ps
287     Double_t l   =t->GetIntegratedLength()/100.; // (m)
288     Double_t mass= -1.;
289     Double_t invBetaGamma= (0.299*time*1.E-3/l)*(0.299*time*1.E-3/l) -1.;
290     if(invBetaGamma<0){mass = -mom*TMath::Sqrt(-invBetaGamma);}
291     else{mass = mom*TMath::Sqrt(invBetaGamma);}
292
293     //The Mass/ vs Momentum Plot:
294     fhTOFMassVsMom->Fill(mass,mom);
295     fhTOFMass->Fill(mass);
296     
297     //PID weights 
298     Double_t r[10]; t->GetTOFpid(r);
299     Double_t rcc=0.;
300     Int_t i;
301     for (i=0; i<AliPID::kSPECIES; i++) rcc+=(c[i]*r[i]);
302     if (rcc==0.) continue;
303     Double_t w[10];
304     for (i=0; i<AliPID::kSPECIES; i++) w[i]=c[i]*r[i]/rcc;
305     
306     fhTOFDeltaTime->Fill((time-times[2])*1.E-3);
307
308     if(label==clab[0] || label==clab[1] || label==clab[2]) {
309       fhTOFDeltaTimeMT->Fill((time-times[2])*1.E-3);
310     }           
311     
312     if (w[4]>w[0] && w[4]>w[1] && w[4]>w[2] && w[4]>w[3]){
313       prsel++;
314       fhTOFIDSpecies->Fill(4);
315     }
316     if (w[3]>w[0] && w[3]>w[1] && w[3]>w[2] && w[3]>w[4]){
317       kasel++;
318       fhTOFIDSpecies->Fill(3);
319     }
320     if (w[2]>w[0] && w[2]>w[1] && w[2]>w[3] && w[2]>w[4]){
321       pisel++;
322       fhTOFIDSpecies->Fill(2);
323     }
324     if (w[1]>w[0] && w[1]>w[2] && w[1]>w[3] && w[1]>w[4]){
325       musel++;
326       fhTOFIDSpecies->Fill(1);
327     }
328     if (w[0]>w[1] && w[0]>w[2] && w[0]>w[3] && w[0]>w[4]){
329       elsel++;   
330       fhTOFIDSpecies->Fill(0);
331     }
332   }
333
334   Float_t fracM= -1;
335   if(nselESD>10)fracM=((Float_t) nmatchTOF)/((Float_t) nselESD);
336   fhTOFMatch->Fill(fracM);
337
338   PostData(0, fOutputContainer);  
339
340 }
341 //______________________________________________________________________________
342 void AliTOFQATask::CreateOutputObjects()
343 {  
344   // Construct histograms:
345   
346   fhTOFMatch= 
347     new TH1F("hTOFMatch","Fraction of Matched TOF tracks",101,-0.005,1.005);
348   fhESDeffPhi= 
349     new TH1F("hESDeffPhi","ESD tracks Phi(vtx)",    180, -180., 180.) ;
350   fhESDeffTheta= 
351     new TH1F("hESDeffTheta","ESD tracks Theta (vtx)",90, 45., 135.) ;
352   fhESDeffMom= 
353     new TH1F("hESDeffMom","ESD tracks Momentum (vtx)",40, 0., 6.) ;
354   fhTOFeffPhi = 
355     new TH1F("hTOFeffPhi","TOF, Matched vs Phi(vtx)", 180,-180, 180.);
356   fhTOFeffPhiMT= 
357     new TH1F("hTOFeffPhiMT","TOF, Well Matched vs Phi(vtx)",180,-180,180.);
358   fhTOFeffTheta= 
359     new TH1F("hTOFeffTheta","TOF, Matched vs Theta(vtx)",90,45.,135.);  
360   fhTOFeffThetaMT= 
361     new TH1F("hTOFeffThetaMT","TOF, Well Matched vs Theta(vtx)",90,45.,135.);
362   fhTOFeffMom = 
363     new TH1F("hTOFeffMom","TOF, Matched vs Momentum ", 40, 0.,6.);
364   fhTOFeffMomMT = 
365     new TH1F("hTOFeffMomMT","TOF, Well Matched vs Momentum ", 40, 0.,6.); 
366   fhTOFsector = 
367     new TH1F("hTOFsector","TOF, Matched vs Sector ", 18,0.,18.); 
368   fhTOFsectorMT = 
369     new TH1F("hTOFsectorMT","TOF, Well Matched vs Sector", 18, 0.,18.); 
370
371   fhESDeffMom->Sumw2(); fhTOFeffMom->Sumw2();  fhTOFeffMomMT->Sumw2();
372   fhESDeffTheta->Sumw2();  fhTOFeffTheta->Sumw2();  fhTOFeffThetaMT->Sumw2();
373   fhESDeffPhi->Sumw2();  fhTOFeffPhi->Sumw2();  fhTOFeffPhiMT->Sumw2();
374   fhTOFsector->Sumw2(); fhTOFsectorMT->Sumw2();
375
376   fhTOFTime = 
377     new TH1F("hTOFTime","TOF, t(TOF)in ns ",1000,0,100.); 
378   fhTOFDeltaTime = 
379     new TH1F("hTOFDeltaTime","TOF,t(TOF)-t(exp,pion), ns ",1000,-4.4,20.);   
380   fhTOFDeltaTimeMT = 
381     new TH1F("hTOFDeltaTimeMT","TOF, t(TOF)-t(exp,pion) for Well Matched, ns ",1000,-4.4,20.); 
382   fhTOFIDSpecies = 
383     new TH1F("hTOFIDSpecies","TOF, ID Sample Composition ",5,-0.5,4.5);
384   fhTOFMassVsMom = 
385     new TH2F("hTOFMassVsMom","TOF, Mass Vs Momentum ",280,-0.2,1.2,600,0.,6.);
386   fhTOFMass = 
387     new TH1F("hTOFMass","TOF, reconstructed mass ",280,-0.2,1.2);
388
389   
390   // create the output container
391   
392   fOutputContainer = new TObjArray(18) ; 
393   fOutputContainer->SetName(GetName()) ; 
394
395   fOutputContainer->AddAt(fhTOFMatch,             0) ; 
396   fOutputContainer->AddAt(fhESDeffPhi,            1) ; 
397   fOutputContainer->AddAt(fhESDeffTheta,          2) ; 
398   fOutputContainer->AddAt(fhESDeffMom,            3) ; 
399   fOutputContainer->AddAt(fhTOFeffPhi,            4) ; 
400   fOutputContainer->AddAt(fhTOFeffPhiMT,          5) ; 
401   fOutputContainer->AddAt(fhTOFeffTheta,          6) ; 
402   fOutputContainer->AddAt(fhTOFeffThetaMT,        7) ; 
403   fOutputContainer->AddAt(fhTOFeffMom,            8) ; 
404   fOutputContainer->AddAt(fhTOFeffMomMT,          9) ; 
405   fOutputContainer->AddAt(fhTOFsector,           10) ; 
406   fOutputContainer->AddAt(fhTOFsectorMT,         11) ; 
407   fOutputContainer->AddAt(fhTOFTime,             12) ; 
408   fOutputContainer->AddAt(fhTOFDeltaTime ,       13) ; 
409   fOutputContainer->AddAt(fhTOFDeltaTimeMT,      14) ; 
410   fOutputContainer->AddAt(fhTOFIDSpecies,        15) ; 
411   fOutputContainer->AddAt(fhTOFMassVsMom,        16) ; 
412   fOutputContainer->AddAt(fhTOFMass,             17) ; 
413   
414 }
415 //______________________________________________________________________________
416 void AliTOFQATask::GetEfficiency() 
417 {
418   // calculates the efficiency
419   
420   
421   fhTOFeffPhiMT->Divide(fhTOFeffPhiMT,fhTOFeffPhi,1,1,"B");
422   fhTOFeffThetaMT->Divide(fhTOFeffThetaMT,fhTOFeffTheta,1,1,"B");
423   fhTOFeffMomMT->Divide(fhTOFeffMomMT,fhTOFeffMom,1,1,"B");
424
425   fhTOFeffPhi->Divide(fhTOFeffPhi,fhESDeffPhi,1,1,"B");
426   fhTOFeffTheta->Divide(fhTOFeffTheta,fhESDeffTheta,1,1,"B");
427   fhTOFeffMom->Divide(fhTOFeffMom,fhESDeffMom,1,1,"B");
428   
429 }
430
431 //______________________________________________________________________________
432 Bool_t AliTOFQATask::DrawHistos() 
433 {
434
435
436   Int_t TOFsectors[18]={0,1,1,0,0,0,1,1,0,1,1,1,1,0,0,1,1,1};//TOF sectors which are supposed to be present
437   const char* part[3]={"pions","kaons","protons"};// pi,ka,pr
438   const Float_t masses[3]={0.1396,0.494,0.938};// particle masses pi,ka,pr
439   // Makes a few plots
440
441   gROOT->SetStyle("Plain");
442   gStyle->SetPalette(1);
443   gStyle->SetOptStat(111110);
444   gStyle->SetPalette(1);
445   gStyle->SetCanvasColor(0);
446   gStyle->SetFrameFillColor(0);
447   //
448   TGaxis::SetMaxDigits(3);  
449   gStyle->SetLabelFont(52, "XYZ");
450   gStyle->SetTitleFont(62, "XYZ");
451   gStyle->SetPadRightMargin(0.02);
452
453   
454   TCanvas * cTOFeff = new TCanvas("cTOFeff", "TOF ESD General", 400, 30, 550, 630) ;
455
456   cTOFeff->Divide(1,2) ;
457   cTOFeff->cd(1);
458   fhTOFMatch->GetXaxis()->SetTitle("Fraction of matched ESD tracks/event");
459   fhTOFMatch->GetYaxis()->SetTitle("Events");
460   fhTOFMatch->SetFillColor(4);
461   fhTOFMatch->Draw();  
462   cTOFeff->cd(2);
463   TPad *b = (TPad*)gPad;
464   b->Divide(2,1);
465   b->cd(1) ;
466   fhTOFsector->GetXaxis()->SetTitle("Sector index of matched TOF Cluster");
467   fhTOFsector->GetYaxis()->SetTitle("Entries");
468   fhTOFsector->SetFillColor(4);
469   fhTOFsector->SetMinimum(0.);
470   fhTOFsector->GetYaxis()->SetNdivisions(205);
471   fhTOFsector->GetYaxis()->SetTitleOffset(1.2);
472   fhTOFsector->Draw("histo");
473   b->cd(2) ;
474   fhTOFeffMom->SetMaximum(1.2);
475   fhTOFeffMom->GetXaxis()->SetTitle("Track momentum (GeV/c)");
476   fhTOFeffMom->GetYaxis()->SetNdivisions(205);
477   fhTOFeffMom->GetYaxis()->SetTitleOffset(1.2);
478   fhTOFeffMom->GetYaxis()->SetTitle("Fraction of matched ESD tracks");
479   fhTOFeffMom->SetFillColor(4);
480   fhTOFeffMom->Draw();
481   fhTOFeffMom->Fit("pol0","Q","",0.5,3.);
482   TF1 *fitMom = fhTOFeffMom->GetFunction("pol0");
483   fhTOFeffMom->Draw("histo,same");
484   
485   cTOFeff->Print("TOF_eff.eps");
486
487
488
489   TCanvas * cTOFtime = new TCanvas("cTOFtime", "TOF measured Times ", 400, 30, 550, 630) ;  
490   cTOFtime->Divide(1,2) ;
491   cTOFtime->cd(1);
492   if ( fhTOFTime->GetMaximum() > 0 ) 
493     cTOFtime->GetPad(1)->SetLogy(1);
494   fhTOFTime->GetXaxis()->SetTitle("TOF time (ns)");
495   fhTOFTime->GetYaxis()->SetTitle("Entries");
496   fhTOFTime->SetFillColor(4);
497   fhTOFTime->Draw();
498   cTOFtime->cd(2);
499   if ( fhTOFDeltaTime->GetMaximum() > 0 ) 
500     cTOFtime->GetPad(2)->SetLogy(1);
501   fhTOFDeltaTime->GetXaxis()->SetTitle("t^{TOF}-t^{exp}_{#pi} (ns)");
502   fhTOFDeltaTime->GetYaxis()->SetTitle("Entries");
503   fhTOFDeltaTime->SetFillColor(4);
504   Int_t ntimepeak=1;
505   TSpectrum *timeDiff = new TSpectrum(2*ntimepeak);
506   Int_t ntime = timeDiff->Search(fhTOFDeltaTime,ntimepeak," ",0.1);
507   fhTOFDeltaTime->Draw();
508
509   cTOFtime->Print("TOF_time.eps");
510
511
512   TCanvas * cTOFpid = new TCanvas("cTOFpid", "TOF PID ", 400, 30, 550, 630) ;  
513   cTOFpid->Divide(1,3) ;
514   cTOFpid->cd(1);
515   if ( fhTOFMass->GetMaximum() > 0 ) 
516     cTOFpid->SetLogy(1);
517   fhTOFMass->GetXaxis()->SetTitle("Reconstructed Mass (GeV/c^{2})");
518   fhTOFMass->GetYaxis()->SetTitle("Entries");
519   fhTOFMass->SetFillColor(4);
520   Int_t npmass=1;
521   if(fhTOFMass->GetEntries()>1000)npmass=3;
522   TSpectrum *mass = new TSpectrum(2*npmass);
523   Int_t nmass = mass->Search(fhTOFMass,npmass," ",0.02);
524   fhTOFMass->Draw();
525   if ( fhTOFMassVsMom->GetMaximum() > 0 ) 
526     cTOFpid->SetLogy(0);
527   cTOFpid->cd(2);
528   fhTOFMassVsMom->GetYaxis()->SetRange(0,400);
529   fhTOFMassVsMom->GetXaxis()->SetTitle("Reconstructed Mass (GeV/c^{2})");
530   fhTOFMassVsMom->GetYaxis()->SetTitle("Track Momentum (GeV/c)");
531   fhTOFMassVsMom->GetXaxis()->SetTitleSize(0.05);
532   fhTOFMassVsMom->GetYaxis()->SetTitleSize(0.05);
533   fhTOFMassVsMom->SetMarkerStyle(20);
534   fhTOFMassVsMom->SetMarkerSize(0.05);
535   fhTOFMassVsMom->SetMarkerColor(2);
536   fhTOFMassVsMom->Draw();
537   cTOFpid->cd(3);
538
539   TLatex *   tex = new TLatex(1., 1.25, "Bayesian PID: a-priori concentrations: [0,0,1,1,1]");
540   tex->SetTextColor(1);
541   tex->SetTextSize(0.045);
542   tex->SetLineWidth(2);
543
544   Float_t norm=1./fhTOFIDSpecies->GetEntries();
545   fhTOFIDSpecies->Scale(norm);
546   fhTOFIDSpecies->SetMaximum(1.2);
547   fhTOFIDSpecies->GetXaxis()->SetTitle("Particle Type");
548   fhTOFIDSpecies->GetYaxis()->SetTitle("ID Fractions");
549   fhTOFIDSpecies->GetXaxis()->SetTitleSize(0.05);
550   fhTOFIDSpecies->GetYaxis()->SetTitleSize(0.05);
551   fhTOFIDSpecies->SetFillColor(4);
552   fhTOFIDSpecies->Draw();
553   tex->Draw();
554  
555   char ch[10];
556
557   Float_t pifrac=fhTOFIDSpecies->GetBinContent(3);
558   Float_t kafrac=fhTOFIDSpecies->GetBinContent(4);
559   Float_t prfrac=fhTOFIDSpecies->GetBinContent(5);
560
561   sprintf(ch,"[2]:pion fraction   = %5.3f",pifrac);    
562   TLatex *   texpi = new TLatex(-0.3, 0.9, ch);
563   texpi->SetTextColor(1);
564   texpi->SetTextSize(0.05);
565   texpi->SetLineWidth(2);
566   texpi->Draw();
567   sprintf(ch,"[3]:kaon fraction   = %5.3f",kafrac);    
568   TLatex *   texka = new TLatex(-0.3, 0.8, ch);
569   texka->SetTextColor(1);
570   texka->SetTextSize(0.05);
571   texka->SetLineWidth(2);
572   texka->Draw();
573   sprintf(ch,"[4]:proton fraction = %5.3f",prfrac);    
574   TLatex *   texpr = new TLatex(-0.3, 0.7, ch);
575   texpr->SetTextColor(1);
576   texpr->SetTextSize(0.05);
577   texpr->SetLineWidth(2);
578   texpr->Draw();
579
580
581   cTOFpid->Print("TOF_pid.eps");
582
583   char line[1024] ; 
584   sprintf(line, ".!tar -zcf %s.tar.gz *.eps", GetName()) ; 
585   gROOT->ProcessLine(line);
586   sprintf(line, ".!rm -fR *.eps"); 
587   gROOT->ProcessLine(line);
588   AliInfo(Form("*** TOF QA plots saved in %s.tar.gz...", GetName())) ;
589
590   Bool_t problem=kFALSE;
591   //------------------------------Matching Efficiency
592
593   //Overall Fraction:
594   Float_t matchFrac= fhTOFMatch->GetMean();
595   if(matchFrac<fmatchFracMin){
596     AliWarning(Form("*** Overall Fraction of matched tracks too low! Fraction = %f", matchFrac)) ;
597     problem=kTRUE;
598   }else{
599     AliInfo(Form("*** Fraction of matched tracks  = %f", matchFrac)) ; 
600   } 
601
602   if(fhTOFeffMom->GetEntries()<1.){
603     AliWarning(Form("*** No tracks matching with TOF! Fraction is = %f", matchFrac)) ; 
604     problem=kTRUE;
605   }
606
607   
608   //The efficiency as a function of momentum:
609   Float_t eff=  fitMom->GetParameter(0);
610   Float_t deff=  fitMom->GetParError(0);
611   if(eff+3*deff<fmatchEffMin){
612     AliWarning(Form("*** Fraction of matched tracks vs Momentum is too low! Fraction= %f", eff)) ;
613     problem=kTRUE;
614   }else{
615     AliInfo(Form("*** Fraction of matched tracks for p>0.5 GeV is = %f", eff)) ;
616   } 
617
618   //Matched tracks vs TOF Sector:
619   for(Int_t isec=1;isec<=18;isec++){
620     if(fhTOFsector->GetBinContent(isec)<1 && TOFsectors[isec-1]>0){
621       AliWarning(Form("*** Missing Entries in sector %i", isec)); 
622       problem=kTRUE;
623     }
624     if(fhTOFsector->GetBinContent(isec)>0 && TOFsectors[isec-1]==0){
625       AliWarning(Form("*** Unexpected Entries in sector %i", isec)); 
626       problem=kTRUE;
627     }
628   }
629
630   //-----------------------------Pid Quality
631
632   // Look at the time - expected time: 
633   if(ntime==0)AliWarning("*** No peak was found in time difference spectrum!");
634   Float_t *timePos = timeDiff->GetPositionX();
635   if(TMath::Abs(timePos[0])>ftimePeakMax){
636     AliWarning(Form("*** Main Peak position in tTOF-TEXP spectrum is sitting far from where expected! Tpeak = %f ps",timePos[0]*1.E3));  
637     problem=kTRUE;
638   }else{
639     AliInfo(Form("*** Main Peak position in tTOF-TEXP found at = %f ps",timePos[0]*1.E3));  
640   }
641   // Look at the Mass Spectrum: 
642   if(nmass==0)AliWarning("*** No peak was found in Mass difference spectrum!");
643   Float_t *massPos = mass->GetPositionX();
644   for(Int_t imass=0;imass<nmass;imass++){   
645     AliInfo(Form("*** the Mass peak for %s found at  = %f GeV/c^2",part[imass],massPos[imass]));
646     if(TMath::Abs( massPos[imass]-masses[imass])> fmassPeakMax){
647       AliWarning(Form("*** the Mass peak position for %s is not in the right place, found at  = %f GeV/c^2",part[imass],massPos[imass]));
648       problem=kTRUE;
649     }
650   }
651
652   // Look at the ID Species: 
653
654   if(fhTOFIDSpecies->GetEntries()>1000){
655     if(pifrac<0.8 || (kafrac<0.01 || kafrac>0.2) || (prfrac<0.01 || prfrac>0.2)){
656       AliWarning(Form("*** Unexpected Id fractions: pions = %f, kaons = %f, protons %f", pifrac,kafrac,prfrac));
657       problem=kTRUE;
658     }
659   }
660
661   delete mass;
662   delete timeDiff;
663   return problem ; 
664 }
665
666 //______________________________________________________________________________
667 void AliTOFQATask::Terminate(Option_t *)
668 {
669   // Processing when the event loop is ended, some plots+checks
670   
671   AliInfo(Form("*** %s Report:", GetName())) ; 
672   GetEfficiency();
673   Bool_t problem = DrawHistos() ; 
674
675   char * report ; 
676   if(problem)
677     report="Problems found, please check!!!";  
678   else 
679     report="OK";
680
681   AliInfo(Form("*** %s Summary Report: %s\n",GetName(), report)) ; 
682   
683 }