CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
ResolutionFunction Class Reference

#include <ResolutionFunction.h>

Inheritance diagram for ResolutionFunction:
BaseFunction

Public Member Functions

resolutionFunctionBase< double * > * function (const unsigned int i)
 Get the ith resolution function. More...
 
 ResolutionFunction (TString identifier)
 
 ResolutionFunction (const MuScleFitDBobject *dbObject)
 
template<class U >
double sigmaCotgTh (const U &track, const int i=0) const
 The second, optional, parameter is the iteration number. More...
 
template<class U >
double sigmaPhi (const U &track, const int i=0) const
 The second, optional, parameter is the iteration number. More...
 
template<class U >
double sigmaPt (const U &track, const int i=0) const
 The second, optional, parameter is the iteration number. More...
 
 ~ResolutionFunction ()
 
- Public Member Functions inherited from BaseFunction
 BaseFunction ()
 
 BaseFunction (const MuScleFitDBobject *dbObject)
 Constructor when receiving database parameters. More...
 
std::vector< double > fitQuality () const
 Return the vector of fit quality values. More...
 
std::vector< int > identifiers () const
 Return the vector of function identifiers. More...
 
std::vector< double > parameters () const
 Return the vector of parameters. More...
 

Protected Member Functions

void readParameters (TString fileName)
 Parser of the parameters file. More...
 
- Protected Member Functions inherited from BaseFunction
template<class T >
void convertToArrays (T **&function_, const std::vector< T * > &functionVec_)
 Convert vectors to arrays for faster random access. The first pointer is replaced, thus it is taken by reference. More...
 

Protected Attributes

resolutionFunctionBase< double * > ** resolutionFunction_
 
std::vector< resolutionFunctionBase< double * > * > resolutionFunctionVec_
 
- Protected Attributes inherited from BaseFunction
std::vector< double > fitQuality_
 
double ** fitQualityArray_
 
std::vector< int > functionId_
 
int iterationNum_
 
double ** parArray_
 
std::vector< double > parVecVec_
 

Detailed Description

Class for the resolution function. It can be built from local file or from db.

Definition at line 15 of file ResolutionFunction.h.

Constructor & Destructor Documentation

ResolutionFunction::ResolutionFunction ( TString  identifier)
inline

The constructor takes a string identifying the parameters to read. It parses the txt file containing the parameters, extracts the index of the correction function and saves the corresponding pointer. It then fills the vector of parameters.

Definition at line 24 of file ResolutionFunction.h.

References gather_cfg::cout, BaseFunction::functionId_, and readParameters().

25  {
26  identifier.Prepend("MuonAnalysis/MomentumScaleCalibration/data/");
27  identifier.Append(".txt");
28  edm::FileInPath fileWithFullPath(identifier.Data());
29  readParameters( fileWithFullPath.fullPath() );
30 
31  std::vector<int>::const_iterator idIt = functionId_.begin();
32  for( ; idIt != functionId_.end(); ++idIt ) std::cout << "idIt = " << *idIt << std::endl;
33  }
void readParameters(TString fileName)
Parser of the parameters file.
std::vector< int > functionId_
Definition: BaseFunction.h:46
ResolutionFunction::ResolutionFunction ( const MuScleFitDBobject dbObject)
inline

This constructor is used when reading parameters from the db. It receives a pointer to an object of type MuScleFitDBobject containing the parameters and the functions identifiers. The object is the same for all the functions.

Definition at line 40 of file ResolutionFunction.h.

References BaseFunction::convertToArrays(), BaseFunction::functionId_, hcalTTPDigis_cfi::id, resolutionFunction_, resolutionFunctionService(), and resolutionFunctionVec_.

40  : BaseFunction( dbObject )
41  {
42  std::vector<int>::const_iterator id = functionId_.begin();
43  for( ; id != functionId_.end(); ++id ) {
45  }
46  // Fill the arrays that will be used when calling the correction function.
48  }
void convertToArrays(T **&function_, const std::vector< T * > &functionVec_)
Convert vectors to arrays for faster random access. The first pointer is replaced, thus it is taken by reference.
Definition: BaseFunction.h:56
resolutionFunctionBase< double * > ** resolutionFunction_
std::vector< resolutionFunctionBase< double * > * > resolutionFunctionVec_
std::vector< int > functionId_
Definition: BaseFunction.h:46
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
Definition: Functions.cc:38
ResolutionFunction::~ResolutionFunction ( )
inline

