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 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
235 AliWarning("No ESD event found for input event");
239 // On the first event, initialize the parameters
240 if (fFirstEvent && esd->GetESDRun()) {
241 GetEventInspector().ReadRunDetails(esd);
243 AliInfoF("Initializing with parameters from the ESD:\n"
244 " AliESDEvent::GetBeamEnergy() ->%f\n"
245 " AliESDEvent::GetBeamType() ->%s\n"
246 " AliESDEvent::GetCurrentL3() ->%f\n"
247 " AliESDEvent::GetMagneticField()->%f\n"
248 " AliESDEvent::GetRunNumber() ->%d\n",
249 esd->GetBeamEnergy(),
252 esd->GetMagneticField(),
253 esd->GetRunNumber());
256 if (!InitializeSubs()) {
257 AliWarning("Initialisation of sub algorithms failed!");
260 AliInfoF("Clearing first event flag from %s to false",
261 fFirstEvent ? "true" : "false");
266 //____________________________________________________________________
268 AliForwardQATask::InitializeSubs()
271 // Initialise the sub objects and stuff. Called on first event
277 if (!ReadCorrections(pe,pv)) {
278 AliWarning("Failed to read corrections");
284 fEventInspector.Init(*pv);
285 fEnergyFitter.Init(*pe);
286 fSharingFilter.Init();
287 fDensityCalculator.Init(*pe);
294 //____________________________________________________________________
296 AliForwardQATask::UserCreateOutputObjects()
299 // Create output objects
305 fEventInspector.DefineOutput(fList);
306 fEnergyFitter.DefineOutput(fList);
307 fSharingFilter.DefineOutput(fList);
308 fDensityCalculator.DefineOutput(fList);
312 //____________________________________________________________________
314 AliForwardQATask::UserExec(Option_t*)
317 // Process each event
323 // static Int_t cnt = 0;
325 // Get the input data
326 AliESDEvent* esd = GetESDEvent();
328 AliWarning("Got no ESD event");
332 // If the first event flag wasn't cleared in the above call to
333 // GetESDEvent, we should not do anything, since nothing has been
334 // initialised yet, so we opt out here (with a warning)
335 AliWarning("Nothing has been initialized yet, opt'ing out");
343 Bool_t lowFlux = kFALSE;
348 UShort_t nClusters = 0;
349 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux,
350 ivz, vz, cent, nClusters);
352 if (found & AliFMDEventInspector::kNoEvent) return;
353 if (found & AliFMDEventInspector::kNoTriggers) return;
354 if (found & AliFMDEventInspector::kNoSPD) return;
355 if (found & AliFMDEventInspector::kNoFMD) return;
356 if (found & AliFMDEventInspector::kNoVertex) return;
357 if (triggers & AliAODForwardMult::kPileUp) return;
358 if (found & AliFMDEventInspector::kBadVertex) return;
360 // We we do not want to use low flux specific code, we disable it here.
361 if (!fEnableLowFlux) lowFlux = false;
364 AliESDFMD* esdFMD = esd->GetFMDData();
366 // Run the energy loss fitter
367 if (!fEnergyFitter.Accumulate(*esdFMD, cent,
368 triggers & AliAODForwardMult::kEmpty)) {
369 AliWarning("Energy fitter failed");
373 // // Apply the sharing filter (or hit merging or clustering if you like)
374 if (!fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD, vz)) {
375 AliWarning("Sharing filter failed!");
379 // Calculate the inclusive charged particle density
380 if (!fDensityCalculator.Calculate(fESDFMD, fHistos, ivz, lowFlux)) {
381 // if (!fDensityCalculator.Calculate(*esdFMD, fHistos, ivz, lowFlux)) {
382 AliWarning("Density calculator failed!");
388 //____________________________________________________________________
390 AliForwardQATask::Terminate(Option_t*)
398 if (fDebug) AliInfo("In Forwards terminate");
402 TList* list = dynamic_cast<TList*>(GetOutputData(1));
404 AliError(Form("No output list defined (%p)", GetOutputData(1)));
405 if (GetOutputData(1)) GetOutputData(1)->Print();
409 // Get our histograms from the container
410 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
411 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
413 if (!fEventInspector.FetchHistograms(list, hEventsTr,
414 hEventsTrVtx, hTriggers)) {
415 AliError(Form("Didn't get histograms from event selector "
416 "(hEventsTr=%p,hEventsTrVtx=%p)",
417 hEventsTr, hEventsTrVtx));
423 fEnergyFitter.Fit(list);
425 AliInfoF("Fitting took %d real-time seconds, and %f CPU seconds",
426 Int_t(swf.RealTime()), swf.CpuTime());
428 fSharingFilter.ScaleHistograms(list,Int_t(hEventsTr->Integral()));
429 fDensityCalculator.ScaleHistograms(list,Int_t(hEventsTrVtx->Integral()));
431 // Make a deep copy and post that as output 2
432 TList* list2 = static_cast<TList*>(list->Clone(Form("%sResults",
434 if (fDebug) AliInfoF("Posting post processing results to %s",
440 AliInfoF("Terminate took %d real-time seconds, and %f CPU seconds",
441 Int_t(swt.RealTime()), swt.CpuTime());
445 //____________________________________________________________________
447 AliForwardQATask::Print(Option_t* option) const
456 std::cout << ClassName() << ": " << GetName() << "\n"
457 << " Enable low flux code: " << (fEnableLowFlux ? "yes" : "no")
459 << " Off-line trigger mask: 0x"
460 << std::hex << std::setfill('0')
461 << std::setw (8) << fOfflineTriggerMask
462 << std::dec << std::setfill (' ') << std::endl;
463 gROOT->IncreaseDirLevel();
464 if (fCorrManager) fCorrManager->Print();
466 std::cout << " Correction manager not set yet" << std::endl;
467 GetEventInspector() .Print(option);
468 GetEnergyFitter() .Print(option);
469 GetSharingFilter() .Print(option);
470 gROOT->DecreaseDirLevel();