CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
JetCorrectorParametersHelper Class Reference

#include <JetCorrectorParametersHelper.h>

Public Types

using tuple_type = typename generate_tuple_type< float, JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY >::type
 
using tuple_type_Nm1 = typename generate_tuple_type< float, JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY - 1 >::type
 

Public Member Functions

bool binBoundChecks (unsigned dim, const float &value, const float &min, const float &max) const
 
void binIndexChecks (unsigned N, const std::vector< float > &fX) const
 
int binIndexN (const std::vector< float > &fX, const std::vector< JetCorrectorParameters::Record > &mRecords) const
 
void checkMiddleBinUniformity (const std::vector< JetCorrectorParameters::Record > &mRecords) const
 
void init (const JetCorrectorParameters::Definitions &mDefinitions, const std::vector< JetCorrectorParameters::Record > &mRecords)
 
void initTransientMaps ()
 
unsigned size () const
 

Private Attributes

std::vector< std::vector< float > > mBinBoundaries
 
std::unordered_map< tuple_type, size_t > mIndexMap
 
std::unordered_map< tuple_type_Nm1, std::pair< size_t, size_t > > mMap
 
unsigned SIZE
 

Detailed Description

Definition at line 24 of file JetCorrectorParametersHelper.h.

Member Typedef Documentation

◆ tuple_type

Definition at line 36 of file JetCorrectorParametersHelper.h.

◆ tuple_type_Nm1

Definition at line 37 of file JetCorrectorParametersHelper.h.

Member Function Documentation

◆ binBoundChecks()

bool JetCorrectorParametersHelper::binBoundChecks ( unsigned  dim,
const float &  value,
const float &  min,
const float &  max 
) const

Definition at line 131 of file JetCorrectorParametersHelper.cc.

134  {
135  if (value < min || value > max)
136  return false;
137  else
138  return true;
139 }

References SiStripPI::max.

Referenced by binIndexN().

◆ binIndexChecks()

void JetCorrectorParametersHelper::binIndexChecks ( unsigned  N,
const std::vector< float > &  fX 
) const

Definition at line 124 of file JetCorrectorParametersHelper.cc.

124  {
125  if (N != fX.size()) {
126  std::stringstream sserr;
127  sserr << "The number of binned variables, " << N << ", doesn't correspond to the number requested, " << fX.size();
128  handleError("JetCorrectorParametersHelper", sserr.str());
129  }
130 }

References N.

Referenced by binIndexN().

◆ binIndexN()

int JetCorrectorParametersHelper::binIndexN ( const std::vector< float > &  fX,
const std::vector< JetCorrectorParameters::Record > &  mRecords 
) const

Definition at line 144 of file JetCorrectorParametersHelper.cc.

