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