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

Last change on this file since 9087 was 9077, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 34.9 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 // Since unsuitable pixels are not counted in the ideal case
543 // there is no empty pixel at all.
544 //
545 MFCosmics fcosmicscal;
546 fcosmicscal.SetNamePedestalCam("MPedestalFundamental"); //CORRECT?
547 fcosmicscal.SetMaxEmptyPixels(0.05);
548 fcosmicscal.SetMaxAcceptedFraction(0.5);
549
550 MContinue contcoscal(&fcosmicscal, "ContCosmicsCal");
551
552 //------------------------------
553 //
554 // Remove events which are too bright. These events could either
555 // be calibration events or events which produce many many
556 // saturating low-gains and thus spoil the dead pixel plot.
557 // These events don't seem to be physical events so we can fairly
558 // remove them (they are no analysable gammas anyway)
559 // So we remove all events which have less than 5% empty pixels.
560 //
561 MFCosmics fcosmicsbright;
562 fcosmicsbright.SetNamePedestalCam("MPedestalFundamental");
563 fcosmicsbright.SetMaxEmptyPixels(0.10);
564 fcosmicsbright.SetMinAcceptedFraction(0.9);
565
566 MContinue contbright(&fcosmicsbright, "ContBrightEvts");
567 contbright.SetInverted();
568
569 //------------------------------
570 //
571 // Thie signal extractors
572 //
573 MTaskEnv taskenv1("ExtractSignal");
574 MTaskEnv taskenv2("ExtractTime");
575 MTaskEnv taskenv3("ExtractInterlaced");
576 taskenv1.SetDefault(extractor1);
577 taskenv2.SetDefault(extractor2);
578 taskenv3.SetDefault(extractor3);
579
580 //
581 // This is new calibration to photo-electrons, hard-coded
582 // as decided at the Wuerzburg software meeting 26.01.05
583 //
584 MCalibrateData calib;
585 calib.SetSignalType(MCalibrateData::kPhe);
586 //calib.AddPedestal("Fundamental");
587 calib.AddPedestal("FromExtractor");
588 calib.AddPedestal("FromExtractorRndm");
589 calib.SetPedestalFlag(MCalibrateData::kEvent);
590
591 //----------------------------------------------------------
592
593 MExtractPINDiode pinext;
594 MExtractBlindPixel bldext;
595
596 // Execute for all events with the calibration trigger. If no
597 // trigger pattern is available do not execute it
598 // The selection is done before prescaling.
599 MFTriggerPattern fcalib("SelectCalEvts");
600 fcalib.SetDefault(kFALSE);
601 fcalib.DenyAll();
602 fcalib.RequireCalibration();
603 fcalib.AllowTriggerLvl1();
604 fcalib.AllowTriggerLvl2();
605 fcalib.AllowSumTrigger();
606
607 MCalibrationChargeCalc chcalc;
608 chcalc.SetContinousCalibration();
609 chcalc.SetExtractor(extractor3);
610
611 MCalibrationRelTimeCalc recalc;
612 MCalibCalcFromPast pacalc;
613
614 chcalc.SetPedestals(&pedcamextr);
615
616 pacalc.SetChargeCalc(&chcalc);
617 if (fIsRelTimesUpdate)
618 pacalc.SetRelTimeCalc(&recalc);
619 pacalc.SetCalibrate(&calib);
620
621 //
622 // Calibration histogramming
623 //
624 MFillH filpin(&hpndiod, "MExtractedSignalPINDiode", "FillPINDiode");
625 MFillH filbnd(&hbndcam, "MExtractedSignalBlindPixel", "FillBlindCam");
626 MFillH filcam(&hchacam, "MExtractedSignalCam", "FillChargeCam");
627 MFillH filtme(&hrelcam, "MArrivalTimeCam", "FillRelTime");
628 //MFillH filhil(&hilocam, "MExtractedSignalCam", "FillHiLoRatio");
629 //MFillH filpul(&hpulcam, "MRawEvtData", "FillPulseTime");
630 filpin.SetBit(MFillH::kDoNotDisplay);
631 filbnd.SetBit(MFillH::kDoNotDisplay);
632 filcam.SetBit(MFillH::kDoNotDisplay);
633 filtme.SetBit(MFillH::kDoNotDisplay);
634 //filhil.SetBit(MFillH::kDoNotDisplay);
635 //filpul.SetBit(MFillH::kDoNotDisplay);
636
637 MCalibrateRelTimes caltm;
638 MBadPixelsCalc bpcal;
639 MBadPixelsTreat treat;
640
641 //bpcal.SetNamePedPhotCam("MPedPhotFromExtractor");
642 bpcal.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
643
644 //treat.AddNamePedPhotCam("MPedPhotFundamental");
645 treat.AddNamePedPhotCam("MPedPhotFromExtractor");
646 treat.AddNamePedPhotCam("MPedPhotFromExtractorRndm");
647 if (!extractor2 && !extractor1->InheritsFrom("MExtractTimeAndCharge"))
648 treat.SetProcessTimes(kFALSE);
649
650 MHCamEvent evt0( 0, "PedFLG", "Fundamental Pedestal from Lo Gain;;P [cnts/sl]");
651 MHCamEvent evt1( 2, "PedRmsFLG", "RMS from Extractor applied to ped.;;\\sigma_{p} [cnts/sl]");
652 MHCamEvent evt2( 0, "Extra'd", "Extracted Signal;;S [cnts/sl]");
653 // MHCamEvent evt3(4, "PedPhot", "Calibrated Pedestal;;P [phe]");
654 MHCamEvent evt4( 5, "PedRMS", "Calibrated RMS from Extractor applied to ped.;;\\sigma_{p} [phe]");
655 MHCamEvent evt5( 0, "Interp'd", "Interpolated Signal scaled with A/A_{0};;S [phe]");
656 MHCamEvent evt6(102, "Unsuitable", "Fraction of unsuitable events per Pixel;;[1]");
657 // MHCamEvent evt7( 6, "Times", "Calibrated Arrival Time;;T [fadc sl]");
658 MHCamEvent evt8( 0, "Conv", "Calibration Conv. Factors;;[phe/cnts]");
659 MHCamEvent evt9( 7, "PulsePos", "Pulse Position of cosmics (>50phe);;T [ns]");
660 MHCamEvent evtR( 4, "HiLoCal", "Hi-/Lo-Gain ratio;;Ratio");
661 MHCamEvent evtO( 7, "HiLoOff", "Lo-/Hi-Gain Offset;;Offset");
662 MHCamEvent evtC( 4, "CalPos", "Extracted pulse position of calibration pulses;;T [sl]");
663 //MHCamEvent evt2(0, "Extra'd", "Extracted Calibration Signal;;S [cnts/sl]");
664 evt2.SetErrorSpread(kFALSE);
665 evt5.SetErrorSpread(kFALSE);
666 evt6.SetErrorSpread(kFALSE);
667 evt6.SetThreshold();
668
669 MFillH fill0(&evt0, "MPedestalFundamental", "FillPedFLG");
670 MFillH fill1(&evt1, "MPedestalFromExtractorRndm", "FillPedRmsFLG");
671 MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtracted");
672 // MFillH fill3(&evt3, "MPedPhotFundamental", "FillPedPhot");
673 MFillH fill4(&evt4, "MPedPhotFromExtractorRndm", "FillPedRMS");
674 MFillH fill5(&evt5, "MSignalCam", "FillInterpolated");
675 MFillH fill6(&evt6, "MBadPixelsCam", "FillUnsuitable");
676 // MFillH fill7(&evt7, "MSignalCam", "FillTimes");
677 MFillH fill8(&evt8, "MCalibConstCam", "FillConv");
678 MFillH fill9(&evt9, "MSignalCam", "FillPulsePos");
679 MFillH fillR(&evtR, "MExtractedSignalCam", "FillHiLoCal");
680 MFillH fillO(&evtO, "MArrivalTimeCam", "FillHiLoOff");
681 MFillH fillC(&evtC, "MArrivalTimeCam", "FillCalPos");
682 //MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtractedSignal");
683
684 MHVsTime histbp("MBadPixelsCam.GetNumUnsuitable");
685 histbp.SetName("BadPixTm");
686 histbp.SetTitle("Number of unsuitable pixels;;N");
687 histbp.SetMinimum(0);
688
689 MHVsTime histdp("MSignalCam.GetNumPixelsUnmapped");
690 histdp.SetName("DeadPixTm");
691 histdp.SetTitle("Number of dead/unmapped pixels;;N");
692 histdp.SetMinimum(0);
693
694 // Task to fill the histogram
695 MFillH fillB(&histbp, "MTime", "FillBadPixTm");
696 MFillH fillD(&histdp, "MTime", "FillDeadPixTm");
697 fillB.SetNameTab("BadPixTm");
698 fillD.SetNameTab("DeadPixTm");
699
700 /*
701 MFillH fillP("MHPulseShape", "", "FillPulseShape");
702 fillP.SetNameTab("Pulse");
703 */
704
705 /*
706 MHVsTime hbadpix("MBadPixelsCam.GetNumUnsuitable");
707 hbadpix.SetNumEvents(50);
708 MFillH fillB(&hbadpix, "MTime");
709 */
710
711 MTaskEnv fillflorian("FinalFantasy");
712 fillflorian.SetDefault();
713
714 // The second rule is for the case reading raw-files!
715 MWriteRootFile write(2, fname, fOverwrite?"RECREATE":"NEW");
716 // Run Header
717 write.AddContainer("MRawRunHeader", "RunHeaders");
718// write.AddContainer("MBadPixelsCam", "RunHeaders");
719 write.AddContainer("MGeomCam", "RunHeaders");
720 // Monte Carlo Headers
721 write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
722 write.AddContainer("MMcFadcHeader", "RunHeaders", kFALSE);
723 write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
724 write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
725 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
726 // Monte Carlo
727 write.AddContainer("MMcEvt", "Events", kFALSE);
728 write.AddContainer("MMcTrig", "Events", kFALSE);
729 // Data tree
730 write.AddContainer("MSignalCam", "Events");
731 // write.AddContainer("MPedPhotFundamental", "Events");
732 write.AddContainer("MPedPhotFromExtractor", "Events");
733 write.AddContainer("MPedPhotFromExtractorRndm", "Events");
734 write.AddContainer("MTime", "Events", kFALSE);
735 write.AddContainer("MRawEvtHeader", "Events");
736 write.AddContainer("MTriggerPattern", "Events");
737
738 // Trees with slow-control information (obsolete
739 // if we don't read merpped root-files)
740 write.AddTree("Trigger", kFALSE);
741 write.AddTree("Drive", kFALSE);
742 write.AddTree("CC", kFALSE);
743 write.AddTree("Pyrometer", kFALSE);
744 write.AddTree("Currents", kFALSE);
745 write.AddTree("Camera", kFALSE);
746 // Slow-Control: Current-tree
747 write.AddContainer("MCameraDC", "Currents", kFALSE);
748 // Slow-Control: Camera-tree
749 write.AddContainer("MCameraAUX", "Camera", kFALSE);
750 write.AddContainer("MCameraCalibration", "Camera", kFALSE);
751 write.AddContainer("MCameraCooling", "Camera", kFALSE);
752 write.AddContainer("MCameraHV", "Camera", kFALSE);
753 write.AddContainer("MCameraLV", "Camera", kFALSE);
754 write.AddContainer("MCameraLids", "Camera", kFALSE);
755
756 // Write the special MC tree
757 MWriteRootFile writemc(2, fname, fOverwrite?"RECREATE":"NEW");
758 writemc.SetName("WriteMC");
759 writemc.AddContainer("MMcEvtBasic", "OriginalMC");
760
761 // Write the special calib tree
762 /*
763 MWriteRootFile writecal(2, fname, fOverwrite?"RECREATE":"NEW");
764 writecal.SetName("WriteCalib");
765 writecal.AddContainer("MBadPixelsCam", "Calib");
766 writecal.AddContainer("MCalibrationChargeCam", "Calib");
767 writecal.AddContainer("MCalibrationRelTimeCam", "Calib");
768 */
769
770 //-----------------------------------------------------------
771 // Build tasklist
772
773 MTaskList tlist2("AllEvents");
774
775 tlist2.AddToList(&caldec);
776 tlist2.AddToList(&decode);
777 tlist2.AddToList(&fillpat);
778 tlist2.AddToList(&apply);
779 //tlist2.AddToList(&merge);
780 tlist2.AddToList(&pedsub);
781
782 //-----------------------------------------------------------
783 // Pedestal extraction
784
785 MTaskList tlist3("PedEvents");
786 tlist3.SetFilter(&fped); // Deny events with cal-trigger
787
788 tlist2.AddToList(&fped); // If no lo-gain require ped-trigger
789 tlist2.AddToList(&tlist3); // and deny cosmics (lvl1/2) trigger
790
791 tlist3.AddToList(&pedlo1); // extract pedestal events
792 tlist3.AddToList(&pedlo2); // extract pedestal events
793 tlist3.AddToList(&pedlo3); // extract pedestal events
794 tlist3.AddToList(&fill0); // fill pedestal events
795 tlist3.AddToList(&fill1); // fill pedestal events
796
797 //-----------------------------------------------------------
798 // Calibration
799
800 MTaskList tlist4("CalEvents");
801 tlist4.SetFilter(&fcalib); // process only events with cal-trigger
802
803 //MFDataPhrase filcalco("MCalibrationConstCam.IsReadyToSave>0.5", "CalibConstFilter");
804 if (fIsInterlaced)
805 {
806 // The task list is executed for all events with the calibration
807 // trigger
808 tlist2.AddToList(&fcalib); // MFTriggerPattern
809 tlist2.AddToList(&tlist4);
810
811 tlist4.AddToList(&taskenv3);
812 tlist4.AddToList(&contcoscal); // MContinue/ContCosmicsCal
813 if (IsUsePINDiode())
814 tlist4.AddToList(&pinext); // MExtractPINDiode
815 if (IsUseBlindPixel())
816 tlist4.AddToList(&bldext); // MExtractBlindPixel
817 tlist4.AddToList(&pacalc); // MCalibCalcFromPast
818 /*
819 tlist3.AddToList(&filcalco); // CalibConstFilter (IsReadyToSave)
820 fill8.SetFilter(&filcalco);
821 tlist3.AddToList(&fill8); // FillConvUpd
822 */
823
824 tlist4.AddToList(&filcam); // FillChargeCam
825 if (fIsRelTimesUpdate)
826 tlist4.AddToList(&filtme); // FillRelTime
827 if (IsUseBlindPixel())
828 tlist4.AddToList(&filbnd); // FillBlindCam
829 if (IsUsePINDiode())
830 tlist4.AddToList(&filpin); // FillPINDiode
831 tlist4.AddToList(&chcalc); // MCalibrationChargeCalc
832 if (fIsRelTimesUpdate)
833 tlist4.AddToList(&recalc); // MCalibrationRelTimeCam
834
835 tlist4.AddToList(&fillC); // FillCalPos
836
837 //tlist3.AddToList(&writecal); // MWriteRootFile
838 }
839
840 //-----------------------------------------------------------
841 // Cosmics extraction
842
843 // remove all events with a cal- or ped-trigger (no matter
844 // whether they have lvl1 or lvl2 or any other flag
845 tlist2.AddToList(&contcalped);
846
847 // Extract the signal
848 if (extractor1)
849 tlist2.AddToList(&taskenv1);
850
851 // remove all events which definitly don't have a signal
852 // using MFCosmics (ContCosmicsPed)
853 // tlist2.AddToList(&contcosped);
854
855 // Extract arrival time (if a dedicated extrator given)
856 if (extractor2)
857 tlist2.AddToList(&taskenv2);
858
859 // Check if we have an extremely bright event (remove them,
860 // they are presumably errornous events or calibration events)
861 tlist2.AddToList(&contbright);
862
863 /*
864 if (fIsHiLoCalibration)
865 {
866 plist.AddToList(&hilocam);
867 tlist2.AddToList(&filhil);
868 }
869
870 if (fIsPulsePosCheck)
871 {
872 plist.AddToList(&hpulcam);
873 tlist2.AddToList(&filpul);
874 }
875 */
876
877 tlist2.AddToList(&fill2);
878 tlist2.AddToList(&fill8); // FillConv
879 tlist2.AddToList(&calib); // MCalibrateData
880 if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
881 tlist2.AddToList(&caltm);
882
883 tlist2.AddToList(&bpcal); // MBadPixelsCalc
884 tlist2.AddToList(&treat); // MBadPixelsTreat
885 tlist2.AddToList(&fill6);
886 // tlist2.AddToList(&fill3);
887 tlist2.AddToList(&fill4);
888 tlist2.AddToList(&fill5);
889 //if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
890 // tlist2.AddToList(&fill7);
891 tlist2.AddToList(&fill9);
892 if (!fSequence.IsMonteCarlo())
893 {
894 tlist2.AddToList(&fillB);
895 tlist2.AddToList(&fillD);
896 }
897 if (extractor1->HasLoGain())
898 {
899 tlist2.AddToList(&fillR);
900 tlist2.AddToList(&fillO);
901 }
902
903 /*
904 MFillH fillC("MHCleaning", "", "FillClean");
905 tlist2.AddToList(&fillC);
906
907 //tlist2.AddToList(&fillP);
908 */
909
910 // ----- Start: Code for encoding movies -----
911
912 MMoviePrepare movprep;
913 MMovieWrite movwrite;
914 movprep.SetRangeFromExtractor(*extractor1);
915
916 //MFDataPhrase movfilt("MMovieData.fMax>150");
917 MFDataPhrase movfilt("MMovieData.fMax>5*MMovieData.fMedianPedestalRms", "MovieFilter");
918
919 MImgCleanStd movclean(8.5, 4.0);
920 movclean.SetMethod(MImgCleanStd::kAbsolute);
921
922 //movprep.SetFilter(&evtnum);
923 movclean.SetFilter(&movfilt);
924 movwrite.SetFilter(&movfilt);
925
926 MTaskList tlistmov("MovieEncoder");
927 tlistmov.AddToList(&movprep);
928 tlistmov.AddToList(&movfilt);
929 tlistmov.AddToList(&movclean);
930 tlistmov.AddToList(&movwrite);
931
932 MFEvtNumber evtnum;
933 //evtnum.SetSelector("ThetaSquared.fVal<0.04");
934 //evtnum.SetFileName("ganymed00000001.root");
935 tlistmov.SetFilter(&evtnum);
936
937 if (fIsMovieMode)
938 {
939 tlist2.AddToList(&evtnum);
940 tlist2.AddToList(&tlistmov);
941 }
942
943 // ----- End: Code for encoding movies -----
944
945 tlist2.AddToList(&fillflorian);
946
947 // Setup List for Drive-tree
948 //MPointingPosCalc pcalc;
949
950 // Now setup main tasklist
951 tlist.AddToList(read);
952
953 if (fSequence.IsMonteCarlo())
954 {
955 if (!fIsMovieMode && !HasNullOut())
956 tlist.AddToList(&writemc);
957 tlist.AddToList(&contmc);
958 }
959
960 //if (IsUseRootData())
961 // tlist2.AddToList(&pextr);
962 tlist.AddToList(&tlist2, fSequence.IsMonteCarlo() ? "Events" : "All");
963
964 //if (fSequence.IsMonteCarlo())
965 // tlist.AddToList(&pcalc, "Drive");
966
967 if (!fIsMovieMode && !HasNullOut())
968 tlist.AddToList(&write);
969
970 // Create and setup the eventloop
971 MEvtLoop evtloop(fName);
972 evtloop.SetParList(&plist);
973 evtloop.SetDisplay(fDisplay);
974 evtloop.SetLogStream(fLog);
975 if (!SetupEnv(evtloop))
976 return kFALSE;
977
978 // Execute first analysis
979 const Bool_t rc = evtloop.Eventloop(fMaxEvents);
980
981 // make sure owned object are deleted
982 if (extractor1 && extractor1!=fExtractor)
983 delete extractor1;
984 if (extractor2)
985 delete extractor2;
986 if (extractor3)
987 delete extractor3;
988
989 // return if job failed
990 if (!rc)
991 {
992 *fLog << err << GetDescriptor() << ": Failed." << endl;
993 return kFALSE;
994 }
995
996 // if everything went ok write and display result
997 DisplayResult(plist);
998
999 /*
1000 if (fIsPixelCheck)
1001 {
1002 if (fIsPulsePosCheck)
1003 hpulcam[fCheckedPixId].DrawClone("");
1004
1005 //if (fIsHiLoCalibration)
1006 // hilocam[fCheckedPixId].DrawClone("");
1007 }
1008 interlacedcont.Add(&pulcam);
1009 */
1010
1011 //if (fIsHiLoCalibration)
1012 // interlacedcont.Add(&hilcam);
1013
1014 //if (fIsPulsePosCheck)
1015 // interlacedcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
1016
1017 //if (fIsHiLoCalibration)
1018 // interlacedcont.Add(plist.FindObject("MHCalibrationHiLoCam"));
1019
1020 if (!WriteResult())
1021 return kFALSE;
1022
1023 // return if job went ok
1024 *fLog << all << GetDescriptor() << ": Done." << endl;
1025 *fLog << endl << endl;
1026
1027 return kTRUE;
1028}
1029
1030
1031void MJCalibrateSignal::DisplayResult(MParList &plist)
1032{
1033 /*
1034 if (!fDisplay || !fIsHiLoCalibration)
1035 return;
1036
1037 MCalibrationHiLoCam *hcam = (MCalibrationHiLoCam*)plist.FindObject("MCalibrationHiLoCam");
1038 MGeomCam *geom = (MGeomCam*)plist.FindObject("MGeomCam");
1039 if (!hcam || !geom)
1040 return;
1041
1042 // Create histograms to display
1043 MHCamera disp1(*geom, "HiLoConv", "Ratio Amplification HiGain vs. LoGain (Charges)");
1044 MHCamera disp2(*geom, "HiLoDiff", "Arrival Time Diff. HiGain vs. LoGain (Times)");
1045
1046 disp1.SetCamContent(*hcam, 0);
1047 disp1.SetCamError( *hcam, 1);
1048 disp2.SetCamContent(*hcam, 5);
1049 disp2.SetCamError( *hcam, 6);
1050
1051 disp1.SetYTitle("R [1]");
1052 disp2.SetYTitle("\\Delta T [FADC sl.]");
1053
1054 TCanvas &c1 = fDisplay->AddTab("HiLoConv");
1055 c1.Divide(2,3);
1056
1057 disp1.CamDraw(c1, 1, 2, 1);
1058 disp2.CamDraw(c1, 2, 2, 1);
1059*/
1060}
1061
Note: See TracBrowser for help on using the repository browser.