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::JetCorrectorParameters ( )
inline

Definition at line 104 of file JetCorrectorParameters.h.

References AlCaHLTBitMon_QueryRunRegistry::string, and valid_.

104 { valid_ = false; }
JetCorrectorParameters::JetCorrectorParameters ( const std::string &  fFile,
const std::string &  fSection = "" 
)

Definition at line 113 of file JetCorrectorParameters.cc.

References RPCNoise_example::check, definitions(), JetCorrectorParameters::Definitions::formula(), mps_fire::i, init(), input, mps_splice::line, MAX_SIZE_DIMENSIONALITY, mDefinitions, mRecords, JetCorrectorParameters::Definitions::nBinVar(), JetCorrectorParameters::Record::nParameters(), record(), trackingPlots::section, 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  std::string section = getSection(line);
120  std::string tmp = getDefinitions(line);
121  if (!section.empty() && tmp.empty()) {
122  currentSection = section;
123  continue;
124  }
125  if (currentSection == fSection) {
126  if (!tmp.empty()) {
127  currentDefinitions = tmp;
128  continue;
129  }
130  Definitions definitions(currentDefinitions);
131  if (!(definitions.nBinVar() == 0 && definitions.formula().empty()))
134  bool check(true);
135  for (unsigned i = 0; i < mDefinitions.nBinVar(); ++i)
136  if (record.xMin(i) == 0 && record.xMax(i) == 0)
137  check = false;
138  if (record.nParameters() == 0)
139  check = false;
140  if (check)
141  mRecords.push_back(record);
142  }
143  }
144  if (currentDefinitions.empty())
145  handleError("JetCorrectorParameters", "No definitions found!!!");
146  if (mRecords.empty() && currentSection.empty())
147  mRecords.push_back(Record());
148  if (mRecords.empty() && !currentSection.empty()) {
149  std::stringstream sserr;
150  sserr << "the requested section " << fSection << " doesn't exist!";
151  handleError("JetCorrectorParameters", sserr.str());
152  }
153  std::sort(mRecords.begin(), mRecords.end());
154  valid_ = true;
155 
157  init();
158  } else {
159  std::stringstream sserr;
160  sserr << "since the binned dimensionality is greater than " << MAX_SIZE_DIMENSIONALITY
161  << " the SimpleJetCorrector will default to using the legacy binIndex function!";
162  handleError("JetCorrectorParameters", sserr.str());
163  }
164 }
float xMin(unsigned fVar) const
const Definitions & definitions() const
std::vector< JetCorrectorParameters::Record > mRecords
const Record & record(unsigned fBin) const
static std::string const input
Definition: EdmProvDump.cc:48
static const int MAX_SIZE_DIMENSIONALITY
float xMax(unsigned fVar) const
tmp
align.sh
Definition: createJobs.py:716
JetCorrectorParameters::Definitions mDefinitions
JetCorrectorParameters::JetCorrectorParameters ( const JetCorrectorParameters::Definitions fDefinitions,
const std::vector< JetCorrectorParameters::Record > &  fRecords 
)
inline

Definition at line 106 of file JetCorrectorParameters.h.

References valid_.

108  : mDefinitions(fDefinitions), mRecords(fRecords) {
109  valid_ = true;
110  }
std::vector< JetCorrectorParameters::Record > mRecords
JetCorrectorParameters::Definitions mDefinitions

Member Function Documentation

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

Definition at line 267 of file JetCorrectorParameters.cc.

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

Referenced by size().

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

Definition at line 176 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(), JetResolution::parameterEtaEval(), size(), and SimpleJetCorrectionUncertainty::uncertainty().

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

Definition at line 200 of file JetCorrectorParameters.cc.

References mRecords.

Referenced by SimpleJetCorrector::correction(), and size().

200  {
201  if (helper->size() > 0) {
202  return helper->binIndexN(fX, mRecords);
203  } else {
204  return -1;
205  }
206 }
Definition: helper.py:1
std::vector< JetCorrectorParameters::Record > mRecords
const Definitions& JetCorrectorParameters::definitions ( ) const
inline
void JetCorrectorParameters::init ( void  )

Definition at line 168 of file JetCorrectorParameters.cc.

References mDefinitions, and mRecords.

Referenced by isValid(), and JetCorrectorParameters().

168  {
169  std::sort(mRecords.begin(), mRecords.end());
170  helper = std::make_shared<JetCorrectorParametersHelper>();
171  helper->init(mDefinitions, mRecords);
172 }
Definition: helper.py:1
std::vector< JetCorrectorParameters::Record > mRecords
JetCorrectorParameters::Definitions mDefinitions
bool JetCorrectorParameters::isValid ( void  ) const
inline
int JetCorrectorParameters::neighbourBin ( unsigned  fIndex,
unsigned  fVar,
bool  fNext 
) const

Definition at line 210 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 size().

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

Definition at line 314 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(), and size().

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

Definition at line 276 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(), and size().

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

Definition at line 247 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__().

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

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 135 of file JetCorrectorParameters.h.

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

Definition at line 135 of file JetCorrectorParameters.h.

Member Data Documentation

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

is this a valid set?

Definition at line 133 of file JetCorrectorParameters.h.

const int JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY = 3
static
JetCorrectorParameters::Definitions JetCorrectorParameters::mDefinitions
private
std::vector<JetCorrectorParameters::Record> JetCorrectorParameters::mRecords
private

Definition at line 130 of file JetCorrectorParameters.h.

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

bool JetCorrectorParameters::valid_
private

Definition at line 131 of file JetCorrectorParameters.h.

Referenced by isValid(), and JetCorrectorParameters().