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>
43 #include <TParticle.h>
46 #include "AliAnalysisManager.h"
47 #include "AliESDEvent.h"
48 #include "AliMCEvent.h"
49 #include "AliESDInputHandler.h"
50 #include "AliMCEventHandler.h"
52 #include "AliESDfriend.h"
53 #include "AliESDfriendTrack.h"
54 #include "AliESDHeader.h"
55 #include "AliESDtrack.h"
56 #include "AliESDtrackCuts.h"
57 #include "AliMCParticle.h"
60 #include "AliTRDtrackV1.h"
61 #include "AliTrackReference.h"
62 #include "AliTRDgeometry.h"
63 #include "AliTRDcluster.h"
64 #include "AliTRDseedV1.h"
65 #include "TTreeStream.h"
72 #include "AliTRDinfoGen.h"
73 #include "info/AliTRDtrackInfo.h"
74 #include "info/AliTRDeventInfo.h"
75 #include "info/AliTRDv0Info.h"
76 #include "info/AliTRDeventCuts.h"
77 #include "macros/AliTRDperformanceTrain.h"
79 ClassImp(AliTRDinfoGen)
81 const Float_t AliTRDinfoGen::fgkITS = 100.; // to be checked
82 const Float_t AliTRDinfoGen::fgkTPC = 290.;
83 const Float_t AliTRDinfoGen::fgkTRD = 365.;
85 const Float_t AliTRDinfoGen::fgkEvVertexZ = 15.;
86 const Int_t AliTRDinfoGen::fgkEvVertexN = 1;
88 const Float_t AliTRDinfoGen::fgkTrkDCAxy = 40.;
89 const Float_t AliTRDinfoGen::fgkTrkDCAz = 15.;
90 const Int_t AliTRDinfoGen::fgkNclTPC = 10;
91 const Float_t AliTRDinfoGen::fgkPt = 0.2;
92 const Float_t AliTRDinfoGen::fgkEta = 0.9;
94 //____________________________________________________________________
95 AliTRDinfoGen::AliTRDinfoGen()
112 // Default constructor
114 SetNameTitle("infoGen", "MC-REC TRD-track list generator");
117 //____________________________________________________________________
118 AliTRDinfoGen::AliTRDinfoGen(char* name)
119 :AliAnalysisTaskSE(name)
135 // Default constructor
137 SetTitle("MC-REC TRD-track list generator");
138 DefineOutput(kTracksBarrel, TObjArray::Class());
139 DefineOutput(kTracksSA, TObjArray::Class());
140 DefineOutput(kTracksKink, TObjArray::Class());
141 DefineOutput(kEventInfo, AliTRDeventInfo::Class());
142 DefineOutput(kV0List, TObjArray::Class());
145 //____________________________________________________________________
146 AliTRDinfoGen::~AliTRDinfoGen()
150 if(fDebugStream) delete fDebugStream;
151 if(fEvTrigger) delete fEvTrigger;
152 if(fTrackCut) delete fTrackCut;
153 if(fEventCut) delete fEventCut;
154 if(fTrackInfo) delete fTrackInfo; fTrackInfo = NULL;
155 if(fEventInfo) delete fEventInfo; fEventInfo = NULL;
156 if(fV0Info) delete fV0Info; fV0Info = NULL;
158 fTracksBarrel->Delete(); delete fTracksBarrel;
159 fTracksBarrel = NULL;
162 fTracksSA->Delete(); delete fTracksSA;
166 fTracksKink->Delete(); delete fTracksKink;
170 fV0List->Delete(); delete fV0List;
175 //____________________________________________________________________
176 void AliTRDinfoGen::UserCreateOutputObjects()
179 // Create Output Containers (TObjectArray containing 1D histograms)
182 fTrackInfo = new AliTRDtrackInfo();
183 fEventInfo = new AliTRDeventInfo();
184 fV0Info = new AliTRDv0Info();
185 fTracksBarrel = new TObjArray(200); fTracksBarrel->SetOwner(kTRUE);
186 fTracksSA = new TObjArray(20); fTracksSA->SetOwner(kTRUE);
187 fTracksKink = new TObjArray(20); fTracksKink->SetOwner(kTRUE);
188 fV0List = new TObjArray(10); fV0List->SetOwner(kTRUE);
191 //____________________________________________________________________
192 void AliTRDinfoGen::UserExec(Option_t *){
197 fESDev = dynamic_cast<AliESDEvent*>(InputEvent());
201 AliError("Failed retrieving ESD event");
205 // event selection : trigger cut
206 if(UseLocalEvSelection() && fEvTrigger){
207 Bool_t kTRIGGERED(kFALSE);
208 const TObjArray *trig = fEvTrigger->Tokenize(" ");
209 for(Int_t itrig=trig->GetEntriesFast(); itrig--;){
210 const Char_t *trigClass(((TObjString*)(*trig)[itrig])->GetName());
211 if(fESDev->IsTriggerClassFired(trigClass)) {
212 AliDebug(2, Form("Ev[%4d] Trigger[%s]", fESDev->GetEventNumberInFile(), trigClass));
218 AliDebug(2, Form("Reject Ev[%4d] Trigger", fESDev->GetEventNumberInFile()));
221 // select only physical events
222 if(fESDev->GetEventType() != 7){
223 AliDebug(2, Form("Reject Ev[%4d] EvType[%d]", fESDev->GetEventNumberInFile(), fESDev->GetEventType()));
228 // if the required trigger is a collision trigger then apply event vertex cut
229 if(UseLocalEvSelection() && IsCollision()){
230 const AliESDVertex *vertex = fESDev->GetPrimaryVertex();
231 if(TMath::Abs(vertex->GetZv())<1.e-10 ||
232 TMath::Abs(vertex->GetZv())>fgkEvVertexZ ||
233 vertex->GetNContributors()<fgkEvVertexN) {
234 AliDebug(2, Form("Reject Ev[%4d] Vertex Zv[%f] Nv[%d]", fESDev->GetEventNumberInFile(), TMath::Abs(vertex->GetZv()), vertex->GetNContributors()));
239 if(fEventCut && !fEventCut->IsSelected(fESDev, IsCollision())) return;
242 AliError("Failed retrieving ESD friend event");
245 if(HasMCdata() && !fMCev){
246 AliError("Failed retrieving MC event");
250 fTracksBarrel->Delete();
252 fTracksKink->Delete();
254 fEventInfo->Delete("");
255 new(fEventInfo)AliTRDeventInfo(fESDev->GetHeader(), const_cast<AliESDRun *>(fESDev->GetESDRun()));
257 Bool_t *trackMap(NULL);
258 AliStack * mStack(NULL);
259 Int_t nTracksMC = HasMCdata() ? fMCev->GetNumberOfTracks() : 0, nTracksESD = fESDev->GetNumberOfTracks();
261 mStack = fMCev->Stack();
263 AliError("Failed retrieving MC Stack");
266 trackMap = new Bool_t[nTracksMC];
267 memset(trackMap, 0, sizeof(Bool_t) * nTracksMC);
270 Double32_t dedx[100]; Int_t nSlices(0);
271 Int_t nTRDout(0), nTRDin(0), nTPC(0)
273 ,nBarrel(0), nSA(0), nKink(0)
274 ,nBarrelMC(0), nSAMC(0), nKinkMC(0);
275 AliESDtrack *esdTrack = NULL;
276 AliESDfriendTrack *esdFriendTrack = NULL;
277 TObject *calObject = NULL;
278 AliTRDtrackV1 *track = NULL;
279 AliTRDseedV1 *tracklet = NULL;
280 AliTRDcluster *cl = NULL;
281 for(Int_t itrk = 0; itrk < nTracksESD; itrk++){
282 esdTrack = fESDev->GetTrack(itrk);
283 AliDebug(3, Form("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2)));
285 if(esdTrack->GetStatus()&AliESDtrack::kTPCout) nTPC++;
286 if(esdTrack->GetStatus()&AliESDtrack::kTRDout) nTRDout++;
287 if(esdTrack->GetStatus()&AliESDtrack::kTRDin) nTRDin++;
289 // look at external track param
290 const AliExternalTrackParam *op = esdTrack->GetOuterParam();
294 op->Global2LocalPosition(xyz, op->GetAlpha());
295 AliDebug(3, Form("op @ X[%7.3f]\n", xyz[0]));
300 Int_t label = -1; UInt_t alab=UINT_MAX;
302 label = esdTrack->GetLabel();
303 alab = TMath::Abs(label);
304 // register the track
305 if(alab < UInt_t(nTracksMC)){
306 trackMap[alab] = kTRUE;
308 AliError(Form("MC label[%d] outside scope for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
311 AliMCParticle *mcParticle = NULL;
312 if(!(mcParticle = (AliMCParticle*) fMCev->GetTrack(alab))){
313 AliError(Form("MC particle label[%d] missing for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
316 fPdg = mcParticle->Particle()->GetPdgCode();
317 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
318 Int_t iref = 0; AliTrackReference *ref = NULL;
320 ref = mcParticle->GetTrackReference(iref);
321 if(ref->LocalX() > fgkTPC) break;
325 new(fTrackInfo) AliTRDtrackInfo();
326 fTrackInfo->SetPDG(fPdg);
327 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
328 Int_t jref = iref;//, kref = 0;
330 ref = mcParticle->GetTrackReference(jref);
331 if(ref->LocalX() > fgkTRD) break;
332 AliDebug(4, Form(" trackRef[%2d (%2d)] @ %7.3f OK", jref-iref, jref, ref->LocalX()));
333 fTrackInfo->AddTrackRef(ref);
336 AliDebug(3, Form("NtrackRefs[%d(%d)]", fTrackInfo->GetNTrackRefs(), nRefs));
338 new (fTrackInfo) AliTRDtrackInfo();
339 fTrackInfo->SetPDG(fPdg);
342 // copy some relevant info to TRD track info
343 fTrackInfo->SetStatus(esdTrack->GetStatus());
344 fTrackInfo->SetTrackId(esdTrack->GetID());
345 Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p);
346 fTrackInfo->SetESDpid(p);
347 fTrackInfo->SetESDpidQuality(esdTrack->GetTRDntrackletsPID());
348 if(!nSlices) nSlices = esdTrack->GetNumberOfTRDslices();
349 memset(dedx, 0, 100*sizeof(Double32_t));
351 for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++)
352 for(Int_t is=0; is<nSlices; is++)
353 dedx[in++]=esdTrack->GetTRDslice(il, is);
354 for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++) dedx[in++]=esdTrack->GetTRDmomentum(il);
355 fTrackInfo->SetSlices(in, dedx);
356 fTrackInfo->SetLabel(label);
357 fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2));
358 // some other Informations which we may wish to store in order to find problematic cases
359 fTrackInfo->SetKinkIndex(esdTrack->GetKinkIndex(0));
360 fTrackInfo->SetTPCncls(static_cast<UShort_t>(esdTrack->GetNcls(1)));
365 esdFriendTrack = fESDfriend->GetTrack(itrk);
368 while((calObject = esdFriendTrack->GetCalibObject(icalib++))){
369 printf("check [%d] %s\n", icalib, calObject->IsA()->GetName());
370 if(strcmp(calObject->IsA()->GetName(),"AliTRDtrackV1") != 0) continue; // Look for the TRDtrack
371 if(!(track = dynamic_cast<AliTRDtrackV1*>(calObject))) break;
372 AliDebug(4, Form("TRD track OK"));
373 // Set the clusters to unused
374 for(Int_t ipl = 0; ipl < AliTRDgeometry::kNlayer; ipl++){
375 if(!(tracklet = track->GetTracklet(ipl))) continue;
376 tracklet->ResetClusterIter();
377 while((cl = tracklet->NextCluster())) cl->Use(0);
379 fTrackInfo->SetTrack(track);
382 AliDebug(3, Form("Ntracklets[%d]\n", fTrackInfo->GetNTracklets()));
383 } else AliDebug(3, "No ESD friends");
384 if(op) fTrackInfo->SetOuterParam(op);
386 if(DebugLevel() >= 1){
387 AliTRDtrackInfo info(*fTrackInfo);
388 (*DebugStream()) << "trackInfo"
389 << "TrackInfo.=" << &info
394 ULong_t status(esdTrack->GetStatus());
395 if((status&AliESDtrack::kTPCout)){
396 if(!esdTrack->GetKinkIndex(0)){ // Barrel Track Selection
397 Bool_t selected(kTRUE);
398 if(UseLocalTrkSelection()){
399 if(esdTrack->Pt() < fgkPt){
400 AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] Pt[%5.2f]", fESDev->GetEventNumberInFile(), itrk, esdTrack->Pt()));
403 if(TMath::Abs(esdTrack->Eta()) > fgkEta){
404 AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] Eta[%5.2f]", fESDev->GetEventNumberInFile(), itrk, TMath::Abs(esdTrack->Eta())));
407 if(esdTrack->GetTPCNcls() < fgkNclTPC){
408 AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] NclTPC[%d]", fESDev->GetEventNumberInFile(), itrk, esdTrack->GetTPCNcls()));
411 Float_t par[2], cov[3];
412 esdTrack->GetImpactParameters(par, cov);
413 if(IsCollision()){ // cuts on DCA
414 if(TMath::Abs(par[0]) > fgkTrkDCAxy){
415 AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] DCAxy[%f]", fESDev->GetEventNumberInFile(), itrk, TMath::Abs(par[0])));
418 if(TMath::Abs(par[1]) > fgkTrkDCAz){
419 AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] DCAz[%f]", fESDev->GetEventNumberInFile(), itrk, TMath::Abs(par[1])));
424 if(fTrackCut && !fTrackCut->IsSelected(esdTrack)) selected = kFALSE;
426 fTracksBarrel->Add(new AliTRDtrackInfo(*fTrackInfo));
430 fTracksKink->Add(new AliTRDtrackInfo(*fTrackInfo));
433 } else if((status&AliESDtrack::kTRDout) && !(status&AliESDtrack::kTRDin)){
434 fTracksSA->Add(new AliTRDtrackInfo(*fTrackInfo));
437 fTrackInfo->Delete("");
440 // AliESDv0 *v0 = NULL;
441 // for(Int_t iv0=0; iv0<fESD->GetNumberOfV0s(); iv0++){
442 // if(!(v0 = fESD->GetV0(iv0))) continue;
443 // fV0List->Add(new AliTRDv0Info(v0));
446 // Insert also MC tracks which are passing TRD where the track is not reconstructed
448 AliDebug(10, "Output of the MC track map:");
449 for(Int_t itk = 0; itk < nTracksMC; itk++) AliDebug(10, Form("trackMap[%d] = %s", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE"));
451 for(Int_t itk = 0; itk < nTracksMC; itk++){
452 if(trackMap[itk]) continue;
453 AliMCParticle *mcParticle = (AliMCParticle*) fMCev->GetTrack(TMath::Abs(itk));
454 Int_t fPdg = mcParticle->Particle()->GetPdgCode();
455 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
456 Int_t iref = 0; AliTrackReference *ref = NULL;
458 new(fTrackInfo) AliTRDtrackInfo();
459 fTrackInfo->SetPDG(fPdg);
460 while(iref<nRefs){ // count TRD TR
462 ref = mcParticle->GetTrackReference(iref);
463 if(ref->LocalX() > fgkTPC && ref->LocalX() < fgkTRD){
464 fTrackInfo->AddTrackRef(ref);
465 nRefsTRD++;kIN=kTRUE;
467 AliDebug(4, Form(" trackRef[%2d] @ x[%7.3f] %s", iref, ref->LocalX(), kIN?"IN":"OUT"));
471 // In this stage we at least require 1 hit inside TRD. What will be done with this tracks is a task for the
473 fTrackInfo->Delete("");
476 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
477 fTrackInfo->SetLabel(itk);
478 if(DebugLevel() >= 1){
479 AliTRDtrackInfo info(*fTrackInfo);
480 (*DebugStream()) << "trackInfo"
481 << "TrackInfo.=" << &info
485 AliDebug(3, Form("Add MC track @ label[%d] nTRDrefs[%d].", itk, nRefsTRD));
486 // check where the track starts
487 ref = mcParticle->GetTrackReference(0);
488 if(ref->LocalX() < fgkITS){
489 fTracksBarrel->Add(new AliTRDtrackInfo(*fTrackInfo));
491 } else if(ref->LocalX() < fgkTPC) {
492 fTracksKink->Add(new AliTRDtrackInfo(*fTrackInfo));
494 } else if(nRefsTRD>6){
495 fTracksSA->Add(new AliTRDtrackInfo(*fTrackInfo));
498 fTrackInfo->Delete("");
503 "\nEv[%3d] Tracks: ESD[%d] MC[%d]\n"
504 " TPCout[%d] TRDin[%d] TRDout[%d]\n"
505 " Barrel[%3d+%3d=%3d] SA[%2d+%2d=%2d] Kink[%2d+%2d=%2d]"
506 ,(Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC
507 , nTPC, nTRDin, nTRDout
508 ,nBarrel, nBarrelMC, fTracksBarrel->GetEntries()
509 ,nSA, nSAMC, fTracksSA->GetEntries()
510 ,nKink, nKinkMC, fTracksKink->GetEntries()
513 PostData(kTracksBarrel, fTracksBarrel);
514 PostData(kTracksSA, fTracksSA);
515 PostData(kTracksKink, fTracksKink);
516 PostData(kEventInfo, fEventInfo);
517 PostData(kV0List, fV0List);
520 //____________________________________________________________________
521 void AliTRDinfoGen::SetTrigger(const Char_t *trigger)
523 if(!fEvTrigger) fEvTrigger = new TString(trigger);
524 else (*fEvTrigger) = trigger;
527 //____________________________________________________________________
528 TTreeSRedirector* AliTRDinfoGen::DebugStream()
531 TDirectory *savedir = gDirectory;
532 fDebugStream = new TTreeSRedirector("TRD.DebugInfoGen.root");