CMS 3D CMS Logo

HGCRecHit.cc
Go to the documentation of this file.
6 #include <cassert>
7 #include <cmath>
8 
9 HGCRecHit::HGCRecHit() : CaloRecHit(), flagBits_(0) {
10 }
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 
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 ) 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 ) chi2 = 64;
56  // use 7 bits
57  uint32_t rawChi2 = lround( chi2 / 64.f * ((1<<7)-1) );
58  // shift by 24 bits (recoFlag + chi2 + outOfTimeEnergy)
59  setFlags( (~(0x7F<<24) & flags()) | ((rawChi2 & 0x7F)<<24) );
60 }
61 
62 void HGCRecHit::setSignalOverSigmaNoise( float sOverNoise ) {
63  // bound the max value of sOverNoise
64  if(sOverNoise > 32.f) sOverNoise = 32.f;
65  //use 8 bits
66  signalOverSigmaNoise_ = lround( sOverNoise / 32.f * ((1<<8)-1) );
67 }
68 
70  return (float)signalOverSigmaNoise_ * 0.125f;
71 }
72 
73 void HGCRecHit::setTimeError( uint8_t timeErrBits ) {
74  // take the bits and put them in the right spot
75  setAux( (~0xFF & aux()) | timeErrBits );
76 }
77 
78 float HGCRecHit::timeError() const {
79  uint32_t timeErrorBits = 0xFF & aux();
80  // all bits off --> time reco bailed out (return negative value)
81  if( (0xFF & timeErrorBits) == 0x00 )
82  return -1;
83  // all bits on --> time error over 5 ns (return large value)
84  if( (0xFF & timeErrorBits) == 0xFF )
85  return 10000;
86 
87  float LSB = 1.26008;
88  uint8_t exponent = timeErrorBits>>5;
89  uint8_t significand = timeErrorBits & ~(0x7<<5);
90  return pow(2.,exponent)*significand*LSB/1000.f;
91 }
92 
93 bool HGCRecHit::isTimeValid() const {
94  if(timeError() <= 0)
95  return false;
96  else
97  return true;
98 }
99 
101  if(!isTimeValid())
102  return false;
103  if(timeError() >= 10000)
104  return false;
105 
106  return true;
107 }
108 
110 bool HGCRecHit::checkFlags(const std::vector<int>& flagsvec ) const {
111 
112  for (std::vector<int>::const_iterator flagPtr = flagsvec.begin();
113  flagPtr!= flagsvec.end(); ++flagPtr) { // check if one of the flags is up
114  if (checkFlag(*flagPtr)) return true;
115  }
116  return false;
117 }
118 
119 
120 std::ostream& operator<<(std::ostream& s, const HGCRecHit& hit) {
121  if (hit.detid().det() == DetId::Forward && hit.detid().subdetId() == HGCEE)
122  return s << HGCalDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
123  else if (hit.detid().det() == DetId::Forward && hit.detid().subdetId() == HGCHEF)
124  return s << HGCalDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
125  else if (hit.detid().det() == DetId::Hcal && hit.detid().subdetId() == HcalEndcap)
126  return s << HcalDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
127  else if (hit.detid().det() == DetId::HGCalEE || hit.detid().det() == DetId::HGCalHSi)
128  return s << HGCSiliconDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
129  else if (hit.detid().det() == DetId::HGCalHSc)
130  return s << HGCScintillatorDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
131  else
132  return s << "HGCRecHit undefined subdetector" ;
133 }
constexpr float energy() const
Definition: CaloRecHit.h:31
void setSignalOverSigmaNoise(float sOverNoise)
Definition: HGCRecHit.cc:62
uint8_t signalOverSigmaNoise_
Definition: HGCRecHit.h:109
constexpr const DetId & detid() const
Definition: CaloRecHit.h:35
bool checkFlags(const std::vector< int > &flagsvec) const
check if one of the flags in a set is true
Definition: HGCRecHit.cc:110
HGCRecHit()
Definition: HGCRecHit.cc:9
bool isTimeErrorValid() const
Definition: HGCRecHit.cc:100
float outOfTimeEnergy() const
Definition: HGCRecHit.cc:26
float signalOverSigmaNoise() const
Definition: HGCRecHit.cc:69
bool checkFlag(int flag) const
check if the flag is true
Definition: HGCRecHit.h:99
bool isTimeValid() const
Definition: HGCRecHit.cc:93
float timeError() const
Definition: HGCRecHit.cc:78
void setOutOfTimeEnergy(float energy)
Definition: HGCRecHit.cc:42
std::ostream & operator<<(std::ostream &s, const HGCRecHit &hit)
Definition: HGCRecHit.cc:120
uint32_t flagBits_
store rechit condition (see Flags enum) in a bit-wise way
Definition: HGCRecHit.h:108
constexpr float time() const
Definition: CaloRecHit.h:33
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
double f[11][100]
Definition: DetId.h:18
void setOutOfTimeChi2(float chi2)
Definition: HGCRecHit.cc:53
float chi2() const
Definition: HGCRecHit.cc:16
constexpr void setFlags(uint32_t flags)
Definition: CaloRecHit.h:37
constexpr uint32_t aux() const
Definition: CaloRecHit.h:52
float outOfTimeChi2() const
Definition: HGCRecHit.cc:21
constexpr void setAux(uint32_t value)
Definition: CaloRecHit.h:51
void setChi2(float chi2)
Definition: HGCRecHit.cc:33
constexpr uint32_t flags() const
Definition: CaloRecHit.h:36
void setTimeError(uint8_t timeErrBits)
Definition: HGCRecHit.cc:73
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39