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