| 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 | // MCerPhotAnal2 //
|
|---|
| 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 "MCerPhotAnal2.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(MCerPhotAnal2);
|
|---|
| 55 |
|
|---|
| 56 | using namespace std;
|
|---|
| 57 |
|
|---|
| 58 | // --------------------------------------------------------------------------
|
|---|
| 59 | //
|
|---|
| 60 | // Default constructor. b is the number of slices before the maximum slice,
|
|---|
| 61 | // a the number of slices behind the maximum slice which is taken as signal.
|
|---|
| 62 | //
|
|---|
| 63 | MCerPhotAnal2::MCerPhotAnal2(Byte_t b, Byte_t a, const char *name, const char *title)
|
|---|
| 64 | : fBefore(b), fAfter(a)
|
|---|
| 65 | {
|
|---|
| 66 | fName = name ? name : "MCerPhotAnal2";
|
|---|
| 67 | fTitle = title ? title : "Task to calculate Cerenkov photons from raw data";
|
|---|
| 68 |
|
|---|
| 69 | AddToBranchList("MRawEvtData.fHiGainPixId");
|
|---|
| 70 | AddToBranchList("MRawEvtData.fLoGainPixId");
|
|---|
| 71 | AddToBranchList("MRawEvtData.fHiGainFadcSamples");
|
|---|
| 72 | AddToBranchList("MRawEvtData.fLoGainFadcSamples");
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | // --------------------------------------------------------------------------
|
|---|
| 76 | //
|
|---|
| 77 | // The PreProcess searches for the following input containers:
|
|---|
| 78 | // - MRawRunHeader
|
|---|
| 79 | // - MRawEvtData
|
|---|
| 80 | // - MPedestalCam
|
|---|
| 81 | //
|
|---|
| 82 | // The following output containers are also searched and created if
|
|---|
| 83 | // they were not found:
|
|---|
| 84 | // - MCerPhotEvt
|
|---|
| 85 | //
|
|---|
| 86 | Int_t MCerPhotAnal2::PreProcess(MParList *pList)
|
|---|
| 87 | {
|
|---|
| 88 | fSkip = 0;
|
|---|
| 89 |
|
|---|
| 90 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 91 | if (!fRunHeader)
|
|---|
| 92 | {
|
|---|
| 93 | *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
|
|---|
| 94 | return kFALSE;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
|---|
| 98 | if (!fRawEvt)
|
|---|
| 99 | {
|
|---|
| 100 | *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
|
|---|
| 101 | return kFALSE;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
|
|---|
| 105 | if (!fCerPhotEvt)
|
|---|
| 106 | return kFALSE;
|
|---|
| 107 |
|
|---|
| 108 | const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 109 | if (!runheader)
|
|---|
| 110 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
|---|
| 111 | else
|
|---|
| 112 | if (runheader->GetRunType() == kRTMonteCarlo)
|
|---|
| 113 | {
|
|---|
| 114 | fPedestals=NULL;
|
|---|
| 115 | return kTRUE;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
|
|---|
| 119 | if (runheader && !fPedestals)
|
|---|
| 120 | return kFALSE;
|
|---|
| 121 |
|
|---|
| 122 | return kTRUE;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | // --------------------------------------------------------------------------
|
|---|
| 126 | //
|
|---|
| 127 | // Calculate the integral of the FADC time slices and store them as a new
|
|---|
| 128 | // pixel in the MCerPhotEvt container.
|
|---|
| 129 | //
|
|---|
| 130 | Int_t MCerPhotAnal2::Process()
|
|---|
| 131 | {
|
|---|
| 132 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 133 |
|
|---|
| 134 | while (pixel.Next())
|
|---|
| 135 | {
|
|---|
| 136 | Byte_t max = pixel.GetNumMaxHiGainSample();
|
|---|
| 137 | Byte_t num = fRawEvt->GetNumHiGainSamples();
|
|---|
| 138 |
|
|---|
| 139 | Byte_t *ptr = pixel.GetHiGainSamples();
|
|---|
| 140 |
|
|---|
| 141 | ULong_t sumb = 0; // sum background
|
|---|
| 142 | ULong_t sqb = 0; // sum sqares background
|
|---|
| 143 | ULong_t sumsb = 0; // sum signal+background
|
|---|
| 144 | ULong_t sqsb = 0; // sum sqares signal+background
|
|---|
| 145 |
|
|---|
| 146 | Int_t sat = 0; // saturates?
|
|---|
| 147 | Int_t nb = 0;
|
|---|
| 148 | Int_t nsb = 0;
|
|---|
| 149 | for (int i=0; i<num; i++)
|
|---|
| 150 | {
|
|---|
| 151 | if (ptr[i]==255)
|
|---|
| 152 | sat++;
|
|---|
| 153 |
|
|---|
| 154 | //if (sat>1)
|
|---|
| 155 | // continue;
|
|---|
| 156 |
|
|---|
| 157 | if (i<max-fBefore || i>max+fAfter)
|
|---|
| 158 | {
|
|---|
| 159 | sumb += ptr[i];
|
|---|
| 160 | sqb += ptr[i]*ptr[i];
|
|---|
| 161 | nb++;
|
|---|
| 162 | }
|
|---|
| 163 | else
|
|---|
| 164 | {
|
|---|
| 165 | sumsb += ptr[i];
|
|---|
| 166 | sqsb += ptr[i]*ptr[i];
|
|---|
| 167 | nsb++;
|
|---|
| 168 | }
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | if (sat>1)
|
|---|
| 172 | {
|
|---|
| 173 | // Area: x9
|
|---|
| 174 | max = pixel.GetNumMaxLoGainSample();
|
|---|
| 175 | num = fRawEvt->GetNumLoGainSamples();
|
|---|
| 176 |
|
|---|
| 177 | ptr = pixel.GetLoGainSamples();
|
|---|
| 178 |
|
|---|
| 179 | sumsb = 0; // sum signal+background
|
|---|
| 180 | sqsb = 0; // sum sqares signal+background
|
|---|
| 181 | //sumb = 0; // sum background
|
|---|
| 182 | //sqb = 0; // sum sqares background
|
|---|
| 183 |
|
|---|
| 184 | //nb = 0;
|
|---|
| 185 | nsb = 0;
|
|---|
| 186 | for (int i=0; i<num; i++)
|
|---|
| 187 | {
|
|---|
| 188 | if (ptr[i]>250)
|
|---|
| 189 | {
|
|---|
| 190 | fSkip++;
|
|---|
| 191 | return kCONTINUE;
|
|---|
| 192 | }
|
|---|
| 193 | if (i<max-fBefore || i>max+fAfter)
|
|---|
| 194 | {
|
|---|
| 195 | /*
|
|---|
| 196 | sumb += ptr[i];
|
|---|
| 197 | sqb += ptr[i]*ptr[i];
|
|---|
| 198 | nb++;*/
|
|---|
| 199 | }
|
|---|
| 200 | else
|
|---|
| 201 | {
|
|---|
| 202 | sumsb += ptr[i];
|
|---|
| 203 | sqsb += ptr[i]*ptr[i];
|
|---|
| 204 | nsb++;
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | Float_t b = (float)sumb/nb; // background
|
|---|
| 210 | Float_t sb = (float)sumsb/nsb; // signal+background
|
|---|
| 211 |
|
|---|
| 212 | Float_t msb = (float)sqb/nb; // mean square background
|
|---|
| 213 | //Float_t mssb = (float)sqsb/nsb; // mean square signal+background
|
|---|
| 214 |
|
|---|
| 215 | Float_t sigb = sqrt(msb-b*b); // sigma background
|
|---|
| 216 | //Float_t sigsb = sqrt(mssb-sb*sb); // sigma signal+background
|
|---|
| 217 |
|
|---|
| 218 | Float_t s = sb-b; // signal
|
|---|
| 219 | Float_t sqs = sqsb-nsb*b; // sum sqaures signal
|
|---|
| 220 |
|
|---|
| 221 | Float_t mss = (float)sqs/nsb; // mean quare signal
|
|---|
| 222 | Float_t sigs = sqrt(mss-s*s); // sigma signal
|
|---|
| 223 |
|
|---|
| 224 | if (sat>1)
|
|---|
| 225 | s*=10; // tgb has measured 9, but Florian said it's 10.
|
|---|
| 226 |
|
|---|
| 227 | Int_t idx = pixel.GetPixelId();
|
|---|
| 228 | fCerPhotEvt->AddPixel(idx, s, sigs);
|
|---|
| 229 |
|
|---|
| 230 | // Preliminary: Do not overwrite pedestals calculated by
|
|---|
| 231 | // MMcPedestalCopy and MMcPedestalNSBAdd
|
|---|
| 232 | if (fPedestals)
|
|---|
| 233 | (*fPedestals)[idx].Set(b, sigb);
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | fCerPhotEvt->FixSize();
|
|---|
| 237 | fCerPhotEvt->SetReadyToSave();
|
|---|
| 238 |
|
|---|
| 239 | if (fPedestals)
|
|---|
| 240 | fPedestals->SetReadyToSave();
|
|---|
| 241 |
|
|---|
| 242 | return kTRUE;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | Int_t MCerPhotAnal2::PostProcess()
|
|---|
| 246 | {
|
|---|
| 247 | if (GetNumExecutions()==0 || fSkip==0)
|
|---|
| 248 | return kTRUE;
|
|---|
| 249 |
|
|---|
| 250 | *fLog << inf << endl;
|
|---|
| 251 | *fLog << GetDescriptor() << " execution statistics:" << endl;
|
|---|
| 252 | *fLog << dec << setfill(' ');
|
|---|
| 253 | *fLog << " " << setw(7) << fSkip << " (" << setw(3) << (int)(fSkip*100/GetNumExecutions()) << "%) Evts skipped due to: lo gain saturated." << endl;
|
|---|
| 254 |
|
|---|
| 255 | return kTRUE;
|
|---|
| 256 | }
|
|---|