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 95 of file JetCorrectorParameters.h.

References AlCaHLTBitMon_QueryRunRegistry::string, and valid_.

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

Definition at line 119 of file JetCorrectorParameters.cc.

References trackerTree::check(), definitions(), JetCorrectorParameters::Definitions::formula(), insertMaterial::getSection(), mps_fire::i, init(), input, geometryCSVtoXML::line, MAX_SIZE_DIMENSIONALITY, mDefinitions, mRecords, JetCorrectorParameters::Definitions::nBinVar(), JetCorrectorParameters::Record::nParameters(), record(), trackingPlots::section, AlCaHLTBitMon_QueryRunRegistry::string, tmp, valid_, JetCorrectorParameters::Record::xMax(), and JetCorrectorParameters::Record::xMin().

120 {
121  std::ifstream input(fFile.c_str());
122  std::string currentSection = "";
124  std::string currentDefinitions = "";
125  while (std::getline(input,line))
126  {
128  std::string tmp = getDefinitions(line);
129  if (!section.empty() && tmp.empty())
130  {
131  currentSection = section;
132  continue;
133  }
134  if (currentSection == fSection)
135  {
136  if (!tmp.empty())
137  {
138  currentDefinitions = tmp;
139  continue;
140  }
141  Definitions definitions(currentDefinitions);
142  if (!(definitions.nBinVar()==0 && definitions.formula()==""))
145  bool check(true);
146  for(unsigned i=0;i<mDefinitions.nBinVar();++i)
147  if (record.xMin(i)==0 && record.xMax(i)==0)
148  check = false;
149  if (record.nParameters() == 0)
150  check = false;
151  if (check)
152  mRecords.push_back(record);
153  }
154  }
155  if (currentDefinitions=="")
156  handleError("JetCorrectorParameters","No definitions found!!!");
157  if (mRecords.empty() && currentSection == "") mRecords.push_back(Record());
158  if (mRecords.empty() && currentSection != "")
159  {
160  std::stringstream sserr;
161  sserr<<"the requested section "<<fSection<<" doesn't exist!";
162  handleError("JetCorrectorParameters",sserr.str());
163  }
164  std::sort(mRecords.begin(), mRecords.end());
165  valid_ = true;
166 
168  {
169  init();
170  }
171  else
172  {
173  std::stringstream sserr;
174  sserr<<"since the binned dimensionality is greater than "<<MAX_SIZE_DIMENSIONALITY
175  <<" the SimpleJetCorrector will default to using the legacy binIndex function!";
176  handleError("JetCorrectorParameters",sserr.str());
177  }
178 }
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:44
static const int MAX_SIZE_DIMENSIONALITY
float xMax(unsigned fVar) const
def getSection(rootNode, name)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
def check(config)
Definition: trackerTree.py:14
JetCorrectorParameters::Definitions mDefinitions
JetCorrectorParameters::JetCorrectorParameters ( const JetCorrectorParameters::Definitions fDefinitions,
const std::vector< JetCorrectorParameters::Record > &  fRecords 
)
inline

Definition at line 97 of file JetCorrectorParameters.h.

References valid_.

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

Member Function Documentation

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

Definition at line 297 of file JetCorrectorParameters.cc.

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

Referenced by size().

298 {
299  std::vector<float> result;
300  for (unsigned i = 0; i < size(); ++i)
301  result.push_back(record(i).xMiddle(fVar));
302  return result;
303 }
const Record & record(unsigned fBin) const
int JetCorrectorParameters::binIndex ( const std::vector< float > &  fX) const

Definition at line 191 of file JetCorrectorParameters.cc.

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

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

