AliPhysics  b555aef (b555aef)
AliNanoAODArrayMaker.cxx
Go to the documentation of this file.
1 
7 #include "AliAnalysisTask.h"
8 #include "AliAnalysisManager.h"
9 
10 #include "AliAODEvent.h"
11 #include "AliNanoAODTrack.h"
12 #include "AliAODTrack.h"
13 
14 #include <TClonesArray.h>
15 
16 #include "AliNanoAODArrayMaker.h"
17 
18 ClassImp(AliNanoAODArrayMaker)
19 
20 //________________________________________________________________________
22  : AliAnalysisTaskSE(name), fOutputArrayName(), fOutputArray(0), fOutputArrayPythiaName(), fPythiaArray(0), fOutputList(0x0)
23 {
24  // Constructor
25 
26  // Output slot #0 id reserved by the base class for AOD
27  // Output slot #1 writes into a TH1 container
28  DefineOutput(1, TList::Class());
29 }
30 
31 //________________________________________________________________________
33 {
34  // Create arrays and set names
35  // Called once
36 
37  fOutputList = new TList();
38  fOutputList->SetOwner(kTRUE);
39 
40  fOutputArray = new TClonesArray("AliAODTrack");
41  fOutputArray->SetName(fOutputArrayName.Data());
42  Printf("%s \n", fOutputArrayName.Data());
43 
44  fDataArray = new TClonesArray("AliAODTrack");
45  fDataArray->SetName(fOutputArrayDataName.Data());
46  Printf("%s \n", fOutputArrayDataName.Data());
47 
48  fPythiaArray = new TClonesArray("AliAODTrack");
49  fPythiaArray->SetName(fOutputArrayPythiaName.Data());
50  Printf("%s \n", fOutputArrayPythiaName.Data());
51 
52  PostData(1,fOutputList);
53 
54 }
55 //________________________________________________________________________
57 {
58  // Main loop
59  // Called for each event
60  if(fIsFirstLoop){
61  InputEvent()->AddObject(fOutputArray);
62  InputEvent()->AddObject(fPythiaArray);
63  InputEvent()->AddObject(fDataArray);
64  fIsFirstLoop = false;
65  }
66 
67  //find NanoAOD particle array
68  TClonesArray *particleArray = static_cast<TClonesArray*> (InputEvent()->FindListObject("Nanotracks"));
69  Int_t nTracks = particleArray->GetEntries();
70 
71  Int_t accTracks = 0;
72  Int_t accTracksPythia = 0;
73  Int_t accTracksData = 0;
74 
75  //get custom NanoAOD variables which had to be defined in the nanoAOD generation
76  Int_t indexHybGlob = AliNanoAODTrackMapping::GetInstance()->GetVarIndex("cstIsGlobalHybrid");
77  Int_t indexIsPyth = AliNanoAODTrackMapping::GetInstance()->GetVarIndex("cstIsPythiaTrack");
78 
79  AliAODTrack* newTrack = new AliAODTrack();
80 
81  //Delte array members from the previous event
82  fPythiaArray->Delete();
83  fOutputArray->Delete();
84  fDataArray->Delete();
85 
86  //loop over particles in the event and add them to the correct arrays
87  for(Int_t iPart=0; iPart<nTracks; iPart++){
88  AliNanoAODTrack *nanoTrack = (AliNanoAODTrack*) particleArray->At(iPart);
89 
90  if (nanoTrack->GetVar(indexIsPyth)==1){
91  GetAODTrack(newTrack, nanoTrack);
92  new ((*fPythiaArray)[accTracksPythia]) AliAODTrack(*newTrack);
93  new ((*fOutputArray)[accTracks]) AliAODTrack(*newTrack);
94  accTracksPythia++;
95  }else{
96  GetAODTrack(newTrack, nanoTrack,indexHybGlob);
97  new ((*fDataArray)[accTracksData]) AliAODTrack(*newTrack);
98  new ((*fOutputArray)[accTracks]) AliAODTrack(*newTrack);
99  accTracksData++;
100  }
101  accTracks++;
102  }
103 
104  delete newTrack;
105 }
106 
107 //________________________________________________________________________
109 {
110  // Called once at the end of the query
111 
112 
113 }
114 //_____________________________________________________________________________________________________
115 void AliNanoAODArrayMaker::GetAODTrack(AliAODTrack* newTrack, AliNanoAODTrack* track, Int_t index)
116 {
117  //create AOD track from NanoAOD track with the availbable information
118  newTrack->SetPt(track->Pt());
119  newTrack->SetTheta(2.*atan(exp(-track->Eta()))); // the same as in AliAnalysisTaskParticleRandomizer
120  newTrack->SetPhi(track->Phi());
121  newTrack->SetCharge(track->Charge());
122  newTrack->SetLabel(track->GetLabel());
123  if (index==-1 || track->GetVar(index) == 1) newTrack->SetIsHybridGlobalConstrainedGlobal();
124  newTrack->SetFilterMap(track->GetFilterMap());
125 
126 }
127 
TClonesArray * fDataArray
name of the output array with data particles
TClonesArray * fOutputArray
name of the output array with all particles
TClonesArray * fPythiaArray
name of the output array with pythia particles
void GetAODTrack(AliAODTrack *newTrack, AliNanoAODTrack *track, Int_t index=-1)
int Int_t
Definition: External.C:63
TString fOutputArrayName
describes if this is the first event loop
virtual void UserCreateOutputObjects()
const char Option_t
Definition: External.C:48
virtual void UserExec(Option_t *option)
creates input arrays for the analysis from NanoAODs
virtual void Terminate(Option_t *)