CMS 3D CMS Logo

Classes | Public Member Functions | Private Types | Private Attributes

jpt::Map Class Reference

Container class for response & efficiency maps. More...

#include <JetPlusTrackCorrector.h>

List of all members.

Classes

class  Element

Public Member Functions

double binCenterEta (uint32_t) const
double binCenterPt (uint32_t) const
void clear ()
double eta (uint32_t) const
uint32_t etaBin (double eta) const
 Map ()
 Map (std::string, bool verbose=false)
uint32_t nEtaBins () const
uint32_t nPtBins () const
void print (std::stringstream &ss) const
double pt (uint32_t) const
uint32_t ptBin (double pt) const
double value (uint32_t eta_bin, uint32_t pt_bin) const
 ~Map ()

Private Types

typedef std::vector< double > VDouble
typedef std::vector< VDoubleVVDouble

Private Attributes

VVDouble data_
std::vector< double > eta_
std::vector< double > pt_

Detailed Description

Container class for response & efficiency maps.

Definition at line 37 of file JetPlusTrackCorrector.h.


Member Typedef Documentation

typedef std::vector<double> jpt::Map::VDouble [private]

Definition at line 74 of file JetPlusTrackCorrector.h.

typedef std::vector<VDouble> jpt::Map::VVDouble [private]

Definition at line 75 of file JetPlusTrackCorrector.h.


Constructor & Destructor Documentation

Map::Map ( std::string  input,
bool  verbose = false 
)

Definition at line 1220 of file JetPlusTrackCorrector.cc.

References clear(), runTheMatrix::data, data_, jpt::Map::Element::eta_, eta_, dbtoweb::file, edm::FileInPath::fullPath(), jpt::Map::Element::ieta_, recoMuon::in, jpt::Map::Element::ipt_, edm::isDebugEnabled(), geometryCSVtoXML::line, LogTrace, print(), pt_, jpt::Map::Element::pt_, cond::rpcobtemp::temp, and jpt::Map::Element::val_.

  : eta_(),
    pt_(),
    data_()
{ 

  // Some init
  clear();
  std::vector<Element> data;

  // Parse file
  std::string file = edm::FileInPath(input).fullPath();
  std::ifstream in( file.c_str() );
  string line;
  uint32_t ieta_old = 0; 
  while ( std::getline( in, line ) ) {
    if ( !line.size() || line[0]=='#' ) { continue; }
    std::istringstream ss(line);
    Element temp;
    ss >> temp.ieta_ >> temp.ipt_ >> temp.eta_ >> temp.pt_ >> temp.val_;
    data.push_back(temp);
    if ( !ieta_old || temp.ieta_ != ieta_old ) { 
      if ( eta_.size() < temp.ieta_+1 ) { eta_.resize(temp.ieta_+1,0.); }
      eta_[temp.ieta_] = temp.eta_;
      ieta_old = temp.ieta_;
    }
    if ( pt_.size() < temp.ipt_+1 ) { pt_.resize(temp.ipt_+1,0.); }
    pt_[temp.ipt_] = temp.pt_;
  }
  
  // Populate container
  data_.resize( eta_.size(), VDouble( pt_.size(), 0. ) );
  std::vector<Element>::const_iterator idata = data.begin();
  std::vector<Element>::const_iterator jdata = data.end();
  for ( ; idata != jdata; ++idata ) { data_[idata->ieta_][idata->ipt_] = idata->val_; }

  // Check
  if ( data_.empty() || data_[0].empty() ) {
    std::stringstream ss;
    ss << "[jpt::Map::" << __func__ << "]"
       << " Problem parsing map in location \"" 
       << file << "\"! ";
    edm::LogError("JetPlusTrackCorrector") << ss.str();
  }

  // Check
  if ( eta_.size() != data_.size() || 
       pt_.size() != ( data_.empty() ? 0 : data_[0].size() ) ) {
    std::stringstream ss;
    ss << "[jpt::Map::" << __func__ << "]"
       << " Discrepancy b/w number of bins!";
    edm::LogError("JetPlusTrackCorrector") << ss.str();
  }

  // Debug
  if ( verbose && edm::isDebugEnabled() ) { 
    std::stringstream ss;
    ss << "[jpt::Map::" << __func__ << "]"
       << " Parsed contents of map at location:" << std::endl
       << "\"" << file << "\"" << std::endl;
    print(ss); 
    LogTrace("JetPlusTrackCorrector") << ss.str();
  } 

}
Map::Map ( )

