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 "info/AliTRDeventInfo.h"
34 #include "AliTRDrecoTask.h"
36 ClassImp(AliTRDrecoTask)
38 TList* AliTRDrecoTask::fgTrendPoint(NULL);
39 TTreeSRedirector* AliTRDrecoTask::fgDebugStream(NULL);
40 //_______________________________________________________
41 AliTRDrecoTask::AliTRDrecoTask()
51 ,fRunTerminate(kFALSE)
53 // Default constructor
54 snprintf(fNameId, 10, "no name");
57 //_______________________________________________________
58 AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
59 : AliAnalysisTaskSE(name)
68 ,fRunTerminate(kFALSE)
70 // Constructor for all derived performance tasks
73 snprintf(fNameId, 10, "no name");
74 DefineInput (1, TObjArray::Class()); // track list
75 DefineOutput(1, TObjArray::Class()); // histogram list
78 //_______________________________________________________
79 AliTRDrecoTask::~AliTRDrecoTask()
82 // Generic task destructor
84 AliDebug(2, Form(" Ending task %s[%s]", GetName(), GetTitle()));
91 fPlotFuncList->Delete();
97 if(fContainer->IsOwner()) fContainer->Delete();
103 TFile::Open("TRD.PerformanceTrend.root", "UPDATE");
104 fgTrendPoint->Write();
111 //_______________________________________________________
112 Int_t AliTRDrecoTask::GetNRefFigures() const
114 if(!fNRefFigures) AliWarning("No reference plots available.");
118 //_______________________________________________________
119 void AliTRDrecoTask::UserCreateOutputObjects()
121 if(!HasFunctorList()) InitFunctorList();
122 fContainer = Histos();
123 PostData(1, fContainer);
126 //_______________________________________________________
127 void AliTRDrecoTask::UserExec(Option_t *)
129 // Loop over Plot functors published by particular tasks
131 fTracks = dynamic_cast<TObjArray *>(GetInputData(1));
132 fEvent = dynamic_cast<AliTRDeventInfo *>(GetInputData(2));
134 AliWarning("No functor list defined for the reference plots");
138 if(!fTracks->GetEntriesFast()) return;
139 else AliDebug(2, Form("Tracks[%d] for %s", fTracks->GetEntriesFast(), GetName()));
141 AliTRDtrackInfo *trackInfo = NULL;
142 TIter plotIter(fPlotFuncList);
143 TObjArrayIter trackIter(fTracks);
144 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
145 fkTrack = trackInfo->GetTrack();
146 fkMC = trackInfo->GetMCinfo();
147 fkESD = trackInfo->GetESDinfo();
149 TMethodCall *plot = NULL;
151 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
157 //_______________________________________________________
158 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
160 AliWarning("Retrieving reference figures not implemented.");
164 //_______________________________________________________
165 Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)
167 // Generic publisher for trend values
170 fgTrendPoint = new TList();
171 fgTrendPoint->SetOwner();
173 fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));
177 //_______________________________________________________
178 void AliTRDrecoTask::InitFunctorList()
180 // Initialize list of functors
182 TClass *c = this->IsA();
185 TIter methIter(c->GetListOfMethods());
186 while((m=dynamic_cast<TMethod*>(methIter()))){
187 TString name(m->GetName());
188 if(!name.BeginsWith("Plot")) continue;
189 if(!fPlotFuncList) fPlotFuncList = new TList();
190 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
194 //_______________________________________________________
195 Bool_t AliTRDrecoTask::Load(const Char_t *file, const Char_t *dir)
197 // Generic container loader
199 if(!TFile::Open(file)){
200 AliWarning(Form("Couldn't open file %s.", file));
204 AliWarning(Form("Couldn't cd to %s in %s.", dir, file));
208 if(!(o = (TObjArray*)gDirectory->Get(GetName()))){
209 AliWarning("Missing histogram container.");
212 fContainer = (TObjArray*)o->Clone(GetName());
217 //________________________________________________________
218 Bool_t AliTRDrecoTask::Save(TObjArray * const results){
220 // Store the output graphs in a ROOT file
221 // Input TObject array will not be written as Key to the file,
222 // only content itself
225 TDirectory *cwd = gDirectory;
226 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
228 TIterator *iter = results->MakeIterator();
229 TObject *inObject = NULL, *outObject = NULL;
230 while((inObject = iter->Next())){
231 outObject = inObject->Clone();
232 outObject->Write(NULL, TObject::kSingleKey);
235 gFile->Close(); delete gFile;
240 //_______________________________________________________
241 Bool_t AliTRDrecoTask::PostProcess()
243 // To be implemented by particular tasks
245 AliWarning("Post processing of reference histograms not implemented.");
249 //_______________________________________________________
250 void AliTRDrecoTask::MakeSummary()
252 // To be implemented by particular tasks
253 AliWarning("Summary not available");
256 //_______________________________________________________
257 void AliTRDrecoTask::SetDebugLevel(Int_t level)
259 // Generic debug handler
261 AliAnalysisTaskSE::SetDebugLevel(level);
263 AliInfo(Form("Debug Level for Task %s set to %d", GetName(), level));
264 TDirectory *savedir = gDirectory;
265 fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");
270 //____________________________________________________________________
271 void AliTRDrecoTask::Terminate(Option_t *)
278 delete fgDebugStream;
279 fgDebugStream = NULL;
281 fContainer = dynamic_cast<TObjArray *>(GetOutputData(1));
282 if(fContainer && fRunTerminate){
288 //________________________________________________________
289 void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const h)
291 // Helper function to avoid duplication of code
292 // Make first guesses on the fit parameters
294 // find the intial parameters of the fit !! (thanks George)
295 Int_t nbinsy = Int_t(.5*h->GetNbinsX());
297 for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
298 f->SetParLimits(0, 0., 3.*sum);
299 f->SetParameter(0, .9*sum);
301 f->SetParLimits(1, -.2, .2);
302 f->SetParameter(1, -0.1);
304 f->SetParLimits(2, 0., 4.e-1);
305 f->SetParameter(2, 2.e-2);
306 if(f->GetNpar() <= 4) return;
308 f->SetParLimits(3, 0., sum);
309 f->SetParameter(3, .1*sum);
311 f->SetParLimits(4, -.3, .3);
312 f->SetParameter(4, 0.);
314 f->SetParLimits(5, 0., 1.e2);
315 f->SetParameter(5, 2.e-1);