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