2 // Calculate the multiplicity in the forward regions event-by-event
10 // - AliAODForwardMult
16 #include "AliForwardMCMultiplicityTask.h"
17 #include "AliTriggerAnalysis.h"
18 #include "AliPhysicsSelection.h"
20 #include "AliESDEvent.h"
21 #include "AliAODHandler.h"
22 #include "AliMultiplicity.h"
23 #include "AliInputEventHandler.h"
24 #include "AliForwardCorrectionManager.h"
25 #include "AliAnalysisManager.h"
27 #include <TDirectory.h>
33 //====================================================================
34 AliForwardMCMultiplicityTask::AliForwardMCMultiplicityTask()
35 : AliForwardMultiplicityBase(),
57 //____________________________________________________________________
58 AliForwardMCMultiplicityTask::AliForwardMCMultiplicityTask(const char* name)
59 : AliForwardMultiplicityBase(name),
68 fEventInspector("event"),
69 fEnergyFitter("energy"),
70 fSharingFilter("sharing"),
71 fDensityCalculator("density"),
72 fCorrections("corrections"),
73 fHistCollector("collector"),
82 DefineOutput(1, TList::Class());
85 //____________________________________________________________________
86 AliForwardMCMultiplicityTask::AliForwardMCMultiplicityTask(const AliForwardMCMultiplicityTask& o)
87 : AliForwardMultiplicityBase(o),
92 fMCESDFMD(o.fMCESDFMD),
93 fMCHistos(o.fMCHistos),
94 fMCAODFMD(o.fMCAODFMD),
96 fEventInspector(o.fEventInspector),
97 fEnergyFitter(o.fEnergyFitter),
98 fSharingFilter(o.fSharingFilter),
99 fDensityCalculator(o.fDensityCalculator),
100 fCorrections(o.fCorrections),
101 fHistCollector(o.fHistCollector),
108 // o Object to copy from
110 DefineOutput(1, TList::Class());
113 //____________________________________________________________________
114 AliForwardMCMultiplicityTask&
115 AliForwardMCMultiplicityTask::operator=(const AliForwardMCMultiplicityTask& o)
118 // Assignment operator
121 // o Object to assign from
124 // Reference to this object
126 AliForwardMultiplicityBase::operator=(o);
129 fEventInspector = o.fEventInspector;
130 fEnergyFitter = o.fEnergyFitter;
131 fSharingFilter = o.fSharingFilter;
132 fDensityCalculator = o.fDensityCalculator;
133 fCorrections = o.fCorrections;
134 fHistCollector = o.fHistCollector;
137 fMCHistos = o.fMCHistos;
138 fMCAODFMD = o.fMCAODFMD;
139 fPrimary = o.fPrimary;
145 //____________________________________________________________________
147 AliForwardMCMultiplicityTask::SetDebug(Int_t dbg)
155 fEventInspector.SetDebug(dbg);
156 fEnergyFitter.SetDebug(dbg);
157 fSharingFilter.SetDebug(dbg);
158 fDensityCalculator.SetDebug(dbg);
159 fCorrections.SetDebug(dbg);
160 fHistCollector.SetDebug(dbg);
162 //____________________________________________________________________
164 AliForwardMCMultiplicityTask::InitializeSubs()
167 // Initialise the sub objects and stuff. Called on first event
170 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
171 fcm.Init(fEventInspector.GetCollisionSystem(),
172 fEventInspector.GetEnergy(),
173 fEventInspector.GetField(),
174 true); // Last true is for MC flag
175 // Check that we have the energy loss fits, needed by
176 // AliFMDSharingFilter
177 // AliFMDDensityCalculator
178 if (!fcm.GetELossFit()) {
179 AliFatal(Form("No energy loss fits"));
182 // Check that we have the double hit correction - (optionally) used by
183 // AliFMDDensityCalculator
184 if (!fcm.GetDoubleHit()) {
185 AliWarning("No double hit corrections");
187 // Check that we have the secondary maps, needed by
189 // AliFMDHistCollector
190 if (!fcm.GetSecondaryMap()) {
191 AliFatal("No secondary corrections");
194 // Check that we have the vertex bias correction, needed by
196 if (!fcm.GetVertexBias()) {
197 AliFatal("No event vertex bias corrections");
200 // Check that we have the merging efficiencies, optionally used by
202 if (!fcm.GetMergingEfficiency()) {
203 AliWarning("No merging efficiencies");
207 const TAxis* pe = fcm.GetEtaAxis();
208 const TAxis* pv = fcm.GetVertexAxis();
209 if (!pe) AliFatal("No eta axis defined");
210 if (!pv) AliFatal("No vertex axis defined");
217 fHData = static_cast<TH2D*>(fAODFMD.GetHistogram().Clone("d2Ndetadphi"));
219 fHData->SetDirectory(0);
223 fEnergyFitter.Init(*pe);
224 fEventInspector.Init(*pv);
225 fDensityCalculator.Init(*pe);
226 fCorrections.Init(*pe);
227 fHistCollector.Init(*pv);
232 //____________________________________________________________________
234 AliForwardMCMultiplicityTask::UserCreateOutputObjects()
237 // Create output objects
242 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
244 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
245 if (!ah) AliFatal("No AOD output handler set in analysis manager");
248 TObject* obj = &fAODFMD;
249 ah->AddBranch("AliAODForwardMult", &obj);
251 TObject* mcobj = &fMCAODFMD;
252 ah->AddBranch("AliAODForwardMult", &mcobj);
254 fPrimary = new TH2D("primary", "MC Primaries",
255 200, -4, 6, 20, 0, 2*TMath::Pi());
256 fPrimary->SetXTitle("#eta");
257 fPrimary->SetYTitle("#varphi [radians]");
258 fPrimary->SetZTitle("d^{2}N_{ch}/d#etad#phi");
260 fPrimary->SetStats(0);
261 fPrimary->SetDirectory(0);
262 ah->AddBranch("TH2D", &fPrimary);
264 fEventInspector.DefineOutput(fList);
265 fEnergyFitter.DefineOutput(fList);
266 fSharingFilter.DefineOutput(fList);
267 fDensityCalculator.DefineOutput(fList);
268 fCorrections.DefineOutput(fList);
272 //____________________________________________________________________
274 AliForwardMCMultiplicityTask::UserExec(Option_t*)
277 // Process each event
283 // Get the input data
284 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
286 AliWarning("No ESD event found for input event");
290 // On the first event, initialize the parameters
291 if (fFirstEvent && esd->GetESDRun()) {
292 fEventInspector.ReadRunDetails(esd);
294 AliInfo(Form("Initializing with parameters from the ESD:\n"
295 " AliESDEvent::GetBeamEnergy() ->%f\n"
296 " AliESDEvent::GetBeamType() ->%s\n"
297 " AliESDEvent::GetCurrentL3() ->%f\n"
298 " AliESDEvent::GetMagneticField()->%f\n"
299 " AliESDEvent::GetRunNumber() ->%d\n",
300 esd->GetBeamEnergy(),
303 esd->GetMagneticField(),
304 esd->GetRunNumber()));
319 Bool_t lowFlux = kFALSE;
323 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux, ivz, vz);
324 if (found & AliFMDEventInspector::kNoEvent) return;
325 if (found & AliFMDEventInspector::kNoTriggers) return;
327 // Set trigger bits, and mark this event for storage
328 fAODFMD.SetTriggerBits(triggers);
329 fMCAODFMD.SetTriggerBits(triggers);
332 if (found & AliFMDEventInspector::kNoSPD) return;
333 if (found & AliFMDEventInspector::kNoFMD) return;
334 if (found & AliFMDEventInspector::kNoVertex) return;
336 fMCAODFMD.SetIpZ(vz);
338 if (found & AliFMDEventInspector::kBadVertex) return;
340 // We we do not want to use low flux specific code, we disable it here.
341 if (!fEnableLowFlux) lowFlux = false;
344 AliESDFMD* esdFMD = esd->GetFMDData();
345 AliMCEvent* mcEvent = MCEvent();
346 // Apply the sharing filter (or hit merging or clustering if you like)
347 if (!fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD)) {
348 AliWarning("Sharing filter failed!");
351 if (!fSharingFilter.FilterMC(*esdFMD, *mcEvent, vz, fMCESDFMD, fPrimary)) {
352 AliWarning("MC Sharing filter failed!");
355 fSharingFilter.CompareResults(fESDFMD, fMCESDFMD);
357 // Do the energy stuff
358 if (!fEnergyFitter.Accumulate(*esdFMD, triggers & AliAODForwardMult::kEmpty)){
359 AliWarning("Energy fitter failed");
363 // Calculate the inclusive charged particle density
364 if (!fDensityCalculator.Calculate(fESDFMD, fHistos, ivz, lowFlux)) {
365 AliWarning("Density calculator failed!");
368 if (!fDensityCalculator.CalculateMC(fMCESDFMD, fMCHistos)) {
369 AliWarning("MC Density calculator failed!");
372 fDensityCalculator.CompareResults(fHistos, fMCHistos);
374 // Do the secondary and other corrections.
375 if (!fCorrections.Correct(fHistos, ivz)) {
376 AliWarning("Corrections failed");
379 if (!fCorrections.CorrectMC(fMCHistos, ivz)) {
380 AliWarning("MC Corrections failed");
383 fCorrections.CompareResults(fHistos, fMCHistos);
385 if (!fHistCollector.Collect(fHistos, ivz, fAODFMD.GetHistogram())) {
386 AliWarning("Histogram collector failed");
389 if (!fHistCollector.Collect(fMCHistos, ivz, fMCAODFMD.GetHistogram())) {
390 AliWarning("MC Histogram collector failed");
394 if (fAODFMD.IsTriggerBits(AliAODForwardMult::kInel))
395 fHData->Add(&(fAODFMD.GetHistogram()));
400 //____________________________________________________________________
402 AliForwardMCMultiplicityTask::Terminate(Option_t*)
410 TList* list = dynamic_cast<TList*>(GetOutputData(1));
412 AliError(Form("No output list defined (%p)", GetOutputData(1)));
413 if (GetOutputData(1)) GetOutputData(1)->Print();
417 // Get our histograms from the container
419 TH1I* hEventsTrVtx = 0;
421 if (!fEventInspector.FetchHistograms(list, hEventsTr,
422 hEventsTrVtx, hTriggers)) {
423 AliError(Form("Didn't get histograms from event selector "
424 "(hEventsTr=%p,hEventsTrVtx=%p)",
425 hEventsTr, hEventsTrVtx));
430 TH2D* hData = static_cast<TH2D*>(list->FindObject("d2Ndetadphi"));
432 AliError(Form("Couldn't get our summed histogram from output "
433 "list %s (d2Ndetadphi=%p)", list->GetName(), hData));
438 // TH1D* dNdeta = fHData->ProjectionX("dNdeta", 0, -1, "e");
439 TH1D* dNdeta = hData->ProjectionX("dNdeta", 1, -1, "e");
440 TH1D* norm = hData->ProjectionX("norm", 0, 1, "");
441 dNdeta->SetTitle("dN_{ch}/d#eta in the forward regions");
442 dNdeta->SetYTitle("#frac{1}{N}#frac{dN_{ch}}{d#eta}");
443 dNdeta->Divide(norm);
445 dNdeta->Scale(Double_t(hEventsTrVtx->GetEntries())/hEventsTr->GetEntries(),
450 fEnergyFitter.Fit(list);
451 fSharingFilter.ScaleHistograms(list,hEventsTr->Integral());
452 fDensityCalculator.ScaleHistograms(list,hEventsTrVtx->Integral());
453 fCorrections.ScaleHistograms(list,hEventsTrVtx->Integral());
456 //____________________________________________________________________
458 AliForwardMCMultiplicityTask::Print(Option_t* option) const
466 AliForwardMultiplicityBase::Print(option);
467 gROOT->IncreaseDirLevel();
468 fEventInspector .Print(option);
469 fEnergyFitter .Print(option);
470 fSharingFilter .Print(option);
471 fDensityCalculator.Print(option);
472 fCorrections .Print(option);
473 fHistCollector .Print(option);
474 gROOT->DecreaseDirLevel();