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

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