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