Jpp test-rotations-old-533-g2bdbdb559
the software that should make you happy
Loading...
Searching...
No Matches
JASTRONOMY::JPseudoExperiment Struct Reference

Pseudo experiment using CDF for combined generation and likelihood evaluation. More...

#include <JPseudoExperiment.hh>

Inheritance diagram for JASTRONOMY::JPseudoExperiment:
JASTRONOMY::JPseudoExperiment_t JASTRONOMY::JExperiment

Classes

struct  cdf_type
 Auxiliary data structure for CDF. More...
 
struct  parameters_type
 Nuisance parameters. More...
 

Public Types

typedef JAspera::fit_type fit_type
 fit type
 

Public Member Functions

 JPseudoExperiment ()
 Default constructor.
 
template<class H_t >
 JPseudoExperiment (const H_t &hs, const H_t &hb)
 Constructor.
 
template<class H_t >
 JPseudoExperiment (const H_t &hS, const H_t &hB, const H_t &hs, const H_t &hb)
 Constructor.
 
void add (const TObject *ps, const TObject *pb)
 Add objects with PDFs of signal and background.
 
void add (const TObject *pS, const TObject *pB, const TObject *ps, const TObject *pb)
 Add objects with PDFs of signal and background.
 
void add (const TH1 &hs, const TH1 &hb)
 Add histograms with PDFs of signal and background.
 
void add (const TH1 &hS, const TH1 &hB, const TH1 &hs, const TH1 &hb)
 Add histograms with PDFs of signal and background.
 
void add (const TH2 &hs, const TH2 &hb)
 Add histograms with PDFs of signal and background.
 
void add (const TH2 &hS, const TH2 &hB, const TH2 &hs, const TH2 &hb)
 Add histograms with PDFs of signal and background.
 
void add (const TH3 &hs, const TH3 &hb)
 Add histograms with PDFs of signal and background.
 
void add (const TH3 &hS, const TH3 &hB, const TH3 &hs, const TH3 &hb)
 Add histograms with PDFs of signal and background.
 
void add (const double s, const double b)
 Add signal and background.
 
void add (const double S, const double B, const double s, const double b)
 Add signal and background.
 
double getSignal () const
 Get total signal.
 
double getBackground () const
 Get total background.
 
void set (const double fS, const double fB)
 Set scaling factors of signal and background strengths.
 
virtual JAsperagetAspera () override
 Get fit method.
 
virtual stats_type run (JAspera &out) const
 
result_type operator() ()
 Generate pseudo experiment and fit signal strength.
 
void operator() (std::vector< result_type > &storage)
 Run pseudo experiments using given storage.
 
template<class T , class JValue_t >
void operator() (JValue_t result_type::*pm, std::vector< T > &storage)
 Run pseudo experiments using given storage.
 
template<class T , class JValue_t >
void operator() (JValue_t JAspera::fit_type::*pm, std::vector< T > &storage)
 Run pseudo experiments using given storage.
 

Static Public Member Functions

static bool check (const double s, const double b)
 Check validity of signal and background.
 
static bool check (const TAxis *ha, const TAxis *hb)
 Check histogram bins.
 
static bool check (const TH1 &ha, const TH1 &hb)
 Check histogram bins.
 
static bool check (const TH2 &ha, const TH2 &hb)
 Check histogram bins.
 
static bool check (const TH3 &ha, const TH3 &hb)
 Check histogram bins.
 

Public Attributes

struct JASTRONOMY::JPseudoExperiment::parameters_type nuisance
 

Protected Member Functions

template<class H_t >
bool add (const TObject *ps, const TObject *pb)
 Add objects with PDF of signal and background.
 
template<class H_t >
bool add (const TObject *pS, const TObject *pB, const TObject *ps, const TObject *pb)
 Add objects with PDF of signal and background.
 

Protected Attributes

cdf_type cs
 CDF of signal.
 
cdf_type cb
 CDF of background.
 
JAspera aspera
 pre-computed N/S values
 
double fs = 1.0
 scaling factor signal strength
 
double fb = 1.0
 scaling factor background strength
 
JAspera fit
 fit
 

Detailed Description

Pseudo experiment using CDF for combined generation and likelihood evaluation.

Definition at line 151 of file JPseudoExperiment.hh.

Member Typedef Documentation

◆ fit_type

Constructor & Destructor Documentation

◆ JPseudoExperiment() [1/3]

