5 #ifndef L1Trigger_L1TMuonEndCap_emtf_LossFunctions 6 #define L1Trigger_L1TMuonEndCap_emtf_LossFunctions 29 virtual double fit(std::vector<Event*>&
v) = 0;
46 return e->trueValue -
e->predictedValue;
49 double fit(std::vector<Event*>&
v)
override {
53 for (
unsigned int i = 0;
i <
v.size();
i++) {
55 SUM +=
e->trueValue -
e->predictedValue;
58 return SUM /
v.size();
61 int id()
override {
return 1; }
75 if ((
e->trueValue -
e->predictedValue) >= 0)
81 double fit(std::vector<Event*>&
v)
override {
85 std::vector<double> residuals(
v.size());
88 for (
unsigned int i = 0;
i <
v.size();
i++) {
90 residuals[
i] = (
e->trueValue -
e->predictedValue);
94 int median_loc = (residuals.size() - 1) / 2;
97 if (residuals.size() % 2 != 0) {
98 std::nth_element(residuals.begin(), residuals.begin() + median_loc, residuals.end());
99 return residuals[median_loc];
104 std::nth_element(residuals.begin(), residuals.begin() + median_loc, residuals.end());
105 double low = residuals[median_loc];
106 std::nth_element(residuals.begin() + median_loc + 1, residuals.begin() + median_loc + 1, residuals.end());
107 double high = residuals[median_loc + 1];
112 int id()
override {
return 2; }
131 return (
e->trueValue -
e->predictedValue);
133 return quantile * (((
e->trueValue -
e->predictedValue) > 0) ? 1.0 : -1.0);
136 double fit(std::vector<Event*>&
v)
override {
143 for (
unsigned int i = 0;
i <
v.size();
i++) {
145 double residual =
e->trueValue -
e->predictedValue;
154 int id()
override {
return 3; }
158 std::vector<double> residuals(
v.size());
161 for (
unsigned int i = 0;
i <
v.size();
i++) {
163 residuals[
i] =
std::abs(
e->trueValue -
e->predictedValue);
166 std::sort(residuals.begin(), residuals.end());
167 unsigned int quantile_location = whichQuantile * (residuals.size() - 1);
168 return residuals[quantile_location];
183 return (
e->trueValue -
e->predictedValue) / (
e->trueValue *
e->trueValue);
186 double fit(std::vector<Event*>&
v)
override {
191 double SUMbottom = 0;
193 for (
unsigned int i = 0;
i <
v.size();
i++) {
195 SUMtop += (
e->trueValue -
e->predictedValue) / (
e->trueValue *
e->trueValue);
196 SUMbottom += 1 / (
e->trueValue *
e->trueValue);
199 return SUMtop / SUMbottom;
202 int id()
override {
return 4; }
double fit(std::vector< Event *> &v) override
std::string name() override
std::string name() override
double fit(std::vector< Event *> &v) override
double target(Event *e) override
double target(Event *e) override
std::string name() override
virtual std::string name()=0
Abs< T >::type abs(const T &t)
double target(Event *e) override
~PercentErrorSquared() override
virtual double target(Event *e)=0
double calculateQuantile(std::vector< Event *> &v, double whichQuantile)
virtual double fit(std::vector< Event *> &v)=0
double fit(std::vector< Event *> &v) override
std::string name() override
double target(Event *e) override
~AbsoluteDeviation() override
double fit(std::vector< Event *> &v) override
virtual ~LossFunction()=default