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 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 25 of file JetCorrectorParametersHelper.h.

Member Typedef Documentation

Definition at line 37 of file JetCorrectorParametersHelper.h.

Definition at line 38 of file JetCorrectorParametersHelper.h.

Member Function Documentation

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

Definition at line 100 of file JetCorrectorParametersHelper.cc.

Referenced by binIndexN(), and size().

101 {
102  if (value < min || value > max) return false;
103  else return true;
104 }
void JetCorrectorParametersHelper::binIndexChecks ( unsigned  N,
const std::vector< float > &  fX 
) const

Definition at line 91 of file JetCorrectorParametersHelper.cc.

Referenced by binIndexN(), and size().

92 {
93  if (N != fX.size())
94  {
95  std::stringstream sserr;
96  sserr<<"# bin variables "<<N<<" doesn't correspont to requested #: "<<fX.size();
97  handleError("JetCorrectorParametersHelper",sserr.str());
98  }
99 }
#define N
Definition: blowfish.cc:9
int JetCorrectorParametersHelper::binIndexN ( const std::vector< float > &  fX,
const std::vector< JetCorrectorParameters::Record > &  mRecords 
) const

Definition at line 109 of file JetCorrectorParametersHelper.cc.

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

Referenced by size().

111 {
112  unsigned Nm1 = SIZE-1;
113  binIndexChecks(SIZE,fX);
114 
115  //Create a container for the indices
116  std::vector<float> fN(SIZE,-1);
117  std::vector<float>::const_iterator tmpIt;
118 
119  // make sure that fX are within the first and last boundaries of mBinBoundaries (other than last dimension)
120  for (unsigned idim=0; idim==0||idim<fX.size()-1; idim++)
121  {
122  if(!binBoundChecks(idim,fX[idim],*mBinBoundaries[idim].begin(),mRecords[size()-1].xMax(idim))) return -1;
123  tmpIt = std::lower_bound(mBinBoundaries[idim].begin(),mBinBoundaries[idim].end(),fX[idim]);
124  // lower_bound finds the entry with the next highest value to fX[0]
125  // so unless the two values are equal, you want the next lowest bin boundary
126  if (*tmpIt != fX[idim])
127  tmpIt-=1;
128  fN[idim] = *tmpIt;
129  }
130 
131  //find the index bounds for the possible values of the last dimension
132  std::pair<size_t,size_t> indexBounds;
133  if(SIZE>1)
134  {
135  tuple_type_Nm1 to_find_Nm1 = gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY-1>([&](size_t i){return (i<Nm1)?fN[i]:-9999;});
136  if (mMap.find(to_find_Nm1)!=mMap.end())
137  indexBounds = mMap.at(to_find_Nm1);
138  else
139  {
140  std::stringstream sserr;
141  sserr<<"couldn't find the index boundaries for dimension "<<Nm1;
142  handleError("JetCorrectorParametersHelper",sserr.str());
143  return -1;
144  }
145 
146  //Check that the requested value is within the bin boundaries for the last dimension
147  if(!binBoundChecks(Nm1,fX[Nm1],mRecords[indexBounds.first].xMin(Nm1),mRecords[indexBounds.second].xMax(Nm1))) return -1;
148  tmpIt = std::lower_bound(mBinBoundaries[Nm1].begin()+indexBounds.first,mBinBoundaries[Nm1].begin()+indexBounds.second,fX[Nm1]);
149  if (*tmpIt != fX[Nm1] && fX[Nm1]<*(mBinBoundaries[Nm1].begin()+indexBounds.second))
150  tmpIt-=1;
151  fN[Nm1] = *tmpIt;
152  }
153 
154  tuple_type to_find = gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY>([&](size_t i){return (i<SIZE)?fN[i]:-9999;});
155  return (mIndexMap.find(to_find)!=mIndexMap.end()) ? mIndexMap.at(to_find) : -1;
156 }
void binIndexChecks(unsigned N, const std::vector< float > &fX) const
std::unordered_map< tuple_type, size_t > mIndexMap
typename generate_tuple_type< float, JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY >::type tuple_type
static const int MAX_SIZE_DIMENSIONALITY
#define end
Definition: vmac.h:37
typename generate_tuple_type< float, JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY-1 >::type tuple_type_Nm1
bool binBoundChecks(unsigned dim, const float &value, const float &min, const float &max) const
#define begin
Definition: vmac.h:30
std::vector< std::vector< float > > mBinBoundaries
std::unordered_map< tuple_type_Nm1, std::pair< size_t, size_t > > mMap
void JetCorrectorParametersHelper::init ( const JetCorrectorParameters::Definitions mDefinitions,
const std::vector< JetCorrectorParameters::Record > &  mRecords 
)

Definition at line 25 of file JetCorrectorParametersHelper.cc.