Definition at line 1288 of file JetPlusTrackCorrector.cc.

References clear().

  : eta_(),
    pt_(),
    data_()
{ 
  clear();
}
Map::~Map ( )

Definition at line 1298 of file JetPlusTrackCorrector.cc.

References clear().

          {
  clear();
}

Member Function Documentation

double Map::binCenterEta ( uint32_t  eta_bin) const

Definition at line 1339 of file JetPlusTrackCorrector.cc.

References eta_.

Referenced by JetPlusTrackCorrector::pionEfficiency().

                                                 {
  if ( !eta_.empty() && eta_bin+1 < eta_.size() ) { 
    return eta_[eta_bin] + ( eta_[eta_bin+1] - eta_[eta_bin] ) / 2.; 
  } else { 
    edm::LogWarning("JetPlusTrackCorrector") 
      << "[jpt::Map::" << __func__ << "]"
      << " Trying to access element " << eta_bin+1
      << " of a vector with size " << eta_.size()
      << "!";
    return eta_[eta_.size()-1]; 
  }
}
double Map::binCenterPt ( uint32_t  pt_bin) const

Definition at line 1354 of file JetPlusTrackCorrector.cc.

References pt_.

Referenced by JetPlusTrackCorrector::pionEfficiency().

                                               {
  if ( !pt_.empty() && pt_bin+1 < pt_.size() ) { 
    return pt_[pt_bin] + ( pt_[pt_bin+1] - pt_[pt_bin] ) / 2.; 
  } else { 
    edm::LogWarning("JetPlusTrackCorrector") 
      << "[jpt::Map::" << __func__ << "]"
      << " Trying to access element " << pt_bin+1
      << " of a vector with size " << pt_.size()
      << "!";
    return pt_[pt_.size()-1]; 
  }
}
void Map::clear ( void  )

Definition at line 1304 of file JetPlusTrackCorrector.cc.

References data_, eta_, and pt_.

Referenced by Map(), and ~Map().

                {
  eta_.clear();
  pt_.clear();
  data_.clear();
}
double Map::eta ( uint32_t  eta_bin) const

Definition at line 1311 of file JetPlusTrackCorrector.cc.

References eta_.

Referenced by etaBin().

                                        {
  if ( !eta_.empty() && eta_bin < eta_.size() ) { return eta_[eta_bin]; }
  else { 
    edm::LogWarning("JetPlusTrackCorrector") 
      << "[jpt::Map::" << __func__ << "]"
      << " Trying to access element " << eta_bin
      << " of a vector with size " << eta_.size()
      << "!";
    return eta_[eta_.size()-1]; 
  }
}
uint32_t Map::etaBin ( double  eta) const

Definition at line 1369 of file JetPlusTrackCorrector.cc.

References eta(), and nEtaBins().

Referenced by JetPlusTrackCorrector::calculateCorr(), and JetPlusTrackCorrector::correctAA().

                                       {
  val = fabs( val );
  for ( uint32_t ieta = 0; ieta < nEtaBins()-1; ++ieta ) { //@@ "-1" is bug?
    if ( val > eta(ieta) && ( ieta+1 == nEtaBins() || val < eta(ieta+1) ) ) { return ieta; }
  }
  return nEtaBins();
}
uint32_t jpt::Map::nEtaBins ( ) const [inline]
uint32_t jpt::Map::nPtBins ( ) const [inline]
void Map::print ( std::stringstream &  ss) const

