1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /////////////////////////////////////////////////////
18 // Check basic detector results at ESD level
19 // - Geometrical efficiency
20 // - Tracking efficiency
25 // Alex Bercuci <A.Bercuci@gsi.de>
27 //////////////////////////////////////////////////////
29 #include <TClonesArray.h>
30 #include <TObjArray.h>
33 #include <TGraphErrors.h>
34 #include <TGraphAsymmErrors.h>
39 #include <TParticle.h>
42 #include "AliAnalysisManager.h"
43 #include "AliESDEvent.h"
44 #include "AliESDkink.h"
45 #include "AliMCEvent.h"
46 #include "AliESDInputHandler.h"
47 #include "AliMCEventHandler.h"
49 #include "AliESDtrack.h"
50 #include "AliMCParticle.h"
53 #include "AliTrackReference.h"
55 #include "AliTRDcheckESD.h"
57 ClassImp(AliTRDcheckESD)
59 const Float_t AliTRDcheckESD::fgkxTPC = 290.;
60 const Float_t AliTRDcheckESD::fgkxTOF = 365.;
61 FILE* AliTRDcheckESD::fgFile = 0x0;
63 //____________________________________________________________________
64 AliTRDcheckESD::AliTRDcheckESD():
65 AliAnalysisTask("checkESD", "ESD checker for TRD info")
73 // Default constructor
76 DefineInput(0, TChain::Class());
77 DefineOutput(0, TObjArray::Class());
80 //____________________________________________________________________
81 AliTRDcheckESD::~AliTRDcheckESD()
94 //____________________________________________________________________
95 void AliTRDcheckESD::ConnectInputData(Option_t *)
98 // Link the Input Data
100 TTree *tree = dynamic_cast<TChain*>(GetInputData(0));
101 if(tree) tree->SetBranchStatus("Tracks", 1);
103 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
104 fESD = esdH ? esdH->GetEvent() : 0x0;
107 AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
108 fMC = mcH ? mcH->MCEvent() : 0x0;
111 //____________________________________________________________________
112 void AliTRDcheckESD::CreateOutputObjects()
115 // Create Output Containers (TObjectArray containing 1D histograms)
117 OpenFile(0, "RECREATE");
121 //____________________________________________________________________
122 Bool_t AliTRDcheckESD::GetRefFigure(Int_t ifig)
125 AliWarning("Please provide a canvas to draw results.");
128 TGraph *g(0x0); TH1 *h(0x0); TLegend *leg(0x0);
131 if(!fHistos || !(h=(TH1I*)fHistos->At(kNCl))) break;
135 leg=new TLegend(.5, .75, .98, .98);
136 leg->SetBorderSize(1); leg->SetFillColor(0);
137 leg->SetHeader("Tracking Efficiency");
138 for(Int_t ieff=0; ieff<4; ieff++){
139 if(!(g=GetGraph(ieff, ""))) break;
141 if((h=(TH1S*)gROOT->FindObject("frame"))) delete h;
142 h=new TH1S("h","",100, 0., 15.);
143 h->SetLineColor(1);h->SetLineWidth(1);
144 h->SetMinimum(0.2);h->SetMaximum(1.2);
145 h->SetXTitle("p_{T} [GeV/c]");
146 h->SetYTitle("Efficiency");
149 g->Draw("pc"); leg->AddEntry(g, g->GetTitle(), "pl");
154 leg=new TLegend(.6, .75, .98, .98);
155 leg->SetBorderSize(1); leg->SetFillColor(0);
156 leg->SetHeader("Energy loss");
157 for(Int_t ieff=0; ieff<2; ieff++){
158 if(!(g=GetGraph(4+ieff, ""))) break;
160 if((h=(TH1S*)gROOT->FindObject("frame"))) delete h;
161 h=new TH1S("h","",100, -0.5, 5.5);
162 h->SetLineColor(0);h->SetLineWidth(1);
163 h->SetMinimum(-0.5);h->SetMaximum(1.2);
164 h->SetXTitle("layer");
165 h->SetYTitle("p_{T}^{Inner TPC} - p_{T}^{layer} [GeV/c]");
168 g->Draw("p"); leg->AddEntry(g, g->GetTitle(), "pl");
175 AliInfo(Form("Reference plot [%d] missing result", ifig));
179 //____________________________________________________________________
180 TGraph* AliTRDcheckESD::GetGraph(Int_t id, Option_t *opt)
182 // Retrieve graph with "id"
183 // Possible options are :
184 // "b" - build graph if none found
185 // "c" - clear existing graph
187 Bool_t kBUILD = strstr(opt, "b"), // build graph if none found
188 kCLEAR = strstr(opt, "c"); // clear existing graph
190 const Char_t *name[] = {
191 "Geo", "Trk", "Pid", "Ref", "Max06", "Mean09"
193 const Char_t *title[] = {
194 "TRD geometrical efficiency (TRDin/TPCout)"
195 ,"TRD tracking efficiency (TRDout/TRDin)"
196 ,"TRD PID efficiency (TRDpid/TRDin)"
197 ,"TRD refit efficiency (TRDrefit/TRDin)"
198 ,"TRD Eloss (Max/90% quantile)"
199 ,"TRD Eloss (Mean/60% quantile)"
201 const Int_t ngr = sizeof(name)/sizeof(Char_t*);
203 AliWarning("No of graphs defined different from definition");
208 fResults = new TObjArray(kNgraphs);
209 fResults->SetOwner();
210 fResults->SetName("results");
214 if((g = dynamic_cast<TGraph*>(fResults->At(id)))){
216 for(Int_t ip=g->GetN(); ip--;) g->RemovePoint(ip);
218 PutTrendValue(name[id], g->GetMean(2));
219 PutTrendValue(Form("%sRMS", name[id]), g->GetRMS(2));
225 g = new TGraphErrors();
226 g->SetMarkerStyle(7);g->SetMarkerColor(kBlack);
227 g->SetLineColor(kBlack);
230 g = new TGraphErrors();
231 g->SetMarkerStyle(7);g->SetMarkerColor(kRed);
232 g->SetLineColor(kRed);
235 g = new TGraphErrors();
236 g->SetMarkerStyle(7);g->SetMarkerColor(kBlue);
237 g->SetLineColor(kBlue);
240 g = new TGraphErrors();
241 g->SetMarkerStyle(7);g->SetMarkerColor(kGreen);
242 g->SetLineColor(kGreen);
245 g = new TGraphAsymmErrors(6);
246 g->SetMarkerStyle(22);g->SetMarkerColor(kRed);
247 g->SetLineColor(kBlack);g->SetLineWidth(2);
250 g = new TGraphAsymmErrors(6);
251 g->SetMarkerStyle(21);
252 g->SetLineColor(kRed);g->SetLineWidth(2);
255 AliWarning(Form("Graph index[%d] missing/not defined.", id));
258 g->SetNameTitle(name[id], title[id]);
259 fResults->AddAt(g, id);
265 //____________________________________________________________________
266 void AliTRDcheckESD::Exec(Option_t *){
271 AliError("ESD event missing.");
275 // Get MC information if available
276 AliStack * fStack = 0x0;
279 AliWarning("MC event missing");
282 if(!(fStack = fMC->Stack())){
283 AliWarning("MC stack missing");
288 Bool_t bTRDin(0), bTRDout(0), bTRDpid(0);
290 AliESDtrack *esdTrack = 0x0;
291 for(Int_t itrk = 0; itrk < fESD->GetNumberOfTracks(); itrk++){
292 bTRDin=0;bTRDout=0;bTRDpid=0;
293 esdTrack = fESD->GetTrack(itrk);
295 // if(esdTrack->GetNcls(1)) nTPC++;
296 // if(esdTrack->GetNcls(2)) nTRD++;
299 ULong_t status = esdTrack->GetStatus();
300 //PrintStatus(status);
302 // define TPC out tracks
303 if(!Bool_t(status & AliESDtrack::kTPCout)) continue;
304 if(esdTrack->GetKinkIndex(0) > 0) continue;
307 Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p);
309 //esdTrack->GetTRDntrackletsPID();
311 // look at external track param
312 const AliExternalTrackParam *op = esdTrack->GetOuterParam();
313 const AliExternalTrackParam *ip = esdTrack->GetInnerParam();
317 op->Global2LocalPosition(xyz, op->GetAlpha());
318 //printf("op @ X[%7.3f]\n", xyz[0]);
322 if(!HasMC()) continue;
324 Int_t fLabel = esdTrack->GetLabel();
325 if(TMath::Abs(fLabel) > fStack->GetNtrack()) continue;
328 AliMCParticle *mcParticle = 0x0;
329 if(!(mcParticle = (AliMCParticle*) fMC->GetTrack(TMath::Abs(fLabel)))){
330 AliWarning(Form("MC particle missing. Label[ %d].", fLabel));
334 AliTrackReference *ref = 0x0;
335 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
337 AliWarning(Form("Track refs missing. Label[%d].", fLabel));
342 ref = mcParticle->GetTrackReference(iref);
343 if(ref->LocalX() > fgkxTPC) break;
348 //TParticle *tParticle = mcParticle->Particle();
349 //Int_t fPdg = tParticle->GetPdgCode();
350 // reject secondaries
351 //if(!tParticle->IsPrimary()) continue;
354 if(ref->LocalX() > fgkxTOF){ // track skipping TRD fiducial volume
355 ref = mcParticle->GetTrackReference(TMath::Max(iref-1, 0));
358 if(esdTrack->GetNcls(2)) bTRDout=1;
359 if(esdTrack->GetTRDntrackletsPID()>=4) bTRDpid=1;
361 } else { // track stopped in TPC
362 ref = mcParticle->GetTrackReference(TMath::Max(iref-1, 0));
365 Float_t pt = ref->Pt();
367 TH2 *h = (TH2I*)fHistos->At(kTRDstat);
368 if(status & AliESDtrack::kTPCout) h->Fill(pt, kTPCout);
369 if(/*status & AliESDtrack::k*/bTRDin) h->Fill(pt, kTRDin);
370 if(/*status & AliESDtrack::k*/bTRDout){
371 ((TH1*)fHistos->At(kNCl))->Fill(esdTrack->GetNcls(2));
372 h->Fill(pt, kTRDout);
374 if(/*status & AliESDtrack::k*/bTRDpid) h->Fill(pt, kTRDpid);
375 if(status & AliESDtrack::kTRDrefit) h->Fill(pt, kTRDref);
378 h = (TH2I*)fHistos->At(kTRDmom);
380 for(Int_t ily=6; ily--;){
381 if((pp=esdTrack->GetTRDmomentum(ily))<0.) continue;
382 h->Fill(ip->GetP()-pp, ily);
386 PostData(0, fHistos);
389 //____________________________________________________________________
390 TObjArray* AliTRDcheckESD::Histos()
392 // Retrieve histograms array if already build or build it
394 if(fHistos) return fHistos;
396 fHistos = new TObjArray(kNhistos);
397 //fHistos->SetOwner(kTRUE);
401 // clusters per tracklet
402 if(!(h = (TH1I*)gROOT->FindObject("hNCl"))){
403 h = new TH1I("hNCl", "Clusters per TRD track", 100, 0., 200.);
404 h->GetXaxis()->SetTitle("N_{cl}^{TRD}");
405 h->GetYaxis()->SetTitle("entries");
407 fHistos->AddAt(h, kNCl);
409 // status bits histogram
410 if(!(h = (TH2I*)gROOT->FindObject("hTRDstat"))){
411 h = new TH2I("hTRDstat", "TRD status bits", 100, 0., 20., kNbits, .5, kNbits+.5);
412 h->GetXaxis()->SetTitle("p_{T} [GeV/c]");
413 h->GetYaxis()->SetTitle("status bits");
414 h->GetZaxis()->SetTitle("entries");
416 fHistos->AddAt(h, kTRDstat);
419 if(!(h = (TH2I*)gROOT->FindObject("hTRDmom"))){
420 h = new TH2I("hTRDmom", "TRD energy loss", 100, -1., 2., 6, -0.5, 5.5);
421 h->GetXaxis()->SetTitle("p_{inner} - p_{ly} [GeV/c]");
422 h->GetYaxis()->SetTitle("layer");
423 h->GetZaxis()->SetTitle("entries");
425 fHistos->AddAt(h, kTRDmom);
430 //____________________________________________________________________
431 Bool_t AliTRDcheckESD::Load(const Char_t *filename, const Char_t *name)
433 // Load data from performance file
435 if(!TFile::Open(filename)){
436 AliWarning(Form("Couldn't open file %s.", filename));
440 if(!(o = (TObjArray*)gFile->Get(name ? name : GetName()))){
441 AliWarning("Missing histogram container.");
444 fHistos = (TObjArray*)o->Clone(GetName());
449 //_______________________________________________________
450 Bool_t AliTRDcheckESD::PutTrendValue(const Char_t *name, Double_t val)
452 // Dump trending value to default file
455 fgFile = fopen("TRD.Performance.txt", "at");
457 fprintf(fgFile, "%s_%s %f\n", GetName(), name, val);
461 //____________________________________________________________________
462 void AliTRDcheckESD::Terminate(Option_t *)
464 // Steer post-processing
467 // geometrical efficiency
468 TH2I *h2 = (TH2I*)fHistos->At(kTRDstat);
469 TH1 *h1[2] = {0x0, 0x0};
470 h1[0] = h2->ProjectionX("checkESDx0", kTPCout, kTPCout);
471 h1[1] = h2->ProjectionX("checkESDx1", kTRDin, kTRDin);
472 Process(h1, (TGraphErrors*)GetGraph(0));
473 delete h1[0];delete h1[1];
475 // tracking efficiency
476 h1[0] = h2->ProjectionX("checkESDx0", kTRDin, kTRDin);
477 h1[1] = h2->ProjectionX("checkESDx1", kTRDout, kTRDout);
478 Process(h1, (TGraphErrors*)GetGraph(1));
482 h1[1] = h2->ProjectionX("checkESDx1", kTRDpid, kTRDpid);
483 Process(h1, (TGraphErrors*)GetGraph(2));
487 h1[1] = h2->ProjectionX("checkESDx1", kTRDref, kTRDref);
488 Process(h1, (TGraphErrors*)GetGraph(3));
490 if(!(h2 = dynamic_cast<TH2I*>(fHistos->At(kTRDmom)))) return;
492 TGraphAsymmErrors *g06 = (TGraphAsymmErrors*)GetGraph(4), *g09 = (TGraphAsymmErrors*)GetGraph(5);
493 TAxis *ax=h2->GetXaxis();
495 const Double_t xq[nq] = {0.05, 0.2, 0.8, 0.95};
497 for(Int_t ily=6; ily--;){
498 h1[0] = h2->ProjectionX("checkESDp0", ily+1, ily+1);
499 h1[0]->GetQuantiles(nq,yq,xq);
500 g06->SetPoint(ily, Float_t(ily), ax->GetBinCenter(h1[0]->GetMaximumBin()));
501 g06->SetPointError(ily, 0., 0., TMath::Abs(yq[0]), yq[3]);
502 g09->SetPoint(ily, Float_t(ily), h1[0]->GetMean());
503 g09->SetPointError(ily, 0., 0., TMath::Abs(yq[1]), yq[2]);
505 //printf(" max[%f] mean[%f] q[%f %f %f %f]\n", ax->GetBinCenter(h1[0]->GetMaximumBin()), h1[0]->GetMean(), yq[0], yq[1], yq[2], yq[3]);
510 //____________________________________________________________________
511 void AliTRDcheckESD::Process(TH1 **h1, TGraphErrors *g)
513 // Generic function to process one reference plot
515 Int_t n1 = 0, n2 = 0, ip=0;
518 TAxis *ax = h1[0]->GetXaxis();
519 for(Int_t ib=1; ib<=ax->GetNbins(); ib++){
520 if(!(n1 = (Int_t)h1[0]->GetBinContent(ib))) continue;
521 n2 = (Int_t)h1[1]->GetBinContent(ib);
522 eff = n2/Float_t(n1);
525 g->SetPoint(ip, ax->GetBinCenter(ib), eff);
526 g->SetPointError(ip, 0., n2 ? eff*TMath::Sqrt(1./n1+1./n2) : 0.);
530 //____________________________________________________________________
531 void AliTRDcheckESD::PrintStatus(ULong_t status)
533 // Dump track status to stdout
535 printf("ITS[i(%d) o(%d) r(%d)] TPC[i(%d) o(%d) r(%d) p(%d)] TRD[i(%d) o(%d) r(%d) p(%d) s(%d)] HMPID[o(%d) p(%d)]\n"
536 ,Bool_t(status & AliESDtrack::kITSin)
537 ,Bool_t(status & AliESDtrack::kITSout)
538 ,Bool_t(status & AliESDtrack::kITSrefit)
539 ,Bool_t(status & AliESDtrack::kTPCin)
540 ,Bool_t(status & AliESDtrack::kTPCout)
541 ,Bool_t(status & AliESDtrack::kTPCrefit)
542 ,Bool_t(status & AliESDtrack::kTPCpid)
543 ,Bool_t(status & AliESDtrack::kTRDin)
544 ,Bool_t(status & AliESDtrack::kTRDout)
545 ,Bool_t(status & AliESDtrack::kTRDrefit)
546 ,Bool_t(status & AliESDtrack::kTRDpid)
547 ,Bool_t(status & AliESDtrack::kTRDStop)
548 ,Bool_t(status & AliESDtrack::kHMPIDout)
549 ,Bool_t(status & AliESDtrack::kHMPIDpid)