CMS 3D CMS Logo

HGCRecHit.cc
Go to the documentation of this file.
7 #include <cassert>
8 #include <cmath>
9 
10 HGCRecHit::HGCRecHit() : CaloRecHit(), flagBits_(0) {}
11 
13  const DetId& id, float energy, float time, uint32_t flags, uint32_t flagBits, uint8_t son, float timeError)
14  : CaloRecHit(id, energy, time, flags), flagBits_(flagBits), signalOverSigmaNoise_(son), timeError_(timeError) {}
15 
16 float HGCRecHit::chi2() const {
17  uint32_t rawChi2 = 0x7F & (flags() >> 4);
18  return (float)rawChi2 / (float)((1 << 7) - 1) * 64.f;
19 }
20 
21 float HGCRecHit::outOfTimeChi2() const {
22  uint32_t rawChi2Prob = 0x7F & (flags() >> 24);
23  return (float)rawChi2Prob / (float)((1 << 7) - 1) * 64.f;
24 }
25 
27  uint32_t rawEnergy = (0x1FFF & flags() >> 11);
28  uint16_t exponent = rawEnergy >> 10;
29  uint16_t significand = ~(0xE << 9) & rawEnergy;
30  return (float)significand * pow(10, exponent - 5);
31 }
32 
33 void HGCRecHit::setChi2(float chi2) {
34  // bound the max value of the chi2
35  if (chi2 > 64)
36  chi2 = 64;
37  // use 7 bits
38  uint32_t rawChi2 = lround(chi2 / 64.f * ((1 << 7) - 1));
39  // shift by 4 bits (recoFlag)
40  setFlags((~(0x7F << 4) & flags()) | ((rawChi2 & 0x7F) << 4));
41 }
42 
44  if (energy > 0.001f) {
45  uint16_t exponent = lround(floor(log10(energy))) + 3;
46  uint16_t significand = lround(energy / pow(10, exponent - 5));
47  // use 13 bits (3 exponent, 10 significand)
48  uint32_t rawEnergy = exponent << 10 | significand;
49  // shift by 11 bits (recoFlag + chi2)
50  setFlags((~(0x1FFF << 11) & flags()) | ((rawEnergy & 0x1FFF) << 11));
51  }
52 }
53 
55  // bound the max value of chi2
56  if (chi2 > 64)
57  chi2 = 64;
58  // use 7 bits
59  uint32_t rawChi2 = lround(chi2 / 64.f * ((1 << 7) - 1));
60  // shift by 24 bits (recoFlag + chi2 + outOfTimeEnergy)
61  setFlags((~(0x7F << 24) & flags()) | ((rawChi2 & 0x7F) << 24));
62 }
63 
64 void HGCRecHit::setSignalOverSigmaNoise(float sOverNoise) {
65  // bound the max value of sOverNoise
66  if (sOverNoise > 32.f)
67  sOverNoise = 32.f;
68  //use 8 bits
69  signalOverSigmaNoise_ = lround(sOverNoise / 32.f * ((1 << 8) - 1));
70 }
71 
72 float HGCRecHit::signalOverSigmaNoise() const { return (float)signalOverSigmaNoise_ * 0.125f; }
73 
74 void HGCRecHit::setTimeError(float timeErr) {
75  //expected resolution on single cell for that given S/N
76  timeError_ = timeErr;
77 }
78 
79 float HGCRecHit::timeError() const { return timeError_; }
80 
81 bool HGCRecHit::isTimeValid() const {
82  if (timeError() <= 0)
83  return false;
84  else
85  return true;
86 }
87 
89  if (!isTimeValid())
90  return false;
91  if (timeError() >= 10000)
92  return false;
93 
94  return true;
95 }
96 
98 bool HGCRecHit::checkFlags(const std::vector<int>& flagsvec) const {
99  for (std::vector<int>::const_iterator flagPtr = flagsvec.begin(); flagPtr != flagsvec.end();
100  ++flagPtr) { // check if one of the flags is up
101  if (checkFlag(*flagPtr))
102  return true;
103  }
104  return false;
105 }
106 
107 std::ostream& operator<<(std::ostream& s, const HGCRecHit& hit) {
108  if (hit.detid().det() == DetId::Forward && hit.detid().subdetId() == HGCEE)
109  return s << HGCalDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
110  else if (hit.detid().det() == DetId::Forward && hit.detid().subdetId() == HGCHEF)
111  return s << HGCalDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
112  else if (hit.detid().det() == DetId::Hcal && hit.detid().subdetId() == HcalEndcap)
113  return s << HcalDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
114  else if (hit.detid().det() == DetId::HGCalEE || hit.detid().det() == DetId::HGCalHSi)
115  return s << HGCSiliconDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
116  else if (hit.detid().det() == DetId::HGCalHSc)
117  return s << HGCScintillatorDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
118  else if (hit.detid().det() == DetId::Forward && hit.detid().subdetId() == HFNose)
119  return s << HFNoseDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
120  else
121  return s << "HGCRecHit undefined subdetector";
122 }
bool checkFlag(int flag) const
check if the flag is true
Definition: HGCRecHit.h:105
bool isTimeValid() const
Definition: HGCRecHit.cc:81
void setSignalOverSigmaNoise(float sOverNoise)
Definition: HGCRecHit.cc:64
uint8_t signalOverSigmaNoise_
Definition: HGCRecHit.h:116
float signalOverSigmaNoise() const
Definition: HGCRecHit.cc:72
bool isTimeErrorValid() const
Definition: HGCRecHit.cc:88
constexpr float energy() const
Definition: CaloRecHit.h:29
void setOutOfTimeEnergy(float energy)
Definition: HGCRecHit.cc:43
constexpr uint32_t flags() const
Definition: CaloRecHit.h:34
std::ostream & operator<<(std::ostream &s, const HGCRecHit &hit)
Definition: HGCRecHit.cc:107
double f[11][100]
float chi2() const
Definition: HGCRecHit.cc:16
void setTimeError(float timeErr)
Definition: HGCRecHit.cc:74
Definition: DetId.h:17
float outOfTimeChi2() const
Definition: HGCRecHit.cc:21
bool checkFlags(const std::vector< int > &flagsvec) const
check if one of the flags in a set is true
Definition: HGCRecHit.cc:98
void setOutOfTimeChi2(float chi2)
Definition: HGCRecHit.cc:54
float outOfTimeEnergy() const
Definition: HGCRecHit.cc:26
float timeError() const
Definition: HGCRecHit.cc:79
constexpr void setFlags(uint32_t flags)
Definition: CaloRecHit.h:35
float timeError_
Definition: HGCRecHit.h:117
void setChi2(float chi2)
Definition: HGCRecHit.cc:33
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29