Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:28

0001 /**
0002  * \class BackgroundFunction
0003  * Class for the resolution function. It can be built from local file or from db.
0004  */
0005 
0006 #ifndef BackgroundFunction_h
0007 #define BackgroundFunction_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 BackgroundFunction : public BaseFunction {
0016 public:
0017   /**
0018    * The constructor takes a string identifying the parameters to read. It
0019    * parses the txt file containing the parameters, extracts the index of the
0020    * correction function and saves the corresponding pointer. It then fills the
0021    * vector of parameters.
0022    */
0023   BackgroundFunction(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    * This constructor is used when reading parameters from the db.
0035    * It receives a pointer to an object of type MuScleFitDBobject containing
0036    * the parameters and the functions identifiers.
0037    * The object is the same for all the functions.
0038    */
0039   BackgroundFunction(const MuScleFitDBobject* dbObject) : BaseFunction(dbObject) {
0040     std::vector<int>::const_iterator id = functionId_.begin();
0041     for (; id != functionId_.end(); ++id) {
0042       // TODO: fix the values for the lower and upper limits
0043       backgroundFunctionVec_.push_back(backgroundFunctionService(*id, 0., 200.));
0044     }
0045     // Fill the arrays that will be used when calling the correction function.
0046     convertToArrays(backgroundFunction_, backgroundFunctionVec_);
0047   }
0048 
0049   ~BackgroundFunction() {
0050     if (parArray_ != nullptr) {
0051       for (unsigned int i = 0; i < functionId_.size(); ++i) {
0052         delete[] parArray_[i];
0053         delete backgroundFunction_[i];
0054       }
0055       delete[] parArray_;
0056       delete[] backgroundFunction_;
0057     }
0058   }
0059   /// Get the ith background function
0060   backgroundFunctionBase* function(const unsigned int i) {
0061     if (backgroundFunctionVec_.size() > i)
0062       return backgroundFunction_[i];
0063     else
0064       return nullptr;
0065   }
0066 
0067 protected:
0068   /// Parser of the parameters file
0069   void readParameters(TString fileName);
0070 
0071   backgroundFunctionBase** backgroundFunction_;
0072   std::vector<backgroundFunctionBase*> backgroundFunctionVec_;
0073 };
0074 
0075 #endif  // BackgroundFunction_h