1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /* $Id: AliTRDtrackInfoGen.cxx 27496 2008-07-22 08:35:45Z cblume $ */
18 ////////////////////////////////////////////////////////////////////////////
20 // Reconstruction QA //
23 // Markus Fasel <M.Fasel@gsi.de> //
25 ////////////////////////////////////////////////////////////////////////////
27 #include <TClonesArray.h>
28 #include <TObjArray.h>
35 #include <TParticle.h>
38 #include "AliAnalysisManager.h"
39 #include "AliESDEvent.h"
40 #include "AliMCEvent.h"
41 #include "AliESDInputHandler.h"
42 #include "AliMCEventHandler.h"
44 #include "AliESDfriend.h"
45 #include "AliESDfriendTrack.h"
46 #include "AliESDHeader.h"
47 #include "AliESDtrack.h"
48 #include "AliMCParticle.h"
51 #include "AliTRDtrackV1.h"
52 #include "AliTrackReference.h"
53 #include "AliTRDgeometry.h"
54 #include "TTreeStream.h"
60 #include "AliTRDtrackInfoGen.h"
61 #include "AliTRDtrackInfo/AliTRDtrackInfo.h"
62 #include "AliTRDtrackInfo/AliTRDeventInfo.h"
64 ClassImp(AliTRDtrackInfoGen)
66 const Float_t AliTRDtrackInfoGen::xTPC = 290.;
67 const Float_t AliTRDtrackInfoGen::xTOF = 365.;
69 //____________________________________________________________________
70 AliTRDtrackInfoGen::AliTRDtrackInfoGen():
71 AliTRDrecoTask("InfoGen", "Track List Generator")
79 // Default constructor
82 DefineInput(0, TChain::Class());
83 DefineOutput(0, TObjArray::Class());
84 DefineOutput(1, AliTRDeventInfo::Class());
85 //DefineOutput(1, TTree::Class());
88 //____________________________________________________________________
89 AliTRDtrackInfoGen::~AliTRDtrackInfoGen()
91 if(fTrackInfo) delete fTrackInfo; fTrackInfo = 0x0;
92 if(fEventInfo) delete fEventInfo; fEventInfo = 0x0;
94 fContainer->Delete(); delete fContainer;
99 //____________________________________________________________________
100 void AliTRDtrackInfoGen::ConnectInputData(Option_t *)
103 // Link the Input Data
105 TTree *tree = dynamic_cast<TChain*>(GetInputData(0));
107 printf("ERROR - ESD event not found");
109 tree->SetBranchStatus("Tracks", 1);
110 tree->SetBranchStatus("ESDfriend*",1);
113 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
115 printf("ERROR - ESD input handler not found");
117 fESD = esdH->GetEvent();
119 printf("ERROR - ESD event not found");
121 esdH->SetActiveBranches("ESDfriend*");
122 fESDfriend = (AliESDfriend *)fESD->FindListObject("AliESDfriend");
126 AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
128 AliError("MC input handler not found");
130 fMC = mcH->MCEvent();
135 //____________________________________________________________________
136 void AliTRDtrackInfoGen::CreateOutputObjects()
139 // Create Output Containers (TObjectArray containing 1D histograms)
141 fTrackInfo = new AliTRDtrackInfo();
142 fEventInfo = new AliTRDeventInfo();
143 fContainer = new TObjArray(1000);
144 fContainer->SetOwner(kTRUE);
146 /* OpenFile(1, "RECREATE");
147 fTree = new TTree("trd", "extract of the TRD detector");
148 fTree->Branch("info", &fTrackInfo);
149 printf("output tree build in %s\n", fTree->GetDirectory()->GetName());*/
152 //____________________________________________________________________
153 void AliTRDtrackInfoGen::Exec(Option_t *){
158 puts("Error: ESD not found");
162 puts("Error: ESD friend not found");
165 if(HasMCdata() && !fMC){
166 puts("Error: Monte Carlo Event not available");
169 fContainer->Delete();
170 fEventInfo->Delete("");
171 fESD->SetESDfriend(fESDfriend);
172 new(fEventInfo)AliTRDeventInfo(fESD->GetHeader(), const_cast<AliESDRun *>(fESD->GetESDRun()));
174 Bool_t *trackMap = 0x0;
175 AliStack * mStack = 0x0;
176 Int_t nTracksMC = HasMCdata() ? fMC->GetNumberOfTracks() : 0, nTracksESD = fESD->GetNumberOfTracks();
178 mStack = fMC->Stack();
180 puts("Error: Cannot get the Monte Carlo Stack");
183 trackMap = new Bool_t[nTracksMC];
184 memset(trackMap, 0, sizeof(Bool_t) * nTracksMC);
187 Int_t nTRD = 0, nTPC = 0, nclsTrklt;
189 printf("Entry[%3d] Tracks: ESD[%d] MC[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC);
191 AliESDtrack *esdTrack = 0x0;
192 AliESDfriendTrack *esdFriendTrack = 0x0;
193 TObject *calObject = 0x0;
194 AliTRDtrackV1 *track = 0x0;
195 for(Int_t itrk = 0; itrk < nTracksESD; itrk++){
196 esdTrack = fESD->GetTrack(itrk);
197 if(fDebugLevel>=2) printf("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2));
198 if(esdTrack->GetNcls(1)) nTPC++;
199 if(esdTrack->GetNcls(2)) nTRD++;
201 // look at external track param
202 const AliExternalTrackParam *op = esdTrack->GetOuterParam();
206 op->Global2LocalPosition(xyz, op->GetAlpha());
207 if(fDebugLevel>=2) printf("op @ X[%7.3f]\n", xyz[0]);
214 label = esdTrack->GetLabel();
215 if(label < nTracksMC) trackMap[TMath::Abs(label)] = kTRUE; // register the track
216 //if (TMath::Abs(label) > mStack->GetNtrack()) continue;
217 AliMCParticle *mcParticle = 0x0;
218 if(!(mcParticle = fMC->GetTrack(TMath::Abs(label)))){
219 printf("E - AliTRDtrackInfoGen::Exec() : MC particle missing for ESD label %d\n", label);
222 fPdg = mcParticle->Particle()->GetPdgCode();
223 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
224 Int_t iref = 0; AliTrackReference *ref = 0x0;
226 ref = mcParticle->GetTrackReference(iref);
227 if(ref->LocalX() > xTPC) break;
228 //printf("\ttrackRef[%2d] @ %7.3f\n", iref, ref->LocalX());
232 new(fTrackInfo) AliTRDtrackInfo();
233 fTrackInfo->SetPDG(fPdg);
234 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
235 Int_t jref = iref;//, kref = 0;
237 ref = mcParticle->GetTrackReference(jref);
238 if(ref->LocalX() > xTOF) break;
239 if(fDebugLevel>=3) printf("\ttrackRef[%2d (%2d)] @ %7.3f OK\n", jref-iref, jref, ref->LocalX());
240 fTrackInfo->AddTrackRef(ref);
243 if(fDebugLevel>=2) printf("NtrackRefs[%d(%d)]\n", fTrackInfo->GetNTrackRefs(), nRefs);
245 new (fTrackInfo) AliTRDtrackInfo();
246 fTrackInfo->SetPDG(fPdg);
249 // copy some relevant info to TRD track info
250 fTrackInfo->SetStatus(esdTrack->GetStatus());
251 fTrackInfo->SetTrackId(esdTrack->GetID());
252 Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p);
253 fTrackInfo->SetESDpid(p);
254 fTrackInfo->SetESDpidQuality(esdTrack->GetTRDntrackletsPID());
255 fTrackInfo->SetLabel(label);
256 fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2));
257 // some other Informations which we may wish to store in order to find problematic cases
258 fTrackInfo->SetKinkIndex(esdTrack->GetKinkIndex(0));
259 fTrackInfo->SetTPCncls(static_cast<UShort_t>(esdTrack->GetNcls(1)));
264 esdFriendTrack = fESDfriend->GetTrack(itrk);
267 while((calObject = esdFriendTrack->GetCalibObject(icalib++))){
268 if(strcmp(calObject->IsA()->GetName(),"AliTRDtrackV1") != 0) continue; // Look for the TRDtrack
269 if(!(track = dynamic_cast<AliTRDtrackV1*>(calObject))) break;
271 if(fDebugLevel>=3) printf("TRD track OK\n");
272 fTrackInfo->SetTrack(track);
275 if(fDebugLevel>=2) printf("Ntracklets[%d]\n", fTrackInfo->GetNTracklets());
276 } else if(fDebugLevel>=2) printf("No ESD friends\n");
277 if(op) fTrackInfo->SetOuterParam(op);
279 if(fDebugLevel >= 1){
280 AliTRDtrackInfo info(*fTrackInfo);
281 (*fDebugStream) << "trackInfo"
282 << "TrackInfo.=" << &info
287 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
288 fTrackInfo->Delete("");
290 if(fDebugLevel>=2) printf("%3d Tracks: TPC[%d] TRD[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTPC, nTRD);
292 // Insert also MC tracks which are passing TRD where the track is not reconstructed
294 if(fDebugLevel > 10){
295 printf("Output of the MC track map:\n");
296 for(Int_t itk = 0; itk < nTracksMC; itk++)
297 printf("trackMap[%d] = %s\n", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE");
300 for(Int_t itk = 0; itk < nTracksMC; itk++){
301 if(trackMap[itk]) continue;
302 AliMCParticle *mcParticle = fMC->GetTrack(TMath::Abs(itk));
303 Int_t fPdg = mcParticle->Particle()->GetPdgCode();
304 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
305 Int_t iref = 0; AliTrackReference *ref = 0x0;
307 new(fTrackInfo) AliTRDtrackInfo();
308 fTrackInfo->SetPDG(fPdg);
310 ref = mcParticle->GetTrackReference(iref);
311 if(fDebugLevel > 3) printf("\ttrackRef[%2d] @ %7.3f", iref, ref->LocalX());
312 if(ref->LocalX() > 250. && ref->LocalX() < 370.){
313 if(fDebugLevel > 3) printf(" OK\n");
314 fTrackInfo->AddTrackRef(ref);
318 if(fDebugLevel > 3) printf("\n");
322 // In this stage we at least require 1 hit inside TRD. What will be done with this tracks is a task for the
324 fTrackInfo->Delete("");
327 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
328 fTrackInfo->SetLabel(itk);
329 if(fDebugLevel >= 1){
330 AliTRDtrackInfo info(*fTrackInfo);
331 (*fDebugStream) << "trackInfo"
332 << "TrackInfo.=" << &info
336 if(fDebugLevel > 2)printf("Registering rejected MC track with label %d\n", itk);
337 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
338 fTrackInfo->Delete("");
342 PostData(0, fContainer);
343 PostData(1, fEventInfo);
347 //____________________________________________________________________
348 void AliTRDtrackInfoGen::Terminate(Option_t *)
351 // Stays empty because we are only interested in the tree
353 if(fDebugLevel>=1) printf("Terminate:\n");
354 //TFile *f =((TFile*)gROOT->FindObject("TRD.TrackInfo.root"));
355 //f->cd(); f->Write(); f->Close();