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

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