| 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, 02/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | ! Hendrik Bartko, 01/2004 <mailto:hbartko@mppmu.mpg.de>
|
|---|
| 20 | ! Markus Gaug , 04/2004 <mailto:markus@ifae.es>
|
|---|
| 21 | !
|
|---|
| 22 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 23 | !
|
|---|
| 24 | !
|
|---|
| 25 | \* ======================================================================== */
|
|---|
| 26 |
|
|---|
| 27 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 28 | //
|
|---|
| 29 | // MExtractSlidingWindow
|
|---|
| 30 | //
|
|---|
| 31 | // Extracts the signal from a sliding window of size fHiGainWindowSize and
|
|---|
| 32 | // fLoGainWindowSize. The signal is the one which maximizes the integral
|
|---|
| 33 | // contents.
|
|---|
| 34 | //
|
|---|
| 35 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 36 | #include "MExtractSlidingWindow.h"
|
|---|
| 37 | #include "MExtractor.h"
|
|---|
| 38 |
|
|---|
| 39 | #include "MLog.h"
|
|---|
| 40 | #include "MLogManip.h"
|
|---|
| 41 |
|
|---|
| 42 | ClassImp(MExtractSlidingWindow);
|
|---|
| 43 |
|
|---|
| 44 | using namespace std;
|
|---|
| 45 |
|
|---|
| 46 | const Byte_t MExtractSlidingWindow::fgHiGainFirst = 3;
|
|---|
| 47 | const Byte_t MExtractSlidingWindow::fgHiGainLast = 14;
|
|---|
| 48 | const Byte_t MExtractSlidingWindow::fgLoGainFirst = 3;
|
|---|
| 49 | const Byte_t MExtractSlidingWindow::fgLoGainLast = 14;
|
|---|
| 50 | const Byte_t MExtractSlidingWindow::fgHiGainWindowSize = 6;
|
|---|
| 51 | const Byte_t MExtractSlidingWindow::fgLoGainWindowSize = 6;
|
|---|
| 52 | // --------------------------------------------------------------------------
|
|---|
| 53 | //
|
|---|
| 54 | // Default constructor.
|
|---|
| 55 | //
|
|---|
| 56 | MExtractSlidingWindow::MExtractSlidingWindow(const char *name, const char *title)
|
|---|
| 57 | {
|
|---|
| 58 |
|
|---|
| 59 | fName = name ? name : "MExtractSlidingWindow";
|
|---|
| 60 | fTitle = title ? title : "Signal Extractor for a sliding FADC window";
|
|---|
| 61 |
|
|---|
| 62 | SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
|
|---|
| 63 | SetWindowSize();
|
|---|
| 64 |
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | void MExtractSlidingWindow::SetWindowSize(Byte_t windowh, Byte_t windowl)
|
|---|
| 68 | {
|
|---|
| 69 |
|
|---|
| 70 | fWindowSizeHiGain = windowh & ~1;
|
|---|
| 71 | fWindowSizeLoGain = windowl & ~1;
|
|---|
| 72 |
|
|---|
| 73 | if (fWindowSizeHiGain != windowh)
|
|---|
| 74 | *fLog << warn << "MExtractSignal2::SetRange - Hi Gain window size has to be even, set to: "
|
|---|
| 75 | << int(fWindowSizeHiGain) << " samples " << endl;
|
|---|
| 76 |
|
|---|
| 77 | if (fWindowSizeLoGain != windowl)
|
|---|
| 78 | *fLog << warn << "MExtractSignal2::SetRange - Lo Gain window size has to be even, set to: "
|
|---|
| 79 | << int(fWindowSizeLoGain) << " samples " << endl;
|
|---|
| 80 |
|
|---|
| 81 | if (fWindowSizeHiGain<2)
|
|---|
| 82 | {
|
|---|
| 83 | fWindowSizeHiGain = 2;
|
|---|
| 84 | *fLog << warn << "MExtractSignal2::SetRange - Hi Gain window size set to two samples" << endl;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | if (fWindowSizeLoGain<2)
|
|---|
| 88 | {
|
|---|
| 89 | fWindowSizeLoGain = 2;
|
|---|
| 90 | *fLog << warn << "MExtractSignal2::SetRange - Lo Gain window size set to two samples" << endl;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | fNumHiGainSamples = (Float_t)fWindowSizeHiGain;
|
|---|
| 94 | fNumLoGainSamples = (Float_t)fWindowSizeLoGain;
|
|---|
| 95 |
|
|---|
| 96 | fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
|
|---|
| 97 | fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 | void MExtractSlidingWindow::FindSignalHiGain(Byte_t *ptr, Int_t size, Int_t &max, Byte_t &sat) const
|
|---|
| 103 | {
|
|---|
| 104 | const Byte_t *end = ptr + size;
|
|---|
| 105 |
|
|---|
| 106 | Int_t sum=0;
|
|---|
| 107 |
|
|---|
| 108 | //
|
|---|
| 109 | // Calculate the sum of the first fWindowSize slices
|
|---|
| 110 | //
|
|---|
| 111 | sat = 0;
|
|---|
| 112 | Byte_t *p = ptr;
|
|---|
| 113 | while (p<ptr+fWindowSizeHiGain)
|
|---|
| 114 | {
|
|---|
| 115 | sum += *p;
|
|---|
| 116 | if (*p++ >= fSaturationLimit)
|
|---|
| 117 | sat++;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | //
|
|---|
| 121 | // Check for saturation in all other slices
|
|---|
| 122 | //
|
|---|
| 123 | while (p<end)
|
|---|
| 124 | if (*p++ >= fSaturationLimit)
|
|---|
| 125 | sat++;
|
|---|
| 126 |
|
|---|
| 127 | //
|
|---|
| 128 | // Calculate the i-th sum as
|
|---|
| 129 | // sum_i+1 = sum_i + slice[i+8] - slice[i]
|
|---|
| 130 | // This is fast and accurate (because we are using int's)
|
|---|
| 131 | //
|
|---|
| 132 | max=sum;
|
|---|
| 133 | for (p=ptr; p+fWindowSizeHiGain<end; p++)
|
|---|
| 134 | {
|
|---|
| 135 | sum += *(p+fWindowSizeHiGain) - *p;
|
|---|
| 136 | if (sum>max)
|
|---|
| 137 | max = sum;
|
|---|
| 138 | }
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 | void MExtractSlidingWindow::FindSignalLoGain(Byte_t *ptr, Int_t size, Int_t &max, Byte_t &sat) const
|
|---|
| 143 | {
|
|---|
| 144 | const Byte_t *end = ptr + size;
|
|---|
| 145 |
|
|---|
| 146 | Int_t sum=0;
|
|---|
| 147 |
|
|---|
| 148 | //
|
|---|
| 149 | // Calculate the sum of the first fWindowSize slices
|
|---|
| 150 | //
|
|---|
| 151 | sat = 0;
|
|---|
| 152 | Byte_t *p = ptr;
|
|---|
| 153 | while (p<ptr+fWindowSizeLoGain)
|
|---|
| 154 | {
|
|---|
| 155 | sum += *p;
|
|---|
| 156 | if (*p++ >= fSaturationLimit)
|
|---|
| 157 | sat++;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | //
|
|---|
| 161 | // Check for saturation in all other slices
|
|---|
| 162 | //
|
|---|
| 163 | while (p<end)
|
|---|
| 164 | if (*p++ >= fSaturationLimit)
|
|---|
| 165 | sat++;
|
|---|
| 166 |
|
|---|
| 167 | //
|
|---|
| 168 | // Calculate the i-th sum as
|
|---|
| 169 | // sum_i+1 = sum_i + slice[i+8] - slice[i]
|
|---|
| 170 | // This is fast and accurate (because we are using int's)
|
|---|
| 171 | //
|
|---|
| 172 | max=sum;
|
|---|
| 173 | for (p=ptr; p+fWindowSizeLoGain<end; p++)
|
|---|
| 174 | {
|
|---|
| 175 | sum += *(p+fWindowSizeLoGain) - *p;
|
|---|
| 176 | if (sum>max)
|
|---|
| 177 | max = sum;
|
|---|
| 178 | }
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|