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

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