ATLAS Offline Software
CaloClusterMLCalibFeatureTransform.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 CALOCLUSTERCORRECTION_CALOCLUSTERMLCALIBFEATURETRANSFORMS_H
6 #define CALOCLUSTERCORRECTION_CALOCLUSTERMLCALIBFEATURETRANSFORMS_H
7 
8 #include <vector>
9 #include <cmath>
10 #include <stdexcept>
11 #include <string>
12 #include <map>
13 #include <functional>
14 
16 {
17  float standard(float x, const std::vector<float> &params)
18  {
19  if (params.size() != 2)
20  throw std::invalid_argument("Standard expects 2 parameters [mean, std_dev]");
21  float mean = params[0], std_dev = params[1];
22  if (std_dev == 0)
23  return x - mean;
24  return (x - mean) / std_dev;
25  }
26 
27  float log(float x, const std::vector<float> & /*params*/)
28  {
29  if (x <= 0)
30  return -INFINITY; // mimic numpy's log(0) behavior
31  return std::log(x);
32  }
33 
34  float logTen(float x, const std::vector<float> & /*params*/)
35  {
36  if (x <= 0)
37  return -INFINITY;
38  return std::log10(x);
39  }
40 
41  float logStandard(float x, const std::vector<float> &params)
42  {
43  if (params.size() != 2)
44  throw std::invalid_argument("LogStandard expects 2 parameters [mean, std_dev]");
45  float log_x = log(x, {});
46  return standard(log_x, params);
47  }
48 
49  float logTenStandard(float x, const std::vector<float> &params)
50  {
51  if (params.size() != 4)
52  throw std::invalid_argument("LogTenStandard expects 4 parameters [xmin, epsilon, mean, std_dev]");
53  float xmin = params[0], epsilon = params[1], mean = params[2], std_dev = params[3];
54  float x_shifted = x - xmin + epsilon;
55  float log_x = logTen(x_shifted, {});
56  return standard(log_x, {mean, std_dev});
57  }
58 
59  float maxAbsolute(float x, const std::vector<float> &params)
60  {
61  if (params.size() != 1)
62  throw std::invalid_argument("MaxAbsolute expects 1 parameter [max_value]");
63  float max_val = params[0];
64  if (max_val == 0)
65  return x;
66  return x / std::abs(max_val);
67  }
68 
69  float minMax(float x, const std::vector<float> &params)
70  {
71  if (params.size() != 2)
72  throw std::invalid_argument("MinMaxNorm expects 2 parameters [min_val, max_val]");
73  float min_val = params[0], max_val = params[1];
74  if (min_val == max_val)
75  return 0.0; // Avoid division by zero
76  return (x - min_val) / (max_val - min_val);
77  }
78 
79  using TransformFunc = std::function<float(float, const std::vector<float> &)>;
80 
81  const std::map<std::string, TransformFunc> TRANSFORMATIONS = {
82  {"Standard", standard},
83  {"Log", log},
84  {"LogTen", logTen},
85  {"LogStandard", logStandard},
86  {"LogTenStandard", logTenStandard},
87  {"MaxAbsolute", maxAbsolute},
88  {"MinMaxNorm", minMax}};
89 }
90 
91 #endif // CALOCLUSTERCORRECTION_CALOCLUSTERMLCALIBFEATURETRANSFORMS_H
CaloClusterMLCalib::maxAbsolute
float maxAbsolute(float x, const std::vector< float > &params)
Definition: CaloClusterMLCalibFeatureTransform.h:59
mean
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:254
CaloClusterMLCalib::TransformFunc
std::function< float(float, const std::vector< float > &)> TransformFunc
Definition: CaloClusterMLCalibFeatureTransform.h:79
CaloClusterMLCalib::logTen
float logTen(float x, const std::vector< float > &)
Definition: CaloClusterMLCalibFeatureTransform.h:34
CaloClusterMLCalib::epsilon
constexpr float epsilon
Definition: CaloClusterMLGaussianMixture.h:16
CaloClusterMLCalib::logStandard
float logStandard(float x, const std::vector< float > &params)
Definition: CaloClusterMLCalibFeatureTransform.h:41
CaloClusterMLCalib::standard
float standard(float x, const std::vector< float > &params)
Definition: CaloClusterMLCalibFeatureTransform.h:17
x
#define x
CaloClusterMLCalib::logTenStandard
float logTenStandard(float x, const std::vector< float > &params)
Definition: CaloClusterMLCalibFeatureTransform.h:49
xmin
double xmin
Definition: listroot.cxx:60
CaloClusterMLCalib::TRANSFORMATIONS
const std::map< std::string, TransformFunc > TRANSFORMATIONS
Definition: CaloClusterMLCalibFeatureTransform.h:81
CaloClusterMLCalib::log
float log(float x, const std::vector< float > &)
Definition: CaloClusterMLCalibFeatureTransform.h:27
CaloClusterMLCalib::minMax
float minMax(float x, const std::vector< float > &params)
Definition: CaloClusterMLCalibFeatureTransform.h:69
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
CaloClusterMLCalib
Definition: CaloClusterMLCalibFeatureTransform.h:16
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65