]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/AliFMDEnergyFitterTask.cxx
coverity fix
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliFMDEnergyFitterTask.cxx
CommitLineData
7984e5f7 1//
2// Histogram and fit the energy loss distributions for the FMD
3//
4// Inputs:
5// - AliESDEvent
6//
7// Outputs:
8// - None
9//
10// Histograms:
11//
12// Corrections used:
13// - None
14//
15//
16//
0bd4b00f 17#include "AliFMDEnergyFitterTask.h"
18#include "AliLog.h"
0bd4b00f 19#include "AliESDEvent.h"
20#include "AliAODForwardMult.h"
21#include "AliForwardCorrectionManager.h"
22#include "AliAnalysisManager.h"
72cc12cd 23#include "AliAnalysisDataSlot.h"
24#include "AliAnalysisDataContainer.h"
0bd4b00f 25#include <TH1.h>
26#include <TDirectory.h>
27#include <TTree.h>
72cc12cd 28#include <TFile.h>
0bd4b00f 29
30//====================================================================
31AliFMDEnergyFitterTask::AliFMDEnergyFitterTask()
32 : AliAnalysisTaskSE(),
33 fFirstEvent(true),
34 fEventInspector(),
35 fEnergyFitter(),
36 fList(0)
37{
7984e5f7 38 //
39 // Constructor
40 //
0bd4b00f 41}
42
43//____________________________________________________________________
44AliFMDEnergyFitterTask::AliFMDEnergyFitterTask(const char* name)
45 : AliAnalysisTaskSE(name),
46 fFirstEvent(true),
47 fEventInspector("event"),
48 fEnergyFitter("energy"),
49 fList(0)
50{
7984e5f7 51 //
52 // Constructor
53 //
54 // Parameters:
55 // name Name of task
56 //
0bd4b00f 57 DefineOutput(1, TList::Class());
8e2bb72a 58 DefineOutput(2, TList::Class());
0bd4b00f 59}
60
61//____________________________________________________________________
62AliFMDEnergyFitterTask::AliFMDEnergyFitterTask(const AliFMDEnergyFitterTask& o)
63 : AliAnalysisTaskSE(o),
64 fFirstEvent(o.fFirstEvent),
65 fEventInspector(o.fEventInspector),
66 fEnergyFitter(o.fEnergyFitter),
67 fList(o.fList)
68{
7984e5f7 69 //
70 // Copy constructor
71 //
72 // Parameters:
73 // o Object to copy from
74 //
0bd4b00f 75 DefineOutput(1, TList::Class());
8e2bb72a 76 DefineOutput(2, TList::Class());
0bd4b00f 77}
78
79//____________________________________________________________________
80AliFMDEnergyFitterTask&
81AliFMDEnergyFitterTask::operator=(const AliFMDEnergyFitterTask& o)
82{
7984e5f7 83 //
84 // Assignment operator
85 //
86 // Parameters:
87 // o Object to assign from
88 //
89 // Return:
90 // Reference to this object
91 //
0bd4b00f 92 AliAnalysisTaskSE::operator=(o);
93
94 fFirstEvent = o.fFirstEvent;
95 fEventInspector = o.fEventInspector;
96 fEnergyFitter = o.fEnergyFitter;
97 fList = o.fList;
98
99 return *this;
100}
101
102//____________________________________________________________________
103void
104AliFMDEnergyFitterTask::SetDebug(Int_t dbg)
105{
7984e5f7 106 //
107 // Set the debug level
108 //
109 // Parameters:
110 // dbg Debug level
111 //
0bd4b00f 112 fEventInspector.SetDebug(dbg);
113 fEnergyFitter.SetDebug(dbg);
114}
115
116//____________________________________________________________________
117void
118AliFMDEnergyFitterTask::Init()
119{
7984e5f7 120 //
121 // Initialize the task
122 //
123 //
0bd4b00f 124 fFirstEvent = true;
125}
126
127//____________________________________________________________________
128void
129AliFMDEnergyFitterTask::InitializeSubs()
130{
7984e5f7 131 //
132 // Initialise the sub objects and stuff. Called on first event
133 //
134 //
0bd4b00f 135 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
136 fcm.Init(fEventInspector.GetCollisionSystem(),
137 fEventInspector.GetEnergy(),
138 fEventInspector.GetField(), 0);
139 TAxis eAxis(0,0,0);
140 TAxis vAxis(10,-10,10);
141 fEnergyFitter.Init(eAxis);
142 fEventInspector.Init(vAxis);
143}
144
145//____________________________________________________________________
146void
147AliFMDEnergyFitterTask::UserCreateOutputObjects()
148{
7984e5f7 149 //
150 // Create output objects
151 //
152 //
0bd4b00f 153 fList = new TList;
154
155 fEventInspector.DefineOutput(fList);
156 fEnergyFitter.DefineOutput(fList);
157
158 PostData(1, fList);
159}
160//____________________________________________________________________
161void
162AliFMDEnergyFitterTask::UserExec(Option_t*)
163{
7984e5f7 164 //
165 // Process each event
166 //
167 // Parameters:
168 // option Not used
169 //
170
0bd4b00f 171 // static Int_t cnt = 0;
172 // cnt++;
173 // Get the input data
174 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
175 // AliInfo(Form("Event # %6d (esd=%p)", cnt, esd));
176 if (!esd) {
177 AliWarning("No ESD event found for input event");
178 return;
179 }
180
181 // On the first event, initialize the parameters
182 if (fFirstEvent && esd->GetESDRun()) {
183 fEventInspector.ReadRunDetails(esd);
184
185 AliInfo(Form("Initializing with parameters from the ESD:\n"
186 " AliESDEvent::GetBeamEnergy() ->%f\n"
187 " AliESDEvent::GetBeamType() ->%s\n"
188 " AliESDEvent::GetCurrentL3() ->%f\n"
189 " AliESDEvent::GetMagneticField()->%f\n"
190 " AliESDEvent::GetRunNumber() ->%d\n",
191 esd->GetBeamEnergy(),
192 esd->GetBeamType(),
193 esd->GetCurrentL3(),
194 esd->GetMagneticField(),
195 esd->GetRunNumber()));
196
197
198
199 // AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
200 // pars->SetParametersFromESD(esd);
201 // pars->PrintStatus();
202 fFirstEvent = false;
203
204 InitializeSubs();
205 }
206 Bool_t lowFlux = kFALSE;
207 UInt_t triggers = 0;
208 UShort_t ivz = 0;
209 Double_t vz = 0;
210 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux, ivz, vz);
211 if (found & AliFMDEventInspector::kNoEvent) return;
212 if (found & AliFMDEventInspector::kNoTriggers) return;
213 if (found & AliFMDEventInspector::kNoSPD) return;
214 if (found & AliFMDEventInspector::kNoFMD) return;
215 if (found & AliFMDEventInspector::kNoVertex) return;
216 if (found & AliFMDEventInspector::kBadVertex) return;
217
218 // Get FMD data
219 AliESDFMD* esdFMD = esd->GetFMDData();
220 // Do the energy stuff
221 if (!fEnergyFitter.Accumulate(*esdFMD, triggers & AliAODForwardMult::kEmpty)){
222 AliWarning("Energy fitter failed");
223 return;
224 }
225 PostData(1, fList);
226}
227
228//____________________________________________________________________
229void
230AliFMDEnergyFitterTask::Terminate(Option_t*)
231{
7984e5f7 232 //
233 // End of job
234 //
235 // Parameters:
236 // option Not used
237 //
1c762251 238 AliInfo(Form("Running terminate of %s", GetName()));
0bd4b00f 239 TList* list = dynamic_cast<TList*>(GetOutputData(1));
240 if (!list) {
241 AliError(Form("No output list defined (%p)", GetOutputData(1)));
242 if (GetOutputData(1)) GetOutputData(1)->Print();
243 return;
244 }
245
8e2bb72a 246#if 0
0bd4b00f 247 // Get our histograms from the container
248 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
249 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
250 TH1I* hTriggers = 0;
251 if (!fEventInspector.FetchHistograms(list, hEventsTr,
252 hEventsTrVtx, hTriggers)) {
253 AliError(Form("Didn't get histograms from event selector "
254 "(hEventsTr=%p,hEventsTrVtx=%p)",
255 hEventsTr, hEventsTrVtx));
256 list->ls();
257 return;
258 }
8e2bb72a 259#endif
1c762251 260 AliInfo("Fitting energy loss spectra");
0bd4b00f 261 fEnergyFitter.Fit(list);
72cc12cd 262
8e2bb72a 263 // Make a deep copy and post that as output 2
264 TList* list2 = static_cast<TList*>(list->Clone(Form("%sResults",
265 list->GetName())));
266 PostData(2, list2);
267#if 0
72cc12cd 268 // Temporary code to save output to a file - should be disabled once
269 // the plugin stuff works
270 list->ls();
271 TDirectory* savdir = gDirectory;
272 TFile* tmp = TFile::Open("elossfits.root", "RECREATE");
273 list->Write(list->GetName(), TObject::kSingleKey);
274 tmp->Write();
275 tmp->Close();
276 savdir->cd();
8e2bb72a 277#endif
0bd4b00f 278}
279
280//____________________________________________________________________
281void
282AliFMDEnergyFitterTask::Print(Option_t*) const
283{
7984e5f7 284 //
285 // Print information
286 //
287 // Parameters:
288 // option Not used
289 //
0bd4b00f 290}
291
292//
293// EOF
294//