CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MomentumScaleCorrector.h
Go to the documentation of this file.
1 
6 #ifndef MomentumScaleCorrector_h
7 #define MomentumScaleCorrector_h
8 
9 #include <fstream>
10 #include <sstream>
14 
26 {
27  public:
34  MomentumScaleCorrector( TString identifier )
35  {
36  identifier.Prepend("MuonAnalysis/MomentumScaleCalibration/data/");
37  identifier.Append(".txt");
38  edm::FileInPath fileWithFullPath(identifier.Data());
39  readParameters( fileWithFullPath.fullPath() );
40  }
46  MomentumScaleCorrector( const MuScleFitDBobject * dbObject ) : 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  }
55 
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  }
66 
68  scaleFunctionBase<double * > * function(const int i) { return scaleFunction_[i]; }
69 
70 
72  template <class U>
73  double operator()( const U & track ) {
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  }
83 
85  template <class U>
86  double correct( const U & lorentzVector ) {
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  }
95 
96  protected:
98  void readParameters( TString fileName );
99 
101  std::vector<scaleFunctionBase<double * > * > scaleFunctionVec_;
102 };
103 
104 #endif // MomentumScaleCorrector_h
scaleFunctionBase< double * > * scaleFunctionService(const int identifier)
Service to build the scale functor corresponding to the passed identifier.
Definition: Functions.cc:3
int i
Definition: DBlmapReader.cc:9
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_
void readParameters(TString fileName)
Parser of the parameters file.
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
MomentumScaleCorrector(TString identifier)
std::vector< int > functionId_
Definition: BaseFunction.h:46
virtual double scale(const double &pt, const double &eta, const double &phi, const int chg, const T &parScale) const =0
double operator()(const U &track)
Method to do the corrections. It is templated to work with all the track types.
MomentumScaleCorrector(const MuScleFitDBobject *dbObject)
double correct(const U &lorentzVector)
Alternative method that can be used with lorentzVectors.
std::vector< scaleFunctionBase< double * > * > scaleFunctionVec_
double ** parArray_
Definition: BaseFunction.h:50