CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends
JetCorrectorParameters Class Reference

#include <JetCorrectorParameters.h>

Classes

class  Definitions
 
class  Record
 

Public Member Functions

std::vector< float > binCenters (unsigned fVar) const
 
int binIndex (const std::vector< float > &fX) const
 
int binIndexN (const std::vector< float > &fX) const
 
const Definitionsdefinitions () const
 
void init ()
 
bool isValid () const
 
 JetCorrectorParameters ()
 
 JetCorrectorParameters (const std::string &fFile, const std::string &fSection="")
 
 JetCorrectorParameters (const JetCorrectorParameters::Definitions &fDefinitions, const std::vector< JetCorrectorParameters::Record > &fRecords)
 
int neighbourBin (unsigned fIndex, unsigned fVar, bool fNext) const
 
void printFile (const std::string &fFileName) const
 
void printScreen () const
 
const Recordrecord (unsigned fBin) const
 
unsigned size () const
 
unsigned size (unsigned fVar) const
 

Static Public Attributes

static const int MAX_SIZE_DIMENSIONALITY = 3
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Private Attributes

std::shared_ptr< JetCorrectorParametersHelperhelper
 is this a valid set? More...
 
JetCorrectorParameters::Definitions mDefinitions
 
std::vector< JetCorrectorParameters::RecordmRecords
 
bool valid_
 

Friends

class boost::serialization::access
 
template<typename CondSerializationT , typename Enabled >
struct cond::serialization::access
 

Detailed Description

Definition at line 25 of file JetCorrectorParameters.h.

Constructor & Destructor Documentation

◆ JetCorrectorParameters() [1/3]

JetCorrectorParameters::JetCorrectorParameters ( )
inline

Definition at line 113 of file JetCorrectorParameters.h.

References valid_.

113 { valid_ = false; }

◆ JetCorrectorParameters() [2/3]

JetCorrectorParameters::JetCorrectorParameters ( const std::string &  fFile,
const std::string &  fSection = "" 
)

Definition at line 113 of file JetCorrectorParameters.cc.

References RPCNoise_example::check, definitions(), mps_fire::i, init(), input, mps_splice::line, MAX_SIZE_DIMENSIONALITY, mDefinitions, mRecords, JetCorrectorParameters::Definitions::nBinVar(), JetCorrectorParameters::Record::nParameters(), record(), hgcalPlots::section, jetUpdater_cfi::sort, AlCaHLTBitMon_QueryRunRegistry::string, createJobs::tmp, valid_, JetCorrectorParameters::Record::xMax(), and JetCorrectorParameters::Record::xMin().

113  {
114  std::ifstream input(fFile.c_str());
115  std::string currentSection = "";
117  std::string currentDefinitions = "";
118  while (std::getline(input, line)) {
119  if (line.empty())
120  continue;
121  std::string section = getSection(line);
122  std::string tmp = getDefinitions(line);
123  if (!section.empty() && tmp.empty()) {
124  currentSection = section;
125  continue;
126  }
127  if (currentSection == fSection) {
128  if (!tmp.empty()) {
129  currentDefinitions = tmp;
130  continue;
131  }
132  Definitions definitions(currentDefinitions);
133  if (!(definitions.nBinVar() == 0 && definitions.formula().empty()))
136  bool check(true);
137  for (unsigned i = 0; i < mDefinitions.nBinVar(); ++i)
138  if (record.xMin(i) == 0 && record.xMax(i) == 0)
139  check = false;
140  if (record.nParameters() == 0)
141  check = false;
142  if (check)
143  mRecords.push_back(record);
144  }
145  }
146  if (currentDefinitions.empty())
147  handleError("JetCorrectorParameters", "No definitions found!!!");
148  if (mRecords.empty() && currentSection.empty())
149  mRecords.push_back(Record());
150  if (mRecords.empty() && !currentSection.empty()) {
151  std::stringstream sserr;
152  sserr << "the requested section " << fSection << " doesn't exist!";
153  handleError("JetCorrectorParameters", sserr.str());
154  }
155  std::sort(mRecords.begin(), mRecords.end());
156  valid_ = true;
157 
159  init();
160  } else {
161  std::stringstream sserr;
162  sserr << "since the binned dimensionality is greater than " << MAX_SIZE_DIMENSIONALITY
163  << " the SimpleJetCorrector will default to using the legacy binIndex function!";
164  handleError("JetCorrectorParameters", sserr.str());
165  }
166 }
std::vector< JetCorrectorParameters::Record > mRecords
static std::string const input
Definition: EdmProvDump.cc:50
static const int MAX_SIZE_DIMENSIONALITY
const Definitions & definitions() const
float xMin(unsigned fVar) const
tmp
align.sh
Definition: createJobs.py:716
JetCorrectorParameters::Definitions mDefinitions
float xMax(unsigned fVar) const
const Record & record(unsigned fBin) const

