1 ///////////////////////////////////////////////////////
\r
3 // Basic class for Performance/Calibration TRD tasks
\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
12 // Author: Alexandru Bercuci <A.Bercuci@gsi.de>, 10/09/2008
\r
14 /////////////////////////////////////////////////////////
\r
17 #include "TMethod.h"
\r
18 #include "TMethodCall.h"
\r
19 #include "TMethodArg.h"
\r
26 #include "TObjArray.h"
\r
27 #include "TDirectory.h"
\r
28 #include "TTreeStream.h"
\r
31 #include "AliAnalysisTask.h"
\r
33 #include "info/AliTRDeventInfo.h"
\r
34 #include "AliTRDrecoTask.h"
\r
36 ClassImp(AliTRDrecoTask)
\r
38 TList* AliTRDrecoTask::fgTrendPoint(NULL);
\r
39 TTreeSRedirector* AliTRDrecoTask::fgDebugStream(NULL);
\r
40 //_______________________________________________________
\r
41 AliTRDrecoTask::AliTRDrecoTask()
\r
42 : AliAnalysisTaskSE()
\r
50 ,fPlotFuncList(NULL)
\r
51 ,fRunTerminate(kFALSE)
\r
53 // Default constructor
\r
54 snprintf(fNameId, 10, "no name");
\r
57 //_______________________________________________________
\r
58 AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
\r
59 : AliAnalysisTaskSE(name)
\r
67 ,fPlotFuncList(NULL)
\r
68 ,fRunTerminate(kFALSE)
\r
70 // Constructor for all derived performance tasks
\r
73 snprintf(fNameId, 10, "no name");
\r
74 DefineInput (1, TObjArray::Class()); // track list
\r
75 DefineInput (2, AliTRDeventInfo::Class()); // event info object
\r
76 DefineOutput(1, TObjArray::Class()); // histogram list
\r
79 //_______________________________________________________
\r
80 AliTRDrecoTask::~AliTRDrecoTask()
\r
83 // Generic task destructor
\r
85 AliDebug(2, Form(" Ending task %s[%s]", GetName(), GetTitle()));
\r
87 delete fgDebugStream;
\r
88 fgDebugStream = NULL;
\r
92 fPlotFuncList->Delete();
\r
93 delete fPlotFuncList;
\r
94 fPlotFuncList = NULL;
\r
98 if(fContainer->IsOwner()) fContainer->Delete();
\r
104 TFile::Open("TRD.PerformanceTrend.root", "UPDATE");
\r
105 fgTrendPoint->Write();
\r
106 delete fgTrendPoint;
\r
112 //_______________________________________________________
\r
113 Int_t AliTRDrecoTask::GetNRefFigures() const
\r
115 if(!fNRefFigures) AliWarning("No reference plots available.");
\r
116 return fNRefFigures;
\r
119 //_______________________________________________________
\r
120 void AliTRDrecoTask::UserCreateOutputObjects()
\r
122 if(!HasFunctorList()) InitFunctorList();
\r
123 fContainer = Histos();
\r
124 PostData(1, fContainer);
\r
127 //_______________________________________________________
\r
128 void AliTRDrecoTask::UserExec(Option_t *)
\r
130 // Loop over Plot functors published by particular tasks
\r
132 fTracks = dynamic_cast<TObjArray *>(GetInputData(1));
\r
133 fEvent = dynamic_cast<AliTRDeventInfo *>(GetInputData(2));
\r
135 if(!fPlotFuncList){
\r
136 AliWarning("No functor list defined for the reference plots");
\r
139 if(!fTracks) return;
\r
140 if(!fTracks->GetEntriesFast()) return;
\r
141 else AliDebug(2, Form("Tracks[%d] for %s", fTracks->GetEntriesFast(), GetName()));
\r
143 AliTRDtrackInfo *trackInfo = NULL;
\r
144 TIter plotIter(fPlotFuncList);
\r
145 TObjArrayIter trackIter(fTracks);
\r
146 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
\r
147 fkTrack = trackInfo->GetTrack();
\r
148 fkMC = trackInfo->GetMCinfo();
\r
149 fkESD = trackInfo->GetESDinfo();
\r
151 TMethodCall *plot = NULL;
\r
153 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
\r
154 plot->Execute(this);
\r
159 //_______________________________________________________
\r
160 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
\r
162 AliWarning("Retrieving reference figures not implemented.");
\r
166 //_______________________________________________________
\r
167 Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)
\r
169 // Generic publisher for trend values
\r
172 fgTrendPoint = new TList();
\r
173 fgTrendPoint->SetOwner();
\r
175 fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));
\r
179 //_______________________________________________________
\r
180 void AliTRDrecoTask::InitFunctorList()
\r
182 // Initialize list of functors
\r
184 TClass *c = this->IsA();
\r
187 TIter methIter(c->GetListOfMethods());
\r
188 while((m=dynamic_cast<TMethod*>(methIter()))){
\r
189 TString name(m->GetName());
\r
190 if(!name.BeginsWith("Plot")) continue;
\r
191 if(!fPlotFuncList) fPlotFuncList = new TList();
\r
192 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
\r
196 //_______________________________________________________
\r
197 Bool_t AliTRDrecoTask::Load(const Char_t *file, const Char_t *dir)
\r
199 // Generic container loader
\r
201 if(!TFile::Open(file)){
\r
202 AliWarning(Form("Couldn't open file %s.", file));
\r
205 if(!gFile->cd(dir)){
\r
206 AliWarning(Form("Couldn't cd to %s in %s.", dir, file));
\r
209 TObjArray *o = NULL;
\r
210 if(!(o = (TObjArray*)gDirectory->Get(GetName()))){
\r
211 AliWarning("Missing histogram container.");
\r
214 fContainer = (TObjArray*)o->Clone(GetName());
\r
219 //________________________________________________________
\r
220 Bool_t AliTRDrecoTask::Save(TObjArray * const results){
\r
222 // Store the output graphs in a ROOT file
\r
223 // Input TObject array will not be written as Key to the file,
\r
224 // only content itself
\r
227 TDirectory *cwd = gDirectory;
\r
228 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
\r
230 TIterator *iter = results->MakeIterator();
\r
231 TObject *inObject = NULL, *outObject = NULL;
\r
232 while((inObject = iter->Next())){
\r
233 outObject = inObject->Clone();
\r
234 outObject->Write(NULL, TObject::kSingleKey);
\r
237 gFile->Close(); delete gFile;
\r
242 //_______________________________________________________
\r
243 Bool_t AliTRDrecoTask::PostProcess()
\r
245 // To be implemented by particular tasks
\r
247 AliWarning("Post processing of reference histograms not implemented.");
\r
251 //_______________________________________________________
\r
252 void AliTRDrecoTask::MakeSummary()
\r
254 // To be implemented by particular tasks
\r
255 AliWarning("Summary not available");
\r
258 //_______________________________________________________
\r
259 void AliTRDrecoTask::SetDebugLevel(Int_t level)
\r
261 // Generic debug handler
\r
263 AliAnalysisTaskSE::SetDebugLevel(level);
\r
264 if(DebugLevel()>=1){
\r
265 AliInfo(Form("Debug Level for Task %s set to %d", GetName(), level));
\r
266 TDirectory *savedir = gDirectory;
\r
267 fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");
\r
272 //____________________________________________________________________
\r
273 void AliTRDrecoTask::Terminate(Option_t *)
\r
279 if(fgDebugStream){
\r
280 delete fgDebugStream;
\r
281 fgDebugStream = NULL;
\r
283 fContainer = dynamic_cast<TObjArray *>(GetOutputData(1));
\r
284 if(fContainer && fRunTerminate){
\r
290 //________________________________________________________
\r
291 void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const h)
\r
293 // Helper function to avoid duplication of code
\r
294 // Make first guesses on the fit parameters
\r
296 // find the intial parameters of the fit !! (thanks George)
\r
297 Int_t nbinsy = Int_t(.5*h->GetNbinsX());
\r
299 for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
\r
300 f->SetParLimits(0, 0., 3.*sum);
\r
301 f->SetParameter(0, .9*sum);
\r
303 f->SetParLimits(1, -.2, .2);
\r
304 f->SetParameter(1, -0.1);
\r
306 f->SetParLimits(2, 0., 4.e-1);
\r
307 f->SetParameter(2, 2.e-2);
\r
308 if(f->GetNpar() <= 4) return;
\r
310 f->SetParLimits(3, 0., sum);
\r
311 f->SetParameter(3, .1*sum);
\r
313 f->SetParLimits(4, -.3, .3);
\r
314 f->SetParameter(4, 0.);
\r
316 f->SetParLimits(5, 0., 1.e2);
\r
317 f->SetParameter(5, 2.e-1);
\r