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