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 "AliESDtrack.h"
47 #include "AliMCParticle.h"
49 #include "AliTRDtrackV1.h"
50 #include "AliTrackReference.h"
51 #include "AliTRDgeometry.h"
52 #include "TTreeStream.h"
57 #include "AliTRDtrackInfoGen.h"
58 #include "AliTRDtrackInfo/AliTRDtrackInfo.h"
60 ClassImp(AliTRDtrackInfoGen)
63 //____________________________________________________________________
64 AliTRDtrackInfoGen::AliTRDtrackInfoGen():
65 AliTRDrecoTask("InfoGen", "Track List Generator")
72 // Default constructor
75 DefineInput(0, TChain::Class());
76 DefineOutput(0, TObjArray::Class());
77 //DefineOutput(1, TTree::Class());
80 //____________________________________________________________________
81 AliTRDtrackInfoGen::~AliTRDtrackInfoGen()
83 if(fTrackInfo) delete fTrackInfo;
86 //____________________________________________________________________
87 void AliTRDtrackInfoGen::ConnectInputData(Option_t *)
90 // Link the Input Data
92 TTree *tree = dynamic_cast<TChain*>(GetInputData(0));
94 printf("ERROR - ESD event not found");
96 tree->SetBranchStatus("Tracks", 1);
97 tree->SetBranchStatus("ESDfriend*",1);
100 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
102 printf("ERROR - ESD input handler not found");
104 fESD = esdH->GetEvent();
106 printf("ERROR - ESD event not found");
108 esdH->SetActiveBranches("ESDfriend*");
109 fESDfriend = (AliESDfriend *)fESD->FindListObject("AliESDfriend");
113 AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
115 AliError("MC input handler not found");
117 fMC = mcH->MCEvent();
122 //____________________________________________________________________
123 void AliTRDtrackInfoGen::CreateOutputObjects()
126 // Create Output Containers (TObjectArray containing 1D histograms)
128 fTrackInfo = new AliTRDtrackInfo();
129 fContainer = new TObjArray(1000);
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());*/
137 //____________________________________________________________________
138 void AliTRDtrackInfoGen::Exec(Option_t *){
143 puts("Error: ESD not found");
147 puts("Error: ESD friend not found");
150 if(HasMCdata() && !fMC){
151 puts("Error: Monte Carlo Event not available");
154 fContainer->Delete();
155 fESD->SetESDfriend(fESDfriend);
157 Bool_t *trackMap = 0x0;
158 AliStack * mStack = 0x0;
160 mStack = fMC->Stack();
162 puts("Error: Cannot get the Monte Carlo Stack");
165 trackMap = new Bool_t[fMC->GetNumberOfTracks()];
166 memset(trackMap, 0, sizeof(Bool_t) * fMC->GetNumberOfTracks());
169 Int_t nTRD = 0, nTPC = 0, nclsTrklt;
170 Int_t nTracks = fESD->GetNumberOfTracks();
172 printf("%3d Tracks: ESD[%d] MC[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracks, HasMCdata() ? mStack->GetNtrack() : 0);
174 AliESDtrack *esdTrack = 0x0;
175 AliESDfriendTrack *esdFriendTrack = 0x0;
176 TObject *calObject = 0x0;
177 AliTRDtrackV1 *track = 0x0;
178 for(Int_t itrk = 0; itrk < nTracks; itrk++){
179 esdTrack = fESD->GetTrack(itrk);
180 if(fDebugLevel>=2) printf("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2));
181 if(esdTrack->GetNcls(1)) nTPC++;
182 if(esdTrack->GetNcls(2)) nTRD++;
184 // look at esternal track param
185 const AliExternalTrackParam *op = esdTrack->GetOuterParam();
189 op->Global2LocalPosition(xyz, op->GetAlpha());
190 if(fDebugLevel>=2) printf("op @ X[%7.3f]\n", xyz[0]);
192 /* if(xyz[0] < 270.){
193 printf("TPC track missing\n");
195 // op->GetXYZAt(ref->LocalX(), AliTracker::GetBz(), xyz);
196 // op->Global2LocalPosition(xyz, op->GetAlpha());
197 // dy = ref->LocalY()- xyz[1];
198 // dz = ref->Z() - xyz[2];
205 label = esdTrack->GetLabel();
206 if(label < fMC->GetNumberOfTracks()) trackMap[TMath::Abs(label)] = kTRUE; // register the track
207 //if (TMath::Abs(label) > mStack->GetNtrack()) continue;
208 AliMCParticle *mcParticle = fMC->GetTrack(TMath::Abs(label));
209 fPdg = mcParticle->Particle()->GetPdgCode();
210 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
211 Int_t iref = 0; AliTrackReference *ref = 0x0;
213 ref = mcParticle->GetTrackReference(iref);
214 if(ref->LocalX() > 250.) break;
215 //printf("\ttrackRef[%2d] @ %7.3f\n", iref, ref->LocalX());
219 // if(!esdTrack->GetNcls(2)) continue;
220 /* printf("No TRD Track References in the Track [%d] I\n", itrk);
221 printf("Label = %d ITS[%d] TPC[%d] TRD[%d]\n", label, esdTrack->GetITSLabel(), esdTrack->GetTPCLabel(), esdTrack->GetTRDLabel());
224 ref = mcParticle->GetTrackReference(kref);
225 printf("\ttrackRef[%2d] @ %7.3f\n", kref, ref->LocalX());
230 new(fTrackInfo) AliTRDtrackInfo(fPdg);
231 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
232 Int_t jref = iref;//, kref = 0;
234 ref = mcParticle->GetTrackReference(jref);
235 if(ref->LocalX() > 370.) break;
236 if(fDebugLevel>=3) printf("\ttrackRef[%2d (%2d)] @ %7.3f OK\n", jref-iref, jref, ref->LocalX());
237 fTrackInfo->AddTrackRef(ref);
240 if(!fTrackInfo->GetNTrackRefs()){
241 //if(!esdTrack->GetNcls(2)) continue;
242 /* printf("No TRD Track References in the Track [%d] II\n", itrk);
243 printf("Label = %d ITS[%d] TPC[%d] TRD[%d]\n", label, esdTrack->GetITSLabel(), esdTrack->GetTPCLabel(), esdTrack- >GetTRDLabel());
246 ref = mcParticle->GetTrackReference(kref);
247 printf("\ttrackRef[%2d] @ %7.3f\n", kref, ref->LocalX());
251 if(fDebugLevel>=2) printf("NtrackRefs[%d(%d)]\n", fTrackInfo->GetNTrackRefs(), nRefs);
253 new (fTrackInfo) AliTRDtrackInfo(fPdg);
256 // copy some relevant info to TRD track info
257 fTrackInfo->SetStatus(esdTrack->GetStatus());
258 fTrackInfo->SetTrackId(esdTrack->GetID());
259 fTrackInfo->SetLabel(label);
260 fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2));
261 fTrackInfo->SetFiredTriggerClass(fESD->GetFiredTriggerClasses());
262 fTrackInfo->SetTriggerCluster(fESD->GetHeader()->GetTriggerCluster());
267 esdFriendTrack = fESDfriend->GetTrack(itrk);
270 while((calObject = esdFriendTrack->GetCalibObject(icalib++))){
271 if(strcmp(calObject->IsA()->GetName(),"AliTRDtrackV1") != 0) continue; // Look for the TRDtrack
272 track = dynamic_cast<AliTRDtrackV1*>(calObject);
274 if(!esdTrack->GetNcls(2)){
275 printf("No TRD clusters but track\n");
279 if(fDebugLevel>=3) printf("TRD track OK\n");
280 fTrackInfo->SetTRDtrack(track);
283 if(fDebugLevel>=2) printf("Ntracklets[%d]\n", fTrackInfo->GetNTracklets());
284 } else if(fDebugLevel>=2) printf("No ESD friends\n");
285 if(op) fTrackInfo->SetOuterParam(op);
287 if(fDebugLevel >= 2){
288 Int_t ncls = esdTrack->GetNcls(2);
289 nclsTrklt = fTrackInfo->GetNumberOfClusters();
290 (*fDebugStream) << "trackInfo"
292 << "Ncls=" << nclsTrklt
293 << "TrackInfo.=" << fTrackInfo
297 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
298 fTrackInfo->Delete("");
300 if(fDebugLevel>=1) printf("%3d Tracks: TPC[%d] TRD[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTPC, nTRD);
302 // Insert also MC tracks which are passing TRD where the track is not reconstructed
304 if(fDebugLevel > 10){
305 printf("Output of the MC track map:\n");
306 for(Int_t itk = 0; itk < fMC->GetNumberOfTracks(); itk++)
307 printf("trackMap[%d] = %s\n", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE");
310 for(Int_t itk = 0; itk < fMC->GetNumberOfTracks(); itk++){
311 if(fDebugLevel >=2 ) printf("Number of MC tracks: %d\n", fMC->GetNumberOfTracks());
312 if(trackMap[itk]) continue;
313 AliMCParticle *mcParticle = fMC->GetTrack(TMath::Abs(itk));
314 Int_t fPdg = mcParticle->Particle()->GetPdgCode();
315 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
316 Int_t iref = 0; AliTrackReference *ref = 0x0;
318 new(fTrackInfo) AliTRDtrackInfo(fPdg);
320 ref = mcParticle->GetTrackReference(iref);
321 if(fDebugLevel > 3) printf("\ttrackRef[%2d] @ %7.3f", iref, ref->LocalX());
322 if(ref->LocalX() > 250. && ref->LocalX() < 370.){
323 if(fDebugLevel > 3) printf(" OK\n");
324 fTrackInfo->AddTrackRef(ref);
328 if(fDebugLevel > 3) printf("\n");
332 // In this stage we at least require 1 hit inside TRD. What will be done with this tracks is a task for the
334 fTrackInfo->Delete("");
337 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
338 fTrackInfo->SetLabel(itk);
339 if(fDebugLevel >= 1){
340 Int_t ncls = esdTrack->GetNcls(2);
341 (*fDebugStream) << "trackInfo"
342 << "ntrackRefs=" << ncls
343 << "TrackInfo.=" << fTrackInfo
346 if(fDebugLevel > 2)printf("Registering rejected MC track with label %d\n", itk);
347 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
348 fTrackInfo->Delete("");
352 PostData(0, fContainer);
356 //____________________________________________________________________
357 void AliTRDtrackInfoGen::Terminate(Option_t *)
360 // Stays empty because we are only interested in the tree
363 if(fDebugLevel>=1) printf("Terminate:\n");
364 //TFile *f =((TFile*)gROOT->FindObject("TRD.TrackInfo.root"));
365 //f->cd(); f->Write(); f->Close();