1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Markus Gaug ,04/2004 <mailto:markus@ifae.es>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MJPedestal
|
---|
29 | //
|
---|
30 | /////////////////////////////////////////////////////////////////////////////
|
---|
31 | #include "MJPedestal.h"
|
---|
32 |
|
---|
33 | #include <TF1.h>
|
---|
34 | #include <TFile.h>
|
---|
35 | #include <TStyle.h>
|
---|
36 | #include <TString.h>
|
---|
37 | #include <TCanvas.h>
|
---|
38 | #include <TSystem.h>
|
---|
39 |
|
---|
40 | #include "MLog.h"
|
---|
41 | #include "MLogManip.h"
|
---|
42 |
|
---|
43 | #include "MRunIter.h"
|
---|
44 | #include "MParList.h"
|
---|
45 | #include "MTaskList.h"
|
---|
46 | #include "MEvtLoop.h"
|
---|
47 | #include "MExtractor.h"
|
---|
48 |
|
---|
49 | #include "MStatusDisplay.h"
|
---|
50 |
|
---|
51 | #include "MGeomCam.h"
|
---|
52 | #include "MHCamera.h"
|
---|
53 | #include "MPedestalCam.h"
|
---|
54 | #include "MBadPixelsCam.h"
|
---|
55 |
|
---|
56 | #include "MReadMarsFile.h"
|
---|
57 | #include "MRawFileRead.h"
|
---|
58 | #include "MGeomApply.h"
|
---|
59 | #include "MBadPixelsMerge.h"
|
---|
60 | #include "MPedCalcPedRun.h"
|
---|
61 |
|
---|
62 | ClassImp(MJPedestal);
|
---|
63 |
|
---|
64 | using namespace std;
|
---|
65 |
|
---|
66 | const Double_t MJPedestal::fgPedestalMin = 4.;
|
---|
67 | const Double_t MJPedestal::fgPedestalMax = 16.;
|
---|
68 | const Double_t MJPedestal::fgPedRmsMin = 0.;
|
---|
69 | const Double_t MJPedestal::fgPedRmsMax = 20.;
|
---|
70 | // --------------------------------------------------------------------------
|
---|
71 | //
|
---|
72 | // Default constructor.
|
---|
73 | //
|
---|
74 | // Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
|
---|
75 | //
|
---|
76 | MJPedestal::MJPedestal(const char *name, const char *title)
|
---|
77 | : fRuns(0), fExtractor(NULL), fDataCheck(kFALSE)
|
---|
78 | {
|
---|
79 | fName = name ? name : "MJPedestal";
|
---|
80 | fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
|
---|
81 | }
|
---|
82 |
|
---|
83 | const char* MJPedestal::GetOutputFile() const
|
---|
84 | {
|
---|
85 |
|
---|
86 | if (!fRuns)
|
---|
87 | return "";
|
---|
88 |
|
---|
89 | return Form("%s/%s-F0.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|
93 | Bool_t MJPedestal::ReadPedestalCam()
|
---|
94 | {
|
---|
95 |
|
---|
96 | const TString fname = GetOutputFile();
|
---|
97 |
|
---|
98 | if (gSystem->AccessPathName(fname, kFileExists))
|
---|
99 | {
|
---|
100 | *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl;
|
---|
101 | return kFALSE;
|
---|
102 | }
|
---|
103 |
|
---|
104 | *fLog << inf << "Reading from file: " << fname << endl;
|
---|
105 |
|
---|
106 | TFile file(fname, "READ");
|
---|
107 | if (fPedestalCam.Read()<=0)
|
---|
108 | {
|
---|
109 | *fLog << err << "Unable to read MPedestalCam from " << fname << endl;
|
---|
110 | return kFALSE;
|
---|
111 | }
|
---|
112 |
|
---|
113 | if (file.FindKey("MBadPixelsCam"))
|
---|
114 | {
|
---|
115 | MBadPixelsCam bad;
|
---|
116 | if (bad.Read()<=0)
|
---|
117 | {
|
---|
118 | *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
|
---|
119 | return kFALSE;
|
---|
120 | }
|
---|
121 | fBadPixels.Merge(bad);
|
---|
122 | }
|
---|
123 |
|
---|
124 | if (fDisplay && !fDisplay->GetCanvas("Pedestals"))
|
---|
125 | fDisplay->Read();
|
---|
126 |
|
---|
127 | return kTRUE;
|
---|
128 | }
|
---|
129 |
|
---|
130 |
|
---|
131 | void MJPedestal::DisplayResult(MParList &plist)
|
---|
132 | {
|
---|
133 |
|
---|
134 | if (!fDisplay)
|
---|
135 | return;
|
---|
136 |
|
---|
137 | //
|
---|
138 | // Update display
|
---|
139 | //
|
---|
140 | TString title = fDisplay->GetTitle();
|
---|
141 | title += "-- Pedestal ";
|
---|
142 | title += fRuns->GetRunsAsString();
|
---|
143 | title += " --";
|
---|
144 | fDisplay->SetTitle(title);
|
---|
145 |
|
---|
146 | //
|
---|
147 | // Get container from list
|
---|
148 | //
|
---|
149 | MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
|
---|
150 |
|
---|
151 | //
|
---|
152 | // Create container to display
|
---|
153 | //
|
---|
154 | MHCamera disp0(geomcam, "MPedestalCam;ped", "Mean Pedestal");
|
---|
155 | MHCamera disp1(geomcam, "MPedestalCam;RMS", "Pedestal RMS");
|
---|
156 |
|
---|
157 | disp0.SetCamContent(fPedestalCam, 0);
|
---|
158 | disp0.SetCamError (fPedestalCam, 1);
|
---|
159 |
|
---|
160 | disp1.SetCamContent(fPedestalCam, 2);
|
---|
161 | disp1.SetCamError (fPedestalCam, 3);
|
---|
162 |
|
---|
163 | disp0.SetYTitle("P [fadc/slice]");
|
---|
164 | disp1.SetYTitle("\\sigma_{P} [fadc/slice]");
|
---|
165 |
|
---|
166 |
|
---|
167 | //
|
---|
168 | // Display data
|
---|
169 | //
|
---|
170 | TCanvas &c3 = fDisplay->AddTab("Pedestals");
|
---|
171 | c3.Divide(2,3);
|
---|
172 |
|
---|
173 | if (fDataCheck)
|
---|
174 | {
|
---|
175 | c3.cd(1);
|
---|
176 | gPad->SetBorderMode(0);
|
---|
177 | gPad->SetTicks();
|
---|
178 | MHCamera *obj1=(MHCamera*)disp0.DrawCopy("hist");
|
---|
179 | obj1->SetDirectory(NULL);
|
---|
180 | obj1->SetMinimum(fgPedestalMin);
|
---|
181 | obj1->SetMaximum(fgPedestalMax);
|
---|
182 | gPad->Modified();
|
---|
183 | gPad->Update();
|
---|
184 |
|
---|
185 | c3.cd(3);
|
---|
186 | gPad->SetBorderMode(0);
|
---|
187 | obj1->SetPrettyPalette();
|
---|
188 | obj1->Draw();
|
---|
189 |
|
---|
190 | c3.cd(5);
|
---|
191 | gPad->SetBorderMode(0);
|
---|
192 | gPad->SetTicks();
|
---|
193 | disp0.DrawProjection(7);
|
---|
194 | gPad->Modified();
|
---|
195 | gPad->Update();
|
---|
196 |
|
---|
197 | c3.cd(2);
|
---|
198 | gPad->SetBorderMode(0);
|
---|
199 | gPad->SetTicks();
|
---|
200 | MHCamera *obj2=(MHCamera*)disp1.DrawCopy("hist");
|
---|
201 | obj2->SetDirectory(NULL);
|
---|
202 | obj2->SetMinimum(fgPedRmsMin);
|
---|
203 | obj2->SetMaximum(fgPedRmsMax);
|
---|
204 | gPad->Modified();
|
---|
205 | gPad->Update();
|
---|
206 |
|
---|
207 | c3.cd(4);
|
---|
208 | gPad->SetBorderMode(0);
|
---|
209 | obj2->SetPrettyPalette();
|
---|
210 | obj2->Draw();
|
---|
211 |
|
---|
212 | c3.cd(6);
|
---|
213 | gPad->SetBorderMode(0);
|
---|
214 | gPad->SetTicks();
|
---|
215 | disp1.DrawProjection(6);
|
---|
216 |
|
---|
217 | }
|
---|
218 | else
|
---|
219 | {
|
---|
220 | disp0.CamDraw(c3, 1, 2, 1);
|
---|
221 | disp1.CamDraw(c3, 2, 2, 6);
|
---|
222 | }
|
---|
223 | }
|
---|
224 |
|
---|
225 | Bool_t MJPedestal::WriteResult()
|
---|
226 | {
|
---|
227 | if (fOutputPath.IsNull())
|
---|
228 | return kTRUE;
|
---|
229 |
|
---|
230 | const TString oname(GetOutputFile());
|
---|
231 |
|
---|
232 | *fLog << inf << "Writing to file: " << oname << endl;
|
---|
233 |
|
---|
234 | TFile file(oname, "UPDATE");
|
---|
235 |
|
---|
236 | if (fDisplay && fDisplay->Write()<=0)
|
---|
237 | {
|
---|
238 | *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
|
---|
239 | return kFALSE;
|
---|
240 | }
|
---|
241 |
|
---|
242 | if (fPedestalCam.Write()<=0)
|
---|
243 | {
|
---|
244 | *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
|
---|
245 | return kFALSE;
|
---|
246 | }
|
---|
247 |
|
---|
248 | if (fBadPixels.Write()<=0)
|
---|
249 | {
|
---|
250 | *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
|
---|
251 | return kFALSE;
|
---|
252 | }
|
---|
253 |
|
---|
254 | return kTRUE;
|
---|
255 | }
|
---|
256 |
|
---|
257 | void MJPedestal::SetOutputPath(const char *path)
|
---|
258 | {
|
---|
259 | fOutputPath = path;
|
---|
260 | if (fOutputPath.EndsWith("/"))
|
---|
261 | fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
|
---|
262 | }
|
---|
263 |
|
---|
264 | Bool_t MJPedestal::Process()
|
---|
265 | {
|
---|
266 | if (!ReadPedestalCam())
|
---|
267 | return ProcessFile();
|
---|
268 |
|
---|
269 | return kTRUE;
|
---|
270 | }
|
---|
271 |
|
---|
272 | Bool_t MJPedestal::ProcessFile()
|
---|
273 | {
|
---|
274 | if (!fRuns)
|
---|
275 | {
|
---|
276 | *fLog << err << "No Runs choosen... abort." << endl;
|
---|
277 | return kFALSE;
|
---|
278 | }
|
---|
279 | if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
|
---|
280 | {
|
---|
281 | *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
|
---|
282 | return kFALSE;
|
---|
283 | }
|
---|
284 |
|
---|
285 | *fLog << inf;
|
---|
286 | fLog->Separator(GetDescriptor());
|
---|
287 | *fLog << "Calculate MPedestalCam from Runs " << fRuns->GetRunsAsString() << endl;
|
---|
288 | *fLog << endl;
|
---|
289 |
|
---|
290 | MParList plist;
|
---|
291 | MTaskList tlist;
|
---|
292 | plist.AddToList(&tlist);
|
---|
293 |
|
---|
294 | MReadMarsFile read("Events");
|
---|
295 | MRawFileRead rawread(NULL);
|
---|
296 |
|
---|
297 | if (fDataCheck)
|
---|
298 | {
|
---|
299 | rawread.AddFiles(*fRuns);
|
---|
300 | tlist.AddToList(&rawread);
|
---|
301 | }
|
---|
302 | else
|
---|
303 | {
|
---|
304 | read.DisableAutoScheme();
|
---|
305 | static_cast<MRead&>(read).AddFiles(*fRuns);
|
---|
306 | tlist.AddToList(&read);
|
---|
307 | }
|
---|
308 | // Enable logging to file
|
---|
309 | //*fLog.SetOutputFile(lname, kTRUE);
|
---|
310 |
|
---|
311 | // Setup Tasklist
|
---|
312 | plist.AddToList(&fPedestalCam);
|
---|
313 | plist.AddToList(&fBadPixels);
|
---|
314 |
|
---|
315 | MGeomApply geomapl;
|
---|
316 | // MBadPixelsMerge merge(&fBadPixels);
|
---|
317 | MPedCalcPedRun pedcalc;
|
---|
318 |
|
---|
319 | if (fExtractor)
|
---|
320 | {
|
---|
321 | pedcalc.SetWindowSize((Int_t)fExtractor->GetNumHiGainSamples());
|
---|
322 | pedcalc.SetRange(fExtractor->GetHiGainFirst(), fExtractor->GetHiGainLast());
|
---|
323 | }
|
---|
324 | else
|
---|
325 | {
|
---|
326 | *fLog << warn << GetDescriptor()
|
---|
327 | << ": No extractor has been chosen, take default number of FADC samples " << endl;
|
---|
328 | }
|
---|
329 |
|
---|
330 | tlist.AddToList(&geomapl);
|
---|
331 | // tlist.AddToList(&merge);
|
---|
332 | //tlist.AddToList(&sigcalc);
|
---|
333 | tlist.AddToList(&pedcalc);
|
---|
334 |
|
---|
335 | //
|
---|
336 | // Execute the eventloop
|
---|
337 | //
|
---|
338 | MEvtLoop evtloop(fName);
|
---|
339 | evtloop.SetParList(&plist);
|
---|
340 | evtloop.SetDisplay(fDisplay);
|
---|
341 | evtloop.SetLogStream(fLog);
|
---|
342 |
|
---|
343 | // Execute first analysis
|
---|
344 | if (!evtloop.Eventloop())
|
---|
345 | {
|
---|
346 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
---|
347 | return kFALSE;
|
---|
348 | }
|
---|
349 |
|
---|
350 | tlist.PrintStatistics();
|
---|
351 |
|
---|
352 | DisplayResult(plist);
|
---|
353 |
|
---|
354 | if (!WriteResult())
|
---|
355 | return kFALSE;
|
---|
356 |
|
---|
357 | *fLog << inf << GetDescriptor() << ": Done." << endl;
|
---|
358 |
|
---|
359 | return kTRUE;
|
---|
360 | }
|
---|