source: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc@ 4814

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