CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | 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
 
const Definitionsdefinitions () const
 
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
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 is this a valid set? More...
 

Private Attributes

JetCorrectorParameters::Definitions mDefinitions
 
std::vector
< JetCorrectorParameters::Record
mRecords
 
bool valid_
 

Friends

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

Detailed Description

Definition at line 19 of file JetCorrectorParameters.h.

Constructor & Destructor Documentation

JetCorrectorParameters::JetCorrectorParameters ( )
inline

Definition at line 81 of file JetCorrectorParameters.h.

References valid_.

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

Definition at line 109 of file JetCorrectorParameters.cc.

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

110 {
111  std::ifstream input(fFile.c_str());
112  std::string currentSection = "";
114  std::string currentDefinitions = "";
115  while (std::getline(input,line))
116  {
117  std::string section = getSection(line);
118  std::string tmp = getDefinitions(line);
119  if (!section.empty() && tmp.empty())
120  {
121  currentSection = section;
122  continue;
123  }
124  if (currentSection == fSection)
125  {
126  if (!tmp.empty())
127  {
128  currentDefinitions = tmp;
129  continue;
130  }
131  Definitions definitions(currentDefinitions);
132  if (!(definitions.nBinVar()==0 && definitions.formula()==""))
135  bool check(true);
136  for(unsigned i=0;i<mDefinitions.nBinVar();++i)
137  if (record.xMin(i)==0 && record.xMax(i)==0)
138  check = false;
139  if (record.nParameters() == 0)
140  check = false;
141  if (check)
142  mRecords.push_back(record);
143  }
144  }
145  if (currentDefinitions=="")
146  handleError("JetCorrectorParameters","No definitions found!!!");
147  if (mRecords.empty() && currentSection == "") mRecords.push_back(Record());
148  if (mRecords.empty() && currentSection != "")
149  {
150  std::stringstream sserr;
151  sserr<<"the requested section "<<fSection<<" doesn't exist!";
152  handleError("JetCorrectorParameters",sserr.str());
153  }
154  std::sort(mRecords.begin(), mRecords.end());
155  valid_ = true;
156 }
float xMin(unsigned fVar) const
int i
Definition: DBlmapReader.cc:9
const Definitions & definitions() const
std::vector< JetCorrectorParameters::Record > mRecords
const Record & record(unsigned fBin) const
static std::string const input
Definition: EdmProvDump.cc:44
bool check(const std::string &)
float xMax(unsigned fVar) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
JetCorrectorParameters::Definitions mDefinitions
JetCorrectorParameters::JetCorrectorParameters ( const JetCorrectorParameters::Definitions fDefinitions,
const std::vector< JetCorrectorParameters::Record > &  fRecords 
)
inline

Definition at line 83 of file JetCorrectorParameters.h.

References valid_.

85  : 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 252 of file JetCorrectorParameters.cc.

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

253 {
254  std::vector<float> result;
255  for (unsigned i = 0; i < size(); ++i)
256  result.push_back(record(i).xMiddle(fVar));
257  return result;
258 }
int i
Definition: DBlmapReader.cc:9
const Record & record(unsigned fBin) const
tuple result
Definition: mps_fire.py:95
int JetCorrectorParameters::binIndex ( const std::vector< float > &  fX) const

Definition at line 160 of file JetCorrectorParameters.cc.

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

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

161 {
162  int result = -1;
163  unsigned N = mDefinitions.nBinVar();
164  if (N != fX.size())
165  {
166  std::stringstream sserr;
167  sserr<<"# bin variables "<<N<<" doesn't correspont to requested #: "<<fX.size();
168  handleError("JetCorrectorParameters",sserr.str());
169  }
170  unsigned tmp;
171  for (unsigned i = 0; i < size(); ++i)
172  {
173  tmp = 0;
174  for (unsigned j=0;j<N;j++)
175  if (fX[j] >= record(i).xMin(j) && fX[j] < record(i).xMax(j))
176  tmp+=1;
177  if (tmp==N)
178  {
179  result = i;
180  break;
181  }
182  }
183  return result;
184 }
float xMin(unsigned fVar) const
int i
Definition: DBlmapReader.cc:9
const Record & record(unsigned fBin) const
tuple result
Definition: mps_fire.py:95
int j
Definition: DBlmapReader.cc:9
float xMax(unsigned fVar) const
#define N
Definition: blowfish.cc:9
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
JetCorrectorParameters::Definitions mDefinitions
const Definitions& JetCorrectorParameters::definitions ( ) const
inline
bool JetCorrectorParameters::isValid ( void  ) const
inline

