| 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, 12/2003 <mailto:moralejo@pd.infn.it>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2003
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MMcCalibrationCalc
|
|---|
| 28 | //
|
|---|
| 29 | // Input Containers:
|
|---|
| 30 | // MRawRunHeader
|
|---|
| 31 | // MMcFadcHeader
|
|---|
| 32 | // MHillas
|
|---|
| 33 | // MNewImagePar
|
|---|
| 34 | // MMcEvt
|
|---|
| 35 | //
|
|---|
| 36 | // Output Containers:
|
|---|
| 37 | // MCalibrationCam
|
|---|
| 38 | //
|
|---|
| 39 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 40 | #include "MMcCalibrationCalc.h"
|
|---|
| 41 |
|
|---|
| 42 | #include <TH1.h>
|
|---|
| 43 |
|
|---|
| 44 | #include "MLog.h"
|
|---|
| 45 | #include "MLogManip.h"
|
|---|
| 46 |
|
|---|
| 47 | #include "MParList.h"
|
|---|
| 48 |
|
|---|
| 49 | #include "MCalibrationPix.h"
|
|---|
| 50 | #include "MCalibrationCam.h"
|
|---|
| 51 |
|
|---|
| 52 | #include "MGeomCam.h"
|
|---|
| 53 | #include "MRawRunHeader.h"
|
|---|
| 54 |
|
|---|
| 55 | #include "MHillas.h"
|
|---|
| 56 | #include "MNewImagePar.h"
|
|---|
| 57 |
|
|---|
| 58 | #include "MMcEvt.hxx"
|
|---|
| 59 | #include "MMcFadcHeader.hxx"
|
|---|
| 60 |
|
|---|
| 61 | ClassImp(MMcCalibrationCalc);
|
|---|
| 62 |
|
|---|
| 63 | using namespace std;
|
|---|
| 64 |
|
|---|
| 65 | MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title)
|
|---|
| 66 | {
|
|---|
| 67 | fName = name ? name : "MMcCalibrationCalc";
|
|---|
| 68 | fTitle = title ? title : "Calculate and write conversion factors into MCalibrationCam Container";
|
|---|
| 69 |
|
|---|
| 70 | fADC2Phot = 0.;
|
|---|
| 71 | fEvents = 0;
|
|---|
| 72 |
|
|---|
| 73 | fHistRatio = new TH1F(AddSerialNumber("HistRatio"), "log10(fPassPhotCone/fSize)", 1500, -3., 3.);
|
|---|
| 74 | fHistRatio->GetXaxis()->SetTitle("log_{10}(fPassPhotCone / fSize) (in photons/ADC count)");
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | // --------------------------------------------------------------------------
|
|---|
| 78 | //
|
|---|
| 79 | // Check for the run type. Return kTRUE if it is a MC run or if there
|
|---|
| 80 | // is no MC run header (old camera files) kFALSE in case of a different
|
|---|
| 81 | // run type
|
|---|
| 82 | //
|
|---|
| 83 | Bool_t MMcCalibrationCalc::CheckRunType(MParList *pList) const
|
|---|
| 84 | {
|
|---|
| 85 | const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 86 | if (!run)
|
|---|
| 87 | {
|
|---|
| 88 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
|---|
| 89 | return kTRUE;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | return run->GetRunType() == kRTMonteCarlo;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | // --------------------------------------------------------------------------
|
|---|
| 96 | //
|
|---|
| 97 | // Make sure, that there is an MCalibrationCam Object in the Parameter List.
|
|---|
| 98 | //
|
|---|
| 99 | Int_t MMcCalibrationCalc::PreProcess(MParList *pList)
|
|---|
| 100 | {
|
|---|
| 101 |
|
|---|
| 102 | fCalCam = (MCalibrationCam*) pList->FindObject(AddSerialNumber("MCalibrationCam"));
|
|---|
| 103 |
|
|---|
| 104 | if ( !fCalCam )
|
|---|
| 105 | {
|
|---|
| 106 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MCalibrationCam") << "... aborting." << endl;
|
|---|
| 107 | return kFALSE;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | fHillas = (MHillas*) pList->FindCreateObj(AddSerialNumber("MHillas"));
|
|---|
| 111 | if ( !fHillas)
|
|---|
| 112 | {
|
|---|
| 113 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MHillas") << "... aborting." << endl;
|
|---|
| 114 | return kFALSE;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | fNew = (MNewImagePar*) pList->FindCreateObj(AddSerialNumber("MNewImagePar"));
|
|---|
| 118 | if ( !fNew)
|
|---|
| 119 | {
|
|---|
| 120 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MNewImagePar") << "... aborting." << endl;
|
|---|
| 121 | return kFALSE;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | fMcEvt = (MMcEvt*) pList->FindCreateObj(AddSerialNumber("MMcEvt"));
|
|---|
| 125 | if ( !fMcEvt)
|
|---|
| 126 | {
|
|---|
| 127 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MMcEvt") << "... aborting." << endl;
|
|---|
| 128 | return kFALSE;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | return kTRUE;
|
|---|
| 132 |
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | // --------------------------------------------------------------------------
|
|---|
| 136 | //
|
|---|
| 137 | // Check for the runtype.
|
|---|
| 138 | // Search for MGeomCam and MMcFadcHeader.
|
|---|
| 139 | //
|
|---|
| 140 | Bool_t MMcCalibrationCalc::ReInit(MParList *pList)
|
|---|
| 141 | {
|
|---|
| 142 | //
|
|---|
| 143 | // If it is no MC file display error and exit
|
|---|
| 144 | //
|
|---|
| 145 | if (!CheckRunType(pList))
|
|---|
| 146 | {
|
|---|
| 147 | *fLog << err << dbginf << "This is no MC file... aborting." << endl;
|
|---|
| 148 | return kFALSE;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | //
|
|---|
| 152 | // Now check the existence of all necessary containers.
|
|---|
| 153 | //
|
|---|
| 154 |
|
|---|
| 155 | fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
|
|---|
| 156 | if ( ! fGeom )
|
|---|
| 157 | {
|
|---|
| 158 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MGeomCam") << "... aborting." << endl;
|
|---|
| 159 | return kFALSE;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
|
|---|
| 163 | if (!fHeaderFadc)
|
|---|
| 164 | {
|
|---|
| 165 | *fLog << err << dbginf << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
|
|---|
| 166 | return kFALSE;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | for (UInt_t ipix = 0; ipix < fGeom->GetNumPixels(); ipix++)
|
|---|
| 170 | {
|
|---|
| 171 | if (fHeaderFadc->GetPedestalRmsHigh(ipix) > 0 ||
|
|---|
| 172 | fHeaderFadc->GetPedestalRmsLow(ipix) > 0 )
|
|---|
| 173 | {
|
|---|
| 174 | *fLog << err << endl << endl << dbginf << "You are trying to calibrate the data using a Camera file produced with added noise. Please use a noiseless file for calibration. Aborting..." << endl << endl;
|
|---|
| 175 | return kFALSE;
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | return kTRUE;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 | // --------------------------------------------------------------------------
|
|---|
| 184 | //
|
|---|
| 185 | // Obtain average ratio of photons in camera to image Size.
|
|---|
| 186 | //
|
|---|
| 187 | Int_t MMcCalibrationCalc::Process()
|
|---|
| 188 | {
|
|---|
| 189 |
|
|---|
| 190 | //
|
|---|
| 191 | // Exclude events with some saturated pixel
|
|---|
| 192 | //
|
|---|
| 193 | if ( fNew->GetNumSaturatedPixels() > 0 )
|
|---|
| 194 | return kTRUE;
|
|---|
| 195 |
|
|---|
| 196 | //
|
|---|
| 197 | // Exclude events with low Size (larger fluctuations)
|
|---|
| 198 | // FIXME? The present cut (1000 "inner-pixel-counts") is somehow arbitrary.
|
|---|
| 199 | // Might it be optimized?
|
|---|
| 200 | //
|
|---|
| 201 | if ( fHillas->GetSize() < 1000 )
|
|---|
| 202 | return kTRUE;
|
|---|
| 203 |
|
|---|
| 204 | fADC2Phot += fMcEvt->GetPassPhotCone() / fHillas->GetSize();
|
|---|
| 205 | fEvents ++;
|
|---|
| 206 |
|
|---|
| 207 | fHistRatio->Fill(log10(fMcEvt->GetPassPhotCone()/fHillas->GetSize()));
|
|---|
| 208 |
|
|---|
| 209 | return kTRUE;
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | // --------------------------------------------------------------------------
|
|---|
| 213 | //
|
|---|
| 214 | // Fill the MCalibrationCam object
|
|---|
| 215 | //
|
|---|
| 216 | Int_t MMcCalibrationCalc::PostProcess()
|
|---|
| 217 | {
|
|---|
| 218 |
|
|---|
| 219 | if (fEvents > 0)
|
|---|
| 220 | fADC2Phot /= fEvents;
|
|---|
| 221 | else
|
|---|
| 222 | {
|
|---|
| 223 | *fLog << err << dbginf << "No events were read! Aborting." << endl;
|
|---|
| 224 | return kFALSE;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | //
|
|---|
| 228 | // For the calibration we no longer use the mean, but thepeak of the distribution:
|
|---|
| 229 | //
|
|---|
| 230 |
|
|---|
| 231 | Float_t summax = 0.;
|
|---|
| 232 | Int_t mode = 0;
|
|---|
| 233 | Int_t reach = 2;
|
|---|
| 234 | for (Int_t ibin = 1+reach; ibin <= fHistRatio->GetNbinsX()-reach; ibin++)
|
|---|
| 235 | {
|
|---|
| 236 | Float_t sum = 0;
|
|---|
| 237 | for(Int_t k = ibin-reach; k <= ibin+reach; k++)
|
|---|
| 238 | sum += fHistRatio->GetBinContent(k);
|
|---|
| 239 | if (sum > summax)
|
|---|
| 240 | {
|
|---|
| 241 | summax = sum;
|
|---|
| 242 | mode = ibin;
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | fADC2Phot = pow(10., fHistRatio->GetXaxis()->GetBinCenter(mode));
|
|---|
| 247 |
|
|---|
| 248 | const int num = fCalCam->GetSize();
|
|---|
| 249 |
|
|---|
| 250 | for (int i=0; i<num; i++)
|
|---|
| 251 | {
|
|---|
| 252 | MCalibrationPix &calpix = (*fCalCam)[i];
|
|---|
| 253 |
|
|---|
| 254 | Float_t factor = fADC2Phot*calpix.GetMeanConversionBlindPixelMethod();
|
|---|
| 255 |
|
|---|
| 256 | calpix.SetConversionBlindPixelMethod(factor, 0., 0.);
|
|---|
| 257 |
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | return kTRUE;
|
|---|
| 261 |
|
|---|
| 262 | }
|
|---|