CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::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 34 of file MomentumScaleCorrector.h.

References readParameters().

35  {
36  identifier.Prepend("MuonAnalysis/MomentumScaleCalibration/data/");
37  identifier.Append(".txt");
38  edm::FileInPath fileWithFullPath(identifier.Data());
39  readParameters( fileWithFullPath.fullPath() );
40  }
void readParameters(TString fileName)
Parser of the parameters file.
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 46 of file MomentumScaleCorrector.h.

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

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

Definition at line 56 of file MomentumScaleCorrector.h.

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

56  {
57  if( parArray_ != 0 ) {
58  for( unsigned int i=0; i<functionId_.size(); ++i ) {
59  delete[] parArray_[i];
60  delete scaleFunction_[i];
61  }
62  delete[] parArray_;
63  delete[] scaleFunction_;
64  }
65  }
int i
Definition: DBlmapReader.cc:9
scaleFunctionBase< double * > ** scaleFunction_
std::vector< int > functionId_
Definition: BaseFunction.h:46
double ** parArray_
Definition: BaseFunction.h:50

Member Function Documentation

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

Alternative method that can be used with lorentzVectors.

Definition at line 86 of file MomentumScaleCorrector.h.

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

86  {
87 
88  // Loop on all the functions and apply them iteratively on the pt corrected by the previous function.
89  double pt = lorentzVector.Pt();
90  for( int i=0; i<=iterationNum_; ++i ) {
91  pt = ( scaleFunction_[i]->scale( pt, lorentzVector.Eta(), lorentzVector.Phi(), 1, parArray_[i]) );
92  }
93  return pt;
94  }
int i
Definition: DBlmapReader.cc:9
scaleFunctionBase< double * > ** scaleFunction_
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
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:50
scaleFunctionBase<double * >* MomentumScaleCorrector::function ( const int  i)
inline

Returns a pointer to the selected function.

Definition at line 68 of file MomentumScaleCorrector.h.

References i, and scaleFunction_.

68 { return scaleFunction_[i]; }
int i
Definition: DBlmapReader.cc:9
scaleFunctionBase< double * > ** scaleFunction_
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 73 of file MomentumScaleCorrector.h.

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

73  {
74 
75  // Loop on all the functions and apply them iteratively on the pt corrected by the previous function.
76  double pt = track.pt();
77  for( int i=0; i<=iterationNum_; ++i ) {
78  // return ( scaleFunction_->scale( track.pt(), track.eta(), track.phi(), track.charge(), parScale_) );
79  pt = ( scaleFunction_[i]->scale( pt, track.eta(), track.phi(), track.charge(), parArray_[i]) );
80  }
81  return pt;
82  }
int i
Definition: DBlmapReader.cc: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:50
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, BaseFunction::functionId_, recoMuon::in, align_cfg::iteration, BaseFunction::iterationNum_, geometryCSVtoXML::line, pileupDistInMC::num, BaseFunction::parArray_, BaseFunction::parVecVec_, scaleFunction_, scaleFunctionService(), scaleFunctionVec_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by MomentumScaleCorrector().

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

Member Data Documentation

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

Definition at line 101 of file MomentumScaleCorrector.h.

Referenced by MomentumScaleCorrector(), and readParameters().