]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/AliFMDEnergyFitterTask.cxx
Preliminary work to get centrality in
[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;
5e4d905e 210 Double_t cent = 0;
211 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux,
212 ivz, vz, cent);
0bd4b00f 213 if (found & AliFMDEventInspector::kNoEvent) return;
214 if (found & AliFMDEventInspector::kNoTriggers) return;
215 if (found & AliFMDEventInspector::kNoSPD) return;
216 if (found & AliFMDEventInspector::kNoFMD) return;
217 if (found & AliFMDEventInspector::kNoVertex) return;
218 if (found & AliFMDEventInspector::kBadVertex) return;
219
220 // Get FMD data
221 AliESDFMD* esdFMD = esd->GetFMDData();
222 // Do the energy stuff
5e4d905e 223 if (!fEnergyFitter.Accumulate(*esdFMD, cent,
224 triggers & AliAODForwardMult::kEmpty)){
0bd4b00f 225 AliWarning("Energy fitter failed");
226 return;
227 }
228 PostData(1, fList);
229}
230
231//____________________________________________________________________
232void
233AliFMDEnergyFitterTask::Terminate(Option_t*)
234{
7984e5f7 235 //
236 // End of job
237 //
238 // Parameters:
239 // option Not used
240 //
1c762251 241 AliInfo(Form("Running terminate of %s", GetName()));
0bd4b00f 242 TList* list = dynamic_cast<TList*>(GetOutputData(1));
243 if (!list) {
244 AliError(Form("No output list defined (%p)", GetOutputData(1)));
245 if (GetOutputData(1)) GetOutputData(1)->Print();
246 return;
247 }
248
8e2bb72a 249#if 0
0bd4b00f 250 // Get our histograms from the container
251 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
252 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
253 TH1I* hTriggers = 0;
254 if (!fEventInspector.FetchHistograms(list, hEventsTr,
255 hEventsTrVtx, hTriggers)) {
256 AliError(Form("Didn't get histograms from event selector "
257 "(hEventsTr=%p,hEventsTrVtx=%p)",
258 hEventsTr, hEventsTrVtx));
259 list->ls();
260 return;
261 }
8e2bb72a 262#endif
1c762251 263 AliInfo("Fitting energy loss spectra");
0bd4b00f 264 fEnergyFitter.Fit(list);
72cc12cd 265
8e2bb72a 266 // Make a deep copy and post that as output 2
267 TList* list2 = static_cast<TList*>(list->Clone(Form("%sResults",
268 list->GetName())));
269 PostData(2, list2);
270#if 0
72cc12cd 271 // Temporary code to save output to a file - should be disabled once
272 // the plugin stuff works
273 list->ls();
274 TDirectory* savdir = gDirectory;
275 TFile* tmp = TFile::Open("elossfits.root", "RECREATE");
276 list->Write(list->GetName(), TObject::kSingleKey);
277 tmp->Write();
278 tmp->Close();
279 savdir->cd();
8e2bb72a 280#endif
0bd4b00f 281}
282
283//____________________________________________________________________
284void
285AliFMDEnergyFitterTask::Print(Option_t*) const
286{
7984e5f7 287 //
288 // Print information
289 //
290 // Parameters:
291 // option Not used
292 //
0bd4b00f 293}
294
295//
296// EOF
297//