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 JetCorrectorParameters::Definitions &fDefinitions, const std::vector< JetCorrectorParameters::Record > &fRecords)
 
 JetCorrectorParameters (const std::string &fFile, const std::string &fSection="")
 
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 104 of file JetCorrectorParameters.h.

104 { valid_ = false; }

References valid_.

◆ JetCorrectorParameters() [2/3]

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

Definition at line 113 of file JetCorrectorParameters.cc.

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 }

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, AlCaHLTBitMon_QueryRunRegistry::string, createJobs::tmp, valid_, JetCorrectorParameters::Record::xMax(), and JetCorrectorParameters::Record::xMin().

◆ JetCorrectorParameters() [3/3]

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

Definition at line 106 of file JetCorrectorParameters.h.

108  : mDefinitions(fDefinitions), mRecords(fRecords) {
109  valid_ = true;
110  }

References valid_.

Member Function Documentation

◆ binCenters()

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

Definition at line 267 of file JetCorrectorParameters.cc.

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 }

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

◆ binIndex()

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

Definition at line 176 of file JetCorrectorParameters.cc.

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 }

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().

◆ binIndexN()

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

Definition at line 200 of file JetCorrectorParameters.cc.

200  {
201  if (helper->size() > 0) {
202  return helper->binIndexN(fX, mRecords);
203  } else {
204  return -1;
205  }
206 }

References mRecords.

Referenced by SimpleJetCorrector::correction().

◆ definitions()

const Definitions& JetCorrectorParameters::definitions ( ) const
inline

◆ init()

void JetCorrectorParameters::init ( void  )

Definition at line 168 of file JetCorrectorParameters.cc.

168  {
169  std::sort(mRecords.begin(), mRecords.end());
170  helper = std::make_shared<JetCorrectorParametersHelper>();
171  helper->init(mDefinitions, mRecords);
172 }

References mDefinitions, and mRecords.

Referenced by JetCorrectorParameters().

◆ isValid()

bool JetCorrectorParameters::isValid ( void  ) const
inline

Definition at line 122 of file JetCorrectorParameters.h.

122 { return valid_; }

References valid_.

Referenced by ntupleDataFormat._Object::_checkIsValid(), and core.AutoHandle.AutoHandle::ReallyLoad().

◆ neighbourBin()

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

Definition at line 210 of file JetCorrectorParameters.cc.

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 }

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().

◆ printFile()

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

Definition at line 314 of file JetCorrectorParameters.cc.

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 }

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().

◆ printScreen()

void JetCorrectorParameters::printScreen ( ) const

Definition at line 276 of file JetCorrectorParameters.cc.

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 }

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().

◆ 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 247 of file JetCorrectorParameters.cc.

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 }

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__().

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 135 of file JetCorrectorParameters.h.

◆ cond::serialization::access

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

Definition at line 135 of file JetCorrectorParameters.h.

Member Data Documentation

◆ helper

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

is this a valid set?

Definition at line 133 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 130 of file JetCorrectorParameters.h.

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

◆ valid_

bool JetCorrectorParameters::valid_
private

Definition at line 131 of file JetCorrectorParameters.h.

Referenced by isValid(), and JetCorrectorParameters().

mps_fire.i
i
Definition: mps_fire.py:428
JetCorrectorParameters::Definitions::binVar
std::vector< std::string > binVar() const
Definition: JetCorrectorParameters.h:44
input
static const std::string input
Definition: EdmProvDump.cc:48
JetCorrectorParameters::Record::xMax
float xMax(unsigned fVar) const
Definition: JetCorrectorParameters.h:76
pfMETCorrectionType0_cfi.formula
formula
Definition: pfMETCorrectionType0_cfi.py:46
gather_cfg.cout
cout
Definition: gather_cfg.py:144
JetCorrectorParameters::Record::parameter
float parameter(unsigned fIndex) const
Definition: JetCorrectorParameters.h:78
JetCorrectorParameters::definitions
const Definitions & definitions() const
Definition: JetCorrectorParameters.h:113
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
photonAnalyzer_cfi.xMin
xMin
Definition: photonAnalyzer_cfi.py:82
JetCorrectorParameters::Definitions::nBinVar
unsigned nBinVar() const
Definition: JetCorrectorParameters.h:41
RPCNoise_example.check
check
Definition: RPCNoise_example.py:71
JetCorrectorParameters::Definitions::level
std::string level() const
Definition: JetCorrectorParameters.h:48
JetCorrectorParameters::Definitions::parVar
std::vector< std::string > parVar() const
Definition: JetCorrectorParameters.h:43
N
#define N
Definition: blowfish.cc:9
JetCorrectorParameters::mDefinitions
JetCorrectorParameters::Definitions mDefinitions
Definition: JetCorrectorParameters.h:129
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
JetCorrectorParameters::Record::xMin
float xMin(unsigned fVar) const
Definition: JetCorrectorParameters.h:75
JetCorrectorParameters::mRecords
std::vector< JetCorrectorParameters::Record > mRecords
Definition: JetCorrectorParameters.h:130
helper
Definition: helper.py:1
JetCorrectorParameters::Definitions::nParVar
unsigned nParVar() const
Definition: JetCorrectorParameters.h:42
JetCorrectorParameters::record
const Record & record(unsigned fBin) const
Definition: JetCorrectorParameters.h:112
definitions
Definition: definitions.py:1
JetCorrectorParameters::Definitions::formula
std::string formula() const
Definition: JetCorrectorParameters.h:47
JetCorrectorParameters::init
void init()
Definition: JetCorrectorParameters.cc:168
Record
JetCorrectorParameters::size
unsigned size() const
Definition: JetCorrectorParameters.h:114
hgcalPlots.section
section
Definition: hgcalPlots.py:2049
multiplicitycorr_cfi.xMax
xMax
Definition: multiplicitycorr_cfi.py:5
JetCorrectorParameters::MAX_SIZE_DIMENSIONALITY
static const int MAX_SIZE_DIMENSIONALITY
Definition: JetCorrectorParameters.h:125
mps_fire.result
result
Definition: mps_fire.py:311
JetCorrectorParameters::valid_
bool valid_
Definition: JetCorrectorParameters.h:131
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
mps_splice.line
line
Definition: mps_splice.py:76
JetCorrectorParameters::Record::nParameters
unsigned nParameters() const
Definition: JetCorrectorParameters.h:80