| 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): Sebastian Raducci, 12/2003 <mailto:raducci@fisica.uniud.it>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2003
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MArrivalTime
|
|---|
| 28 | //
|
|---|
| 29 | // Times are calculated using the TSpline5 Root Class
|
|---|
| 30 | //
|
|---|
| 31 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 32 | #include "MArrivalTime.h"
|
|---|
| 33 |
|
|---|
| 34 | #include "MGeomCam.h"
|
|---|
| 35 | #include "MGeomPix.h"
|
|---|
| 36 |
|
|---|
| 37 | #include "MLog.h"
|
|---|
| 38 | #include "MLogManip.h"
|
|---|
| 39 |
|
|---|
| 40 | #include "MRawEvtPixelIter.h"
|
|---|
| 41 | #include "MRawEvtData.h"
|
|---|
| 42 |
|
|---|
| 43 | ClassImp(MArrivalTime);
|
|---|
| 44 |
|
|---|
| 45 | using namespace std;
|
|---|
| 46 |
|
|---|
| 47 | // --------------------------------------------------------------------------
|
|---|
| 48 | //
|
|---|
| 49 | // Creates an object containing the arrival time for each pixel in the event
|
|---|
| 50 | //
|
|---|
| 51 | MArrivalTime::MArrivalTime(const char *name, const char *title)
|
|---|
| 52 | {
|
|---|
| 53 | fName = name ? name : "MArrivalTime";
|
|---|
| 54 | fTitle = title ? title : "Photons arrival times Information";
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | //
|
|---|
| 58 | // Calculates the arrival time for each pixel
|
|---|
| 59 | // Possible Methods
|
|---|
| 60 | // Case 1: Spline5 (From TSpline5 Root Class)
|
|---|
| 61 | //
|
|---|
| 62 | //
|
|---|
| 63 |
|
|---|
| 64 | void MArrivalTime::Calc(const MRawEvtData &evt, const MGeomCam &geom)
|
|---|
| 65 | {
|
|---|
| 66 | const Int_t n = geom.GetNumPixels();
|
|---|
| 67 |
|
|---|
| 68 | fData.Set(n);
|
|---|
| 69 | fData.Reset();
|
|---|
| 70 |
|
|---|
| 71 | MRawEvtPixelIter pixel((MRawEvtData*)&evt);
|
|---|
| 72 |
|
|---|
| 73 | while ( pixel.Next() )
|
|---|
| 74 | {
|
|---|
| 75 | const UInt_t idx = pixel.GetPixelId();
|
|---|
| 76 |
|
|---|
| 77 | //If pixel has saturated and hasn't lo gains we return -1
|
|---|
| 78 |
|
|---|
| 79 | if (pixel.GetMaxHiGainSample() == 0xff)
|
|---|
| 80 | {
|
|---|
| 81 | if (!pixel.HasLoGain())
|
|---|
| 82 | {
|
|---|
| 83 | fData[idx]=-1.0;
|
|---|
| 84 | }
|
|---|
| 85 | else //Calculate time using Lo Gains
|
|---|
| 86 | {
|
|---|
| 87 | Byte_t *ptr = pixel.GetLoGainSamples();
|
|---|
| 88 |
|
|---|
| 89 | Int_t nSlice = evt.GetNumLoGainSamples();
|
|---|
| 90 | //Some casts are needed because TSpline5 constructor accepts only Double_t values
|
|---|
| 91 | Double_t ptr2[nSlice];
|
|---|
| 92 | for (Int_t i = 0; i < nSlice; i++)
|
|---|
| 93 | ptr2[i]=(Double_t)ptr[i];
|
|---|
| 94 | TSpline5 *spline = new TSpline5("spline",(Double_t) 0,(Double_t)(nSlice - 1),ptr2,nSlice);
|
|---|
| 95 | //Now find the maximum evaluating the spline function at every 1/10 time slice
|
|---|
| 96 | Double_t abscissa=0.0;
|
|---|
| 97 | Double_t maxAb=0.0;
|
|---|
| 98 | Double_t maxOrd=0.0;
|
|---|
| 99 | Double_t swap;
|
|---|
| 100 | while (abscissa <= nSlice - 1)
|
|---|
| 101 | {
|
|---|
| 102 | swap=spline->Eval(abscissa);
|
|---|
| 103 | if (swap > maxOrd)
|
|---|
| 104 | {
|
|---|
| 105 | maxOrd = swap;
|
|---|
| 106 | maxAb = abscissa;
|
|---|
| 107 | }
|
|---|
| 108 | abscissa += 0.1;
|
|---|
| 109 | }
|
|---|
| 110 | fData[idx]=maxAb;
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 | else //Calculate time using Hi Gains
|
|---|
| 114 | {
|
|---|
| 115 | Byte_t *ptr = pixel.GetHiGainSamples();
|
|---|
| 116 |
|
|---|
| 117 | Int_t nSlice = evt.GetNumHiGainSamples();
|
|---|
| 118 | //Some casts are needed because TSpline5 constructor accepts only Double_t values
|
|---|
| 119 | Double_t ptr2[nSlice];
|
|---|
| 120 | for (Int_t i = 0; i < nSlice; i++)
|
|---|
| 121 | ptr2[i]=(Double_t)ptr[i];
|
|---|
| 122 | TSpline5 *spline = new TSpline5("spline",(Double_t) 0,(Double_t)(nSlice - 1),ptr2,nSlice);
|
|---|
| 123 | //Now find the maximum evaluating the spline function at every 1/10 time slice
|
|---|
| 124 | Double_t abscissa=0.0;
|
|---|
| 125 | Double_t maxAb=0.0;
|
|---|
| 126 | Double_t maxOrd=0.0;
|
|---|
| 127 | Double_t swap;
|
|---|
| 128 | while (abscissa <= nSlice - 1)
|
|---|
| 129 | {
|
|---|
| 130 | swap=spline->Eval(abscissa);
|
|---|
| 131 | if (swap > maxOrd)
|
|---|
| 132 | {
|
|---|
| 133 | maxOrd = swap;
|
|---|
| 134 | maxAb = abscissa;
|
|---|
| 135 | }
|
|---|
| 136 | abscissa += 0.1;
|
|---|
| 137 | }
|
|---|
| 138 | fData[idx]=maxAb;
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | // -------------------------------------------------------------------------
|
|---|
| 144 | //
|
|---|
| 145 | // Finds the clusters with similar Arrival Time
|
|---|
| 146 | //
|
|---|
| 147 | // PRELIMINARY!! For now the Arrival Time is not the one calculated with
|
|---|
| 148 | // the splines, but it's the Max Slice Idx
|
|---|
| 149 | //
|
|---|
| 150 | // TEST!! This method is used only for test. Do not use it until
|
|---|
| 151 | // it becomes stable
|
|---|
| 152 | //
|
|---|
| 153 |
|
|---|
| 154 | void MArrivalTime::EvalClusters(const MRawEvtData &evt, const MGeomCam &geom)
|
|---|
| 155 | {
|
|---|
| 156 | const Int_t n = geom.GetNumPixels();
|
|---|
| 157 |
|
|---|
| 158 | fData2.Set(n);
|
|---|
| 159 | fData2.Reset(-1);
|
|---|
| 160 | fData3.Set(n);
|
|---|
| 161 | fData3.Reset(-1);
|
|---|
| 162 | fData4.Set(n);
|
|---|
| 163 | fData4.Reset(-1);
|
|---|
| 164 | fData5.Set(n);
|
|---|
| 165 | fData5.Reset(-1);
|
|---|
| 166 |
|
|---|
| 167 | MRawEvtPixelIter pixel((MRawEvtData*)&evt);
|
|---|
| 168 |
|
|---|
| 169 | // Array that says if a pixel has been already checked or not
|
|---|
| 170 |
|
|---|
| 171 | for (Int_t i = 0; i < n; i++)
|
|---|
| 172 | fPixelChecked[i] = kFALSE;
|
|---|
| 173 |
|
|---|
| 174 | // This fakeData array will be subsituted with the fData Array.
|
|---|
| 175 | fakeData.Set(n);
|
|---|
| 176 | fakeData.Reset();
|
|---|
| 177 |
|
|---|
| 178 | while ( pixel.Next() )
|
|---|
| 179 | {
|
|---|
| 180 | fakeData[pixel.GetPixelId()]=pixel.GetIdxMaxHiLoGainSample();
|
|---|
| 181 | }
|
|---|
| 182 | // End of fakeData preparation
|
|---|
| 183 |
|
|---|
| 184 | // Max dimension of cluster
|
|---|
| 185 | Short_t dimCluster;
|
|---|
| 186 |
|
|---|
| 187 | while ( pixel.Next() )
|
|---|
| 188 | {
|
|---|
| 189 | if (!fPixelChecked[pixel.GetPixelId()])
|
|---|
| 190 | {
|
|---|
| 191 | dimCluster = 0;
|
|---|
| 192 | fCluster.Set(n);
|
|---|
| 193 | fCluster.Reset(-1);
|
|---|
| 194 | fCluster[dimCluster]=pixel.GetPixelId();
|
|---|
| 195 | dimCluster++;
|
|---|
| 196 |
|
|---|
| 197 | CheckNeighbours(evt,geom,
|
|---|
| 198 | pixel.GetPixelId(), &dimCluster);
|
|---|
| 199 |
|
|---|
| 200 | if (dimCluster > 4)
|
|---|
| 201 | {
|
|---|
| 202 | for (Int_t i = 0; i < dimCluster; i++)
|
|---|
| 203 | fData5[fCluster[i]]=fakeData[fCluster[i]];
|
|---|
| 204 | }
|
|---|
| 205 | if (dimCluster > 3)
|
|---|
| 206 | {
|
|---|
| 207 | for (Int_t i = 0; i < dimCluster; i++)
|
|---|
| 208 | fData4[fCluster[i]]=fakeData[fCluster[i]];
|
|---|
| 209 | }
|
|---|
| 210 | if (dimCluster > 2)
|
|---|
| 211 | {
|
|---|
| 212 | for (Int_t i = 0; i < dimCluster; i++)
|
|---|
| 213 | fData3[fCluster[i]]=fakeData[fCluster[i]];
|
|---|
| 214 | }
|
|---|
| 215 | if (dimCluster > 1)
|
|---|
| 216 | {
|
|---|
| 217 | for (Int_t i = 0; i < dimCluster; i++)
|
|---|
| 218 | fData2[fCluster[i]]=fakeData[fCluster[i]];
|
|---|
| 219 | }
|
|---|
| 220 | }
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | // --------------------------------------------------------------------------
|
|---|
| 226 | //
|
|---|
| 227 | // Function to check the nearest neighbour pixels arrivaltime
|
|---|
| 228 | //
|
|---|
| 229 |
|
|---|
| 230 | void MArrivalTime::CheckNeighbours(const MRawEvtData &evt, const MGeomCam &geom,
|
|---|
| 231 | Short_t idx, Short_t *dimCluster)
|
|---|
| 232 | {
|
|---|
| 233 | Byte_t numNeighbors=geom[idx].GetNumNeighbors();
|
|---|
| 234 | fPixelChecked[idx] = kTRUE;
|
|---|
| 235 |
|
|---|
| 236 | for (Byte_t i=0x00; i < numNeighbors; i++)
|
|---|
| 237 | {
|
|---|
| 238 |
|
|---|
| 239 | if (!fPixelChecked[geom[idx].GetNeighbor(i)] &&
|
|---|
| 240 | fakeData[idx] == fakeData[geom[idx].GetNeighbor(i)])
|
|---|
| 241 | {
|
|---|
| 242 | fCluster[*dimCluster]=geom[idx].GetNeighbor(i);
|
|---|
| 243 | *dimCluster++;
|
|---|
| 244 | CheckNeighbours(evt, geom,
|
|---|
| 245 | geom[idx].GetNeighbor(i), dimCluster);
|
|---|
| 246 | }
|
|---|
| 247 | }
|
|---|
| 248 | }
|
|---|
| 249 | // --------------------------------------------------------------------------
|
|---|
| 250 | //
|
|---|
| 251 | // Returns the arrival time value
|
|---|
| 252 | //
|
|---|
| 253 |
|
|---|
| 254 | Bool_t MArrivalTime::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
|
|---|
| 255 | {
|
|---|
| 256 | if (idx<0 || idx>=fData.GetSize())
|
|---|
| 257 | return kFALSE;
|
|---|
| 258 |
|
|---|
| 259 | switch (type)
|
|---|
| 260 | {
|
|---|
| 261 | case 0:
|
|---|
| 262 | case 1:
|
|---|
| 263 | val = fData[idx];
|
|---|
| 264 | break;
|
|---|
| 265 | case 2:
|
|---|
| 266 | val = fData2[idx];
|
|---|
| 267 | break;
|
|---|
| 268 | case 3:
|
|---|
| 269 | val = fData3[idx];
|
|---|
| 270 | break;
|
|---|
| 271 | case 4:
|
|---|
| 272 | val = fData4[idx];
|
|---|
| 273 | break;
|
|---|
| 274 | case 5:
|
|---|
| 275 | val = fData5[idx];
|
|---|
| 276 | break;
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| 279 | return kTRUE;
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | void MArrivalTime::DrawPixelContent(Int_t num) const
|
|---|
| 283 | {
|
|---|
| 284 | *fLog << warn << "MArrivalTime::DrawPixelContent - not available." << endl;
|
|---|
| 285 | }
|
|---|