9a281e83 |
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 | |
16 | |
17 | #include <TClonesArray.h> |
18 | #include <TObjArray.h> |
19 | #include <TObject.h> |
20 | #include <TH2I.h> |
48797466 |
21 | #include <TGraphErrors.h> |
9a281e83 |
22 | #include <TFile.h> |
23 | #include <TTree.h> |
24 | #include <TROOT.h> |
25 | #include <TChain.h> |
26 | #include <TParticle.h> |
27 | |
28 | #include "AliLog.h" |
29 | #include "AliAnalysisManager.h" |
30 | #include "AliESDEvent.h" |
d12237d6 |
31 | #include "AliESDkink.h" |
9a281e83 |
32 | #include "AliMCEvent.h" |
33 | #include "AliESDInputHandler.h" |
34 | #include "AliMCEventHandler.h" |
35 | |
36 | #include "AliESDtrack.h" |
37 | #include "AliMCParticle.h" |
38 | #include "AliPID.h" |
39 | #include "AliStack.h" |
40 | #include "AliTrackReference.h" |
9a281e83 |
41 | |
42 | #include "AliTRDcheckESD.h" |
43 | |
44 | ClassImp(AliTRDcheckESD) |
45 | |
965e895b |
46 | const Int_t AliTRDcheckESD::fgkNgraphs = 4; |
47 | const Float_t AliTRDcheckESD::fgkxTPC = 290.; |
48 | const Float_t AliTRDcheckESD::fgkxTOF = 365.; |
9a281e83 |
49 | |
50 | //____________________________________________________________________ |
51 | AliTRDcheckESD::AliTRDcheckESD(): |
52 | AliAnalysisTask("ESDchecker", "TRD checker @ ESD level") |
53 | ,fStatus(0) |
54 | ,fESD(0x0) |
55 | ,fMC(0x0) |
56 | ,fHistos(0x0) |
57 | { |
58 | // |
59 | // Default constructor |
60 | // |
49c7f0a5 |
61 | SetMC(kTRUE); |
9a281e83 |
62 | DefineInput(0, TChain::Class()); |
63 | DefineOutput(0, TObjArray::Class()); |
64 | } |
65 | |
66 | //____________________________________________________________________ |
67 | AliTRDcheckESD::~AliTRDcheckESD() |
68 | { |
69 | if(fHistos){ |
70 | //fHistos->Delete(); |
71 | delete fHistos; |
72 | } |
73 | } |
74 | |
75 | //____________________________________________________________________ |
76 | void AliTRDcheckESD::ConnectInputData(Option_t *) |
77 | { |
78 | // |
79 | // Link the Input Data |
80 | // |
81 | TTree *tree = dynamic_cast<TChain*>(GetInputData(0)); |
82 | if(tree) tree->SetBranchStatus("Tracks", 1); |
83 | |
84 | AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()); |
85 | fESD = esdH ? esdH->GetEvent() : 0x0; |
86 | |
87 | if(!HasMC()) return; |
88 | AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()); |
89 | fMC = mcH ? mcH->MCEvent() : 0x0; |
90 | } |
91 | |
92 | //____________________________________________________________________ |
93 | void AliTRDcheckESD::CreateOutputObjects() |
94 | { |
95 | // |
96 | // Create Output Containers (TObjectArray containing 1D histograms) |
97 | // |
98 | OpenFile(0, "RECREATE"); |
c2fd5953 |
99 | Histos(); |
9a281e83 |
100 | } |
101 | |
965e895b |
102 | //____________________________________________________________________ |
103 | TGraphErrors* AliTRDcheckESD::GetGraph(Int_t id, Option_t*) |
104 | { |
105 | Bool_t kBUILD = 1, // build graph if none found |
106 | kCLEAR = 1; // clear existing graph |
107 | |
108 | const Char_t *name[] = { |
109 | "Geo", "Trk", "Pid", "Ref" |
110 | }; |
111 | const Char_t *title[] = { |
112 | "TRD geometrical efficiency (TRDin/TPCout)" |
113 | ,"TRD tracking efficiency (TRDout/TRDin)" |
114 | ,"TRD PID efficiency (TRDpid/TRDin)" |
115 | ,"TRD refit efficiency (TRDrefit/TRDin)" |
116 | }; |
117 | const Int_t ngr = sizeof(name)/sizeof(Char_t*); |
118 | if(ngr != fgkNgraphs){ |
119 | AliWarning("No of graphs defined different from definition"); |
120 | return 0x0; |
121 | } |
122 | |
123 | TObjArray *res = 0x0; |
124 | if(!(res = (TObjArray*)fHistos->At(kResults)) || |
125 | (id < 0 || id >= ngr)){ |
126 | AliWarning("Graph missing."); |
127 | return 0x0; |
128 | } |
129 | |
130 | TGraphErrors *g = 0x0; |
131 | if((g = dynamic_cast<TGraphErrors*>(res->At(id)))){ |
132 | if(kCLEAR) for(Int_t ip=g->GetN(); ip--;) g->RemovePoint(ip); |
133 | } else { |
134 | if(kBUILD){ |
135 | g = new TGraphErrors(); |
136 | g->SetNameTitle(name[id], title[id]); |
137 | res->AddAt(g, id); |
138 | } |
139 | } |
140 | return g; |
141 | } |
142 | |
9a281e83 |
143 | //____________________________________________________________________ |
144 | void AliTRDcheckESD::Exec(Option_t *){ |
145 | // |
146 | // Run the Analysis |
147 | // |
148 | if(!fESD){ |
48797466 |
149 | AliError("ESD event missing."); |
9a281e83 |
150 | return; |
151 | } |
152 | |
153 | // Get MC information if available |
154 | AliStack * fStack = 0x0; |
155 | if(HasMC() && !fMC){ |
48797466 |
156 | AliWarning("MC event missing"); |
9a281e83 |
157 | SetMC(kFALSE); |
158 | } else { |
159 | if(!(fStack = fMC->Stack())){ |
48797466 |
160 | AliWarning("MC stack missing"); |
9a281e83 |
161 | SetMC(kFALSE); |
162 | } |
163 | } |
d12237d6 |
164 | Bool_t TRDin(0), TRDout(0), TRDpid(0); |
9a281e83 |
165 | |
9a281e83 |
166 | AliESDtrack *esdTrack = 0x0; |
167 | for(Int_t itrk = 0; itrk < fESD->GetNumberOfTracks(); itrk++){ |
d12237d6 |
168 | TRDin=0;TRDout=0;TRDpid=0; |
9a281e83 |
169 | esdTrack = fESD->GetTrack(itrk); |
d12237d6 |
170 | |
171 | // if(esdTrack->GetNcls(1)) nTPC++; |
172 | // if(esdTrack->GetNcls(2)) nTRD++; |
9a281e83 |
173 | |
174 | // track status |
d12237d6 |
175 | ULong_t status = esdTrack->GetStatus(); |
176 | |
177 | // define TPC out tracks |
178 | if(!Bool_t(status & AliESDtrack::kTPCout)) continue; |
179 | if(esdTrack->GetKinkIndex(0) > 0) continue; |
9a281e83 |
180 | |
181 | // TRD PID |
182 | Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p); |
183 | // pid quality |
184 | esdTrack->GetTRDpidQuality(); |
9a281e83 |
185 | |
186 | // look at external track param |
187 | const AliExternalTrackParam *op = esdTrack->GetOuterParam(); |
188 | Double_t xyz[3]; |
189 | if(op){ |
190 | op->GetXYZ(xyz); |
191 | op->Global2LocalPosition(xyz, op->GetAlpha()); |
192 | //printf("op @ X[%7.3f]\n", xyz[0]); |
193 | } |
194 | |
195 | // read MC info |
196 | if(!HasMC()) continue; |
197 | |
198 | Int_t fLabel = esdTrack->GetLabel(); |
199 | if(TMath::Abs(fLabel) > fStack->GetNtrack()) continue; |
200 | |
201 | // read MC particle |
202 | AliMCParticle *mcParticle = 0x0; |
203 | if(!(mcParticle = fMC->GetTrack(TMath::Abs(fLabel)))){ |
48797466 |
204 | AliWarning(Form("MC particle missing. Label[ %d].", fLabel)); |
9a281e83 |
205 | continue; |
206 | } |
207 | |
208 | AliTrackReference *ref = 0x0; |
209 | Int_t nRefs = mcParticle->GetNumberOfTrackReferences(); |
48797466 |
210 | if(!nRefs){ |
211 | AliWarning(Form("Track refs missing. Label[%d].", fLabel)); |
212 | continue; |
213 | } |
9a281e83 |
214 | Int_t iref = 0; |
215 | while(iref<nRefs){ |
216 | ref = mcParticle->GetTrackReference(iref); |
965e895b |
217 | if(ref->LocalX() > fgkxTPC) break; |
9a281e83 |
218 | ref=0x0; iref++; |
219 | } |
220 | |
221 | // read TParticle |
965e895b |
222 | //TParticle *tParticle = mcParticle->Particle(); |
48797466 |
223 | //Int_t fPdg = tParticle->GetPdgCode(); |
d12237d6 |
224 | // reject secondaries |
225 | //if(!tParticle->IsPrimary()) continue; |
9a281e83 |
226 | |
d12237d6 |
227 | if(ref){ |
965e895b |
228 | if(ref->LocalX() > fgkxTOF){ // track skipping TRD fiducial volume |
48797466 |
229 | ref = mcParticle->GetTrackReference(TMath::Max(iref-1, 0)); |
9a281e83 |
230 | } else { |
d12237d6 |
231 | TRDin=1; |
232 | if(esdTrack->GetNcls(2)) TRDout=1; |
965e895b |
233 | if(esdTrack->GetTRDpidQuality()>=4) TRDpid=1; |
9a281e83 |
234 | } |
d12237d6 |
235 | } else { // track stopped in TPC |
48797466 |
236 | ref = mcParticle->GetTrackReference(TMath::Max(iref-1, 0)); |
237 | } |
d12237d6 |
238 | // get the MC pt !! |
9a281e83 |
239 | Float_t pt = ref->Pt(); |
d12237d6 |
240 | |
9a281e83 |
241 | TH2 *h = (TH2I*)fHistos->At(kTRDstat); |
d12237d6 |
242 | if(status & AliESDtrack::kTPCout) h->Fill(pt, kTPCout); |
243 | if(/*status & AliESDtrack::k*/TRDin) h->Fill(pt, kTRDin); |
9a281e83 |
244 | if(/*status & AliESDtrack::k*/TRDout){ |
245 | ((TH1*)fHistos->At(kNCl))->Fill(esdTrack->GetNcls(2)); |
d12237d6 |
246 | h->Fill(pt, kTRDout); |
9a281e83 |
247 | } |
965e895b |
248 | if(/*status & AliESDtrack::k*/TRDpid) h->Fill(pt, kTRDpid); |
249 | if(status & AliESDtrack::kTRDrefit) h->Fill(pt, kTRDref); |
9a281e83 |
250 | } |
9a281e83 |
251 | PostData(0, fHistos); |
252 | } |
253 | |
c2fd5953 |
254 | //____________________________________________________________________ |
255 | TObjArray* AliTRDcheckESD::Histos() |
256 | { |
257 | if(fHistos) return fHistos; |
258 | |
259 | fHistos = new TObjArray(kNhistos); |
260 | //fHistos->SetOwner(kTRUE); |
261 | |
262 | TH1 *h = 0x0; |
263 | |
264 | // clusters per tracklet |
265 | if(!(h = (TH1I*)gROOT->FindObject("hNCl"))){ |
266 | h = new TH1I("hNCl", "Clusters per TRD track", 100, 0., 200.); |
267 | h->GetXaxis()->SetTitle("N_{cl}^{TRD}"); |
268 | h->GetYaxis()->SetTitle("entries"); |
269 | } else h->Reset(); |
270 | fHistos->AddAt(h, kNCl); |
271 | |
272 | // status bits histogram |
273 | if(!(h = (TH2I*)gROOT->FindObject("hTRDstat"))){ |
274 | h = new TH2I("hTRDstat", "TRD status bits", 100, 0., 20., kNbits, .5, kNbits+.5); |
275 | h->GetXaxis()->SetTitle("p_{T} [GeV/c]"); |
276 | h->GetYaxis()->SetTitle("status bits"); |
277 | h->GetZaxis()->SetTitle("entries"); |
278 | } else h->Reset(); |
279 | fHistos->AddAt(h, kTRDstat); |
280 | |
281 | // results array |
282 | TObjArray *res = new TObjArray(); |
283 | res->SetName("Results"); |
284 | fHistos->AddAt(res, kResults); |
285 | return fHistos; |
286 | } |
287 | |
965e895b |
288 | //____________________________________________________________________ |
289 | Bool_t AliTRDcheckESD::Load(const Char_t *filename, const Char_t *name) |
290 | { |
291 | if(!TFile::Open(filename)){ |
292 | AliWarning(Form("Couldn't open file %s.", filename)); |
293 | return kFALSE; |
294 | } |
295 | TObjArray *o = 0x0; |
296 | if(!(o = (TObjArray*)gFile->Get(name ? name : GetName()))){ |
297 | AliWarning("Missing histogram container."); |
298 | return kFALSE; |
299 | } |
300 | fHistos = (TObjArray*)o->Clone(GetName()); |
301 | gFile->Close(); |
302 | return kTRUE; |
303 | } |
9a281e83 |
304 | |
305 | //____________________________________________________________________ |
306 | void AliTRDcheckESD::Terminate(Option_t *) |
307 | { |
965e895b |
308 | TObjArray *res = 0x0; |
309 | if(!(res = (TObjArray*)fHistos->At(kResults))){ |
310 | AliWarning("Graph container missing."); |
311 | return; |
312 | } |
313 | if(!res->GetEntriesFast()) res->Expand(fgkNgraphs); |
48797466 |
314 | |
315 | // geometrical efficiency |
965e895b |
316 | TH2I *h2 = (TH2I*)fHistos->At(kTRDstat); |
317 | TH1 *h1[2] = {0x0, 0x0}; |
d12237d6 |
318 | h1[0] = h2->ProjectionX("px0", kTPCout, kTPCout); |
319 | h1[1] = h2->ProjectionX("px1", kTRDin, kTRDin); |
965e895b |
320 | Process(h1, GetGraph(0)); |
48797466 |
321 | |
322 | // tracking efficiency |
d12237d6 |
323 | h1[0] = h2->ProjectionX("px0", kTRDin, kTRDin); |
324 | h1[1] = h2->ProjectionX("px1", kTRDout, kTRDout); |
965e895b |
325 | Process(h1, GetGraph(1)); |
48797466 |
326 | |
327 | // PID efficiency |
965e895b |
328 | //h1[0] = h2->ProjectionX("px0", kTRDin, kTRDin); |
d12237d6 |
329 | h1[1] = h2->ProjectionX("px1", kTRDpid, kTRDpid); |
965e895b |
330 | Process(h1, GetGraph(2)); |
331 | |
332 | // Refit efficiency |
333 | //h1[0] = h2->ProjectionX("px0", kTRDin, kTRDin); |
334 | h1[1] = h2->ProjectionX("px1", kTRDref, kTRDref); |
335 | Process(h1, GetGraph(3)); |
336 | } |
337 | |
338 | //____________________________________________________________________ |
339 | void AliTRDcheckESD::Process(TH1 **h1, TGraphErrors *g) |
340 | { |
341 | Int_t n1 = 0, n2 = 0, ip=0; |
342 | Double_t eff = 0.; |
343 | |
344 | TAxis *ax = h1[0]->GetXaxis(); |
48797466 |
345 | for(Int_t ib=1; ib<=ax->GetNbins(); ib++){ |
346 | if(!(n1 = (Int_t)h1[0]->GetBinContent(ib))) continue; |
347 | n2 = (Int_t)h1[1]->GetBinContent(ib); |
348 | eff = n2/Float_t(n1); |
349 | |
350 | ip=g->GetN(); |
351 | g->SetPoint(ip, ax->GetBinCenter(ib), eff); |
352 | g->SetPointError(ip, 0., n2 ? eff*TMath::Sqrt(1./n1+1./n2) : 0.); |
353 | } |
9a281e83 |
354 | } |