CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalRecHit.h
Go to the documentation of this file.
1 #ifndef DATAFORMATS_ECALRECHIT_H
2 #define DATAFORMATS_ECALRECHIT_H 1
3 
6 
7 #include <vector>
8 #include <math.h>
9 
15 class EcalRecHit {
16 public:
17  typedef DetId key_type;
18 
19  // recHit flags
20  enum Flags {
21  kGood=0, // channel ok, the energy and time measurement are reliable
22  kPoorReco, // the energy is available from the UncalibRecHit, but approximate (bad shape, large chi2)
23  kOutOfTime, // the energy is available from the UncalibRecHit (sync reco), but the event is out of time
24  kFaultyHardware, // The energy is available from the UncalibRecHit, channel is faulty at some hardware level (e.g. noisy)
25  kNoisy, // the channel is very noisy
26  kPoorCalib, // the energy is available from the UncalibRecHit, but the calibration of the channel is poor
27  kSaturated, // saturated channel (recovery not tried)
28  kLeadingEdgeRecovered, // saturated channel: energy estimated from the leading edge before saturation
29  kNeighboursRecovered, // saturated/isolated dead: energy estimated from neighbours
30  kTowerRecovered, // channel in TT with no data link, info retrieved from Trigger Primitive
31  kDead, // channel is dead and any recovery fails
32  kKilled, // MC only flag: the channel is killed in the real detector
33  kTPSaturated, // the channel is in a region with saturated TP
34  kL1SpikeFlag, // the channel is in a region with TP with sFGVB = 0
35  kWeird, // the signal is believed to originate from an anomalous deposit (spike)
36  kDiWeird, // the signal is anomalous, and neighbors another anomalous signal
37  kHasSwitchToGain6, // at least one data frame is in G6
38  kHasSwitchToGain1, // at least one data frame is in G1
39  //
40  kUnknown // to ease the interface with functions returning flags.
41  };
42 
43  // ES recHit flags
44  enum ESFlags {
61  };
62 
63  EcalRecHit(): energy_(0), time_(0), flagBits_(0) {}
64  // by default a recHit is greated with no flag
65  explicit EcalRecHit(const DetId& id, float energy, float time, uint32_t extra = 0, uint32_t flagBits = 0):
66  id_(id), energy_(energy), time_(time), flagBits_(flagBits), extra_(extra) {}
67 
68  float energy() const { return energy_; }
69  void setEnergy(float energy) { energy_=energy; }
70  float time() const { return time_; }
71  const DetId& detid() const { return id_; }
72 
74  // For the moment not returning a specific id for subdetector
75  // @TODO why this method?! should use detid()
76  DetId id() const { return DetId(detid());}
77 
78  bool isRecovered() const {
82  }
83 
84  bool isTimeValid() const { return (this->timeError() > 0); }
85 
86  bool isTimeErrorValid() const {
87  if(!isTimeValid())
88  return false;
89 
90  if(timeError() >= 10000)
91  return false;
92 
93  return true;
94  }
95 
96  static inline uint32_t getMasked(uint32_t value, uint32_t offset, uint32_t width) {
97  return (value >> offset) & ((1 << width) - 1);
98  }
99 
100  static inline uint32_t setMasked(uint32_t value, uint32_t x, uint32_t offset, uint32_t width) {
101  const uint32_t mask = ((1 << width) - 1) << offset;
102  value &= ~mask;
103  value |= (x & ((1U << width) - 1)) << offset;
104  return value;
105  }
106 
107 
108  /* the new bit structure
109  * 0..6 - chi2 in time events (chi2()), offset=0, width=7
110  * 8..20 - energy in out-of-time (outOfTimeEnergy()), offset=8, width=13
111  * 24..31 - timeError(), offset=24, width=8
112  */
113  float chi2() const {
114  uint32_t rawChi2 = getMasked(extra_, 0, 7);
115  return (float)rawChi2 / (float)((1<<7)-1) * 64.;
116  }
117 
118  void setChi2(float chi2) {
119  // bound the max value of the chi2
120  if (chi2 > 64) chi2 = 64;
121 
122  // use 7 bits
123  uint32_t rawChi2 = lround(chi2 / 64. * ((1<<7)-1));
124  extra_ = setMasked(extra_, rawChi2, 0, 7);
125  }
126 
127 
128  float outOfTimeEnergy() const {
129  uint32_t rawEnergy = getMasked(extra_, 8, 13);
130  uint16_t exponent = rawEnergy >> 10;
131  uint16_t significand = ~(0xE<<9) & rawEnergy;
132  return (float) significand*pow(10,exponent-5);
133  }
134 
135  // set the energy for out of time events
136  // (only energy >= 0 will be stored)
138  uint32_t rawEnergy = 0;
139  if (energy > 0.001) {
140  uint16_t exponent = lround(floor(log10(energy))) + 3;
141  uint16_t significand = lround(energy/pow(10, exponent - 5));
142  // use 13 bits (3 exponent, 10 significand)
143  rawEnergy = exponent << 10 | significand;
144  }
145 
146  extra_ = setMasked(extra_, rawEnergy, 8, 13);
147  }
148 
149  float timeError() const {
150  uint32_t timeErrorBits = getMasked(extra_, 24, 8);
151  // all bits off --> time reco bailed out (return negative value)
152  if( (0xFF & timeErrorBits) == 0x00 )
153  return -1;
154  // all bits on --> time error over 5 ns (return large value)
155  if( (0xFF & timeErrorBits) == 0xFF )
156  return 10000;
157 
158  float LSB = 1.26008;
159  uint8_t exponent = timeErrorBits>>5;
160  uint8_t significand = timeErrorBits & ~(0x7<<5);
161  return pow(2.,exponent)*significand*LSB/1000.;
162  }
163 
164  void setTimeError(uint8_t timeErrBits) {
165  extra_ = setMasked(extra_, timeErrBits & 0xFF, 24, 8);
166  }
167 
168  float outOfTimeChi2() const { return 0; }
169  void setOutOfTimeChi2(short chi2) { /* not used */ }
170 
172  void setFlag(int flag) {flagBits_|= (0x1 << flag);}
173  void unsetFlag(int flag) {flagBits_ &= ~(0x1 << flag);}
174 
176  bool checkFlag(int flag) const {return flagBits_ & ( 0x1<<flag);}
177 
179  bool checkFlags(const std::vector<int>& flagsvec) const {
180  for (std::vector<int>::const_iterator flagPtr = flagsvec.begin();
181  flagPtr!= flagsvec.end(); ++flagPtr) { // check if one of the flags is up
182 
183  if (checkFlag(*flagPtr)) return true;
184  }
185 
186  return false;
187  }
188 
190  bool checkFlagMask(uint32_t mask) const { return flagBits_&mask; }
191 
193  Flags recoFlag() const {
194  for (int i=kUnknown; ; --i){
195  if (checkFlag(i)) return Flags(i);
196  if (i==0) break;
197  }
198 
199  // no flag assigned, assume good
200  return kGood;
201  }
202 
203 private:
204  // from calorechit
206  float energy_;
207  float time_;
208 
210  uint32_t flagBits_;
211 
212  // packed uint32_t for timeError, chi2, outOfTimeEnergy
213  uint32_t extra_;
214 };
215 
216 std::ostream& operator<<(std::ostream& s, const EcalRecHit& hit);
217 
218 #endif
int i
Definition: DBlmapReader.cc:9
void unsetFlag(int flag)
Definition: EcalRecHit.h:173
bool isTimeErrorValid() const
Definition: EcalRecHit.h:86
bool checkFlags(const std::vector< int > &flagsvec) const
check if one of the flags in a set is true
Definition: EcalRecHit.h:179
static uint32_t setMasked(uint32_t value, uint32_t x, uint32_t offset, uint32_t width)
Definition: EcalRecHit.h:100
const DetId & detid() const
Definition: EcalRecHit.h:71
float time() const
Definition: EcalRecHit.h:70
void setFlag(int flag)
set the flags (from Flags or ESFlags)
Definition: EcalRecHit.h:172
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
bool isTimeValid() const
Definition: EcalRecHit.h:84
bool isRecovered() const
Definition: EcalRecHit.h:78
void setTimeError(uint8_t timeErrBits)
Definition: EcalRecHit.h:164
float time_
Definition: EcalRecHit.h:207
float outOfTimeEnergy() const
Definition: EcalRecHit.h:128
bool checkFlag(int flag) const
check if the flag is true
Definition: EcalRecHit.h:176
float outOfTimeChi2() const
Definition: EcalRecHit.h:168
float chi2() const
Definition: EcalRecHit.h:113
float energy() const
Definition: EcalRecHit.h:68
unsigned int offset(bool)
float timeError() const
Definition: EcalRecHit.h:149
Definition: DetId.h:18
static uint32_t getMasked(uint32_t value, uint32_t offset, uint32_t width)
Definition: EcalRecHit.h:96
DetId id() const
get the id
Definition: EcalRecHit.h:76
void setEnergy(float energy)
Definition: EcalRecHit.h:69
void setOutOfTimeChi2(short chi2)
Definition: EcalRecHit.h:169
Flags recoFlag() const
DEPRECATED provided for temporary backward compatibility.
Definition: EcalRecHit.h:193
EcalRecHit(const DetId &id, float energy, float time, uint32_t extra=0, uint32_t flagBits=0)
Definition: EcalRecHit.h:65
bool checkFlagMask(uint32_t mask) const
apply a bitmask to our flags. Experts only
Definition: EcalRecHit.h:190
float energy_
Definition: EcalRecHit.h:206
void setChi2(float chi2)
Definition: EcalRecHit.h:118
void setOutOfTimeEnergy(float energy)
Definition: EcalRecHit.h:137
uint32_t extra_
Definition: EcalRecHit.h:213
DetId key_type
Definition: EcalRecHit.h:17
DetId id_
Definition: EcalRecHit.h:205
Definition: DDAxes.h:10
uint32_t flagBits_
store rechit condition (see Flags enum) in a bit-wise way
Definition: EcalRecHit.h:210
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40