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