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

Last change on this file since 9476 was 9473, checked in by tbretz, 15 years ago
*** empty log message ***
File size: 35.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-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
237Bool_t MJCalibrateSignal::Process(MPedestalCam &pedcamab, MPedestalCam &pedcambias,
238 MPedestalCam &pedcamextr)
239{
240 if (!fSequence.IsValid())
241 {
242 *fLog << err << "ERROR - Sequence invalid..." << endl;
243 return kFALSE;
244 }
245
246 // --------------------------------------------------------------------------------
247
248 *fLog << inf;
249 fLog->Separator(GetDescriptor());
250 *fLog << "Calculate calibrated data from Sequence #";
251 *fLog << fSequence.GetSequence() << endl << endl;
252
253
254 if (!CheckEnv())
255 return kFALSE;
256
257 // --------------------------------------------------------------------------------
258
259 MDirIter iter;
260 if (fSequence.IsValid())
261 {
262 if (fSequence.GetRuns(iter, MSequence::kRawDat)<=0)
263 return kFALSE;
264 }
265
266 // Read File
267 MHCalibrationChargeCam hchacam;
268 MHCalibrationChargeBlindCam hbndcam;
269 MHCalibrationChargePINDiode hpndiod;
270 MHCalibrationRelTimeCam hrelcam;
271 //MHCalibrationHiLoCam hilocam;
272 //MHCalibrationPulseTimeCam hpulcam;
273
274 hchacam.SetOscillations(kFALSE);
275 hbndcam.SetOscillations(kFALSE);
276 hrelcam.SetOscillations(kFALSE);
277
278 MCalibrationChargeCam calcam;
279 MCalibrationQECam qecam;
280 MCalibrationBlindCam bndcam;
281 MCalibrationChargePINDiode pind;
282 MCalibrationRelTimeCam tmcam;
283 //MCalibrationHiLoCam hilcam;
284 //MCalibrationPulseTimeCam pulcam;
285
286 MBadPixelsCam badpix;
287
288 TObjArray interlacedcont;
289 if (fIsInterlaced)
290 {
291 interlacedcont.Add(&hchacam);
292 if (IsUseBlindPixel())
293 interlacedcont.Add(&hbndcam);
294 if (IsUsePINDiode())
295 interlacedcont.Add(&hpndiod);
296 if (fIsRelTimesUpdate)
297 interlacedcont.Add(&hrelcam);
298 }
299
300 MExtractor *extractor1=fExtractor;
301 MExtractor *extractor2=0;
302 MExtractor *extractor3=0;
303 TString geom;
304
305 TObjArray calibcont;
306 calibcont.Add(&calcam);
307 calibcont.Add(&qecam);
308 calibcont.Add(&bndcam);
309 calibcont.Add(&tmcam);
310 if (IsUseBlindPixel())
311 calibcont.Add(&bndcam);
312
313 if (!ReadCalibration(calibcont, badpix, extractor2, extractor3, geom))
314 return kFALSE;
315
316 *fLog << all;
317 if (!geom.IsNull())
318 *fLog << inf << "Camera geometry found in file: " << geom << endl;
319 else
320 *fLog << inf << "No Camera geometry found using default <MGeomCamMagic>" << endl;
321
322 if (extractor3)
323 {
324 *fLog << underline << "Signal Extractor found in calibration file" << endl;
325 extractor3->Print();
326 *fLog << endl;
327 }
328 else
329 *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
330
331
332 if (extractor1)
333 {
334 *fLog << underline << "Modified Signal Extractor set by user." << endl;
335 extractor1->Print();
336 *fLog << endl;
337 }
338 else
339 {
340 *fLog << inf << "No modified Signal Extractor set by user... using ExtractSignal." << endl;
341 extractor1 = extractor3 ? (MExtractor*)extractor3->Clone() : 0;
342 }
343
344 if (extractor2)
345 {
346 *fLog << underline << "Time Extractor found in calibration file" << endl;
347 extractor2->Print();
348 *fLog << endl;
349 }
350 else
351 *fLog << inf << "No Time Extractor: ExtractTime in file." << endl;
352
353 // This is necessary for the case in which it is not in the files
354 MCalibConstCam constcam;
355
356 //MBadPixelsCam badcam;
357 constcam.SetBadPixels(&badpix);
358
359 // Setup Parlist
360 MParList plist;
361 plist.AddToList(this); // take care of fDisplay!
362 plist.AddToList(&badpix);
363 plist.AddToList(&constcam);
364 //plist.AddToList(&hilcam);
365 plist.AddToList(&calibcont); // Using AddToList(TObjArray *)
366 plist.AddToList(&interlacedcont); // Using AddToList(TObjArray *)
367 //plist.AddToList(&pulcam);
368
369 // Setup Tasklist
370 MTaskList tlist;
371 plist.AddToList(&tlist);
372
373 MReadMarsFile readmc("Events");
374 readmc.DisableAutoScheme();
375
376 MRawFileRead rawread(NULL);
377 rawread.SetForceMode(); // Ignore broken time-stamps
378
379 MRead *read = fSequence.IsMonteCarlo() ? (MRead*)&readmc : (MRead*)&rawread;
380 read->AddFiles(iter);
381
382 const TString fname(Form("s/(([0-9]+_)?(M[12]_)?[0-9.]+)_D_(.*[.])(raw|raw[.]gz|root)$/%s\\/$1_Y_$4root/",
383 Esc(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.GetFileID", "MTriggerPattern.GetUnprescaled");
414 if (fSequence.IsMonteCarlo())
415 hpat.SetWeight("100./MMcRunHeader.fNumSimulatedShowers");
416 else
417 hpat.SetWeight("1./TMath::Max(MRawRunHeader.GetRunLength,1)");
418 hpat.SetName("TrigPat");
419 hpat.SetTitle("Rate of the trigger pattern [Hz];File Id;Trigger Pattern;Rate [Hz]");
420 hpat.InitLabels(MH3::kLabelsXY);
421 //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");
422 hpat.DefaultLabelY("UNKNOWN");
423 hpat.DefineLabelY( 0, "0"); // 0: No pattern
424 hpat.DefineLabelY( 1, "Trig"); // 1: Lvl1
425 hpat.DefineLabelY( 2, "Cal"); // 2: Cal
426 hpat.DefineLabelY( 3, "Cal"); // Cal+Lvl1
427 hpat.DefineLabelY( 4, "Trig"); // 4: Lvl2
428 hpat.DefineLabelY( 5, "Trig"); // Lvl2+Lvl1
429 hpat.DefineLabelY( 7, "Cal"); // Lvl2+Cal+Lvl
430 hpat.DefineLabelY( 8, "Ped"); // 8: Ped
431 hpat.DefineLabelY( 9, "Ped+Trig"); // Ped+Lvl1
432 hpat.DefineLabelY(10, "Ped+Cal"); // Ped+Cal
433 hpat.DefineLabelY(12, "Ped+Trig"); // Ped+Lvl2
434 hpat.DefineLabelY(13, "Ped+Trig"); // Ped+Lvl2+Lvl1
435 hpat.DefineLabelY(16, "Pin"); // 16: Pin
436 hpat.DefineLabelY(32, "Sum"); // 32: Sum
437 hpat.DefineLabelY(33, "Trig"); // Sum+Lvl1
438 hpat.DefineLabelY(34, "Cal"); // Sum+Cal
439 hpat.DefineLabelY(35, "Cal"); // Sum+Cal+Lvl1
440 hpat.DefineLabelY(36, "Trig"); // Sum+Lvl2
441 hpat.DefineLabelY(37, "Trig"); // Sum+Lvl1+Lvl2
442 hpat.DefineLabelY(39, "Cal"); // Sum+Lvl2+Cal+Lvl1
443
444 MFillH fillpat(&hpat, "", "FillPattern");
445 fillpat.SetDrawOption("box");
446
447 // This will make that for data with version less than 5, where
448 // trigger patterns were not yet correct, all the events in the real
449 // data file will be processed. In any case there are no interleaved
450 // calibration events in such data, so this is fine.
451 // We allow only cosmics triggered events to pass (before prescaling)
452 MFTriggerPattern fcalped("SelectTrigEvts");
453 fcalped.SetInverted();
454 fcalped.SetDefault(kTRUE);
455 fcalped.DenyAll();
456 fcalped.AllowTriggerLvl1();
457 fcalped.AllowTriggerLvl2();
458 fcalped.AllowSumTrigger();
459
460 // This will skip interleaved events with a cal- or ped-trigger
461 MContinue contcalped(&fcalped, "ContNonTrigger");
462
463 // Create the pedestal subtracted raw-data
464 MPedestalSubtract pedsub;
465 pedsub.SetPedestalCam(&pedcamab);
466
467 // Do signal and pedestal calculation
468 MPedCalcFromLoGain pedlo1("MPedCalcFundamental");
469 pedlo1.SetPedestalUpdate(kTRUE);
470 pedlo1.SetNamePedestalCamOut("MPedestalFundamental");
471
472 MPedCalcFromLoGain pedlo2("MPedCalcWithExtractorRndm");
473 pedlo2.SetPedestalUpdate(kTRUE);
474 pedlo2.SetRandomCalculation(kTRUE);
475 pedlo2.SetNamePedestalCamOut("MPedestalFromExtractorRndm");
476
477 MPedCalcFromLoGain pedlo3("MPedCalcWithExtractor");
478 pedlo3.SetPedestalUpdate(kTRUE);
479 pedlo3.SetRandomCalculation(kFALSE);
480 pedlo3.SetNamePedestalCamOut("MPedestalFromExtractor");
481
482 if (!extractor1)
483 {
484 *fLog << err << "ERROR - extractor1 == NULL" << endl;
485 return kFALSE;
486 }
487
488 // Setup to use the hi-gain extraction window in the lo-gain
489 // range (the start of the lo-gain range is added automatically
490 // by MPedCalcFromLoGain)
491 //
492 // The window size of the extractor is not yet initialized,
493 // so we have to stick to the extraction range
494 //
495 // Even if we would like to use a range comparable to the
496 // hi-gain extraction we use the lo-gain range to make
497 // sure that exclusions (eg. due to switching noise)
498 // are correctly handled.
499 //
500 pedlo1.SetRangeFromExtractor(*extractor1);
501
502 if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
503 {
504 pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
505 pedlo3.SetExtractor((MExtractTimeAndCharge*)extractor1);
506 }
507 else
508 {
509 pedlo2.SetRangeFromExtractor(*extractor1);
510 pedlo3.SetRangeFromExtractor(*extractor1);
511 }
512
513 //------------------------------
514 //
515 // this is the filter to find pedestal events. For the Siegen FADC
516 // these are all events which are not calibration events because
517 // the pedestal is extracted from the lo-gain signal. For MUX
518 // data this are artifiially triggered events with the pedestal
519 // trigger flag, and for safty without Lvl1 or Lvl2 flag)
520 //
521 // For the time "before" the trigger pattern all events (Siegen FADC)
522 // can be considered to be pedestal, because this was also the time
523 // without artifially calibration events
524 //
525 // Deny or allow is done before prescaling.
526 //
527 MFTriggerPattern fped("SelectPedestals");
528 fped.SetDefault(kTRUE);
529 fped.DenyCalibration();
530 if (!extractor1->HasLoGain())
531 {
532 fped.DenyAll();
533 fped.RequirePedestal();
534 }
535
536 //------------------------------
537 //
538 // Apply a filter against cosmics (this is to make sure that the
539 // trigger system was working properly and no empty events survive)
540 // For every event 5% of the pixel must not be empty. In PostProcess
541 // an error is raised if more than 50% of the events were skipped.
542 //
543 // Since unsuitable pixels are not counted in the ideal case
544 // there is no empty pixel at all.
545 //
546 MFCosmics fcosmicscal;
547 fcosmicscal.SetNamePedestalCam("MPedestalFundamental"); //CORRECT?
548 fcosmicscal.SetMaxEmptyPixels(0.05);
549 fcosmicscal.SetMaxAcceptedFraction(0.5);
550
551 MContinue contcoscal(&fcosmicscal, "ContCosmicsCal");
552
553 //------------------------------
554 //
555 // Remove events which are too bright. These events could either
556 // be calibration events or events which produce many many
557 // saturating low-gains and thus spoil the dead pixel plot.
558 // These events don't seem to be physical events so we can fairly
559 // remove them (they are no analysable gammas anyway)
560 // So we remove all events which have less than 5% empty pixels.
561 //
562 MFCosmics fcosmicsbright;
563 fcosmicsbright.SetNamePedestalCam("MPedestalFundamental");
564 fcosmicsbright.SetMaxEmptyPixels(0.10);
565 fcosmicsbright.SetMinAcceptedFraction(0.9);
566
567 MContinue contbright(&fcosmicsbright, "ContBrightEvts");
568 contbright.SetInverted();
569
570 //------------------------------
571 //
572 // Thie signal extractors
573 //
574 MTaskEnv taskenv1("ExtractSignal");
575 MTaskEnv taskenv2("ExtractTime");
576 MTaskEnv taskenv3("ExtractInterlaced");
577 taskenv1.SetDefault(extractor1);
578 taskenv2.SetDefault(extractor2);
579 taskenv3.SetDefault(extractor3);
580
581 //
582 // This is new calibration to photo-electrons, hard-coded
583 // as decided at the Wuerzburg software meeting 26.01.05
584 //
585 MCalibrateData calib;
586 calib.SetSignalType(MCalibrateData::kPhe);
587 //calib.AddPedestal("Fundamental");
588 calib.AddPedestal("FromExtractor");
589 calib.AddPedestal("FromExtractorRndm");
590 calib.SetPedestalFlag(MCalibrateData::kEvent);
591
592 //----------------------------------------------------------
593
594 MExtractPINDiode pinext;
595 MExtractBlindPixel bldext;
596
597 // Execute for all events with the calibration trigger. If no
598 // trigger pattern is available do not execute it
599 // The selection is done before prescaling.
600 MFTriggerPattern fcalib("SelectCalEvts");
601 fcalib.SetDefault(kFALSE);
602 fcalib.DenyAll();
603 fcalib.RequireCalibration();
604 fcalib.AllowTriggerLvl1();
605 fcalib.AllowTriggerLvl2();
606 fcalib.AllowSumTrigger();
607
608 MCalibrationChargeCalc chcalc;
609 chcalc.SetContinousCalibration();
610 chcalc.SetExtractor(extractor3);
611
612 MCalibrationRelTimeCalc recalc;
613 MCalibCalcFromPast pacalc;
614
615 chcalc.SetPedestals(&pedcamextr);
616
617 pacalc.SetChargeCalc(&chcalc);
618 if (fIsRelTimesUpdate)
619 pacalc.SetRelTimeCalc(&recalc);
620 pacalc.SetCalibrate(&calib);
621
622 //
623 // Calibration histogramming
624 //
625 MFillH filpin(&hpndiod, "MExtractedSignalPINDiode", "FillPINDiode");
626 MFillH filbnd(&hbndcam, "MExtractedSignalBlindPixel", "FillBlindCam");
627 MFillH filcam(&hchacam, "MExtractedSignalCam", "FillChargeCam");
628 MFillH filtme(&hrelcam, "MArrivalTimeCam", "FillRelTime");
629 //MFillH filhil(&hilocam, "MExtractedSignalCam", "FillHiLoRatio");
630 //MFillH filpul(&hpulcam, "MRawEvtData", "FillPulseTime");
631 filpin.SetBit(MFillH::kDoNotDisplay);
632 filbnd.SetBit(MFillH::kDoNotDisplay);
633 filcam.SetBit(MFillH::kDoNotDisplay);
634 filtme.SetBit(MFillH::kDoNotDisplay);
635 //filhil.SetBit(MFillH::kDoNotDisplay);
636 //filpul.SetBit(MFillH::kDoNotDisplay);
637
638 MCalibrateRelTimes caltm;
639 MBadPixelsCalc bpcal;
640 MBadPixelsTreat treat;
641
642 //bpcal.SetNamePedPhotCam("MPedPhotFromExtractor");
643 bpcal.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
644
645 //treat.AddNamePedPhotCam("MPedPhotFundamental");
646 treat.AddNamePedPhotCam("MPedPhotFromExtractor");
647 treat.AddNamePedPhotCam("MPedPhotFromExtractorRndm");
648 if (!extractor2 && !extractor1->InheritsFrom("MExtractTimeAndCharge"))
649 treat.SetProcessTimes(kFALSE);
650
651 MHCamEvent evt0( 0, "PedFLG", "Fundamental Pedestal from Lo Gain;;P [cnts/sl]");
652 MHCamEvent evt1( 2, "PedRmsFLG", "RMS from Extractor applied to ped.;;\\sigma_{p} [cnts/sl]");
653 MHCamEvent evt2( 0, "Extra'd", "Extracted Signal;;S [cnts/sl]");
654 // MHCamEvent evt3(4, "PedPhot", "Calibrated Pedestal;;P [phe]");
655 MHCamEvent evt4( 5, "PedRMS", "Calibrated RMS from Extractor applied to ped.;;\\sigma_{p} [phe]");
656 MHCamEvent evt5( 0, "Interp'd", "Interpolated Signal scaled with A/A_{0};;S [phe]");
657 MHCamEvent evt6(102, "Unsuitable", "Fraction of unsuitable events per Pixel;;[1]");
658 // MHCamEvent evt7( 6, "Times", "Calibrated Arrival Time;;T [fadc sl]");
659 MHCamEvent evt8( 0, "Conv", "Calibration Conv. Factors;;[phe/cnts]");
660 MHCamEvent evt9( 7, "PulsePos", "Pulse Position of cosmics (>50phe);;T [ns]");
661 MHCamEvent evtR( 4, "HiLoCal", "Hi-/Lo-Gain ratio;;Ratio");
662 MHCamEvent evtO( 7, "HiLoOff", "Lo-/Hi-Gain Offset;;Offset");
663 MHCamEvent evtC( 4, "CalPos", "Extracted pulse position of calibration pulses;;T [sl]");
664 //MHCamEvent evt2(0, "Extra'd", "Extracted Calibration Signal;;S [cnts/sl]");
665 evt2.SetErrorSpread(kFALSE);
666 evt5.SetErrorSpread(kFALSE);
667 evt6.SetErrorSpread(kFALSE);
668 evt6.SetThreshold();
669
670 MFillH fill0(&evt0, "MPedestalFundamental", "FillPedFLG");
671 MFillH fill1(&evt1, "MPedestalFromExtractorRndm", "FillPedRmsFLG");
672 MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtracted");
673 // MFillH fill3(&evt3, "MPedPhotFundamental", "FillPedPhot");
674 MFillH fill4(&evt4, "MPedPhotFromExtractorRndm", "FillPedRMS");
675 MFillH fill5(&evt5, "MSignalCam", "FillInterpolated");
676 MFillH fill6(&evt6, "MBadPixelsCam", "FillUnsuitable");
677 // MFillH fill7(&evt7, "MSignalCam", "FillTimes");
678 MFillH fill8(&evt8, "MCalibConstCam", "FillConv");
679 MFillH fill9(&evt9, "MSignalCam", "FillPulsePos");
680 MFillH fillR(&evtR, "MExtractedSignalCam", "FillHiLoCal");
681 MFillH fillO(&evtO, "MArrivalTimeCam", "FillHiLoOff");
682 MFillH fillC(&evtC, "MArrivalTimeCam", "FillCalPos");
683 //MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtractedSignal");
684
685 MHVsTime histbp("MBadPixelsCam.GetNumUnsuitable");
686 histbp.SetName("BadPixTm");
687 histbp.SetTitle("Number of unsuitable pixels;;N");
688 histbp.SetMinimum(0);
689
690 MHVsTime histdp("MSignalCam.GetNumPixelsUnmapped");
691 histdp.SetName("DeadPixTm");
692 histdp.SetTitle("Number of dead/unmapped pixels;;N");
693 histdp.SetMinimum(0);
694
695 // Task to fill the histogram
696 MFillH fillB(&histbp, "MTime", "FillBadPixTm");
697 MFillH fillD(&histdp, "MTime", "FillDeadPixTm");
698 fillB.SetNameTab("BadPixTm");
699 fillD.SetNameTab("DeadPixTm");
700
701 /*
702 MFillH fillP("MHPulseShape", "", "FillPulseShape");
703 fillP.SetNameTab("Pulse");
704 */
705
706 /*
707 MHVsTime hbadpix("MBadPixelsCam.GetNumUnsuitable");
708 hbadpix.SetNumEvents(50);
709 MFillH fillB(&hbadpix, "MTime");
710 */
711
712 MTaskEnv fillflorian("FinalFantasy");
713 fillflorian.SetDefault();
714
715 // The second rule is for the case reading raw-files!
716 MWriteRootFile write(2, fname, fOverwrite?"RECREATE":"NEW", "Calibrated Data");
717 // Run Header
718 write.AddContainer("MRawRunHeader", "RunHeaders");
719// write.AddContainer("MBadPixelsCam", "RunHeaders");
720 write.AddContainer("MGeomCam", "RunHeaders");
721 // Monte Carlo Headers
722 write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
723 write.AddContainer("MMcFadcHeader", "RunHeaders", kFALSE);
724 write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
725 write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
726 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
727 write.AddContainer("MCorsikaRunHeader", "RunHeaders", kFALSE);
728 // Monte Carlo
729 write.AddContainer("MMcEvt", "Events", kFALSE);
730 write.AddContainer("MMcTrig", "Events", kFALSE);
731 write.AddContainer("MCorsikaEvtHeader", "Events", kFALSE);
732 // Data tree
733 write.AddContainer("MSignalCam", "Events");
734 // write.AddContainer("MPedPhotFundamental", "Events");
735 write.AddContainer("MPedPhotFromExtractor", "Events");
736 write.AddContainer("MPedPhotFromExtractorRndm", "Events");
737 write.AddContainer("MTime", "Events", kFALSE);
738 write.AddContainer("MRawEvtHeader", "Events");
739 write.AddContainer("MTriggerPattern", "Events");
740
741 // Trees with slow-control information (obsolete
742 // if we don't read merpped root-files)
743 write.AddTree("Trigger", kFALSE);
744 write.AddTree("Drive", kFALSE);
745 write.AddTree("CC", kFALSE);
746 write.AddTree("Pyrometer", kFALSE);
747 write.AddTree("Currents", kFALSE);
748 write.AddTree("Camera", kFALSE);
749 // Slow-Control: Current-tree
750 write.AddContainer("MCameraDC", "Currents", kFALSE);
751 // Slow-Control: Camera-tree
752 write.AddContainer("MCameraAUX", "Camera", kFALSE);
753 write.AddContainer("MCameraCalibration", "Camera", kFALSE);
754 write.AddContainer("MCameraCooling", "Camera", kFALSE);
755 write.AddContainer("MCameraHV", "Camera", kFALSE);
756 write.AddContainer("MCameraLV", "Camera", kFALSE);
757 write.AddContainer("MCameraLids", "Camera", kFALSE);
758
759 // Write the special MC tree
760 MWriteRootFile writemc(2, fname, fOverwrite?"RECREATE":"NEW", "Calibrated Data");
761 writemc.SetName("WriteMC");
762 writemc.AddContainer("MMcEvtBasic", "OriginalMC", kFALSE);
763 if (fSequence.IsMonteCarlo())
764 writemc.AddCopySource("OriginalMC", kFALSE);
765
766 // Write the special calib tree
767 /*
768 MWriteRootFile writecal(2, fname, fOverwrite?"RECREATE":"NEW");
769 writecal.SetName("WriteCalib");
770 writecal.AddContainer("MBadPixelsCam", "Calib");
771 writecal.AddContainer("MCalibrationChargeCam", "Calib");
772 writecal.AddContainer("MCalibrationRelTimeCam", "Calib");
773 */
774
775 //-----------------------------------------------------------
776 // Build tasklist
777
778 MTaskList tlist2("AllEvents");
779
780 tlist2.AddToList(&caldec);
781 tlist2.AddToList(&decode);
782 tlist2.AddToList(&fillpat);
783 tlist2.AddToList(&apply);
784 //tlist2.AddToList(&merge);
785 tlist2.AddToList(&pedsub);
786
787 //-----------------------------------------------------------
788 // Pedestal extraction
789
790 MTaskList tlist3("PedEvents");
791 tlist3.SetFilter(&fped); // Deny events with cal-trigger
792
793 tlist2.AddToList(&fped); // If no lo-gain require ped-trigger
794 tlist2.AddToList(&tlist3); // and deny cosmics (lvl1/2) trigger
795
796 tlist3.AddToList(&pedlo1); // extract pedestal events
797 tlist3.AddToList(&pedlo2); // extract pedestal events
798 tlist3.AddToList(&pedlo3); // extract pedestal events
799 tlist3.AddToList(&fill0); // fill pedestal events
800 tlist3.AddToList(&fill1); // fill pedestal events
801
802 //-----------------------------------------------------------
803 // Calibration
804
805 MTaskList tlist4("CalEvents");
806 tlist4.SetFilter(&fcalib); // process only events with cal-trigger
807
808 //MFDataPhrase filcalco("MCalibrationConstCam.IsReadyToSave>0.5", "CalibConstFilter");
809 if (fIsInterlaced)
810 {
811 // The task list is executed for all events with the calibration
812 // trigger
813 tlist2.AddToList(&fcalib); // MFTriggerPattern
814 tlist2.AddToList(&tlist4);
815
816 tlist4.AddToList(&taskenv3);
817 tlist4.AddToList(&contcoscal); // MContinue/ContCosmicsCal
818 if (IsUsePINDiode())
819 tlist4.AddToList(&pinext); // MExtractPINDiode
820 if (IsUseBlindPixel())
821 tlist4.AddToList(&bldext); // MExtractBlindPixel
822 tlist4.AddToList(&pacalc); // MCalibCalcFromPast
823 /*
824 tlist3.AddToList(&filcalco); // CalibConstFilter (IsReadyToSave)
825 fill8.SetFilter(&filcalco);
826 tlist3.AddToList(&fill8); // FillConvUpd
827 */
828
829 tlist4.AddToList(&filcam); // FillChargeCam
830 if (fIsRelTimesUpdate)
831 tlist4.AddToList(&filtme); // FillRelTime
832 if (IsUseBlindPixel())
833 tlist4.AddToList(&filbnd); // FillBlindCam
834 if (IsUsePINDiode())
835 tlist4.AddToList(&filpin); // FillPINDiode
836 tlist4.AddToList(&chcalc); // MCalibrationChargeCalc
837 if (fIsRelTimesUpdate)
838 tlist4.AddToList(&recalc); // MCalibrationRelTimeCam
839
840 tlist4.AddToList(&fillC); // FillCalPos
841
842 //tlist3.AddToList(&writecal); // MWriteRootFile
843 }
844
845 //-----------------------------------------------------------
846 // Cosmics extraction
847
848 // remove all events with a cal- or ped-trigger (no matter
849 // whether they have lvl1 or lvl2 or any other flag
850 tlist2.AddToList(&contcalped);
851
852 // Extract the signal
853 if (extractor1)
854 tlist2.AddToList(&taskenv1);
855
856 // remove all events which definitly don't have a signal
857 // using MFCosmics (ContCosmicsPed)
858 // tlist2.AddToList(&contcosped);
859
860 // Extract arrival time (if a dedicated extrator given)
861 if (extractor2)
862 tlist2.AddToList(&taskenv2);
863
864 // Check if we have an extremely bright event (remove them,
865 // they are presumably errornous events or calibration events)
866 tlist2.AddToList(&contbright);
867
868 /*
869 if (fIsHiLoCalibration)
870 {
871 plist.AddToList(&hilocam);
872 tlist2.AddToList(&filhil);
873 }
874
875 if (fIsPulsePosCheck)
876 {
877 plist.AddToList(&hpulcam);
878 tlist2.AddToList(&filpul);
879 }
880 */
881
882 tlist2.AddToList(&fill2);
883 tlist2.AddToList(&fill8); // FillConv
884 tlist2.AddToList(&calib); // MCalibrateData
885 if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
886 tlist2.AddToList(&caltm);
887
888 tlist2.AddToList(&bpcal); // MBadPixelsCalc
889 tlist2.AddToList(&treat); // MBadPixelsTreat
890 tlist2.AddToList(&fill6);
891 // tlist2.AddToList(&fill3);
892 tlist2.AddToList(&fill4);
893 tlist2.AddToList(&fill5);
894 //if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
895 // tlist2.AddToList(&fill7);
896 tlist2.AddToList(&fill9);
897 if (!fSequence.IsMonteCarlo())
898 {
899 tlist2.AddToList(&fillB);
900 tlist2.AddToList(&fillD);
901 }
902 if (extractor1->HasLoGain())
903 {
904 tlist2.AddToList(&fillR);
905 tlist2.AddToList(&fillO);
906 }
907
908 /*
909 MFillH fillC("MHCleaning", "", "FillClean");
910 tlist2.AddToList(&fillC);
911
912 //tlist2.AddToList(&fillP);
913 */
914
915 // ----- Start: Code for encoding movies -----
916
917 MMoviePrepare movprep;
918 MMovieWrite movwrite;
919 movprep.SetRangeFromExtractor(*extractor1);
920
921 //MFDataPhrase movfilt("MMovieData.fMax>150");
922 MFDataPhrase movfilt("MMovieData.fMax>5*MMovieData.fMedianPedestalRms", "MovieFilter");
923
924 MImgCleanStd movclean(8.5, 4.0);
925 movclean.SetMethod(MImgCleanStd::kAbsolute);
926
927 //movprep.SetFilter(&evtnum);
928 movclean.SetFilter(&movfilt);
929 movwrite.SetFilter(&movfilt);
930
931 MTaskList tlistmov("MovieEncoder");
932 tlistmov.AddToList(&movprep);
933 tlistmov.AddToList(&movfilt);
934 tlistmov.AddToList(&movclean);
935 tlistmov.AddToList(&movwrite);
936
937 MFEvtNumber evtnum;
938 //evtnum.SetSelector("ThetaSquared.fVal<0.04");
939 //evtnum.SetFileName("ganymed00000001.root");
940 tlistmov.SetFilter(&evtnum);
941
942 if (fIsMovieMode)
943 {
944 tlist2.AddToList(&evtnum);
945 tlist2.AddToList(&tlistmov);
946 }
947
948 // ----- End: Code for encoding movies -----
949
950 tlist2.AddToList(&fillflorian);
951
952 // Setup List for Drive-tree
953 //MPointingPosCalc pcalc;
954
955 // Now setup main tasklist
956 tlist.AddToList(read);
957
958 if (fSequence.IsMonteCarlo())
959 {
960 if (!fIsMovieMode && !HasNullOut())
961 tlist.AddToList(&writemc);
962 tlist.AddToList(&contmc);
963 }
964
965 //if (IsUseRootData())
966 // tlist2.AddToList(&pextr);
967 tlist.AddToList(&tlist2, fSequence.IsMonteCarlo() ? "Events" : "All");
968
969 //if (fSequence.IsMonteCarlo())
970 // tlist.AddToList(&pcalc, "Drive");
971
972 if (!fIsMovieMode && !HasNullOut())
973 tlist.AddToList(&write);
974
975 // Create and setup the eventloop
976 MEvtLoop evtloop(fName);
977 evtloop.SetParList(&plist);
978 evtloop.SetDisplay(fDisplay);
979 evtloop.SetLogStream(fLog);
980 if (!SetupEnv(evtloop))
981 return kFALSE;
982
983 // Execute first analysis
984 const Bool_t rc = evtloop.Eventloop(fMaxEvents);
985
986 // make sure owned object are deleted
987 if (extractor1 && extractor1!=fExtractor)
988 delete extractor1;
989 if (extractor2)
990 delete extractor2;
991 if (extractor3)
992 delete extractor3;
993
994 // return if job failed
995 if (!rc)
996 {
997 *fLog << err << GetDescriptor() << ": Failed." << endl;
998 return kFALSE;
999 }
1000
1001 // if everything went ok write and display result
1002 DisplayResult(plist);
1003
1004 /*
1005 if (fIsPixelCheck)
1006 {
1007 if (fIsPulsePosCheck)
1008 hpulcam[fCheckedPixId].DrawClone("");
1009
1010 //if (fIsHiLoCalibration)
1011 // hilocam[fCheckedPixId].DrawClone("");
1012 }
1013 interlacedcont.Add(&pulcam);
1014 */
1015
1016 //if (fIsHiLoCalibration)
1017 // interlacedcont.Add(&hilcam);
1018
1019 //if (fIsPulsePosCheck)
1020 // interlacedcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
1021
1022 //if (fIsHiLoCalibration)
1023 // interlacedcont.Add(plist.FindObject("MHCalibrationHiLoCam"));
1024
1025 if (!WriteResult())
1026 return kFALSE;
1027
1028 // return if job went ok
1029 *fLog << all << GetDescriptor() << ": Done." << endl;
1030 *fLog << endl << endl;
1031
1032 return kTRUE;
1033}
1034
1035
1036void MJCalibrateSignal::DisplayResult(MParList &plist)
1037{
1038 /*
1039 if (!fDisplay || !fIsHiLoCalibration)
1040 return;
1041
1042 MCalibrationHiLoCam *hcam = (MCalibrationHiLoCam*)plist.FindObject("MCalibrationHiLoCam");
1043 MGeomCam *geom = (MGeomCam*)plist.FindObject("MGeomCam");
1044 if (!hcam || !geom)
1045 return;
1046
1047 // Create histograms to display
1048 MHCamera disp1(*geom, "HiLoConv", "Ratio Amplification HiGain vs. LoGain (Charges)");
1049 MHCamera disp2(*geom, "HiLoDiff", "Arrival Time Diff. HiGain vs. LoGain (Times)");
1050
1051 disp1.SetCamContent(*hcam, 0);
1052 disp1.SetCamError( *hcam, 1);
1053 disp2.SetCamContent(*hcam, 5);
1054 disp2.SetCamError( *hcam, 6);
1055
1056 disp1.SetYTitle("R [1]");
1057 disp2.SetYTitle("\\Delta T [FADC sl.]");
1058
1059 TCanvas &c1 = fDisplay->AddTab("HiLoConv");
1060 c1.Divide(2,3);
1061
1062 disp1.CamDraw(c1, 1, 2, 1);
1063 disp2.CamDraw(c1, 2, 2, 1);
1064*/
1065}
1066
Note: See TracBrowser for help on using the repository browser.