]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/AliFMDEnergyFitterTask.cxx
Renamed
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliFMDEnergyFitterTask.cxx
1 #include "AliFMDEnergyFitterTask.h"
2 #include "AliLog.h"
3 // #include "AliFMDAnaParameters.h"
4 #include "AliESDEvent.h"
5 #include "AliAODForwardMult.h"
6 #include "AliForwardCorrectionManager.h"
7 #include "AliAnalysisManager.h"
8 #include <TH1.h>
9 #include <TDirectory.h>
10 #include <TTree.h>
11
12 //====================================================================
13 AliFMDEnergyFitterTask::AliFMDEnergyFitterTask()
14   : AliAnalysisTaskSE(),
15     fFirstEvent(true),
16     fEventInspector(),
17     fEnergyFitter(),
18     fList(0)
19 {
20 }
21
22 //____________________________________________________________________
23 AliFMDEnergyFitterTask::AliFMDEnergyFitterTask(const char* name)
24   : AliAnalysisTaskSE(name), 
25     fFirstEvent(true),
26     fEventInspector("event"),
27     fEnergyFitter("energy"),
28     fList(0)
29 {
30   DefineOutput(1, TList::Class());
31 }
32
33 //____________________________________________________________________
34 AliFMDEnergyFitterTask::AliFMDEnergyFitterTask(const AliFMDEnergyFitterTask& o)
35   : AliAnalysisTaskSE(o),
36     fFirstEvent(o.fFirstEvent),
37     fEventInspector(o.fEventInspector),
38     fEnergyFitter(o.fEnergyFitter),
39     fList(o.fList) 
40 {
41   DefineOutput(1, TList::Class());
42 }
43
44 //____________________________________________________________________
45 AliFMDEnergyFitterTask&
46 AliFMDEnergyFitterTask::operator=(const AliFMDEnergyFitterTask& o)
47 {
48   AliAnalysisTaskSE::operator=(o);
49
50   fFirstEvent        = o.fFirstEvent;
51   fEventInspector    = o.fEventInspector;
52   fEnergyFitter      = o.fEnergyFitter;
53   fList              = o.fList;
54
55   return *this;
56 }
57
58 //____________________________________________________________________
59 void
60 AliFMDEnergyFitterTask::SetDebug(Int_t dbg)
61 {
62   fEventInspector.SetDebug(dbg);
63   fEnergyFitter.SetDebug(dbg);
64 }
65
66 //____________________________________________________________________
67 void
68 AliFMDEnergyFitterTask::Init()
69 {
70   fFirstEvent = true;
71 }
72
73 //____________________________________________________________________
74 void
75 AliFMDEnergyFitterTask::InitializeSubs()
76 {
77
78   // AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
79   // pars->Init(kTRUE);
80
81   AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
82   fcm.Init(fEventInspector.GetCollisionSystem(), 
83            fEventInspector.GetEnergy(),
84            fEventInspector.GetField(), 0);
85   TAxis eAxis(0,0,0);
86   TAxis vAxis(10,-10,10);
87   fEnergyFitter.Init(eAxis);
88   fEventInspector.Init(vAxis);
89 }
90
91 //____________________________________________________________________
92 void
93 AliFMDEnergyFitterTask::UserCreateOutputObjects()
94 {
95   fList = new TList;
96
97   fEventInspector.DefineOutput(fList);
98   fEnergyFitter.DefineOutput(fList);
99
100   PostData(1, fList);
101 }
102 //____________________________________________________________________
103 void
104 AliFMDEnergyFitterTask::UserExec(Option_t*)
105 {
106   // static Int_t cnt = 0;
107   // cnt++;
108   // Get the input data 
109   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
110   // AliInfo(Form("Event # %6d (esd=%p)", cnt, esd));
111   if (!esd) { 
112     AliWarning("No ESD event found for input event");
113     return;
114   }
115
116   // On the first event, initialize the parameters 
117   if (fFirstEvent && esd->GetESDRun()) { 
118     fEventInspector.ReadRunDetails(esd);
119     
120     AliInfo(Form("Initializing with parameters from the ESD:\n"
121                  "         AliESDEvent::GetBeamEnergy()   ->%f\n"
122                  "         AliESDEvent::GetBeamType()     ->%s\n"
123                  "         AliESDEvent::GetCurrentL3()    ->%f\n"
124                  "         AliESDEvent::GetMagneticField()->%f\n"
125                  "         AliESDEvent::GetRunNumber()    ->%d\n",
126                  esd->GetBeamEnergy(), 
127                  esd->GetBeamType(),
128                  esd->GetCurrentL3(), 
129                  esd->GetMagneticField(),
130                  esd->GetRunNumber()));
131
132               
133
134     // AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
135     // pars->SetParametersFromESD(esd);
136     // pars->PrintStatus();
137     fFirstEvent = false;
138
139     InitializeSubs();
140   }
141   Bool_t   lowFlux  = kFALSE;
142   UInt_t   triggers = 0;
143   UShort_t ivz      = 0;
144   Double_t vz       = 0;
145   UInt_t   found    = fEventInspector.Process(esd, triggers, lowFlux, ivz, vz);
146   if (found & AliFMDEventInspector::kNoEvent)    return;
147   if (found & AliFMDEventInspector::kNoTriggers) return;
148   if (found & AliFMDEventInspector::kNoSPD)     return;
149   if (found & AliFMDEventInspector::kNoFMD)     return;
150   if (found & AliFMDEventInspector::kNoVertex)  return;
151   if (found & AliFMDEventInspector::kBadVertex) return;
152
153   // Get FMD data 
154   AliESDFMD* esdFMD = esd->GetFMDData();
155   // Do the energy stuff 
156   if (!fEnergyFitter.Accumulate(*esdFMD, triggers & AliAODForwardMult::kEmpty)){
157     AliWarning("Energy fitter failed");
158     return;
159   }
160   PostData(1, fList);
161 }
162
163 //____________________________________________________________________
164 void
165 AliFMDEnergyFitterTask::Terminate(Option_t*)
166 {
167   TList* list = dynamic_cast<TList*>(GetOutputData(1));
168   if (!list) {
169     AliError(Form("No output list defined (%p)", GetOutputData(1)));
170     if (GetOutputData(1)) GetOutputData(1)->Print();
171     return;
172   }
173   
174   // Get our histograms from the container 
175   TH1I* hEventsTr    = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
176   TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
177   TH1I* hTriggers    = 0;
178   if (!fEventInspector.FetchHistograms(list, hEventsTr, 
179                                        hEventsTrVtx, hTriggers)) { 
180     AliError(Form("Didn't get histograms from event selector "
181                   "(hEventsTr=%p,hEventsTrVtx=%p)", 
182                   hEventsTr, hEventsTrVtx));
183     list->ls();
184     return;
185   }
186   fEnergyFitter.Fit(list);
187 }
188
189 //____________________________________________________________________
190 void
191 AliFMDEnergyFitterTask::Print(Option_t*) const
192 {
193 }
194
195 //
196 // EOF
197 //