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