]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG1/TRD/AliTRDrecoTask.cxx
Coverity
[u/mrichter/AliRoot.git] / PWG1 / TRD / AliTRDrecoTask.cxx
CommitLineData
94b94be0 1///////////////////////////////////////////////////////\r
2//\r
3// Basic class for Performance/Calibration TRD tasks\r
4// \r
5// It performs generic tasks like :\r
6// - data file manegment\r
7// - reference container management\r
8// - debug container management\r
9// - interaction with AliAnalysisManager\r
10// - Plot functor loop\r
11//\r
12// Author: Alexandru Bercuci <A.Bercuci@gsi.de>, 10/09/2008\r
13//\r
14/////////////////////////////////////////////////////////\r
15\r
16#include "TClass.h"\r
17#include "TMethod.h"\r
18#include "TMethodCall.h"\r
19#include "TMethodArg.h"\r
20#include "TFile.h"\r
21#include "TChain.h"\r
22#include "TList.h"\r
23#include "TMap.h"\r
24#include "TH1.h"\r
25#include "TF1.h"\r
26#include "TObjArray.h"\r
27#include "TDirectory.h"\r
28#include "TTreeStream.h"\r
29\r
30#include "AliLog.h"\r
31#include "AliAnalysisTask.h"\r
3ceb45ae 32#include "AliExternalTrackParam.h"\r
94b94be0 33\r
4860c9db 34#include "AliAnalysisManager.h"\r
94b94be0 35#include "info/AliTRDeventInfo.h"\r
36#include "AliTRDrecoTask.h"\r
3ceb45ae 37#include "AliTRDtrackV1.h"\r
38#include "AliTRDpidUtil.h"\r
94b94be0 39\r
40ClassImp(AliTRDrecoTask)\r
41\r
42TList* AliTRDrecoTask::fgTrendPoint(NULL);\r
43TTreeSRedirector* AliTRDrecoTask::fgDebugStream(NULL);\r
44//_______________________________________________________\r
45AliTRDrecoTask::AliTRDrecoTask()\r
46 : AliAnalysisTaskSE()\r
47 ,fNRefFigures(0)\r
48 ,fContainer(NULL)\r
49 ,fEvent(NULL)\r
50 ,fTracks(NULL)\r
51 ,fkTrack(NULL)\r
52 ,fkMC(NULL)\r
53 ,fkESD(NULL)\r
3ceb45ae 54 ,fSpecies(-6)\r
55 ,fPt(-1.)\r
56 ,fPhi(0.)\r
57 ,fEta(0.)\r
94b94be0 58 ,fPlotFuncList(NULL)\r
59 ,fRunTerminate(kFALSE)\r
60{\r
61// Default constructor\r
62 snprintf(fNameId, 10, "no name");\r
63}\r
64\r
65//_______________________________________________________\r
66AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)\r
67 : AliAnalysisTaskSE(name)\r
68 ,fNRefFigures(0)\r
69 ,fContainer(NULL)\r
70 ,fEvent(NULL)\r
71 ,fTracks(NULL)\r
72 ,fkTrack(NULL)\r
73 ,fkMC(NULL)\r
74 ,fkESD(NULL)\r
3ceb45ae 75 ,fSpecies(-6)\r
76 ,fPt(-1.)\r
77 ,fPhi(0.)\r
78 ,fEta(0.)\r
94b94be0 79 ,fPlotFuncList(NULL)\r
80 ,fRunTerminate(kFALSE)\r
81{\r
82// Constructor for all derived performance tasks\r
83\r
84 SetTitle(title);\r
85 snprintf(fNameId, 10, "no name");\r
86 DefineInput (1, TObjArray::Class()); // track list\r
87 DefineInput (2, AliTRDeventInfo::Class()); // event info object\r
88 DefineOutput(1, TObjArray::Class()); // histogram list\r
89}\r
90\r
91//_______________________________________________________\r
92AliTRDrecoTask::~AliTRDrecoTask() \r
93{\r
94\r
95 // Generic task destructor\r
96\r
97 AliDebug(2, Form(" Ending task %s[%s]", GetName(), GetTitle()));\r
98 if(fgDebugStream){ \r
99 delete fgDebugStream;\r
100 fgDebugStream = NULL;\r
101 }\r
102\r
103 if(fPlotFuncList){\r
104 fPlotFuncList->Delete();\r
105 delete fPlotFuncList;\r
106 fPlotFuncList = NULL;\r
107 }\r
108 \r
f0857a6a 109 if(fContainer && !(AliAnalysisManager::GetAnalysisManager() && AliAnalysisManager::GetAnalysisManager()->IsProofMode())){\r
94b94be0 110 if(fContainer->IsOwner()) fContainer->Delete();\r
111 delete fContainer;\r
112 fContainer = NULL;\r
113 }\r
114\r
115 if(fgTrendPoint){\r
116 TFile::Open("TRD.PerformanceTrend.root", "UPDATE");\r
117 fgTrendPoint->Write();\r
118 delete fgTrendPoint;\r
119 fgTrendPoint=NULL;\r
120 gFile->Close();\r
121 }\r
122}\r
123\r
124//_______________________________________________________\r
125Int_t AliTRDrecoTask::GetNRefFigures() const \r
126{ \r
127 if(!fNRefFigures) AliWarning("No reference plots available.");\r
128 return fNRefFigures; \r
129} \r
130\r
131//_______________________________________________________\r
132void AliTRDrecoTask::UserCreateOutputObjects()\r
133{\r
134 if(!HasFunctorList()) InitFunctorList();\r
135 fContainer = Histos();\r
136 PostData(1, fContainer);\r
137}\r
138\r
139//_______________________________________________________\r
140void AliTRDrecoTask::UserExec(Option_t *)\r
141{\r
142// Loop over Plot functors published by particular tasks\r
143\r
144 fTracks = dynamic_cast<TObjArray *>(GetInputData(1));\r
145 fEvent = dynamic_cast<AliTRDeventInfo *>(GetInputData(2));\r
146\r
147 if(!fPlotFuncList){\r
148 AliWarning("No functor list defined for the reference plots");\r
149 return;\r
150 }\r
151 if(!fTracks) return;\r
152 if(!fTracks->GetEntriesFast()) return;\r
153 else AliDebug(2, Form("Tracks[%d] for %s", fTracks->GetEntriesFast(), GetName()));\r
154\r
155 AliTRDtrackInfo *trackInfo = NULL;\r
156 TIter plotIter(fPlotFuncList);\r
157 TObjArrayIter trackIter(fTracks);\r
158 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){\r
159 fkTrack = trackInfo->GetTrack();\r
160 fkMC = trackInfo->GetMCinfo();\r
161 fkESD = trackInfo->GetESDinfo();\r
3ceb45ae 162 // cache properties of the track at TRD entrance\r
163 // check input track status\r
164 AliExternalTrackParam *tin(NULL);\r
165 fPt=-1; fEta=0.; fPhi=0.; fSpecies=-6;\r
166 if(!fkTrack || !(tin = fkTrack->GetTrackIn())) AliDebug(2, "Track did not entered TRD fiducial volume.");\r
167 else {\r
168 fPt = tin->Pt();\r
169 fEta = tin->Eta();\r
170 Double_t xyz[3];\r
171 if(!tin->GetXYZ(xyz)) AliDebug(2, "Failed getting global track postion");\r
172 else fPhi = TMath::ATan2(xyz[1], xyz[0]);\r
173 fSpecies= fkTrack->Charge()*(AliTRDpidUtil::Mass2Pid(fkTrack->GetMass())+1);\r
174 }\r
94b94be0 175\r
176 TMethodCall *plot = NULL;\r
177 plotIter.Reset();\r
178 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){\r
179 plot->Execute(this);\r
180 }\r
181 }\r
182}\r
183\r
184//_______________________________________________________\r
185Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)\r
186{\r
187 AliWarning("Retrieving reference figures not implemented.");\r
188 return kFALSE;\r
189}\r
190\r
191//_______________________________________________________\r
192Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)\r
193{\r
194// Generic publisher for trend values\r
195\r
196 if(!fgTrendPoint){\r
197 fgTrendPoint = new TList();\r
198 fgTrendPoint->SetOwner();\r
199 }\r
200 fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));\r
201 return kTRUE;\r
202}\r
203\r
204//_______________________________________________________\r
205void AliTRDrecoTask::InitFunctorList()\r
206{\r
207// Initialize list of functors\r
208\r
209 TClass *c = this->IsA();\r
3ed01fbe 210 if(fPlotFuncList) fPlotFuncList->Clear();\r
94b94be0 211\r
212 TMethod *m = NULL;\r
213 TIter methIter(c->GetListOfMethods());\r
214 while((m=dynamic_cast<TMethod*>(methIter()))){\r
215 TString name(m->GetName());\r
216 if(!name.BeginsWith("Plot")) continue;\r
217 if(!fPlotFuncList) fPlotFuncList = new TList();\r
218 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));\r
219 }\r
220}\r
221\r
222//_______________________________________________________\r
223Bool_t AliTRDrecoTask::Load(const Char_t *file, const Char_t *dir)\r
224{\r
225// Generic container loader\r
226\r
227 if(!TFile::Open(file)){\r
228 AliWarning(Form("Couldn't open file %s.", file));\r
229 return kFALSE;\r
230 }\r
231 if(!gFile->cd(dir)){\r
232 AliWarning(Form("Couldn't cd to %s in %s.", dir, file));\r
233 return kFALSE;\r
234 }\r
235 TObjArray *o = NULL;\r
236 if(!(o = (TObjArray*)gDirectory->Get(GetName()))){\r
237 AliWarning("Missing histogram container.");\r
238 return kFALSE;\r
239 }\r
240 fContainer = (TObjArray*)o->Clone(GetName());\r
241 gFile->Close();\r
242 return kTRUE;\r
243}\r
244\r
245//________________________________________________________\r
246Bool_t AliTRDrecoTask::Save(TObjArray * const results){\r
247 //\r
248 // Store the output graphs in a ROOT file\r
249 // Input TObject array will not be written as Key to the file,\r
250 // only content itself\r
251 //\r
252\r
253 TDirectory *cwd = gDirectory;\r
254 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;\r
255\r
256 TIterator *iter = results->MakeIterator();\r
257 TObject *inObject = NULL, *outObject = NULL;\r
258 while((inObject = iter->Next())){\r
259 outObject = inObject->Clone();\r
260 outObject->Write(NULL, TObject::kSingleKey);\r
261 }\r
262 delete iter;\r
263 gFile->Close(); delete gFile;\r
264 cwd->cd(); \r
265 return kTRUE;\r
266}\r
267\r
268//_______________________________________________________\r
269Bool_t AliTRDrecoTask::PostProcess()\r
270{\r
271// To be implemented by particular tasks\r
272\r
273 AliWarning("Post processing of reference histograms not implemented.");\r
274 return kTRUE;\r
275}\r
276\r
277//_______________________________________________________\r
278void AliTRDrecoTask::MakeSummary()\r
279{\r
280// To be implemented by particular tasks\r
281 AliWarning("Summary not available");\r
282}\r
283\r
284//_______________________________________________________\r
285void AliTRDrecoTask::SetDebugLevel(Int_t level)\r
286{\r
287// Generic debug handler\r
288\r
289 AliAnalysisTaskSE::SetDebugLevel(level);\r
290 if(DebugLevel()>=1){\r
291 AliInfo(Form("Debug Level for Task %s set to %d", GetName(), level));\r
292 TDirectory *savedir = gDirectory;\r
293 fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");\r
294 savedir->cd();\r
295 }\r
296}\r
297\r
298//____________________________________________________________________\r
299void AliTRDrecoTask::Terminate(Option_t *)\r
300{\r
301 //\r
302 // Terminate\r
303 //\r
304\r
305 if(fgDebugStream){ \r
306 delete fgDebugStream;\r
307 fgDebugStream = NULL;\r
308 }\r
309 fContainer = dynamic_cast<TObjArray *>(GetOutputData(1));\r
310 if(fContainer && fRunTerminate){\r
311 PostProcess();\r
312 MakeSummary();\r
313 }\r
314}\r
315\r
316//________________________________________________________\r
317void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const h)\r
318{\r
319// Helper function to avoid duplication of code\r
320// Make first guesses on the fit parameters\r
321\r
322 // find the intial parameters of the fit !! (thanks George)\r
323 Int_t nbinsy = Int_t(.5*h->GetNbinsX());\r
324 Double_t sum = 0.;\r
325 for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;\r
326 f->SetParLimits(0, 0., 3.*sum);\r
327 f->SetParameter(0, .9*sum);\r
328\r
329 f->SetParLimits(1, -.2, .2);\r
330 f->SetParameter(1, -0.1);\r
331\r
332 f->SetParLimits(2, 0., 4.e-1);\r
333 f->SetParameter(2, 2.e-2);\r
334 if(f->GetNpar() <= 4) return;\r
335\r
336 f->SetParLimits(3, 0., sum);\r
337 f->SetParameter(3, .1*sum);\r
338\r
339 f->SetParLimits(4, -.3, .3);\r
340 f->SetParameter(4, 0.);\r
341\r
342 f->SetParLimits(5, 0., 1.e2);\r
343 f->SetParameter(5, 2.e-1);\r
344}\r