Go to the documentation of this file.00001
00006 #ifndef ResolutionFunction_h
00007 #define ResolutionFunction_h
00008
00009 #include <fstream>
00010 #include <sstream>
00011 #include "MuonAnalysis/MomentumScaleCalibration/interface/BaseFunction.h"
00012 #include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h"
00013 #include "FWCore/ParameterSet/interface/FileInPath.h"
00014
00015 class ResolutionFunction : public BaseFunction
00016 {
00017 public:
00024 ResolutionFunction( TString identifier )
00025 {
00026 identifier.Prepend("MuonAnalysis/MomentumScaleCalibration/data/");
00027 identifier.Append(".txt");
00028 edm::FileInPath fileWithFullPath(identifier.Data());
00029 readParameters( fileWithFullPath.fullPath() );
00030
00031 std::vector<int>::const_iterator idIt = functionId_.begin();
00032 for( ; idIt != functionId_.end(); ++idIt ) std::cout << "idIt = " << *idIt << std::endl;
00033 }
00040 ResolutionFunction( const MuScleFitDBobject * dbObject ) : BaseFunction( dbObject )
00041 {
00042 std::vector<int>::const_iterator id = functionId_.begin();
00043 for( ; id != functionId_.end(); ++id ) {
00044 resolutionFunctionVec_.push_back( resolutionFunctionService( *id ) );
00045 }
00046
00047 convertToArrays(resolutionFunction_, resolutionFunctionVec_);
00048 }
00049
00050 ~ResolutionFunction() {
00051 if( parArray_ != 0 ) {
00052 for( unsigned int i=0; i<functionId_.size(); ++i ) {
00053 delete[] parArray_[i];
00054 delete resolutionFunction_[i];
00055 }
00056 delete[] parArray_;
00057 delete[] resolutionFunction_;
00058 }
00059 }
00060
00061
00062
00063
00064
00066 template <class U>
00067 double sigmaPt(const U & track, const int i=0) const {
00068 if( i > iterationNum_ || i < 0 ) {
00069 std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0" << std::endl;
00070 exit(1);
00071 }
00072 return resolutionFunction_[i]->sigmaPt(track.pt(), track.eta(), parArray_[i]);
00073 }
00075 template <class U>
00076 double sigmaCotgTh(const U & track, const int i=0) const {
00077 if( i > iterationNum_ || i < 0 ) {
00078 std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0" << std::endl;
00079 exit(1);
00080 }
00081 return resolutionFunction_[i]->sigmaCotgTh(track.pt(), track.eta(), parArray_[i]);
00082 }
00084 template <class U>
00085 double sigmaPhi(const U & track, const int i=0) const {
00086 if( i > iterationNum_ || i < 0 ) {
00087 std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0" << std::endl;
00088 exit(1);
00089 }
00090 return resolutionFunction_[i]->sigmaPhi(track.pt(), track.eta(), parArray_[i]);
00091 }
00093 resolutionFunctionBase<double * > * function( const unsigned int i )
00094 {
00095 if( resolutionFunctionVec_.size() > i ) return resolutionFunction_[i];
00096 else return 0;
00097 }
00098
00099 protected:
00101 void readParameters( TString fileName );
00102
00103 resolutionFunctionBase<double * > ** resolutionFunction_;
00104 std::vector<resolutionFunctionBase<double * > * > resolutionFunctionVec_;
00105 };
00106
00107 #endif // ResolutionFunction_h