]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/AliFMDEnergyFitterTask.cxx
adding new track QA task running on ESD and AOD, bug fixes to QAMC (M. Verweij)
[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>
e58000b7 29#include "AliMCEvent.h"
30#include "AliGenHijingEventHeader.h"
31#include "AliHeader.h"
32#include <iostream>
0bd4b00f 33
34//====================================================================
35AliFMDEnergyFitterTask::AliFMDEnergyFitterTask()
36 : AliAnalysisTaskSE(),
37 fFirstEvent(true),
38 fEventInspector(),
39 fEnergyFitter(),
6f4c294b 40 fList(0),
41 fbLow(0),
42 fbHigh(100)
0bd4b00f 43{
7984e5f7 44 //
45 // Constructor
46 //
0bd4b00f 47}
48
49//____________________________________________________________________
50AliFMDEnergyFitterTask::AliFMDEnergyFitterTask(const char* name)
51 : AliAnalysisTaskSE(name),
52 fFirstEvent(true),
53 fEventInspector("event"),
54 fEnergyFitter("energy"),
e58000b7 55 fList(0),
56 fbLow(0),
57 fbHigh(100)
0bd4b00f 58{
7984e5f7 59 //
60 // Constructor
61 //
62 // Parameters:
63 // name Name of task
64 //
0bd4b00f 65 DefineOutput(1, TList::Class());
8e2bb72a 66 DefineOutput(2, TList::Class());
0bd4b00f 67}
68
69//____________________________________________________________________
70AliFMDEnergyFitterTask::AliFMDEnergyFitterTask(const AliFMDEnergyFitterTask& o)
71 : AliAnalysisTaskSE(o),
72 fFirstEvent(o.fFirstEvent),
73 fEventInspector(o.fEventInspector),
74 fEnergyFitter(o.fEnergyFitter),
6f4c294b 75 fList(o.fList),
76 fbLow(o.fbLow),
77 fbHigh(o.fbHigh)
0bd4b00f 78{
7984e5f7 79 //
80 // Copy constructor
81 //
82 // Parameters:
83 // o Object to copy from
84 //
0bd4b00f 85 DefineOutput(1, TList::Class());
8e2bb72a 86 DefineOutput(2, TList::Class());
0bd4b00f 87}
88
89//____________________________________________________________________
90AliFMDEnergyFitterTask&
91AliFMDEnergyFitterTask::operator=(const AliFMDEnergyFitterTask& o)
92{
7984e5f7 93 //
94 // Assignment operator
95 //
96 // Parameters:
97 // o Object to assign from
98 //
99 // Return:
100 // Reference to this object
101 //
0bd4b00f 102 AliAnalysisTaskSE::operator=(o);
103
104 fFirstEvent = o.fFirstEvent;
105 fEventInspector = o.fEventInspector;
106 fEnergyFitter = o.fEnergyFitter;
107 fList = o.fList;
6f4c294b 108 fbLow = o.fbLow;
109 fbHigh = o.fbHigh;
0bd4b00f 110
111 return *this;
112}
113
114//____________________________________________________________________
115void
116AliFMDEnergyFitterTask::SetDebug(Int_t dbg)
117{
7984e5f7 118 //
119 // Set the debug level
120 //
121 // Parameters:
122 // dbg Debug level
123 //
0bd4b00f 124 fEventInspector.SetDebug(dbg);
125 fEnergyFitter.SetDebug(dbg);
126}
127
128//____________________________________________________________________
129void
130AliFMDEnergyFitterTask::Init()
131{
7984e5f7 132 //
133 // Initialize the task
134 //
135 //
0bd4b00f 136 fFirstEvent = true;
137}
138
139//____________________________________________________________________
140void
141AliFMDEnergyFitterTask::InitializeSubs()
142{
7984e5f7 143 //
144 // Initialise the sub objects and stuff. Called on first event
145 //
146 //
0bd4b00f 147 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
148 fcm.Init(fEventInspector.GetCollisionSystem(),
149 fEventInspector.GetEnergy(),
150 fEventInspector.GetField(), 0);
151 TAxis eAxis(0,0,0);
152 TAxis vAxis(10,-10,10);
153 fEnergyFitter.Init(eAxis);
154 fEventInspector.Init(vAxis);
155}
156
157//____________________________________________________________________
158void
159AliFMDEnergyFitterTask::UserCreateOutputObjects()
160{
7984e5f7 161 //
162 // Create output objects
163 //
164 //
0bd4b00f 165 fList = new TList;
166
167 fEventInspector.DefineOutput(fList);
168 fEnergyFitter.DefineOutput(fList);
169
170 PostData(1, fList);
171}
172//____________________________________________________________________
173void
174AliFMDEnergyFitterTask::UserExec(Option_t*)
175{
7984e5f7 176 //
177 // Process each event
178 //
179 // Parameters:
180 // option Not used
181 //
182
0bd4b00f 183 // static Int_t cnt = 0;
184 // cnt++;
185 // Get the input data
e58000b7 186
187 AliMCEvent* mcevent = MCEvent();
188 if(mcevent) {
189 AliHeader* header = mcevent->Header();
e58000b7 190 AliGenHijingEventHeader* hijingHeader = dynamic_cast<AliGenHijingEventHeader*>(header->GenEventHeader());
191 if(hijingHeader) {
192 Float_t b = hijingHeader->ImpactParameter();
193 if(b<fbLow || b>fbHigh) return;
194 else
195 std::cout<<"Selecting event with impact parameter "<<b<<std::endl;
196 }
197
198 }
199
0bd4b00f 200 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
201 // AliInfo(Form("Event # %6d (esd=%p)", cnt, esd));
202 if (!esd) {
203 AliWarning("No ESD event found for input event");
204 return;
205 }
206
207 // On the first event, initialize the parameters
208 if (fFirstEvent && esd->GetESDRun()) {
209 fEventInspector.ReadRunDetails(esd);
210
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(),
218 esd->GetBeamType(),
219 esd->GetCurrentL3(),
220 esd->GetMagneticField(),
221 esd->GetRunNumber()));
222
223
224
225 // AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
226 // pars->SetParametersFromESD(esd);
227 // pars->PrintStatus();
228 fFirstEvent = false;
229
230 InitializeSubs();
231 }
232 Bool_t lowFlux = kFALSE;
233 UInt_t triggers = 0;
234 UShort_t ivz = 0;
235 Double_t vz = 0;
5e4d905e 236 Double_t cent = 0;
237 UInt_t found = fEventInspector.Process(esd, triggers, lowFlux,
238 ivz, vz, cent);
0bd4b00f 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;
245
246 // Get FMD data
247 AliESDFMD* esdFMD = esd->GetFMDData();
248 // Do the energy stuff
5e4d905e 249 if (!fEnergyFitter.Accumulate(*esdFMD, cent,
250 triggers & AliAODForwardMult::kEmpty)){
0bd4b00f 251 AliWarning("Energy fitter failed");
252 return;
253 }
254 PostData(1, fList);
255}
256
257//____________________________________________________________________
258void
259AliFMDEnergyFitterTask::Terminate(Option_t*)
260{
7984e5f7 261 //
262 // End of job
263 //
264 // Parameters:
265 // option Not used
266 //
1c762251 267 AliInfo(Form("Running terminate of %s", GetName()));
0bd4b00f 268 TList* list = dynamic_cast<TList*>(GetOutputData(1));
269 if (!list) {
270 AliError(Form("No output list defined (%p)", GetOutputData(1)));
271 if (GetOutputData(1)) GetOutputData(1)->Print();
272 return;
273 }
274
8e2bb72a 275#if 0
0bd4b00f 276 // Get our histograms from the container
277 TH1I* hEventsTr = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
278 TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
279 TH1I* hTriggers = 0;
280 if (!fEventInspector.FetchHistograms(list, hEventsTr,
281 hEventsTrVtx, hTriggers)) {
282 AliError(Form("Didn't get histograms from event selector "
283 "(hEventsTr=%p,hEventsTrVtx=%p)",
284 hEventsTr, hEventsTrVtx));
285 list->ls();
286 return;
287 }
8e2bb72a 288#endif
1c762251 289 AliInfo("Fitting energy loss spectra");
0bd4b00f 290 fEnergyFitter.Fit(list);
72cc12cd 291
8e2bb72a 292 // Make a deep copy and post that as output 2
293 TList* list2 = static_cast<TList*>(list->Clone(Form("%sResults",
294 list->GetName())));
295 PostData(2, list2);
296#if 0
72cc12cd 297 // Temporary code to save output to a file - should be disabled once
298 // the plugin stuff works
299 list->ls();
300 TDirectory* savdir = gDirectory;
301 TFile* tmp = TFile::Open("elossfits.root", "RECREATE");
302 list->Write(list->GetName(), TObject::kSingleKey);
303 tmp->Write();
304 tmp->Close();
305 savdir->cd();
8e2bb72a 306#endif
0bd4b00f 307}
308
309//____________________________________________________________________
310void
311AliFMDEnergyFitterTask::Print(Option_t*) const
312{
7984e5f7 313 //
314 // Print information
315 //
316 // Parameters:
317 // option Not used
318 //
0bd4b00f 319}
320
321//
322// EOF
323//