145  {
146  unsigned Nm1 = SIZE - 1;
147  binIndexChecks(SIZE, fX);
148 
149  //Create a container for the indices
150  std::vector<float> fN(SIZE, -1);
151  std::vector<float>::const_iterator tmpIt;
152 
153  // make sure that fX are within the first and last boundaries of mBinBoundaries (other than last dimension)
154  for (unsigned idim = 0; idim == 0 || idim < fX.size() - 1; idim++) {
155  if (!binBoundChecks(idim, fX[idim], *mBinBoundaries[idim].begin(), mRecords[size() - 1].xMax(idim)))
156  return -1;
157  tmpIt = std::lower_bound(mBinBoundaries[idim].begin(), mBinBoundaries[idim].end(), fX[idim]);
158  // lower_bound finds the entry with the next highest value to fX[0]
159  // so unless the two values are equal, you want the next lowest bin boundary
160  if (tmpIt == mBinBoundaries[idim].end())
161  tmpIt = mBinBoundaries[idim].begin() + mBinBoundaries[idim].size() - 1;
162  else if (*tmpIt != fX[idim])
163  tmpIt -= 1;
164  fN[idim] = *tmpIt;
165  }
166 
167  //find the index bounds for the possible values of the last dimension
168  std::pair<size_t, size_t> indexBounds;
169  if (SIZE > 1) {
171  [&](size_t i) { return (i < Nm1) ? fN[i] : -9999; });
172  if (mMap.find(to_find_Nm1) != mMap.end())
173  indexBounds = mMap.at(to_find_Nm1);
174  else {
175  std::stringstream sserr;
176  sserr << "couldn't find the index boundaries for dimension " << Nm1 << std::endl
177  << "looking for last bin with N-1 values of " << to_find_Nm1 << std::endl;
178  handleError("JetCorrectorParametersHelper", sserr.str());
179  return -1;
180  }
181 
182  //Check that the requested value is within the bin boundaries for the last dimension
183  if (!binBoundChecks(Nm1, fX[Nm1], mRecords[indexBounds.first].xMin(Nm1), mRecords[indexBounds.second].xMax(Nm1)))
184  return -1;
185  tmpIt = std::lower_bound(
186  mBinBoundaries[Nm1].begin() + indexBounds.first, mBinBoundaries[Nm1].begin() + indexBounds.second, fX[Nm1]);
187  if (*tmpIt != fX[Nm1] && fX[Nm1] < *(mBinBoundaries[Nm1].begin() + indexBounds.second))
188  tmpIt -= 1;
189  fN[Nm1] = *tmpIt;
190  }
191 
192  tuple_type to_find =
193  gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY>([&](size_t i) { return (i < SIZE) ? fN[i] : -9999; });
194  return (mIndexMap.find(to_find) != mIndexMap.end()) ? mIndexMap.at(to_find) : -1;
195 }

References binBoundChecks(), binIndexChecks(), mps_fire::end, hcaldqm::quantity::fN, mps_fire::i, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY, mBinBoundaries, mIndexMap, mMap, size(), SIZE, and multiplicitycorr_cfi::xMax.

◆ checkMiddleBinUniformity()

void JetCorrectorParametersHelper::checkMiddleBinUniformity ( const std::vector< JetCorrectorParameters::Record > &  mRecords) const

Definition at line 90 of file JetCorrectorParametersHelper.cc.

91  {
92  unsigned N = SIZE - 2;
93  size_t nRec = mRecords.size();
94  std::vector<int> fN(N, -1);
95  //The order of looping (records or dimensions) does not matter because you have to go through all of them once anyway
96  //Loop over each binned dimension that isn't the first or the last
97  for (unsigned idim = 1; idim <= N; idim++) {
98  int nBoundaryPassed = 0;
99  if (fN[idim - 1] == -1)
100  fN[idim - 1] = mBinBoundaries[idim].size();
101  //Loop over the mRecords vector
102  for (unsigned iRecord = 0; iRecord < nRec; iRecord++) {
103  if (mRecords[iRecord].xMin(idim) != mBinBoundaries[idim][nBoundaryPassed % fN[idim - 1]]) {
104  throw cms::Exception("MissingRecord")
105  << "found a missing record in binned dimension " << idim << " after record " << iRecord << std::endl
106  << "\tthe bin lower bound should have been " << mBinBoundaries[idim][nBoundaryPassed % fN[idim - 1]]
107  << ", but was instead " << mRecords[iRecord].xMin(idim) << std::endl
108  << "\tall binned dimensions, besides the last one, must have uniform binning." << std::endl
109  << mRecords[iRecord - 1] << std::endl
110  << mRecords[iRecord] << std::endl;
111  } else if ((iRecord == nRec - 1 || mRecords[iRecord].xMin(idim) != mRecords[iRecord + 1].xMin(idim))) {
112  nBoundaryPassed++;
113  } else {
114  continue;
115  }
116  }
117  }
118 }

References Exception, hcaldqm::quantity::fN, mBinBoundaries, N, SIZE, and photonAnalyzer_cfi::xMin.

Referenced by init().

◆ init()

void JetCorrectorParametersHelper::init ( const JetCorrectorParameters::Definitions mDefinitions,
const std::vector< JetCorrectorParameters::Record > &  mRecords 
)

