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

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