192 {
193  int result = -1;
194  unsigned N = mDefinitions.nBinVar();
195  if (N != fX.size())
196  {
197  std::stringstream sserr;
198  sserr<<"# bin variables "<<N<<" doesn't correspont to requested #: "<<fX.size();
199  handleError("JetCorrectorParameters",sserr.str());
200  }
201  unsigned tmp;
202  for (unsigned i = 0; i < size(); ++i)
203  {
204  tmp = 0;
205  for (unsigned j=0;j<N;j++)
206  if (fX[j] >= record(i).xMin(j) && fX[j] < record(i).xMax(j))
207  tmp+=1;
208  if (tmp==N)
209  {
210  result = i;
211  break;
212  }
213  }
214  return result;
215 }
float xMin(unsigned fVar) const
const Record & record(unsigned fBin) const
float xMax(unsigned fVar) const
#define N
Definition: blowfish.cc:9
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
JetCorrectorParameters::Definitions mDefinitions
int JetCorrectorParameters::binIndexN ( const std::vector< float > &  fX) const

Definition at line 219 of file JetCorrectorParameters.cc.

References mRecords.

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

220 {
221  if(helper->size()>0)
222  {
223  return helper->binIndexN(fX,mRecords);
224  }
225  else
226  {
227  return -1;
228  }
229 }
Definition: helper.py:1
std::vector< JetCorrectorParameters::Record > mRecords
const Definitions& JetCorrectorParameters::definitions ( ) const
inline
void JetCorrectorParameters::init ( void  )

Definition at line 182 of file JetCorrectorParameters.cc.

References mDefinitions, and mRecords.

Referenced by isValid(), and JetCorrectorParameters().

183 {
184  std::sort(mRecords.begin(), mRecords.end());
185  helper = std::make_shared<JetCorrectorParametersHelper>();
186  helper->init(mDefinitions,mRecords);
187 }
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 233 of file JetCorrectorParameters.cc.

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

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

234 {
235  int result = -1;
236  unsigned N = mDefinitions.nBinVar();
237  if (fVar >= N)
238  {
239  std::stringstream sserr;
240  sserr<<"# of bin variables "<<N<<" doesn't correspond to requested #: "<<fVar;
241  handleError("JetCorrectorParameters",sserr.str());
242  }
243  unsigned tmp;
244  for (unsigned i = 0; i < size(); ++i)
245  {
246  tmp = 0;
247  for (unsigned j=0;j<fVar;j++)
248  if (fabs(record(i).xMin(j)-record(fIndex).xMin(j))<0.0001)
249  tmp+=1;
250  for (unsigned j=fVar+1;j<N;j++)
251  if (fabs(record(i).xMin(j)-record(fIndex).xMin(j))<0.0001)
252  tmp+=1;
253  if (tmp<N-1)
254  continue;
255  if (tmp==N-1)
256  {
257  if (fNext)
258  if (fabs(record(i).xMin(fVar)-record(fIndex).xMax(fVar))<0.0001)
259  tmp+=1;
260  if (!fNext)
261  if (fabs(record(i).xMax(fVar)-record(fIndex).xMin(fVar))<0.0001)
262  tmp+=1;
263  }
264  if (tmp==N)
265  {
266  result = i;
267  break;
268  }
269  }
270  return result;
271 }
const Record & record(unsigned fBin) const
#define N
Definition: blowfish.cc:9
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
JetCorrectorParameters::Definitions mDefinitions
void JetCorrectorParameters::printFile ( const std::string &  fFileName) const

Definition at line 345 of file JetCorrectorParameters.cc.

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

Referenced by JetCorrectorDBReader::analyze(), and size().