Definition at line 50 of file ResolutionFunction.h.

References BaseFunction::functionId_, mps_fire::i, BaseFunction::parArray_, and resolutionFunction_.

50  {
51  if( parArray_ != 0 ) {
52  for( unsigned int i=0; i<functionId_.size(); ++i ) {
53  delete[] parArray_[i];
54  delete resolutionFunction_[i];
55  }
56  delete[] parArray_;
57  delete[] resolutionFunction_;
58  }
59  }
resolutionFunctionBase< double * > ** resolutionFunction_
std::vector< int > functionId_
Definition: BaseFunction.h:46
double ** parArray_
Definition: BaseFunction.h:50

Member Function Documentation

resolutionFunctionBase<double * >* ResolutionFunction::function ( const unsigned int  i)
inline

Get the ith resolution function.

Definition at line 93 of file ResolutionFunction.h.

References MillePedeFileConverter_cfg::fileName, mps_fire::i, readParameters(), resolutionFunction_, and resolutionFunctionVec_.

94  {
95  if( resolutionFunctionVec_.size() > i ) return resolutionFunction_[i];
96  else return 0;
97  }
resolutionFunctionBase< double * > ** resolutionFunction_
std::vector< resolutionFunctionBase< double * > * > resolutionFunctionVec_
void ResolutionFunction::readParameters ( TString  fileName)
protected

Parser of the parameters file.

Definition at line 3 of file ResolutionFunction.cc.

References BaseFunction::convertToArrays(), BaseFunction::functionId_, recoMuon::in, align_cfg::iteration, BaseFunction::iterationNum_, geometryCSVtoXML::line, pileupDistInMC::num, BaseFunction::parArray_, BaseFunction::parVecVec_, resolutionFunction_, resolutionFunctionService(), resolutionFunctionVec_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by function(), and ResolutionFunction().

4 {
5  iterationNum_ = 0;
6  parArray_ = 0;
7  // std::vector<double> parameterErrors;
8 
9  // Read the parameters file
10  std::ifstream parametersFile(fileName.Data());
12 
13  std::string iteration("Iteration ");
14  // Loop on the file lines
15  while (parametersFile) {
16  getline( parametersFile, line );
17  size_t lineInt = line.find("value");
18 
19  // if( line.find(iteration) != std::string::npos ) {
20  size_t iterationSubStr = line.find(iteration);
21 
22  // Take the iteration number
23  if( iterationSubStr != std::string::npos ) {
24 
25  int functionNum = 0;
26  // This can be used when dealing with multiple iterations
27 
28  // std::cout << "line = " << line << std::endl;
29  std::stringstream sLine(line);
31  int wordCounter = 0;
32  // Warning: this strongly depends on the parameters file structure.
33  while( sLine >> num ) {
34  ++wordCounter;
35  // std::cout << "num["<<wordCounter<<"] = " << num << std::endl;
36  if( wordCounter == 8 ) {
37  std::stringstream in(num);
38  in >> functionNum;
39  }
40  if( wordCounter == 13 ) {
41  std::stringstream in(num);
42  in >> iterationNum_;
43  }
44  }
45  // std::cout << "iteration number = " << iterationNum_ << std::endl;
46  // std::cout << "scale function number = " << scaleFunctionNum << std::endl;
47 
48  // Create a new vector to hold the parameters for this iteration
49 // std::vector<double> parVec;
50 // parVecVec_.push_back(parVec);
51 
52  // Set the scaleFunction
53  // scaleFunction_ = scaleFunctionArrayForVec[scaleFunctionNum];
54  // scaleFunction_ = scaleFunctionArray[scaleFunctionNum];
55  functionId_.push_back(functionNum);
56  // scaleFunctionVec_.push_back( scaleFunctionArray[scaleFunctionNum] );
57  resolutionFunctionVec_.push_back( resolutionFunctionService( functionNum ) );
58  }
59  // Take the parameters for the current iteration
60  if ( (lineInt != std::string::npos) ) {
61  size_t subStr1 = line.find("value");
62  std::stringstream paramStr;
63  double param = 0;
64  // Even if all the rest of the line is taken, the following
65  // convertion to a double will stop at the end of the first number.
66  paramStr << line.substr(subStr1+5);
67  paramStr >> param;
68 // // Fill the last vector of parameters, which corresponds to this iteration.
69 // parVecVec_.back().push_back(param);
70  parVecVec_.push_back(param);
71  // std::cout << "param = " << param << std::endl;
72 
73  // This is to extract parameter errors
74  // size_t subStr2 = line.find("+-");
75  // std::stringstream parErrorStr;
76  // double parError = 0;
77  // parErrorStr << line.substr(subStr2+1);
78  // parErrorStr >> parError;
79  // parameterErrors.push_back(parError);
80  // std::cout << "parError = " << parError << std::endl;
81  }
82  }
83 
85 }
std::vector< double > parVecVec_
Definition: BaseFunction.h:47
void convertToArrays(T **&function_, const std::vector< T * > &functionVec_)
Convert vectors to arrays for faster random access. The first pointer is replaced, thus it is taken by reference.
Definition: BaseFunction.h:56
resolutionFunctionBase< double * > ** resolutionFunction_
std::vector< resolutionFunctionBase< double * > * > resolutionFunctionVec_
std::vector< int > functionId_
Definition: BaseFunction.h:46
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
Definition: Functions.cc:38
double ** parArray_
Definition: BaseFunction.h:50
template<class U >
double ResolutionFunction::sigmaCotgTh ( const U &  track,
const int  i = 0 
) const
inline

