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

#include <TFCS1DFunctionInt32Histogram.h>

Inheritance diagram for TFCS1DFunctionInt32Histogram:
Collaboration diagram for TFCS1DFunctionInt32Histogram:

Public Types

typedef uint32_t HistoContent_t
 

Public Member Functions

 TFCS1DFunctionInt32Histogram (const TH1 *hist=nullptr)
 
 ~TFCS1DFunctionInt32Histogram ()
 
void Initialize (const TH1 *hist)
 
virtual double rnd_to_fct (double rnd) const
 Function gets random number rnd in the range [0,1) as argument and returns function value according to a histogram distribution. More...
 
virtual bool operator== (const TFCS1DFunction &ref) const
 The == operator compares the content of instances. More...
 
const std::vector< float > & get_HistoBordersx () const
 
std::vector< float > & get_HistoBordersx ()
 
const std::vector< HistoContent_t > & get_HistoContents () const
 
std::vector< HistoContent_t > & get_HistoContents ()
 
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 double rnd_to_fct (double rnd) const=0
 Function gets random number rnd in the range [0,1) as argument and returns function value. More...
 
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 (TH1 *hist=nullptr)
 
static double get_maxdev (TH1 *, TH1 *)
 
static double CheckAndIntegrate1DHistogram (const TH1 *hist, std::vector< double > &integral_vec, int &first, int &last)
 
static TH1 *generate_histogram_random_slope ATLAS_NOT_THREAD_SAFE (int nbinsx=50, double xmin=0, double xmax=1, double zerothreshold=0.1)
 
static TH1 *generate_histogram_random_gauss ATLAS_NOT_THREAD_SAFE (int nbinsx=50, int ntoy=100000, double xmin=1, double xmax=5, double xpeak=1.5, double sigma=0.6)
 
static void unit_test ATLAS_NOT_THREAD_SAFE (TH1 *hist, TFCS1DFunction *rtof, int nrnd=1000000, TH1 *histfine=nullptr)
 
static std::string startMsg (MSG::Level lvl, const std::string &file, int line)
 Make a message to decorate the start of logging. More...
 

Static Public Attributes

static const HistoContent_t s_MaxValue = UINT32_MAX
 

Protected Attributes

std::vector< float > m_HistoBorders
 
std::vector< HistoContent_tm_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 TFCS1DFunctionInt32Histogram.h.

Member Typedef Documentation

◆ HistoContent_t

Definition at line 27 of file TFCS1DFunctionInt32Histogram.h.

Constructor & Destructor Documentation

◆ TFCS1DFunctionInt32Histogram()

TFCS1DFunctionInt32Histogram::TFCS1DFunctionInt32Histogram ( const TH1 hist = nullptr)
inline

Definition at line 17 of file TFCS1DFunctionInt32Histogram.h.

17  {
18  if (hist)
20  };

◆ ~TFCS1DFunctionInt32Histogram()

TFCS1DFunctionInt32Histogram::~TFCS1DFunctionInt32Histogram ( )
inline

Definition at line 21 of file TFCS1DFunctionInt32Histogram.h.

21 {};

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE() [1/4]

static TH1* generate_histogram_random_slope TFCS1DFunction::ATLAS_NOT_THREAD_SAFE ( int  nbinsx = 50,
double  xmin = 0,
double  xmax = 1,
double  zerothreshold = 0.1 
)
staticinherited

◆ ATLAS_NOT_THREAD_SAFE() [2/4]

static TH1* generate_histogram_random_gauss TFCS1DFunction::ATLAS_NOT_THREAD_SAFE ( int  nbinsx = 50,
int  ntoy = 100000,
double  xmin = 1,
double  xmax = 5,
double  xpeak = 1.5,
double  sigma = 0.6 
)
staticinherited

◆ ATLAS_NOT_THREAD_SAFE() [3/4]

static void unit_test TFCS1DFunction::ATLAS_NOT_THREAD_SAFE ( TH1 hist,
TFCS1DFunction rtof,
int  nrnd = 1000000,
TH1 histfine = nullptr 
)
staticinherited

