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