ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes | Static Private Attributes | List of all members
TFCS2DFunctionHistogram Class Reference

#include <TFCS2DFunctionHistogram.h>

Inheritance diagram for TFCS2DFunctionHistogram:
Collaboration diagram for TFCS2DFunctionHistogram:

Public Member Functions

 TFCS2DFunctionHistogram (TH2 *hist=nullptr)
 
 ~TFCS2DFunctionHistogram ()
 
void Initialize (TH2 *hist)
 
virtual void rnd_to_fct (float &valuex, float &valuey, float rnd0, float rnd1) const
 
const std::vector< float > & get_HistoBordersx () const
 
std::vector< float > & get_HistoBordersx ()
 
const std::vector< float > & get_HistoBordersy () const
 
std::vector< float > & get_HistoBordersy ()
 
const std::vector< float > & get_HistoContents () const
 
std::vector< float > & get_HistoContents ()
 
virtual void rnd_to_fct (float &valuex, float &valuey, float rnd0, float rnd1) const=0
 
virtual void rnd_to_fct (float value[], const float rnd[]) const
 
virtual int ndim () const
 Return the number of dimensions for the function. More...
 
virtual void rnd_to_fct (float value[], const float rnd[]) const
 Function gets array of random numbers rnd[] in the range [0,1) as arguments and returns function value in array value. More...
 
virtual std::size_t MemorySize () const
 Gives the total memory size, including the size of additional memory allocated inside the class. More...
 
bool msgLvl (const MSG::Level lvl) const
 Check whether the logging system is active at the provided verbosity level. More...
 
MsgStream & msg () const
 Return a stream for sending messages directly (no decoration) More...
 
MsgStream & msg (const MSG::Level lvl) const
 Return a decorated starting stream for sending messages. More...
 
MSG::Level level () const
 Retrieve output level. More...
 
virtual void setLevel (MSG::Level lvl)
 Update outputlevel. More...
 

Static Public Member Functions

static void unit_test ATLAS_NOT_THREAD_SAFE (TH2 *hist=nullptr)
 
static double CheckAndIntegrate2DHistogram (const TH2 *hist, std::vector< double > &integral_vec, int &first, int &last)
 
static void unit_test ATLAS_NOT_THREAD_SAFE (TH2 *hist=nullptr, TFCS2DFunction *rtof=nullptr, const char *outfilename="TFCS2DFunction_unit_test.root", int nrnd=10000000)
 
static void unit_tests ATLAS_NOT_THREAD_SAFE (TH2 *hist=nullptr, const char *outfilename="TFCS2DFunction_unit_test.root", int nrnd=10000000)
 
static std::string startMsg (MSG::Level lvl, const std::string &file, int line)
 Make a message to decorate the start of logging. More...
 

Protected Attributes

std::vector< float > m_HistoBorders
 
std::vector< float > m_HistoBordersy
 
std::vector< float > m_HistoContents
 

Private Attributes

std::string m_nm
 Message source name. More...
 

Static Private Attributes

static boost::thread_specific_ptr< MsgStream > m_msg_tls ATLAS_THREAD_SAFE
 Do not persistify! More...
 

Detailed Description

Definition at line 15 of file TFCS2DFunctionHistogram.h.

Constructor & Destructor Documentation

◆ TFCS2DFunctionHistogram()

TFCS2DFunctionHistogram::TFCS2DFunctionHistogram ( TH2 hist = nullptr)
inline

Definition at line 17 of file TFCS2DFunctionHistogram.h.

17  {
18  if (hist)
20  };

◆ ~TFCS2DFunctionHistogram()

TFCS2DFunctionHistogram::~TFCS2DFunctionHistogram ( )
inline

Definition at line 21 of file TFCS2DFunctionHistogram.h.

21 {};

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE() [1/3]

static void unit_test TFCS2DFunctionHistogram::ATLAS_NOT_THREAD_SAFE ( TH2 hist = nullptr)
static

◆ ATLAS_NOT_THREAD_SAFE() [2/3]

