CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalRecHit.cc
Go to the documentation of this file.
6 #include <cassert>
7 #include <math.h>
8 
9 
11 
12  return ( checkFlag(kLeadingEdgeRecovered) ||
15  );
16 }
17 
18 float EcalRecHit::chi2() const
19 {
20  uint32_t rawChi2 = 0x7F & (flags()>>4);
21  return (float)rawChi2 / (float)((1<<7)-1) * 64.;
22 }
23 
24 
25 
27 {
28  uint32_t rawChi2Prob = 0x7F & (flags()>>24);
29  return (float)rawChi2Prob / (float)((1<<7)-1) * 64.;
30 }
31 
33 {
34  uint32_t rawEnergy = (0x1FFF & flags()>>11);
35  uint16_t exponent = rawEnergy>>10;
36  uint16_t significand = ~(0xE<<9) & rawEnergy;
37  return (float) significand*pow(10,exponent-5);
38 }
39 
40 
41 
42 
43 
44 void EcalRecHit::setChi2( float chi2 )
45 {
46  // bound the max value of the chi2
47  if ( chi2 > 64 ) chi2 = 64;
48  // use 7 bits
49  uint32_t rawChi2 = lround( chi2 / 64. * ((1<<7)-1) );
50  // shift by 4 bits (recoFlag)
51  setFlags( (~(0x7F<<4) & flags()) | ((rawChi2 & 0x7F)<<4) );
52 }
53 
55 {
56  if ( energy > 0.001 ) {
57  uint16_t exponent = lround(floor(log10(energy)))+3;
58  uint16_t significand = lround(energy/pow(10,exponent-5));
59  // use 13 bits (3 exponent, 10 significand)
60  uint32_t rawEnergy = exponent<<10 | significand;
61  // shift by 11 bits (recoFlag + chi2)
62  setFlags( ( ~(0x1FFF<<11) & flags()) | ((rawEnergy & 0x1FFF)<<11) );
63  }
64 }
65 
66 
67 
68 
69 void EcalRecHit::setOutOfTimeChi2( float chi2 )
70 {
71  // bound the max value of chi2
72  if ( chi2 > 64 ) chi2 = 64;
73  // use 7 bits
74  uint32_t rawChi2 = lround( chi2 / 64. * ((1<<7)-1) );
75  // shift by 24 bits (recoFlag + chi2 + outOfTimeEnergy)
76  setFlags( (~(0x7F<<24) & flags()) | ((rawChi2 & 0x7F)<<24) );
77 }
78 
79 
80 void EcalRecHit::setTimeError( uint8_t timeErrBits )
81 {
82  // take the bits and put them in the right spot
83  setAux( (~0xFF & aux()) | timeErrBits );
84 }
85 
86 
87 float EcalRecHit::timeError() const
88 {
89  uint32_t timeErrorBits = 0xFF & aux();
90  // all bits off --> time reco bailed out (return negative value)
91  if( (0xFF & timeErrorBits) == 0x00 )
92  return -1;
93  // all bits on --> time error over 5 ns (return large value)
94  if( (0xFF & timeErrorBits) == 0xFF )
95  return 10000;
96 
97  float LSB = 1.26008;
98  uint8_t exponent = timeErrorBits>>5;
99  uint8_t significand = timeErrorBits & ~(0x7<<5);
100  return pow(2.,exponent)*significand*LSB/1000.;
101 }
102 
103 
105 {
106  if(timeError() <= 0)
107  return false;
108  else
109  return true;
110 }
111 
112 
114 {
115  if(!isTimeValid())
116  return false;
117  if(timeError() >= 10000)
118  return false;
119 
120  return true;
121 }
122 
123 
125 bool EcalRecHit::checkFlags(const std::vector<int>& flagsvec ) const{
126  for (std::vector<int>::const_iterator flagPtr = flagsvec.begin();
127  flagPtr!= flagsvec.end(); ++flagPtr) { // check if one of the flags is up
128  if (checkFlag(*flagPtr)) return true;
129  }
130  return false;
131 }
132 
133 
136  for (int i=kUnknown; ; --i){
137  if (checkFlag(i)) return Flags(i);
138  if (i==0) break;
139  }
140  // no flag assigned, assume good
141  return kGood;
142 }
143 
144 
145 
146 std::ostream& operator<<(std::ostream& s, const EcalRecHit& hit) {
147  if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalBarrel)
148  return s << EBDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
149  else if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalEndcap)
150  return s << EEDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
151  else if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalPreshower)
152  return s << ESDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
153  else
154  return s << "EcalRecHit undefined subdetector" ;
155 }
156 
157 
int i
Definition: DBlmapReader.cc:9
bool isTimeErrorValid() const
Definition: EcalRecHit.cc:113
bool checkFlags(const std::vector< int > &flagsvec) const
check if one of the flags in a set is true
Definition: EcalRecHit.cc:125
uint32_t aux() const
Definition: CaloRecHit.h:26
const DetId & detid() const
Definition: CaloRecHit.h:20
Flags recoFlag() const
DEPRECATED provided for temporary backward compatibility.
Definition: EcalRecHit.cc:135
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
float time() const
Definition: CaloRecHit.h:19
bool isTimeValid() const
Definition: EcalRecHit.cc:104
bool isRecovered() const
Definition: EcalRecHit.cc:10
void setTimeError(uint8_t timeErrBits)
Definition: EcalRecHit.cc:80
float outOfTimeEnergy() const
Definition: EcalRecHit.cc:32
bool checkFlag(int flag) const
check if the flag is true
Definition: EcalRecHit.h:106
float outOfTimeChi2() const
Definition: EcalRecHit.cc:26
float energy() const
Definition: CaloRecHit.h:17
float chi2() const
Definition: EcalRecHit.cc:18
uint32_t flags() const
Definition: CaloRecHit.h:21
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
float timeError() const
Definition: EcalRecHit.cc:87
void setFlags(uint32_t flags)
Definition: CaloRecHit.h:22
void setOutOfTimeChi2(float chi2)
Definition: EcalRecHit.cc:69
void setChi2(float chi2)
Definition: EcalRecHit.cc:44
void setOutOfTimeEnergy(float energy)
Definition: EcalRecHit.cc:54
void setAux(uint32_t value)
Definition: CaloRecHit.h:25
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40