Belle II Software  release-08-01-10
CDCHit.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 <cdc/dataobjects/CDCHit.h>
10 #include <cdc/dataobjects/CDCSimHit.h>
11 #include <mdst/dataobjects/MCParticle.h>
12 #include <framework/datastore/RelationVector.h>
13 
14 
15 using namespace std;
16 using namespace Belle2;
17 
18 CDCHit::CDCHit(unsigned short tdcCount, unsigned short charge,
19  unsigned short iSuperLayer, unsigned short iLayer, unsigned short iWire, unsigned short status, unsigned short tot,
20  signed short otherHitIndex, unsigned short leadingEdgeCharge)
21 {
22  setTDCCount(tdcCount);
23  setADCCount(charge);
24  setWireID(iSuperLayer, iLayer, iWire);
25  setStatus(status);
26  setTOT(tot);
27  setOtherHitIndex(otherHitIndex);
28  setADCCountAtLeadingEdge(leadingEdgeCharge);
29 }
30 
31 
32 DigitBase::EAppendStatus CDCHit::addBGDigit(const DigitBase* bg)
33 {
34  const auto* bgDigit = static_cast<const CDCHit*>(bg);
35  const unsigned short tdc4Sg = m_tdcCount;
36  const unsigned short adc4Sg = m_adcCount;
37  const unsigned short tot4Sg = m_tot;
38  const unsigned short tdc4Bg = bgDigit->getTDCCount();
39  const unsigned short adc4Bg = bgDigit->getADCCount();
40  const unsigned short tot4Bg = bgDigit->getTOT();
41  // B2DEBUG(28, "Sg tdc,adc,tot= " << tdc4Sg << " " << adc4Sg << " " << tot4Sg);
42  // B2DEBUG(28, "Bg tdc,adc,tot= " << tdc4Bg << " " << adc4Bg << " " << tot4Bg);
43  int diff = static_cast<int>(m_tdcCount) - static_cast<int>(bgDigit->getTDCCount());
44 
45  // If the BG hit is faster than the true hit, the TDC count is replaced, and
46  // relation is removed.
47  // ADC counts are summed up.
48  if (diff < 0) {
49  *this = *bgDigit;
50  auto relSimHits = this->getRelationsFrom<CDCSimHit>();
51  for (int i = relSimHits.size() - 1; i >= 0; --i) {
52  relSimHits.remove(i);
53  }
54  auto relMCParticles = this->getRelationsFrom<MCParticle>();
55  for (int i = relMCParticles.size() - 1; i >= 0; --i) {
56  relMCParticles.remove(i);
57  }
58  }
59 
60  m_adcCount = adc4Sg + adc4Bg;
61 
62  //Set TOT for signal+background case. It is assumed that the start timing
63  //of a pulse (input to ADC) is given by the TDC-count. This is an
64  //approximation becasue analog (for ADC) and digital (for TDC) parts are
65  //different in the front-end electronics.
66  unsigned short s1 = tdc4Sg; //start time of 1st pulse
67  unsigned short s2 = tdc4Bg; //start time of 2nd pulse
68  unsigned short w1 = 32 * tot4Sg; //its width
69  unsigned short w2 = 32 * tot4Bg; //its width
70  if (tdc4Sg < tdc4Bg) {
71  s1 = tdc4Bg;
72  w1 = 32 * tot4Bg;
73  s2 = tdc4Sg;
74  w2 = 32 * tot4Sg;
75  }
76  const unsigned short e1 = s1 - w1; //end time of 1st pulse
77  const unsigned short e2 = s2 - w2; //end time of 2nd pulse
78  // B2DEBUG(28, "s1,e1,w1,s2,e2,w2= " << s1 << " " << e1 << " " << w1 << " " << s2 << " " << e2 << " " << w2);
79 
80  double pulseW = w1 + w2;
81  if (e1 <= e2) {
82  pulseW = w1;
83  } else if (e1 <= s2) {
84  pulseW = s1 - e2;
85  }
86 
87  // maxtot=29 is hard-coded now
88  m_tot = std::min(std::round(pulseW / 32.), 29.);
89  // B2DEBUG(28, "adcCount,tot= " << m_adcCount << " " << m_tot);
90 
91  return DigitBase::c_DontAppend;
92 }
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
short getTDCCount() const
Getter for TDC count.
Definition: CDCHit.h:219
A common base for subdetector Digits.
Definition: DigitBase.h:26
EAppendStatus
Enum for return state of addBGDigit function.
Definition: DigitBase.h:32
Abstract base class for different kinds of events.