26 const std::vector<JetCorrectorParameters::Record>& mRecordsLocal)
31 std::stringstream sserr;
32 sserr<<
"The number of binned variables requested ("<<
SIZE<<
") is greater than the number allowed (" 34 handleError(
"JetCorrectorParametersHelper",sserr.str());
39 size_t nRec = mRecordsLocal.size();
40 size_t indexMapSize=0, tmpIndexMapSize=0;
41 for (
unsigned i = 0;
i < nRec; ++
i)
43 for (
unsigned j=0;j<
SIZE;j++)
53 if(SIZE>1 && (
i==nRec-1 || mRecordsLocal[
i].
xMin(j-1)!=mRecordsLocal[
i+1].
xMin(j-1))) {
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));
62 tuple_type tmpTuple = gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY>([&](
size_t k){
return (
k<SIZE)?mRecordsLocal[
i].xMin(
k):-9999;});
65 if(indexMapSize==tmpIndexMapSize)
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());
76 std::stringstream sserr;
77 sserr<<
"Did not find all bin boundaries for dimension "<<
SIZE-1<<
"!!!"<<std::endl
79 handleError(
"JetCorrectorParametersHelper",sserr.str());
82 if (indexMapSize!=nRec)
84 handleError(
"JetCorrectorParametersHelper",
"The mapping of bin lower bounds to indices does not contain all possible entries!!!");
94 size_t nRec = mRecords.size();
95 std::vector<int>
fN(N,-1);
98 for (
unsigned idim=1; idim<=
N; idim++) {
99 int nBoundaryPassed = 0;
102 for (
unsigned iRecord=0; iRecord<nRec; iRecord++) {
104 throw cms::Exception(
"MissingRecord") <<
"found a missing record in binned dimension " << idim <<
" after record " << iRecord << std::endl
105 <<
"\tthe bin lower bound should have been " <<
mBinBoundaries[idim][nBoundaryPassed%fN[idim-1]]
106 <<
", but was instead " << mRecords[iRecord].xMin(idim) << std::endl
107 <<
"\tall binned dimensions, besides the last one, must have uniform binning." << std::endl
108 << mRecords[iRecord-1] << std::endl << mRecords[iRecord] << std::endl;
110 else if((iRecord==nRec-1 || mRecords[iRecord].
xMin(idim)!=mRecords[iRecord+1].
xMin(idim))) {
128 std::stringstream sserr;
129 sserr<<
"The number of binned variables, "<<N<<
", doesn't correspond to the number requested, "<<fX.size();
130 handleError(
"JetCorrectorParametersHelper",sserr.str());
135 if (value < min || value > max)
return false;
143 const std::vector<JetCorrectorParameters::Record>& mRecords)
const 145 unsigned Nm1 =
SIZE-1;
149 std::vector<float>
fN(
SIZE,-1);
150 std::vector<float>::const_iterator tmpIt;
153 for (
unsigned idim=0; idim==0||idim<fX.size()-1; idim++)
161 else if (*tmpIt != fX[idim])
167 std::pair<size_t,size_t> indexBounds;
171 if (
mMap.find(to_find_Nm1)!=
mMap.end())
172 indexBounds =
mMap.at(to_find_Nm1);
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());
183 if(!
binBoundChecks(Nm1,fX[Nm1],mRecords[indexBounds.first].xMin(Nm1),mRecords[indexBounds.second].xMax(Nm1)))
return -1;
190 tuple_type to_find = gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY>([&](
size_t i){
return (
i<
SIZE)?fN[
i]:-9999;});
int binIndexN(const std::vector< float > &fX, const std::vector< JetCorrectorParameters::Record > &mRecords) const
void binIndexChecks(unsigned N, const std::vector< float > &fX) const
void checkMiddleBinUniformity(const std::vector< JetCorrectorParameters::Record > &mRecords) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
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
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
void init(const JetCorrectorParameters::Definitions &mDefinitions, const std::vector< JetCorrectorParameters::Record > &mRecords)
std::vector< std::vector< float > > mBinBoundaries
std::unordered_map< tuple_type_Nm1, std::pair< size_t, size_t > > mMap