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()
53 //_______________________________________________________
54 AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
55 : AliAnalysisTaskSE(name)
66 DefineInput (1, TObjArray::Class());
67 DefineOutput(1, TObjArray::Class());
70 //_______________________________________________________
71 AliTRDrecoTask::~AliTRDrecoTask()
74 // Generic task destructor
76 AliDebug(1, Form(" Ending %s (%s)\n", GetName(), GetTitle()));
83 fPlotFuncList->Delete();
89 if(fContainer->IsOwner()) fContainer->Delete();
95 TFile::Open("TRD.PerformanceTrend.root", "UPDATE");
96 fgTrendPoint->Write();
103 //_______________________________________________________
104 void AliTRDrecoTask::ConnectInputData(Option_t *)
107 // Connect input data
109 AliAnalysisTaskSE::ConnectInputData();
110 fTracks = dynamic_cast<TObjArray *>(GetInputData(1));
113 //_______________________________________________________
114 void AliTRDrecoTask::UserExec(Option_t *)
116 // Loop over Plot functors published by particular tasks
119 AliWarning("No functor list defined for the reference plots");
123 if(!fTracks->GetEntriesFast()) return;
125 AliTRDtrackInfo *trackInfo = NULL;
126 TIter plotIter(fPlotFuncList);
127 TObjArrayIter trackIter(fTracks);
128 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
129 fkTrack = trackInfo->GetTrack();
130 fkMC = trackInfo->GetMCinfo();
131 fkESD = trackInfo->GetESDinfo();
133 TMethodCall *plot = NULL;
135 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
139 PostData(1, fContainer);
142 //_______________________________________________________
143 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
145 AliWarning("Retrieving reference figures not implemented.");
149 //_______________________________________________________
150 Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)
152 // Generic publisher for trend values
155 fgTrendPoint = new TList();
156 fgTrendPoint->SetOwner();
158 fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));
162 //_______________________________________________________
163 void AliTRDrecoTask::InitFunctorList()
165 // Initialize list of functors
167 TClass *c = this->IsA();
170 TIter methIter(c->GetListOfMethods());
171 while((m=dynamic_cast<TMethod*>(methIter()))){
172 TString name(m->GetName());
173 if(!name.BeginsWith("Plot")) continue;
174 if(!fPlotFuncList) fPlotFuncList = new TList();
175 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
179 //_______________________________________________________
180 Bool_t AliTRDrecoTask::Load(const Char_t *filename)
182 // Generic container loader
184 if(!TFile::Open(filename)){
185 AliWarning(Form("Couldn't open file %s.", filename));
189 if(!(o = (TObjArray*)gFile->Get(GetName()))){
190 AliWarning("Missing histogram container.");
193 fContainer = (TObjArray*)o->Clone(GetName());
198 //________________________________________________________
199 Bool_t AliTRDrecoTask::Save(TObjArray * const results){
201 // Store the output graphs in a ROOT file
202 // Input TObject array will not be written as Key to the file,
203 // only content itself
206 TDirectory *cwd = gDirectory;
207 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
209 TIterator *iter = results->MakeIterator();
210 TObject *inObject = NULL, *outObject = NULL;
211 while((inObject = iter->Next())){
212 outObject = inObject->Clone();
213 outObject->Write(NULL, TObject::kSingleKey);
216 gFile->Close(); delete gFile;
221 //_______________________________________________________
222 Bool_t AliTRDrecoTask::PostProcess()
224 // To be implemented by particular tasks
226 AliWarning("Post processing of reference histograms not implemented.");
230 //_______________________________________________________
231 void AliTRDrecoTask::SetDebugLevel(Int_t level)
233 // Generic debug handler
237 TDirectory *savedir = gDirectory;
238 fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");
243 //____________________________________________________________________
244 void AliTRDrecoTask::Terminate(Option_t *)
251 delete fgDebugStream;
252 fgDebugStream = NULL;
255 if(HasPostProcess()) PostProcess();
258 //________________________________________________________
259 void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const h)
261 // Helper function to avoid duplication of code
262 // Make first guesses on the fit parameters
264 // find the intial parameters of the fit !! (thanks George)
265 Int_t nbinsy = Int_t(.5*h->GetNbinsX());
267 for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
268 f->SetParLimits(0, 0., 3.*sum);
269 f->SetParameter(0, .9*sum);
271 f->SetParLimits(1, -.2, .2);
272 f->SetParameter(1, -0.1);
274 f->SetParLimits(2, 0., 4.e-1);
275 f->SetParameter(2, 2.e-2);
276 if(f->GetNpar() <= 4) return;
278 f->SetParLimits(3, 0., sum);
279 f->SetParameter(3, .1*sum);
281 f->SetParLimits(4, -.3, .3);
282 f->SetParameter(4, 0.);
284 f->SetParLimits(5, 0., 1.e2);
285 f->SetParameter(5, 2.e-1);