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();
65 //_______________________________________________________
66 void AliTRDrecoTask::ConnectInputData(Option_t *)
72 fTracks = dynamic_cast<TObjArray *>(GetInputData(0));
75 //_______________________________________________________
76 void AliTRDrecoTask::Exec(Option_t *)
79 AliWarning("No functor list defined for the reference plots");
83 if(!fTracks->GetEntriesFast()) return;
85 AliTRDtrackInfo *trackInfo = 0x0;
86 TIter plotIter(fPlotFuncList);
87 TObjArrayIter trackIter(fTracks);
88 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
89 fTrack = trackInfo->GetTrack();
90 fMC = trackInfo->GetMCinfo();
91 fESD = trackInfo->GetESDinfo();
93 TMethodCall *plot = 0x0;
95 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
99 PostData(0, fContainer);
102 //_______________________________________________________
103 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
105 AliWarning("Retrieving reference figures not implemented.");
109 //_______________________________________________________
110 Bool_t AliTRDrecoTask::PutTrendValue(Char_t *name, Double_t val, Double_t err)
113 fgFile = fopen("TRD.Performance.txt", "at");
115 fprintf(fgFile, "%s_%s %f %f\n", GetName(), name, val, err);
119 //_______________________________________________________
120 void AliTRDrecoTask::InitFunctorList()
122 TClass *c = this->IsA();
125 TIter methIter(c->GetListOfMethods());
126 while((m=dynamic_cast<TMethod*>(methIter()))){
127 TString name(m->GetName());
128 if(!name.BeginsWith("Plot")) continue;
129 if(!fPlotFuncList) fPlotFuncList = new TList();
130 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
134 //_______________________________________________________
135 Bool_t AliTRDrecoTask::Load(const Char_t *filename)
137 if(!TFile::Open(filename)){
138 AliWarning(Form("Couldn't open file %s.", filename));
142 if(!(o = (TObjArray*)gFile->Get(GetName()))){
143 AliWarning("Missing histogram container.");
146 fContainer = (TObjArray*)o->Clone(GetName());
151 //________________________________________________________
152 Bool_t AliTRDrecoTask::Save(TObjArray *results){
154 // Store the output graphs in a ROOT file
155 // Input TObject array will not be written as Key to the file,
156 // only content itself
159 TDirectory *cwd = gDirectory;
160 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
162 TIterator *iter = results->MakeIterator();
163 TObject *inObject = 0x0, *outObject = 0x0;
164 while((inObject = iter->Next())){
165 outObject = inObject->Clone();
166 outObject->Write(0x0, TObject::kSingleKey);
169 gFile->Close(); delete gFile;
174 //_______________________________________________________
175 Bool_t AliTRDrecoTask::PostProcess()
177 AliWarning("Post processing of reference histograms not implemented.");
181 //_______________________________________________________
182 void AliTRDrecoTask::SetDebugLevel(Int_t level)
186 TDirectory *savedir = gDirectory;
187 fDebugStream = new TTreeSRedirector(Form("TRD.DBG%s.root", GetName()));
192 //________________________________________________________
193 void AliTRDrecoTask::Adjust(TF1 *f, TH1 *h)
195 // Helper function to avoid duplication of code
196 // Make first guesses on the fit parameters
198 // find the intial parameters of the fit !! (thanks George)
199 Int_t nbinsy = Int_t(.5*h->GetNbinsX());
201 for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
202 f->SetParLimits(0, 0., 3.*sum);
203 f->SetParameter(0, .9*sum);
205 f->SetParLimits(1, -.2, .2);
206 f->SetParameter(1, -0.1);
208 f->SetParLimits(2, 0., 4.e-1);
209 f->SetParameter(2, 2.e-2);
210 if(f->GetNpar() <= 4) return;
212 f->SetParLimits(3, 0., sum);
213 f->SetParameter(3, .1*sum);
215 f->SetParLimits(4, -.3, .3);
216 f->SetParameter(4, 0.);
218 f->SetParLimits(5, 0., 1.e2);
219 f->SetParameter(5, 2.e-1);