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