1 ///////////////////////////////////////////////////////
3 // Basic class for Performance/Calibration TRD tasks
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
12 // Author: Alexandru Bercuci <A.Bercuci@gsi.de>, 10/09/2008
14 /////////////////////////////////////////////////////////
18 #include "TMethodCall.h"
19 #include "TMethodArg.h"
26 #include "TObjArray.h"
27 #include "TDirectory.h"
28 #include "TTreeStream.h"
31 #include "AliAnalysisTask.h"
33 #include "AliTRDrecoTask.h"
35 ClassImp(AliTRDrecoTask)
37 TList* AliTRDrecoTask::fgTrendPoint(NULL);
38 TTreeSRedirector* AliTRDrecoTask::fgDebugStream(NULL);
39 //_______________________________________________________
40 AliTRDrecoTask::AliTRDrecoTask()
50 // Default constructor
53 //_______________________________________________________
54 AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
55 : AliAnalysisTaskSE(name)
64 // Constructor for all derived performance tasks
67 DefineInput (1, TObjArray::Class()); // track list
68 DefineOutput(1, TObjArray::Class()); // histogram list
71 //_______________________________________________________
72 AliTRDrecoTask::~AliTRDrecoTask()
75 // Generic task destructor
77 AliDebug(2, Form(" Ending task %s[%s]", GetName(), GetTitle()));
84 fPlotFuncList->Delete();
90 if(fContainer->IsOwner()) fContainer->Delete();
96 TFile::Open("TRD.PerformanceTrend.root", "UPDATE");
97 fgTrendPoint->Write();
104 //_______________________________________________________
105 Int_t AliTRDrecoTask::GetNRefFigures() const
107 if(!fNRefFigures) AliWarning("No reference plots available.");
111 //_______________________________________________________
112 void AliTRDrecoTask::UserCreateOutputObjects()
114 if(!HasFunctorList()) InitFunctorList();
115 fContainer = Histos();
116 PostData(1, fContainer);
119 //_______________________________________________________
120 void AliTRDrecoTask::UserExec(Option_t *)
122 // Loop over Plot functors published by particular tasks
124 fTracks = dynamic_cast<TObjArray *>(GetInputData(1));
126 AliWarning("No functor list defined for the reference plots");
130 if(!fTracks->GetEntriesFast()) return;
131 else AliDebug(2, Form("Tracks[%d] for %s", fTracks->GetEntriesFast(), GetName()));
133 AliTRDtrackInfo *trackInfo = NULL;
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();
141 TMethodCall *plot = NULL;
143 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
149 //_______________________________________________________
150 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
152 AliWarning("Retrieving reference figures not implemented.");
156 //_______________________________________________________
157 Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)
159 // Generic publisher for trend values
162 fgTrendPoint = new TList();
163 fgTrendPoint->SetOwner();
165 fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));
169 //_______________________________________________________
170 void AliTRDrecoTask::InitFunctorList()
172 // Initialize list of functors
174 TClass *c = this->IsA();
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, ""));
186 //_______________________________________________________
187 Bool_t AliTRDrecoTask::Load(const Char_t *file, const Char_t *dir)
189 // Generic container loader
191 if(!TFile::Open(file)){
192 AliWarning(Form("Couldn't open file %s.", file));
196 AliWarning(Form("Couldn't cd to %s in %s.", dir, file));
200 if(!(o = (TObjArray*)gDirectory->Get(GetName()))){
201 AliWarning("Missing histogram container.");
204 fContainer = (TObjArray*)o->Clone(GetName());
209 //________________________________________________________
210 Bool_t AliTRDrecoTask::Save(TObjArray * const results){
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
217 TDirectory *cwd = gDirectory;
218 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
220 TIterator *iter = results->MakeIterator();
221 TObject *inObject = NULL, *outObject = NULL;
222 while((inObject = iter->Next())){
223 outObject = inObject->Clone();
224 outObject->Write(NULL, TObject::kSingleKey);
227 gFile->Close(); delete gFile;
232 //_______________________________________________________
233 Bool_t AliTRDrecoTask::PostProcess()
235 // To be implemented by particular tasks
237 AliWarning("Post processing of reference histograms not implemented.");
241 //_______________________________________________________
242 void AliTRDrecoTask::MakeSummary()
244 // To be implemented by particular tasks
245 AliWarning("Summary not available");
248 //_______________________________________________________
249 void AliTRDrecoTask::SetDebugLevel(Int_t level)
251 // Generic debug handler
253 AliAnalysisTaskSE::SetDebugLevel(level);
255 AliInfo(Form("Debug Level for Task %s set to %d", GetName(), level));
256 TDirectory *savedir = gDirectory;
257 fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");
262 //____________________________________________________________________
263 void AliTRDrecoTask::Terminate(Option_t *)
270 delete fgDebugStream;
271 fgDebugStream = NULL;
273 fContainer = dynamic_cast<TObjArray *>(GetOutputData(1));
280 //________________________________________________________
281 void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const h)
283 // Helper function to avoid duplication of code
284 // Make first guesses on the fit parameters
286 // find the intial parameters of the fit !! (thanks George)
287 Int_t nbinsy = Int_t(.5*h->GetNbinsX());
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);
293 f->SetParLimits(1, -.2, .2);
294 f->SetParameter(1, -0.1);
296 f->SetParLimits(2, 0., 4.e-1);
297 f->SetParameter(2, 2.e-2);
298 if(f->GetNpar() <= 4) return;
300 f->SetParLimits(3, 0., sum);
301 f->SetParameter(3, .1*sum);
303 f->SetParLimits(4, -.3, .3);
304 f->SetParameter(4, 0.);
306 f->SetParLimits(5, 0., 1.e2);
307 f->SetParameter(5, 2.e-1);