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