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 const Float_t AliTRDinfoGen::fgkEvVertexZ = 15.;
81 const Int_t AliTRDinfoGen::fgkEvVertexN = 1;
83 const Float_t AliTRDinfoGen::fgkTrkDCAxy = 40.;
84 const Float_t AliTRDinfoGen::fgkTrkDCAz = 15.;
85 const Int_t AliTRDinfoGen::fgkNclTPC = 10;
86 const Float_t AliTRDinfoGen::fgkPt = 0.2;
87 const Float_t AliTRDinfoGen::fgkEta = 0.9;
89 //____________________________________________________________________
90 AliTRDinfoGen::AliTRDinfoGen():
92 ,fEvTrigger("CINT1B-ABCE-NOPF-ALL")
101 // Default constructor
105 AliTRDinfoGen::AliTRDinfoGen(char* name):
106 AliTRDrecoTask(name, "MC-REC TRD-track list generator")
115 // Default constructor
117 DefineOutput(2, AliTRDeventInfo::Class()); // -> TRDeventInfo
118 DefineOutput(3, TObjArray::Class()); // -> TObjArray
121 //____________________________________________________________________
122 AliTRDinfoGen::~AliTRDinfoGen()
126 if(fTrackInfo) delete fTrackInfo; fTrackInfo = NULL;
127 if(fEventInfo) delete fEventInfo; fEventInfo = NULL;
128 if(fV0Info) delete fV0Info; fV0Info = NULL;
130 fContainer->Delete(); delete fContainer;
134 fV0container->Delete(); delete fV0container;
139 //____________________________________________________________________
140 void AliTRDinfoGen::UserCreateOutputObjects()
143 // Create Output Containers (TObjectArray containing 1D histograms)
145 fTrackInfo = new AliTRDtrackInfo();
146 fEventInfo = new AliTRDeventInfo();
147 fV0Info = new AliTRDv0Info();
148 fContainer = new TObjArray(1000);
149 fContainer->SetOwner(kTRUE);
150 fV0container = new TObjArray(50);
151 fV0container->SetOwner(kTRUE);
155 //____________________________________________________________________
156 void AliTRDinfoGen::UserExec(Option_t *){
160 fESDev = dynamic_cast<AliESDEvent*>(InputEvent());
164 AliError("Failed retrieving ESD event");
168 // event selection : trigger cut
169 if(UseLocalEvSelection() &&
170 fEvTrigger.Data()[0]!='\0'){
171 Bool_t kTRIGGERED(kFALSE);
172 const TObjArray *trig = fEvTrigger.Tokenize(" ");
173 for(Int_t itrig=trig->GetEntriesFast(); itrig--;){
174 const Char_t *trigClass(((TObjString*)(*trig)[itrig])->GetName());
175 if(fESDev->IsTriggerClassFired(trigClass)) {
176 AliDebug(2, Form("Ev[%4d] Trigger[%s]", fESDev->GetEventNumberInFile(), trigClass));
181 if(!kTRIGGERED) return;
183 // select only physical events
184 if(fESDev->GetEventType() != 7) return;
187 // if the required trigger is a collision trigger then apply event vertex cut
188 if(UseLocalEvSelection() && IsCollision()){
189 const AliESDVertex *vertex = fESDev->GetPrimaryVertex();
190 if(TMath::Abs(vertex->GetZv())<1.e-10 ||
191 TMath::Abs(vertex->GetZv())>fgkEvVertexZ ||
192 vertex->GetNContributors()<fgkEvVertexN) {
193 //PostData(0, fOutStorage);
199 AliError("Failed retrieving ESD friend event");
202 if(HasMCdata() && !fMCev){
203 AliError("Failed retrieving MC event");
207 fContainer->Delete();
208 fV0container->Delete();
209 fEventInfo->Delete("");
210 new(fEventInfo)AliTRDeventInfo(fESDev->GetHeader(), const_cast<AliESDRun *>(fESDev->GetESDRun()));
212 Bool_t *trackMap(NULL);
213 AliStack * mStack(NULL);
214 Int_t nTracksMC = HasMCdata() ? fMCev->GetNumberOfTracks() : 0, nTracksESD = fESDev->GetNumberOfTracks();
216 mStack = fMCev->Stack();
218 AliError("Failed retrieving MC Stack");
221 trackMap = new Bool_t[nTracksMC];
222 memset(trackMap, 0, sizeof(Bool_t) * nTracksMC);
225 Double32_t dedx[100]; Int_t nSlices(0);
226 Int_t nTRDout(0), nTRDin(0), nTPC(0), nclsTrklt;
227 AliDebug(2, Form("Entry[%3d] Tracks: ESD[%d] MC[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC));
228 AliESDtrack *esdTrack = NULL;
229 AliESDfriendTrack *esdFriendTrack = NULL;
230 TObject *calObject = NULL;
231 AliTRDtrackV1 *track = NULL;
232 AliTRDseedV1 *tracklet = NULL;
233 AliTRDcluster *cl = NULL;
234 for(Int_t itrk = 0; itrk < nTracksESD; itrk++){
235 esdTrack = fESDev->GetTrack(itrk);
236 AliDebug(3, Form("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2)));
239 if(UseLocalTrkSelection()){
240 if(esdTrack->Pt() < fgkPt) continue;
241 if(TMath::Abs(esdTrack->Eta()) > fgkEta) continue;
242 if(esdTrack->GetTPCNcls() < fgkNclTPC) continue;
243 Float_t par[2], cov[3];
244 esdTrack->GetImpactParameters(par, cov);
245 if(IsCollision()){ // cuts on DCA
246 if(TMath::Abs(par[0]) > fgkTrkDCAxy) continue;
247 if(TMath::Abs(par[1]) > fgkTrkDCAz) continue;
251 if(esdTrack->GetStatus()&AliESDtrack::kTPCout) nTPC++;
252 if(esdTrack->GetStatus()&AliESDtrack::kTRDout) nTRDout++;
253 if(esdTrack->GetStatus()&AliESDtrack::kTRDin) nTRDin++;
255 // look at external track param
256 const AliExternalTrackParam *op = esdTrack->GetOuterParam();
260 op->Global2LocalPosition(xyz, op->GetAlpha());
261 AliDebug(3, Form("op @ X[%7.3f]\n", xyz[0]));
266 Int_t label = -1; UInt_t alab=UINT_MAX;
268 label = esdTrack->GetLabel();
269 alab = TMath::Abs(label);
270 // register the track
271 if(alab < UInt_t(nTracksMC)){
272 trackMap[alab] = kTRUE;
274 AliError(Form("MC label[%d] outside scope for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
277 AliMCParticle *mcParticle = NULL;
278 if(!(mcParticle = (AliMCParticle*) fMCev->GetTrack(alab))){
279 AliError(Form("MC particle label[%d] missing for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
282 fPdg = mcParticle->Particle()->GetPdgCode();
283 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
284 Int_t iref = 0; AliTrackReference *ref = NULL;
286 ref = mcParticle->GetTrackReference(iref);
287 if(ref->LocalX() > fgkTPC) break;
291 new(fTrackInfo) AliTRDtrackInfo();
292 fTrackInfo->SetPDG(fPdg);
293 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
294 Int_t jref = iref;//, kref = 0;
296 ref = mcParticle->GetTrackReference(jref);
297 if(ref->LocalX() > fgkTOF) break;
298 AliDebug(4, Form(" trackRef[%2d (%2d)] @ %7.3f OK", jref-iref, jref, ref->LocalX()));
299 fTrackInfo->AddTrackRef(ref);
302 AliDebug(3, Form("NtrackRefs[%d(%d)]", fTrackInfo->GetNTrackRefs(), nRefs));
304 new (fTrackInfo) AliTRDtrackInfo();
305 fTrackInfo->SetPDG(fPdg);
308 // copy some relevant info to TRD track info
309 fTrackInfo->SetStatus(esdTrack->GetStatus());
310 fTrackInfo->SetTrackId(esdTrack->GetID());
311 Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p);
312 fTrackInfo->SetESDpid(p);
313 fTrackInfo->SetESDpidQuality(esdTrack->GetTRDntrackletsPID());
314 if(!nSlices) nSlices = esdTrack->GetNumberOfTRDslices();
315 memset(dedx, 0, 100*sizeof(Double32_t));
317 for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++)
318 for(Int_t is=0; is<nSlices; is++)
319 dedx[in++]=esdTrack->GetTRDslice(il, is);
320 for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++) dedx[in++]=esdTrack->GetTRDmomentum(il);
321 fTrackInfo->SetSlices(in, dedx);
322 fTrackInfo->SetLabel(label);
323 fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2));
324 // some other Informations which we may wish to store in order to find problematic cases
325 fTrackInfo->SetKinkIndex(esdTrack->GetKinkIndex(0));
326 fTrackInfo->SetTPCncls(static_cast<UShort_t>(esdTrack->GetNcls(1)));
331 esdFriendTrack = fESDfriend->GetTrack(itrk);
334 while((calObject = esdFriendTrack->GetCalibObject(icalib++))){
335 if(strcmp(calObject->IsA()->GetName(),"AliTRDtrackV1") != 0) continue; // Look for the TRDtrack
336 if(!(track = dynamic_cast<AliTRDtrackV1*>(calObject))) break;
337 AliDebug(4, Form("TRD track OK"));
338 // Set the clusters to unused
339 for(Int_t ipl = 0; ipl < AliTRDgeometry::kNlayer; ipl++){
340 if(!(tracklet = track->GetTracklet(ipl))) continue;
341 tracklet->ResetClusterIter();
342 while((cl = tracklet->NextCluster())) cl->Use(0);
344 fTrackInfo->SetTrack(track);
347 AliDebug(3, Form("Ntracklets[%d]\n", fTrackInfo->GetNTracklets()));
348 } else AliDebug(3, "No ESD friends");
349 if(op) fTrackInfo->SetOuterParam(op);
351 if(DebugLevel() >= 1){
352 AliTRDtrackInfo info(*fTrackInfo);
353 (*DebugStream()) << "trackInfo"
354 << "TrackInfo.=" << &info
359 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
360 fTrackInfo->Delete("");
362 AliDebug(2, Form("%3d Tracks: TPCout[%d] TRDin[%d] TRDout[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTPC, nTRDin, nTRDout));
364 // AliESDv0 *v0 = NULL;
365 // for(Int_t iv0=0; iv0<fESD->GetNumberOfV0s(); iv0++){
366 // if(!(v0 = fESD->GetV0(iv0))) continue;
367 // fV0container->Add(new AliTRDv0Info(v0));
370 // Insert also MC tracks which are passing TRD where the track is not reconstructed
372 AliDebug(10, "Output of the MC track map:");
373 for(Int_t itk = 0; itk < nTracksMC; itk++) AliDebug(10, Form("trackMap[%d] = %s", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE"));
375 for(Int_t itk = 0; itk < nTracksMC; itk++){
376 if(trackMap[itk]) continue;
377 AliMCParticle *mcParticle = (AliMCParticle*) fMCev->GetTrack(TMath::Abs(itk));
378 Int_t fPdg = mcParticle->Particle()->GetPdgCode();
379 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
380 Int_t iref = 0; AliTrackReference *ref = NULL;
382 new(fTrackInfo) AliTRDtrackInfo();
383 fTrackInfo->SetPDG(fPdg);
386 ref = mcParticle->GetTrackReference(iref);
387 if(ref->LocalX() > fgkTPC && ref->LocalX() < fgkTOF){
388 fTrackInfo->AddTrackRef(ref);
389 nRefsTRD++;kIN=kTRUE;
391 AliDebug(4, Form(" trackRef[%2d] @ x[%7.3f] %s", iref, ref->LocalX(), kIN?"IN":"OUT"));
395 // In this stage we at least require 1 hit inside TRD. What will be done with this tracks is a task for the
397 fTrackInfo->Delete("");
400 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
401 fTrackInfo->SetLabel(itk);
402 if(DebugLevel() >= 1){
403 AliTRDtrackInfo info(*fTrackInfo);
404 (*DebugStream()) << "trackInfo"
405 << "TrackInfo.=" << &info
409 AliDebug(3, Form("Add MC track @ label[%d] nTRDrefs[%d].", itk, nRefsTRD));
410 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
411 fTrackInfo->Delete("");
415 PostData(1, fContainer);
416 PostData(2, fEventInfo);
417 PostData(3, fV0container);