Belle II Software development
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
15using namespace std;
16
17namespace Belle2 {
24 float TOPDigit::s_pileupTime = 0;
25
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
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 }
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
@ c_DontAppend
do not append BG digit to digits
Definition: DigitBase.h:33
@ c_Append
append BG digit to digits
Definition: DigitBase.h:34
Class to store TOP digitized hits (output of TOPDigitizer or raw data unpacker) relations to TOPSimHi...
Definition: TOPDigit.h:24
float m_time
calibrated time in [ns], t0-subtracted
Definition: TOPDigit.h:425
float m_rawTime
raw time expressed in samples (TDC bins)
Definition: TOPDigit.h:424
unsigned short m_firstWindow
first ASIC window of the merged waveform
Definition: TOPDigit.h:430
int m_pulseHeight
pulse height [ADC counts]
Definition: TOPDigit.h:427
static float s_doubleHitResolution
double hit resolving time in [ns]
Definition: TOPDigit.h:435
DigitBase::EAppendStatus addBGDigit(const DigitBase *bg) override
Implementation of the base class function.
Definition: TOPDigit.cc:36
int getModulo256Sample() const
Returns sample number modulo 256.
Definition: TOPDigit.cc:26
static float s_pileupTime
pile-up time in [ns]
Definition: TOPDigit.h:436
Abstract base class for different kinds of events.
STL namespace.