| 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): Josep Flix 04/2001 <mailto:jflix@ifae.es>
|
|---|
| 19 | ! Author(s): Thomas Bretz 05/2001 <mailto:tbretz@uni-sw.gwdg.de>
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | // //
|
|---|
| 28 | // MPedCalcPedRun //
|
|---|
| 29 | // //
|
|---|
| 30 | // Input Containers: //
|
|---|
| 31 | // MRawEvtData //
|
|---|
| 32 | // //
|
|---|
| 33 | // Output Containers: //
|
|---|
| 34 | // MPedestalCam //
|
|---|
| 35 | // //
|
|---|
| 36 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 37 |
|
|---|
| 38 | #include "MPedCalcPedRun.h"
|
|---|
| 39 |
|
|---|
| 40 | #include "MParList.h"
|
|---|
| 41 |
|
|---|
| 42 | #include "MLog.h"
|
|---|
| 43 | #include "MLogManip.h"
|
|---|
| 44 |
|
|---|
| 45 | #include "MRawRunHeader.h"
|
|---|
| 46 | #include "MRawEvtPixelIter.h"
|
|---|
| 47 | #include "MRawEvtData.h"
|
|---|
| 48 |
|
|---|
| 49 | #include "MPedestalPix.h"
|
|---|
| 50 | #include "MPedestalCam.h"
|
|---|
| 51 |
|
|---|
| 52 | ClassImp(MPedCalcPedRun);
|
|---|
| 53 |
|
|---|
| 54 | using namespace std;
|
|---|
| 55 |
|
|---|
| 56 | MPedCalcPedRun::MPedCalcPedRun(const char *name, const char *title)
|
|---|
| 57 | {
|
|---|
| 58 | fName = name ? name : "MPedCalcPedRun";
|
|---|
| 59 | fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
|
|---|
| 60 |
|
|---|
| 61 | AddToBranchList("fHiGainPixId");
|
|---|
| 62 | //AddToBranchList("fLoGainPixId");
|
|---|
| 63 | AddToBranchList("fHiGainFadcSamples");
|
|---|
| 64 | //AddToBranchList("fLoGainFadcSamples");
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | Int_t MPedCalcPedRun::PreProcess( MParList *pList )
|
|---|
| 68 | {
|
|---|
| 69 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
|---|
| 70 | if (!fRawEvt)
|
|---|
| 71 | {
|
|---|
| 72 | *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
|
|---|
| 73 | return kFALSE;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
|
|---|
| 77 | if (!fPedestals)
|
|---|
| 78 | return kFALSE;
|
|---|
| 79 |
|
|---|
| 80 | return kTRUE;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | Bool_t MPedCalcPedRun::ReInit(MParList *pList )
|
|---|
| 84 | {
|
|---|
| 85 |
|
|---|
| 86 | fRunheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 87 | if (!fRunheader)
|
|---|
| 88 | {
|
|---|
| 89 | *fLog << warn << dbginf <<
|
|---|
| 90 | "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
|---|
| 91 | }
|
|---|
| 92 | else
|
|---|
| 93 | if (fRunheader->GetRunType() == kRTMonteCarlo)
|
|---|
| 94 | {
|
|---|
| 95 | return kTRUE;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | fNumHiGainSamples = fRunheader->GetNumSamplesHiGain();
|
|---|
| 99 |
|
|---|
| 100 | return kTRUE;
|
|---|
| 101 |
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 | Int_t MPedCalcPedRun::Process()
|
|---|
| 106 | {
|
|---|
| 107 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 108 |
|
|---|
| 109 | while (pixel.Next())
|
|---|
| 110 | {
|
|---|
| 111 | Byte_t *ptr = pixel.GetHiGainSamples();
|
|---|
| 112 | const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples();
|
|---|
| 113 |
|
|---|
| 114 | const Float_t higainped = CalcHiGainMean(ptr, end);
|
|---|
| 115 | const Float_t higainrms = CalcHiGainRms(ptr, end, higainped);
|
|---|
| 116 |
|
|---|
| 117 | //const Float_t higainpederr = CalcHiGainMeanErr(higainrms);
|
|---|
| 118 | //const Float_t higainrmserr = CalcHiGainRmsErr(higainrms);
|
|---|
| 119 |
|
|---|
| 120 | const UInt_t pixid = pixel.GetPixelId();
|
|---|
| 121 | MPedestalPix &pix = (*fPedestals)[pixid];
|
|---|
| 122 |
|
|---|
| 123 | pix.Set(higainped, higainrms);
|
|---|
| 124 | //pix.SetPedestalRms(higainpederr, higainrmserr);
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | fPedestals->SetReadyToSave();
|
|---|
| 128 |
|
|---|
| 129 | return kTRUE;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | Float_t MPedCalcPedRun::CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const
|
|---|
| 133 | {
|
|---|
| 134 | Int_t sum=0;
|
|---|
| 135 |
|
|---|
| 136 | do sum += *ptr;
|
|---|
| 137 | while (++ptr != end);
|
|---|
| 138 |
|
|---|
| 139 | return (Float_t)sum/fNumHiGainSamples;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 | Float_t MPedCalcPedRun::CalcHiGainRms(Byte_t *ptr, const Byte_t *end, Float_t higainped) const
|
|---|
| 144 | {
|
|---|
| 145 | Float_t rms = 0;
|
|---|
| 146 |
|
|---|
| 147 | do
|
|---|
| 148 | {
|
|---|
| 149 | const Float_t diff = (Float_t)(*ptr)-higainped;
|
|---|
| 150 |
|
|---|
| 151 | rms += diff*diff;
|
|---|
| 152 | } while (++ptr != end);
|
|---|
| 153 |
|
|---|
| 154 | return sqrt(rms/fNumHiGainSamples);
|
|---|
| 155 | }
|
|---|
| 156 | /*
|
|---|
| 157 | Float_t MPedCalcPedRun::CalcHiGainMeanErr(Float_t higainrms) const
|
|---|
| 158 | {
|
|---|
| 159 | return higainrms/sqrt((float)fNumHiGainSamples);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | Float_t MPedCalcPedRun::CalcHiGainRmsErr(Float_t higainrms) const
|
|---|
| 163 | {
|
|---|
| 164 | return higainrms/sqrt(2.*fNumHiGainSamples);
|
|---|
| 165 | }
|
|---|
| 166 | */
|
|---|