]>
Commit | Line | Data |
---|---|---|
1ee39b3a | 1 | /////////////////////////////////////////////////////// |
2 | // | |
3 | // Basic class for Performance/Calibration TRD tasks | |
4 | // | |
5 | // It performs generic tasks like : | |
6 | // - data file manegment | |
7 | // - reference container management | |
8 | // - debug container management | |
9 | // - interaction with AliAnalysisManager | |
10 | // - Plot functor loop | |
11 | // | |
12 | // Author: Alexandru Bercuci <A.Bercuci@gsi.de>, 10/09/2008 | |
13 | // | |
14 | ///////////////////////////////////////////////////////// | |
15 | ||
16 | #include "TClass.h" | |
17 | #include "TMethod.h" | |
18 | #include "TMethodCall.h" | |
19 | #include "TMethodArg.h" | |
20 | #include "TFile.h" | |
f8f46e4d | 21 | #include "TChain.h" |
1ee39b3a | 22 | #include "TList.h" |
23 | #include "TMap.h" | |
24 | #include "TH1.h" | |
25 | #include "TF1.h" | |
26 | #include "TObjArray.h" | |
27 | #include "TDirectory.h" | |
28 | #include "TTreeStream.h" | |
29 | ||
30 | #include "AliLog.h" | |
31 | #include "AliAnalysisTask.h" | |
32 | ||
33 | #include "AliTRDrecoTask.h" | |
34 | ||
35 | ClassImp(AliTRDrecoTask) | |
36 | ||
db99a57a | 37 | TList* AliTRDrecoTask::fgTrendPoint(NULL); |
38 | TTreeSRedirector* AliTRDrecoTask::fgDebugStream(NULL); | |
1ee39b3a | 39 | //_______________________________________________________ |
f8f46e4d | 40 | AliTRDrecoTask::AliTRDrecoTask() |
41 | : AliAnalysisTaskSE() | |
42 | ,fNRefFigures(0) | |
db99a57a | 43 | ,fContainer(NULL) |
44 | ,fTracks(NULL) | |
45 | ,fkTrack(NULL) | |
46 | ,fkMC(NULL) | |
47 | ,fkESD(NULL) | |
48 | ,fDebugLevel(0) | |
49 | ,fPlotFuncList(NULL) | |
f8f46e4d | 50 | { |
705f8b0a | 51 | // Default constructor |
f8f46e4d | 52 | } |
53 | ||
db99a57a | 54 | //_______________________________________________________ |
f2e89a4c | 55 | AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title) |
f8f46e4d | 56 | : AliAnalysisTaskSE(name) |
1ee39b3a | 57 | ,fNRefFigures(0) |
db99a57a | 58 | ,fContainer(NULL) |
59 | ,fTracks(NULL) | |
60 | ,fkTrack(NULL) | |
61 | ,fkMC(NULL) | |
62 | ,fkESD(NULL) | |
63 | ,fDebugLevel(0) | |
64 | ,fPlotFuncList(NULL) | |
1ee39b3a | 65 | { |
705f8b0a | 66 | // Constructor for all derived performance tasks |
1ee39b3a | 67 | |
705f8b0a | 68 | SetTitle(title); |
69 | DefineInput (1, TObjArray::Class()); // track list | |
70 | DefineOutput(1, TObjArray::Class()); // histogram list | |
b4414720 | 71 | } |
72 | ||
1ee39b3a | 73 | //_______________________________________________________ |
74 | AliTRDrecoTask::~AliTRDrecoTask() | |
75 | { | |
76 | ||
77 | // Generic task destructor | |
78 | ||
79 | AliDebug(1, Form(" Ending %s (%s)\n", GetName(), GetTitle())); | |
80 | if(fgDebugStream){ | |
81 | delete fgDebugStream; | |
db99a57a | 82 | fgDebugStream = NULL; |
1ee39b3a | 83 | } |
84 | ||
85 | if(fPlotFuncList){ | |
86 | fPlotFuncList->Delete(); | |
87 | delete fPlotFuncList; | |
db99a57a | 88 | fPlotFuncList = NULL; |
1ee39b3a | 89 | } |
90 | ||
91 | if(fContainer){ | |
92 | if(fContainer->IsOwner()) fContainer->Delete(); | |
93 | delete fContainer; | |
db99a57a | 94 | fContainer = NULL; |
1ee39b3a | 95 | } |
96 | ||
97 | if(fgTrendPoint){ | |
98 | TFile::Open("TRD.PerformanceTrend.root", "UPDATE"); | |
99 | fgTrendPoint->Write(); | |
100 | delete fgTrendPoint; | |
db99a57a | 101 | fgTrendPoint=NULL; |
1ee39b3a | 102 | gFile->Close(); |
103 | } | |
104 | } | |
105 | ||
106 | //_______________________________________________________ | |
107 | void AliTRDrecoTask::ConnectInputData(Option_t *) | |
108 | { | |
109 | // | |
110 | // Connect input data | |
111 | // | |
705f8b0a | 112 | AliAnalysisTaskSE::ConnectInputData(); |
113 | fTracks = dynamic_cast<TObjArray *>(GetInputData(1)); | |
1ee39b3a | 114 | } |
115 | ||
116 | //_______________________________________________________ | |
f8f46e4d | 117 | void AliTRDrecoTask::UserExec(Option_t *) |
1ee39b3a | 118 | { |
119 | // Loop over Plot functors published by particular tasks | |
120 | ||
121 | if(!fPlotFuncList){ | |
122 | AliWarning("No functor list defined for the reference plots"); | |
123 | return; | |
124 | } | |
125 | if(!fTracks) return; | |
126 | if(!fTracks->GetEntriesFast()) return; | |
127 | ||
db99a57a | 128 | AliTRDtrackInfo *trackInfo = NULL; |
1ee39b3a | 129 | TIter plotIter(fPlotFuncList); |
130 | TObjArrayIter trackIter(fTracks); | |
131 | while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){ | |
132 | fkTrack = trackInfo->GetTrack(); | |
133 | fkMC = trackInfo->GetMCinfo(); | |
134 | fkESD = trackInfo->GetESDinfo(); | |
135 | ||
db99a57a | 136 | TMethodCall *plot = NULL; |
1ee39b3a | 137 | plotIter.Reset(); |
138 | while((plot=dynamic_cast<TMethodCall*>(plotIter()))){ | |
139 | plot->Execute(this); | |
140 | } | |
141 | } | |
f8f46e4d | 142 | PostData(1, fContainer); |
1ee39b3a | 143 | } |
144 | ||
145 | //_______________________________________________________ | |
146 | Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/) | |
147 | { | |
148 | AliWarning("Retrieving reference figures not implemented."); | |
149 | return kFALSE; | |
150 | } | |
151 | ||
152 | //_______________________________________________________ | |
153 | Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val) | |
154 | { | |
155 | // Generic publisher for trend values | |
156 | ||
157 | if(!fgTrendPoint){ | |
158 | fgTrendPoint = new TList(); | |
159 | fgTrendPoint->SetOwner(); | |
160 | } | |
161 | fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val))); | |
162 | return kTRUE; | |
163 | } | |
164 | ||
165 | //_______________________________________________________ | |
166 | void AliTRDrecoTask::InitFunctorList() | |
167 | { | |
168 | // Initialize list of functors | |
169 | ||
170 | TClass *c = this->IsA(); | |
171 | ||
db99a57a | 172 | TMethod *m = NULL; |
1ee39b3a | 173 | TIter methIter(c->GetListOfMethods()); |
174 | while((m=dynamic_cast<TMethod*>(methIter()))){ | |
175 | TString name(m->GetName()); | |
176 | if(!name.BeginsWith("Plot")) continue; | |
177 | if(!fPlotFuncList) fPlotFuncList = new TList(); | |
178 | fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, "")); | |
179 | } | |
180 | } | |
181 | ||
182 | //_______________________________________________________ | |
183 | Bool_t AliTRDrecoTask::Load(const Char_t *filename) | |
184 | { | |
185 | // Generic container loader | |
186 | ||
187 | if(!TFile::Open(filename)){ | |
188 | AliWarning(Form("Couldn't open file %s.", filename)); | |
189 | return kFALSE; | |
190 | } | |
db99a57a | 191 | TObjArray *o = NULL; |
1ee39b3a | 192 | if(!(o = (TObjArray*)gFile->Get(GetName()))){ |
193 | AliWarning("Missing histogram container."); | |
194 | return kFALSE; | |
195 | } | |
196 | fContainer = (TObjArray*)o->Clone(GetName()); | |
197 | gFile->Close(); | |
198 | return kTRUE; | |
199 | } | |
200 | ||
201 | //________________________________________________________ | |
202 | Bool_t AliTRDrecoTask::Save(TObjArray * const results){ | |
203 | // | |
204 | // Store the output graphs in a ROOT file | |
205 | // Input TObject array will not be written as Key to the file, | |
206 | // only content itself | |
207 | // | |
208 | ||
209 | TDirectory *cwd = gDirectory; | |
210 | if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE; | |
211 | ||
212 | TIterator *iter = results->MakeIterator(); | |
db99a57a | 213 | TObject *inObject = NULL, *outObject = NULL; |
1ee39b3a | 214 | while((inObject = iter->Next())){ |
215 | outObject = inObject->Clone(); | |
db99a57a | 216 | outObject->Write(NULL, TObject::kSingleKey); |
1ee39b3a | 217 | } |
218 | delete iter; | |
219 | gFile->Close(); delete gFile; | |
220 | cwd->cd(); | |
221 | return kTRUE; | |
222 | } | |
223 | ||
224 | //_______________________________________________________ | |
225 | Bool_t AliTRDrecoTask::PostProcess() | |
226 | { | |
227 | // To be implemented by particular tasks | |
228 | ||
229 | AliWarning("Post processing of reference histograms not implemented."); | |
230 | return kFALSE; | |
231 | } | |
232 | ||
233 | //_______________________________________________________ | |
234 | void AliTRDrecoTask::SetDebugLevel(Int_t level) | |
235 | { | |
236 | // Generic debug handler | |
237 | ||
f8f46e4d | 238 | fDebug = level; |
239 | if(fDebug>=1){ | |
1ee39b3a | 240 | TDirectory *savedir = gDirectory; |
241 | fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root"); | |
242 | savedir->cd(); | |
243 | } | |
244 | } | |
245 | ||
246 | //____________________________________________________________________ | |
247 | void AliTRDrecoTask::Terminate(Option_t *) | |
248 | { | |
249 | // | |
250 | // Terminate | |
251 | // | |
252 | ||
253 | if(fgDebugStream){ | |
254 | delete fgDebugStream; | |
db99a57a | 255 | fgDebugStream = NULL; |
f8f46e4d | 256 | fDebug = 0; |
1ee39b3a | 257 | } |
258 | if(HasPostProcess()) PostProcess(); | |
259 | } | |
260 | ||
261 | //________________________________________________________ | |
262 | void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const h) | |
263 | { | |
264 | // Helper function to avoid duplication of code | |
265 | // Make first guesses on the fit parameters | |
266 | ||
267 | // find the intial parameters of the fit !! (thanks George) | |
268 | Int_t nbinsy = Int_t(.5*h->GetNbinsX()); | |
269 | Double_t sum = 0.; | |
270 | for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.; | |
271 | f->SetParLimits(0, 0., 3.*sum); | |
272 | f->SetParameter(0, .9*sum); | |
273 | ||
274 | f->SetParLimits(1, -.2, .2); | |
275 | f->SetParameter(1, -0.1); | |
276 | ||
277 | f->SetParLimits(2, 0., 4.e-1); | |
278 | f->SetParameter(2, 2.e-2); | |
279 | if(f->GetNpar() <= 4) return; | |
280 | ||
281 | f->SetParLimits(3, 0., sum); | |
282 | f->SetParameter(3, .1*sum); | |
283 | ||
284 | f->SetParLimits(4, -.3, .3); | |
285 | f->SetParameter(4, 0.); | |
286 | ||
287 | f->SetParLimits(5, 0., 1.e2); | |
288 | f->SetParameter(5, 2.e-1); | |
289 | } |