00001
00003
00004
00005
00007
00008 #ifndef ELECTRONPHOTONFOURMOMENTUMCORRECTION_EGAMMAENERGYCORRECTIONTOOL_H
00009 #define ELECTRONPHOTONFOURMOMENTUMCORRECTION_EGAMMAENERGYCORRECTIONTOOL_H
00010
00011
00012 #include <string>
00013 #include <vector>
00014 #include <iostream>
00015 #include <fstream>
00016 #include <cstdlib>
00017 #include <iomanip>
00018 #include <cmath>
00019 #include <cctype>
00020 #include <cstddef>
00021
00022
00023 #include "PATCore/PATCoreEnums.h"
00024 #include <AsgTools/AsgMessaging.h>
00025
00026
00027
00028 #include "TRandom3.h"
00029 #include "TList.h"
00030 #include "TFile.h"
00031 #include "TGraphErrors.h"
00032 #include "TH1D.h"
00033 #include "TH2F.h"
00034 #include "TSystem.h"
00035 #include "TF1.h"
00036
00037
00038 class eg_resolution;
00039 class get_MaterialResolutionEffect;
00040 class e1hg_systematics;
00041 namespace egGain { class GainTool;
00042 class GainUncertainty;
00043 }
00044
00045
00046 namespace egEnergyCorr {
00047 struct ROOT6_OpenNamespaceWorkaround { };
00048
00049
00050 namespace Resolution {
00051 struct ROOT6_OpenNamespaceWorkaround { };
00052
00053 enum Variation {
00054
00055
00056
00057
00058 None,
00059
00060
00061 Nominal,
00062
00063
00064 AllDown, AllUp,
00065
00066
00067 ZSmearingDown, ZSmearingUp,
00068
00069
00070 SamplingTermDown, SamplingTermUp,
00071
00072
00073 MaterialIDDown, MaterialIDUp, MaterialCaloDown, MaterialCaloUp, MaterialGapDown, MaterialGapUp, MaterialCryoDown, MaterialCryoUp,
00074
00075
00076 PileUpDown, PileUpUp,
00077
00078
00079 MaterialIBLUp, MaterialIBLDown, MaterialPP0Up, MaterialPP0Down,
00080
00081
00082
00083 LastResolutionVariation
00084
00085 };
00086
00087
00088 enum resolutionType {
00089
00090 Gaussian,
00091
00092 SigmaEff80,
00093
00094 SigmaEff90
00095 };
00096
00097 }
00098
00099
00100
00101 namespace Scale {
00102 struct ROOT6_OpenNamespaceWorkaround { };
00103
00104 enum Variation {
00105
00106
00107 None,
00108
00109
00110 Nominal,
00111
00112
00113
00114
00115
00116 MomentumUp, MomentumDown,
00117
00118
00119
00120
00121
00122 ZeeStatUp, ZeeStatDown, ZeeSystUp, ZeeSystDown, ZeePhysUp, ZeePhysDown, ZeeAllUp, ZeeAllDown,
00123
00124
00125 LArCalibUp, LArCalibDown, LArUnconvCalibUp, LArUnconvCalibDown, LArElecCalibUp, LArElecCalibDown, LArElecUnconvUp, LArElecUnconvDown,
00126
00127
00128 LArCalibExtra2015PreUp, LArCalibExtra2015PreDown,
00129 LArTemperature2015PreUp, LArTemperature2015PreDown,
00130
00131
00132 LArTemperature2016PreUp, LArTemperature2016PreDown,
00133
00134
00135 G4Up, G4Down,
00136
00137
00138 E4ScintillatorUp, E4ScintillatorDown,
00139
00140
00141 PSUp, PSDown, S12Up, S12Down,
00142
00143
00144 S12ExtraLastEtaBinRun2Up, S12ExtraLastEtaBinRun2Down,
00145
00146
00147 MatIDUp, MatIDDown, MatCryoUp, MatCryoDown, MatCaloUp, MatCaloDown,
00148
00149
00150 L1GainUp, L1GainDown, L2GainUp, L2GainDown,
00151
00152
00153 PedestalUp, PedestalDown,
00154
00155
00156 Wtots1Up, Wtots1Down,
00157
00158
00159 MatPP0Up, MatPP0Down,
00160
00161
00162
00163
00164 LeakageUnconvUp, LeakageUnconvDown, LeakageConvUp, LeakageConvDown,
00165
00166
00167 ConvEfficiencyUp, ConvEfficiencyDown, ConvFakeRateUp, ConvFakeRateDown, ConvRadiusUp, ConvRadiusDown,
00168
00169
00170 AllUp, AllDown,
00171 AllCorrelatedUp, AllCorrelatedDown,
00172
00173
00174 LastScaleVariation
00175
00176 };
00177
00178 }
00179
00180
00181
00182
00183 enum ESModel {
00184
00185 es2010,
00186
00187 es2011c,
00188
00189 es2011d,
00190 es2011dMedium,
00191 es2011dTight,
00192
00193 es2012a,
00194
00195 es2012c,
00196 es2012cMedium,
00197 es2012cTight,
00198
00199 es2015_day0_3percent,
00200 es2012XX,
00201 es2015PRE,
00202 es2015PRE_res_improved,
00203 es2015cPRE,
00204 es2015cPRE_res_improved,
00205 es2015c_summer,
00206 es2016PRE,
00207 es2017,
00208
00209 UNDEFINED
00210
00211 };
00212
00213
00214
00215 enum Geometry {
00216 ConfigA=0,
00217 ConfigCD,
00218 ConfigEL,
00219 ConfigFMX,
00220 ConfigGp
00221 };
00222
00223
00224
00225 enum MaterialCategory {
00226 MatID,
00227 MatCryo,
00228 MatCalo
00229 };
00230
00231 }
00232
00233
00234 namespace AtlasRoot {
00235
00236
00237 static const double GeV = 1.e+3;
00238
00239 class egammaEnergyCorrectionTool : public asg::AsgMessaging {
00240
00241 public:
00242 egammaEnergyCorrectionTool();
00243 virtual ~egammaEnergyCorrectionTool();
00244
00245
00247
00248
00249 void setESModel ( egEnergyCorr::ESModel val ){ m_esmodel = val; }
00250
00251
00252 int initialize();
00253
00254
00256
00257
00258 inline void setFileName ( const std::string& val ){ m_rootFileName = val; }
00259
00260
00261 void setRandomSeed( unsigned seed=0 ) { m_random3.SetSeed(seed); }
00262
00263 void useStatErrorScaling(bool flag) { m_use_stat_error_scaling = flag; }
00264
00265 void use_temp_correction201215(bool flag) { m_use_temp_correction201215 = flag; }
00266 void use_temp_correction201516(bool flag) { m_use_temp_correction201516 = flag; }
00267 void use_uA2MeV_2015_first2weeks_correction(bool flag) { m_use_uA2MeV_2015_first2weeks_correction = flag; }
00268
00269 double applyMCCalibration( double eta, double ET, PATCore::ParticleType::Type ptype ) const;
00270
00276 double getCorrectedMomentum( PATCore::ParticleDataType::DataType dataType,
00277 PATCore::ParticleType::Type ptype,
00278 double momentum,
00279 double trk_eta,
00280 egEnergyCorr::Scale::Variation scaleVar = egEnergyCorr::Scale::None,
00281 double varSF = 1.0 ) const;
00282
00283 double getCorrectedEnergy( unsigned int runnumber,
00284 PATCore::ParticleDataType::DataType dataType,
00285 PATCore::ParticleType::Type ptype,
00286 double cl_eta,
00287 double cl_etaCalo,
00288 double energy,
00289 double energyS2,
00290 double eraw,
00291 egEnergyCorr::Scale::Variation scaleVar = egEnergyCorr::Scale::None,
00292 egEnergyCorr::Resolution::Variation resVar = egEnergyCorr::Resolution::None,
00293 egEnergyCorr::Resolution::resolutionType resType = egEnergyCorr::Resolution::SigmaEff90,
00294 double varSF = 1.0 ) const;
00295
00296
00297 double resolution(double energy, double cl_eta, double cl_etaCalo,
00298 PATCore::ParticleType::Type ptype,
00299 bool withCT,
00300 bool fast,
00301 egEnergyCorr::Resolution::resolutionType resType = egEnergyCorr::Resolution::SigmaEff90 ) const;
00302
00303
00304 double getResolutionError(double energy, double eta, double etaCalo, PATCore::ParticleType::Type ptype, egEnergyCorr::Resolution::Variation value,
00305 egEnergyCorr::Resolution::resolutionType resType = egEnergyCorr::Resolution::Gaussian) const;
00306
00307
00308 std::string variationName(egEnergyCorr::Scale::Variation& var) const;
00309 std::string variationName(egEnergyCorr::Resolution::Variation& var) const;
00310
00311 static egEnergyCorr::Scale::Variation ScaleVariationFromString(std::string& var);
00312 static egEnergyCorr::Resolution::Variation ResolutionVariationFromString(std::string& var);
00313
00314
00315 const TAxis& get_ZeeStat_eta_axis() const { return *m_zeeNom->GetXaxis(); }
00316
00317 private:
00318
00319 mutable egGain::GainTool* m_gain_tool;
00320 egGain::GainUncertainty* m_gain_tool_run2;
00321 mutable eg_resolution* m_resolution_tool;
00322 mutable get_MaterialResolutionEffect* m_getMaterialDelta;
00323 mutable e1hg_systematics* m_e1hg_tool;
00324
00325 double getAlphaValue(long int runnumber, double cl_eta, double cl_etaCalo,
00326 double energy, double energyS2, double eraw,
00327 PATCore::ParticleType::Type ptype = PATCore::ParticleType::Electron,
00328 egEnergyCorr::Scale::Variation var = egEnergyCorr::Scale::Nominal,
00329 double varSF = 1. ) const;
00330
00331 double getAlphaUncertainty(long int runnumber, double cl_eta, double cl_etaCalo,
00332 double energy,
00333 double energyS2,
00334 double eraw,
00335 PATCore::ParticleType::Type ptype = PATCore::ParticleType::Electron,
00336 egEnergyCorr::Scale::Variation var = egEnergyCorr::Scale::Nominal,
00337 double varSF = 1. ) const;
00338
00339
00341
00342
00343 double getSmearingCorrection( double eta, double etaCalo, double energy,
00344 PATCore::ParticleType::Type ptype = PATCore::ParticleType::Electron,
00345 PATCore::ParticleDataType::DataType dataType = PATCore::ParticleDataType::Full,
00346 egEnergyCorr::Resolution::Variation value = egEnergyCorr::Resolution::Nominal,
00347 egEnergyCorr::Resolution::resolutionType resType = egEnergyCorr::Resolution::SigmaEff90 ) const;
00348
00350
00351
00352 double applyAFtoG4(double eta, PATCore::ParticleType::Type ptype) const;
00353 double applyFStoG4(double eta) const;
00354
00355
00356
00357
00358 double mcSamplingTerm(double cl_eta) const;
00359 double mcSamplingTermRelError( double cl_eta ) const;
00360 double mcNoiseTerm( double cl_eta ) const;
00361 double mcConstantTerm( double cl_eta ) const;
00362
00363
00364 double dataConstantTerm(double eta) const;
00365 double dataConstantTermError(double eta) const;
00366
00367
00368 double dataZPeakResolution( double cl_eta ) const;
00369 double mcZPeakResolution( double cl_eta ) const;
00370 double dataConstantTermCorError( double cl_eta ) const;
00371 double fcn_sigma( double energy, double Cdata, double Cdata_er, double S, double S_er ) const;
00372 void resolutionError( double energy, double cl_eta, double& errUp, double& errDown ) const;
00373
00374
00375
00376 double getZeeMeanET( double cl_eta ) const;
00377
00378 double getAlphaZee(long int runnumber, double eta, egEnergyCorr::Scale::Variation var = egEnergyCorr::Scale::Nominal, double varSF = 1. ) const;
00379
00380 double getE4Uncertainty(double eta) const;
00381 double getE4NonLinearity(double cl_eta, double meanE, PATCore::ParticleType::Type) const;
00382
00383 double getWtots1Uncertainty(double cl_eta, double energy, PATCore::ParticleType::Type ptype) const;
00384
00385 double getLayerUncertainty( int iLayer, double cl_eta,
00386 egEnergyCorr::Scale::Variation var = egEnergyCorr::Scale::Nominal, double varSF=1. ) const;
00387
00388 double getLayerNonLinearity( int iLayer, double cl_eta, double energy, PATCore::ParticleType::Type ptype ) const;
00389
00390 double getDeltaX( double cl_eta, egEnergyCorr::MaterialCategory imat,
00391 egEnergyCorr::Scale::Variation var = egEnergyCorr::Scale::Nominal ) const;
00392
00393 double getAlphaMaterial( double cl_eta, egEnergyCorr::MaterialCategory imat, PATCore::ParticleType::Type ptype,
00394 egEnergyCorr::Scale::Variation var = egEnergyCorr::Scale::Nominal, double varSF = 1. ) const;
00395
00396 double getMaterialNonLinearity( double cl_eta, double energy, egEnergyCorr::MaterialCategory imat, PATCore::ParticleType::Type ptype,
00397 egEnergyCorr::Scale::Variation var = egEnergyCorr::Scale::Nominal, double varSF = 1. ) const;
00398
00399 double getAlphaLeakage(double cl_eta, PATCore::ParticleType::Type ptype,
00400 egEnergyCorr::Scale::Variation var = egEnergyCorr::Scale::Nominal, double varSF = 1. ) const;
00401
00402 double getAlphaConvSyst(double cl_eta, double energy, PATCore::ParticleType::Type ptype,
00403 egEnergyCorr::Scale::Variation var = egEnergyCorr::Scale::Nominal, double varSF = 1. ) const;
00404
00405 double getAlphaPedestal(double cl_eta, double energy, double eraw, PATCore::ParticleType::Type ptype, bool isRef,
00406 egEnergyCorr::Scale::Variation var = egEnergyCorr::Scale::Nominal, double varSF = 1. ) const;
00407
00408 double getLayerPedestal(double cl_eta, PATCore::ParticleType::Type ptype, int iLayer,
00409 egEnergyCorr::Scale::Variation var = egEnergyCorr::Scale::Nominal, double varSF = 1. ) const;
00410 double get_ZeeSyst(double eta) const;
00411 bool isInCrack( double cl_eta ) const;
00412 double nearestEtaBEC( double cl_eta ) const;
00413
00423 void getResolution_systematics(int particle_type, double energy, double eta, double etaCalo, int syst_mask, double& resolution, double& resolution_error,double& resolution_error_up, double & resolution_error_down, int resol_type=0) const;
00424
00425
00426 double pileUpTerm(double eta, int particle_type) const;
00427
00428 private:
00429
00430
00431 TFile* m_rootFile;
00432 std::string m_rootFileName;
00433
00434 mutable TRandom3 m_random3;
00435
00436 unsigned int m_begRunNumber;
00437 unsigned int m_endRunNumber;
00438
00439 TH1D* m_trkSyst;
00440
00441 TH1D* m_aPSNom;
00442 TH1D* m_daPSCor;
00443 TH1D* m_aS12Nom;
00444 TH1D* m_daS12Cor;
00445
00446 TH1D* m_zeeNom;
00447 TH1D* m_zeeNom_data2015;
00448
00449 TH1D* m_zeeSyst;
00450 TH1D* m_zeePhys;
00451 TH1* m_uA2MeV_2015_first2weeks_correction;
00452
00453 TH1D* m_resNom;
00454 TH1D* m_resSyst;
00455 TH1D* m_peakResData;
00456 TH1D* m_peakResMC;
00457
00458 TH1D* m_dX_ID_Nom;
00459
00460 TH1D* m_dX_IPPS_Nom;
00461 TH1D* m_dX_IPPS_LAr;
00462
00463 TH1D* m_dX_IPAcc_Nom;
00464 TH1D* m_dX_IPAcc_G4;
00465 TH1D* m_dX_IPAcc_LAr;
00466 TH1D* m_dX_IPAcc_GL1;
00467
00468 TH1D* m_dX_PSAcc_Nom;
00469 TH1D* m_dX_PSAcc_G4;
00470 TH1D* m_dX_PSAcc_LAr;
00471
00472 TAxis* m_psElectronEtaBins;
00473 TList* m_psElectronGraphs;
00474 TAxis* m_psUnconvertedEtaBins;
00475 TList* m_psUnconvertedGraphs;
00476 TAxis* m_psConvertedEtaBins;
00477 TList* m_psConvertedGraphs;
00478
00479 TAxis* m_E4ElectronEtaBins = nullptr;
00480 TList* m_E4ElectronGraphs = nullptr;
00481 TAxis* m_E4UnconvertedEtaBins = nullptr;
00482 TList* m_E4UnconvertedGraphs = nullptr;
00483 TAxis* m_E4ConvertedEtaBins = nullptr;
00484 TList* m_E4ConvertedGraphs = nullptr;
00485
00486 TAxis* m_s12ElectronEtaBins;
00487 TList* m_s12ElectronGraphs;
00488 TAxis* m_s12UnconvertedEtaBins;
00489 TList* m_s12UnconvertedGraphs;
00490 TAxis* m_s12ConvertedEtaBins;
00491 TList* m_s12ConvertedGraphs;
00492
00493 TH1D* m_pedestalL0;
00494 TH1D* m_pedestalL1;
00495 TH1D* m_pedestalL2;
00496 TH1D* m_pedestalL3;
00497
00498 TH1F* m_pedestals_es2017;
00499
00500 TH1D* m_convRadius;
00501 TH1D* m_convFakeRate;
00502 TH1D* m_convRecoEfficiency;
00503
00504 TH1D* m_leakageConverted;
00505 TH1D* m_leakageUnconverted;
00506
00507 TH1D* m_zeeES2Profile;
00508
00509 TH2D* m_pp0_elec;
00510 TH2D* m_pp0_unconv;
00511 TH2D* m_pp0_conv;
00512
00513 TH1D* m_wstot_slope_A_data;
00514 TH1D* m_wstot_slope_B_MC;
00515 TH1D* m_wstot_40GeV_data;
00516 TH1D* m_wstot_40GeV_MC;
00517 TH1D* m_wstot_pT_data_p0_electrons;
00518 TH1D* m_wstot_pT_data_p1_electrons;
00519 TH1D* m_wstot_pT_data_p0_unconverted_photons;
00520 TH1D* m_wstot_pT_data_p1_unconverted_photons;
00521 TH1D* m_wstot_pT_data_p0_converted_photons;
00522 TH1D* m_wstot_pT_data_p1_converted_photons;
00523 TH1D* m_wstot_pT_MC_p0_electrons;
00524 TH1D* m_wstot_pT_MC_p1_electrons;
00525 TH1D* m_wstot_pT_MC_p0_unconverted_photons;
00526 TH1D* m_wstot_pT_MC_p1_unconverted_photons;
00527 TH1D* m_wstot_pT_MC_p0_converted_photons;
00528 TH1D* m_wstot_pT_MC_p1_converted_photons;
00529
00530
00531
00532 std::vector<TH1D*> m_matElectronScale;
00533 std::vector<TH1D*> m_matUnconvertedScale;
00534 std::vector<TH1D*> m_matConvertedScale;
00535 std::vector<TH1D*> m_matElectronCstTerm;
00536 std::vector<TH1D*> m_matX0Additions;
00537
00538
00539
00540 TAxis* m_matElectronEtaBins;
00541 std::vector<TList*> m_matElectronGraphs;
00542
00543
00544
00545 TH1D* m_G4OverAFII_electron;
00546 TH1D* m_G4OverAFII_converted;
00547 TH1D* m_G4OverAFII_unconverted;
00548 TH1D* m_G4OverFrSh;
00549
00550 TH2F* m_G4OverAFII_resolution_electron;
00551 TH2F* m_G4OverAFII_resolution_unconverted;
00552 TH2F* m_G4OverAFII_resolution_converted;
00553
00554
00555
00556 egEnergyCorr::ESModel m_esmodel;
00557
00558
00559
00560 bool m_use_etaCalo_scales;
00561
00562
00563 bool m_applyPSCorrection;
00564 bool m_applyS12Correction;
00565
00566 bool m_initialized;
00567 bool m_use_new_resolution_model;
00568 bool m_use_stat_error_scaling;
00569
00570 bool m_use_temp_correction201215;
00571 bool m_use_temp_correction201516;
00572 bool m_use_uA2MeV_2015_first2weeks_correction;
00573 };
00574
00575 }
00576
00577
00578
00579 #endif