![]() |
FairShip
|
#include <EventHistogram.h>
Public Member Functions | |
| EventHistogram (const char *name, const char *title, Int_t nbins, Double_t xlow, Double_t xup, Bool_t covariance=kFALSE, Int_t nReplicas=0) | |
| EventHistogram (const char *name, const char *title, Int_t nbins, const Double_t *edges, Bool_t covariance=kFALSE, Int_t nReplicas=0) | |
| ~EventHistogram () | |
| EventHistogram (const EventHistogram &)=delete | |
| EventHistogram & | operator= (const EventHistogram &)=delete |
| void | Fill (Double_t x, Double_t w=1.) |
| Add one branch of the current event. | |
| void | EndEvent (ULong64_t eventKey=0) |
| void | AddEmptyEvents (Long64_t n) |
| Generated events that left no entry still count in the normalisation. | |
| void | Add (const EventHistogram &other) |
| Long64_t | GetNEvents () const |
| Bool_t | HasOpenEvent () const |
| TH1D * | MakeResult (const char *name=nullptr) const |
| Contents per generated event with event-level errors. | |
| TH1D * | MakeNaive (const char *name=nullptr) const |
| Same contents with sqrt(sum w^2)/N errors, for comparison only. | |
| TH1D * | MakeNeff (const char *name=nullptr) const |
| TMatrixDSym | GetCovariance () const |
| std::vector< Double_t > | GetBootstrapErrors () const |
| void | Write (TDirectory *dir=gDirectory) const |
Static Public Member Functions | |
| static std::unique_ptr< EventHistogram > | Read (TDirectory *dir, const char *name) |
| static ULong64_t | MakeEventKey (ULong64_t run, ULong64_t event) |
| static Int_t | ReplicaWeight (ULong64_t key, Int_t replica) |
Private Member Functions | |
| EventHistogram ()=default | |
| void | Init (Bool_t covariance, Int_t nReplicas) |
| void | InitEventBuffers () |
| void | CheckClosed (const char *where) const |
| TH1D * | MakePerEvent (const char *name, const char *suffix) const |
Private Attributes | |
| std::unique_ptr< TH1D > | fSum |
| contents sum t, sumw2 sum t^2 | |
| std::unique_ptr< TH1D > | fNaive |
| contents sum w, sumw2 sum w^2 | |
| std::unique_ptr< TH2D > | fCov |
| optional: sum t_a t_b | |
| std::unique_ptr< TH2D > | fBoot |
| optional: (bin, replica) sum r t | |
| std::vector< Double_t > | fCurrent |
| t_b of the open event, incl. flows | |
| std::vector< Int_t > | fTouched |
| bins filled in the open event | |
| std::vector< bool > | fIsTouched |
| per bin: listed in fTouched | |
| Long64_t | fNEvents = 0 |
Histogram with event-level uncertainties for weighted samples whose entries are correlated within an event, such as the split kaon/pion clones of exitHadronAbsorber.
Every branch of an event (clones, split decays, their secondaries) shares the history of the primary interaction, so the branches are not independent entries and sqrt(sum w^2) underestimates the error. The independent unit is the event: the weights of an event are summed per bin first,
t_eb = sum_{i in e, x_i in b} w_i,
and the per-event sums are treated as the observations. With N generated events (including those that left no entry), the bin content per event and its error are
mu_b = sum_e t_eb / N, sigma_b^2 = (sum_e t_eb^2 / N - mu_b^2) / (N - 1).
Usage:
EventHistogram h("p_mu", "muon momentum;p (GeV/c)", 40, 0., 400.); for each event: for each muon: h.Fill(p, w); h.EndEvent(EventHistogram::MakeEventKey(run, event)); h.AddEmptyEvents(nGenerated - nWritten); std::unique_ptr<TH1D> result(h.MakeResult());
Write() stores plain ROOT objects that hadd merges correctly: a TH1D whose contents are sum_e t_eb and whose sum of squared weights is sum_e t_eb^2, the same for sqrt(sum w^2) for comparison, optional covariance and bootstrap accumulators, and the number of events. Read() restores the accumulator from them.
Definition at line 50 of file EventHistogram.h.
| EventHistogram::EventHistogram | ( | const char * | name, |
| const char * | title, | ||
| Int_t | nbins, | ||
| Double_t | xlow, | ||
| Double_t | xup, | ||
| Bool_t | covariance = kFALSE, | ||
| Int_t | nReplicas = 0 ) |
| covariance | also accumulate sum_e t_ea t_eb for the covariance |
| nReplicas | number of Poisson bootstrap replicas (0 = none) |
Definition at line 48 of file EventHistogram.cxx.
| EventHistogram::EventHistogram | ( | const char * | name, |
| const char * | title, | ||
| Int_t | nbins, | ||
| const Double_t * | edges, | ||
| Bool_t | covariance = kFALSE, | ||
| Int_t | nReplicas = 0 ) |
Definition at line 55 of file EventHistogram.cxx.
|
default |
|
delete |
|
privatedefault |
| void EventHistogram::Add | ( | const EventHistogram & | other | ) |
Merge an accumulator filled with independent events and equal binning. Throws std::invalid_argument if binning, covariance or number of replicas differ; the target is then unchanged.
Definition at line 145 of file EventHistogram.cxx.
| void EventHistogram::AddEmptyEvents | ( | Long64_t | n | ) |
Generated events that left no entry still count in the normalisation.
Definition at line 143 of file EventHistogram.cxx.
|
private |
Definition at line 169 of file EventHistogram.cxx.
| void EventHistogram::EndEvent | ( | ULong64_t | eventKey = 0 | ) |
Close the current event. The key seeds the bootstrap replica weights; use MakeEventKey(run, event) so replicas agree across files and jobs.
Definition at line 104 of file EventHistogram.cxx.
| void EventHistogram::Fill | ( | Double_t | x, |
| Double_t | w = 1. ) |
Add one branch of the current event.
Definition at line 93 of file EventHistogram.cxx.
| std::vector< Double_t > EventHistogram::GetBootstrapErrors | ( | ) | const |
Spread of the bootstrap replicas, per generated event (in-range bins). Throws std::logic_error with fewer than two replicas.
Definition at line 247 of file EventHistogram.cxx.
| TMatrixDSym EventHistogram::GetCovariance | ( | ) | const |
Covariance of the per-event bin contents (in-range bins only). Throws std::logic_error if created without covariance.
Definition at line 227 of file EventHistogram.cxx.
|
inline |
Definition at line 77 of file EventHistogram.h.
|
inline |
Definition at line 78 of file EventHistogram.h.
|
private |
Definition at line 64 of file EventHistogram.cxx.
|
private |
Definition at line 88 of file EventHistogram.cxx.
|
inlinestatic |
Definition at line 101 of file EventHistogram.h.
| TH1D * EventHistogram::MakeNaive | ( | const char * | name = nullptr | ) | const |
Same contents with sqrt(sum w^2)/N errors, for comparison only.
Definition at line 203 of file EventHistogram.cxx.
| TH1D * EventHistogram::MakeNeff | ( | const char * | name = nullptr | ) | const |
Effective number of independent events per bin, (sum t)^2 / sum t^2. Below about 20 the error estimate itself becomes unreliable.
Definition at line 216 of file EventHistogram.cxx.
|
private |
Definition at line 177 of file EventHistogram.cxx.
| TH1D * EventHistogram::MakeResult | ( | const char * | name = nullptr | ) | const |
Contents per generated event with event-level errors.
Definition at line 186 of file EventHistogram.cxx.
|
delete |
|
static |
Definition at line 289 of file EventHistogram.cxx.
|
static |
Poisson(1) replica weight, a pure function of key and replica so that the Python implementation (event_histogram.py) gives the same replicas.
Definition at line 323 of file EventHistogram.cxx.
| void EventHistogram::Write | ( | TDirectory * | dir = gDirectory | ) | const |
Writing or reading results with an open event throws std::logic_error. Read() returns nullptr if the objects are missing or hold different numbers of events, e.g. after hadd of files with different settings.
Definition at line 271 of file EventHistogram.cxx.
|
private |
optional: (bin, replica) sum r t
Definition at line 118 of file EventHistogram.h.
|
private |
optional: sum t_a t_b
Definition at line 117 of file EventHistogram.h.
|
private |
t_b of the open event, incl. flows
Definition at line 119 of file EventHistogram.h.
|
private |
per bin: listed in fTouched
Definition at line 121 of file EventHistogram.h.
|
private |
contents sum w, sumw2 sum w^2
Definition at line 116 of file EventHistogram.h.
|
private |
Definition at line 122 of file EventHistogram.h.
|
private |
contents sum t, sumw2 sum t^2
Definition at line 115 of file EventHistogram.h.
|
private |
bins filled in the open event
Definition at line 120 of file EventHistogram.h.