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

Last change on this file since 9439 was 9410, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 35.2 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 // Monte Carlo
728 write.AddContainer("MMcEvt", "Events", kFALSE);
729 write.AddContainer("MMcTrig", "Events", kFALSE);
730 // Data tree
731 write.AddContainer("MSignalCam", "Events");
732 // write.AddContainer("MPedPhotFundamental", "Events");
733 write.AddContainer("MPedPhotFromExtractor", "Events");
734 write.AddContainer("MPedPhotFromExtractorRndm", "Events");
735 write.AddContainer("MTime", "Events", kFALSE);
736 write.AddContainer("MRawEvtHeader", "Events");
737 write.AddContainer("MTriggerPattern", "Events");
738
739 // Trees with slow-control information (obsolete
740 // if we don't read merpped root-files)
741 write.AddTree("Trigger", kFALSE);
742 write.AddTree("Drive", kFALSE);
743 write.AddTree("CC", kFALSE);
744 write.AddTree("Pyrometer", kFALSE);
745 write.AddTree("Currents", kFALSE);
746 write.AddTree("Camera", kFALSE);
747 // Slow-Control: Current-tree
748 write.AddContainer("MCameraDC", "Currents", kFALSE);
749 // Slow-Control: Camera-tree
750 write.AddContainer("MCameraAUX", "Camera", kFALSE);
751 write.AddContainer("MCameraCalibration", "Camera", kFALSE);
752 write.AddContainer("MCameraCooling", "Camera", kFALSE);
753 write.AddContainer("MCameraHV", "Camera", kFALSE);
754 write.AddContainer("MCameraLV", "Camera", kFALSE);
755 write.AddContainer("MCameraLids", "Camera", kFALSE);
756
757 // Write the special MC tree
758 MWriteRootFile writemc(2, fname, fOverwrite?"RECREATE":"NEW", "Calibrated Data");
759 writemc.SetName("WriteMC");
760 writemc.AddContainer("MMcEvtBasic", "OriginalMC", kFALSE);
761 if (fSequence.IsMonteCarlo())
762 writemc.AddCopySource("OriginalMC", kFALSE);
763
764 // Write the special calib tree
765 /*
766 MWriteRootFile writecal(2, fname, fOverwrite?"RECREATE":"NEW");
767 writecal.SetName("WriteCalib");
768 writecal.AddContainer("MBadPixelsCam", "Calib");
769 writecal.AddContainer("MCalibrationChargeCam", "Calib");
770 writecal.AddContainer("MCalibrationRelTimeCam", "Calib");
771 */
772
773 //-----------------------------------------------------------
774 // Build tasklist
775
776 MTaskList tlist2("AllEvents");
777
778 tlist2.AddToList(&caldec);
779 tlist2.AddToList(&decode);
780 tlist2.AddToList(&fillpat);
781 tlist2.AddToList(&apply);
782 //tlist2.AddToList(&merge);
783 tlist2.AddToList(&pedsub);
784
785 //-----------------------------------------------------------
786 // Pedestal extraction
787
788 MTaskList tlist3("PedEvents");
789 tlist3.SetFilter(&fped); // Deny events with cal-trigger
790
791 tlist2.AddToList(&fped); // If no lo-gain require ped-trigger
792 tlist2.AddToList(&tlist3); // and deny cosmics (lvl1/2) trigger
793
794 tlist3.AddToList(&pedlo1); // extract pedestal events
795 tlist3.AddToList(&pedlo2); // extract pedestal events
796 tlist3.AddToList(&pedlo3); // extract pedestal events
797 tlist3.AddToList(&fill0); // fill pedestal events
798 tlist3.AddToList(&fill1); // fill pedestal events
799
800 //-----------------------------------------------------------
801 // Calibration
802
803 MTaskList tlist4("CalEvents");
804 tlist4.SetFilter(&fcalib); // process only events with cal-trigger
805
806 //MFDataPhrase filcalco("MCalibrationConstCam.IsReadyToSave>0.5", "CalibConstFilter");
807 if (fIsInterlaced)
808 {
809 // The task list is executed for all events with the calibration
810 // trigger
811 tlist2.AddToList(&fcalib); // MFTriggerPattern
812 tlist2.AddToList(&tlist4);
813
814 tlist4.AddToList(&taskenv3);
815 tlist4.AddToList(&contcoscal); // MContinue/ContCosmicsCal
816 if (IsUsePINDiode())
817 tlist4.AddToList(&pinext); // MExtractPINDiode
818 if (IsUseBlindPixel())
819 tlist4.AddToList(&bldext); // MExtractBlindPixel
820 tlist4.AddToList(&pacalc); // MCalibCalcFromPast
821 /*
822 tlist3.AddToList(&filcalco); // CalibConstFilter (IsReadyToSave)
823 fill8.SetFilter(&filcalco);
824 tlist3.AddToList(&fill8); // FillConvUpd
825 */
826
827 tlist4.AddToList(&filcam); // FillChargeCam
828 if (fIsRelTimesUpdate)
829 tlist4.AddToList(&filtme); // FillRelTime
830 if (IsUseBlindPixel())
831 tlist4.AddToList(&filbnd); // FillBlindCam
832 if (IsUsePINDiode())
833 tlist4.AddToList(&filpin); // FillPINDiode
834 tlist4.AddToList(&chcalc); // MCalibrationChargeCalc
835 if (fIsRelTimesUpdate)
836 tlist4.AddToList(&recalc); // MCalibrationRelTimeCam
837
838 tlist4.AddToList(&fillC); // FillCalPos
839
840 //tlist3.AddToList(&writecal); // MWriteRootFile
841 }
842
843 //-----------------------------------------------------------
844 // Cosmics extraction
845
846 // remove all events with a cal- or ped-trigger (no matter
847 // whether they have lvl1 or lvl2 or any other flag
848 tlist2.AddToList(&contcalped);
849
850 // Extract the signal
851 if (extractor1)
852 tlist2.AddToList(&taskenv1);
853
854 // remove all events which definitly don't have a signal
855 // using MFCosmics (ContCosmicsPed)
856 // tlist2.AddToList(&contcosped);
857
858 // Extract arrival time (if a dedicated extrator given)
859 if (extractor2)
860 tlist2.AddToList(&taskenv2);
861
862 // Check if we have an extremely bright event (remove them,
863 // they are presumably errornous events or calibration events)
864 tlist2.AddToList(&contbright);
865
866 /*
867 if (fIsHiLoCalibration)
868 {
869 plist.AddToList(&hilocam);
870 tlist2.AddToList(&filhil);
871 }
872
873 if (fIsPulsePosCheck)
874 {
875 plist.AddToList(&hpulcam);
876 tlist2.AddToList(&filpul);
877 }
878 */
879
880 tlist2.AddToList(&fill2);
881 tlist2.AddToList(&fill8); // FillConv
882 tlist2.AddToList(&calib); // MCalibrateData
883 if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
884 tlist2.AddToList(&caltm);
885
886 tlist2.AddToList(&bpcal); // MBadPixelsCalc
887 tlist2.AddToList(&treat); // MBadPixelsTreat
888 tlist2.AddToList(&fill6);
889 // tlist2.AddToList(&fill3);
890 tlist2.AddToList(&fill4);
891 tlist2.AddToList(&fill5);
892 //if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
893 // tlist2.AddToList(&fill7);
894 tlist2.AddToList(&fill9);
895 if (!fSequence.IsMonteCarlo())
896 {
897 tlist2.AddToList(&fillB);
898 tlist2.AddToList(&fillD);
899 }
900 if (extractor1->HasLoGain())
901 {
902 tlist2.AddToList(&fillR);
903 tlist2.AddToList(&fillO);
904 }
905
906 /*
907 MFillH fillC("MHCleaning", "", "FillClean");
908 tlist2.AddToList(&fillC);
909
910 //tlist2.AddToList(&fillP);
911 */
912
913 // ----- Start: Code for encoding movies -----
914
915 MMoviePrepare movprep;
916 MMovieWrite movwrite;
917 movprep.SetRangeFromExtractor(*extractor1);
918
919 //MFDataPhrase movfilt("MMovieData.fMax>150");
920 MFDataPhrase movfilt("MMovieData.fMax>5*MMovieData.fMedianPedestalRms", "MovieFilter");
921
922 MImgCleanStd movclean(8.5, 4.0);
923 movclean.SetMethod(MImgCleanStd::kAbsolute);
924
925 //movprep.SetFilter(&evtnum);
926 movclean.SetFilter(&movfilt);
927 movwrite.SetFilter(&movfilt);
928
929 MTaskList tlistmov("MovieEncoder");
930 tlistmov.AddToList(&movprep);
931 tlistmov.AddToList(&movfilt);
932 tlistmov.AddToList(&movclean);
933 tlistmov.AddToList(&movwrite);
934
935 MFEvtNumber evtnum;
936 //evtnum.SetSelector("ThetaSquared.fVal<0.04");
937 //evtnum.SetFileName("ganymed00000001.root");
938 tlistmov.SetFilter(&evtnum);
939
940 if (fIsMovieMode)
941 {
942 tlist2.AddToList(&evtnum);
943 tlist2.AddToList(&tlistmov);
944 }
945
946 // ----- End: Code for encoding movies -----
947
948 tlist2.AddToList(&fillflorian);
949
950 // Setup List for Drive-tree
951 //MPointingPosCalc pcalc;
952
953 // Now setup main tasklist
954 tlist.AddToList(read);
955
956 if (fSequence.IsMonteCarlo())
957 {
958 if (!fIsMovieMode && !HasNullOut())
959 tlist.AddToList(&writemc);
960 tlist.AddToList(&contmc);
961 }
962
963 //if (IsUseRootData())
964 // tlist2.AddToList(&pextr);
965 tlist.AddToList(&tlist2, fSequence.IsMonteCarlo() ? "Events" : "All");
966
967 //if (fSequence.IsMonteCarlo())
968 // tlist.AddToList(&pcalc, "Drive");
969
970 if (!fIsMovieMode && !HasNullOut())
971 tlist.AddToList(&write);
972
973 // Create and setup the eventloop
974 MEvtLoop evtloop(fName);
975 evtloop.SetParList(&plist);
976 evtloop.SetDisplay(fDisplay);
977 evtloop.SetLogStream(fLog);
978 if (!SetupEnv(evtloop))
979 return kFALSE;
980
981 // Execute first analysis
982 const Bool_t rc = evtloop.Eventloop(fMaxEvents);
983
984 // make sure owned object are deleted
985 if (extractor1 && extractor1!=fExtractor)
986 delete extractor1;
987 if (extractor2)
988 delete extractor2;
989 if (extractor3)
990 delete extractor3;
991
992 // return if job failed
993 if (!rc)
994 {
995 *fLog << err << GetDescriptor() << ": Failed." << endl;
996 return kFALSE;
997 }
998
999 // if everything went ok write and display result
1000 DisplayResult(plist);
1001
1002 /*
1003 if (fIsPixelCheck)
1004 {
1005 if (fIsPulsePosCheck)
1006 hpulcam[fCheckedPixId].DrawClone("");
1007
1008 //if (fIsHiLoCalibration)
1009 // hilocam[fCheckedPixId].DrawClone("");
1010 }
1011 interlacedcont.Add(&pulcam);
1012 */
1013
1014 //if (fIsHiLoCalibration)
1015 // interlacedcont.Add(&hilcam);
1016
1017 //if (fIsPulsePosCheck)
1018 // interlacedcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
1019
1020 //if (fIsHiLoCalibration)
1021 // interlacedcont.Add(plist.FindObject("MHCalibrationHiLoCam"));
1022
1023 if (!WriteResult())
1024 return kFALSE;
1025
1026 // return if job went ok
1027 *fLog << all << GetDescriptor() << ": Done." << endl;
1028 *fLog << endl << endl;
1029
1030 return kTRUE;
1031}
1032
1033
1034void MJCalibrateSignal::DisplayResult(MParList &plist)
1035{
1036 /*
1037 if (!fDisplay || !fIsHiLoCalibration)
1038 return;
1039
1040 MCalibrationHiLoCam *hcam = (MCalibrationHiLoCam*)plist.FindObject("MCalibrationHiLoCam");
1041 MGeomCam *geom = (MGeomCam*)plist.FindObject("MGeomCam");
1042 if (!hcam || !geom)
1043 return;
1044
1045 // Create histograms to display
1046 MHCamera disp1(*geom, "HiLoConv", "Ratio Amplification HiGain vs. LoGain (Charges)");
1047 MHCamera disp2(*geom, "HiLoDiff", "Arrival Time Diff. HiGain vs. LoGain (Times)");
1048
1049 disp1.SetCamContent(*hcam, 0);
1050 disp1.SetCamError( *hcam, 1);
1051 disp2.SetCamContent(*hcam, 5);
1052 disp2.SetCamError( *hcam, 6);
1053
1054 disp1.SetYTitle("R [1]");
1055 disp2.SetYTitle("\\Delta T [FADC sl.]");
1056
1057 TCanvas &c1 = fDisplay->AddTab("HiLoConv");
1058 c1.Divide(2,3);
1059
1060 disp1.CamDraw(c1, 1, 2, 1);
1061 disp2.CamDraw(c1, 2, 2, 1);
1062*/
1063}
1064
Note: See TracBrowser for help on using the repository browser.