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

Last change on this file since 6964 was 6958, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 29.6 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 if (IsUseBlindPixel())
371 interlacedcont.Add(&hbndcam);
372 if (IsUsePINDiode())
373 interlacedcont.Add(&hpndiod);
374 if (fIsRelTimesUpdate)
375 interlacedcont.Add(&hrelcam);
376 }
377
378 MExtractor *extractor1=fExtractor;
379 MExtractor *extractor2=0;
380 MExtractor *extractor3=0;
381 TString geom;
382
383 TObjArray calibcont;
384 calibcont.Add(&calcam);
385 calibcont.Add(&qecam);
386 calibcont.Add(&bndcam);
387 calibcont.Add(&pind);
388 calibcont.Add(&tmcam);
389
390 if (!ReadCalibration(calibcont, badpix, extractor2, extractor3, geom))
391 return kFALSE;
392
393 *fLog << all;
394 if (!geom.IsNull())
395 *fLog << inf << "Camera geometry found in file: " << geom << endl;
396 else
397 *fLog << inf << "No Camera geometry found using default <MGeomCamMagic>" << endl;
398
399 if (extractor3)
400 {
401 *fLog << underline << "Signal Extractor found in calibration file" << endl;
402 extractor3->Print();
403 *fLog << endl;
404 }
405 else
406 *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
407
408
409 if (extractor1)
410 {
411 *fLog << underline << "Modified Signal Extractor set by user." << endl;
412 extractor1->Print();
413 *fLog << endl;
414 }
415 else
416 {
417 *fLog << inf << "No modified Signal Extractor set by user... using ExtractSignal." << endl;
418 extractor1 = extractor3 ? (MExtractor*)extractor3->Clone() : 0;
419 }
420
421 if (extractor2)
422 {
423 *fLog << underline << "Time Extractor found in calibration file" << endl;
424 extractor2->Print();
425 *fLog << endl;
426 }
427 else
428 *fLog << inf << "No Time Extractor: ExtractTime in file." << endl;
429
430 // This is necessary for the case in which it is not in the files
431 MBadPixelsCam badcam;
432
433 // Setup Parlist
434 MParList plist;
435 plist.AddToList(this); // take care of fDisplay!
436 plist.AddToList(&badcam);
437 plist.AddToList(&hilcam);
438 plist.AddToList(&calibcont); // Using AddToList(TObjArray *)
439 plist.AddToList(&interlacedcont); // Using AddToList(TObjArray *)
440 plist.AddToList(&pulcam);
441
442 // Setup Tasklist
443 MTaskList tlist;
444 plist.AddToList(&tlist);
445
446 MReadReports readreal;
447 readreal.AddTree("Events", "MTime.", kTRUE);
448 readreal.AddTree("Trigger");
449 readreal.AddTree("Camera");
450 readreal.AddTree("Drive");
451 readreal.AddTree("CC");
452 readreal.AddTree("Currents");
453
454 MReadMarsFile readmc("Events");
455 readmc.DisableAutoScheme();
456
457 MRawFileRead rawread(NULL);
458
459 MRead *read = 0;
460 switch (GetDataFlag())
461 {
462 case kIsUseRawData: read = &rawread; break;
463 case kIsUseMC: read = &readmc; break;
464 case kIsUseRootData: read = &readreal; break;
465 }
466 read->AddFiles(fSequence.IsValid() ? iter : *fRuns);
467
468 const TString fname(Form("%s{s/_D_/_Y_}{s/.raw$/.root}", fPathOut.Data()));
469
470
471 // Skips MC which have no contents. This are precisely the
472 // events which fullfilled the MC Lvl1 trigger and an
473 // arbitrary cut (typically at 50phe) to speed up simulation
474 MContinue contmc("MRawEvtData.GetNumPixels<0.5", "ContEmptyMC");
475
476 MPointingPosInterpolate pextr;
477 pextr.AddFiles(&iter);
478
479 MGeomApply apply; // Only necessary to create geometry
480 if (!geom.IsNull())
481 apply.SetGeometry(geom);
482 MBadPixelsMerge merge(&badpix);
483
484 // Make sure that pedcamab has the correct name
485 pedcamab.SetName("MPedestalFundamental");
486 pedcamextr.SetName("MPedestalFromExtractorRndm");
487 pedcambias.SetName("MPedestalFromExtractor");
488 plist.AddToList(&pedcamextr);
489 plist.AddToList(&pedcambias);
490 plist.AddToList(&pedcamab);
491
492 MArrivalTimeCam timecam;
493 plist.AddToList(&timecam);
494
495 // Check for interleaved events
496 MCalibrationPatternDecode caldec;
497 MTriggerPatternDecode decode;
498
499 MFTriggerPattern ftp;
500 // ftp.RequireCalibration();
501 ftp.DenyCalibration();
502 ftp.DenyPedestal();
503 // ftp.DenyPinDiode();
504 ftp.SetInverted();
505 MContinue conttp(&ftp, "ContTrigPattern");
506 // --> tlist2
507
508 // Do signal and pedestal calculation
509 MPedCalcFromLoGain pedlo1("MPedCalcFundamental");
510 pedlo1.SetPedestalUpdate(kTRUE);
511 pedlo1.SetNamePedestalCamOut("MPedestalFundamental");
512
513 MPedCalcFromLoGain pedlo2("MPedCalcWithExtractorRndm");
514 pedlo2.SetPedestalUpdate(kTRUE);
515 pedlo2.SetRandomCalculation(kTRUE);
516 pedlo2.SetNamePedestalCamIn("MPedestalFundamental");
517 pedlo2.SetNamePedestalCamOut("MPedestalFromExtractorRndm");
518
519 MPedCalcFromLoGain pedlo3("MPedCalcWithExtractor");
520 pedlo3.SetPedestalUpdate(kTRUE);
521 pedlo3.SetRandomCalculation(kFALSE);
522 pedlo3.SetNamePedestalCamIn("MPedestalFundamental");
523 pedlo3.SetNamePedestalCamOut("MPedestalFromExtractor");
524
525 if (extractor1)
526 {
527 extractor1->SetPedestals(&pedcamab);
528
529 if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
530 {
531 pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
532 pedlo3.SetExtractor((MExtractTimeAndCharge*)extractor1);
533 const Int_t win = ((MExtractTimeAndCharge*)extractor1)->GetWindowSizeHiGain();
534 pedlo1.SetExtractWindow(15, win);
535 pedlo2.SetExtractWindow(15, win/*obsolete*/);
536 pedlo3.SetExtractWindow(15, win/*obsolete*/);
537 }
538 else
539 {
540 // FIXME: How to get the fixed value 15 automatically?
541 const Int_t f = (Int_t)(15.5+extractor1->GetHiGainFirst());
542 const Int_t n = (Int_t)(15.5+extractor1->GetNumHiGainSamples());
543 pedlo1.SetExtractWindow(f, n);
544 pedlo2.SetExtractWindow(f, n);
545 pedlo3.SetExtractWindow(f, n);
546 }
547 }
548 if (extractor2)
549 extractor2->SetPedestals(&pedcamab);
550
551 if (extractor3)
552 extractor3->SetPedestals(&pedcamab);
553
554 MFCosmics fcosmics;
555 fcosmics.SetNamePedestalCam("MPedestalFundamental");
556 MContinue contcos(&fcosmics, "ContTrigEvts");
557 contcos.SetInverted();
558
559 //MMcPedestalCopy pcopy;
560 MTaskEnv taskenv1("ExtractSignal");
561 MTaskEnv taskenv2("ExtractTime");
562 MTaskEnv taskenv3("ExtractInterlaced");
563 taskenv1.SetDefault(extractor1);
564 taskenv2.SetDefault(extractor2);
565 taskenv3.SetDefault(extractor3);
566
567 //
568 // This is new calibration to photo-electrons, hard-coded
569 // as decided at the Wuerzburg software meeting 26.01.05
570 //
571 MCalibrateData calib;
572 calib.SetSignalType(MCalibrateData::kPhe);
573 calib.AddPedestal("Fundamental");
574 calib.AddPedestal("FromExtractor");
575 calib.AddPedestal("FromExtractorRndm");
576 calib.SetPedestalFlag(MCalibrateData::kEvent);
577 //----------------------------------------------------------
578
579 MExtractPINDiode pinext;
580 MExtractBlindPixel bldext;
581
582 MFTriggerPattern fcalib("CalibFilter");
583 fcalib.RequireCalibration();
584
585 MCalibrationChargeCalc chcalc;
586 MCalibrationRelTimeCalc recalc;
587 MCalibCalcFromPast pacalc;
588 chcalc.SetOutputFile("");
589 recalc.SetOutputFile("");
590
591 pinext.SetPedestals(&pedcamab);
592 bldext.SetPedestals(&pedcamab);
593 chcalc.SetPedestals(&pedcamextr);
594
595 pacalc.SetChargeCalc(&chcalc);
596 if (fIsRelTimesUpdate)
597 pacalc.SetRelTimeCalc(&recalc);
598 pacalc.SetCalibrate(&calib);
599
600 //
601 // Intensity Calibration histogramming
602 //
603 MFillH filpin(&hpndiod, "MExtractedSignalPINDiode", "FillPINDiode");
604 MFillH filbnd(&hbndcam, "MExtractedSignalBlindPixel", "FillBlindCam");
605 MFillH filcam(&hchacam, "MExtractedSignalCam", "FillChargeCam");
606 MFillH filtme(&hrelcam, "MArrivalTimeCam", "FillRelTime");
607 MFillH filhil("MHCalibrationHiLoCam", "MExtractedSignalCam", "FillHiLoRatio");
608 MFillH filpul("MHCalibrationPulseTimeCam", "MRawEvtData", "FillPulseTime");
609 filpin.SetBit(MFillH::kDoNotDisplay);
610 filbnd.SetBit(MFillH::kDoNotDisplay);
611 filcam.SetBit(MFillH::kDoNotDisplay);
612 filtme.SetBit(MFillH::kDoNotDisplay);
613 filhil.SetBit(MFillH::kDoNotDisplay);
614 filpul.SetBit(MFillH::kDoNotDisplay);
615
616 MCalibrateRelTimes caltm;
617 MBadPixelsCalc bpcal;
618 MBadPixelsTreat treat;
619
620 bpcal.SetNamePedPhotCam("MPedPhotFromExtractor");
621 treat.AddNamePedPhotCam("MPedPhotFundamental");
622 treat.AddNamePedPhotCam("MPedPhotFromExtractor");
623 treat.AddNamePedPhotCam("MPedPhotFromExtractorRndm");
624 if (!extractor2 && !extractor1->InheritsFrom("MExtractTimeAndCharge"))
625 treat.SetProcessTimes(kFALSE);
626
627 MHCamEvent evt0(0, "PedFLG", "Fundamental Pedestal from Lo Gain;;P [cnts/sl]");
628 MHCamEvent evt1(2, "PedRmsFLG", "RMS from Extractor applied to ped.;;\\sigma_{p} [cnts/sl]");
629 MHCamEvent evt2(0, "Extra'd", "Extracted Signal;;S [cnts/sl]");
630 // MHCamEvent evt3(4, "PedPhot", "Calibrated Pedestal;;P [phe]");
631 MHCamEvent evt4(5, "PedRMS", "Calibrated RMS from Extractor applied to ped.;;\\sigma_{p} [phe]");
632 MHCamEvent evt5(0, "Interp'd", "Interpolated Signal;;S [phe]");
633 MHCamEvent evt6(2, "Unsuitable", "Fraction of unsuitable events per Pixel;;[1]");
634 MHCamEvent evt7(6, "Times", "Calibrated Arrival Time;;T [fadc sl]");
635 MHCamEvent evt8(0, "Conv", "Calibration Conv. Factors;;[phe/fadc cnts]");
636 MHCamEvent evt9(7, "PulsePos", "Pulse Position of cosmics (>15phe);;T"); //Calibration Conv. Factors;;[phe/fadc cnts]
637 /*
638 MHCamEventTH evt9(6, "PulsePos", "Pulse Position of cosmics"); //Calibration Conv. Factors;;[phe/fadc cnts]
639 evt9.SetNameThreshold("MCerPhotEvt");
640 evt9.SetThreshold(15);
641 */
642/*
643 evt0.EnableSqrtVariance();
644 evt1.EnableSqrtVariance();
645 evt2.EnableSqrtVariance();
646 // evt3.EnableVariance();
647 evt4.EnableSqrtVariance();
648 evt5.EnableSqrtVariance();
649 evt7.EnableSqrtVariance();
650 evt8.EnableSqrtVariance();
651 */
652 MFillH fill0(&evt0, "MPedestalFundamental", "FillPedFLG");
653 MFillH fill1(&evt1, "MPedestalFromExtractorRndm", "FillPedRmsFLG");
654 MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtracted");
655 // MFillH fill3(&evt3, "MPedPhotFundamental", "FillPedPhot");
656 MFillH fill4(&evt4, "MPedPhotFromExtractorRndm", "FillPedRMS");
657 MFillH fill5(&evt5, "MSignalCam", "FillInterpolated");
658 MFillH fill6(&evt6, "MBadPixelsCam", "FillUnsuitable");
659 MFillH fill7(&evt7, "MSignalCam", "FillTimes");
660 MFillH fill8(&evt8, "MCalibConstCam", "FillConv");
661 MFillH fill9(&evt9, "MSignalCam", "FillPulse");
662
663 MTaskEnv fillflorian("FinalFantasy");
664 fillflorian.SetDefault();
665
666 // The second rule is for the case reading raw-files!
667 MWriteRootFile write(2, fname, fOverwrite?"RECREATE":"NEW");
668 // Run Header
669 write.AddContainer("MRawRunHeader", "RunHeaders");
670 write.AddContainer("MBadPixelsCam", "RunHeaders");
671 write.AddContainer("MGeomCam", "RunHeaders");
672 // Monte Carlo Headers
673 write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
674 write.AddContainer("MMcFadcHeader", "RunHeaders", kFALSE);
675 write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
676 write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
677 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
678 // Monte Carlo
679 write.AddContainer("MMcEvt", "Events", kFALSE);
680 write.AddContainer("MMcTrig", "Events", kFALSE);
681 // Data tree
682 write.AddContainer("MSignalCam", "Events");
683 write.AddContainer("MPedPhotFundamental", "Events");
684 write.AddContainer("MPedPhotFromExtractor", "Events");
685 write.AddContainer("MPedPhotFromExtractorRndm", "Events");
686 write.AddContainer("MTime", "Events", kFALSE);
687 write.AddContainer("MRawEvtHeader", "Events");
688 //write.AddContainer("MArrivalTime", "Events", kFALSE);
689 //write.AddContainer("MPointingPos", "Events", kFALSE);
690 // Slow-Control: Current-tree
691 write.AddContainer("MTimeCurrents", "Currents", kFALSE);
692 write.AddContainer("MCameraDC", "Currents", kFALSE);
693 write.AddContainer("MReportCurrents", "Currents", kFALSE);
694 // Slow-Control: Camera-tree
695 write.AddContainer("MReportCamera", "Camera", kFALSE);
696 write.AddContainer("MTimeCamera", "Camera", kFALSE);
697 write.AddContainer("MCameraAUX", "Camera", kFALSE);
698 write.AddContainer("MCameraCalibration", "Camera", kFALSE);
699 write.AddContainer("MCameraCooling", "Camera", kFALSE);
700 write.AddContainer("MCameraHV", "Camera", kFALSE);
701 write.AddContainer("MCameraLV", "Camera", kFALSE);
702 write.AddContainer("MCameraLids", "Camera", kFALSE);
703 // Slow-Control: Trigger-tree
704 write.AddContainer("MReportTrigger", "Trigger", kFALSE);
705 write.AddContainer("MTimeTrigger", "Trigger", kFALSE);
706 // Slow-Control: Drive-tree
707 write.AddContainer("MReportDrive", "Drive", kFALSE);
708 write.AddContainer("MTimeDrive", "Drive", kFALSE);
709 // Slow-Control: Central Control-tree
710 write.AddContainer("MReportCC", "CC", kFALSE);
711 write.AddContainer("MTimeCC", "CC", kFALSE);
712
713 // Write the special MC tree
714 MWriteRootFile writemc(2, fname, fOverwrite?"RECREATE":"NEW");
715 writemc.SetName("WriteMC");
716 writemc.AddContainer("MMcEvtBasic", "OriginalMC");
717
718 // Now setup tasklist for events
719 MTaskList tlist2;
720
721 tlist2.AddToList(&caldec);
722 tlist2.AddToList(&decode);
723 tlist2.AddToList(&apply);
724 tlist2.AddToList(&merge);
725 tlist2.AddToList(&pedlo1);
726 tlist2.AddToList(&pedlo2);
727 tlist2.AddToList(&pedlo3);
728 //-----------------------------------------------------------
729
730 MTaskList tlist3;
731 tlist3.SetFilter(&fcalib);
732
733 if (fIsInterlaced)
734 {
735 tlist2.AddToList(&fcalib);
736 tlist2.AddToList(&tlist3);
737
738 tlist3.AddToList(&pinext);
739 tlist3.AddToList(&bldext);
740 tlist3.AddToList(&taskenv3);
741 tlist3.AddToList(&pacalc);
742 tlist3.AddToList(&filcam);
743 if (fIsRelTimesUpdate)
744 tlist3.AddToList(&filtme);
745 if (IsUseBlindPixel())
746 tlist3.AddToList(&filbnd);
747 if (IsUsePINDiode())
748 tlist3.AddToList(&filpin);
749 tlist3.AddToList(&chcalc);
750 if (fIsRelTimesUpdate)
751 tlist3.AddToList(&recalc);
752 }
753
754 // Continue for all non-cosmic events
755 tlist2.AddToList(&conttp);
756 if (extractor1)
757 tlist2.AddToList(&taskenv1);
758 if (extractor2)
759 tlist2.AddToList(&taskenv2);
760 tlist2.AddToList(&fill0);
761 tlist2.AddToList(&fill1);
762 tlist2.AddToList(&contcos);
763 if (fIsHiLoCalibration)
764 tlist2.AddToList(&filhil);
765 if (fIsPulsePosCheck)
766 tlist2.AddToList(&filpul);
767 tlist2.AddToList(&fill2);
768 tlist2.AddToList(&calib);
769 if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
770 tlist2.AddToList(&caltm);
771 if (fIsInterlaced)
772 tlist2.AddToList(&fill8);
773 tlist2.AddToList(&bpcal);
774 tlist2.AddToList(&treat);
775 tlist2.AddToList(&fill6);
776 // tlist2.AddToList(&fill3);
777 tlist2.AddToList(&fill4);
778 tlist2.AddToList(&fill5);
779 if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
780 tlist2.AddToList(&fill7);
781 tlist2.AddToList(&fill9);
782
783 tlist2.AddToList(&fillflorian);
784
785 // Setup List for Drive-tree
786 //MPointingPosCalc pcalc;
787
788 // Now setup main tasklist
789 tlist.AddToList(read);
790 if (IsUseMC())
791 {
792 tlist.AddToList(&writemc);
793 tlist.AddToList(&contmc);
794 }
795
796 if (IsUseRootData())
797 tlist2.AddToList(&pextr);
798 tlist.AddToList(&tlist2, IsUseRootData() ? "Events" : "All");
799
800 //if (IsUseMC())
801 // tlist.AddToList(&pcalc, "Drive");
802
803 tlist.AddToList(&write);
804
805 // Create and setup the eventloop
806 MEvtLoop evtloop(fName);
807 evtloop.SetParList(&plist);
808 evtloop.SetDisplay(fDisplay);
809 evtloop.SetLogStream(fLog);
810 if (!SetupEnv(evtloop))
811 return kFALSE;
812
813 // Execute first analysis
814 const Bool_t rc = evtloop.Eventloop(fMaxEvents);
815
816 // Print statistics
817 if (read->GetNumExecutions()>0)
818 tlist.PrintStatistics();
819
820 // make sure owned object are deleted
821 if (extractor1 && extractor1!=fExtractor)
822 delete extractor1;
823 if (extractor2)
824 delete extractor2;
825 if (extractor3)
826 delete extractor3;
827
828 // return if job failed
829 if (!rc)
830 {
831 *fLog << err << GetDescriptor() << ": Failed." << endl;
832 return kFALSE;
833 }
834
835 // if everything went ok write and display result
836 DisplayResult(plist);
837
838 if (fIsPixelCheck)
839 {
840 if (fIsPulsePosCheck)
841 {
842 MHCalibrationPulseTimeCam *pcam = (MHCalibrationPulseTimeCam*)plist.FindObject("MHCalibrationPulseTimeCam");
843 MHCalibrationPix &pix1 = (*pcam)[fCheckedPixId];
844 pix1.DrawClone("");
845 }
846
847 if (fIsHiLoCalibration)
848 {
849 MHCalibrationHiLoCam *hcam = (MHCalibrationHiLoCam*)plist.FindObject("MHCalibrationHiLoCam");
850 MHCalibrationPix &pix2 = (*hcam)[fCheckedPixId];
851 pix2.DrawClone("");
852 }
853 }
854
855 interlacedcont.Add(&pulcam);
856
857 if (fIsHiLoCalibration)
858 interlacedcont.Add(&hilcam);
859
860 if (IsHistsStorage())
861 {
862 interlacedcont.Add(plist.FindObject("MHCalibrationHiLoCam"));
863 interlacedcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
864 }
865
866 if (!WriteResult(interlacedcont))
867 return kFALSE;
868
869 // return if job went ok
870 *fLog << all << GetDescriptor() << ": Done." << endl;
871 *fLog << endl << endl;
872
873 return kTRUE;
874}
875
876
877void MJCalibrateSignal::DisplayResult(MParList &plist)
878{
879
880 if (!fDisplay)
881 return;
882
883 MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
884/*
885 //
886 // Get container from list
887 //
888 MCalibrationPulseTimeCam *pcam = (MCalibrationPulseTimeCam*)plist.FindObject("MCalibrationPulseTimeCam");
889
890 MHCamera disp11 (geomcam, "PulseTime", "Mean pulse arrival time cosmics");
891 MHCamera disp21 (geomcam, "PulseTimeRMS", "RMS of pulse arrival time cosmics");
892
893 if (pcam)
894 {
895 disp11.SetCamContent(*pcam, 0);
896 disp11.SetCamError( *pcam, 1);
897 disp21.SetCamContent(*pcam, 2);
898 disp21.SetCamError( *pcam, 3);
899 }
900
901 disp11.SetYTitle("T [FADC sl.]");
902 disp21.SetYTitle("T [FADC sl.]");
903
904 if (fIsPulsePosCheck)
905 {
906 TCanvas &c0 = fDisplay->AddTab("PulseTime");
907 c0.Divide(2,3);
908
909 disp11.CamDraw(c0, 1, 2, 1);
910 disp21.CamDraw(c0, 2, 2, 1);
911 }
912 */
913 if (!fIsHiLoCalibration)
914 return;
915
916 MCalibrationHiLoCam *hcam = (MCalibrationHiLoCam*)plist.FindObject("MCalibrationHiLoCam");
917
918 // Create histograms to display
919 MHCamera disp1 (geomcam, "HiLoConv", "Ratio Amplification HiGain vs. LoGain (Charges)");
920 MHCamera disp2 (geomcam, "HiLoDiff", "Arrival Time Diff. HiGain vs. LoGain (Times)");
921
922 disp1.SetCamContent(*hcam, 0);
923 disp1.SetCamError( *hcam, 1);
924 disp2.SetCamContent(*hcam, 5);
925 disp2.SetCamError( *hcam, 6);
926
927 disp1.SetYTitle("R [1]");
928 disp2.SetYTitle("\\Delta T [FADC sl.]");
929
930
931 TCanvas &c1 = fDisplay->AddTab("HiLoConv");
932 c1.Divide(2,3);
933
934 disp1.CamDraw(c1, 1, 2, 1);
935 disp2.CamDraw(c1, 2, 2, 1);
936}
937
Note: See TracBrowser for help on using the repository browser.