ATLAS Offline Software
Loading...
Searching...
No Matches
TFCS2DFunctionTemplateInterpolationExpHistogram< Txvec, Tyvec, Tz, Trandom > Class Template Reference

#include <TFCS2DFunctionTemplateInterpolationExpHistogram.h>

Inheritance diagram for TFCS2DFunctionTemplateInterpolationExpHistogram< Txvec, Tyvec, Tz, Trandom >:
Collaboration diagram for TFCS2DFunctionTemplateInterpolationExpHistogram< Txvec, Tyvec, Tz, Trandom >:

Public Types

typedef TFCS1DFunction_size_t size_t
typedef float random_type
typedef Txvec xvec_type
typedef Tyvec yvec_type
typedef Tz z_value_type

Public Member Functions

 TFCS2DFunctionTemplateInterpolationExpHistogram (TH2 *hist=nullptr)
virtual void rnd_to_fct (float &valuex, float &valuey, float rnd, float rnd2) const
 Function gets random number rnd in the range [0,1) as argument and returns function value according to a histogram distribution.
virtual void rnd_to_fct (float value[], const float rnd[]) const
 Function gets random number rnd in the range [0,1) as argument and returns function value according to a histogram distribution.
std::size_t MemorySizeArray () const
std::size_t MemorySize () const
 Gives the total memory size, including the size of additional memory allocated inside the class.
void set_nbins (size_t nbinsx, size_t nbinsy)
 set number of bins
size_t get_nbins () const
 return number of bins
void Initialize (const TH2 *hist)
 Initialize from root histogram.
const Txvec & get_HistoBordersx () const
const Tyvec & get_HistoBordersy () const
const TFCS1DFunction_HistogramContent< Tz, float > & get_HistoContents () const
virtual int ndim () const
 Return the number of dimensions for the function.
bool msgLvl (const MSG::Level lvl) const
 Check whether the logging system is active at the provided verbosity level.
MsgStream & msg () const
 Return a stream for sending messages directly (no decoration)
MsgStream & msg (const MSG::Level lvl) const
 Return a decorated starting stream for sending messages.
MSG::Level level () const
 Retrieve output level.
virtual void setLevel (MSG::Level lvl)
 Update outputlevel.

Static Public Member Functions

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.

Protected Attributes

Txvec m_HistoBordersx
Tyvec m_HistoBordersy
TFCS1DFunction_HistogramContent< Tz, float > m_HistoContents

Private Attributes

std::string m_nm
 Message source name.

Static Private Attributes

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

Detailed Description

template<typename Txvec, typename Tyvec, typename Tz, typename Trandom = float>
class TFCS2DFunctionTemplateInterpolationExpHistogram< Txvec, Tyvec, Tz, Trandom >

Definition at line 17 of file TFCS2DFunctionTemplateInterpolationExpHistogram.h.

Member Typedef Documentation

◆ random_type

typedef float TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::random_type
inherited

Definition at line 20 of file TFCS2DFunctionTemplateHistogram.h.

◆ size_t

typedef TFCS1DFunction_size_t TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::size_t
inherited

Definition at line 19 of file TFCS2DFunctionTemplateHistogram.h.

◆ xvec_type

typedef Txvec TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::xvec_type
inherited

Definition at line 21 of file TFCS2DFunctionTemplateHistogram.h.

◆ yvec_type

typedef Tyvec TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::yvec_type
inherited

Definition at line 22 of file TFCS2DFunctionTemplateHistogram.h.

◆ z_value_type

typedef Tz TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::z_value_type
inherited

Definition at line 23 of file TFCS2DFunctionTemplateHistogram.h.

Constructor & Destructor Documentation

◆ TFCS2DFunctionTemplateInterpolationExpHistogram()

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE() [1/2]

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() [2/2]

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();
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 (std::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 }
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--)
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}
#define ATH_MSG_NOCLASS(logger_name, x)
Definition MLogging.h:52

◆ get_HistoBordersx()

const Txvec & TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::get_HistoBordersx ( ) const
inlineinherited

