]>
Commit | Line | Data |
---|---|---|
1ee39b3a | 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 | /* $Id: AliTRDinfoGen.cxx 27496 2008-07-22 08:35:45Z cblume $ */ | |
17 | ||
18 | //////////////////////////////////////////////////////////////////////////// | |
19 | // | |
20 | // Tender wagon for TRD performance/calibration train | |
21 | // | |
22 | // In this wagon the information from | |
23 | // - ESD | |
24 | // - Friends [if available] | |
25 | // - MC [if available] | |
26 | // are grouped into AliTRDtrackInfo objects and fed to worker tasks | |
27 | // | |
28 | // Authors: | |
29 | // Markus Fasel <M.Fasel@gsi.de> | |
30 | // Alexandru Bercuci <A.Bercuci@gsi.de> | |
31 | // | |
32 | //////////////////////////////////////////////////////////////////////////// | |
33 | ||
34 | #include <TClonesArray.h> | |
35 | #include <TObjArray.h> | |
36 | #include <TObject.h> | |
37 | #include <TH1F.h> | |
38 | #include <TFile.h> | |
39 | #include <TTree.h> | |
40 | #include <TROOT.h> | |
41 | #include <TChain.h> | |
42 | #include <TParticle.h> | |
43 | ||
44 | #include "AliLog.h" | |
45 | #include "AliAnalysisManager.h" | |
46 | #include "AliESDEvent.h" | |
47 | #include "AliMCEvent.h" | |
48 | #include "AliESDInputHandler.h" | |
49 | #include "AliMCEventHandler.h" | |
50 | ||
51 | #include "AliESDfriend.h" | |
52 | #include "AliESDfriendTrack.h" | |
53 | #include "AliESDHeader.h" | |
54 | #include "AliESDtrack.h" | |
55 | #include "AliMCParticle.h" | |
56 | #include "AliPID.h" | |
57 | #include "AliStack.h" | |
58 | #include "AliTRDtrackV1.h" | |
59 | #include "AliTrackReference.h" | |
60 | #include "AliTRDgeometry.h" | |
61 | #include "AliTRDcluster.h" | |
62 | #include "AliTRDseedV1.h" | |
63 | #include "TTreeStream.h" | |
64 | ||
65 | #include <cstdio> | |
66 | #include <climits> | |
67 | #include <cstring> | |
68 | #include <iostream> | |
69 | ||
70 | #include "AliTRDinfoGen.h" | |
71 | #include "info/AliTRDtrackInfo.h" | |
72 | #include "info/AliTRDeventInfo.h" | |
73 | #include "info/AliTRDv0Info.h" | |
74 | ||
75 | ClassImp(AliTRDinfoGen) | |
76 | ||
77 | const Float_t AliTRDinfoGen::fgkTPC = 290.; | |
78 | const Float_t AliTRDinfoGen::fgkTOF = 365.; | |
79 | ||
3f19c2cd | 80 | const Float_t AliTRDinfoGen::fgkEvVertexZ = 15.; |
81 | const Int_t AliTRDinfoGen::fgkEvVertexN = 1; | |
82 | ||
83 | const Float_t AliTRDinfoGen::fgkTrkDCAxy = 40.; | |
84 | const Float_t AliTRDinfoGen::fgkTrkDCAz = 15.; | |
85 | const Int_t AliTRDinfoGen::fgkNclTPC = 10; | |
86 | const Float_t AliTRDinfoGen::fgkPt = 0.2; | |
87 | const Float_t AliTRDinfoGen::fgkEta = 0.9; | |
88 | ||
1ee39b3a | 89 | //____________________________________________________________________ |
90 | AliTRDinfoGen::AliTRDinfoGen(): | |
f8f46e4d | 91 | AliTRDrecoTask() |
3f19c2cd | 92 | ,fEvTrigger("CINT1B-ABCE-NOPF-ALL") |
770382d9 | 93 | ,fESDev(NULL) |
94 | ,fMCev(NULL) | |
770382d9 | 95 | ,fTrackInfo(NULL) |
96 | ,fEventInfo(NULL) | |
97 | ,fV0container(NULL) | |
98 | ,fV0Info(NULL) | |
1ee39b3a | 99 | { |
100 | // | |
101 | // Default constructor | |
102 | // | |
f8f46e4d | 103 | } |
1ee39b3a | 104 | |
f8f46e4d | 105 | AliTRDinfoGen::AliTRDinfoGen(char* name): |
106 | AliTRDrecoTask(name, "MC-REC TRD-track list generator") | |
107 | ,fESDev(NULL) | |
108 | ,fMCev(NULL) | |
109 | ,fTrackInfo(NULL) | |
110 | ,fEventInfo(NULL) | |
111 | ,fV0container(NULL) | |
112 | ,fV0Info(NULL) | |
113 | { | |
114 | // | |
115 | // Default constructor | |
116 | // | |
117 | DefineOutput(2, AliTRDeventInfo::Class()); // -> TRDeventInfo | |
118 | DefineOutput(3, TObjArray::Class()); // -> TObjArray | |
1ee39b3a | 119 | } |
120 | ||
121 | //____________________________________________________________________ | |
122 | AliTRDinfoGen::~AliTRDinfoGen() | |
123 | { | |
124 | // Destructor | |
770382d9 | 125 | |
770382d9 | 126 | if(fTrackInfo) delete fTrackInfo; fTrackInfo = NULL; |
770382d9 | 127 | if(fEventInfo) delete fEventInfo; fEventInfo = NULL; |
770382d9 | 128 | if(fV0Info) delete fV0Info; fV0Info = NULL; |
1ee39b3a | 129 | if(fContainer){ |
130 | fContainer->Delete(); delete fContainer; | |
770382d9 | 131 | fContainer = NULL; |
1ee39b3a | 132 | } |
133 | if(fV0container){ | |
134 | fV0container->Delete(); delete fV0container; | |
770382d9 | 135 | fV0container = NULL; |
1ee39b3a | 136 | } |
137 | } | |
138 | ||
139 | //____________________________________________________________________ | |
f8f46e4d | 140 | void AliTRDinfoGen::UserCreateOutputObjects() |
1ee39b3a | 141 | { |
142 | // | |
143 | // Create Output Containers (TObjectArray containing 1D histograms) | |
144 | // | |
145 | fTrackInfo = new AliTRDtrackInfo(); | |
146 | fEventInfo = new AliTRDeventInfo(); | |
147 | fV0Info = new AliTRDv0Info(); | |
148 | fContainer = new TObjArray(1000); | |
149 | fContainer->SetOwner(kTRUE); | |
150 | fV0container = new TObjArray(50); | |
151 | fV0container->SetOwner(kTRUE); | |
152 | ||
153 | } | |
154 | ||
155 | //____________________________________________________________________ | |
f8f46e4d | 156 | void AliTRDinfoGen::UserExec(Option_t *){ |
1ee39b3a | 157 | // |
158 | // Run the Analysis | |
159 | // | |
f8f46e4d | 160 | fESDev = dynamic_cast<AliESDEvent*>(InputEvent()); |
161 | fMCev = MCEvent(); | |
162 | ||
1ee39b3a | 163 | if(!fESDev){ |
164 | AliError("Failed retrieving ESD event"); | |
165 | return; | |
166 | } | |
3f19c2cd | 167 | |
168 | // event selection : trigger cut | |
169 | if(UseLocalEvSelection() && | |
170 | fEvTrigger.Data()[0]!='\0'){ | |
171 | Bool_t kTRIGGERED(kFALSE); | |
172 | const TObjArray *trig = fEvTrigger.Tokenize(" "); | |
173 | for(Int_t itrig=trig->GetEntriesFast(); itrig--;){ | |
174 | const Char_t *trigClass(((TObjString*)(*trig)[itrig])->GetName()); | |
175 | if(fESDev->IsTriggerClassFired(trigClass)) { | |
176 | AliDebug(2, Form("Ev[%4d] Trigger[%s]", fESDev->GetEventNumberInFile(), trigClass)); | |
177 | kTRIGGERED = kTRUE; | |
178 | break; | |
179 | } | |
180 | } | |
181 | if(!kTRIGGERED) return; | |
182 | ||
183 | // select only physical events | |
184 | if(fESDev->GetEventType() != 7) return; | |
185 | } | |
186 | ||
187 | // if the required trigger is a collision trigger then apply event vertex cut | |
188 | if(UseLocalEvSelection() && IsCollision()){ | |
189 | const AliESDVertex *vertex = fESDev->GetPrimaryVertex(); | |
190 | if(TMath::Abs(vertex->GetZv())<1.e-10 || | |
191 | TMath::Abs(vertex->GetZv())>fgkEvVertexZ || | |
192 | vertex->GetNContributors()<fgkEvVertexN) { | |
193 | //PostData(0, fOutStorage); | |
194 | return; | |
195 | } | |
196 | } | |
197 | ||
1ee39b3a | 198 | if(!fESDfriend){ |
199 | AliError("Failed retrieving ESD friend event"); | |
200 | return; | |
201 | } | |
202 | if(HasMCdata() && !fMCev){ | |
203 | AliError("Failed retrieving MC event"); | |
204 | return; | |
205 | } | |
f8f46e4d | 206 | |
1ee39b3a | 207 | fContainer->Delete(); |
208 | fV0container->Delete(); | |
209 | fEventInfo->Delete(""); | |
1ee39b3a | 210 | new(fEventInfo)AliTRDeventInfo(fESDev->GetHeader(), const_cast<AliESDRun *>(fESDev->GetESDRun())); |
211 | ||
770382d9 | 212 | Bool_t *trackMap(NULL); |
213 | AliStack * mStack(NULL); | |
1ee39b3a | 214 | Int_t nTracksMC = HasMCdata() ? fMCev->GetNumberOfTracks() : 0, nTracksESD = fESDev->GetNumberOfTracks(); |
215 | if(HasMCdata()){ | |
216 | mStack = fMCev->Stack(); | |
217 | if(!mStack){ | |
218 | AliError("Failed retrieving MC Stack"); | |
219 | return; | |
220 | } | |
221 | trackMap = new Bool_t[nTracksMC]; | |
222 | memset(trackMap, 0, sizeof(Bool_t) * nTracksMC); | |
223 | } | |
224 | ||
f232df0d | 225 | Double32_t dedx[100]; Int_t nSlices(0); |
770382d9 | 226 | Int_t nTRDout(0), nTRDin(0), nTPC(0), nclsTrklt; |
1ee39b3a | 227 | AliDebug(2, Form("Entry[%3d] Tracks: ESD[%d] MC[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC)); |
770382d9 | 228 | AliESDtrack *esdTrack = NULL; |
229 | AliESDfriendTrack *esdFriendTrack = NULL; | |
230 | TObject *calObject = NULL; | |
231 | AliTRDtrackV1 *track = NULL; | |
232 | AliTRDseedV1 *tracklet = NULL; | |
233 | AliTRDcluster *cl = NULL; | |
1ee39b3a | 234 | for(Int_t itrk = 0; itrk < nTracksESD; itrk++){ |
235 | esdTrack = fESDev->GetTrack(itrk); | |
236 | AliDebug(3, Form("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2))); | |
3f19c2cd | 237 | |
238 | // Track Selection | |
239 | if(UseLocalTrkSelection()){ | |
240 | if(esdTrack->Pt() < fgkPt) continue; | |
241 | if(TMath::Abs(esdTrack->Eta()) > fgkEta) continue; | |
242 | if(esdTrack->GetTPCNcls() < fgkNclTPC) continue; | |
243 | Float_t par[2], cov[3]; | |
244 | esdTrack->GetImpactParameters(par, cov); | |
245 | if(IsCollision()){ // cuts on DCA | |
246 | if(TMath::Abs(par[0]) > fgkTrkDCAxy) continue; | |
247 | if(TMath::Abs(par[1]) > fgkTrkDCAz) continue; | |
248 | } | |
249 | } | |
250 | ||
770382d9 | 251 | if(esdTrack->GetStatus()&AliESDtrack::kTPCout) nTPC++; |
252 | if(esdTrack->GetStatus()&AliESDtrack::kTRDout) nTRDout++; | |
253 | if(esdTrack->GetStatus()&AliESDtrack::kTRDin) nTRDin++; | |
1ee39b3a | 254 | |
255 | // look at external track param | |
256 | const AliExternalTrackParam *op = esdTrack->GetOuterParam(); | |
257 | Double_t xyz[3]; | |
258 | if(op){ | |
259 | op->GetXYZ(xyz); | |
260 | op->Global2LocalPosition(xyz, op->GetAlpha()); | |
261 | AliDebug(3, Form("op @ X[%7.3f]\n", xyz[0])); | |
262 | } | |
263 | ||
264 | // read MC info | |
265 | Int_t fPdg = -1; | |
266 | Int_t label = -1; UInt_t alab=UINT_MAX; | |
267 | if(HasMCdata()){ | |
268 | label = esdTrack->GetLabel(); | |
269 | alab = TMath::Abs(label); | |
270 | // register the track | |
271 | if(alab < UInt_t(nTracksMC)){ | |
272 | trackMap[alab] = kTRUE; | |
273 | } else { | |
274 | AliError(Form("MC label[%d] outside scope for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk)); | |
275 | continue; | |
276 | } | |
770382d9 | 277 | AliMCParticle *mcParticle = NULL; |
1ee39b3a | 278 | if(!(mcParticle = (AliMCParticle*) fMCev->GetTrack(alab))){ |
279 | AliError(Form("MC particle label[%d] missing for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk)); | |
280 | continue; | |
281 | } | |
282 | fPdg = mcParticle->Particle()->GetPdgCode(); | |
283 | Int_t nRefs = mcParticle->GetNumberOfTrackReferences(); | |
770382d9 | 284 | Int_t iref = 0; AliTrackReference *ref = NULL; |
1ee39b3a | 285 | while(iref<nRefs){ |
286 | ref = mcParticle->GetTrackReference(iref); | |
287 | if(ref->LocalX() > fgkTPC) break; | |
288 | iref++; | |
289 | } | |
290 | ||
291 | new(fTrackInfo) AliTRDtrackInfo(); | |
292 | fTrackInfo->SetPDG(fPdg); | |
293 | fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary()); | |
294 | Int_t jref = iref;//, kref = 0; | |
295 | while(jref<nRefs){ | |
296 | ref = mcParticle->GetTrackReference(jref); | |
297 | if(ref->LocalX() > fgkTOF) break; | |
298 | AliDebug(4, Form(" trackRef[%2d (%2d)] @ %7.3f OK", jref-iref, jref, ref->LocalX())); | |
299 | fTrackInfo->AddTrackRef(ref); | |
300 | jref++; | |
301 | } | |
302 | AliDebug(3, Form("NtrackRefs[%d(%d)]", fTrackInfo->GetNTrackRefs(), nRefs)); | |
303 | } else { | |
304 | new (fTrackInfo) AliTRDtrackInfo(); | |
305 | fTrackInfo->SetPDG(fPdg); | |
306 | } | |
307 | ||
308 | // copy some relevant info to TRD track info | |
309 | fTrackInfo->SetStatus(esdTrack->GetStatus()); | |
310 | fTrackInfo->SetTrackId(esdTrack->GetID()); | |
311 | Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p); | |
312 | fTrackInfo->SetESDpid(p); | |
313 | fTrackInfo->SetESDpidQuality(esdTrack->GetTRDntrackletsPID()); | |
f232df0d | 314 | if(!nSlices) nSlices = esdTrack->GetNumberOfTRDslices(); |
315 | memset(dedx, 0, 100*sizeof(Double32_t)); | |
92c40e64 | 316 | Int_t in(0); |
317 | for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++) | |
318 | for(Int_t is=0; is<nSlices; is++) | |
319 | dedx[in++]=esdTrack->GetTRDslice(il, is); | |
320 | for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++) dedx[in++]=esdTrack->GetTRDmomentum(il); | |
321 | fTrackInfo->SetSlices(in, dedx); | |
1ee39b3a | 322 | fTrackInfo->SetLabel(label); |
323 | fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2)); | |
324 | // some other Informations which we may wish to store in order to find problematic cases | |
325 | fTrackInfo->SetKinkIndex(esdTrack->GetKinkIndex(0)); | |
326 | fTrackInfo->SetTPCncls(static_cast<UShort_t>(esdTrack->GetNcls(1))); | |
327 | nclsTrklt = 0; | |
328 | ||
329 | ||
330 | // read REC info | |
331 | esdFriendTrack = fESDfriend->GetTrack(itrk); | |
332 | if(esdFriendTrack){ | |
333 | Int_t icalib = 0; | |
334 | while((calObject = esdFriendTrack->GetCalibObject(icalib++))){ | |
335 | if(strcmp(calObject->IsA()->GetName(),"AliTRDtrackV1") != 0) continue; // Look for the TRDtrack | |
336 | if(!(track = dynamic_cast<AliTRDtrackV1*>(calObject))) break; | |
1ee39b3a | 337 | AliDebug(4, Form("TRD track OK")); |
338 | // Set the clusters to unused | |
339 | for(Int_t ipl = 0; ipl < AliTRDgeometry::kNlayer; ipl++){ | |
340 | if(!(tracklet = track->GetTracklet(ipl))) continue; | |
341 | tracklet->ResetClusterIter(); | |
342 | while((cl = tracklet->NextCluster())) cl->Use(0); | |
343 | } | |
344 | fTrackInfo->SetTrack(track); | |
345 | break; | |
346 | } | |
347 | AliDebug(3, Form("Ntracklets[%d]\n", fTrackInfo->GetNTracklets())); | |
348 | } else AliDebug(3, "No ESD friends"); | |
349 | if(op) fTrackInfo->SetOuterParam(op); | |
350 | ||
351 | if(DebugLevel() >= 1){ | |
352 | AliTRDtrackInfo info(*fTrackInfo); | |
353 | (*DebugStream()) << "trackInfo" | |
354 | << "TrackInfo.=" << &info | |
355 | << "\n"; | |
356 | info.Delete(""); | |
357 | } | |
358 | ||
359 | fContainer->Add(new AliTRDtrackInfo(*fTrackInfo)); | |
360 | fTrackInfo->Delete(""); | |
361 | } | |
770382d9 | 362 | AliDebug(2, Form("%3d Tracks: TPCout[%d] TRDin[%d] TRDout[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTPC, nTRDin, nTRDout)); |
1ee39b3a | 363 | |
770382d9 | 364 | // AliESDv0 *v0 = NULL; |
1ee39b3a | 365 | // for(Int_t iv0=0; iv0<fESD->GetNumberOfV0s(); iv0++){ |
366 | // if(!(v0 = fESD->GetV0(iv0))) continue; | |
367 | // fV0container->Add(new AliTRDv0Info(v0)); | |
368 | // } | |
369 | ||
370 | // Insert also MC tracks which are passing TRD where the track is not reconstructed | |
371 | if(HasMCdata()){ | |
372 | AliDebug(10, "Output of the MC track map:"); | |
373 | for(Int_t itk = 0; itk < nTracksMC; itk++) AliDebug(10, Form("trackMap[%d] = %s", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE")); | |
374 | ||
375 | for(Int_t itk = 0; itk < nTracksMC; itk++){ | |
376 | if(trackMap[itk]) continue; | |
377 | AliMCParticle *mcParticle = (AliMCParticle*) fMCev->GetTrack(TMath::Abs(itk)); | |
378 | Int_t fPdg = mcParticle->Particle()->GetPdgCode(); | |
379 | Int_t nRefs = mcParticle->GetNumberOfTrackReferences(); | |
770382d9 | 380 | Int_t iref = 0; AliTrackReference *ref = NULL; |
1ee39b3a | 381 | Int_t nRefsTRD = 0; |
382 | new(fTrackInfo) AliTRDtrackInfo(); | |
383 | fTrackInfo->SetPDG(fPdg); | |
384 | while(iref<nRefs){ | |
770382d9 | 385 | Bool_t kIN(kFALSE); |
1ee39b3a | 386 | ref = mcParticle->GetTrackReference(iref); |
770382d9 | 387 | if(ref->LocalX() > fgkTPC && ref->LocalX() < fgkTOF){ |
1ee39b3a | 388 | fTrackInfo->AddTrackRef(ref); |
770382d9 | 389 | nRefsTRD++;kIN=kTRUE; |
1ee39b3a | 390 | } |
770382d9 | 391 | AliDebug(4, Form(" trackRef[%2d] @ x[%7.3f] %s", iref, ref->LocalX(), kIN?"IN":"OUT")); |
1ee39b3a | 392 | iref++; |
393 | } | |
394 | if(!nRefsTRD){ | |
395 | // In this stage we at least require 1 hit inside TRD. What will be done with this tracks is a task for the | |
396 | // analysis job | |
397 | fTrackInfo->Delete(""); | |
398 | continue; | |
399 | } | |
400 | fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary()); | |
401 | fTrackInfo->SetLabel(itk); | |
402 | if(DebugLevel() >= 1){ | |
403 | AliTRDtrackInfo info(*fTrackInfo); | |
404 | (*DebugStream()) << "trackInfo" | |
405 | << "TrackInfo.=" << &info | |
406 | << "\n"; | |
407 | info.Delete(""); | |
408 | } | |
770382d9 | 409 | AliDebug(3, Form("Add MC track @ label[%d] nTRDrefs[%d].", itk, nRefsTRD)); |
1ee39b3a | 410 | fContainer->Add(new AliTRDtrackInfo(*fTrackInfo)); |
411 | fTrackInfo->Delete(""); | |
412 | } | |
413 | delete[] trackMap; | |
414 | } | |
f8f46e4d | 415 | PostData(1, fContainer); |
416 | PostData(2, fEventInfo); | |
417 | PostData(3, fV0container); | |
1ee39b3a | 418 | } |
419 |