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>
29 #include "AliMCEvent.h"
30 #include "AliGenHijingEventHeader.h"
31 #include "AliHeader.h"
34 //====================================================================
35 AliFMDEnergyFitterTask::AliFMDEnergyFitterTask()
36 : AliAnalysisTaskSE(),
49 //____________________________________________________________________
50 AliFMDEnergyFitterTask::AliFMDEnergyFitterTask(const char* name)
51 : AliAnalysisTaskSE(name),
53 fEventInspector("event"),
54 fEnergyFitter("energy"),
65 DefineOutput(1, TList::Class());
66 DefineOutput(2, TList::Class());
69 //____________________________________________________________________
70 AliFMDEnergyFitterTask::AliFMDEnergyFitterTask(const AliFMDEnergyFitterTask& o)
71 : AliAnalysisTaskSE(o),
72 fFirstEvent(o.fFirstEvent),
73 fEventInspector(o.fEventInspector),
74 fEnergyFitter(o.fEnergyFitter),
83 // o Object to copy from
85 DefineOutput(1, TList::Class());
86 DefineOutput(2, TList::Class());
89 //____________________________________________________________________
90 AliFMDEnergyFitterTask&
91 AliFMDEnergyFitterTask::operator=(const AliFMDEnergyFitterTask& o)
94 // Assignment operator
97 // o Object to assign from
100 // Reference to this object
102 AliAnalysisTaskSE::operator=(o);
104 fFirstEvent = o.fFirstEvent;
105 fEventInspector = o.fEventInspector;
106 fEnergyFitter = o.fEnergyFitter;
114 //____________________________________________________________________
116 AliFMDEnergyFitterTask::SetDebug(Int_t dbg)
119 // Set the debug level
124 fEventInspector.SetDebug(dbg);
125 fEnergyFitter.SetDebug(dbg);
128 //____________________________________________________________________
130 AliFMDEnergyFitterTask::Init()
133 // Initialize the task
139 //____________________________________________________________________
141 AliFMDEnergyFitterTask::InitializeSubs()
144 // Initialise the sub objects and stuff. Called on first event
147 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
148 fcm.Init(fEventInspector.GetCollisionSystem(),
149 fEventInspector.GetEnergy(),
150 fEventInspector.GetField(), 0);
152 TAxis vAxis(10,-10,10);
153 fEnergyFitter.Init(eAxis);
154 fEventInspector.Init(vAxis);
157 //____________________________________________________________________
159 AliFMDEnergyFitterTask::UserCreateOutputObjects()
162 // Create output objects
167 fEventInspector.DefineOutput(fList);
168 fEnergyFitter.DefineOutput(fList);
172 //____________________________________________________________________
174 AliFMDEnergyFitterTask::UserExec(Option_t*)
177 // Process each event
183 // static Int_t cnt = 0;
185 // Get the input data
187 AliMCEvent* mcevent = MCEvent();
189 AliHeader* header = mcevent->Header();
190 AliGenHijingEventHeader* hijingHeader = dynamic_cast<AliGenHijingEventHeader*>(header->GenEventHeader());
192 Float_t b = hijingHeader->ImpactParameter();
193 if(b<fbLow || b>fbHigh) return;
195 std::cout<<"Selecting event with impact parameter "<<b<<std::endl;
200 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
201 // AliInfo(Form("Event # %6d (esd=%p)", cnt, esd));
203 AliWarning("No ESD event found for input event");
207 // On the first event, initialize the parameters
208 if (fFirstEvent && esd->GetESDRun()) {
209 fEventInspector.ReadRunDetails(esd);
211 AliInfo(Form("Initializing with parameters from the ESD:\n"
212 " AliESDEvent::GetBeamEnergy() ->%f\n"
213 " AliESDEvent::GetBeamType() ->%s\n"
214 " AliESDEvent::GetCurrentL3() ->%f\n"
215 " AliESDEvent::GetMagneticField()->%f\n"
216 " AliESDEvent::GetRunNumber() ->%d\n",
217 esd->GetBeamEnergy(),
220 esd->GetMagneticField(),
221 esd->GetRunNumber()));
225 // AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
226 // pars->SetParametersFromESD(esd);
227 // pars->PrintStatus();
232 Bool_t lowFlux = kFALSE;
237 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux,
239 if (found & AliFMDEventInspector::kNoEvent) return;
240 if (found & AliFMDEventInspector::kNoTriggers) return;
241 if (found & AliFMDEventInspector::kNoSPD) return;
242 if (found & AliFMDEventInspector::kNoFMD) return;
243 if (found & AliFMDEventInspector::kNoVertex) return;
244 if (found & AliFMDEventInspector::kBadVertex) return;
247 // if( cent < 40 || cent >50 ) return;
248 // else std::cout<<"selecting event with cent "<<cent<<std::endl;
252 AliESDFMD* esdFMD = esd->GetFMDData();
253 // Do the energy stuff
254 if (!fEnergyFitter.Accumulate(*esdFMD, cent,
255 triggers & AliAODForwardMult::kEmpty)){
256 AliWarning("Energy fitter failed");
262 //____________________________________________________________________
264 AliFMDEnergyFitterTask::Terminate(Option_t*)
272 AliInfo(Form("Running terminate of %s", GetName()));
273 TList* list = dynamic_cast<TList*>(GetOutputData(1));
275 AliError(Form("No output list defined (%p)", GetOutputData(1)));
276 if (GetOutputData(1)) GetOutputData(1)->Print();
281 // Get our histograms from the container
282 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
283 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
285 if (!fEventInspector.FetchHistograms(list, hEventsTr,
286 hEventsTrVtx, hTriggers)) {
287 AliError(Form("Didn't get histograms from event selector "
288 "(hEventsTr=%p,hEventsTrVtx=%p)",
289 hEventsTr, hEventsTrVtx));
294 AliInfo("Fitting energy loss spectra");
295 fEnergyFitter.Fit(list);
297 // Make a deep copy and post that as output 2
298 TList* list2 = static_cast<TList*>(list->Clone(Form("%sResults",
302 // Temporary code to save output to a file - should be disabled once
303 // the plugin stuff works
305 TDirectory* savdir = gDirectory;
306 TFile* tmp = TFile::Open("elossfits.root", "RECREATE");
307 list->Write(list->GetName(), TObject::kSingleKey);
314 //____________________________________________________________________
316 AliFMDEnergyFitterTask::Print(Option_t*) const