| 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): Abelardo Moralejo 7/2002 <mailto:moralejo@pd.infn.it>
|
|---|
| 19 | ! Author(s): Thomas Bretz 2002 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2002-2003
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | //
|
|---|
| 28 | // MPedestalSum
|
|---|
| 29 | //
|
|---|
| 30 | // This is a task which calculates the number of photons from the FADC
|
|---|
| 31 | // time slices. It weights the each slice according to the numbers in
|
|---|
| 32 | // the array fWeight (default: all slices added up with weight 1).
|
|---|
| 33 | //
|
|---|
| 34 | // The weights are rescaled, such that sum(weigths)=num slices
|
|---|
| 35 | //
|
|---|
| 36 | // Input Containers:
|
|---|
| 37 | // MRawRunHeader, MRawEvtData, MPedestalCam
|
|---|
| 38 | //
|
|---|
| 39 | // Output Containers:
|
|---|
| 40 | // MCerPhotEvt
|
|---|
| 41 | //
|
|---|
| 42 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 43 | #include "MPedestalSum.h"
|
|---|
| 44 |
|
|---|
| 45 | #include "MParList.h"
|
|---|
| 46 |
|
|---|
| 47 | #include "MLog.h"
|
|---|
| 48 | #include "MLogManip.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "MMcRunHeader.hxx"
|
|---|
| 51 |
|
|---|
| 52 | #include "MRawRunHeader.h"
|
|---|
| 53 | #include "MRawEvtData.h" // MRawEvtData::GetNumPixels
|
|---|
| 54 | #include "MCerPhotEvt.h"
|
|---|
| 55 | #include "MPedestalPix.h"
|
|---|
| 56 | #include "MPedestalCam.h"
|
|---|
| 57 | #include "MRawEvtPixelIter.h"
|
|---|
| 58 |
|
|---|
| 59 | ClassImp(MPedestalSum);
|
|---|
| 60 |
|
|---|
| 61 | using namespace std;
|
|---|
| 62 |
|
|---|
| 63 | // --------------------------------------------------------------------------
|
|---|
| 64 | //
|
|---|
| 65 | // Default constructor.
|
|---|
| 66 | //
|
|---|
| 67 | MPedestalSum::MPedestalSum(const char *name, const char *title)
|
|---|
| 68 | {
|
|---|
| 69 | fName = name ? name : "MPedestalSum";
|
|---|
| 70 | fTitle = title ? title : "Calculate pixel signal from FADC data";
|
|---|
| 71 |
|
|---|
| 72 | AddToBranchList("MRawEvtData.fHiGainPixId");
|
|---|
| 73 | AddToBranchList("MRawEvtData.fLoGainPixId");
|
|---|
| 74 | AddToBranchList("MRawEvtData.fHiGainFadcSamples");
|
|---|
| 75 | AddToBranchList("MRawEvtData.fLoGainFadcSamples");
|
|---|
| 76 |
|
|---|
| 77 | SetDefaultWeights();
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | // --------------------------------------------------------------------------
|
|---|
| 81 | //
|
|---|
| 82 | // The PreProcess searches for the following input containers:
|
|---|
| 83 | // - MRawRunHeader
|
|---|
| 84 | // - MRawEvtData
|
|---|
| 85 | // - MPedestalCam
|
|---|
| 86 | //
|
|---|
| 87 | // The following output containers are also searched and created if
|
|---|
| 88 | // they were not found:
|
|---|
| 89 | // - MCerPhotEvt
|
|---|
| 90 | //
|
|---|
| 91 | Int_t MPedestalSum::PreProcess(MParList *pList)
|
|---|
| 92 | {
|
|---|
| 93 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 94 | if (!fRunHeader)
|
|---|
| 95 | {
|
|---|
| 96 | *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
|
|---|
| 97 | return kFALSE;
|
|---|
| 98 | }
|
|---|
| 99 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
|---|
| 100 | if (!fRawEvt)
|
|---|
| 101 | {
|
|---|
| 102 | *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
|
|---|
| 103 | return kFALSE;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
|
|---|
| 107 | if (!fCerPhotEvt)
|
|---|
| 108 | {
|
|---|
| 109 | *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
|
|---|
| 110 | return kFALSE;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | return kTRUE;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | // --------------------------------------------------------------------------
|
|---|
| 117 | //
|
|---|
| 118 | // Check for the run type and camera version.
|
|---|
| 119 | // If the file is a MC file and the used camera version is <= 40
|
|---|
| 120 | // we enable a fix for truncated pedestal means in this version.
|
|---|
| 121 | //
|
|---|
| 122 | Bool_t MPedestalSum::ReInit(MParList *pList)
|
|---|
| 123 | {
|
|---|
| 124 | /*
|
|---|
| 125 | const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 126 | if (!runheader)
|
|---|
| 127 | {
|
|---|
| 128 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
|---|
| 129 | return kTRUE;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | if (fRunHeader->GetNumSamplesHiGain() != fWeight.GetSize())
|
|---|
| 133 | {
|
|---|
| 134 | *fLog << dbginf << "Number of FADC slices (" << fRunHeader->GetNumSamplesHiGain() <<") is different from assumed one (" << fWeight.GetSize() << ")... aborting." << endl;
|
|---|
| 135 | return kFALSE;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | Bool_t fIsMcFile = runheader->GetRunType() == kRTMonteCarlo;
|
|---|
| 139 | if (!fIsMcFile)
|
|---|
| 140 | return kTRUE;
|
|---|
| 141 |
|
|---|
| 142 | ScalePedestals();
|
|---|
| 143 |
|
|---|
| 144 | MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
|
|---|
| 145 | if (!mcrunheader)
|
|---|
| 146 | {
|
|---|
| 147 | *fLog << warn << dbginf << "Warning - cannot check for camera version, MC run header not found." << endl;
|
|---|
| 148 | return kTRUE;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | fEnableFix = kFALSE;
|
|---|
| 152 | if (mcrunheader->GetCamVersion() <= 40)
|
|---|
| 153 | fEnableFix = kTRUE;
|
|---|
| 154 | */
|
|---|
| 155 | return kTRUE;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | void MPedestalSum::ScalePedestals()
|
|---|
| 159 | {
|
|---|
| 160 | Int_t n = 577; //FIXME: fPedestals->GetNumPixel();
|
|---|
| 161 |
|
|---|
| 162 | for (int idx=0; idx<n; idx++)
|
|---|
| 163 | {
|
|---|
| 164 | MPedestalPix &ped = (*fPedestals)[idx];
|
|---|
| 165 |
|
|---|
| 166 | const Double_t offset = fEnableFix ? ped.GetPedestal()-0.5 : ped.GetPedestal();
|
|---|
| 167 | ped.Set(offset*fSumWeights, ped.GetPedestalRms()*sqrt(fSumQuadWeights));
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | fPedestals->SetReadyToSave();
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | // --------------------------------------------------------------------------
|
|---|
| 174 | //
|
|---|
| 175 | // Calculate the integral of the FADC time slices and store them as a new
|
|---|
| 176 | // pixel in the MCerPhotEvt container.
|
|---|
| 177 | //
|
|---|
| 178 | Int_t MPedestalSum::Process()
|
|---|
| 179 | {
|
|---|
| 180 | //fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
|
|---|
| 181 |
|
|---|
| 182 | // if (fIsMcFile)
|
|---|
| 183 | // ScalePedestals();
|
|---|
| 184 |
|
|---|
| 185 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 186 |
|
|---|
| 187 | while (pixel.Next())
|
|---|
| 188 | {
|
|---|
| 189 | const UInt_t idx = pixel.GetPixelId();
|
|---|
| 190 |
|
|---|
| 191 | const int n = fRunHeader->GetNumSamplesHiGain();
|
|---|
| 192 |
|
|---|
| 193 | //
|
|---|
| 194 | // Calculate pixel signal unless it has all FADC slices empty:
|
|---|
| 195 | //
|
|---|
| 196 | Byte_t *ptr = pixel.GetHiGainSamples();
|
|---|
| 197 |
|
|---|
| 198 | Float_t nphot = 0;
|
|---|
| 199 | Float_t nerr = 0;
|
|---|
| 200 | for(Int_t i=0; i<n; i++)
|
|---|
| 201 | {
|
|---|
| 202 | nphot += ptr[i];
|
|---|
| 203 | nerr += ptr[i]*ptr[i];
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | nphot /= n;
|
|---|
| 207 |
|
|---|
| 208 | fCerPhotEvt->AddPixel(idx, nphot, sqrt(nerr/n-nphot*nphot));
|
|---|
| 209 |
|
|---|
| 210 | // FIXME! Handling of Lo Gains is missing!
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | fCerPhotEvt->FixSize();
|
|---|
| 214 | fCerPhotEvt->SetReadyToSave();
|
|---|
| 215 |
|
|---|
| 216 | return kTRUE;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | // --------------------------------------------------------------------------
|
|---|
| 220 | //
|
|---|
| 221 | // Set default values for the number of slices and weights:
|
|---|
| 222 | //
|
|---|
| 223 | void MPedestalSum::SetDefaultWeights()
|
|---|
| 224 | {
|
|---|
| 225 | const Float_t dummy[15] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
|
|---|
| 226 | fWeight.Set(15, dummy);
|
|---|
| 227 | }
|
|---|