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