◆ ATLAS_NOT_THREAD_SAFE() [4/4]

static void unit_test TFCS1DFunctionInt32Histogram::ATLAS_NOT_THREAD_SAFE ( TH1 hist = nullptr)
static

◆ CheckAndIntegrate1DHistogram()

double TFCS1DFunction::CheckAndIntegrate1DHistogram ( const TH1 hist,
std::vector< double > &  integral_vec,
int &  first,
int &  last 
)
staticinherited

Definition at line 52 of file TFCS1DFunction.cxx.

53  {
55  Int_t nbins = hist->GetNbinsX();
56 
57  float integral = 0;
58  integral_vec.resize(nbins);
59  for (int ix = 1; ix <= nbins; ix++) {
60  float binval = hist->GetBinContent(ix);
61  if (binval < 0) {
62  // Can't work if a bin is negative, forcing bins to 0 in this case
63  double fraction = binval / hist->Integral();
64  if (TMath::Abs(fraction) > 1e-5) {
65  ATH_MSG_NOCLASS(logger, "Warning: bin content is negative in histogram "
66  << hist->GetName() << " : "
67  << hist->GetTitle() << " binval=" << binval
68  << " " << fraction * 100
69  << "% of integral=" << hist->Integral()
70  << ". Forcing bin to 0.");
71  }
72  binval = 0;
73  }
74  integral += binval;
75  integral_vec[ix - 1] = integral;
76  }
77 
78  for (first = 0; first < nbins; first++)
79  if (integral_vec[first] != 0)
80  break;
81  for (last = nbins - 1; last > 0; last--)
82  if (integral_vec[last] != integral)
83  break;
84  last++;
85 
86  if (integral <= 0) {
87  ATH_MSG_NOCLASS(logger, "Error: histogram "
88  << hist->GetName() << " : " << hist->GetTitle()
89  << " integral=" << integral << " is <=0");
90  }
91  return integral;
92 }

◆ get_HistoBordersx() [1/2]

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

Definition at line 39 of file TFCS1DFunctionInt32Histogram.h.

39 { return m_HistoBorders; };

◆ get_HistoBordersx() [2/2]

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

Definition at line 36 of file TFCS1DFunctionInt32Histogram.h.

36  {
37  return m_HistoBorders;
38  };

◆ get_HistoContents() [1/2]

std::vector<HistoContent_t>& TFCS1DFunctionInt32Histogram::get_HistoContents ( )
inline

Definition at line 43 of file TFCS1DFunctionInt32Histogram.h.

43 { return m_HistoContents; };

◆ get_HistoContents() [2/2]

const std::vector<HistoContent_t>& TFCS1DFunctionInt32Histogram::get_HistoContents ( ) const
inline

Definition at line 40 of file TFCS1DFunctionInt32Histogram.h.

40  {
41  return m_HistoContents;
42  };

◆ get_maxdev()

double TFCS1DFunction::get_maxdev ( TH1 h_input1,
TH1 h_approx1 
)
staticinherited

Definition at line 21 of file TFCS1DFunction.cxx.

21  {
22  TH1D *h_input = (TH1D *)h_input1->Clone("h_input");
23  TH1D *h_approx = (TH1D *)h_approx1->Clone("h_approx");
24 
25  double maxdev = 0.0;
26 
27  // normalize the histos to the same area:
28  double integral_input = h_input->Integral();
29  double integral_approx = 0.0;
30  for (int b = 1; b <= h_input->GetNbinsX(); b++)
31  integral_approx +=
32  h_approx->GetBinContent(h_approx->FindBin(h_input->GetBinCenter(b)));
33  h_approx->Scale(integral_input / integral_approx);
34 
35  double ymax = h_approx->GetBinContent(h_approx->GetNbinsX()) -
36  h_approx->GetBinContent(h_approx->GetMinimumBin());
37  for (int i = 1; i <= h_input->GetNbinsX(); i++) {
38  double val = fabs(h_approx->GetBinContent(
39  h_approx->FindBin(h_input->GetBinCenter(i))) -
40  h_input->GetBinContent(i)) /
41  ymax;
42  if (val > maxdev)
43  maxdev = val;
44  }
45 
46  delete h_input;
47  delete h_approx;
48 
49  return maxdev * 100.0;
50 }

