Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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