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) {
177 if (!fcm.GetELossFit()) {
178 AliWarning("No energy loss fits");
180 // Fall-back values if we do not have the energy loss fits
181 AliFMDMultCuts& sfLCuts = GetSharingFilter().GetLCuts();
182 if (sfLCuts.GetMethod() != AliFMDMultCuts::kFixed) {
184 AliWarningF("Using fixed cut @ %f for the lower bound "
185 "of the sharing filter", cut);
186 sfLCuts.SetMultCuts(cut);
188 AliFMDMultCuts& sfHCuts = GetSharingFilter().GetHCuts();
189 if (sfHCuts.GetMethod() != AliFMDMultCuts::kFixed) {
191 AliWarningF("Using fixed cut @ %f for the upper bound "
192 "of the sharing filter", cut);
193 sfHCuts.SetMultCuts(cut);
195 AliFMDMultCuts& dcCuts = GetDensityCalculator().GetCuts();
196 if (dcCuts.GetMethod() != AliFMDMultCuts::kFixed) {
198 AliWarningF("Using fixed cut @ %f for the lower bound "
199 "of the density calculator", cut);
200 dcCuts.SetMultCuts(cut);
204 fcm.GetELossFit()->CacheBins(GetDensityCalculator().GetMinQuality());
210 //____________________________________________________________________
212 AliForwardQATask::ReadCorrections(const TAxis*& pe,
221 UInt_t what = AliForwardCorrectionManager::kAll;
222 what ^= AliForwardCorrectionManager::kDoubleHit;
223 what ^= AliForwardCorrectionManager::kVertexBias;
224 what ^= AliForwardCorrectionManager::kAcceptance;
225 what ^= AliForwardCorrectionManager::kMergingEfficiency;
227 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
228 if (!fcm.Init(GetEventInspector().GetRunNumber(),
229 GetEventInspector().GetCollisionSystem(),
230 GetEventInspector().GetEnergy(),
231 GetEventInspector().GetField(),
235 false)) return false;
236 if (!CheckCorrections(what)) {
240 // Sett our persistency pointer
241 // fCorrManager = &fcm;
243 // Get the eta axis from the secondary maps - if read in
245 pe = fcm.GetEtaAxis();
246 if (!pe) AliFatal("No eta axis defined");
248 // Get the vertex axis from the secondary maps - if read in
250 pv = fcm.GetVertexAxis();
251 if (!pv) AliFatal("No vertex axis defined");
257 //____________________________________________________________________
259 AliForwardQATask::GetESDEvent()
262 // Get the ESD event. IF this is the first event, initialise
264 DGUARD(fDebug,2,"Get the ESD event");
266 DMSG(fDebug,3,"We're a Zombie - bailing out");
269 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
271 AliWarning("No ESD event found for input event");
275 // On the first event, initialize the parameters
276 if (fFirstEvent && esd->GetESDRun()) {
277 GetEventInspector().ReadRunDetails(esd);
279 AliInfoF("Initializing with parameters from the ESD:\n"
280 " AliESDEvent::GetBeamEnergy() ->%f\n"
281 " AliESDEvent::GetBeamType() ->%s\n"
282 " AliESDEvent::GetCurrentL3() ->%f\n"
283 " AliESDEvent::GetMagneticField()->%f\n"
284 " AliESDEvent::GetRunNumber() ->%d",
285 esd->GetBeamEnergy(),
288 esd->GetMagneticField(),
289 esd->GetRunNumber());
292 if (!SetupForData()) {
293 AliWarning("Initialisation of sub algorithms failed!");
298 AliInfoF("Clearing first event flag from %s to false",
299 fFirstEvent ? "true" : "false");
304 //____________________________________________________________________
306 AliForwardQATask::SetupForData()
309 // Initialise the sub objects and stuff. Called on first event
315 if (!ReadCorrections(pe,pv)) {
316 AliWarning("Using default binning");
317 pv = new TAxis(10,-10, 10);
318 pe = new TAxis(240,-6,6);
323 fEventInspector.SetupForData(*pv);
324 fEnergyFitter.SetupForData(*pe);
325 fSharingFilter.SetupForData(*pe);
326 fDensityCalculator.SetupForData(*pe);
333 //____________________________________________________________________
335 AliForwardQATask::UserCreateOutputObjects()
338 // Create output objects
344 fEventInspector.CreateOutputObjects(fList);
345 fEnergyFitter.CreateOutputObjects(fList);
346 fSharingFilter.CreateOutputObjects(fList);
347 fDensityCalculator.CreateOutputObjects(fList);
351 //____________________________________________________________________
353 AliForwardQATask::UserExec(Option_t*)
356 // Process each event
361 DGUARD(fDebug,1,"Process the input event");
363 // static Int_t cnt = 0;
365 // Get the input data
366 AliESDEvent* esd = GetESDEvent();
368 AliWarning("Got no ESD event");
372 // If the first event flag wasn't cleared in the above call to
373 // GetESDEvent, we should not do anything, since nothing has been
374 // initialised yet, so we opt out here (with a warning)
375 AliWarning("Nothing has been initialized yet, opt'ing out");
383 Bool_t lowFlux = kFALSE;
388 UShort_t nClusters = 0;
389 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux,
390 ivz, ip, cent, nClusters);
393 if (found & AliFMDEventInspector::kNoEvent) ok = false;
394 if (found & AliFMDEventInspector::kNoTriggers) ok = false;
395 if (found & AliFMDEventInspector::kNoSPD) ok = false;
396 if (found & AliFMDEventInspector::kNoFMD) ok = false;
397 if (found & AliFMDEventInspector::kNoVertex) ok = false;
398 if (triggers & AliAODForwardMult::kPileUp) ok = false;
399 if (found & AliFMDEventInspector::kBadVertex) ok = false;
401 DMSG(fDebug,2,"Event failed selection: %s",
402 AliFMDEventInspector::CodeString(found));
405 DMSG(fDebug,2,"Event triggers: %s",
406 AliAODForwardMult::GetTriggerString(triggers));
408 // We we do not want to use low flux specific code, we disable it here.
409 if (!fEnableLowFlux) lowFlux = false;
412 AliESDFMD* esdFMD = esd->GetFMDData();
414 // Run the energy loss fitter
415 if (!fEnergyFitter.Accumulate(*esdFMD, cent,
416 triggers & AliAODForwardMult::kEmpty)) {
417 AliWarning("Energy fitter failed");
421 // // Apply the sharing filter (or hit merging or clustering if you like)
422 if (!fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD, ip.Z())) {
423 AliWarning("Sharing filter failed!");
427 // Calculate the inclusive charged particle density
428 if (!fDensityCalculator.Calculate(fESDFMD, fHistos, lowFlux, cent, ip)) {
429 // if (!fDensityCalculator.Calculate(*esdFMD, fHistos, ivz, lowFlux)) {
430 AliWarning("Density calculator failed!");
437 //____________________________________________________________________
439 AliForwardQATask::Terminate(Option_t*)
447 if (fDebug) AliInfo("In Forwards terminate");
451 TList* list = dynamic_cast<TList*>(GetOutputData(1));
453 AliError(Form("No output list defined (%p)", GetOutputData(1)));
454 if (GetOutputData(1)) GetOutputData(1)->Print();
458 // Make a deep copy and post that as output 2
459 TList* list2 = static_cast<TList*>(list->Clone(Form("%sResults",
463 // Get our histograms from the container
464 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
465 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
466 TH1I* hEventsAcc = 0;
468 if (!fEventInspector.FetchHistograms(list,
473 AliError(Form("Didn't get histograms from event selector "
474 "(hEventsTr=%p,hEventsTrVtx=%p,hEventsAcc=%p)",
475 hEventsTr, hEventsTrVtx,hEventsAcc));
481 fEnergyFitter.Fit(list2);
483 AliInfoF("Fitting took %d real-time seconds, and %f CPU seconds",
484 Int_t(swf.RealTime()), swf.CpuTime());
486 fSharingFilter.Terminate(list,list2,Int_t(hEventsTr->Integral()));
487 fDensityCalculator.Terminate(list,list2,Int_t(hEventsTrVtx->Integral()));
489 if (fDebug) AliInfoF("Posting post processing results to %s",
494 AliInfoF("Terminate took %d real-time seconds, and %f CPU seconds",
495 Int_t(swt.RealTime()), swt.CpuTime());
500 //____________________________________________________________________
502 AliForwardQATask::Print(Option_t* option) const
511 std::cout << ClassName() << ": " << GetName() << "\n"
512 << " Enable low flux code: " << (fEnableLowFlux ? "yes" : "no")
514 << " Off-line trigger mask: 0x"
515 << std::hex << std::setfill('0')
516 << std::setw (8) << fOfflineTriggerMask
517 << std::dec << std::setfill (' ') << std::endl;
518 gROOT->IncreaseDirLevel();
519 if (fCorrManager) fCorrManager->Print();
521 std::cout << " Correction manager not set yet" << std::endl;
522 GetEventInspector() .Print(option);
523 GetEnergyFitter() .Print(option);
524 GetSharingFilter() .Print(option);
525 GetDensityCalculator().Print(option);
526 gROOT->DecreaseDirLevel();