source: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignalFromOutside.cc@ 6000

Last change on this file since 6000 was 5866, checked in by gaug, 20 years ago
*** empty log message ***
File size: 17.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// MJCalibrateSignalFromOutside
27//
28// This class is reading the output written by callisto. It calibrates
29// signal and time.
30//
31// The signal and time extractors are read from the callisto-output. In
32// pricipal you could overwrite these default using the resource file,
33// but this is NOT recommended!
34//
35/////////////////////////////////////////////////////////////////////////////
36#include "MJCalibrateSignalFromOutside.h"
37
38#include <TEnv.h>
39#include <TFile.h>
40
41#include "MLog.h"
42#include "MLogManip.h"
43
44#include "MDirIter.h"
45#include "MRunIter.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 "MPedPhotCam.h"
56#include "MCalibrationHiLoCam.h"
57#include "MBadPixelsCam.h"
58
59#include "MCalibrationQECam.h"
60#include "MCalibrationBlindCam.h"
61#include "MCalibrationChargeCam.h"
62#include "MCalibrationRelTimeCam.h"
63#include "MCalibrationChargePINDiode.h"
64
65#include "MCalibrationChargeCalc.h"
66#include "MCalibrationRelTimeCalc.h"
67
68#include "MCalibrationIntensityChargeCam.h"
69#include "MCalibrationIntensityBlindCam.h"
70#include "MCalibrationIntensityRelTimeCam.h"
71#include "MCalibrationIntensityQECam.h"
72#include "MBadPixelsIntensityCam.h"
73
74#include "MHCalibrationChargeCam.h"
75#include "MHCalibrationChargeBlindCam.h"
76#include "MHCalibrationChargePINDiode.h"
77#include "MHCalibrationRelTimeCam.h"
78
79#include "MCalibCalcFromPast.h"
80
81#include "MReadReports.h"
82#include "MReadMarsFile.h"
83#include "MRawFileRead.h"
84#include "MTriggerPatternDecode.h"
85#include "MFTriggerPattern.h"
86#include "MContinue.h"
87#include "MGeomApply.h"
88#include "MMcPedestalCopy.h"
89#include "MPointingPosCalc.h"
90#include "MPedCalcFromLoGain.h"
91#include "MExtractor.h"
92#include "MExtractPINDiode.h"
93#include "MExtractBlindPixel.h"
94#include "MTaskEnv.h"
95#include "MCalibrateData.h"
96#include "MCalibrateRelTimes.h"
97#include "MBadPixelsMerge.h"
98#include "MBadPixelsCalc.h"
99#include "MBadPixelsTreat.h"
100#include "MFillH.h"
101#include "MWriteRootFile.h"
102
103ClassImp(MJCalibrateSignalFromOutside);
104
105using namespace std;
106
107// --------------------------------------------------------------------------
108//
109// Default constructor.
110//
111// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
112//
113MJCalibrateSignalFromOutside::MJCalibrateSignalFromOutside(const char *name, const char *title)
114 : fIsDataCheck(kFALSE), fGeometry("MGeomCamMagic"), fInterlaced(kFALSE)
115{
116 fName = name ? name : "MJCalibrateSignalFromOutside";
117 fTitle = title ? title : "Tool to calibrate data";
118}
119
120Bool_t MJCalibrateSignalFromOutside::WriteResult()
121{
122 if (fPathOut.IsNull())
123 {
124 *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
125 return kTRUE;
126 }
127
128 const TString oname = Form("%s/signal%08d.root", (const char*)fPathOut, fSequence.GetSequence());
129
130 *fLog << inf << "Writing to file: " << oname << endl;
131
132 TFile file(oname, "RECREATE");
133
134 *fLog << inf << " - MStatusDisplay..." << flush;
135 if (fDisplay && fDisplay->Write()<=0)
136 {
137 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
138 return kFALSE;
139 }
140 *fLog << inf << "ok." << endl;
141
142 return kTRUE;
143}
144
145Bool_t MJCalibrateSignalFromOutside::ProcessFile(MPedestalCam &pedcamab, MPedestalCam &pedcam2, MCalibrationChargeCam &chargecam, MCalibrationQECam &qecam, MCalibrationRelTimeCam &relcam, Byte_t filetype)
146{
147 // --------------------------------------------------------------------------------
148
149 *fLog << inf;
150 fLog->Separator(GetDescriptor());
151
152 *fLog << "Calibrate data from ";
153 *fLog << "Runs " << fRuns->GetRunsAsString() << endl;
154 *fLog << endl;
155
156 MDirIter iter;
157
158 *fLog << all;
159 if (fExtractor)
160 {
161 *fLog << underline << "Signal Extractor found in calibration file" << endl;
162 fExtractor->Print();
163 *fLog << endl;
164 }
165 else
166 {
167 *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
168 return kFALSE;
169 }
170
171 fExtractor->SetPedestals(&pedcamab);
172
173 // Setup Parlist
174 MParList plist;
175 plist.AddToList(this); // take care of fDisplay!
176 plist.AddToList(&fBadPixels);
177 plist.AddToList(&pedcam2);
178 plist.AddToList(&pedcamab);
179 plist.AddToList(&chargecam);
180 plist.AddToList(&qecam);
181 plist.AddToList(&relcam);
182
183 MCalibrationIntensityChargeCam intenscharge;
184 MCalibrationIntensityRelTimeCam intensreltime;
185 MCalibrationIntensityQECam intensqe;
186 MCalibrationIntensityBlindCam intensblind;
187 MBadPixelsIntensityCam intensbad;
188
189 MHCalibrationChargeCam hchargecam;
190 MHCalibrationChargeBlindCam hblindcam;
191 MHCalibrationChargePINDiode hpindiode;
192 MHCalibrationRelTimeCam hrelcam;
193
194 //
195 // Calibration Results containers
196 //
197 if (fInterlaced)
198 {
199 plist.AddToList(&intensqe);
200 plist.AddToList(&intenscharge);
201 plist.AddToList(&intensblind);
202 // plist.AddToList(&intensCalibrationPINDiode);
203 plist.AddToList(&intensreltime);
204 plist.AddToList(&intensbad);
205
206 hchargecam.SetLast(499.5);
207 hchargecam.SetNbins(300);
208
209 hchargecam.SetLoGain(kFALSE);
210 hrelcam.SetLoGain(kFALSE);
211
212 hchargecam.SetOscillations(kFALSE);
213 hrelcam.SetOscillations(kFALSE);
214
215 plist.AddToList(&hchargecam);
216 plist.AddToList(&hblindcam);
217 plist.AddToList(&hrelcam);
218 plist.AddToList(&hpindiode);
219 }
220
221 MPedPhotCam pedphotcam;
222 plist.AddToList(&pedphotcam);
223
224 MFillH fillhilo("MHCalibrationHiLoCam", "MExtractedSignalCam", "FillHiLoCam");
225 fillhilo.SetBit(MFillH::kDoNotDisplay);
226
227 MCalibrationHiLoCam hilocam;
228 plist.AddToList(&hilocam);
229 // Setup Tasklist
230 MTaskList tlist;
231 plist.AddToList(&tlist);
232
233 MReadReports readreal;
234 readreal.AddTree("Events", "MTime.", kTRUE);
235 readreal.AddTree("Trigger");
236 readreal.AddTree("Camera");
237 readreal.AddTree("Drive");
238 readreal.AddTree("CC");
239 readreal.AddTree("Currents");
240
241 // MReadMarsFile read("Events");
242 // read.DisableAutoScheme();
243 MRawFileRead rawread(NULL);
244 if (IsDataCheck())
245 rawread.AddFiles(*fRuns);
246 else
247 {
248 // read.AddFiles(*fRuns);
249 readreal.AddFiles(*fRuns);
250 }
251
252 // Check for interleaved events
253 MTriggerPatternDecode decode;
254
255 MGeomApply apply; // Only necessary to create geometry
256 apply.SetGeometry(fGeometry);
257 MBadPixelsMerge merge(&fBadPixels);
258
259 MPedestalCam pedcam;
260
261 pedcamab.SetName("MPedestalFundamental");
262 pedcam2.SetName("MPedestalFromExtractorRndm");
263 pedcam.SetName("MPedestalFromExtractor");
264 plist.AddToList(&pedcam);
265 plist.AddToList(&pedcam2);
266 plist.AddToList(&pedcamab);
267
268 // Do signal and pedestal calculation
269 MPedCalcFromLoGain pedlo1("MPedCalcFundamental");
270 pedlo1.SetPedestalUpdate(kTRUE);
271 pedlo1.SetNamePedestalCamOut("MPedestalFundamental");
272
273 MPedCalcFromLoGain pedlo2("MPedCalcWithExtractorRndm");
274 pedlo2.SetPedestalUpdate(kTRUE);
275 pedlo2.SetRandomCalculation(kTRUE);
276 pedlo2.SetNamePedestalCamIn("MPedestalFundamental");
277 pedlo2.SetNamePedestalCamOut("MPedestalFromExtractorRndm");
278
279 MPedCalcFromLoGain pedlo3("MPedCalcWithExtractor");
280 pedlo3.SetPedestalUpdate(kTRUE);
281 pedlo3.SetRandomCalculation(kFALSE);
282 pedlo3.SetNamePedestalCamIn("MPedestalFundamental");
283 pedlo3.SetNamePedestalCamOut("MPedestalFromExtractor");
284
285 if (fExtractor)
286 {
287 fExtractor->SetPedestals(&pedcamab);
288
289 if (fExtractor->InheritsFrom("MExtractTimeAndCharge"))
290 {
291 pedlo2.SetExtractor((MExtractTimeAndCharge*)fExtractor);
292 pedlo3.SetExtractor((MExtractTimeAndCharge*)fExtractor);
293 pedlo1.SetExtractWindow(15, 0/*obsolete*/);
294 pedlo2.SetExtractWindow(15, 0/*obsolete*/);
295 pedlo3.SetExtractWindow(15, 0/*obsolete*/);
296 }
297 else
298 {
299 // FIXME: How to get the fixed value 15 automatically?
300 const Int_t f = (Int_t)(15.5+fExtractor->GetHiGainFirst());
301 const Int_t n = (Int_t)(15.5+fExtractor->GetNumHiGainSamples());
302 pedlo1.SetExtractWindow(f, n);
303 pedlo2.SetExtractWindow(f, n);
304 pedlo3.SetExtractWindow(f, n);
305 }
306 }
307
308 MMcPedestalCopy pcopy;
309 MTaskEnv taskenv1("ExtractSignal");
310 taskenv1.SetDefault(fExtractor);
311 MCalibrateData calib;
312 if (filetype==3) // MC file
313 {
314 calib.SetCalibrationMode(MCalibrateData::kFfactor);
315 calib.SetPedestalFlag(MCalibrateData::kRun);
316 calib.AddPedestal("MPedestalCam", "MPedPhotFundamental");
317 calib.AddPedestal("MPedestalCam", "MPedPhotFromExtractor");
318 calib.AddPedestal("MPedestalCam", "MPedPhotFromExtractorRndm");
319 }
320 else
321 {
322 calib.AddPedestal("Fundamental");
323 calib.AddPedestal("FromExtractor");
324 calib.AddPedestal("FromExtractorRndm");
325 calib.SetPedestalFlag(MCalibrateData::kEvent);
326 calib.SetSignalType(MCalibrateData::kPhe);
327 }
328
329 MCalibrateRelTimes caltm;
330 MBadPixelsCalc bpcal;
331 MBadPixelsTreat treat;
332
333 bpcal.SetNamePedPhotCam("MPedPhotFromExtractor");
334 treat.AddNamePedPhotCam("MPedPhotFundamental");
335 treat.AddNamePedPhotCam("MPedPhotFromExtractor");
336 treat.AddNamePedPhotCam("MPedPhotFromExtractorRndm");
337
338 MHCamEvent evt0(0, "PedFLG", "Pedestal from Lo Gain;;P [fadc/sl]");
339 MHCamEvent evt1(2, "PedRmsFLG", "Pedestal RMS from Lo Gain;;\\sigma_{p} [fadc/sl]");
340 MHCamEvent evt2(0, "Extra'd", "Extracted Signal;;S [fadc/sl]");
341 MHCamEvent evt3(0, "PedPhot", "Calibrated Pedestal;;P [\\gamma]");
342 MHCamEvent evt4(1, "PedRMS", "Calibrated Pedestal RMS;;\\sigma_{p} [\\gamma]");
343 MHCamEvent evt5(3, "Interp'd", "Interpolated Signal;;S [\\gamma]");
344 MHCamEvent evt6(2, "Unsuitable", "Unsuitable event ratio;;%");
345 MHCamEvent evt7(0, "Times", "Arrival Time;;T [slice]");
346 MHCamEvent evt8(0, "HiLoConv", "Ratio Hi-Lo Gain Signal;;Ratio [1]");
347
348 evt0.EnableVariance();
349 evt1.EnableVariance();
350 evt2.EnableVariance();
351 evt3.EnableVariance();
352 evt4.EnableVariance();
353 evt5.EnableVariance();
354 evt7.EnableVariance();
355 evt8.EnableVariance();
356
357 MFillH fill0(&evt0, "MPedestalFundamental", "FillPedFLG");
358 MFillH fill1(&evt1, "MPedestalFromExtractorRndm", "FillPedRmsFLG");
359 MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtracted");
360 MFillH fill3(&evt3, "MPedPhotFundamental", "FillPedPhot");
361 MFillH fill4(&evt4, "MPedPhotFromExtractorRndm","FillPedRMS");
362 MFillH fill5(&evt5, "MCerPhotEvt", "FillInterpolated");
363 MFillH fill6(&evt6, "MBadPixelsCam", "FillUnsuitable");
364 MFillH fill7(&evt7, "MArrivalTime", "FillTimes");
365 MFillH fill8(&evt8, &hilocam, "FillHiLo");
366
367 MWriteRootFile write(2, Form("%s{s/_D_/_Y_}", fPathOut.Data()), fOverwrite);
368 // Run Header
369 write.AddContainer("MRawRunHeader", "RunHeaders");
370 write.AddContainer("MBadPixelsCam", "RunHeaders");
371 write.AddContainer("MGeomCam", "RunHeaders");
372 // Monte Carlo Headers
373 write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
374 write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
375 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
376 // Monte Carlo
377 write.AddContainer("MMcEvt", "Events", kFALSE);
378 write.AddContainer("MMcTrig", "Events", kFALSE);
379 // Data
380 write.AddContainer("MCerPhotEvt", "Events");
381 write.AddContainer("MPedPhotCam", "Events");
382 write.AddContainer("MTime", "Events", kFALSE);
383 write.AddContainer("MRawEvtHeader", "Events");
384 write.AddContainer("MArrivalTime", "Events");
385 // Slow-Control: Current
386 write.AddContainer("MTimeCurrents", "Currents", kFALSE);
387 write.AddContainer("MCameraDC", "Currents", kFALSE);
388 write.AddContainer("MReportCurrents", "Currents", kFALSE);
389 // Slow-Control: Camera
390 write.AddContainer("MReportCamera", "Camera", kFALSE);
391 write.AddContainer("MTimeCamera", "Camera", kFALSE);
392 write.AddContainer("MCameraAUX", "Camera", kFALSE);
393 write.AddContainer("MCameraCalibration", "Camera", kFALSE);
394 write.AddContainer("MCameraCooling", "Camera", kFALSE);
395 write.AddContainer("MCameraHV", "Camera", kFALSE);
396 write.AddContainer("MCameraLV", "Camera", kFALSE);
397 write.AddContainer("MCameraLids", "Camera", kFALSE);
398 // Slow-Control: Trigger
399 write.AddContainer("MReportTrigger", "Trigger", kFALSE);
400 write.AddContainer("MTimeTrigger", "Trigger", kFALSE);
401 // Slow-Control: Drive
402 write.AddContainer("MPointingPos", "Drive", kFALSE);
403 write.AddContainer("MReportDrive", "Drive", kFALSE);
404 write.AddContainer("MTimeDrive", "Drive", kFALSE);
405 // Slow-Control: Central Control
406 write.AddContainer("MReportCC", "CC", kFALSE);
407 write.AddContainer("MTimeCC", "CC", kFALSE);
408
409 // Now setup tasklist for events
410 MTaskList tlist2;
411 tlist2.AddToList(&apply);
412 tlist2.AddToList(&merge);
413 tlist2.AddToList(&decode);
414 if (filetype==3)
415 tlist2.AddToList(&pcopy);
416 else
417 {
418 tlist2.AddToList(&pedlo1);
419 tlist2.AddToList(&pedlo2);
420 }
421 MExtractPINDiode pinext;
422 MExtractBlindPixel blindext;
423
424 MFTriggerPattern fcalib;
425
426 MCalibrationChargeCalc chargecalc;
427 MCalibrationRelTimeCalc relcalc;
428
429 MCalibCalcFromPast pastcalc;
430
431 pinext.SetPedestals(&pedcamab);
432 blindext.SetPedestals(&pedcamab);
433 chargecalc.SetPedestals(&pedcam2);
434
435 pastcalc.SetChargeCalc(&chargecalc);
436 pastcalc.SetRelTimeCalc(&relcalc);
437 pastcalc.SetCalibrate(&calib);
438
439 tlist2.AddToList(&fill0);
440 tlist2.AddToList(&fill1);
441 tlist2.AddToList(&taskenv1);
442 tlist2.AddToList(&fill2);
443 tlist2.AddToList(&pinext);
444 tlist2.AddToList(&blindext);
445 //
446 // Calibration histogramming
447 //
448 MFillH fillpin("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode", "FillPINDiode");
449 MFillH fillbnd("MHCalibrationChargeBlindCam", "MExtractedSignalBlindPixel", "FillBlindCam");
450 MFillH fillcam("MHCalibrationChargeCam", "MExtractedSignalCam", "FillChargeCam");
451 MFillH filltme("MHCalibrationRelTimeCam", "MArrivalTimeCam", "FillRelTime");
452 fillpin.SetBit(MFillH::kDoNotDisplay);
453 fillbnd.SetBit(MFillH::kDoNotDisplay);
454 fillcam.SetBit(MFillH::kDoNotDisplay);
455 filltme.SetBit(MFillH::kDoNotDisplay);
456
457 //
458 // Calibration Results containers
459 //
460 if (fInterlaced)
461 {
462 fcalib.DenyCalibration();
463 fcalib.SetInverted();
464
465 chargecalc.SetFilter(&fcalib);
466 pastcalc.SetFilter( &fcalib);
467 fillcam.SetFilter(&fcalib);
468 filltme.SetFilter(&fcalib);
469 fillbnd.SetFilter(&fcalib);
470 fillpin.SetFilter(&fcalib);
471
472 tlist2.AddToList(&fcalib);
473 tlist2.AddToList(&pastcalc);
474 tlist2.AddToList(&fillcam);
475 tlist2.AddToList(&filltme);
476 tlist2.AddToList(&fillbnd);
477 tlist2.AddToList(&fillpin);
478 tlist2.AddToList(&chargecalc);
479 tlist2.AddToList(&relcalc);
480 }
481
482 tlist2.AddToList(&calib);
483 if (&relcam)
484 tlist2.AddToList(&caltm);
485 tlist2.AddToList(&fillhilo);
486 tlist2.AddToList(&fill3);
487 tlist2.AddToList(&bpcal);
488 tlist2.AddToList(&treat);
489 tlist2.AddToList(&fill4);
490 tlist2.AddToList(&fill5);
491 tlist2.AddToList(&fill6);
492 tlist2.AddToList(&fill7);
493 tlist2.AddToList(&fill8);
494
495 // Setup List for Drive-tree
496 MPointingPosCalc pcalc;
497
498 // Now setup main tasklist
499 tlist.AddToList(IsDataCheck() ? (MTask*)&rawread : (MTask*)&readreal);
500 tlist.AddToList(&tlist2, IsDataCheck()?"All":"Events");
501
502 // if (!IsDataCheck())
503 // tlist.AddToList(&pcalc, "Drive");
504
505 tlist.AddToList(&write);
506
507 // Create and setup the eventloop
508 MEvtLoop evtloop(fName);
509 evtloop.SetParList(&plist);
510 evtloop.SetDisplay(fDisplay);
511 evtloop.SetLogStream(fLog);
512 if (!SetupEnv(evtloop))
513 return kFALSE;
514
515 // Execute first analysis
516 if (!evtloop.Eventloop(fMaxEvents))
517 {
518 *fLog << err << GetDescriptor() << ": Failed." << endl;
519 return kFALSE;
520 }
521
522 tlist.PrintStatistics();
523
524
525 if (fInterlaced)
526 {
527 TObjArray cont;
528 cont.Add(&intensqe);
529 cont.Add(&intenscharge);
530 cont.Add(&intensblind);
531 // cont.Add(&intensCalibrationPINDiode);
532 cont.Add(&intensreltime);
533 cont.Add(&intensbad);
534 WriteContainer(cont);
535 }
536
537 if (!WriteResult())
538 return kFALSE;
539
540 *fLog << all << GetDescriptor() << ": Done." << endl;
541 *fLog << endl << endl;
542
543 return kTRUE;
544}
Note: See TracBrowser for help on using the repository browser.