AliPhysics  6f1d526 (6f1d526)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalEsdTrackFilterTask.cxx
Go to the documentation of this file.
1 //
2 // Task to filter Esd tracks and propagate to Emcal surface.
3 //
4 // Author: C.Loizides
5 
7 #include <TClonesArray.h>
8 #include <TRandom3.h>
9 #include <TGeoGlobalMagField.h>
10 #include <AliAnalysisManager.h>
11 #include <AliEMCALRecoUtils.h>
12 #include <AliESDEvent.h>
13 #include <AliESDtrackCuts.h>
14 #include <AliMagF.h>
15 #include <AliTrackerBase.h>
16 
17 
19 
20 //________________________________________________________________________
23  fEsdTrackCuts(0),
24  fDoSpdVtxCon(0),
25  fHybridTrackCuts(0),
26  fTracksName(),
27  fIncludeNoITS(kTRUE),
28  fDoPropagation(kFALSE),
29  fDist(440),
30  fTrackEfficiency(0),
31  fIsMC(kFALSE),
32  fEsdEv(0),
33  fTracks(0)
34 {
35  // Constructor.
36 }
37 
38 //________________________________________________________________________
40  AliAnalysisTaskSE(name),
41  fEsdTrackCuts(0),
42  fDoSpdVtxCon(0),
43  fHybridTrackCuts(0),
44  fTracksName("EsdTracksOut"),
45  fIncludeNoITS(kTRUE),
46  fDoPropagation(kFALSE),
47  fDist(440),
48  fTrackEfficiency(0),
49  fIsMC(kFALSE),
50  fEsdEv(0),
51  fTracks(0)
52 {
53  // Constructor.
54 
55  if (!name)
56  return;
57 
58  SetName(name);
59 
60  fBranchNames = "ESD:AliESDHeader.,AliESDRun.,SPDVertex.,Tracks";
61 }
62 
63 //________________________________________________________________________
65 {
66  //Destructor
67 
68  delete fEsdTrackCuts;
69 }
70 
71 //________________________________________________________________________
73 {
74  // Create histograms.
75 
76  fTracks = new TClonesArray("AliESDtrack");
77  fTracks->SetName(fTracksName);
78 
79 
80  if (!fEsdTrackCuts) {
81  if (fDoSpdVtxCon) {
82  AliInfo("No track cuts given, creating default (standard only TPC) cuts");
83  fEsdTrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
84  fEsdTrackCuts->SetPtRange(0.15,1e3);
85  }
86  else {
87  AliWarning("No track cuts given, but maybe this is indeed intended?");
88  }
89  }
90 }
91 
92 //________________________________________________________________________
94 {
95  // Main loop, called for each event.
96 
97  fEsdEv = dynamic_cast<AliESDEvent*>(InputEvent());
98  if (!fEsdEv) {
99  AliError("Task works only on ESD events, returning");
100  return;
101  }
102 
103  AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
104  if (!am) {
105  AliError("Manager zero, returning");
106  return;
107  }
108 
109  // add tracks to event if not yet there
110  fTracks->Delete();
111  if (!(InputEvent()->FindListObject(fTracksName)))
112  InputEvent()->AddObject(fTracks);
113 
114  if (!fHybridTrackCuts) { // constrain TPC tracks to SPD vertex if fDoSpdVtxCon==kTRUE
115  am->LoadBranch("AliESDRun.");
116  am->LoadBranch("AliESDHeader.");
117  am->LoadBranch("Tracks");
118 
119  if (fDoSpdVtxCon) {
120  if (!TGeoGlobalMagField::Instance()->GetField()) { // construct field map
121  fEsdEv->InitMagneticField();
122  }
123  am->LoadBranch("SPDVertex.");
124  const AliESDVertex *vtxSPD = fEsdEv->GetPrimaryVertexSPD();
125  if (!vtxSPD) {
126  AliError("No SPD vertex, returning");
127  return;
128  }
129  Int_t ntr = fEsdEv->GetNumberOfTracks();
130  for (Int_t i=0, ntrnew=0; i<ntr; ++i) {
131  AliESDtrack *etrack = fEsdEv->GetTrack(i);
132  if (!etrack)
133  continue;
134 
135  if (!fEsdTrackCuts->AcceptTrack(etrack))
136  continue;
137 
138  AliESDtrack *ntrack = AliESDtrackCuts::GetTPCOnlyTrack(fEsdEv,etrack->GetID());
139  if (!ntrack)
140  continue;
141  if (ntrack->Pt()<=0) {
142  delete ntrack;
143  continue;
144  }
145  Double_t bfield[3] = {0,0,0};
146  ntrack->GetBxByBz(bfield);
147  AliExternalTrackParam exParam;
148  Bool_t relate = ntrack->RelateToVertexBxByBz(vtxSPD,bfield,kVeryBig,&exParam);
149  if (!relate) {
150  delete ntrack;
151  continue;
152  }
153  // set the constraint parameters to the track
154  ntrack->Set(exParam.GetX(),exParam.GetAlpha(),exParam.GetParameter(),exParam.GetCovariance());
155  if (ntrack->Pt()<=0) {
156  delete ntrack;
157  continue;
158  }
159 
160  if (fTrackEfficiency) {
161  Double_t r = gRandom->Rndm();
162  if (fTrackEfficiency->Eval(ntrack->Pt()) < r)
163  continue;
164  }
165 
166  if (fDoPropagation)
167  AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(ntrack,fDist);
168  new ((*fTracks)[ntrnew++]) AliESDtrack(*ntrack);
169  delete ntrack;
170  }
171  } else { /* no spd vtx constraint */
172  Int_t ntr = fEsdEv->GetNumberOfTracks();
173  for (Int_t i=0, ntrnew=0; i<ntr; ++i) {
174  AliESDtrack *etrack = fEsdEv->GetTrack(i);
175  if (!etrack)
176  continue;
177 
178  if ((fEsdTrackCuts!=0) && !fEsdTrackCuts->AcceptTrack(etrack))
179  continue;
180 
181  if (fTrackEfficiency) {
182  Double_t r = gRandom->Rndm();
183  if (fTrackEfficiency->Eval(etrack->Pt()) < r)
184  continue;
185  }
186 
187  AliESDtrack *ntrack = new ((*fTracks)[ntrnew++]) AliESDtrack(*etrack);
188  if (fDoPropagation)
189  AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(ntrack,fDist);
190  }
191  }
192 
193  } else { // use hybrid track cuts
194 
195  am->LoadBranch("Tracks");
196  Int_t ntr = fEsdEv->GetNumberOfTracks();
197  for (Int_t i=0, ntrnew=0; i<ntr; ++i) {
198  AliESDtrack *etrack = fEsdEv->GetTrack(i);
199  if (!etrack)
200  continue;
201 
202  if (fEsdTrackCuts->AcceptTrack(etrack)) {
203  if (fTrackEfficiency) {
204  Double_t r = gRandom->Rndm();
205  if (fTrackEfficiency->Eval(etrack->Pt()) < r)
206  continue;
207  }
208  AliESDtrack *newTrack = new ((*fTracks)[ntrnew]) AliESDtrack(*etrack);
209  if (fDoPropagation)
210  AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(newTrack,fDist);
211  newTrack->SetBit(BIT(22),0);
212  newTrack->SetBit(BIT(23),0);
213  if (!fMCEvent) newTrack->SetLabel(0);
214  ++ntrnew;
215  } else if (fHybridTrackCuts->AcceptTrack(etrack)) {
216  if (!etrack->GetConstrainedParam())
217  continue;
218  UInt_t status = etrack->GetStatus();
219  if (!fIncludeNoITS && ((status&AliESDtrack::kITSrefit)==0))
220  continue;
221 
222  if (fTrackEfficiency) {
223  Double_t r = gRandom->Rndm();
224  if (fTrackEfficiency->Eval(etrack->Pt()) < r)
225  continue;
226  }
227  AliESDtrack *newTrack = new ((*fTracks)[ntrnew]) AliESDtrack(*etrack);
228  if (fDoPropagation)
229  AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(newTrack,fDist);
230  const AliExternalTrackParam* constrainParam = etrack->GetConstrainedParam();
231  newTrack->Set(constrainParam->GetX(),
232  constrainParam->GetAlpha(),
233  constrainParam->GetParameter(),
234  constrainParam->GetCovariance());
235  if ((status&AliESDtrack::kITSrefit)==0) {
236  newTrack->SetBit(BIT(22),0); //type 2
237  newTrack->SetBit(BIT(23),1);
238  } else {
239  newTrack->SetBit(BIT(22),1); //type 1
240  newTrack->SetBit(BIT(23),0);
241  }
242  if (!fMCEvent) newTrack->SetLabel(0);
243  ++ntrnew;
244  }
245  }
246  }
247 }
TClonesArray * fTracks
esd event
double Double_t
Definition: External.C:58
ClassImp(AliEmcalEsdTrackFilterTask) AliEmcalEsdTrackFilterTask
TRandom * gRandom
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53