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

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