Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:40

0001 #include "DataFormats/HGCRecHit/interface/HGCUncalibratedRecHit.h"
0002 #include <cmath>
0003 
0004 HGCUncalibratedRecHit::HGCUncalibratedRecHit()
0005     : amplitude_(0.),
0006       pedestal_(0.),
0007       jitter_(0.),
0008       chi2_(10000.),
0009       OOTamplitude_(0.),
0010       OOTchi2_(10000.),
0011       flags_(0),
0012       aux_(0) {}
0013 
0014 HGCUncalibratedRecHit::HGCUncalibratedRecHit(
0015     const DetId& id, float ampl, float ped, float jit, float chi2, uint32_t flags, uint32_t aux)
0016     : amplitude_(ampl),
0017       pedestal_(ped),
0018       jitter_(jit),
0019       chi2_(chi2),
0020       OOTamplitude_(0.),
0021       OOTchi2_(10000.),
0022       flags_(flags),
0023       aux_(aux),
0024       id_(id) {}
0025 
0026 HGCUncalibratedRecHit::~HGCUncalibratedRecHit() {}
0027 
0028 bool HGCUncalibratedRecHit::isSaturated() const { return HGCUncalibratedRecHit::checkFlag(kSaturated); }
0029 
0030 float HGCUncalibratedRecHit::jitterError() const {
0031   // stored in ps, but return BXs to match with jitter units
0032   uint32_t jitterErrorBits = 0xFF & aux_;
0033   // all bits off --> time reco bailed out (return negative value)
0034   if ((0xFF & jitterErrorBits) == 0x00)
0035     return -1;
0036   // all bits on  --> time error over 5 ns (return large value)
0037   if ((0xFF & jitterErrorBits) == 0xFF)
0038     return 10000;
0039 
0040   float LSB = 1.26008;
0041   uint8_t exponent = jitterErrorBits >> 5;
0042   uint8_t significand = jitterErrorBits & ~(0x7 << 5);
0043   return (float)(pow(2., exponent) * significand * LSB) / (25. * 1000);
0044 }
0045 
0046 void HGCUncalibratedRecHit::setJitterError(float jitterErr) {
0047   // use 8 bits (3 exp, 5 mant) and store in ps
0048   // has range of 5 ps - 5000 ps
0049   // expect input in BX units
0050   // all bits off --> time reco bailed out
0051   if (jitterErr < 0) {
0052     aux_ = (~0xFF & aux_);
0053     return;
0054   }
0055   // all bits on  --> time error over 5 ns
0056   if (25 * jitterErr >= 5) {
0057     aux_ = (0xFF | aux_);
0058     return;
0059   }
0060 
0061   float LSB = 1.26008;
0062   float quantityInLSB = (1000 * 25 * jitterErr) / LSB;
0063   int log2OfQuantity = (int)(log2(quantityInLSB));
0064   int exponentTmp = log2OfQuantity - 4;
0065   uint8_t exponent = 0;
0066   if (exponentTmp > 0)
0067     exponent = exponentTmp;
0068   uint8_t significand = (int)(lround(quantityInLSB / pow(2., exponent)));
0069   uint32_t jitterErrorBits = exponent << 5 | significand;
0070 
0071   if ((0xFF & jitterErrorBits) == 0xFF)
0072     jitterErrorBits = 0xFE;
0073   if ((0xFF & jitterErrorBits) == 0x00)
0074     jitterErrorBits = 0x01;
0075 
0076   aux_ = (~0xFF & aux_) | (jitterErrorBits & 0xFF);
0077 }
0078 
0079 bool HGCUncalibratedRecHit::isJitterValid() const {
0080   if (jitterError() <= 0)
0081     return false;
0082   else
0083     return true;
0084 }
0085 
0086 bool HGCUncalibratedRecHit::isJitterErrorValid() const {
0087   if (!isJitterValid())
0088     return false;
0089   if (jitterError() >= 10000)
0090     return false;
0091 
0092   return true;
0093 }
0094 
0095 uint8_t HGCUncalibratedRecHit::jitterErrorBits() const {
0096   uint8_t jitterErrorBits = 0xFF & aux_;
0097   return jitterErrorBits;
0098 }
0099 
0100 void HGCUncalibratedRecHit::setFlagBit(HGCUncalibratedRecHit::Flags flag) {
0101   if (flag == kGood) {
0102     //then set all bits to zero;
0103     flags_ = 0;
0104     return;
0105   }
0106   // else set the flagbit
0107   flags_ |= 0x1 << flag;
0108 }
0109 
0110 bool HGCUncalibratedRecHit::checkFlag(HGCUncalibratedRecHit::Flags flag) const {
0111   if (flag == kGood) {
0112     if (!flags_)
0113       return true;
0114     else
0115       return false;
0116   }  // if all flags are unset, then hit is good
0117   return flags_ & (0x1 << flag);
0118 }