]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/AliForwardMultiplicityTask.cxx
Various upgrades. NSD true trigger for MC, pileup selection for analysis, fixes for...
[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(),
fffea31d 37 fEventInspector(),
38 fEnergyFitter(),
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),
fffea31d 57 fEventInspector("event"),
58 fEnergyFitter("energy"),
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),
fffea31d 81 fEventInspector(o.fEventInspector),
82 fEnergyFitter(o.fEnergyFitter),
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;
115 fEnergyFitter = o.fEnergyFitter;
7e4038b5 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;
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);
138 fEnergyFitter.SetDebug(dbg);
139 fSharingFilter.SetDebug(dbg);
140 fDensityCalculator.SetDebug(dbg);
141 fCorrections.SetDebug(dbg);
142 fHistCollector.SetDebug(dbg);
143}
144
7e4038b5 145//____________________________________________________________________
146void
0bd4b00f 147AliForwardMultiplicityTask::InitializeSubs()
7e4038b5 148{
7984e5f7 149 //
150 // Initialise the sub objects and stuff. Called on first event
151 //
152 //
7ec4d843 153 const TAxis* pe = 0;
154 const TAxis* pv = 0;
0bd4b00f 155
7ec4d843 156 if (!ReadCorrections(pe,pv)) return;
fffea31d 157
0bd4b00f 158 fHistos.Init(*pe);
159 fAODFMD.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
0bd4b00f 166 fEnergyFitter.Init(*pe);
167 fEventInspector.Init(*pv);
1174780f 168 fDensityCalculator.Init(*pe);
7ec4d843 169 fCorrections.Init(*pe);
0bd4b00f 170 fHistCollector.Init(*pv);
171
172 this->Print();
7e4038b5 173}
174
175//____________________________________________________________________
176void
0bd4b00f 177AliForwardMultiplicityTask::UserCreateOutputObjects()
7e4038b5 178{
7984e5f7 179 //
180 // Create output objects
181 //
182 //
7e4038b5 183 fList = new TList;
184
185 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
0bd4b00f 186 AliAODHandler* ah =
187 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
fffea31d 188 if (!ah) AliFatal("No AOD output handler set in analysis manager");
7e4038b5 189
190
191 TObject* obj = &fAODFMD;
192 ah->AddBranch("AliAODForwardMult", &obj);
193
fffea31d 194 fEventInspector.DefineOutput(fList);
195 fEnergyFitter.DefineOutput(fList);
9d99b0dd 196 fSharingFilter.DefineOutput(fList);
197 fDensityCalculator.DefineOutput(fList);
198 fCorrections.DefineOutput(fList);
0bd4b00f 199
200 PostData(1, fList);
7e4038b5 201}
202//____________________________________________________________________
203void
0bd4b00f 204AliForwardMultiplicityTask::UserExec(Option_t*)
7e4038b5 205{
7984e5f7 206 //
207 // Process each event
208 //
209 // Parameters:
210 // option Not used
211 //
212
0bd4b00f 213 // static Int_t cnt = 0;
214 // cnt++;
7e4038b5 215 // Get the input data
7ec4d843 216 AliESDEvent* esd = GetESDEvent();
7e4038b5 217
7e4038b5 218 // Clear stuff
219 fHistos.Clear();
220 fESDFMD.Clear();
221 fAODFMD.Clear();
e58000b7 222
fffea31d 223 Bool_t lowFlux = kFALSE;
224 UInt_t triggers = 0;
0bd4b00f 225 UShort_t ivz = 0;
fffea31d 226 Double_t vz = 0;
5e4d905e 227 Double_t cent = -1;
228 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux,
229 ivz, vz, cent);
e58000b7 230
9bff843b 231 if (found & AliFMDEventInspector::kNoEvent) return;
232 if (found & AliFMDEventInspector::kNoTriggers) return;
233
fffea31d 234 // Set trigger bits, and mark this event for storage
9d99b0dd 235 fAODFMD.SetTriggerBits(triggers);
b2e7f2d6 236 fAODFMD.SetSNN(fEventInspector.GetEnergy());
237 fAODFMD.SetSystem(fEventInspector.GetCollisionSystem());
e58000b7 238 fAODFMD.SetCentrality(cent);
7e4038b5 239 MarkEventForStore();
e58000b7 240
3c5497d0 241 if (found & AliFMDEventInspector::kNoSPD) return;
242 if (found & AliFMDEventInspector::kNoFMD) return;
243 if (found & AliFMDEventInspector::kNoVertex) return;
e58000b7 244
245 if (triggers & AliAODForwardMult::kPileUp) return;
246
fffea31d 247 fAODFMD.SetIpZ(vz);
7e4038b5 248
fffea31d 249 if (found & AliFMDEventInspector::kBadVertex) return;
7e4038b5 250
0bd4b00f 251 // We we do not want to use low flux specific code, we disable it here.
252 if (!fEnableLowFlux) lowFlux = false;
253
fffea31d 254 // Get FMD data
255 AliESDFMD* esdFMD = esd->GetFMDData();
256 // Apply the sharing filter (or hit merging or clustering if you like)
257 if (!fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD)) {
258 AliWarning("Sharing filter failed!");
7e4038b5 259 return;
260 }
261
fffea31d 262 // Do the energy stuff
5e4d905e 263 if (!fEnergyFitter.Accumulate(*esdFMD, cent,
264 triggers & AliAODForwardMult::kEmpty)){
fffea31d 265 AliWarning("Energy fitter failed");
7e4038b5 266 return;
267 }
268
269 // Calculate the inclusive charged particle density
270 if (!fDensityCalculator.Calculate(fESDFMD, fHistos, ivz, lowFlux)) {
271 AliWarning("Density calculator failed!");
272 return;
273 }
274
275 // Do the secondary and other corrections.
276 if (!fCorrections.Correct(fHistos, ivz)) {
277 AliWarning("Corrections failed");
278 return;
279 }
280
281 if (!fHistCollector.Collect(fHistos, ivz, fAODFMD.GetHistogram())) {
282 AliWarning("Histogram collector failed");
283 return;
284 }
285
286 if (fAODFMD.IsTriggerBits(AliAODForwardMult::kInel))
287 fHData->Add(&(fAODFMD.GetHistogram()));
2d68d438 288
289 PostData(1, fList);
7e4038b5 290}
291
292//____________________________________________________________________
293void
0bd4b00f 294AliForwardMultiplicityTask::Terminate(Option_t*)
7e4038b5 295{
7984e5f7 296 //
297 // End of job
298 //
299 // Parameters:
300 // option Not used
301 //
302
7e4038b5 303 TList* list = dynamic_cast<TList*>(GetOutputData(1));
304 if (!list) {
2d68d438 305 AliError(Form("No output list defined (%p)", GetOutputData(1)));
306 if (GetOutputData(1)) GetOutputData(1)->Print();
7e4038b5 307 return;
308 }
9d99b0dd 309
310 // Get our histograms from the container
fffea31d 311 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
312 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
313 TH1I* hTriggers = 0;
314 if (!fEventInspector.FetchHistograms(list, hEventsTr,
315 hEventsTrVtx, hTriggers)) {
316 AliError(Form("Didn't get histograms from event selector "
317 "(hEventsTr=%p,hEventsTrVtx=%p)",
318 hEventsTr, hEventsTrVtx));
319 list->ls();
320 return;
321 }
322
9d99b0dd 323 TH2D* hData = static_cast<TH2D*>(list->FindObject("d2Ndetadphi"));
fffea31d 324 if (!hData) {
325 AliError(Form("Couldn't get our summed histogram from output "
326 "list %s (d2Ndetadphi=%p)", list->GetName(), hData));
2d68d438 327 list->ls();
328 return;
329 }
9d99b0dd 330
7e4038b5 331 // TH1D* dNdeta = fHData->ProjectionX("dNdeta", 0, -1, "e");
9d99b0dd 332 TH1D* dNdeta = hData->ProjectionX("dNdeta", 1, -1, "e");
0bd4b00f 333 TH1D* norm = hData->ProjectionX("norm", 0, 1, "");
7e4038b5 334 dNdeta->SetTitle("dN_{ch}/d#eta in the forward regions");
335 dNdeta->SetYTitle("#frac{1}{N}#frac{dN_{ch}}{d#eta}");
336 dNdeta->Divide(norm);
337 dNdeta->SetStats(0);
9d99b0dd 338 dNdeta->Scale(Double_t(hEventsTrVtx->GetEntries())/hEventsTr->GetEntries(),
7e4038b5 339 "width");
7e4038b5 340 list->Add(dNdeta);
0bd4b00f 341 list->Add(norm);
fffea31d 342
343 fEnergyFitter.Fit(list);
6feacd76 344 fSharingFilter.ScaleHistograms(list,Int_t(hEventsTr->Integral()));
345 fDensityCalculator.ScaleHistograms(list,Int_t(hEventsTrVtx->Integral()));
346 fCorrections.ScaleHistograms(list,Int_t(hEventsTrVtx->Integral()));
7e4038b5 347}
7e4038b5 348
349//
350// EOF
351//