JASTRONOMY::JPseudoExperiment::JPseudoExperiment ( )
inline

Default constructor.

Definition at line 157 of file JPseudoExperiment.hh.

158 {}

◆ JPseudoExperiment() [2/3]

template<class H_t >
JASTRONOMY::JPseudoExperiment::JPseudoExperiment ( const H_t & hs,
const H_t & hb )
inline

Constructor.

Parameters
hshistogram with PDF of signal
hbhistogram with PDF of background

Definition at line 168 of file JPseudoExperiment.hh.

170 {
171 add(hs, hb);
172 }
void add(const TObject *ps, const TObject *pb)
Add objects with PDFs of signal and background.

◆ JPseudoExperiment() [3/3]

template<class H_t >
JASTRONOMY::JPseudoExperiment::JPseudoExperiment ( const H_t & hS,
const H_t & hB,
const H_t & hs,
const H_t & hb )
inline

Constructor.

Parameters
hShistogram with PDF for generation of signal
hBhistogram with PDF for generation of background
hshistogram with PDF for evaluation of signal
hbhistogram with PDF for evaluation of background

Definition at line 184 of file JPseudoExperiment.hh.

188 {
189 add(hS, hB, hs, hb);
190 }

Member Function Documentation

◆ add() [1/12]

void JASTRONOMY::JPseudoExperiment::add ( const TObject * ps,
const TObject * pb )
inline

Add objects with PDFs of signal and background.

Parameters
pspointer to object with PDF of signal
pbpointer to object with PDF of background

Definition at line 199 of file JPseudoExperiment.hh.

201 {
202 if (add<TH3>(ps, pb)) { return; }
203 if (add<TH2>(ps, pb)) { return; }
204 if (add<TH1>(ps, pb)) { return; }
205 }

◆ add() [2/12]

void JASTRONOMY::JPseudoExperiment::add ( const TObject * pS,
const TObject * pB,
const TObject * ps,
const TObject * pb )
inline

Add objects with PDFs of signal and background.

Parameters
pSpointer to object with PDF for generation of signal
pBpointer to object with PDF for generation of background
pspointer to object with PDF for evaluation of signal
pbpointer to object with PDF for evaluation of background

Definition at line 216 of file JPseudoExperiment.hh.

220 {
221 if (add<TH3>(pS, pB, ps, pb)) { return; }
222 if (add<TH2>(pS, pB, ps, pb)) { return; }
223 if (add<TH1>(pS, pB, ps, pb)) { return; }
224 }

◆ add() [3/12]

void JASTRONOMY::JPseudoExperiment::add ( const TH1 & hs,
const TH1 & hb )
inline

Add histograms with PDFs of signal and background.

Parameters
hshistogram with PDF of signal
hbhistogram with PDF of background

Definition at line 233 of file JPseudoExperiment.hh.

235 {
236 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
237 add(hs.GetBinContent(ix),
238 hb.GetBinContent(ix));
239 }
240 }

◆ add() [4/12]

void JASTRONOMY::JPseudoExperiment::add ( const TH1 & hS,
const TH1 & hB,
const TH1 & hs,
const TH1 & hb )
inline

Add histograms with PDFs of signal and background.

Parameters
hShistogram with PDF for generation of signal
hBhistogram with PDF for generation of background
hshistogram with PDF for evaluation of signal
hbhistogram with PDF for evaluation of background

Definition at line 251 of file JPseudoExperiment.hh.

255 {
256 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
257 add(hS.GetBinContent(ix),
258 hB.GetBinContent(ix),
259 hs.GetBinContent(ix),
260 hb.GetBinContent(ix));
261 }
262 }

◆ add() [5/12]

void JASTRONOMY::JPseudoExperiment::add ( const TH2 & hs,
const TH2 & hb )
inline

Add histograms with PDFs of signal and background.

Parameters
hshistogram with PDF of signal
hbhistogram with PDF of background

Definition at line 271 of file JPseudoExperiment.hh.

273 {
274 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
275 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
276 add(hs.GetBinContent(ix, iy),
277 hb.GetBinContent(ix, iy));
278 }
279 }
280 }

◆ add() [6/12]

void JASTRONOMY::JPseudoExperiment::add ( const TH2 & hS,
const TH2 & hB,
const TH2 & hs,
const TH2 & hb )
inline

Add histograms with PDFs of signal and background.

