2 // Calculate the multiplicity in the forward regions event-by-event
14 #include "AliForwardQATask.h"
15 #include "AliForwardUtil.h"
16 #include "AliTriggerAnalysis.h"
17 #include "AliPhysicsSelection.h"
19 #include "AliESDEvent.h"
20 #include "AliAODHandler.h"
21 #include "AliMultiplicity.h"
22 #include "AliInputEventHandler.h"
23 #include "AliForwardCorrectionManager.h"
24 #include "AliAnalysisManager.h"
25 #include "AliAODForwardMult.h"
27 #include <TDirectory.h>
30 #include <TStopwatch.h>
32 //====================================================================
33 AliForwardQATask::AliForwardQATask()
34 : AliAnalysisTaskSE(),
35 fEnableLowFlux(false),
52 //____________________________________________________________________
53 AliForwardQATask::AliForwardQATask(const char* name)
54 : AliAnalysisTaskSE(name),
55 fEnableLowFlux(false),
60 fEventInspector("event"),
61 fEnergyFitter("energy"),
62 fSharingFilter("sharing"),
63 fDensityCalculator("density"),
73 DefineOutput(1, TList::Class());
74 DefineOutput(2, TList::Class());
75 fCorrManager = &AliForwardCorrectionManager::Instance();
76 fEnergyFitter.SetNParticles(1); // Just find the 1st peak
77 fEnergyFitter.SetDoMakeObject(false);
78 fEnergyFitter.SetUseIncreasingBins(true);
79 fEnergyFitter.SetDoFits(kTRUE);
80 fEnergyFitter.SetLowCut(0.4);
81 fEnergyFitter.SetFitRangeBinWidth(4);
82 fEnergyFitter.SetMinEntries(1000);
85 //____________________________________________________________________
86 AliForwardQATask::AliForwardQATask(const AliForwardQATask& o)
87 : AliAnalysisTaskSE(o),
88 fEnableLowFlux(o.fEnableLowFlux),
89 fFirstEvent(o.fFirstEvent),
90 fCorrManager(o.fCorrManager),
93 fEventInspector(o.fEventInspector),
94 fEnergyFitter(o.fEnergyFitter),
95 fSharingFilter(o.fSharingFilter),
96 fDensityCalculator(o.fDensityCalculator),
104 // o Object to copy from
106 DefineOutput(1, TList::Class());
107 DefineOutput(2, TList::Class());
110 //____________________________________________________________________
112 AliForwardQATask::operator=(const AliForwardQATask& o)
115 // Assignment operator
118 // o Object to assign from
121 // Reference to this object
123 if (&o == this) return *this;
124 AliAnalysisTaskSE::operator=(o);
126 fEnableLowFlux = o.fEnableLowFlux;
127 fFirstEvent = o.fFirstEvent;
128 fCorrManager = o.fCorrManager;
129 fEventInspector = o.fEventInspector;
130 fEnergyFitter = o.fEnergyFitter;
131 fSharingFilter = o.fSharingFilter;
132 fDensityCalculator = o.fDensityCalculator;
140 //____________________________________________________________________
142 AliForwardQATask::SetDebug(Int_t dbg)
151 fEventInspector.SetDebug(dbg);
152 fEnergyFitter.SetDebug(dbg);
153 fSharingFilter.SetDebug(dbg);
154 fDensityCalculator.SetDebug(dbg);
157 //____________________________________________________________________
159 AliForwardQATask::CheckCorrections(UInt_t what)
162 // Check if all needed corrections are there and accounted for. If not,
166 // what Which corrections is needed
169 // true if all present, false otherwise
172 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
173 // Check that we have the energy loss fits, needed by
174 // AliFMDSharingFilter
175 // AliFMDDensityCalculator
176 if (what & AliForwardCorrectionManager::kELossFits && !fcm.GetELossFit()) {
177 AliWarning("No energy loss fits");
179 // Fall-back values if we do not have the energy loss fits
180 AliFMDMultCuts& sfLCuts = GetSharingFilter().GetLCuts();
181 if (sfLCuts.GetMethod() != AliFMDMultCuts::kFixed) {
183 AliWarningF("Using fixed cut @ %f for the lower bound "
184 "of the sharing filter", cut);
185 sfLCuts.SetMultCuts(cut);
187 AliFMDMultCuts& sfHCuts = GetSharingFilter().GetHCuts();
188 if (sfHCuts.GetMethod() != AliFMDMultCuts::kFixed) {
190 AliWarningF("Using fixed cut @ %f for the upper bound "
191 "of the sharing filter", cut);
192 sfHCuts.SetMultCuts(cut);
194 AliFMDMultCuts& dcCuts = GetDensityCalculator().GetCuts();
195 if (dcCuts.GetMethod() != AliFMDMultCuts::kFixed) {
197 AliWarningF("Using fixed cut @ %f for the lower bound "
198 "of the density calculator", cut);
199 dcCuts.SetMultCuts(cut);
205 //____________________________________________________________________
207 AliForwardQATask::ReadCorrections(const TAxis*& pe,
215 UInt_t what = AliForwardCorrectionManager::kAll;
216 what ^= AliForwardCorrectionManager::kDoubleHit;
217 what ^= AliForwardCorrectionManager::kVertexBias;
218 what ^= AliForwardCorrectionManager::kAcceptance;
219 what ^= AliForwardCorrectionManager::kMergingEfficiency;
221 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
222 if (!fcm.Init(GetEventInspector().GetCollisionSystem(),
223 GetEventInspector().GetEnergy(),
224 GetEventInspector().GetField(),
227 if (!CheckCorrections(what)) {
231 // Sett our persistency pointer
232 // fCorrManager = &fcm;
234 // Get the eta axis from the secondary maps - if read in
236 pe = fcm.GetEtaAxis();
237 if (!pe) AliFatal("No eta axis defined");
239 // Get the vertex axis from the secondary maps - if read in
241 pv = fcm.GetVertexAxis();
242 if (!pv) AliFatal("No vertex axis defined");
248 //____________________________________________________________________
250 AliForwardQATask::GetESDEvent()
253 // Get the ESD event. IF this is the first event, initialise
255 DGUARD(fDebug,2,"Get the ESD event");
257 DMSG(fDebug,3,"We're a Zombie - bailing out");
260 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
262 AliWarning("No ESD event found for input event");
266 // On the first event, initialize the parameters
267 if (fFirstEvent && esd->GetESDRun()) {
268 GetEventInspector().ReadRunDetails(esd);
270 AliInfoF("Initializing with parameters from the ESD:\n"
271 " AliESDEvent::GetBeamEnergy() ->%f\n"
272 " AliESDEvent::GetBeamType() ->%s\n"
273 " AliESDEvent::GetCurrentL3() ->%f\n"
274 " AliESDEvent::GetMagneticField()->%f\n"
275 " AliESDEvent::GetRunNumber() ->%d",
276 esd->GetBeamEnergy(),
279 esd->GetMagneticField(),
280 esd->GetRunNumber());
283 if (!SetupForData()) {
284 AliWarning("Initialisation of sub algorithms failed!");
289 AliInfoF("Clearing first event flag from %s to false",
290 fFirstEvent ? "true" : "false");
295 //____________________________________________________________________
297 AliForwardQATask::SetupForData()
300 // Initialise the sub objects and stuff. Called on first event
306 if (!ReadCorrections(pe,pv)) {
307 AliWarning("Using default binning");
308 pv = new TAxis(10,-10, 10);
309 pe = new TAxis(240,-6,6);
314 fEventInspector.SetupForData(*pv);
315 fEnergyFitter.SetupForData(*pe);
316 fSharingFilter.SetupForData(*pe);
317 fDensityCalculator.SetupForData(*pe);
324 //____________________________________________________________________
326 AliForwardQATask::UserCreateOutputObjects()
329 // Create output objects
335 fEventInspector.CreateOutputObjects(fList);
336 fEnergyFitter.CreateOutputObjects(fList);
337 fSharingFilter.CreateOutputObjects(fList);
338 fDensityCalculator.CreateOutputObjects(fList);
342 //____________________________________________________________________
344 AliForwardQATask::UserExec(Option_t*)
347 // Process each event
352 DGUARD(fDebug,1,"Process the input event");
354 // static Int_t cnt = 0;
356 // Get the input data
357 AliESDEvent* esd = GetESDEvent();
359 AliWarning("Got no ESD event");
363 // If the first event flag wasn't cleared in the above call to
364 // GetESDEvent, we should not do anything, since nothing has been
365 // initialised yet, so we opt out here (with a warning)
366 AliWarning("Nothing has been initialized yet, opt'ing out");
374 Bool_t lowFlux = kFALSE;
379 UShort_t nClusters = 0;
380 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux,
381 ivz, ip, cent, nClusters);
384 if (found & AliFMDEventInspector::kNoEvent) ok = false;
385 if (found & AliFMDEventInspector::kNoTriggers) ok = false;
386 if (found & AliFMDEventInspector::kNoSPD) ok = false;
387 if (found & AliFMDEventInspector::kNoFMD) ok = false;
388 if (found & AliFMDEventInspector::kNoVertex) ok = false;
389 if (triggers & AliAODForwardMult::kPileUp) ok = false;
390 if (found & AliFMDEventInspector::kBadVertex) ok = false;
392 DMSG(fDebug,2,"Event failed selection: %s",
393 AliFMDEventInspector::CodeString(found));
396 DMSG(fDebug,2,"Event triggers: %s",
397 AliAODForwardMult::GetTriggerString(triggers));
399 // We we do not want to use low flux specific code, we disable it here.
400 if (!fEnableLowFlux) lowFlux = false;
403 AliESDFMD* esdFMD = esd->GetFMDData();
405 // Run the energy loss fitter
406 if (!fEnergyFitter.Accumulate(*esdFMD, cent,
407 triggers & AliAODForwardMult::kEmpty)) {
408 AliWarning("Energy fitter failed");
412 // // Apply the sharing filter (or hit merging or clustering if you like)
413 if (!fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD, ip.Z())) {
414 AliWarning("Sharing filter failed!");
418 // Calculate the inclusive charged particle density
419 if (!fDensityCalculator.Calculate(fESDFMD, fHistos, lowFlux, cent, ip)) {
420 // if (!fDensityCalculator.Calculate(*esdFMD, fHistos, ivz, lowFlux)) {
421 AliWarning("Density calculator failed!");
428 //____________________________________________________________________
430 AliForwardQATask::Terminate(Option_t*)
438 if (fDebug) AliInfo("In Forwards terminate");
442 TList* list = dynamic_cast<TList*>(GetOutputData(1));
444 AliError(Form("No output list defined (%p)", GetOutputData(1)));
445 if (GetOutputData(1)) GetOutputData(1)->Print();
449 // Make a deep copy and post that as output 2
450 TList* list2 = static_cast<TList*>(list->Clone(Form("%sResults",
454 // Get our histograms from the container
455 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
456 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
457 TH1I* hEventsAcc = 0;
459 if (!fEventInspector.FetchHistograms(list,
464 AliError(Form("Didn't get histograms from event selector "
465 "(hEventsTr=%p,hEventsTrVtx=%p,hEventsAcc=%p)",
466 hEventsTr, hEventsTrVtx,hEventsAcc));
472 fEnergyFitter.Fit(list2);
474 AliInfoF("Fitting took %d real-time seconds, and %f CPU seconds",
475 Int_t(swf.RealTime()), swf.CpuTime());
477 fSharingFilter.Terminate(list,list2,Int_t(hEventsTr->Integral()));
478 fDensityCalculator.Terminate(list,list2,Int_t(hEventsTrVtx->Integral()));
480 if (fDebug) AliInfoF("Posting post processing results to %s",
485 AliInfoF("Terminate took %d real-time seconds, and %f CPU seconds",
486 Int_t(swt.RealTime()), swt.CpuTime());
491 //____________________________________________________________________
493 AliForwardQATask::Print(Option_t* option) const
502 std::cout << ClassName() << ": " << GetName() << "\n"
503 << " Enable low flux code: " << (fEnableLowFlux ? "yes" : "no")
505 << " Off-line trigger mask: 0x"
506 << std::hex << std::setfill('0')
507 << std::setw (8) << fOfflineTriggerMask
508 << std::dec << std::setfill (' ') << std::endl;
509 gROOT->IncreaseDirLevel();
510 if (fCorrManager) fCorrManager->Print();
512 std::cout << " Correction manager not set yet" << std::endl;
513 GetEventInspector() .Print(option);
514 GetEnergyFitter() .Print(option);
515 GetSharingFilter() .Print(option);
516 GetDensityCalculator().Print(option);
517 gROOT->DecreaseDirLevel();