Definition at line 24 of file JetCorrectorParametersHelper.cc.

25  {
26  SIZE = mDefinitionsLocal.nBinVar();
28  std::stringstream sserr;
29  sserr << "The number of binned variables requested (" << SIZE << ") is greater than the number allowed ("
31  handleError("JetCorrectorParametersHelper", sserr.str());
32  }
33 
35  size_t start = 0, end = 0;
36  size_t nRec = mRecordsLocal.size();
37  size_t indexMapSize = 0, tmpIndexMapSize = 0;
38  for (unsigned i = 0; i < nRec; ++i) {
39  for (unsigned j = 0; j < SIZE; j++) {
40  if (j < SIZE - 1 && std::find(mBinBoundaries[j].begin(), mBinBoundaries[j].end(), mRecordsLocal[i].xMin(j)) ==
41  mBinBoundaries[j].end())
42  mBinBoundaries[j].push_back(mRecordsLocal[i].xMin(j));
43  else if (j == SIZE - 1) {
44  if (i == 0)
45  mBinBoundaries[j].reserve(mRecordsLocal.size());
46 
47  mBinBoundaries[j].push_back(mRecordsLocal[i].xMin(j));
48 
49  if (SIZE > 1 && (i == nRec - 1 || mRecordsLocal[i].xMin(j - 1) != mRecordsLocal[i + 1].xMin(j - 1))) {
50  end = i;
51  //mMap.emplace(gen_tuple<SIZE-1>([&](size_t k){return mRecordsLocal[i].xMin(k);}),std::make_pair(start,end));
52  mMap.emplace(gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY - 1>(
53  [&](size_t k) { return (k < SIZE - 1) ? mRecordsLocal[i].xMin(k) : -9999; }),
54  std::make_pair(start, end));
55  start = i + 1;
56  }
57  }
58  }
59  indexMapSize = mIndexMap.size();
60  tuple_type tmpTuple = gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY>(
61  [&](size_t k) { return (k < SIZE) ? mRecordsLocal[i].xMin(k) : -9999; });
62  mIndexMap.emplace(tmpTuple, i);
63  tmpIndexMapSize = mIndexMap.size();
64  if (indexMapSize == tmpIndexMapSize) {
65  size_t existing_index = mIndexMap.find(tmpTuple)->second;
66  std::stringstream sserr;
67  sserr << "Duplicate binning in record found (existing index,current index)=(" << existing_index << "," << i << ")"
68  << std::endl
69  << "\tBins(lower bounds)=" << tmpTuple;
70  handleError("JetCorrectorParametersHelper", sserr.str());
71  }
72  }
73  if (mBinBoundaries[SIZE - 1].size() != nRec) {
74  std::stringstream sserr;
75  sserr << "Did not find all bin boundaries for dimension " << SIZE - 1 << "!!!" << std::endl
76  << "Found " << mBinBoundaries[SIZE - 1].size() << " out of " << nRec << " records";
77  handleError("JetCorrectorParametersHelper", sserr.str());
78  }
79  indexMapSize = mIndexMap.size();
80  if (indexMapSize != nRec) {
81  handleError("JetCorrectorParametersHelper",
82  "The mapping of bin lower bounds to indices does not contain all possible entries!!!");
83  }
84  // This function checks that all of the middle binned parameters (not the first or last) contain the same range of bins.
85  // If not an exception will be thrown as the mapping will work only if all bins but the last are uniform.
86  if (SIZE > 2)
87  checkMiddleBinUniformity(mRecordsLocal);
88 }

References checkMiddleBinUniformity(), mps_fire::end, spr::find(), mps_fire::i, initTransientMaps(), dqmiolumiharvest::j, dqmdumpme::k, JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY, mBinBoundaries, mIndexMap, mMap, JetCorrectorParameters::Definitions::nBinVar(), size(), SIZE, and photonAnalyzer_cfi::xMin.

◆ initTransientMaps()

void JetCorrectorParametersHelper::initTransientMaps ( )

