Belle II Software  release-08-01-10
TOPDigit.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <top/dataobjects/TOPDigit.h>
10 #include <top/dataobjects/TOPRawDigit.h>
11 #include <top/dataobjects/TOPSimHit.h>
12 #include <mdst/dataobjects/MCParticle.h>
13 #include <framework/datastore/RelationVector.h>
14 
15 using namespace std;
16 
17 namespace Belle2 {
23  float TOPDigit::s_doubleHitResolution = 0;
24  float TOPDigit::s_pileupTime = 0;
25 
26  int TOPDigit::getModulo256Sample() const
27  {
28  int sample = int(m_rawTime);
29  if (m_rawTime < 0) sample--;
30  sample += (int) m_firstWindow * 64;
31  if (sample < 0) return 256 + sample % 256;
32  return sample % 256;
33  }
34 
35 
36  DigitBase::EAppendStatus TOPDigit::addBGDigit(const DigitBase* bg)
37  {
38  const auto* bgDigit = static_cast<const TOPDigit*>(bg);
39  double diff = m_time - bgDigit->getTime();
40 
41  if (fabs(diff) > s_doubleHitResolution) return DigitBase::c_Append; // no pile-up
42 
43  if (fabs(diff) < s_pileupTime) { // pile-up results in time averaging
44  const double time[2] = {m_time, bgDigit->getTime()};
45  const double rawTime[2] = {m_rawTime, bgDigit->getRawTime()};
46  const int pulseHeight[2] = {m_pulseHeight, bgDigit->getPulseHeight()};
47  double sum = pulseHeight[0] + pulseHeight[1];
48  if (sum > 0) {
49  m_time = (time[0] * pulseHeight[0] + time[1] * pulseHeight[1]) / sum;
50  m_rawTime = (rawTime[0] * pulseHeight[0] + rawTime[1] * pulseHeight[1]) / sum;
51  // m_timeError =
52  // m_pulseWidth =
53  // m_integral =
54  } else {
55  m_time = (time[0] + time[1]) / 2;
56  m_rawTime = (rawTime[0] + rawTime[1]) / 2;
57  // m_timeError =
58  // m_pulseWidth =
59  // m_integral =
60  }
61  m_pulseHeight = int(sum);
62  double reweight = sum > 0 ? pulseHeight[0] / sum : 0.5;
63  auto relSimHits = this->getRelationsTo<TOPSimHit>();
64  for (size_t i = 0; i < relSimHits.size(); ++i) {
65  float weight = relSimHits.weight(i) * reweight;
66  relSimHits.setWeight(i, weight);
67  }
68  auto relRawDigits = this->getRelationsTo<TOPRawDigit>();
69  for (size_t i = 0; i < relRawDigits.size(); ++i) {
70  float weight = relRawDigits.weight(i) * reweight;
71  relRawDigits.setWeight(i, weight);
72  }
73  auto relMCParticles = this->getRelationsTo<MCParticle>();
74  for (size_t i = 0; i < relMCParticles.size(); ++i) {
75  float weight = relMCParticles.weight(i) * reweight;
76  relMCParticles.setWeight(i, weight);
77  }
78  } else { // pile-up results in discarding the second-in-time hit
79  if (diff > 0) {
80  // bg digit is the first-in-time hit, therefore replace and remove relations
81  *this = *bgDigit;
82 
83  // remove relations (going from back side!)
84  auto relSimHits = this->getRelationsTo<TOPSimHit>();
85  for (int i = relSimHits.size() - 1; i >= 0; --i) {
86  relSimHits.remove(i);
87  }
88  auto relRawDigits = this->getRelationsTo<TOPRawDigit>();
89  for (int i = relRawDigits.size() - 1; i >= 0; --i) {
90  relRawDigits.remove(i);
91  }
92  auto relMCParticles = this->getRelationsTo<MCParticle>();
93  for (int i = relMCParticles.size() - 1; i >= 0; --i) {
94  relMCParticles.remove(i);
95  }
96  }
97  }
98  return DigitBase::c_DontAppend;
99 
100  }
101 
103 } // end Belle2 namespace
104 
A common base for subdetector Digits.
Definition: DigitBase.h:26
EAppendStatus
Enum for return state of addBGDigit function.
Definition: DigitBase.h:32
Class to store TOP digitized hits (output of TOPDigitizer or raw data unpacker) relations to TOPSimHi...
Definition: TOPDigit.h:24
double getTime() const
Returns t0-subtracted and calibrated time.
Definition: TOPDigit.h:372
Abstract base class for different kinds of events.