Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ElectronPhotonVariableCorrectionBase.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 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 #include "boost/thread/tss.hpp"
28 #include <memory>
29 #include <vector>
30 
31 // forward declarations
32 class TObject;
33 class TGraph;
34 class TH2;
35 class TEnv;
36 class TRandom3;
37 
38 // ===========================================================================
39 // Class ElectronPhotonVariableCorrectionBase
40 // ===========================================================================
41 
43 {
44 
45 public:
49  ElectronPhotonVariableCorrectionBase(const std::string& myname);
52 
57  virtual StatusCode initialize() override;
58 
68 
78 
85  const CP::CorrectionCode correctedCopy( const xAOD::Photon& in_photon, xAOD::Photon*& out_photon ) const;
86 
93  const CP::CorrectionCode correctedCopy( const xAOD::Electron& in_electron, xAOD::Electron*& out_electron) const;
94 
96  const std::string& getCorrectionVariable() { return m_correctionVariable; };
97 
103  enum class EGammaObjects{
104  Failure = 0,
105  unconvertedPhotons = 1,
107  allPhotons,
108  allElectrons,
110  }; //end enum EGammaObjects
111 
114 
118  bool applyToConvertedPhotons() const;
119 
123  bool applyToUnconvertedPhotons() const;
124 
128  bool applyToElectrons() const; //check if passed flag is compatible with electron
129 
130 private:
132  enum class parameterType{
133  Failure = 0,
134  EtaDependentTGraph = 1,
136  EtaBinned,
137  PtBinned,
141  }; // end enum ParameterType
143  std::string m_configFile;
145  std::string m_correctionVariable;
147  bool m_doGaussianSmearing = false;
149  mutable boost::thread_specific_ptr<TRandom3> m_TRandom_tls;
151  std::vector<float> m_uncorrectedDiscontinuities;
155  std::unique_ptr<TFormula> m_correctionFunctionTFormula;
159  std::vector<parameterType> m_ParameterTypeVector;
161  std::vector<TGraph*> m_graphCopies;
163  std::vector<TH2*> m_TH2Copies;
165  std::vector<float> m_useAbsEtaTH2;
167  std::vector<std::vector<float>> m_binValues;
169  std::vector<float> m_etaBins;
173  std::vector<float> m_ptBins;
175  std::vector<bool> m_interpolatePtFlags;
179  bool m_retrievedEtaBinning = false;
181  bool m_retrievedPtBinning = false;
183  std::unique_ptr<SG::AuxElement::Accessor<float>> m_variableToCorrect;
185  std::unique_ptr<SG::AuxElement::Accessor<float>> m_originalVariable;
186 
192 
198 
202  bool passedCorrectPhotonType(const xAOD::Photon& photon) const;
203 
207  bool isEqualToUncorrectedDiscontinuity(const float value) const;
208 
217 
226  const StatusCode getEtaPtBinningsFromConf(const bool getEtaBins, const bool getPtBins, const TString& binValues, const TString& interpolate, TEnv& env, const int parameter_number);
227 
237  const StatusCode getObjectFromRootFile(TEnv& env, const int parameter_number, const TString& filePathKey, const TString& nameKey, std::unique_ptr<TObject>& return_object);
238 
247  const StatusCode getCorrectionParameters(const float pt, const float eta, const float ph,
248  std::vector<float>& properties) const;
249 
256  const StatusCode get1DBinnedParameter(float& return_parameter_value, const float evalPoint, const std::vector<float>& binning, const int parameter_number) const;
257 
264  const StatusCode get2DBinnedParameter(float& return_parameter_value, const float etaEvalPoint, const float ptEvalPoint, const int parameter_number) const;
265 
272  const StatusCode get2DHistParameter(float& return_parameter_value, const float etaEvalPoint, const float phiEvalPoint, const int parameter_number) const;
273 
279  static const StatusCode findBin(int& return_bin, const float evalPoint, const std::vector<float>& binning) ;
280 
285  bool getInterpolationFlag(const int parameter_number) const;
286 
294  const StatusCode interpolate(float& return_parameter_value, const float evalPoint, const int bin, const std::vector<float>& binning, const std::vector<float>& binValues) const;
295 
301  const StatusCode getBinCenter(float& return_bin_center, const std::vector<float>& binning, const int bin_int) const;
302 
310  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) ;
311 
316  const StatusCode getDensity(float& value, const std::string& eventShapeContainer) const;
317 
325  const StatusCode getKinematicProperties(const xAOD::Egamma& egamma_object, float& pt, float& eta, float& phi) const;
326 
333  void correct(float& return_corrected_variable, const float original_variable,
334  const std::vector<float>& properties, unsigned int rndSeed = 0) const;
335 
337  TRandom3* getTLSRandomGen(unsigned int seed) const;
338 
339 }; //end class ElectronPhotonVariableCorrectionBase
340 
341 #endif
ElectronPhotonVariableCorrectionBase::m_uncorrectedDiscontinuities
std::vector< float > m_uncorrectedDiscontinuities
Values of discontinuities in the variable which should not be corrected.
Definition: ElectronPhotonVariableCorrectionBase.h:151
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:159
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
python.TestDriveDummies.properties
dictionary properties
Definition: TestDriveDummies.py:14
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:175
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
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:124
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:177
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:179
ElectronPhotonVariableCorrectionBase::parameterType::EtaBinned
@ EtaBinned
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
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:171
ElectronPhotonVariableCorrectionBase::m_numberOfFunctionParameters
int m_numberOfFunctionParameters
Number of parameters of the variable correction function.
Definition: ElectronPhotonVariableCorrectionBase.h:157
ElectronPhotonVariableCorrectionBase::~ElectronPhotonVariableCorrectionBase
~ElectronPhotonVariableCorrectionBase()
Standard destructor.
Definition: ElectronPhotonVariableCorrectionBase.h:51
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:167
ElectronPhotonVariableCorrectionBase::parameterType
parameterType
Use enum and not string for type of function parameter in order to do faster comparisons.
Definition: ElectronPhotonVariableCorrectionBase.h:132
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:161
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:103
ElectronPhotonVariableCorrectionBase::m_correctionFunctionString
std::string m_correctionFunctionString
Function to use for the variable correction, TFormula style.
Definition: ElectronPhotonVariableCorrectionBase.h:153
ElectronPhotonVariableCorrectionBase
Class to correct electron and photon MC variables.
Definition: ElectronPhotonVariableCorrectionBase.h:43
ElectronPhotonVariableCorrectionBase::m_configFile
std::string m_configFile
The name of the configuration file.
Definition: ElectronPhotonVariableCorrectionBase.h:143
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:169
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
ElectronPhotonVariableCorrectionBase::m_variableToCorrect
std::unique_ptr< SG::AuxElement::Accessor< float > > m_variableToCorrect
Accessor for the variable to be corrected.
Definition: ElectronPhotonVariableCorrectionBase.h:183
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:155
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:173
ElectronPhotonVariableCorrectionBase::parameterType::PtBinned
@ PtBinned
ElectronPhotonVariableCorrectionBase::m_doGaussianSmearing
bool m_doGaussianSmearing
Whether to apply normal correction or smearing correction.
Definition: ElectronPhotonVariableCorrectionBase.h:147
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:163
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:149
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:181
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:200
ElectronPhotonVariableCorrectionBase::getCorrectionVariable
const std::string & getCorrectionVariable()
Returns the variable which should be corrected according to the passed configuration file.
Definition: ElectronPhotonVariableCorrectionBase.h:96
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
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
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:165
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:145
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:185
ElectronPhotonVariableCorrectionBase::isAppliedTo
ElectronPhotonVariableCorrectionBase::EGammaObjects isAppliedTo()
Returns the type of EGamma object to which the correction should be applied.
Definition: ElectronPhotonVariableCorrectionBase.h:113
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