Commit ba73b12a authored by Jean-Baptiste De Vivie De Regie's avatar Jean-Baptiste De Vivie De Regie
Browse files

harmonize

parent 701ea053
......@@ -135,6 +135,8 @@ private:
std::string m_configFile;
//! @brief The name of the variable to correct
std::string m_correctionVariable;
//! @brief Values of discontinuities in the variable which should not be corrected
std::vector<float> m_uncorrectedDiscontinuities;
//! @brief Function to use for the variable correction, TF1 style
std::string m_correctionFunctionString;
//! @brief The actual TF1 correction function
......@@ -181,6 +183,11 @@ private:
*/
bool passedCorrectPhotonType(const xAOD::Photon& photon) const;
/** @brief Check if the value passed is equal to one of the values passed via the UncorrectedDiscontinuites flag and should thus not be corrected
* @param value The value which should be checked
*/
bool isEqualToUncorrectedDiscontinuity(const float value) const;
/** @brief Get the relevant information for a correction function parameter from the given conf file
* @param env The given TEnv, which is used to read out the current conf file
* @param parameter_number The parameter number with respect to the m_correctionFunctionTF1
......@@ -188,7 +195,7 @@ private:
* @details The relevant information for the parameter with the given parameter number and given parameter type is retrieved from the current configuration
* file, and saved in the according member variables of the class, i.e. m_graphCopies, m_binValues, m_etaBins, m_ptBins
*/
const StatusCode getParameterInformationFromConf(TEnv& env, const int& parameter_number, const ElectronPhotonVariableCorrectionBase::parameterType& type);
const StatusCode getParameterInformationFromConf(TEnv& env, const int parameter_number, const ElectronPhotonVariableCorrectionBase::parameterType type);
/** @brief Get the actual parameters entering the correction TF1 for the current e/y object to be corrected
* @param properties The vector where the values of the correction TF1 parameters will be saved in
......@@ -197,7 +204,7 @@ private:
* @details As every electron/photon has different values of pT/eta, the correction function must be adapted accordingly for every e/y. The according values of
* each of the correction function parameters are updated with this function.
*/
const StatusCode getCorrectionParameters(std::vector<float>& properties, const float& pt, const float& absEta) const;
const StatusCode getCorrectionParameters(std::vector<float>& properties, const float pt, const float absEta) const;
/** @brief Get the correction function parameter value if its type is eta- or pT-binned
* @param return_parameter_value The respective correction function parameter value is saved in this parameter
......@@ -205,7 +212,7 @@ private:
* @param binning The eta or pT binning
* @param parameter_number The number of the parameter with respect to the correction TF1. Needed in order to retrieve the correct values matching this parameter.
*/
const StatusCode get1DBinnedParameter(float& return_parameter_value, const float& evalPoint, const std::vector<float>& binning, const int& parameter_number) const;
const StatusCode get1DBinnedParameter(float& return_parameter_value, const float evalPoint, const std::vector<float>& binning, const int parameter_number) const;
/** @brief Get the correction function parameter value if its type is eta- and pT-binned
* @param return_parameter_value The respective correction function parameter value is saved in this parameter
......@@ -213,20 +220,20 @@ private:
* @param ptEvalPoint pT evaluation point - i.e., the pT value of the current e/y object to be corrected. Used to find the correct pT bin to use for the correction
* @param parameter_number The number of the parameter with respect to the correction TF1. Needed in order to retrieve the correct values matching this parameter.
*/
const StatusCode get2DBinnedParameter(float& return_parameter_value, const float& etaEvalPoint, const float& ptEvalPoint, const int& parameter_number) const;
const StatusCode get2DBinnedParameter(float& return_parameter_value, const float etaEvalPoint, const float ptEvalPoint, const int parameter_number) const;
/** @brief Find the bin number in which the evalPoint is located in the binning binning.
* @param return_bin The respective bin number is saved in this parameter
* @param evalPoint The evaluation point for which the bin number should be found
* @param binning The binning which should be evaluated
*/
const StatusCode findBin(int& return_bin, const float& evalPoint, const std::vector<float>& binning) const;
const StatusCode findBin(int& return_bin, const float evalPoint, const std::vector<float>& binning) const;
/** @brief Return the interpolation flag of parameter parameter_number as a boolean.
* @param parameter_number Number of the parameter for which the interpolation flag should be checked
* @return The interpolation flag of parameter parameter_number (boolean)
*/
bool getInterpolationFlag(const int& parameter_number) const;
bool getInterpolationFlag(const int parameter_number) const;
/** @brief Given a point x, approximates the value via linear interpolation based on the two nearest bin centers. Re-implementation of Double_t TH1::Interpolate( Double_t x) const.
* @param return_parameter_value The interpolated parameter value is saved in this parameter
......@@ -235,14 +242,14 @@ private:
* @param binning The binning based on which the interpolation should be done
* @param binValues The bin values according to the binning given in 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;
const StatusCode interpolate(float& return_parameter_value, const float evalPoint, const int bin, const std::vector<float>& binning, const std::vector<float>& binValues) const;
/** @brief Get the bin center of a bin bin_int using the binning binning
* @param return_bin_center The bin center is saved in this parameter
* @param binning The binning which should be used to find the bin centers
* @param bin_int The bin for which the bin center should be found
*/
const StatusCode getBinCenter(float& return_bin_center, const std::vector<float>& binning, const int& bin_int) const;
const StatusCode getBinCenter(float& return_bin_center, const std::vector<float>& binning, const int bin_int) const;
/** @brief Returns the linearly intrpolated value of value given the bin centers and bin values
* @param value The x-value at which the interpolation should be done
......@@ -251,7 +258,7 @@ private:
* @param right_bin_center The x-value of the right bin center used for the interpolation
* @param right_bin_value The y-value of the right bin at the right bin center
*/
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) const;
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) const;
/** @brief Get the events energy density from the eventShape
* @param value The respective correction function parameter value is saved in this parameter
......@@ -273,7 +280,7 @@ private:
* @param original_variable The original value of the corrected variable
* @param properties The vector containing the correction TF1 parameters so the correction TF1 can be set for the respective e/y object
*/
const StatusCode correct(float& return_corrected_variable, const float &original_variable, std::vector<float>& properties) const;
const StatusCode correct(float& return_corrected_variable, const float original_variable, std::vector<float>& properties) const;
}; //end class ElectronPhotonVariableCorrectionBase
......
......@@ -36,7 +36,7 @@ public:
/** @brief Standard constructor
* @param myname Internal name of the tool instance, so they can be distinguished
*/
ElectronPhotonVariableCorrectionTool( const std::string& myname);
ElectronPhotonVariableCorrectionTool(const std::string& myname);
//! @brief Standard destructor
~ElectronPhotonVariableCorrectionTool() {};
......
......@@ -145,6 +145,12 @@ The correction values for each respective bin are given to the tool using the fl
Parameter2Values: 1.; 0.9; 0.7; 0.45; 0.6; 1.1
```
If wanted, a partwise linear interpolation between the given pT bin values can be used. For this, simply set the flag `Parameter*Interpolate` to `TRUE` if `Parameter*` is a parameter binned in pT. If the flag is not set, it is assumed to be `FALSE`, however, the code does not complain if you explicitly set the flag to `FALSE`. The implemented method mostly follows the [interpolation method implemented in the ROOT TH1 class](https://root.cern.ch/doc/master/classTH1.html#a8ca269364ca55ea1e7fb65f9d3b21722). For interpolation into the last pt bin, whose upper boundary is infinity, we treat the bin as having the width "w" of the next-to-last bin. Thus, we interpolate a distance w/2 into the last bin, and after this distance the value is constant. For example, this would look like this:
```bash
Parameter2Interpolate: TRUE
```
For the **event density**, no further information must be given to the tool. The tool will extract the event density from the event and use it as the respective parameter.
If you want to include parameters depending on other quantities, please read the [developer manual](#how-to-change-and-adapt-the-tool-developer-manual) or [contact the developers](mailto:nils.gillwald@desy.de).
......@@ -159,6 +165,14 @@ In order to check whether the passed object in e.g. `applyCorrection` is intende
The tool will then check if the passed object is compatible with the `ApplyTo` flag provided, and will fail with a `CP::CorrectionCode::Error` if the object type is not as expected.
If there are **discrete parameter values which should be left uncorrected**, you can use the flag `UncorrectedDiscontinuities`. You should pass all values which should not be corrected to it as a list, like this:
```bash
UncorrectedDiscontinuities: 0.0; 1.0
```
Note that this will work fine for integer-like floats! It will probably fail for longer floats because of the internal floating point precision of C++ (i.e. the code checks equality using `==`, and does not check if the difference between the variable value and the values which should be skipped is smaller than some epsilon). If you need this to work for all floats, contact the maintainers and we'll see what we can do.
An **example configuration file** containing examples for all possible flags can be found in `./data/ElectronPhotonVariableCorrectionBase_ExampleConf.conf`. The complete list of example configuration files is (all in `./data/`):
- `ElectronPhotonVariableCorrectionBase_ExampleConvertedPhotonConf.conf` for converted photons,
......@@ -167,7 +181,7 @@ An **example configuration file** containing examples for all possible flags can
- `ElectronPhotonVariableCorrectionBase_ExampleIsoCorrectionConf.conf` for the isolation correction,
- `ElectronPhotonVariableCorrectionBase_ExampleConf.conf` general example showing what the tool can do and how all different possible parameters can be handled.
The .root file currently used for testing is `/pnfs/desy.de/atlas/dq2/atlaslocalgroupdisk/rucio/mc16_13TeV/da/80/DAOD_HIGG1D2.18400890._000001.pool.root.1`.
The .root file currently used for testing is `/pnfs/desy.de/atlas/dq2/atlaslocalgroupdisk/rucio/mc16_13TeV/3b/36/DAOD_HIGG1D2.20317301._000001.pool.root.1`.
#### The tool configuration file
......
......@@ -158,6 +158,18 @@ StatusCode ElectronPhotonVariableCorrectionBase::initialize()
return StatusCode::FAILURE;
}
// check if there are any (discrete) values which should be left uncorrected
if (env.Lookup("UncorrectedDiscontinuities"))
{
m_uncorrectedDiscontinuities = AsgConfigHelper::HelperFloat("UncorrectedDiscontinuities", env);
// if flag is given, but no values, fail
if (m_uncorrectedDiscontinuities.size() < 1)
{
ATH_MSG_ERROR("Did not find any discontinuities to not correct, despite finding the flag UncorrectedDiscontinuities.");
return StatusCode::FAILURE;
}
}
//everything worked out, so
return StatusCode::SUCCESS;
}
......@@ -182,6 +194,11 @@ const CP::CorrectionCode ElectronPhotonVariableCorrectionBase::applyCorrection(x
original_variable = (*m_variableToCorrect)(photon);
//Save the original value to the photon under different name
(*m_originalVariable)(photon) = original_variable;
// check if tool should skip correcting this variable, as it's from some discontinuity
if (isEqualToUncorrectedDiscontinuity(original_variable))
{
return CP::CorrectionCode::Ok;
}
}
else
{
......@@ -233,6 +250,11 @@ const CP::CorrectionCode ElectronPhotonVariableCorrectionBase::applyCorrection(x
original_variable = (*m_variableToCorrect)(electron);
//Save the original value to the photon under different name
(*m_originalVariable)(electron) = original_variable;
// check if tool should skip correcting this variable, as it's from some discontinuity
if (isEqualToUncorrectedDiscontinuity(original_variable))
{
return CP::CorrectionCode::Ok;
}
}
else
{
......@@ -269,7 +291,7 @@ const CP::CorrectionCode ElectronPhotonVariableCorrectionBase::applyCorrection(x
return CP::CorrectionCode::Ok;
}
const StatusCode ElectronPhotonVariableCorrectionBase::correct(float& return_corrected_variable, const float &original_variable, std::vector<float>& properties) const
const StatusCode ElectronPhotonVariableCorrectionBase::correct(float& return_corrected_variable, const float original_variable, std::vector<float>& properties) const
{
// set the parameters of the correction function
for (unsigned int parameter_itr = 0; parameter_itr < properties.size(); parameter_itr++)
......@@ -307,6 +329,27 @@ const CP::CorrectionCode ElectronPhotonVariableCorrectionBase::correctedCopy( co
// Helper Functions
// ===========================================================================
bool ElectronPhotonVariableCorrectionBase::isEqualToUncorrectedDiscontinuity(const float value) const
{
// if no values set, return false as there is nothing to check
if (m_uncorrectedDiscontinuities.size() < 1)
{
return false;
}
// check all discontinuities which where passed
for (unsigned int value_itr = 0; value_itr < m_uncorrectedDiscontinuities.size(); value_itr++)
{
if (value == m_uncorrectedDiscontinuities.at(value_itr))
{
// if the value is equal to one of the discontinuities, no need to check further
return true;
}
}
// if we eer get here, the value was never equal to a discontinuity
return false;
}
const StatusCode ElectronPhotonVariableCorrectionBase::getKinematicProperties(const xAOD::Egamma& egamma_object, float& pt, float& absEta) const
{
// just reteriving eta and pt is probably less expensive then checking if I need it and
......@@ -336,7 +379,7 @@ const StatusCode ElectronPhotonVariableCorrectionBase::getKinematicProperties(co
return StatusCode::SUCCESS;
}
const StatusCode ElectronPhotonVariableCorrectionBase::getParameterInformationFromConf(TEnv& env, const int& parameter_number, const ElectronPhotonVariableCorrectionBase::parameterType& type)
const StatusCode ElectronPhotonVariableCorrectionBase::getParameterInformationFromConf(TEnv& env, const int parameter_number, const ElectronPhotonVariableCorrectionBase::parameterType type)
{
// don't want to write the same code multiple times, so set flags when to retrieve eta/pt bins
bool getEtaBins = false;
......@@ -498,7 +541,7 @@ const StatusCode ElectronPhotonVariableCorrectionBase::getParameterInformationFr
return StatusCode::SUCCESS;
}
const StatusCode ElectronPhotonVariableCorrectionBase::getCorrectionParameters(std::vector<float>& properties, const float& pt, const float& absEta) const
const StatusCode ElectronPhotonVariableCorrectionBase::getCorrectionParameters(std::vector<float>& properties, const float pt, const float absEta) const
{
// according to the parameter type, get the actual parameter going to the correction function
// for this, loop over the parameter type vector
......@@ -541,7 +584,7 @@ const StatusCode ElectronPhotonVariableCorrectionBase::getCorrectionParameters(s
return StatusCode::SUCCESS;
}
const StatusCode ElectronPhotonVariableCorrectionBase::get1DBinnedParameter(float& return_parameter_value, const float& evalPoint, const std::vector<float>& binning, const int& parameter_number) const
const StatusCode ElectronPhotonVariableCorrectionBase::get1DBinnedParameter(float& return_parameter_value, const float evalPoint, const std::vector<float>& binning, const int parameter_number) const
{
ANA_MSG_VERBOSE("EvalPoint: " << evalPoint);
// need to find the bin in which the evalPoint is
......@@ -563,7 +606,7 @@ const StatusCode ElectronPhotonVariableCorrectionBase::get1DBinnedParameter(floa
return StatusCode::SUCCESS;
}
const StatusCode ElectronPhotonVariableCorrectionBase::get2DBinnedParameter(float& return_parameter_value, const float& etaEvalPoint, const float& ptEvalPoint, const int& parameter_number) const
const StatusCode ElectronPhotonVariableCorrectionBase::get2DBinnedParameter(float& return_parameter_value, const float etaEvalPoint, const float ptEvalPoint, const int parameter_number) const
{
//need to find eta bin, and need to find pt bin
//from this, calculate which parameter of the list is needed to be returned.
......@@ -614,7 +657,7 @@ const StatusCode ElectronPhotonVariableCorrectionBase::get2DBinnedParameter(floa
return StatusCode::SUCCESS;
}
const StatusCode ElectronPhotonVariableCorrectionBase::findBin(int& return_bin, const float& evalPoint, const std::vector<float>& binning) const
const StatusCode ElectronPhotonVariableCorrectionBase::findBin(int& return_bin, const float evalPoint, const std::vector<float>& binning) const
{
// need to find the bin in which the evalPoint is
return_bin = -1;
......@@ -650,7 +693,7 @@ const StatusCode ElectronPhotonVariableCorrectionBase::findBin(int& return_bin,
return StatusCode::SUCCESS;
}
bool ElectronPhotonVariableCorrectionBase::getInterpolationFlag(const int& parameter_number) const
bool ElectronPhotonVariableCorrectionBase::getInterpolationFlag(const int parameter_number) const
{
bool do_interpolation = false;
// get parameter number type
......@@ -664,7 +707,7 @@ bool ElectronPhotonVariableCorrectionBase::getInterpolationFlag(const int& param
return do_interpolation;
}
const StatusCode ElectronPhotonVariableCorrectionBase::interpolate(float& return_parameter_value, const float& evalPoint, const int& bin, const std::vector<float>& binning, const std::vector<float>& binValues) const
const StatusCode ElectronPhotonVariableCorrectionBase::interpolate(float& return_parameter_value, const float evalPoint, const int bin, const std::vector<float>& binning, const std::vector<float>& binValues) const
{
// check if passed binning is consistent
if (binning.size() != binValues.size())
......@@ -724,7 +767,7 @@ const StatusCode ElectronPhotonVariableCorrectionBase::interpolate(float& return
return StatusCode::SUCCESS;
}
const StatusCode ElectronPhotonVariableCorrectionBase::getBinCenter(float& return_bin_center, const std::vector<float>& binning, const int& bin_int) const
const StatusCode ElectronPhotonVariableCorrectionBase::getBinCenter(float& return_bin_center, const std::vector<float>& binning, const int bin_int) const
{
if (bin_int < 0)
{
......@@ -760,7 +803,7 @@ const StatusCode ElectronPhotonVariableCorrectionBase::getBinCenter(float& retur
return StatusCode::SUCCESS;
}
float ElectronPhotonVariableCorrectionBase::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) const
float ElectronPhotonVariableCorrectionBase::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) const
{
return left_bin_value + (value - left_bin_center) * (right_bin_value - left_bin_value) / (right_bin_center - left_bin_center);
}
......
......@@ -148,7 +148,7 @@ const StatusCode ElectronPhotonVariableCorrectionTool::applyToFlagMatchesToolHol
// get ApplyTo flag
ElectronPhotonVariableCorrectionBase::EGammaObjects confFileType = toolHolder.at(tool_itr)->isAppliedTo();
// skip all further tests if should be applied to all objects
if ((confFileType == ElectronPhotonVariableCorrectionBase::EGammaObjects::allEGammaObjects)) continue;
if (confFileType == ElectronPhotonVariableCorrectionBase::EGammaObjects::allEGammaObjects) continue;
// continue if ApplyTo flag matches toolholder
if (toolHolderType == ElectronPhotonVariableCorrectionBase::EGammaObjects::convertedPhotons && toolHolder.at(tool_itr)->applyToConvertedPhotons()) continue;
if (toolHolderType == ElectronPhotonVariableCorrectionBase::EGammaObjects::unconvertedPhotons && toolHolder.at(tool_itr)->applyToUnconvertedPhotons()) continue;
......
......@@ -9,6 +9,10 @@ ApplyTo: AllEGammaObjects
#name of the variable to correct
Variable: Rhad
#discontinuous values of Rhad which should not be corrected
UncorrectedDiscontinuities: 0.0; 1.0
#function used for correction
#the function must be written in TF1 style
#note: this is an unphysical example, just illustrating the different possible
......@@ -38,8 +42,12 @@ Parameter2Values: 1.; 0.9; 0.7; 0.45; 0.6; 1.1
Parameter3Type: PtBinned
Parameter3Values: 2.; 2.5; 3.1; 3.9; 4.5; 6
#this flag could be omitted, default setting is false
Parameter3Interpolate: FALSE
Parameter4Type: EtaTimesPtBinned
#interpolate the pT values between bins
Parameter4Interpolate: TRUE
#Code is assuming that the values are binned in eta x pt in the conf file
#the pt binning must be represented by the rows
#the eta binning must be represented by the columns
......
......@@ -4,11 +4,13 @@
# This is a configuration file to test the application of corrections to photons
Variable: Eratio
Function: x + [0]
nFunctionParameters: 1
Function: [0] * x + [1]
nFunctionParameters: 2
ApplyTo: convertedPhotons
UncorrectedDiscontinuities: 0.; 1.
PtBins: 0.0; 10000; 50000; 100000
Parameter0Type: PtBinned
Parameter0Values: 1.; 2.; 3.; 4.
......
......@@ -4,11 +4,13 @@
# This is a configuration file to test the application of corrections to photons
Variable: Rhad
Function: x + [0]
nFunctionParameters: 1
Function: [0] * x + [1]
nFunctionParameters: 2
ApplyTo: convertedPhotons
UncorrectedDiscontinuities: 0.; 1.
PtBins: 0.0; 10000; 50000; 100000
Parameter0Type: PtBinned
Parameter0Values: 1.; 2.; 3.; 4.
......
......@@ -6,13 +6,26 @@
ApplyTo: allElectrons
Variable: Eratio
Function: x + [0]
nFunctionParameters: 1
UncorrectedDiscontinuities: 0.; 1.
Function: [0] + [1] * x + [2] * x**2
nFunctionParameters: 3
PtBins: 0.0; 10000; 50000; 100000
Parameter0Type: PtBinned
Parameter0Values: 1.; 2.; 3.; 4.
Parameter0Interpolate: TRUE
EtaBins: 0.0; 1.5; 3.
EtaBins: 0.0; 1.; 2.
Parameter1Type: EtaBinned
Parameter1Values: 1.; 2.; 3.
Parameter2Type: EtaTimesPtBinned
Parameter2Interpolate: TRUE
#pT \ eta >0.0 >1. >2.
Parameter2Values: 0.5; 1.; 1.5; #0 - 10 GeV#
+Parameter2Values: 2.; 2.5; 3; #10 - 50 GeV#
+Parameter2Values: 3.1; 3.2; 3.3; #50 - 100 GeV#
+Parameter2Values: 3.4; 3.5; 4. #> 100 GeV#
......@@ -6,8 +6,11 @@
ApplyTo: allElectrons
Variable: Rhad
Function: x + [0]
nFunctionParameters: 1
UncorrectedDiscontinuities: 0.; 1.
Function: [0] * x + [1]
nFunctionParameters: 2
PtBins: 0.0; 10000; 50000; 100000
Parameter0Type: PtBinned
......
......@@ -4,11 +4,13 @@
# This is a configuration file to test the application of corrections to photons
Variable: Eratio
Function: x + [0]
nFunctionParameters: 1
Function: [0] * x + [1]
nFunctionParameters: 2
ApplyTo: unconvertedPhotons
UncorrectedDiscontinuities: 0.; 1.
PtBins: 0.0; 10000; 50000; 100000
Parameter0Type: PtBinned
Parameter0Values: 1.; 2.; 3.; 4.
......
......@@ -4,11 +4,13 @@
# This is a configuration file to test the application of corrections to photons
Variable: Rhad
Function: x + [0]
nFunctionParameters: 1
Function: [0] * x + [1]
nFunctionParameters: 2
ApplyTo: unconvertedPhotons
UncorrectedDiscontinuities: 0.; 1.
PtBins: 0.0; 10000; 50000; 100000
Parameter0Type: PtBinned
Parameter0Values: 1.; 2.; 3.; 4.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment