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

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