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

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