File indexing completed on 2024-04-06 12:22:37
0001
0002
0003
0004
0005
0006 #ifndef ResolutionFunction_h
0007 #define ResolutionFunction_h
0008
0009 #include <fstream>
0010 #include <sstream>
0011 #include "MuonAnalysis/MomentumScaleCalibration/interface/BaseFunction.h"
0012 #include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h"
0013 #include "FWCore/ParameterSet/interface/FileInPath.h"
0014
0015 class ResolutionFunction : public BaseFunction {
0016 public:
0017
0018
0019
0020
0021
0022
0023 ResolutionFunction(TString identifier) {
0024 identifier.Prepend("MuonAnalysis/MomentumScaleCalibration/data/");
0025 identifier.Append(".txt");
0026 edm::FileInPath fileWithFullPath(identifier.Data());
0027 readParameters(fileWithFullPath.fullPath());
0028
0029 std::vector<int>::const_iterator idIt = functionId_.begin();
0030 for (; idIt != functionId_.end(); ++idIt)
0031 std::cout << "idIt = " << *idIt << std::endl;
0032 }
0033
0034
0035
0036
0037
0038
0039 ResolutionFunction(const MuScleFitDBobject* dbObject) : BaseFunction(dbObject) {
0040 std::vector<int>::const_iterator id = functionId_.begin();
0041 for (; id != functionId_.end(); ++id) {
0042 resolutionFunctionVec_.push_back(resolutionFunctionService(*id));
0043 }
0044
0045 convertToArrays(resolutionFunction_, resolutionFunctionVec_);
0046 }
0047
0048 ~ResolutionFunction() {
0049 if (parArray_ != nullptr) {
0050 for (unsigned int i = 0; i < functionId_.size(); ++i) {
0051 delete[] parArray_[i];
0052 delete resolutionFunction_[i];
0053 }
0054 delete[] parArray_;
0055 delete[] resolutionFunction_;
0056 }
0057 }
0058
0059
0060
0061
0062
0063
0064 template <class U>
0065 double sigmaPt(const U& track, const int i = 0) const {
0066 if (i > iterationNum_ || i < 0) {
0067 std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0"
0068 << std::endl;
0069 exit(1);
0070 }
0071 return resolutionFunction_[i]->sigmaPt(track.pt(), track.eta(), parArray_[i]);
0072 }
0073
0074 template <class U>
0075 double sigmaCotgTh(const U& track, const int i = 0) const {
0076 if (i > iterationNum_ || i < 0) {
0077 std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0"
0078 << std::endl;
0079 exit(1);
0080 }
0081 return resolutionFunction_[i]->sigmaCotgTh(track.pt(), track.eta(), parArray_[i]);
0082 }
0083
0084 template <class U>
0085 double sigmaPhi(const U& track, const int i = 0) const {
0086 if (i > iterationNum_ || i < 0) {
0087 std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0"
0088 << std::endl;
0089 exit(1);
0090 }
0091 return resolutionFunction_[i]->sigmaPhi(track.pt(), track.eta(), parArray_[i]);
0092 }
0093
0094 resolutionFunctionBase<double*>* function(const unsigned int i) {
0095 if (resolutionFunctionVec_.size() > i)
0096 return resolutionFunction_[i];
0097 else
0098 return nullptr;
0099 }
0100
0101 protected:
0102
0103 void readParameters(TString fileName);
0104
0105 resolutionFunctionBase<double*>** resolutionFunction_;
0106 std::vector<resolutionFunctionBase<double*>*> resolutionFunctionVec_;
0107 };
0108
0109 #endif