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 if (IsZombie()) return 0;
234 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
236 AliWarning("No ESD event found for input event");
240 // On the first event, initialize the parameters
241 if (fFirstEvent && esd->GetESDRun()) {
242 GetEventInspector().ReadRunDetails(esd);
244 AliInfoF("Initializing with parameters from the ESD:\n"
245 " AliESDEvent::GetBeamEnergy() ->%f\n"
246 " AliESDEvent::GetBeamType() ->%s\n"
247 " AliESDEvent::GetCurrentL3() ->%f\n"
248 " AliESDEvent::GetMagneticField()->%f\n"
249 " AliESDEvent::GetRunNumber() ->%d",
250 esd->GetBeamEnergy(),
253 esd->GetMagneticField(),
254 esd->GetRunNumber());
257 if (!InitializeSubs()) {
258 AliWarning("Initialisation of sub algorithms failed!");
263 AliInfoF("Clearing first event flag from %s to false",
264 fFirstEvent ? "true" : "false");
269 //____________________________________________________________________
271 AliForwardQATask::InitializeSubs()
274 // Initialise the sub objects and stuff. Called on first event
280 if (!ReadCorrections(pe,pv)) {
281 AliWarning("Using default binning");
282 pv = new TAxis(10,-10, 10);
283 pe = new TAxis(240,-6,6);
288 fEventInspector.Init(*pv);
289 fEnergyFitter.Init(*pe);
290 fSharingFilter.Init();
291 fDensityCalculator.Init(*pe);
298 //____________________________________________________________________
300 AliForwardQATask::UserCreateOutputObjects()
303 // Create output objects
309 fEventInspector.DefineOutput(fList);
310 fEnergyFitter.DefineOutput(fList);
311 fSharingFilter.DefineOutput(fList);
312 fDensityCalculator.DefineOutput(fList);
316 //____________________________________________________________________
318 AliForwardQATask::UserExec(Option_t*)
321 // Process each event
327 // static Int_t cnt = 0;
329 // Get the input data
330 AliESDEvent* esd = GetESDEvent();
332 AliWarning("Got no ESD event");
336 // If the first event flag wasn't cleared in the above call to
337 // GetESDEvent, we should not do anything, since nothing has been
338 // initialised yet, so we opt out here (with a warning)
339 AliWarning("Nothing has been initialized yet, opt'ing out");
347 Bool_t lowFlux = kFALSE;
352 UShort_t nClusters = 0;
353 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux,
354 ivz, vz, cent, nClusters);
356 if (found & AliFMDEventInspector::kNoEvent) return;
357 if (found & AliFMDEventInspector::kNoTriggers) return;
358 if (found & AliFMDEventInspector::kNoSPD) return;
359 if (found & AliFMDEventInspector::kNoFMD) return;
360 if (found & AliFMDEventInspector::kNoVertex) return;
361 if (triggers & AliAODForwardMult::kPileUp) return;
362 if (found & AliFMDEventInspector::kBadVertex) return;
364 // We we do not want to use low flux specific code, we disable it here.
365 if (!fEnableLowFlux) lowFlux = false;
368 AliESDFMD* esdFMD = esd->GetFMDData();
370 // Run the energy loss fitter
371 if (!fEnergyFitter.Accumulate(*esdFMD, cent,
372 triggers & AliAODForwardMult::kEmpty)) {
373 AliWarning("Energy fitter failed");
377 // // Apply the sharing filter (or hit merging or clustering if you like)
378 if (!fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD, vz)) {
379 AliWarning("Sharing filter failed!");
383 // Calculate the inclusive charged particle density
384 if (!fDensityCalculator.Calculate(fESDFMD, fHistos, ivz, lowFlux)) {
385 // if (!fDensityCalculator.Calculate(*esdFMD, fHistos, ivz, lowFlux)) {
386 AliWarning("Density calculator failed!");
393 //____________________________________________________________________
395 AliForwardQATask::Terminate(Option_t*)
403 if (fDebug) AliInfo("In Forwards terminate");
407 TList* list = dynamic_cast<TList*>(GetOutputData(1));
409 AliError(Form("No output list defined (%p)", GetOutputData(1)));
410 if (GetOutputData(1)) GetOutputData(1)->Print();
414 // Get our histograms from the container
415 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
416 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
418 if (!fEventInspector.FetchHistograms(list, hEventsTr,
419 hEventsTrVtx, hTriggers)) {
420 AliError(Form("Didn't get histograms from event selector "
421 "(hEventsTr=%p,hEventsTrVtx=%p)",
422 hEventsTr, hEventsTrVtx));
428 fEnergyFitter.Fit(list);
430 AliInfoF("Fitting took %d real-time seconds, and %f CPU seconds",
431 Int_t(swf.RealTime()), swf.CpuTime());
433 fSharingFilter.ScaleHistograms(list,Int_t(hEventsTr->Integral()));
434 fDensityCalculator.ScaleHistograms(list,Int_t(hEventsTrVtx->Integral()));
436 // Make a deep copy and post that as output 2
437 TList* list2 = static_cast<TList*>(list->Clone(Form("%sResults",
439 if (fDebug) AliInfoF("Posting post processing results to %s",
445 AliInfoF("Terminate took %d real-time seconds, and %f CPU seconds",
446 Int_t(swt.RealTime()), swt.CpuTime());
450 //____________________________________________________________________
452 AliForwardQATask::Print(Option_t* option) const
461 std::cout << ClassName() << ": " << GetName() << "\n"
462 << " Enable low flux code: " << (fEnableLowFlux ? "yes" : "no")
464 << " Off-line trigger mask: 0x"
465 << std::hex << std::setfill('0')
466 << std::setw (8) << fOfflineTriggerMask
467 << std::dec << std::setfill (' ') << std::endl;
468 gROOT->IncreaseDirLevel();
469 if (fCorrManager) fCorrManager->Print();
471 std::cout << " Correction manager not set yet" << std::endl;
472 GetEventInspector() .Print(option);
473 GetEnergyFitter() .Print(option);
474 GetSharingFilter() .Print(option);
475 gROOT->DecreaseDirLevel();