References begin, end, spr::find(), mps_fire::i, initTransientMaps(), gen::k, JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY, mBinBoundaries, mIndexMap, mMap, JetCorrectorParameters::Definitions::nBinVar(), size(), SIZE, and anotherprimaryvertexanalyzer_cfi::xMin.

Referenced by size().

27 {
28  SIZE = mDefinitionsLocal.nBinVar();
30  {
31  std::stringstream sserr;
32  sserr<<"The number of binned variables requested ("<<SIZE<<") is greater than the number allowed ("
34  handleError("JetCorrectorParametersHelper",sserr.str());
35  }
36 
38  size_t start=0, end=0;
39  size_t nRec = mRecordsLocal.size();
40  size_t indexMapSize=0, tmpIndexMapSize=0;
41  for (unsigned i = 0; i < nRec; ++i)
42  {
43  for (unsigned j=0;j<SIZE;j++)
44  {
45  if(j<SIZE-1 && std::find(mBinBoundaries[j].begin(),mBinBoundaries[j].end(),mRecordsLocal[i].xMin(j))==mBinBoundaries[j].end())
46  mBinBoundaries[j].push_back(mRecordsLocal[i].xMin(j));
47  else if(j==SIZE-1) {
48  if(i==0)
49  mBinBoundaries[j].reserve(mRecordsLocal.size());
50 
51  mBinBoundaries[j].push_back(mRecordsLocal[i].xMin(j));
52 
53  if(SIZE>1 && (i==nRec-1 || mRecordsLocal[i].xMin(j-1)!=mRecordsLocal[i+1].xMin(j-1))) {
54  end = i;
55  //mMap.emplace(gen_tuple<SIZE-1>([&](size_t k){return mRecordsLocal[i].xMin(k);}),std::make_pair(start,end));
56  mMap.emplace(gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY-1>([&](size_t k){return (k<SIZE-1)?mRecordsLocal[i].xMin(k):-9999;}),std::make_pair(start,end));
57  start = i+1;
58  }
59  }
60  }
61  indexMapSize = mIndexMap.size();
62  tuple_type tmpTuple = gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY>([&](size_t k){return (k<SIZE)?mRecordsLocal[i].xMin(k):-9999;});
63  mIndexMap.emplace(tmpTuple,i);
64  tmpIndexMapSize = mIndexMap.size();
65  if(indexMapSize==tmpIndexMapSize)
66  {
67  size_t existing_index = mIndexMap.find(tmpTuple)->second;
68  std::stringstream sserr;
69  sserr<<"Duplicate binning in record found (existing index,current index)=("
70  <<existing_index<<","<<i<<")"<<std::endl<<"\tBins(lower bounds)="<<tmpTuple;
71  handleError("JetCorrectorParametersHelper",sserr.str());
72  }
73  }
74  if (mBinBoundaries[SIZE-1].size()!=nRec)
75  {
76  std::stringstream sserr;
77  sserr<<"Did not find all bin boundaries for dimension "<<SIZE-1<<"!!!"<<std::endl
78  <<"Found "<<mBinBoundaries[SIZE-1].size()<<" out of "<<nRec<<" records";
79  handleError("JetCorrectorParametersHelper",sserr.str());
80  }
81  indexMapSize = mIndexMap.size();
82  if (indexMapSize!=nRec)
83  {
84  handleError("JetCorrectorParametersHelper","The mapping of bin lower bounds to indices does not contain all possible entries!!!");
85  }
86 }
Definition: start.py:1
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::unordered_map< tuple_type, size_t > mIndexMap
typename generate_tuple_type< float, JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY >::type tuple_type
static const int MAX_SIZE_DIMENSIONALITY
#define end
Definition: vmac.h:37
int k[5][pyjets_maxn]
#define begin
Definition: vmac.h:30
std::vector< std::vector< float > > mBinBoundaries
std::unordered_map< tuple_type_Nm1, std::pair< size_t, size_t > > mMap
void JetCorrectorParametersHelper::initTransientMaps ( )

Definition at line 18 of file JetCorrectorParametersHelper.cc.

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

Referenced by init(), and size().

19 {
20  mIndexMap.clear();
21  mMap.clear();
22  mBinBoundaries.clear();
24 }
std::unordered_map< tuple_type, size_t > mIndexMap
static const int MAX_SIZE_DIMENSIONALITY
std::vector< std::vector< float > > mBinBoundaries
std::unordered_map< tuple_type_Nm1, std::pair< size_t, size_t > > mMap
unsigned JetCorrectorParametersHelper::size ( void  ) const
inline

Member Data Documentation

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

Definition at line 42 of file JetCorrectorParametersHelper.h.

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

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().

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().

unsigned JetCorrectorParametersHelper::SIZE
private

Definition at line 48 of file JetCorrectorParametersHelper.h.

Referenced by binIndexN(), and init().