CMS 3D CMS Logo

ResolutionFunction.h
Go to the documentation of this file.
1 
6 #ifndef ResolutionFunction_h
7 #define ResolutionFunction_h
8 
9 #include <fstream>
10 #include <sstream>
14 
16 public:
23  ResolutionFunction(TString identifier) {
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  }
39  ResolutionFunction(const MuScleFitDBobject* dbObject) : 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  }
47 
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  }
58 
59  // EM+SC: 2013.01.11
60  // lorentzVector have both capital and lower case methods for pt(), eta() and phi
61  // if a lorentzVector is passed use, parArray form iteration i=0
62 
64  template <class U>
65  double sigmaPt(const U& track, const int i = 0) const {
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  }
74  template <class U>
75  double sigmaCotgTh(const U& track, const int i = 0) const {
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  }
84  template <class U>
85  double sigmaPhi(const U& track, const int i = 0) const {
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  }
94  resolutionFunctionBase<double*>* function(const unsigned int i) {
95  if (resolutionFunctionVec_.size() > i)
96  return resolutionFunction_[i];
97  else
98  return nullptr;
99  }
100 
101 protected:
103  void readParameters(TString fileName);
104 
106  std::vector<resolutionFunctionBase<double*>*> resolutionFunctionVec_;
107 };
108 
109 #endif // ResolutionFunction_h
ResolutionFunction(const MuScleFitDBobject *dbObject)
double sigmaCotgTh(const U &track, const int i=0) const
The second, optional, parameter is the iteration number.
resolutionFunctionBase< double * > ** resolutionFunction_
double sigmaPt(const U &track, const int i=0) const
The second, optional, parameter is the iteration number.
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
Definition: Functions.cc:70
virtual double sigmaPt(const double &pt, const double &eta, const T &parval)=0
void readParameters(TString fileName)
Parser of the parameters file.
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
virtual double sigmaCotgTh(const double &pt, const double &eta, const T &parval)=0
std::vector< resolutionFunctionBase< double * > * > resolutionFunctionVec_
double sigmaPhi(const U &track, const int i=0) const
The second, optional, parameter is the iteration number.
virtual double sigmaPhi(const double &pt, const double &eta, const T &parval)=0
ResolutionFunction(TString identifier)
double ** parArray_
Definition: BaseFunction.h:42
def exit(msg="")