| 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 9/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | ! Wolfgang Wittek 7/2003 <mailto:wittek@mppmu.mpg.de>
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2003
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | // //
|
|---|
| 28 | // MEnergyTable //
|
|---|
| 29 | // Energy Tables generated at discrete Zenith and threshold //
|
|---|
| 30 | // We then interpolate between them to estimate the energy //
|
|---|
| 31 | // //
|
|---|
| 32 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 33 | #include "MEnergyTable.h"
|
|---|
| 34 |
|
|---|
| 35 | #include "MParList.h"
|
|---|
| 36 |
|
|---|
| 37 | #include "MGeomCam.h"
|
|---|
| 38 | #include "MMcEvt.hxx"
|
|---|
| 39 | #include "MPointingPos.h"
|
|---|
| 40 | #include "MHMatrix.h"
|
|---|
| 41 | #include "MHillas.h"
|
|---|
| 42 | #include "MHillasSrc.h"
|
|---|
| 43 | #include "MNewImagePar.h"
|
|---|
| 44 | #include "MEnergyEstimate.h"
|
|---|
| 45 | #include "MParameters.h"
|
|---|
| 46 |
|
|---|
| 47 | #include "MLog.h"
|
|---|
| 48 | #include "MLogManip.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "TFile.h"
|
|---|
| 51 |
|
|---|
| 52 | ClassImp(MEnergyTable);
|
|---|
| 53 |
|
|---|
| 54 | // --------------------------------------------------------------------------
|
|---|
| 55 | //
|
|---|
| 56 | // Default constructor. Give the name of the parameter container (MHillas)
|
|---|
| 57 | // storing width, length and size (Default="MHillas").
|
|---|
| 58 | // For the Zenith Angle MMcEvt.fTheta is used.
|
|---|
| 59 | //
|
|---|
| 60 | MEnergyTable::MEnergyTable(const char *name, const char *title)
|
|---|
| 61 | {
|
|---|
| 62 |
|
|---|
| 63 | fName = name ? name : "MEnergyTable";
|
|---|
| 64 | fTitle = title ? title : "Task to estimate the energy using MC Tables";
|
|---|
| 65 |
|
|---|
| 66 | fNameHillasSrc = "MHillasSrc";
|
|---|
| 67 | fNameHillas = "MHillas";
|
|---|
| 68 | fNameMC = "MMcEvt";
|
|---|
| 69 | fNamePoint = "MPointingPos";
|
|---|
| 70 |
|
|---|
| 71 | //fNameParameter = "MParameterD";
|
|---|
| 72 |
|
|---|
| 73 | fNameParameter = "MEnergyTable";
|
|---|
| 74 | fNameParameterL = "ScaledLength";
|
|---|
| 75 | fNameParameterW = "ScaledWidth";
|
|---|
| 76 |
|
|---|
| 77 | SetNameParameter("MEnergyTable");
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 | // --------------------------------------------------------------------------
|
|---|
| 82 | //
|
|---|
| 83 | // Destructor.
|
|---|
| 84 | //
|
|---|
| 85 | MEnergyTable::~MEnergyTable()
|
|---|
| 86 | {
|
|---|
| 87 |
|
|---|
| 88 | delete fHillasSrc;
|
|---|
| 89 | delete fHillas;
|
|---|
| 90 | delete fParameter;
|
|---|
| 91 | delete fParameterL;
|
|---|
| 92 | delete fParameterW;
|
|---|
| 93 | delete fPointing;
|
|---|
| 94 |
|
|---|
| 95 | fTableFile->Close();
|
|---|
| 96 |
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | Int_t MEnergyTable::PreProcess(MParList *pList)
|
|---|
| 100 | {
|
|---|
| 101 |
|
|---|
| 102 | fHillasSrc = (MHillasSrc*)pList->FindCreateObj("MHillasSrc", AddSerialNumber(fNameHillasSrc));
|
|---|
| 103 | if (!fHillasSrc)
|
|---|
| 104 | return kFALSE;
|
|---|
| 105 |
|
|---|
| 106 | fHillas = (MHillas*)pList->FindCreateObj("MHillas", AddSerialNumber(fNameHillas));
|
|---|
| 107 | if (!fHillas)
|
|---|
| 108 | return kFALSE;
|
|---|
| 109 |
|
|---|
| 110 | fPointing = (MPointingPos*)pList->FindCreateObj("MPointingPos", AddSerialNumber(fNamePoint));
|
|---|
| 111 | if (!fPointing)
|
|---|
| 112 | return kFALSE;
|
|---|
| 113 |
|
|---|
| 114 | fParameter = (MParameterD*)pList->FindCreateObj("MParameterD", fNameParameter);
|
|---|
| 115 | if (!fParameter)
|
|---|
| 116 | return kFALSE;
|
|---|
| 117 |
|
|---|
| 118 | fParameterW = (MParameterD*)pList->FindCreateObj("MParameterD", fNameParameterW);
|
|---|
| 119 | if (!fParameterW)
|
|---|
| 120 | return kFALSE;
|
|---|
| 121 |
|
|---|
| 122 | fParameterL = (MParameterD*)pList->FindCreateObj("MParameterD", fNameParameterL);
|
|---|
| 123 | if (!fParameterL)
|
|---|
| 124 | return kFALSE;
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | return kTRUE;
|
|---|
| 128 |
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | Int_t MEnergyTable::Process()
|
|---|
| 132 | {
|
|---|
| 133 |
|
|---|
| 134 | Double_t fDist = fHillasSrc->GetDist();
|
|---|
| 135 | Double_t fSize = fHillas->GetSize();
|
|---|
| 136 | fZenith = fPointing->GetZd();
|
|---|
| 137 | fThreshold = 305.; //TODO
|
|---|
| 138 |
|
|---|
| 139 | iZenith = 0;
|
|---|
| 140 | iThreshold = 0;
|
|---|
| 141 |
|
|---|
| 142 | for( int i = 0; i < 2; i++ )
|
|---|
| 143 | if( fZenith >= iZen[i] && fZenith < iZen[i+1] ) iZenith = i;
|
|---|
| 144 |
|
|---|
| 145 | for( int i = 0; i < 2; i++ )
|
|---|
| 146 | if( fThreshold >= iThr[i] && fThreshold < iThr[i+1] ) iThreshold = i;
|
|---|
| 147 |
|
|---|
| 148 | if( iZenith != -999 && iThreshold != -999 )
|
|---|
| 149 | {
|
|---|
| 150 |
|
|---|
| 151 | // Cannot get Threshold Yet so doing 1D interpolation on Zenith angle
|
|---|
| 152 | // Between i and i+1 bin
|
|---|
| 153 |
|
|---|
| 154 | iX = hEnergy[iZenith][0]->GetXaxis()->FindBin(log10(fSize));
|
|---|
| 155 | iY = hEnergy[iZenith][0]->GetYaxis()->FindBin(fDist);
|
|---|
| 156 | fEnergy1 = hEnergy[iZenith][0]->GetBinContent(iX,iY);
|
|---|
| 157 | fLength1 = hLength[iZenith][0]->GetBinContent(iX,iY);
|
|---|
| 158 | fLengthSigma1 = hLength[iZenith][0]->GetBinContent(iX,iY);
|
|---|
| 159 | fWidth1 = hLength[iZenith][0]->GetBinContent(iX,iY);
|
|---|
| 160 | fWidthSigma1 = hLength[iZenith][0]->GetBinContent(iX,iY);
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 | iX = hEnergy[iZenith+1][0]->GetXaxis()->FindBin(log10(fSize));
|
|---|
| 164 | iY = hEnergy[iZenith+1][0]->GetYaxis()->FindBin(fDist);
|
|---|
| 165 | fEnergy2 = hEnergy[iZenith+1][0]->GetBinContent(iX,iY);
|
|---|
| 166 | fLength2 = hLength[iZenith+1][0]->GetBinContent(iX,iY);
|
|---|
| 167 | fLengthSigma2 = hLength[iZenith+1][0]->GetBinContent(iX,iY);
|
|---|
| 168 | fWidth2 = hLength[iZenith+1][0]->GetBinContent(iX,iY);
|
|---|
| 169 | fWidthSigma2 = hLength[iZenith+1][0]->GetBinContent(iX,iY);
|
|---|
| 170 |
|
|---|
| 171 | fEnergyRecon = fEnergy2-fEnergy1;
|
|---|
| 172 | fEnergyRecon /= cos(D2R*iZen[iZenith+1]) - cos(D2R*iZen[iZenith]);
|
|---|
| 173 | fEnergyRecon *= cos(D2R*fZenith) - cos(D2R*iZen[iZenith]);
|
|---|
| 174 | fEnergyRecon += fEnergy1;
|
|---|
| 175 |
|
|---|
| 176 | fLength = fLength2-fLength1;
|
|---|
| 177 | fLength /= cos(D2R*iZen[iZenith+1]) - cos(D2R*iZen[iZenith]);
|
|---|
| 178 | fLength *= cos(D2R*fZenith) - cos(D2R*iZen[iZenith]);
|
|---|
| 179 | fLength += fLength1;
|
|---|
| 180 |
|
|---|
| 181 | fLengthSigma = fLengthSigma2-fLengthSigma1;
|
|---|
| 182 | fLengthSigma /= cos(D2R*iZen[iZenith+1]) - cos(D2R*iZen[iZenith]);
|
|---|
| 183 | fLengthSigma *= cos(D2R*fZenith) - cos(D2R*iZen[iZenith]);
|
|---|
| 184 | fLengthSigma += fLengthSigma1;
|
|---|
| 185 |
|
|---|
| 186 | fWidth = fWidth2-fWidth1;
|
|---|
| 187 | fWidth /= cos(D2R*iZen[iZenith+1]) - cos(D2R*iZen[iZenith]);
|
|---|
| 188 | fWidth *= cos(D2R*fZenith) - cos(D2R*iZen[iZenith]);
|
|---|
| 189 | fWidth += fWidth1;
|
|---|
| 190 |
|
|---|
| 191 | fWidthSigma = fWidthSigma2-fWidthSigma1;
|
|---|
| 192 | fWidthSigma /= cos(D2R*iZen[iZenith+1]) - cos(D2R*iZen[iZenith]);
|
|---|
| 193 | fWidthSigma *= cos(D2R*fZenith) - cos(D2R*iZen[iZenith]);
|
|---|
| 194 | fWidthSigma += fWidthSigma1;
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 | RSW = (fHillas->GetWidth()-fWidth)/fWidthSigma;
|
|---|
| 198 | RSL = (fHillas->GetLength()-fLength)/fLengthSigma;
|
|---|
| 199 |
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | fParameter->SetVal(fEnergyRecon);
|
|---|
| 203 | fParameter->SetReadyToSave();
|
|---|
| 204 |
|
|---|
| 205 | fParameterW->SetVal(RSW);
|
|---|
| 206 | fParameterW->SetReadyToSave();
|
|---|
| 207 | fParameterL->SetVal(RSL);
|
|---|
| 208 | fParameterL->SetReadyToSave();
|
|---|
| 209 |
|
|---|
| 210 | return kTRUE;
|
|---|
| 211 |
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | Int_t MEnergyTable::SetTableFile( const TString sTableFile )
|
|---|
| 215 | {
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 | fTableFile = new TFile(sTableFile,"OPEN");
|
|---|
| 219 | if( fTableFile->IsZombie() )
|
|---|
| 220 | {
|
|---|
| 221 | cout << "Cannot open Table File: " << sTableFile << endl;
|
|---|
| 222 | return kFALSE;
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | // TODO
|
|---|
| 226 | iZen[0] = 5;
|
|---|
| 227 | iZen[1] = 30;
|
|---|
| 228 | iZen[2] = 45;
|
|---|
| 229 | iThr[0] = 300;
|
|---|
| 230 | iThr[1] = 405;
|
|---|
| 231 | iThr[2] = 500;
|
|---|
| 232 |
|
|---|
| 233 | for( int i = 0; i < 3; i++ )
|
|---|
| 234 | {
|
|---|
| 235 | for( int j = 0; j < 3; j++ )
|
|---|
| 236 | {
|
|---|
| 237 |
|
|---|
| 238 | sprintf(sHistDir,"z%.2d/t%.2d",iZen[i],iThr[j]);
|
|---|
| 239 | sprintf(sHistName,"z%.2d/t%.2d/hEnergyAverage_%.2d_%.2d",iZen[i],iThr[j],iZen[i],iThr[j]);
|
|---|
| 240 | sprintf(sHistNameL,"z%.2d/t%.2d/hLengthAverage_%.2d_%.2d",iZen[i],iThr[j],iZen[i],iThr[j]);
|
|---|
| 241 | sprintf(sHistNameLS,"z%.2d/t%.2d/hLengthSigma_%.2d_%.2d",iZen[i],iThr[j],iZen[i],iThr[j]);
|
|---|
| 242 | sprintf(sHistNameW,"z%.2d/t%.2d/hWidthAverage_%.2d_%.2d",iZen[i],iThr[j],iZen[i],iThr[j]);
|
|---|
| 243 | sprintf(sHistNameWS,"z%.2d/t%.2d/hWidthSigma_%.2d_%.2d",iZen[i],iThr[j],iZen[i],iThr[j]);
|
|---|
| 244 |
|
|---|
| 245 | if( fTableFile->GetDirectory(sHistDir) )
|
|---|
| 246 | {
|
|---|
| 247 | fTableFile->cd(sHistDir);
|
|---|
| 248 | cout << "Adding: " << i << " " << j << " " << sHistDir << endl;
|
|---|
| 249 |
|
|---|
| 250 | htempE.push_back( (TH2F*)fTableFile->Get(sHistName) );
|
|---|
| 251 | htempL.push_back( (TH2F*)fTableFile->Get(sHistNameL) );
|
|---|
| 252 | htempLS.push_back( (TH2F*)fTableFile->Get(sHistNameLS) );
|
|---|
| 253 | htempW.push_back( (TH2F*)fTableFile->Get(sHistNameW) );
|
|---|
| 254 | htempWS.push_back( (TH2F*)fTableFile->Get(sHistNameWS) );
|
|---|
| 255 |
|
|---|
| 256 | } else
|
|---|
| 257 | {
|
|---|
| 258 | cout << "Error Table File not complete!" << endl;
|
|---|
| 259 | return kFALSE;
|
|---|
| 260 | }
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | hEnergy.push_back(htempE);
|
|---|
| 264 | hLength.push_back(htempL);
|
|---|
| 265 | hLengthSigma.push_back(htempLS);
|
|---|
| 266 | hWidth.push_back(htempW);
|
|---|
| 267 | hWidthSigma.push_back(htempWS);
|
|---|
| 268 |
|
|---|
| 269 | htempE.clear();
|
|---|
| 270 | htempL.clear();
|
|---|
| 271 | htempLS.clear();
|
|---|
| 272 | htempW.clear();
|
|---|
| 273 | htempWS.clear();
|
|---|
| 274 |
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | return kTRUE;
|
|---|
| 278 |
|
|---|
| 279 | }
|
|---|