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 #include <iostream>
10 
11 EcalRecHit::EcalRecHit() : CaloRecHit(), flagBits_(0) {
12 }
13 
14 EcalRecHit::EcalRecHit(const DetId& id, float energy, float time, uint32_t flags, uint32_t flagBits) :
15  CaloRecHit(id,energy,time,flags),
16  flagBits_(flagBits)
17 {
18 }
19 
21  return ( recoFlag() == kLeadingEdgeRecovered
23  || recoFlag() == kTowerRecovered
24  );
25 }
26 
27 float EcalRecHit::chi2() const
28 {
29  uint32_t rawChi2 = 0x7F & (flags()>>4);
30  return (float)rawChi2 / (float)((1<<7)-1) * 64.;
31 }
32 
33 float EcalRecHit::chi2Prob() const
34 {
35  std::cerr << "Please retrieve the chi2 value instead of its probability.\n";
36  std::cerr << "Use the method EcalRecHit::chi2() for that purpose.\n";
37  std::cerr << "The chi2 is still in a commissioning phase and further\n";
38  std::cerr << "actions will be taken in the future. Thanks.\n";
39  assert(false);
40  uint32_t rawChi2Prob = 0x7F & (flags()>>4);
41  return (float)rawChi2Prob / (float)((1<<7)-1);
42 }
43 
45 {
46  std::cerr << "Please retrieve the chi2 value instead of its probability.\n";
47  std::cerr << "Use the method EcalRecHit::outOfTimeChi2() for that purpose.\n";
48  std::cerr << "The chi2 is still in a commissioning phase and further\n";
49  std::cerr << "actions will be taken in the future. Thanks.\n";
50  assert(false);
51  /*
52  uint32_t rawChi2Prob = 0x7F & (flags()>>24);
53  return (float)rawChi2Prob / (float)((1<<7)-1);
54  */
55  return -1; // will never get here
56 }
57 
59 {
60  uint32_t rawChi2Prob = 0x7F & (flags()>>24);
61  return (float)rawChi2Prob / (float)((1<<7)-1) * 64.;
62 }
63 
65 {
66  uint32_t rawEnergy = (0x1FFF & flags()>>11);
67  uint16_t exponent = rawEnergy>>10;
68  uint16_t significand = ~(0xE<<9) & rawEnergy;
69  return (float) significand*pow(10,exponent-5);
70 }
71 
72 void EcalRecHit::setRecoFlag( uint32_t flag )
73 {
74  setFlags( (~0xF & flags()) | (flag & 0xF) );
75 }
76 
77 void EcalRecHit::setChi2Prob( float chi2Prob )
78 {
79  /* not used - store the raw chi2 instead */
80  std::cerr << "Please store the chi2 value instead of its probability.\n";
81  std::cerr << "Use the method EcalRecHit::setChi2() for that purpose.\n";
82  std::cerr << "The chi2 is still in a commissioning phase and further\n";
83  std::cerr << "actions will be taken in the future. Thanks.\n";
84  assert(false);
85  /*
86  if ( chi2Prob < 0 || chi2Prob > 1 ) {
87  edm::LogWarning("EcalRecHit::setChi2Prob") << "chi2Prob outside limits [0, 1] : " << chi2Prob;
88  } else {
89  // use 7 bits
90  uint32_t rawChi2Prob = lround( chi2Prob * ((1<<7)-1) );
91  // shift by 4 bits (recoFlag)
92  setFlags( (~(0x7F<<4) & flags()) | ((rawChi2Prob & 0x7F)<<4) );
93  }
94  */
95 }
96 
98 {
99  // bound the max value of the chi2
100  if ( chi2 > 64 ) chi2 = 64;
101  // use 7 bits
102  uint32_t rawChi2 = lround( chi2 / 64. * ((1<<7)-1) );
103  // shift by 4 bits (recoFlag)
104  setFlags( (~(0x7F<<4) & flags()) | ((rawChi2 & 0x7F)<<4) );
105 }
106 
108 {
109  if ( energy > 0.001 ) {
110  uint16_t exponent = lround(floor(log10(energy)))+3;
111  uint16_t significand = lround(energy/pow(10,exponent-5));
112  // use 13 bits (3 exponent, 10 significand)
113  uint32_t rawEnergy = exponent<<10 | significand;
114  // shift by 11 bits (recoFlag + chi2)
115  setFlags( ( ~(0x1FFF<<11) & flags()) | ((rawEnergy & 0x1FFF)<<11) );
116  }
117 }
118 
119 void EcalRecHit::setOutOfTimeChi2Prob( float chi2Prob )
120 {
121  /* not used - store the raw chi2 instead */
122  std::cerr << "Please store the chi2 value instead of its probability.\n";
123  std::cerr << "Use the method EcalRecHit::setOutOfTimeChi2() for that purpose.\n";
124  std::cerr << "The chi2 is still in a commissioning phase and further\n";
125  std::cerr << "actions will be taken in the future. Thanks.\n";
126  assert(false);
127  /*
128  if ( chi2Prob < 0 || chi2Prob > 1 ) {
129  edm::LogWarning("EcalRecHit::setOutOfTimeChi2Prob") << "chi2Prob outside limits [0, 1] : " << chi2Prob;
130  } else {
131  // use 7 bits
132  uint32_t rawChi2Prob = lround( chi2Prob * ((1<<7)-1) );
133  // shift by 24 bits (recoFlag + chi2 + outOfTimeEnergy)
134  setFlags( (~(0x7F<<24) & flags()) | ((rawChi2Prob & 0x7F)<<24) );
135  }
136  */
137 }
138 
139 
141 {
142  // bound the max value of chi2
143  if ( chi2 > 64 ) chi2 = 64;
144  // use 7 bits
145  uint32_t rawChi2 = lround( chi2 / 64. * ((1<<7)-1) );
146  // shift by 24 bits (recoFlag + chi2 + outOfTimeEnergy)
147  setFlags( (~(0x7F<<24) & flags()) | ((rawChi2 & 0x7F)<<24) );
148 }
149 
150 
151 void EcalRecHit::setTimeError( uint8_t timeErrBits )
152 {
153  // take the bits and put them in the right spot
154  setAux( (~0xFF & aux()) | timeErrBits );
155 }
156 
157 
159 {
160  uint32_t timeErrorBits = 0xFF & aux();
161  // all bits off --> time reco bailed out (return negative value)
162  if( (0xFF & timeErrorBits) == 0x00 )
163  return -1;
164  // all bits on --> time error over 5 ns (return large value)
165  if( (0xFF & timeErrorBits) == 0xFF )
166  return 10000;
167 
168  float LSB = 1.26008;
169  uint8_t exponent = timeErrorBits>>5;
170  uint8_t significand = timeErrorBits & ~(0x7<<5);
171  return pow(2.,exponent)*significand*LSB/1000.;
172 }
173 
174 
176 {
177  if(timeError() <= 0)
178  return false;
179  else
180  return true;
181 }
182 
183 
185 {
186  if(!isTimeValid())
187  return false;
188  if(timeError() >= 10000)
189  return false;
190 
191  return true;
192 }
193 
194 std::ostream& operator<<(std::ostream& s, const EcalRecHit& hit) {
195  if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalBarrel)
196  return s << EBDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
197  else if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalEndcap)
198  return s << EEDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
199  else if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalPreshower)
200  return s << ESDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
201  else
202  return s << "EcalRecHit undefined subdetector" ;
203 }
long int flag
Definition: mlp_lapack.h:47
bool isTimeErrorValid() const
Definition: EcalRecHit.cc:184
uint32_t aux() const
Definition: CaloRecHit.h:27
const DetId & detid() const
Definition: CaloRecHit.h:21
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
float time() const
Definition: CaloRecHit.h:20
bool isTimeValid() const
Definition: EcalRecHit.cc:175
float chi2Prob() const
Definition: EcalRecHit.cc:33
float outOfTimeChi2Prob() const
Definition: EcalRecHit.cc:44
bool isRecovered() const
Definition: EcalRecHit.cc:20
void setTimeError(uint8_t timeErrBits)
Definition: EcalRecHit.cc:151
void setRecoFlag(uint32_t flag)
Definition: EcalRecHit.cc:72
uint32_t recoFlag() const
Definition: EcalRecHit.h:78
float outOfTimeEnergy() const
Definition: EcalRecHit.cc:64
float outOfTimeChi2() const
Definition: EcalRecHit.cc:58
float energy() const
Definition: CaloRecHit.h:19
float chi2() const
Definition: EcalRecHit.cc:27
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:39
float timeError() const
Definition: EcalRecHit.cc:158
void setFlags(uint32_t flags)
Definition: CaloRecHit.h:23
void setChi2Prob(float chi2Prob)
Definition: EcalRecHit.cc:77
void setOutOfTimeChi2(float chi2)
Definition: EcalRecHit.cc:140
Definition: DetId.h:20
void setChi2(float chi2)
Definition: EcalRecHit.cc:97
void setOutOfTimeEnergy(float energy)
Definition: EcalRecHit.cc:107
void setAux(uint32_t value)
Definition: CaloRecHit.h:26
string s
Definition: asciidump.py:422
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
void setOutOfTimeChi2Prob(float chi2Prob)
Definition: EcalRecHit.cc:119