AliPhysics  63e47e1 (63e47e1)
AliAnalysisTaskGCPartToPWG4Part.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include "TChain.h"
3 #include "TTree.h"
4 #include "TH1F.h"
5 #include "TCanvas.h"
6 #include "TString.h"
7 
8 #include "AliAnalysisTask.h"
9 #include "AliAnalysisManager.h"
11 
12 #include "AliESDEvent.h"
13 #include "AliESDCaloCluster.h"
14 #include "AliESDInputHandler.h"
15 
16 #include "AliAODPWG4ParticleCorrelation.h"
17 #include "AliAODEvent.h"
18 #include "AliAODHandler.h"
19 #include "AliAODCaloCluster.h"
20 #include "AliAODConversionPhoton.h"
21 #include "AliAODJet.h"
22 
23 #include "AliAODInputHandler.h"
24 
25 #include "AliAODMCParticle.h"
26 
27 
28 #include "AliAODMCHeader.h"
29 // Gamma - jet correlation analysis task
30 // Authors: Svein Lindal
31 
32 
33 using namespace std;
34 
36 
37 //________________________________________________________________________
40  fDeltaAODFileName(""),
41  fGammaCutString("GammaConv"),
42  fPionCutString("GammaConv"),
43  fAODBranchName("GammaConv_gamma"),
44  fAODPWG4Photons(NULL),
45  fAODPWG4Pi0(NULL),
46  fDebugLevel(0)
47 {
48  // Dummy Constructor
49 }
50 
51 //________________________________________________________________________________
53 
54  if(fAODPWG4Photons)
55  delete fAODPWG4Photons;
56  fAODPWG4Photons = NULL;
57 
58  if(fAODPWG4Pi0)
59  delete fAODPWG4Pi0;
60  fAODPWG4Pi0 = NULL;
61 
62 
63 }
64 
65 
66 
67 //________________________________________________________________________
69  AliAnalysisTaskSE(name),
70  fDeltaAODFileName(""),
71  fGammaCutString("GammaConv"),
72  fPionCutString("GammaConv"),
73  fAODBranchName("GammaConv_gamma"),
74  fAODPWG4Photons(NULL),
75  fAODPWG4Pi0(NULL),
76  fDebugLevel(0)
77 {
78  // Constructor
79  DefineInput(0, TChain::Class());
80  // Output slot #0 id reserved by the base class for AOD
81 
82  // Output slot #1 writes into a TH1 container
83  DefineOutput(1, TList::Class());
84 
85 }
86 
87 
88 
89 //________________________________________________________________________
91  fAODPWG4Photons = new TClonesArray("AliAODPWG4ParticleCorrelation", 0);
92  fAODPWG4Photons->SetName("PhotonsCTS");
93  AddAODBranch("TClonesArray", &fAODPWG4Photons);
94 
95  fAODPWG4Pi0 = new TClonesArray("AliAODPWG4ParticleCorrelation", 0);
96  fAODPWG4Pi0->SetName("Pi0sCTS");
97  AddAODBranch("TClonesArray", &fAODPWG4Pi0);
98 
99 }
100 
101 //________________________________________________________________________
103 {
104 
105  //AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);
106 
107  //Clear stuff for new event
108  CleanUp();
109 
111  AliAODEvent * aodEvent = GetAODEvent();
112  if(!aodEvent) {
113  AliError("No AOD event!!");
114  return;
115  }
116 
117  ProcessConvGamma(aodEvent);
118 
119 }
120 
121 
122 
123 
124 //___________________________________________________________________________________________
126 
127  TClonesArray * tracks = aodEvent->GetTracks();
128  if(!tracks) {
129  cout << "No tracks!!!"<<endl;
130  return;
131  }
132 
133 
134  TClonesArray * convGamma = GetConversionGammas(aodEvent);
135  if(!convGamma) {
136  AliError(Form("No branch by name %s found in file %s", fAODBranchName.Data(), fDeltaAODFileName.Data()));
137  return;
138  }
139 
140 
141  //TClonesArray * arrayMC = dynamic_cast<TClonesArray*>(aodEvent->GetList()->FindObject(AliAODMCParticle::StdBranchName()));
142  for (Int_t iPhot = 0; iPhot < convGamma->GetEntriesFast(); iPhot++) {
143 
144  AliAODPWG4ParticleCorrelation * photon = NULL;
145  AliAODConversionPhoton * convParticle = dynamic_cast<AliAODConversionPhoton*>(convGamma->At(iPhot));
146  if (convParticle && BothTracksPresent(convParticle, tracks)) {
147  photon = AddToAOD(convParticle, fAODPWG4Photons, 2); //"ConvGamma");
148 
149  } else {
150  continue;
151  }
152 
153  if(photon && fDebugLevel > 2) {
154  printf("Added conversion photon number %d, pt: %f \n", iPhot, photon->Pt());
155  }
156 
157  }
158 
159 
160  TClonesArray * pions = GetPions(aodEvent);
161  if(!pions) {
162  AliError(Form("No branch by name %s found in file %s", fAODBranchName.Data(), fDeltaAODFileName.Data()));
163  return;
164  }
165 
166  for (Int_t iPhot = 0; iPhot < pions->GetEntriesFast(); iPhot++) {
167  AliAODPWG4ParticleCorrelation * pion = NULL;
168  AliAODConversionPhoton * convParticle = dynamic_cast<AliAODConversionPhoton*>(pions->At(iPhot));
169  if (convParticle && BothGammaPresent(convParticle, convGamma, tracks)) {
170  pion = AddPionToAOD(convParticle, fAODPWG4Pi0, 2); //"ConvGamma");
171 
172  } else {
173  continue;
174  }
175 
176  if(pion && fDebugLevel > 2) {
177  printf("Added conversion pion number %d, pt: %f \n", iPhot, pion->Pt());
178  }
179  }
180 
181 
182 
183 }
184 
185 
186 
187 
188 
190 AliAODPWG4ParticleCorrelation * AliAnalysisTaskGCPartToPWG4Part::AddToAOD(AliAODConversionPhoton * aodO, TClonesArray * branch, Int_t detector) {
191  new((*branch)[branch->GetEntriesFast()]) AliAODPWG4ParticleCorrelation(aodO->Px(), aodO->Py(), aodO->Pz(), aodO->E());
192  AliAODPWG4ParticleCorrelation * photon = dynamic_cast<AliAODPWG4ParticleCorrelation*>(branch->Last());
193  if(photon) {
194  photon->SetTrackLabel(aodO->GetLabel1(), aodO->GetLabel2());
195  photon->SetDetectorTag(detector);
196  return photon;
197  } else {
198  return NULL;
199  }
200 
201 }
202 
203 
205 AliAODPWG4ParticleCorrelation * AliAnalysisTaskGCPartToPWG4Part::AddPionToAOD(AliAODConversionPhoton * pion, TClonesArray * branch, Int_t detector) {
206  new((*branch)[branch->GetEntriesFast()]) AliAODPWG4ParticleCorrelation(pion->Px(), pion->Py(), pion->Pz(), pion->E());
207  AliAODPWG4ParticleCorrelation * pwg4Pion = dynamic_cast<AliAODPWG4ParticleCorrelation*>(branch->Last());
208  if(pwg4Pion) {
209  Int_t tl[4] = {-1, -1, -1, -1};
210  //pion->GetGrandChildren(photons, tl);
211  pwg4Pion->SetTrackLabel(tl[0], tl[1], tl[2], tl[3]);
212  pwg4Pion->SetDetectorTag(detector);
213  for(Int_t i = 0; i < 4; i++) {
214  cout << tl[i] << " ";
215  }
216  cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
217  return pwg4Pion;
218  } else {
219  return NULL;
220  }
221 
222 }
223 
224 
225 
226 
227 //_____________________________________________________________________
229  // Draw result to the screen
230  // Called once at the end of the query
231 }
232 
233 //_____________________________________________________________________
235  //Get the AOD event from whereever it might be
236  AliAODEvent * aodEvent = dynamic_cast<AliAODEvent*>(InputEvent());
237  if(!aodEvent) {
238  aodEvent = AODEvent();
239  }
240 
241  return aodEvent;
242 
243 }
244 
245 
246 //_____________________________________________________________________
247 TClonesArray * AliAnalysisTaskGCPartToPWG4Part::GetAODBranch(const AliAODEvent * aodEvent, TString branchName) const {
248 
249  //Get Conversion gamma branch of AOD. First try standard AOD
250  TClonesArray * branch = dynamic_cast<TClonesArray*>(aodEvent->FindListObject(branchName.Data()));
251 
252 
253  //If it's there, send it back
254  if(branch) return branch;
255 
256 
257  //If AOD not in standard file have to locate it in delta AOD
258  if( !(fDeltaAODFileName.Length() > 0) ) return NULL;
259 
260  AliAODHandler * aodHandler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
261  if(aodHandler) {
262  AliAODExtension * gExt = dynamic_cast<AliAODExtension*>(aodHandler->GetExtensions()->FindObject(fDeltaAODFileName));
263  if(gExt) {
264  AliAODEvent * gcEvent = gExt->GetAOD();
265  return dynamic_cast<TClonesArray*>(gcEvent->FindListObject(branchName.Data()));
266  }
267  }
268  return NULL;
269 
270 }
271 //_____________________________________________________________________
273  return GetAODBranch(aodEvent, Form("%s_gamma", fGammaCutString.Data()));
274 
275 }
276 
277 //_____________________________________________________________________
278 TClonesArray * AliAnalysisTaskGCPartToPWG4Part::GetPions(const AliAODEvent * aodEvent) const {
279  return GetAODBranch(aodEvent, Form("%s_Pi0", fPionCutString.Data()));
280 
281 }
282 
283 
284 //_________________________________________________________________________
286  fAODPWG4Photons->Delete();
287  fAODPWG4Pi0->Delete();
288 }
289 
290 
291 //______________________________________________________________________________________________
292 Bool_t AliAnalysisTaskGCPartToPWG4Part::BothTracksPresent(const AliAODConversionPhoton * const photon, const TClonesArray * const tracks) const {
293 
294  AliAODTrack * track1 = NULL;
295  AliAODTrack * track2 = NULL;
296  for(Int_t i = 0; i < tracks->GetEntriesFast(); i++) {
297  AliAODTrack * track = dynamic_cast<AliAODTrack*>(tracks->At(i));
298  if(track) {
299  if(track->GetID() == photon->GetLabel1()) track1 = track;
300  else if (track->GetID() == photon->GetLabel2()) track2 = track;
301  if(track1 && track2) break;
302  }
303  }
304 
305  if(track1 && track2) {
306  return kTRUE;
307  }
308  cout << "Could not get both tracks!!! labels " << photon->GetLabel1() << " " << photon->GetLabel2() <<endl;
309  return kFALSE;
310 
311 
312 }
313 
314 //______________________________________________________________________________________________
315 Bool_t AliAnalysisTaskGCPartToPWG4Part::BothGammaPresent(const AliAODConversionPhoton * const pion, const TClonesArray * const photons, const TClonesArray * const tracks) const {
316 
317  AliAODConversionPhoton * photon1 = dynamic_cast<AliAODConversionPhoton*>(photons->At(pion->GetLabel1()));
318  AliAODConversionPhoton * photon2 = dynamic_cast<AliAODConversionPhoton*>(photons->At(pion->GetLabel2()));
319 
320  if(photon1 && photon2) {
321  if( BothTracksPresent(photon1, tracks) && BothTracksPresent(photon1, tracks)) {
322  return kTRUE;
323  }
324  } else {
325  cout << "can't find both photons "<< endl;
326  }
327 
328  return kFALSE;
329 }
TString fPionCutString
The cut string of the conversion analysis used to produce input AOD.
TString fGammaCutString
File where Gamma Conv AOD is located, if not in default AOD.
AliAODPWG4ParticleCorrelation * AddToAOD(AliAODConversionPhoton *aodO, TClonesArray *branch, Int_t detector)
virtual Int_t GetLabel1() const
TClonesArray * GetConversionGammas(const AliAODEvent *aodEvent) const
int Int_t
Definition: External.C:63
Bool_t BothGammaPresent(const AliAODConversionPhoton *const pion, const TClonesArray *const photons, const TClonesArray *const tracks) const
AliAODPWG4ParticleCorrelation * AddPionToAOD(AliAODConversionPhoton *pion, TClonesArray *branch, Int_t detector)
Int_t fDebugLevel
virtual Int_t GetLabel2() const
TClonesArray * GetAODBranch(const AliAODEvent *aodEvent, TString branchName) const
void ProcessConvGamma(const AliAODEvent *const aodEvent)
Bool_t BothTracksPresent(const AliAODConversionPhoton *const photon, const TClonesArray *const tracks) const
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53
TClonesArray * GetPions(const AliAODEvent *aodEvent) const
TString fAODBranchName
The cut string of the conversion analysis used to produce input AOD.