1 #if !defined( __CINT__) || defined(__MAKECINT__)
10 #include <TParticle.h>
12 #include "AliRunLoader.h"
13 #include "AliLoader.h"
17 #include "AliHeader.h"
18 #include "AliGenEventHeader.h"
20 const Int_t kXiMinus = 3312;
21 const Int_t kOmegaMinus = 3334;
25 TH1F* CreateHisto(const char* name, const char* title,
26 Int_t nBins, Double_t xMin, Double_t xMax,
27 const char* xLabel = NULL, const char* yLabel = NULL)
31 TH1F* result = new TH1F(name, title, nBins, xMin, xMax);
32 result->SetOption("E");
33 if (xLabel) result->GetXaxis()->SetTitle(xLabel);
34 if (yLabel) result->GetYaxis()->SetTitle(yLabel);
35 result->SetMarkerStyle(kFullCircle);
39 TH1F* CreateEffHisto(TH1F* hGen, TH1F* hRec)
41 // create an efficiency histogram
43 Int_t nBins = hGen->GetNbinsX();
44 TH1F* hEff = (TH1F*) hGen->Clone("hEff");
46 hEff->SetStats(kFALSE);
48 hEff->SetMaximum(110.);
49 hEff->GetYaxis()->SetTitle("#epsilon [%]");
51 for (Int_t iBin = 0; iBin <= nBins; iBin++) {
52 Double_t nGen = hGen->GetBinContent(iBin);
53 Double_t nRec = hRec->GetBinContent(iBin);
55 Double_t eff = nRec/nGen;
56 hEff->SetBinContent(iBin, 100. * eff);
57 Double_t error = sqrt(eff*(1.-eff) / nGen);
58 if (error == 0) error = 0.0001;
59 hEff->SetBinError(iBin, 100. * error);
61 hEff->SetBinContent(iBin, -100.);
62 hEff->SetBinError(iBin, 0);
69 Bool_t FitHisto(TH1* histo, Double_t& res, Double_t& resError)
71 // fit a gaussian to a histogram
73 static TF1* fitFunc = new TF1("fitFunc", "gaus");
74 fitFunc->SetLineWidth(2);
75 fitFunc->SetFillStyle(0);
76 Double_t maxFitRange = 2;
78 if (histo->Integral() > 50) {
79 Float_t mean = histo->GetMean();
80 Float_t rms = histo->GetRMS();
81 fitFunc->SetRange(mean - maxFitRange*rms, mean + maxFitRange*rms);
82 fitFunc->SetParameters(mean, rms);
83 histo->Fit(fitFunc, "QRI0");
84 histo->GetFunction("fitFunc")->ResetBit(1<<9);
85 res = TMath::Abs(fitFunc->GetParameter(2));
86 resError = TMath::Abs(fitFunc->GetParError(2));
94 Bool_t CheckESD(const char* gAliceFileName = "galice.root",
95 const char* esdFileName = "AliESDs.root")
97 // check the content of the ESD
100 Int_t checkNGenLow = 1;
102 Double_t checkEffLow = 0.5;
103 Double_t checkEffSigma = 3;
104 Double_t checkFakeHigh = 0.5;
105 Double_t checkFakeSigma = 3;
107 Double_t checkResPtInvHigh = 5;
108 Double_t checkResPtInvSigma = 3;
109 Double_t checkResPhiHigh = 10;
110 Double_t checkResPhiSigma = 3;
111 Double_t checkResThetaHigh = 10;
112 Double_t checkResThetaSigma = 3;
114 Double_t checkPIDEffLow = 0.5;
115 Double_t checkPIDEffSigma = 3;
116 Double_t checkResTOFHigh = 500;
117 Double_t checkResTOFSigma = 3;
119 Double_t checkPHOSNLow = 5;
120 Double_t checkPHOSEnergyLow = 0.3;
121 Double_t checkPHOSEnergyHigh = 1.0;
122 Double_t checkEMCALNLow = 50;
123 Double_t checkEMCALEnergyLow = 0.05;
124 Double_t checkEMCALEnergyHigh = 1.0;
126 Double_t checkMUONNLow = 1;
127 Double_t checkMUONPtLow = 0.5;
128 Double_t checkMUONPtHigh = 10.;
130 Double_t cutPtV0 = 0.3;
131 Double_t checkV0EffLow = 0.02;
132 Double_t checkV0EffSigma = 3;
133 Double_t cutPtCascade = 0.5;
134 Double_t checkCascadeEffLow = 0.01;
135 Double_t checkCascadeEffSigma = 3;
137 // open run loader and load gAlice, kinematics and header
138 AliRunLoader* runLoader = AliRunLoader::Open(gAliceFileName);
140 Error("CheckESD", "getting run loader from file %s failed",
144 runLoader->LoadgAlice();
145 gAlice = runLoader->GetAliRun();
147 Error("CheckESD", "no galice object found");
150 runLoader->LoadKinematics();
151 runLoader->LoadHeader();
154 TFile* esdFile = TFile::Open(esdFileName);
155 if (!esdFile || !esdFile->IsOpen()) {
156 Error("CheckESD", "opening ESD file %s failed", esdFileName);
159 AliESD* esd = new AliESD;
160 TTree* tree = (TTree*) esdFile->Get("esdTree");
162 Error("CheckESD", "no ESD tree found");
165 tree->SetBranchAddress("ESD", &esd);
167 // efficienc and resolution histograms
171 TH1F* hGen = CreateHisto("hGen", "generated tracks",
172 nBinsPt, minPt, maxPt, "p_{t} [GeV/c]", "N");
173 TH1F* hRec = CreateHisto("hRec", "reconstructed tracks",
174 nBinsPt, minPt, maxPt, "p_{t} [GeV/c]", "N");
179 TH1F* hResPtInv = CreateHisto("hResPtInv", "", 100, -10, 10,
180 "(p_{t,rec}^{-1}-p_{t,sim}^{-1}) / p_{t,sim}^{-1} [%]", "N");
181 TH1F* hResPhi = CreateHisto("hResPhi", "", 100, -20, 20,
182 "#phi_{rec}-#phi_{sim} [mrad]", "N");
183 TH1F* hResTheta = CreateHisto("hResTheta", "", 100, -20, 20,
184 "#theta_{rec}-#theta_{sim} [mrad]", "N");
187 Int_t partCode[AliESDtrack::kSPECIES] =
188 {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
189 const char* partName[AliESDtrack::kSPECIES+1] =
190 {"electron", "muon", "pion", "kaon", "proton", "other"};
191 Double_t partFrac[AliESDtrack::kSPECIES] =
192 {0.01, 0.01, 0.85, 0.10, 0.05};
193 Int_t identified[AliESDtrack::kSPECIES+1][AliESDtrack::kSPECIES];
194 for (Int_t iGen = 0; iGen < AliESDtrack::kSPECIES+1; iGen++) {
195 for (Int_t iRec = 0; iRec < AliESDtrack::kSPECIES; iRec++) {
196 identified[iGen][iRec] = 0;
199 Int_t nIdentified = 0;
202 TH2F* hDEdxRight = new TH2F("hDEdxRight", "", 300, 0, 3, 100, 0, 400);
203 hDEdxRight->SetStats(kFALSE);
204 hDEdxRight->GetXaxis()->SetTitle("p [GeV/c]");
205 hDEdxRight->GetYaxis()->SetTitle("dE/dx_{TPC}");
206 hDEdxRight->SetMarkerStyle(kFullCircle);
207 hDEdxRight->SetMarkerSize(0.4);
208 TH2F* hDEdxWrong = new TH2F("hDEdxWrong", "", 300, 0, 3, 100, 0, 400);
209 hDEdxWrong->SetStats(kFALSE);
210 hDEdxWrong->GetXaxis()->SetTitle("p [GeV/c]");
211 hDEdxWrong->GetYaxis()->SetTitle("dE/dx_{TPC}");
212 hDEdxWrong->SetMarkerStyle(kFullCircle);
213 hDEdxWrong->SetMarkerSize(0.4);
214 hDEdxWrong->SetMarkerColor(kRed);
215 TH1F* hResTOFRight = CreateHisto("hResTOFRight", "", 100, -1000, 1000,
216 "t_{TOF}-t_{track} [ps]", "N");
217 TH1F* hResTOFWrong = CreateHisto("hResTOFWrong", "", 100, -1000, 1000,
218 "t_{TOF}-t_{track} [ps]", "N");
219 hResTOFWrong->SetLineColor(kRed);
222 TH1F* hEPHOS = CreateHisto("hEPHOS", "PHOS", 100, 0, 5, "E [GeV]", "N");
223 TH1F* hEEMCAL = CreateHisto("hEEMCAL", "EMCAL", 100, 0, 2, "E [GeV]", "N");
226 TH1F* hPtMUON = CreateHisto("hPtMUON", "MUON", 100, 0, 20,
227 "p_{t} [GeV/c]", "N");
230 TH1F* hMassK0 = CreateHisto("hMassK0", "K^{0}", 100, 0.4, 0.6,
231 "M(#pi^{+}#pi^{-}) [GeV/c^{2}]", "N");
232 TH1F* hMassLambda = CreateHisto("hMassLambda", "#Lambda", 100, 1.0, 1.2,
233 "M(p#pi^{-}) [GeV/c^{2}]", "N");
234 TH1F* hMassLambdaBar = CreateHisto("hMassLambdaBar", "#bar{#Lambda}",
236 "M(#bar{p}#pi^{+}) [GeV/c^{2}]", "N");
239 TH1F* hMassXi = CreateHisto("hMassXi", "#Xi", 100, 1.2, 1.5,
240 "M(#Lambda#pi) [GeV/c^{2}]", "N");
241 TH1F* hMassOmega = CreateHisto("hMassOmega", "#Omega", 100, 1.5, 1.8,
242 "M(#LambdaK) [GeV/c^{2}]", "N");
243 Int_t nGenCascades = 0;
244 Int_t nRecCascades = 0;
247 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
248 runLoader->GetEvent(iEvent);
250 // select simulated primary particles, V0s and cascades
251 AliStack* stack = gAlice->Stack();
252 Int_t nParticles = stack->GetNtrack();
254 runLoader->GetHeader()->GenEventHeader()->PrimaryVertex(vertex);
255 TObjArray selParticles;
257 TObjArray selCascades;
258 for (Int_t iParticle = 0; iParticle < nParticles; iParticle++) {
259 TParticle* particle = stack->Particle(iParticle);
260 if (!particle) continue;
261 if (particle->Pt() < 0.001) continue;
262 if (TMath::Abs(particle->Eta()) > 0.9) continue;
263 TVector3 dVertex(particle->Vx() - vertex[0],
264 particle->Vy() - vertex[1],
265 particle->Vz() - vertex[2]);
266 if (dVertex.Mag() > 0.0001) continue;
268 switch (TMath::Abs(particle->GetPdgCode())) {
274 if (particle->Pt() > minPt) {
275 selParticles.Add(particle);
277 hGen->Fill(particle->Pt());
283 if (particle->Pt() > cutPtV0) {
285 selV0s.Add(particle);
291 if (particle->Pt() > cutPtCascade) {
293 selCascades.Add(particle);
301 // get the event summary data
302 tree->GetEvent(iEvent);
304 Error("CheckESD", "no ESD object found for event %d", iEvent);
309 for (Int_t iTrack = 0; iTrack < esd->GetNumberOfTracks(); iTrack++) {
310 AliESDtrack* track = esd->GetTrack(iTrack);
312 // select tracks of selected particles
313 Int_t label = TMath::Abs(track->GetLabel());
314 if (label > stack->GetNtrack()) continue; // background
315 TParticle* particle = stack->Particle(label);
316 if (!selParticles.Contains(particle)) continue;
317 if ((track->GetStatus() & AliESDtrack::kITSrefit) == 0) continue;
318 if (track->GetConstrainedChi2() > 1e9) continue;
319 selParticles.Remove(particle); // don't count multiple tracks
322 hRec->Fill(particle->Pt());
323 if (track->GetLabel() < 0) nFake++;
327 track->GetConstrainedPxPyPz(p);
329 hResPtInv->Fill(100. * (1./pTrack.Pt() - 1./particle->Pt()) *
331 hResPhi->Fill(1000. * (pTrack.Phi() - particle->Phi()));
332 hResTheta->Fill(1000. * (pTrack.Theta() - particle->Theta()));
335 if ((track->GetStatus() & AliESDtrack::kESDpid) == 0) continue;
337 for (Int_t i = 0; i < AliESDtrack::kSPECIES; i++) {
338 if (TMath::Abs(particle->GetPdgCode()) == partCode[i]) iGen = i;
340 Double_t probability[AliESDtrack::kSPECIES];
341 track->GetESDpid(probability);
344 for (Int_t i = 0; i < AliESDtrack::kSPECIES; i++) {
345 probability[i] *= partFrac[i];
346 if (probability[i] > pMax) {
347 pMax = probability[i];
351 identified[iGen][iRec]++;
352 if (iGen == iRec) nIdentified++;
355 Double_t time[AliESDtrack::kSPECIES];
356 track->GetIntegratedTimes(time);
358 hDEdxRight->Fill(pTrack.Mag(), track->GetTPCsignal());
359 if ((track->GetStatus() & AliESDtrack::kTOFpid) != 0) {
360 hResTOFRight->Fill(track->GetTOFsignal() - time[iRec]);
363 hDEdxWrong->Fill(pTrack.Mag(), track->GetTPCsignal());
364 if ((track->GetStatus() & AliESDtrack::kTOFpid) != 0) {
365 hResTOFWrong->Fill(track->GetTOFsignal() - time[iRec]);
370 // loop over calo tracks
371 for (Int_t iTrack = 0; iTrack < esd->GetNumberOfTracks(); iTrack++) {
372 AliESDtrack* track = esd->GetTrack(iTrack);
373 if (track->IsPHOS()) {
374 hEPHOS->Fill(track->GetPHOSsignal());
375 } else if (track->IsEMCAL()) {
376 hEEMCAL->Fill(track->GetEMCALsignal());
380 // loop over muon tracks
382 for (Int_t iTrack = 0; iTrack < esd->GetNumberOfMuonTracks(); iTrack++) {
383 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
384 Double_t ptInv = TMath::Abs(muonTrack->GetInverseBendingMomentum());
386 hPtMUON->Fill(1./ptInv);
392 for (Int_t iV0 = 0; iV0 < esd->GetNumberOfV0s(); iV0++) {
393 AliESDv0* v0 = esd->GetV0(iV0);
394 v0->ChangeMassHypothesis(kK0Short);
395 hMassK0->Fill(v0->GetEffMass());
396 v0->ChangeMassHypothesis(kLambda0);
397 hMassLambda->Fill(v0->GetEffMass());
398 v0->ChangeMassHypothesis(kLambda0Bar);
399 hMassLambdaBar->Fill(v0->GetEffMass());
401 Int_t negLabel = TMath::Abs(esd->GetTrack(v0->GetNindex())->GetLabel());
402 if (negLabel > stack->GetNtrack()) continue; // background
403 Int_t negMother = stack->Particle(negLabel)->GetMother(0);
404 if (negMother < 0) continue;
405 Int_t posLabel = TMath::Abs(esd->GetTrack(v0->GetPindex())->GetLabel());
406 if (posLabel > stack->GetNtrack()) continue; // background
407 Int_t posMother = stack->Particle(posLabel)->GetMother(0);
408 if (negMother != posMother) continue;
409 TParticle* particle = stack->Particle(negMother);
410 if (!selV0s.Contains(particle)) continue;
411 selV0s.Remove(particle);
415 // loop over Cascades
416 for (Int_t iCascade = 0; iCascade < esd->GetNumberOfCascades();
418 AliESDcascade* cascade = esd->GetCascade(iCascade);
420 cascade->ChangeMassHypothesis(v0q,kXiMinus);
421 hMassXi->Fill(cascade->GetEffMass());
422 cascade->ChangeMassHypothesis(v0q,kOmegaMinus);
423 hMassOmega->Fill(cascade->GetEffMass());
425 Int_t negLabel = TMath::Abs(esd->GetTrack(cascade->GetNindex())
427 if (negLabel > stack->GetNtrack()) continue; // background
428 Int_t negMother = stack->Particle(negLabel)->GetMother(0);
429 if (negMother < 0) continue;
430 Int_t posLabel = TMath::Abs(esd->GetTrack(cascade->GetPindex())
432 if (posLabel > stack->GetNtrack()) continue; // background
433 Int_t posMother = stack->Particle(posLabel)->GetMother(0);
434 if (negMother != posMother) continue;
435 Int_t v0Mother = stack->Particle(negMother)->GetMother(0);
436 if (v0Mother < 0) continue;
437 Int_t bacLabel = TMath::Abs(esd->GetTrack(cascade->GetBindex())
439 if (bacLabel > stack->GetNtrack()) continue; // background
440 Int_t bacMother = stack->Particle(bacLabel)->GetMother(0);
441 if (v0Mother != bacMother) continue;
442 TParticle* particle = stack->Particle(v0Mother);
443 if (!selCascades.Contains(particle)) continue;
444 selCascades.Remove(particle);
450 if (nGen < checkNGenLow) {
451 Warning("CheckESD", "low number of generated particles: %d", Int_t(nGen));
454 TH1F* hEff = CreateEffHisto(hGen, hRec);
456 Info("CheckESD", "%d out of %d tracks reconstructed including %d "
457 "fake tracks", nRec, nGen, nFake);
460 Double_t eff = nRec*1./nGen;
461 Double_t effError = TMath::Sqrt(eff*(1.-eff) / nGen);
462 Double_t fake = nFake*1./nGen;
463 Double_t fakeError = TMath::Sqrt(fake*(1.-fake) / nGen);
464 Info("CheckESD", "eff = (%.1f +- %.1f) %% fake = (%.1f +- %.1f) %%",
465 100.*eff, 100.*effError, 100.*fake, 100.*fakeError);
467 if (eff < checkEffLow - checkEffSigma*effError) {
468 Warning("CheckESD", "low efficiency: (%.1f +- %.1f) %%",
469 100.*eff, 100.*effError);
471 if (fake > checkFakeHigh + checkFakeSigma*fakeError) {
472 Warning("CheckESD", "high fake: (%.1f +- %.1f) %%",
473 100.*fake, 100.*fakeError);
477 Double_t res, resError;
478 if (FitHisto(hResPtInv, res, resError)) {
479 Info("CheckESD", "relative inverse pt resolution = (%.1f +- %.1f) %%",
481 if (res > checkResPtInvHigh + checkResPtInvSigma*resError) {
482 Warning("CheckESD", "bad pt resolution: (%.1f +- %.1f) %%",
487 if (FitHisto(hResPhi, res, resError)) {
488 Info("CheckESD", "phi resolution = (%.1f +- %.1f) mrad", res, resError);
489 if (res > checkResPhiHigh + checkResPhiSigma*resError) {
490 Warning("CheckESD", "bad phi resolution: (%.1f +- %.1f) mrad",
495 if (FitHisto(hResTheta, res, resError)) {
496 Info("CheckESD", "theta resolution = (%.1f +- %.1f) mrad",
498 if (res > checkResThetaHigh + checkResThetaSigma*resError) {
499 Warning("CheckESD", "bad theta resolution: (%.1f +- %.1f) mrad",
506 Double_t eff = nIdentified*1./nRec;
507 Double_t effError = TMath::Sqrt(eff*(1.-eff) / nRec);
508 Info("CheckESD", "PID eff = (%.1f +- %.1f) %%",
509 100.*eff, 100.*effError);
510 if (eff < checkPIDEffLow - checkPIDEffSigma*effError) {
511 Warning("CheckESD", "low PID efficiency: (%.1f +- %.1f) %%",
512 100.*eff, 100.*effError);
516 printf("%9s:", "gen\\rec");
517 for (Int_t iRec = 0; iRec < AliESDtrack::kSPECIES; iRec++) {
518 printf("%9s", partName[iRec]);
521 for (Int_t iGen = 0; iGen < AliESDtrack::kSPECIES+1; iGen++) {
522 printf("%9s:", partName[iGen]);
523 for (Int_t iRec = 0; iRec < AliESDtrack::kSPECIES; iRec++) {
524 printf("%9d", identified[iGen][iRec]);
529 if (FitHisto(hResTOFRight, res, resError)) {
530 Info("CheckESD", "TOF resolution = (%.1f +- %.1f) ps", res, resError);
531 if (res > checkResTOFHigh + checkResTOFSigma*resError) {
532 Warning("CheckESD", "bad TOF resolution: (%.1f +- %.1f) ps",
538 if (hEPHOS->Integral() < checkPHOSNLow) {
539 Warning("CheckESD", "low number of PHOS particles: %d",
540 Int_t(hEPHOS->Integral()));
542 Double_t mean = hEPHOS->GetMean();
543 if (mean < checkPHOSEnergyLow) {
544 Warning("CheckESD", "low mean PHOS energy: %.1f GeV", mean);
545 } else if (mean > checkPHOSEnergyHigh) {
546 Warning("CheckESD", "high mean PHOS energy: %.1f GeV", mean);
550 if (hEEMCAL->Integral() < checkEMCALNLow) {
551 Warning("CheckESD", "low number of EMCAL particles: %d",
552 Int_t(hEEMCAL->Integral()));
554 Double_t mean = hEEMCAL->GetMean();
555 if (mean < checkEMCALEnergyLow) {
556 Warning("CheckESD", "low mean EMCAL energy: %.1f GeV", mean);
557 } else if (mean > checkEMCALEnergyHigh) {
558 Warning("CheckESD", "high mean EMCAL energy: %.1f GeV", mean);
563 if (hPtMUON->Integral() < checkMUONNLow) {
564 Warning("CheckESD", "low number of MUON particles: %d",
565 Int_t(hPtMUON->Integral()));
567 Double_t mean = hPtMUON->GetMean();
568 if (mean < checkMUONPtLow) {
569 Warning("CheckESD", "low mean MUON pt: %.1f GeV/c", mean);
570 } else if (mean > checkMUONPtHigh) {
571 Warning("CheckESD", "high mean MUON pt: %.1f GeV/c", mean);
577 Double_t eff = nRecV0s*1./nGenV0s;
578 Double_t effError = TMath::Sqrt(eff*(1.-eff) / nGenV0s);
579 if (effError == 0) effError = checkV0EffLow / TMath::Sqrt(1.*nGenV0s);
580 Info("CheckESD", "V0 eff = (%.1f +- %.1f) %%",
581 100.*eff, 100.*effError);
582 if (eff < checkV0EffLow - checkV0EffSigma*effError) {
583 Warning("CheckESD", "low V0 efficiency: (%.1f +- %.1f) %%",
584 100.*eff, 100.*effError);
589 if (nGenCascades > 0) {
590 Double_t eff = nRecCascades*1./nGenCascades;
591 Double_t effError = TMath::Sqrt(eff*(1.-eff) / nGenCascades);
592 if (effError == 0) effError = checkV0EffLow /
593 TMath::Sqrt(1.*nGenCascades);
594 Info("CheckESD", "Cascade eff = (%.1f +- %.1f) %%",
595 100.*eff, 100.*effError);
596 if (eff < checkCascadeEffLow - checkCascadeEffSigma*effError) {
597 Warning("CheckESD", "low Cascade efficiency: (%.1f +- %.1f) %%",
598 100.*eff, 100.*effError);
603 // draw the histograms if not in batch mode
604 if (!gROOT->IsBatch()) {
608 hResPtInv->DrawCopy("E");
610 hResPhi->DrawCopy("E");
612 hResTheta->DrawCopy("E");
614 hDEdxRight->DrawCopy();
615 hDEdxWrong->DrawCopy("SAME");
617 hResTOFRight->DrawCopy("E");
618 hResTOFWrong->DrawCopy("SAME");
620 hEPHOS->DrawCopy("E");
622 hEEMCAL->DrawCopy("E");
624 hPtMUON->DrawCopy("E");
626 hMassK0->DrawCopy("E");
628 hMassLambda->DrawCopy("E");
630 hMassLambdaBar->DrawCopy("E");
632 hMassXi->DrawCopy("E");
634 hMassOmega->DrawCopy("E");
637 // write the output histograms to a file
638 TFile* outputFile = TFile::Open("check.root", "recreate");
639 if (!outputFile || !outputFile->IsOpen()) {
640 Error("CheckESD", "opening output file check.root failed");
649 hResTOFRight->Write();
650 hResTOFWrong->Write();
655 hMassLambda->Write();
656 hMassLambdaBar->Write();
678 delete hMassLambdaBar;
686 runLoader->UnloadHeader();
687 runLoader->UnloadKinematics();
691 Info("CheckESD", "check of ESD was successfull");