]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/AliForwardMultiplicityTask.cxx
Code clean-up in dN/deta calculation.
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliForwardMultiplicityTask.cxx
1 // 
2 // Calculate the multiplicity in the forward regions event-by-event 
3 // 
4 // Inputs: 
5 //   - AliESDEvent 
6 //
7 // Outputs: 
8 //   - AliAODForwardMult 
9 // 
10 // Histograms 
11 //   
12 // Corrections used 
13 //
14 #include "AliForwardMultiplicityTask.h"
15 #include "AliTriggerAnalysis.h"
16 #include "AliPhysicsSelection.h"
17 #include "AliLog.h"
18 #include "AliESDEvent.h"
19 #include "AliAODHandler.h"
20 #include "AliMultiplicity.h"
21 #include "AliInputEventHandler.h"
22 #include "AliForwardCorrectionManager.h"
23 #include "AliAnalysisManager.h"
24 #include <TH1.h>
25 #include <TDirectory.h>
26 #include <TTree.h>
27 #include <TROOT.h>
28
29
30 //====================================================================
31 AliForwardMultiplicityTask::AliForwardMultiplicityTask()
32   : AliForwardMultiplicityBase(),
33     fHData(0),
34     fESDFMD(),
35     fHistos(),
36     fAODFMD(),
37     fEventInspector(),
38     fSharingFilter(),
39     fDensityCalculator(),
40     fCorrections(),
41     fHistCollector(),
42     fList(0)
43 {
44   // 
45   // Constructor
46   //
47 }
48
49 //____________________________________________________________________
50 AliForwardMultiplicityTask::AliForwardMultiplicityTask(const char* name)
51   : AliForwardMultiplicityBase(name),
52     fHData(0),
53     fESDFMD(),
54     fHistos(),
55     fAODFMD(false),
56     fEventInspector("event"),
57     fSharingFilter("sharing"), 
58     fDensityCalculator("density"),
59     fCorrections("corrections"),
60     fHistCollector("collector"),
61     fList(0)
62 {
63   // 
64   // Constructor 
65   // 
66   // Parameters:
67   //    name Name of task 
68   //
69   DefineOutput(1, TList::Class());
70 }
71
72 //____________________________________________________________________
73 AliForwardMultiplicityTask::AliForwardMultiplicityTask(const AliForwardMultiplicityTask& o)
74   : AliForwardMultiplicityBase(o),
75     fHData(o.fHData),
76     fESDFMD(o.fESDFMD),
77     fHistos(o.fHistos),
78     fAODFMD(o.fAODFMD),
79     fEventInspector(o.fEventInspector),
80     fSharingFilter(o.fSharingFilter),
81     fDensityCalculator(o.fDensityCalculator),
82     fCorrections(o.fCorrections),
83     fHistCollector(o.fHistCollector),
84     fList(o.fList) 
85 {
86   // 
87   // Copy constructor 
88   // 
89   // Parameters:
90   //    o Object to copy from 
91   //
92   DefineOutput(1, TList::Class());
93 }
94
95 //____________________________________________________________________
96 AliForwardMultiplicityTask&
97 AliForwardMultiplicityTask::operator=(const AliForwardMultiplicityTask& o)
98 {
99   // 
100   // Assignment operator 
101   // 
102   // Parameters:
103   //    o Object to assign from 
104   // 
105   // Return:
106   //    Reference to this object 
107   //
108   AliForwardMultiplicityBase::operator=(o);
109
110   fHData             = o.fHData;
111   fEventInspector    = o.fEventInspector;
112   fSharingFilter     = o.fSharingFilter;
113   fDensityCalculator = o.fDensityCalculator;
114   fCorrections       = o.fCorrections;
115   fHistCollector     = o.fHistCollector;
116   fHistos            = o.fHistos;
117   fAODFMD            = o.fAODFMD;
118   fList              = o.fList;
119
120   return *this;
121 }
122
123 //____________________________________________________________________
124 void
125 AliForwardMultiplicityTask::SetDebug(Int_t dbg)
126 {
127   // 
128   // Set debug level 
129   // 
130   // Parameters:
131   //    dbg Debug level
132   //
133   fEventInspector.SetDebug(dbg);
134   fSharingFilter.SetDebug(dbg);
135   fDensityCalculator.SetDebug(dbg);
136   fCorrections.SetDebug(dbg);
137   fHistCollector.SetDebug(dbg);
138 }
139
140 //____________________________________________________________________
141 void
142 AliForwardMultiplicityTask::InitializeSubs()
143 {
144   // 
145   // Initialise the sub objects and stuff.  Called on first event 
146   // 
147   //
148   const TAxis* pe = 0;
149   const TAxis* pv = 0;
150
151   if (!ReadCorrections(pe,pv)) return;
152
153   fHistos.Init(*pe);
154   fAODFMD.Init(*pe);
155
156   fHData = static_cast<TH2D*>(fAODFMD.GetHistogram().Clone("d2Ndetadphi"));
157   fHData->SetStats(0);
158   fHData->SetDirectory(0);
159   fList->Add(fHData);
160
161   fEventInspector.Init(*pv);
162   fDensityCalculator.Init(*pe);
163   fCorrections.Init(*pe);
164   fHistCollector.Init(*pv,*pe);
165
166   this->Print();
167 }
168
169 //____________________________________________________________________
170 void
171 AliForwardMultiplicityTask::UserCreateOutputObjects()
172 {
173   // 
174   // Create output objects 
175   // 
176   //
177   fList = new TList;
178   fList->SetOwner();
179
180   AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
181   AliAODHandler*      ah = 
182     dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
183   if (!ah) AliFatal("No AOD output handler set in analysis manager");
184     
185     
186   TObject* obj = &fAODFMD;
187   ah->AddBranch("AliAODForwardMult", &obj);
188
189   fEventInspector.DefineOutput(fList);
190   fSharingFilter.DefineOutput(fList);
191   fDensityCalculator.DefineOutput(fList);
192   fCorrections.DefineOutput(fList);
193   fHistCollector.DefineOutput(fList);
194
195   PostData(1, fList);
196 }
197 //____________________________________________________________________
198 void
199 AliForwardMultiplicityTask::UserExec(Option_t*)
200 {
201   // 
202   // Process each event 
203   // 
204   // Parameters:
205   //    option Not used
206   //  
207
208   // static Int_t cnt = 0;
209   // cnt++;
210   // Get the input data 
211   AliESDEvent* esd = GetESDEvent();
212
213   // Clear stuff 
214   fHistos.Clear();
215   fESDFMD.Clear();
216   fAODFMD.Clear();
217   
218   Bool_t   lowFlux  = kFALSE;
219   UInt_t   triggers = 0;
220   UShort_t ivz      = 0;
221   Double_t vz       = 0;
222   Double_t cent     = -1;
223   UInt_t   found    = fEventInspector.Process(esd, triggers, lowFlux, 
224                                               ivz, vz, cent);
225   
226   if (found & AliFMDEventInspector::kNoEvent)    return;
227   if (found & AliFMDEventInspector::kNoTriggers) return;
228
229   // Set trigger bits, and mark this event for storage 
230   fAODFMD.SetTriggerBits(triggers);
231   fAODFMD.SetSNN(fEventInspector.GetEnergy());
232   fAODFMD.SetSystem(fEventInspector.GetCollisionSystem());
233   fAODFMD.SetCentrality(cent);
234   MarkEventForStore();
235   
236   if (found & AliFMDEventInspector::kNoSPD)      return;
237   if (found & AliFMDEventInspector::kNoFMD)      return;
238   if (found & AliFMDEventInspector::kNoVertex)   return;
239   
240   if (triggers & AliAODForwardMult::kPileUp) return;
241   
242   fAODFMD.SetIpZ(vz);
243
244   if (found & AliFMDEventInspector::kBadVertex) return;
245
246   // We we do not want to use low flux specific code, we disable it here. 
247   if (!fEnableLowFlux) lowFlux = false;
248
249   // Get FMD data 
250   AliESDFMD* esdFMD = esd->GetFMDData();
251   //  // Apply the sharing filter (or hit merging or clustering if you like)
252   if (!fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD)) { 
253     AliWarning("Sharing filter failed!");
254     return;
255   }
256
257   // Calculate the inclusive charged particle density 
258   //if (!fDensityCalculator.Calculate(fESDFMD, fHistos, ivz, lowFlux)) { 
259   if (!fDensityCalculator.Calculate(*esdFMD, fHistos, ivz, lowFlux)) { 
260     AliWarning("Density calculator failed!");
261     return;
262   }
263   
264   // Do the secondary and other corrections. 
265   if (!fCorrections.Correct(fHistos, ivz)) { 
266     AliWarning("Corrections failed");
267     return;
268   }
269
270   if (!fHistCollector.Collect(fHistos, ivz, fAODFMD.GetHistogram())) {
271     AliWarning("Histogram collector failed");
272     return;
273   }
274
275   if (fAODFMD.IsTriggerBits(AliAODForwardMult::kInel))
276     fHData->Add(&(fAODFMD.GetHistogram()));
277
278   PostData(1, fList);
279 }
280
281 //____________________________________________________________________
282 void
283 AliForwardMultiplicityTask::Terminate(Option_t*)
284 {
285   // 
286   // End of job
287   // 
288   // Parameters:
289   //    option Not used 
290   //
291
292   TList* list = dynamic_cast<TList*>(GetOutputData(1));
293   if (!list) {
294     AliError(Form("No output list defined (%p)", GetOutputData(1)));
295     if (GetOutputData(1)) GetOutputData(1)->Print();
296     return;
297   }
298   
299   // Get our histograms from the container 
300   TH1I* hEventsTr    = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
301   TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
302   TH1I* hTriggers    = 0;
303   if (!fEventInspector.FetchHistograms(list, hEventsTr, 
304                                        hEventsTrVtx, hTriggers)) { 
305     AliError(Form("Didn't get histograms from event selector "
306                   "(hEventsTr=%p,hEventsTrVtx=%p)", 
307                   hEventsTr, hEventsTrVtx));
308     list->ls();
309     return;
310   }
311
312   TH2D* hData        = static_cast<TH2D*>(list->FindObject("d2Ndetadphi"));
313   if (!hData) { 
314     AliError(Form("Couldn't get our summed histogram from output "
315                   "list %s (d2Ndetadphi=%p)", list->GetName(), hData));
316     list->ls();
317     return;
318   }
319   
320   // TH1D* dNdeta = fHData->ProjectionX("dNdeta", 0, -1, "e");
321   TH1D* dNdeta = hData->ProjectionX("dNdeta", 1, -1, "e");
322   TH1D* norm   = hData->ProjectionX("norm",   0,  0,  "");
323   dNdeta->SetTitle("dN_{ch}/d#eta in the forward regions");
324   dNdeta->SetYTitle("#frac{1}{N}#frac{dN_{ch}}{d#eta}");
325   dNdeta->Divide(norm);
326   dNdeta->SetStats(0);
327   dNdeta->Scale(Double_t(hEventsTrVtx->GetEntries())/hEventsTr->GetEntries(),
328                 "width");
329   list->Add(dNdeta);
330   list->Add(norm);
331
332   fSharingFilter.ScaleHistograms(list,Int_t(hEventsTr->Integral()));
333   fDensityCalculator.ScaleHistograms(list,Int_t(hEventsTrVtx->Integral()));
334   fCorrections.ScaleHistograms(list,Int_t(hEventsTrVtx->Integral()));
335 }
336
337 //
338 // EOF
339 //