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

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