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 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MJCalibrateSignal
|
---|
28 | //
|
---|
29 | // This class is reading the output written by callisto. It calibrates
|
---|
30 | // signal and time.
|
---|
31 | //
|
---|
32 | // The signal and time extractors are read from the callisto-output. In
|
---|
33 | // pricipal you could overwrite these default using the resource file,
|
---|
34 | // but this is NOT recommended!
|
---|
35 | //
|
---|
36 | /////////////////////////////////////////////////////////////////////////////
|
---|
37 | #include "MJCalibrateSignal.h"
|
---|
38 |
|
---|
39 | #include <TEnv.h>
|
---|
40 | #include <TFile.h>
|
---|
41 |
|
---|
42 | #include "MLog.h"
|
---|
43 | #include "MLogManip.h"
|
---|
44 |
|
---|
45 | #include "MDirIter.h"
|
---|
46 | #include "MParList.h"
|
---|
47 | #include "MTaskList.h"
|
---|
48 | #include "MEvtLoop.h"
|
---|
49 |
|
---|
50 | #include "MJPedestal.h"
|
---|
51 | #include "MStatusDisplay.h"
|
---|
52 |
|
---|
53 | #include "MHCamEvent.h"
|
---|
54 | #include "MPedestalCam.h"
|
---|
55 | #include "MBadPixelsCam.h"
|
---|
56 | #include "MCalibrationQECam.h"
|
---|
57 | #include "MCalibrationChargeCam.h"
|
---|
58 | #include "MCalibrationRelTimeCam.h"
|
---|
59 |
|
---|
60 | #include "MReadMarsFile.h"
|
---|
61 | #include "MGeomApply.h"
|
---|
62 | #include "MPedCalcFromLoGain.h"
|
---|
63 | #include "MExtractor.h"
|
---|
64 | #include "MTaskEnv.h"
|
---|
65 | #include "MCalibrateData.h"
|
---|
66 | #include "MCalibrateRelTimes.h"
|
---|
67 | #include "MBadPixelsMerge.h"
|
---|
68 | #include "MBadPixelsCalc.h"
|
---|
69 | #include "MBadPixelsTreat.h"
|
---|
70 | #include "MFillH.h"
|
---|
71 | #include "MWriteRootFile.h"
|
---|
72 |
|
---|
73 | ClassImp(MJCalibrateSignal);
|
---|
74 |
|
---|
75 | using namespace std;
|
---|
76 |
|
---|
77 | // --------------------------------------------------------------------------
|
---|
78 | //
|
---|
79 | // Default constructor.
|
---|
80 | //
|
---|
81 | // Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
|
---|
82 | //
|
---|
83 | MJCalibrateSignal::MJCalibrateSignal(const char *name, const char *title)
|
---|
84 | {
|
---|
85 | fName = name ? name : "MJCalibrateSignal";
|
---|
86 | fTitle = title ? title : "Tool to calibrate data";
|
---|
87 | }
|
---|
88 |
|
---|
89 | Bool_t MJCalibrateSignal::WriteResult()
|
---|
90 | {
|
---|
91 | if (fPathOut.IsNull())
|
---|
92 | {
|
---|
93 | *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
|
---|
94 | return kTRUE;
|
---|
95 | }
|
---|
96 |
|
---|
97 | const TString oname = Form("%s/calped%06d.root", (const char*)fPathOut, fSequence.GetSequence());
|
---|
98 |
|
---|
99 | *fLog << inf << "Writing to file: " << oname << endl;
|
---|
100 |
|
---|
101 | TFile file(oname, "RECREATE");
|
---|
102 |
|
---|
103 | *fLog << inf << " - MStatusDisplay..." << flush;
|
---|
104 | if (fDisplay && fDisplay->Write()<=0)
|
---|
105 | {
|
---|
106 | *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
|
---|
107 | return kFALSE;
|
---|
108 | }
|
---|
109 | *fLog << inf << "ok." << endl;
|
---|
110 |
|
---|
111 | return kTRUE;
|
---|
112 | }
|
---|
113 |
|
---|
114 | Bool_t MJCalibrateSignal::ReadCalibration(MCalibrationCam &calcam,
|
---|
115 | MCalibrationCam &qecam,
|
---|
116 | MCalibrationCam &tmcam,
|
---|
117 | MBadPixelsCam &badpix, MTask* &ext1, MTask* &ext2) const
|
---|
118 | {
|
---|
119 | const TString fname = Form("%s/calib%06d.root", fPathIn.Data(), fSequence.GetSequence());
|
---|
120 |
|
---|
121 | TFile file(fname, "READ");
|
---|
122 | if (!file.IsOpen())
|
---|
123 | {
|
---|
124 | *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
|
---|
125 | return kFALSE;
|
---|
126 | }
|
---|
127 |
|
---|
128 | if (calcam.Read("MCalibrationChargeCam")<=0)
|
---|
129 | {
|
---|
130 | *fLog << err << dbginf << "ERROR - Unable to read MCalibrationChargeCam from file " << fname << endl;
|
---|
131 | return kFALSE;
|
---|
132 | }
|
---|
133 | if (qecam.Read("MCalibrationQECam")<=0)
|
---|
134 | {
|
---|
135 | *fLog << err << dbginf << "ERROR - Unable to read MCalibrationQECam from file " << fname << endl;
|
---|
136 | return kFALSE;
|
---|
137 | }
|
---|
138 | if (tmcam.Read("MCalibrationRelTimeCam")<=0)
|
---|
139 | {
|
---|
140 | *fLog << err << dbginf << "ERROR - Unable to read MCalibrationRelTimeCam from file " << fname << endl;
|
---|
141 | return kFALSE;
|
---|
142 | }
|
---|
143 | if (badpix.Read("MBadPixelsCam")<=0)
|
---|
144 | {
|
---|
145 | *fLog << err << dbginf << "ERROR - Unable to read MBadPixelsCam from file " << fname << endl;
|
---|
146 | return kFALSE;
|
---|
147 | }
|
---|
148 |
|
---|
149 | TObject *o = file.Get("ExtractSignal");
|
---|
150 | if (!o)
|
---|
151 | {
|
---|
152 | *fLog << err << dbginf << "ERROR - Unable to read ExtractSignal from file " << fname << endl;
|
---|
153 | return kFALSE;
|
---|
154 | }
|
---|
155 | if (!o->InheritsFrom(MExtractor::Class()))
|
---|
156 | {
|
---|
157 | *fLog << err << dbginf << "ERROR - ExtractSignal read from " << fname << " doesn't inherit from MExtractor!" << endl;
|
---|
158 | return kFALSE;
|
---|
159 | }
|
---|
160 | ext1 = (MTask*)o->Clone();
|
---|
161 |
|
---|
162 | o = file.Get("ExtractTime");
|
---|
163 | if (!o)
|
---|
164 | {
|
---|
165 | *fLog << err << dbginf << "ERROR - Unable to read ExtractTime from file " << fname << endl;
|
---|
166 | return kFALSE;
|
---|
167 | }
|
---|
168 | if (!o->InheritsFrom(MExtractor::Class()))
|
---|
169 | {
|
---|
170 | *fLog << err << dbginf << "ERROR - ExtractTime read from " << fname << " doesn't inherit from MExtractor!" << endl;
|
---|
171 | return kFALSE;
|
---|
172 | }
|
---|
173 | ext2 = (MTask*)o->Clone();
|
---|
174 |
|
---|
175 | return kTRUE;
|
---|
176 | }
|
---|
177 |
|
---|
178 | Bool_t MJCalibrateSignal::ProcessFile(MPedestalCam &pedcam)
|
---|
179 | {
|
---|
180 | if (!fSequence.IsValid())
|
---|
181 | {
|
---|
182 | *fLog << err << "ERROR - Sequence invalid!" << endl;
|
---|
183 | return kFALSE;
|
---|
184 | }
|
---|
185 |
|
---|
186 | //if (!CheckEnv())
|
---|
187 | // return kFALSE;
|
---|
188 |
|
---|
189 | CheckEnv();
|
---|
190 |
|
---|
191 | // --------------------------------------------------------------------------------
|
---|
192 |
|
---|
193 | *fLog << inf;
|
---|
194 | fLog->Separator(GetDescriptor());
|
---|
195 | *fLog << "Calculate calibrated data from runs ";
|
---|
196 | *fLog << fSequence.GetName() << endl;
|
---|
197 | *fLog << endl;
|
---|
198 |
|
---|
199 | // --------------------------------------------------------------------------------
|
---|
200 |
|
---|
201 | MDirIter iter;
|
---|
202 | const Int_t n0 = fSequence.SetupDatRuns(iter, fPathData);
|
---|
203 | const Int_t n1 = fSequence.GetNumDatRuns();
|
---|
204 | if (n0==0)
|
---|
205 | {
|
---|
206 | *fLog << err << "ERROR - No input files of sequence found!" << endl;
|
---|
207 | return kFALSE;
|
---|
208 | }
|
---|
209 | if (n0!=n1)
|
---|
210 | {
|
---|
211 | *fLog << err << "ERROR - Number of files found (" << n0 << ") doesn't match number of files in sequence (" << n1 << ")" << endl;
|
---|
212 | return kFALSE;
|
---|
213 | }
|
---|
214 |
|
---|
215 | // Read File
|
---|
216 | MCalibrationChargeCam calcam;
|
---|
217 | MCalibrationQECam qecam;
|
---|
218 | MCalibrationRelTimeCam tmcam;
|
---|
219 | MBadPixelsCam badpix;
|
---|
220 |
|
---|
221 | MTask *extractor1=0;
|
---|
222 | MTask *extractor2=0;
|
---|
223 |
|
---|
224 | if (!ReadCalibration(calcam, qecam, tmcam, badpix, extractor1, extractor2))
|
---|
225 | return kFALSE;
|
---|
226 |
|
---|
227 | *fLog << all;
|
---|
228 | *fLog << "Extractors read from file" << endl;
|
---|
229 | *fLog << "=========================" << endl;
|
---|
230 | extractor1->Print();
|
---|
231 | *fLog << endl;
|
---|
232 | extractor2->Print();
|
---|
233 | *fLog << endl;
|
---|
234 |
|
---|
235 | // This is necessary for the case in which it is not in the files
|
---|
236 | MBadPixelsCam badcam;
|
---|
237 |
|
---|
238 | // Setup Parlist
|
---|
239 | MParList plist;
|
---|
240 | plist.AddToList(this); // take care of fDisplay!
|
---|
241 | plist.AddToList(&calcam);
|
---|
242 | plist.AddToList(&qecam);
|
---|
243 | plist.AddToList(&tmcam);
|
---|
244 | plist.AddToList(&badcam);
|
---|
245 | plist.AddToList(&pedcam);
|
---|
246 |
|
---|
247 | // Setup Tasklist
|
---|
248 | MTaskList tlist;
|
---|
249 | plist.AddToList(&tlist);
|
---|
250 |
|
---|
251 | MReadMarsFile read("Events");
|
---|
252 | read.DisableAutoScheme();
|
---|
253 | read.AddFiles(iter);
|
---|
254 | //read.AddFiles(fnamein);
|
---|
255 |
|
---|
256 | MGeomApply apply; // Only necessary to craete geometry
|
---|
257 | MBadPixelsMerge merge(&badpix);
|
---|
258 | MPedCalcFromLoGain pedlo;
|
---|
259 | //MExtractSlidingWindow extsignal;
|
---|
260 | MTaskEnv taskenv1("ExtractSignal");
|
---|
261 | taskenv1.SetDefault(extractor1);
|
---|
262 | //MExtractTimeFastSpline exttime;
|
---|
263 | MTaskEnv taskenv2("ExtractTime");
|
---|
264 | taskenv2.SetDefault(extractor2);
|
---|
265 | MCalibrateData calib;
|
---|
266 | MCalibrateRelTimes caltm;
|
---|
267 | MBadPixelsCalc bpcal;
|
---|
268 | MBadPixelsTreat treat;
|
---|
269 |
|
---|
270 | MHCamEvent evt0("PedestalFLG");
|
---|
271 | MHCamEvent evt1("Extra'd");
|
---|
272 | MHCamEvent evt2("PedPhot");
|
---|
273 | MHCamEvent evt3("Interp'd");
|
---|
274 | MHCamEvent evt4("Unsuitable");
|
---|
275 | MHCamEvent evt5("Times");
|
---|
276 | evt0.SetType(0);
|
---|
277 | evt1.SetType(0);
|
---|
278 | evt2.SetType(0);
|
---|
279 | evt3.SetType(0);
|
---|
280 | evt4.SetType(2);
|
---|
281 | evt5.SetType(0);
|
---|
282 | MFillH fill0(&evt0, "MPedestalCam", "FillPedestalFLG");
|
---|
283 | MFillH fill1(&evt1, "MExtractedSignalCam", "FillExtracted");
|
---|
284 | MFillH fill2(&evt2, "MPedPhotCam", "FillPedPhot");
|
---|
285 | MFillH fill3(&evt3, "MCerPhotEvt", "FillInterpolated");
|
---|
286 | MFillH fill4(&evt4, "MBadPixelsCam", "FillUnsuitable");
|
---|
287 | MFillH fill5(&evt5, "MArrivalTime", "FillTimes");
|
---|
288 |
|
---|
289 | MWriteRootFile write(2, Form("%s{s/_D_/_Y_}", fPathOut.Data()), fOverwrite);
|
---|
290 | write.AddContainer("MCerPhotEvt", "Events");
|
---|
291 | write.AddContainer("MPedPhotCam", "Events");
|
---|
292 | write.AddContainer("MTime", "Events");
|
---|
293 | write.AddContainer("MRawEvtHeader", "Events");
|
---|
294 | write.AddContainer("MArrivalTime", "Events");
|
---|
295 | write.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
296 | write.AddContainer("MBadPixelsCam", "RunHeaders");
|
---|
297 | write.AddContainer("MGeomCam", "RunHeaders");
|
---|
298 |
|
---|
299 | tlist.AddToList(&read);
|
---|
300 | tlist.AddToList(&apply);
|
---|
301 | tlist.AddToList(&merge);
|
---|
302 | tlist.AddToList(&pedlo);
|
---|
303 | tlist.AddToList(&fill0);
|
---|
304 | tlist.AddToList(&taskenv1);
|
---|
305 | tlist.AddToList(&taskenv2);
|
---|
306 | tlist.AddToList(&fill1);
|
---|
307 | tlist.AddToList(&calib);
|
---|
308 | tlist.AddToList(&caltm);
|
---|
309 | tlist.AddToList(&fill2);
|
---|
310 | tlist.AddToList(&bpcal);
|
---|
311 | tlist.AddToList(&treat);
|
---|
312 | tlist.AddToList(&fill3);
|
---|
313 | tlist.AddToList(&fill4);
|
---|
314 | tlist.AddToList(&fill5);
|
---|
315 | tlist.AddToList(&write);
|
---|
316 |
|
---|
317 | // Create and setup the eventloop
|
---|
318 | MEvtLoop evtloop(fName);
|
---|
319 | evtloop.SetParList(&plist);
|
---|
320 | evtloop.SetDisplay(fDisplay);
|
---|
321 | evtloop.SetLogStream(fLog);
|
---|
322 | if (GetEnv())
|
---|
323 | evtloop.ReadEnv(*GetEnv());
|
---|
324 |
|
---|
325 | // Execute first analysis
|
---|
326 | if (!evtloop.Eventloop(fMaxEvents))
|
---|
327 | {
|
---|
328 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
---|
329 | return kFALSE;
|
---|
330 | }
|
---|
331 |
|
---|
332 | tlist.PrintStatistics();
|
---|
333 |
|
---|
334 | if (!WriteResult())
|
---|
335 | return kFALSE;
|
---|
336 |
|
---|
337 | *fLog << all << GetDescriptor() << ": Done." << endl;
|
---|
338 |
|
---|
339 | return kTRUE;
|
---|
340 | }
|
---|