CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Types | Private Attributes
jpt::Map Class Reference

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

#include <JetPlusTrackCorrector.h>

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 (std::string, bool verbose=false)
 
 Map ()
 
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(), jpt::Map::Element::pt_, pt_, cond::rpcobtemp::temp, and jpt::Map::Element::val_.

1221  : eta_(),
1222  pt_(),
1223  data_()
1224 {
1225 
1226  // Some init
1227  clear();
1228  std::vector<Element> data;
1229 
1230  // Parse file
1231  std::string file = edm::FileInPath(input).fullPath();
1232  std::ifstream in( file.c_str() );
1233  string line;
1234  uint32_t ieta_old = 0;
1235  while ( std::getline( in, line ) ) {
1236  if ( !line.size() || line[0]=='#' ) { continue; }
1237  std::istringstream ss(line);
1238  Element temp;
1239  ss >> temp.ieta_ >> temp.ipt_ >> temp.eta_ >> temp.pt_ >> temp.val_;
1240  data.push_back(temp);
1241  if ( !ieta_old || temp.ieta_ != ieta_old ) {
1242  if ( eta_.size() < temp.ieta_+1 ) { eta_.resize(temp.ieta_+1,0.); }
1243  eta_[temp.ieta_] = temp.eta_;
1244  ieta_old = temp.ieta_;
1245  }
1246  if ( pt_.size() < temp.ipt_+1 ) { pt_.resize(temp.ipt_+1,0.); }
1247  pt_[temp.ipt_] = temp.pt_;
1248  }
1249 
1250  // Populate container
1251  data_.resize( eta_.size(), VDouble( pt_.size(), 0. ) );
1252  std::vector<Element>::const_iterator idata = data.begin();
1253  std::vector<Element>::const_iterator jdata = data.end();
1254  for ( ; idata != jdata; ++idata ) { data_[idata->ieta_][idata->ipt_] = idata->val_; }
1255 
1256  // Check
1257  if ( data_.empty() || data_[0].empty() ) {
1258  std::stringstream ss;
1259  ss << "[jpt::Map::" << __func__ << "]"
1260  << " Problem parsing map in location \""
1261  << file << "\"! ";
1262  edm::LogError("JetPlusTrackCorrector") << ss.str();
1263  }
1264 
1265  // Check
1266  if ( eta_.size() != data_.size() ||
1267  pt_.size() != ( data_.empty() ? 0 : data_[0].size() ) ) {
1268  std::stringstream ss;
1269  ss << "[jpt::Map::" << __func__ << "]"
1270  << " Discrepancy b/w number of bins!";
1271  edm::LogError("JetPlusTrackCorrector") << ss.str();
1272  }
1273 
1274  // Debug
1275  if ( verbose && edm::isDebugEnabled() ) {
1276  std::stringstream ss;
1277  ss << "[jpt::Map::" << __func__ << "]"
1278  << " Parsed contents of map at location:" << std::endl
1279  << "\"" << file << "\"" << std::endl;
1280  print(ss);
1281  LogTrace("JetPlusTrackCorrector") << ss.str();
1282  }
1283 
1284 }
bool isDebugEnabled()
list file
Definition: dbtoweb.py:253
void print(std::stringstream &ss) const
#define LogTrace(id)
tuple input
Definition: collect_tpl.py:10
std::vector< double > pt_
std::vector< double > eta_
std::string fullPath() const
Definition: FileInPath.cc:170
std::vector< double > VDouble
Map::Map ( )

Definition at line 1288 of file JetPlusTrackCorrector.cc.

References clear().

1289  : eta_(),
1290  pt_(),
1291  data_()
1292 {
1293  clear();
1294 }
std::vector< double > pt_
std::vector< double > eta_
Map::~Map ( )

Definition at line 1298 of file JetPlusTrackCorrector.cc.

References clear().

1298  {
1299  clear();
1300 }

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().

1339  {
1340  if ( !eta_.empty() && eta_bin+1 < eta_.size() ) {
1341  return eta_[eta_bin] + ( eta_[eta_bin+1] - eta_[eta_bin] ) / 2.;
1342  } else {
1343  edm::LogWarning("JetPlusTrackCorrector")
1344  << "[jpt::Map::" << __func__ << "]"
1345  << " Trying to access element " << eta_bin+1
1346  << " of a vector with size " << eta_.size()
1347  << "!";
1348  return eta_[eta_.size()-1];
1349  }
1350 }
std::vector< double > eta_
double Map::binCenterPt ( uint32_t  pt_bin) const

Definition at line 1354 of file JetPlusTrackCorrector.cc.

References pt_.

Referenced by JetPlusTrackCorrector::pionEfficiency().

