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 "MStatusDisplay.h"
|
---|
51 |
|
---|
52 | #include "MGeomCam.h"
|
---|
53 | #include "MHCamEvent.h"
|
---|
54 | #include "MPedestalCam.h"
|
---|
55 | #include "MBadPixelsCam.h"
|
---|
56 |
|
---|
57 | #include "MCalibrationChargePINDiode.h"
|
---|
58 |
|
---|
59 | #include "MCalibrationQECam.h"
|
---|
60 | #include "MCalibrationBlindCam.h"
|
---|
61 | #include "MCalibrationChargeCam.h"
|
---|
62 | #include "MCalibrationRelTimeCam.h"
|
---|
63 | /*
|
---|
64 | #include "MCalibrationIntensityQECam.h"
|
---|
65 | #include "MCalibrationIntensityBlindCam.h"
|
---|
66 | #include "MCalibrationIntensityChargeCam.h"
|
---|
67 | #include "MCalibrationIntensityRelTimeCam.h"
|
---|
68 | */
|
---|
69 | #include "MReadReports.h"
|
---|
70 | #include "MReadMarsFile.h"
|
---|
71 | #include "MRawFileRead.h"
|
---|
72 | #include "MGeomApply.h"
|
---|
73 | #include "MMcPedestalCopy.h"
|
---|
74 | #include "MPointingPosCalc.h"
|
---|
75 | #include "MPedCalcFromLoGain.h"
|
---|
76 | #include "MExtractor.h"
|
---|
77 | #include "MTaskEnv.h"
|
---|
78 | #include "MCalibrateData.h"
|
---|
79 | #include "MCalibrateRelTimes.h"
|
---|
80 | #include "MBadPixelsMerge.h"
|
---|
81 | #include "MBadPixelsCalc.h"
|
---|
82 | #include "MBadPixelsTreat.h"
|
---|
83 | #include "MFillH.h"
|
---|
84 | #include "MWriteRootFile.h"
|
---|
85 |
|
---|
86 | ClassImp(MJCalibrateSignal);
|
---|
87 |
|
---|
88 | using namespace std;
|
---|
89 |
|
---|
90 | // --------------------------------------------------------------------------
|
---|
91 | //
|
---|
92 | // Default constructor.
|
---|
93 | //
|
---|
94 | // Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
|
---|
95 | //
|
---|
96 | MJCalibrateSignal::MJCalibrateSignal(const char *name, const char *title)
|
---|
97 | {
|
---|
98 | fName = name ? name : "MJCalibrateSignal";
|
---|
99 | fTitle = title ? title : "Tool to calibrate data";
|
---|
100 | }
|
---|
101 |
|
---|
102 | Bool_t MJCalibrateSignal::WriteResult()
|
---|
103 | {
|
---|
104 | if (fPathOut.IsNull())
|
---|
105 | {
|
---|
106 | *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
|
---|
107 | return kTRUE;
|
---|
108 | }
|
---|
109 |
|
---|
110 | const TString oname = Form("%s/signal%06d.root", (const char*)fPathOut, fSequence.GetSequence());
|
---|
111 |
|
---|
112 | *fLog << inf << "Writing to file: " << oname << endl;
|
---|
113 |
|
---|
114 | TFile file(oname, "RECREATE");
|
---|
115 |
|
---|
116 | *fLog << inf << " - MStatusDisplay..." << flush;
|
---|
117 | if (fDisplay && fDisplay->Write()<=0)
|
---|
118 | {
|
---|
119 | *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
|
---|
120 | return kFALSE;
|
---|
121 | }
|
---|
122 | *fLog << inf << "ok." << endl;
|
---|
123 |
|
---|
124 | return kTRUE;
|
---|
125 | }
|
---|
126 |
|
---|
127 | Bool_t MJCalibrateSignal::ReadCalibration(TObjArray &l, MBadPixelsCam &cam, MTask* &ext1, MTask* &ext2, TString &geom) const
|
---|
128 | {
|
---|
129 | const TString fname = Form("%s/calib%06d.root", fPathIn.Data(), fSequence.GetSequence());
|
---|
130 |
|
---|
131 | *fLog << inf << "Reading from file: " << fname << endl;
|
---|
132 |
|
---|
133 | TFile file(fname, "READ");
|
---|
134 | if (!file.IsOpen())
|
---|
135 | {
|
---|
136 | *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
|
---|
137 | return kFALSE;
|
---|
138 | }
|
---|
139 |
|
---|
140 | TObject *o = file.Get("ExtractSignal");
|
---|
141 | if (o && !o->InheritsFrom(MExtractor::Class()))
|
---|
142 | {
|
---|
143 | *fLog << err << dbginf << "ERROR - ExtractSignal read from " << fname << " doesn't inherit from MExtractor!" << endl;
|
---|
144 | return kFALSE;
|
---|
145 | }
|
---|
146 | ext1 = o ? (MTask*)o->Clone() : NULL;
|
---|
147 |
|
---|
148 | o = file.Get("ExtractTime");
|
---|
149 | if (o && !o->InheritsFrom(MExtractor::Class()))
|
---|
150 | {
|
---|
151 | *fLog << err << dbginf << "ERROR - ExtractTime read from " << fname << " doesn't inherit from MExtractor!" << endl;
|
---|
152 | return kFALSE;
|
---|
153 | }
|
---|
154 | ext2 = o ? (MTask*)o->Clone() : NULL;
|
---|
155 | if (!ext1 && !ext2)
|
---|
156 | {
|
---|
157 | *fLog << err << dbginf << "ERROR - Neither ExtractSignal nor ExrtractTime found in " << fname << "!" << endl;
|
---|
158 | return kFALSE;
|
---|
159 | }
|
---|
160 |
|
---|
161 | o = file.Get("MGeomCam");
|
---|
162 | if (o && !o->InheritsFrom(MGeomCam::Class()))
|
---|
163 | {
|
---|
164 | *fLog << err << dbginf << "ERROR - MGeomCam read from " << fname << " doesn't inherit from MGeomCam!" << endl;
|
---|
165 | return kFALSE;
|
---|
166 | }
|
---|
167 | geom = o ? o->ClassName() : "";
|
---|
168 |
|
---|
169 | TObjArray cont(l);
|
---|
170 | cont.Add(&cam);
|
---|
171 | return ReadContainer(cont);
|
---|
172 | }
|
---|
173 |
|
---|
174 | Bool_t MJCalibrateSignal::ProcessFile(MPedestalCam &pedcam)
|
---|
175 | {
|
---|
176 | if (!fSequence.IsValid())
|
---|
177 | {
|
---|
178 | *fLog << err << "ERROR - Sequence invalid!" << endl;
|
---|
179 | return kFALSE;
|
---|
180 | }
|
---|
181 |
|
---|
182 | //if (!CheckEnv())
|
---|
183 | // return kFALSE;
|
---|
184 |
|
---|
185 | CheckEnv();
|
---|
186 |
|
---|
187 | // --------------------------------------------------------------------------------
|
---|
188 |
|
---|
189 | *fLog << inf;
|
---|
190 | fLog->Separator(GetDescriptor());
|
---|
191 | *fLog << "Calculate calibrated data from runs ";
|
---|
192 | *fLog << fSequence.GetName() << endl;
|
---|
193 | *fLog << endl;
|
---|
194 |
|
---|
195 | // --------------------------------------------------------------------------------
|
---|
196 |
|
---|
197 | MDirIter iter;
|
---|
198 | const Int_t n0 = fSequence.SetupDatRuns(iter, fPathData);
|
---|
199 | const Int_t n1 = fSequence.GetNumDatRuns();
|
---|
200 | if (n0==0)
|
---|
201 | {
|
---|
202 | *fLog << err << "ERROR - No input files of sequence found!" << endl;
|
---|
203 | return kFALSE;
|
---|
204 | }
|
---|
205 | if (n0!=n1)
|
---|
206 | {
|
---|
207 | *fLog << err << "ERROR - Number of files found (" << n0 << ") doesn't match number of files in sequence (" << n1 << ")" << endl;
|
---|
208 | return kFALSE;
|
---|
209 | }
|
---|
210 |
|
---|
211 | // Read File
|
---|
212 | /*
|
---|
213 | MCalibrationIntensityChargeCam calcam;
|
---|
214 | MCalibrationIntensityQECam qecam;
|
---|
215 | MCalibrationIntensityBlindCam bndcam;
|
---|
216 | MCalibrationIntensityRelTimeCam tmcam;
|
---|
217 | */
|
---|
218 | MCalibrationChargeCam calcam;
|
---|
219 | MCalibrationQECam qecam;
|
---|
220 | MCalibrationBlindCam bndcam;
|
---|
221 | MCalibrationChargePINDiode pind;
|
---|
222 | MCalibrationRelTimeCam tmcam;
|
---|
223 | MBadPixelsCam badpix;
|
---|
224 |
|
---|
225 | MTask *extractor1=0;
|
---|
226 | MTask *extractor2=0;
|
---|
227 | TString geom;
|
---|
228 |
|
---|
229 | TObjArray calibcont;
|
---|
230 | calibcont.Add(&calcam);
|
---|
231 | calibcont.Add(&qecam);
|
---|
232 | calibcont.Add(&bndcam);
|
---|
233 | calibcont.Add(&pind);
|
---|
234 | calibcont.Add(&tmcam);
|
---|
235 |
|
---|
236 | if (!ReadCalibration(calibcont, badpix, extractor1, extractor2, geom))
|
---|
237 | return kFALSE;
|
---|
238 |
|
---|
239 | *fLog << all;
|
---|
240 | if (extractor1)
|
---|
241 | {
|
---|
242 | *fLog << underline << "Signal Extractor found in calibration file" << endl;
|
---|
243 | extractor1->Print();
|
---|
244 | *fLog << endl;
|
---|
245 | }
|
---|
246 | else
|
---|
247 | *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
|
---|
248 |
|
---|
249 | if (extractor2)
|
---|
250 | {
|
---|
251 | *fLog << underline << "Time Extractor found in calibration file" << endl;
|
---|
252 | extractor2->Print();
|
---|
253 | *fLog << endl;
|
---|
254 | }
|
---|
255 | else
|
---|
256 | *fLog << inf << "No Time Extractor: ExtractTime in file." << endl;
|
---|
257 |
|
---|
258 | if (!geom.IsNull())
|
---|
259 | *fLog << inf << "Camera geometry found in file: " << geom << endl;
|
---|
260 | else
|
---|
261 | *fLog << inf << "No Camera geometry found using default <MGeomCamMagic>" << endl;
|
---|
262 |
|
---|
263 | // This is necessary for the case in which it is not in the files
|
---|
264 | MBadPixelsCam badcam;
|
---|
265 |
|
---|
266 | // Setup Parlist
|
---|
267 | MParList plist;
|
---|
268 | plist.AddToList(this); // take care of fDisplay!
|
---|
269 | plist.AddToList(&badcam);
|
---|
270 | plist.AddToList(&pedcam);
|
---|
271 | plist.AddToList(&calibcont);
|
---|
272 |
|
---|
273 | // Setup Tasklist
|
---|
274 | MTaskList tlist;
|
---|
275 | plist.AddToList(&tlist);
|
---|
276 |
|
---|
277 | // FIXME: Move this to an intermediate class MJMagic
|
---|
278 | Byte_t filetype = 2;
|
---|
279 | /*
|
---|
280 | TString name = iter.Next();
|
---|
281 | Byte_t filetype = MRawFileRead::IsFileValid(name);
|
---|
282 | if (!filetype)
|
---|
283 | filetype = MReadMarsFile::IsFileValid(name)+1;
|
---|
284 | if (filetype<1||filetype>3)
|
---|
285 | {
|
---|
286 | gLog << err << "ERROR - FileType #" << (int)filetype << " of first file " << name << " unknown..." << endl;
|
---|
287 | return kFALSE;
|
---|
288 | } */
|
---|
289 | // 1 = raw-file
|
---|
290 | // 2 = raw-root file
|
---|
291 | // 3 = mc-raw file
|
---|
292 |
|
---|
293 | MReadReports readreal;
|
---|
294 | readreal.AddTree("Events", "MTime.", kTRUE);
|
---|
295 | readreal.AddTree("Trigger");
|
---|
296 | readreal.AddTree("Camera");
|
---|
297 | readreal.AddTree("Drive");
|
---|
298 | readreal.AddTree("CC");
|
---|
299 | readreal.AddTree("Currents");
|
---|
300 | readreal.AddFiles(iter);
|
---|
301 |
|
---|
302 | MReadMarsFile readmc("Events");
|
---|
303 | readmc.DisableAutoScheme();
|
---|
304 | readmc.AddFiles(iter);
|
---|
305 |
|
---|
306 | MRawFileRead readraw(NULL);
|
---|
307 | readraw.AddFiles(iter);
|
---|
308 |
|
---|
309 | MGeomApply apply; // Only necessary to create geometry
|
---|
310 | if (!geom.IsNull())
|
---|
311 | apply.SetGeometry(geom);
|
---|
312 | MBadPixelsMerge merge(&badpix);
|
---|
313 | MPedCalcFromLoGain pedlo;
|
---|
314 | MMcPedestalCopy pcopy;
|
---|
315 | MTaskEnv taskenv1("ExtractSignal");
|
---|
316 | MTaskEnv taskenv2("ExtractTime");
|
---|
317 | taskenv1.SetDefault(extractor1);
|
---|
318 | taskenv2.SetDefault(extractor2);
|
---|
319 | MCalibrateData calib;
|
---|
320 | if (filetype==3)
|
---|
321 | calib.SetCalibrationMode(MCalibrateData::kFfactor);
|
---|
322 | MCalibrateRelTimes caltm;
|
---|
323 | MBadPixelsCalc bpcal;
|
---|
324 | MBadPixelsTreat treat;
|
---|
325 |
|
---|
326 | MHCamEvent evt0(0, "PedestalFLG", "Pedestal from Lo Gain;;P [fadc/sl]");
|
---|
327 | MHCamEvent evt1(0, "Extra'd", "Extracted Signal;;S [fadc/sl]");
|
---|
328 | MHCamEvent evt2(0, "PedPhot", "Calibrated Pedestal;;P [\\gamma]");
|
---|
329 | MHCamEvent evt3(1, "PedRMS", "Calibrated Pedestal RMS;;\\sigma_{p} [\\gamma]");
|
---|
330 | MHCamEvent evt4(0, "Interp'd", "Interpolated Signal;;S [\\gamma]");
|
---|
331 | MHCamEvent evt5(2, "Unsuitable", "Unsuitable event ratio;;%");
|
---|
332 | MHCamEvent evt6(0, "Times", "Arrival Time;;T [slice]");
|
---|
333 | evt0.EnableVariance();
|
---|
334 | evt2.EnableVariance();
|
---|
335 | evt3.EnableVariance();
|
---|
336 | evt6.EnableVariance();
|
---|
337 |
|
---|
338 | MFillH fill0(&evt0, "MPedestalCam", "FillPedestalFLG");
|
---|
339 | MFillH fill1(&evt1, "MExtractedSignalCam", "FillExtracted");
|
---|
340 | MFillH fill2(&evt2, "MPedPhotCam", "FillPedPhot");
|
---|
341 | MFillH fill3(&evt3, "MPedPhotCam", "FillPedRMS");
|
---|
342 | MFillH fill4(&evt4, "MCerPhotEvt", "FillInterpolated");
|
---|
343 | MFillH fill5(&evt5, "MBadPixelsCam", "FillUnsuitable");
|
---|
344 | MFillH fill6(&evt6, "MArrivalTime", "FillTimes");
|
---|
345 |
|
---|
346 | MWriteRootFile write(2, Form("%s{s/_D_/_Y_}", fPathOut.Data()), fOverwrite);
|
---|
347 | // Run Header
|
---|
348 | write.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
349 | write.AddContainer("MBadPixelsCam", "RunHeaders");
|
---|
350 | write.AddContainer("MGeomCam", "RunHeaders");
|
---|
351 | // Monte Carlo Headers
|
---|
352 | write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
|
---|
353 | write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
|
---|
354 | write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
|
---|
355 | // Monte Carlo
|
---|
356 | write.AddContainer("MMcEvt", "Events", kFALSE);
|
---|
357 | write.AddContainer("MMcTrig", "Events", kFALSE);
|
---|
358 | // Data
|
---|
359 | write.AddContainer("MCerPhotEvt", "Events");
|
---|
360 | write.AddContainer("MPedPhotCam", "Events");
|
---|
361 | write.AddContainer("MTime", "Events", kFALSE);
|
---|
362 | write.AddContainer("MRawEvtHeader", "Events");
|
---|
363 | write.AddContainer("MArrivalTime", "Events");
|
---|
364 | // Slow-Control: Current
|
---|
365 | write.AddContainer("MTimeCurrents", "Currents", kFALSE);
|
---|
366 | write.AddContainer("MCameraDC", "Currents", kFALSE);
|
---|
367 | write.AddContainer("MReportCurrents", "Currents", kFALSE);
|
---|
368 | // Slow-Control: Camera
|
---|
369 | write.AddContainer("MReportCamera", "Camera", kFALSE);
|
---|
370 | write.AddContainer("MTimeCamera", "Camera", kFALSE);
|
---|
371 | write.AddContainer("MCameraAUX", "Camera", kFALSE);
|
---|
372 | write.AddContainer("MCameraCalibration", "Camera", kFALSE);
|
---|
373 | write.AddContainer("MCameraCooling", "Camera", kFALSE);
|
---|
374 | write.AddContainer("MCameraHV", "Camera", kFALSE);
|
---|
375 | write.AddContainer("MCameraLV", "Camera", kFALSE);
|
---|
376 | write.AddContainer("MCameraLids", "Camera", kFALSE);
|
---|
377 | // Slow-Control: Trigger
|
---|
378 | write.AddContainer("MReportTrigger", "Trigger", kFALSE);
|
---|
379 | write.AddContainer("MTimeTrigger", "Trigger", kFALSE);
|
---|
380 | // Slow-Control: Drive
|
---|
381 | write.AddContainer("MPointingPos", "Drive", kFALSE);
|
---|
382 | write.AddContainer("MReportDrive", "Drive", kFALSE);
|
---|
383 | write.AddContainer("MTimeDrive", "Drive", kFALSE);
|
---|
384 | // Slow-Control: Central Control
|
---|
385 | write.AddContainer("MReportCC", "CC", kFALSE);
|
---|
386 | write.AddContainer("MTimeCC", "CC", kFALSE);
|
---|
387 |
|
---|
388 | // Now setup tasklist for events
|
---|
389 | MTaskList tlist2;
|
---|
390 | tlist2.AddToList(&apply);
|
---|
391 | tlist2.AddToList(&merge);
|
---|
392 | tlist2.AddToList(filetype==3 ? (MTask*)&pcopy : (MTask*)&pedlo);
|
---|
393 | tlist2.AddToList(&fill0);
|
---|
394 | if (extractor1)
|
---|
395 | tlist2.AddToList(&taskenv1);
|
---|
396 | if (extractor2)
|
---|
397 | tlist2.AddToList(&taskenv2);
|
---|
398 | tlist2.AddToList(&fill1);
|
---|
399 | tlist2.AddToList(&calib);
|
---|
400 | tlist2.AddToList(&caltm);
|
---|
401 | tlist2.AddToList(&fill2);
|
---|
402 | tlist2.AddToList(&bpcal);
|
---|
403 | tlist2.AddToList(&treat);
|
---|
404 | tlist2.AddToList(&fill3);
|
---|
405 | tlist2.AddToList(&fill4);
|
---|
406 | tlist2.AddToList(&fill5);
|
---|
407 | tlist2.AddToList(&fill6);
|
---|
408 |
|
---|
409 | // Setup List for Drive-tree
|
---|
410 | MPointingPosCalc pcalc;
|
---|
411 |
|
---|
412 | // Now setup main tasklist
|
---|
413 | switch (filetype)
|
---|
414 | {
|
---|
415 | case 1: tlist.AddToList(&readraw); break;
|
---|
416 | case 2: tlist.AddToList(&readreal); break;
|
---|
417 | case 3: tlist.AddToList(&readmc); break;
|
---|
418 | }
|
---|
419 |
|
---|
420 | tlist.AddToList(&tlist2, "Events");
|
---|
421 | tlist.AddToList(&pcalc, "Drive");
|
---|
422 | tlist.AddToList(&write);
|
---|
423 |
|
---|
424 | // Create and setup the eventloop
|
---|
425 | MEvtLoop evtloop(fName);
|
---|
426 | evtloop.SetParList(&plist);
|
---|
427 | evtloop.SetDisplay(fDisplay);
|
---|
428 | evtloop.SetLogStream(fLog);
|
---|
429 | if (!SetupEnv(evtloop))
|
---|
430 | return kFALSE;
|
---|
431 |
|
---|
432 | // Execute first analysis
|
---|
433 | if (!evtloop.Eventloop(fMaxEvents))
|
---|
434 | {
|
---|
435 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
---|
436 | return kFALSE;
|
---|
437 | }
|
---|
438 |
|
---|
439 | tlist.PrintStatistics();
|
---|
440 |
|
---|
441 | if (!WriteResult())
|
---|
442 | return kFALSE;
|
---|
443 |
|
---|
444 | *fLog << all << GetDescriptor() << ": Done." << endl;
|
---|
445 | *fLog << endl << endl;
|
---|
446 |
|
---|
447 | return kTRUE;
|
---|
448 | }
|
---|