3 #include "TMethodCall.h"
4 #include "TMethodArg.h"
10 #include "TDirectory.h"
11 #include "TTreeStream.h"
14 #include "AliAnalysisTask.h"
16 #include "AliTRDrecoTask.h"
18 ClassImp(AliTRDrecoTask)
19 FILE* AliTRDrecoTask::fgFile = 0x0;
20 //_______________________________________________________
21 AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
22 : AliAnalysisTask(name, title)
33 DefineInput(0, TObjArray::Class());
34 DefineOutput(0, TObjArray::Class());
37 //_______________________________________________________
38 AliTRDrecoTask::~AliTRDrecoTask()
40 printf(" %s (%s)\n", GetName(), GetTitle());
47 fPlotFuncList->Delete();
53 if(fContainer->IsOwner()) fContainer->Delete();
64 //_______________________________________________________
65 void AliTRDrecoTask::ConnectInputData(Option_t *)
71 fTracks = dynamic_cast<TObjArray *>(GetInputData(0));
74 //_______________________________________________________
75 void AliTRDrecoTask::Exec(Option_t *)
78 AliWarning("No functor list defined for the reference plots");
82 if(!fTracks->GetEntriesFast()) return;
84 AliTRDtrackInfo *trackInfo = 0x0;
85 TIter plotIter(fPlotFuncList);
86 TObjArrayIter trackIter(fTracks);
87 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
88 fTrack = trackInfo->GetTrack();
89 fMC = trackInfo->GetMCinfo();
90 fESD = trackInfo->GetESDinfo();
92 TMethodCall *plot = 0x0;
94 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
98 PostData(0, fContainer);
101 //_______________________________________________________
102 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
104 AliWarning("Retrieving reference figures not implemented.");
108 //_______________________________________________________
109 Bool_t AliTRDrecoTask::PutTrendValue(Char_t *name, Double_t val, Double_t err)
112 fgFile = fopen("TRD.Performance.txt", "wt");
114 fprintf(fgFile, "%s_%s %f %f\n", GetName(), name, val, err);
118 //_______________________________________________________
119 void AliTRDrecoTask::InitFunctorList()
121 TClass *c = this->IsA();
124 TIter methIter(c->GetListOfMethods());
125 while((m=dynamic_cast<TMethod*>(methIter()))){
126 TString name(m->GetName());
127 if(!name.BeginsWith("Plot")) continue;
128 if(!fPlotFuncList) fPlotFuncList = new TList();
129 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
133 //_______________________________________________________
134 Bool_t AliTRDrecoTask::Load(const Char_t *filename)
136 if(!TFile::Open(filename)){
137 AliWarning(Form("Couldn't open file %s.", filename));
141 if(!(o = (TObjArray*)gFile->Get(GetName()))){
142 AliWarning("Missing histogram container.");
145 fContainer = (TObjArray*)o->Clone(GetName());
150 //________________________________________________________
151 Bool_t AliTRDrecoTask::Save(TObjArray *results){
153 // Store the output graphs in a ROOT file
154 // Input TObject array will not be written as Key to the file,
155 // only content itself
158 TDirectory *cwd = gDirectory;
159 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
161 TIterator *iter = results->MakeIterator();
162 TObject *inObject = 0x0, *outObject = 0x0;
163 while((inObject = iter->Next())){
164 outObject = inObject->Clone();
165 outObject->Write(0x0, TObject::kSingleKey);
168 gFile->Close(); delete gFile;
173 //_______________________________________________________
174 Bool_t AliTRDrecoTask::PostProcess()
176 AliWarning("Post processing of reference histograms not implemented.");
180 //_______________________________________________________
181 void AliTRDrecoTask::SetDebugLevel(Int_t level)
185 TDirectory *savedir = gDirectory;
186 fDebugStream = new TTreeSRedirector(Form("TRD.DBG%s.root", GetName()));
191 //________________________________________________________
192 void AliTRDrecoTask::Adjust(TF1 *f, TH1 *h)
194 // Helper function to avoid duplication of code
195 // Make first guesses on the fit parameters
197 // find the intial parameters of the fit !! (thanks George)
198 Int_t nbinsy = Int_t(.5*h->GetNbinsX());
200 for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
201 f->SetParLimits(0, 0., 3.*sum);
202 f->SetParameter(0, .9*sum);
204 f->SetParLimits(1, -.2, .2);
205 f->SetParameter(1, -0.1);
207 f->SetParLimits(2, 0., 4.e-1);
208 f->SetParameter(2, 2.e-2);
209 if(f->GetNpar() <= 4) return;
211 f->SetParLimits(3, 0., sum);
212 f->SetParameter(3, .1*sum);
214 f->SetParLimits(4, -.3, .3);
215 f->SetParameter(4, 0.);
217 f->SetParLimits(5, 0., 1.e2);
218 f->SetParameter(5, 2.e-1);