static void unit_tests TFCS2DFunction::ATLAS_NOT_THREAD_SAFE ( TH2 hist = nullptr,
const char *  outfilename = "TFCS2DFunction_unit_test.root",
int  nrnd = 10000000 
)
staticinherited

◆ ATLAS_NOT_THREAD_SAFE() [3/3]

static void unit_test TFCS2DFunction::ATLAS_NOT_THREAD_SAFE ( TH2 hist = nullptr,
TFCS2DFunction rtof = nullptr,
const char *  outfilename = "TFCS2DFunction_unit_test.root",
int  nrnd = 10000000 
)
staticinherited

◆ CheckAndIntegrate2DHistogram()

double TFCS2DFunction::CheckAndIntegrate2DHistogram ( const TH2 hist,
std::vector< double > &  integral_vec,
int &  first,
int &  last 
)
staticinherited

Definition at line 26 of file TFCS2DFunction.cxx.

27  {
29  Int_t nbinsx = hist->GetNbinsX();
30  Int_t nbinsy = hist->GetNbinsY();
31  Int_t nbins = nbinsx * nbinsy;
32 
33  float integral = 0.0;
34  float hint = hist->Integral();
35  integral_vec.resize(nbins);
36 
37  for (int ix = 1; ix <= nbinsx; ix++) {
38  for (int iy = 1; iy <= nbinsy; iy++) {
39  int globalbin = (ix - 1) * nbinsy + iy - 1;
40  float binval = hist->GetBinContent(ix, iy);
41  if (binval < 0) {
42  // Can't work if a bin is negative, forcing bins to 0 in this case
43  double fraction = binval / hint;
44  if (TMath::Abs(fraction) > 1e-5) {
46  "Warning: bin content is negative in histogram "
47  << hist->GetName() << " : " << hist->GetTitle()
48  << " binval=" << binval << " " << fraction * 100
49  << "% of integral=" << hist->Integral()
50  << ". Forcing bin to 0.");
51  }
52  binval = 0;
53  }
54  integral += binval;
55  integral_vec[globalbin] = integral;
56  }
57  }
58 
59  for (first = 0; first < nbins; first++)
60  if (integral_vec[first] != 0)
61  break;
62  for (last = nbins - 1; last > 0; last--)
63  if (integral_vec[last] != integral)
64  break;
65  last++;
66 
67  if (integral <= 0) {
68  ATH_MSG_NOCLASS(logger, "Error: histogram "
69  << hist->GetName() << " : " << hist->GetTitle()
70  << " integral=" << integral << " is <=0");
71  }
72 
73  return integral;
74 }

◆ get_HistoBordersx() [1/2]

std::vector<float>& TFCS2DFunctionHistogram::get_HistoBordersx ( )
inline

Definition at line 32 of file TFCS2DFunctionHistogram.h.

32 { return m_HistoBorders; };

◆ get_HistoBordersx() [2/2]

const std::vector<float>& TFCS2DFunctionHistogram::get_HistoBordersx ( ) const
inline

Definition at line 29 of file TFCS2DFunctionHistogram.h.

29  {
30  return m_HistoBorders;
31  };

◆ get_HistoBordersy() [1/2]

std::vector<float>& TFCS2DFunctionHistogram::get_HistoBordersy ( )
inline

Definition at line 36 of file TFCS2DFunctionHistogram.h.

36 { return m_HistoBordersy; };

◆ get_HistoBordersy() [2/2]

const std::vector<float>& TFCS2DFunctionHistogram::get_HistoBordersy ( ) const
inline

Definition at line 33 of file TFCS2DFunctionHistogram.h.

33  {
34  return m_HistoBordersy;
35  };

◆ get_HistoContents() [1/2]

std::vector<float>& TFCS2DFunctionHistogram::get_HistoContents ( )
inline

Definition at line 40 of file TFCS2DFunctionHistogram.h.

40 { return m_HistoContents; };

◆ get_HistoContents() [2/2]

const std::vector<float>& TFCS2DFunctionHistogram::get_HistoContents ( ) const
inline

Definition at line 37 of file TFCS2DFunctionHistogram.h.

