Skip to content

Commit

Permalink
Fix two off-by-one errors that only affected the 1D and 2D cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexx Perloff committed Feb 24, 2017
1 parent 5457951 commit c7427a4
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions CondFormats/JetMETObjects/src/JetCorrectorParametersHelper.cc
Expand Up @@ -31,7 +31,7 @@ void JetCorrectorParametersHelper::init(const JetCorrectorParameters::Definition
std::stringstream sserr;
sserr<<"The number of binned variables requested ("<<SIZE<<") is greater than the number allowed ("
<<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY<<")";
handleError("JetCorrectorParameters",sserr.str());
handleError("JetCorrectorParametersHelper",sserr.str());
}

initTransientMaps();
Expand All @@ -53,13 +53,12 @@ void JetCorrectorParametersHelper::init(const JetCorrectorParameters::Definition
if(SIZE>1 && (i==nRec-1 || mRecordsLocal[i].xMin(j-1)!=mRecordsLocal[i+1].xMin(j-1))) {
end = i;
//mMap.emplace(gen_tuple<SIZE-1>([&](size_t k){return mRecordsLocal[i].xMin(k);}),std::make_pair(start,end));
mMap.emplace(gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY-1>([&](size_t k){return (k<SIZE)?mRecordsLocal[i].xMin(k):-9999;}),std::make_pair(start,end));
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));
start = i+1;
}
}
}
indexMapSize = mIndexMap.size();
//tuple_type tmpTuple = gen_tuple<SIZE>([&](size_t k){return mRecordsLocal[i].xMin(k);});
tuple_type tmpTuple = gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY>([&](size_t k){return (k<SIZE)?mRecordsLocal[i].xMin(k):-9999;});
mIndexMap.emplace(tmpTuple,i);
tmpIndexMapSize = mIndexMap.size();
Expand All @@ -69,20 +68,20 @@ void JetCorrectorParametersHelper::init(const JetCorrectorParameters::Definition
std::stringstream sserr;
sserr<<"Duplicate binning in record found (existing index,current index)=("
<<existing_index<<","<<i<<")"<<std::endl<<"\tBins(lower bounds)="<<tmpTuple;
handleError("JetCorrectorParameters",sserr.str());
handleError("JetCorrectorParametersHelper",sserr.str());
}
}
if (mBinBoundaries[SIZE-1].size()!=nRec)
{
std::stringstream sserr;
sserr<<"Did not find all bin boundaries for dimension "<<SIZE-1<<"!!!"<<std::endl
<<"Found "<<mBinBoundaries[SIZE-1].size()<<" out of "<<nRec<<" records";
handleError("JetCorrectorParameters",sserr.str());
handleError("JetCorrectorParametersHelper",sserr.str());
}
indexMapSize = mIndexMap.size();
if (indexMapSize!=nRec)
{
handleError("JetCorrectorParameters","The mapping of bin lower bounds to indices does not contain all possible entries!!!");
handleError("JetCorrectorParametersHelper","The mapping of bin lower bounds to indices does not contain all possible entries!!!");
}
}
//------------------------------------------------------------------------
Expand All @@ -95,7 +94,7 @@ void JetCorrectorParametersHelper::binIndexChecks(unsigned N, const std::vector<
{
std::stringstream sserr;
sserr<<"# bin variables "<<N<<" doesn't correspont to requested #: "<<fX.size();
handleError("JetCorrectorParameters",sserr.str());
handleError("JetCorrectorParametersHelper",sserr.str());
}
}
bool JetCorrectorParametersHelper::binBoundChecks(unsigned dim, const float& value, const float& min, const float& max) const
Expand All @@ -105,7 +104,7 @@ bool JetCorrectorParametersHelper::binBoundChecks(unsigned dim, const float& val
std::stringstream sserr;
sserr<<"Value for dimension "<<dim<<" is outside of the bin boundaries"<<std::endl
<<"\tRequested "<<value<<" for boundaries ("<<min<<","<<max<<")";
handleError("JetCorrectorParameters",sserr.str());
handleError("JetCorrectorParametersHelper",sserr.str());
return false;
}
return true;
Expand All @@ -125,7 +124,7 @@ int JetCorrectorParametersHelper::binIndexN(const std::vector<float>& fX,
std::vector<float>::const_iterator tmpIt;

// make sure that fX are within the first and last boundaries of mBinBoundaries (other than last dimension)
for (unsigned idim=0; idim<fX.size()-1; idim++)
for (unsigned idim=0; idim==0||idim<fX.size()-1; idim++)
{
if(!binBoundChecks(idim,fX[idim],*mBinBoundaries[idim].begin(),mRecords[size()-1].xMax(idim))) return -1;
tmpIt = std::lower_bound(mBinBoundaries[idim].begin(),mBinBoundaries[idim].end(),fX[idim]);
Expand All @@ -140,14 +139,14 @@ int JetCorrectorParametersHelper::binIndexN(const std::vector<float>& fX,
std::pair<size_t,size_t> indexBounds;
if(SIZE>1)
{
tuple_type_Nm1 to_find_Nm1 = gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY-1>([&](size_t i){return (i<SIZE)?fN[i]:-9999;});
tuple_type_Nm1 to_find_Nm1 = gen_tuple<JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY-1>([&](size_t i){return (i<Nm1)?fN[i]:-9999;});
if (mMap.find(to_find_Nm1)!=mMap.end())
indexBounds = mMap.at(to_find_Nm1);
else
{
std::stringstream sserr;
sserr<<"couldn't find the index boundaries for dimension "<<Nm1;
handleError("JetCorrectorParameters",sserr.str());
handleError("JetCorrectorParametersHelper",sserr.str());
return -1;
}

Expand Down

0 comments on commit c7427a4

Please sign in to comment.