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 // Tender wagon for TRD performance/calibration train
22 // In this wagon the information from
24 // - Friends [if available]
25 // - MC [if available]
26 // are grouped into AliTRDtrackInfo objects and fed to worker tasks
29 // Markus Fasel <M.Fasel@gsi.de>
30 // Alexandru Bercuci <A.Bercuci@gsi.de>
32 ////////////////////////////////////////////////////////////////////////////
34 #include <TClonesArray.h>
35 #include <TObjArray.h>
42 #include <TParticle.h>
45 #include "AliAnalysisManager.h"
46 #include "AliESDEvent.h"
47 #include "AliMCEvent.h"
48 #include "AliESDInputHandler.h"
49 #include "AliMCEventHandler.h"
51 #include "AliESDfriend.h"
52 #include "AliESDfriendTrack.h"
53 #include "AliESDHeader.h"
54 #include "AliESDtrack.h"
55 #include "AliMCParticle.h"
58 #include "AliTRDtrackV1.h"
59 #include "AliTrackReference.h"
60 #include "AliTRDgeometry.h"
61 #include "AliTRDcluster.h"
62 #include "AliTRDseedV1.h"
63 #include "TTreeStream.h"
70 #include "AliTRDinfoGen.h"
71 #include "info/AliTRDtrackInfo.h"
72 #include "info/AliTRDeventInfo.h"
73 #include "info/AliTRDv0Info.h"
75 ClassImp(AliTRDinfoGen)
77 const Float_t AliTRDinfoGen::fgkTPC = 290.;
78 const Float_t AliTRDinfoGen::fgkTOF = 365.;
80 //____________________________________________________________________
81 AliTRDinfoGen::AliTRDinfoGen():
82 AliTRDrecoTask("infoGen", "MC-REC TRD-track list generator")
92 // Default constructor
95 DefineInput(0, TChain::Class());
96 DefineOutput(0, TObjArray::Class());
97 DefineOutput(1, AliTRDeventInfo::Class());
98 DefineOutput(2, TObjArray::Class());
101 //____________________________________________________________________
102 AliTRDinfoGen::~AliTRDinfoGen()
105 if(fTrackInfo) delete fTrackInfo; fTrackInfo = 0x0;
106 if(fEventInfo) delete fEventInfo; fEventInfo = 0x0;
107 if(fV0Info) delete fV0Info; fV0Info = 0x0;
109 fContainer->Delete(); delete fContainer;
113 fV0container->Delete(); delete fV0container;
118 //____________________________________________________________________
119 void AliTRDinfoGen::ConnectInputData(Option_t *)
122 // Link the Input Data
124 TTree *tree = dynamic_cast<TChain*>(GetInputData(0));
126 printf("ERROR - ESD event not found");
128 tree->SetBranchStatus("Tracks", 1);
129 tree->SetBranchStatus("ESDfriend*",1);
132 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
134 printf("ERROR - ESD input handler not found");
136 fESDev = esdH->GetEvent();
138 printf("ERROR - ESD event not found");
140 esdH->SetActiveBranches("ESDfriend*");
141 fESDfriend = (AliESDfriend *)fESDev->FindListObject("AliESDfriend");
145 AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
147 AliError("MC input handler not found");
149 fMCev = mcH->MCEvent();
154 //____________________________________________________________________
155 void AliTRDinfoGen::CreateOutputObjects()
158 // Create Output Containers (TObjectArray containing 1D histograms)
160 fTrackInfo = new AliTRDtrackInfo();
161 fEventInfo = new AliTRDeventInfo();
162 fV0Info = new AliTRDv0Info();
163 fContainer = new TObjArray(1000);
164 fContainer->SetOwner(kTRUE);
165 fV0container = new TObjArray(50);
166 fV0container->SetOwner(kTRUE);
170 //____________________________________________________________________
171 void AliTRDinfoGen::Exec(Option_t *){
176 AliError("Failed retrieving ESD event");
180 AliError("Failed retrieving ESD friend event");
183 if(HasMCdata() && !fMCev){
184 AliError("Failed retrieving MC event");
187 fContainer->Delete();
188 fV0container->Delete();
189 fEventInfo->Delete("");
190 fESDev->SetESDfriend(fESDfriend);
191 new(fEventInfo)AliTRDeventInfo(fESDev->GetHeader(), const_cast<AliESDRun *>(fESDev->GetESDRun()));
193 Bool_t *trackMap = 0x0;
194 AliStack * mStack = 0x0;
195 Int_t nTracksMC = HasMCdata() ? fMCev->GetNumberOfTracks() : 0, nTracksESD = fESDev->GetNumberOfTracks();
197 mStack = fMCev->Stack();
199 AliError("Failed retrieving MC Stack");
202 trackMap = new Bool_t[nTracksMC];
203 memset(trackMap, 0, sizeof(Bool_t) * nTracksMC);
206 Int_t nTRD = 0, nTPC = 0, nclsTrklt;
207 AliDebug(2, Form("Entry[%3d] Tracks: ESD[%d] MC[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC));
208 AliESDtrack *esdTrack = 0x0;
209 AliESDfriendTrack *esdFriendTrack = 0x0;
210 TObject *calObject = 0x0;
211 AliTRDtrackV1 *track = 0x0;
212 AliTRDseedV1 *tracklet = 0x0;
213 AliTRDcluster *cl = 0x0;
214 for(Int_t itrk = 0; itrk < nTracksESD; itrk++){
215 esdTrack = fESDev->GetTrack(itrk);
216 AliDebug(3, Form("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2)));
217 if(esdTrack->GetNcls(1)) nTPC++;
218 if(esdTrack->GetNcls(2)) nTRD++;
220 // look at external track param
221 const AliExternalTrackParam *op = esdTrack->GetOuterParam();
225 op->Global2LocalPosition(xyz, op->GetAlpha());
226 AliDebug(3, Form("op @ X[%7.3f]\n", xyz[0]));
231 Int_t label = -1; UInt_t alab=UINT_MAX;
233 label = esdTrack->GetLabel();
234 alab = TMath::Abs(label);
235 // register the track
236 if(alab < UInt_t(nTracksMC)){
237 trackMap[alab] = kTRUE;
239 AliError(Form("MC label[%d] outside scope for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
242 AliMCParticle *mcParticle = 0x0;
243 if(!(mcParticle = (AliMCParticle*) fMCev->GetTrack(alab))){
244 AliError(Form("MC particle label[%d] missing for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
247 fPdg = mcParticle->Particle()->GetPdgCode();
248 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
249 Int_t iref = 0; AliTrackReference *ref = 0x0;
251 ref = mcParticle->GetTrackReference(iref);
252 if(ref->LocalX() > fgkTPC) break;
256 new(fTrackInfo) AliTRDtrackInfo();
257 fTrackInfo->SetPDG(fPdg);
258 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
259 Int_t jref = iref;//, kref = 0;
261 ref = mcParticle->GetTrackReference(jref);
262 if(ref->LocalX() > fgkTOF) break;
263 AliDebug(4, Form(" trackRef[%2d (%2d)] @ %7.3f OK", jref-iref, jref, ref->LocalX()));
264 fTrackInfo->AddTrackRef(ref);
267 AliDebug(3, Form("NtrackRefs[%d(%d)]", fTrackInfo->GetNTrackRefs(), nRefs));
269 new (fTrackInfo) AliTRDtrackInfo();
270 fTrackInfo->SetPDG(fPdg);
273 // copy some relevant info to TRD track info
274 fTrackInfo->SetStatus(esdTrack->GetStatus());
275 fTrackInfo->SetTrackId(esdTrack->GetID());
276 Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p);
277 fTrackInfo->SetESDpid(p);
278 fTrackInfo->SetESDpidQuality(esdTrack->GetTRDntrackletsPID());
279 fTrackInfo->SetLabel(label);
280 fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2));
281 // some other Informations which we may wish to store in order to find problematic cases
282 fTrackInfo->SetKinkIndex(esdTrack->GetKinkIndex(0));
283 fTrackInfo->SetTPCncls(static_cast<UShort_t>(esdTrack->GetNcls(1)));
288 esdFriendTrack = fESDfriend->GetTrack(itrk);
291 while((calObject = esdFriendTrack->GetCalibObject(icalib++))){
292 if(strcmp(calObject->IsA()->GetName(),"AliTRDtrackV1") != 0) continue; // Look for the TRDtrack
293 if(!(track = dynamic_cast<AliTRDtrackV1*>(calObject))) break;
295 AliDebug(4, Form("TRD track OK"));
296 // Set the clusters to unused
297 for(Int_t ipl = 0; ipl < AliTRDgeometry::kNlayer; ipl++){
298 if(!(tracklet = track->GetTracklet(ipl))) continue;
299 tracklet->ResetClusterIter();
300 while((cl = tracklet->NextCluster())) cl->Use(0);
302 fTrackInfo->SetTrack(track);
305 AliDebug(3, Form("Ntracklets[%d]\n", fTrackInfo->GetNTracklets()));
306 } else AliDebug(3, "No ESD friends");
307 if(op) fTrackInfo->SetOuterParam(op);
309 if(DebugLevel() >= 1){
310 AliTRDtrackInfo info(*fTrackInfo);
311 (*DebugStream()) << "trackInfo"
312 << "TrackInfo.=" << &info
317 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
318 fTrackInfo->Delete("");
320 AliDebug(3, Form("%3d Tracks: TPC[%d] TRD[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTPC, nTRD));
322 // AliESDv0 *v0 = 0x0;
323 // for(Int_t iv0=0; iv0<fESD->GetNumberOfV0s(); iv0++){
324 // if(!(v0 = fESD->GetV0(iv0))) continue;
325 // fV0container->Add(new AliTRDv0Info(v0));
328 // Insert also MC tracks which are passing TRD where the track is not reconstructed
330 AliDebug(10, "Output of the MC track map:");
331 for(Int_t itk = 0; itk < nTracksMC; itk++) AliDebug(10, Form("trackMap[%d] = %s", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE"));
333 for(Int_t itk = 0; itk < nTracksMC; itk++){
334 if(trackMap[itk]) continue;
335 AliMCParticle *mcParticle = (AliMCParticle*) fMCev->GetTrack(TMath::Abs(itk));
336 Int_t fPdg = mcParticle->Particle()->GetPdgCode();
337 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
338 Int_t iref = 0; AliTrackReference *ref = 0x0;
340 new(fTrackInfo) AliTRDtrackInfo();
341 fTrackInfo->SetPDG(fPdg);
343 ref = mcParticle->GetTrackReference(iref);
344 if(ref->LocalX() > 250. && ref->LocalX() < 370.){
345 AliDebug(4, Form(" trackRef[%2d] @ %7.3f IN", iref, ref->LocalX()));
346 fTrackInfo->AddTrackRef(ref);
349 else AliDebug(4, Form(" trackRef[%2d] @ %7.3f OUT", iref, ref->LocalX()));
353 // In this stage we at least require 1 hit inside TRD. What will be done with this tracks is a task for the
355 fTrackInfo->Delete("");
358 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
359 fTrackInfo->SetLabel(itk);
360 if(DebugLevel() >= 1){
361 AliTRDtrackInfo info(*fTrackInfo);
362 (*DebugStream()) << "trackInfo"
363 << "TrackInfo.=" << &info
367 AliDebug(3, Form("Registering rejected MC track with label %d", itk));
368 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
369 fTrackInfo->Delete("");
373 PostData(0, fContainer);
374 PostData(1, fEventInfo);
375 PostData(2, fV0container);