Definition at line 96 of file JetCorrectorParameters.h.

References valid_.

Referenced by core.AutoHandle.AutoHandle::ReallyLoad().

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

Definition at line 188 of file JetCorrectorParameters.cc.

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

Referenced by SimpleJetCorrector::correction().

189 {
190  int result = -1;
191  unsigned N = mDefinitions.nBinVar();
192  if (fVar >= N)
193  {
194  std::stringstream sserr;
195  sserr<<"# of bin variables "<<N<<" doesn't correspond to requested #: "<<fVar;
196  handleError("JetCorrectorParameters",sserr.str());
197  }
198  unsigned tmp;
199  for (unsigned i = 0; i < size(); ++i)
200  {
201  tmp = 0;
202  for (unsigned j=0;j<fVar;j++)
203  if (fabs(record(i).xMin(j)-record(fIndex).xMin(j))<0.0001)
204  tmp+=1;
205  for (unsigned j=fVar+1;j<N;j++)
206  if (fabs(record(i).xMin(j)-record(fIndex).xMin(j))<0.0001)
207  tmp+=1;
208  if (tmp<N-1)
209  continue;
210  if (tmp==N-1)
211  {
212  if (fNext)
213  if (fabs(record(i).xMin(fVar)-record(fIndex).xMax(fVar))<0.0001)
214  tmp+=1;
215  if (!fNext)
216  if (fabs(record(i).xMax(fVar)-record(fIndex).xMin(fVar))<0.0001)
217  tmp+=1;
218  }
219  if (tmp==N)
220  {
221  result = i;
222  break;
223  }
224  }
225  return result;
226 }
int i
Definition: DBlmapReader.cc:9
const Record & record(unsigned fBin) const
tuple result
Definition: mps_fire.py:95
int j
Definition: DBlmapReader.cc:9
#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 300 of file JetCorrectorParameters.cc.

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

301 {
302  std::ofstream txtFile;
303  txtFile.open(fFileName.c_str());
304  txtFile.setf(std::ios::right);
305  txtFile<<"{"<<definitions().nBinVar()<<std::setw(15);
306  for(unsigned i=0;i<definitions().nBinVar();i++)
307  txtFile<<definitions().binVar(i)<<std::setw(15);
308  txtFile<<definitions().nParVar()<<std::setw(15);
309  for(unsigned i=0;i<definitions().nParVar();i++)
310  txtFile<<definitions().parVar(i)<<std::setw(15);
311  txtFile<<std::setw(definitions().formula().size()+15)<<definitions().formula()<<std::setw(15);
312  if (definitions().isResponse())
313  txtFile<<"Response"<<std::setw(15);
314  else
315  txtFile<<"Correction"<<std::setw(15);
316  txtFile<<definitions().level()<<"}"<<"\n";
317  for(unsigned i=0;i<size();i++)
318  {
319  for(unsigned j=0;j<definitions().nBinVar();j++)
320  txtFile<<record(i).xMin(j)<<std::setw(15)<<record(i).xMax(j)<<std::setw(15);
321  txtFile<<record(i).nParameters()<<std::setw(15);
322  for(unsigned j=0;j<record(i).nParameters();j++)
323  txtFile<<record(i).parameter(j)<<std::setw(15);
324  txtFile<<"\n";
325  }
326  txtFile.close();
327 }
float xMin(unsigned fVar) const
int i
Definition: DBlmapReader.cc:9
const Definitions & definitions() const
const Record & record(unsigned fBin) const
std::vector< std::string > parVar() const
float parameter(unsigned fIndex) const
int j
Definition: DBlmapReader.cc:9
float xMax(unsigned fVar) const
std::vector< std::string > binVar() const
void JetCorrectorParameters::printScreen ( ) const

