| 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@astro.uni-wuerzburg.de>
|
|---|
| 20 | ! Author(s): Sebastian Commichau 12/2003
|
|---|
| 21 | ! Author(s): Javier Rico 01/2004
|
|---|
| 22 | !
|
|---|
| 23 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 24 | !
|
|---|
| 25 | !
|
|---|
| 26 | \* ======================================================================== */
|
|---|
| 27 |
|
|---|
| 28 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 29 | //
|
|---|
| 30 | // MPedCalcPedRun
|
|---|
| 31 | //
|
|---|
| 32 | // This task takes a pedestal run file and fills MPedestalCam during
|
|---|
| 33 | // the Process() with the pedestal and rms computed in an event basis.
|
|---|
| 34 | // In the PostProcess() MPedestalCam is finally filled with the pedestal
|
|---|
| 35 | // mean and rms computed in a run basis.
|
|---|
| 36 | // More than one run (file) can be merged
|
|---|
| 37 | //
|
|---|
| 38 | // Input Containers:
|
|---|
| 39 | // MRawEvtData
|
|---|
| 40 | //
|
|---|
| 41 | // Output Containers:
|
|---|
| 42 | // MPedestalCam
|
|---|
| 43 | //
|
|---|
| 44 | //
|
|---|
| 45 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 46 | #include "MPedCalcPedRun.h"
|
|---|
| 47 |
|
|---|
| 48 | #include "MParList.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "MLog.h"
|
|---|
| 51 | #include "MLogManip.h"
|
|---|
| 52 |
|
|---|
| 53 | #include "MRawRunHeader.h"
|
|---|
| 54 | #include "MRawEvtPixelIter.h"
|
|---|
| 55 | #include "MRawEvtData.h"
|
|---|
| 56 |
|
|---|
| 57 | #include "MPedestalPix.h"
|
|---|
| 58 | #include "MPedestalCam.h"
|
|---|
| 59 |
|
|---|
| 60 | #include "MGeomCamMagic.h"
|
|---|
| 61 |
|
|---|
| 62 | ClassImp(MPedCalcPedRun);
|
|---|
| 63 |
|
|---|
| 64 | using namespace std;
|
|---|
| 65 |
|
|---|
| 66 | // --------------------------------------------------------------------------
|
|---|
| 67 | //
|
|---|
| 68 | // default constructor
|
|---|
| 69 | //
|
|---|
| 70 | MPedCalcPedRun::MPedCalcPedRun(const char *name, const char *title)
|
|---|
| 71 | {
|
|---|
| 72 | fName = name ? name : "MPedCalcPedRun";
|
|---|
| 73 | fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
|
|---|
| 74 |
|
|---|
| 75 | AddToBranchList("fHiGainPixId");
|
|---|
| 76 | AddToBranchList("fHiGainFadcSamples");
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | // --------------------------------------------------------------------------
|
|---|
| 80 | //
|
|---|
| 81 | // Look for the following input containers:
|
|---|
| 82 | //
|
|---|
| 83 | // - MRawEvtData
|
|---|
| 84 | //
|
|---|
| 85 | // The following output containers are also searched and created if
|
|---|
| 86 | // they were not found:
|
|---|
| 87 | //
|
|---|
| 88 | // - MPedestalCam
|
|---|
| 89 | //
|
|---|
| 90 | Int_t MPedCalcPedRun::PreProcess( MParList *pList )
|
|---|
| 91 | {
|
|---|
| 92 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
|---|
| 93 | if (!fRawEvt)
|
|---|
| 94 | {
|
|---|
| 95 | *fLog << err << "MRawEvtData not found... aborting." << endl;
|
|---|
| 96 | return kFALSE;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
|
|---|
| 100 | if (!fPedestals)
|
|---|
| 101 | return kFALSE;
|
|---|
| 102 |
|
|---|
| 103 | fNumSamplesTot=0;
|
|---|
| 104 |
|
|---|
| 105 | return kTRUE;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | // --------------------------------------------------------------------------
|
|---|
| 109 | //
|
|---|
| 110 | // The ReInit searches for the following input containers:
|
|---|
| 111 | // - MRawRunHeader
|
|---|
| 112 | //
|
|---|
| 113 | // It also initializes the data arrays fSumx and fSumx2
|
|---|
| 114 | // (only for the first read file)
|
|---|
| 115 | //
|
|---|
| 116 | Bool_t MPedCalcPedRun::ReInit(MParList *pList)
|
|---|
| 117 | {
|
|---|
| 118 | const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 119 | if (!runheader)
|
|---|
| 120 | {
|
|---|
| 121 | *fLog << warn << dbginf;
|
|---|
| 122 | *fLog << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
|---|
| 123 | }
|
|---|
| 124 | else
|
|---|
| 125 | if (runheader->GetRunType() == kRTMonteCarlo)
|
|---|
| 126 | return kTRUE;
|
|---|
| 127 |
|
|---|
| 128 | fNumPixels = fPedestals->GetSize();
|
|---|
| 129 |
|
|---|
| 130 | if(fSumx.GetSize()==0)
|
|---|
| 131 | {
|
|---|
| 132 | fSumx.Set(fNumPixels);
|
|---|
| 133 | fSumx2.Set(fNumPixels);
|
|---|
| 134 |
|
|---|
| 135 | fSumx.Reset();
|
|---|
| 136 | fSumx2.Reset();
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | // Calculate an even number for the hi gain samples to avoid
|
|---|
| 140 | // biases due to the fluctuation in pedestal from one slice to
|
|---|
| 141 | // the other one
|
|---|
| 142 | fNumHiGainSamples = runheader->GetNumSamplesHiGain() & ~1;
|
|---|
| 143 |
|
|---|
| 144 | return kTRUE;
|
|---|
| 145 | }
|
|---|
| 146 | // --------------------------------------------------------------------------
|
|---|
| 147 | //
|
|---|
| 148 | // Fill the MPedestalCam container with the signal mean and rms for the event.
|
|---|
| 149 | // Store the measured signal in arrays fSumx and fSumx2 so that we can
|
|---|
| 150 | // calculate the overall mean and rms in the PostProcess()
|
|---|
| 151 | //
|
|---|
| 152 | Int_t MPedCalcPedRun::Process()
|
|---|
| 153 | {
|
|---|
| 154 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 155 |
|
|---|
| 156 | while (pixel.Next())
|
|---|
| 157 | {
|
|---|
| 158 | Byte_t *ptr = pixel.GetHiGainSamples();
|
|---|
| 159 | const Byte_t *end = ptr + fNumHiGainSamples;
|
|---|
| 160 |
|
|---|
| 161 | UInt_t sum = 0;
|
|---|
| 162 | UInt_t sqr = 0;
|
|---|
| 163 |
|
|---|
| 164 | do
|
|---|
| 165 | {
|
|---|
| 166 | sum += *ptr;
|
|---|
| 167 | sqr += *ptr * *ptr;
|
|---|
| 168 | }
|
|---|
| 169 | while (++ptr != end);
|
|---|
| 170 |
|
|---|
| 171 | const Float_t msum = (Float_t)sum;
|
|---|
| 172 | const Float_t msqr = (Float_t)sqr;
|
|---|
| 173 |
|
|---|
| 174 | const Float_t higainped = msum/fNumHiGainSamples;
|
|---|
| 175 | const Float_t higainrms = TMath::Sqrt((msqr-msum*msum/fNumHiGainSamples)/(fNumHiGainSamples-1.));
|
|---|
| 176 |
|
|---|
| 177 | const UInt_t idx = pixel.GetPixelId();
|
|---|
| 178 | (*fPedestals)[idx].Set(higainped, higainrms);
|
|---|
| 179 |
|
|---|
| 180 | fSumx[idx] += msum;
|
|---|
| 181 | //
|
|---|
| 182 | // The old version:
|
|---|
| 183 | //
|
|---|
| 184 | // fSumx2[idx] += msqr;
|
|---|
| 185 | //
|
|---|
| 186 | // The new version:
|
|---|
| 187 | //
|
|---|
| 188 | fSumx2[idx] += msum*msum;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | fPedestals->SetReadyToSave();
|
|---|
| 192 | fNumSamplesTot += fNumHiGainSamples;
|
|---|
| 193 |
|
|---|
| 194 | return kTRUE;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | // --------------------------------------------------------------------------
|
|---|
| 198 | //
|
|---|
| 199 | // Compute signal mean and rms in the whole run and store it in MPedestalCam
|
|---|
| 200 | //
|
|---|
| 201 | Int_t MPedCalcPedRun::PostProcess()
|
|---|
| 202 | {
|
|---|
| 203 | // Compute pedestals and rms from the whole run
|
|---|
| 204 | const ULong_t n = fNumSamplesTot;
|
|---|
| 205 | const ULong_t nevts = GetNumExecutions();
|
|---|
| 206 |
|
|---|
| 207 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 208 |
|
|---|
| 209 | while (pixel.Next())
|
|---|
| 210 | {
|
|---|
| 211 | const UInt_t pixid = pixel.GetPixelId();
|
|---|
| 212 |
|
|---|
| 213 | const Float_t sum = fSumx.At(pixid);
|
|---|
| 214 | const Float_t sum2 = fSumx2.At(pixid);
|
|---|
| 215 |
|
|---|
| 216 | const Float_t higainped = sum/n;
|
|---|
| 217 | //
|
|---|
| 218 | // The old version:
|
|---|
| 219 | //
|
|---|
| 220 | // const Float_t higainrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.));
|
|---|
| 221 | //
|
|---|
| 222 | // The new version:
|
|---|
| 223 | //
|
|---|
| 224 | const Float_t higainrms = TMath::Sqrt((sum2-sum*sum/nevts)/(nevts-1.)/(Float_t)fNumHiGainSamples);
|
|---|
| 225 |
|
|---|
| 226 | (*fPedestals)[pixid].Set(higainped, higainrms);
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | return kTRUE;
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|