◆ JetCorrectorParameters() [3/3]

JetCorrectorParameters::JetCorrectorParameters ( const JetCorrectorParameters::Definitions fDefinitions,
const std::vector< JetCorrectorParameters::Record > &  fRecords 
)
inline

Definition at line 115 of file JetCorrectorParameters.h.

References valid_.

117  : mDefinitions(fDefinitions), mRecords(fRecords) {
118  valid_ = true;
119  }
std::vector< JetCorrectorParameters::Record > mRecords
JetCorrectorParameters::Definitions mDefinitions

Member Function Documentation

◆ binCenters()

std::vector< float > JetCorrectorParameters::binCenters ( unsigned  fVar) const

Definition at line 269 of file JetCorrectorParameters.cc.

References mps_fire::i, record(), mps_fire::result, and size().

269  {
270  std::vector<float> result;
271  for (unsigned i = 0; i < size(); ++i)
272  result.push_back(record(i).xMiddle(fVar));
273  return result;
274 }
const Record & record(unsigned fBin) const

◆ binIndex()

int JetCorrectorParameters::binIndex ( const std::vector< float > &  fX) const

Definition at line 178 of file JetCorrectorParameters.cc.

References mps_fire::i, dqmiolumiharvest::j, mDefinitions, N, JetCorrectorParameters::Definitions::nBinVar(), record(), mps_fire::result, size(), createJobs::tmp, JetCorrectorParameters::Record::xMax(), and JetCorrectorParameters::Record::xMin().

Referenced by SimpleJetCorrector::correction(), and SimpleJetCorrectionUncertainty::uncertainty().

178  {
179  int result = -1;
180  unsigned N = mDefinitions.nBinVar();
181  if (N != fX.size()) {
182  std::stringstream sserr;
183  sserr << "# bin variables " << N << " doesn't correspont to requested #: " << fX.size();
184  handleError("JetCorrectorParameters", sserr.str());
185  }
186  unsigned tmp;
187  for (unsigned i = 0; i < size(); ++i) {
188  tmp = 0;
189  for (unsigned j = 0; j < N; j++)
190  if (fX[j] >= record(i).xMin(j) && fX[j] < record(i).xMax(j))
191  tmp += 1;
192  if (tmp == N) {
193  result = i;
194  break;
195  }
196  }
197  return result;
198 }
#define N
Definition: blowfish.cc:9
float xMin(unsigned fVar) const
tmp
align.sh
Definition: createJobs.py:716
JetCorrectorParameters::Definitions mDefinitions
float xMax(unsigned fVar) const
const Record & record(unsigned fBin) const

◆ binIndexN()

int JetCorrectorParameters::binIndexN ( const std::vector< float > &  fX) const

Definition at line 202 of file JetCorrectorParameters.cc.

References mRecords.

Referenced by SimpleJetCorrector::correction().

202  {
203  if (helper->size() > 0) {
204  return helper->binIndexN(fX, mRecords);
205  } else {
206  return -1;
207  }
208 }
Definition: helper.py:1
std::vector< JetCorrectorParameters::Record > mRecords

◆ definitions()

const Definitions& JetCorrectorParameters::definitions ( ) const
inline

◆ init()

void JetCorrectorParameters::init ( void  )

Definition at line 170 of file JetCorrectorParameters.cc.

References mDefinitions, mRecords, and jetUpdater_cfi::sort.

Referenced by JetCorrectorParameters().

170  {
171  std::sort(mRecords.begin(), mRecords.end());
172  helper = std::make_shared<JetCorrectorParametersHelper>();
173  helper->init(mDefinitions, mRecords);
174 }
Definition: helper.py:1
std::vector< JetCorrectorParameters::Record > mRecords
JetCorrectorParameters::Definitions mDefinitions

◆ isValid()

bool JetCorrectorParameters::isValid ( void  ) const
inline

◆ neighbourBin()

int JetCorrectorParameters::neighbourBin ( unsigned  fIndex,
unsigned  fVar,
bool  fNext 
) const

Definition at line 212 of file JetCorrectorParameters.cc.

References mps_fire::i, dqmiolumiharvest::j, mDefinitions, N, JetCorrectorParameters::Definitions::nBinVar(), record(), mps_fire::result, size(), createJobs::tmp, multiplicitycorr_cfi::xMax, and photonAnalyzer_cfi::xMin.

Referenced by SimpleJetCorrector::correction().

