56 return StatusCode::FAILURE;
62 ATH_MSG_ERROR(
"Config file string is empty. Please provide a config file to the tool.");
63 return StatusCode::FAILURE;
70 env.IgnoreDuplicates(
false);
73 if (env.Lookup(
"Variable"))
79 ATH_MSG_ERROR(
"Correction variable is empty or not in configuration file.");
80 return StatusCode::FAILURE;
91 if (env.Lookup(
"doGaussianSmearing"))
96 if (env.Lookup(
"Function"))
104 ATH_MSG_ERROR(
"Correction function is empty or not in configuration file.");
105 return StatusCode::FAILURE;
109 if (env.Lookup(
"nFunctionParameters"))
117 ATH_MSG_ERROR(
"When using Gaussian smearing, there can only be two " <<
118 "function parameters, the Gaussian mean and the Gaussian width");
119 return StatusCode::FAILURE;
125 ATH_MSG_ERROR(
"You did not specify the number of parameters in the correction function.");
126 return StatusCode::FAILURE;
141 TString
parameterType = TString::Format(
"Parameter%dType",parameter_itr);
148 ATH_MSG_ERROR(
"Parameter " << parameter_itr <<
" read-in failed, not an allowed parameter type.");
149 return StatusCode::FAILURE;
159 return StatusCode::FAILURE;
164 if (env.Lookup(
"ApplyTo"))
166 std::string applyToObjectsFlag = env.GetValue(
"ApplyTo",
"Failure");
171 ATH_MSG_ERROR(
"You did not correctly specify the object type in the ApplyTo flag.");
172 return StatusCode::FAILURE;
178 ATH_MSG_ERROR(
"You did not specify to which objects this conf file should be applied to (ApplyTo).");
179 return StatusCode::FAILURE;
183 if (env.Lookup(
"UncorrectedDiscontinuities"))
189 ATH_MSG_ERROR(
"Did not find any discontinuities to not correct, despite finding the flag UncorrectedDiscontinuities.");
190 return StatusCode::FAILURE;
195 return StatusCode::SUCCESS;
206 ATH_MSG_ERROR(
"You specified in the conf file that the tool should only be used for (un-)converted photons, but passed the other conversion type.");
212 float original_variable = 0.;
215 original_variable = (*m_variableToCorrect)(photon);
217 (*m_originalVariable)(photon) = original_variable;
237 ATH_MSG_ERROR(
"Could not retrieve kinematic properties of this photon object.");
241 std::vector<float> properties;
244 ATH_MSG_ERROR(
"Could not get the correction parameters for this photon object.");
259 ATH_MSG_ERROR(
"You want to correct electrons, but passed a conf file with ApplyTo flag not set for electrons. Are you using the correct conf file?");
265 float original_variable = 0.;
275 ATH_MSG_ERROR(
"you are trying to fudge transformed_e_probability_ht but the electron has no track!");
280 ATH_MSG_ERROR(
"you are trying to fudge transformed_e_probability_ht but eProbabilityHT is not present");
284 const double tau = 15.0;
285 const double fEpsilon = 1.0e-30;
286 double pid_tmp = TRT_PID;
288 pid_tmp = 1.0 - 1.0e-15;
289 else if (pid_tmp <= fEpsilon)
291 double trans_TRT_PID = -std::log(1.0 / pid_tmp - 1.0) * (1. / double(tau));
293 (*m_variableToCorrect)(electron) = (
float)trans_TRT_PID;
298 original_variable = (*m_variableToCorrect)(electron);
300 (*m_originalVariable)(electron) = original_variable;
320 ATH_MSG_ERROR(
"Could not retrieve kinematic properties of this electron object.");
324 std::vector<float> properties;
327 ATH_MSG_ERROR(
"Could not get the correction parameters for this electron object.");
333 unsigned int rndSeed(0);
336 rndSeed = 1 +
static_cast<unsigned int>(pt + std::abs(
eta) * 1E3 + std::abs(
phi) * 1E6);
347 const std::vector<float>& properties,
348 unsigned int rndSeed)
const
355 double x = original_variable;
356 std::vector<double> dpars (properties.begin(), properties.end());
364 const double gaussMean = properties.at(0);
365 const double gaussAbsWidth = std::abs(properties.at(1));
368 if (gaussAbsWidth == 0.0)
370 return_corrected_variable = original_variable + gaussMean;
375 return_corrected_variable = original_variable +
430 if ( cluster ==
nullptr )
432 ATH_MSG_ERROR(
"EGamma object calorimeter cluster is NULL: Cluster " << cluster);
433 return StatusCode::FAILURE;
440 const double energy = cluster->
e();
443 const double cosheta = cosh(
eta);
444 et = (cosheta != 0.) ? energy/cosheta : 0.;
450 ATH_MSG_WARNING(
"Encountered EGamma object with strange pT: " << pt <<
" MeV. Correcting as if it has a pT of 0.");
456 return StatusCode::SUCCESS;
462 bool getEtaBins =
false;
463 bool getPtBins =
false;
465 TString filePathKey = TString::Format(
"Parameter%dFile",parameter_number);
466 TString graphNameKey = TString::Format(
"Parameter%dGraphName",parameter_number);
467 TString histNameKey = TString::Format(
"Parameter%dTH2Name",parameter_number);
468 TString binValues = TString::Format(
"Parameter%dValues",parameter_number);
469 TString
interpolate = TString::Format(
"Parameter%dInterpolate",parameter_number);
480 return StatusCode::FAILURE;
482 auto* graph =
dynamic_cast<TGraph*
>(
object.get());
484 ATH_MSG_ERROR(
"Object for parameter " << parameter_number <<
" is not a TGraph.");
485 return StatusCode::FAILURE;
487 m_graphCopies.at(parameter_number) = std::unique_ptr<TGraph>(
static_cast<TGraph*
>(
object.
release()));
508 return StatusCode::FAILURE;
510 auto* th2 =
dynamic_cast<TH2*
>(
object.get());
512 ATH_MSG_ERROR(
"Object for parameter " << parameter_number <<
" is not a TH2.");
513 return StatusCode::FAILURE;
516 auto* axis = th2->GetXaxis();
519 return StatusCode::FAILURE;
521 const float lowest_bin_boundary = axis->GetBinLowEdge(1);
522 if (lowest_bin_boundary > 0) {
524 "Lowest bin edge in TH2 for parameter "
526 <<
" is > 0. Please provide the TH2 including corrections either "
527 "for the positive eta range (starting at 0), or the whole eta "
528 "range (starting with a negative dummy value which is treated "
530 return StatusCode::FAILURE;
534 std::unique_ptr<TH2>(
static_cast<TH2*
>(
object.
release()));
539 return StatusCode::SUCCESS;
546 if (getEtaBins || getPtBins)
550 return StatusCode::SUCCESS;
559 if (env.Lookup(
"EtaBins"))
566 ATH_MSG_ERROR(
"Lowest bin edge given for parameter " << parameter_number <<
" is > 0. Please provide the lower bin edges of your correction binning in the conf file, starting with either 0 (for corrections symmetric in eta) or a negative number (being treated as -infinity).");
567 return StatusCode::FAILURE;
579 return StatusCode::FAILURE;
586 if (env.Lookup(
"PtBins"))
593 ATH_MSG_ERROR(
"Lowest bin edge given for parameter " << parameter_number <<
" is not 0. Please provide the lower bin edges of your correction binning in the conf file, starting with 0.");
594 return StatusCode::FAILURE;
602 return StatusCode::FAILURE;
611 if ( getEtaBins || getPtBins)
614 if (env.Lookup(binValues))
622 return StatusCode::FAILURE;
627 return StatusCode::SUCCESS;
630std::unique_ptr<TObject>
634 TString filePath =
"";
635 TString objectName =
"";
637 if (env.Lookup(filePathKey))
644 ATH_MSG_ERROR(
"Could not locate Parameter" << parameter_number <<
" TObject file.");
650 ATH_MSG_ERROR(
"Could not retrieve Parameter" << parameter_number <<
" file path.");
654 if (env.Lookup(nameKey))
657 objectName = env.GetValue(nameKey.Data(),
"");
661 ATH_MSG_ERROR(
"Could not retrieve Parameter" << parameter_number <<
" object name.");
665 auto file = std::make_unique<TFile>(filePath.Data(),
"READ");
669 TObject*
object =
file->Get(objectName.Data());
671 ATH_MSG_ERROR(
"Could not find TObject " << objectName <<
" in file " << filePath);
675 auto returnObj = std::unique_ptr<TObject> (object->Clone());
677 if (
auto pHist =
dynamic_cast<TH1*
>(returnObj.get());pHist !=
nullptr)
679 pHist->SetDirectory(
nullptr);
684 ATH_MSG_ERROR(
"Could not open Parameter" << parameter_number <<
" TObject file " << filePath.Data());
690 std::vector<float>& properties)
const
695 float etaForBinned =
eta;
697 { etaForBinned = std::abs(
eta); }
708 const std::string shapeStr{
"TopoClusterIsoCentralEventShape"};
715 properties.at(parameter_itr) =
m_graphCopies.at(parameter_itr)->Eval(etaForBinned);
719 properties.at(parameter_itr) =
m_graphCopies.at(parameter_itr)->Eval(pt);
736 float etaForThisTH2 =
eta;
738 { etaForThisTH2 = std::abs(
eta); }
753 for (
auto p : properties)
757 return StatusCode::SUCCESS;
775 return_parameter_value =
m_binValues.at(parameter_number).at(
bin);
779 return StatusCode::SUCCESS;
808 int bin_number_in_bin_values =
m_etaBins.size() * ptBin + etaBin;
815 std::vector<float> tmp_binValuesAtEtaSlice;
817 for (
unsigned int binValue_itr = etaBin; binValue_itr <
m_binValues.at(parameter_number).
size(); binValue_itr +=
m_etaBins.size())
819 tmp_binValuesAtEtaSlice.push_back(
m_binValues.at(parameter_number).at(binValue_itr));
826 return_parameter_value =
m_binValues.at(parameter_number).at(bin_number_in_bin_values);
830 return StatusCode::SUCCESS;
836 float this_etaEvalPoint = etaEvalPoint;
837 ATH_MSG_VERBOSE(
"eta = " << this_etaEvalPoint <<
" phi = " << phiEvalPoint);
841 this_etaEvalPoint =
m_TH2Copies.at(parameter_number)->GetXaxis()->GetBinCenter(1);
842 ATH_MSG_VERBOSE(
"eta was out of bounds of TH2, corrected to eta = " << this_etaEvalPoint);
845 const int bin_number =
m_TH2Copies.at(parameter_number)->FindBin(this_etaEvalPoint, phiEvalPoint);
846 return_parameter_value =
m_TH2Copies.at(parameter_number)->GetBinContent(bin_number);
850 return StatusCode::SUCCESS;
859 if (evalPoint < binning.at(0))
863 return StatusCode::SUCCESS;
867 for (
unsigned int bin_itr = 0; bin_itr < binning.size()-1; bin_itr++)
870 if (evalPoint > binning.at(bin_itr) && evalPoint < binning.at(bin_itr + 1))
873 return_bin = bin_itr;
881 if (return_bin == -1)
883 return_bin = binning.size()-1;
887 return StatusCode::SUCCESS;
892 bool do_interpolation =
false;
901 return do_interpolation;
907 if (binning.size() != binValues.size())
909 ATH_MSG_ERROR(
"Binning and bin values have different sizes.");
910 return StatusCode::FAILURE;
914 float leftmost_bin_center = 0;
916 if (evalPoint <= leftmost_bin_center)
918 return_parameter_value = binValues.at(0);
919 return StatusCode::SUCCESS;
923 float rightmost_bin_center = 0;
925 if (evalPoint >= rightmost_bin_center)
927 return_parameter_value = binValues.at(binValues.size()-1);
928 return StatusCode::SUCCESS;
931 float left_bin_center = 0;
932 float right_bin_center = 0;
933 float left_bin_value = 0;
934 float right_bin_value = 0;
935 float current_bin_center = 0;
939 if (evalPoint <= current_bin_center)
944 left_bin_value = binValues.at(
bin-1);
945 right_bin_value = binValues.at(
bin);
952 left_bin_value = binValues.at(
bin);
953 right_bin_value = binValues.at(
bin+1);
955 ATH_MSG_VERBOSE(
"bin centers : " << left_bin_center <<
" " << right_bin_center <<
" current : " << current_bin_center <<
" values : " << left_bin_value <<
" " << right_bin_value);
958 return_parameter_value =
interpolate_function(evalPoint, left_bin_center, left_bin_value, right_bin_center, right_bin_value);
961 return StatusCode::SUCCESS;
969 return StatusCode::FAILURE;
973 long unsigned int bin = bin_int;
975 if (
bin >= binning.size())
977 ATH_MSG_ERROR(
"The requested bin is out of range of the passed binning.");
978 return StatusCode::FAILURE;
984 if (
bin == binning.size()-1)
987 float bin_width = binning.at(
bin) - binning.at(
bin-1);
988 return_bin_center = binning.at(
bin) + 0.5 * bin_width;
993 return_bin_center = 0.5 * (binning.at(
bin) + binning.at(
bin+1));
997 return StatusCode::SUCCESS;
1002 return left_bin_value + (value - left_bin_center) * (right_bin_value - left_bin_value) / (right_bin_center - left_bin_center);
1009 if(
evtStore()->retrieve(evtShape, eventShapeContainer).isFailure()){
1010 ATH_MSG_ERROR(
"Cannot retrieve density container " << eventShapeContainer);
1011 return StatusCode::FAILURE;
1015 return StatusCode::SUCCESS;
1021 if( input ==
"EtaDependentTGraph")
1023 else if( input ==
"PtDependentTGraph")
1025 else if( input ==
"EtaBinned")
1027 else if( input ==
"PtBinned")
1029 else if( input ==
"EtaTimesPtBinned")
1031 else if( input ==
"EtaTimesPhiTH2")
1033 else if( input ==
"EventDensity")
1038 ATH_MSG_ERROR(input.c_str() <<
" is not an allowed parameter type.");
1046 if( input ==
"unconvertedPhotons" )
1048 else if( input ==
"convertedPhotons" )
1050 else if( input ==
"allPhotons" )
1052 else if( input ==
"allElectrons" )
1054 else if( input ==
"allEGammaObjects" )
1059 ATH_MSG_ERROR(input.c_str() <<
" is not an allowed EGamma object type to apply corrections to.");
1068 bool isUnconvertedPhoton = !isConvertedPhoton;
1094 return (applyToAllEGamma || applyToAllElectrons);
1102 random =
new TRandom3();
1105 random->SetSeed(seed);
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
size_t size() const
Number of registered mappings.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ Ok
The correction was done successfully.
std::unique_ptr< TFormula > m_correctionFunctionTFormula
The actual TFormula correction function.
std::vector< std::vector< float > > m_binValues
List of eta/pt dependent values, stored if needed by the respective correction function parameter.
boost::thread_specific_ptr< TRandom3 > m_TRandom_tls
thread-safe TRandom3 for setting seed of random smearing correction
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.
bool m_retrievedPtBinning
Store if already retrieved pt binning.
bool m_doGaussianSmearing
Whether to apply normal correction or smearing correction.
bool applyToConvertedPhotons() const
Check if the ApplyTo flag passed in the conf file is compatible with converted photons.
const StatusCode getDensity(float &value, const std::string &eventShapeContainer) const
Get the events energy density from the eventShape.
std::vector< float > m_useAbsEtaTH2
Store the lowest eta bin boundary: used for checking if the respective TH2 needs the eta or abs(eta) ...
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.
bool applyToUnconvertedPhotons() const
Check if the ApplyTo flag passed in the conf file is compatible with uconverted photons.
std::vector< float > m_ptBins
List of bin boundaries in pT, stored if needed by any correction function parameter.
bool m_retrievedEtaBinning
Store if already retrieved eta binning.
bool isEqualToUncorrectedDiscontinuity(const float value) const
Check if the value passed is equal to one of the values passed via the UncorrectedDiscontinuites flag...
parameterType
Use enum and not string for type of function parameter in order to do faster comparisons.
std::unique_ptr< SG::Accessor< float > > m_originalVariable
Accessor to store the original value of the corrected variable.
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.
std::string m_correctionFunctionString
Function to use for the variable correction, TFormula style.
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.
std::vector< std::unique_ptr< TH2 > > m_TH2Copies
Copy of the TH2 from the root file, stored if needed by the respective correction function parameter.
std::vector< parameterType > m_ParameterTypeVector
Map of the correction function parameter number to the parameter type.
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.
std::string m_configFile
The name of the configuration file.
TRandom3 * getTLSRandomGen(unsigned int seed) const
Getting thread safe random number generator (and resetting its seed).
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.
const CP::CorrectionCode applyCorrection(xAOD::Photon &photon) const
Apply the correction given in the conf file to the passed photon.
std::vector< float > m_uncorrectedDiscontinuities
Values of discontinuities in the variable which should not be corrected.
virtual StatusCode initialize() override
Initialize the class instance.
std::unique_ptr< TObject > getObjectFromRootFile(TEnv &env, const int parameter_number, const TString &filePathKey, const TString &nameKey)
Get a TObject storing corrections (i.e.
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.
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...
std::vector< float > m_etaBins
List of bin boundaries in eta, stored if needed by any correction function parameter.
ElectronPhotonVariableCorrectionBase::parameterType stringToParameterType(const std::string &input) const
Convert input string to a parameter function type.
bool getInterpolationFlag(const int parameter_number) const
Return the interpolation flag of parameter parameter_number as a boolean.
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.
ElectronPhotonVariableCorrectionBase::EGammaObjects stringToEGammaObject(const std::string &input) const
Convert input string to egamma object type.
int m_numberOfFunctionParameters
Number of parameters of the variable correction function.
bool applyToElectrons() const
Check if the ApplyTo flag passed in the conf file is compatible with electrons.
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.
std::string m_correctionVariable
The name of the variable to correct.
ElectronPhotonVariableCorrectionBase(const std::string &myname)
Standard constructor.
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.
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...
const StatusCode getKinematicProperties(const xAOD::Egamma &egamma_object, float &pt, float &eta, float &phi) const
Get the e/y kinematic properties.
EGammaObjects
Define the categories of EGamma objects tool can be applied to.
std::unique_ptr< SG::Accessor< float > > m_variableToCorrect
Accessor for the variable to be corrected.
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 ...
bool m_useAbsEtaBinned
Store if the eta binned parameters need the eta or abs(eta) value for evaluation.
std::vector< std::unique_ptr< TGraph > > m_graphCopies
Copy of the TGraph from the root file, stored if needed by the respective correction function paramet...
ElectronPhotonVariableCorrectionBase::EGammaObjects m_applyToObjects
The type of objects to which the specific conf file settings are allowed to be applied to.
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.
float phiBE(const unsigned layer) const
Get the phi in one layer of the EM Calo.
virtual double e() const
The total energy of the particle.
float etaBE(const unsigned layer) const
Get the eta in one layer of the EM Calo.
const xAOD::CaloCluster * caloCluster(size_t index=0) const
Pointer to the xAOD::CaloCluster/s that define the electron candidate.
bool getDensity(EventDensityID id, double &v) const
Get a density variable from the object.
static std::string release
std::vector< float > HelperFloat(const std::string &input, TEnv &env)
bool isConvertedPhoton(const xAOD::Egamma *eg, bool excludeTRT=false)
is the object a converted photon
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Egamma_v1 Egamma
Definition of the current "egamma version".
Photon_v1 Photon
Definition of the current "egamma version".
EventShape_v1 EventShape
Definition of the current event format version.
@ eProbabilityHT
Electron probability from High Threshold (HT) information [float].
Electron_v1 Electron
Definition of the current "egamma version".
Extra patterns decribing particle interation process.