Parameters
hShistogram with PDF for generation of signal
hBhistogram with PDF for generation of background
hshistogram with PDF for evaluation of signal
hbhistogram with PDF for evaluation of background

Definition at line 291 of file JPseudoExperiment.hh.

295 {
296 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
297 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
298 add(hS.GetBinContent(ix, iy),
299 hB.GetBinContent(ix, iy),
300 hs.GetBinContent(ix, iy),
301 hb.GetBinContent(ix, iy));
302 }
303 }
304 }

◆ add() [7/12]

void JASTRONOMY::JPseudoExperiment::add ( const TH3 & hs,
const TH3 & hb )
inline

Add histograms with PDFs of signal and background.

Parameters
hshistogram with PDF of signal
hbhistogram with PDF of background

Definition at line 313 of file JPseudoExperiment.hh.

315 {
316 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
317 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
318 for (Int_t iz = 1; iz <= hs.GetZaxis()->GetNbins(); ++iz) {
319 add(hs.GetBinContent(ix, iy, iz),
320 hb.GetBinContent(ix, iy, iz));
321 }
322 }
323 }
324 }

◆ add() [8/12]

void JASTRONOMY::JPseudoExperiment::add ( const TH3 & hS,
const TH3 & hB,
const TH3 & hs,
const TH3 & hb )
inline

Add histograms with PDFs of signal and background.

Parameters
hShistogram with PDF for generation of signal
hBhistogram with PDF for generation of background
hshistogram with PDF for evaluation of signal
hbhistogram with PDF for evaluation of background

Definition at line 335 of file JPseudoExperiment.hh.

339 {
340 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
341 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
342 for (Int_t iz = 1; iz <= hs.GetZaxis()->GetNbins(); ++iz) {
343 add(hS.GetBinContent(ix, iy, iz),
344 hB.GetBinContent(ix, iy, iz),
345 hs.GetBinContent(ix, iy, iz),
346 hb.GetBinContent(ix, iy, iz));
347 }
348 }
349 }
350 }

◆ add() [9/12]

void JASTRONOMY::JPseudoExperiment::add ( const double s,
const double b )
inline

Add signal and background.

Parameters
ssignal
bbackground

Definition at line 359 of file JPseudoExperiment.hh.

361 {
362 if (check(s, b)) {
363
364 cs.put(s);
365 cb.put(b);
366
367 aspera.put(s, b);
368 }
369 }
void put(const double s, const double b)
Put signal and background to list of pre-computed N/S values.
Definition JAspera.hh:44
static bool check(const double s, const double b)
Check validity of signal and background.
void put(const double x)
Put given value.
cdf_type cb
CDF of background.
JAspera aspera
pre-computed N/S values

◆ add() [10/12]

void JASTRONOMY::JPseudoExperiment::add ( const double S,
const double B,
const double s,
const double b )
inline

Add signal and background.

Parameters
Ssignal for generation
Bbackground for generation
ssignal for evaluation
bbackground for evaluation

Definition at line 380 of file JPseudoExperiment.hh.

384 {
385 if (//check(S, B) &&
386 check(s, b)) {
387
388 cs.put(S);
389 cb.put(B);
390
391 aspera.put(s, b);
392 }
393 }

◆ getSignal()

double JASTRONOMY::JPseudoExperiment::getSignal ( ) const
inline

Get total signal.

Returns
signal

Definition at line 401 of file JPseudoExperiment.hh.

402 {
403 return cs.back() * this->fs;
404 }
double fs
scaling factor signal strength

◆ getBackground()

double JASTRONOMY::JPseudoExperiment::getBackground ( ) const
inline

Get total background.

Returns
background

Definition at line 412 of file JPseudoExperiment.hh.

413 {
414 return cb.back() * this->fb;
415 }
double fb
scaling factor background strength

◆ set()

void JASTRONOMY::JPseudoExperiment::set ( const double fS,
const double fB )
inline

Set scaling factors of signal and background strengths.

Parameters
fSsignal strength
fBbackground strength

Definition at line 424 of file JPseudoExperiment.hh.

425 {
426 for (auto& i : aspera) {
427 i *= fB / this->fb;
428 }
429
430 this->fs = fS;
431 this->fb = fB;
432 }

◆ getAspera()

virtual JAspera & JASTRONOMY::JPseudoExperiment::getAspera ( )
inlineoverridevirtual

Get fit method.

Returns
fit

Implements JASTRONOMY::JPseudoExperiment_t.

Definition at line 440 of file JPseudoExperiment.hh.

