|
ATLAS Offline Software
|
Go to the documentation of this file.
57 return StatusCode::FAILURE;
63 ATH_MSG_ERROR(
"Config file string is empty. Please provide a config file to the tool.");
64 return StatusCode::FAILURE;
71 env.IgnoreDuplicates(
false);
74 if (
env.Lookup(
"Variable"))
80 ATH_MSG_ERROR(
"Correction variable is empty or not in configuration file.");
81 return StatusCode::FAILURE;
92 if (
env.Lookup(
"doGaussianSmearing"))
97 if (
env.Lookup(
"Function"))
105 ATH_MSG_ERROR(
"Correction function is empty or not in configuration file.");
106 return StatusCode::FAILURE;
110 if (
env.Lookup(
"nFunctionParameters"))
118 ATH_MSG_ERROR(
"When using Gaussian smearing, there can only be two " <<
119 "function parameters, the Gaussian mean and the Gaussian width");
120 return StatusCode::FAILURE;
126 ATH_MSG_ERROR(
"You did not specify the number of parameters in the correction function.");
127 return StatusCode::FAILURE;
149 ATH_MSG_ERROR(
"Parameter " << parameter_itr <<
" read-in failed, not an allowed parameter type.");
150 return StatusCode::FAILURE;
160 return StatusCode::FAILURE;
165 if (
env.Lookup(
"ApplyTo"))
167 std::string applyToObjectsFlag =
env.GetValue(
"ApplyTo",
"Failure");
172 ATH_MSG_ERROR(
"You did not correctly specify the object type in the ApplyTo flag.");
173 return StatusCode::FAILURE;
179 ATH_MSG_ERROR(
"You did not specify to which objects this conf file should be applied to (ApplyTo).");
180 return StatusCode::FAILURE;
184 if (
env.Lookup(
"UncorrectedDiscontinuities"))
190 ATH_MSG_ERROR(
"Did not find any discontinuities to not correct, despite finding the flag UncorrectedDiscontinuities.");
191 return StatusCode::FAILURE;
196 return StatusCode::SUCCESS;
207 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.");
213 float original_variable = 0.;
216 original_variable = (*m_variableToCorrect)(
photon);
218 (*m_originalVariable)(
photon) = original_variable;
238 ATH_MSG_ERROR(
"Could not retrieve kinematic properties of this photon object.");
245 ATH_MSG_ERROR(
"Could not get the correction parameters for this photon object.");
260 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?");
266 float original_variable = 0.;
276 ATH_MSG_ERROR(
"you are trying to fudge transformed_e_probability_ht but the electron has no track!");
281 ATH_MSG_ERROR(
"you are trying to fudge transformed_e_probability_ht but eProbabilityHT is not present");
285 const double tau = 15.0;
286 const double fEpsilon = 1.0e-30;
287 double pid_tmp = TRT_PID;
289 pid_tmp = 1.0 - 1.0e-15;
290 else if (pid_tmp <= fEpsilon)
292 double trans_TRT_PID = -
std::log(1.0 / pid_tmp - 1.0) * (1. /
double(tau));
294 (*m_variableToCorrect)(
electron) = (
float)trans_TRT_PID;
299 original_variable = (*m_variableToCorrect)(
electron);
301 (*m_originalVariable)(
electron) = original_variable;
321 ATH_MSG_ERROR(
"Could not retrieve kinematic properties of this electron object.");
328 ATH_MSG_ERROR(
"Could not get the correction parameters for this electron object.");
334 unsigned int rndSeed(0);
337 rndSeed = 1 +
static_cast<unsigned int>(
pt + std::abs(
eta) * 1E3 + std::abs(
phi) * 1E6);
349 unsigned int rndSeed)
const
356 double x = original_variable;
366 const double gaussAbsWidth = std::abs(
properties.at(1));
369 if (gaussAbsWidth == 0.0)
371 return_corrected_variable = original_variable + gaussMean;
376 return_corrected_variable = original_variable +
431 if ( cluster ==
nullptr )
433 ATH_MSG_ERROR(
"EGamma object calorimeter cluster is NULL: Cluster " << cluster);
434 return StatusCode::FAILURE;
441 const double energy = cluster->
e();
444 const double cosheta = cosh(
eta);
445 et = (cosheta != 0.) ?
energy/cosheta : 0.;
451 ATH_MSG_WARNING(
"Encountered EGamma object with strange pT: " <<
pt <<
" MeV. Correcting as if it has a pT of 0.");
457 return StatusCode::SUCCESS;
463 bool getEtaBins =
false;
464 bool getPtBins =
false;
466 TString filePathKey =
TString::Format(
"Parameter%dFile",parameter_number);
467 TString graphNameKey =
TString::Format(
"Parameter%dGraphName",parameter_number);
468 TString histNameKey =
TString::Format(
"Parameter%dTH2Name",parameter_number);
469 TString binValues =
TString::Format(
"Parameter%dValues",parameter_number);
479 std::unique_ptr<TObject> graph;
500 std::unique_ptr<TObject> th2;
502 m_TH2Copies.at(parameter_number) = (TH2*)th2.get();
506 float lowest_bin_boundary = ((TH2*)th2.get())->GetXaxis()->GetBinLowEdge(1);
508 if (lowest_bin_boundary > 0)
510 ATH_MSG_ERROR(
"Lowest bin edge in TH2 for parameter " << parameter_number <<
" is > 0. Please provide the TH2 including corrections either for the positive eta range (starting at 0), or the whole eta range (starting with a negative dummy value which is treated as -infinity.");
511 return StatusCode::FAILURE;
524 return StatusCode::SUCCESS;
531 if (getEtaBins || getPtBins)
535 return StatusCode::SUCCESS;
544 if (
env.Lookup(
"EtaBins"))
551 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).");
552 return StatusCode::FAILURE;
564 return StatusCode::FAILURE;
571 if (
env.Lookup(
"PtBins"))
578 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.");
579 return StatusCode::FAILURE;
587 return StatusCode::FAILURE;
596 if ( getEtaBins || getPtBins)
599 if (
env.Lookup(binValues))
607 return StatusCode::FAILURE;
612 return StatusCode::SUCCESS;
619 TString objectName =
"";
621 if (
env.Lookup(filePathKey))
628 ATH_MSG_ERROR(
"Could not locate Parameter" << parameter_number <<
" TObject file.");
629 return StatusCode::FAILURE;
634 ATH_MSG_ERROR(
"Could not retrieve Parameter" << parameter_number <<
" file path.");
635 return StatusCode::FAILURE;
638 if (
env.Lookup(nameKey))
641 objectName =
env.GetValue(nameKey.Data(),
"");
645 ATH_MSG_ERROR(
"Could not retrieve Parameter" << parameter_number <<
" object name.");
646 return StatusCode::FAILURE;
649 std::unique_ptr<TFile>
file (
new TFile(
filePath.Data(),
"READ"));
654 if (
file->Get(objectName))
656 return_object = std::unique_ptr<TObject> (
file->Get(objectName.Data())->Clone());
658 if (
dynamic_cast<TH1*
>(return_object.get()) !=
nullptr)
660 dynamic_cast<TH1*
>(return_object.get())->
SetDirectory(
nullptr);
667 return StatusCode::FAILURE;
672 ATH_MSG_ERROR(
"Could not open Parameter" << parameter_number <<
" TObject file " <<
filePath.Data());
673 return StatusCode::FAILURE;
677 return StatusCode::SUCCESS;
687 float etaForBinned =
eta;
689 { etaForBinned = std::abs(
eta); }
727 float etaForThisTH2 =
eta;
729 { etaForThisTH2 = std::abs(
eta); }
748 return StatusCode::SUCCESS;
766 return_parameter_value =
m_binValues.at(parameter_number).at(
bin);
770 return StatusCode::SUCCESS;
806 std::vector<float> tmp_binValuesAtEtaSlice;
810 tmp_binValuesAtEtaSlice.push_back(
m_binValues.at(parameter_number).at(binValue_itr));
817 return_parameter_value =
m_binValues.at(parameter_number).at(bin_number_in_bin_values);
821 return StatusCode::SUCCESS;
827 float this_etaEvalPoint = etaEvalPoint;
828 ATH_MSG_VERBOSE(
"eta = " << this_etaEvalPoint <<
" phi = " << phiEvalPoint);
832 this_etaEvalPoint =
m_TH2Copies.at(parameter_number)->GetXaxis()->GetBinCenter(1);
833 ATH_MSG_VERBOSE(
"eta was out of bounds of TH2, corrected to eta = " << this_etaEvalPoint);
836 const int bin_number =
m_TH2Copies.at(parameter_number)->FindBin(this_etaEvalPoint, phiEvalPoint);
837 return_parameter_value =
m_TH2Copies.at(parameter_number)->GetBinContent(bin_number);
841 return StatusCode::SUCCESS;
854 return StatusCode::SUCCESS;
858 for (
unsigned int bin_itr = 0; bin_itr <
binning.size()-1; bin_itr++)
861 if (evalPoint >
binning.at(bin_itr) && evalPoint <
binning.at(bin_itr + 1))
864 return_bin = bin_itr;
872 if (return_bin == -1)
878 return StatusCode::SUCCESS;
883 bool do_interpolation =
false;
892 return do_interpolation;
898 if (
binning.size() != binValues.size())
900 ATH_MSG_ERROR(
"Binning and bin values have different sizes.");
901 return StatusCode::FAILURE;
905 float leftmost_bin_center = 0;
907 if (evalPoint <= leftmost_bin_center)
909 return_parameter_value = binValues.at(0);
910 return StatusCode::SUCCESS;
914 float rightmost_bin_center = 0;
916 if (evalPoint >= rightmost_bin_center)
918 return_parameter_value = binValues.at(binValues.size()-1);
919 return StatusCode::SUCCESS;
922 float left_bin_center = 0;
923 float right_bin_center = 0;
924 float left_bin_value = 0;
925 float right_bin_value = 0;
926 float current_bin_center = 0;
930 if (evalPoint <= current_bin_center)
935 left_bin_value = binValues.at(
bin-1);
936 right_bin_value = binValues.at(
bin);
943 left_bin_value = binValues.at(
bin);
944 right_bin_value = binValues.at(
bin+1);
946 ATH_MSG_VERBOSE(
"bin centers : " << left_bin_center <<
" " << right_bin_center <<
" current : " << current_bin_center <<
" values : " << left_bin_value <<
" " << right_bin_value);
949 return_parameter_value =
interpolate_function(evalPoint, left_bin_center, left_bin_value, right_bin_center, right_bin_value);
952 return StatusCode::SUCCESS;
960 return StatusCode::FAILURE;
964 long unsigned int bin = bin_int;
968 ATH_MSG_ERROR(
"The requested bin is out of range of the passed binning.");
969 return StatusCode::FAILURE;
988 return StatusCode::SUCCESS;
993 return left_bin_value + (
value - left_bin_center) * (right_bin_value - left_bin_value) / (right_bin_center - left_bin_center);
1001 ATH_MSG_ERROR(
"Cannot retrieve density container " << eventShapeContainer);
1002 return StatusCode::FAILURE;
1006 return StatusCode::SUCCESS;
1012 if(
input ==
"EtaDependentTGraph")
1014 else if(
input ==
"PtDependentTGraph")
1016 else if(
input ==
"EtaBinned")
1018 else if(
input ==
"PtBinned")
1020 else if(
input ==
"EtaTimesPtBinned")
1022 else if(
input ==
"EtaTimesPhiTH2")
1024 else if(
input ==
"EventDensity")
1037 if(
input ==
"unconvertedPhotons" )
1039 else if(
input ==
"convertedPhotons" )
1041 else if(
input ==
"allPhotons" )
1043 else if(
input ==
"allElectrons" )
1045 else if(
input ==
"allEGammaObjects" )
1050 ATH_MSG_ERROR(
input.c_str() <<
" is not an allowed EGamma object type to apply corrections to.");
1085 return (applyToAllEGamma || applyToAllElectrons);
1093 random =
new TRandom3();
1096 random->SetSeed(seed);
def retrieve(aClass, aKey=None)
bool getDensity(EventDensityID id, double &v) const
Get a density variable from the object.
std::vector< float > m_uncorrectedDiscontinuities
Values of discontinuities in the variable which should not be corrected.
bool applyToConvertedPhotons() const
Check if the ApplyTo flag passed in the conf file is compatible with converted photons.
const StatusCode getKinematicProperties(const xAOD::Egamma &egamma_object, float &pt, float &eta, float &phi) const
Get the e/y kinematic properties.
virtual StatusCode initialize() override
Initialize the class instance.
Extra patterns decribing particle interation process.
Electron_v1 Electron
Definition of the current "egamma version".
std::vector< parameterType > m_ParameterTypeVector
Map of the correction function parameter number to the parameter type.
Scalar phi() const
phi method
const CP::CorrectionCode applyCorrection(xAOD::Photon &photon) const
Apply the correction given in the conf file to the passed photon.
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...
Scalar eta() const
pseudorapidity method
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
bool applyToElectrons() const
Check if the ApplyTo flag passed in the conf file is compatible with electrons.
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.
ElectronPhotonVariableCorrectionBase::EGammaObjects m_applyToObjects
The type of objects to which the specific conf file settings are allowed to be applied to.
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.
const StatusCode getDensity(float &value, const std::string &eventShapeContainer) const
Get the events energy density from the eventShape.
float phiBE(const unsigned layer) const
Get the phi in one layer of the EM Calo.
#define ATH_MSG_VERBOSE(x)
bool m_retrievedEtaBinning
Store if already retrieved eta binning.
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...
bool m_useAbsEtaBinned
Store if the eta binned parameters need the eta or abs(eta) value for evaluation.
int m_numberOfFunctionParameters
Number of parameters of the variable correction function.
float etaBE(const unsigned layer) const
Get the eta in one layer of the EM Calo.
std::vector< std::vector< float > > m_binValues
List of eta/pt dependent values, stored if needed by the respective correction function parameter.
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
parameterType
Use enum and not string for type of function parameter in order to do faster comparisons.
@ Error
Some error happened during the object correction.
Description of a calorimeter cluster.
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap etaBin
bool isConvertedPhoton(const xAOD::Egamma *eg, bool excludeTRT=false)
is the object a converted photon
ElectronPhotonVariableCorrectionBase::EGammaObjects stringToEGammaObject(const std::string &input) const
Convert input string to egamma object type.
std::vector< TGraph * > m_graphCopies
Copy of the TGraph from the root file, stored if needed by the respective correction function paramet...
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.
::StatusCode StatusCode
StatusCode definition for legacy code.
EGammaObjects
Define the categories of EGamma objects tool can be applied to.
const xAOD::CaloCluster * caloCluster(size_t index=0) const
Pointer to the xAOD::CaloCluster/s that define the electron candidate.
std::string m_correctionFunctionString
Function to use for the variable correction, TFormula style.
std::string m_configFile
The name of the configuration file.
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.
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.
std::vector< float > m_etaBins
List of bin boundaries in eta, stored if needed by any correction function parameter.
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.
Data class for event shapes.
std::unique_ptr< SG::AuxElement::Accessor< float > > m_variableToCorrect
Accessor for the variable to be corrected.
bool getInterpolationFlag(const int parameter_number) const
Return the interpolation flag of parameter parameter_number as a boolean.
bool SetDirectory(TObject *object, TDirectory *directory)
effects: set the directory this object is associated with returns: whether the object type actively k...
std::unique_ptr< TFormula > m_correctionFunctionTFormula
The actual TFormula correction function.
std::vector< float > m_ptBins
List of bin boundaries in pT, stored if needed by any correction function parameter.
bool m_doGaussianSmearing
Whether to apply normal correction or smearing correction.
std::vector< TH2 * > m_TH2Copies
Copy of the TH2 from the root file, 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
Photon_v1 Photon
Definition of the current "egamma version".
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 PathResolverFindCalibFile(const std::string &logical_file_name)
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.
@ Ok
The correction was done successfully.
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::parameterType stringToParameterType(const std::string &input) const
Convert input string to a parameter function type.
#define ATH_MSG_WARNING(x)
float interpolate(const CaloRec::Array< 2 > &a, float x, unsigned int degree, unsigned int ycol=1, const CaloRec::Array< 1 > ®ions=CaloRec::Array< 1 >(), int n_points=-1, bool fixZero=false)
Polynomial interpolation in a table.
Return value from object correction CP tools.
bool isEqualToUncorrectedDiscontinuity(const float value) const
Check if the value passed is equal to one of the values passed via the UncorrectedDiscontinuites flag...
@ eProbabilityHT
Electron probability from High Threshold (HT) information [float].
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 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.
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 ...
Class describing a TrackParticle.
TRandom3 * getTLSRandomGen(unsigned int seed) const
Getting thread safe random number generator (and resetting its seed)
std::string m_correctionVariable
The name of the variable to correct.
std::vector< float > HelperFloat(const std::string &input, TEnv &env)
std::unique_ptr< SG::AuxElement::Accessor< float > > m_originalVariable
Accessor to store the original value of the corrected variable.
virtual double e() const
The total energy of the particle.
ElectronPhotonVariableCorrectionBase(const std::string &myname)
Standard constructor.
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.
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.
bool applyToUnconvertedPhotons() const
Check if the ApplyTo flag passed in the conf file is compatible with uconverted photons.