]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG1/TRD/AliTRDrecoTask.cxx
Warnings corrected.
[u/mrichter/AliRoot.git] / PWG1 / TRD / AliTRDrecoTask.cxx
CommitLineData
1ee39b3a 1///////////////////////////////////////////////////////
2//
3// Basic class for Performance/Calibration TRD tasks
4//
5// It performs generic tasks like :
6// - data file manegment
7// - reference container management
8// - debug container management
9// - interaction with AliAnalysisManager
10// - Plot functor loop
11//
12// Author: Alexandru Bercuci <A.Bercuci@gsi.de>, 10/09/2008
13//
14/////////////////////////////////////////////////////////
15
16#include "TClass.h"
17#include "TMethod.h"
18#include "TMethodCall.h"
19#include "TMethodArg.h"
20#include "TFile.h"
f8f46e4d 21#include "TChain.h"
1ee39b3a 22#include "TList.h"
23#include "TMap.h"
24#include "TH1.h"
25#include "TF1.h"
26#include "TObjArray.h"
27#include "TDirectory.h"
28#include "TTreeStream.h"
29
30#include "AliLog.h"
31#include "AliAnalysisTask.h"
32
33#include "AliTRDrecoTask.h"
34
35ClassImp(AliTRDrecoTask)
36
37TList* AliTRDrecoTask::fgTrendPoint(0x0);
38TTreeSRedirector* AliTRDrecoTask::fgDebugStream(0x0);
39//_______________________________________________________
f8f46e4d 40
41AliTRDrecoTask::AliTRDrecoTask()
42 : AliAnalysisTaskSE()
43 ,fNRefFigures(0)
44 ,fContainer(0x0)
45 ,fTracks(0x0)
46 ,fkTrack(0x0)
47 ,fkMC(0x0)
48 ,fkESD(0x0)
59bc7110 49 ,fDebugLevel(0)
f8f46e4d 50 ,fPlotFuncList(0x0)
51{
52}
53
54AliTRDrecoTask::AliTRDrecoTask(const char *name, const char */*title*/)
55 : AliAnalysisTaskSE(name)
1ee39b3a 56 ,fNRefFigures(0)
57 ,fContainer(0x0)
58 ,fTracks(0x0)
59 ,fkTrack(0x0)
60 ,fkMC(0x0)
61 ,fkESD(0x0)
59bc7110 62 ,fDebugLevel(0)
1ee39b3a 63 ,fPlotFuncList(0x0)
64{
f8f46e4d 65 DefineInput (1, TObjArray::Class());
66 DefineOutput(1, TObjArray::Class());
1ee39b3a 67}
68
69//_______________________________________________________
70AliTRDrecoTask::~AliTRDrecoTask()
71{
72
73 // Generic task destructor
74
75 AliDebug(1, Form(" Ending %s (%s)\n", GetName(), GetTitle()));
76 if(fgDebugStream){
77 delete fgDebugStream;
78 fgDebugStream = 0x0;
79 }
80
81 if(fPlotFuncList){
82 fPlotFuncList->Delete();
83 delete fPlotFuncList;
84 fPlotFuncList = 0x0;
85 }
86
87 if(fContainer){
88 if(fContainer->IsOwner()) fContainer->Delete();
89 delete fContainer;
90 fContainer = 0x0;
91 }
92
93 if(fgTrendPoint){
94 TFile::Open("TRD.PerformanceTrend.root", "UPDATE");
95 fgTrendPoint->Write();
96 delete fgTrendPoint;
97 fgTrendPoint=0x0;
98 gFile->Close();
99 }
100}
101
102//_______________________________________________________
103void AliTRDrecoTask::ConnectInputData(Option_t *)
104{
105 //
106 // Connect input data
107 //
f8f46e4d 108 AliAnalysisTaskSE::ConnectInputData();
109 fTracks = dynamic_cast<TObjArray *>(GetInputData(1));
1ee39b3a 110}
111
112//_______________________________________________________
f8f46e4d 113void AliTRDrecoTask::UserExec(Option_t *)
1ee39b3a 114{
115// Loop over Plot functors published by particular tasks
116
117 if(!fPlotFuncList){
118 AliWarning("No functor list defined for the reference plots");
119 return;
120 }
121 if(!fTracks) return;
122 if(!fTracks->GetEntriesFast()) return;
123
124 AliTRDtrackInfo *trackInfo = 0x0;
125 TIter plotIter(fPlotFuncList);
126 TObjArrayIter trackIter(fTracks);
127 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
128 fkTrack = trackInfo->GetTrack();
129 fkMC = trackInfo->GetMCinfo();
130 fkESD = trackInfo->GetESDinfo();
131
132 TMethodCall *plot = 0x0;
133 plotIter.Reset();
134 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
135 plot->Execute(this);
136 }
137 }
f8f46e4d 138 PostData(1, fContainer);
1ee39b3a 139}
140
141//_______________________________________________________
142Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
143{
144 AliWarning("Retrieving reference figures not implemented.");
145 return kFALSE;
146}
147
148//_______________________________________________________
149Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)
150{
151// Generic publisher for trend values
152
153 if(!fgTrendPoint){
154 fgTrendPoint = new TList();
155 fgTrendPoint->SetOwner();
156 }
157 fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));
158 return kTRUE;
159}
160
161//_______________________________________________________
162void AliTRDrecoTask::InitFunctorList()
163{
164// Initialize list of functors
165
166 TClass *c = this->IsA();
167
168 TMethod *m = 0x0;
169 TIter methIter(c->GetListOfMethods());
170 while((m=dynamic_cast<TMethod*>(methIter()))){
171 TString name(m->GetName());
172 if(!name.BeginsWith("Plot")) continue;
173 if(!fPlotFuncList) fPlotFuncList = new TList();
174 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
175 }
176}
177
178//_______________________________________________________
179Bool_t AliTRDrecoTask::Load(const Char_t *filename)
180{
181// Generic container loader
182
183 if(!TFile::Open(filename)){
184 AliWarning(Form("Couldn't open file %s.", filename));
185 return kFALSE;
186 }
187 TObjArray *o = 0x0;
188 if(!(o = (TObjArray*)gFile->Get(GetName()))){
189 AliWarning("Missing histogram container.");
190 return kFALSE;
191 }
192 fContainer = (TObjArray*)o->Clone(GetName());
193 gFile->Close();
194 return kTRUE;
195}
196
197//________________________________________________________
198Bool_t AliTRDrecoTask::Save(TObjArray * const results){
199 //
200 // Store the output graphs in a ROOT file
201 // Input TObject array will not be written as Key to the file,
202 // only content itself
203 //
204
205 TDirectory *cwd = gDirectory;
206 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
207
208 TIterator *iter = results->MakeIterator();
209 TObject *inObject = 0x0, *outObject = 0x0;
210 while((inObject = iter->Next())){
211 outObject = inObject->Clone();
212 outObject->Write(0x0, TObject::kSingleKey);
213 }
214 delete iter;
215 gFile->Close(); delete gFile;
216 cwd->cd();
217 return kTRUE;
218}
219
220//_______________________________________________________
221Bool_t AliTRDrecoTask::PostProcess()
222{
223// To be implemented by particular tasks
224
225 AliWarning("Post processing of reference histograms not implemented.");
226 return kFALSE;
227}
228
229//_______________________________________________________
230void AliTRDrecoTask::SetDebugLevel(Int_t level)
231{
232// Generic debug handler
233
f8f46e4d 234 fDebug = level;
235 if(fDebug>=1){
1ee39b3a 236 TDirectory *savedir = gDirectory;
237 fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");
238 savedir->cd();
239 }
240}
241
242//____________________________________________________________________
243void AliTRDrecoTask::Terminate(Option_t *)
244{
245 //
246 // Terminate
247 //
248
249 if(fgDebugStream){
250 delete fgDebugStream;
251 fgDebugStream = 0x0;
f8f46e4d 252 fDebug = 0;
1ee39b3a 253 }
254 if(HasPostProcess()) PostProcess();
255}
256
257//________________________________________________________
258void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const h)
259{
260// Helper function to avoid duplication of code
261// Make first guesses on the fit parameters
262
263 // find the intial parameters of the fit !! (thanks George)
264 Int_t nbinsy = Int_t(.5*h->GetNbinsX());
265 Double_t sum = 0.;
266 for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
267 f->SetParLimits(0, 0., 3.*sum);
268 f->SetParameter(0, .9*sum);
269
270 f->SetParLimits(1, -.2, .2);
271 f->SetParameter(1, -0.1);
272
273 f->SetParLimits(2, 0., 4.e-1);
274 f->SetParameter(2, 2.e-2);
275 if(f->GetNpar() <= 4) return;
276
277 f->SetParLimits(3, 0., sum);
278 f->SetParameter(3, .1*sum);
279
280 f->SetParLimits(4, -.3, .3);
281 f->SetParameter(4, 0.);
282
283 f->SetParLimits(5, 0., 1.e2);
284 f->SetParameter(5, 2.e-1);
285}