]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/CaloCalib/AliAnalysisTaskEMCALPi0PbPb.cxx
Clean way to get input from clusterizer and event
[u/mrichter/AliRoot.git] / PWG4 / CaloCalib / AliAnalysisTaskEMCALPi0PbPb.cxx
1 // $Id$
2
3 #include "AliAnalysisTaskEMCALPi0PbPb.h"
4 #include <TChain.h>
5 #include <TClonesArray.h>
6 #include <TH1F.h>
7 #include <TH2F.h>
8 #include <TList.h>
9 #include <TLorentzVector.h>
10 #include "AliAODEvent.h"
11 #include "AliAODVertex.h"
12 #include "AliAnalysisManager.h"
13 #include "AliAnalysisTaskEMCALClusterizeFast.h"
14 #include "AliCentrality.h"
15 #include "AliEMCALGeoUtils.h"
16 #include "AliESDEvent.h"
17 #include "AliESDVertex.h"
18 #include "AliLog.h"
19
20 ClassImp(AliAnalysisTaskEMCALPi0PbPb)
21
22 //________________________________________________________________________
23 AliAnalysisTaskEMCALPi0PbPb::AliAnalysisTaskEMCALPi0PbPb() 
24   : AliAnalysisTaskSE(),
25     fCentVar(),
26     fCentFrom(0),
27     fCentTo(100),
28     fVtxZMin(-7),
29     fVtxZMax(+7),
30     fUseQualFlag(1),
31     fClusName(),
32     fOutput(0),
33     fEsdEv(0),
34     fAodEv(0),
35     fRecPoints(0),
36     fEsdClusters(0),
37     fEsdCells(0),
38     fAodClusters(0),
39     fAodCells(0),
40     fHcuts(0),
41     fHvertexZ(0),
42     fHcent(0)
43 {
44   // ROOT constructor.
45 }
46
47 //________________________________________________________________________
48 AliAnalysisTaskEMCALPi0PbPb::AliAnalysisTaskEMCALPi0PbPb(const char *name) 
49   : AliAnalysisTaskSE(name),
50     fCentVar("V0M"),
51     fCentFrom(0),
52     fCentTo(100),
53     fVtxZMin(-7),
54     fVtxZMax(+7),
55     fUseQualFlag(1),
56     fClusName(),
57     fOutput(0),
58     fEsdEv(0),
59     fAodEv(0),
60     fRecPoints(0),
61     fEsdClusters(0),
62     fEsdCells(0),
63     fAodClusters(0),
64     fAodCells(0),
65     fHcuts(0),
66     fHvertexZ(0),
67     fHcent(0)
68 {
69   // Constructor.
70
71   DefineInput(0, TChain::Class());
72   DefineOutput(1, TList::Class());
73   fBranchNames="ESD:AliESDRun.,AliESDHeader.,PrimaryVertex,EMCALCells.,CaloClusters "
74                "AOD:header,vertices,emcalCells,caloClusters";
75 }
76
77 //________________________________________________________________________
78 AliAnalysisTaskEMCALPi0PbPb::~AliAnalysisTaskEMCALPi0PbPb()
79 {
80   // Destructor.
81
82   delete fOutput; fOutput = 0;
83 }
84
85 //________________________________________________________________________
86 void AliAnalysisTaskEMCALPi0PbPb::UserCreateOutputObjects()
87 {
88   // Create user objects here.
89
90   fOutput = new TList();
91   fOutput->SetOwner();
92
93   fHcuts = new TH1F("hEventCuts","",4,0.5,4.5);
94   fHcuts->GetXaxis()->SetBinLabel(1,"All (PS)");
95   fHcuts->GetXaxis()->SetBinLabel(2,Form("%s: %.0f-%.0f",fCentVar.Data(),fCentFrom,fCentTo));
96   fHcuts->GetXaxis()->SetBinLabel(3,"QFlag");
97   fHcuts->GetXaxis()->SetBinLabel(4,Form("zvtx: %.0f-%.0f",fVtxZMin,fVtxZMax));
98   fOutput->Add(fHcuts);
99   fHvertexZ = new TH1F("hVertexZBeforeCuts",";z [cm];",100,-25,25);
100   fOutput->Add(fHvertexZ);
101   fHcent = new TH1F("hCentBeforeCuts",Form(";%s;",fCentVar.Data()),101,-1,100);
102   fOutput->Add(fHcent);
103
104   PostData(1, fOutput); 
105 }
106
107 //________________________________________________________________________
108 void AliAnalysisTaskEMCALPi0PbPb::UserExec(Option_t *) 
109 {
110   // Called for each event.
111
112   if (!InputEvent())
113     return;
114
115   AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
116   fEsdEv = dynamic_cast<AliESDEvent*>(InputEvent());
117   if (fEsdEv) {
118     am->LoadBranch("AliESDRun.");
119     am->LoadBranch("AliESDHeader.");
120   } else {
121     fAodEv = dynamic_cast<AliAODEvent*>(InputEvent());
122     am->LoadBranch("header");
123   }
124
125   Int_t cut = 1;
126   fHcuts->Fill(cut++);
127
128   const AliCentrality *centP = InputEvent()->GetCentrality();
129   Double_t cent = centP->GetCentralityPercentileUnchecked(fCentVar);
130   fHcent->Fill(cent);
131   if (cent<fCentFrom||cent>fCentTo)
132     return;
133
134   fHcuts->Fill(cut++);
135   
136   if (fUseQualFlag) {
137     if (centP->GetQuality()>0)
138       return;
139   }
140
141   fHcuts->Fill(cut++);
142
143   if (fEsdEv) {
144     am->LoadBranch("PrimaryVertex");
145   } else {
146     fAodEv = dynamic_cast<AliAODEvent*>(InputEvent());
147     am->LoadBranch("vertices");
148   }
149
150   const AliVVertex *vertex = InputEvent()->GetPrimaryVertex();
151   if (!vertex)
152     return;
153
154   fHvertexZ->Fill(vertex->GetZ());
155
156   if(vertex->GetZ()<fVtxZMin||vertex->GetZ()>fVtxZMax)
157     return;
158
159   fHcuts->Fill(cut++);
160
161   fRecPoints   = 0; // will be set if fClusName is given and AliAnalysisTaskEMCALClusterizeFast is used
162   fEsdClusters = 0; // will be set if ESD input used and if fRecPoints are not set of if clusters are attached
163   fEsdCells    = 0; // will be set if ESD input used
164   fAodClusters = 0; // will be set if AOD input used and if fRecPoints are not set of if clusters are attached
165                     //             or if fClusName is given and AliAnalysisTaskEMCALClusterizeFast in AOD output mode
166   fAodCells    = 0; // will be set if AOD input used
167
168   // deal with special output from AliAnalysisTaskEMCALClusterizeFast first
169   Bool_t clusattached = 0;
170   Bool_t recalibrated = 0;
171   if (1 && !fClusName.IsNull()) {
172     AliAnalysisTaskEMCALClusterizeFast *cltask = 0;
173     TObjArray *ts = am->GetTasks();
174     cltask = dynamic_cast<AliAnalysisTaskEMCALClusterizeFast*>(ts->FindObject(fClusName));
175     if (cltask && cltask->GetClusters()) {
176       fRecPoints = cltask->GetClusters();
177       clusattached = cltask->GetAttachClusters();
178       if (cltask->GetCalibData()!=0)
179         recalibrated = kTRUE;
180     }
181   }
182   if (1 && AODEvent() && !fClusName.IsNull()) {
183     TList *l = AODEvent()->GetList();
184     TClonesArray *clus = 0;
185     if (l) {
186       clus = dynamic_cast<TClonesArray*>(l->FindObject(fClusName));
187       fAodClusters = clus;
188     }
189   }
190
191   if (fEsdEv) { // ESD input mode
192     if (1 && (!fRecPoints||clusattached)) {
193       if (!clusattached)
194         am->LoadBranch("CaloClusters");
195       TList *l = fEsdEv->GetList();
196       TClonesArray *clus = 0;
197       if (l) {
198         clus = dynamic_cast<TClonesArray*>(l->FindObject("CaloClusters"));
199         fEsdClusters = clus;
200       }
201     }
202     if (1) {
203       if (!recalibrated)
204         am->LoadBranch("EMCALCells.");
205       fEsdCells = fEsdEv->GetEMCALCells();
206     }
207   } else if (fAodEv) { // AOD input mode
208     if (1 && (!fAodClusters || clusattached)) {
209       if (!clusattached)
210         am->LoadBranch("caloClusters");
211       TList *l = fAodEv->GetList();
212       TClonesArray *clus = 0;
213       if (l) {
214         clus = dynamic_cast<TClonesArray*>(l->FindObject("caloClusters"));
215         fAodClusters = clus;
216       }
217     }
218     if (1) {
219       if (!recalibrated)
220         am->LoadBranch("emcalCells");
221       fAodCells = fAodEv->GetEMCALCells();
222     }
223   } else {
224     AliFatal("Impossible to not have either pointer to ESD or AOD event");
225   }
226
227   if (1) {
228     AliDebug(2,Form("fRecPoints   set: %p", fRecPoints));
229     AliDebug(2,Form("fEsdClusters set: %p", fEsdClusters));
230     AliDebug(2,Form("fEsdCells    set: %p", fEsdCells));
231     AliDebug(2,Form("fAodClusters set: %p", fAodClusters));
232     AliDebug(2,Form("fAodCells    set: %p", fAodCells));
233   }
234
235   FillCellHists();
236   FillClusHists();
237   FillPionHists();
238
239   PostData(1, fOutput);
240 }      
241
242 //________________________________________________________________________
243 void AliAnalysisTaskEMCALPi0PbPb::Terminate(Option_t *) 
244 {
245   // Terminate called at the end of analysis.
246 }
247
248 //________________________________________________________________________
249 void AliAnalysisTaskEMCALPi0PbPb::FillCellHists()
250 {
251   // Fill histograms related to cell properties.
252 }
253
254 //________________________________________________________________________
255 void AliAnalysisTaskEMCALPi0PbPb::FillClusHists()
256 {
257   // Fill histograms related to cluster properties.
258 }
259
260 //________________________________________________________________________
261 void AliAnalysisTaskEMCALPi0PbPb::FillPionHists()
262 {
263   // Fill histograms related to pions.
264 }
265