File indexing completed on 2024-04-06 12:04:05
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
0031 uint32_t jitterErrorBits = 0xFF & aux_;
0032
0033 if ((0xFF & jitterErrorBits) == 0x00)
0034 return -1;
0035
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
0047
0048
0049
0050 if (jitterErr <= 0) {
0051 aux_ = (~0xFF & aux_);
0052 return;
0053 }
0054
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
0102 flags_ = 0;
0103 return;
0104 }
0105
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 }
0116 return flags_ & (0x1 << flag);
0117 }
0118
0119
0120 float EcalUncalibratedRecHit::nonCorrectedTime() const {
0121 float encBits = static_cast<float>(jitterErrorBits());
0122 float decJitter =
0123 ecalcctiming::nonCorrectedSlope * jitter_ + ecalcctiming::encodingOffest - encBits / ecalcctiming::encodingValue;
0124 float nonCorrectedTime = (encBits > 1 && encBits < 254) ? ecalcctiming::clockToNS * decJitter : -30.0;
0125 return nonCorrectedTime;
0126 }
0127
0128 void EcalUncalibratedRecHit::setNonCorrectedTime(const float correctedJitter, const float nonCorrectedJitter) {
0129 float fDiff = ecalcctiming::nonCorrectedSlope * correctedJitter - nonCorrectedJitter + ecalcctiming::encodingOffest;
0130 int encBits = std::floor((fDiff * ecalcctiming::encodingValue) + 0.5);
0131 int bits = (encBits < 1) ? 1 : (encBits > 254) ? 254 : encBits;
0132 aux_ = (~0xFF & aux_) | (static_cast<uint8_t>(bits) & 0xFF);
0133 }