ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSParametrizationFloatSelectChain.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <algorithm>
7#include <iterator>
8#include <iostream>
9
10//=============================================
11//======= TFCSParametrizationFloatSelectChain =========
12//=============================================
13
15 TFCSParametrizationBase *param, float low, float up) {
16 if (up < low) {
17 // can't handle wrong order of bounds
18 ATH_MSG_ERROR("Cannot add " << param->GetName() << ": range [" << low << ","
19 << up << ") not well defined");
20 return -1;
21 }
22 if (get_number_of_bins() == 0) {
23 // special case of adding the first bin
24 push_back_in_bin(param, 0);
25 m_bin_low_edge[0] = low;
26 m_bin_low_edge[1] = up;
27 return 0;
28 }
29 int ilow = val_to_bin(low);
30 int iup = val_to_bin(up);
31 if (ilow < 0 && iup < 0 && m_bin_low_edge[get_number_of_bins()] == low) {
32 // special case of adding bin at the end of existing bins
33 int endbin = get_number_of_bins();
34 push_back_in_bin(param, endbin);
35 m_bin_low_edge[endbin] = low;
36 m_bin_low_edge[endbin + 1] = up;
37 return endbin;
38 }
39
40 if (ilow < 0 && iup < 0) {
41 // can't handle disjunct ranges
42 ATH_MSG_ERROR("Cannot add " << param->GetName() << ": range [" << low << ","
43 << up << ") which is outside existing range ["
44 << m_bin_low_edge[0] << ","
46 return -1;
47 }
48
49 if (iup >= 0 && ilow >= 0 && iup - ilow == 1 && m_bin_low_edge[ilow] == low &&
50 m_bin_low_edge[iup] == up) {
51 // Case of adding to an existing bin
52 push_back_in_bin(param, ilow);
53 return ilow;
54 }
55
56 if (ilow < 0 && iup == 0 && m_bin_low_edge[iup] == up) {
57 // Case of adding a new first bin before existing bins
58 int newbin = iup;
59 int oldsize = m_bin_start.size();
60 m_bin_start.resize(oldsize + 1, m_bin_start.back());
61 m_bin_start.shrink_to_fit();
62 m_bin_low_edge.resize(oldsize + 1, m_bin_low_edge.back());
63 m_bin_low_edge.shrink_to_fit();
64 for (int i = oldsize; i > newbin; --i) {
65 m_bin_start[i] = m_bin_start[i - 1];
67 }
68 m_bin_low_edge[newbin] = low;
69 m_bin_low_edge[newbin + 1] = up;
70 push_back_in_bin(param, newbin);
71 return newbin;
72 }
73
74 ATH_MSG_ERROR("Cannot add "
75 << param->GetName() << ": range [" << low << "," << up
76 << ") covers more than one bin in existing range ["
77 << m_bin_low_edge[0] << ","
79 << ") or splits an existing bin");
80 return -1;
81}
82
91
93 if (val < m_bin_low_edge[0]) {
94 ATH_MSG_VERBOSE("val_to_bin(" << val << ")=-1: " << val << " < "
95 << m_bin_low_edge[0]);
96 return -1;
97 }
98 if (val >= m_bin_low_edge[get_number_of_bins()]) {
99 ATH_MSG_VERBOSE("val_to_bin(" << val << ")=-1: " << val << " >= "
101 return -1;
102 }
103
104 auto it = std::upper_bound(m_bin_low_edge.begin(), m_bin_low_edge.end(), val);
105 int dist = std::distance(m_bin_low_edge.begin(), it) - 1;
106 ATH_MSG_VERBOSE("val_to_bin(" << val << ")=" << dist);
107 return dist;
108}
109
114 logger,
115 "==================================================================");
117 logger,
118 "= Please call TFCSParametrizationEkinSelectChain::unit_test(...) =");
120 logger,
121 "= or TFCSParametrizationEtaSelectChain ::unit_test(...) =");
123 logger,
124 "=================================================================="
125 << std::endl);
126}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_NOCLASS(logger_name, x)
Definition MLogging.h:52
Cut down AthMessaging.
Definition MLogging.h:176
virtual unsigned int get_number_of_bins() const
std::vector< unsigned int > m_bin_start
Contains the index where the TFCSParametrizationBase* instances to run for a given bin start.
virtual void push_back_in_bin(TFCSParametrizationBase *param, unsigned int bin)
virtual int push_back_in_bin(TFCSParametrizationBase *param, float low, float up)
static void unit_test(TFCSSimulationState *simulstate=nullptr, TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
static Root::TMsgLogger logger("iLumiCalc")