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

Last change on this file since 8986 was 8986, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 34.1 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-2008
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// Core
43#include "MLog.h"
44#include "MLogManip.h"
45
46#include "MDirIter.h"
47#include "MTaskList.h"
48#include "MParList.h"
49#include "MEvtLoop.h"
50
51#include "MStatusDisplay.h"
52
53// General containers
54#include "MGeomCam.h"
55#include "MBadPixelsCam.h"
56#include "MCalibConstCam.h"
57#include "MPedestalCam.h"
58#include "MArrivalTimeCam.h"
59
60// General histograms
61#include "MH3.h"
62#include "MHCamEvent.h"
63#include "MHVsTime.h"
64
65// Calibration containers
66#include "MCalibrationQECam.h"
67#include "MCalibrationBlindCam.h"
68#include "MCalibrationChargeCam.h"
69#include "MCalibrationRelTimeCam.h"
70#include "MCalibrationChargePINDiode.h"
71
72// Calibration histograms
73#include "MHCalibrationChargeCam.h"
74#include "MHCalibrationChargeBlindCam.h"
75#include "MHCalibrationChargePINDiode.h"
76#include "MHCalibrationRelTimeCam.h"
77
78// Tasks
79#include "MReadMarsFile.h"
80#include "MRawFileRead.h"
81#include "MTaskEnv.h"
82#include "MContinue.h"
83#include "MFillH.h"
84#include "MGeomApply.h"
85#include "MExtractTimeAndCharge.h"
86#include "MTriggerPatternDecode.h"
87#include "MCalibrationPatternDecode.h"
88#include "MCalibrationChargeCalc.h"
89#include "MCalibrationRelTimeCalc.h"
90#include "MCalibCalcFromPast.h"
91#include "MPedestalSubtract.h"
92#include "MPedCalcFromLoGain.h"
93#include "MCalibrateData.h"
94#include "MExtractPINDiode.h"
95#include "MExtractBlindPixel.h"
96#include "MCalibrateRelTimes.h"
97#include "MBadPixelsCalc.h"
98#include "MBadPixelsTreat.h"
99#include "MWriteRootFile.h"
100
101// Filter
102#include "MFTriggerPattern.h"
103#include "MFCosmics.h"
104#include "MFilterList.h"
105#include "MFDataPhrase.h"
106
107// Classes for writing movies
108#include "MFEvtNumber.h"
109#include "MMoviePrepare.h"
110#include "MMovieWrite.h"
111#include "MImgCleanStd.h"
112
113
114ClassImp(MJCalibrateSignal);
115
116using namespace std;
117
118// --------------------------------------------------------------------------
119//
120// Default constructor.
121//
122// Sets:
123// - fIsInterlaced to kTRUE
124// - fIsRelTimesUpdate to kFALSE
125// - fIsHiLoCalibration to kFALSE
126//
127MJCalibrateSignal::MJCalibrateSignal(const char *name, const char *title)
128 : fExtractor(0), fIsInterlaced(kTRUE), fIsRelTimesUpdate(kTRUE), fIsMovieMode(kFALSE)
129{
130 fName = name ? name : "MJCalibrateSignal";
131 fTitle = title ? title : "Tool to calibrate data";
132}
133
134MJCalibrateSignal::~MJCalibrateSignal()
135{
136 if (fExtractor)
137 delete fExtractor;
138}
139
140void MJCalibrateSignal::SetExtractor(const MExtractor *ext)
141{
142 if (fExtractor)
143 delete fExtractor;
144
145 fExtractor = ext ? (MExtractor*)ext->Clone() : NULL;
146}
147
148Bool_t MJCalibrateSignal::WriteResult() const
149{
150 if (IsNoStorage() || fIsMovieMode)
151 return kTRUE;
152
153 // FIXME: This is not nice because it will update the signal
154 // file always. Which might make the usage outside of
155 // callisto difficult.
156 TObjArray cont;
157 cont.Add(const_cast<TEnv*>(GetEnv()));
158 cont.Add(const_cast<MSequence*>(&fSequence));
159
160 if (fDisplay)
161 {
162 TString title = "-- Calibrate Signal: ";
163 title += fSequence.GetSequence();
164 title += " --";
165 fDisplay->SetTitle(title, kFALSE);
166
167 cont.Add(fDisplay);
168 }
169
170 const TString name(Form("signal%08d.root", fSequence.GetSequence()));
171 return WriteContainer(cont, name, "UPDATE");
172}
173
174Bool_t MJCalibrateSignal::ReadCalibration(TObjArray &l, MBadPixelsCam &cam, MExtractor* &ext2, MExtractor* &ext3, TString &geom) const
175{
176 TString fname = Form("%s/calib%08d.root", fPathIn.Data(), fSequence.GetSequence());
177
178 *fLog << inf << "Reading from file: " << fname << endl;
179
180 TFile file(fname, "READ");
181 if (!file.IsOpen())
182 {
183 *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
184 return kFALSE;
185 }
186
187 TObject *o = file.Get("ExtractSignal");
188 if (o && !o->InheritsFrom(MExtractor::Class()))
189 {
190 *fLog << err << dbginf << "ERROR - ExtractSignal read from " << fname << " doesn't inherit from MExtractor!" << endl;
191 return kFALSE;
192 }
193 ext3 = o ? (MExtractor*)o->Clone() : NULL;
194
195 o = file.Get("ExtractTime");
196 if (o && !o->InheritsFrom(MExtractor::Class()))
197 {
198 *fLog << err << dbginf << "ERROR - ExtractTime read from " << fname << " doesn't inherit from MExtractor!" << endl;
199 return kFALSE;
200 }
201 ext2 = o ? (MExtractor*)o->Clone() : NULL;
202 if (!ext3 && !ext2)
203 {
204 *fLog << err << dbginf << "ERROR - Neither ExtractSignal nor ExrtractTime found in " << fname << "!" << endl;
205 return kFALSE;
206 }
207
208 o = file.Get("MGeomCam");
209 if (o && !o->InheritsFrom(MGeomCam::Class()))
210 {
211 *fLog << err << dbginf << "ERROR - MGeomCam read from " << fname << " doesn't inherit from MGeomCam!" << endl;
212 return kFALSE;
213 }
214 geom = o ? o->ClassName() : "";
215
216 TObjArray cont(l);
217 cont.Add(&cam);
218 return ReadContainer(cont);
219}
220
221// --------------------------------------------------------------------------
222//
223// MJCalibration allows to setup several option by a resource file:
224// MJCalibrateSignal.RawData: yes,no
225//
226// For more details see the class description and the corresponding Getters
227//
228Bool_t MJCalibrateSignal::CheckEnvLocal()
229{
230 SetInterlaced(GetEnv("Interlaced", fIsInterlaced));
231 SetRelTimesUpdate(GetEnv("RelTimesUpdate", fIsRelTimesUpdate));
232 SetMovieMode(GetEnv("MovieMode", fIsMovieMode));
233
234 return MJCalib::CheckEnvLocal();
235}
236
237#include "MParameterCalc.h" // FIXME
238Bool_t MJCalibrateSignal::Process(MPedestalCam &pedcamab, MPedestalCam &pedcambias,
239 MPedestalCam &pedcamextr)
240{
241 if (!fSequence.IsValid())
242 {
243 *fLog << err << "ERROR - Sequence invalid..." << endl;
244 return kFALSE;
245 }
246
247 *fLog << inf;
248 fLog->Separator(GetDescriptor());
249 *fLog << "Calculate calibrated data from Sequence #";
250 *fLog << fSequence.GetSequence() << endl << endl;
251
252
253 //if (!CheckEnv())
254 // return kFALSE;
255
256 CheckEnv();
257
258 // --------------------------------------------------------------------------------
259
260 MDirIter iter;
261 if (fSequence.IsValid())
262 {
263 if (fSequence.SetupDatRuns(iter, 0, !fSequence.IsMonteCarlo())<=0)
264 return kFALSE;
265 }
266
267 // Read File
268 MHCalibrationChargeCam hchacam;
269 MHCalibrationChargeBlindCam hbndcam;
270 MHCalibrationChargePINDiode hpndiod;
271 MHCalibrationRelTimeCam hrelcam;
272 //MHCalibrationHiLoCam hilocam;
273 //MHCalibrationPulseTimeCam hpulcam;
274
275 hchacam.SetOscillations(kFALSE);
276 hbndcam.SetOscillations(kFALSE);
277 hrelcam.SetOscillations(kFALSE);
278
279 MCalibrationChargeCam calcam;
280 MCalibrationQECam qecam;
281 MCalibrationBlindCam bndcam;
282 MCalibrationChargePINDiode pind;
283 MCalibrationRelTimeCam tmcam;
284 //MCalibrationHiLoCam hilcam;
285 //MCalibrationPulseTimeCam pulcam;
286
287 MBadPixelsCam badpix;
288
289 TObjArray interlacedcont;
290 if (fIsInterlaced)
291 {
292 interlacedcont.Add(&hchacam);
293 if (IsUseBlindPixel())
294 interlacedcont.Add(&hbndcam);
295 if (IsUsePINDiode())
296 interlacedcont.Add(&hpndiod);
297 if (fIsRelTimesUpdate)
298 interlacedcont.Add(&hrelcam);
299 }
300
301 MExtractor *extractor1=fExtractor;
302 MExtractor *extractor2=0;
303 MExtractor *extractor3=0;
304 TString geom;
305
306 TObjArray calibcont;
307 calibcont.Add(&calcam);
308 calibcont.Add(&qecam);
309 calibcont.Add(&bndcam);
310 calibcont.Add(&tmcam);
311 if (IsUseBlindPixel())
312 calibcont.Add(&bndcam);
313
314 if (!ReadCalibration(calibcont, badpix, extractor2, extractor3, geom))
315 return kFALSE;
316
317 *fLog << all;
318 if (!geom.IsNull())
319 *fLog << inf << "Camera geometry found in file: " << geom << endl;
320 else
321 *fLog << inf << "No Camera geometry found using default <MGeomCamMagic>" << endl;
322
323 if (extractor3)
324 {
325 *fLog << underline << "Signal Extractor found in calibration file" << endl;
326 extractor3->Print();
327 *fLog << endl;
328 }
329 else
330 *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
331
332
333 if (extractor1)
334 {
335 *fLog << underline << "Modified Signal Extractor set by user." << endl;
336 extractor1->Print();
337 *fLog << endl;
338 }
339 else
340 {
341 *fLog << inf << "No modified Signal Extractor set by user... using ExtractSignal." << endl;
342 extractor1 = extractor3 ? (MExtractor*)extractor3->Clone() : 0;
343 }
344
345 if (extractor2)
346 {
347 *fLog << underline << "Time Extractor found in calibration file" << endl;
348 extractor2->Print();
349 *fLog << endl;
350 }
351 else
352 *fLog << inf << "No Time Extractor: ExtractTime in file." << endl;
353
354 // This is necessary for the case in which it is not in the files
355 MCalibConstCam constcam;
356
357 //MBadPixelsCam badcam;
358 constcam.SetBadPixels(&badpix);
359
360 // Setup Parlist
361 MParList plist;
362 plist.AddToList(this); // take care of fDisplay!
363 plist.AddToList(&badpix);
364 plist.AddToList(&constcam);
365 //plist.AddToList(&hilcam);
366 plist.AddToList(&calibcont); // Using AddToList(TObjArray *)
367 plist.AddToList(&interlacedcont); // Using AddToList(TObjArray *)
368 //plist.AddToList(&pulcam);
369
370 // Setup Tasklist
371 MTaskList tlist;
372 plist.AddToList(&tlist);
373
374 MReadMarsFile readmc("Events");
375 readmc.DisableAutoScheme();
376
377 MRawFileRead rawread(NULL);
378 rawread.SetForceMode(); // Ignore broken time-stamps
379
380 MRead *read = fSequence.IsMonteCarlo() ? (MRead*)&readmc : (MRead*)&rawread;
381 read->AddFiles(iter);
382
383 const TString fname(Form("%s{s/_D_/_Y_}{s/\\.raw$/.root}{s/\\.raw\\.gz$/.root}", fPathOut.Data()));
384
385 // Skips MC which have no contents. This are precisely the
386 // events which fullfilled the MC Lvl1 trigger and an
387 // arbitrary cut (typically at 50phe) to speed up simulation
388 MContinue contmc("MRawEvtData.GetNumPixels<0.5", "ContEmptyMC");
389
390 //MPointingPosInterpolate pextr;
391 //pextr.AddFiles(&iter);
392
393 MGeomApply apply; // Only necessary to create geometry
394 if (!geom.IsNull())
395 apply.SetGeometry(geom);
396 //MBadPixelsMerge merge(&badpix);
397
398 // Make sure that pedcamab has the correct name
399 pedcamab.SetName("MPedestalFundamental");
400 pedcamextr.SetName("MPedestalFromExtractorRndm");
401 pedcambias.SetName("MPedestalFromExtractor");
402 plist.AddToList(&pedcamextr);
403 plist.AddToList(&pedcambias);
404 plist.AddToList(&pedcamab);
405
406 MArrivalTimeCam timecam;
407 plist.AddToList(&timecam);
408
409 // Check for interleaved events
410 MCalibrationPatternDecode caldec;
411 MTriggerPatternDecode decode;
412
413 MH3 hpat("MRawRunHeader.fRunNumber", "MTriggerPattern.GetUnprescaled");
414 hpat.SetWeight("1./MRawRunHeader.GetRunLength");
415 hpat.SetName("TrigPat");
416 hpat.SetTitle("Rate of the trigger pattern [Hz];Run Number;Trigger Pattern;Rate [Hz]");
417 hpat.InitLabels(MH3::kLabelsXY);
418 //hpat.DefineLabelsY("1=Lvl1;2=Cal;3=Cal;4=Lvl2;5=Cal;7=Cal;8=Ped;9=Ped+Trig;13=Ped+Trig;16=Pin;32=Sum");
419 hpat.DefaultLabelY("UNKNOWN");
420 hpat.DefineLabelY( 0, "0"); // 0: No pattern
421 hpat.DefineLabelY( 1, "Trig"); // 1: Lvl1
422 hpat.DefineLabelY( 2, "Cal"); // 2: Cal
423 hpat.DefineLabelY( 3, "Cal"); // Cal+Lvl1
424 hpat.DefineLabelY( 4, "Trig"); // 4: Lvl2
425 hpat.DefineLabelY( 5, "Trig"); // Lvl2+Lvl1
426 hpat.DefineLabelY( 7, "Cal"); // Lvl2+Cal+Lvl
427 hpat.DefineLabelY( 8, "Ped"); // 8: Ped
428 hpat.DefineLabelY( 9, "Ped+Trig"); // Ped+Lvl1
429 hpat.DefineLabelY(10, "Ped+Cal"); // Ped+Cal
430 hpat.DefineLabelY(12, "Ped+Trig"); // Ped+Lvl2
431 hpat.DefineLabelY(13, "Ped+Trig"); // Ped+Lvl2+Lvl1
432 hpat.DefineLabelY(16, "Pin"); // 16: Pin
433 hpat.DefineLabelY(32, "Sum"); // 32: Sum
434 hpat.DefineLabelY(33, "Trig"); // Sum+Lvl1
435 hpat.DefineLabelY(34, "Cal"); // Sum+Cal
436 hpat.DefineLabelY(35, "Cal"); // Sum+Cal+Lvl1
437 hpat.DefineLabelY(36, "Trig"); // Sum+Lvl2
438 hpat.DefineLabelY(37, "Trig"); // Sum+Lvl1+Lvl2
439 hpat.DefineLabelY(39, "Cal"); // Sum+Lvl2+Cal+Lvl1
440
441 MFillH fillpat(&hpat, "", "FillPattern");
442 fillpat.SetDrawOption("box");
443
444 // This will make that for data with version less than 5, where
445 // trigger patterns were not yet correct, all the events in the real
446 // data file will be processed. In any case there are no interleaved
447 // calibration events in such data, so this is fine.
448 // We allow only cosmics triggered events to pass (before prescaling)
449 MFTriggerPattern fcalped("SelectTrigEvts");
450 fcalped.SetInverted();
451 fcalped.SetDefault(kTRUE);
452 fcalped.DenyAll();
453 fcalped.AllowTriggerLvl1();
454 fcalped.AllowTriggerLvl2();
455 fcalped.AllowSumTrigger();
456
457 // This will skip interleaved events with a cal- or ped-trigger
458 MContinue contcalped(&fcalped, "ContNonTrigger");
459
460 // Create the pedestal subtracted raw-data
461 MPedestalSubtract pedsub;
462 pedsub.SetPedestalCam(&pedcamab);
463
464 // Do signal and pedestal calculation
465 MPedCalcFromLoGain pedlo1("MPedCalcFundamental");
466 pedlo1.SetPedestalUpdate(kTRUE);
467 pedlo1.SetNamePedestalCamOut("MPedestalFundamental");
468
469 MPedCalcFromLoGain pedlo2("MPedCalcWithExtractorRndm");
470 pedlo2.SetPedestalUpdate(kTRUE);
471 pedlo2.SetRandomCalculation(kTRUE);
472 pedlo2.SetNamePedestalCamOut("MPedestalFromExtractorRndm");
473
474 MPedCalcFromLoGain pedlo3("MPedCalcWithExtractor");
475 pedlo3.SetPedestalUpdate(kTRUE);
476 pedlo3.SetRandomCalculation(kFALSE);
477 pedlo3.SetNamePedestalCamOut("MPedestalFromExtractor");
478
479 if (!extractor1)
480 {
481 *fLog << err << "ERROR - extractor1 == NULL" << endl;
482 return kFALSE;
483 }
484
485 // Setup to use the hi-gain extraction window in the lo-gain
486 // range (the start of the lo-gain range is added automatically
487 // by MPedCalcFromLoGain)
488 //
489 // The window size of the extractor is not yet initialized,
490 // so we have to stick to the extraction range
491 //
492 // Even if we would like to use a range comparable to the
493 // hi-gain extraction we use the lo-gain range to make
494 // sure that exclusions (eg. due to switching noise)
495 // are correctly handled.
496 //
497 pedlo1.SetRangeFromExtractor(*extractor1);
498
499 if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
500 {
501 pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
502 pedlo3.SetExtractor((MExtractTimeAndCharge*)extractor1);
503 }
504 else
505 {
506 pedlo2.SetRangeFromExtractor(*extractor1);
507 pedlo3.SetRangeFromExtractor(*extractor1);
508 }
509
510 //------------------------------
511 //
512 // this is the filter to find pedestal events. For the Siegen FADC
513 // these are all events which are not calibration events because
514 // the pedestal is extracted from the lo-gain signal. For MUX
515 // data this are artifiially triggered events with the pedestal
516 // trigger flag, and for safty without Lvl1 or Lvl2 flag)
517 //
518 // For the time "before" the trigger pattern all events (Siegen FADC)
519 // can be considered to be pedestal, because this was also the time
520 // without artifially calibration events
521 //
522 // Deny or allow is done before prescaling.
523 //
524 MFTriggerPattern fped("SelectPedestals");
525 fped.SetDefault(kTRUE);
526 fped.DenyCalibration();
527 if (!extractor1->HasLoGain())
528 {
529 fped.DenyAll();
530 fped.RequirePedestal();
531 }
532
533 //------------------------------
534 //
535 // Apply a filter against cosmics (this is to make sure that the
536 // trigger system was working properly and no empty events survive)
537 // For every event 5% of the pixel must not be empty. In PostProcess
538 // an error is raised if more than 50% of the events were skipped.
539 //
540 MFCosmics fcosmicscal;
541 fcosmicscal.SetNamePedestalCam("MPedestalFundamental"); //CORRECT?
542 fcosmicscal.SetMaxEmptyPixels(0.05);
543 fcosmicscal.SetMaxAcceptedFraction(0.5);
544
545 MContinue contcoscal(&fcosmicscal, "ContCosmicsCal");
546
547 //------------------------------
548 /*
549 MFCosmics fcosmicsped; // Def=20% empty pixels
550 fcosmicsped.SetNamePedestalCam("MPedestalFundamental"); //CORRECT?
551 MContinue contcosped(&fcosmicsped, "ContCosmicsPed");
552 contcosped.SetInverted();
553 */
554
555 //------------------------------
556 //
557 // Thie signal extractors
558 //
559 MTaskEnv taskenv1("ExtractSignal");
560 MTaskEnv taskenv2("ExtractTime");
561 MTaskEnv taskenv3("ExtractInterlaced");
562 taskenv1.SetDefault(extractor1);
563 taskenv2.SetDefault(extractor2);
564 taskenv3.SetDefault(extractor3);
565
566 //
567 // This is new calibration to photo-electrons, hard-coded
568 // as decided at the Wuerzburg software meeting 26.01.05
569 //
570 MCalibrateData calib;
571 calib.SetSignalType(MCalibrateData::kPhe);
572 //calib.AddPedestal("Fundamental");
573 calib.AddPedestal("FromExtractor");
574 calib.AddPedestal("FromExtractorRndm");
575 calib.SetPedestalFlag(MCalibrateData::kEvent);
576
577 //----------------------------------------------------------
578
579 MExtractPINDiode pinext;
580 MExtractBlindPixel bldext;
581
582 // Execute for all events with the calibration trigger. If no
583 // trigger pattern is available do not execute it
584 // The selection is done before prescaling.
585 MFTriggerPattern fcalib("SelectCalEvts");
586 fcalib.SetDefault(kFALSE);
587 fcalib.DenyAll();
588 fcalib.RequireCalibration();
589 fcalib.AllowTriggerLvl1();
590 fcalib.AllowTriggerLvl2();
591 fcalib.AllowSumTrigger();
592
593 MCalibrationChargeCalc chcalc;
594 chcalc.SetContinousCalibration();
595 chcalc.SetExtractor(extractor3);
596
597 MCalibrationRelTimeCalc recalc;
598 MCalibCalcFromPast pacalc;
599
600 chcalc.SetPedestals(&pedcamextr);
601
602 pacalc.SetChargeCalc(&chcalc);
603 if (fIsRelTimesUpdate)
604 pacalc.SetRelTimeCalc(&recalc);
605 pacalc.SetCalibrate(&calib);
606
607 //
608 // Calibration histogramming
609 //
610 MFillH filpin(&hpndiod, "MExtractedSignalPINDiode", "FillPINDiode");
611 MFillH filbnd(&hbndcam, "MExtractedSignalBlindPixel", "FillBlindCam");
612 MFillH filcam(&hchacam, "MExtractedSignalCam", "FillChargeCam");
613 MFillH filtme(&hrelcam, "MArrivalTimeCam", "FillRelTime");
614 //MFillH filhil(&hilocam, "MExtractedSignalCam", "FillHiLoRatio");
615 //MFillH filpul(&hpulcam, "MRawEvtData", "FillPulseTime");
616 filpin.SetBit(MFillH::kDoNotDisplay);
617 filbnd.SetBit(MFillH::kDoNotDisplay);
618 filcam.SetBit(MFillH::kDoNotDisplay);
619 filtme.SetBit(MFillH::kDoNotDisplay);
620 //filhil.SetBit(MFillH::kDoNotDisplay);
621 //filpul.SetBit(MFillH::kDoNotDisplay);
622
623 MCalibrateRelTimes caltm;
624 MBadPixelsCalc bpcal;
625 MBadPixelsTreat treat;
626
627 //bpcal.SetNamePedPhotCam("MPedPhotFromExtractor");
628 bpcal.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
629
630 //treat.AddNamePedPhotCam("MPedPhotFundamental");
631 treat.AddNamePedPhotCam("MPedPhotFromExtractor");
632 treat.AddNamePedPhotCam("MPedPhotFromExtractorRndm");
633 if (!extractor2 && !extractor1->InheritsFrom("MExtractTimeAndCharge"))
634 treat.SetProcessTimes(kFALSE);
635
636 MHCamEvent evt0( 0, "PedFLG", "Fundamental Pedestal from Lo Gain;;P [cnts/sl]");
637 MHCamEvent evt1( 2, "PedRmsFLG", "RMS from Extractor applied to ped.;;\\sigma_{p} [cnts/sl]");
638 MHCamEvent evt2( 0, "Extra'd", "Extracted Signal;;S [cnts/sl]");
639 // MHCamEvent evt3(4, "PedPhot", "Calibrated Pedestal;;P [phe]");
640 MHCamEvent evt4( 5, "PedRMS", "Calibrated RMS from Extractor applied to ped.;;\\sigma_{p} [phe]");
641 MHCamEvent evt5( 0, "Interp'd", "Interpolated Signal scaled with A/A_{0};;S [phe]");
642 MHCamEvent evt6(102, "Unsuitable", "Fraction of unsuitable events per Pixel;;[1]");
643 // MHCamEvent evt7( 6, "Times", "Calibrated Arrival Time;;T [fadc sl]");
644 MHCamEvent evt8( 0, "Conv", "Calibration Conv. Factors;;[phe/cnts]");
645 MHCamEvent evt9( 7, "PulsePos", "Pulse Position of cosmics (>50phe);;T [ns]");
646 MHCamEvent evtR( 4, "HiLoCal", "Hi-/Lo-Gain ratio;;Ratio");
647 MHCamEvent evtO( 7, "HiLoOff", "Lo-/Hi-Gain Offset;;Offset");
648 MHCamEvent evtC( 4, "CalPos", "Extracted pulse position of calibration pulses;;T [sl]");
649 //MHCamEvent evt2(0, "Extra'd", "Extracted Calibration Signal;;S [cnts/sl]");
650 evt2.SetErrorSpread(kFALSE);
651 evt5.SetErrorSpread(kFALSE);
652 evt6.SetErrorSpread(kFALSE);
653 evt6.SetThreshold();
654
655 MFillH fill0(&evt0, "MPedestalFundamental", "FillPedFLG");
656 MFillH fill1(&evt1, "MPedestalFromExtractorRndm", "FillPedRmsFLG");
657 MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtracted");
658 // MFillH fill3(&evt3, "MPedPhotFundamental", "FillPedPhot");
659 MFillH fill4(&evt4, "MPedPhotFromExtractorRndm", "FillPedRMS");
660 MFillH fill5(&evt5, "MSignalCam", "FillInterpolated");
661 MFillH fill6(&evt6, "MBadPixelsCam", "FillUnsuitable");
662 // MFillH fill7(&evt7, "MSignalCam", "FillTimes");
663 MFillH fill8(&evt8, "MCalibConstCam", "FillConv");
664 MFillH fill9(&evt9, "MSignalCam", "FillPulsePos");
665 MFillH fillR(&evtR, "MExtractedSignalCam", "FillHiLoCal");
666 MFillH fillO(&evtO, "MArrivalTimeCam", "FillHiLoOff");
667 MFillH fillC(&evtC, "MArrivalTimeCam", "FillCalPos");
668 //MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtractedSignal");
669
670 MHVsTime histbp("MBadPixelsCam.GetNumUnsuitable");
671 histbp.SetName("BadPixTm");
672 histbp.SetTitle("Number of unsuitable pixels;;N");
673 histbp.SetMinimum(0);
674
675 MHVsTime histdp("MSignalCam.GetNumPixelsUnmapped");
676 histdp.SetName("DeadPixTm");
677 histdp.SetTitle("Number of dead/unmapped pixels;;N");
678 histdp.SetMinimum(0);
679
680 // Task to fill the histogram
681 MFillH fillB(&histbp, "MTime", "FillBadPixTm");
682 MFillH fillD(&histdp, "MTime", "FillDeadPixTm");
683 fillB.SetNameTab("BadPixTm");
684 fillD.SetNameTab("DeadPixTm");
685
686 /*
687 MFillH fillP("MHPulseShape", "", "FillPulseShape");
688 fillP.SetNameTab("Pulse");
689 */
690
691 /*
692 MHVsTime hbadpix("MBadPixelsCam.GetNumUnsuitable");
693 hbadpix.SetNumEvents(50);
694 MFillH fillB(&hbadpix, "MTime");
695 */
696
697 MTaskEnv fillflorian("FinalFantasy");
698 fillflorian.SetDefault();
699
700 // The second rule is for the case reading raw-files!
701 MWriteRootFile write(2, fname, fOverwrite?"RECREATE":"NEW");
702 // Run Header
703 write.AddContainer("MRawRunHeader", "RunHeaders");
704// write.AddContainer("MBadPixelsCam", "RunHeaders");
705 write.AddContainer("MGeomCam", "RunHeaders");
706 // Monte Carlo Headers
707 write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
708 write.AddContainer("MMcFadcHeader", "RunHeaders", kFALSE);
709 write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
710 write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
711 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
712 // Monte Carlo
713 write.AddContainer("MMcEvt", "Events", kFALSE);
714 write.AddContainer("MMcTrig", "Events", kFALSE);
715 // Data tree
716 write.AddContainer("MSignalCam", "Events");
717 // write.AddContainer("MPedPhotFundamental", "Events");
718 write.AddContainer("MPedPhotFromExtractor", "Events");
719 write.AddContainer("MPedPhotFromExtractorRndm", "Events");
720 write.AddContainer("MTime", "Events", kFALSE);
721 write.AddContainer("MRawEvtHeader", "Events");
722 write.AddContainer("MTriggerPattern", "Events");
723
724 // Trees with slow-control information (obsolete
725 // if we don't read merpped root-files)
726 write.AddTree("Trigger", kFALSE);
727 write.AddTree("Drive", kFALSE);
728 write.AddTree("CC", kFALSE);
729 write.AddTree("Pyrometer", kFALSE);
730 write.AddTree("Currents", kFALSE);
731 write.AddTree("Camera", kFALSE);
732 // Slow-Control: Current-tree
733 write.AddContainer("MCameraDC", "Currents", kFALSE);
734 // Slow-Control: Camera-tree
735 write.AddContainer("MCameraAUX", "Camera", kFALSE);
736 write.AddContainer("MCameraCalibration", "Camera", kFALSE);
737 write.AddContainer("MCameraCooling", "Camera", kFALSE);
738 write.AddContainer("MCameraHV", "Camera", kFALSE);
739 write.AddContainer("MCameraLV", "Camera", kFALSE);
740 write.AddContainer("MCameraLids", "Camera", kFALSE);
741
742 // Write the special MC tree
743 MWriteRootFile writemc(2, fname, fOverwrite?"RECREATE":"NEW");
744 writemc.SetName("WriteMC");
745 writemc.AddContainer("MMcEvtBasic", "OriginalMC");
746
747 // Write the special calib tree
748 /*
749 MWriteRootFile writecal(2, fname, fOverwrite?"RECREATE":"NEW");
750 writecal.SetName("WriteCalib");
751 writecal.AddContainer("MBadPixelsCam", "Calib");
752 writecal.AddContainer("MCalibrationChargeCam", "Calib");
753 writecal.AddContainer("MCalibrationRelTimeCam", "Calib");
754 */
755
756 //-----------------------------------------------------------
757 // Build tasklist
758
759 MTaskList tlist2;
760
761 tlist2.AddToList(&caldec);
762 tlist2.AddToList(&decode);
763 tlist2.AddToList(&fillpat);
764 tlist2.AddToList(&apply);
765 //tlist2.AddToList(&merge);
766 tlist2.AddToList(&pedsub);
767
768 //-----------------------------------------------------------
769 // Pedestal extraction
770
771 MTaskList tlist3;
772 tlist3.SetFilter(&fped); // Deny events with cal-trigger
773
774 tlist2.AddToList(&fped); // If no lo-gain require ped-trigger
775 tlist2.AddToList(&tlist3); // and deny cosmics (lvl1/2) trigger
776
777 tlist3.AddToList(&pedlo1); // extract pedestal events
778 tlist3.AddToList(&pedlo2); // extract pedestal events
779 tlist3.AddToList(&pedlo3); // extract pedestal events
780 tlist3.AddToList(&fill0); // fill pedestal events
781 tlist3.AddToList(&fill1); // fill pedestal events
782
783 //-----------------------------------------------------------
784 // Calibration
785
786 MTaskList tlist4;
787 tlist4.SetFilter(&fcalib); // process only events with cal-trigger
788
789 //MFDataPhrase filcalco("MCalibrationConstCam.IsReadyToSave>0.5", "CalibConstFilter");
790 if (fIsInterlaced)
791 {
792 // The task list is executed for all events with the calibration
793 // trigger
794 tlist2.AddToList(&fcalib); // MFTriggerPattern
795 tlist2.AddToList(&tlist4);
796
797 tlist4.AddToList(&taskenv3);
798 tlist4.AddToList(&contcoscal); // MContinue/ContCosmicsCal
799 if (IsUsePINDiode())
800 tlist4.AddToList(&pinext); // MExtractPINDiode
801 if (IsUseBlindPixel())
802 tlist4.AddToList(&bldext); // MExtractBlindPixel
803 tlist4.AddToList(&pacalc); // MCalibCalcFromPast
804 /*
805 tlist3.AddToList(&filcalco); // CalibConstFilter (IsReadyToSave)
806 fill8.SetFilter(&filcalco);
807 tlist3.AddToList(&fill8); // FillConvUpd
808 */
809
810 tlist4.AddToList(&filcam); // FillChargeCam
811 if (fIsRelTimesUpdate)
812 tlist4.AddToList(&filtme); // FillRelTime
813 if (IsUseBlindPixel())
814 tlist4.AddToList(&filbnd); // FillBlindCam
815 if (IsUsePINDiode())
816 tlist4.AddToList(&filpin); // FillPINDiode
817 tlist4.AddToList(&chcalc); // MCalibrationChargeCalc
818 if (fIsRelTimesUpdate)
819 tlist4.AddToList(&recalc); // MCalibrationRelTimeCam
820
821 tlist4.AddToList(&fillC); // FillCalPos
822
823 //tlist3.AddToList(&writecal); // MWriteRootFile
824 }
825
826 //-----------------------------------------------------------
827 // Cosmics extraction
828
829 // remove all events with a cal- or ped-trigger (no matter
830 // whether they have lvl1 or lvl2 or any other flag
831 tlist2.AddToList(&contcalped);
832
833 // Extract the signal
834 if (extractor1)
835 tlist2.AddToList(&taskenv1);
836
837 // remove all events which definitly don't have a signal
838 // using MFCosmics (ContCosmicsPed)
839 // tlist2.AddToList(&contcosped);
840
841 // Extract arrival time (if a dedicated extrator given)
842 if (extractor2)
843 tlist2.AddToList(&taskenv2);
844
845 /*
846 if (fIsHiLoCalibration)
847 {
848 plist.AddToList(&hilocam);
849 tlist2.AddToList(&filhil);
850 }
851
852 if (fIsPulsePosCheck)
853 {
854 plist.AddToList(&hpulcam);
855 tlist2.AddToList(&filpul);
856 }
857 */
858
859 tlist2.AddToList(&fill2);
860 tlist2.AddToList(&fill8); // FillConv
861 tlist2.AddToList(&calib); // MCalibrateData
862 if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
863 tlist2.AddToList(&caltm);
864
865 tlist2.AddToList(&bpcal); // MBadPixelsCalc
866 tlist2.AddToList(&treat); // MBadPixelsTreat
867 tlist2.AddToList(&fill6);
868 // tlist2.AddToList(&fill3);
869 tlist2.AddToList(&fill4);
870 tlist2.AddToList(&fill5);
871 //if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
872 // tlist2.AddToList(&fill7);
873 tlist2.AddToList(&fill9);
874 if (!fSequence.IsMonteCarlo())
875 {
876 tlist2.AddToList(&fillB);
877 tlist2.AddToList(&fillD);
878 }
879 if (extractor1->HasLoGain())
880 {
881 tlist2.AddToList(&fillR);
882 tlist2.AddToList(&fillO);
883 }
884
885 /*
886 MFillH fillC("MHCleaning", "", "FillClean");
887 tlist2.AddToList(&fillC);
888
889 //tlist2.AddToList(&fillP);
890 */
891
892 // ----- Start: Code for encoding movies -----
893
894 MMoviePrepare movprep;
895 MMovieWrite movwrite;
896 movprep.SetRangeFromExtractor(*extractor1);
897
898 //MFDataPhrase movfilt("MMovieData.fMax>150");
899 MFDataPhrase movfilt("MMovieData.fMax>5*MMovieData.fMedianPedestalRms", "MovieFilter");
900
901 MImgCleanStd movclean(8.5, 4.0);
902 movclean.SetMethod(MImgCleanStd::kAbsolute);
903
904 //movprep.SetFilter(&evtnum);
905 movclean.SetFilter(&movfilt);
906 movwrite.SetFilter(&movfilt);
907
908 MTaskList tlistmov("MovieEncoder");
909 tlistmov.AddToList(&movprep);
910 tlistmov.AddToList(&movfilt);
911 tlistmov.AddToList(&movclean);
912 tlistmov.AddToList(&movwrite);
913
914 MFEvtNumber evtnum;
915 //evtnum.SetSelector("ThetaSquared.fVal<0.04");
916 //evtnum.SetFileName("ganymed00000001.root");
917 tlistmov.SetFilter(&evtnum);
918
919 if (fIsMovieMode)
920 {
921 tlist2.AddToList(&evtnum);
922 tlist2.AddToList(&tlistmov);
923 }
924
925 // ----- End: Code for encoding movies -----
926
927 tlist2.AddToList(&fillflorian);
928
929 // Setup List for Drive-tree
930 //MPointingPosCalc pcalc;
931
932 // Now setup main tasklist
933 tlist.AddToList(read);
934
935 if (fSequence.IsMonteCarlo())
936 {
937 if (!fIsMovieMode && !HasNullOut())
938 tlist.AddToList(&writemc);
939 tlist.AddToList(&contmc);
940 }
941
942 //if (IsUseRootData())
943 // tlist2.AddToList(&pextr);
944 tlist.AddToList(&tlist2, fSequence.IsMonteCarlo() ? "Events" : "All");
945
946 //if (fSequence.IsMonteCarlo())
947 // tlist.AddToList(&pcalc, "Drive");
948
949 if (!fIsMovieMode && !HasNullOut())
950 tlist.AddToList(&write);
951
952 // Create and setup the eventloop
953 MEvtLoop evtloop(fName);
954 evtloop.SetParList(&plist);
955 evtloop.SetDisplay(fDisplay);
956 evtloop.SetLogStream(fLog);
957 if (!SetupEnv(evtloop))
958 return kFALSE;
959
960 // Execute first analysis
961 const Bool_t rc = evtloop.Eventloop(fMaxEvents);
962
963 // make sure owned object are deleted
964 if (extractor1 && extractor1!=fExtractor)
965 delete extractor1;
966 if (extractor2)
967 delete extractor2;
968 if (extractor3)
969 delete extractor3;
970
971 // return if job failed
972 if (!rc)
973 {
974 *fLog << err << GetDescriptor() << ": Failed." << endl;
975 return kFALSE;
976 }
977
978 // if everything went ok write and display result
979 DisplayResult(plist);
980
981 /*
982 if (fIsPixelCheck)
983 {
984 if (fIsPulsePosCheck)
985 hpulcam[fCheckedPixId].DrawClone("");
986
987 //if (fIsHiLoCalibration)
988 // hilocam[fCheckedPixId].DrawClone("");
989 }
990 interlacedcont.Add(&pulcam);
991 */
992
993 //if (fIsHiLoCalibration)
994 // interlacedcont.Add(&hilcam);
995
996 //if (fIsPulsePosCheck)
997 // interlacedcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
998
999 //if (fIsHiLoCalibration)
1000 // interlacedcont.Add(plist.FindObject("MHCalibrationHiLoCam"));
1001
1002 if (!WriteResult())
1003 return kFALSE;
1004
1005 // return if job went ok
1006 *fLog << all << GetDescriptor() << ": Done." << endl;
1007 *fLog << endl << endl;
1008
1009 return kTRUE;
1010}
1011
1012
1013void MJCalibrateSignal::DisplayResult(MParList &plist)
1014{
1015 /*
1016 if (!fDisplay || !fIsHiLoCalibration)
1017 return;
1018
1019 MCalibrationHiLoCam *hcam = (MCalibrationHiLoCam*)plist.FindObject("MCalibrationHiLoCam");
1020 MGeomCam *geom = (MGeomCam*)plist.FindObject("MGeomCam");
1021 if (!hcam || !geom)
1022 return;
1023
1024 // Create histograms to display
1025 MHCamera disp1(*geom, "HiLoConv", "Ratio Amplification HiGain vs. LoGain (Charges)");
1026 MHCamera disp2(*geom, "HiLoDiff", "Arrival Time Diff. HiGain vs. LoGain (Times)");
1027
1028 disp1.SetCamContent(*hcam, 0);
1029 disp1.SetCamError( *hcam, 1);
1030 disp2.SetCamContent(*hcam, 5);
1031 disp2.SetCamError( *hcam, 6);
1032
1033 disp1.SetYTitle("R [1]");
1034 disp2.SetYTitle("\\Delta T [FADC sl.]");
1035
1036 TCanvas &c1 = fDisplay->AddTab("HiLoConv");
1037 c1.Divide(2,3);
1038
1039 disp1.CamDraw(c1, 1, 2, 1);
1040 disp2.CamDraw(c1, 2, 2, 1);
1041*/
1042}
1043
Note: See TracBrowser for help on using the repository browser.