37  {
38  return m_HistoContents;
39  };

◆ Initialize()

void TFCS2DFunctionHistogram::Initialize ( TH2 hist)

Definition at line 18 of file TFCS2DFunctionHistogram.cxx.

18  {
19  Int_t nbinsx = hist->GetNbinsX();
20  Int_t nbinsy = hist->GetNbinsY();
21  Int_t nbins = nbinsx * nbinsy;
22 
23  float integral = 0;
24  m_HistoBorders.resize(nbinsx + 1);
25  m_HistoBordersy.resize(nbinsy + 1);
26  m_HistoContents.resize(nbins);
27  int ibin = 0;
28  for (int iy = 1; iy <= nbinsy; iy++) {
29  for (int ix = 1; ix <= nbinsx; ix++) {
30  float binval = hist->GetBinContent(ix, iy);
31  if (binval < 0) {
32  // Can't work if a bin is negative, forcing bins to 0 in this case
33  double fraction = binval / hist->Integral();
34  if (TMath::Abs(fraction) > 1e-5) {
35  ATH_MSG_WARNING("bin content is negative in histogram "
36  << hist->GetName() << " : " << hist->GetTitle()
37  << " binval=" << binval << " " << fraction * 100
38  << "% of integral=" << hist->Integral()
39  << ". Forcing bin to 0.");
40  }
41  binval = 0;
42  }
43  integral += binval;
44  m_HistoContents[ibin] = integral;
45  ++ibin;
46  }
47  }
48  if (integral <= 0) {
49  ATH_MSG_ERROR("histogram " << hist->GetName() << " : " << hist->GetTitle()
50  << " integral=" << integral << " is <=0");
51  m_HistoBorders.resize(0);
52  m_HistoBordersy.resize(0);
53  m_HistoContents.resize(0);
54  return;
55  }
56 
57  for (int ix = 1; ix <= nbinsx; ix++)
58  m_HistoBorders[ix - 1] = hist->GetXaxis()->GetBinLowEdge(ix);
59  m_HistoBorders[nbinsx] = hist->GetXaxis()->GetXmax();
60 
61  for (int iy = 1; iy <= nbinsy; iy++)
62  m_HistoBordersy[iy - 1] = hist->GetYaxis()->GetBinLowEdge(iy);
63  m_HistoBordersy[nbinsy] = hist->GetYaxis()->GetXmax();
64 
65  for (ibin = 0; ibin < nbins; ++ibin)
66  m_HistoContents[ibin] /= integral;
67 }

◆ level()

MSG::Level ISF_FCS::MLogging::level ( ) const
inlineinherited

Retrieve output level.

Definition at line 201 of file MLogging.h.

201 { return msg().level(); }

◆ MemorySize()

virtual std::size_t TFCSFunction::MemorySize ( ) const
inlinevirtualinherited

Gives the total memory size, including the size of additional memory allocated inside the class.

Reimplemented in TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, Trandom >, and TFCS1DFunctionTemplateHistogram< Txvec, Ty, Trandom >.

Definition at line 19 of file TFCSFunction.h.

19 { return sizeof(*this); };

◆ msg() [1/2]

MsgStream & ISF_FCS::MLogging::msg ( ) const
inlineinherited

Return a stream for sending messages directly (no decoration)

Definition at line 231 of file MLogging.h.

231  {
232  MsgStream *ms = m_msg_tls.get();
233  if (!ms) {
234  ms = new MsgStream(Athena::getMessageSvc(), m_nm);
235  m_msg_tls.reset(ms);
236  }
237  return *ms;
238 }

◆ msg() [2/2]

MsgStream & ISF_FCS::MLogging::msg ( const MSG::Level  lvl) const
inlineinherited

Return a decorated starting stream for sending messages.

Definition at line 240 of file MLogging.h.

240  {
241  return msg() << lvl;
242 }

◆ msgLvl()

bool ISF_FCS::MLogging::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Check whether the logging system is active at the provided verbosity level.

Definition at line 222 of file MLogging.h.

