1 #if !defined( __CINT__) || defined(__MAKECINT__)
11 #include <TParticle.h>
13 #include "AliRunLoader.h"
14 #include "AliLoader.h"
15 #include "AliESDEvent.h"
17 #include "AliESDcascade.h"
18 #include "AliESDMuonTrack.h"
19 #include "AliESDCaloCluster.h"
22 #include "AliHeader.h"
23 #include "AliGenEventHeader.h"
26 const Int_t kXiMinus = 3312;
27 const Int_t kOmegaMinus = 3334;
30 TH1F* CreateHisto(const char* name, const char* title,
31 Int_t nBins, Double_t xMin, Double_t xMax,
32 const char* xLabel = NULL, const char* yLabel = NULL)
36 TH1F* result = new TH1F(name, title, nBins, xMin, xMax);
37 result->SetOption("E");
38 if (xLabel) result->GetXaxis()->SetTitle(xLabel);
39 if (yLabel) result->GetYaxis()->SetTitle(yLabel);
40 result->SetMarkerStyle(kFullCircle);
44 TH1F* CreateEffHisto(TH1F* hGen, TH1F* hRec)
46 // create an efficiency histogram
48 Int_t nBins = hGen->GetNbinsX();
49 TH1F* hEff = (TH1F*) hGen->Clone("hEff");
51 hEff->SetStats(kFALSE);
53 hEff->SetMaximum(110.);
54 hEff->GetYaxis()->SetTitle("#epsilon [%]");
56 for (Int_t iBin = 0; iBin <= nBins; iBin++) {
57 Double_t nGen = hGen->GetBinContent(iBin);
58 Double_t nRec = hRec->GetBinContent(iBin);
60 Double_t eff = nRec/nGen;
61 hEff->SetBinContent(iBin, 100. * eff);
62 Double_t error = sqrt(eff*(1.-eff) / nGen);
63 if (error == 0) error = 0.0001;
64 hEff->SetBinError(iBin, 100. * error);
66 hEff->SetBinContent(iBin, -100.);
67 hEff->SetBinError(iBin, 0);
74 Bool_t FitHisto(TH1* histo, Double_t& res, Double_t& resError)
76 // fit a gaussian to a histogram
78 static TF1* fitFunc = new TF1("fitFunc", "gaus");
79 fitFunc->SetLineWidth(2);
80 fitFunc->SetFillStyle(0);
81 Double_t maxFitRange = 2;
83 if (histo->Integral() > 50) {
84 Float_t mean = histo->GetMean();
85 Float_t rms = histo->GetRMS();
86 fitFunc->SetRange(mean - maxFitRange*rms, mean + maxFitRange*rms);
87 fitFunc->SetParameters(mean, rms);
88 histo->Fit(fitFunc, "QRI0");
89 histo->GetFunction("fitFunc")->ResetBit(1<<9);
90 res = TMath::Abs(fitFunc->GetParameter(2));
91 resError = TMath::Abs(fitFunc->GetParError(2));
99 Bool_t CheckESD(const char* gAliceFileName = "galice.root",
100 const char* esdFileName = "AliESDs.root")
102 // check the content of the ESD
105 Int_t checkNGenLow = 1;
107 Double_t checkEffLow = 0.5;
108 Double_t checkEffSigma = 3;
109 Double_t checkFakeHigh = 0.5;
110 Double_t checkFakeSigma = 3;
112 Double_t checkResPtInvHigh = 5;
113 Double_t checkResPtInvSigma = 3;
114 Double_t checkResPhiHigh = 10;
115 Double_t checkResPhiSigma = 3;
116 Double_t checkResThetaHigh = 10;
117 Double_t checkResThetaSigma = 3;
119 Double_t checkPIDEffLow = 0.5;
120 Double_t checkPIDEffSigma = 3;
121 Double_t checkResTOFHigh = 500;
122 Double_t checkResTOFSigma = 3;
124 Double_t checkPHOSNLow = 5;
125 Double_t checkPHOSEnergyLow = 0.3;
126 Double_t checkPHOSEnergyHigh = 1.0;
127 Double_t checkEMCALNLow = 50;
128 Double_t checkEMCALEnergyLow = 0.05;
129 Double_t checkEMCALEnergyHigh = 1.0;
131 Double_t checkMUONNLow = 1;
132 Double_t checkMUONPtLow = 0.5;
133 Double_t checkMUONPtHigh = 10.;
135 Double_t cutPtV0 = 0.3;
136 Double_t checkV0EffLow = 0.02;
137 Double_t checkV0EffSigma = 3;
138 Double_t cutPtCascade = 0.5;
139 Double_t checkCascadeEffLow = 0.01;
140 Double_t checkCascadeEffSigma = 3;
142 // open run loader and load gAlice, kinematics and header
143 AliRunLoader* runLoader = AliRunLoader::Open(gAliceFileName);
145 Error("CheckESD", "getting run loader from file %s failed",
149 runLoader->LoadgAlice();
150 gAlice = runLoader->GetAliRun();
152 Error("CheckESD", "no galice object found");
155 runLoader->LoadKinematics();
156 runLoader->LoadHeader();
159 TFile* esdFile = TFile::Open(esdFileName);
160 if (!esdFile || !esdFile->IsOpen()) {
161 Error("CheckESD", "opening ESD file %s failed", esdFileName);
164 AliESDEvent * esd = new AliESDEvent;
165 TTree* tree = (TTree*) esdFile->Get("esdTree");
167 Error("CheckESD", "no ESD tree found");
170 esd->ReadFromTree(tree);
172 // efficiency and resolution histograms
176 TH1F* hGen = CreateHisto("hGen", "generated tracks",
177 nBinsPt, minPt, maxPt, "p_{t} [GeV/c]", "N");
178 TH1F* hRec = CreateHisto("hRec", "reconstructed tracks",
179 nBinsPt, minPt, maxPt, "p_{t} [GeV/c]", "N");
184 TH1F* hResPtInv = CreateHisto("hResPtInv", "", 100, -10, 10,
185 "(p_{t,rec}^{-1}-p_{t,sim}^{-1}) / p_{t,sim}^{-1} [%]", "N");
186 TH1F* hResPhi = CreateHisto("hResPhi", "", 100, -20, 20,
187 "#phi_{rec}-#phi_{sim} [mrad]", "N");
188 TH1F* hResTheta = CreateHisto("hResTheta", "", 100, -20, 20,
189 "#theta_{rec}-#theta_{sim} [mrad]", "N");
192 Int_t partCode[AliPID::kSPECIES] =
193 {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
194 const char* partName[AliPID::kSPECIES+1] =
195 {"electron", "muon", "pion", "kaon", "proton", "other"};
196 Double_t partFrac[AliPID::kSPECIES] =
197 {0.01, 0.01, 0.85, 0.10, 0.05};
198 Int_t identified[AliPID::kSPECIES+1][AliPID::kSPECIES];
199 for (Int_t iGen = 0; iGen < AliPID::kSPECIES+1; iGen++) {
200 for (Int_t iRec = 0; iRec < AliPID::kSPECIES; iRec++) {
201 identified[iGen][iRec] = 0;
204 Int_t nIdentified = 0;
207 TH2F* hDEdxRight = new TH2F("hDEdxRight", "", 300, 0, 3, 100, 0, 400);
208 hDEdxRight->SetStats(kFALSE);
209 hDEdxRight->GetXaxis()->SetTitle("p [GeV/c]");
210 hDEdxRight->GetYaxis()->SetTitle("dE/dx_{TPC}");
211 hDEdxRight->SetMarkerStyle(kFullCircle);
212 hDEdxRight->SetMarkerSize(0.4);
213 TH2F* hDEdxWrong = new TH2F("hDEdxWrong", "", 300, 0, 3, 100, 0, 400);
214 hDEdxWrong->SetStats(kFALSE);
215 hDEdxWrong->GetXaxis()->SetTitle("p [GeV/c]");
216 hDEdxWrong->GetYaxis()->SetTitle("dE/dx_{TPC}");
217 hDEdxWrong->SetMarkerStyle(kFullCircle);
218 hDEdxWrong->SetMarkerSize(0.4);
219 hDEdxWrong->SetMarkerColor(kRed);
220 TH1F* hResTOFRight = CreateHisto("hResTOFRight", "", 100, -1000, 1000,
221 "t_{TOF}-t_{track} [ps]", "N");
222 TH1F* hResTOFWrong = CreateHisto("hResTOFWrong", "", 100, -1000, 1000,
223 "t_{TOF}-t_{track} [ps]", "N");
224 hResTOFWrong->SetLineColor(kRed);
227 TH1F* hEPHOS = CreateHisto("hEPHOS", "PHOS", 100, 0, 5, "E [GeV]", "N");
228 TH1F* hEEMCAL = CreateHisto("hEEMCAL", "EMCAL", 100, 0, 50, "E [GeV]", "N");
231 TH1F* hPtMUON = CreateHisto("hPtMUON", "MUON", 100, 0, 20,
232 "p_{t} [GeV/c]", "N");
235 TH1F* hMassK0 = CreateHisto("hMassK0", "K^{0}", 100, 0.4, 0.6,
236 "M(#pi^{+}#pi^{-}) [GeV/c^{2}]", "N");
237 TH1F* hMassLambda = CreateHisto("hMassLambda", "#Lambda", 100, 1.0, 1.2,
238 "M(p#pi^{-}) [GeV/c^{2}]", "N");
239 TH1F* hMassLambdaBar = CreateHisto("hMassLambdaBar", "#bar{#Lambda}",
241 "M(#bar{p}#pi^{+}) [GeV/c^{2}]", "N");
244 TH1F* hMassXi = CreateHisto("hMassXi", "#Xi", 100, 1.2, 1.5,
245 "M(#Lambda#pi) [GeV/c^{2}]", "N");
246 TH1F* hMassOmega = CreateHisto("hMassOmega", "#Omega", 100, 1.5, 1.8,
247 "M(#LambdaK) [GeV/c^{2}]", "N");
248 Int_t nGenCascades = 0;
249 Int_t nRecCascades = 0;
252 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
253 runLoader->GetEvent(iEvent);
255 // select simulated primary particles, V0s and cascades
256 AliStack* stack = gAlice->Stack();
257 Int_t nParticles = stack->GetNtrack();
259 runLoader->GetHeader()->GenEventHeader()->PrimaryVertex(vertex);
260 TObjArray selParticles;
262 TObjArray selCascades;
263 for (Int_t iParticle = 0; iParticle < nParticles; iParticle++) {
264 TParticle* particle = stack->Particle(iParticle);
265 if (!particle) continue;
266 if (particle->Pt() < 0.001) continue;
267 if (TMath::Abs(particle->Eta()) > 0.9) continue;
268 TVector3 dVertex(particle->Vx() - vertex[0],
269 particle->Vy() - vertex[1],
270 particle->Vz() - vertex[2]);
271 if (dVertex.Mag() > 0.0001) continue;
273 switch (TMath::Abs(particle->GetPdgCode())) {
279 if (particle->Pt() > minPt) {
280 selParticles.Add(particle);
282 hGen->Fill(particle->Pt());
288 if (particle->Pt() > cutPtV0) {
290 selV0s.Add(particle);
296 if (particle->Pt() > cutPtCascade) {
298 selCascades.Add(particle);
306 // get the event summary data
307 tree->GetEvent(iEvent);
309 Error("CheckESD", "no ESD object found for event %d", iEvent);
314 for (Int_t iTrack = 0; iTrack < esd->GetNumberOfTracks(); iTrack++) {
315 AliESDtrack* track = esd->GetTrack(iTrack);
317 // select tracks of selected particles
318 Int_t label = TMath::Abs(track->GetLabel());
319 if (label > stack->GetNtrack()) continue; // background
320 TParticle* particle = stack->Particle(label);
321 if (!selParticles.Contains(particle)) continue;
322 if ((track->GetStatus() & AliESDtrack::kITSrefit) == 0) continue;
323 if (track->GetConstrainedChi2() > 1e9) continue;
324 selParticles.Remove(particle); // don't count multiple tracks
327 hRec->Fill(particle->Pt());
328 if (track->GetLabel() < 0) nFake++;
331 hResPtInv->Fill(100. * (TMath::Abs(track->GetSigned1Pt()) - 1./particle->Pt()) *
333 hResPhi->Fill(1000. * (track->Phi() - particle->Phi()));
334 hResTheta->Fill(1000. * (track->Theta() - particle->Theta()));
337 if ((track->GetStatus() & AliESDtrack::kESDpid) == 0) continue;
339 for (Int_t i = 0; i < AliPID::kSPECIES; i++) {
340 if (TMath::Abs(particle->GetPdgCode()) == partCode[i]) iGen = i;
342 Double_t probability[AliPID::kSPECIES];
343 track->GetESDpid(probability);
346 for (Int_t i = 0; i < AliPID::kSPECIES; i++) {
347 probability[i] *= partFrac[i];
348 if (probability[i] > pMax) {
349 pMax = probability[i];
353 identified[iGen][iRec]++;
354 if (iGen == iRec) nIdentified++;
357 Double_t time[AliPID::kSPECIES];
358 track->GetIntegratedTimes(time);
360 hDEdxRight->Fill(particle->P(), track->GetTPCsignal());
361 if ((track->GetStatus() & AliESDtrack::kTOFpid) != 0) {
362 hResTOFRight->Fill(track->GetTOFsignal() - time[iRec]);
365 hDEdxWrong->Fill(particle->P(), track->GetTPCsignal());
366 if ((track->GetStatus() & AliESDtrack::kTOFpid) != 0) {
367 hResTOFWrong->Fill(track->GetTOFsignal() - time[iRec]);
372 // loop over muon tracks
374 for (Int_t iTrack = 0; iTrack < esd->GetNumberOfMuonTracks(); iTrack++) {
375 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
376 Double_t ptInv = TMath::Abs(muonTrack->GetInverseBendingMomentum());
378 hPtMUON->Fill(1./ptInv);
384 for (Int_t iV0 = 0; iV0 < esd->GetNumberOfV0s(); iV0++) {
385 AliESDv0* v0 = esd->GetV0(iV0);
386 if (v0->GetOnFlyStatus()) continue;
387 v0->ChangeMassHypothesis(kK0Short);
388 hMassK0->Fill(v0->GetEffMass());
389 v0->ChangeMassHypothesis(kLambda0);
390 hMassLambda->Fill(v0->GetEffMass());
391 v0->ChangeMassHypothesis(kLambda0Bar);
392 hMassLambdaBar->Fill(v0->GetEffMass());
394 Int_t negLabel = TMath::Abs(esd->GetTrack(v0->GetNindex())->GetLabel());
395 if (negLabel > stack->GetNtrack()) continue; // background
396 Int_t negMother = stack->Particle(negLabel)->GetMother(0);
397 if (negMother < 0) continue;
398 Int_t posLabel = TMath::Abs(esd->GetTrack(v0->GetPindex())->GetLabel());
399 if (posLabel > stack->GetNtrack()) continue; // background
400 Int_t posMother = stack->Particle(posLabel)->GetMother(0);
401 if (negMother != posMother) continue;
402 TParticle* particle = stack->Particle(negMother);
403 if (!selV0s.Contains(particle)) continue;
404 selV0s.Remove(particle);
408 // loop over Cascades
409 for (Int_t iCascade = 0; iCascade < esd->GetNumberOfCascades();
411 AliESDcascade* cascade = esd->GetCascade(iCascade);
413 cascade->ChangeMassHypothesis(v0q,kXiMinus);
414 hMassXi->Fill(cascade->GetEffMass());
415 cascade->ChangeMassHypothesis(v0q,kOmegaMinus);
416 hMassOmega->Fill(cascade->GetEffMass());
418 Int_t negLabel = TMath::Abs(esd->GetTrack(cascade->GetNindex())
420 if (negLabel > stack->GetNtrack()) continue; // background
421 Int_t negMother = stack->Particle(negLabel)->GetMother(0);
422 if (negMother < 0) continue;
423 Int_t posLabel = TMath::Abs(esd->GetTrack(cascade->GetPindex())
425 if (posLabel > stack->GetNtrack()) continue; // background
426 Int_t posMother = stack->Particle(posLabel)->GetMother(0);
427 if (negMother != posMother) continue;
428 Int_t v0Mother = stack->Particle(negMother)->GetMother(0);
429 if (v0Mother < 0) continue;
430 Int_t bacLabel = TMath::Abs(esd->GetTrack(cascade->GetBindex())
432 if (bacLabel > stack->GetNtrack()) continue; // background
433 Int_t bacMother = stack->Particle(bacLabel)->GetMother(0);
434 if (v0Mother != bacMother) continue;
435 TParticle* particle = stack->Particle(v0Mother);
436 if (!selCascades.Contains(particle)) continue;
437 selCascades.Remove(particle);
441 // loop over the clusters
443 for (Int_t iCluster=0; iCluster<esd->GetNumberOfCaloClusters(); iCluster++) {
444 AliESDCaloCluster * clust = esd->GetCaloCluster(iCluster);
445 if (clust->IsPHOS()) hEPHOS->Fill(clust->E());
446 if (clust->IsEMCAL()) hEEMCAL->Fill(clust->E());
453 if (nGen < checkNGenLow) {
454 Warning("CheckESD", "low number of generated particles: %d", Int_t(nGen));
457 TH1F* hEff = CreateEffHisto(hGen, hRec);
459 Info("CheckESD", "%d out of %d tracks reconstructed including %d "
460 "fake tracks", nRec, nGen, nFake);
463 Double_t eff = nRec*1./nGen;
464 Double_t effError = TMath::Sqrt(eff*(1.-eff) / nGen);
465 Double_t fake = nFake*1./nGen;
466 Double_t fakeError = TMath::Sqrt(fake*(1.-fake) / nGen);
467 Info("CheckESD", "eff = (%.1f +- %.1f) %% fake = (%.1f +- %.1f) %%",
468 100.*eff, 100.*effError, 100.*fake, 100.*fakeError);
470 if (eff < checkEffLow - checkEffSigma*effError) {
471 Warning("CheckESD", "low efficiency: (%.1f +- %.1f) %%",
472 100.*eff, 100.*effError);
474 if (fake > checkFakeHigh + checkFakeSigma*fakeError) {
475 Warning("CheckESD", "high fake: (%.1f +- %.1f) %%",
476 100.*fake, 100.*fakeError);
480 Double_t res, resError;
481 if (FitHisto(hResPtInv, res, resError)) {
482 Info("CheckESD", "relative inverse pt resolution = (%.1f +- %.1f) %%",
484 if (res > checkResPtInvHigh + checkResPtInvSigma*resError) {
485 Warning("CheckESD", "bad pt resolution: (%.1f +- %.1f) %%",
490 if (FitHisto(hResPhi, res, resError)) {
491 Info("CheckESD", "phi resolution = (%.1f +- %.1f) mrad", res, resError);
492 if (res > checkResPhiHigh + checkResPhiSigma*resError) {
493 Warning("CheckESD", "bad phi resolution: (%.1f +- %.1f) mrad",
498 if (FitHisto(hResTheta, res, resError)) {
499 Info("CheckESD", "theta resolution = (%.1f +- %.1f) mrad",
501 if (res > checkResThetaHigh + checkResThetaSigma*resError) {
502 Warning("CheckESD", "bad theta resolution: (%.1f +- %.1f) mrad",
509 Double_t eff = nIdentified*1./nRec;
510 Double_t effError = TMath::Sqrt(eff*(1.-eff) / nRec);
511 Info("CheckESD", "PID eff = (%.1f +- %.1f) %%",
512 100.*eff, 100.*effError);
513 if (eff < checkPIDEffLow - checkPIDEffSigma*effError) {
514 Warning("CheckESD", "low PID efficiency: (%.1f +- %.1f) %%",
515 100.*eff, 100.*effError);
519 printf("%9s:", "gen\\rec");
520 for (Int_t iRec = 0; iRec < AliPID::kSPECIES; iRec++) {
521 printf("%9s", partName[iRec]);
524 for (Int_t iGen = 0; iGen < AliPID::kSPECIES+1; iGen++) {
525 printf("%9s:", partName[iGen]);
526 for (Int_t iRec = 0; iRec < AliPID::kSPECIES; iRec++) {
527 printf("%9d", identified[iGen][iRec]);
532 if (FitHisto(hResTOFRight, res, resError)) {
533 Info("CheckESD", "TOF resolution = (%.1f +- %.1f) ps", res, resError);
534 if (res > checkResTOFHigh + checkResTOFSigma*resError) {
535 Warning("CheckESD", "bad TOF resolution: (%.1f +- %.1f) ps",
541 if (hEPHOS->Integral() < checkPHOSNLow) {
542 Warning("CheckESD", "low number of PHOS particles: %d",
543 Int_t(hEPHOS->Integral()));
545 Double_t mean = hEPHOS->GetMean();
546 if (mean < checkPHOSEnergyLow) {
547 Warning("CheckESD", "low mean PHOS energy: %.1f GeV", mean);
548 } else if (mean > checkPHOSEnergyHigh) {
549 Warning("CheckESD", "high mean PHOS energy: %.1f GeV", mean);
553 if (hEEMCAL->Integral() < checkEMCALNLow) {
554 Warning("CheckESD", "low number of EMCAL particles: %d",
555 Int_t(hEEMCAL->Integral()));
557 Double_t mean = hEEMCAL->GetMean();
558 if (mean < checkEMCALEnergyLow) {
559 Warning("CheckESD", "low mean EMCAL energy: %.1f GeV", mean);
560 } else if (mean > checkEMCALEnergyHigh) {
561 Warning("CheckESD", "high mean EMCAL energy: %.1f GeV", mean);
566 if (hPtMUON->Integral() < checkMUONNLow) {
567 Warning("CheckESD", "low number of MUON particles: %d",
568 Int_t(hPtMUON->Integral()));
570 Double_t mean = hPtMUON->GetMean();
571 if (mean < checkMUONPtLow) {
572 Warning("CheckESD", "low mean MUON pt: %.1f GeV/c", mean);
573 } else if (mean > checkMUONPtHigh) {
574 Warning("CheckESD", "high mean MUON pt: %.1f GeV/c", mean);
580 Double_t eff = nRecV0s*1./nGenV0s;
581 Double_t effError = TMath::Sqrt(eff*(1.-eff) / nGenV0s);
582 if (effError == 0) effError = checkV0EffLow / TMath::Sqrt(1.*nGenV0s);
583 Info("CheckESD", "V0 eff = (%.1f +- %.1f) %%",
584 100.*eff, 100.*effError);
585 if (eff < checkV0EffLow - checkV0EffSigma*effError) {
586 Warning("CheckESD", "low V0 efficiency: (%.1f +- %.1f) %%",
587 100.*eff, 100.*effError);
592 if (nGenCascades > 0) {
593 Double_t eff = nRecCascades*1./nGenCascades;
594 Double_t effError = TMath::Sqrt(eff*(1.-eff) / nGenCascades);
595 if (effError == 0) effError = checkV0EffLow /
596 TMath::Sqrt(1.*nGenCascades);
597 Info("CheckESD", "Cascade eff = (%.1f +- %.1f) %%",
598 100.*eff, 100.*effError);
599 if (eff < checkCascadeEffLow - checkCascadeEffSigma*effError) {
600 Warning("CheckESD", "low Cascade efficiency: (%.1f +- %.1f) %%",
601 100.*eff, 100.*effError);
606 // draw the histograms if not in batch mode
607 if (!gROOT->IsBatch()) {
611 hResPtInv->DrawCopy("E");
613 hResPhi->DrawCopy("E");
615 hResTheta->DrawCopy("E");
617 hDEdxRight->DrawCopy();
618 hDEdxWrong->DrawCopy("SAME");
620 hResTOFRight->DrawCopy("E");
621 hResTOFWrong->DrawCopy("SAME");
623 hEPHOS->DrawCopy("E");
625 hEEMCAL->DrawCopy("E");
627 hPtMUON->DrawCopy("E");
629 hMassK0->DrawCopy("E");
631 hMassLambda->DrawCopy("E");
633 hMassLambdaBar->DrawCopy("E");
635 hMassXi->DrawCopy("E");
637 hMassOmega->DrawCopy("E");
640 // write the output histograms to a file
641 TFile* outputFile = TFile::Open("check.root", "recreate");
642 if (!outputFile || !outputFile->IsOpen()) {
643 Error("CheckESD", "opening output file check.root failed");
652 hResTOFRight->Write();
653 hResTOFWrong->Write();
658 hMassLambda->Write();
659 hMassLambdaBar->Write();
681 delete hMassLambdaBar;
689 runLoader->UnloadHeader();
690 runLoader->UnloadKinematics();
694 Info("CheckESD", "check of ESD was successfull");