-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVEffectiveAreaCalculator.h
More file actions
379 lines (322 loc) · 14.2 KB
/
VEffectiveAreaCalculator.h
File metadata and controls
379 lines (322 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
//!< VEffectiveAreaCalculator calculate effective areas and energy spectra
#ifndef VEffectiveAreaCalculator_H
#define VEffectiveAreaCalculator_H
#include "CData.h"
#include "VGammaHadronCuts.h"
#include "VAnaSumRunParameter.h"
#include "VAstronometry.h"
#include "VEffectiveAreaCalculatorMCHistograms.h"
#include "TEfficiency.h"
#include "VHistogramUtilities.h"
#include "VInstrumentResponseFunctionRunParameter.h"
#include "VStatistics.h"
#include "VSpectralWeight.h"
#include "VUtilities.h"
#include "TChain.h"
#include "TDirectory.h"
#include "TF1.h"
#include "TFile.h"
#include "TGraphErrors.h"
#include "TGraph2DErrors.h"
#include "TGraphAsymmErrors.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TList.h"
#include "TMath.h"
#include "TProfile.h"
#include "TTree.h"
#include "TMinuit.h"
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
class VEffectiveAreaCalculator
{
private:
vector< vector< double > > fEffArea_time;
vector< vector< double > > fEffAreaMC_time;
vector< double > timebins;
float fMC_ScatterArea;
bool bNOFILE;
TDirectory* fGDirectory;
TFile* fCloneTreeFile;
vector< double > fZe;
vector< double > fMCZe;
vector< vector< double > > fEff_WobbleOffsets;
vector< vector< vector< double > > > fEff_Noise;
vector< vector< vector< vector< double > > > > fEff_SpectralIndex;
// effective areas (reading of effective areas)
unsigned int fNBins; // bins in the true energy of MC (fEff_E0)
unsigned int fBiasBin; // bins in the energy bias
unsigned int fhistoNEbins; // energy bins for histograms only
unsigned int fResponseMatricesEbinning; // fine bins for response matrices. Likelihood analysis.
unsigned int fLogAngularBin; // bins for the log10(angular diff R,MC [deg])
vector< double > fEff_E0;
map< unsigned int, vector< double > > fEffArea_map;
map< unsigned int, vector< double > > fEffAreaMC_map;
map< unsigned int, unsigned int > fEntry_map;
map< unsigned int, TH2F* > fEsysMCRelative2D_map;
vector< double > fEff_EsysMCRelative_EnergyAxis;
map< unsigned int, vector< double > > fEff_EsysMCRelative;
unsigned int fNMeanEffectiveArea;
unsigned int fNMeanEffectiveAreaMC;
unsigned int fNMeanResponseMatrix;
unsigned int fNTimeBinnedMeanEffectiveArea;
unsigned int fNTimeBinnedMeanEffectiveAreaMC;
vector< double > fVMeanEffectiveArea;
vector< double > fVMeanEffectiveAreaMC;
vector< double > fVTimeBinnedMeanEffectiveArea;
vector< double > fVTimeBinnedMeanEffectiveAreaMC;
TGraphAsymmErrors* gMeanEffectiveArea;
TGraph2DErrors* gTimeBinnedMeanEffectiveArea;
TGraphAsymmErrors* gMeanEffectiveAreaMC;
TH2F* hMeanResponseMatrix;
TGraphErrors* gMeanSystematicErrorGraph;
// unique event counting
map< unsigned int, unsigned short int> fUniqueEventCounter;
vector< double > fAreaRadius;
vector< string > fScatterMode;
vector< double > fXWobble; //!< wobble offset in camera coordinates (grisudet)
vector< double > fYWobble; //!< wobble offset in camera coordinates (grisudet)
vector< int > fNoise;
vector< double > fPedVar;
double fEnergyAxis_minimum_defaultValue;
double fEnergyAxis_maximum_defaultValue;
double fLogAngular_minimum_defaultValue;
double fLogAngular_maximum_defaultValue;
VInstrumentResponseFunctionRunParameter* fRunPara;
VGammaHadronCuts* fCuts;
bool fIsotropicArrivalDirections;
// effective area calculation
vector< double > fVMinAz;
vector< double > fVMaxAz;
// spectral weighting
vector< double > fVSpectralIndex;
VSpectralWeight* fSpectralWeight;
// list of histograms
vector< vector< TList* > > hList;
vector< vector< TH1D* > > hVEmc;
vector< vector< TH1D* > > hVEcut;
vector< vector< TH1D* > > hVEcutLin;
vector< vector< TH1D* > > hVEcutNoTh2;
vector< vector< TH1D* > > hVEcutRec;
vector< vector< TH1D* > > hVEcutUW;
vector< vector< TH1D* > > hVEcutRecUW;
vector< vector< TH1D* > > hVEcutRecNoTh2;
vector< vector< TProfile* > > hVEmcSWeight;
vector< vector< TH1D* > > hVEcut500;
vector< vector< TProfile* > > hVEsysRec;
vector< vector< TProfile* > > hVEsysMC;
vector< vector< TProfile* > > hVEsysMCRelative;
vector< vector< TH2F* > > hVEsysMCRelativeRMS;
vector< vector< TH2F* > > hVEsysMCRelative2D;
vector< vector< TH2F* > > hVEsysMCRelative2DNoDirectionCut;
vector< vector< TH2F* > > hVEsys2D;
vector< vector< TH2F* > > hVResponseMatrix;
vector< vector< TH2F* > > hVResponseMatrixFine;
vector< vector< TProfile* > > hVResponseMatrixProfile;
vector< vector< TH2F* > > hVResponseMatrixQC;
vector< vector< TH2F* > > hVEmcCutCTA;
vector< vector< TH2F* > > hVResponseMatrixFineQC;
vector< vector< TH2F* > > hVResponseMatrixNoDirectionCut;
vector< vector< TH2F* > > hVResponseMatrixFineNoDirectionCut;
vector< vector< TH2F* > > hVAngErec2D; // direction reconstruction
vector< vector< TH2F* > > hVAngMC2D; // direction reconstruction
vector< vector< TH1D* > > hVWeightedRate;
vector< vector< TH1D* > > hVWeightedRate005;
vector< vector< vector < TH1D* > > > hVEcutSub;
// angular resolution graphs (vector in az)
vector< TGraphErrors* > fGraph_AngularResolution68p;
vector< TGraphErrors* > fGraph_AngularResolution95p;
vector< TH2F* > hVAngularDiff_2D;
vector< TH2F* > hVAngularDiffEmc_2D;
vector< TH2F* > hVAngularLogDiff_2D;
vector< TH2F* > hVAngularLogDiffEmc_2D;
// written to the EffArea tree
TList* hisTreeList;
TH1D* hEmc;
TH1D* hEcut;
TH1D* hEcut500;
TH1D* hEcutLin;
TH1D* hEcutRec;
TH1D* hEcutUW;
TH1D* hEcutRecUW;
TH1D* hEcutNoTh2;
TH1D* hEcutRecNoTh2;
TGraphAsymmErrors* gEffAreaMC;
TGraphAsymmErrors* gEffAreaRec;
TGraphAsymmErrors* gEffAreaNoTh2MC;
TGraphAsymmErrors* gEffAreaNoTh2Rec;
TProfile* hEmcSWeight;
TProfile* hEsysRec;
TProfile* hEsysMC;
TProfile* hEsysMCRelative;
TH2F* hEsysMCRelativeRMS;
TH2F* hEsysMCRelative2D;
TH2F* hEsys2D;
TH2F* hEmcCutCTA;
TH2F* hResponseMatrixFine;
TH2F* hResponseMatrixFineQC;
TH2F* hResponseMatrix;
TProfile* hResponseMatrixProfile;
TH2F* hResponseMatrixQC;
TH2F* hEsysMCRelative2DNoDirectionCut;
TH2F* hResponseMatrixNoDirectionCut;
TH2F* hResponseMatrixFineNoDirectionCut;
TH1D* hWeightedRate;
TH1D* hWeightedRate005;
vector< TH1D* > hEcutSub; //! events after individual cuts
TH2F* hAngularDiff_2D;
TH2F* hAngularDiffEmc_2D;
TH2F* hAngularLogDiff_2D;
TH2F* hAngularLogDiffEmc_2D;
int fEffectiveAreaVsEnergyMC; // 0 = vs MC energy, 1 = vs rec energy (approx. method), 2 = vs rec energy (default)
bool bLikelihoodAnalysis;
TTree* fEffArea;
TTree* fEffTree;
double ze;
int fAzBin; //!< az bin: definitions see getEffectiveArea
double fMinAz;
double fMaxAz;
double fXoff;
double fYoff;
double fWoff;
double fSpectralIndex;
int fTNoise;
double fTPedvar;
int nbins;
double e0[1000];
double eff[1000];
double effNoTh2[1000];
UShort_t nbins_MC;
float e0_MC[1000];
float eff_MC[1000];
double seff_L[1000];
double seff_U[1000];
float eff_error[1000];
float effNoTh2_error[1000];
float esys_rel[1000];
int Rec_nbins;
double Rec_e0[1000];
double Rec_eff[1000];
double Rec_effNoTh2[1000];
double Rec_seff_L[1000];
double Rec_seff_U[1000];
int nbins_ResMat;
double ResMat_MC[1000];
double ResMat_Rec[1000];
double ResMat_Rec_Err[1000];
float Rec_eff_error[1000];
float Rec_effNoTh2_error[1000];
float Rec_angRes_p68[1000];
float Rec_angRes_p80[1000];
// H2F effective area tree
float fH2F_e0_esys[1000];
// effective area smoothing
int fSmoothIter;
double fSmoothThreshold;
bool bEffectiveAreasareFunctions;
bool bEffectiveAreasareHistograms;
bool fClopperPearson; // statistic option for error calculation
// mean values from getEffectiveAreas
double fEffectiveAreas_meanZe;
double fEffectiveAreas_meanWoff;
double fEffectiveAreas_meanPedVar;
double fEffectiveAreas_meanIndex;
double fEffectiveAreas_meanN;
// effective areas fit functions
vector< TF1* > fEffAreaFitFunction;
TF1* fGauss;
double hres_binw;
double* hres_bins;
vector <double> hres_binc;
int hres_nbins;
TGraphAsymmErrors* applyResponseMatrix( TH2* h, TGraphAsymmErrors* g );
bool binomialDivide( TGraphAsymmErrors* g, TH1D* hrec, TH1D* hmc );
void copyProfileHistograms( TProfile*, TProfile* );
void copyHistograms( TH1*, TH1*, bool );
void fillAngularResolution( unsigned int i_az, bool iContaintment_95p );
double getAzMean( double azmin, double azmax );
double getCRWeight( double iEMC_TeV_log10, TH1* h );
template <typename T> vector< T > get_irf_vector( int i_nbins, T* i_e0, T* i_irf );
TH2F* get_irf2D_vector( int nx, float minx, float maxx, int ny, float miny, float maxy, float* value );
bool getEffectiveAreasFromFitFunction( TTree*, double azmin, double azmax, double ispectralindex );
void getEffectiveAreasFromFitFunction( unsigned int, unsigned int, double, double&, double& );
double getEffectiveAreasFromHistograms( double erec, double ze, double woff, double iPedVar,
double iSpectralIndex, bool bAddtoMeanEffectiveArea = true,
int iEffectiveAreaVsEnergyMC = 2 );
bool getMonteCarloSpectra( VEffectiveAreaCalculatorMCHistograms* );
double getMCSolidAngleNormalization();
vector< unsigned int > getUpperLowBins( vector< double > i_values, double d );
bool initializeEffectiveAreasFromHistograms( TTree*, TH1D*, double azmin, double azmax, double ispectralindex, double ipedvar, TTree* iEffAreaH2F = 0 );
vector< double > interpolate_effectiveArea( double iV, double iVLower, double iVupper,
vector< double > iEL, vector< double > iEU, bool iCos = true );
TH2F* interpolate_responseMatrix( double iV, double iVLower, double iVupper, TH2F* iElower, TH2F* iEupper, bool iCos = true );
void multiplyByScatterArea( TGraphAsymmErrors* g );
void reset();
void smoothEffectiveAreas( map< unsigned int, vector< double > > );
public:
VEffectiveAreaCalculator( string ieffFile, double azmin, double azmax, double iPedVar, double iIndex,
vector< double> fMCZe, int iSmoothIter = -1, double iSmoothThreshold = 1.,
int iEffectiveAreaVsEnergyMC = 2, bool iLikelihoodAnalysis = false );
VEffectiveAreaCalculator( VInstrumentResponseFunctionRunParameter*, VGammaHadronCuts* );
~VEffectiveAreaCalculator();
void cleanup();
bool fill( TH1D* hE0mc, CData* d, VEffectiveAreaCalculatorMCHistograms* iMC_histo, unsigned int iEnergyReconstructionMethod, unsigned int iDirectionReconstructionMethod );
TH1D* getHistogramhEmc();
TGraphErrors* getMeanSystematicErrorHistogram();
TTree* getTree()
{
return fEffArea;
}
int getEnergyAxis_nbins_defaultValue()
{
return fhistoNEbins;
}
double getEnergyAxis_minimum_defaultValue()
{
return fEnergyAxis_minimum_defaultValue;
}
double getEnergyAxis_maximum_defaultValue()
{
return fEnergyAxis_maximum_defaultValue;
}
double getEffectiveArea( double erec, double ze, double iWoff, double iPedvar, double iSpectralIndex = -2.5,
bool bAddtoMeanEffectiveArea = true, int iEffectiveAreaVsEnergyMC = 2 );
TGraphAsymmErrors* getMeanEffectiveArea();
TGraph2DErrors* getTimeBinnedMeanEffectiveArea();
TGraphAsymmErrors* getMeanEffectiveAreaMC();
void addMeanResponseMatrix( TH2F* i_hTmp ) ;
TH2F* getMeanResponseMatrix()
{
return hMeanResponseMatrix;
}
void setTimeBinnedMeanEffectiveArea();
void setTimeBinnedMeanEffectiveAreaMC( double i_time );
void initializeHistograms( vector< double > iAzMin, vector< double > iAzMax, vector< double > iSpectralIndex );
void resetHistograms( unsigned int iZe );
void resetHistogramsVectors( unsigned int iZe );
void setAngularResolution2D( unsigned int i_az, vector< TH2D* > );
void setAngularResolutionGraph( unsigned int i_az, TGraphErrors* g, bool iAngContainment_95p );
void setAzimuthCut( int iAzBin, double iAzMin, double iAzMax );
void setEffectiveArea( int iMC )
{
fEffectiveAreaVsEnergyMC = iMC;
}
void setIsotropicArrivalDirections( bool iB = false )
{
fIsotropicArrivalDirections = iB;
}
bool setMonteCarloEnergyRange( double iMin, double iMax, double iMCIndex = 2. );
void setNoiseLevel( int iN, double iP );
void setStatisticsOption( bool iClopperPearson = false )
{
fClopperPearson = iClopperPearson;
}
void setWobbleOffset( double x, double y );
void resetTimeBin();
void setTimeBin( double time );
};
#endif