]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/qaRec/AliTRDrecoTask.cxx
update Cl Error Param task for magnetic field
[u/mrichter/AliRoot.git] / TRD / qaRec / AliTRDrecoTask.cxx
CommitLineData
de520d8f 1#include "TClass.h"
2#include "TMethod.h"
3#include "TMethodCall.h"
4#include "TMethodArg.h"
d85cd79c 5#include "TFile.h"
de520d8f 6#include "TList.h"
fc0946a7 7#include "TH1.h"
8#include "TF1.h"
3d86166d 9#include "TObjArray.h"
10#include "TDirectory.h"
11#include "TTreeStream.h"
12
13#include "AliLog.h"
14#include "AliAnalysisTask.h"
15
16#include "AliTRDrecoTask.h"
17
18ClassImp(AliTRDrecoTask)
19
20//_______________________________________________________
21AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
22 : AliAnalysisTask(name, title)
23 ,fNRefFigures(0)
24 ,fDebugLevel(0)
de520d8f 25 ,fPlotFuncList(0x0)
3d86166d 26 ,fContainer(0x0)
27 ,fTracks(0x0)
de520d8f 28 ,fTrack(0x0)
29 ,fMC(0x0)
30 ,fESD(0x0)
3d86166d 31 ,fDebugStream(0x0)
32{
33 DefineInput(0, TObjArray::Class());
34 DefineOutput(0, TObjArray::Class());
35}
36
37//_______________________________________________________
38AliTRDrecoTask::~AliTRDrecoTask()
39{
40 if(fDebugStream){
41 delete fDebugStream;
42 fDebugStream = 0x0;
43 }
44
de520d8f 45 if(fPlotFuncList){
46 fPlotFuncList->Delete();
47 delete fPlotFuncList;
48 fPlotFuncList = 0x0;
49 }
50
3d86166d 51 if(fContainer){
94f34623 52 if(fContainer->IsOwner()) fContainer->Delete();
3d86166d 53 delete fContainer;
54 fContainer = 0x0;
55 }
56}
57
58//_______________________________________________________
59void AliTRDrecoTask::ConnectInputData(Option_t *)
60{
61 //
62 // Connect input data
63 //
64
65 fTracks = dynamic_cast<TObjArray *>(GetInputData(0));
66}
67
de520d8f 68//_______________________________________________________
69void AliTRDrecoTask::Exec(Option_t *)
70{
71 if(!fPlotFuncList){
72 AliWarning("No functor list defined for the reference plots");
73 return;
74 }
75 if(!fTracks) return;
76 if(!fTracks->GetEntriesFast()) return;
77
78 AliTRDtrackInfo *trackInfo = 0x0;
79 TIter plotIter(fPlotFuncList);
80 TObjArrayIter trackIter(fTracks);
81 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
82 fTrack = trackInfo->GetTrack();
83 fMC = trackInfo->GetMCinfo();
84 fESD = trackInfo->GetESDinfo();
85
86 TMethodCall *plot = 0x0;
87 plotIter.Reset();
88 while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
89 plot->Execute(this);
90 }
91 }
92 PostData(0, fContainer);
93}
3d86166d 94
95//_______________________________________________________
e15179be 96Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
3d86166d 97{
98 AliWarning("Retrieving reference figures not implemented.");
e15179be 99 return kFALSE;
3d86166d 100}
101
de520d8f 102//_______________________________________________________
103void AliTRDrecoTask::InitFunctorList()
104{
105 TClass *c = this->IsA();
106
107 TMethod *m = 0x0;
108 TIter methIter(c->GetListOfMethods());
109 while((m=dynamic_cast<TMethod*>(methIter()))){
110 TString name(m->GetName());
111 if(!name.BeginsWith("Plot")) continue;
112 if(!fPlotFuncList) fPlotFuncList = new TList();
cf194b94 113 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
de520d8f 114 }
115}
116
3d86166d 117//_______________________________________________________
28efdace 118Bool_t AliTRDrecoTask::Load(const Char_t *filename)
3d86166d 119{
75d00a6d 120 if(!TFile::Open(filename)){
121 AliWarning(Form("Couldn't open file %s.", filename));
122 return kFALSE;
123 }
124 TObjArray *o = 0x0;
125 if(!(o = (TObjArray*)gFile->Get(GetName()))){
126 AliWarning("Missing histogram container.");
127 return kFALSE;
128 }
d85cd79c 129 fContainer = (TObjArray*)o->Clone(GetName());
130 gFile->Close();
75d00a6d 131 return kTRUE;
3d86166d 132}
133
134//_______________________________________________________
135Bool_t AliTRDrecoTask::PostProcess()
136{
137 AliWarning("Post processing of reference histograms not implemented.");
138 return kFALSE;
139}
140
141//_______________________________________________________
142void AliTRDrecoTask::SetDebugLevel(Int_t level)
143{
144 fDebugLevel = level;
b718144c 145 if(fDebugLevel>=1){
3d86166d 146 TDirectory *savedir = gDirectory;
147 fDebugStream = new TTreeSRedirector(Form("TRD.Debug%s.root", GetName()));
148 savedir->cd();
149 }
150}
fc0946a7 151
152//________________________________________________________
153void AliTRDrecoTask::Adjust(TF1 *f, TH1 *h)
154{
155// Helper function to avoid duplication of code
156// Make first guesses on the fit parameters
157
158 // find the intial parameters of the fit !! (thanks George)
159 Int_t nbinsy = Int_t(.5*h->GetNbinsX());
160 Double_t sum = 0.;
161 for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
162 f->SetParLimits(0, 0., 3.*sum);
163 f->SetParameter(0, .9*sum);
164
165 f->SetParLimits(1, -.2, .2);
166 f->SetParameter(1, -0.1);
167
168 f->SetParLimits(2, 0., 4.e-1);
169 f->SetParameter(2, 2.e-2);
170 if(f->GetNpar() <= 4) return;
171
172 f->SetParLimits(3, 0., sum);
173 f->SetParameter(3, .1*sum);
174
175 f->SetParLimits(4, -.3, .3);
176 f->SetParameter(4, 0.);
177
178 f->SetParLimits(5, 0., 1.e2);
179 f->SetParameter(5, 2.e-1);
180}