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

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