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(0x0);
38 TTreeSRedirector* AliTRDrecoTask::fgDebugStream(0x0);
39 //_______________________________________________________
41 AliTRDrecoTask::AliTRDrecoTask()
54 AliTRDrecoTask::AliTRDrecoTask(const char *name, const char */*title*/)
55 : AliAnalysisTaskSE(name)
65 DefineInput (1, TObjArray::Class());
66 DefineOutput(1, TObjArray::Class());
69 //_______________________________________________________
70 AliTRDrecoTask::~AliTRDrecoTask()
73 // Generic task destructor
75 AliDebug(1, Form(" Ending %s (%s)\n", GetName(), GetTitle()));
82 fPlotFuncList->Delete();
88 if(fContainer->IsOwner()) fContainer->Delete();
94 TFile::Open("TRD.PerformanceTrend.root", "UPDATE");
95 fgTrendPoint->Write();
102 //_______________________________________________________
103 void AliTRDrecoTask::ConnectInputData(Option_t *)
106 // Connect input data
108 AliAnalysisTaskSE::ConnectInputData();
109 fTracks = dynamic_cast<TObjArray *>(GetInputData(1));
112 //_______________________________________________________
113 void AliTRDrecoTask::UserExec(Option_t *)
115 // Loop over Plot functors published by particular tasks
118 AliWarning("No functor list defined for the reference plots");
122 if(!fTracks->GetEntriesFast()) return;
124 AliTRDtrackInfo *trackInfo = 0x0;
125 TIter plotIter(fPlotFuncList);
126 TObjArrayIter trackIter(fTracks);
127 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
128 fkTrack = trackInfo->GetTrack();
129 fkMC = trackInfo->GetMCinfo();
130 fkESD = trackInfo->GetESDinfo();
132 TMethodCall *plot = 0x0;
134 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
138 PostData(1, fContainer);
141 //_______________________________________________________
142 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
144 AliWarning("Retrieving reference figures not implemented.");
148 //_______________________________________________________
149 Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)
151 // Generic publisher for trend values
154 fgTrendPoint = new TList();
155 fgTrendPoint->SetOwner();
157 fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));
161 //_______________________________________________________
162 void AliTRDrecoTask::InitFunctorList()
164 // Initialize list of functors
166 TClass *c = this->IsA();
169 TIter methIter(c->GetListOfMethods());
170 while((m=dynamic_cast<TMethod*>(methIter()))){
171 TString name(m->GetName());
172 if(!name.BeginsWith("Plot")) continue;
173 if(!fPlotFuncList) fPlotFuncList = new TList();
174 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
178 //_______________________________________________________
179 Bool_t AliTRDrecoTask::Load(const Char_t *filename)
181 // Generic container loader
183 if(!TFile::Open(filename)){
184 AliWarning(Form("Couldn't open file %s.", filename));
188 if(!(o = (TObjArray*)gFile->Get(GetName()))){
189 AliWarning("Missing histogram container.");
192 fContainer = (TObjArray*)o->Clone(GetName());
197 //________________________________________________________
198 Bool_t AliTRDrecoTask::Save(TObjArray * const results){
200 // Store the output graphs in a ROOT file
201 // Input TObject array will not be written as Key to the file,
202 // only content itself
205 TDirectory *cwd = gDirectory;
206 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
208 TIterator *iter = results->MakeIterator();
209 TObject *inObject = 0x0, *outObject = 0x0;
210 while((inObject = iter->Next())){
211 outObject = inObject->Clone();
212 outObject->Write(0x0, TObject::kSingleKey);
215 gFile->Close(); delete gFile;
220 //_______________________________________________________
221 Bool_t AliTRDrecoTask::PostProcess()
223 // To be implemented by particular tasks
225 AliWarning("Post processing of reference histograms not implemented.");
229 //_______________________________________________________
230 void AliTRDrecoTask::SetDebugLevel(Int_t level)
232 // Generic debug handler
236 TDirectory *savedir = gDirectory;
237 fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");
242 //____________________________________________________________________
243 void AliTRDrecoTask::Terminate(Option_t *)
250 delete fgDebugStream;
254 if(HasPostProcess()) PostProcess();
257 //________________________________________________________
258 void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const h)
260 // Helper function to avoid duplication of code
261 // Make first guesses on the fit parameters
263 // find the intial parameters of the fit !! (thanks George)
264 Int_t nbinsy = Int_t(.5*h->GetNbinsX());
266 for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
267 f->SetParLimits(0, 0., 3.*sum);
268 f->SetParameter(0, .9*sum);
270 f->SetParLimits(1, -.2, .2);
271 f->SetParameter(1, -0.1);
273 f->SetParLimits(2, 0., 4.e-1);
274 f->SetParameter(2, 2.e-2);
275 if(f->GetNpar() <= 4) return;
277 f->SetParLimits(3, 0., sum);
278 f->SetParameter(3, .1*sum);
280 f->SetParLimits(4, -.3, .3);
281 f->SetParameter(4, 0.);
283 f->SetParLimits(5, 0., 1.e2);
284 f->SetParameter(5, 2.e-1);