Definition at line 1404 of file JetPlusTrackCorrector.cc.

References data_, eta_, and pt_.

Referenced by Map(), and jpt::Efficiency::print().

                                           {
  ss << " Number of bins in eta : " << data_.size() << std::endl 
     << " Number of bins in pt  : " << ( data_.empty() ? 0 : data_[0].size() ) << std::endl;
  VVDouble::const_iterator ieta = data_.begin();
  VVDouble::const_iterator jeta = data_.end();
  for ( ; ieta != jeta; ++ieta ) {
    VDouble::const_iterator ipt = ieta->begin();
    VDouble::const_iterator jpt = ieta->end();
    for ( ; ipt != jpt; ++ipt ) {
      uint32_t eta_bin = static_cast<uint32_t>( ieta - data_.begin() );
      uint32_t pt_bin  = static_cast<uint32_t>( ipt - ieta->begin() );
      ss << " EtaBinNumber: " << eta_bin 
         << " PtBinNumber: " << pt_bin 
         << " EtaValue: " << eta_[ eta_bin ]
         << " PtValue: " << pt_[ pt_bin ]
         << " Value: " << data_[eta_bin][pt_bin]
         << std::endl;
    }
  }
}
double Map::pt ( uint32_t  pt_bin) const

Definition at line 1325 of file JetPlusTrackCorrector.cc.

References pt_.

Referenced by ptBin().

                                      {
  if ( !pt_.empty() && pt_bin < pt_.size() ) { return pt_[pt_bin]; }
  else { 
    edm::LogWarning("JetPlusTrackCorrector") 
      << "[jpt::Map::" << __func__ << "]"
      << " Trying to access element " << pt_bin
      << " of a vector with size " << pt_.size()
      << "!";
    return pt_[pt_.size()-1]; 
  }
}
uint32_t Map::ptBin ( double  pt) const

Definition at line 1379 of file JetPlusTrackCorrector.cc.

References nPtBins(), and pt().

Referenced by JetPlusTrackCorrector::calculateCorr(), and JetPlusTrackCorrector::correctAA().

                                      {
  val = fabs( val );
  for ( uint32_t ipt = 0; ipt < nPtBins()-1; ++ipt ) { //@@ "-1" is bug?
    if ( val > pt(ipt) && ( (ipt+1) == nPtBins() || val < pt(ipt+1) ) ) { return ipt; }
  }
  return nPtBins();
}
double Map::value ( uint32_t  eta_bin,
uint32_t  pt_bin 
) const

Definition at line 1389 of file JetPlusTrackCorrector.cc.

References data_.

Referenced by JetPlusTrackCorrector::calculateCorr(), JetPlusTrackCorrector::correctAA(), jpt::Efficiency::inConeCorr(), and jpt::Efficiency::outOfConeCorr().

                                                           {
  if ( eta_bin < data_.size() && 
       pt_bin < ( data_.empty() ? 0 : data_[0].size() ) ) { return data_[eta_bin][pt_bin]; }
  else { 
    edm::LogWarning("JetPlusTrackCorrector") 
      << "[jpt::Map::" << __func__ << "]"
      << " Trying to access element (" << eta_bin << "," << pt_bin << ")"
      << " of a vector with size (" << data_.size() << "," << ( data_.empty() ? 0 : data_[0].size() ) << ")"
      << "!";
    return 1.; 
  }
}

Member Data Documentation

Definition at line 79 of file JetPlusTrackCorrector.h.

Referenced by clear(), Map(), print(), and value().

std::vector<double> jpt::Map::eta_ [private]

Definition at line 77 of file JetPlusTrackCorrector.h.

Referenced by binCenterEta(), clear(), eta(), Map(), nEtaBins(), and print().

std::vector<double> jpt::Map::pt_ [private]

Definition at line 78 of file JetPlusTrackCorrector.h.

Referenced by binCenterPt(), clear(), Map(), nPtBins(), print(), and pt().