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 }
HGCRecHit::setSignalOverSigmaNoise
void setSignalOverSigmaNoise(float sOverNoise)
Definition: HGCRecHit.cc:64
HGCRecHit::signalOverSigmaNoise_
uint8_t signalOverSigmaNoise_
Definition: HGCRecHit.h:116
HGCRecHit::isTimeValid
bool isTimeValid() const
Definition: HGCRecHit.cc:81
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
CaloRecHit::energy
constexpr float energy() const
Definition: CaloRecHit.h:29
HGCScintillatorDetId.h
HGCRecHit::checkFlag
bool checkFlag(int flag) const
check if the flag is true
Definition: HGCRecHit.h:105
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
DetId::Hcal
Definition: DetId.h:28
HGCSiliconDetId.h
operator<<
std::ostream & operator<<(std::ostream &s, const HGCRecHit &hit)
Definition: HGCRecHit.cc:107
protons_cff.time
time
Definition: protons_cff.py:39
HFNoseDetId.h
CaloRecHit
Definition: CaloRecHit.h:23
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
HFNoseDetId
Definition: HFNoseDetId.h:22
HGCSiliconDetId
Definition: HGCSiliconDetId.h:22
HGCRecHit::timeError
float timeError() const
Definition: HGCRecHit.cc:79
DetId
Definition: DetId.h:17
DetId::HGCalHSi
Definition: DetId.h:33
DetId::HGCalEE
Definition: DetId.h:32
alignCSCRings.s
s
Definition: alignCSCRings.py:92
HGCRecHit::setOutOfTimeEnergy
void setOutOfTimeEnergy(float energy)
Definition: HGCRecHit.cc:43
HGCRecHit.h
HFNose
Definition: ForwardSubdetector.h:11
HLT_FULL_cff.exponent
exponent
Definition: HLT_FULL_cff.py:52799
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
HGCRecHit
Definition: HGCRecHit.h:14
HGCEE
Definition: ForwardSubdetector.h:8
HGCRecHit::setTimeError
void setTimeError(float timeErr)
Definition: HGCRecHit.cc:74
HcalDetId.h
CaloRecHit::setFlags
constexpr void setFlags(uint32_t flags)
Definition: CaloRecHit.h:35
HcalDetId
Definition: HcalDetId.h:12
HGCRecHit::checkFlags
bool checkFlags(const std::vector< int > &flagsvec) const
check if one of the flags in a set is true
Definition: HGCRecHit.cc:98
HGCRecHit::setOutOfTimeChi2
void setOutOfTimeChi2(float chi2)
Definition: HGCRecHit.cc:54
HGCRecHit::outOfTimeChi2
float outOfTimeChi2() const
Definition: HGCRecHit.cc:21
HGCRecHit::HGCRecHit
HGCRecHit()
Definition: HGCRecHit.cc:10
HGCalDetId
Definition: HGCalDetId.h:8
HGCalDetId.h
HGCRecHit::timeError_
float timeError_
Definition: HGCRecHit.h:117
HGCRecHit::isTimeErrorValid
bool isTimeErrorValid() const
Definition: HGCRecHit.cc:88
HcalEndcap
Definition: HcalAssistant.h:34
HGCRecHit::setChi2
void setChi2(float chi2)
Definition: HGCRecHit.cc:33
HGCScintillatorDetId
Definition: HGCScintillatorDetId.h:23
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
DetId::HGCalHSc
Definition: DetId.h:34
HGCRecHit::outOfTimeEnergy
float outOfTimeEnergy() const
Definition: HGCRecHit.cc:26
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
HGCRecHit::signalOverSigmaNoise
float signalOverSigmaNoise() const
Definition: HGCRecHit.cc:72
HGCHEF
Definition: ForwardSubdetector.h:9
DetId::Forward
Definition: DetId.h:30
HLT_FULL_cff.flags
flags
Definition: HLT_FULL_cff.py:13150
HGCRecHit::chi2
float chi2() const
Definition: HGCRecHit.cc:16
hit
Definition: SiStripHitEffFromCalibTree.cc:88
CaloRecHit::flags
constexpr uint32_t flags() const
Definition: CaloRecHit.h:34