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