CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/MuonAnalysis/MomentumScaleCalibration/interface/ResolutionFunction.h

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     // Fill the arrays that will be used when calling the correction function.
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 
00062   template <class U>
00063   double sigmaPt(const U & track, const int i = 0) {
00064     if( i > iterationNum_ || i < 0 ) {
00065       std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0" << std::endl;
00066       exit(1);
00067     }
00068     return resolutionFunction_[i]->sigmaPt(track.pt(), track.eta(), parArray_[i]);
00069   }
00071   template <class U>
00072   double sigmaCotgTh(const U & track, const int i = 0) {
00073     if( i > iterationNum_ || i < 0 ) {
00074       std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0" << std::endl;
00075       exit(1);
00076     }
00077     return resolutionFunction_[i]->sigmaCotgTh(track.pt(), track.eta(), parArray_[i]);
00078   }
00080   template <class U>
00081   double sigmaPhi(const U & track, const int i = 0) {
00082     if( i > iterationNum_ || i < 0 ) {
00083       std::cout << "Error: wrong iteration number, there are " << iterationNum_ << "iterations, ther first one is 0" << std::endl;
00084       exit(1);
00085     }
00086     return resolutionFunction_[i]->sigmaPhi(track.pt(), track.eta(), parArray_[i]);
00087   }
00089   resolutionFunctionBase<double * > * function( const unsigned int i )
00090   {
00091     if( resolutionFunctionVec_.size() > i ) return resolutionFunction_[i];
00092     else return 0;
00093   }
00094 protected:
00096   void readParameters( TString fileName );
00097 
00098   resolutionFunctionBase<double * > ** resolutionFunction_;
00099   std::vector<resolutionFunctionBase<double * > * > resolutionFunctionVec_;
00100 };
00101 
00102 #endif // ResolutionFunction_h