]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG1/TRD/AliTRDinfoGen.cxx
Fix for bug #70969: Memory leaks in AliTPCcalibDButil
[u/mrichter/AliRoot.git] / PWG1 / TRD / AliTRDinfoGen.cxx
CommitLineData
1ee39b3a 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
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**************************************************************************/
15
16/* $Id: AliTRDinfoGen.cxx 27496 2008-07-22 08:35:45Z cblume $ */
17
18////////////////////////////////////////////////////////////////////////////
19//
20// Tender wagon for TRD performance/calibration train
21//
22// In this wagon the information from
23// - ESD
24// - Friends [if available]
25// - MC [if available]
26// are grouped into AliTRDtrackInfo objects and fed to worker tasks
27//
28// Authors:
29// Markus Fasel <M.Fasel@gsi.de>
30// Alexandru Bercuci <A.Bercuci@gsi.de>
31//
32////////////////////////////////////////////////////////////////////////////
33
34#include <TClonesArray.h>
35#include <TObjArray.h>
36#include <TObject.h>
705f8b0a 37#include <TString.h>
058c3053 38#include <TH1S.h>
39#include <TPad.h>
1ee39b3a 40#include <TFile.h>
41#include <TTree.h>
42#include <TROOT.h>
43#include <TChain.h>
44#include <TParticle.h>
45
46#include "AliLog.h"
47#include "AliAnalysisManager.h"
801d4d50 48#include "AliCDBManager.h"
1ee39b3a 49#include "AliESDEvent.h"
50#include "AliMCEvent.h"
51#include "AliESDInputHandler.h"
52#include "AliMCEventHandler.h"
53
54#include "AliESDfriend.h"
55#include "AliESDfriendTrack.h"
56#include "AliESDHeader.h"
57#include "AliESDtrack.h"
3d19c1b0 58#include "AliESDv0.h"
07ece31c 59#include "AliESDtrackCuts.h"
1ee39b3a 60#include "AliMCParticle.h"
61#include "AliPID.h"
62#include "AliStack.h"
1ee39b3a 63#include "AliTrackReference.h"
1ee39b3a 64#include "TTreeStream.h"
65
66#include <cstdio>
67#include <climits>
68#include <cstring>
69#include <iostream>
70
801d4d50 71#include "AliTRDcalibDB.h"
72#include "AliTRDtrackerV1.h"
73#include "AliTRDgeometry.h"
74#include "AliTRDtrackV1.h"
75#include "AliTRDseedV1.h"
76#include "AliTRDcluster.h"
1ee39b3a 77#include "AliTRDinfoGen.h"
78#include "info/AliTRDtrackInfo.h"
79#include "info/AliTRDeventInfo.h"
80#include "info/AliTRDv0Info.h"
07ece31c 81#include "info/AliTRDeventCuts.h"
705f8b0a 82#include "macros/AliTRDperformanceTrain.h"
1ee39b3a 83
84ClassImp(AliTRDinfoGen)
85
3d2a3dff 86const Float_t AliTRDinfoGen::fgkITS = 100.; // to be checked
1ee39b3a 87const Float_t AliTRDinfoGen::fgkTPC = 290.;
3d2a3dff 88const Float_t AliTRDinfoGen::fgkTRD = 365.;
1ee39b3a 89
3f19c2cd 90const Float_t AliTRDinfoGen::fgkEvVertexZ = 15.;
91const Int_t AliTRDinfoGen::fgkEvVertexN = 1;
92
bd05b0f1 93const Float_t AliTRDinfoGen::fgkTrkDCAxy = 3.;
94const Float_t AliTRDinfoGen::fgkTrkDCAz = 10.;
95const Int_t AliTRDinfoGen::fgkNclTPC = 70;
3f19c2cd 96const Float_t AliTRDinfoGen::fgkPt = 0.2;
97const Float_t AliTRDinfoGen::fgkEta = 0.9;
98
1ee39b3a 99//____________________________________________________________________
db99a57a 100AliTRDinfoGen::AliTRDinfoGen()
705f8b0a 101 :AliAnalysisTaskSE()
102 ,fEvTrigger(NULL)
770382d9 103 ,fESDev(NULL)
104 ,fMCev(NULL)
705f8b0a 105 ,fEventCut(NULL)
106 ,fTrackCut(NULL)
3d19c1b0 107 ,fV0Cut(NULL)
801d4d50 108 ,fOCDB("local://$ALICE_ROOT/OCDB")
770382d9 109 ,fTrackInfo(NULL)
110 ,fEventInfo(NULL)
770382d9 111 ,fV0Info(NULL)
705f8b0a 112 ,fTracksBarrel(NULL)
113 ,fTracksSA(NULL)
114 ,fTracksKink(NULL)
115 ,fV0List(NULL)
058c3053 116 ,fContainer(NULL)
705f8b0a 117 ,fDebugStream(NULL)
1ee39b3a 118{
119 //
120 // Default constructor
121 //
76106bcc 122 SetNameTitle("TRDinfoGen", "MC-REC TRD-track list generator");
f8f46e4d 123}
1ee39b3a 124
07ece31c 125//____________________________________________________________________
db99a57a 126AliTRDinfoGen::AliTRDinfoGen(char* name)
705f8b0a 127 :AliAnalysisTaskSE(name)
128 ,fEvTrigger(NULL)
f8f46e4d 129 ,fESDev(NULL)
130 ,fMCev(NULL)
705f8b0a 131 ,fEventCut(NULL)
132 ,fTrackCut(NULL)
3d19c1b0 133 ,fV0Cut(NULL)
801d4d50 134 ,fOCDB("local://$ALICE_ROOT/OCDB")
f8f46e4d 135 ,fTrackInfo(NULL)
136 ,fEventInfo(NULL)
f8f46e4d 137 ,fV0Info(NULL)
705f8b0a 138 ,fTracksBarrel(NULL)
139 ,fTracksSA(NULL)
140 ,fTracksKink(NULL)
141 ,fV0List(NULL)
058c3053 142 ,fContainer(NULL)
705f8b0a 143 ,fDebugStream(NULL)
f8f46e4d 144{
145 //
146 // Default constructor
147 //
705f8b0a 148 SetTitle("MC-REC TRD-track list generator");
149 DefineOutput(kTracksBarrel, TObjArray::Class());
150 DefineOutput(kTracksSA, TObjArray::Class());
151 DefineOutput(kTracksKink, TObjArray::Class());
152 DefineOutput(kEventInfo, AliTRDeventInfo::Class());
153 DefineOutput(kV0List, TObjArray::Class());
058c3053 154 DefineOutput(kMonitor, TObjArray::Class()); // histogram list
1ee39b3a 155}
156
157//____________________________________________________________________
158AliTRDinfoGen::~AliTRDinfoGen()
159{
160// Destructor
705f8b0a 161
0205fb04 162 if(fDebugStream) delete fDebugStream;
705f8b0a 163 if(fEvTrigger) delete fEvTrigger;
3d19c1b0 164 if(fV0Cut) delete fV0Cut;
07ece31c 165 if(fTrackCut) delete fTrackCut;
166 if(fEventCut) delete fEventCut;
770382d9 167 if(fTrackInfo) delete fTrackInfo; fTrackInfo = NULL;
770382d9 168 if(fEventInfo) delete fEventInfo; fEventInfo = NULL;
770382d9 169 if(fV0Info) delete fV0Info; fV0Info = NULL;
705f8b0a 170 if(fTracksBarrel){
171 fTracksBarrel->Delete(); delete fTracksBarrel;
172 fTracksBarrel = NULL;
173 }
174 if(fTracksSA){
175 fTracksSA->Delete(); delete fTracksSA;
176 fTracksSA = NULL;
1ee39b3a 177 }
705f8b0a 178 if(fTracksKink){
179 fTracksKink->Delete(); delete fTracksKink;
180 fTracksKink = NULL;
181 }
182 if(fV0List){
3d19c1b0 183 fV0List->Delete();
184 delete fV0List;
705f8b0a 185 fV0List = NULL;
1ee39b3a 186 }
058c3053 187 if(fContainer){
188 fContainer->Delete();
189 delete fContainer;
190 fContainer = NULL;
191 }
192}
193
194//____________________________________________________________________
195Bool_t AliTRDinfoGen::GetRefFigure(Int_t)
196{
197 if(!gPad){
198 AliWarning("Please provide a canvas to draw results.");
199 return kFALSE;
200 }
201 fContainer->At(0)->Draw("bar");
202 return kTRUE;
1ee39b3a 203}
204
205//____________________________________________________________________
f8f46e4d 206void AliTRDinfoGen::UserCreateOutputObjects()
1ee39b3a 207{
208 //
209 // Create Output Containers (TObjectArray containing 1D histograms)
210 //
b4414720 211
1ee39b3a 212 fTrackInfo = new AliTRDtrackInfo();
213 fEventInfo = new AliTRDeventInfo();
214 fV0Info = new AliTRDv0Info();
705f8b0a 215 fTracksBarrel = new TObjArray(200); fTracksBarrel->SetOwner(kTRUE);
216 fTracksSA = new TObjArray(20); fTracksSA->SetOwner(kTRUE);
217 fTracksKink = new TObjArray(20); fTracksKink->SetOwner(kTRUE);
218 fV0List = new TObjArray(10); fV0List->SetOwner(kTRUE);
058c3053 219
220 // define general monitor
221 fContainer = new TObjArray(1); fContainer->SetOwner(kTRUE);
222 TH1 *h=new TH1S("hStat", "Run statistics;Observable;Entries", 12, -0.5, 11.5);
223 TAxis *ax(h->GetXaxis());
224 ax->SetBinLabel( 1, "ESD");
225 ax->SetBinLabel( 2, "MC");
226 ax->SetBinLabel( 3, "V0");
227 ax->SetBinLabel( 4, "TPC");
228 ax->SetBinLabel( 5, "TRDin");
229 ax->SetBinLabel( 6, "TRDout");
230 ax->SetBinLabel( 7, "Barrel");
231 ax->SetBinLabel( 8, "BarrelMC");
232 ax->SetBinLabel( 9, "SA");
233 ax->SetBinLabel(10, "SAMC");
234 ax->SetBinLabel(11, "Kink");
235 ax->SetBinLabel(12, "KinkMC");
236 fContainer->AddAt(h, 0);
068e2c00 237 PostData(kMonitor, fContainer);
058c3053 238}
239
240//____________________________________________________________________
241Bool_t AliTRDinfoGen::Load(const Char_t *file, const Char_t *dir, const Char_t *name)
242{
243// Load data from performance file
244
245 if(!TFile::Open(file)){
246 AliWarning(Form("Couldn't open file %s.", file));
247 return kFALSE;
248 }
249 if(dir){
250 if(!gFile->cd(dir)){
251 AliWarning(Form("Couldn't cd to %s in %s.", dir, file));
252 return kFALSE;
253 }
254 }
255 TObjArray *o(NULL);
256 const Char_t *tn=(name ? name : GetName());
257 if(!(o = (TObjArray*)gDirectory->Get(tn))){
258 AliWarning(Form("Missing histogram container %s.", tn));
259 return kFALSE;
260 }
261 fContainer = (TObjArray*)o->Clone(GetName());
262 gFile->Close();
263 return kTRUE;
1ee39b3a 264}
265
266//____________________________________________________________________
f8f46e4d 267void AliTRDinfoGen::UserExec(Option_t *){
1ee39b3a 268 //
269 // Run the Analysis
270 //
f2e89a4c 271
d80a6a00 272 fTracksBarrel->Delete();
273 fTracksSA->Delete();
274 fTracksKink->Delete();
275 fV0List->Delete();
276 fEventInfo->Delete("");
277
f8f46e4d 278 fESDev = dynamic_cast<AliESDEvent*>(InputEvent());
1ee39b3a 279 if(!fESDev){
280 AliError("Failed retrieving ESD event");
281 return;
282 }
801d4d50 283 if(!IsInitOCDB()){
284 // prepare OCDB access
285 AliCDBManager* ocdb = AliCDBManager::Instance();
286 ocdb->SetDefaultStorage(fOCDB.Data());
287 ocdb->SetRun(fESDev->GetRunNumber());
288 AliTRDtrackerV1::SetNTimeBins(AliTRDcalibDB::Instance()->GetNumberOfTimeBinsDCS());
289 AliInfo(Form("OCDB : Loc[%s] Run[%d] TB[%d]", fOCDB.Data(), ocdb->GetRun(), AliTRDtrackerV1::GetNTimeBins()));
290 SetInitOCDB();
291 }
292
293 // link MC if available
294 fMCev = MCEvent();
3f19c2cd 295
296 // event selection : trigger cut
705f8b0a 297 if(UseLocalEvSelection() && fEvTrigger){
3f19c2cd 298 Bool_t kTRIGGERED(kFALSE);
705f8b0a 299 const TObjArray *trig = fEvTrigger->Tokenize(" ");
3f19c2cd 300 for(Int_t itrig=trig->GetEntriesFast(); itrig--;){
301 const Char_t *trigClass(((TObjString*)(*trig)[itrig])->GetName());
302 if(fESDev->IsTriggerClassFired(trigClass)) {
303 AliDebug(2, Form("Ev[%4d] Trigger[%s]", fESDev->GetEventNumberInFile(), trigClass));
304 kTRIGGERED = kTRUE;
305 break;
306 }
307 }
55d5090e 308 if(!kTRIGGERED){
309 AliDebug(2, Form("Reject Ev[%4d] Trigger", fESDev->GetEventNumberInFile()));
310 return;
311 }
3f19c2cd 312 // select only physical events
55d5090e 313 if(fESDev->GetEventType() != 7){
314 AliDebug(2, Form("Reject Ev[%4d] EvType[%d]", fESDev->GetEventNumberInFile(), fESDev->GetEventType()));
315 return;
316 }
3f19c2cd 317 }
318
319 // if the required trigger is a collision trigger then apply event vertex cut
320 if(UseLocalEvSelection() && IsCollision()){
321 const AliESDVertex *vertex = fESDev->GetPrimaryVertex();
322 if(TMath::Abs(vertex->GetZv())<1.e-10 ||
323 TMath::Abs(vertex->GetZv())>fgkEvVertexZ ||
324 vertex->GetNContributors()<fgkEvVertexN) {
55d5090e 325 AliDebug(2, Form("Reject Ev[%4d] Vertex Zv[%f] Nv[%d]", fESDev->GetEventNumberInFile(), TMath::Abs(vertex->GetZv()), vertex->GetNContributors()));
3f19c2cd 326 return;
327 }
328 }
329
07ece31c 330 if(fEventCut && !fEventCut->IsSelected(fESDev, IsCollision())) return;
331
1ee39b3a 332 if(!fESDfriend){
333 AliError("Failed retrieving ESD friend event");
334 return;
335 }
336 if(HasMCdata() && !fMCev){
337 AliError("Failed retrieving MC event");
338 return;
339 }
f8f46e4d 340
1ee39b3a 341 new(fEventInfo)AliTRDeventInfo(fESDev->GetHeader(), const_cast<AliESDRun *>(fESDev->GetESDRun()));
342
770382d9 343 Bool_t *trackMap(NULL);
344 AliStack * mStack(NULL);
1ee39b3a 345 Int_t nTracksMC = HasMCdata() ? fMCev->GetNumberOfTracks() : 0, nTracksESD = fESDev->GetNumberOfTracks();
346 if(HasMCdata()){
347 mStack = fMCev->Stack();
348 if(!mStack){
349 AliError("Failed retrieving MC Stack");
350 return;
351 }
352 trackMap = new Bool_t[nTracksMC];
353 memset(trackMap, 0, sizeof(Bool_t) * nTracksMC);
354 }
355
f232df0d 356 Double32_t dedx[100]; Int_t nSlices(0);
3d2a3dff 357 Int_t nTRDout(0), nTRDin(0), nTPC(0)
358 ,nclsTrklt
359 ,nBarrel(0), nSA(0), nKink(0)
360 ,nBarrelMC(0), nSAMC(0), nKinkMC(0);
770382d9 361 AliESDtrack *esdTrack = NULL;
362 AliESDfriendTrack *esdFriendTrack = NULL;
363 TObject *calObject = NULL;
364 AliTRDtrackV1 *track = NULL;
365 AliTRDseedV1 *tracklet = NULL;
366 AliTRDcluster *cl = NULL;
d80a6a00 367
368
369 // LOOP 0 - over ESD v0s
370 Float_t bField(fESDev->GetMagneticField());
371 AliESDv0 *v0(NULL);
372 Int_t v0pid[AliPID::kSPECIES];
373 for(Int_t iv0(0); iv0<fESDev->GetNumberOfV0s(); iv0++){
374 if(!(v0 = fESDev->GetV0(iv0))) continue;
375 // register v0
376 if(fV0Cut) new(fV0Info) AliTRDv0Info(*fV0Cut);
377 else new(fV0Info) AliTRDv0Info();
378 fV0Info->SetMagField(bField);
379 fV0Info->SetV0tracks(fESDev->GetTrack(v0->GetPindex()), fESDev->GetTrack(v0->GetNindex()));
380 fV0Info->SetV0Info(v0);
381 fV0List->Add(new AliTRDv0Info(*fV0Info));// kFOUND=kFALSE;
382 }
383
384
385 // LOOP 1 - over ESD tracks
1ee39b3a 386 for(Int_t itrk = 0; itrk < nTracksESD; itrk++){
267f8668 387 new(fTrackInfo) AliTRDtrackInfo();
1ee39b3a 388 esdTrack = fESDev->GetTrack(itrk);
389 AliDebug(3, Form("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2)));
3f19c2cd 390
770382d9 391 if(esdTrack->GetStatus()&AliESDtrack::kTPCout) nTPC++;
392 if(esdTrack->GetStatus()&AliESDtrack::kTRDout) nTRDout++;
393 if(esdTrack->GetStatus()&AliESDtrack::kTRDin) nTRDin++;
1ee39b3a 394
395 // look at external track param
396 const AliExternalTrackParam *op = esdTrack->GetOuterParam();
397 Double_t xyz[3];
398 if(op){
399 op->GetXYZ(xyz);
400 op->Global2LocalPosition(xyz, op->GetAlpha());
401 AliDebug(3, Form("op @ X[%7.3f]\n", xyz[0]));
402 }
403
404 // read MC info
405 Int_t fPdg = -1;
406 Int_t label = -1; UInt_t alab=UINT_MAX;
407 if(HasMCdata()){
408 label = esdTrack->GetLabel();
409 alab = TMath::Abs(label);
410 // register the track
411 if(alab < UInt_t(nTracksMC)){
412 trackMap[alab] = kTRUE;
413 } else {
414 AliError(Form("MC label[%d] outside scope for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
415 continue;
416 }
770382d9 417 AliMCParticle *mcParticle = NULL;
1ee39b3a 418 if(!(mcParticle = (AliMCParticle*) fMCev->GetTrack(alab))){
419 AliError(Form("MC particle label[%d] missing for Ev[%d] Trk[%d].", label, (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), itrk));
420 continue;
421 }
422 fPdg = mcParticle->Particle()->GetPdgCode();
423 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
770382d9 424 Int_t iref = 0; AliTrackReference *ref = NULL;
1ee39b3a 425 while(iref<nRefs){
426 ref = mcParticle->GetTrackReference(iref);
427 if(ref->LocalX() > fgkTPC) break;
428 iref++;
429 }
430
267f8668 431 fTrackInfo->SetMC();
1ee39b3a 432 fTrackInfo->SetPDG(fPdg);
433 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
b09af9ec 434 fTrackInfo->SetLabel(label);
1ee39b3a 435 Int_t jref = iref;//, kref = 0;
436 while(jref<nRefs){
437 ref = mcParticle->GetTrackReference(jref);
3d2a3dff 438 if(ref->LocalX() > fgkTRD) break;
1ee39b3a 439 AliDebug(4, Form(" trackRef[%2d (%2d)] @ %7.3f OK", jref-iref, jref, ref->LocalX()));
440 fTrackInfo->AddTrackRef(ref);
441 jref++;
442 }
443 AliDebug(3, Form("NtrackRefs[%d(%d)]", fTrackInfo->GetNTrackRefs(), nRefs));
1ee39b3a 444 }
445
446 // copy some relevant info to TRD track info
447 fTrackInfo->SetStatus(esdTrack->GetStatus());
448 fTrackInfo->SetTrackId(esdTrack->GetID());
449 Double_t p[AliPID::kSPECIES]; esdTrack->GetTRDpid(p);
450 fTrackInfo->SetESDpid(p);
451 fTrackInfo->SetESDpidQuality(esdTrack->GetTRDntrackletsPID());
f232df0d 452 if(!nSlices) nSlices = esdTrack->GetNumberOfTRDslices();
453 memset(dedx, 0, 100*sizeof(Double32_t));
92c40e64 454 Int_t in(0);
455 for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++)
456 for(Int_t is=0; is<nSlices; is++)
457 dedx[in++]=esdTrack->GetTRDslice(il, is);
458 for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++) dedx[in++]=esdTrack->GetTRDmomentum(il);
459 fTrackInfo->SetSlices(in, dedx);
1ee39b3a 460 fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2));
461 // some other Informations which we may wish to store in order to find problematic cases
462 fTrackInfo->SetKinkIndex(esdTrack->GetKinkIndex(0));
463 fTrackInfo->SetTPCncls(static_cast<UShort_t>(esdTrack->GetNcls(1)));
464 nclsTrklt = 0;
465
d80a6a00 466 // set V0pid info
467 AliTRDv0Info *v0info = new AliTRDv0Info();
468 for(Int_t iv(0); iv<fV0List->GetEntriesFast(); iv++){
469 if(!(v0info = (AliTRDv0Info*)fV0List->At(iv))) continue;
470 if(!v0info->fTrackP && !v0info->fTrackN) continue;
471 if(!v0info->HasTrack(fTrackInfo)) continue;
472 memset(v0pid, 0, AliPID::kSPECIES*sizeof(Int_t));
473 fTrackInfo->SetV0();
474 for(Int_t is=AliPID::kSPECIES; is--;){v0pid[is] = v0info->GetPID(is, fTrackInfo);}
475 fTrackInfo->SetV0pid(v0pid);
476 fTrackInfo->SetV0();
477 //const AliTRDtrackInfo::AliESDinfo *ei = fTrackInfo->GetESDinfo();
478 break;
479 }
1ee39b3a 480
481 // read REC info
482 esdFriendTrack = fESDfriend->GetTrack(itrk);
483 if(esdFriendTrack){
484 Int_t icalib = 0;
485 while((calObject = esdFriendTrack->GetCalibObject(icalib++))){
486 if(strcmp(calObject->IsA()->GetName(),"AliTRDtrackV1") != 0) continue; // Look for the TRDtrack
487 if(!(track = dynamic_cast<AliTRDtrackV1*>(calObject))) break;
1ee39b3a 488 AliDebug(4, Form("TRD track OK"));
489 // Set the clusters to unused
490 for(Int_t ipl = 0; ipl < AliTRDgeometry::kNlayer; ipl++){
491 if(!(tracklet = track->GetTracklet(ipl))) continue;
492 tracklet->ResetClusterIter();
493 while((cl = tracklet->NextCluster())) cl->Use(0);
494 }
495 fTrackInfo->SetTrack(track);
496 break;
497 }
498 AliDebug(3, Form("Ntracklets[%d]\n", fTrackInfo->GetNTracklets()));
499 } else AliDebug(3, "No ESD friends");
500 if(op) fTrackInfo->SetOuterParam(op);
501
502 if(DebugLevel() >= 1){
503 AliTRDtrackInfo info(*fTrackInfo);
504 (*DebugStream()) << "trackInfo"
505 << "TrackInfo.=" << &info
506 << "\n";
507 info.Delete("");
508 }
705f8b0a 509
510 ULong_t status(esdTrack->GetStatus());
511 if((status&AliESDtrack::kTPCout)){
512 if(!esdTrack->GetKinkIndex(0)){ // Barrel Track Selection
513 Bool_t selected(kTRUE);
514 if(UseLocalTrkSelection()){
55d5090e 515 if(esdTrack->Pt() < fgkPt){
516 AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] Pt[%5.2f]", fESDev->GetEventNumberInFile(), itrk, esdTrack->Pt()));
517 selected = kFALSE;
518 }
dfd7d48b 519 if(selected && TMath::Abs(esdTrack->Eta()) > fgkEta){
55d5090e 520 AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] Eta[%5.2f]", fESDev->GetEventNumberInFile(), itrk, TMath::Abs(esdTrack->Eta())));
521 selected = kFALSE;
522 }
dfd7d48b 523 if(selected && esdTrack->GetTPCNcls() < fgkNclTPC){
55d5090e 524 AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] NclTPC[%d]", fESDev->GetEventNumberInFile(), itrk, esdTrack->GetTPCNcls()));
525 selected = kFALSE;
526 }
705f8b0a 527 Float_t par[2], cov[3];
528 esdTrack->GetImpactParameters(par, cov);
529 if(IsCollision()){ // cuts on DCA
dfd7d48b 530 if(selected && TMath::Abs(par[0]) > fgkTrkDCAxy){
55d5090e 531 AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] DCAxy[%f]", fESDev->GetEventNumberInFile(), itrk, TMath::Abs(par[0])));
532 selected = kFALSE;
533 }
dfd7d48b 534 if(selected && TMath::Abs(par[1]) > fgkTrkDCAz){
55d5090e 535 AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] DCAz[%f]", fESDev->GetEventNumberInFile(), itrk, TMath::Abs(par[1])));
536 selected = kFALSE;
537 }
dfd7d48b 538 } else if(selected && fMCev && !fMCev->IsPhysicalPrimary(alab)){;
539 AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] Primary", fESDev->GetEventNumberInFile(), itrk));
540 selected = kFALSE;
705f8b0a 541 }
542 }
543 if(fTrackCut && !fTrackCut->IsSelected(esdTrack)) selected = kFALSE;
3d2a3dff 544 if(selected){
545 fTracksBarrel->Add(new AliTRDtrackInfo(*fTrackInfo));
546 nBarrel++;
547 }
548 } else {
549 fTracksKink->Add(new AliTRDtrackInfo(*fTrackInfo));
550 nKink++;
551 }
552 } else if((status&AliESDtrack::kTRDout) && !(status&AliESDtrack::kTRDin)){
553 fTracksSA->Add(new AliTRDtrackInfo(*fTrackInfo));
554 nSA++;
555 }
1ee39b3a 556 fTrackInfo->Delete("");
557 }
1ee39b3a 558
3d19c1b0 559 // LOOP 2 - over MC tracks which are passing TRD where the track is not reconstructed
1ee39b3a 560 if(HasMCdata()){
561 AliDebug(10, "Output of the MC track map:");
562 for(Int_t itk = 0; itk < nTracksMC; itk++) AliDebug(10, Form("trackMap[%d] = %s", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE"));
563
564 for(Int_t itk = 0; itk < nTracksMC; itk++){
565 if(trackMap[itk]) continue;
566 AliMCParticle *mcParticle = (AliMCParticle*) fMCev->GetTrack(TMath::Abs(itk));
567 Int_t fPdg = mcParticle->Particle()->GetPdgCode();
568 Int_t nRefs = mcParticle->GetNumberOfTrackReferences();
770382d9 569 Int_t iref = 0; AliTrackReference *ref = NULL;
1ee39b3a 570 Int_t nRefsTRD = 0;
571 new(fTrackInfo) AliTRDtrackInfo();
4c860218 572 fTrackInfo->SetMC();
1ee39b3a 573 fTrackInfo->SetPDG(fPdg);
3d2a3dff 574 while(iref<nRefs){ // count TRD TR
770382d9 575 Bool_t kIN(kFALSE);
1ee39b3a 576 ref = mcParticle->GetTrackReference(iref);
3d2a3dff 577 if(ref->LocalX() > fgkTPC && ref->LocalX() < fgkTRD){
1ee39b3a 578 fTrackInfo->AddTrackRef(ref);
770382d9 579 nRefsTRD++;kIN=kTRUE;
1ee39b3a 580 }
770382d9 581 AliDebug(4, Form(" trackRef[%2d] @ x[%7.3f] %s", iref, ref->LocalX(), kIN?"IN":"OUT"));
1ee39b3a 582 iref++;
583 }
584 if(!nRefsTRD){
585 // In this stage we at least require 1 hit inside TRD. What will be done with this tracks is a task for the
586 // analysis job
587 fTrackInfo->Delete("");
588 continue;
589 }
590 fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
591 fTrackInfo->SetLabel(itk);
592 if(DebugLevel() >= 1){
593 AliTRDtrackInfo info(*fTrackInfo);
594 (*DebugStream()) << "trackInfo"
595 << "TrackInfo.=" << &info
596 << "\n";
597 info.Delete("");
598 }
770382d9 599 AliDebug(3, Form("Add MC track @ label[%d] nTRDrefs[%d].", itk, nRefsTRD));
3d2a3dff 600 // check where the track starts
601 ref = mcParticle->GetTrackReference(0);
602 if(ref->LocalX() < fgkITS){
603 fTracksBarrel->Add(new AliTRDtrackInfo(*fTrackInfo));
604 nBarrelMC++;
605 } else if(ref->LocalX() < fgkTPC) {
606 fTracksKink->Add(new AliTRDtrackInfo(*fTrackInfo));
607 nKinkMC++;
608 } else if(nRefsTRD>6){
609 fTracksSA->Add(new AliTRDtrackInfo(*fTrackInfo));
610 nSAMC++;
611 }
1ee39b3a 612 fTrackInfo->Delete("");
613 }
614 delete[] trackMap;
615 }
b9ddd472 616 AliDebug(1, Form(
3d19c1b0 617 "\nEv[%3d] Tracks: ESD[%d] MC[%d] V0[%d]\n"
3d2a3dff 618 " TPCout[%d] TRDin[%d] TRDout[%d]\n"
619 " Barrel[%3d+%3d=%3d] SA[%2d+%2d=%2d] Kink[%2d+%2d=%2d]"
3d19c1b0 620 ,(Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC, fV0List->GetEntries()
3d2a3dff 621 , nTPC, nTRDin, nTRDout
622 ,nBarrel, nBarrelMC, fTracksBarrel->GetEntries()
623 ,nSA, nSAMC, fTracksSA->GetEntries()
624 ,nKink, nKinkMC, fTracksKink->GetEntries()
625 ));
058c3053 626 // save track statistics
627 TH1 *h((TH1S*)fContainer->At(0));
628 h->Fill( 0., nTracksESD);
629 h->Fill( 1., nTracksMC);
630 h->Fill( 2., fV0List->GetEntries());
631 h->Fill( 3., nTPC);
632 h->Fill( 4., nTRDin);
633 h->Fill( 5., nTRDout);
634 h->Fill( 6., nBarrel);
635 h->Fill( 7., nBarrelMC);
636 h->Fill( 8., nSA);
637 h->Fill( 9., nSAMC);
638 h->Fill(10., nKink);
639 h->Fill(11., nKinkMC);
3d2a3dff 640
705f8b0a 641 PostData(kTracksBarrel, fTracksBarrel);
642 PostData(kTracksSA, fTracksSA);
643 PostData(kTracksKink, fTracksKink);
644 PostData(kEventInfo, fEventInfo);
645 PostData(kV0List, fV0List);
646}
647
3d19c1b0 648//____________________________________________________________________
649void AliTRDinfoGen::SetLocalV0Selection(AliTRDv0Info *v0)
650{
651// Set V0 cuts from outside
652
653 if(!fV0Cut) fV0Cut = new AliTRDv0Info(*v0);
654 else new(fV0Cut) AliTRDv0Info(*v0);
655}
656
705f8b0a 657//____________________________________________________________________
658void AliTRDinfoGen::SetTrigger(const Char_t *trigger)
659{
660 if(!fEvTrigger) fEvTrigger = new TString(trigger);
661 else (*fEvTrigger) = trigger;
662}
663
664//____________________________________________________________________
665TTreeSRedirector* AliTRDinfoGen::DebugStream()
666{
667 if(!fDebugStream){
668 TDirectory *savedir = gDirectory;
669 fDebugStream = new TTreeSRedirector("TRD.DebugInfoGen.root");
670 savedir->cd();
671 }
672 return fDebugStream;
1ee39b3a 673}
674
705f8b0a 675
058c3053 676