The second, optional, parameter is the iteration number.

Definition at line 76 of file ResolutionFunction.h.

References gather_cfg::cout, cmsRelvalreport::exit, mps_fire::i, BaseFunction::iterationNum_, BaseFunction::parArray_, resolutionFunction_, and resolutionFunctionBase< T >::sigmaCotgTh().

Referenced by MuScleFitUtils::massResolution().

76  {
77  if( i > iterationNum_ || i < 0 ) {
78  std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0" << std::endl;
79  exit(1);
80  }
81  return resolutionFunction_[i]->sigmaCotgTh(track.pt(), track.eta(), parArray_[i]);
82  }
resolutionFunctionBase< double * > ** resolutionFunction_
virtual double sigmaCotgTh(const double &pt, const double &eta, const T &parval)=0
double ** parArray_
Definition: BaseFunction.h:50
template<class U >
double ResolutionFunction::sigmaPhi ( const U &  track,
const int  i = 0 
) const
inline

The second, optional, parameter is the iteration number.

Definition at line 85 of file ResolutionFunction.h.

References gather_cfg::cout, cmsRelvalreport::exit, mps_fire::i, BaseFunction::iterationNum_, BaseFunction::parArray_, resolutionFunction_, and resolutionFunctionBase< T >::sigmaPhi().

Referenced by MuScleFitUtils::massResolution().

85  {
86  if( i > iterationNum_ || i < 0 ) {
87  std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0" << std::endl;
88  exit(1);
89  }
90  return resolutionFunction_[i]->sigmaPhi(track.pt(), track.eta(), parArray_[i]);
91  }
resolutionFunctionBase< double * > ** resolutionFunction_
virtual double sigmaPhi(const double &pt, const double &eta, const T &parval)=0
double ** parArray_
Definition: BaseFunction.h:50
template<class U >
double ResolutionFunction::sigmaPt ( const U &  track,
const int  i = 0 
) const
inline

The second, optional, parameter is the iteration number.

Definition at line 67 of file ResolutionFunction.h.

References gather_cfg::cout, cmsRelvalreport::exit, mps_fire::i, BaseFunction::iterationNum_, BaseFunction::parArray_, resolutionFunction_, and resolutionFunctionBase< T >::sigmaPt().

Referenced by MuScleFitUtils::massResolution().

67  {
68  if( i > iterationNum_ || i < 0 ) {
69  std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0" << std::endl;
70  exit(1);
71  }
72  return resolutionFunction_[i]->sigmaPt(track.pt(), track.eta(), parArray_[i]);
73  }
resolutionFunctionBase< double * > ** resolutionFunction_
virtual double sigmaPt(const double &pt, const double &eta, const T &parval)=0
double ** parArray_
Definition: BaseFunction.h:50

Member Data Documentation

resolutionFunctionBase<double * >** ResolutionFunction::resolutionFunction_
protected
std::vector<resolutionFunctionBase<double * > * > ResolutionFunction::resolutionFunctionVec_
protected

Definition at line 104 of file ResolutionFunction.h.

Referenced by function(), readParameters(), and ResolutionFunction().