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 = NULL;
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() : NULL;
107 AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
108 fMC = mcH ? mcH->MCEvent() : NULL;
111 //____________________________________________________________________
112 void AliTRDcheckESD::CreateOutputObjects()
115 // Create Output Containers (TObjectArray containing 1D histograms)
117 //OpenFile(0, "RECREATE");
122 //____________________________________________________________________
123 TGraph* AliTRDcheckESD::GetGraph(Int_t id, Option_t *opt)
125 // Retrieve graph with "id"
126 // Possible options are :
127 // "b" - build graph if none found
128 // "c" - clear existing graph
130 Bool_t kBUILD = strstr(opt, "b"), // build graph if none found
131 kCLEAR = strstr(opt, "c"); // clear existing graph
133 const Char_t *name[] = {
134 "Geo", "Trk", "Pid", "Ref", "Max06", "Mean09"
136 const Char_t *title[] = {
137 "TRD geometrical efficiency (TRDin/TPCout)"
138 ,"TRD tracking efficiency (TRDout/TRDin)"
139 ,"TRD PID efficiency (TRDpid/TRDin)"
140 ,"TRD refit efficiency (TRDrefit/TRDin)"
141 ,"TRD Eloss (Max/90% quantile)"
142 ,"TRD Eloss (Mean/60% quantile)"
144 const Int_t ngr = sizeof(name)/sizeof(Char_t*);
146 AliWarning("No of graphs defined different from definition");
151 fResults = new TObjArray(kNgraphs);
152 fResults->SetOwner();
153 fResults->SetName("results");
157 if((g = dynamic_cast<TGraph*>(fResults->At(id)))){
159 for(Int_t ip=g->GetN(); ip--;) g->RemovePoint(ip);
161 PutTrendValue(name[id], g->GetMean(2));
162 PutTrendValue(Form("%sRMS", name[id]), g->GetRMS(2));
168 g = new TGraphErrors();
171 g = new TGraphErrors();
174 g = new TGraphErrors();
177 g = new TGraphErrors();
180 g = new TGraphAsymmErrors(6);
181 g->SetMarkerStyle(22);g->SetMarkerColor(kRed);
182 g->SetLineColor(kBlack);g->SetLineWidth(2);
185 g = new TGraphAsymmErrors(6);
186 g->SetMarkerStyle(21);
187 g->SetLineColor(kRed);g->SetLineWidth(2);
190 AliWarning(Form("Graph index[%d] missing/not defined.", id));
193 g->SetNameTitle(name[id], title[id]);
194 fResults->AddAt(g, id);
200 //____________________________________________________________________
201 void AliTRDcheckESD::Exec(Option_t *){
206 AliError("ESD event missing.");
210 // Get MC information if available
211 AliStack * fStack = NULL;
214 AliWarning("MC event missing");
217 if(!(fStack = fMC->Stack())){
218 AliWarning("MC stack missing");
225 AliESDtrack *esdTrack(NULL);
226 for(Int_t itrk = 0; itrk < fESD->GetNumberOfTracks(); itrk++){
227 esdTrack = fESD->GetTrack(itrk);
229 // if(esdTrack->GetNcls(1)) nTPC++;
230 // if(esdTrack->GetNcls(2)) nTRD++;
233 ULong_t status = esdTrack->GetStatus();
234 //PrintStatus(status);
236 // define TPC out tracks
237 if(!Bool_t(status & AliESDtrack::kTPCout)) continue;
238 if(esdTrack->GetKinkIndex(0) > 0) continue;
241 Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p);
243 //esdTrack->GetTRDntrackletsPID();
245 // look at external track param
246 const AliExternalTrackParam *op = esdTrack->GetOuterParam();
247 const AliExternalTrackParam *ip = esdTrack->GetInnerParam();
249 Float_t pt(0.); Bool_t kFOUND(kFALSE);
251 // read MC info if available
253 AliTrackReference *ref(NULL);
254 Int_t fLabel(esdTrack->GetLabel());
255 if(TMath::Abs(fLabel) > fStack->GetNtrack()) continue;
258 AliMCParticle *mcParticle(NULL);
259 if(!(mcParticle = (AliMCParticle*) fMC->GetTrack(TMath::Abs(fLabel)))){
260 AliWarning(Form("MC particle missing. Label[ %d].", fLabel));
264 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
266 AliWarning(Form("Track refs missing. Label[%d].", fLabel));
271 ref = mcParticle->GetTrackReference(iref);
272 if(ref->LocalX() > fgkxTPC) break;
276 if(ref->LocalX() > fgkxTOF){ // track skipping TRD fiducial volume
277 ref = mcParticle->GetTrackReference(TMath::Max(iref-1, 0));
279 } else { // track stopped in TPC
280 ref = mcParticle->GetTrackReference(TMath::Max(iref-1, 0));
282 pt = ref->Pt();kFOUND=kTRUE;
283 } else { // use reconstructed values
285 Double_t x(op->GetX());
286 if(x<fgkxTOF && x>fgkxTPC){
299 h = (TH2I*)fHistos->At(kTRDstat);
300 if(status & AliESDtrack::kTPCout) h->Fill(pt, kTPCout);
301 if(status & AliESDtrack::kTRDin) h->Fill(pt, kTRDin);
302 if(status & AliESDtrack::kTRDout){
303 ((TH1*)fHistos->At(kNCl))->Fill(esdTrack->GetNcls(2));
304 h->Fill(pt, kTRDout);
306 if(status & AliESDtrack::kTRDpid) h->Fill(pt, kTRDpid);
307 if(status & AliESDtrack::kTRDrefit) h->Fill(pt, kTRDref);
311 h = (TH2I*)fHistos->At(kTRDmom);
313 for(Int_t ily=6; ily--;){
314 if((p=esdTrack->GetTRDmomentum(ily))<0.) continue;
315 h->Fill(ip->GetP()-p, ily);
319 PostData(0, fHistos);
322 //____________________________________________________________________
323 TObjArray* AliTRDcheckESD::Histos()
325 // Retrieve histograms array if already build or build it
327 if(fHistos) return fHistos;
329 fHistos = new TObjArray(kNhistos);
330 //fHistos->SetOwner(kTRUE);
334 // clusters per tracklet
335 if(!(h = (TH1I*)gROOT->FindObject("hNCl"))){
336 h = new TH1I("hNCl", "Clusters per TRD track", 100, 0., 200.);
337 h->GetXaxis()->SetTitle("N_{cl}^{TRD}");
338 h->GetYaxis()->SetTitle("entries");
340 fHistos->AddAt(h, kNCl);
342 // status bits histogram
343 if(!(h = (TH2I*)gROOT->FindObject("hTRDstat"))){
344 h = new TH2I("hTRDstat", "TRD status bits", 100, 0., 20., kNbits, .5, kNbits+.5);
345 h->GetXaxis()->SetTitle("p_{T} [GeV/c]");
346 h->GetYaxis()->SetTitle("status bits");
347 h->GetZaxis()->SetTitle("entries");
349 fHistos->AddAt(h, kTRDstat);
352 if(!(h = (TH2I*)gROOT->FindObject("hTRDmom"))){
353 h = new TH2I("hTRDmom", "TRD energy loss", 100, -1., 2., 6, -0.5, 5.5);
354 h->GetXaxis()->SetTitle("p_{inner} - p_{ly} [GeV/c]");
355 h->GetYaxis()->SetTitle("layer");
356 h->GetZaxis()->SetTitle("entries");
358 fHistos->AddAt(h, kTRDmom);
363 //____________________________________________________________________
364 Bool_t AliTRDcheckESD::Load(const Char_t *filename, const Char_t *name)
366 // Load data from performance file
368 if(!TFile::Open(filename)){
369 AliWarning(Form("Couldn't open file %s.", filename));
373 if(!(o = (TObjArray*)gFile->Get(name ? name : GetName()))){
374 AliWarning("Missing histogram container.");
377 fHistos = (TObjArray*)o->Clone(GetName());
379 SETBIT(fStatus, kLoad);
383 //_______________________________________________________
384 Bool_t AliTRDcheckESD::PutTrendValue(const Char_t *name, Double_t val)
386 // Dump trending value to default file
389 fgFile = fopen("TRD.Performance.txt", "at");
391 fprintf(fgFile, "%s_%s %f\n", GetName(), name, val);
395 //____________________________________________________________________
396 void AliTRDcheckESD::Terminate(Option_t *)
398 // Steer post-processing
400 fHistos = dynamic_cast<TObjArray *>(GetOutputData(0));
402 AliError("Histogram container not found in output");
407 // geometrical efficiency
408 TH2I *h2 = (TH2I*)fHistos->At(kTRDstat);
409 TH1 *h1[2] = {NULL, NULL};
410 h1[0] = h2->ProjectionX("checkESDx0", kTPCout, kTPCout);
411 h1[1] = h2->ProjectionX("checkESDx1", kTRDin, kTRDin);
412 Process(h1, (TGraphErrors*)GetGraph(0));
413 delete h1[0];delete h1[1];
415 // tracking efficiency
416 h1[0] = h2->ProjectionX("checkESDx0", kTRDin, kTRDin);
417 h1[1] = h2->ProjectionX("checkESDx1", kTRDout, kTRDout);
418 Process(h1, (TGraphErrors*)GetGraph(1));
422 h1[1] = h2->ProjectionX("checkESDx1", kTRDpid, kTRDpid);
423 Process(h1, (TGraphErrors*)GetGraph(2));
427 h1[1] = h2->ProjectionX("checkESDx1", kTRDref, kTRDref);
428 Process(h1, (TGraphErrors*)GetGraph(3));
430 if(!(h2 = dynamic_cast<TH2I*>(fHistos->At(kTRDmom)))) return;
432 TGraphAsymmErrors *g06 = (TGraphAsymmErrors*)GetGraph(4), *g09 = (TGraphAsymmErrors*)GetGraph(5);
433 TAxis *ax=h2->GetXaxis();
435 const Double_t xq[nq] = {0.05, 0.2, 0.8, 0.95};
437 for(Int_t ily=6; ily--;){
438 h1[0] = h2->ProjectionX("checkESDp0", ily+1, ily+1);
439 h1[0]->GetQuantiles(nq,yq,xq);
440 g06->SetPoint(ily, Float_t(ily), ax->GetBinCenter(h1[0]->GetMaximumBin()));
441 g06->SetPointError(ily, 0., 0., TMath::Abs(yq[0]), yq[3]);
442 g09->SetPoint(ily, Float_t(ily), h1[0]->GetMean());
443 g09->SetPointError(ily, 0., 0., TMath::Abs(yq[1]), yq[2]);
445 //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]);
450 //____________________________________________________________________
451 void AliTRDcheckESD::Process(TH1 **h1, TGraphErrors *g)
453 // Generic function to process one reference plot
455 Int_t n1 = 0, n2 = 0, ip=0;
458 TAxis *ax = h1[0]->GetXaxis();
459 for(Int_t ib=1; ib<=ax->GetNbins(); ib++){
460 if(!(n1 = (Int_t)h1[0]->GetBinContent(ib))) continue;
461 n2 = (Int_t)h1[1]->GetBinContent(ib);
462 eff = n2/Float_t(n1);
465 g->SetPoint(ip, ax->GetBinCenter(ib), eff);
466 g->SetPointError(ip, 0., n2 ? eff*TMath::Sqrt(1./n1+1./n2) : 0.);
470 //____________________________________________________________________
471 void AliTRDcheckESD::PrintStatus(ULong_t status)
473 // Dump track status to stdout
475 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"
476 ,Bool_t(status & AliESDtrack::kITSin)
477 ,Bool_t(status & AliESDtrack::kITSout)
478 ,Bool_t(status & AliESDtrack::kITSrefit)
479 ,Bool_t(status & AliESDtrack::kTPCin)
480 ,Bool_t(status & AliESDtrack::kTPCout)
481 ,Bool_t(status & AliESDtrack::kTPCrefit)
482 ,Bool_t(status & AliESDtrack::kTPCpid)
483 ,Bool_t(status & AliESDtrack::kTRDin)
484 ,Bool_t(status & AliESDtrack::kTRDout)
485 ,Bool_t(status & AliESDtrack::kTRDrefit)
486 ,Bool_t(status & AliESDtrack::kTRDpid)
487 ,Bool_t(status & AliESDtrack::kTRDStop)
488 ,Bool_t(status & AliESDtrack::kHMPIDout)
489 ,Bool_t(status & AliESDtrack::kHMPIDpid)