CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Protected Attributes

MomentumScaleCorrector Class Reference

#include <MomentumScaleCorrector.h>

Inheritance diagram for MomentumScaleCorrector:
BaseFunction

List of all members.

Public Member Functions

template<class U >
double correct (const U &lorentzVector)
 Alternative method that can be used with lorentzVectors.
scaleFunctionBase< double * > * function (const int i)
 Returns a pointer to the selected function.
 MomentumScaleCorrector (TString identifier)
 MomentumScaleCorrector (const MuScleFitDBobject *dbObject)
template<class U >
double operator() (const U &track)
 Method to do the corrections. It is templated to work with all the track types.
 ~MomentumScaleCorrector ()

Protected Member Functions

void readParameters (TString fileName)
 Parser of the parameters file.

Protected Attributes

scaleFunctionBase< double * > ** scaleFunction_
std::vector< scaleFunctionBase
< double * > * > 
scaleFunctionVec_

Detailed Description

MomentumScaleCorrector class Author M. De Mattia - 18/11/2008 This is used to have a common set of functions for the specialized templates to use. The constructor receives the name identifying the parameters for the correction function. It reads the parameters from a txt file in data/.

It handles multiple iterations. It is also possible to use different functions in different iterations.

ATTENTION: it is important that iterations numbers in the txt file start from 0.

Definition at line 25 of file MomentumScaleCorrector.h.


Constructor & Destructor Documentation

MomentumScaleCorrector::MomentumScaleCorrector ( TString  identifier) [inline]

The constructor takes a string identifying the parameters to read. It parses the txt file containing the parameters, extracts the index of the correction function and saves the corresponding pointer. It then fills the vector of parameters.

Definition at line 34 of file MomentumScaleCorrector.h.

References readParameters().

  {
    identifier.Prepend("MuonAnalysis/MomentumScaleCalibration/data/");
    identifier.Append(".txt");
    edm::FileInPath fileWithFullPath(identifier.Data());
    readParameters( fileWithFullPath.fullPath() );
  }
MomentumScaleCorrector::MomentumScaleCorrector ( const MuScleFitDBobject dbObject) [inline]

This constructor is used when reading parameters from the db. It receives a pointer to an object of type MuScleFitDBobject containing the parameters and the functions identifiers.

Definition at line 46 of file MomentumScaleCorrector.h.

References BaseFunction::convertToArrays(), BaseFunction::functionId_, scaleFunction_, scaleFunctionService(), and scaleFunctionVec_.

                                                               : BaseFunction( dbObject )
  {
    std::vector<int>::const_iterator id = functionId_.begin();
    for( ; id != functionId_.end(); ++id ) {
      scaleFunctionVec_.push_back( scaleFunctionService( *id ) );
    }
    // Fill the arrays that will be used when calling the correction function.
    convertToArrays(scaleFunction_, scaleFunctionVec_);
  }
MomentumScaleCorrector::~MomentumScaleCorrector ( ) [inline]

Definition at line 56 of file MomentumScaleCorrector.h.

References BaseFunction::functionId_, i, BaseFunction::parArray_, and scaleFunction_.

                            {
    if( parArray_ != 0 ) {
      for( unsigned int i=0; i<functionId_.size(); ++i ) {
        delete[] parArray_[i];
        delete scaleFunction_[i];
      }
      delete[] parArray_;
      delete[] scaleFunction_;
    }
  }

Member Function Documentation

template<class U >
double MomentumScaleCorrector::correct ( const U &  lorentzVector) [inline]

Alternative method that can be used with lorentzVectors.

Definition at line 86 of file MomentumScaleCorrector.h.

References i, BaseFunction::iterationNum_, BaseFunction::parArray_, scaleFunctionBase< T >::scale(), and scaleFunction_.

                                            {

    // Loop on all the functions and apply them iteratively on the pt corrected by the previous function.
    double pt = lorentzVector.Pt();
    for( int i=0; i<=iterationNum_; ++i ) {
      pt = ( scaleFunction_[i]->scale( pt, lorentzVector.Eta(), lorentzVector.Phi(), 1, parArray_[i]) );
    }
    return pt;
  }
scaleFunctionBase<double * >* MomentumScaleCorrector::function ( const int  i) [inline]

Returns a pointer to the selected function.

Definition at line 68 of file MomentumScaleCorrector.h.

References i, and scaleFunction_.

{ return scaleFunction_[i]; }
template<class U >
double MomentumScaleCorrector::operator() ( const U &  track) [inline]

Method to do the corrections. It is templated to work with all the track types.

