| 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 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | // //
|
|---|
| 27 | // MCerPhotAnal //
|
|---|
| 28 | // //
|
|---|
| 29 | // This is a task which calculates the number of photons from the FADC //
|
|---|
| 30 | // time slices. At the moment it integrates simply the FADC values. //
|
|---|
| 31 | // //
|
|---|
| 32 | // Input Containers: //
|
|---|
| 33 | // MRawEvtData, MPedesdtalCam //
|
|---|
| 34 | // //
|
|---|
| 35 | // Output Containers: //
|
|---|
| 36 | // MCerPhotEvt //
|
|---|
| 37 | // //
|
|---|
| 38 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 39 |
|
|---|
| 40 | #include "MCerPhotAnal.h"
|
|---|
| 41 |
|
|---|
| 42 | #include "MParList.h"
|
|---|
| 43 |
|
|---|
| 44 | #include "MLog.h"
|
|---|
| 45 | #include "MLogManip.h"
|
|---|
| 46 |
|
|---|
| 47 | #include "MRawRunHeader.h"
|
|---|
| 48 | #include "MRawEvtData.h" // MRawEvtData::GetNumPixels
|
|---|
| 49 | #include "MCerPhotEvt.h"
|
|---|
| 50 | #include "MPedestalPix.h"
|
|---|
| 51 | #include "MPedestalCam.h"
|
|---|
| 52 | #include "MRawEvtPixelIter.h"
|
|---|
| 53 |
|
|---|
| 54 | ClassImp(MCerPhotAnal);
|
|---|
| 55 |
|
|---|
| 56 | using namespace std;
|
|---|
| 57 |
|
|---|
| 58 | // --------------------------------------------------------------------------
|
|---|
| 59 | //
|
|---|
| 60 | // Default constructor.
|
|---|
| 61 | //
|
|---|
| 62 | MCerPhotAnal::MCerPhotAnal(const char *name, const char *title)
|
|---|
| 63 | {
|
|---|
| 64 | fName = name ? name : "MCerPhotAnal";
|
|---|
| 65 | fTitle = title ? title : "Task to calculate Cerenkov photons from raw data";
|
|---|
| 66 |
|
|---|
| 67 | AddToBranchList("MRawEvtData.fHiGainPixId");
|
|---|
| 68 | AddToBranchList("MRawEvtData.fLoGainPixId");
|
|---|
| 69 | AddToBranchList("MRawEvtData.fHiGainFadcSamples");
|
|---|
| 70 | AddToBranchList("MRawEvtData.fLoGainFadcSamples");
|
|---|
| 71 |
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | // --------------------------------------------------------------------------
|
|---|
| 75 | //
|
|---|
| 76 | // The PreProcess searches for the following input containers:
|
|---|
| 77 | // - MRawRunHeader
|
|---|
| 78 | // - MRawEvtData
|
|---|
| 79 | // - MPedestalCam
|
|---|
| 80 | //
|
|---|
| 81 | // The following output containers are also searched and created if
|
|---|
| 82 | // they were not found:
|
|---|
| 83 | // - MCerPhotEvt
|
|---|
| 84 | //
|
|---|
| 85 | Bool_t MCerPhotAnal::PreProcess(MParList *pList)
|
|---|
| 86 | {
|
|---|
| 87 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 88 | if (!fRunHeader)
|
|---|
| 89 | {
|
|---|
| 90 | *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
|
|---|
| 91 | return kFALSE;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
|---|
| 95 | if (!fRawEvt)
|
|---|
| 96 | {
|
|---|
| 97 | *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
|
|---|
| 98 | return kFALSE;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
|
|---|
| 102 | if (!fPedestals)
|
|---|
| 103 | {
|
|---|
| 104 | *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
|
|---|
| 105 | return kFALSE;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
|
|---|
| 109 | if (!fCerPhotEvt)
|
|---|
| 110 | return kFALSE;
|
|---|
| 111 |
|
|---|
| 112 | return kTRUE;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | // --------------------------------------------------------------------------
|
|---|
| 116 | //
|
|---|
| 117 | // Calculate the integral of the FADC time slices and store them as a new
|
|---|
| 118 | // pixel in the MCerPhotEvt container.
|
|---|
| 119 | //
|
|---|
| 120 | Bool_t MCerPhotAnal::Process()
|
|---|
| 121 | {
|
|---|
| 122 | //fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
|
|---|
| 123 |
|
|---|
| 124 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 125 |
|
|---|
| 126 | while (pixel.Next())
|
|---|
| 127 | {
|
|---|
| 128 | Byte_t *ptr = pixel.GetHiGainSamples();
|
|---|
| 129 | const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples();
|
|---|
| 130 | const Byte_t *limit = end - 5;
|
|---|
| 131 |
|
|---|
| 132 | Int_t sum=0;
|
|---|
| 133 | Int_t sumpeak=0;
|
|---|
| 134 | Int_t sumlocal =0;
|
|---|
| 135 | Int_t slice=0;
|
|---|
| 136 | Int_t slicelocal=0;
|
|---|
| 137 |
|
|---|
| 138 | do
|
|---|
| 139 | {
|
|---|
| 140 | sumlocal = 0;
|
|---|
| 141 | for (Int_t i = 0; i<5;i++)
|
|---|
| 142 | sumlocal += *(ptr+i);
|
|---|
| 143 |
|
|---|
| 144 | if (sumpeak < sumlocal)
|
|---|
| 145 | {
|
|---|
| 146 | slice=slicelocal;
|
|---|
| 147 | sumpeak = sumlocal;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | slicelocal++;
|
|---|
| 151 | sum += *ptr;
|
|---|
| 152 | } while (++ptr != limit);
|
|---|
| 153 |
|
|---|
| 154 | do sum += *ptr;
|
|---|
| 155 | while (++ptr != end);
|
|---|
| 156 |
|
|---|
| 157 | Float_t pedes = (Float_t)(sum-sumpeak)/(fRawEvt->GetNumHiGainSamples()-5);
|
|---|
| 158 | Float_t nphot = (Float_t)sumpeak - 5.0*pedes;
|
|---|
| 159 |
|
|---|
| 160 | Float_t sigmaped=0;
|
|---|
| 161 |
|
|---|
| 162 | slicelocal=0;
|
|---|
| 163 | sumlocal = 0;
|
|---|
| 164 |
|
|---|
| 165 | ptr = pixel.GetHiGainSamples();
|
|---|
| 166 | do
|
|---|
| 167 | {
|
|---|
| 168 | if (slicelocal==slice)
|
|---|
| 169 | ptr += 4;
|
|---|
| 170 | else
|
|---|
| 171 | {
|
|---|
| 172 | sumlocal = *ptr;
|
|---|
| 173 |
|
|---|
| 174 | const Float_t d = (Float_t)sumlocal-pedes;
|
|---|
| 175 | sigmaped += d*d;
|
|---|
| 176 | }
|
|---|
| 177 | slicelocal++;
|
|---|
| 178 | }
|
|---|
| 179 | while (++ptr != end);
|
|---|
| 180 |
|
|---|
| 181 | sigmaped /= (fRawEvt->GetNumHiGainSamples()-5);
|
|---|
| 182 | sigmaped = sqrt((float)sumlocal);
|
|---|
| 183 |
|
|---|
| 184 | const UInt_t pixid = pixel.GetPixelId();
|
|---|
| 185 |
|
|---|
| 186 | MPedestalPix &ped = (*fPedestals)[pixid];
|
|---|
| 187 |
|
|---|
| 188 | //
|
|---|
| 189 | // sanity check (old MC files sometimes have pixids>577)
|
|---|
| 190 | //
|
|---|
| 191 | if (!fPedestals->CheckBounds(pixid))
|
|---|
| 192 | {
|
|---|
| 193 | *fLog << inf << "Pixel ID larger than camera... skipping event." << endl;
|
|---|
| 194 | return kCONTINUE;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | fCerPhotEvt->AddPixel(pixid, nphot, sigmaped/2.236);
|
|---|
| 198 | ped.SetPedestal(pedes, sigmaped);
|
|---|
| 199 | ped.SetPedestalRms(sigmaped/sqrt(fRawEvt->GetNumHiGainSamples()-5.),
|
|---|
| 200 | sigmaped/sqrt(2.*(fRawEvt->GetNumHiGainSamples()-5)));
|
|---|
| 201 |
|
|---|
| 202 | // FIXME! Handling of Lo Gains is missing!
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | fCerPhotEvt->FixSize();
|
|---|
| 206 | fCerPhotEvt->SetReadyToSave();
|
|---|
| 207 |
|
|---|
| 208 | return kTRUE;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|