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