ATLAS Offline Software
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] << ","
45  << m_bin_low_edge[get_number_of_bins()] << ")");
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 
84  TFCSParametrizationBase *param, unsigned int bin) {
86  if (m_bin_low_edge.size() < m_bin_start.size()) {
87  m_bin_low_edge.resize(m_bin_start.size(), m_bin_low_edge.back());
88  m_bin_low_edge.shrink_to_fit();
89  }
90 }
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  }
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 }
ISF_FCS::MLogging
Cut down AthMessaging.
Definition: MLogging.h:176
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TFCSParametrizationBinnedChain::push_back_in_bin
virtual void push_back_in_bin(TFCSParametrizationBase *param, unsigned int bin)
Definition: TFCSParametrizationBinnedChain.cxx:31
bin
Definition: BinsDiffFromStripMedian.h:43
TFCSExtrapolationState
Definition: TFCSExtrapolationState.h:13
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TFCSParametrizationFloatSelectChain::unit_test
static void unit_test(TFCSSimulationState *simulstate=nullptr, TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
Definition: TFCSParametrizationFloatSelectChain.cxx:110
TFCSParametrizationBase
Definition: TFCSParametrizationBase.h:46
TFCSParametrizationBinnedChain::get_number_of_bins
virtual unsigned int get_number_of_bins() const
Definition: TFCSParametrizationBinnedChain.h:22
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TFCSParametrizationFloatSelectChain::push_back_in_bin
virtual int push_back_in_bin(TFCSParametrizationBase *param, float low, float up)
Definition: TFCSParametrizationFloatSelectChain.cxx:14
TFCSParametrizationFloatSelectChain.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
CalibCoolCompareRT.up
up
Definition: CalibCoolCompareRT.py:109
TFCSParametrizationFloatSelectChain::val_to_bin
int val_to_bin(float val) const
Definition: TFCSParametrizationFloatSelectChain.cxx:92
ATH_MSG_NOCLASS
#define ATH_MSG_NOCLASS(logger_name, x)
Definition: MLogging.h:52
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
TFCSTruthState
Definition: TFCSTruthState.h:13
TFCSSimulationState
Definition: TFCSSimulationState.h:32
TFCSParametrizationFloatSelectChain::m_bin_low_edge
std::vector< float > m_bin_low_edge
Definition: TFCSParametrizationFloatSelectChain.h:41
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14
TFCSParametrizationBinnedChain::m_bin_start
std::vector< unsigned int > m_bin_start
Contains the index where the TFCSParametrizationBase* instances to run for a given bin start.
Definition: TFCSParametrizationBinnedChain.h:53