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

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