441 {
442 return this->fit;
443 }

◆ run()

virtual stats_type JASTRONOMY::JPseudoExperiment::run ( JAspera & out) const
inlinevirtual

Implements JASTRONOMY::JPseudoExperiment_t.

Definition at line 452 of file JPseudoExperiment.hh.

453 {
454 out.addSignal(aspera.getSignal());
455
456 const size_t ns = gRandom->Poisson(getSignal() * nuisance.signal ->get()); // number of signal events
457 const size_t nb = gRandom->Poisson(getBackground() * nuisance.background->get()); // number of background events
458
459 for (size_t i = ns; i != 0; --i) { out.push_back(aspera[cs.get_index(gRandom->Rndm())]); } // store distributed signal events
460 for (size_t i = nb; i != 0; --i) { out.push_back(aspera[cb.get_index(gRandom->Rndm())]); } // store distributed background events
461
462 return { ns, nb };
463 }
double getSignal() const
Get total signal strength.
Definition JAspera.hh:198
size_t get_index(const double rv) const
Get index corresponding to given random value.
struct JASTRONOMY::JPseudoExperiment::parameters_type nuisance
double getSignal() const
Get total signal.
double getBackground() const
Get total background.

◆ add() [11/12]

template<class H_t >
bool JASTRONOMY::JPseudoExperiment::add ( const TObject * ps,
const TObject * pb )
inlineprotected

Add objects with PDF of signal and background.

Parameters
pspointer to object with PDF of signal
pbpointer to object with PDF of background
Returns
true if added; else false

Definition at line 512 of file JPseudoExperiment.hh.

514 {
515 if (dynamic_cast<const H_t*>(ps) != NULL &&
516 dynamic_cast<const H_t*>(pb) != NULL) {
517
518 const H_t& hs = dynamic_cast<const H_t&>(*ps);
519 const H_t& hb = dynamic_cast<const H_t&>(*pb);
520
521 if (check(hs, hb)) {
522
523 add(hs, hb);
524
525 return true;
526 }
527 }
528
529 return false;
530 }

◆ add() [12/12]

template<class H_t >
bool JASTRONOMY::JPseudoExperiment::add ( const TObject * pS,
const TObject * pB,
const TObject * ps,
const TObject * pb )
inlineprotected

Add objects with PDF of signal and background.

Parameters
pSpointer to object with PDF for generation of signal
pBpointer to object with PDF for generation of background
pspointer to object with PDF for evaluation of signal
pbpointer to object with PDF for evaluation of background
Returns
true if added; else false

Definition at line 543 of file JPseudoExperiment.hh.

547 {
548 if (dynamic_cast<const H_t*>(pS) != NULL &&
549 dynamic_cast<const H_t*>(pB) != NULL &&
550 dynamic_cast<const H_t*>(ps) != NULL &&
551 dynamic_cast<const H_t*>(pb) != NULL) {
552
553 const H_t& hS = dynamic_cast<const H_t&>(*pS);
554 const H_t& hB = dynamic_cast<const H_t&>(*pB);
555 const H_t& hs = dynamic_cast<const H_t&>(*ps);
556 const H_t& hb = dynamic_cast<const H_t&>(*pb);
557
558 if (check(hS, hB) && check(hB, hs) && check(hs, hb)) {
559
560 add(hS, hB, hs, hb);
561
562 return true;
563 }
564 }
565
566 return false;
567 }

◆ operator()() [1/4]

result_type JASTRONOMY::JPseudoExperiment_t::operator() ( )
inlineinherited

Generate pseudo experiment and fit signal strength.

Returns
result

Definition at line 93 of file JPseudoExperiment.hh.

94 {
95 JAspera& aspera = getAspera();
96
97 // reset
98
99 aspera.clear();
100 aspera.setSignal(0.0);
101
102 return { run(aspera), aspera() };
103 }
virtual JAspera & getAspera()=0
Get fit method.
virtual stats_type run(JAspera &out) const =0

◆ operator()() [2/4]

void JASTRONOMY::JPseudoExperiment_t::operator() ( std::vector< result_type > & storage)
inlineinherited

Run pseudo experiments using given storage.

Parameters
storagestorage

Definition at line 111 of file JPseudoExperiment.hh.

112 {
113 for (auto& i : storage) {
114 i = (*this)();
115 }
116 }

◆ operator()() [3/4]