Definition at line 262 of file JetCorrectorParameters.cc.

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

263 {
264  std::cout<<"--------------------------------------------"<<std::endl;
265  std::cout<<"//////// PARAMETERS: //////////////////////"<<std::endl;
266  std::cout<<"--------------------------------------------"<<std::endl;
267  std::cout<<"Number of binning variables: "<<definitions().nBinVar()<<std::endl;
268  std::cout<<"Names of binning variables: ";
269  for(unsigned i=0;i<definitions().nBinVar();i++)
270  std::cout<<definitions().binVar(i)<<" ";
271  std::cout<<std::endl;
272  std::cout<<"--------------------------------------------"<<std::endl;
273  std::cout<<"Number of parameter variables: "<<definitions().nParVar()<<std::endl;
274  std::cout<<"Names of parameter variables: ";
275  for(unsigned i=0;i<definitions().nParVar();i++)
276  std::cout<<definitions().parVar(i)<<" ";
277  std::cout<<std::endl;
278  std::cout<<"--------------------------------------------"<<std::endl;
279  std::cout<<"Parametrization Formula: "<<definitions().formula()<<std::endl;
280  if (definitions().isResponse())
281  std::cout<<"Type (Response or Correction): "<<"Response"<<std::endl;
282  else
283  std::cout<<"Type (Response or Correction): "<<"Correction"<<std::endl;
284  std::cout<<"Correction Level: "<<definitions().level()<<std::endl;
285  std::cout<<"--------------------------------------------"<<std::endl;
286  std::cout<<"------- Bin contents -----------------------"<<std::endl;
287  for(unsigned i=0;i<size();i++)
288  {
289  for(unsigned j=0;j<definitions().nBinVar();j++)
290  std::cout<<record(i).xMin(j)<<" "<<record(i).xMax(j)<<" ";
291  std::cout<<record(i).nParameters()<<" ";
292  for(unsigned j=0;j<record(i).nParameters();j++)
293  std::cout<<record(i).parameter(j)<<" ";
294  std::cout<<std::endl;
295  }
296 }
float xMin(unsigned fVar) const
int i
Definition: DBlmapReader.cc:9
const Definitions & definitions() const
const Record & record(unsigned fBin) const
std::vector< std::string > parVar() const
float parameter(unsigned fIndex) const
int j
Definition: DBlmapReader.cc:9
float xMax(unsigned fVar) const
tuple cout
Definition: gather_cfg.py:145
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

is this a valid set?

unsigned JetCorrectorParameters::size ( void  ) const
inline
unsigned JetCorrectorParameters::size ( unsigned  fVar) const

Definition at line 230 of file JetCorrectorParameters.cc.

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

231 {
232  if (fVar >= mDefinitions.nBinVar())
233  {
234  std::stringstream sserr;
235  sserr<<"requested bin variable index "<<fVar<<" is greater than number of variables "<<mDefinitions.nBinVar();
236  handleError("JetCorrectorParameters",sserr.str());
237  }
238  unsigned result = 0;
239  float tmpMin(-9999),tmpMax(-9999);
240  for (unsigned i = 0; i < size(); ++i)
241  if (record(i).xMin(fVar) > tmpMin && record(i).xMax(fVar) > tmpMax)
242  {
243  result++;
244  tmpMin = record(i).xMin(fVar);
245  tmpMax = record(i).xMax(fVar);
246  }
247  return result;
248 }
float xMin(unsigned fVar) const
int i
Definition: DBlmapReader.cc:9
const Record & record(unsigned fBin) const
tuple result
Definition: mps_fire.py:95
float xMax(unsigned fVar) const
JetCorrectorParameters::Definitions mDefinitions

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 104 of file JetCorrectorParameters.h.

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

Definition at line 104 of file JetCorrectorParameters.h.

Member Data Documentation

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

Definition at line 101 of file JetCorrectorParameters.h.

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

bool JetCorrectorParameters::valid_
private

Definition at line 102 of file JetCorrectorParameters.h.

Referenced by isValid(), and JetCorrectorParameters().