1354  {
1355  if ( !pt_.empty() && pt_bin+1 < pt_.size() ) {
1356  return pt_[pt_bin] + ( pt_[pt_bin+1] - pt_[pt_bin] ) / 2.;
1357  } else {
1358  edm::LogWarning("JetPlusTrackCorrector")
1359  << "[jpt::Map::" << __func__ << "]"
1360  << " Trying to access element " << pt_bin+1
1361  << " of a vector with size " << pt_.size()
1362  << "!";
1363  return pt_[pt_.size()-1];
1364  }
1365 }
std::vector< double > pt_
void Map::clear ( void  )

Definition at line 1304 of file JetPlusTrackCorrector.cc.

References data_, eta_, and pt_.

Referenced by python.Vispa.Views.BoxDecayView.BoxDecayView::closeEvent(), Map(), python.Vispa.Views.LineDecayView.LineDecayView::setDataObjects(), python.Vispa.Views.BoxDecayView.BoxDecayView::updateContent(), and ~Map().

1304  {
1305  eta_.clear();
1306  pt_.clear();
1307  data_.clear();
1308 }
std::vector< double > pt_
std::vector< double > eta_
double Map::eta ( uint32_t  eta_bin) const

Definition at line 1311 of file JetPlusTrackCorrector.cc.

References eta_.

Referenced by etaBin().

1311  {
1312  if ( !eta_.empty() && eta_bin < eta_.size() ) { return eta_[eta_bin]; }
1313  else {
1314  edm::LogWarning("JetPlusTrackCorrector")
1315  << "[jpt::Map::" << __func__ << "]"
1316  << " Trying to access element " << eta_bin
1317  << " of a vector with size " << eta_.size()
1318  << "!";
1319  return eta_[eta_.size()-1];
1320  }
1321 }
std::vector< double > eta_
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().

1369  {
1370  val = fabs( val );
1371  for ( uint32_t ieta = 0; ieta < nEtaBins()-1; ++ieta ) { //@@ "-1" is bug?
1372  if ( val > eta(ieta) && ( ieta+1 == nEtaBins() || val < eta(ieta+1) ) ) { return ieta; }
1373  }
1374  return nEtaBins();
1375 }
uint32_t nEtaBins() const
double eta(uint32_t) const
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().

1404  {
1405  ss << " Number of bins in eta : " << data_.size() << std::endl
1406  << " Number of bins in pt : " << ( data_.empty() ? 0 : data_[0].size() ) << std::endl;
1407  VVDouble::const_iterator ieta = data_.begin();
1408  VVDouble::const_iterator jeta = data_.end();
1409  for ( ; ieta != jeta; ++ieta ) {
1410  VDouble::const_iterator ipt = ieta->begin();
1411  VDouble::const_iterator jpt = ieta->end();
1412  for ( ; ipt != jpt; ++ipt ) {
1413  uint32_t eta_bin = static_cast<uint32_t>( ieta - data_.begin() );
1414  uint32_t pt_bin = static_cast<uint32_t>( ipt - ieta->begin() );
1415  ss << " EtaBinNumber: " << eta_bin
1416  << " PtBinNumber: " << pt_bin
1417  << " EtaValue: " << eta_[ eta_bin ]
1418  << " PtValue: " << pt_[ pt_bin ]
1419  << " Value: " << data_[eta_bin][pt_bin]
1420  << std::endl;
1421  }
1422  }
1423 }
std::vector< double > pt_
std::vector< double > eta_
double Map::pt ( uint32_t  pt_bin) const

Definition at line 1325 of file JetPlusTrackCorrector.cc.

References pt_.

Referenced by ptBin().

1325  {
1326  if ( !pt_.empty() && pt_bin < pt_.size() ) { return pt_[pt_bin]; }
1327  else {
1328  edm::LogWarning("JetPlusTrackCorrector")
1329  << "[jpt::Map::" << __func__ << "]"
1330  << " Trying to access element " << pt_bin
1331  << " of a vector with size " << pt_.size()
1332  << "!";
1333  return pt_[pt_.size()-1];
1334  }
1335 }
std::vector< double > pt_
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().

1379  {
1380  val = fabs( val );
1381  for ( uint32_t ipt = 0; ipt < nPtBins()-1; ++ipt ) { //@@ "-1" is bug?
1382  if ( val > pt(ipt) && ( (ipt+1) == nPtBins() || val < pt(ipt+1) ) ) { return ipt; }
1383  }
1384  return nPtBins();
1385 }
double pt(uint32_t) const
uint32_t nPtBins() const
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().

1389  {
1390  if ( eta_bin < data_.size() &&
1391  pt_bin < ( data_.empty() ? 0 : data_[0].size() ) ) { return data_[eta_bin][pt_bin]; }
1392  else {
1393  edm::LogWarning("JetPlusTrackCorrector")
1394  << "[jpt::Map::" << __func__ << "]"
1395  << " Trying to access element (" << eta_bin << "," << pt_bin << ")"
1396  << " of a vector with size (" << data_.size() << "," << ( data_.empty() ? 0 : data_[0].size() ) << ")"
1397  << "!";
1398  return 1.;
1399  }
1400 }

Member Data Documentation

VVDouble jpt::Map::data_
private

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().