◆ get_HistoBordersy()

const Tyvec & TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::get_HistoBordersy ( ) const
inlineinherited

◆ get_HistoContents()

const TFCS1DFunction_HistogramContent< Tz, float > & TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::get_HistoContents ( ) const
inlineinherited

Definition at line 235 of file TFCS2DFunctionTemplateHistogram.h.

235 {
236 return m_HistoContents;
237 };

◆ get_nbins()

size_t TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::get_nbins ( ) const
inlineinherited

return number of bins

Definition at line 46 of file TFCS2DFunctionTemplateHistogram.h.

46{ return m_HistoContents.get_nbins(); };

◆ Initialize()

void TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::Initialize ( const TH2 * hist)
inlineinherited

Initialize from root histogram.

Depending on the precision of the x- and y-axis, bins are merged if numerical identical

Definition at line 52 of file TFCS2DFunctionTemplateHistogram.h.

52 {
53 Int_t nbinsx = hist->GetNbinsX();
54 Int_t nbinsy = hist->GetNbinsY();
56 int first, last;
57 double integral =
59 printf("initializing 2D template...");
60 if (integral <= 0) {
61 set_nbins(0, 0);
62 } else {
64
65 // m_HistoBordersx.SetMinMax(hist->GetXaxis()->GetBinLowEdge(first+1),hist->GetXaxis()->GetBinUpEdge(last+1));
66 m_HistoBordersx.SetMinMax(hist->GetXaxis()->GetBinLowEdge(1),
67 hist->GetXaxis()->GetBinUpEdge(nbinsx));
68 m_HistoBordersy.SetMinMax(hist->GetYaxis()->GetBinLowEdge(1),
69 hist->GetYaxis()->GetBinUpEdge(nbinsy));
70 // Int_t ihist=0;
71 for (Int_t ibinx = 1; ibinx <= hist->GetNbinsX(); ++ibinx) {
72 m_HistoBordersx.SetBinLowEdge(
73 ibinx, hist->GetXaxis()->GetBinLowEdge(ibinx + 1));
74 // if(ihist>0)
75 // if(m_HistoBorders.GetBinLowEdge(ihist-1)==m_HistoBorders.GetBinLowEdge(ihist))
76 // { ATH_MSG_INFO( bin="<<ibin+1<<"
77 // x="<<hist->GetXaxis()->GetBinLowEdge(ibin+1)<<"
78 // fx="<<m_HistoBorders.GetBinLowEdge(ihist);
79 // --ihist;
80 // ATH_MSG_INFO(" bin="<<ibin <<"
81 // x="<<hist->GetXaxis()->GetBinLowEdge(ibin )<<"
82 // fx="<<m_HistoBorders.GetBinLowEdge(ihist));
83 // }
84 } // for
85 for (Int_t ibiny = 1; ibiny <= hist->GetNbinsY(); ++ibiny) {
86 m_HistoBordersy.SetBinLowEdge(
87 ibiny, hist->GetYaxis()->GetBinLowEdge(ibiny + 1));
88 // if(ihist>0)
89 // if(m_HistoBorders.GetBinLowEdge(ihist-1)==m_HistoBorders.GetBinLowEdge(ihist))
90 // { ATH_MSG_INFO("Skip bin="<<ibin+1<<"
91 // x="<<hist->GetXaxis()->GetBinLowEdge(ibin+1)<<"
92 // fx="<<m_HistoBorders.GetBinLowEdge(ihist));
93 // --ihist;
94 // ATH_MSG_INFO(" bin="<<ibin <<"
95 // x="<<hist->GetXaxis()->GetBinLowEdge(ibin )<<"
96 // fx="<<m_HistoBorders.GetBinLowEdge(ihist));
97 // }
98 } // for
99
100 for (Int_t ibinx = 1; ibinx <= hist->GetNbinsX(); ++ibinx)
101 for (Int_t ibiny = 1; ibiny <= hist->GetNbinsY(); ++ibiny) {
102 int globalbin = (ibinx - 1) * hist->GetNbinsY() + ibiny - 1;
103 m_HistoContents.set_fraction(
105 // if(ihist>0)
106 // if(m_HistoContents.get_fraction(ihist-1)==m_HistoContents.get_fraction(ihist))
107 // {
108 // ATH_MSG_INFO("Skip fbin="<<ihist<<"
109 // fx="<<m_HistoBorders.GetBinLowEdge(ihist)<<"
110 // frac="<<m_HistoContents.get_fraction(ihist));
111 // --ihist;
112 // ATH_MSG_INFO(" fbin="<<ihist<<"
113 // fx="<<m_HistoBorders.GetBinLowEdge(ihist)<<"
114 // frac="<<m_HistoContents.get_fraction(ihist));
115 // }
116
117 // ATH_MSG_INFO("bin="<<ibin+1<<"
118 // fbin="<<ihist<<"/"<<m_HistoBorders.get_nbins()<<"
119 // x=["<<hist->GetXaxis()->GetBinLowEdge(ibin+1)<<","<<hist->GetXaxis()->GetBinUpEdge(ibin+1)<<"]
120 // fx="<<m_HistoBorders.GetBinLowEdge(ihist)<<"
121 // int="<<temp_HistoContents[ibin]/integral<<"
122 // frac="<<m_HistoContents.get_fraction(ihist));
123
124 // ++ihist;
125 }
126 // if(ihist!=nbins) {
127 // set_nbins(ihist);
128 // m_HistoBorders.SetMinMax(hist->GetXaxis()->GetBinLowEdge(first+1),hist->GetXaxis()->GetBinUpEdge(last+1));
129 // }
130 } // for ibinx
131 } // for ibiny
static double CheckAndIntegrate2DHistogram(const TH2 *hist, std::vector< double > &integral_vec, int &first, int &last)

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

std::size_t TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::MemorySize ( ) const
inlinevirtualinherited

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

Reimplemented from TFCSFunction.

Definition at line 36 of file TFCS2DFunctionTemplateHistogram.h.

◆ MemorySizeArray()

std::size_t TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::MemorySizeArray ( ) const
inlineinherited

Definition at line 31 of file TFCS2DFunctionTemplateHistogram.h.

31 {
32 return m_HistoBordersx.MemorySizeArray() +
33 m_HistoBordersy.MemorySizeArray() +
34 m_HistoContents.MemorySizeArray();
35 };

◆ msg() [1/2]

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

Return a stream for sending messages directly (no decoration)

Definition at line 194 of file MLogging.h.

231 {
232 MsgStream *ms = m_msg_tls.get();
233 if (!ms) {
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 197 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 191 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.

Definition at line 20 of file TFCS2DFunction.h.

20{ return 2; };

◆ rnd_to_fct() [1/2]

( float value[],
const float rnd[] ) const
virtualinherited

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

Reimplemented from TFCS2DFunction.

◆ rnd_to_fct() [2/2]

template<typename Txvec, typename Tyvec, typename Tz, typename Trandom = float>
virtual void TFCS2DFunctionTemplateInterpolationExpHistogram< Txvec, Tyvec, Tz, Trandom >::rnd_to_fct ( float & valuex,
float & valuey,
float rnd,
float rnd2 ) const
inlinevirtual

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

An exponential interpolation is done within each bin

Implements TFCS2DFunction.

Definition at line 36 of file TFCS2DFunctionTemplateInterpolationExpHistogram.h.

37 {
38 size_t nbins = get_nbins();
39 if (nbins == 0) {
40 valuex = 0.0;
41 valuey = 0.0;
42 return;
43 }
45 size_t ibin = m_HistoContents.get_bin(rnd, residual_rnd);
46
47 Trandom frac = m_HistoContents.get_fraction(ibin);
48
49 size_t ibiny =
51 .get_nbins(); // printf("%d ", m_HistoBordersy.get_nbins() );
52 size_t ibinx = ibin / m_HistoBordersy.get_nbins();
53 // size_t nbinsx = m_HistoBordersx.get_nbins();
54 size_t nbinsy = m_HistoBordersy.get_nbins();
55
56 Trandom dfrac = 0.0;
57 auto l = m_HistoBordersy.GetBinLength(ibiny);
58 Trandom dfracprev = 0.0;
59 Trandom ldfrac = 0.0;
60 auto lprev = l;
61 if (ibiny > 0) {
62 Trandom fracprev = m_HistoContents.get_fraction(ibin - 1);
64 if (ibiny > 1) {
65 dfracprev = fracprev - m_HistoContents.get_fraction(ibin - 2);
66 } else {
68 if (ibinx > 0)
69 dfracprev -= m_HistoContents.get_fraction(ibin - 2);
70 }
71 lprev = m_HistoBordersy.GetBinLength(ibiny - 1);
72 } else {
73 dfrac = frac;
74 if (ibinx > 0)
75 dfrac -= m_HistoContents.get_fraction(ibin - 1);
77 }
78
79 if (dfrac > 0.0 && dfracprev > 0.0) {
81 }
82
83 Trandom dfracnext = 0.0;
84 Trandom ldfracnext = 0.0;
85 auto lnext = l;
86 if (ibiny < nbinsy - 1) {
87 dfracnext = m_HistoContents.get_fraction(ibin + 1) - frac;
88 lnext = m_HistoBordersy.GetBinLength(ibiny + 1);
89 } else {
91 }
92
93 if (dfrac > 0.0 && dfracnext > 0.0) {
95 }
96
97 Trandom beta = 0.0, betaprev = 0.0, betanext = 0.0;
98 betanext = ldfracnext / (lnext + l) / 0.5;
99 betaprev = ldfrac / (lprev + l) / 0.5;
100 beta = 0.5 * (betaprev + betanext);
101 // printf("betaprev=%13.5e betanext=%13.5e beta=%13.5e\n", betaprev,
102 // betanext, beta); printf("l=%13.5e lnext=%13.5e\n", l, lnext);
103 // printf("log=%13.5e lognext=%13.5e logprev=%13.5e\n", log(dfrac/l),
104 // log(dfracnext/lnext), log(dfracprev/lprev) ); printf("ldfrac=%13.5e
105 // ldfracnext=%13.5e\n", ldfrac, ldfracnext );
106
107 valuey = m_HistoBordersy.position_exp(ibiny, beta, residual_rnd);
108 valuex = m_HistoBordersx.position(ibinx, rnd2);
109 }

◆ set_nbins()

void TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::set_nbins ( size_t nbinsx,
size_t nbinsy )
inlineinherited

set number of bins

Definition at line 39 of file TFCS2DFunctionTemplateHistogram.h.

39 {
40 m_HistoBordersx.set_nbins(nbinsx);
41 m_HistoBordersy.set_nbins(nbinsy);
42 m_HistoContents.set_nbins(nbinsx * nbinsy);
43 };

◆ setLevel()

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

Update outputlevel.

Definition at line 203 of file MLogging.cxx.

105 {
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 207 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('/');
122 int trim_point = path_len;
123 int total_len = file.length();
127 const char *LevelNames[MSG::NUM_LEVELS] = {
128 "NIL", "VERBOSE", "DEBUG", "INFO", "WARNING", "ERROR", "FATAL", "ALWAYS"};
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_HistoBordersx

Txvec TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::m_HistoBordersx
protectedinherited

Definition at line 243 of file TFCS2DFunctionTemplateHistogram.h.

◆ m_HistoBordersy

Tyvec TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::m_HistoBordersy
protectedinherited

Definition at line 244 of file TFCS2DFunctionTemplateHistogram.h.

◆ m_HistoContents

TFCS1DFunction_HistogramContent<Tz, float> TFCS2DFunctionTemplateHistogram< Txvec, Tyvec, Tz, float >::m_HistoContents
protectedinherited

Definition at line 245 of file TFCS2DFunctionTemplateHistogram.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 file: