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