222  {
223  if (msg().level() <= lvl) {
224  msg() << lvl;
225  return true;
226  } else {
227  return false;
228  }
229 }

◆ ndim()

virtual int TFCS2DFunction::ndim ( ) const
inlinevirtualinherited

Return the number of dimensions for the function.

Reimplemented from TFCSFunction.

Definition at line 20 of file TFCS2DFunction.h.

20 { return 2; };

◆ rnd_to_fct() [1/4]

void TFCS2DFunctionHistogram::rnd_to_fct ( float &  valuex,
float &  valuey,
float  rnd0,
float  rnd1 
) const
virtual

Implements TFCS2DFunction.

Definition at line 69 of file TFCS2DFunctionHistogram.cxx.

70  {
71  if (m_HistoContents.empty()) {
72  valuex = 0;
73  valuey = 0;
74  return;
75  }
76  auto it =
77  std::upper_bound(m_HistoContents.begin(), m_HistoContents.end(), rnd0);
78  int ibin = std::distance(m_HistoContents.begin(), it);
79  if (ibin >= (int)m_HistoContents.size())
80  ibin = m_HistoContents.size() - 1;
81  Int_t nbinsx = m_HistoBorders.size() - 1;
82  Int_t biny = ibin / nbinsx;
83  Int_t binx = ibin - nbinsx * biny;
84 
85  float basecont = 0;
86  if (ibin > 0)
87  basecont = m_HistoContents[ibin - 1];
88 
89  float dcont = m_HistoContents[ibin] - basecont;
90  if (dcont > 0) {
91  valuex = m_HistoBorders[binx] +
92  (m_HistoBorders[binx + 1] - m_HistoBorders[binx]) *
93  (rnd0 - basecont) / dcont;
94  } else {
95  valuex = m_HistoBorders[binx] +
96  (m_HistoBorders[binx + 1] - m_HistoBorders[binx]) / 2;
97  }
98  valuey = m_HistoBordersy[biny] +
99  (m_HistoBordersy[biny + 1] - m_HistoBordersy[biny]) * rnd1;
100 }

◆ rnd_to_fct() [2/4]

virtual void TFCS2DFunction::rnd_to_fct

◆ rnd_to_fct() [3/4]

void TFCS2DFunction::rnd_to_fct ( float  value[],
const float  rnd[] 
) const
virtualinherited

Function gets array of random numbers rnd[] in the range [0,1) as arguments and returns function value in array value.

For a n-dimensional function, value and rnd should both have n elements.

Implements TFCSFunction.

Definition at line 20 of file TFCS2DFunction.cxx.

20  {
21  rnd_to_fct(value[0], value[1], rnd[0], rnd[1]);
22 }

◆ rnd_to_fct() [4/4]

void TFCS2DFunction::rnd_to_fct

Definition at line 24 of file TFCS2DFunction.cxx.

20  {
21  rnd_to_fct(value[0], value[1], rnd[0], rnd[1]);
22 }

◆ setLevel()

void ISF_FCS::MLogging::setLevel ( MSG::Level  lvl)
virtualinherited

Update outputlevel.

Definition at line 105 of file MLogging.cxx.

105  {
106  lvl = (lvl >= MSG::NUM_LEVELS) ? MSG::ALWAYS
107  : (lvl < MSG::NIL) ? MSG::NIL
108  : lvl;
109  msg().setLevel(lvl);
110 }

◆ startMsg()

std::string ISF_FCS::MLogging::startMsg ( MSG::Level  lvl,
const std::string &  file,
int  line 
)
staticinherited

Make a message to decorate the start of logging.

Print a message for the start of logging.

Definition at line 116 of file MLogging.cxx.

