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() [1/2]

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 23 of file ResolutionFunction.h.

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

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

◆ ResolutionFunction() [2/2]

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 39 of file ResolutionFunction.h.

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

39  : BaseFunction(dbObject) {
40  std::vector<int>::const_iterator id = functionId_.begin();
41  for (; id != functionId_.end(); ++id) {
43  }
44  // Fill the arrays that will be used when calling the correction function.
46  }
resolutionFunctionBase< double * > ** resolutionFunction_
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
Definition: Functions.cc:70
std::vector< int > functionId_
Definition: BaseFunction.h:38
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:48
std::vector< resolutionFunctionBase< double * > * > resolutionFunctionVec_

◆ ~ResolutionFunction()

ResolutionFunction::~ResolutionFunction ( )
inline

Definition at line 48 of file ResolutionFunction.h.

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

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

Member Function Documentation

◆ function()

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

Get the ith resolution function.

Definition at line 94 of file ResolutionFunction.h.

References mps_fire::i, resolutionFunction_, and resolutionFunctionVec_.

94  {
95  if (resolutionFunctionVec_.size() > i)
96  return resolutionFunction_[i];
97  else
98  return nullptr;
99  }
resolutionFunctionBase< double * > ** resolutionFunction_
std::vector< resolutionFunctionBase< double * > * > resolutionFunctionVec_

◆ readParameters()

void ResolutionFunction::readParameters ( TString  fileName)
protected

Parser of the parameters file.

Definition at line 3 of file ResolutionFunction.cc.

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

Referenced by ResolutionFunction().

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

◆ sigmaCotgTh()

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 75 of file ResolutionFunction.h.

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

Referenced by MuScleFitUtils::massResolution().

75  {
76  if (i > iterationNum_ || i < 0) {
77  std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0"
78  << 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:42
def exit(msg="")

◆ sigmaPhi()

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, beamvalidation::exit(), mps_fire::i, BaseFunction::iterationNum_, BaseFunction::parArray_, resolutionFunction_, resolutionFunctionBase< T >::sigmaPhi(), and HLT_2024v11_cff::track.

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"
88  << std::endl;
89  exit(1);
90  }
91  return resolutionFunction_[i]->sigmaPhi(track.pt(), track.eta(), parArray_[i]);
92  }
resolutionFunctionBase< double * > ** resolutionFunction_
virtual double sigmaPhi(const double &pt, const double &eta, const T &parval)=0
double ** parArray_
Definition: BaseFunction.h:42
def exit(msg="")

◆ sigmaPt()

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 65 of file ResolutionFunction.h.

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

Referenced by MuScleFitUtils::massResolution().

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

Member Data Documentation

◆ resolutionFunction_

resolutionFunctionBase<double*>** ResolutionFunction::resolutionFunction_
protected

◆ resolutionFunctionVec_

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

Definition at line 106 of file ResolutionFunction.h.

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