]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/AliForwarddNdetaTask.cxx
Renamed script to add Central AOD task from
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliForwarddNdetaTask.cxx
1 //====================================================================
2 #include "AliForwarddNdetaTask.h"
3 #include <TMath.h>
4 #include <TH2D.h>
5 #include <TH1D.h>
6 #include <THStack.h>
7 #include <TList.h>
8 #include <AliAnalysisManager.h>
9 #include <AliAODEvent.h>
10 #include <AliAODHandler.h>
11 #include <AliAODInputHandler.h>
12 #include "AliForwardUtil.h"
13 #include "AliAODForwardMult.h"
14
15 //____________________________________________________________________
16 AliForwarddNdetaTask::AliForwarddNdetaTask()
17   : AliBasedNdetaTask()
18 {
19   //
20   // Constructor 
21   // 
22 }
23
24 //____________________________________________________________________
25 AliForwarddNdetaTask::AliForwarddNdetaTask(const char* /* name */)
26   : AliBasedNdetaTask("Forward")
27 {
28   // 
29   // Constructor
30   // 
31   // Paramters
32   //   name    Name of task 
33 }
34
35 //____________________________________________________________________
36 AliForwarddNdetaTask::AliForwarddNdetaTask(const AliForwarddNdetaTask& o)
37   : AliBasedNdetaTask(o)
38 {
39   // 
40   // Copy constructor
41   // 
42 }
43
44 //____________________________________________________________________
45 AliBasedNdetaTask::CentralityBin*
46 AliForwarddNdetaTask::MakeCentralityBin(const char* name, Short_t l, Short_t h) 
47   const 
48 {
49   // 
50   // Make a new centrality bin
51   // 
52   // Parameters:
53   //    name   Histogram names
54   //    l      Lower cut
55   //    h      Upper cut
56   // 
57   // Return:
58   //    Newly allocated object (of our type)
59   //
60   return new AliForwarddNdetaTask::CentralityBin(name, l, h);
61 }
62
63 //____________________________________________________________________
64 void
65 AliForwarddNdetaTask::UserExec(Option_t* option)
66 {
67   // 
68   // Called at each event 
69   //
70   // This is called once in the master 
71   // 
72   // Parameters:
73   //    option Not used 
74   //
75   AliBasedNdetaTask::UserExec(option);
76   
77   AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
78   if (!aod) {
79     AliError("Cannot get the AOD event");
80     return;
81   } 
82
83   TObject* obj = aod->FindListObject("Forward");
84   if (!obj) { 
85     AliWarning("No forward object found");
86     return;
87   }
88   AliAODForwardMult* forward = static_cast<AliAODForwardMult*>(obj);
89  
90   TObject* oPrimary   = aod->FindListObject("primary");
91   if (!oPrimary) return;
92   
93   TH2D* primary   = static_cast<TH2D*>(oPrimary);
94
95   // Loop over centrality bins 
96   TIter next(fListOfCentralities);
97   CentralityBin* bin = 0;
98   while ((bin = static_cast<CentralityBin*>(next()))) 
99     bin->ProcessPrimary(forward, fTriggerMask, fVtxMin, fVtxMax, primary);
100 }  
101   
102
103 //____________________________________________________________________
104 TH2D*
105 AliForwarddNdetaTask::GetHistogram(const AliAODEvent* aod, Bool_t mc)
106 {
107   // 
108   // Retrieve the histogram 
109   // 
110   // Parameters:
111   //    aod AOD event 
112   //    mc  Whether to get the MC histogram or not
113   // 
114   // Return:
115   //    Retrieved histogram or null
116   //
117   TObject* obj = 0;
118   if (mc) obj = aod->FindListObject("ForwardMC");
119   else    obj = aod->FindListObject("Forward");
120
121   // We should have a forward object at least 
122   if (!obj) {
123     if (!mc) AliWarning("No Forward object found AOD");
124     return 0;
125   }
126   AliAODForwardMult* forward = static_cast<AliAODForwardMult*>(obj);
127   return &(forward->GetHistogram());
128 }
129
130 //========================================================================
131 void
132 AliForwarddNdetaTask::CentralityBin::ProcessPrimary(const AliAODForwardMult* 
133                                                     forward, 
134                                                     Int_t triggerMask,
135                                                     Double_t vzMin, 
136                                                     Double_t vzMax, 
137                                                     const TH2D* primary)
138
139   // Check the centrality class unless this is the 'all' bin 
140   if (!IsAllBin()) { 
141     Double_t centrality = forward->GetCentrality();
142     if (centrality < fLow || centrality >= fHigh) return;
143   }
144   
145   if (!fSumPrimary) { 
146     fSumPrimary = static_cast<TH2D*>(primary->Clone("truth"));
147     fSumPrimary->SetDirectory(0);
148     fSumPrimary->Reset();
149     fSums->Add(fSumPrimary);
150   }
151   if (triggerMask == AliAODForwardMult::kInel ||
152       (triggerMask == AliAODForwardMult::kNSD && 
153        forward->IsTriggerBits(AliAODForwardMult::kMCNSD)))
154     fSumPrimary->Add(primary);
155   
156   // Check if we have an event of interest. 
157   if (!forward->IsTriggerBits(triggerMask)) return;
158   
159   //Check for pileup
160   if (forward->IsTriggerBits(AliAODForwardMult::kPileUp)) return;
161   
162   // Check that we have a valid vertex
163   if (!forward->HasIpZ()) return;
164
165   // Check that vertex is within cuts 
166   if (!forward->InRange(vzMin, vzMax)) return;
167
168   
169   
170 }
171
172 //________________________________________________________________________
173 void
174 AliForwarddNdetaTask::CentralityBin::End(TList*      sums, 
175                                          TList*      results,
176                                          UShort_t    scheme,
177                                          const TH1*  shapeCorr, 
178                                          Double_t    trigEff,
179                                          Bool_t      symmetrice,
180                                          Int_t       rebin, 
181                                          Bool_t      corrEmpty, 
182                                          Bool_t      cutEdges, 
183                                          Double_t    vzMin, 
184                                          Double_t    vzMax, 
185                                          Int_t       triggerMask,
186                                          Int_t       color,
187                                          Int_t       marker)
188 {
189   AliBasedNdetaTask::CentralityBin::End(sums, results, scheme, 
190                                         shapeCorr, trigEff, 
191                                         symmetrice, rebin, corrEmpty, cutEdges,
192                                         vzMin, vzMax, triggerMask,
193                                         color, marker);
194
195   fSumPrimary     = static_cast<TH2D*>(fSums->FindObject("truth"));
196
197   if (!fSumPrimary) return;
198   Int_t n = (triggerMask == AliAODForwardMult::kNSD ? 
199              Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinMCNSD)) : 
200              Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinAll)));
201
202     
203   TH1D* dndetaTruth = fSumPrimary->ProjectionX("dndetaTruth",1,
204                                                fSumPrimary->GetNbinsY(),"e");
205   dndetaTruth->Scale(1./n, "width");
206
207   SetHistogramAttributes(dndetaTruth, color-2, marker+4, "Monte-Carlo truth");
208     
209   fOutput->Add(dndetaTruth);
210   fOutput->Add(Rebin(dndetaTruth, rebin, cutEdges));
211 }
212
213 //________________________________________________________________________
214 //
215 // EOF
216 //