24 for(
unsigned i=0;
i<fBinVar.size();
i++)
26 for(
unsigned i=0;i<fParVar.size();i++)
38 std::vector<std::string> tokens = getTokens(fLine);
41 if (tokens.size() < 6)
43 std::stringstream sserr;
44 sserr<<
"(line "<<fLine<<
"): less than 6 expected tokens:"<<tokens.size();
45 handleError(
"JetCorrectorParameters::Definitions",sserr.str());
47 unsigned nvar = getUnsigned(tokens[0]);
48 unsigned npar = getUnsigned(tokens[nvar+1]);
49 for(
unsigned i=0;
i<nvar;
i++)
51 for(
unsigned i=0;
i<npar;
i++)
57 else if (ss ==
"Correction")
59 else if (ss ==
"Resolution")
61 else if (ss.find(
"PAR")==0)
65 std::stringstream sserr;
66 sserr<<
"unknown option ("<<ss<<
")";
67 handleError(
"JetCorrectorParameters::Definitions",sserr.str());
69 mLevel = tokens[npar+nvar+4];
80 std::vector<std::string> tokens = getTokens(fLine);
83 if (tokens.size() < 3)
85 std::stringstream sserr;
86 sserr<<
"(line "<<fLine<<
"): "<<
"three tokens expected, "<<tokens.size()<<
" provided.";
87 handleError(
"JetCorrectorParameters::Record",sserr.str());
91 mMin.push_back(getFloat(tokens[
i*2]));
92 mMax.push_back(getFloat(tokens[i*2+1]));
94 unsigned nParam = getUnsigned(tokens[2*mNvar]);
95 if (nParam != tokens.size()-(2*mNvar+1))
97 std::stringstream sserr;
98 sserr<<
"(line "<<fLine<<
"): "<<tokens.size()-(2*mNvar+1)<<
" parameters, but nParam="<<nParam<<
".";
99 handleError(
"JetCorrectorParameters::Record",sserr.str());
101 for (
unsigned i = (2*mNvar+1);
i < tokens.size(); ++
i)
107 for(
unsigned j=0;j<fBin.
nVar();j++)
108 out<<fBin.
xMin(j)<<
" "<<fBin.
xMax(j)<<
" ";
121 std::ifstream
input(fFile.c_str());
125 while (std::getline(
input,line))
129 if (!section.empty() && tmp.empty())
134 if (currentSection == fSection)
138 currentDefinitions =
tmp;
155 if (currentDefinitions==
"")
156 handleError(
"JetCorrectorParameters",
"No definitions found!!!");
158 if (
mRecords.empty() && currentSection !=
"")
160 std::stringstream sserr;
161 sserr<<
"the requested section "<<fSection<<
" doesn't exist!";
162 handleError(
"JetCorrectorParameters",sserr.str());
173 std::stringstream sserr;
175 <<
" the SimpleJetCorrector will default to using the legacy binIndex function!";
176 handleError(
"JetCorrectorParameters",sserr.str());
185 helper = std::make_shared<JetCorrectorParametersHelper>();
197 std::stringstream sserr;
198 sserr<<
"# bin variables "<<N<<
" doesn't correspont to requested #: "<<fX.size();
199 handleError(
"JetCorrectorParameters",sserr.str());
202 for (
unsigned i = 0;
i <
size(); ++
i)
205 for (
unsigned j=0;j<
N;j++)
239 std::stringstream sserr;
240 sserr<<
"# of bin variables "<<N<<
" doesn't correspond to requested #: "<<fVar;
241 handleError(
"JetCorrectorParameters",sserr.str());
244 for (
unsigned i = 0;
i <
size(); ++
i)
247 for (
unsigned j=0;j<fVar;j++)
250 for (
unsigned j=fVar+1;j<
N;j++)
279 std::stringstream sserr;
280 sserr<<
"requested bin variable index "<<fVar<<
" is greater than number of variables "<<
mDefinitions.
nBinVar();
281 handleError(
"JetCorrectorParameters",sserr.str());
284 float tmpMin(-9999),tmpMax(-9999);
285 for (
unsigned i = 0;
i <
size(); ++
i)
299 std::vector<float>
result;
300 for (
unsigned i = 0;
i <
size(); ++
i)
309 std::cout<<
"--------------------------------------------"<<std::endl;
310 std::cout<<
"//////// PARAMETERS: //////////////////////"<<std::endl;
311 std::cout<<
"--------------------------------------------"<<std::endl;
313 std::cout<<
"Names of binning variables: ";
317 std::cout<<
"--------------------------------------------"<<std::endl;
319 std::cout<<
"Names of parameter variables: ";
323 std::cout<<
"--------------------------------------------"<<std::endl;
326 std::cout<<
"Type (Response or Correction): "<<
"Response"<<std::endl;
328 std::cout<<
"Type (Response or Correction): "<<
"Correction"<<std::endl;
330 std::cout<<
"--------------------------------------------"<<std::endl;
331 std::cout<<
"------- Bin contents -----------------------"<<std::endl;
347 std::ofstream txtFile;
348 txtFile.open(fFileName.c_str());
349 txtFile.setf(std::ios::right);
358 txtFile<<
"Response"<<std::setw(15);
360 txtFile<<
"Correction"<<std::setw(15);
375 const std::vector<std::string> labels_ = {
387 "UncertaintyAbsolute",
388 "UncertaintyHighPtExtra",
389 "UncertaintySinglePionECAL",
392 "UncertaintyRelativeJEREC1",
393 "UncertaintyRelativeJEREC2",
394 "UncertaintyRelativeJERHF",
395 "UncertaintyRelativeStatEC2",
396 "UncertaintyRelativeStatHF",
397 "UncertaintyRelativeFSR",
398 "UncertaintyPileUpDataMC",
399 "UncertaintyPileUpOOT",
400 "UncertaintyPileUpPtBB",
401 "UncertaintyPileUpBias",
402 "UncertaintyPileUpJetRate",
403 "UncertaintySinglePionHCAL",
404 "UncertaintyRelativePtEC1",
405 "UncertaintyRelativePtEC2",
406 "UncertaintyRelativePtHF",
407 "UncertaintyRelativeSample",
408 "UncertaintyPileUpPtEC",
409 "UncertaintyPileUpPtHF",
416 const std::vector<std::string> l5Flavors_ = {
427 const std::vector<std::string> l7Partons_ = {
441 if ( isL5(k) )
return findL5Flavor(k);
442 else if ( isL7(k) )
return findL7Parton(k);
443 else return labels_[
k];
448 if ( k == L5Flavor )
return labels_[L5Flavor];
450 return l5Flavors_[k / 100 - 1];
455 if ( k == L7Parton )
return labels_[L7Parton];
457 return l7Partons_[k / 1000 - 1];
461 std::vector<std::string> &
outputs )
464 std::ifstream
input( inputFile.c_str() );
465 while( !
input.eof() ) {
467 input.getline(buff,10000);
469 if ( in[0] ==
'[' ) {
472 outputs.push_back( tok );
476 std::cout <<
"Found these sections for file: " << std::endl;
477 copy(outputs.begin(),outputs.end(), std::ostream_iterator<std::string>(
std::cout,
"\n") );
484 std::cout <<
"flav = " << flav << std::endl;
486 std::cout <<
"This is L5, getL5Bin = " << getL5Bin(flav) << std::endl;
487 correctionsL5_.push_back(
pair_type(getL5Bin(flav),j) );
489 else if ( isL7(i) ) {
490 std::cout <<
"This is L7, getL7Bin = " << getL7Bin(flav) << std::endl;
491 correctionsL7_.push_back(
pair_type(getL7Bin(flav),j) );
493 else if ( flav ==
"" ) {
494 corrections_.push_back(
pair_type(i,j) );
496 std::cout <<
"***** NOT ADDING " << flav <<
", corresponding position in JetCorrectorParameters is not found." << std::endl;
504 collection_type::const_iterator ibegin, iend,
i;
506 ibegin = correctionsL5_.begin();
507 iend = correctionsL5_.end();
509 }
else if ( isL7(k) ) {
510 ibegin = correctionsL7_.begin();
511 iend = correctionsL7_.end();
514 ibegin = corrections_.begin();
515 iend = corrections_.end();
518 for ( ; i != iend; ++
i ) {
519 if ( k == i->first )
return i->second;
521 throw cms::Exception(
"InvalidInput") <<
" cannot find key " <<
static_cast<int>(
k)
522 <<
" in the JEC payload, this usually means you have to change the global tag" << std::endl;
529 for ( collection_type::const_iterator ibegin = corrections_.begin(),
530 iend = corrections_.end(),
i = ibegin;
i != iend; ++
i ) {
531 keys.push_back(
i->first );
533 for ( collection_type::const_iterator ibegin = correctionsL5_.begin(),
534 iend = correctionsL5_.end(),
i = ibegin;
i != iend; ++
i ) {
535 keys.push_back(
i->first );
537 for ( collection_type::const_iterator ibegin = correctionsL7_.begin(),
538 iend = correctionsL7_.end(),
i = ibegin;
i != iend; ++
i ) {
539 keys.push_back(
i->first );
547 std::vector<std::string>::const_iterator
found =
548 find( l5Flavors_.begin(), l5Flavors_.end(), flav );
549 if ( found != l5Flavors_.end() ) {
550 return (found - l5Flavors_.begin() + 1) * 100;
552 else return L5Flavor;
557 std::vector<std::string>::const_iterator
found =
558 find( l7Partons_.begin(), l7Partons_.end(), flav );
559 if ( found != l7Partons_.end() ) {
560 return (found - l7Partons_.begin() + 1) * 1000;
562 else return L7Parton;
567 return k == L5Flavor ||
568 ( k / 100 > 0 && k / 1000 == 0 );
572 return k == L7Parton ||
582 std::vector<std::string>::const_iterator found1 =
583 find( l5Flavors_.begin(), l5Flavors_.end(),
label );
584 if ( found1 != l5Flavors_.end() ) {
585 return getL5Bin(label);
589 std::vector<std::string>::const_iterator found2 =
590 find( l7Partons_.begin(), l7Partons_.end(),
label );
591 if ( found2 != l7Partons_.end() ) {
592 return getL7Bin(label);
596 std::vector<std::string>::const_iterator found3 =
597 find( labels_.begin(), labels_.end(),
label );
598 if ( found3 != labels_.end() ) {
599 return static_cast<key_type>(found3 - labels_.begin());
603 throw cms::Exception(
"InvalidInput") <<
" Cannot find label " << label << std::endl;
float xMin(unsigned fVar) const
std::vector< float > mMax
static std::string findLabel(key_type k)
void push_back(key_type i, value_type const &j, label_type const &flav="")
std::vector< float > mMin
const Definitions & definitions() const
static key_type getL5Bin(std::string const &flav)
std::vector< JetCorrectorParameters::Record > mRecords
const Record & record(unsigned fBin) const
std::vector< float > mParameters
std::vector< std::string > parVar() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::string formula() const
static std::string const input
static std::string findL5Flavor(key_type k)
float parameter(unsigned fIndex) const
std::ostream & operator<<(std::ostream &out, const JetCorrectorParameters::Record &fBin)
void printFile(const std::string &fFileName) const
int binIndex(const std::vector< float > &fX) const
std::vector< float > binCenters(unsigned fVar) const
static std::string findL7Parton(key_type k)
static const int MAX_SIZE_DIMENSIONALITY
float xMiddle(unsigned fVar) const
key_type findKey(std::string const &label) const
static bool isL7(key_type k)
float xMax(unsigned fVar) const
#define TYPELOOKUP_DATA_REG(_dataclass_)
std::string level() const
def getSection(rootNode, name)
static bool isL5(key_type k)
std::vector< std::string > mParVar
std::vector< std::string > mBinVar
int binIndexN(const std::vector< float > &fX) const
static key_type getL7Bin(std::string const &flav)
std::vector< std::vector< double > > tmp
unsigned nParameters() const
static void getSections(std::string inputFile, std::vector< std::string > &outputs)
void validKeys(std::vector< key_type > &keys) const
std::vector< std::string > binVar() const
JetCorrectorParameters::Definitions mDefinitions
int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const
JetCorrectorParameters const & operator[](key_type k) const