AliPhysics  v5-06-40-01 (42bb456)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliEmcalTrackPropagatorTask.cxx
Go to the documentation of this file.
1 // $Id: AliEmcalTrackPropagatorTask.cxx | Mon Dec 9 12:59:28 2013 +0100 | Constantin Loizides $
2 //
3 // Task to propagate tracks to EMCAL surface.
4 //
5 // Author: C.Loizides
6 
8 #include <TClonesArray.h>
9 #include "AliAODEvent.h"
10 #include "AliAnalysisManager.h"
11 #include "AliEMCALRecoUtils.h"
12 #include "AliESDEvent.h"
13 
15 
16 //________________________________________________________________________
18  AliAnalysisTaskSE("AliEmcalTrackPropagatorTask"),
19  fTracksInName(),
20  fTracksOutName(),
21  fDist(440),
22  fOnlyIfNotSet(kTRUE),
23  fTracksIn(0),
24  fTracksOut(0)
25 {
26  // Constructor.
27 }
28 
29 //________________________________________________________________________
31  AliAnalysisTaskSE("AliEmcalTrackPropagatorTask"),
32  fTracksInName(),
33  fTracksOutName(),
34  fDist(440),
35  fOnlyIfNotSet(kTRUE),
36  fTracksIn(0),
37  fTracksOut(0)
38 {
39  // Constructor.
40 
41  if (!name)
42  return;
43 
44  SetName(name);
45 
46  fBranchNames = "ESD:AliESDHeader.,Tracks";
47 }
48 
49 //________________________________________________________________________
51 {
52  // Destructor.
53 }
54 
55 //________________________________________________________________________
57 {
58  // User create output objects.
59 }
60 
61 //________________________________________________________________________
63 {
64  // Main loop, called for each event.
65 
66  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(InputEvent());
67  AliAODEvent *aodev = 0;
68  if (!esdev) {
69  aodev = dynamic_cast<AliAODEvent*>(InputEvent());
70  if (!aodev) {
71  AliError("Task needs AOD or ESD event, returning");
72  return;
73  }
74  }
75 
76  if (fTracksInName.Length()==0) {
77  if (esdev) {
78  fTracksInName = "Tracks";
79  } else {
80  fTracksInName = "tracks";
81  }
82  }
83 
84  AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
85  if (!am) {
86  AliError("Manager zero, returning");
87  return;
88  }
89  if (fTracksInName == "Tracks")
90  am->LoadBranch("Tracks");
91  else if (fTracksInName == "tracks")
92  am->LoadBranch("tracks");
93 
94  if (!fTracksIn) {
95  fTracksIn = dynamic_cast<TClonesArray*>((InputEvent()->FindListObject(fTracksInName)));
96  if (!fTracksIn) {
97  AliError(Form("Could not get tracks %s, returning", fTracksInName.Data()));
98  return;
99  }
100  }
101 
102  if ((fTracksOutName.Length()>0) && !fTracksOut) {
103  if ((InputEvent()->FindListObject(fTracksOutName))) {
104  AliError(Form("Could not add tracks %s to event, returning", fTracksOutName.Data()));
105  return;
106  }
107  if (esdev)
108  fTracksOut = new TClonesArray("AliESDtrack");
109  else
110  fTracksOut = new TClonesArray("AliAODTrack");
111  fTracksOut->SetName(fTracksOutName);
112  InputEvent()->AddObject(fTracksOut);
113  }
114 
115  const Int_t ntr = fTracksIn->GetEntries();
116  for (Int_t i=0; i<ntr; ++i) {
117  AliVTrack *inTrack = dynamic_cast<AliVTrack*>(fTracksIn->At(i));
118  if (!inTrack)
119  continue;
120  if (inTrack->IsExtrapolatedToEMCAL() && fOnlyIfNotSet)
121  continue;
122  AliVTrack *outTrack = inTrack;
123  if (fTracksOut) {
124  if (esdev)
125  outTrack = new ((*fTracksOut)[i]) AliESDtrack(*((AliESDtrack*)inTrack));
126  else
127  outTrack = new ((*fTracksOut)[i]) AliAODTrack(*((AliAODTrack*)inTrack));
128  }
129  AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(outTrack,fDist);
130  }
131 }
TClonesArray * fTracksOut
track array in
ClassImp(AliEmcalTrackPropagatorTask) AliEmcalTrackPropagatorTask