ATLAS Offline Software
ElectronPhotonVariableCorrectionBase.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ElectronPhotonVariableCorrectionBase_H
6 #define ElectronPhotonVariableCorrectionBase_H
7 
16 //ATLAS includes
17 #include "AsgTools/AsgTool.h"
19 
20 //EDM includes
21 #include "xAODEgamma/Electron.h"
22 #include "xAODEgamma/Photon.h"
23 
24 //Root includes
25 #include "TFormula.h"
26 
27 // forward declarations
28 class TObject;
29 class TGraph;
30 class TH2;
31 class TEnv;
32 class TRandom3;
33 
34 // ===========================================================================
35 // Class ElectronPhotonVariableCorrectionBase
36 // ===========================================================================
37 
39 {
40 
41 public:
45  ElectronPhotonVariableCorrectionBase(const std::string& myname);
48 
53  virtual StatusCode initialize() override;
54 
64 
74 
81  const CP::CorrectionCode correctedCopy( const xAOD::Photon& in_photon, xAOD::Photon*& out_photon ) const;
82 
89  const CP::CorrectionCode correctedCopy( const xAOD::Electron& in_electron, xAOD::Electron*& out_electron) const;
90 
92  const std::string getCorrectionVariable() { return m_correctionVariable; };
93 
99  enum class EGammaObjects{
100  Failure = 0,
101  unconvertedPhotons = 1,
103  allPhotons,
104  allElectrons,
106  }; //end enum EGammaObjects
107 
110 
114  bool applyToConvertedPhotons() const;
115 
119  bool applyToUnconvertedPhotons() const;
120 
124  bool applyToElectrons() const; //check if passed flag is compatible with electron
125 
126 private:
128  enum class parameterType{
129  Failure = 0,
130  EtaDependentTGraph = 1,
132  EtaBinned,
133  PtBinned,
137  }; // end enum ParameterType
139  std::string m_configFile;
141  std::string m_correctionVariable;
143  bool m_doGaussianSmearing = false;
145  mutable boost::thread_specific_ptr<TRandom3> m_TRandom_tls;
147  std::vector<float> m_uncorrectedDiscontinuities;
151  std::unique_ptr<TFormula> m_correctionFunctionTFormula;
155  std::vector<parameterType> m_ParameterTypeVector;
157  std::vector<TGraph*> m_graphCopies;
159  std::vector<TH2*> m_TH2Copies;
161  std::vector<float> m_useAbsEtaTH2;
163  std::vector<std::vector<float>> m_binValues;
165  std::vector<float> m_etaBins;
169  std::vector<float> m_ptBins;
171  std::vector<bool> m_interpolatePtFlags;
175  bool m_retrievedEtaBinning = false;
177  bool m_retrievedPtBinning = false;
179  std::unique_ptr<SG::AuxElement::Accessor<float>> m_variableToCorrect;
181  std::unique_ptr<SG::AuxElement::Accessor<float>> m_originalVariable;
182 
188 
194 
198  bool passedCorrectPhotonType(const xAOD::Photon& photon) const;
199 
203  bool isEqualToUncorrectedDiscontinuity(const float value) const;
204 
213 
222  const StatusCode getEtaPtBinningsFromConf(const bool getEtaBins, const bool getPtBins, const TString& binValues, const TString& interpolate, TEnv& env, const int parameter_number);
223 
233  const StatusCode getObjectFromRootFile(TEnv& env, const int parameter_number, const TString& filePathKey, const TString& nameKey, std::unique_ptr<TObject>& return_object);
234 
243  const StatusCode getCorrectionParameters(const float pt, const float eta, const float ph,
244  std::vector<float>& properties) const;
245 
252  const StatusCode get1DBinnedParameter(float& return_parameter_value, const float evalPoint, const std::vector<float>& binning, const int parameter_number) const;
253 
260  const StatusCode get2DBinnedParameter(float& return_parameter_value, const float etaEvalPoint, const float ptEvalPoint, const int parameter_number) const;
261 
268  const StatusCode get2DHistParameter(float& return_parameter_value, const float etaEvalPoint, const float phiEvalPoint, const int parameter_number) const;
269 
275  static const StatusCode findBin(int& return_bin, const float evalPoint, const std::vector<float>& binning) ;
276 
281  bool getInterpolationFlag(const int parameter_number) const;
282 
290  const StatusCode interpolate(float& return_parameter_value, const float evalPoint, const int bin, const std::vector<float>& binning, const std::vector<float>& binValues) const;
291 
297  const StatusCode getBinCenter(float& return_bin_center, const std::vector<float>& binning, const int bin_int) const;
298 
306  static float interpolate_function(const float value, const float left_bin_center, const float left_bin_value, const float right_bin_center, const float right_bin_value) ;
307 
312  const StatusCode getDensity(float& value, const std::string& eventShapeContainer) const;
313 
321  const StatusCode getKinematicProperties(const xAOD::Egamma& egamma_object, float& pt, float& eta, float& phi) const;
322 
329  void correct(float& return_corrected_variable, const float original_variable,
330  const std::vector<float>& properties, unsigned int rndSeed = 0) const;
331 
333  TRandom3* getTLSRandomGen(unsigned int seed) const;
334 
335 }; //end class ElectronPhotonVariableCorrectionBase
336 
337 #endif
ElectronPhotonVariableCorrectionBase::m_uncorrectedDiscontinuities
std::vector< float > m_uncorrectedDiscontinuities
Values of discontinuities in the variable which should not be corrected.
Definition: ElectronPhotonVariableCorrectionBase.h:147
ElectronPhotonVariableCorrectionBase::applyToConvertedPhotons
bool applyToConvertedPhotons() const
Check if the ApplyTo flag passed in the conf file is compatible with converted photons.
Definition: ElectronPhotonVariableCorrectionBase.cxx:1065
ElectronPhotonVariableCorrectionBase::getKinematicProperties
const StatusCode getKinematicProperties(const xAOD::Egamma &egamma_object, float &pt, float &eta, float &phi) const
Get the e/y kinematic properties.
Definition: ElectronPhotonVariableCorrectionBase.cxx:424
ElectronPhotonVariableCorrectionBase::initialize
virtual StatusCode initialize() override
Initialize the class instance.
Definition: ElectronPhotonVariableCorrectionBase.cxx:47
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
AddEmptyComponent.binning
binning
Definition: AddEmptyComponent.py:34
ElectronPhotonVariableCorrectionBase::m_ParameterTypeVector
std::vector< parameterType > m_ParameterTypeVector
Map of the correction function parameter number to the parameter type.
Definition: ElectronPhotonVariableCorrectionBase.h:155
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
ElectronPhotonVariableCorrectionBase::applyCorrection
const CP::CorrectionCode applyCorrection(xAOD::Photon &photon) const
Apply the correction given in the conf file to the passed photon.
Definition: ElectronPhotonVariableCorrectionBase.cxx:202
ElectronPhotonVariableCorrectionBase::m_interpolatePtFlags
std::vector< bool > m_interpolatePtFlags
List of bools whether a parameter should use linear interpolation in pT if it's some kind of pT binne...
Definition: ElectronPhotonVariableCorrectionBase.h:171
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
ElectronPhotonVariableCorrectionBase::applyToElectrons
bool applyToElectrons() const
Check if the ApplyTo flag passed in the conf file is compatible with electrons.
Definition: ElectronPhotonVariableCorrectionBase.cxx:1081
test_pyathena.pt
pt
Definition: test_pyathena.py:11
ElectronPhotonVariableCorrectionBase::correct
void correct(float &return_corrected_variable, const float original_variable, const std::vector< float > &properties, unsigned int rndSeed=0) const
Actual application of the correction to the variable.
Definition: ElectronPhotonVariableCorrectionBase.cxx:347
bin
Definition: BinsDiffFromStripMedian.h:43
athena.value
value
Definition: athena.py:122
ElectronPhotonVariableCorrectionBase::m_applyToObjects
ElectronPhotonVariableCorrectionBase::EGammaObjects m_applyToObjects
The type of objects to which the specific conf file settings are allowed to be applied to.
Definition: ElectronPhotonVariableCorrectionBase.h:173
ElectronPhotonVariableCorrectionBase::findBin
static const StatusCode findBin(int &return_bin, const float evalPoint, const std::vector< float > &binning)
Find the bin number in which the evalPoint is located in the binning binning.
Definition: ElectronPhotonVariableCorrectionBase.cxx:845
ElectronPhotonVariableCorrectionBase::getDensity
const StatusCode getDensity(float &value, const std::string &eventShapeContainer) const
Get the events energy density from the eventShape.
Definition: ElectronPhotonVariableCorrectionBase.cxx:996
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
ElectronPhotonVariableCorrectionBase::EGammaObjects::allElectrons
@ allElectrons
ElectronPhotonVariableCorrectionBase::m_retrievedEtaBinning
bool m_retrievedEtaBinning
Store if already retrieved eta binning.
Definition: ElectronPhotonVariableCorrectionBase.h:175
ElectronPhotonVariableCorrectionBase::parameterType::EtaBinned
@ EtaBinned
ElectronPhotonVariableCorrectionBase::interpolate
const StatusCode interpolate(float &return_parameter_value, const float evalPoint, const int bin, const std::vector< float > &binning, const std::vector< float > &binValues) const
Given a point x, approximates the value via linear interpolation based on the two nearest bin centers...
Definition: ElectronPhotonVariableCorrectionBase.cxx:895
ElectronPhotonVariableCorrectionBase::parameterType::EtaDependentTGraph
@ EtaDependentTGraph
ElectronPhotonVariableCorrectionBase::m_useAbsEtaBinned
bool m_useAbsEtaBinned
Store if the eta binned parameters need the eta or abs(eta) value for evaluation.
Definition: ElectronPhotonVariableCorrectionBase.h:167
ElectronPhotonVariableCorrectionBase::m_numberOfFunctionParameters
int m_numberOfFunctionParameters
Number of parameters of the variable correction function.
Definition: ElectronPhotonVariableCorrectionBase.h:153
ElectronPhotonVariableCorrectionBase::~ElectronPhotonVariableCorrectionBase
~ElectronPhotonVariableCorrectionBase()
Standard destructor.
Definition: ElectronPhotonVariableCorrectionBase.h:47
ElectronPhotonVariableCorrectionBase::m_binValues
std::vector< std::vector< float > > m_binValues
List of eta/pt dependent values, stored if needed by the respective correction function parameter.
Definition: ElectronPhotonVariableCorrectionBase.h:163
ElectronPhotonVariableCorrectionBase::parameterType
parameterType
Use enum and not string for type of function parameter in order to do faster comparisons.
Definition: ElectronPhotonVariableCorrectionBase.h:128
ElectronPhotonVariableCorrectionBase::parameterType::EtaTimesPhiTH2
@ EtaTimesPhiTH2
ElectronPhotonVariableCorrectionBase::parameterType::EtaTimesPtBinned
@ EtaTimesPtBinned
ElectronPhotonVariableCorrectionBase::parameterType::PtDependentTGraph
@ PtDependentTGraph
ElectronPhotonVariableCorrectionBase::stringToEGammaObject
ElectronPhotonVariableCorrectionBase::EGammaObjects stringToEGammaObject(const std::string &input) const
Convert input string to egamma object type.
Definition: ElectronPhotonVariableCorrectionBase.cxx:1034
ElectronPhotonVariableCorrectionBase::EGammaObjects::convertedPhotons
@ convertedPhotons
ElectronPhotonVariableCorrectionBase::m_graphCopies
std::vector< TGraph * > m_graphCopies
Copy of the TGraph from the root file, stored if needed by the respective correction function paramet...
Definition: ElectronPhotonVariableCorrectionBase.h:157
ElectronPhotonVariableCorrectionBase::get2DHistParameter
const StatusCode get2DHistParameter(float &return_parameter_value, const float etaEvalPoint, const float phiEvalPoint, const int parameter_number) const
Get the correction function parameter value if its type is eta- and pT-binned.
Definition: ElectronPhotonVariableCorrectionBase.cxx:824
Photon.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
ElectronPhotonVariableCorrectionBase::EGammaObjects
EGammaObjects
Define the categories of EGamma objects tool can be applied to.
Definition: ElectronPhotonVariableCorrectionBase.h:99
ElectronPhotonVariableCorrectionBase::m_correctionFunctionString
std::string m_correctionFunctionString
Function to use for the variable correction, TFormula style.
Definition: ElectronPhotonVariableCorrectionBase.h:149
ElectronPhotonVariableCorrectionBase
Class to correct electron and photon MC variables.
Definition: ElectronPhotonVariableCorrectionBase.h:39
ElectronPhotonVariableCorrectionBase::m_configFile
std::string m_configFile
The name of the configuration file.
Definition: ElectronPhotonVariableCorrectionBase.h:139
ElectronPhotonVariableCorrectionBase::get2DBinnedParameter
const StatusCode get2DBinnedParameter(float &return_parameter_value, const float etaEvalPoint, const float ptEvalPoint, const int parameter_number) const
Get the correction function parameter value if its type is eta- and pT-binned.
Definition: ElectronPhotonVariableCorrectionBase.cxx:773
ElectronPhotonVariableCorrectionBase::getObjectFromRootFile
const StatusCode getObjectFromRootFile(TEnv &env, const int parameter_number, const TString &filePathKey, const TString &nameKey, std::unique_ptr< TObject > &return_object)
Get a TObject storing corrections (i.e.
Definition: ElectronPhotonVariableCorrectionBase.cxx:615
ElectronPhotonVariableCorrectionBase::m_etaBins
std::vector< float > m_etaBins
List of bin boundaries in eta, stored if needed by any correction function parameter.
Definition: ElectronPhotonVariableCorrectionBase.h:165
TH2
Definition: rootspy.cxx:373
ElectronPhotonVariableCorrectionBase::EGammaObjects::Failure
@ Failure
ElectronPhotonVariableCorrectionBase::get1DBinnedParameter
const StatusCode get1DBinnedParameter(float &return_parameter_value, const float evalPoint, const std::vector< float > &binning, const int parameter_number) const
Get the correction function parameter value if its type is eta- or pT-binned.
Definition: ElectronPhotonVariableCorrectionBase.cxx:751
python.JsonUtils.properties
properties
Definition: JsonUtils.py:96
ElectronPhotonVariableCorrectionBase::m_variableToCorrect
std::unique_ptr< SG::AuxElement::Accessor< float > > m_variableToCorrect
Accessor for the variable to be corrected.
Definition: ElectronPhotonVariableCorrectionBase.h:179
ElectronPhotonVariableCorrectionBase::getInterpolationFlag
bool getInterpolationFlag(const int parameter_number) const
Return the interpolation flag of parameter parameter_number as a boolean.
Definition: ElectronPhotonVariableCorrectionBase.cxx:881
ElectronPhotonVariableCorrectionBase::m_correctionFunctionTFormula
std::unique_ptr< TFormula > m_correctionFunctionTFormula
The actual TFormula correction function.
Definition: ElectronPhotonVariableCorrectionBase.h:151
ElectronPhotonVariableCorrectionBase::m_ptBins
std::vector< float > m_ptBins
List of bin boundaries in pT, stored if needed by any correction function parameter.
Definition: ElectronPhotonVariableCorrectionBase.h:169
ElectronPhotonVariableCorrectionBase::parameterType::PtBinned
@ PtBinned
ElectronPhotonVariableCorrectionBase::m_doGaussianSmearing
bool m_doGaussianSmearing
Whether to apply normal correction or smearing correction.
Definition: ElectronPhotonVariableCorrectionBase.h:143
xAOD::Electron_v1
Definition: Electron_v1.h:34
ElectronPhotonVariableCorrectionBase::m_TH2Copies
std::vector< TH2 * > m_TH2Copies
Copy of the TH2 from the root file, stored if needed by the respective correction function parameter.
Definition: ElectronPhotonVariableCorrectionBase.h:159
ElectronPhotonVariableCorrectionBase::m_TRandom_tls
boost::thread_specific_ptr< TRandom3 > m_TRandom_tls
thread-safe TRandom3 for setting seed of random smearing correction
Definition: ElectronPhotonVariableCorrectionBase.h:145
ElectronPhotonVariableCorrectionBase::getEtaPtBinningsFromConf
const StatusCode getEtaPtBinningsFromConf(const bool getEtaBins, const bool getPtBins, const TString &binValues, const TString &interpolate, TEnv &env, const int parameter_number)
Get the eta and pt binning as well as the respective correction values from the given conf file.
Definition: ElectronPhotonVariableCorrectionBase.cxx:538
ElectronPhotonVariableCorrectionBase::parameterType::Failure
@ Failure
ElectronPhotonVariableCorrectionBase::getBinCenter
const StatusCode getBinCenter(float &return_bin_center, const std::vector< float > &binning, const int bin_int) const
Get the bin center of a bin bin_int using the binning binning.
Definition: ElectronPhotonVariableCorrectionBase.cxx:955
ElectronPhotonVariableCorrectionBase::m_retrievedPtBinning
bool m_retrievedPtBinning
Store if already retrieved pt binning.
Definition: ElectronPhotonVariableCorrectionBase.h:177
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:199
xAOD::Photon_v1
Definition: Photon_v1.h:37
ElectronPhotonVariableCorrectionBase::correctedCopy
const CP::CorrectionCode correctedCopy(const xAOD::Photon &in_photon, xAOD::Photon *&out_photon) const
Make a corrected copy of the passed photon according to the given conf file.
Definition: ElectronPhotonVariableCorrectionBase.cxx:387
ElectronPhotonVariableCorrectionBase::stringToParameterType
ElectronPhotonVariableCorrectionBase::parameterType stringToParameterType(const std::string &input) const
Convert input string to a parameter function type.
Definition: ElectronPhotonVariableCorrectionBase.cxx:1009
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
ElectronPhotonVariableCorrectionBase::getCorrectionVariable
const std::string getCorrectionVariable()
Returns the variable which should be corrected according to the passed configuration file.
Definition: ElectronPhotonVariableCorrectionBase.h:92
ElectronPhotonVariableCorrectionBase::isEqualToUncorrectedDiscontinuity
bool isEqualToUncorrectedDiscontinuity(const float value) const
Check if the value passed is equal to one of the values passed via the UncorrectedDiscontinuites flag...
Definition: ElectronPhotonVariableCorrectionBase.cxx:403
ElectronPhotonVariableCorrectionBase::EGammaObjects::allEGammaObjects
@ allEGammaObjects
ElectronPhotonVariableCorrectionBase::m_useAbsEtaTH2
std::vector< float > m_useAbsEtaTH2
Store the lowest eta bin boundary: used for checking if the respective TH2 needs the eta or abs(eta) ...
Definition: ElectronPhotonVariableCorrectionBase.h:161
ElectronPhotonVariableCorrectionBase::parameterType::EventDensity
@ EventDensity
ElectronPhotonVariableCorrectionBase::getCorrectionParameters
const StatusCode getCorrectionParameters(const float pt, const float eta, const float ph, std::vector< float > &properties) const
Get the actual parameters of the TF1 function used for the current e/y object to be corrected.
Definition: ElectronPhotonVariableCorrectionBase.cxx:681
CorrectionCode.h
Electron.h
ElectronPhotonVariableCorrectionBase::passedCorrectPhotonType
bool passedCorrectPhotonType(const xAOD::Photon &photon) const
Check if the photon which was passed to the tool has the correct type, if only (un)converted photons ...
Definition: ElectronPhotonVariableCorrectionBase.cxx:1055
ElectronPhotonVariableCorrectionBase::getTLSRandomGen
TRandom3 * getTLSRandomGen(unsigned int seed) const
Getting thread safe random number generator (and resetting its seed)
Definition: ElectronPhotonVariableCorrectionBase.cxx:1089
ElectronPhotonVariableCorrectionBase::m_correctionVariable
std::string m_correctionVariable
The name of the variable to correct.
Definition: ElectronPhotonVariableCorrectionBase.h:141
AsgTool.h
python.DataFormatRates.env
env
Definition: DataFormatRates.py:32
ElectronPhotonVariableCorrectionBase::EGammaObjects::allPhotons
@ allPhotons
ElectronPhotonVariableCorrectionBase::m_originalVariable
std::unique_ptr< SG::AuxElement::Accessor< float > > m_originalVariable
Accessor to store the original value of the corrected variable.
Definition: ElectronPhotonVariableCorrectionBase.h:181
ElectronPhotonVariableCorrectionBase::isAppliedTo
ElectronPhotonVariableCorrectionBase::EGammaObjects isAppliedTo()
Returns the type of EGamma object to which the correction should be applied.
Definition: ElectronPhotonVariableCorrectionBase.h:109
ElectronPhotonVariableCorrectionBase::ElectronPhotonVariableCorrectionBase
ElectronPhotonVariableCorrectionBase(const std::string &myname)
Standard constructor.
Definition: ElectronPhotonVariableCorrectionBase.cxx:37
ElectronPhotonVariableCorrectionBase::getParameterInformationFromConf
const StatusCode getParameterInformationFromConf(TEnv &env, const int parameter_number, const ElectronPhotonVariableCorrectionBase::parameterType type)
Get the relevant information for a correction function parameter from the given conf file.
Definition: ElectronPhotonVariableCorrectionBase.cxx:460
ElectronPhotonVariableCorrectionBase::interpolate_function
static float interpolate_function(const float value, const float left_bin_center, const float left_bin_value, const float right_bin_center, const float right_bin_value)
Returns the linearly intrpolated value of value given the bin centers and bin values.
Definition: ElectronPhotonVariableCorrectionBase.cxx:991
ElectronPhotonVariableCorrectionBase::applyToUnconvertedPhotons
bool applyToUnconvertedPhotons() const
Check if the ApplyTo flag passed in the conf file is compatible with uconverted photons.
Definition: ElectronPhotonVariableCorrectionBase.cxx:1073
ElectronPhotonVariableCorrectionBase::EGammaObjects::unconvertedPhotons
@ unconvertedPhotons