Definition at line 18 of file JetCorrectorParametersHelper.cc.

18  {
19  mIndexMap.clear();
20  mMap.clear();
21  mBinBoundaries.clear();
22  mBinBoundaries.assign(JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY, std::vector<float>(0, 0));
23 }

References JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY, mBinBoundaries, mIndexMap, and mMap.

Referenced by init().

◆ size()

unsigned JetCorrectorParametersHelper::size ( void  ) const
inline

Member Data Documentation

◆ mBinBoundaries

std::vector<std::vector<float> > JetCorrectorParametersHelper::mBinBoundaries
private

◆ mIndexMap

std::unordered_map<tuple_type, size_t> JetCorrectorParametersHelper::mIndexMap
private

Definition at line 44 of file JetCorrectorParametersHelper.h.

Referenced by binIndexN(), init(), initTransientMaps(), and size().

◆ mMap

std::unordered_map<tuple_type_Nm1, std::pair<size_t, size_t> > JetCorrectorParametersHelper::mMap
private

Definition at line 46 of file JetCorrectorParametersHelper.h.

Referenced by binIndexN(), init(), and initTransientMaps().

◆ SIZE

unsigned JetCorrectorParametersHelper::SIZE
private

Definition at line 48 of file JetCorrectorParametersHelper.h.

Referenced by binIndexN(), checkMiddleBinUniformity(), and init().

mps_fire.i
i
Definition: mps_fire.py:428
start
Definition: start.py:1
JetCorrectorParametersHelper::tuple_type
typename generate_tuple_type< float, JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY >::type tuple_type
Definition: JetCorrectorParametersHelper.h:36
JetCorrectorParametersHelper::mBinBoundaries
std::vector< std::vector< float > > mBinBoundaries
Definition: JetCorrectorParametersHelper.h:42
JetCorrectorParametersHelper::binBoundChecks
bool binBoundChecks(unsigned dim, const float &value, const float &min, const float &max) const
Definition: JetCorrectorParametersHelper.cc:131
JetCorrectorParametersHelper::binIndexChecks
void binIndexChecks(unsigned N, const std::vector< float > &fX) const
Definition: JetCorrectorParametersHelper.cc:124
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
photonAnalyzer_cfi.xMin
xMin
Definition: photonAnalyzer_cfi.py:82
mps_fire.end
end
Definition: mps_fire.py:242
N
#define N
Definition: blowfish.cc:9
JetCorrectorParametersHelper::checkMiddleBinUniformity
void checkMiddleBinUniformity(const std::vector< JetCorrectorParameters::Record > &mRecords) const
Definition: JetCorrectorParametersHelper.cc:90
JetCorrectorParametersHelper::tuple_type_Nm1
typename generate_tuple_type< float, JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY - 1 >::type tuple_type_Nm1
Definition: JetCorrectorParametersHelper.h:37
dqmdumpme.k
k
Definition: dqmdumpme.py:60
hcaldqm::quantity::fN
Definition: ValueQuantity.h:11
JetCorrectorParametersHelper::initTransientMaps
void initTransientMaps()
Definition: JetCorrectorParametersHelper.cc:18
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
JetCorrectorParametersHelper::mIndexMap
std::unordered_map< tuple_type, size_t > mIndexMap
Definition: JetCorrectorParametersHelper.h:44
JetCorrectorParametersHelper::mMap
std::unordered_map< tuple_type_Nm1, std::pair< size_t, size_t > > mMap
Definition: JetCorrectorParametersHelper.h:46
Exception
Definition: hltDiff.cc:246
multiplicitycorr_cfi.xMax
xMax
Definition: multiplicitycorr_cfi.py:5
JetCorrectorParametersHelper::size
unsigned size() const
Definition: JetCorrectorParametersHelper.h:27
JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY
static const int MAX_SIZE_DIMENSIONALITY
Definition: JetCorrectorParameters.h:125
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
JetCorrectorParametersHelper::SIZE
unsigned SIZE
Definition: JetCorrectorParametersHelper.h:48