AliPhysics  d565ceb (d565ceb)
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 #include <TRandom3.h>
16 
17 #include "AliNanoAODArrayMaker.h"
18 
19 ClassImp(AliNanoAODArrayMaker)
20 
21 //________________________________________________________________________
23  : AliAnalysisTaskSE(name), fOutputArrayName(), fOutputArray(0), fOutputArrayPythiaName(), fPythiaArray(0), fTrackEffPythia(1.0), fTrackEffData(1.0), fRandom(), fOutputList(0x0)
24 {
25  // Constructor
26 
27  // Output slot #0 id reserved by the base class for AOD
28  // Output slot #1 writes into a TH1 container
29  DefineOutput(1, TList::Class());
30 }
31 
32 //________________________________________________________________________
34 {
35  // Create arrays and set names
36  // Called once
37 
38  fRandom = new TRandom3(0);
39 
40  fOutputList = new TList();
41  fOutputList->SetOwner(kTRUE);
42 
43  fOutputArray = new TClonesArray("AliAODTrack");
44  fOutputArray->SetName(fOutputArrayName.Data());
45  Printf("%s \n", fOutputArrayName.Data());
46 
47  fDataArray = new TClonesArray("AliAODTrack");
48  fDataArray->SetName(fOutputArrayDataName.Data());
49  Printf("%s \n", fOutputArrayDataName.Data());
50 
51  fPythiaArray = new TClonesArray("AliAODTrack");
52  fPythiaArray->SetName(fOutputArrayPythiaName.Data());
53  Printf("%s \n", fOutputArrayPythiaName.Data());
54 
55  PostData(1,fOutputList);
56 
57 }
58 //________________________________________________________________________
60 {
61  // Main loop
62  // Called for each event
63  if(fIsFirstLoop){
64  //add dummy arrays so that the clean up for Nano AOD arrays works, this is necessary because normal AODs contain more arrays in the AOD event in the standard format. Only Arrays after these standard events will be resetted for the next AOD event. These dummy arrays ensure that the arrays added further below are properly resetted in the framework
65  TClonesArray* dummy[30];
66 
67  int number_dummy = 22-InputEvent()->GetList()->GetSize();//22 is the number of entries in the standard AODs
68  if(number_dummy<0)
69  number_dummy=0;
70 
71  for(int i=0; i<number_dummy; i++){
72  dummy[i] = new TClonesArray(Form("dummy%i", i));//due to the definition of the content to be dummy this array cannot be filled or deleted
73  dummy[i]->SetName(Form("dummy%i", i));
74  InputEvent()->AddObject(dummy[i]);
75  }
76 
77  InputEvent()->AddObject(fOutputArray);
78  InputEvent()->AddObject(fPythiaArray);
79  InputEvent()->AddObject(fDataArray);
80  fIsFirstLoop = false;
81  }
82 
83  //find NanoAOD particle array
84  TClonesArray *particleArray = static_cast<TClonesArray*> (InputEvent()->FindListObject("Nanotracks"));
85  Int_t nTracks = particleArray->GetEntries();
86 
87  Int_t accTracks = 0;
88  Int_t accTracksPythia = 0;
89  Int_t accTracksData = 0;
90 
91  //get custom NanoAOD variables which had to be defined in the nanoAOD generation
92  Int_t indexHybGlob = AliNanoAODTrackMapping::GetInstance()->GetVarIndex("cstIsGlobalHybrid");
93  Int_t indexIsPyth = AliNanoAODTrackMapping::GetInstance()->GetVarIndex("cstIsPythiaTrack");
94 
95  AliAODTrack* newTrack = new AliAODTrack();
96 
97  //loop over particles in the event and add them to the correct arrays
98  for(Int_t iPart=0; iPart<nTracks; iPart++){
99  AliNanoAODTrack *nanoTrack = (AliNanoAODTrack*) particleArray->At(iPart);
100 
101  if (nanoTrack->GetVar(indexIsPyth)==1){
102  // Discard tracks due to lowered tracking efficiency
103  if (fTrackEffPythia < 1.0 && fTrackEffPythia < fRandom->Rndm())
104  continue;
105  GetAODTrack(newTrack, nanoTrack);
106  new ((*fPythiaArray)[accTracksPythia]) AliAODTrack(*newTrack);
107  accTracksPythia++;
108  }else{
109  // Discard tracks due to lowered tracking efficiency
110  if (fTrackEffData < 1.0 && fTrackEffData < fRandom->Rndm())
111  continue;
112  GetAODTrack(newTrack, nanoTrack,indexHybGlob);
113  new ((*fDataArray)[accTracksData]) AliAODTrack(*newTrack);
114  accTracksData++;
115  }
116 
117  new ((*fOutputArray)[accTracks]) AliAODTrack(*newTrack);
118  accTracks++;
119  }
120 
121  delete newTrack;
122 }
123 
124 //________________________________________________________________________
126 {
127  // Called once at the end of the query
128 
129 
130 }
131 //_____________________________________________________________________________________________________
132 void AliNanoAODArrayMaker::GetAODTrack(AliAODTrack* newTrack, AliNanoAODTrack* track, Int_t index)
133 {
134  //create AOD track from NanoAOD track with the availbable information
135  newTrack->SetPt(track->Pt());
136  newTrack->SetTheta(2.*atan(exp(-track->Eta()))); // the same as in AliAnalysisTaskParticleRandomizer
137  newTrack->SetPhi(track->Phi());
138  newTrack->SetCharge(track->Charge());
139  newTrack->SetLabel(track->GetLabel());
140  if (index==-1 || track->GetVar(index) == 1) newTrack->SetIsHybridGlobalConstrainedGlobal(true);
141  else newTrack->SetIsHybridGlobalConstrainedGlobal(false);
142  newTrack->SetFilterMap(track->GetFilterMap());
143 
144 }
145 
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
TRandom3 * fRandom
artificial tracking efficiency modification for data particles
TString fOutputArrayName
describes if this is the first event loop
Double_t fTrackEffData
artificial tracking efficiency modification for PYTHIA particles
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 *)