]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/qaRec/AliTRDrecoTask.cxx
fix PID reference figures style (AlexW)
[u/mrichter/AliRoot.git] / TRD / qaRec / AliTRDrecoTask.cxx
1 #include "TClass.h"
2 #include "TMethod.h"
3 #include "TMethodCall.h"
4 #include "TMethodArg.h"
5 #include "TFile.h"
6 #include "TList.h"
7 #include "TH1.h"
8 #include "TF1.h"
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
18 ClassImp(AliTRDrecoTask)
19
20 //_______________________________________________________
21 AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
22   : AliAnalysisTask(name, title)
23   ,fNRefFigures(0)
24   ,fDebugLevel(0)
25   ,fPlotFuncList(0x0)
26   ,fContainer(0x0)
27   ,fTracks(0x0)
28   ,fTrack(0x0)
29   ,fMC(0x0)
30   ,fESD(0x0)
31   ,fDebugStream(0x0)
32 {
33   DefineInput(0, TObjArray::Class());
34   DefineOutput(0, TObjArray::Class());
35 }
36
37 //_______________________________________________________
38 AliTRDrecoTask::~AliTRDrecoTask() 
39 {
40   if(fDebugStream){ 
41     delete fDebugStream;
42     fDebugStream = 0x0;
43   }
44
45   if(fPlotFuncList){
46     fPlotFuncList->Delete();
47     delete fPlotFuncList;
48     fPlotFuncList = 0x0;
49   }
50   
51   if(fContainer){
52     if(fContainer->IsOwner()) fContainer->Delete();
53     delete fContainer;
54     fContainer = 0x0;
55   }
56 }
57
58 //_______________________________________________________
59 void AliTRDrecoTask::ConnectInputData(Option_t *)
60 {
61   //
62   // Connect input data
63   //
64
65   fTracks = dynamic_cast<TObjArray *>(GetInputData(0));
66 }
67
68 //_______________________________________________________
69 void 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 }
94
95 //_______________________________________________________
96 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
97 {
98   AliWarning("Retrieving reference figures not implemented.");
99   return kFALSE;
100 }
101
102 //_______________________________________________________
103 void 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();
113     fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
114   }
115 }
116
117 //_______________________________________________________
118 Bool_t AliTRDrecoTask::Load(const Char_t *filename)
119 {
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   }
129   fContainer = (TObjArray*)o->Clone(GetName());
130   gFile->Close();
131   return kTRUE;
132 }
133
134 //_______________________________________________________
135 Bool_t AliTRDrecoTask::PostProcess()
136 {
137   AliWarning("Post processing of reference histograms not implemented.");
138   return kFALSE;
139 }
140
141 //_______________________________________________________
142 void AliTRDrecoTask::SetDebugLevel(Int_t level)
143 {
144   fDebugLevel = level;
145   if(fDebugLevel>=1){
146     TDirectory *savedir = gDirectory;
147     fDebugStream = new TTreeSRedirector(Form("TRD.Debug%s.root", GetName()));
148     savedir->cd();
149   }
150 }
151
152 //________________________________________________________
153 void 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 }