| 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 <mailto:jrico@ifae.es>
|
|---|
| 22 | ! Author(s): Markus Gaug 01/2004 <mailto:markus@ifae.es>
|
|---|
| 23 | ! Author(s): Florian Goebel 06/2004 <mailto:fgoebel@mppmu.mpg.de>
|
|---|
| 24 | !
|
|---|
| 25 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 26 | !
|
|---|
| 27 | !
|
|---|
| 28 | \* ======================================================================== */
|
|---|
| 29 |
|
|---|
| 30 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 31 | //
|
|---|
| 32 | // MPedCalcLoGain
|
|---|
| 33 | //
|
|---|
| 34 | //
|
|---|
| 35 | // This task is derived form MPedCalcPedRun, described below. However, It
|
|---|
| 36 | // calculates the pedstals using the low gain slices, whenever the difference
|
|---|
| 37 | // between the highest and the lowest slice in the high gain
|
|---|
| 38 | // slices is below a given threshold (SetMaxHiGainVar). In this case the receiver
|
|---|
| 39 | // boards do not switch to lo gain and the so called lo gain slices are actually
|
|---|
| 40 | // high gain slices.
|
|---|
| 41 | //
|
|---|
| 42 | // MPedCalcLoGain also fills the ABoffset in MPedestalPix which allows to correct
|
|---|
| 43 | // the 150 MHz clock noise.
|
|---|
| 44 | //
|
|---|
| 45 | // This task takes a pedestal run file and fills MPedestalCam during
|
|---|
| 46 | // the Process() with the pedestal and rms computed in an event basis.
|
|---|
| 47 | // In the PostProcess() MPedestalCam is finally filled with the pedestal
|
|---|
| 48 | // mean and rms computed in a run basis.
|
|---|
| 49 | // More than one run (file) can be merged
|
|---|
| 50 | //
|
|---|
| 51 | // MPedCalcPedRun applies the following formula (1):
|
|---|
| 52 | //
|
|---|
| 53 | // Pedestal per slice = sum(x_i) / n / slices
|
|---|
| 54 | // PedRMS per slice = Sqrt( ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices )
|
|---|
| 55 | //
|
|---|
| 56 | // where x_i is the sum of "slices" FADC slices and sum means the sum over all
|
|---|
| 57 | // events. "n" is the number of events, "slices" is the number of summed FADC samples.
|
|---|
| 58 | //
|
|---|
| 59 | // Note that the slice-to-slice fluctuations are not Gaussian, but Poissonian, thus
|
|---|
| 60 | // asymmetric and they are correlated.
|
|---|
| 61 | //
|
|---|
| 62 | // It is important to know that the Pedestal per slice and PedRMS per slice depend
|
|---|
| 63 | // on the number of used FADC slices, as seen in the following plots:
|
|---|
| 64 | //
|
|---|
| 65 | //Begin_Html
|
|---|
| 66 | /*
|
|---|
| 67 | <img src="images/PedestalStudyInner.gif">
|
|---|
| 68 | */
|
|---|
| 69 | //End_Html
|
|---|
| 70 | //
|
|---|
| 71 | //Begin_Html
|
|---|
| 72 | /*
|
|---|
| 73 | <img src="images/PedestalStudyOuter.gif">
|
|---|
| 74 | */
|
|---|
| 75 | //
|
|---|
| 76 | // The plots show the inner and outer pixels, respectivly and have the following meaning:
|
|---|
| 77 | //
|
|---|
| 78 | // 1) The calculated mean pedestal per slice (from MPedCalcFromLoGain)
|
|---|
| 79 | // 2) The fitted mean pedestal per slice (from MHPedestalCam)
|
|---|
| 80 | // 3) The calculated pedestal RMS per slice (from MPedCalcFromLoGain)
|
|---|
| 81 | // 4) The fitted sigma of the pedestal distribution per slice
|
|---|
| 82 | // (from MHPedestalCam)
|
|---|
| 83 | // 5) The relative difference between calculation and histogram fit
|
|---|
| 84 | // for the mean
|
|---|
| 85 | // 6) The relative difference between calculation and histogram fit
|
|---|
| 86 | // for the sigma or RMS, respectively.
|
|---|
| 87 | //
|
|---|
| 88 | // The calculated means do not change significantly except for the case of 2 slices,
|
|---|
| 89 | // however the RMS changes from 5.7 per slice in the case of 2 extracted slices
|
|---|
| 90 | // to 8.3 per slice in the case of 26 extracted slices. This change is very significant.
|
|---|
| 91 | //
|
|---|
| 92 | // The plots have been produced on run 20123. You can reproduce them using
|
|---|
| 93 | // the macro pedestalstudies.C
|
|---|
| 94 | //
|
|---|
| 95 | // Usage of this class:
|
|---|
| 96 | // ====================
|
|---|
| 97 | //
|
|---|
| 98 | // Call: SetRange(higainfirst, higainlast, logainfirst, logainlast)
|
|---|
| 99 | // to modify the ranges in which the window is allowed to move.
|
|---|
| 100 | // Defaults are:
|
|---|
| 101 | //
|
|---|
| 102 | // fHiGainFirst = fgHiGainFirst = 0
|
|---|
| 103 | // fHiGainLast = fgHiGainLast = 29
|
|---|
| 104 | // fLoGainFirst = fgLoGainFirst = 0
|
|---|
| 105 | // fLoGainLast = fgLoGainLast = 14
|
|---|
| 106 | //
|
|---|
| 107 | // Call: SetWindowSize(windowhigain, windowlogain)
|
|---|
| 108 | // to modify the sliding window widths. Windows have to be an even number.
|
|---|
| 109 | // In case of odd numbers, the window will be modified.
|
|---|
| 110 | //
|
|---|
| 111 | // Defaults are:
|
|---|
| 112 | //
|
|---|
| 113 | // fHiGainWindowSize = fgHiGainWindowSize = 14
|
|---|
| 114 | // fLoGainWindowSize = fgLoGainWindowSize = 0
|
|---|
| 115 | //
|
|---|
| 116 | // Variables:
|
|---|
| 117 | // fgHiGainFirst; First FADC slice Hi-Gain (currently set to: 3)
|
|---|
| 118 | // fgHiGainLast: Last FADC slice Hi-Gain (currently set to: 14)
|
|---|
| 119 | // fgLoGainFirst: First FADC slice Lo-Gain (currently set to: 3)
|
|---|
| 120 | // fgLoGainLast: Last FADC slice Lo-Gain (currently set to: 14)
|
|---|
| 121 | // fgHiGainWindowSize: The extraction window Hi-Gain
|
|---|
| 122 | // fgLoGainWindowSize: The extraction window Lo-Gain
|
|---|
| 123 | // fgMaxHiGainVar: The maximum difference between the highest and lowest slice
|
|---|
| 124 | // in the high gain window allowed in order to use low gain
|
|---|
| 125 | //
|
|---|
| 126 | // Input Containers:
|
|---|
| 127 | // MRawEvtData
|
|---|
| 128 | // MRawRunHeader
|
|---|
| 129 | // MGeomCam
|
|---|
| 130 | //
|
|---|
| 131 | // Output Containers:
|
|---|
| 132 | // MPedestalCam
|
|---|
| 133 | //
|
|---|
| 134 | // See also: MPedestalCam, MPedestalPix, MHPedestalCam, MExtractor
|
|---|
| 135 | //
|
|---|
| 136 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 137 | #include "MPedCalcFromLoGain.h"
|
|---|
| 138 | #include "MExtractor.h"
|
|---|
| 139 |
|
|---|
| 140 | #include "MParList.h"
|
|---|
| 141 |
|
|---|
| 142 | #include "MLog.h"
|
|---|
| 143 | #include "MLogManip.h"
|
|---|
| 144 |
|
|---|
| 145 | #include "MRawRunHeader.h"
|
|---|
| 146 | #include "MRawEvtPixelIter.h"
|
|---|
| 147 | #include "MRawEvtData.h"
|
|---|
| 148 |
|
|---|
| 149 | #include "MPedestalPix.h"
|
|---|
| 150 | #include "MPedestalCam.h"
|
|---|
| 151 |
|
|---|
| 152 | #include "MGeomPix.h"
|
|---|
| 153 | #include "MGeomCam.h"
|
|---|
| 154 |
|
|---|
| 155 | ClassImp(MPedCalcFromLoGain);
|
|---|
| 156 |
|
|---|
| 157 | using namespace std;
|
|---|
| 158 |
|
|---|
| 159 | const Byte_t MPedCalcFromLoGain::fgHiGainFirst = 0;
|
|---|
| 160 | const Byte_t MPedCalcFromLoGain::fgHiGainLast = 11;
|
|---|
| 161 | const Byte_t MPedCalcFromLoGain::fgLoGainFirst = 1;
|
|---|
| 162 | const Byte_t MPedCalcFromLoGain::fgLoGainLast = 14;
|
|---|
| 163 | const Byte_t MPedCalcFromLoGain::fgHiGainWindowSize = 12;
|
|---|
| 164 | const Byte_t MPedCalcFromLoGain::fgLoGainWindowSize = 14;
|
|---|
| 165 | const Byte_t MPedCalcFromLoGain::fgMaxHiGainVar = 40;
|
|---|
| 166 |
|
|---|
| 167 | // --------------------------------------------------------------------------
|
|---|
| 168 | //
|
|---|
| 169 | // Default constructor:
|
|---|
| 170 | //
|
|---|
| 171 | // Sets:
|
|---|
| 172 | // - all pointers to NULL
|
|---|
| 173 | // - fWindowSizeHiGain to fgHiGainWindowSize
|
|---|
| 174 | // - fWindowSizeLoGain to fgLoGainWindowSize
|
|---|
| 175 | //
|
|---|
| 176 | // Calls:
|
|---|
| 177 | // - AddToBranchList("fHiGainPixId");
|
|---|
| 178 | // - AddToBranchList("fHiGainFadcSamples");
|
|---|
| 179 | // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
|
|---|
| 180 | // - Clear()
|
|---|
| 181 | //
|
|---|
| 182 | MPedCalcFromLoGain::MPedCalcFromLoGain(const char *name, const char *title)
|
|---|
| 183 | : fWindowSizeHiGain(fgHiGainWindowSize),
|
|---|
| 184 | fWindowSizeLoGain(fgLoGainWindowSize),
|
|---|
| 185 | fGeom(NULL), fPedContainerName("MPedestalCam")
|
|---|
| 186 | {
|
|---|
| 187 | fName = name ? name : "MPedCalcFromLoGain";
|
|---|
| 188 | fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
|
|---|
| 189 |
|
|---|
| 190 | AddToBranchList("fHiGainPixId");
|
|---|
| 191 | AddToBranchList("fLoGainPixId");
|
|---|
| 192 | AddToBranchList("fHiGainFadcSamples");
|
|---|
| 193 | AddToBranchList("fLoGainFadcSamples");
|
|---|
| 194 |
|
|---|
| 195 | SetRange();
|
|---|
| 196 | SetMaxHiGainVar();
|
|---|
| 197 | SetPedestalUpdate(kTRUE);
|
|---|
| 198 | SetNumEventsDump(500);
|
|---|
| 199 |
|
|---|
| 200 | Clear();
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | // --------------------------------------------------------------------------
|
|---|
| 204 | //
|
|---|
| 205 | // Sets:
|
|---|
| 206 | // - fNumSamplesTot to 0
|
|---|
| 207 | // - fRawEvt to NULL
|
|---|
| 208 | // - fRunHeader to NULL
|
|---|
| 209 | // - fPedestals to NULL
|
|---|
| 210 | //
|
|---|
| 211 | void MPedCalcFromLoGain::Clear(const Option_t *o)
|
|---|
| 212 | {
|
|---|
| 213 | fRawEvt = NULL;
|
|---|
| 214 | fRunHeader = NULL;
|
|---|
| 215 | fPedestals = NULL;
|
|---|
| 216 |
|
|---|
| 217 | // If the size is yet set, set the size
|
|---|
| 218 | if (fSumx.GetSize()>0)
|
|---|
| 219 | {
|
|---|
| 220 | // Reset contents of arrays.
|
|---|
| 221 | fSumx.Reset();
|
|---|
| 222 | fSumx2.Reset();
|
|---|
| 223 | fSumAB0.Reset();
|
|---|
| 224 | fSumAB1.Reset();
|
|---|
| 225 | fNumEventsUsed.Reset();
|
|---|
| 226 | fTotalCounter.Reset();
|
|---|
| 227 | }
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | // --------------------------------------------------------------------------
|
|---|
| 231 | //
|
|---|
| 232 | // SetRange:
|
|---|
| 233 | //
|
|---|
| 234 | // Calls:
|
|---|
| 235 | // - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
|
|---|
| 236 | // - SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain);
|
|---|
| 237 | //
|
|---|
| 238 | void MPedCalcFromLoGain::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
|---|
| 239 | {
|
|---|
| 240 | MExtractor::SetRange(hifirst, hilast, lofirst, lolast);
|
|---|
| 241 |
|
|---|
| 242 | //
|
|---|
| 243 | // Redo the checks if the window is still inside the ranges
|
|---|
| 244 | //
|
|---|
| 245 | SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain);
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | // --------------------------------------------------------------------------
|
|---|
| 249 | //
|
|---|
| 250 | void MPedCalcFromLoGain::SetMaxHiGainVar(Byte_t maxvar)
|
|---|
| 251 | {
|
|---|
| 252 | fMaxHiGainVar = maxvar;
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | // --------------------------------------------------------------------------
|
|---|
| 256 | //
|
|---|
| 257 | // Checks:
|
|---|
| 258 | // - if a window is odd, subtract one
|
|---|
| 259 | // - if a window is bigger than the one defined by the ranges, set it to the available range
|
|---|
| 260 | // - if a window is smaller than 2, set it to 2
|
|---|
| 261 | //
|
|---|
| 262 | // Sets:
|
|---|
| 263 | // - fNumHiGainSamples to: (Float_t)fWindowSizeHiGain
|
|---|
| 264 | // - fNumLoGainSamples to: (Float_t)fWindowSizeLoGain
|
|---|
| 265 | // - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
|
|---|
| 266 | // - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)
|
|---|
| 267 | //
|
|---|
| 268 | void MPedCalcFromLoGain::SetWindowSize(Byte_t windowh, Byte_t windowl)
|
|---|
| 269 | {
|
|---|
| 270 | fWindowSizeHiGain = windowh & ~1;
|
|---|
| 271 | fWindowSizeLoGain = windowl & ~1;
|
|---|
| 272 |
|
|---|
| 273 | if (fWindowSizeHiGain != windowh)
|
|---|
| 274 | {
|
|---|
| 275 | *fLog << warn;
|
|---|
| 276 | *fLog << GetDescriptor() << ": HiGain window has to be even, set to: ";
|
|---|
| 277 | *fLog << int(fWindowSizeHiGain) << " samples " << endl;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | if (fWindowSizeLoGain != windowl)
|
|---|
| 281 | {
|
|---|
| 282 | *fLog << warn;
|
|---|
| 283 | *fLog << GetDescriptor() << ": Lo Gain window has to be even, set to: ";
|
|---|
| 284 | *fLog << int(fWindowSizeLoGain) << " samples " << endl;
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1;
|
|---|
| 288 | const Byte_t availlorange = (fLoGainLast-fLoGainFirst+1) & ~1;
|
|---|
| 289 |
|
|---|
| 290 | if (fWindowSizeHiGain > availhirange)
|
|---|
| 291 | {
|
|---|
| 292 | *fLog << warn;
|
|---|
| 293 | *fLog << GetDescriptor() << ": HiGain window " << (int)fWindowSizeHiGain;
|
|---|
| 294 | *fLog << " out of range [" << (int)fHiGainFirst;
|
|---|
| 295 | *fLog << "," << (int)fHiGainLast << "]" << endl;
|
|---|
| 296 | *fLog << "Will set window size to " << (int)availhirange << endl;
|
|---|
| 297 | fWindowSizeHiGain = availhirange;
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | if (fWindowSizeLoGain > availlorange)
|
|---|
| 301 | {
|
|---|
| 302 | *fLog << warn;
|
|---|
| 303 | *fLog << GetDescriptor() << ": LoGain window " << (int)fWindowSizeLoGain;
|
|---|
| 304 | *fLog << " out of range [" << (int)fLoGainFirst;
|
|---|
| 305 | *fLog << "," << (int)fLoGainLast << "]" << endl;
|
|---|
| 306 | *fLog << "Will set window size to " << (int)availlorange << endl;
|
|---|
| 307 | fWindowSizeLoGain = availlorange;
|
|---|
| 308 | }
|
|---|
| 309 | /*
|
|---|
| 310 | fNumHiGainSamples = (Float_t)fWindowSizeHiGain;
|
|---|
| 311 | fNumLoGainSamples = (Float_t)fWindowSizeLoGain;
|
|---|
| 312 |
|
|---|
| 313 | fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
|
|---|
| 314 | fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
|
|---|
| 315 | */
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | // --------------------------------------------------------------------------
|
|---|
| 319 | //
|
|---|
| 320 | // Look for the following input containers:
|
|---|
| 321 | //
|
|---|
| 322 | // - MRawEvtData
|
|---|
| 323 | // - MRawRunHeader
|
|---|
| 324 | // - MGeomCam
|
|---|
| 325 | //
|
|---|
| 326 | // The following output containers are also searched and created if
|
|---|
| 327 | // they were not found:
|
|---|
| 328 | //
|
|---|
| 329 | // - MPedestalCam
|
|---|
| 330 | //
|
|---|
| 331 | Int_t MPedCalcFromLoGain::PreProcess(MParList *pList)
|
|---|
| 332 | {
|
|---|
| 333 | Clear();
|
|---|
| 334 |
|
|---|
| 335 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
|---|
| 336 | if (!fRawEvt)
|
|---|
| 337 | {
|
|---|
| 338 | *fLog << err << "MRawEvtData not found... aborting." << endl;
|
|---|
| 339 | return kFALSE;
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
|
|---|
| 343 | if (!fRunHeader)
|
|---|
| 344 | {
|
|---|
| 345 | *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
|
|---|
| 346 | return kFALSE;
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
|
|---|
| 350 | if (!fGeom)
|
|---|
| 351 | {
|
|---|
| 352 | *fLog << err << "MGeomCam not found... aborting." << endl;
|
|---|
| 353 | return kFALSE;
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| 356 | fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fPedContainerName));
|
|---|
| 357 | if (!fPedestals)
|
|---|
| 358 | return kFALSE;
|
|---|
| 359 |
|
|---|
| 360 | if (fNumEventsDump<=0 && fPedestalUpdate)
|
|---|
| 361 | {
|
|---|
| 362 | *fLog << warn << "Pedestal Update switched on and Number of Events to dump <= 0... fNumEventsDump=1000" << endl;
|
|---|
| 363 | fNumEventsDump=1000;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | *fLog << inf << "Continous update switched " << (fPedestalUpdate?"on":"off");
|
|---|
| 367 | if (fPedestalUpdate)
|
|---|
| 368 | *fLog << " (dump each " << fNumEventsDump << " events)" << endl;
|
|---|
| 369 | *fLog << endl;
|
|---|
| 370 |
|
|---|
| 371 | return kTRUE;
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | // --------------------------------------------------------------------------
|
|---|
| 375 | //
|
|---|
| 376 | // The ReInit searches for:
|
|---|
| 377 | // - MRawRunHeader::GetNumSamplesHiGain()
|
|---|
| 378 | // - MRawRunHeader::GetNumSamplesLoGain()
|
|---|
| 379 | //
|
|---|
| 380 | // In case that the variables fHiGainLast and fLoGainLast are smaller than
|
|---|
| 381 | // the even part of the number of samples obtained from the run header, a
|
|---|
| 382 | // warning is given an the range is set back accordingly. A call to:
|
|---|
| 383 | // - SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast) or
|
|---|
| 384 | // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
|
|---|
| 385 | // is performed in that case. The variable diff means here the difference
|
|---|
| 386 | // between the requested range (fHiGainLast) and the available one. Note that
|
|---|
| 387 | // the functions SetRange() are mostly overloaded and perform more checks,
|
|---|
| 388 | // modifying the ranges again, if necessary.
|
|---|
| 389 | //
|
|---|
| 390 | Bool_t MPedCalcFromLoGain::ReInit(MParList *pList)
|
|---|
| 391 | {
|
|---|
| 392 | if (fRunHeader->GetNumSamplesHiGain()<1)
|
|---|
| 393 | {
|
|---|
| 394 | *fLog << err << "ERROR - Number of available HiGainSamples<1... abort." << endl;
|
|---|
| 395 | return kFALSE;
|
|---|
| 396 | }
|
|---|
| 397 | if (fRunHeader->GetNumSamplesLoGain()<1)
|
|---|
| 398 | {
|
|---|
| 399 | *fLog << err << "ERROR - Number of available LoGainSamples<1... abort." << endl;
|
|---|
| 400 | return kFALSE;
|
|---|
| 401 | }
|
|---|
| 402 |
|
|---|
| 403 | fHiGainFirst = TMath::Max(fHiGainFirst, 0);
|
|---|
| 404 | fHiGainLast = TMath::Min(fHiGainLast, fRunHeader->GetNumSamplesHiGain()-1);
|
|---|
| 405 |
|
|---|
| 406 | fLoGainFirst = TMath::Max(fLoGainFirst, 0);
|
|---|
| 407 | fLoGainLast = TMath::Min(fLoGainLast, fRunHeader->GetNumSamplesLoGain()-1);
|
|---|
| 408 |
|
|---|
| 409 | const Double_t wh = fWindowSizeHiGain;
|
|---|
| 410 | const Double_t wl = fWindowSizeLoGain;
|
|---|
| 411 | const Double_t fh = fHiGainFirst;
|
|---|
| 412 | const Double_t fl = fLoGainFirst;;
|
|---|
| 413 |
|
|---|
| 414 | fWindowSizeHiGain = TMath::Min(fWindowSizeHiGain, fHiGainLast-fHiGainFirst+1);
|
|---|
| 415 | fWindowSizeLoGain = TMath::Min(fWindowSizeLoGain, fLoGainLast-fLoGainFirst+1);
|
|---|
| 416 |
|
|---|
| 417 | SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast);
|
|---|
| 418 |
|
|---|
| 419 | if (wh!=fWindowSizeHiGain || fh!=fHiGainFirst || wl!=fWindowSizeLoGain || fl!=fLoGainFirst)
|
|---|
| 420 | {
|
|---|
| 421 | *fLog << inf << endl;
|
|---|
| 422 | *fLog << "Taking " << Form("%2d", (int)fWindowSizeHiGain) << " slices of Hi-Gain starting at slice " << (int)fHiGainFirst << endl;
|
|---|
| 423 | *fLog << "Taking " << Form("%2d", (int)fWindowSizeLoGain) << " slices of Lo-Gain starting at slice " << (int)fLoGainFirst << endl;
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | if (fWindowSizeHiGain==0)
|
|---|
| 427 | {
|
|---|
| 428 | *fLog << err << "ERROR - HiGain windows size == 0... abort." << endl;
|
|---|
| 429 | return kFALSE;
|
|---|
| 430 | }
|
|---|
| 431 | if (fWindowSizeLoGain==0)
|
|---|
| 432 | {
|
|---|
| 433 | *fLog << err << "ERROR - HiGain windows size == 0... abort." << endl;
|
|---|
| 434 | return kFALSE;
|
|---|
| 435 | }
|
|---|
| 436 |
|
|---|
| 437 | // If the size is not yet set, set the size
|
|---|
| 438 | if (fSumx.GetSize()==0)
|
|---|
| 439 | {
|
|---|
| 440 | const Int_t npixels = fPedestals->GetSize();
|
|---|
| 441 |
|
|---|
| 442 | fSumx. Set(npixels);
|
|---|
| 443 | fSumx2.Set(npixels);
|
|---|
| 444 | fSumAB0.Set(npixels);
|
|---|
| 445 | fSumAB1.Set(npixels);
|
|---|
| 446 | fNumEventsUsed.Set(npixels);
|
|---|
| 447 | fTotalCounter.Set(npixels);
|
|---|
| 448 |
|
|---|
| 449 | // Reset contents of arrays.
|
|---|
| 450 | fSumx.Reset();
|
|---|
| 451 | fSumx2.Reset();
|
|---|
| 452 | fSumAB0.Reset();
|
|---|
| 453 | fSumAB1.Reset();
|
|---|
| 454 | fNumEventsUsed.Reset();
|
|---|
| 455 | fTotalCounter.Reset();
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | return kTRUE;
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | void MPedCalcFromLoGain::Calc(ULong_t n, UInt_t idx)
|
|---|
| 462 | {
|
|---|
| 463 | const ULong_t nsamplestot = n*fWindowSizeLoGain;
|
|---|
| 464 |
|
|---|
| 465 | const Float_t sum = fSumx.At(idx);
|
|---|
| 466 | const Float_t sum2 = fSumx2.At(idx);
|
|---|
| 467 | const Float_t ped = sum/nsamplestot;
|
|---|
| 468 |
|
|---|
| 469 | // 1. Calculate the Variance of the sums:
|
|---|
| 470 | Float_t var = (sum2-sum*sum/n)/(n-1.);
|
|---|
| 471 |
|
|---|
| 472 | // 2. Scale the variance to the number of slices:
|
|---|
| 473 | var /= (Float_t)(fWindowSizeLoGain);
|
|---|
| 474 |
|
|---|
| 475 | // 3. Calculate the RMS from the Variance:
|
|---|
| 476 | const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
|
|---|
| 477 |
|
|---|
| 478 | // 4. Calculate the amplitude of the 150MHz "AB" noise
|
|---|
| 479 | const Float_t abOffs = (fSumAB0[idx] - fSumAB1[idx]) / nsamplestot;
|
|---|
| 480 |
|
|---|
| 481 | (*fPedestals)[idx].Set(ped, rms, abOffs, n);
|
|---|
| 482 |
|
|---|
| 483 | fTotalCounter[idx]++;
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | // --------------------------------------------------------------------------
|
|---|
| 487 | //
|
|---|
| 488 | // Fill the MPedestalCam container with the signal mean and rms for the event.
|
|---|
| 489 | // Store the measured signal in arrays fSumx and fSumx2 so that we can
|
|---|
| 490 | // calculate the overall mean and rms in the PostProcess()
|
|---|
| 491 | //
|
|---|
| 492 | Int_t MPedCalcFromLoGain::Process()
|
|---|
| 493 | {
|
|---|
| 494 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 495 |
|
|---|
| 496 | while (pixel.Next())
|
|---|
| 497 | {
|
|---|
| 498 | const UInt_t idx = pixel.GetPixelId();
|
|---|
| 499 |
|
|---|
| 500 | Byte_t *ptr = pixel.GetHiGainSamples() + fHiGainFirst;
|
|---|
| 501 | Byte_t *end = ptr + fWindowSizeHiGain;
|
|---|
| 502 |
|
|---|
| 503 | UInt_t sum = 0;
|
|---|
| 504 | UInt_t sqr = 0;
|
|---|
| 505 |
|
|---|
| 506 | UInt_t max = 0;
|
|---|
| 507 | UInt_t min = 255;
|
|---|
| 508 |
|
|---|
| 509 | // Find the maximum and minimum signal per slice in the high gain window
|
|---|
| 510 | do {
|
|---|
| 511 | if (*ptr > max)
|
|---|
| 512 | max = *ptr;
|
|---|
| 513 | if (*ptr < min)
|
|---|
| 514 | min = *ptr;
|
|---|
| 515 | } while (++ptr != end);
|
|---|
| 516 |
|
|---|
| 517 | // If the maximum in the high gain window is smaller than
|
|---|
| 518 | if (max-min>=fMaxHiGainVar || max>=255)
|
|---|
| 519 | continue;
|
|---|
| 520 |
|
|---|
| 521 | ptr = pixel.GetLoGainSamples() + fLoGainFirst;
|
|---|
| 522 | end = ptr + fWindowSizeLoGain;
|
|---|
| 523 |
|
|---|
| 524 | Byte_t *firstSlice = ptr;
|
|---|
| 525 |
|
|---|
| 526 | do {
|
|---|
| 527 | sum += *ptr;
|
|---|
| 528 | sqr += *ptr * *ptr;
|
|---|
| 529 | } while (++ptr != end);
|
|---|
| 530 |
|
|---|
| 531 | const Float_t msum = (Float_t)sum;
|
|---|
| 532 | const Float_t sqrsum = msum*msum;
|
|---|
| 533 |
|
|---|
| 534 | fSumx[idx] += msum;
|
|---|
| 535 | fSumx2[idx] += sqrsum;
|
|---|
| 536 | fNumEventsUsed[idx]++;
|
|---|
| 537 |
|
|---|
| 538 | // Calculate the amplitude of the 150MHz "AB" noise
|
|---|
| 539 |
|
|---|
| 540 | if (pixel.IsABFlagValid())
|
|---|
| 541 | {
|
|---|
| 542 | const Int_t abFlag = (fRunHeader->GetNumSamplesHiGain()
|
|---|
| 543 | + fLoGainFirst + pixel.HasABFlag()) & 0x1;
|
|---|
| 544 | for (Int_t islice=0; islice<fWindowSizeLoGain; islice+=2)
|
|---|
| 545 | {
|
|---|
| 546 | const Int_t sliceAB0 = islice + abFlag;
|
|---|
| 547 | const Int_t sliceAB1 = islice - abFlag + 1;
|
|---|
| 548 | fSumAB0[idx] += firstSlice[sliceAB0];
|
|---|
| 549 | fSumAB1[idx] += firstSlice[sliceAB1];
|
|---|
| 550 | }
|
|---|
| 551 | }
|
|---|
| 552 |
|
|---|
| 553 | if (!fPedestalUpdate || fNumEventsUsed[idx]<fNumEventsDump)
|
|---|
| 554 | continue;
|
|---|
| 555 |
|
|---|
| 556 | Calc(fNumEventsDump, idx);
|
|---|
| 557 |
|
|---|
| 558 | fNumEventsUsed[idx]=0;
|
|---|
| 559 | fSumx[idx]=0;
|
|---|
| 560 | fSumx2[idx]=0;
|
|---|
| 561 | fSumAB0[idx]=0;
|
|---|
| 562 | fSumAB1[idx]=0;
|
|---|
| 563 | }
|
|---|
| 564 |
|
|---|
| 565 | if (fPedestalUpdate)
|
|---|
| 566 | {
|
|---|
| 567 | //fPedestals->ReCalc(*fGeom);
|
|---|
| 568 | fPedestals->SetReadyToSave();
|
|---|
| 569 | }
|
|---|
| 570 |
|
|---|
| 571 | return kTRUE;
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | // --------------------------------------------------------------------------
|
|---|
| 575 | //
|
|---|
| 576 | // Compute signal mean and rms in the whole run and store it in MPedestalCam
|
|---|
| 577 | //
|
|---|
| 578 | Int_t MPedCalcFromLoGain::PostProcess()
|
|---|
| 579 | {
|
|---|
| 580 | // Compute pedestals and rms from the whole run
|
|---|
| 581 | if (fPedestalUpdate || GetNumExecutions()<1)
|
|---|
| 582 | return kTRUE;
|
|---|
| 583 |
|
|---|
| 584 | *fLog << flush << inf << "Calculating pedestals..." << flush;
|
|---|
| 585 |
|
|---|
| 586 | Double_t sum = 0;
|
|---|
| 587 |
|
|---|
| 588 | const Int_t npix = fGeom->GetNumPixels();
|
|---|
| 589 | for (Int_t idx=0; idx<npix; idx++)
|
|---|
| 590 | {
|
|---|
| 591 | const ULong_t n = fNumEventsUsed[idx];
|
|---|
| 592 | if (n>1)
|
|---|
| 593 | Calc(n, idx);
|
|---|
| 594 | sum += n;
|
|---|
| 595 | }
|
|---|
| 596 |
|
|---|
| 597 | *fLog << flush << inf << "Calculating means..." << flush;
|
|---|
| 598 |
|
|---|
| 599 | fPedestals->SetTotalEntries((UInt_t)(sum/npix*(fWindowSizeLoGain+fWindowSizeHiGain)));
|
|---|
| 600 | fPedestals->ReCalc(*fGeom);
|
|---|
| 601 | fPedestals->SetReadyToSave();
|
|---|
| 602 | return kTRUE;
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
|---|
| 606 | {
|
|---|
| 607 | if (MExtractor::ReadEnv(env, prefix, print)==kERROR)
|
|---|
| 608 | return kERROR;
|
|---|
| 609 |
|
|---|
| 610 | Bool_t rc=kFALSE;
|
|---|
| 611 |
|
|---|
| 612 | Byte_t hw = fWindowSizeHiGain;
|
|---|
| 613 | Byte_t lw = fWindowSizeLoGain;
|
|---|
| 614 | if (IsEnvDefined(env, prefix, "WindowSizeHiGain", print))
|
|---|
| 615 | {
|
|---|
| 616 | hw = GetEnvValue(env, prefix, "WindowSizeHiGain", hw);
|
|---|
| 617 | rc = kTRUE;
|
|---|
| 618 | }
|
|---|
| 619 | if (IsEnvDefined(env, prefix, "WindowSizeLoGain", print))
|
|---|
| 620 | {
|
|---|
| 621 | lw = GetEnvValue(env, prefix, "WindowSizeLoGain", lw);
|
|---|
| 622 | rc = kTRUE;
|
|---|
| 623 | }
|
|---|
| 624 |
|
|---|
| 625 | if (rc)
|
|---|
| 626 | SetWindowSize(hw, lw);
|
|---|
| 627 |
|
|---|
| 628 | if (IsEnvDefined(env, prefix, "NumEventsDump", print))
|
|---|
| 629 | {
|
|---|
| 630 | SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", fNumEventsDump));
|
|---|
| 631 | rc = kTRUE;
|
|---|
| 632 | }
|
|---|
| 633 |
|
|---|
| 634 | if (IsEnvDefined(env, prefix, "MaxHiGainVar", print))
|
|---|
| 635 | {
|
|---|
| 636 | SetMaxHiGainVar(GetEnvValue(env, prefix, "MaxHiGainVar", fMaxHiGainVar));
|
|---|
| 637 | rc = kTRUE;
|
|---|
| 638 | }
|
|---|
| 639 |
|
|---|
| 640 | if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
|
|---|
| 641 | {
|
|---|
| 642 | SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
|
|---|
| 643 | rc = kTRUE;
|
|---|
| 644 | }
|
|---|
| 645 |
|
|---|
| 646 | return rc;
|
|---|
| 647 | }
|
|---|