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) const
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");
183 //____________________________________________________________________
185 AliForwardQATask::ReadCorrections(const TAxis*& pe,
193 UInt_t what = AliForwardCorrectionManager::kAll;
194 what ^= AliForwardCorrectionManager::kDoubleHit;
195 what ^= AliForwardCorrectionManager::kVertexBias;
196 what ^= AliForwardCorrectionManager::kAcceptance;
197 what ^= AliForwardCorrectionManager::kMergingEfficiency;
199 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
200 if (!fcm.Init(GetEventInspector().GetCollisionSystem(),
201 GetEventInspector().GetEnergy(),
202 GetEventInspector().GetField(),
205 if (!CheckCorrections(what)) {
209 // Sett our persistency pointer
210 // fCorrManager = &fcm;
212 // Get the eta axis from the secondary maps - if read in
214 pe = fcm.GetEtaAxis();
215 if (!pe) AliFatal("No eta axis defined");
217 // Get the vertex axis from the secondary maps - if read in
219 pv = fcm.GetVertexAxis();
220 if (!pv) AliFatal("No vertex axis defined");
226 //____________________________________________________________________
228 AliForwardQATask::GetESDEvent()
231 // Get the ESD event. IF this is the first event, initialise
233 DGUARD(fDebug,2,"Get the ESD event");
235 DMSG(fDebug,3,"We're a Zombie - bailing out");
238 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
240 AliWarning("No ESD event found for input event");
244 // On the first event, initialize the parameters
245 if (fFirstEvent && esd->GetESDRun()) {
246 GetEventInspector().ReadRunDetails(esd);
248 AliInfoF("Initializing with parameters from the ESD:\n"
249 " AliESDEvent::GetBeamEnergy() ->%f\n"
250 " AliESDEvent::GetBeamType() ->%s\n"
251 " AliESDEvent::GetCurrentL3() ->%f\n"
252 " AliESDEvent::GetMagneticField()->%f\n"
253 " AliESDEvent::GetRunNumber() ->%d",
254 esd->GetBeamEnergy(),
257 esd->GetMagneticField(),
258 esd->GetRunNumber());
261 if (!InitializeSubs()) {
262 AliWarning("Initialisation of sub algorithms failed!");
267 AliInfoF("Clearing first event flag from %s to false",
268 fFirstEvent ? "true" : "false");
273 //____________________________________________________________________
275 AliForwardQATask::InitializeSubs()
278 // Initialise the sub objects and stuff. Called on first event
284 if (!ReadCorrections(pe,pv)) {
285 AliWarning("Using default binning");
286 pv = new TAxis(10,-10, 10);
287 pe = new TAxis(240,-6,6);
292 fEventInspector.Init(*pv);
293 fEnergyFitter.Init(*pe);
294 fSharingFilter.Init(*pe);
295 fDensityCalculator.Init(*pe);
302 //____________________________________________________________________
304 AliForwardQATask::UserCreateOutputObjects()
307 // Create output objects
313 fEventInspector.DefineOutput(fList);
314 fEnergyFitter.DefineOutput(fList);
315 fSharingFilter.DefineOutput(fList);
316 fDensityCalculator.DefineOutput(fList);
320 //____________________________________________________________________
322 AliForwardQATask::UserExec(Option_t*)
325 // Process each event
330 DGUARD(fDebug,1,"Process the input event");
332 // static Int_t cnt = 0;
334 // Get the input data
335 AliESDEvent* esd = GetESDEvent();
337 AliWarning("Got no ESD event");
341 // If the first event flag wasn't cleared in the above call to
342 // GetESDEvent, we should not do anything, since nothing has been
343 // initialised yet, so we opt out here (with a warning)
344 AliWarning("Nothing has been initialized yet, opt'ing out");
352 Bool_t lowFlux = kFALSE;
357 UShort_t nClusters = 0;
358 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux,
359 ivz, vz, cent, nClusters);
362 if (found & AliFMDEventInspector::kNoEvent) ok = false;
363 if (found & AliFMDEventInspector::kNoTriggers) ok = false;
364 if (found & AliFMDEventInspector::kNoSPD) ok = false;
365 if (found & AliFMDEventInspector::kNoFMD) ok = false;
366 if (found & AliFMDEventInspector::kNoVertex) ok = false;
367 if (triggers & AliAODForwardMult::kPileUp) ok = false;
368 if (found & AliFMDEventInspector::kBadVertex) ok = false;
370 DMSG(fDebug,2,"Event failed selection: %s",
371 AliFMDEventInspector::CodeString(found));
374 DMSG(fDebug,2,"Event triggers: %s", AliAODForwardMult::GetTriggerString(triggers));
376 // We we do not want to use low flux specific code, we disable it here.
377 if (!fEnableLowFlux) lowFlux = false;
380 AliESDFMD* esdFMD = esd->GetFMDData();
382 // Run the energy loss fitter
383 if (!fEnergyFitter.Accumulate(*esdFMD, cent,
384 triggers & AliAODForwardMult::kEmpty)) {
385 AliWarning("Energy fitter failed");
389 // // Apply the sharing filter (or hit merging or clustering if you like)
390 if (!fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD, vz)) {
391 AliWarning("Sharing filter failed!");
395 // Calculate the inclusive charged particle density
396 if (!fDensityCalculator.Calculate(fESDFMD, fHistos, ivz, lowFlux)) {
397 // if (!fDensityCalculator.Calculate(*esdFMD, fHistos, ivz, lowFlux)) {
398 AliWarning("Density calculator failed!");
405 //____________________________________________________________________
407 AliForwardQATask::Terminate(Option_t*)
415 if (fDebug) AliInfo("In Forwards terminate");
419 TList* list = dynamic_cast<TList*>(GetOutputData(1));
421 AliError(Form("No output list defined (%p)", GetOutputData(1)));
422 if (GetOutputData(1)) GetOutputData(1)->Print();
426 // Get our histograms from the container
427 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
428 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
430 if (!fEventInspector.FetchHistograms(list, hEventsTr,
431 hEventsTrVtx, hTriggers)) {
432 AliError(Form("Didn't get histograms from event selector "
433 "(hEventsTr=%p,hEventsTrVtx=%p)",
434 hEventsTr, hEventsTrVtx));
440 fEnergyFitter.Fit(list);
442 AliInfoF("Fitting took %d real-time seconds, and %f CPU seconds",
443 Int_t(swf.RealTime()), swf.CpuTime());
445 fSharingFilter.ScaleHistograms(list,Int_t(hEventsTr->Integral()));
446 fDensityCalculator.ScaleHistograms(list,Int_t(hEventsTrVtx->Integral()));
448 // Make a deep copy and post that as output 2
449 TList* list2 = static_cast<TList*>(list->Clone(Form("%sResults",
451 if (fDebug) AliInfoF("Posting post processing results to %s",
457 AliInfoF("Terminate took %d real-time seconds, and %f CPU seconds",
458 Int_t(swt.RealTime()), swt.CpuTime());
462 //____________________________________________________________________
464 AliForwardQATask::Print(Option_t* option) const
473 std::cout << ClassName() << ": " << GetName() << "\n"
474 << " Enable low flux code: " << (fEnableLowFlux ? "yes" : "no")
476 << " Off-line trigger mask: 0x"
477 << std::hex << std::setfill('0')
478 << std::setw (8) << fOfflineTriggerMask
479 << std::dec << std::setfill (' ') << std::endl;
480 gROOT->IncreaseDirLevel();
481 if (fCorrManager) fCorrManager->Print();
483 std::cout << " Correction manager not set yet" << std::endl;
484 GetEventInspector() .Print(option);
485 GetEnergyFitter() .Print(option);
486 GetSharingFilter() .Print(option);
487 gROOT->DecreaseDirLevel();