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

Last change on this file since 8076 was 7984, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 27.3 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 "MRunIter.h"
47#include "MParList.h"
48#include "MTaskList.h"
49#include "MEvtLoop.h"
50
51#include "MStatusDisplay.h"
52
53#include "MGeomCam.h"
54#include "MHCamEvent.h"
55//#include "MHCamEventTH.h"
56#include "MPedestalCam.h"
57#include "MBadPixelsCam.h"
58#include "MArrivalTimeCam.h"
59
60#include "MCalibrationQECam.h"
61#include "MCalibrationBlindCam.h"
62#include "MCalibrationChargeCam.h"
63#include "MCalibrationRelTimeCam.h"
64#include "MCalibrationChargePINDiode.h"
65#include "MCalibrationHiLoCam.h"
66#include "MCalibrationPulseTimeCam.h"
67#include "MCalibrationPatternDecode.h"
68
69#include "MCalibrationChargeCalc.h"
70#include "MCalibrationRelTimeCalc.h"
71
72#include "MCalibrationIntensityChargeCam.h"
73#include "MCalibrationIntensityBlindCam.h"
74#include "MCalibrationIntensityRelTimeCam.h"
75#include "MCalibrationIntensityQECam.h"
76#include "MCalibrationIntensityConstCam.h"
77#include "MBadPixelsIntensityCam.h"
78
79#include "MHCalibrationChargeCam.h"
80#include "MHCalibrationChargeBlindCam.h"
81#include "MHCalibrationChargePINDiode.h"
82#include "MHCalibrationRelTimeCam.h"
83#include "MHCalibrationPulseTimeCam.h"
84#include "MHCalibrationHiLoCam.h"
85#include "MHCamera.h"
86
87#include "MCalibCalcFromPast.h"
88
89#include "MReadReports.h"
90#include "MReadMarsFile.h"
91#include "MRawFileRead.h"
92#include "MContinue.h"
93#include "MTriggerPatternDecode.h"
94#include "MFTriggerPattern.h"
95#include "MGeomApply.h"
96//#include "MMcPedestalCopy.h"
97#include "MPointingPosCalc.h"
98#include "MPedCalcFromLoGain.h"
99#include "MExtractor.h"
100#include "MExtractTimeAndCharge.h"
101#include "MExtractPINDiode.h"
102#include "MExtractBlindPixel.h"
103#include "MFCosmics.h"
104#include "MTaskEnv.h"
105#include "MCalibrateData.h"
106#include "MCalibrateRelTimes.h"
107#include "MBadPixelsMerge.h"
108#include "MBadPixelsCalc.h"
109#include "MBadPixelsTreat.h"
110#include "MFillH.h"
111#include "MWriteRootFile.h"
112
113ClassImp(MJCalibrateSignal);
114
115using namespace std;
116
117// --------------------------------------------------------------------------
118//
119// Default constructor.
120//
121// Sets:
122// - fIsInterlaced to kTRUE
123// - fIsRelTimesUpdate to kFALSE
124// - fIsHiLoCalibration to kFALSE
125// - fPulsePosCheck to kTRUE
126//
127MJCalibrateSignal::MJCalibrateSignal(const char *name, const char *title)
128 : fExtractor(0), fIsInterlaced(kTRUE), fIsRelTimesUpdate(kFALSE)
129{
130 fName = name ? name : "MJCalibrateSignal";
131 fTitle = title ? title : "Tool to calibrate data";
132
133 SetPulsePosCheck();
134 //fCruns = NULL;
135}
136
137MJCalibrateSignal::~MJCalibrateSignal()
138{
139 if (fExtractor)
140 delete fExtractor;
141}
142
143void MJCalibrateSignal::SetExtractor(const MExtractor *ext)
144{
145 if (fExtractor)
146 delete fExtractor;
147
148 fExtractor = ext ? (MExtractor*)ext->Clone() : NULL;
149}
150
151Bool_t MJCalibrateSignal::WriteResult(TObjArray &cont)
152{
153 if (IsNoStorage())
154 return kTRUE;
155
156 const TString name(Form("signal%08d.root", fSequence.GetSequence()));
157 return WriteContainer(cont, name);
158}
159
160Bool_t MJCalibrateSignal::ReadCalibration(TObjArray &l, MBadPixelsCam &cam, MExtractor* &ext2, MExtractor* &ext3, TString &geom) const
161{
162 TString fname = Form("%s/calib%08d.root", fPathIn.Data(), fSequence.GetSequence());
163
164 *fLog << inf << "Reading from file: " << fname << endl;
165
166 TFile file(fname, "READ");
167 if (!file.IsOpen())
168 {
169 *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
170 return kFALSE;
171 }
172
173 TObject *o = file.Get("ExtractSignal");
174 if (o && !o->InheritsFrom(MExtractor::Class()))
175 {
176 *fLog << err << dbginf << "ERROR - ExtractSignal read from " << fname << " doesn't inherit from MExtractor!" << endl;
177 return kFALSE;
178 }
179 ext3 = o ? (MExtractor*)o->Clone() : NULL;
180
181 o = file.Get("ExtractTime");
182 if (o && !o->InheritsFrom(MExtractor::Class()))
183 {
184 *fLog << err << dbginf << "ERROR - ExtractTime read from " << fname << " doesn't inherit from MExtractor!" << endl;
185 return kFALSE;
186 }
187 ext2 = o ? (MExtractor*)o->Clone() : NULL;
188 if (!ext3 && !ext2)
189 {
190 *fLog << err << dbginf << "ERROR - Neither ExtractSignal nor ExrtractTime found in " << fname << "!" << endl;
191 return kFALSE;
192 }
193
194 o = file.Get("MGeomCam");
195 if (o && !o->InheritsFrom(MGeomCam::Class()))
196 {
197 *fLog << err << dbginf << "ERROR - MGeomCam read from " << fname << " doesn't inherit from MGeomCam!" << endl;
198 return kFALSE;
199 }
200 geom = o ? o->ClassName() : "";
201
202 TObjArray cont(l);
203 cont.Add(&cam);
204 return ReadContainer(cont);
205}
206
207// --------------------------------------------------------------------------
208//
209// MJCalibration allows to setup several option by a resource file:
210// MJCalibrateSignal.RawData: yes,no
211//
212// For more details see the class description and the corresponding Getters
213//
214Bool_t MJCalibrateSignal::CheckEnvLocal()
215{
216 SetInterlaced(GetEnv("Interlaced", fIsInterlaced));
217 SetRelTimesUpdate(GetEnv("RelTimesUpdate", fIsRelTimesUpdate));
218
219 return MJCalib::CheckEnvLocal();
220}
221
222Bool_t MJCalibrateSignal::Process(MPedestalCam &pedcamab, MPedestalCam &pedcambias,
223 MPedestalCam &pedcamextr)
224{
225 if (!fSequence.IsValid())
226 {
227 *fLog << err << "ERROR - Sequence invalid..." << endl;
228 return kFALSE;
229 }
230
231 *fLog << inf;
232 fLog->Separator(GetDescriptor());
233 *fLog << "Calculate calibrated data from Sequence #";
234 *fLog << fSequence.GetSequence() << endl << endl;
235
236
237 //if (!CheckEnv())
238 // return kFALSE;
239
240 CheckEnv();
241
242 // --------------------------------------------------------------------------------
243
244 MDirIter iter;
245 if (fSequence.IsValid())
246 {
247 const Int_t n0 = fSequence.SetupDatRuns(iter, fPathData, IsUseRawData());
248 const Int_t n1 = fSequence.GetNumDatRuns();
249 if (n0==0)
250 {
251 *fLog << err << "ERROR - No input files of sequence found!" << endl;
252 return kFALSE;
253 }
254 if (n0!=n1)
255 {
256 *fLog << err << "ERROR - Number of files found (" << n0 << ") doesn't match number of files in sequence (" << n1 << ")" << endl;
257 if (fLog->GetDebugLevel()>4)
258 {
259 *fLog << dbg << "Files which are searched:" << endl;
260 iter.Print();
261 }
262 return kFALSE;
263 }
264 }
265
266 // Read File
267 MCalibrationIntensityChargeCam ichcam;
268 MCalibrationIntensityQECam iqecam;
269 MCalibrationIntensityBlindCam iblcam;
270 MCalibrationIntensityRelTimeCam itmcam;
271 MCalibrationIntensityConstCam icncam;
272 MBadPixelsIntensityCam ibdcam;
273
274 MHCalibrationChargeCam hchacam;
275 MHCalibrationChargeBlindCam hbndcam;
276 MHCalibrationChargePINDiode hpndiod;
277 MHCalibrationRelTimeCam hrelcam;
278 MHCalibrationHiLoCam hilocam;
279 MHCalibrationPulseTimeCam hpulcam;
280
281 hchacam.SetOscillations(kFALSE);
282 hbndcam.SetOscillations(kFALSE);
283 hrelcam.SetOscillations(kFALSE);
284
285 MCalibrationChargeCam calcam;
286 MCalibrationQECam qecam;
287 MCalibrationBlindCam bndcam;
288 MCalibrationChargePINDiode pind;
289 MCalibrationRelTimeCam tmcam;
290 MCalibrationHiLoCam hilcam;
291 MCalibrationPulseTimeCam pulcam;
292
293 MBadPixelsCam badpix;
294
295 TObjArray interlacedcont;
296 if (fIsInterlaced)
297 {
298 interlacedcont.Add(&ichcam);
299 interlacedcont.Add(&iqecam);
300 interlacedcont.Add(&iblcam);
301 interlacedcont.Add(&itmcam);
302 interlacedcont.Add(&ibdcam);
303 interlacedcont.Add(&icncam);
304 interlacedcont.Add(&hchacam);
305 if (IsUseBlindPixel())
306 interlacedcont.Add(&hbndcam);
307 if (IsUsePINDiode())
308 interlacedcont.Add(&hpndiod);
309 if (fIsRelTimesUpdate)
310 interlacedcont.Add(&hrelcam);
311 }
312
313 MExtractor *extractor1=fExtractor;
314 MExtractor *extractor2=0;
315 MExtractor *extractor3=0;
316 TString geom;
317
318 TObjArray calibcont;
319 calibcont.Add(&calcam);
320 calibcont.Add(&qecam);
321 calibcont.Add(&bndcam);
322 calibcont.Add(&tmcam);
323 if (IsUseBlindPixel())
324 calibcont.Add(&bndcam);
325
326 if (!ReadCalibration(calibcont, badpix, extractor2, extractor3, geom))
327 return kFALSE;
328
329 *fLog << all;
330 if (!geom.IsNull())
331 *fLog << inf << "Camera geometry found in file: " << geom << endl;
332 else
333 *fLog << inf << "No Camera geometry found using default <MGeomCamMagic>" << endl;
334
335 if (extractor3)
336 {
337 *fLog << underline << "Signal Extractor found in calibration file" << endl;
338 extractor3->Print();
339 *fLog << endl;
340 }
341 else
342 *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
343
344
345 if (extractor1)
346 {
347 *fLog << underline << "Modified Signal Extractor set by user." << endl;
348 extractor1->Print();
349 *fLog << endl;
350 }
351 else
352 {
353 *fLog << inf << "No modified Signal Extractor set by user... using ExtractSignal." << endl;
354 extractor1 = extractor3 ? (MExtractor*)extractor3->Clone() : 0;
355 }
356
357 if (extractor2)
358 {
359 *fLog << underline << "Time Extractor found in calibration file" << endl;
360 extractor2->Print();
361 *fLog << endl;
362 }
363 else
364 *fLog << inf << "No Time Extractor: ExtractTime in file." << endl;
365
366 // This is necessary for the case in which it is not in the files
367 MBadPixelsCam badcam;
368 icncam.SetBadPixels(&badpix);
369
370 // Setup Parlist
371 MParList plist;
372 plist.AddToList(this); // take care of fDisplay!
373 plist.AddToList(&badcam);
374 plist.AddToList(&hilcam);
375 plist.AddToList(&calibcont); // Using AddToList(TObjArray *)
376 plist.AddToList(&interlacedcont); // Using AddToList(TObjArray *)
377 plist.AddToList(&pulcam);
378
379 // Setup Tasklist
380 MTaskList tlist;
381 plist.AddToList(&tlist);
382
383 MReadReports readreal;
384 readreal.AddTree("Events", "MTime.", MReadReports::kMaster);
385 readreal.AddTree("Trigger");
386 readreal.AddTree("Camera");
387 readreal.AddTree("Drive");
388 readreal.AddTree("CC");
389 readreal.AddTree("Currents");
390
391 MReadMarsFile readmc("Events");
392 readmc.DisableAutoScheme();
393
394 MRawFileRead rawread(NULL);
395
396 MRead *read = 0;
397 switch (GetDataFlag())
398 {
399 case kIsUseRawData: read = &rawread; break;
400 case kIsUseMC: read = &readmc; break;
401 case kIsUseRootData: read = &readreal; break;
402 }
403 read->AddFiles(iter);
404
405 const TString fname(Form("%s{s/_D_/_Y_}{s/\\.raw$/.root}{s/\\.raw\\.gz$/.root}", fPathOut.Data()));
406
407
408 // Skips MC which have no contents. This are precisely the
409 // events which fullfilled the MC Lvl1 trigger and an
410 // arbitrary cut (typically at 50phe) to speed up simulation
411 MContinue contmc("MRawEvtData.GetNumPixels<0.5", "ContEmptyMC");
412
413 //MPointingPosInterpolate pextr;
414 //pextr.AddFiles(&iter);
415
416 MGeomApply apply; // Only necessary to create geometry
417 if (!geom.IsNull())
418 apply.SetGeometry(geom);
419 MBadPixelsMerge merge(&badpix);
420
421 // Make sure that pedcamab has the correct name
422 pedcamab.SetName("MPedestalFundamental");
423 pedcamextr.SetName("MPedestalFromExtractorRndm");
424 pedcambias.SetName("MPedestalFromExtractor");
425 plist.AddToList(&pedcamextr);
426 plist.AddToList(&pedcambias);
427 plist.AddToList(&pedcamab);
428
429 MArrivalTimeCam timecam;
430 plist.AddToList(&timecam);
431
432 // Check for interleaved events
433 MCalibrationPatternDecode caldec;
434 MTriggerPatternDecode decode;
435
436 // This will make that for data with version less than 5, where
437 // trigger patterns were not yet correct, all the events in the real
438 // data file will be processed. In any case there are no interleaved
439 // calibration events in such data, so this is fine.
440 MFTriggerPattern ftp;
441 ftp.SetDefault(kTRUE);
442 // ftp.RequireCalibration();
443 ftp.DenyCalibration();
444 ftp.DenyPedestal();
445 // ftp.DenyPinDiode();
446 ftp.SetInverted();
447
448 // This will skip interleaved calibration events and pedestal events (if any)
449 // --> tlist2
450 MContinue conttp(&ftp, "ContTrigPattern");
451
452 // Do signal and pedestal calculation
453 MPedCalcFromLoGain pedlo1("MPedCalcFundamental");
454 pedlo1.SetPedestalUpdate(kTRUE);
455 pedlo1.SetNamePedestalCamOut("MPedestalFundamental");
456
457 MPedCalcFromLoGain pedlo2("MPedCalcWithExtractorRndm");
458 pedlo2.SetPedestalUpdate(kTRUE);
459 pedlo2.SetRandomCalculation(kTRUE);
460 pedlo2.SetNamePedestalCamIn("MPedestalFundamental");
461 pedlo2.SetNamePedestalCamOut("MPedestalFromExtractorRndm");
462
463 MPedCalcFromLoGain pedlo3("MPedCalcWithExtractor");
464 pedlo3.SetPedestalUpdate(kTRUE);
465 pedlo3.SetRandomCalculation(kFALSE);
466 pedlo3.SetNamePedestalCamIn("MPedestalFundamental");
467 pedlo3.SetNamePedestalCamOut("MPedestalFromExtractor");
468
469 if (extractor1)
470 {
471 extractor1->SetPedestals(&pedcamab);
472
473 if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
474 {
475 pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
476 pedlo3.SetExtractor((MExtractTimeAndCharge*)extractor1);
477 const Int_t win = ((MExtractTimeAndCharge*)extractor1)->GetWindowSizeHiGain();
478 pedlo1.SetExtractWindow(15, win);
479 pedlo2.SetExtractWindow(15, win/*obsolete*/);
480 pedlo3.SetExtractWindow(15, win/*obsolete*/);
481 }
482 else
483 {
484 // FIXME: How to get the fixed value 15 automatically?
485 const Int_t f = (Int_t)(15.5+extractor1->GetHiGainFirst());
486 const Int_t n = (Int_t)(15.5+extractor1->GetNumHiGainSamples());
487 pedlo1.SetExtractWindow(f, n);
488 pedlo2.SetExtractWindow(f, n);
489 pedlo3.SetExtractWindow(f, n);
490 }
491 }
492 if (extractor2)
493 extractor2->SetPedestals(&pedcamab);
494
495 if (extractor3)
496 extractor3->SetPedestals(&pedcamab);
497
498 MFCosmics fcosmics;
499 fcosmics.SetNamePedestalCam("MPedestalFundamental");
500 MContinue contcos(&fcosmics, "ContTrigEvts");
501 contcos.SetInverted();
502
503 //MMcPedestalCopy pcopy;
504 MTaskEnv taskenv1("ExtractSignal");
505 MTaskEnv taskenv2("ExtractTime");
506 MTaskEnv taskenv3("ExtractInterlaced");
507 taskenv1.SetDefault(extractor1);
508 taskenv2.SetDefault(extractor2);
509 taskenv3.SetDefault(extractor3);
510
511 //
512 // This is new calibration to photo-electrons, hard-coded
513 // as decided at the Wuerzburg software meeting 26.01.05
514 //
515 MCalibrateData calib;
516 calib.SetSignalType(MCalibrateData::kPhe);
517 calib.AddPedestal("Fundamental");
518 calib.AddPedestal("FromExtractor");
519 calib.AddPedestal("FromExtractorRndm");
520 calib.SetPedestalFlag(MCalibrateData::kEvent);
521 //----------------------------------------------------------
522
523 MExtractPINDiode pinext;
524 MExtractBlindPixel bldext;
525
526 MFTriggerPattern fcalib("CalibFilter");
527 fcalib.SetDefault(kFALSE);
528 fcalib.RequireCalibration();
529
530 MCalibrationChargeCalc chcalc;
531 chcalc.SetExtractor(extractor3);
532
533 MCalibrationRelTimeCalc recalc;
534 MCalibCalcFromPast pacalc;
535 chcalc.SetOutputFile("");
536 recalc.SetOutputFile("");
537
538 pinext.SetPedestals(&pedcamab);
539 bldext.SetPedestals(&pedcamab);
540 chcalc.SetPedestals(&pedcamextr);
541
542 pacalc.SetChargeCalc(&chcalc);
543 if (fIsRelTimesUpdate)
544 pacalc.SetRelTimeCalc(&recalc);
545 pacalc.SetCalibrate(&calib);
546
547 //
548 // Intensity Calibration histogramming
549 //
550 MFillH filpin(&hpndiod, "MExtractedSignalPINDiode", "FillPINDiode");
551 MFillH filbnd(&hbndcam, "MExtractedSignalBlindPixel", "FillBlindCam");
552 MFillH filcam(&hchacam, "MExtractedSignalCam", "FillChargeCam");
553 MFillH filtme(&hrelcam, "MArrivalTimeCam", "FillRelTime");
554 MFillH filhil(&hilocam, "MExtractedSignalCam", "FillHiLoRatio");
555 MFillH filpul(&hpulcam, "MRawEvtData", "FillPulseTime");
556 filpin.SetBit(MFillH::kDoNotDisplay);
557 filbnd.SetBit(MFillH::kDoNotDisplay);
558 filcam.SetBit(MFillH::kDoNotDisplay);
559 filtme.SetBit(MFillH::kDoNotDisplay);
560 filhil.SetBit(MFillH::kDoNotDisplay);
561 filpul.SetBit(MFillH::kDoNotDisplay);
562
563 MCalibrateRelTimes caltm;
564 MBadPixelsCalc bpcal;
565 MBadPixelsTreat treat;
566
567 bpcal.SetNamePedPhotCam("MPedPhotFromExtractor");
568 treat.AddNamePedPhotCam("MPedPhotFundamental");
569 treat.AddNamePedPhotCam("MPedPhotFromExtractor");
570 treat.AddNamePedPhotCam("MPedPhotFromExtractorRndm");
571 if (!extractor2 && !extractor1->InheritsFrom("MExtractTimeAndCharge"))
572 treat.SetProcessTimes(kFALSE);
573
574 MHCamEvent evt0( 0, "PedFLG", "Fundamental Pedestal from Lo Gain;;P [cnts/sl]");
575 MHCamEvent evt1( 2, "PedRmsFLG", "RMS from Extractor applied to ped.;;\\sigma_{p} [cnts/sl]");
576 MHCamEvent evt2( 0, "Extra'd", "Extracted Signal;;S [cnts/sl]");
577 // MHCamEvent evt3(4, "PedPhot", "Calibrated Pedestal;;P [phe]");
578 MHCamEvent evt4( 5, "PedRMS", "Calibrated RMS from Extractor applied to ped.;;\\sigma_{p} [phe]");
579 MHCamEvent evt5( 0, "Interp'd", "Interpolated Signal scaled with A/A_{0};;S [phe]");
580 MHCamEvent evt6(102, "Unsuitable", "Fraction of unsuitable events per Pixel;;[1]");
581 // MHCamEvent evt7( 6, "Times", "Calibrated Arrival Time;;T [fadc sl]");
582 MHCamEvent evt8( 0, "Conv", "Calibration Conv. Factors;;[phe/fadc cnts]");
583 MHCamEvent evt9( 7, "PulsePos", "Pulse Position of cosmics (>50phe);;T");
584 MHCamEvent evtR( 4, "HiLoCal", "Hi-/Lo-Gain ratio;;Ratio");
585 MHCamEvent evtO( 7, "HiLoOff", "Lo-/Hi-Gain Offset;;Offset");
586 evt6.SetThreshold();
587
588 MFillH fill0(&evt0, "MPedestalFundamental", "FillPedFLG");
589 MFillH fill1(&evt1, "MPedestalFromExtractorRndm", "FillPedRmsFLG");
590 MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtracted");
591 // MFillH fill3(&evt3, "MPedPhotFundamental", "FillPedPhot");
592 MFillH fill4(&evt4, "MPedPhotFromExtractorRndm", "FillPedRMS");
593 MFillH fill5(&evt5, "MSignalCam", "FillInterpolated");
594 MFillH fill6(&evt6, "MBadPixelsCam", "FillUnsuitable");
595 // MFillH fill7(&evt7, "MSignalCam", "FillTimes");
596 MFillH fill8(&evt8, "MCalibrationIntensityConstCam", "FillConv");
597 MFillH fill9(&evt9, "MSignalCam", "FillPulse");
598 MFillH fillR(&evtR, "MExtractedSignalCam", "FillHiLoCal");
599 MFillH fillO(&evtO, "MArrivalTimeCam", "FillHiLoOff");
600
601 MTaskEnv fillflorian("FinalFantasy");
602 fillflorian.SetDefault();
603
604 // The second rule is for the case reading raw-files!
605 MWriteRootFile write(2, fname, fOverwrite?"RECREATE":"NEW");
606 // Run Header
607 write.AddContainer("MRawRunHeader", "RunHeaders");
608 write.AddContainer("MBadPixelsCam", "RunHeaders");
609 write.AddContainer("MGeomCam", "RunHeaders");
610 // Monte Carlo Headers
611 write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
612 write.AddContainer("MMcFadcHeader", "RunHeaders", kFALSE);
613 write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
614 write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
615 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
616 // Monte Carlo
617 write.AddContainer("MMcEvt", "Events", kFALSE);
618 write.AddContainer("MMcTrig", "Events", kFALSE);
619 // Data tree
620 write.AddContainer("MSignalCam", "Events");
621 write.AddContainer("MPedPhotFundamental", "Events");
622 write.AddContainer("MPedPhotFromExtractor", "Events");
623 write.AddContainer("MPedPhotFromExtractorRndm", "Events");
624 write.AddContainer("MTime", "Events", kFALSE);
625 write.AddContainer("MRawEvtHeader", "Events");
626 // Slow-Control: Current-tree
627 write.AddContainer("MTimeCurrents", "Currents", kFALSE);
628 write.AddContainer("MCameraDC", "Currents", kFALSE);
629 write.AddContainer("MReportCurrents", "Currents", kFALSE);
630 // Slow-Control: Camera-tree
631 write.AddContainer("MReportCamera", "Camera", kFALSE);
632 write.AddContainer("MTimeCamera", "Camera", kFALSE);
633 write.AddContainer("MCameraAUX", "Camera", kFALSE);
634 write.AddContainer("MCameraCalibration", "Camera", kFALSE);
635 write.AddContainer("MCameraCooling", "Camera", kFALSE);
636 write.AddContainer("MCameraHV", "Camera", kFALSE);
637 write.AddContainer("MCameraLV", "Camera", kFALSE);
638 write.AddContainer("MCameraLids", "Camera", kFALSE);
639 // Slow-Control: Trigger-tree
640 write.AddContainer("MReportTrigger", "Trigger", kFALSE);
641 write.AddContainer("MTimeTrigger", "Trigger", kFALSE);
642 // Slow-Control: Drive-tree
643 write.AddContainer("MReportDrive", "Drive", kFALSE);
644 write.AddContainer("MTimeDrive", "Drive", kFALSE);
645 // Slow-Control: Central Control-tree
646 write.AddContainer("MReportCC", "CC", kFALSE);
647 write.AddContainer("MTimeCC", "CC", kFALSE);
648
649 // Write the special MC tree
650 MWriteRootFile writemc(2, fname, fOverwrite?"RECREATE":"NEW");
651 writemc.SetName("WriteMC");
652 writemc.AddContainer("MMcEvtBasic", "OriginalMC");
653
654 // Now setup tasklist for events
655 MTaskList tlist2;
656
657 tlist2.AddToList(&caldec);
658 tlist2.AddToList(&decode);
659 tlist2.AddToList(&apply);
660 tlist2.AddToList(&merge);
661 tlist2.AddToList(&pedlo1);
662 tlist2.AddToList(&pedlo2);
663 tlist2.AddToList(&pedlo3);
664 //-----------------------------------------------------------
665
666 MTaskList tlist3;
667 tlist3.SetFilter(&fcalib);
668
669 if (fIsInterlaced)
670 {
671 tlist2.AddToList(&fcalib);
672 tlist2.AddToList(&tlist3);
673
674 if (IsUsePINDiode())
675 tlist3.AddToList(&pinext);
676 if (IsUseBlindPixel())
677 tlist3.AddToList(&bldext);
678 tlist3.AddToList(&taskenv3);
679 tlist3.AddToList(&pacalc);
680 tlist3.AddToList(&filcam);
681 if (fIsRelTimesUpdate)
682 tlist3.AddToList(&filtme);
683 if (IsUseBlindPixel())
684 tlist3.AddToList(&filbnd);
685 if (IsUsePINDiode())
686 tlist3.AddToList(&filpin);
687 tlist3.AddToList(&chcalc);
688 if (fIsRelTimesUpdate)
689 tlist3.AddToList(&recalc);
690 }
691
692 // Continue for all non-cosmic events
693 tlist2.AddToList(&conttp);
694 if (extractor1)
695 tlist2.AddToList(&taskenv1);
696 if (extractor2)
697 tlist2.AddToList(&taskenv2);
698 tlist2.AddToList(&fill0);
699 tlist2.AddToList(&fill1);
700 tlist2.AddToList(&contcos);
701 if (fIsHiLoCalibration)
702 {
703 plist.AddToList(&hilocam);
704 tlist2.AddToList(&filhil);
705 }
706 if (fIsPulsePosCheck)
707 {
708 plist.AddToList(&hpulcam);
709 tlist2.AddToList(&filpul);
710 }
711
712 tlist2.AddToList(&fill2);
713 tlist2.AddToList(&calib);
714 if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
715 tlist2.AddToList(&caltm);
716 if (fIsInterlaced)
717 tlist2.AddToList(&fill8);
718 tlist2.AddToList(&bpcal);
719 tlist2.AddToList(&treat);
720 tlist2.AddToList(&fill6);
721 // tlist2.AddToList(&fill3);
722 tlist2.AddToList(&fill4);
723 tlist2.AddToList(&fill5);
724 //if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
725 // tlist2.AddToList(&fill7);
726 tlist2.AddToList(&fill9);
727 tlist2.AddToList(&fillR);
728 tlist2.AddToList(&fillO);
729
730 tlist2.AddToList(&fillflorian);
731
732 // Setup List for Drive-tree
733 //MPointingPosCalc pcalc;
734
735 // Now setup main tasklist
736 tlist.AddToList(read);
737
738 if (IsUseMC())
739 {
740 tlist.AddToList(&writemc);
741 tlist.AddToList(&contmc);
742 }
743
744 //if (IsUseRootData())
745 // tlist2.AddToList(&pextr);
746 tlist.AddToList(&tlist2, IsUseRootData() ? "Events" : "All");
747
748 //if (IsUseMC())
749 // tlist.AddToList(&pcalc, "Drive");
750
751 tlist.AddToList(&write);
752
753 // Create and setup the eventloop
754 MEvtLoop evtloop(fName);
755 evtloop.SetParList(&plist);
756 evtloop.SetDisplay(fDisplay);
757 evtloop.SetLogStream(fLog);
758 if (!SetupEnv(evtloop))
759 return kFALSE;
760
761 // Execute first analysis
762 const Bool_t rc = evtloop.Eventloop(fMaxEvents);
763
764 // make sure owned object are deleted
765 if (extractor1 && extractor1!=fExtractor)
766 delete extractor1;
767 if (extractor2)
768 delete extractor2;
769 if (extractor3)
770 delete extractor3;
771
772 // return if job failed
773 if (!rc)
774 {
775 *fLog << err << GetDescriptor() << ": Failed." << endl;
776 return kFALSE;
777 }
778
779 // if everything went ok write and display result
780 DisplayResult(plist);
781
782 if (fIsPixelCheck)
783 {
784 if (fIsPulsePosCheck)
785 hpulcam[fCheckedPixId].DrawClone("");
786
787 if (fIsHiLoCalibration)
788 hilocam[fCheckedPixId].DrawClone("");
789 }
790
791 interlacedcont.Add(&pulcam);
792
793 if (fIsHiLoCalibration)
794 interlacedcont.Add(&hilcam);
795
796 if (fIsPulsePosCheck)
797 interlacedcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
798
799 if (fIsHiLoCalibration)
800 interlacedcont.Add(plist.FindObject("MHCalibrationHiLoCam"));
801
802 if (!WriteResult(interlacedcont))
803 return kFALSE;
804
805 // return if job went ok
806 *fLog << all << GetDescriptor() << ": Done." << endl;
807 *fLog << endl << endl;
808
809 return kTRUE;
810}
811
812
813void MJCalibrateSignal::DisplayResult(MParList &plist)
814{
815 if (!fDisplay || !fIsHiLoCalibration)
816 return;
817
818 MCalibrationHiLoCam *hcam = (MCalibrationHiLoCam*)plist.FindObject("MCalibrationHiLoCam");
819 MGeomCam *geom = (MGeomCam*)plist.FindObject("MGeomCam");
820 if (!hcam || !geom)
821 return;
822
823 // Create histograms to display
824 MHCamera disp1(*geom, "HiLoConv", "Ratio Amplification HiGain vs. LoGain (Charges)");
825 MHCamera disp2(*geom, "HiLoDiff", "Arrival Time Diff. HiGain vs. LoGain (Times)");
826
827 disp1.SetCamContent(*hcam, 0);
828 disp1.SetCamError( *hcam, 1);
829 disp2.SetCamContent(*hcam, 5);
830 disp2.SetCamError( *hcam, 6);
831
832 disp1.SetYTitle("R [1]");
833 disp2.SetYTitle("\\Delta T [FADC sl.]");
834
835 TCanvas &c1 = fDisplay->AddTab("HiLoConv");
836 c1.Divide(2,3);
837
838 disp1.CamDraw(c1, 1, 2, 1);
839 disp2.CamDraw(c1, 2, 2, 1);
840}
841
Note: See TracBrowser for help on using the repository browser.