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"
25 #include "TObjArray.h"
26 #include "TDirectory.h"
27 #include "TTreeStream.h"
30 #include "AliAnalysisTask.h"
32 #include "AliTRDrecoTask.h"
34 ClassImp(AliTRDrecoTask)
36 TList* AliTRDrecoTask::fgTrendPoint(0x0);
37 TTreeSRedirector* AliTRDrecoTask::fgDebugStream(0x0);
38 //_______________________________________________________
39 AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
40 : AliAnalysisTask(name, title)
50 DefineInput(0, TObjArray::Class());
51 DefineOutput(0, TObjArray::Class());
54 //_______________________________________________________
55 AliTRDrecoTask::~AliTRDrecoTask()
58 // Generic task destructor
60 AliDebug(1, Form(" Ending %s (%s)\n", GetName(), GetTitle()));
67 fPlotFuncList->Delete();
73 if(fContainer->IsOwner()) fContainer->Delete();
79 TFile::Open("TRD.PerformanceTrend.root", "UPDATE");
80 fgTrendPoint->Write();
87 //_______________________________________________________
88 void AliTRDrecoTask::ConnectInputData(Option_t *)
94 fTracks = dynamic_cast<TObjArray *>(GetInputData(0));
97 //_______________________________________________________
98 void AliTRDrecoTask::Exec(Option_t *)
100 // Loop over Plot functors published by particular tasks
103 AliWarning("No functor list defined for the reference plots");
107 if(!fTracks->GetEntriesFast()) return;
109 AliTRDtrackInfo *trackInfo = 0x0;
110 TIter plotIter(fPlotFuncList);
111 TObjArrayIter trackIter(fTracks);
112 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
113 fkTrack = trackInfo->GetTrack();
114 fkMC = trackInfo->GetMCinfo();
115 fkESD = trackInfo->GetESDinfo();
117 TMethodCall *plot = 0x0;
119 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
123 PostData(0, fContainer);
126 //_______________________________________________________
127 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
129 AliWarning("Retrieving reference figures not implemented.");
133 //_______________________________________________________
134 Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)
136 // Generic publisher for trend values
139 fgTrendPoint = new TList();
140 fgTrendPoint->SetOwner();
142 fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));
146 //_______________________________________________________
147 void AliTRDrecoTask::InitFunctorList()
149 // Initialize list of functors
151 TClass *c = this->IsA();
154 TIter methIter(c->GetListOfMethods());
155 while((m=dynamic_cast<TMethod*>(methIter()))){
156 TString name(m->GetName());
157 if(!name.BeginsWith("Plot")) continue;
158 if(!fPlotFuncList) fPlotFuncList = new TList();
159 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
163 //_______________________________________________________
164 Bool_t AliTRDrecoTask::Load(const Char_t *filename)
166 // Generic container loader
168 if(!TFile::Open(filename)){
169 AliWarning(Form("Couldn't open file %s.", filename));
173 if(!(o = (TObjArray*)gFile->Get(GetName()))){
174 AliWarning("Missing histogram container.");
177 fContainer = (TObjArray*)o->Clone(GetName());
182 //________________________________________________________
183 Bool_t AliTRDrecoTask::Save(TObjArray * const results){
185 // Store the output graphs in a ROOT file
186 // Input TObject array will not be written as Key to the file,
187 // only content itself
190 TDirectory *cwd = gDirectory;
191 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
193 TIterator *iter = results->MakeIterator();
194 TObject *inObject = 0x0, *outObject = 0x0;
195 while((inObject = iter->Next())){
196 outObject = inObject->Clone();
197 outObject->Write(0x0, TObject::kSingleKey);
200 gFile->Close(); delete gFile;
205 //_______________________________________________________
206 Bool_t AliTRDrecoTask::PostProcess()
208 // To be implemented by particular tasks
210 AliWarning("Post processing of reference histograms not implemented.");
214 //_______________________________________________________
215 void AliTRDrecoTask::SetDebugLevel(Int_t level)
217 // Generic debug handler
221 TDirectory *savedir = gDirectory;
222 fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");
227 //____________________________________________________________________
228 void AliTRDrecoTask::Terminate(Option_t *)
235 delete fgDebugStream;
239 if(HasPostProcess()) PostProcess();
242 //________________________________________________________
243 void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const h)
245 // Helper function to avoid duplication of code
246 // Make first guesses on the fit parameters
248 // find the intial parameters of the fit !! (thanks George)
249 Int_t nbinsy = Int_t(.5*h->GetNbinsX());
251 for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
252 f->SetParLimits(0, 0., 3.*sum);
253 f->SetParameter(0, .9*sum);
255 f->SetParLimits(1, -.2, .2);
256 f->SetParameter(1, -0.1);
258 f->SetParLimits(2, 0., 4.e-1);
259 f->SetParameter(2, 2.e-2);
260 if(f->GetNpar() <= 4) return;
262 f->SetParLimits(3, 0., sum);
263 f->SetParameter(3, .1*sum);
265 f->SetParLimits(4, -.3, .3);
266 f->SetParameter(4, 0.);
268 f->SetParLimits(5, 0., 1.e2);
269 f->SetParameter(5, 2.e-1);