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