Belle II Software development
HistDelta Class Reference

Class to keep track of delta histograms. More...

#include <HistDelta.h>

Public Types

enum  EDeltaType {
  c_Disabled = 0 ,
  c_Entries = 1 ,
  c_Underflow = 2 ,
  c_Events = 3
}
 enum definition for delta algo Disabled: nothing Entries: use nr histogram entries Underflow: use entries in histogram underflow bin Events: use nr processed events from framework (but: unreliable for normalization as the number of events for this specific histogram may differ) More...
 

Public Member Functions

 HistDelta (EDeltaType t=c_Disabled, int p=0, unsigned int a=0)
 Constructor.
 
 ~HistDelta ()
 Destructor.
 
void set (EDeltaType t, int p, unsigned int a)
 Parameter setter.
 
void setNotUpdated (void)
 Set not-updated yet status.
 
void update (const TH1 *hist)
 Check if update of delta histogram is necessary.
 
void reset (void)
 Reset histogram and deltas, not the parameters.
 
TH1 * getDelta (unsigned int n=0, bool onlyIfUpdated=true) const
 Get Delta Histogram.
 

Public Attributes

EDeltaType m_type {c_Disabled}
 type of delta algo
 
int m_parameter {0}
 parameter depending on algo, e.g.
 
unsigned int m_amountDeltas {}
 amount of past histograms, at least 1
 
std::unique_ptr< TH1 > m_lastHist {nullptr}
 Pointer to last histogram state for check.
 
int m_lastValue {0}
 last value for comparison, depending on type
 
std::vector< std::unique_ptr< TH1 > > m_deltaHists
 vector of histograms (max m_amountDeltas)
 
bool m_updated {false}
 if any delta was updated in this event
 

Detailed Description

Class to keep track of delta histograms.

Definition at line 23 of file HistDelta.h.

Member Enumeration Documentation

◆ EDeltaType

enum EDeltaType

enum definition for delta algo Disabled: nothing Entries: use nr histogram entries Underflow: use entries in histogram underflow bin Events: use nr processed events from framework (but: unreliable for normalization as the number of events for this specific histogram may differ)

Definition at line 32 of file HistDelta.h.

32{ c_Disabled = 0, c_Entries = 1, c_Underflow = 2, c_Events = 3};

Constructor & Destructor Documentation

◆ HistDelta()

HistDelta ( EDeltaType  t = c_Disabled,
int  p = 0,
unsigned int  a = 0 
)

Constructor.

Parameters
ttype
pparameter for type
aamount of deletas in the past

Definition at line 15 of file HistDelta.cc.

16{
17 m_type = t;
18 m_parameter = p;
20 m_lastHist = nullptr; // implied
21 m_lastValue = 0; // implied
22}
EDeltaType m_type
type of delta algo
Definition: HistDelta.h:33
std::unique_ptr< TH1 > m_lastHist
Pointer to last histogram state for check.
Definition: HistDelta.h:36
int m_lastValue
last value for comparison, depending on type
Definition: HistDelta.h:37
unsigned int m_amountDeltas
amount of past histograms, at least 1
Definition: HistDelta.h:35
int m_parameter
parameter depending on algo, e.g.
Definition: HistDelta.h:34

◆ ~HistDelta()

~HistDelta ( )

Destructor.

Definition at line 24 of file HistDelta.cc.

25{
26 m_lastHist = nullptr;
27 m_deltaHists.clear();
28}
std::vector< std::unique_ptr< TH1 > > m_deltaHists
vector of histograms (max m_amountDeltas)
Definition: HistDelta.h:38

Member Function Documentation

◆ getDelta()

TH1 * getDelta ( unsigned int  n = 0,
bool  onlyIfUpdated = true 
) const

Get Delta Histogram.

Parameters
nnumber of delta into the past, 0 is most recent one
onlyIfUpdatedreq only updated deltas, return nullptr otherwise
Returns
Found histogram or nullptr

Definition at line 107 of file HistDelta.cc.

108{
109 if (onlyIfUpdated && !m_updated) return nullptr;// not updated, but requested
110 if (n >= m_deltaHists.size()) return nullptr;
111 return m_deltaHists.at(n).get();
112}
bool m_updated
if any delta was updated in this event
Definition: HistDelta.h:39

◆ reset()

void reset ( void  )

Reset histogram and deltas, not the parameters.

