FairShip
Loading...
Searching...
No Matches
EventHistogram.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5#ifndef SHIPDATA_EVENTHISTOGRAM_H_
6#define SHIPDATA_EVENTHISTOGRAM_H_
7
8#include <memory>
9#include <vector>
10
11#include "Rtypes.h"
12#include "TDirectory.h"
13#include "TH1D.h"
14#include "TH2D.h"
15#include "TMatrixDSym.h"
16
51 public:
54 EventHistogram(const char* name, const char* title, Int_t nbins,
55 Double_t xlow, Double_t xup, Bool_t covariance = kFALSE,
56 Int_t nReplicas = 0);
57 EventHistogram(const char* name, const char* title, Int_t nbins,
58 const Double_t* edges, Bool_t covariance = kFALSE,
59 Int_t nReplicas = 0);
61
64
66 void Fill(Double_t x, Double_t w = 1.);
69 void EndEvent(ULong64_t eventKey = 0);
71 void AddEmptyEvents(Long64_t n);
75 void Add(const EventHistogram& other);
76
77 Long64_t GetNEvents() const { return fNEvents; }
78 Bool_t HasOpenEvent() const { return !fTouched.empty(); }
79
81 TH1D* MakeResult(const char* name = nullptr) const;
83 TH1D* MakeNaive(const char* name = nullptr) const;
86 TH1D* MakeNeff(const char* name = nullptr) const;
89 TMatrixDSym GetCovariance() const;
92 std::vector<Double_t> GetBootstrapErrors() const;
93
97 void Write(TDirectory* dir = gDirectory) const;
98 static std::unique_ptr<EventHistogram> Read(TDirectory* dir,
99 const char* name);
100
101 static ULong64_t MakeEventKey(ULong64_t run, ULong64_t event) {
102 return (run << 32) ^ event;
103 }
104
106 static Int_t ReplicaWeight(ULong64_t key, Int_t replica);
107
108 private:
109 EventHistogram() = default;
110 void Init(Bool_t covariance, Int_t nReplicas);
111 void InitEventBuffers();
112 void CheckClosed(const char* where) const;
113 TH1D* MakePerEvent(const char* name, const char* suffix) const;
114
115 std::unique_ptr<TH1D> fSum;
116 std::unique_ptr<TH1D> fNaive;
117 std::unique_ptr<TH2D> fCov;
118 std::unique_ptr<TH2D> fBoot;
119 std::vector<Double_t> fCurrent;
120 std::vector<Int_t> fTouched;
121 std::vector<bool> fIsTouched;
122 Long64_t fNEvents = 0;
123};
124
125#endif // SHIPDATA_EVENTHISTOGRAM_H_
EventHistogram(const EventHistogram &)=delete
std::vector< bool > fIsTouched
per bin: listed in fTouched
TH1D * MakeNeff(const char *name=nullptr) const
EventHistogram()=default
void Fill(Double_t x, Double_t w=1.)
Add one branch of the current event.
std::unique_ptr< TH2D > fCov
optional: sum t_a t_b
Long64_t GetNEvents() const
TH1D * MakePerEvent(const char *name, const char *suffix) const
void Init(Bool_t covariance, Int_t nReplicas)
static std::unique_ptr< EventHistogram > Read(TDirectory *dir, const char *name)
static Int_t ReplicaWeight(ULong64_t key, Int_t replica)
TH1D * MakeResult(const char *name=nullptr) const
Contents per generated event with event-level errors.
std::unique_ptr< TH1D > fSum
contents sum t, sumw2 sum t^2
void AddEmptyEvents(Long64_t n)
Generated events that left no entry still count in the normalisation.
std::unique_ptr< TH2D > fBoot
optional: (bin, replica) sum r t
EventHistogram(const char *name, const char *title, Int_t nbins, Double_t xlow, Double_t xup, Bool_t covariance=kFALSE, Int_t nReplicas=0)
void EndEvent(ULong64_t eventKey=0)
void Add(const EventHistogram &other)
std::vector< Double_t > fCurrent
t_b of the open event, incl. flows
TH1D * MakeNaive(const char *name=nullptr) const
Same contents with sqrt(sum w^2)/N errors, for comparison only.
std::unique_ptr< TH1D > fNaive
contents sum w, sumw2 sum w^2
Bool_t HasOpenEvent() const
EventHistogram & operator=(const EventHistogram &)=delete
void CheckClosed(const char *where) const
TMatrixDSym GetCovariance() const
std::vector< Double_t > GetBootstrapErrors() const
std::vector< Int_t > fTouched
bins filled in the open event
void Write(TDirectory *dir=gDirectory) const
static ULong64_t MakeEventKey(ULong64_t run, ULong64_t event)