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