116  {
117  int col1_len = 20;
118  int col2_len = 5;
119  int col3_len = 10;
120  auto last_slash = file.find_last_of('/');
121  int path_len = last_slash == std::string::npos ? 0 : last_slash;
122  int trim_point = path_len;
123  int total_len = file.length();
124  if (total_len - path_len > col1_len)
125  trim_point = total_len - col1_len;
126  std::string trimmed_name = file.substr(trim_point);
127  const char *LevelNames[MSG::NUM_LEVELS] = {
128  "NIL", "VERBOSE", "DEBUG", "INFO", "WARNING", "ERROR", "FATAL", "ALWAYS"};
129  std::string level = LevelNames[lvl];
130  std::string level_string = std::string("(") + level + ") ";
131  std::stringstream output;
132  output << std::setw(col1_len) << std::right << trimmed_name << ":"
133  << std::setw(col2_len) << std::left << line << std::setw(col3_len)
134  << std::right << level_string;
135  return output.str();
136 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

boost::thread_specific_ptr<MsgStream> m_msg_tls ISF_FCS::MLogging::ATLAS_THREAD_SAFE
inlinestaticprivateinherited

Do not persistify!

MsgStream instance (a std::cout like with print-out levels)

Definition at line 215 of file MLogging.h.

◆ m_HistoBorders

std::vector<float> TFCS2DFunctionHistogram::m_HistoBorders
protected

Definition at line 45 of file TFCS2DFunctionHistogram.h.

◆ m_HistoBordersy

std::vector<float> TFCS2DFunctionHistogram::m_HistoBordersy
protected

Definition at line 46 of file TFCS2DFunctionHistogram.h.

◆ m_HistoContents

std::vector<float> TFCS2DFunctionHistogram::m_HistoContents
protected

Definition at line 47 of file TFCS2DFunctionHistogram.h.

◆ m_nm

std::string ISF_FCS::MLogging::m_nm
privateinherited

Message source name.

Definition at line 211 of file MLogging.h.


The documentation for this class was generated from the following files:
ISF_FCS::MLogging
Cut down AthMessaging.
Definition: MLogging.h:176
checkFileSG.line
line
Definition: checkFileSG.py:75
integral
double integral(TH1 *h)
Definition: computils.cxx:57
plotBeamSpotVxVal.globalbin
globalbin
Definition: plotBeamSpotVxVal.py:247
ISF_FCS::MLogging::level
MSG::Level level() const
Retrieve output level.
Definition: MLogging.h:201
plotmaker.hist
hist
Definition: plotmaker.py:148
skel.it
it
Definition: skel.GENtoEVGEN.py:423
TFCS2DFunctionHistogram::m_HistoContents
std::vector< float > m_HistoContents
Definition: TFCS2DFunctionHistogram.h:47
athena.value
value
Definition: athena.py:122
TFCS2DFunctionHistogram::Initialize
void Initialize(TH2 *hist)
Definition: TFCS2DFunctionHistogram.cxx:18
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
TFCS2DFunction::rnd_to_fct
virtual void rnd_to_fct(float &valuex, float &valuey, float rnd0, float rnd1) const =0
ISF_FCS::MLogging::msg
MsgStream & msg() const
Return a stream for sending messages directly (no decoration)
Definition: MLogging.h:231
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigConf::MSGTC::ALWAYS
@ ALWAYS
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:29
ISF_FCS::MLogging::m_nm
std::string m_nm
Message source name.
Definition: MLogging.h:211
file
TFile * file
Definition: tile_monitor.h:29
merge.output
output
Definition: merge.py:17
TFCS2DFunctionHistogram::rnd_to_fct
virtual void rnd_to_fct(float &valuex, float &valuey, float rnd0, float rnd1) const
Definition: TFCS2DFunctionHistogram.cxx:69
TrigConf::MSGTC::NUM_LEVELS
@ NUM_LEVELS
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:30
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
ATH_MSG_NOCLASS
#define ATH_MSG_NOCLASS(logger_name, x)
Definition: MLogging.h:52
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DeMoScan.first
bool first
Definition: DeMoScan.py:534
TFCS2DFunctionHistogram::m_HistoBorders
std::vector< float > m_HistoBorders
Definition: TFCS2DFunctionHistogram.h:45
TrigConf::MSGTC::NIL
@ NIL
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:22
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14
TFCS2DFunctionHistogram::m_HistoBordersy
std::vector< float > m_HistoBordersy
Definition: TFCS2DFunctionHistogram.h:46