Belle II Software  release-05-02-19
TOPHitRateCounter.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <background/modules/BeamBkgHitRateMonitor/HitRateBase.h>
14 #include <framework/datastore/StoreArray.h>
15 #include <framework/database/DBObjPtr.h>
16 #include <top/dataobjects/TOPDigit.h>
17 #include <top/dbobjects/TOPCalChannelMask.h>
18 #include <TTree.h>
19 #include <TH1F.h>
20 #include <map>
21 
22 namespace Belle2 {
27  namespace Background {
28 
35  class TOPHitRateCounter: public HitRateBase {
36 
37  public:
38 
42  struct TreeStruct {
43  float slotRates[16] = {0};
44  float averageRate = 0;
45  int numEvents = 0;
46  bool valid = false;
51  void normalize()
52  {
53  if (numEvents == 0) return;
54  for (auto& slotRate : slotRates) slotRate /= numEvents;
56  }
57 
58  };
59 
65  TOPHitRateCounter(double timeOffset, double timeWindow):
66  m_timeOffset(timeOffset), m_timeWindow(timeWindow)
67  {}
68 
73  virtual void initialize(TTree* tree) override;
74 
78  virtual void clear() override;
79 
84  virtual void accumulate(unsigned timeStamp) override;
85 
90  virtual void normalize(unsigned timeStamp) override;
91 
92  private:
93 
97  void setActiveFractions();
98 
99  // class parameters: to be set via constructor or setters
100  double m_timeOffset = 0;
101  double m_timeWindow = 0;
103  // tree structure
106  // buffer
107  std::map<unsigned, TreeStruct> m_buffer;
109  // collections
112  // DB payloads
115  // control histograms: to check if time offset and window size are correctly set
116  TH1F* m_hits = 0;
117  TH1F* m_hitsInWindow = 0;
119  // other
120  double m_activeFractions[16] = {0};
121  double m_activeTotal = 0;
123  };
124 
125  } // Background namespace
127 } // Belle2 namespace
Belle2::Background::TOPHitRateCounter::initialize
virtual void initialize(TTree *tree) override
Class initializer: set branch addresses and other staf.
Definition: TOPHitRateCounter.cc:28
Belle2::Background::TOPHitRateCounter::TreeStruct
tree structure
Definition: TOPHitRateCounter.h:50
Belle2::Background::TOPHitRateCounter::normalize
virtual void normalize(unsigned timeStamp) override
Normalize accumulated hits (e.g.
Definition: TOPHitRateCounter.cc:88
Belle2::Background::TOPHitRateCounter::TreeStruct::numEvents
int numEvents
number of events accumulated
Definition: TOPHitRateCounter.h:53
Belle2::Background::TOPHitRateCounter::m_hits
TH1F * m_hits
time distribution of hits in wide range
Definition: TOPHitRateCounter.h:124
Belle2::Background::TOPHitRateCounter::m_activeTotal
double m_activeTotal
total fraction of active channels
Definition: TOPHitRateCounter.h:129
Belle2::Background::TOPHitRateCounter::m_timeOffset
double m_timeOffset
time offset of hits [ns]
Definition: TOPHitRateCounter.h:108
Belle2::DBObjPtr
Class for accessing objects in the database.
Definition: DBObjPtr.h:31
Belle2::Background::TOPHitRateCounter::TreeStruct::valid
bool valid
status: true = rates valid
Definition: TOPHitRateCounter.h:54
Belle2::Background::TOPHitRateCounter::m_activeFractions
double m_activeFractions[16]
fractions of active channels in slots
Definition: TOPHitRateCounter.h:128
Belle2::Background::TOPHitRateCounter::m_buffer
std::map< unsigned, TreeStruct > m_buffer
average rates in time stamps
Definition: TOPHitRateCounter.h:115
Belle2::Background::TOPHitRateCounter::TreeStruct::normalize
void normalize()
normalize accumulated hits to single event
Definition: TOPHitRateCounter.h:59
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Background::TOPHitRateCounter::m_timeWindow
double m_timeWindow
time window in which to count hits [ns]
Definition: TOPHitRateCounter.h:109
Belle2::Background::TOPHitRateCounter::m_channelMask
DBObjPtr< TOPCalChannelMask > m_channelMask
channel mask
Definition: TOPHitRateCounter.h:121
Belle2::Background::TOPHitRateCounter::m_rates
TreeStruct m_rates
tree variables
Definition: TOPHitRateCounter.h:112
Belle2::Background::TOPHitRateCounter::TOPHitRateCounter
TOPHitRateCounter(double timeOffset, double timeWindow)
Constructor.
Definition: TOPHitRateCounter.h:73
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::Background::TOPHitRateCounter::setActiveFractions
void setActiveFractions()
Sets fractions of active channels.
Definition: TOPHitRateCounter.cc:120
Belle2::Background::TOPHitRateCounter::accumulate
virtual void accumulate(unsigned timeStamp) override
Accumulate hits.
Definition: TOPHitRateCounter.cc:56
Belle2::Background::TOPHitRateCounter::TreeStruct::slotRates
float slotRates[16]
hit rates per PMT of the modules (slots) [MHz]
Definition: TOPHitRateCounter.h:51
Belle2::Background::TOPHitRateCounter::TreeStruct::averageRate
float averageRate
average hit rate per PMT [MHz]
Definition: TOPHitRateCounter.h:52
Belle2::Background::TOPHitRateCounter::m_digits
StoreArray< TOPDigit > m_digits
collection of digits
Definition: TOPHitRateCounter.h:118
Belle2::Background::TOPHitRateCounter::clear
virtual void clear() override
Clear time-stamp buffer to prepare for 'accumulate'.
Definition: TOPHitRateCounter.cc:51
Belle2::Background::TOPHitRateCounter::m_hitsInWindow
TH1F * m_hitsInWindow
time distribution of hits inside timeWindow
Definition: TOPHitRateCounter.h:125