CMS 3D CMS Logo

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

#include <MomentumScaleCorrector.h>

Inheritance diagram for MomentumScaleCorrector:
BaseFunction

Public Member Functions

template<class U >
double correct (const U &lorentzVector)
 Alternative method that can be used with lorentzVectors. More...
 
scaleFunctionBase< double * > * function (const int i)
 Returns a pointer to the selected function. More...
 
 MomentumScaleCorrector (TString identifier)
 
 MomentumScaleCorrector (const MuScleFitDBobject *dbObject)
 
template<class U >
double operator() (const U &track)
 Method to do the corrections. It is templated to work with all the track types. More...
 
 ~MomentumScaleCorrector ()
 
- 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

scaleFunctionBase< double * > ** scaleFunction_
 
std::vector< scaleFunctionBase< double * > * > scaleFunctionVec_
 
- 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

MomentumScaleCorrector class Author M. De Mattia - 18/11/2008 This is used to have a common set of functions for the specialized templates to use. The constructor receives the name identifying the parameters for the correction function. It reads the parameters from a txt file in data/.

It handles multiple iterations. It is also possible to use different functions in different iterations.

ATTENTION: it is important that iterations numbers in the txt file start from 0.

Definition at line 25 of file MomentumScaleCorrector.h.

Constructor & Destructor Documentation

◆ MomentumScaleCorrector() [1/2]

MomentumScaleCorrector::MomentumScaleCorrector ( 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 33 of file MomentumScaleCorrector.h.

References readParameters().

33  {
34  identifier.Prepend("MuonAnalysis/MomentumScaleCalibration/data/");
35  identifier.Append(".txt");
36  edm::FileInPath fileWithFullPath(identifier.Data());
37  readParameters(fileWithFullPath.fullPath());
38  }
void readParameters(TString fileName)
Parser of the parameters file.

◆ MomentumScaleCorrector() [2/2]

MomentumScaleCorrector::MomentumScaleCorrector ( 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.

Definition at line 44 of file MomentumScaleCorrector.h.

References BaseFunction::convertToArrays(), BaseFunction::functionId_, l1ctLayer2EG_cff::id, scaleFunction_, scaleFunctionService(), and scaleFunctionVec_.

44  : BaseFunction(dbObject) {
45  std::vector<int>::const_iterator id = functionId_.begin();
46  for (; id != functionId_.end(); ++id) {
48  }
49  // Fill the arrays that will be used when calling the correction function.
51  }
scaleFunctionBase< double * > * scaleFunctionService(const int identifier)
Service to build the scale functor corresponding to the passed identifier.
Definition: Functions.cc:3
scaleFunctionBase< double * > ** scaleFunction_
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< scaleFunctionBase< double * > * > scaleFunctionVec_

◆ ~MomentumScaleCorrector()

MomentumScaleCorrector::~MomentumScaleCorrector ( )
inline

Definition at line 53 of file MomentumScaleCorrector.h.

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

53  {
54  if (parArray_ != nullptr) {
55  for (unsigned int i = 0; i < functionId_.size(); ++i) {
56  delete[] parArray_[i];
57  delete scaleFunction_[i];
58  }
59  delete[] parArray_;
60  delete[] scaleFunction_;
61  }
62  }
scaleFunctionBase< double * > ** scaleFunction_
std::vector< int > functionId_
Definition: BaseFunction.h:38
double ** parArray_
Definition: BaseFunction.h:42

Member Function Documentation

◆ correct()

template<class U >
double MomentumScaleCorrector::correct ( const U &  lorentzVector)
inline

Alternative method that can be used with lorentzVectors.

Definition at line 81 of file MomentumScaleCorrector.h.

References mps_fire::i, BaseFunction::iterationNum_, BaseFunction::parArray_, DiDispStaMuonMonitor_cfi::pt, scaleFunctionBase< T >::scale(), and scaleFunction_.

Referenced by KalmanMuonCorrector.KalmanMuonCorrector::correct_all(), and JetReCalibrator.JetReCalibrator::correctAll().

81  {
82  // Loop on all the functions and apply them iteratively on the pt corrected by the previous function.
83  double pt = lorentzVector.Pt();
84  for (int i = 0; i <= iterationNum_; ++i) {
85  pt = (scaleFunction_[i]->scale(pt, lorentzVector.Eta(), lorentzVector.Phi(), 1, parArray_[i]));
86  }
87  return pt;
88  }
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
scaleFunctionBase< double * > ** scaleFunction_
virtual double scale(const double &pt, const double &eta, const double &phi, const int chg, const T &parScale) const =0
double ** parArray_
Definition: BaseFunction.h:42

◆ function()

scaleFunctionBase<double*>* MomentumScaleCorrector::function ( const int  i)
inline

Returns a pointer to the selected function.

Definition at line 65 of file MomentumScaleCorrector.h.

References mps_fire::i, and scaleFunction_.

65 { return scaleFunction_[i]; }
scaleFunctionBase< double * > ** scaleFunction_

◆ operator()()

template<class U >
double MomentumScaleCorrector::operator() ( const U &  track)
inline

Method to do the corrections. It is templated to work with all the track types.

Definition at line 69 of file MomentumScaleCorrector.h.

References mps_fire::i, BaseFunction::iterationNum_, BaseFunction::parArray_, DiDispStaMuonMonitor_cfi::pt, scaleFunctionBase< T >::scale(), scaleFunction_, and HLT_2024v14_cff::track.

69  {
70  // Loop on all the functions and apply them iteratively on the pt corrected by the previous function.
71  double pt = track.pt();
72  for (int i = 0; i <= iterationNum_; ++i) {
73  // return ( scaleFunction_->scale( track.pt(), track.eta(), track.phi(), track.charge(), parScale_) );
74  pt = (scaleFunction_[i]->scale(pt, track.eta(), track.phi(), track.charge(), parArray_[i]));
75  }
76  return pt;
77  }
scaleFunctionBase< double * > ** scaleFunction_
virtual double scale(const double &pt, const double &eta, const double &phi, const int chg, const T &parScale) const =0
double ** parArray_
Definition: BaseFunction.h:42

◆ readParameters()

void MomentumScaleCorrector::readParameters ( TString  fileName)
protected

Parser of the parameters file.

Definition at line 3 of file MomentumScaleCorrector.cc.

References BaseFunction::convertToArrays(), gather_cfg::cout, MillePedeFileConverter_cfg::fileName, BaseFunction::functionId_, recoMuon::in, align_cfg::iteration, BaseFunction::iterationNum_, mps_splice::line, EgammaValidation_cff::num, BaseFunction::parArray_, BaseFunction::parVecVec_, scaleFunction_, scaleFunctionService(), scaleFunctionVec_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by MomentumScaleCorrector().

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

Member Data Documentation

◆ scaleFunction_

scaleFunctionBase<double*>** MomentumScaleCorrector::scaleFunction_
protected

◆ scaleFunctionVec_

std::vector<scaleFunctionBase<double*>*> MomentumScaleCorrector::scaleFunctionVec_
protected

Definition at line 95 of file MomentumScaleCorrector.h.

Referenced by MomentumScaleCorrector(), and readParameters().