ATLAS Offline Software
PhysicsVariablePlots.icc
Go to the documentation of this file.
1 
2 template < typename T >
3 StatusCode PhysicsVariablePlots::defineHistogram( const std::string& variableName,
4  const std::string& title,
5  int nBinsX, double xMin, double xMax,
6  const std::string& path ) {
7 
8  if ( m_Histograms1D.find( variableName.c_str() ) != m_Histograms1D.end() ) {
9  ATH_MSG_ERROR( "Trying to define histogram for variable '" << variableName << "' but this histogram already exists!" );
10  return StatusCode::FAILURE;
11  }
12 
13  m_Histograms1D[ variableName.c_str() ] = new T( variableName.c_str(),
14  title.c_str(),
15  nBinsX,xMin,xMax );
16 
17  std::string subPath = "";
18  if ( not path.empty() ) subPath = path + "/";
19 
20  const std::string histoPath = "/MYSTREAM/"+ subPath + variableName;
21  TH1* histoObj = m_Histograms1D.at( variableName.c_str() );
22  ATH_CHECK( m_histSvc->regHist( histoPath,histoObj ) );
23 
24  return StatusCode::SUCCESS;
25 }
26 
27 template < typename T >
28 StatusCode PhysicsVariablePlots::defineHistogram( const std::string& variableName,
29  const std::string& title,
30  int nBinsX, double xMin, double xMax,
31  int nBinsY, double yMin, double yMax,
32  const std::string& path ) {
33 
34  if ( m_Histograms2D.find( variableName.c_str() ) != m_Histograms2D.end() ) {
35  ATH_MSG_ERROR( "Trying to define histogram for variable '" << variableName << "' but this histogram already exists!" );
36  return StatusCode::FAILURE;
37  }
38 
39  m_Histograms2D[ variableName.c_str() ] = new T( variableName.c_str(),
40  title.c_str(),
41  nBinsX,xMin,xMax,
42  nBinsY,yMin,yMax );
43 
44  std::string subPath = "";
45  if ( not path.empty() ) subPath = path + "/";
46 
47  const std::string histoPath = "/MYSTREAM/" + subPath + variableName;
48  TH2* histoObj = m_Histograms2D.at( variableName.c_str() );
49  ATH_CHECK( m_histSvc->regHist( histoPath,histoObj ) );
50 
51  return StatusCode::SUCCESS;
52 }
53 
54 template < typename T >
55 StatusCode PhysicsVariablePlots::fillHistogram( const std::string& variableName,
56  T value ) {
57 
58  if ( m_Histograms1D.find( variableName.c_str() ) == m_Histograms1D.end() ) {
59  ATH_MSG_ERROR( "Trying to fill histogram for variable '" << variableName << "' but this histogram has not been stored!" );
60  return StatusCode::FAILURE;
61  }
62 
63  m_Histograms1D.at( variableName.c_str() )->Fill( value );
64  return StatusCode::SUCCESS;
65 }
66 
67 template < typename T,typename U >
68 StatusCode PhysicsVariablePlots::fillHistogram( const std::string& variableName,
69  T valueX,
70  U valueY ) {
71 
72  if ( m_Histograms2D.find( variableName.c_str() ) == m_Histograms2D.end() ) {
73  ATH_MSG_ERROR( "Trying to fill histogram for variable '" << variableName << "' but this histogram has not been stored!" );
74  return StatusCode::FAILURE;
75  }
76 
77  m_Histograms2D.at( variableName.c_str() )->Fill( valueX,valueY );
78  return StatusCode::SUCCESS;
79 }
80