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(1, Form(" Ending %s (%s)\n", GetName(), GetTitle()));
84 fPlotFuncList->Delete();
90 if(fContainer->IsOwner()) fContainer->Delete();
96 TFile::Open("TRD.PerformanceTrend.root", "UPDATE");
97 fgTrendPoint->Write();
104 //_______________________________________________________
105 void AliTRDrecoTask::ConnectInputData(Option_t *)
108 // Connect input data
110 AliAnalysisTaskSE::ConnectInputData();
111 fTracks = dynamic_cast<TObjArray *>(GetInputData(1));
114 //_______________________________________________________
115 void AliTRDrecoTask::UserExec(Option_t *)
117 // Loop over Plot functors published by particular tasks
120 AliWarning("No functor list defined for the reference plots");
124 if(!fTracks->GetEntriesFast()) return;
126 AliTRDtrackInfo *trackInfo = NULL;
127 TIter plotIter(fPlotFuncList);
128 TObjArrayIter trackIter(fTracks);
129 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
130 fkTrack = trackInfo->GetTrack();
131 fkMC = trackInfo->GetMCinfo();
132 fkESD = trackInfo->GetESDinfo();
134 TMethodCall *plot = NULL;
136 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
140 PostData(1, fContainer);
143 //_______________________________________________________
144 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
146 AliWarning("Retrieving reference figures not implemented.");
150 //_______________________________________________________
151 Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)
153 // Generic publisher for trend values
156 fgTrendPoint = new TList();
157 fgTrendPoint->SetOwner();
159 fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));
163 //_______________________________________________________
164 void AliTRDrecoTask::InitFunctorList()
166 // Initialize list of functors
168 TClass *c = this->IsA();
171 TIter methIter(c->GetListOfMethods());
172 while((m=dynamic_cast<TMethod*>(methIter()))){
173 TString name(m->GetName());
174 if(!name.BeginsWith("Plot")) continue;
175 if(!fPlotFuncList) fPlotFuncList = new TList();
176 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
180 //_______________________________________________________
181 Bool_t AliTRDrecoTask::Load(const Char_t *filename)
183 // Generic container loader
185 if(!TFile::Open(filename)){
186 AliWarning(Form("Couldn't open file %s.", filename));
190 if(!(o = (TObjArray*)gFile->Get(GetName()))){
191 AliWarning("Missing histogram container.");
194 fContainer = (TObjArray*)o->Clone(GetName());
199 //________________________________________________________
200 Bool_t AliTRDrecoTask::Save(TObjArray * const results){
202 // Store the output graphs in a ROOT file
203 // Input TObject array will not be written as Key to the file,
204 // only content itself
207 TDirectory *cwd = gDirectory;
208 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
210 TIterator *iter = results->MakeIterator();
211 TObject *inObject = NULL, *outObject = NULL;
212 while((inObject = iter->Next())){
213 outObject = inObject->Clone();
214 outObject->Write(NULL, TObject::kSingleKey);
217 gFile->Close(); delete gFile;
222 //_______________________________________________________
223 Bool_t AliTRDrecoTask::PostProcess()
225 // To be implemented by particular tasks
227 AliWarning("Post processing of reference histograms not implemented.");
231 //_______________________________________________________
232 void AliTRDrecoTask::SetDebugLevel(Int_t level)
234 // Generic debug handler
236 AliAnalysisTaskSE::SetDebugLevel(level);
238 TDirectory *savedir = gDirectory;
239 fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");
244 //____________________________________________________________________
245 void AliTRDrecoTask::Terminate(Option_t *)
252 delete fgDebugStream;
253 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);