212  {
213  int result = -1;
214  unsigned N = mDefinitions.nBinVar();
215  if (fVar >= N) {
216  std::stringstream sserr;
217  sserr << "# of bin variables " << N << " doesn't correspond to requested #: " << fVar;
218  handleError("JetCorrectorParameters", sserr.str());
219  }
220  unsigned tmp;
221  for (unsigned i = 0; i < size(); ++i) {
222  tmp = 0;
223  for (unsigned j = 0; j < fVar; j++)
224  if (fabs(record(i).xMin(j) - record(fIndex).xMin(j)) < 0.0001)
225  tmp += 1;
226  for (unsigned j = fVar + 1; j < N; j++)
227  if (fabs(record(i).xMin(j) - record(fIndex).xMin(j)) < 0.0001)
228  tmp += 1;
229  if (tmp < N - 1)
230  continue;
231  if (tmp == N - 1) {
232  if (fNext)
233  if (fabs(record(i).xMin(fVar) - record(fIndex).xMax(fVar)) < 0.0001)
234  tmp += 1;
235  if (!fNext)
236  if (fabs(record(i).xMax(fVar) - record(fIndex).xMin(fVar)) < 0.0001)
237  tmp += 1;
238  }
239  if (tmp == N) {
240  result = i;
241  break;
242  }
243  }
244  return result;
245 }
#define N
Definition: blowfish.cc:9
tmp
align.sh
Definition: createJobs.py:716
JetCorrectorParameters::Definitions mDefinitions
const Record & record(unsigned fBin) const

◆ printFile()

void JetCorrectorParameters::printFile ( const std::string &  fFileName) const

Definition at line 316 of file JetCorrectorParameters.cc.

References JetCorrectorParameters::Definitions::binVar(), definitions(), pfMETCorrectionType0_cfi::formula, JetCorrectorParameters::Definitions::formula(), mps_fire::i, dqmiolumiharvest::j, JetCorrectorParameters::Definitions::level(), JetCorrectorParameters::Definitions::nBinVar(), JetCorrectorParameters::Record::nParameters(), JetCorrectorParameters::Definitions::nParVar(), JetCorrectorParameters::Record::parameter(), JetCorrectorParameters::Definitions::parVar(), record(), size(), JetCorrectorParameters::Record::xMax(), and JetCorrectorParameters::Record::xMin().

Referenced by JetCorrectorDBReader::analyze().

316  {
317  std::ofstream txtFile;
318  txtFile.open(fFileName.c_str());
319  txtFile.setf(std::ios::right);
320  txtFile << "{" << definitions().nBinVar() << std::setw(15);
321  for (unsigned i = 0; i < definitions().nBinVar(); i++)
322  txtFile << definitions().binVar(i) << std::setw(15);
323  txtFile << definitions().nParVar() << std::setw(15);
324  for (unsigned i = 0; i < definitions().nParVar(); i++)
325  txtFile << definitions().parVar(i) << std::setw(15);
326  txtFile << std::setw(definitions().formula().size() + 15) << definitions().formula() << std::setw(15);
327  if (definitions().isResponse())
328  txtFile << "Response" << std::setw(15);
329  else
330  txtFile << "Correction" << std::setw(15);
331  txtFile << definitions().level() << "}"
332  << "\n";
333  for (unsigned i = 0; i < size(); i++) {
334  for (unsigned j = 0; j < definitions().nBinVar(); j++)
335  txtFile << record(i).xMin(j) << std::setw(15) << record(i).xMax(j) << std::setw(15);
336  txtFile << record(i).nParameters() << std::setw(15);
337  for (unsigned j = 0; j < record(i).nParameters(); j++)
338  txtFile << record(i).parameter(j) << std::setw(15);
339  txtFile << "\n";
340  }
341  txtFile.close();
342 }
std::vector< std::string > binVar() const
std::vector< std::string > parVar() const
const Definitions & definitions() const
float xMin(unsigned fVar) const
float parameter(unsigned fIndex) const
float xMax(unsigned fVar) const
const Record & record(unsigned fBin) const

◆ printScreen()

void JetCorrectorParameters::printScreen ( ) const

Definition at line 278 of file JetCorrectorParameters.cc.

References JetCorrectorParameters::Definitions::binVar(), gather_cfg::cout, definitions(), JetCorrectorParameters::Definitions::formula(), mps_fire::i, dqmiolumiharvest::j, JetCorrectorParameters::Definitions::level(), JetCorrectorParameters::Definitions::nBinVar(), JetCorrectorParameters::Record::nParameters(), JetCorrectorParameters::Definitions::nParVar(), JetCorrectorParameters::Record::parameter(), JetCorrectorParameters::Definitions::parVar(), record(), size(), JetCorrectorParameters::Record::xMax(), and JetCorrectorParameters::Record::xMin().

Referenced by JetCorrectorDBReader::analyze().