Definition at line 100 of file HistDelta.cc.

101{
102 m_deltaHists.clear();
103 if (m_lastHist) m_lastHist->Reset();
104 m_lastValue = 0;
105}

◆ set()

void set ( EDeltaType  t,
int  p,
unsigned int  a 
)

Parameter setter.

Parameters
ttype
pparameter for type
aamount of deltas in the past

Definition at line 30 of file HistDelta.cc.

31{
32 m_type = t;
33 m_parameter = p;
35 m_lastHist = nullptr;
36 m_lastValue = 0;
37 m_deltaHists.clear();
38}

◆ setNotUpdated()

void setNotUpdated ( void  )
inline

Set not-updated yet status.

Definition at line 62 of file HistDelta.h.

62{m_updated = false;};

◆ update()

void update ( const TH1 *  hist)

Check if update of delta histogram is necessary.

Parameters
histpointer to histogram

else { not (yet) enough data for update special case of initial sampling is not covered in this code -> leave it up to the user code e.g. if getDelta(0) returns a nullptr, the user code writer should decide if it is useful to use the basic histogram }

Definition at line 40 of file HistDelta.cc.

41{
42 m_updated = false;
43 if (currentHist == nullptr) return; // this won't make sense
44 gROOT->cd(); // make sure we dont accidentally write the histograms to a open file
45 // cover first update after start
46 if (m_lastHist == nullptr) {
47 m_lastHist = std::unique_ptr<TH1> ((TH1*)(currentHist->Clone()));
48 m_lastHist->SetName(TString(currentHist->GetName()) + "_last");
49 m_lastHist->Reset();
50 m_updated = true;
51 }
52 // now check if need to update m_deltaHists
53 bool need_update = false;
54 switch (m_type) {
55 case c_Entries:
56 // default case, look at the entries in the histogram
57 need_update = currentHist->GetEntries() - m_lastHist->GetEntries() >= m_parameter;
58 break;
59 case c_Underflow:
60 // here we misuse underflow as event counter in some histograms, e.g. PXD
61 need_update = currentHist->GetBinContent(0) - m_lastHist->GetBinContent(0) >= m_parameter;
62 break;
63 case c_Events:
64 // use event processed counter
66 if (need_update) m_lastValue = DQMHistAnalysisModule::getEventProcessed(); // update last value
67 break;
68 default:
69 // any unsupported types map to case 0(Disabled), and will disable delta for this hist
70 [[fallthrough]];
71 case c_Disabled:
72 break;
73 }
74
75 if (need_update) {
76 m_updated = true;
77 auto delta = (TH1*)currentHist->Clone();
78 delta->SetName(TString(delta->GetName()) + "_delta");
79 delta->Add(m_lastHist.get(), -1.);
80
81 // we use this as a fifo, but cannot use queue as we need the random access
82 // maybe use deque?
83 m_deltaHists.emplace(m_deltaHists.begin(), delta);
84 if (m_deltaHists.size() > m_amountDeltas) {
85 // remove (and delete) last element
86 m_deltaHists.erase(m_deltaHists.begin() + m_deltaHists.size() - 1);
87 }
88 m_lastHist->Reset();
89 m_lastHist->Add(currentHist);
90 }
98}
static int getEventProcessed(void)
Get the number of processed events.

Member Data Documentation

◆ m_amountDeltas

unsigned int m_amountDeltas {}

amount of past histograms, at least 1

Definition at line 35 of file HistDelta.h.

◆ m_deltaHists

std::vector<std::unique_ptr<TH1> > m_deltaHists

vector of histograms (max m_amountDeltas)

Definition at line 38 of file HistDelta.h.

◆ m_lastHist

std::unique_ptr<TH1> m_lastHist {nullptr}

Pointer to last histogram state for check.

Definition at line 36 of file HistDelta.h.

◆ m_lastValue

int m_lastValue {0}

last value for comparison, depending on type

Definition at line 37 of file HistDelta.h.

◆ m_parameter

int m_parameter {0}

parameter depending on algo, e.g.

nr of entries or events

Definition at line 34 of file HistDelta.h.

◆ m_type

EDeltaType m_type {c_Disabled}

type of delta algo

Definition at line 33 of file HistDelta.h.

◆ m_updated

bool m_updated {false}

if any delta was updated in this event

Definition at line 39 of file HistDelta.h.


The documentation for this class was generated from the following files: