]>
Commit | Line | Data |
---|---|---|
814ecea4 | 1 | /************************************************************************** |
d2381af5 | 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 | **************************************************************************/ | |
814ecea4 | 15 | |
16 | /* $Id: AliTRDtrackInfoGen.cxx 27496 2008-07-22 08:35:45Z cblume $ */ | |
17 | ||
18 | //////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
20 | // Reconstruction QA // | |
21 | // // | |
22 | // Authors: // | |
23 | // Markus Fasel <M.Fasel@gsi.de> // | |
24 | // // | |
25 | //////////////////////////////////////////////////////////////////////////// | |
26 | ||
27 | #include <TClonesArray.h> | |
28 | #include <TObjArray.h> | |
29 | #include <TObject.h> | |
30 | #include <TH1F.h> | |
31 | #include <TFile.h> | |
32 | #include <TTree.h> | |
33 | #include <TROOT.h> | |
34 | #include <TChain.h> | |
35 | #include <TParticle.h> | |
36 | ||
37 | #include "AliLog.h" | |
38 | #include "AliAnalysisManager.h" | |
39 | #include "AliESDEvent.h" | |
40 | #include "AliMCEvent.h" | |
41 | #include "AliESDInputHandler.h" | |
42 | #include "AliMCEventHandler.h" | |
43 | ||
44 | #include "AliESDfriend.h" | |
45 | #include "AliESDfriendTrack.h" | |
a24151d1 | 46 | #include "AliESDHeader.h" |
814ecea4 | 47 | #include "AliESDtrack.h" |
48 | #include "AliMCParticle.h" | |
c46a7947 | 49 | #include "AliPID.h" |
814ecea4 | 50 | #include "AliStack.h" |
51 | #include "AliTRDtrackV1.h" | |
52 | #include "AliTrackReference.h" | |
53 | #include "AliTRDgeometry.h" | |
54 | #include "TTreeStream.h" | |
55 | ||
56 | #include <cstdio> | |
57 | #include <cstring> | |
afefec95 | 58 | #include <iostream> |
814ecea4 | 59 | |
60 | #include "AliTRDtrackInfoGen.h" | |
61 | #include "AliTRDtrackInfo/AliTRDtrackInfo.h" | |
a24151d1 | 62 | #include "AliTRDtrackInfo/AliTRDeventInfo.h" |
814ecea4 | 63 | |
64 | ClassImp(AliTRDtrackInfoGen) | |
65 | ||
303f052c | 66 | const Float_t AliTRDtrackInfoGen::xTPC = 290.; |
67 | const Float_t AliTRDtrackInfoGen::xTOF = 365.; | |
814ecea4 | 68 | |
69 | //____________________________________________________________________ | |
3d86166d | 70 | AliTRDtrackInfoGen::AliTRDtrackInfoGen(): |
71 | AliTRDrecoTask("InfoGen", "Track List Generator") | |
814ecea4 | 72 | ,fESD(0x0) |
73 | ,fMC(0x0) | |
74 | ,fESDfriend(0x0) | |
75 | ,fTrackInfo(0x0) | |
a24151d1 | 76 | ,fEventInfo(0x0) |
814ecea4 | 77 | { |
78 | // | |
79 | // Default constructor | |
80 | // | |
81 | ||
82 | DefineInput(0, TChain::Class()); | |
83 | DefineOutput(0, TObjArray::Class()); | |
a24151d1 | 84 | DefineOutput(1, AliTRDeventInfo::Class()); |
814ecea4 | 85 | //DefineOutput(1, TTree::Class()); |
86 | } | |
87 | ||
88 | //____________________________________________________________________ | |
ed383798 | 89 | AliTRDtrackInfoGen::~AliTRDtrackInfoGen() |
90 | { | |
91 | if(fTrackInfo) delete fTrackInfo; | |
b23de807 | 92 | //if(fEventInfo) delete fEventInfo; |
afefec95 | 93 | //fTrackInfo = 0x0; fEventInfo = 0x0; |
ed383798 | 94 | } |
95 | ||
96 | //____________________________________________________________________ | |
814ecea4 | 97 | void AliTRDtrackInfoGen::ConnectInputData(Option_t *) |
98 | { | |
99 | // | |
100 | // Link the Input Data | |
101 | // | |
d2381af5 | 102 | TTree *tree = dynamic_cast<TChain*>(GetInputData(0)); |
103 | if(!tree){ | |
814ecea4 | 104 | printf("ERROR - ESD event not found"); |
d2381af5 | 105 | } else { |
106 | tree->SetBranchStatus("Tracks", 1); | |
107 | tree->SetBranchStatus("ESDfriend*",1); | |
814ecea4 | 108 | } |
109 | ||
110 | AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()); | |
111 | if(!esdH){ | |
d2381af5 | 112 | printf("ERROR - ESD input handler not found"); |
814ecea4 | 113 | } else { |
114 | fESD = esdH->GetEvent(); | |
115 | if(!fESD){ | |
d2381af5 | 116 | printf("ERROR - ESD event not found"); |
814ecea4 | 117 | } else { |
118 | esdH->SetActiveBranches("ESDfriend*"); | |
119 | fESDfriend = (AliESDfriend *)fESD->FindListObject("AliESDfriend"); | |
814ecea4 | 120 | } |
121 | } | |
4b8f8a35 | 122 | if(HasMCdata()){ |
d2381af5 | 123 | AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()); |
124 | if(!mcH){ | |
125 | AliError("MC input handler not found"); | |
126 | } else { | |
127 | fMC = mcH->MCEvent(); | |
128 | } | |
814ecea4 | 129 | } |
130 | } | |
131 | ||
132 | //____________________________________________________________________ | |
133 | void AliTRDtrackInfoGen::CreateOutputObjects() | |
134 | { | |
135 | // | |
136 | // Create Output Containers (TObjectArray containing 1D histograms) | |
137 | // | |
138 | fTrackInfo = new AliTRDtrackInfo(); | |
a24151d1 | 139 | fEventInfo = new AliTRDeventInfo(); |
3d86166d | 140 | fContainer = new TObjArray(1000); |
814ecea4 | 141 | |
142 | /* OpenFile(1, "RECREATE"); | |
143 | fTree = new TTree("trd", "extract of the TRD detector"); | |
144 | fTree->Branch("info", &fTrackInfo); | |
145 | printf("output tree build in %s\n", fTree->GetDirectory()->GetName());*/ | |
146 | } | |
147 | ||
148 | //____________________________________________________________________ | |
149 | void AliTRDtrackInfoGen::Exec(Option_t *){ | |
d2381af5 | 150 | // |
151 | // Run the Analysis | |
152 | // | |
153 | if(!fESD){ | |
154 | puts("Error: ESD not found"); | |
155 | return; | |
156 | } | |
157 | if(!fESDfriend){ | |
158 | puts("Error: ESD friend not found"); | |
159 | return; | |
160 | } | |
161 | if(HasMCdata() && !fMC){ | |
162 | puts("Error: Monte Carlo Event not available"); | |
163 | return; | |
164 | } | |
3d86166d | 165 | fContainer->Delete(); |
afefec95 | 166 | fEventInfo->Delete(""); |
d2381af5 | 167 | fESD->SetESDfriend(fESDfriend); |
a24151d1 | 168 | new(fEventInfo)AliTRDeventInfo(fESD->GetHeader(), const_cast<AliESDRun *>(fESD->GetESDRun())); |
d2381af5 | 169 | |
170 | Bool_t *trackMap = 0x0; | |
171 | AliStack * mStack = 0x0; | |
172 | if(HasMCdata()){ | |
173 | mStack = fMC->Stack(); | |
174 | if(!mStack){ | |
175 | puts("Error: Cannot get the Monte Carlo Stack"); | |
176 | return; | |
177 | } | |
178 | trackMap = new Bool_t[fMC->GetNumberOfTracks()]; | |
179 | memset(trackMap, 0, sizeof(Bool_t) * fMC->GetNumberOfTracks()); | |
180 | } | |
181 | ||
182 | Int_t nTRD = 0, nTPC = 0, nclsTrklt; | |
183 | Int_t nTracks = fESD->GetNumberOfTracks(); | |
184 | if(fDebugLevel>=1){ | |
b718144c | 185 | printf("Entry[%3d] Tracks: ESD[%d] MC[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracks, HasMCdata() ? mStack->GetNtrack() : 0); |
d2381af5 | 186 | } |
187 | AliESDtrack *esdTrack = 0x0; | |
188 | AliESDfriendTrack *esdFriendTrack = 0x0; | |
189 | TObject *calObject = 0x0; | |
190 | AliTRDtrackV1 *track = 0x0; | |
191 | for(Int_t itrk = 0; itrk < nTracks; itrk++){ | |
192 | esdTrack = fESD->GetTrack(itrk); | |
193 | if(fDebugLevel>=2) printf("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2)); | |
194 | if(esdTrack->GetNcls(1)) nTPC++; | |
195 | if(esdTrack->GetNcls(2)) nTRD++; | |
814ecea4 | 196 | |
303f052c | 197 | // look at external track param |
d2381af5 | 198 | const AliExternalTrackParam *op = esdTrack->GetOuterParam(); |
199 | Double_t xyz[3]; | |
200 | if(op){ | |
201 | op->GetXYZ(xyz); | |
202 | op->Global2LocalPosition(xyz, op->GetAlpha()); | |
203 | if(fDebugLevel>=2) printf("op @ X[%7.3f]\n", xyz[0]); | |
204 | } | |
814ecea4 | 205 | |
d2381af5 | 206 | // read MC info |
207 | Int_t fPdg = -1; | |
208 | Int_t label = -1; | |
209 | if(HasMCdata()){ | |
210 | label = esdTrack->GetLabel(); | |
211 | if(label < fMC->GetNumberOfTracks()) trackMap[TMath::Abs(label)] = kTRUE; // register the track | |
212 | //if (TMath::Abs(label) > mStack->GetNtrack()) continue; | |
5d6dc395 | 213 | AliMCParticle *mcParticle = 0x0; |
214 | if(!(mcParticle = fMC->GetTrack(TMath::Abs(label)))){ | |
215 | printf("E - AliTRDtrackInfoGen::Exec() : MC particle missing for ESD label %d\n", label); | |
216 | continue; | |
217 | } | |
d2381af5 | 218 | fPdg = mcParticle->Particle()->GetPdgCode(); |
219 | Int_t nRefs = mcParticle->GetNumberOfTrackReferences(); | |
220 | Int_t iref = 0; AliTrackReference *ref = 0x0; | |
221 | while(iref<nRefs){ | |
222 | ref = mcParticle->GetTrackReference(iref); | |
303f052c | 223 | if(ref->LocalX() > xTPC) break; |
d2381af5 | 224 | //printf("\ttrackRef[%2d] @ %7.3f\n", iref, ref->LocalX()); |
225 | iref++; | |
226 | } | |
814ecea4 | 227 | |
93e41bce | 228 | new(fTrackInfo) AliTRDtrackInfo(); |
229 | fTrackInfo->SetPDG(fPdg); | |
d2381af5 | 230 | fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary()); |
231 | Int_t jref = iref;//, kref = 0; | |
232 | while(jref<nRefs){ | |
233 | ref = mcParticle->GetTrackReference(jref); | |
303f052c | 234 | if(ref->LocalX() > xTOF) break; |
d2381af5 | 235 | if(fDebugLevel>=3) printf("\ttrackRef[%2d (%2d)] @ %7.3f OK\n", jref-iref, jref, ref->LocalX()); |
236 | fTrackInfo->AddTrackRef(ref); | |
237 | jref++; | |
238 | } | |
d2381af5 | 239 | if(fDebugLevel>=2) printf("NtrackRefs[%d(%d)]\n", fTrackInfo->GetNTrackRefs(), nRefs); |
240 | } else { | |
93e41bce | 241 | new (fTrackInfo) AliTRDtrackInfo(); |
242 | fTrackInfo->SetPDG(fPdg); | |
d2381af5 | 243 | } |
814ecea4 | 244 | |
d2381af5 | 245 | // copy some relevant info to TRD track info |
246 | fTrackInfo->SetStatus(esdTrack->GetStatus()); | |
247 | fTrackInfo->SetTrackId(esdTrack->GetID()); | |
c46a7947 | 248 | Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p); |
249 | fTrackInfo->SetESDpid(p); | |
250 | fTrackInfo->SetESDpidQuality(esdTrack->GetTRDpidQuality()); | |
d2381af5 | 251 | fTrackInfo->SetLabel(label); |
252 | fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2)); | |
52a79f8d | 253 | // some other Informations which we may wish to store in order to find problematic cases |
254 | fTrackInfo->SetKinkIndex(esdTrack->GetKinkIndex(0)); | |
255 | fTrackInfo->SetTPCncls(static_cast<UShort_t>(esdTrack->GetNcls(1))); | |
d2381af5 | 256 | nclsTrklt = 0; |
257 | ||
814ecea4 | 258 | |
d2381af5 | 259 | // read REC info |
260 | esdFriendTrack = fESDfriend->GetTrack(itrk); | |
261 | if(esdFriendTrack){ | |
262 | Int_t icalib = 0; | |
263 | while((calObject = esdFriendTrack->GetCalibObject(icalib++))){ | |
264 | if(strcmp(calObject->IsA()->GetName(),"AliTRDtrackV1") != 0) continue; // Look for the TRDtrack | |
b718144c | 265 | if(!(track = dynamic_cast<AliTRDtrackV1*>(calObject))) break; |
266 | nTRD++; | |
d2381af5 | 267 | if(fDebugLevel>=3) printf("TRD track OK\n"); |
c46a7947 | 268 | fTrackInfo->SetTrack(track); |
d2381af5 | 269 | break; |
270 | } | |
271 | if(fDebugLevel>=2) printf("Ntracklets[%d]\n", fTrackInfo->GetNTracklets()); | |
272 | } else if(fDebugLevel>=2) printf("No ESD friends\n"); | |
273 | if(op) fTrackInfo->SetOuterParam(op); | |
814ecea4 | 274 | |
b718144c | 275 | if(fDebugLevel >= 1){ |
276 | AliTRDtrackInfo info(*fTrackInfo); | |
d2381af5 | 277 | (*fDebugStream) << "trackInfo" |
b718144c | 278 | << "TrackInfo.=" << &info |
d2381af5 | 279 | << "\n"; |
b718144c | 280 | info.Delete(""); |
d2381af5 | 281 | } |
282 | ||
3d86166d | 283 | fContainer->Add(new AliTRDtrackInfo(*fTrackInfo)); |
d2381af5 | 284 | fTrackInfo->Delete(""); |
285 | } | |
b718144c | 286 | if(fDebugLevel>=2) printf("%3d Tracks: TPC[%d] TRD[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTPC, nTRD); |
4b8f8a35 | 287 | |
d2381af5 | 288 | // Insert also MC tracks which are passing TRD where the track is not reconstructed |
289 | if(HasMCdata()){ | |
290 | if(fDebugLevel > 10){ | |
291 | printf("Output of the MC track map:\n"); | |
292 | for(Int_t itk = 0; itk < fMC->GetNumberOfTracks(); itk++) | |
293 | printf("trackMap[%d] = %s\n", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE"); | |
294 | } | |
295 | ||
296 | for(Int_t itk = 0; itk < fMC->GetNumberOfTracks(); itk++){ | |
297 | if(fDebugLevel >=2 ) printf("Number of MC tracks: %d\n", fMC->GetNumberOfTracks()); | |
298 | if(trackMap[itk]) continue; | |
299 | AliMCParticle *mcParticle = fMC->GetTrack(TMath::Abs(itk)); | |
300 | Int_t fPdg = mcParticle->Particle()->GetPdgCode(); | |
301 | Int_t nRefs = mcParticle->GetNumberOfTrackReferences(); | |
302 | Int_t iref = 0; AliTrackReference *ref = 0x0; | |
303 | Int_t nRefsTRD = 0; | |
93e41bce | 304 | new(fTrackInfo) AliTRDtrackInfo(); |
305 | fTrackInfo->SetPDG(fPdg); | |
d2381af5 | 306 | while(iref<nRefs){ |
307 | ref = mcParticle->GetTrackReference(iref); | |
308 | if(fDebugLevel > 3) printf("\ttrackRef[%2d] @ %7.3f", iref, ref->LocalX()); | |
309 | if(ref->LocalX() > 250. && ref->LocalX() < 370.){ | |
310 | if(fDebugLevel > 3) printf(" OK\n"); | |
311 | fTrackInfo->AddTrackRef(ref); | |
312 | nRefsTRD++; | |
313 | } | |
314 | else | |
315 | if(fDebugLevel > 3) printf("\n"); | |
316 | iref++; | |
317 | } | |
318 | if(!nRefsTRD){ | |
319 | // In this stage we at least require 1 hit inside TRD. What will be done with this tracks is a task for the | |
320 | // analysis job | |
321 | fTrackInfo->Delete(""); | |
322 | continue; | |
323 | } | |
324 | fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary()); | |
325 | fTrackInfo->SetLabel(itk); | |
326 | if(fDebugLevel >= 1){ | |
b718144c | 327 | AliTRDtrackInfo info(*fTrackInfo); |
d2381af5 | 328 | (*fDebugStream) << "trackInfo" |
b718144c | 329 | << "TrackInfo.=" << &info |
d2381af5 | 330 | << "\n"; |
b718144c | 331 | info.Delete(""); |
d2381af5 | 332 | } |
333 | if(fDebugLevel > 2)printf("Registering rejected MC track with label %d\n", itk); | |
3d86166d | 334 | fContainer->Add(new AliTRDtrackInfo(*fTrackInfo)); |
d2381af5 | 335 | fTrackInfo->Delete(""); |
336 | } | |
337 | delete[] trackMap; | |
338 | } | |
3d86166d | 339 | PostData(0, fContainer); |
a24151d1 | 340 | PostData(1, fEventInfo); |
814ecea4 | 341 | } |
342 | ||
814ecea4 | 343 | |
344 | //____________________________________________________________________ | |
345 | void AliTRDtrackInfoGen::Terminate(Option_t *) | |
346 | { | |
347 | // | |
348 | // Stays empty because we are only interested in the tree | |
349 | // | |
814ecea4 | 350 | if(fDebugLevel>=1) printf("Terminate:\n"); |
351 | //TFile *f =((TFile*)gROOT->FindObject("TRD.TrackInfo.root")); | |
352 | //f->cd(); f->Write(); f->Close(); | |
353 | ||
3d86166d | 354 | if(fDebugStream){ |
355 | delete fDebugStream; | |
356 | fDebugStream = 0x0; | |
357 | } | |
814ecea4 | 358 | } |