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: AliTRDinfoGen.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 "AliTRDcluster.h"
55 #include "AliTRDseedV1.h"
56 #include "TTreeStream.h"
63 #include "AliTRDinfoGen.h"
64 #include "info/AliTRDtrackInfo.h"
65 #include "info/AliTRDeventInfo.h"
66 #include "info/AliTRDv0Info.h"
68 ClassImp(AliTRDinfoGen)
70 const Float_t AliTRDinfoGen::xTPC = 290.;
71 const Float_t AliTRDinfoGen::xTOF = 365.;
73 //____________________________________________________________________
74 AliTRDinfoGen::AliTRDinfoGen():
75 AliTRDrecoTask("infoGen", "MC-REC TRD-track list generator")
85 // Default constructor
88 DefineInput(0, TChain::Class());
89 DefineOutput(0, TObjArray::Class());
90 DefineOutput(1, AliTRDeventInfo::Class());
91 DefineOutput(2, TObjArray::Class());
94 //____________________________________________________________________
95 AliTRDinfoGen::~AliTRDinfoGen()
97 if(fTrackInfo) delete fTrackInfo; fTrackInfo = 0x0;
98 if(fEventInfo) delete fEventInfo; fEventInfo = 0x0;
99 if(fV0Info) delete fV0Info; fV0Info = 0x0;
101 fContainer->Delete(); delete fContainer;
105 fV0container->Delete(); delete fV0container;
110 //____________________________________________________________________
111 void AliTRDinfoGen::ConnectInputData(Option_t *)
114 // Link the Input Data
116 TTree *tree = dynamic_cast<TChain*>(GetInputData(0));
118 printf("ERROR - ESD event not found");
120 tree->SetBranchStatus("Tracks", 1);
121 tree->SetBranchStatus("ESDfriend*",1);
124 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
126 printf("ERROR - ESD input handler not found");
128 fESD = esdH->GetEvent();
130 printf("ERROR - ESD event not found");
132 esdH->SetActiveBranches("ESDfriend*");
133 fESDfriend = (AliESDfriend *)fESD->FindListObject("AliESDfriend");
137 AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
139 AliError("MC input handler not found");
141 fMC = mcH->MCEvent();
146 //____________________________________________________________________
147 void AliTRDinfoGen::CreateOutputObjects()
150 // Create Output Containers (TObjectArray containing 1D histograms)
152 fTrackInfo = new AliTRDtrackInfo();
153 fEventInfo = new AliTRDeventInfo();
154 fV0Info = new AliTRDv0Info();
155 fContainer = new TObjArray(1000);
156 fContainer->SetOwner(kTRUE);
157 fV0container = new TObjArray(50);
158 fV0container->SetOwner(kTRUE);
162 //____________________________________________________________________
163 void AliTRDinfoGen::Exec(Option_t *){
168 AliError("Failed retrieving ESD event");
172 AliError("Failed retrieving ESD friend event");
175 if(HasMCdata() && !fMC){
176 AliError("Failed retrieving MC event");
179 fContainer->Delete();
180 fV0container->Delete();
181 fEventInfo->Delete("");
182 fESD->SetESDfriend(fESDfriend);
183 new(fEventInfo)AliTRDeventInfo(fESD->GetHeader(), const_cast<AliESDRun *>(fESD->GetESDRun()));
185 Bool_t *trackMap = 0x0;
186 AliStack * mStack = 0x0;
187 Int_t nTracksMC = HasMCdata() ? fMC->GetNumberOfTracks() : 0, nTracksESD = fESD->GetNumberOfTracks();
189 mStack = fMC->Stack();
191 AliError("Failed retrieving MC Stack");
194 trackMap = new Bool_t[nTracksMC];
195 memset(trackMap, 0, sizeof(Bool_t) * nTracksMC);
198 Int_t nTRD = 0, nTPC = 0, nclsTrklt;
200 printf("Entry[%3d] Tracks: ESD[%d] MC[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC);
202 AliESDtrack *esdTrack = 0x0;
203 AliESDfriendTrack *esdFriendTrack = 0x0;
204 TObject *calObject = 0x0;
205 AliTRDtrackV1 *track = 0x0;
206 AliTRDseedV1 *tracklet = 0x0;
207 AliTRDcluster *cl = 0x0;
208 for(Int_t itrk = 0; itrk < nTracksESD; itrk++){
209 esdTrack = fESD->GetTrack(itrk);
210 if(fDebugLevel>=2) printf("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2));
211 if(esdTrack->GetNcls(1)) nTPC++;
212 if(esdTrack->GetNcls(2)) nTRD++;
214 // look at external track param
215 const AliExternalTrackParam *op = esdTrack->GetOuterParam();
219 op->Global2LocalPosition(xyz, op->GetAlpha());
220 if(fDebugLevel>=2) printf("op @ X[%7.3f]\n", xyz[0]);
225 Int_t label = -1; UInt_t alab=UINT_MAX;
227 label = esdTrack->GetLabel();
228 alab = TMath::Abs(label);
229 // register the track
230 if(alab < UInt_t(nTracksMC)){
231 trackMap[alab] = kTRUE;
233 AliError(Form("MC label[%d] outside scope for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
236 AliMCParticle *mcParticle = 0x0;
237 if(!(mcParticle = (AliMCParticle*) fMC->GetTrack(alab))){
238 AliError(Form("MC particle label[%d] missing for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
241 fPdg = mcParticle->Particle()->GetPdgCode();
242 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
243 Int_t iref = 0; AliTrackReference *ref = 0x0;
245 ref = mcParticle->GetTrackReference(iref);
246 if(ref->LocalX() > xTPC) break;
250 new(fTrackInfo) AliTRDtrackInfo();
251 fTrackInfo->SetPDG(fPdg);
252 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
253 Int_t jref = iref;//, kref = 0;
255 ref = mcParticle->GetTrackReference(jref);
256 if(ref->LocalX() > xTOF) break;
257 if(fDebugLevel>=3) printf("\ttrackRef[%2d (%2d)] @ %7.3f OK\n", jref-iref, jref, ref->LocalX());
258 fTrackInfo->AddTrackRef(ref);
261 if(fDebugLevel>=2) printf("NtrackRefs[%d(%d)]\n", fTrackInfo->GetNTrackRefs(), nRefs);
263 new (fTrackInfo) AliTRDtrackInfo();
264 fTrackInfo->SetPDG(fPdg);
267 // copy some relevant info to TRD track info
268 fTrackInfo->SetStatus(esdTrack->GetStatus());
269 fTrackInfo->SetTrackId(esdTrack->GetID());
270 Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p);
271 fTrackInfo->SetESDpid(p);
272 fTrackInfo->SetESDpidQuality(esdTrack->GetTRDntrackletsPID());
273 fTrackInfo->SetLabel(label);
274 fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2));
275 // some other Informations which we may wish to store in order to find problematic cases
276 fTrackInfo->SetKinkIndex(esdTrack->GetKinkIndex(0));
277 fTrackInfo->SetTPCncls(static_cast<UShort_t>(esdTrack->GetNcls(1)));
282 esdFriendTrack = fESDfriend->GetTrack(itrk);
285 while((calObject = esdFriendTrack->GetCalibObject(icalib++))){
286 if(strcmp(calObject->IsA()->GetName(),"AliTRDtrackV1") != 0) continue; // Look for the TRDtrack
287 if(!(track = dynamic_cast<AliTRDtrackV1*>(calObject))) break;
289 if(fDebugLevel>=3) printf("TRD track OK\n");
290 // Set the clusters to unused
291 for(Int_t ipl = 0; ipl < AliTRDgeometry::kNlayer; ipl++){
292 if(!(tracklet = track->GetTracklet(ipl))) continue;
293 tracklet->ResetClusterIter();
294 while((cl = tracklet->NextCluster())) cl->Use(0);
296 fTrackInfo->SetTrack(track);
299 if(fDebugLevel>=2) printf("Ntracklets[%d]\n", fTrackInfo->GetNTracklets());
300 } else if(fDebugLevel>=2) printf("No ESD friends\n");
301 if(op) fTrackInfo->SetOuterParam(op);
303 if(fDebugLevel >= 1){
304 AliTRDtrackInfo info(*fTrackInfo);
305 (*fDebugStream) << "trackInfo"
306 << "TrackInfo.=" << &info
311 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
312 fTrackInfo->Delete("");
314 if(fDebugLevel>=2) printf("%3d Tracks: TPC[%d] TRD[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTPC, nTRD);
317 for(Int_t iv0=0; iv0<fESD->GetNumberOfV0s(); iv0++){
318 if(!(v0 = fESD->GetV0(iv0))) continue;
319 fV0container->Add(new AliTRDv0Info(v0));
322 // Insert also MC tracks which are passing TRD where the track is not reconstructed
324 if(fDebugLevel > 10){
325 printf("Output of the MC track map:\n");
326 for(Int_t itk = 0; itk < nTracksMC; itk++)
327 printf("trackMap[%d] = %s\n", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE");
330 for(Int_t itk = 0; itk < nTracksMC; itk++){
331 if(trackMap[itk]) continue;
332 AliMCParticle *mcParticle = (AliMCParticle*) fMC->GetTrack(TMath::Abs(itk));
333 Int_t fPdg = mcParticle->Particle()->GetPdgCode();
334 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
335 Int_t iref = 0; AliTrackReference *ref = 0x0;
337 new(fTrackInfo) AliTRDtrackInfo();
338 fTrackInfo->SetPDG(fPdg);
340 ref = mcParticle->GetTrackReference(iref);
341 if(fDebugLevel > 3) printf("\ttrackRef[%2d] @ %7.3f", iref, ref->LocalX());
342 if(ref->LocalX() > 250. && ref->LocalX() < 370.){
343 if(fDebugLevel > 3) printf(" OK\n");
344 fTrackInfo->AddTrackRef(ref);
348 if(fDebugLevel > 3) printf("\n");
352 // In this stage we at least require 1 hit inside TRD. What will be done with this tracks is a task for the
354 fTrackInfo->Delete("");
357 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
358 fTrackInfo->SetLabel(itk);
359 if(fDebugLevel >= 1){
360 AliTRDtrackInfo info(*fTrackInfo);
361 (*fDebugStream) << "trackInfo"
362 << "TrackInfo.=" << &info
366 if(fDebugLevel > 2)printf("Registering rejected MC track with label %d\n", itk);
367 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
368 fTrackInfo->Delete("");
372 PostData(0, fContainer);
373 PostData(1, fEventInfo);
374 PostData(2, fV0container);
378 //____________________________________________________________________
379 void AliTRDinfoGen::Terminate(Option_t *)
382 // Stays empty because we are only interested in the tree