CMS 3D CMS Logo

HGCRecHit.cc
Go to the documentation of this file.
5 #include <cassert>
6 #include <math.h>
7 
8 HGCRecHit::HGCRecHit() : CaloRecHit(), flagBits_(0) {
9 }
10 
11 HGCRecHit::HGCRecHit(const DetId& id, float energy, float time, uint32_t flags, uint32_t flagBits) :
12  CaloRecHit(id,energy,time,flags), flagBits_(flagBits) {
13 }
14 
15 float HGCRecHit::chi2() const {
16  uint32_t rawChi2 = 0x7F & (flags()>>4);
17  return (float)rawChi2 / (float)((1<<7)-1) * 64.;
18 }
19 
20 float HGCRecHit::outOfTimeChi2() const {
21  uint32_t rawChi2Prob = 0x7F & (flags()>>24);
22  return (float)rawChi2Prob / (float)((1<<7)-1) * 64.;
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 ) chi2 = 64;
35  // use 7 bits
36  uint32_t rawChi2 = lround( chi2 / 64. * ((1<<7)-1) );
37  // shift by 4 bits (recoFlag)
38  setFlags( (~(0x7F<<4) & flags()) | ((rawChi2 & 0x7F)<<4) );
39 }
40 
42  if ( energy > 0.001 ) {
43  uint16_t exponent = lround(floor(log10(energy)))+3;
44  uint16_t significand = lround(energy/pow(10,exponent-5));
45  // use 13 bits (3 exponent, 10 significand)
46  uint32_t rawEnergy = exponent<<10 | significand;
47  // shift by 11 bits (recoFlag + chi2)
48  setFlags( ( ~(0x1FFF<<11) & flags()) | ((rawEnergy & 0x1FFF)<<11) );
49  }
50 }
51 
53  // bound the max value of chi2
54  if ( chi2 > 64 ) chi2 = 64;
55  // use 7 bits
56  uint32_t rawChi2 = lround( chi2 / 64. * ((1<<7)-1) );
57  // shift by 24 bits (recoFlag + chi2 + outOfTimeEnergy)
58  setFlags( (~(0x7F<<24) & flags()) | ((rawChi2 & 0x7F)<<24) );
59 }
60 
61 void HGCRecHit::setTimeError( uint8_t timeErrBits ) {
62  // take the bits and put them in the right spot
63  setAux( (~0xFF & aux()) | timeErrBits );
64 }
65 
66 float HGCRecHit::timeError() const {
67  uint32_t timeErrorBits = 0xFF & aux();
68  // all bits off --> time reco bailed out (return negative value)
69  if( (0xFF & timeErrorBits) == 0x00 )
70  return -1;
71  // all bits on --> time error over 5 ns (return large value)
72  if( (0xFF & timeErrorBits) == 0xFF )
73  return 10000;
74 
75  float LSB = 1.26008;
76  uint8_t exponent = timeErrorBits>>5;
77  uint8_t significand = timeErrorBits & ~(0x7<<5);
78  return pow(2.,exponent)*significand*LSB/1000.;
79 }
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 
100  for (std::vector<int>::const_iterator flagPtr = flagsvec.begin();
101  flagPtr!= flagsvec.end(); ++flagPtr) { // check if one of the flags is up
102  if (checkFlag(*flagPtr)) return true;
103  }
104  return false;
105 }
106 
107 
108 std::ostream& operator<<(std::ostream& s, const HGCRecHit& hit) {
109  if (hit.detid().det() == DetId::Forward && hit.detid().subdetId() == HGCEE)
110  return s << HGCalDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
111  else if (hit.detid().det() == DetId::Forward && hit.detid().subdetId() == HGCHEF)
112  return s << HGCalDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
113  else if (hit.detid().det() == DetId::Forward && hit.detid().subdetId() == HGCHEB)
114  return s << HGCHEDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
115  else
116  return s << "HGCRecHit undefined subdetector" ;
117 }
uint32_t aux() const
Definition: CaloRecHit.h:27
const DetId & detid() const
Definition: CaloRecHit.h:21
bool checkFlags(const std::vector< int > &flagsvec) const
check if one of the flags in a set is true
Definition: HGCRecHit.cc:98
HGCRecHit()
Definition: HGCRecHit.cc:8
bool isTimeErrorValid() const
Definition: HGCRecHit.cc:88
float time() const
Definition: CaloRecHit.h:19
float outOfTimeEnergy() const
Definition: HGCRecHit.cc:25
bool checkFlag(int flag) const
check if the flag is true
Definition: HGCRecHit.h:95
bool isTimeValid() const
Definition: HGCRecHit.cc:81
float timeError() const
Definition: HGCRecHit.cc:66
void setOutOfTimeEnergy(float energy)
Definition: HGCRecHit.cc:41
std::ostream & operator<<(std::ostream &s, const HGCRecHit &hit)
Definition: HGCRecHit.cc:108
uint32_t flagBits_
store rechit condition (see Flags enum) in a bit-wise way
Definition: HGCRecHit.h:104
float energy() const
Definition: CaloRecHit.h:17
uint32_t flags() const
Definition: CaloRecHit.h:22
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
void setFlags(uint32_t flags)
Definition: CaloRecHit.h:23
Definition: DetId.h:18
void setOutOfTimeChi2(float chi2)
Definition: HGCRecHit.cc:52
void setAux(uint32_t value)
Definition: CaloRecHit.h:26
float chi2() const
Definition: HGCRecHit.cc:15
float outOfTimeChi2() const
Definition: HGCRecHit.cc:20
void setChi2(float chi2)
Definition: HGCRecHit.cc:32
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
void setTimeError(uint8_t timeErrBits)
Definition: HGCRecHit.cc:61
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40