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

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