1 #include "AliForwardMultiplicityTask.h"
2 #include "AliTriggerAnalysis.h"
3 #include "AliPhysicsSelection.h"
5 // #include "AliFMDAnaParameters.h"
6 #include "AliESDEvent.h"
7 #include "AliAODHandler.h"
8 #include "AliMultiplicity.h"
9 #include "AliInputEventHandler.h"
10 #include "AliForwardCorrectionManager.h"
11 #include "AliAnalysisManager.h"
13 #include <TDirectory.h>
19 //====================================================================
20 AliForwardMultiplicityTask::AliForwardMultiplicityTask()
21 : AliAnalysisTaskSE(),
38 //____________________________________________________________________
39 AliForwardMultiplicityTask::AliForwardMultiplicityTask(const char* name)
40 : AliAnalysisTaskSE(name),
47 fEventInspector("event"),
48 fEnergyFitter("energy"),
49 fSharingFilter("sharing"),
50 fDensityCalculator("density"),
51 fCorrections("corrections"),
52 fHistCollector("collector"),
55 DefineOutput(1, TList::Class());
58 //____________________________________________________________________
59 AliForwardMultiplicityTask::AliForwardMultiplicityTask(const AliForwardMultiplicityTask& o)
60 : AliAnalysisTaskSE(o),
61 fEnableLowFlux(o.fEnableLowFlux),
67 fEventInspector(o.fEventInspector),
68 fEnergyFitter(o.fEnergyFitter),
69 fSharingFilter(o.fSharingFilter),
70 fDensityCalculator(o.fDensityCalculator),
71 fCorrections(o.fCorrections),
72 fHistCollector(o.fHistCollector),
75 DefineOutput(1, TList::Class());
78 //____________________________________________________________________
79 AliForwardMultiplicityTask&
80 AliForwardMultiplicityTask::operator=(const AliForwardMultiplicityTask& o)
82 AliAnalysisTaskSE::operator=(o);
84 fEnableLowFlux = o.fEnableLowFlux;
86 fFirstEvent = o.fFirstEvent;
87 fEventInspector = o.fEventInspector;
88 fEnergyFitter = o.fEnergyFitter;
89 fSharingFilter = o.fSharingFilter;
90 fDensityCalculator = o.fDensityCalculator;
91 fCorrections = o.fCorrections;
92 fHistCollector = o.fHistCollector;
100 //____________________________________________________________________
102 AliForwardMultiplicityTask::SetDebug(Int_t dbg)
104 fEventInspector.SetDebug(dbg);
105 fEnergyFitter.SetDebug(dbg);
106 fSharingFilter.SetDebug(dbg);
107 fDensityCalculator.SetDebug(dbg);
108 fCorrections.SetDebug(dbg);
109 fHistCollector.SetDebug(dbg);
112 //____________________________________________________________________
114 AliForwardMultiplicityTask::Init()
119 //____________________________________________________________________
121 AliForwardMultiplicityTask::InitializeSubs()
124 // AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
125 // pars->Init(kTRUE);
127 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
128 fcm.Init(fEventInspector.GetCollisionSystem(),
129 fEventInspector.GetEnergy(),
130 fEventInspector.GetField());
131 // Check that we have the energy loss fits, needed by
132 // AliFMDSharingFilter
133 // AliFMDDensityCalculator
134 if (!fcm.GetELossFit()) {
135 AliFatal(Form("No energy loss fits"));
138 // Check that we have the double hit correction - (optionally) used by
139 // AliFMDDensityCalculator
140 if (!fcm.GetDoubleHit()) {
141 AliWarning("No double hit corrections");
143 // Check that we have the secondary maps, needed by
145 // AliFMDHistCollector
146 if (!fcm.GetSecondaryMap()) {
147 AliFatal("No secondary corrections");
150 // Check that we have the vertex bias correction, needed by
152 if (!fcm.GetVertexBias()) {
153 AliFatal("No event vertex bias corrections");
156 // Check that we have the merging efficiencies, optionally used by
158 if (!fcm.GetMergingEfficiency()) {
159 AliWarning("No merging efficiencies");
163 const TAxis* pe = fcm.GetEtaAxis();
164 const TAxis* pv = fcm.GetVertexAxis();
165 if (!pe) AliFatal("No eta axis defined");
166 if (!pv) AliFatal("No vertex axis defined");
168 // TAxis e(pars->GetNetaBins(), pars->GetEtaMin(), pars->GetEtaMax());
169 // TAxis v(pars->GetNvtxBins(), -pars->GetVtxCutZ(), pars->GetVtxCutZ());
175 fHData = static_cast<TH2D*>(fAODFMD.GetHistogram().Clone("d2Ndetadphi"));
177 fHData->SetDirectory(0);
180 fEnergyFitter.Init(*pe);
181 fEventInspector.Init(*pv);
182 fHistCollector.Init(*pv);
187 //____________________________________________________________________
189 AliForwardMultiplicityTask::UserCreateOutputObjects()
193 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
195 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
196 if (!ah) AliFatal("No AOD output handler set in analysis manager");
199 TObject* obj = &fAODFMD;
200 ah->AddBranch("AliAODForwardMult", &obj);
202 fEventInspector.DefineOutput(fList);
203 fEnergyFitter.DefineOutput(fList);
204 fSharingFilter.DefineOutput(fList);
205 fDensityCalculator.DefineOutput(fList);
206 fCorrections.DefineOutput(fList);
210 //____________________________________________________________________
212 AliForwardMultiplicityTask::UserExec(Option_t*)
214 // static Int_t cnt = 0;
216 // Get the input data
217 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
218 // AliInfo(Form("Event # %6d (esd=%p)", cnt, esd));
220 AliWarning("No ESD event found for input event");
224 // On the first event, initialize the parameters
225 if (fFirstEvent && esd->GetESDRun()) {
226 fEventInspector.ReadRunDetails(esd);
228 AliInfo(Form("Initializing with parameters from the ESD:\n"
229 " AliESDEvent::GetBeamEnergy() ->%f\n"
230 " AliESDEvent::GetBeamType() ->%s\n"
231 " AliESDEvent::GetCurrentL3() ->%f\n"
232 " AliESDEvent::GetMagneticField()->%f\n"
233 " AliESDEvent::GetRunNumber() ->%d\n",
234 esd->GetBeamEnergy(),
237 esd->GetMagneticField(),
238 esd->GetRunNumber()));
242 // AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
243 // pars->SetParametersFromESD(esd);
244 // pars->PrintStatus();
254 Bool_t lowFlux = kFALSE;
258 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux, ivz, vz);
259 if (found & AliFMDEventInspector::kNoEvent) return;
260 if (found & AliFMDEventInspector::kNoTriggers) return;
262 // Set trigger bits, and mark this event for storage
263 fAODFMD.SetTriggerBits(triggers);
266 if (found & AliFMDEventInspector::kNoSPD) return;
267 if (found & AliFMDEventInspector::kNoFMD) return;
268 if (found & AliFMDEventInspector::kNoVertex) return;
271 if (found & AliFMDEventInspector::kBadVertex) return;
273 // We we do not want to use low flux specific code, we disable it here.
274 if (!fEnableLowFlux) lowFlux = false;
277 AliESDFMD* esdFMD = esd->GetFMDData();
278 // Apply the sharing filter (or hit merging or clustering if you like)
279 if (!fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD)) {
280 AliWarning("Sharing filter failed!");
284 // Do the energy stuff
285 if (!fEnergyFitter.Accumulate(*esdFMD, triggers & AliAODForwardMult::kEmpty)){
286 AliWarning("Energy fitter failed");
290 // Calculate the inclusive charged particle density
291 if (!fDensityCalculator.Calculate(fESDFMD, fHistos, ivz, lowFlux)) {
292 AliWarning("Density calculator failed!");
296 // Do the secondary and other corrections.
297 if (!fCorrections.Correct(fHistos, ivz)) {
298 AliWarning("Corrections failed");
302 if (!fHistCollector.Collect(fHistos, ivz, fAODFMD.GetHistogram())) {
303 AliWarning("Histogram collector failed");
307 if (fAODFMD.IsTriggerBits(AliAODForwardMult::kInel))
308 fHData->Add(&(fAODFMD.GetHistogram()));
313 //____________________________________________________________________
315 AliForwardMultiplicityTask::Terminate(Option_t*)
317 TList* list = dynamic_cast<TList*>(GetOutputData(1));
319 AliError(Form("No output list defined (%p)", GetOutputData(1)));
320 if (GetOutputData(1)) GetOutputData(1)->Print();
324 // Get our histograms from the container
325 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
326 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
328 if (!fEventInspector.FetchHistograms(list, hEventsTr,
329 hEventsTrVtx, hTriggers)) {
330 AliError(Form("Didn't get histograms from event selector "
331 "(hEventsTr=%p,hEventsTrVtx=%p)",
332 hEventsTr, hEventsTrVtx));
337 TH2D* hData = static_cast<TH2D*>(list->FindObject("d2Ndetadphi"));
339 AliError(Form("Couldn't get our summed histogram from output "
340 "list %s (d2Ndetadphi=%p)", list->GetName(), hData));
345 // TH1D* dNdeta = fHData->ProjectionX("dNdeta", 0, -1, "e");
346 TH1D* dNdeta = hData->ProjectionX("dNdeta", 1, -1, "e");
347 TH1D* norm = hData->ProjectionX("norm", 0, 1, "");
348 dNdeta->SetTitle("dN_{ch}/d#eta in the forward regions");
349 dNdeta->SetYTitle("#frac{1}{N}#frac{dN_{ch}}{d#eta}");
350 dNdeta->Divide(norm);
352 dNdeta->Scale(Double_t(hEventsTrVtx->GetEntries())/hEventsTr->GetEntries(),
357 fEnergyFitter.Fit(list);
358 fSharingFilter.ScaleHistograms(list,hEventsTr->Integral());
359 fDensityCalculator.ScaleHistograms(list,hEventsTrVtx->Integral());
360 fCorrections.ScaleHistograms(list,hEventsTrVtx->Integral());
363 //____________________________________________________________________
365 AliForwardMultiplicityTask::MarkEventForStore() const
367 // Make sure the AOD tree is filled
368 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
370 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
372 AliFatal("No AOD output handler set in analysis manager");
374 ah->SetFillAOD(kTRUE);
377 //____________________________________________________________________
379 AliForwardMultiplicityTask::Print(Option_t* option) const
381 std::cout << "AliForwardMultiplicityTask: " << GetName() << "\n"
382 << " Enable low flux code: " << (fEnableLowFlux ? "yes" : "no")
384 gROOT->IncreaseDirLevel();
385 fEventInspector .Print(option);
386 fEnergyFitter .Print(option);
387 fSharingFilter .Print(option);
388 fDensityCalculator.Print(option);
389 fCorrections .Print(option);
390 fHistCollector .Print(option);
391 gROOT->DecreaseDirLevel();