Definition at line 73 of file MomentumScaleCorrector.h.

References i, BaseFunction::iterationNum_, BaseFunction::parArray_, scaleFunctionBase< T >::scale(), and scaleFunction_.

                                       {

    // Loop on all the functions and apply them iteratively on the pt corrected by the previous function.
    double pt = track.pt();
    for( int i=0; i<=iterationNum_; ++i ) {
      // return ( scaleFunction_->scale( track.pt(), track.eta(), track.phi(), track.charge(), parScale_) );
      pt = ( scaleFunction_[i]->scale( pt, track.eta(), track.phi(), track.charge(), parArray_[i]) );
    }
    return pt;
  }
void MomentumScaleCorrector::readParameters ( TString  fileName) [protected]

Parser of the parameters file.

Definition at line 3 of file MomentumScaleCorrector.cc.

References BaseFunction::convertToArrays(), gather_cfg::cout, BaseFunction::functionId_, recoMuon::in, align_cfg::iteration, BaseFunction::iterationNum_, geometryCSVtoXML::line, BaseFunction::parArray_, BaseFunction::parVecVec_, scaleFunction_, scaleFunctionService(), and scaleFunctionVec_.

Referenced by MomentumScaleCorrector().

{
  iterationNum_ = 0;
  parArray_ = 0;
  // std::vector<double> parameterErrors;

  // Read the parameters file
  ifstream parametersFile(fileName.Data());

  if( !parametersFile.is_open() ) {
    std::cout << "Error: file " << fileName << " not found. Aborting." << std::endl;
    abort();
  }
  std::string line;

  std::string iteration("Iteration ");
  // Loop on the file lines
  while (parametersFile) {
    getline( parametersFile, line );
    size_t lineInt = line.find("value");

    // if( line.find(iteration) != std::string::npos ) {
    size_t iterationSubStr = line.find(iteration);

    // Take the iteration number
    if( iterationSubStr != std::string::npos ) {

      int scaleFunctionNum = 0;
      // This can be used when dealing with multiple iterations

      // std::cout << "line = " << line << std::endl;
      std::stringstream sLine(line);
      std::string num;
      int wordCounter = 0;
      // Warning: this strongly depends on the parameters file structure.
      while( sLine >> num ) {
        ++wordCounter;
        //         std::cout << "num["<<wordCounter<<"] = " << num << std::endl;
        if( wordCounter == 9 ) {
          std::stringstream in(num);
          in >> scaleFunctionNum;
        }
        if( wordCounter == 13 ) {
          std::stringstream in(num);
          in >> iterationNum_;
        }
      }
      // std::cout << "iteration number = " << iterationNum_ << std::endl;
      // std::cout << "scale function number = " << scaleFunctionNum << std::endl;

      // Create a new vector to hold the parameters for this iteration
//       std::vector<double> parScale;
//       parVecVec_.push_back(parScale);

      // Set the scaleFunction
      // scaleFunction_ = scaleFunctionArrayForVec[scaleFunctionNum];
      // scaleFunction_ = scaleFunctionArray[scaleFunctionNum];
      functionId_.push_back(scaleFunctionNum);
      // scaleFunctionVec_.push_back( scaleFunctionArray[scaleFunctionNum] );
      scaleFunctionVec_.push_back( scaleFunctionService( scaleFunctionNum ) );
    }
    // Take the parameters for the current iteration
    if ( (lineInt != std::string::npos) ) {
      size_t subStr1 = line.find("value");
      std::stringstream paramStr;
      double param = 0;
      // Even if all the rest of the line is taken, the following
      // conversion to a double will stop at the end of the first number.
      paramStr << line.substr(subStr1+5);
      paramStr >> param;
//       // Fill the last vector of parameters, which corresponds to this iteration.
//       parVecVec_.back().push_back(param);
      parVecVec_.push_back(param);
      // std::cout << "param = " << param << std::endl;

      // This is to extract parameter errors
      // size_t subStr2 = line.find("+-");
      // std::stringstream parErrorStr;
      // double parError = 0;
      // parErrorStr << line.substr(subStr2+1);
      // parErrorStr >> parError;
      // parameterErrors.push_back(parError);
      // std::cout << "parError = " << parError << std::endl;
    }
  }

  convertToArrays( scaleFunction_, scaleFunctionVec_ );
}

Member Data Documentation

std::vector<scaleFunctionBase<double * > * > MomentumScaleCorrector::scaleFunctionVec_ [protected]

Definition at line 101 of file MomentumScaleCorrector.h.

Referenced by MomentumScaleCorrector(), and readParameters().