]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/AliForwardMultiplicityTask.cxx
Added 2012 geom
[u/mrichter/AliRoot.git] / PWGLF / 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     fRingSums(),
38     fEventInspector(),
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     fRingSums(),
58     fEventInspector("event"),
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     fRingSums(o.fRingSums),
82     fEventInspector(o.fEventInspector),
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   if (&o == this) return *this;
112   AliForwardMultiplicityBase::operator=(o);
113
114   fHData             = o.fHData;
115   fEventInspector    = o.fEventInspector;
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   fRingSums          = o.fRingSums;
123   fList              = o.fList;
124
125   return *this;
126 }
127
128 //____________________________________________________________________
129 void
130 AliForwardMultiplicityTask::SetDebug(Int_t dbg)
131 {
132   // 
133   // Set debug level 
134   // 
135   // Parameters:
136   //    dbg Debug level
137   //
138   fEventInspector.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   fRingSums.Init(*pe);
161
162   fHData = static_cast<TH2D*>(fAODFMD.GetHistogram().Clone("d2Ndetadphi"));
163   fHData->SetStats(0);
164   fHData->SetDirectory(0);
165   fList->Add(fHData);
166
167   TList* rings = new TList;
168   rings->SetName("ringSums");
169   rings->SetOwner();
170   fList->Add(rings);
171
172   rings->Add(fRingSums.Get(1, 'I'));
173   rings->Add(fRingSums.Get(2, 'I'));
174   rings->Add(fRingSums.Get(2, 'O'));
175   rings->Add(fRingSums.Get(3, 'I'));
176   rings->Add(fRingSums.Get(3, 'O'));
177   fRingSums.Get(1, 'I')->SetMarkerColor(AliForwardUtil::RingColor(1, 'I'));
178   fRingSums.Get(2, 'I')->SetMarkerColor(AliForwardUtil::RingColor(2, 'I'));
179   fRingSums.Get(2, 'O')->SetMarkerColor(AliForwardUtil::RingColor(2, 'O'));
180   fRingSums.Get(3, 'I')->SetMarkerColor(AliForwardUtil::RingColor(3, 'I'));
181   fRingSums.Get(3, 'O')->SetMarkerColor(AliForwardUtil::RingColor(3, 'O'));
182
183   fEventInspector.Init(*pv);
184   fSharingFilter.Init();
185   fDensityCalculator.Init(*pe);
186   fCorrections.Init(*pe);
187   fHistCollector.Init(*pv,*pe);
188
189   this->Print();
190 }
191
192 //____________________________________________________________________
193 void
194 AliForwardMultiplicityTask::UserCreateOutputObjects()
195 {
196   // 
197   // Create output objects 
198   // 
199   //
200   fList = new TList;
201   fList->SetOwner();
202
203   AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
204   AliAODHandler*      ah = 
205     dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
206   if (!ah) AliFatal("No AOD output handler set in analysis manager");
207     
208     
209   TObject* obj = &fAODFMD;
210   ah->AddBranch("AliAODForwardMult", &obj);
211
212   fEventInspector.DefineOutput(fList);
213   fSharingFilter.DefineOutput(fList);
214   fDensityCalculator.DefineOutput(fList);
215   fCorrections.DefineOutput(fList);
216   fHistCollector.DefineOutput(fList);
217
218   PostData(1, fList);
219 }
220 //____________________________________________________________________
221 void
222 AliForwardMultiplicityTask::UserExec(Option_t*)
223 {
224   // 
225   // Process each event 
226   // 
227   // Parameters:
228   //    option Not used
229   //  
230
231   // static Int_t cnt = 0;
232   // cnt++;
233   // Get the input data 
234   AliESDEvent* esd = GetESDEvent();
235
236   // Clear stuff 
237   fHistos.Clear();
238   fESDFMD.Clear();
239   fAODFMD.Clear();
240   
241   Bool_t   lowFlux   = kFALSE;
242   UInt_t   triggers  = 0;
243   UShort_t ivz       = 0;
244   Double_t vz        = 0;
245   Double_t cent      = -1;
246   UShort_t nClusters = 0;
247   UInt_t   found     = fEventInspector.Process(esd, triggers, lowFlux, 
248                                                ivz, vz, cent, nClusters);
249   
250   if (found & AliFMDEventInspector::kNoEvent)    return;
251   if (found & AliFMDEventInspector::kNoTriggers) return;
252
253   // Set trigger bits, and mark this event for storage 
254   fAODFMD.SetTriggerBits(triggers);
255   fAODFMD.SetSNN(fEventInspector.GetEnergy());
256   fAODFMD.SetSystem(fEventInspector.GetCollisionSystem());
257   fAODFMD.SetCentrality(cent);
258   fAODFMD.SetNClusters(nClusters);
259   MarkEventForStore();
260   
261   if (found & AliFMDEventInspector::kNoSPD)      return;
262   if (found & AliFMDEventInspector::kNoFMD)      return;
263   if (found & AliFMDEventInspector::kNoVertex)   return;
264   
265   if (triggers & AliAODForwardMult::kPileUp) return;
266   
267   fAODFMD.SetIpZ(vz);
268
269   if (found & AliFMDEventInspector::kBadVertex) return;
270
271   // We we do not want to use low flux specific code, we disable it here. 
272   if (!fEnableLowFlux) lowFlux = false;
273
274   // Get FMD data 
275   AliESDFMD* esdFMD = esd->GetFMDData();
276   //  // Apply the sharing filter (or hit merging or clustering if you like)
277   if (!fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD)) { 
278     AliWarning("Sharing filter failed!");
279     return;
280   }
281
282   // Calculate the inclusive charged particle density 
283   if (!fDensityCalculator.Calculate(fESDFMD, fHistos, ivz, lowFlux, cent)) { 
284     // if (!fDensityCalculator.Calculate(*esdFMD, fHistos, ivz, lowFlux)) { 
285     AliWarning("Density calculator failed!");
286     return;
287   }
288   
289   // Do the secondary and other corrections. 
290   if (!fCorrections.Correct(fHistos, ivz)) { 
291     AliWarning("Corrections failed");
292     return;
293   }
294
295   if (!fHistCollector.Collect(fHistos, fRingSums, 
296                               ivz, fAODFMD.GetHistogram())) {
297     AliWarning("Histogram collector failed");
298     return;
299   }
300
301   if (fAODFMD.IsTriggerBits(AliAODForwardMult::kInel))
302     fHData->Add(&(fAODFMD.GetHistogram()));
303
304   PostData(1, fList);
305 }
306
307 //____________________________________________________________________
308 void
309 AliForwardMultiplicityTask::Terminate(Option_t*)
310 {
311   // 
312   // End of job
313   // 
314   // Parameters:
315   //    option Not used 
316   //
317
318   TList* list = dynamic_cast<TList*>(GetOutputData(1));
319   if (!list) {
320     AliError(Form("No output list defined (%p)", GetOutputData(1)));
321     if (GetOutputData(1)) GetOutputData(1)->Print();
322     return;
323   }
324   
325   // Get our histograms from the container 
326   TH1I* hEventsTr    = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
327   TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
328   TH1I* hTriggers    = 0;
329   if (!fEventInspector.FetchHistograms(list, hEventsTr, 
330                                        hEventsTrVtx, hTriggers)) { 
331     AliError(Form("Didn't get histograms from event selector "
332                   "(hEventsTr=%p,hEventsTrVtx=%p)", 
333                   hEventsTr, hEventsTrVtx));
334     list->ls();
335     return;
336   }
337
338   TH2D* hData        = static_cast<TH2D*>(list->FindObject("d2Ndetadphi"));
339   if (!hData) { 
340     AliError(Form("Couldn't get our summed histogram from output "
341                   "list %s (d2Ndetadphi=%p)", list->GetName(), hData));
342     list->ls();
343     return;
344   }
345   
346   // TH1D* dNdeta = fHData->ProjectionX("dNdeta", 0, -1, "e");
347   TH1D* dNdeta = hData->ProjectionX("dNdeta", 1, -1, "e");
348   TH1D* norm   = hData->ProjectionX("norm",   0,  0,  "");
349   dNdeta->SetTitle("dN_{ch}/d#eta in the forward regions");
350   dNdeta->SetYTitle("#frac{1}{N}#frac{dN_{ch}}{d#eta}");
351   dNdeta->Divide(norm);
352   dNdeta->SetStats(0);
353   dNdeta->Scale(Double_t(hEventsTrVtx->GetEntries())/hEventsTr->GetEntries(),
354                 "width");
355   list->Add(dNdeta);
356   list->Add(norm);
357
358   MakeRingdNdeta(list, "ringSums", list, "ringResults");
359
360   fSharingFilter.ScaleHistograms(list,Int_t(hEventsTr->Integral()));
361   fDensityCalculator.ScaleHistograms(list,Int_t(hEventsTrVtx->Integral()));
362   fCorrections.ScaleHistograms(list,Int_t(hEventsTrVtx->Integral()));
363 }
364
365 //
366 // EOF
367 //