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 "AliESDtrackCuts.h"
56 #include "AliMCParticle.h"
59 #include "AliTRDtrackV1.h"
60 #include "AliTrackReference.h"
61 #include "AliTRDgeometry.h"
62 #include "AliTRDcluster.h"
63 #include "AliTRDseedV1.h"
64 #include "TTreeStream.h"
71 #include "AliTRDinfoGen.h"
72 #include "info/AliTRDtrackInfo.h"
73 #include "info/AliTRDeventInfo.h"
74 #include "info/AliTRDv0Info.h"
75 #include "info/AliTRDeventCuts.h"
77 ClassImp(AliTRDinfoGen)
79 const Float_t AliTRDinfoGen::fgkTPC = 290.;
80 const Float_t AliTRDinfoGen::fgkTOF = 365.;
82 const Float_t AliTRDinfoGen::fgkEvVertexZ = 15.;
83 const Int_t AliTRDinfoGen::fgkEvVertexN = 1;
85 const Float_t AliTRDinfoGen::fgkTrkDCAxy = 40.;
86 const Float_t AliTRDinfoGen::fgkTrkDCAz = 15.;
87 const Int_t AliTRDinfoGen::fgkNclTPC = 10;
88 const Float_t AliTRDinfoGen::fgkPt = 0.2;
89 const Float_t AliTRDinfoGen::fgkEta = 0.9;
91 //____________________________________________________________________
92 AliTRDinfoGen::AliTRDinfoGen():
94 ,fEvTrigger("CINT1B-ABCE-NOPF-ALL")
105 // Default constructor
109 //____________________________________________________________________
110 AliTRDinfoGen::AliTRDinfoGen(char* name):
111 AliTRDrecoTask(name, "MC-REC TRD-track list generator")
123 // Default constructor
125 DefineOutput(2, AliTRDeventInfo::Class()); // -> TRDeventInfo
126 DefineOutput(3, TObjArray::Class()); // -> TObjArray
129 //____________________________________________________________________
130 AliTRDinfoGen::~AliTRDinfoGen()
134 if(fTrackCut) delete fTrackCut;
135 if(fEventCut) delete fEventCut;
136 if(fTrackInfo) delete fTrackInfo; fTrackInfo = NULL;
137 if(fEventInfo) delete fEventInfo; fEventInfo = NULL;
138 if(fV0Info) delete fV0Info; fV0Info = NULL;
140 fContainer->Delete(); delete fContainer;
144 fV0container->Delete(); delete fV0container;
149 //____________________________________________________________________
150 void AliTRDinfoGen::UserCreateOutputObjects()
153 // Create Output Containers (TObjectArray containing 1D histograms)
155 fTrackInfo = new AliTRDtrackInfo();
156 fEventInfo = new AliTRDeventInfo();
157 fV0Info = new AliTRDv0Info();
158 fContainer = new TObjArray(1000);
159 fContainer->SetOwner(kTRUE);
160 fV0container = new TObjArray(50);
161 fV0container->SetOwner(kTRUE);
164 //____________________________________________________________________
165 void AliTRDinfoGen::UserExec(Option_t *){
169 fESDev = dynamic_cast<AliESDEvent*>(InputEvent());
173 AliError("Failed retrieving ESD event");
177 // event selection : trigger cut
178 if(UseLocalEvSelection() &&
179 fEvTrigger.Data()[0]!='\0'){
180 Bool_t kTRIGGERED(kFALSE);
181 const TObjArray *trig = fEvTrigger.Tokenize(" ");
182 for(Int_t itrig=trig->GetEntriesFast(); itrig--;){
183 const Char_t *trigClass(((TObjString*)(*trig)[itrig])->GetName());
184 if(fESDev->IsTriggerClassFired(trigClass)) {
185 AliDebug(2, Form("Ev[%4d] Trigger[%s]", fESDev->GetEventNumberInFile(), trigClass));
190 if(!kTRIGGERED) return;
192 // select only physical events
193 if(fESDev->GetEventType() != 7) return;
196 // if the required trigger is a collision trigger then apply event vertex cut
197 if(UseLocalEvSelection() && IsCollision()){
198 const AliESDVertex *vertex = fESDev->GetPrimaryVertex();
199 if(TMath::Abs(vertex->GetZv())<1.e-10 ||
200 TMath::Abs(vertex->GetZv())>fgkEvVertexZ ||
201 vertex->GetNContributors()<fgkEvVertexN) {
202 //PostData(0, fOutStorage);
207 if(fEventCut && !fEventCut->IsSelected(fESDev, IsCollision())) return;
210 AliError("Failed retrieving ESD friend event");
213 if(HasMCdata() && !fMCev){
214 AliError("Failed retrieving MC event");
218 fContainer->Delete();
219 fV0container->Delete();
220 fEventInfo->Delete("");
221 new(fEventInfo)AliTRDeventInfo(fESDev->GetHeader(), const_cast<AliESDRun *>(fESDev->GetESDRun()));
223 Bool_t *trackMap(NULL);
224 AliStack * mStack(NULL);
225 Int_t nTracksMC = HasMCdata() ? fMCev->GetNumberOfTracks() : 0, nTracksESD = fESDev->GetNumberOfTracks();
227 mStack = fMCev->Stack();
229 AliError("Failed retrieving MC Stack");
232 trackMap = new Bool_t[nTracksMC];
233 memset(trackMap, 0, sizeof(Bool_t) * nTracksMC);
236 Double32_t dedx[100]; Int_t nSlices(0);
237 Int_t nTRDout(0), nTRDin(0), nTPC(0), nclsTrklt;
238 AliDebug(2, Form("Entry[%3d] Tracks: ESD[%d] MC[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC));
239 AliESDtrack *esdTrack = NULL;
240 AliESDfriendTrack *esdFriendTrack = NULL;
241 TObject *calObject = NULL;
242 AliTRDtrackV1 *track = NULL;
243 AliTRDseedV1 *tracklet = NULL;
244 AliTRDcluster *cl = NULL;
245 for(Int_t itrk = 0; itrk < nTracksESD; itrk++){
246 esdTrack = fESDev->GetTrack(itrk);
247 AliDebug(3, Form("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2)));
250 if(UseLocalTrkSelection()){
251 if(esdTrack->Pt() < fgkPt) continue;
252 if(TMath::Abs(esdTrack->Eta()) > fgkEta) continue;
253 if(esdTrack->GetTPCNcls() < fgkNclTPC) continue;
254 Float_t par[2], cov[3];
255 esdTrack->GetImpactParameters(par, cov);
256 if(IsCollision()){ // cuts on DCA
257 if(TMath::Abs(par[0]) > fgkTrkDCAxy) continue;
258 if(TMath::Abs(par[1]) > fgkTrkDCAz) continue;
261 if(fTrackCut && !fTrackCut->IsSelected(esdTrack)) continue;
263 if(esdTrack->GetStatus()&AliESDtrack::kTPCout) nTPC++;
264 if(esdTrack->GetStatus()&AliESDtrack::kTRDout) nTRDout++;
265 if(esdTrack->GetStatus()&AliESDtrack::kTRDin) nTRDin++;
267 // look at external track param
268 const AliExternalTrackParam *op = esdTrack->GetOuterParam();
272 op->Global2LocalPosition(xyz, op->GetAlpha());
273 AliDebug(3, Form("op @ X[%7.3f]\n", xyz[0]));
278 Int_t label = -1; UInt_t alab=UINT_MAX;
280 label = esdTrack->GetLabel();
281 alab = TMath::Abs(label);
282 // register the track
283 if(alab < UInt_t(nTracksMC)){
284 trackMap[alab] = kTRUE;
286 AliError(Form("MC label[%d] outside scope for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
289 AliMCParticle *mcParticle = NULL;
290 if(!(mcParticle = (AliMCParticle*) fMCev->GetTrack(alab))){
291 AliError(Form("MC particle label[%d] missing for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
294 fPdg = mcParticle->Particle()->GetPdgCode();
295 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
296 Int_t iref = 0; AliTrackReference *ref = NULL;
298 ref = mcParticle->GetTrackReference(iref);
299 if(ref->LocalX() > fgkTPC) break;
303 new(fTrackInfo) AliTRDtrackInfo();
304 fTrackInfo->SetPDG(fPdg);
305 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
306 Int_t jref = iref;//, kref = 0;
308 ref = mcParticle->GetTrackReference(jref);
309 if(ref->LocalX() > fgkTOF) break;
310 AliDebug(4, Form(" trackRef[%2d (%2d)] @ %7.3f OK", jref-iref, jref, ref->LocalX()));
311 fTrackInfo->AddTrackRef(ref);
314 AliDebug(3, Form("NtrackRefs[%d(%d)]", fTrackInfo->GetNTrackRefs(), nRefs));
316 new (fTrackInfo) AliTRDtrackInfo();
317 fTrackInfo->SetPDG(fPdg);
320 // copy some relevant info to TRD track info
321 fTrackInfo->SetStatus(esdTrack->GetStatus());
322 fTrackInfo->SetTrackId(esdTrack->GetID());
323 Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p);
324 fTrackInfo->SetESDpid(p);
325 fTrackInfo->SetESDpidQuality(esdTrack->GetTRDntrackletsPID());
326 if(!nSlices) nSlices = esdTrack->GetNumberOfTRDslices();
327 memset(dedx, 0, 100*sizeof(Double32_t));
329 for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++)
330 for(Int_t is=0; is<nSlices; is++)
331 dedx[in++]=esdTrack->GetTRDslice(il, is);
332 for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++) dedx[in++]=esdTrack->GetTRDmomentum(il);
333 fTrackInfo->SetSlices(in, dedx);
334 fTrackInfo->SetLabel(label);
335 fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2));
336 // some other Informations which we may wish to store in order to find problematic cases
337 fTrackInfo->SetKinkIndex(esdTrack->GetKinkIndex(0));
338 fTrackInfo->SetTPCncls(static_cast<UShort_t>(esdTrack->GetNcls(1)));
343 esdFriendTrack = fESDfriend->GetTrack(itrk);
346 while((calObject = esdFriendTrack->GetCalibObject(icalib++))){
347 if(strcmp(calObject->IsA()->GetName(),"AliTRDtrackV1") != 0) continue; // Look for the TRDtrack
348 if(!(track = dynamic_cast<AliTRDtrackV1*>(calObject))) break;
349 AliDebug(4, Form("TRD track OK"));
350 // Set the clusters to unused
351 for(Int_t ipl = 0; ipl < AliTRDgeometry::kNlayer; ipl++){
352 if(!(tracklet = track->GetTracklet(ipl))) continue;
353 tracklet->ResetClusterIter();
354 while((cl = tracklet->NextCluster())) cl->Use(0);
356 fTrackInfo->SetTrack(track);
359 AliDebug(3, Form("Ntracklets[%d]\n", fTrackInfo->GetNTracklets()));
360 } else AliDebug(3, "No ESD friends");
361 if(op) fTrackInfo->SetOuterParam(op);
363 if(DebugLevel() >= 1){
364 AliTRDtrackInfo info(*fTrackInfo);
365 (*DebugStream()) << "trackInfo"
366 << "TrackInfo.=" << &info
371 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
372 fTrackInfo->Delete("");
374 AliDebug(2, Form("%3d Tracks: TPCout[%d] TRDin[%d] TRDout[%d]\n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTPC, nTRDin, nTRDout));
376 // AliESDv0 *v0 = NULL;
377 // for(Int_t iv0=0; iv0<fESD->GetNumberOfV0s(); iv0++){
378 // if(!(v0 = fESD->GetV0(iv0))) continue;
379 // fV0container->Add(new AliTRDv0Info(v0));
382 // Insert also MC tracks which are passing TRD where the track is not reconstructed
384 AliDebug(10, "Output of the MC track map:");
385 for(Int_t itk = 0; itk < nTracksMC; itk++) AliDebug(10, Form("trackMap[%d] = %s", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE"));
387 for(Int_t itk = 0; itk < nTracksMC; itk++){
388 if(trackMap[itk]) continue;
389 AliMCParticle *mcParticle = (AliMCParticle*) fMCev->GetTrack(TMath::Abs(itk));
390 Int_t fPdg = mcParticle->Particle()->GetPdgCode();
391 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
392 Int_t iref = 0; AliTrackReference *ref = NULL;
394 new(fTrackInfo) AliTRDtrackInfo();
395 fTrackInfo->SetPDG(fPdg);
398 ref = mcParticle->GetTrackReference(iref);
399 if(ref->LocalX() > fgkTPC && ref->LocalX() < fgkTOF){
400 fTrackInfo->AddTrackRef(ref);
401 nRefsTRD++;kIN=kTRUE;
403 AliDebug(4, Form(" trackRef[%2d] @ x[%7.3f] %s", iref, ref->LocalX(), kIN?"IN":"OUT"));
407 // In this stage we at least require 1 hit inside TRD. What will be done with this tracks is a task for the
409 fTrackInfo->Delete("");
412 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
413 fTrackInfo->SetLabel(itk);
414 if(DebugLevel() >= 1){
415 AliTRDtrackInfo info(*fTrackInfo);
416 (*DebugStream()) << "trackInfo"
417 << "TrackInfo.=" << &info
421 AliDebug(3, Form("Add MC track @ label[%d] nTRDrefs[%d].", itk, nRefsTRD));
422 fContainer->Add(new AliTRDtrackInfo(*fTrackInfo));
423 fTrackInfo->Delete("");
427 PostData(1, fContainer);
428 PostData(2, fEventInfo);
429 PostData(3, fV0container);