| 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, 02/2004 <mailto:hbartko@mppmu.mpg.de>
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | //
|
|---|
| 28 | // MArrivalTimeCalc2
|
|---|
| 29 | //
|
|---|
| 30 | // Calculates the arrival time as the mean time of the fWindowSize time slices
|
|---|
| 31 | // which have the highest integral content.
|
|---|
| 32 | //
|
|---|
| 33 | //
|
|---|
| 34 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 35 | #include "MArrivalTimeCalc2.h"
|
|---|
| 36 |
|
|---|
| 37 | #include "MLog.h"
|
|---|
| 38 | #include "MLogManip.h"
|
|---|
| 39 |
|
|---|
| 40 | #include "MParList.h"
|
|---|
| 41 |
|
|---|
| 42 | #include "MRawEvtData.h"
|
|---|
| 43 | #include "MRawEvtPixelIter.h"
|
|---|
| 44 |
|
|---|
| 45 | #include "MPedestalCam.h"
|
|---|
| 46 | #include "MPedestalPix.h"
|
|---|
| 47 |
|
|---|
| 48 | #include "MArrivalTimeCam.h"
|
|---|
| 49 | #include "MArrivalTimePix.h"
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | ClassImp(MArrivalTimeCalc2);
|
|---|
| 53 |
|
|---|
| 54 | using namespace std;
|
|---|
| 55 |
|
|---|
| 56 | const Byte_t MArrivalTimeCalc2::fgSaturationLimit = 254;
|
|---|
| 57 | const Byte_t MArrivalTimeCalc2::fgFirst = 0;
|
|---|
| 58 | const Byte_t MArrivalTimeCalc2::fgLast = 14;
|
|---|
| 59 | const Byte_t MArrivalTimeCalc2::fgWindowSize = 6;
|
|---|
| 60 |
|
|---|
| 61 | // --------------------------------------------------------------------------
|
|---|
| 62 | //
|
|---|
| 63 | // Default constructor.
|
|---|
| 64 | //
|
|---|
| 65 | MArrivalTimeCalc2::MArrivalTimeCalc2(const char *name, const char *title)
|
|---|
| 66 | : fSaturationLimit(fgSaturationLimit)
|
|---|
| 67 | {
|
|---|
| 68 |
|
|---|
| 69 | fName = name ? name : "MArrivalTimeCalc2";
|
|---|
| 70 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
|---|
| 71 |
|
|---|
| 72 | AddToBranchList("MRawEvtData.*");
|
|---|
| 73 |
|
|---|
| 74 | SetRange();
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | void MArrivalTimeCalc2::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast, Byte_t windowsize)
|
|---|
| 78 | {
|
|---|
| 79 |
|
|---|
| 80 | fNumHiGainSamples = hilast-hifirst+1;
|
|---|
| 81 | fNumLoGainSamples = lolast-lofirst+1;
|
|---|
| 82 |
|
|---|
| 83 | fHiGainFirst = hifirst;
|
|---|
| 84 | fLoGainFirst = lofirst;
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | fWindowSize = windowsize & ~1;
|
|---|
| 88 |
|
|---|
| 89 | if (fWindowSize != windowsize)
|
|---|
| 90 | *fLog << warn << "MArrivalTimeCalc2::SetRange - window size has to be even, set to: " << int(fWindowSize) << " samples " << endl;
|
|---|
| 91 |
|
|---|
| 92 | if (fWindowSize<2)
|
|---|
| 93 | {
|
|---|
| 94 | fWindowSize = 2;
|
|---|
| 95 | *fLog << warn << "MArrivalTimeCalc2::SetRange - window size set to two samples" << endl;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | if (fWindowSize > fNumHiGainSamples)
|
|---|
| 99 | {
|
|---|
| 100 | fWindowSize = fNumLoGainSamples & ~1;
|
|---|
| 101 | *fLog << warn << "MArrivalTimeCalc2::SetRange - window size set to " << int(fWindowSize) << " samples " << endl;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | if (fWindowSize > fNumLoGainSamples)
|
|---|
| 105 | {
|
|---|
| 106 | fWindowSize = fNumLoGainSamples & ~1;
|
|---|
| 107 | *fLog << warn << "MArrivalTimeCalc2::SetRange - window size set to " << int(fWindowSize) << " samples " << endl;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | fWindowSizeSqrt = TMath::Sqrt((Float_t)fWindowSize);
|
|---|
| 111 |
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 | // --------------------------------------------------------------------------
|
|---|
| 117 | //
|
|---|
| 118 | // The PreProcess searches for the following input containers:
|
|---|
| 119 | // - MRawEvtData
|
|---|
| 120 | // - MPedestalCam
|
|---|
| 121 | //
|
|---|
| 122 | // The following output containers are also searched and created if
|
|---|
| 123 | // they were not found:
|
|---|
| 124 | //
|
|---|
| 125 | // - MExtractedSignalCam
|
|---|
| 126 | //
|
|---|
| 127 | Int_t MArrivalTimeCalc2::PreProcess(MParList *pList)
|
|---|
| 128 | {
|
|---|
| 129 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
|---|
| 130 | if (!fRawEvt)
|
|---|
| 131 | {
|
|---|
| 132 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
|---|
| 133 | return kFALSE;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
|---|
| 140 | if (!fPedestals)
|
|---|
| 141 | {
|
|---|
| 142 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
|---|
| 143 | return kFALSE;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | fArrivalTime = (MArrivalTimeCam*)pList->FindCreateObj(AddSerialNumber("MArrivalTimeCam"));
|
|---|
| 147 | if (!fArrivalTime)
|
|---|
| 148 | return kFALSE;
|
|---|
| 149 |
|
|---|
| 150 | return kTRUE;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | void MArrivalTimeCalc2::FindSignalTime(Byte_t *ptr, Byte_t size, Float_t &time, Float_t &deltatime, Int_t &sat, Float_t pedes, Float_t pedrms) const
|
|---|
| 154 | {
|
|---|
| 155 | const Byte_t *end = ptr + size;
|
|---|
| 156 |
|
|---|
| 157 | Int_t sum=0; // integral content of the actual window
|
|---|
| 158 | Int_t max = 0; // highest integral content of all windows
|
|---|
| 159 |
|
|---|
| 160 | //
|
|---|
| 161 | // Calculate the sum of the first fWindowSize slices
|
|---|
| 162 | //
|
|---|
| 163 | sat = 0;
|
|---|
| 164 | Byte_t *p = ptr;
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 | while (p<ptr+fWindowSize)
|
|---|
| 168 | {
|
|---|
| 169 | sum += *p;
|
|---|
| 170 | if (*p++ >= fSaturationLimit)
|
|---|
| 171 | sat++;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | //
|
|---|
| 175 | // Check for saturation in all other slices
|
|---|
| 176 | //
|
|---|
| 177 | while (p<end)
|
|---|
| 178 | if (*p++ >= fSaturationLimit)
|
|---|
| 179 | sat++;
|
|---|
| 180 |
|
|---|
| 181 | //
|
|---|
| 182 | // Calculate the i-th sum as
|
|---|
| 183 | // sum_i+1 = sum_i + slice[i+8] - slice[i]
|
|---|
| 184 | // This is fast and accurate (because we are using int's)
|
|---|
| 185 | //
|
|---|
| 186 | max=sum;
|
|---|
| 187 | Byte_t *ptrmax=ptr; // pointer to the first slice of the maximum window
|
|---|
| 188 |
|
|---|
| 189 | for (p=ptr; p+fWindowSize<end; p++)
|
|---|
| 190 | {
|
|---|
| 191 | sum += *(p+fWindowSize) - *p;
|
|---|
| 192 |
|
|---|
| 193 | if (sum>max)
|
|---|
| 194 | {
|
|---|
| 195 | max = sum;
|
|---|
| 196 | ptrmax = p;
|
|---|
| 197 | }
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 | // now calculate the time for the maximum window
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 | Int_t timesignalsum = 0;
|
|---|
| 205 | Int_t timesquaredsum =0;
|
|---|
| 206 | Int_t timesum =0;
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 | for (p=ptrmax; p < ptrmax + fWindowSize; p++)
|
|---|
| 210 | {
|
|---|
| 211 | timesignalsum += *p*(p-ptr);
|
|---|
| 212 | timesum += p-ptr;
|
|---|
| 213 | timesquaredsum += (p-ptr)*(p-ptr);
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 | float pedsubsum = max - fWindowSize*pedes;
|
|---|
| 218 |
|
|---|
| 219 | float pedsubtimesignalsum = timesignalsum - timesum*pedes;
|
|---|
| 220 |
|
|---|
| 221 | time = pedsubsum != 0 ? pedsubtimesignalsum / pedsubsum : 1;
|
|---|
| 222 |
|
|---|
| 223 | deltatime = pedsubsum != 0 ? pedrms / pedsubsum * sqrt(timesquaredsum - fWindowSize*time) : 1;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | // --------------------------------------------------------------------------
|
|---|
| 227 | //
|
|---|
| 228 | // Calculates the arrival time as the mean time of the fWindowSize time slices
|
|---|
| 229 | // which have the highest integral content.
|
|---|
| 230 | //
|
|---|
| 231 | Int_t MArrivalTimeCalc2::Process()
|
|---|
| 232 | {
|
|---|
| 233 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 | Int_t sat=0;
|
|---|
| 237 | while (pixel.Next())
|
|---|
| 238 | {
|
|---|
| 239 | //
|
|---|
| 240 | // Find signal in hi- and lo-gain
|
|---|
| 241 | //
|
|---|
| 242 | Float_t timehi, timelo, deltatimehi, deltatimelo;
|
|---|
| 243 | Int_t sathi, satlo;
|
|---|
| 244 |
|
|---|
| 245 | //
|
|---|
| 246 | // Take correspodning pedestal
|
|---|
| 247 | //
|
|---|
| 248 | const Int_t pixid = pixel.GetPixelId();
|
|---|
| 249 |
|
|---|
| 250 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
|---|
| 251 |
|
|---|
| 252 | MArrivalTimePix &pix = (*fArrivalTime)[pixid];
|
|---|
| 253 |
|
|---|
| 254 | const Float_t pedes = ped.GetPedestal();
|
|---|
| 255 | const Float_t pedrms = ped.GetPedestalRms();
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 | FindSignalTime(pixel.GetHiGainSamples()+fHiGainFirst, fNumHiGainSamples, timehi, deltatimehi, sathi, pedes, pedrms);
|
|---|
| 259 | FindSignalTime(pixel.GetLoGainSamples()+fLoGainFirst, fNumLoGainSamples, timelo, deltatimelo, satlo, pedes, pedrms);
|
|---|
| 260 |
|
|---|
| 261 | if (satlo)
|
|---|
| 262 | sat++;
|
|---|
| 263 |
|
|---|
| 264 | pix.SetArrivalTime(timehi, deltatimehi,
|
|---|
| 265 | timelo, deltatimelo);
|
|---|
| 266 |
|
|---|
| 267 | pix.SetGainSaturation(sathi, sathi, satlo);
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 | } /* while (pixel.Next()) */
|
|---|
| 271 |
|
|---|
| 272 | fArrivalTime->SetReadyToSave();
|
|---|
| 273 |
|
|---|
| 274 | //
|
|---|
| 275 | // Print a warning if event has saturationg lo-gains
|
|---|
| 276 | //
|
|---|
| 277 | if (sat)
|
|---|
| 278 | *fLog << warn << "WARNING - Lo Gain saturated in " << sat << " pixels." << endl;
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 | return kTRUE;
|
|---|
| 282 | }
|
|---|