346 {
347  std::ofstream txtFile;
348  txtFile.open(fFileName.c_str());
349  txtFile.setf(std::ios::right);
350  txtFile<<"{"<<definitions().nBinVar()<<std::setw(15);
351  for(unsigned i=0;i<definitions().nBinVar();i++)
352  txtFile<<definitions().binVar(i)<<std::setw(15);
353  txtFile<<definitions().nParVar()<<std::setw(15);
354  for(unsigned i=0;i<definitions().nParVar();i++)
355  txtFile<<definitions().parVar(i)<<std::setw(15);
356  txtFile<<std::setw(definitions().formula().size()+15)<<definitions().formula()<<std::setw(15);
357  if (definitions().isResponse())
358  txtFile<<"Response"<<std::setw(15);
359  else
360  txtFile<<"Correction"<<std::setw(15);
361  txtFile<<definitions().level()<<"}"<<"\n";
362  for(unsigned i=0;i<size();i++)
363  {
364  for(unsigned j=0;j<definitions().nBinVar();j++)
365  txtFile<<record(i).xMin(j)<<std::setw(15)<<record(i).xMax(j)<<std::setw(15);
366  txtFile<<record(i).nParameters()<<std::setw(15);
367  for(unsigned j=0;j<record(i).nParameters();j++)
368  txtFile<<record(i).parameter(j)<<std::setw(15);
369  txtFile<<"\n";
370  }
371  txtFile.close();
372 }
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 307 of file JetCorrectorParameters.cc.

References JetCorrectorParameters::Definitions::binVar(), gather_cfg::cout, definitions(), JetCorrectorParameters::Definitions::formula(), mps_fire::i, 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().

308 {
309  std::cout<<"--------------------------------------------"<<std::endl;
310  std::cout<<"//////// PARAMETERS: //////////////////////"<<std::endl;
311  std::cout<<"--------------------------------------------"<<std::endl;
312  std::cout<<"Number of binning variables: "<<definitions().nBinVar()<<std::endl;
313  std::cout<<"Names of binning variables: ";
314  for(unsigned i=0;i<definitions().nBinVar();i++)
315  std::cout<<definitions().binVar(i)<<" ";
316  std::cout<<std::endl;
317  std::cout<<"--------------------------------------------"<<std::endl;
318  std::cout<<"Number of parameter variables: "<<definitions().nParVar()<<std::endl;
319  std::cout<<"Names of parameter variables: ";
320  for(unsigned i=0;i<definitions().nParVar();i++)
321  std::cout<<definitions().parVar(i)<<" ";
322  std::cout<<std::endl;
323  std::cout<<"--------------------------------------------"<<std::endl;
324  std::cout<<"Parametrization Formula: "<<definitions().formula()<<std::endl;
325  if (definitions().isResponse())
326  std::cout<<"Type (Response or Correction): "<<"Response"<<std::endl;
327  else
328  std::cout<<"Type (Response or Correction): "<<"Correction"<<std::endl;
329  std::cout<<"Correction Level: "<<definitions().level()<<std::endl;
330  std::cout<<"--------------------------------------------"<<std::endl;
331  std::cout<<"------- Bin contents -----------------------"<<std::endl;
332  for(unsigned i=0;i<size();i++)
333  {
334  for(unsigned j=0;j<definitions().nBinVar();j++)
335  std::cout<<record(i).xMin(j)<<" "<<record(i).xMax(j)<<" ";
336  std::cout<<record(i).nParameters()<<" ";
337  for(unsigned j=0;j<record(i).nParameters();j++)
338  std::cout<<record(i).parameter(j)<<" ";
339  std::cout<<std::endl;
340  }
341 }
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 275 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__().

276 {
277  if (fVar >= mDefinitions.nBinVar())
278  {
279  std::stringstream sserr;
280  sserr<<"requested bin variable index "<<fVar<<" is greater than number of variables "<<mDefinitions.nBinVar();
281  handleError("JetCorrectorParameters",sserr.str());
282  }
283  unsigned result = 0;
284  float tmpMin(-9999),tmpMax(-9999);
285  for (unsigned i = 0; i < size(); ++i)
286  if (record(i).xMin(fVar) > tmpMin && record(i).xMax(fVar) > tmpMax)
287  {
288  result++;
289  tmpMin = record(i).xMin(fVar);
290  tmpMax = record(i).xMax(fVar);
291  }
292  return result;
293 }
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 124 of file JetCorrectorParameters.h.

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

Definition at line 124 of file JetCorrectorParameters.h.

Member Data Documentation

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

is this a valid set?

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

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

bool JetCorrectorParameters::valid_
private

Definition at line 120 of file JetCorrectorParameters.h.

Referenced by isValid(), and JetCorrectorParameters().