1 ///////////////////////////////////////////////////////
\r
3 // Basic class for Performance/Calibration TRD tasks
\r
5 // It performs generic tasks like :
\r
6 // - data file manegment
\r
7 // - reference container management
\r
8 // - debug container management
\r
9 // - interaction with AliAnalysisManager
\r
10 // - Plot functor loop
\r
12 // Author: Alexandru Bercuci <A.Bercuci@gsi.de>, 10/09/2008
\r
14 /////////////////////////////////////////////////////////
\r
17 #include "TMethod.h"
\r
18 #include "TMethodCall.h"
\r
19 #include "TMethodArg.h"
\r
26 #include "TObjArray.h"
\r
27 #include "TDirectory.h"
\r
28 #include "TTreeStream.h"
\r
31 #include "AliAnalysisTask.h"
\r
32 #include "AliExternalTrackParam.h"
\r
34 #include "AliAnalysisManager.h"
\r
35 #include "info/AliTRDeventInfo.h"
\r
36 #include "AliTRDrecoTask.h"
\r
37 #include "AliTRDtrackV1.h"
\r
38 #include "AliTRDpidUtil.h"
\r
40 ClassImp(AliTRDrecoTask)
\r
42 TList* AliTRDrecoTask::fgTrendPoint(NULL);
\r
43 TTreeSRedirector* AliTRDrecoTask::fgDebugStream(NULL);
\r
44 //_______________________________________________________
\r
45 AliTRDrecoTask::AliTRDrecoTask()
\r
46 : AliAnalysisTaskSE()
\r
58 ,fPlotFuncList(NULL)
\r
59 ,fRunTerminate(kFALSE)
\r
61 // Default constructor
\r
62 snprintf(fNameId, 10, "no name");
\r
65 //_______________________________________________________
\r
66 AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
\r
67 : AliAnalysisTaskSE(name)
\r
79 ,fPlotFuncList(NULL)
\r
80 ,fRunTerminate(kFALSE)
\r
82 // Constructor for all derived performance tasks
\r
85 snprintf(fNameId, 10, "no name");
\r
86 DefineInput (1, TObjArray::Class()); // track list
\r
87 DefineInput (2, AliTRDeventInfo::Class()); // event info object
\r
88 DefineOutput(1, TObjArray::Class()); // histogram list
\r
91 //_______________________________________________________
\r
92 AliTRDrecoTask::~AliTRDrecoTask()
\r
95 // Generic task destructor
\r
97 AliDebug(2, Form(" Ending task %s[%s]", GetName(), GetTitle()));
\r
99 delete fgDebugStream;
\r
100 fgDebugStream = NULL;
\r
104 fPlotFuncList->Delete();
\r
105 delete fPlotFuncList;
\r
106 fPlotFuncList = NULL;
\r
109 if(fContainer && !(AliAnalysisManager::GetAnalysisManager() && AliAnalysisManager::GetAnalysisManager()->IsProofMode())){
\r
110 if(fContainer->IsOwner()) fContainer->Delete();
\r
116 TFile::Open("TRD.PerformanceTrend.root", "UPDATE");
\r
117 fgTrendPoint->Write();
\r
118 delete fgTrendPoint;
\r
124 //_______________________________________________________
\r
125 Int_t AliTRDrecoTask::GetNRefFigures() const
\r
127 if(!fNRefFigures) AliWarning("No reference plots available.");
\r
128 return fNRefFigures;
\r
131 //_______________________________________________________
\r
132 void AliTRDrecoTask::UserCreateOutputObjects()
\r
134 if(!HasFunctorList()) InitFunctorList();
\r
135 fContainer = Histos();
\r
136 PostData(1, fContainer);
\r
139 //_______________________________________________________
\r
140 void AliTRDrecoTask::UserExec(Option_t *)
\r
142 // Loop over Plot functors published by particular tasks
\r
144 fTracks = dynamic_cast<TObjArray *>(GetInputData(1));
\r
145 fEvent = dynamic_cast<AliTRDeventInfo *>(GetInputData(2));
\r
147 if(!fPlotFuncList){
\r
148 AliWarning("No functor list defined for the reference plots");
\r
151 if(!fTracks) return;
\r
152 if(!fTracks->GetEntriesFast()) return;
\r
153 else AliDebug(2, Form("Tracks[%d] for %s", fTracks->GetEntriesFast(), GetName()));
\r
155 AliTRDtrackInfo *trackInfo = NULL;
\r
156 TIter plotIter(fPlotFuncList);
\r
157 TObjArrayIter trackIter(fTracks);
\r
158 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
\r
159 fkTrack = trackInfo->GetTrack();
\r
160 fkMC = trackInfo->GetMCinfo();
\r
161 fkESD = trackInfo->GetESDinfo();
\r
162 // cache properties of the track at TRD entrance
\r
163 // check input track status
\r
164 AliExternalTrackParam *tin(NULL);
\r
165 fPt=-1; fEta=0.; fPhi=0.; fSpecies=-6;
\r
166 if(!fkTrack || !(tin = fkTrack->GetTrackIn())) AliDebug(2, "Track did not entered TRD fiducial volume.");
\r
171 if(!tin->GetXYZ(xyz)) AliDebug(2, "Failed getting global track postion");
\r
172 else fPhi = TMath::ATan2(xyz[1], xyz[0]);
\r
173 fSpecies= fkTrack->Charge()*(AliTRDpidUtil::Mass2Pid(fkTrack->GetMass())+1);
\r
176 TMethodCall *plot = NULL;
\r
178 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
\r
179 plot->Execute(this);
\r
184 //_______________________________________________________
\r
185 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
\r
187 AliWarning("Retrieving reference figures not implemented.");
\r
191 //_______________________________________________________
\r
192 Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)
\r
194 // Generic publisher for trend values
\r
197 fgTrendPoint = new TList();
\r
198 fgTrendPoint->SetOwner();
\r
200 fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));
\r
204 //_______________________________________________________
\r
205 void AliTRDrecoTask::InitFunctorList()
\r
207 // Initialize list of functors
\r
209 TClass *c = this->IsA();
\r
210 if(fPlotFuncList) fPlotFuncList->Clear();
\r
213 TIter methIter(c->GetListOfMethods());
\r
214 while((m=dynamic_cast<TMethod*>(methIter()))){
\r
215 TString name(m->GetName());
\r
216 if(!name.BeginsWith("Plot")) continue;
\r
217 if(!fPlotFuncList) fPlotFuncList = new TList();
\r
218 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
\r
222 //_______________________________________________________
\r
223 Bool_t AliTRDrecoTask::Load(const Char_t *file, const Char_t *dir)
\r
225 // Generic container loader
\r
227 if(!TFile::Open(file)){
\r
228 AliWarning(Form("Couldn't open file %s.", file));
\r
231 if(!gFile->cd(dir)){
\r
232 AliWarning(Form("Couldn't cd to %s in %s.", dir, file));
\r
235 TObjArray *o = NULL;
\r
236 if(!(o = (TObjArray*)gDirectory->Get(GetName()))){
\r
237 AliWarning("Missing histogram container.");
\r
240 fContainer = (TObjArray*)o->Clone(GetName());
\r
245 //________________________________________________________
\r
246 Bool_t AliTRDrecoTask::Save(TObjArray * const results){
\r
248 // Store the output graphs in a ROOT file
\r
249 // Input TObject array will not be written as Key to the file,
\r
250 // only content itself
\r
253 TDirectory *cwd = gDirectory;
\r
254 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
\r
256 TIterator *iter = results->MakeIterator();
\r
257 TObject *inObject = NULL, *outObject = NULL;
\r
258 while((inObject = iter->Next())){
\r
259 outObject = inObject->Clone();
\r
260 outObject->Write(NULL, TObject::kSingleKey);
\r
263 gFile->Close(); delete gFile;
\r
268 //_______________________________________________________
\r
269 Bool_t AliTRDrecoTask::PostProcess()
\r
271 // To be implemented by particular tasks
\r
273 AliWarning("Post processing of reference histograms not implemented.");
\r
277 //_______________________________________________________
\r
278 void AliTRDrecoTask::MakeSummary()
\r
280 // To be implemented by particular tasks
\r
281 AliWarning("Summary not available");
\r
284 //_______________________________________________________
\r
285 void AliTRDrecoTask::SetDebugLevel(Int_t level)
\r
287 // Generic debug handler
\r
289 AliAnalysisTaskSE::SetDebugLevel(level);
\r
290 if(DebugLevel()>=1){
\r
291 AliInfo(Form("Debug Level for Task %s set to %d", GetName(), level));
\r
292 TDirectory *savedir = gDirectory;
\r
293 fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");
\r
298 //____________________________________________________________________
\r
299 void AliTRDrecoTask::Terminate(Option_t *)
\r
305 if(fgDebugStream){
\r
306 delete fgDebugStream;
\r
307 fgDebugStream = NULL;
\r
309 fContainer = dynamic_cast<TObjArray *>(GetOutputData(1));
\r
310 if(fContainer && fRunTerminate){
\r
316 //________________________________________________________
\r
317 void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const h)
\r
319 // Helper function to avoid duplication of code
\r
320 // Make first guesses on the fit parameters
\r
322 // find the intial parameters of the fit !! (thanks George)
\r
323 Int_t nbinsy = Int_t(.5*h->GetNbinsX());
\r
325 for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
\r
326 f->SetParLimits(0, 0., 3.*sum);
\r
327 f->SetParameter(0, .9*sum);
\r
329 f->SetParLimits(1, -.2, .2);
\r
330 f->SetParameter(1, -0.1);
\r
332 f->SetParLimits(2, 0., 4.e-1);
\r
333 f->SetParameter(2, 2.e-2);
\r
334 if(f->GetNpar() <= 4) return;
\r
336 f->SetParLimits(3, 0., sum);
\r
337 f->SetParameter(3, .1*sum);
\r
339 f->SetParLimits(4, -.3, .3);
\r
340 f->SetParameter(4, 0.);
\r
342 f->SetParLimits(5, 0., 1.e2);
\r
343 f->SetParameter(5, 2.e-1);
\r