278  {
279  std::cout << "--------------------------------------------" << std::endl;
280  std::cout << "//////// PARAMETERS: //////////////////////" << std::endl;
281  std::cout << "--------------------------------------------" << std::endl;
282  std::cout << "Number of binning variables: " << definitions().nBinVar() << std::endl;
283  std::cout << "Names of binning variables: ";
284  for (unsigned i = 0; i < definitions().nBinVar(); i++)
285  std::cout << definitions().binVar(i) << " ";
286  std::cout << std::endl;
287  std::cout << "--------------------------------------------" << std::endl;
288  std::cout << "Number of parameter variables: " << definitions().nParVar() << std::endl;
289  std::cout << "Names of parameter variables: ";
290  for (unsigned i = 0; i < definitions().nParVar(); i++)
291  std::cout << definitions().parVar(i) << " ";
292  std::cout << std::endl;
293  std::cout << "--------------------------------------------" << std::endl;
294  std::cout << "Parametrization Formula: " << definitions().formula() << std::endl;
295  if (definitions().isResponse())
296  std::cout << "Type (Response or Correction): "
297  << "Response" << std::endl;
298  else
299  std::cout << "Type (Response or Correction): "
300  << "Correction" << std::endl;
301  std::cout << "Correction Level: " << definitions().level() << std::endl;
302  std::cout << "--------------------------------------------" << std::endl;
303  std::cout << "------- Bin contents -----------------------" << std::endl;
304  for (unsigned i = 0; i < size(); i++) {
305  for (unsigned j = 0; j < definitions().nBinVar(); j++)
306  std::cout << record(i).xMin(j) << " " << record(i).xMax(j) << " ";
307  std::cout << record(i).nParameters() << " ";
308  for (unsigned j = 0; j < record(i).nParameters(); j++)
309  std::cout << record(i).parameter(j) << " ";
310  std::cout << std::endl;
311  }
312 }
std::vector< std::string > binVar() const
std::vector< std::string > parVar() const
const Definitions & definitions() const
float xMin(unsigned fVar) const
float parameter(unsigned fIndex) const
float xMax(unsigned fVar) const
const Record & record(unsigned fBin) const

◆ record()

const Record& JetCorrectorParameters::record ( unsigned  fBin) const
inline

◆ serialize()

template<class Archive >
void JetCorrectorParameters::serialize ( Archive &  ar,
const unsigned int  version 
)
private

◆ size() [1/2]

unsigned JetCorrectorParameters::size ( void  ) const
inline

◆ size() [2/2]

unsigned JetCorrectorParameters::size ( unsigned  fVar) const

Definition at line 249 of file JetCorrectorParameters.cc.

References mps_fire::i, mDefinitions, JetCorrectorParameters::Definitions::nBinVar(), record(), mps_fire::result, size(), JetCorrectorParameters::Record::xMax(), and JetCorrectorParameters::Record::xMin().

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

249  {
250  if (fVar >= mDefinitions.nBinVar()) {
251  std::stringstream sserr;
252  sserr << "requested bin variable index " << fVar << " is greater than number of variables "
253  << mDefinitions.nBinVar();
254  handleError("JetCorrectorParameters", sserr.str());
255  }
256  unsigned result = 0;
257  float tmpMin(-9999), tmpMax(-9999);
258  for (unsigned i = 0; i < size(); ++i)
259  if (record(i).xMin(fVar) > tmpMin && record(i).xMax(fVar) > tmpMax) {
260  result++;
261  tmpMin = record(i).xMin(fVar);
262  tmpMax = record(i).xMax(fVar);
263  }
264  return result;
265 }
float xMin(unsigned fVar) const
JetCorrectorParameters::Definitions mDefinitions
float xMax(unsigned fVar) const
const Record & record(unsigned fBin) const

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 144 of file JetCorrectorParameters.h.

◆ cond::serialization::access

template<typename CondSerializationT , typename Enabled >
friend struct cond::serialization::access
friend

Definition at line 144 of file JetCorrectorParameters.h.

Member Data Documentation

◆ helper

std::shared_ptr<JetCorrectorParametersHelper> JetCorrectorParameters::helper
private

is this a valid set?

Definition at line 142 of file JetCorrectorParameters.h.

◆ MAX_SIZE_DIMENSIONALITY

const int JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY = 3
static

◆ mDefinitions

JetCorrectorParameters::Definitions JetCorrectorParameters::mDefinitions
private

◆ mRecords

std::vector<JetCorrectorParameters::Record> JetCorrectorParameters::mRecords
private

Definition at line 139 of file JetCorrectorParameters.h.

Referenced by binIndexN(), init(), JetCorrectorParameters(), record(), and size().

◆ valid_

bool JetCorrectorParameters::valid_
private

Definition at line 140 of file JetCorrectorParameters.h.

Referenced by isValid(), and JetCorrectorParameters().