Belle II Software  release-05-01-25
KLMHitRateCounter.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, Kirill Chilikin *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 /* C++ headers. */
14 #include <map>
15 
16 /* External headers. */
17 #include <TTree.h>
18 
19 /* Belle2 headers. */
20 #include <background/modules/BeamBkgHitRateMonitor/HitRateBase.h>
21 #include <klm/dataobjects/KLMDigit.h>
22 #include <klm/dataobjects/KLMElementNumbers.h>
23 #include <klm/dataobjects/KLMModuleArrayIndex.h>
24 #include <framework/database/DBObjPtr.h>
25 #include <framework/datastore/StoreArray.h>
26 #include <klm/dbobjects/KLMChannelStatus.h>
27 
28 namespace Belle2 {
34  namespace Background {
35 
39  class KLMHitRateCounter: public HitRateBase {
40 
41  public:
42 
46  struct TreeStruct {
47 
50 
52  float averageRate = 0;
53 
55  int numEvents = 0;
56 
58  bool valid = false;
59 
63  void normalize()
64  {
65  if (numEvents == 0)
66  return;
67  for (int i = 0; i < KLMElementNumbers::getTotalModuleNumber(); ++i)
68  moduleRates[i] /= numEvents;
70  }
71 
72  };
73 
77  KLMHitRateCounter() {};
78 
83  virtual void initialize(TTree* tree) override;
84 
88  virtual void clear() override;
89 
94  virtual void accumulate(unsigned timeStamp) override;
95 
100  virtual void normalize(unsigned timeStamp) override;
101 
102  private:
103 
105  TreeStruct m_rates;
106 
108  std::map<unsigned, TreeStruct> m_buffer;
109 
112 
114  const KLMElementNumbers* m_ElementNumbers = nullptr;
115 
117  const KLMModuleArrayIndex* m_ModuleArrayIndex = nullptr;
118 
121 
122  };
123 
124  }
125 
127 }
Belle2::Background::KLMHitRateCounter::TreeStruct::valid
bool valid
Whether the rates are valid.
Definition: KLMHitRateCounter.h:66
Belle2::Background::KLMHitRateCounter::m_digits
StoreArray< KLMDigit > m_digits
KLM digits.
Definition: KLMHitRateCounter.h:119
Belle2::Background::KLMHitRateCounter::m_rates
TreeStruct m_rates
Tree data.
Definition: KLMHitRateCounter.h:113
Belle2::Background::KLMHitRateCounter::initialize
virtual void initialize(TTree *tree) override
Class initializer.
Definition: KLMHitRateCounter.cc:16
Belle2::Background::KLMHitRateCounter::TreeStruct::moduleRates
float moduleRates[KLMElementNumbers::getTotalModuleNumber()]
Hit rates in each module.
Definition: KLMHitRateCounter.h:57
Belle2::KLMElementNumbers::getTotalModuleNumber
static constexpr int getTotalModuleNumber()
Get total number of modules.
Definition: KLMElementNumbers.h:251
Belle2::Background::KLMHitRateCounter::normalize
virtual void normalize(unsigned timeStamp) override
Normalize accumulated hits (i.e.
Definition: KLMHitRateCounter.cc:71
Belle2::DBObjPtr
Class for accessing objects in the database.
Definition: DBObjPtr.h:31
Belle2::Background::KLMHitRateCounter::m_ElementNumbers
const KLMElementNumbers * m_ElementNumbers
KLM element numbers.
Definition: KLMHitRateCounter.h:122
Belle2::Background::KLMHitRateCounter::TreeStruct::numEvents
int numEvents
Number of accumulated events.
Definition: KLMHitRateCounter.h:63
Belle2::KLMModuleArrayIndex
KLM module array index.
Definition: KLMModuleArrayIndex.h:33
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Background::KLMHitRateCounter::accumulate
virtual void accumulate(unsigned timeStamp) override
Accumulate hits.
Definition: KLMHitRateCounter.cc:37
Belle2::Background::KLMHitRateCounter::KLMHitRateCounter
KLMHitRateCounter()
Constructor.
Definition: KLMHitRateCounter.h:85
Belle2::Background::KLMHitRateCounter::m_ChannelStatus
DBObjPtr< KLMChannelStatus > m_ChannelStatus
KLM channel status.
Definition: KLMHitRateCounter.h:128
Belle2::Background::KLMHitRateCounter::TreeStruct::averageRate
float averageRate
Total detector average hit rate.
Definition: KLMHitRateCounter.h:60
Belle2::Background::KLMHitRateCounter::TreeStruct::normalize
void normalize()
Normalize accumulated hits to single event.
Definition: KLMHitRateCounter.h:71
Belle2::Background::KLMHitRateCounter::clear
virtual void clear() override
Clear time-stamp buffer to prepare for 'accumulate'.
Definition: KLMHitRateCounter.cc:32
Belle2::Background::KLMHitRateCounter::m_ModuleArrayIndex
const KLMModuleArrayIndex * m_ModuleArrayIndex
KLM module array index.
Definition: KLMHitRateCounter.h:125
Belle2::KLMElementNumbers
KLM element numbers.
Definition: KLMElementNumbers.h:37
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::Background::KLMHitRateCounter::m_buffer
std::map< unsigned, TreeStruct > m_buffer
Buffer.
Definition: KLMHitRateCounter.h:116