◆ Initialize()

void TFCS1DFunctionInt32Histogram::Initialize ( const TH1 hist)

Definition at line 22 of file TFCS1DFunctionInt32Histogram.cxx.

22  {
23  Int_t nbinsx = hist->GetNbinsX();
24  Int_t nbins = nbinsx;
25 
26  float integral = 0;
27  m_HistoBorders.resize(nbinsx + 1);
28  m_HistoContents.resize(nbins);
29  std::vector<double> temp_HistoContents(nbins);
30  int ibin = 0;
31  for (int ix = 1; ix <= nbinsx; ix++) {
32  float binval = hist->GetBinContent(ix);
33  if (binval < 0) {
34  // Can't work if a bin is negative, forcing bins to 0 in this case
35  double fraction = binval / hist->Integral();
36  if (TMath::Abs(fraction) > 1e-5) {
37  ATH_MSG_WARNING("bin content is negative in histogram "
38  << hist->GetName() << " : " << hist->GetTitle()
39  << " binval=" << binval << " " << fraction * 100
40  << "% of integral=" << hist->Integral()
41  << ". Forcing bin to 0.");
42  }
43  binval = 0;
44  }
45  integral += binval;
46  temp_HistoContents[ibin] = integral;
47  ++ibin;
48  }
49  if (integral <= 0) {
50  ATH_MSG_ERROR("histogram " << hist->GetName() << " : " << hist->GetTitle()
51  << " integral=" << integral << " is <=0");
52  m_HistoBorders.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 (ibin = 0; ibin < nbins; ++ibin) {
62  m_HistoContents[ibin] = s_MaxValue * (temp_HistoContents[ibin] / integral);
63  }
64 }

◆ 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 TFCS1DFunction::ndim ( ) const
inlinevirtualinherited

Return the number of dimensions for the function.

Reimplemented from TFCSFunction.

Definition at line 22 of file TFCS1DFunction.h.

22 { return 1; };

◆ operator==()

bool TFCS1DFunctionInt32Histogram::operator== ( const TFCS1DFunction ref) const
virtual

The == operator compares the content of instances.

The implementation in the base class only returns true for a comparison with itself

Reimplemented from TFCS1DFunction.

Definition at line 94 of file TFCS1DFunctionInt32Histogram.cxx.

94  {
95  if (IsA() != ref.IsA())
96  return false;
97  const TFCS1DFunctionInt32Histogram &ref_typed =
98  static_cast<const TFCS1DFunctionInt32Histogram &>(ref);
99 
100  if (m_HistoBorders != ref_typed.m_HistoBorders)
101  return false;
102  if (m_HistoContents != ref_typed.m_HistoContents)
103  return false;
104  return true;
105 }

◆ rnd_to_fct() [1/4]

double TFCS1DFunctionInt32Histogram::rnd_to_fct ( double  rnd) const
virtual

Function gets random number rnd in the range [0,1) as argument and returns function value according to a histogram distribution.

Implements TFCS1DFunction.

Definition at line 66 of file TFCS1DFunctionInt32Histogram.cxx.

66  {
67  if (m_HistoContents.empty()) {
68  return 0;
69  }
70  HistoContent_t int_rnd = s_MaxValue * rnd;
71  auto it =
72  std::upper_bound(m_HistoContents.begin(), m_HistoContents.end(), int_rnd);
73  int ibin = std::distance(m_HistoContents.begin(), it);
74  if (ibin >= (int)m_HistoContents.size())
75  ibin = m_HistoContents.size() - 1;
76  Int_t binx = ibin;
77 
78  HistoContent_t basecont = 0;
79  if (ibin > 0)
80  basecont = m_HistoContents[ibin - 1];
81 
82  HistoContent_t dcont = m_HistoContents[ibin] - basecont;
83  if (dcont > 0) {
84  return m_HistoBorders[binx] +
85  ((m_HistoBorders[binx + 1] - m_HistoBorders[binx]) *
86  (int_rnd - basecont)) /
87  dcont;
88  } else {
89  return m_HistoBorders[binx] +
90  (m_HistoBorders[binx + 1] - m_HistoBorders[binx]) / 2;
91  }
92 }

◆ rnd_to_fct() [2/4]

virtual double TFCS1DFunction::rnd_to_fct

Function gets random number rnd in the range [0,1) as argument and returns function value.

◆ rnd_to_fct() [3/4]

void TFCS1DFunction::rnd_to_fct

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.

Definition at line 27 of file TFCS1DFunction.cxx.

17  {
18  value[0] = rnd_to_fct(rnd[0]);
19 }

◆ rnd_to_fct() [4/4]

void TFCS1DFunction::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 17 of file TFCS1DFunction.cxx.

17  {
18  value[0] = rnd_to_fct(rnd[0]);
19 }

◆ 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> TFCS1DFunctionInt32Histogram::m_HistoBorders
protected

Definition at line 48 of file TFCS1DFunctionInt32Histogram.h.

◆ m_HistoContents

std::vector<HistoContent_t> TFCS1DFunctionInt32Histogram::m_HistoContents
protected

Definition at line 49 of file TFCS1DFunctionInt32Histogram.h.

◆ m_nm

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

Message source name.

Definition at line 211 of file MLogging.h.

◆ s_MaxValue

const TFCS1DFunctionInt32Histogram::HistoContent_t TFCS1DFunctionInt32Histogram::s_MaxValue = UINT32_MAX
static

Definition at line 28 of file TFCS1DFunctionInt32Histogram.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
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
integral
double integral(TH1 *h)
Definition: computils.cxx:57
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
TFCS1DFunction::rnd_to_fct
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 valu...
Definition: TFCS1DFunction.cxx:17
TFCS1DFunctionInt32Histogram::HistoContent_t
uint32_t HistoContent_t
Definition: TFCS1DFunctionInt32Histogram.h:27
TH1D
Definition: rootspy.cxx:342
athena.value
value
Definition: athena.py:122
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
TFCS1DFunctionInt32Histogram::rnd_to_fct
virtual double rnd_to_fct(double rnd) const
Function gets random number rnd in the range [0,1) as argument and returns function value according t...
Definition: TFCS1DFunctionInt32Histogram.cxx:66
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
TH1D::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:347
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
TFCS1DFunctionInt32Histogram::m_HistoBorders
std::vector< float > m_HistoBorders
Definition: TFCS1DFunctionInt32Histogram.h:48
TrigConf::MSGTC::ALWAYS
@ ALWAYS
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:29
lumiFormat.i
int i
Definition: lumiFormat.py:92
TFCS1DFunctionInt32Histogram
Definition: TFCS1DFunctionInt32Histogram.h:15
ISF_FCS::MLogging::m_nm
std::string m_nm
Message source name.
Definition: MLogging.h:211
file
TFile * file
Definition: tile_monitor.h:29
TFCS1DFunctionInt32Histogram::s_MaxValue
static const HistoContent_t s_MaxValue
Definition: TFCS1DFunctionInt32Histogram.h:28
merge.output
output
Definition: merge.py:17
TrigConf::MSGTC::NUM_LEVELS
@ NUM_LEVELS
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:30
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
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
ref
const boost::regex ref(r_ef)
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
DeMoScan.first
bool first
Definition: DeMoScan.py:534
TrigConf::MSGTC::NIL
@ NIL
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:22
TFCS1DFunctionInt32Histogram::m_HistoContents
std::vector< HistoContent_t > m_HistoContents
Definition: TFCS1DFunctionInt32Histogram.h:49
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
TFCS1DFunctionInt32Histogram::Initialize
void Initialize(const TH1 *hist)
Definition: TFCS1DFunctionInt32Histogram.cxx:22
ymax
double ymax
Definition: listroot.cxx:64