template<class T , class JValue_t >
void JASTRONOMY::JPseudoExperiment_t::operator() ( JValue_t result_type::* pm,
std::vector< T > & storage )
inlineinherited

Run pseudo experiments using given storage.

Parameters
pmpointer to data member of result
storagestorage

Definition at line 126 of file JPseudoExperiment.hh.

127 {
128 for (auto& i : storage) {
129 i = (*this)().*pm;
130 }
131 }

◆ operator()() [4/4]

template<class T , class JValue_t >
void JASTRONOMY::JPseudoExperiment_t::operator() ( JValue_t JAspera::fit_type::* pm,
std::vector< T > & storage )
inlineinherited

Run pseudo experiments using given storage.

Parameters
pmpointer to data member of result
storagestorage

Definition at line 141 of file JPseudoExperiment.hh.

142 {
143 (*this)(static_cast<JValue_t result_type::*>(pm), storage);
144 }

◆ check() [1/5]

static bool JASTRONOMY::JExperiment::check ( const double s,
const double b )
inlinestaticinherited

Check validity of signal and background.

Parameters
ssignal
bbackground
Returns
true if signal and backgroud are valid; else false

Definition at line 34 of file JExperiment.hh.

35 {
36 return (s > 0.0 && b > 0.0);
37 }

◆ check() [2/5]

static bool JASTRONOMY::JExperiment::check ( const TAxis * ha,
const TAxis * hb )
inlinestaticinherited

Check histogram bins.

Parameters
hahistogram axis
hbhistogram axis
Returns
true if same binning; else false

Definition at line 47 of file JExperiment.hh.

48 {
49 return (ha->GetNbins() == hb->GetNbins() &&
50 ha->GetXmin() == hb->GetXmin() &&
51 ha->GetXmax() == hb->GetXmax());
52 }

◆ check() [3/5]

static bool JASTRONOMY::JExperiment::check ( const TH1 & ha,
const TH1 & hb )
inlinestaticinherited

Check histogram bins.

Parameters
hahistogram
hbhistogram
Returns
true if same binning; else false

Definition at line 61 of file JExperiment.hh.

62 {
63 return check(ha.GetXaxis(), hb.GetXaxis());
64 }

◆ check() [4/5]

static bool JASTRONOMY::JExperiment::check ( const TH2 & ha,
const TH2 & hb )
inlinestaticinherited

Check histogram bins.

Parameters
hahistogram
hbhistogram
Returns
true if same binning; else false

Definition at line 74 of file JExperiment.hh.

75 {
76 return (check(ha.GetXaxis(), hb.GetXaxis()) &&
77 check(ha.GetYaxis(), hb.GetYaxis()));
78 }

◆ check() [5/5]

static bool JASTRONOMY::JExperiment::check ( const TH3 & ha,
const TH3 & hb )
inlinestaticinherited

Check histogram bins.

Parameters
hahistogram
hbhistogram
Returns
true if same binning; else false

Definition at line 88 of file JExperiment.hh.

89 {
90 return (check(ha.GetXaxis(), hb.GetXaxis()) &&
91 check(ha.GetYaxis(), hb.GetYaxis()) &&
92 check(ha.GetZaxis(), hb.GetZaxis()));
93 }

Member Data Documentation

◆ nuisance

struct JASTRONOMY::JPseudoExperiment::parameters_type JASTRONOMY::JPseudoExperiment::nuisance

◆ cs

cdf_type JASTRONOMY::JPseudoExperiment::cs
protected

CDF of signal.

Definition at line 621 of file JPseudoExperiment.hh.

◆ cb

cdf_type JASTRONOMY::JPseudoExperiment::cb
protected

CDF of background.

Definition at line 622 of file JPseudoExperiment.hh.

◆ aspera

JAspera JASTRONOMY::JPseudoExperiment::aspera
protected

pre-computed N/S values

Definition at line 624 of file JPseudoExperiment.hh.

◆ fs

double JASTRONOMY::JPseudoExperiment::fs = 1.0
protected

scaling factor signal strength

Definition at line 626 of file JPseudoExperiment.hh.

◆ fb

double JASTRONOMY::JPseudoExperiment::fb = 1.0
protected

scaling factor background strength

Definition at line 627 of file JPseudoExperiment.hh.

◆ fit

JAspera JASTRONOMY::JPseudoExperiment::fit
protected

fit

Definition at line 629 of file JPseudoExperiment.hh.


The documentation for this struct was generated from the following file: