2 // Histogram and fit the energy loss distributions for the FMD
17 #include "AliFMDEnergyFitterTask.h"
19 #include "AliESDEvent.h"
20 #include "AliAODForwardMult.h"
21 #include "AliForwardCorrectionManager.h"
22 #include "AliAnalysisManager.h"
23 #include "AliAnalysisDataSlot.h"
24 #include "AliAnalysisDataContainer.h"
26 #include <TDirectory.h>
30 //====================================================================
31 AliFMDEnergyFitterTask::AliFMDEnergyFitterTask()
32 : AliAnalysisTaskSE(),
43 //____________________________________________________________________
44 AliFMDEnergyFitterTask::AliFMDEnergyFitterTask(const char* name)
45 : AliAnalysisTaskSE(name),
47 fEventInspector("event"),
48 fEnergyFitter("energy"),
57 DefineOutput(1, TList::Class());
60 //____________________________________________________________________
61 AliFMDEnergyFitterTask::AliFMDEnergyFitterTask(const AliFMDEnergyFitterTask& o)
62 : AliAnalysisTaskSE(o),
63 fFirstEvent(o.fFirstEvent),
64 fEventInspector(o.fEventInspector),
65 fEnergyFitter(o.fEnergyFitter),
72 // o Object to copy from
74 DefineOutput(1, TList::Class());
77 //____________________________________________________________________
78 AliFMDEnergyFitterTask&
79 AliFMDEnergyFitterTask::operator=(const AliFMDEnergyFitterTask& o)
82 // Assignment operator
85 // o Object to assign from
88 // Reference to this object
90 AliAnalysisTaskSE::operator=(o);
92 fFirstEvent = o.fFirstEvent;
93 fEventInspector = o.fEventInspector;
94 fEnergyFitter = o.fEnergyFitter;
100 //____________________________________________________________________
102 AliFMDEnergyFitterTask::SetDebug(Int_t dbg)
105 // Set the debug level
110 fEventInspector.SetDebug(dbg);
111 fEnergyFitter.SetDebug(dbg);
114 //____________________________________________________________________
116 AliFMDEnergyFitterTask::Init()
119 // Initialize the task
125 //____________________________________________________________________
127 AliFMDEnergyFitterTask::InitializeSubs()
130 // Initialise the sub objects and stuff. Called on first event
133 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
134 fcm.Init(fEventInspector.GetCollisionSystem(),
135 fEventInspector.GetEnergy(),
136 fEventInspector.GetField(), 0);
138 TAxis vAxis(10,-10,10);
139 fEnergyFitter.Init(eAxis);
140 fEventInspector.Init(vAxis);
143 //____________________________________________________________________
145 AliFMDEnergyFitterTask::UserCreateOutputObjects()
148 // Create output objects
153 fEventInspector.DefineOutput(fList);
154 fEnergyFitter.DefineOutput(fList);
158 //____________________________________________________________________
160 AliFMDEnergyFitterTask::UserExec(Option_t*)
163 // Process each event
169 // static Int_t cnt = 0;
171 // Get the input data
172 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
173 // AliInfo(Form("Event # %6d (esd=%p)", cnt, esd));
175 AliWarning("No ESD event found for input event");
179 // On the first event, initialize the parameters
180 if (fFirstEvent && esd->GetESDRun()) {
181 fEventInspector.ReadRunDetails(esd);
183 AliInfo(Form("Initializing with parameters from the ESD:\n"
184 " AliESDEvent::GetBeamEnergy() ->%f\n"
185 " AliESDEvent::GetBeamType() ->%s\n"
186 " AliESDEvent::GetCurrentL3() ->%f\n"
187 " AliESDEvent::GetMagneticField()->%f\n"
188 " AliESDEvent::GetRunNumber() ->%d\n",
189 esd->GetBeamEnergy(),
192 esd->GetMagneticField(),
193 esd->GetRunNumber()));
197 // AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
198 // pars->SetParametersFromESD(esd);
199 // pars->PrintStatus();
204 Bool_t lowFlux = kFALSE;
208 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux, ivz, vz);
209 if (found & AliFMDEventInspector::kNoEvent) return;
210 if (found & AliFMDEventInspector::kNoTriggers) return;
211 if (found & AliFMDEventInspector::kNoSPD) return;
212 if (found & AliFMDEventInspector::kNoFMD) return;
213 if (found & AliFMDEventInspector::kNoVertex) return;
214 if (found & AliFMDEventInspector::kBadVertex) return;
217 AliESDFMD* esdFMD = esd->GetFMDData();
218 // Do the energy stuff
219 if (!fEnergyFitter.Accumulate(*esdFMD, triggers & AliAODForwardMult::kEmpty)){
220 AliWarning("Energy fitter failed");
226 //____________________________________________________________________
228 AliFMDEnergyFitterTask::Terminate(Option_t*)
236 AliInfo(Form("Running terminate of %s", GetName()));
237 TList* list = dynamic_cast<TList*>(GetOutputData(1));
239 AliError(Form("No output list defined (%p)", GetOutputData(1)));
240 if (GetOutputData(1)) GetOutputData(1)->Print();
244 // Get our histograms from the container
245 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
246 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
248 if (!fEventInspector.FetchHistograms(list, hEventsTr,
249 hEventsTrVtx, hTriggers)) {
250 AliError(Form("Didn't get histograms from event selector "
251 "(hEventsTr=%p,hEventsTrVtx=%p)",
252 hEventsTr, hEventsTrVtx));
256 AliInfo("Fitting energy loss spectra");
257 fEnergyFitter.Fit(list);
259 // Investigate output slot
260 AliAnalysisDataSlot* oslot = GetOutputSlot(1);
262 AliAnalysisDataContainer* ocont = oslot->GetContainer();
264 TFile* ofile = ocont->GetFile();
266 AliInfo(Form("Output file %s opened with option %s (%s)",
267 ofile->GetName(), ofile->GetOption(),
268 ofile->IsWritable() ? "read-write" : "read-only"));
272 AliWarning("No output file associated with data container");
275 AliWarning("No container associated with slot 1");
278 AliWarning("Slot number 1 not defined");
280 // Temporary code to save output to a file - should be disabled once
281 // the plugin stuff works
283 TDirectory* savdir = gDirectory;
284 TFile* tmp = TFile::Open("elossfits.root", "RECREATE");
285 list->Write(list->GetName(), TObject::kSingleKey);
291 //____________________________________________________________________
293 AliFMDEnergyFitterTask::Print(Option_t*) const