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

Last change on this file since 8897 was 8897, checked in by tbretz, 12 years ago
*** empty log message ***
File size: 33.2 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18!   Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20!   Copyright: MAGIC Software Development, 2000-2008
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27//  MJCalibrateSignal
28//
29// This class is reading the output written by callisto. It calibrates
30// signal and time.
31//
32// The signal and time extractors are read from the callisto-output. In
33// pricipal you could overwrite these default using the resource file,
34// but this is NOT recommended!
35//
36/////////////////////////////////////////////////////////////////////////////
37#include "MJCalibrateSignal.h"
38
39#include <TEnv.h>
40#include <TFile.h>
41
42// Core
43#include "MLog.h"
44#include "MLogManip.h"
45
46#include "MDirIter.h"
47#include "MTaskList.h"
48#include "MParList.h"
49#include "MEvtLoop.h"
50
51#include "MStatusDisplay.h"
52
53// General containers
54#include "MGeomCam.h"
55#include "MBadPixelsCam.h"
56#include "MCalibConstCam.h"
57#include "MPedestalCam.h"
58#include "MArrivalTimeCam.h"
59
60// General histograms
61#include "MH3.h"
62#include "MHCamEvent.h"
63#include "MHVsTime.h"
64
65// Calibration containers
66#include "MCalibrationQECam.h"
67#include "MCalibrationBlindCam.h"
68#include "MCalibrationChargeCam.h"
69#include "MCalibrationRelTimeCam.h"
70#include "MCalibrationChargePINDiode.h"
71
72// Calibration histograms
73#include "MHCalibrationChargeCam.h"
74#include "MHCalibrationChargeBlindCam.h"
75#include "MHCalibrationChargePINDiode.h"
76#include "MHCalibrationRelTimeCam.h"
77
78// Tasks
79#include "MReadMarsFile.h"
80#include "MRawFileRead.h"
81#include "MTaskEnv.h"
82#include "MContinue.h"
83#include "MFillH.h"
84#include "MGeomApply.h"
85#include "MExtractTimeAndCharge.h"
86#include "MTriggerPatternDecode.h"
87#include "MCalibrationPatternDecode.h"
88#include "MCalibrationChargeCalc.h"
89#include "MCalibrationRelTimeCalc.h"
90#include "MCalibCalcFromPast.h"
91#include "MPedestalSubtract.h"
92#include "MPedCalcFromLoGain.h"
93#include "MCalibrateData.h"
94#include "MExtractPINDiode.h"
95#include "MExtractBlindPixel.h"
96#include "MCalibrateRelTimes.h"
97#include "MBadPixelsCalc.h"
98#include "MBadPixelsTreat.h"
99#include "MWriteRootFile.h"
100
101// Filter
102#include "MFTriggerPattern.h"
103#include "MFCosmics.h"
104#include "MFilterList.h"
105#include "MFDataPhrase.h"
106
107// Classes for writing movies
108#include "MFEvtNumber.h"
109#include "MMoviePrepare.h"
110#include "MMovieWrite.h"
111#include "MImgCleanStd.h"
112
113
114ClassImp(MJCalibrateSignal);
115
116using namespace std;
117
118// --------------------------------------------------------------------------
119//
120// Default constructor.
121//
122// Sets:
123// - fIsInterlaced to kTRUE
124// - fIsRelTimesUpdate to kFALSE
125// - fIsHiLoCalibration to kFALSE
126//
127MJCalibrateSignal::MJCalibrateSignal(const char *name, const char *title)
128    : fExtractor(0), fIsInterlaced(kTRUE), fIsRelTimesUpdate(kTRUE), fIsMovieMode(kFALSE)
129{
130    fName  = name  ? name  : "MJCalibrateSignal";
131    fTitle = title ? title : "Tool to calibrate data";
132}
133
134MJCalibrateSignal::~MJCalibrateSignal()
135{
136    if (fExtractor)
137        delete fExtractor;
138}
139
140void MJCalibrateSignal::SetExtractor(const MExtractor *ext)
141{
142    if (fExtractor)
143        delete fExtractor;
144
145    fExtractor = ext ? (MExtractor*)ext->Clone() : NULL;
146}
147
148Bool_t MJCalibrateSignal::WriteResult() const
149{
150    if (IsNoStorage() || fIsMovieMode)
151        return kTRUE;
152
153    // FIXME: This is not nice because it will update the signal
154    // file always. Which might make the usage outside of
155    // callisto difficult.
156    TObjArray cont;
157    cont.Add(const_cast<TEnv*>(GetEnv()));
158    cont.Add(const_cast<MSequence*>(&fSequence));
159
160    if (fDisplay)
161        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    MFTriggerPattern fcalped;
435    fcalped.SetInverted();
436    fcalped.SetDefault(kTRUE);
437    //    ftp.RequireCalibration();
438    fcalped.DenyCalibration();
439    fcalped.DenyPedestal();
440    //    ftp.DenyPinDiode();
441
442    // This will skip interleaved events with a cal- or ped-trigger
443    MContinue contcalped(&fcalped, "ContTrigPattern");
444
445    // Create the pedestal subtracted raw-data
446    MPedestalSubtract pedsub;
447    pedsub.SetPedestalCam(&pedcamab);
448
449    // Do signal and pedestal calculation
450    MPedCalcFromLoGain     pedlo1("MPedCalcFundamental");
451    pedlo1.SetPedestalUpdate(kTRUE);
452    pedlo1.SetNamePedestalCamOut("MPedestalFundamental");
453
454    MPedCalcFromLoGain     pedlo2("MPedCalcWithExtractorRndm");
455    pedlo2.SetPedestalUpdate(kTRUE);
456    pedlo2.SetRandomCalculation(kTRUE);
457    pedlo2.SetNamePedestalCamOut("MPedestalFromExtractorRndm");
458
459    MPedCalcFromLoGain     pedlo3("MPedCalcWithExtractor");
460    pedlo3.SetPedestalUpdate(kTRUE);
461    pedlo3.SetRandomCalculation(kFALSE);
462    pedlo3.SetNamePedestalCamOut("MPedestalFromExtractor");
463
464    if (!extractor1)
465    {
466        *fLog << err << "ERROR - extractor1 == NULL" << endl;
467        return kFALSE;
468    }
469
470    // Setup to use the hi-gain extraction window in the lo-gain
471    // range (the start of the lo-gain range is added automatically
472    // by MPedCalcFromLoGain)
473    //
474    // The window size of the extractor is not yet initialized,
475    // so we have to stick to the extraction range
476    //
477    // Even if we would like to use a range comparable to the
478    // hi-gain extraction we use the lo-gain range to make
479    // sure that exclusions (eg. due to switching noise)
480    // are correctly handled.
481    //
482    pedlo1.SetRangeFromExtractor(*extractor1);
483
484    if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
485    {
486        pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
487        pedlo3.SetExtractor((MExtractTimeAndCharge*)extractor1);
488    }
489    else
490    {
491        pedlo2.SetRangeFromExtractor(*extractor1);
492        pedlo3.SetRangeFromExtractor(*extractor1);
493    }
494
495    //------------------------------
496    //
497    // this is the filter to find pedestal events. For the Siegen FADC
498    // these are all events which are not calibration events because
499    // the pedestal is extracted from the lo-gain signal. For MUX
500    // data this are artifiially triggered events with the pedestal
501    // trigger flag, and for safty without Lvl1 or Lvl2 flag)
502    //
503    // For the time "before" the trigger pattern all events (Siegen FADC)
504    // can be considered to be pedestal, because this was also the time
505    // without artifially calibration events
506    //
507    MFTriggerPattern fped;
508    fped.SetDefault(kTRUE);
509    fped.DenyCalibration();
510    if (!extractor1->HasLoGain())
511    {
512        fped.RequirePedestal();
513        fped.DenyTriggerLvl1();
514        fped.DenyTriggerLvl2();
515    }
516
517    //------------------------------
518    //
519    // Apply a filter against cosmics (this is to make sure that the
520    // trigger system was working properly and no empty events survive)
521    // For every event 5% of the pixel must not be empty. In PostProcess
522    // an error is raised if more than 50% of the events were skipped.
523    //
524    MFCosmics fcosmicscal;
525    fcosmicscal.SetNamePedestalCam("MPedestalFundamental"); //CORRECT?
526    fcosmicscal.SetMaxEmptyPixels(0.05);
527    fcosmicscal.SetMaxAcceptedFraction(0.5);
528
529    MContinue contcoscal(&fcosmicscal, "ContCosmicsCal");
530    contcoscal.SetInverted();
531
532    //------------------------------
533    /*
534     MFCosmics fcosmicsped; // Def=20% empty pixels
535     fcosmicsped.SetNamePedestalCam("MPedestalFundamental"); //CORRECT?
536     MContinue contcosped(&fcosmicsped, "ContCosmicsPed");
537     contcosped.SetInverted();
538    */
539
540    //------------------------------
541    //
542    // Thie signal extractors
543    //
544    MTaskEnv taskenv1("ExtractSignal");
545    MTaskEnv taskenv2("ExtractTime");
546    MTaskEnv taskenv3("ExtractInterlaced");
547    taskenv1.SetDefault(extractor1);
548    taskenv2.SetDefault(extractor2);
549    taskenv3.SetDefault(extractor3);
550
551    //
552    // This is new calibration to photo-electrons, hard-coded
553    // as decided at the Wuerzburg software meeting 26.01.05
554    //
555    MCalibrateData calib;
556    calib.SetSignalType(MCalibrateData::kPhe);
557    //calib.AddPedestal("Fundamental");
558    calib.AddPedestal("FromExtractor");
559    calib.AddPedestal("FromExtractorRndm");
560    calib.SetPedestalFlag(MCalibrateData::kEvent);
561
562    //----------------------------------------------------------
563
564    MExtractPINDiode        pinext;
565    MExtractBlindPixel      bldext;
566
567    MFTriggerPattern        fcalib("CalibFilter");
568    fcalib.SetDefault(kFALSE);
569    fcalib.RequireCalibration();
570    //fcalib.DenyPedestal(); // This should never happen!
571
572    MCalibrationChargeCalc  chcalc;
573    chcalc.SetContinousCalibration();
574    chcalc.SetExtractor(extractor3);
575
576    MCalibrationRelTimeCalc recalc;
577    MCalibCalcFromPast      pacalc;
578
579    chcalc.SetPedestals(&pedcamextr);
580
581    pacalc.SetChargeCalc(&chcalc);
582    if (fIsRelTimesUpdate)
583      pacalc.SetRelTimeCalc(&recalc);
584    pacalc.SetCalibrate(&calib);
585
586    //
587    // Calibration histogramming
588    //
589    MFillH filpin(&hpndiod, "MExtractedSignalPINDiode",   "FillPINDiode");
590    MFillH filbnd(&hbndcam, "MExtractedSignalBlindPixel", "FillBlindCam");
591    MFillH filcam(&hchacam, "MExtractedSignalCam",        "FillChargeCam");
592    MFillH filtme(&hrelcam, "MArrivalTimeCam",            "FillRelTime");
593    //MFillH filhil(&hilocam, "MExtractedSignalCam",        "FillHiLoRatio");
594    //MFillH filpul(&hpulcam, "MRawEvtData",                "FillPulseTime");
595    filpin.SetBit(MFillH::kDoNotDisplay);
596    filbnd.SetBit(MFillH::kDoNotDisplay);
597    filcam.SetBit(MFillH::kDoNotDisplay);
598    filtme.SetBit(MFillH::kDoNotDisplay);
599    //filhil.SetBit(MFillH::kDoNotDisplay);
600    //filpul.SetBit(MFillH::kDoNotDisplay);
601
602    MCalibrateRelTimes caltm;
603    MBadPixelsCalc     bpcal;
604    MBadPixelsTreat    treat;
605
606    //bpcal.SetNamePedPhotCam("MPedPhotFromExtractor");
607    bpcal.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
608
609    //treat.AddNamePedPhotCam("MPedPhotFundamental");
610    treat.AddNamePedPhotCam("MPedPhotFromExtractor");
611    treat.AddNamePedPhotCam("MPedPhotFromExtractorRndm");
612    if (!extractor2 && !extractor1->InheritsFrom("MExtractTimeAndCharge"))
613        treat.SetProcessTimes(kFALSE);
614
615    MHCamEvent evt0(  0, "PedFLG",     "Fundamental Pedestal from Lo Gain;;P [cnts/sl]");
616    MHCamEvent evt1(  2, "PedRmsFLG",  "RMS from Extractor applied to ped.;;\\sigma_{p} [cnts/sl]");
617    MHCamEvent evt2(  0, "Extra'd",    "Extracted Signal;;S [cnts/sl]");
618    // MHCamEvent evt3(4, "PedPhot",    "Calibrated Pedestal;;P [phe]");
619    MHCamEvent evt4(  5, "PedRMS",     "Calibrated RMS from Extractor applied to ped.;;\\sigma_{p} [phe]");
620    MHCamEvent evt5(  0, "Interp'd",   "Interpolated Signal scaled with A/A_{0};;S [phe]");
621    MHCamEvent evt6(102, "Unsuitable", "Fraction of unsuitable events per Pixel;;[1]");
622    // MHCamEvent evt7(  6, "Times",      "Calibrated Arrival Time;;T [fadc sl]");
623    MHCamEvent evt8(  0, "Conv",       "Calibration Conv. Factors;;[phe/cnts]");
624    MHCamEvent evt9(  7, "PulsePos",   "Pulse Position of cosmics (>50phe);;T [ns]");
625    MHCamEvent evtR(  4, "HiLoCal",    "Hi-/Lo-Gain ratio;;Ratio");
626    MHCamEvent evtO(  7, "HiLoOff",    "Lo-/Hi-Gain Offset;;Offset");
627    evt2.SetErrorSpread(kFALSE);
628    evt5.SetErrorSpread(kFALSE);
629    evt6.SetErrorSpread(kFALSE);
630    evt6.SetThreshold();
631
632    MFillH fill0(&evt0, "MPedestalFundamental",          "FillPedFLG");
633    MFillH fill1(&evt1, "MPedestalFromExtractorRndm",    "FillPedRmsFLG");
634    MFillH fill2(&evt2, "MExtractedSignalCam",           "FillExtracted");
635    // MFillH fill3(&evt3, "MPedPhotFundamental",  "FillPedPhot");
636    MFillH fill4(&evt4, "MPedPhotFromExtractorRndm",     "FillPedRMS");
637    MFillH fill5(&evt5, "MSignalCam",                    "FillInterpolated");
638    MFillH fill6(&evt6, "MBadPixelsCam",                 "FillUnsuitable");
639    // MFillH fill7(&evt7, "MSignalCam",                    "FillTimes");
640    MFillH fill8(&evt8, "MCalibConstCam",                "FillConv");
641    MFillH fill9(&evt9, "MSignalCam",                    "FillPulse");
642    MFillH fillR(&evtR, "MExtractedSignalCam",           "FillHiLoCal");
643    MFillH fillO(&evtO, "MArrivalTimeCam",               "FillHiLoOff");
644
645    MHVsTime histbp("MBadPixelsCam.GetNumUnsuitable");
646    histbp.SetName("BadPixTm");
647    histbp.SetTitle("Number of unsuitable pixels;;N");
648    histbp.SetMinimum(0);
649
650    MHVsTime histdp("MSignalCam.GetNumPixelsUnmapped");
651    histdp.SetName("DeadPixTm");
652    histdp.SetTitle("Number of dead/unmapped pixels;;N");
653    histdp.SetMinimum(0);
654
655    // Task to fill the histogram
656    MFillH fillB(&histbp, "MTime", "FillBadPixTm");
657    MFillH fillD(&histdp, "MTime", "FillDeadPixTm");
658    fillB.SetNameTab("BadPixTm");
659    fillD.SetNameTab("DeadPixTm");
660
661    /*
662     MFillH fillP("MHPulseShape", "", "FillPulseShape");
663     fillP.SetNameTab("Pulse");
664     */
665
666    /*
667     MHVsTime hbadpix("MBadPixelsCam.GetNumUnsuitable");
668     hbadpix.SetNumEvents(50);
669     MFillH fillB(&hbadpix, "MTime");
670     */
671
672    MTaskEnv fillflorian("FinalFantasy");
673    fillflorian.SetDefault();
674
675    // The second rule is for the case reading raw-files!
676    MWriteRootFile write(2, fname, fOverwrite?"RECREATE":"NEW");
677    // Run Header
678    write.AddContainer("MRawRunHeader",             "RunHeaders");
679//    write.AddContainer("MBadPixelsCam",             "RunHeaders");
680    write.AddContainer("MGeomCam",                  "RunHeaders");
681    // Monte Carlo Headers
682    write.AddContainer("MMcRunHeader",              "RunHeaders", kFALSE);
683    write.AddContainer("MMcFadcHeader",             "RunHeaders", kFALSE);
684    write.AddContainer("MMcTrigHeader",             "RunHeaders", kFALSE);
685    write.AddContainer("MMcConfigRunHeader",        "RunHeaders", kFALSE);
686    write.AddContainer("MMcCorsikaRunHeader",       "RunHeaders", kFALSE);
687    // Monte Carlo
688    write.AddContainer("MMcEvt",                    "Events",     kFALSE);
689    write.AddContainer("MMcTrig",                   "Events",     kFALSE);
690    // Data tree
691    write.AddContainer("MSignalCam",                "Events");
692    // write.AddContainer("MPedPhotFundamental",               "Events");
693    write.AddContainer("MPedPhotFromExtractor",     "Events");
694    write.AddContainer("MPedPhotFromExtractorRndm", "Events");
695    write.AddContainer("MTime",                     "Events",     kFALSE);
696    write.AddContainer("MRawEvtHeader",             "Events");
697
698    // Slow-Control: Current-tree
699    write.AddContainer("MTimeCurrents",             "Currents",   kFALSE);
700    write.AddContainer("MCameraDC",                 "Currents",   kFALSE);
701    write.AddContainer("MReportCurrents",           "Currents",   kFALSE);
702    // Slow-Control: Camera-tree
703    write.AddContainer("MReportCamera",             "Camera",     kFALSE);
704    write.AddContainer("MTimeCamera",               "Camera",     kFALSE);
705    write.AddContainer("MCameraAUX",                "Camera",     kFALSE);
706    write.AddContainer("MCameraCalibration",        "Camera",     kFALSE);
707    write.AddContainer("MCameraCooling",            "Camera",     kFALSE);
708    write.AddContainer("MCameraHV",                 "Camera",     kFALSE);
709    write.AddContainer("MCameraLV",                 "Camera",     kFALSE);
710    write.AddContainer("MCameraLids",               "Camera",     kFALSE);
711    // Slow-Control: Trigger-tree
712    write.AddContainer("MReportTrigger",            "Trigger",    kFALSE);
713    write.AddContainer("MTimeTrigger",              "Trigger",    kFALSE);
714    // Slow-Control: Drive-tree
715    write.AddContainer("MReportDrive",              "Drive",      kFALSE);
716    write.AddContainer("MTimeDrive",                "Drive",      kFALSE);
717    // Slow-Control: Central Control-tree
718    write.AddContainer("MReportCC",                 "CC",         kFALSE);
719    write.AddContainer("MTimeCC",                   "CC",         kFALSE);
720
721    // Write the special MC tree
722    MWriteRootFile writemc(2, fname, fOverwrite?"RECREATE":"NEW");
723    writemc.SetName("WriteMC");
724    writemc.AddContainer("MMcEvtBasic", "OriginalMC");
725
726    // Write the special calib tree
727    /*
728    MWriteRootFile writecal(2, fname, fOverwrite?"RECREATE":"NEW");
729    writecal.SetName("WriteCalib");
730    writecal.AddContainer("MBadPixelsCam",          "Calib");
731    writecal.AddContainer("MCalibrationChargeCam",  "Calib");
732    writecal.AddContainer("MCalibrationRelTimeCam", "Calib");
733    */
734
735    //-----------------------------------------------------------
736    // Build tasklist
737
738    MTaskList tlist2;
739
740    tlist2.AddToList(&caldec);
741    tlist2.AddToList(&decode);
742    tlist2.AddToList(&fillpat);
743    tlist2.AddToList(&apply);
744    //tlist2.AddToList(&merge);
745    tlist2.AddToList(&pedsub);
746
747    //-----------------------------------------------------------
748    // Pedestal extraction
749
750    MTaskList tlist3;
751    tlist3.SetFilter(&fped);         // Deny events with cal-trigger
752
753    tlist2.AddToList(&fped);         // If no lo-gain require ped-trigger
754    tlist2.AddToList(&tlist3);       //  and deny cosmics (lvl1/2) trigger
755
756    tlist3.AddToList(&pedlo1);       // extract pedestal events
757    tlist3.AddToList(&pedlo2);       // extract pedestal events
758    tlist3.AddToList(&pedlo3);       // extract pedestal events
759    tlist3.AddToList(&fill0);        // fill pedestal events
760    tlist3.AddToList(&fill1);        // fill pedestal events
761
762    //-----------------------------------------------------------
763    // Calibration
764
765    MTaskList tlist4;
766    tlist4.SetFilter(&fcalib);       // process only events with cal-trigger
767
768    //MFDataPhrase filcalco("MCalibrationConstCam.IsReadyToSave>0.5", "CalibConstFilter");
769    if (fIsInterlaced)
770    {
771        tlist2.AddToList(&fcalib);     // MFTriggerPattern
772        tlist2.AddToList(&tlist4);
773
774        tlist4.AddToList(&taskenv3);
775        tlist4.AddToList(&contcoscal); // MContinue/ContCosmicsCal
776        if (IsUsePINDiode())
777            tlist4.AddToList(&pinext); // MExtractPINDiode
778        if (IsUseBlindPixel())
779            tlist4.AddToList(&bldext); // MExtractBlindPixel
780        tlist4.AddToList(&pacalc);     // MCalibCalcFromPast
781        /*
782         tlist3.AddToList(&filcalco);   // CalibConstFilter (IsReadyToSave)
783         fill8.SetFilter(&filcalco);
784         tlist3.AddToList(&fill8);      // FillConvUpd
785         */
786
787        tlist4.AddToList(&filcam);     // FillChargeCam
788        if (fIsRelTimesUpdate)
789          tlist4.AddToList(&filtme);   // FillRelTime
790        if (IsUseBlindPixel())
791            tlist4.AddToList(&filbnd); // FillBlindCam
792        if (IsUsePINDiode())
793            tlist4.AddToList(&filpin); // FillPINDiode
794        tlist4.AddToList(&chcalc);     // MCalibrationChargeCalc
795        if (fIsRelTimesUpdate)
796            tlist4.AddToList(&recalc); // MCalibrationRelTimeCam
797
798        //tlist3.AddToList(&writecal);   // MWriteRootFile
799    }
800
801    //-----------------------------------------------------------
802    // Cosmics extraction
803
804    // remove all events with a cal- or ped-trigger (no matter
805    // whether they have lvl1 or lvl2 or any other flag
806    tlist2.AddToList(&contcalped);
807
808    // Extract the signal
809    if (extractor1)
810      tlist2.AddToList(&taskenv1);
811
812    // remove all events which definitly don't have a signal
813    // using MFCosmics (ContCosmicsPed)
814    // tlist2.AddToList(&contcosped);
815
816    // Extract arrival time (if a dedicated extrator given)
817    if (extractor2)
818        tlist2.AddToList(&taskenv2);
819
820    /*
821    if (fIsHiLoCalibration)
822    {
823        plist.AddToList(&hilocam);
824        tlist2.AddToList(&filhil);
825        }
826
827    if (fIsPulsePosCheck)
828    {
829        plist.AddToList(&hpulcam);
830        tlist2.AddToList(&filpul);
831    }
832    */
833
834    tlist2.AddToList(&fill2);
835    tlist2.AddToList(&fill8);        // FillConv
836    tlist2.AddToList(&calib);        // MCalibrateData
837    if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
838        tlist2.AddToList(&caltm);
839
840    tlist2.AddToList(&bpcal);        // MBadPixelsCalc
841    tlist2.AddToList(&treat);        // MBadPixelsTreat
842    tlist2.AddToList(&fill6);
843    //    tlist2.AddToList(&fill3);
844    tlist2.AddToList(&fill4);
845    tlist2.AddToList(&fill5);
846    //if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
847    //    tlist2.AddToList(&fill7);
848    tlist2.AddToList(&fill9);
849    if (!fSequence.IsMonteCarlo())
850    {
851        tlist2.AddToList(&fillB);
852        tlist2.AddToList(&fillD);
853    }
854    if (extractor1->HasLoGain())
855    {
856        tlist2.AddToList(&fillR);
857        tlist2.AddToList(&fillO);
858    }
859
860    /*
861     MFillH fillC("MHCleaning", "", "FillClean");
862     tlist2.AddToList(&fillC);
863
864     //tlist2.AddToList(&fillP);
865     */
866
867    // ----- Start: Code for encoding movies -----
868
869    MMoviePrepare movprep;
870    MMovieWrite   movwrite;
871    movprep.SetRangeFromExtractor(*extractor1);
872
873    //MFDataPhrase movfilt("MMovieData.fMax>150");
874    MFDataPhrase movfilt("MMovieData.fMax>5*MMovieData.fMedianPedestalRms", "MovieFilter");
875
876    MImgCleanStd movclean(8.5, 4.0);
877    movclean.SetMethod(MImgCleanStd::kAbsolute);
878
879    //movprep.SetFilter(&evtnum);
880    movclean.SetFilter(&movfilt);
881    movwrite.SetFilter(&movfilt);
882
883    MTaskList tlistmov("MovieEncoder");
884    tlistmov.AddToList(&movprep);
885    tlistmov.AddToList(&movfilt);
886    tlistmov.AddToList(&movclean);
887    tlistmov.AddToList(&movwrite);
888
889    MFEvtNumber evtnum;
890    //evtnum.SetSelector("ThetaSquared.fVal<0.04");
891    //evtnum.SetFileName("ganymed00000001.root");
892    tlistmov.SetFilter(&evtnum);
893
894    if (fIsMovieMode)
895    {
896        tlist2.AddToList(&evtnum);
897        tlist2.AddToList(&tlistmov);
898    }
899
900    // ----- End: Code for encoding movies -----
901
902    tlist2.AddToList(&fillflorian);
903
904    // Setup List for Drive-tree
905    //MPointingPosCalc pcalc;
906
907    // Now setup main tasklist
908    tlist.AddToList(read);
909
910    if (fSequence.IsMonteCarlo())
911    {
912        if (!fIsMovieMode)
913            tlist.AddToList(&writemc);
914        tlist.AddToList(&contmc);
915    }
916
917    //if (IsUseRootData())
918    //  tlist2.AddToList(&pextr);
919    tlist.AddToList(&tlist2, fSequence.IsMonteCarlo() ? "Events" : "All");
920
921    //if (fSequence.IsMonteCarlo())
922    //  tlist.AddToList(&pcalc, "Drive");
923
924    if (!fIsMovieMode)
925        tlist.AddToList(&write);
926
927    // Create and setup the eventloop
928    MEvtLoop evtloop(fName);
929    evtloop.SetParList(&plist);
930    evtloop.SetDisplay(fDisplay);
931    evtloop.SetLogStream(fLog);
932    if (!SetupEnv(evtloop))
933        return kFALSE;
934
935    // Execute first analysis
936    const Bool_t rc = evtloop.Eventloop(fMaxEvents);
937
938    // make sure owned object are deleted
939    if (extractor1 && extractor1!=fExtractor)
940        delete extractor1;
941    if (extractor2)
942        delete extractor2;
943    if (extractor3)
944        delete extractor3;
945
946    // return if job failed
947    if (!rc)
948    {
949        *fLog << err << GetDescriptor() << ": Failed." << endl;
950        return kFALSE;
951    }
952
953    // if everything went ok write and display result
954    DisplayResult(plist);
955
956    /*
957    if (fIsPixelCheck)
958      {
959        if (fIsPulsePosCheck)
960            hpulcam[fCheckedPixId].DrawClone("");
961
962        //if (fIsHiLoCalibration)
963        //    hilocam[fCheckedPixId].DrawClone("");
964      }
965    interlacedcont.Add(&pulcam);
966    */
967
968    //if (fIsHiLoCalibration)
969    //  interlacedcont.Add(&hilcam);
970
971    //if (fIsPulsePosCheck)
972    //    interlacedcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
973
974    //if (fIsHiLoCalibration)
975    //    interlacedcont.Add(plist.FindObject("MHCalibrationHiLoCam"));
976
977    if (!WriteResult())
978        return kFALSE;
979
980    // return if job went ok
981    *fLog << all << GetDescriptor() << ": Done." << endl;
982    *fLog << endl << endl;
983
984    return kTRUE;
985}
986
987
988void MJCalibrateSignal::DisplayResult(MParList &plist)
989{
990    /*
991    if (!fDisplay || !fIsHiLoCalibration)
992        return;
993
994    MCalibrationHiLoCam *hcam = (MCalibrationHiLoCam*)plist.FindObject("MCalibrationHiLoCam");
995    MGeomCam            *geom = (MGeomCam*)plist.FindObject("MGeomCam");
996    if (!hcam || !geom)
997        return;
998
999    // Create histograms to display
1000    MHCamera disp1(*geom, "HiLoConv", "Ratio Amplification HiGain vs. LoGain (Charges)");
1001    MHCamera disp2(*geom, "HiLoDiff", "Arrival Time Diff. HiGain vs. LoGain (Times)");
1002
1003    disp1.SetCamContent(*hcam, 0);
1004    disp1.SetCamError(  *hcam, 1);
1005    disp2.SetCamContent(*hcam, 5);
1006    disp2.SetCamError(  *hcam, 6);
1007
1008    disp1.SetYTitle("R [1]");
1009    disp2.SetYTitle("\\Delta T [FADC sl.]");
1010
1011    TCanvas &c1 = fDisplay->AddTab("HiLoConv");
1012    c1.Divide(2,3);
1013
1014    disp1.CamDraw(c1, 1, 2, 1);
1015    disp2.CamDraw(c1, 2, 2, 1);
1016*/
1017}
1018
Note: See TracBrowser for help on using the repository browser.