diff --git a/DataFormats/EcalRecHit/interface/EcalRecHit.h b/DataFormats/EcalRecHit/interface/EcalRecHit.h index 338afcb0d31fa..de75b78a00f40 100644 --- a/DataFormats/EcalRecHit/interface/EcalRecHit.h +++ b/DataFormats/EcalRecHit/interface/EcalRecHit.h @@ -13,144 +13,145 @@ * \author P. Meridiani INFN Roma1 */ -class EcalRecHit { -public: - typedef DetId key_type; - - // recHit flags - enum Flags { - kGood = 0, // channel ok, the energy and time measurement are reliable - kPoorReco, // the energy is available from the UncalibRecHit, but approximate (bad shape, large chi2) - kOutOfTime, // the energy is available from the UncalibRecHit (sync reco), but the event is out of time - kFaultyHardware, // The energy is available from the UncalibRecHit, channel is faulty at some hardware level (e.g. noisy) - kNoisy, // the channel is very noisy - kPoorCalib, // the energy is available from the UncalibRecHit, but the calibration of the channel is poor - kSaturated, // saturated channel (recovery not tried) - kLeadingEdgeRecovered, // saturated channel: energy estimated from the leading edge before saturation - kNeighboursRecovered, // saturated/isolated dead: energy estimated from neighbours - kTowerRecovered, // channel in TT with no data link, info retrieved from Trigger Primitive - kDead, // channel is dead and any recovery fails - kKilled, // MC only flag: the channel is killed in the real detector - kTPSaturated, // the channel is in a region with saturated TP - kL1SpikeFlag, // the channel is in a region with TP with sFGVB = 0 - kWeird, // the signal is believed to originate from an anomalous deposit (spike) - kDiWeird, // the signal is anomalous, and neighbors another anomalous signal - kHasSwitchToGain6, // at least one data frame is in G6 - kHasSwitchToGain1, // at least one data frame is in G1 - // - kUnknown // to ease the interface with functions returning flags. - }; - - // ES recHit flags - enum ESFlags { - kESGood, - kESDead, - kESHot, - kESPassBX, - kESTwoGoodRatios, - kESBadRatioFor12, - kESBadRatioFor23Upper, - kESBadRatioFor23Lower, - kESTS1Largest, - kESTS3Largest, - kESTS3Negative, - kESSaturated, - kESTS2Saturated, - kESTS3Saturated, - kESTS13Sigmas, - kESTS15Sigmas - }; +namespace io_v1 { + class EcalRecHit { + public: + typedef DetId key_type; + + // recHit flags + enum Flags { + kGood = 0, // channel ok, the energy and time measurement are reliable + kPoorReco, // the energy is available from the UncalibRecHit, but approximate (bad shape, large chi2) + kOutOfTime, // the energy is available from the UncalibRecHit (sync reco), but the event is out of time + kFaultyHardware, // The energy is available from the UncalibRecHit, channel is faulty at some hardware level (e.g. noisy) + kNoisy, // the channel is very noisy + kPoorCalib, // the energy is available from the UncalibRecHit, but the calibration of the channel is poor + kSaturated, // saturated channel (recovery not tried) + kLeadingEdgeRecovered, // saturated channel: energy estimated from the leading edge before saturation + kNeighboursRecovered, // saturated/isolated dead: energy estimated from neighbours + kTowerRecovered, // channel in TT with no data link, info retrieved from Trigger Primitive + kDead, // channel is dead and any recovery fails + kKilled, // MC only flag: the channel is killed in the real detector + kTPSaturated, // the channel is in a region with saturated TP + kL1SpikeFlag, // the channel is in a region with TP with sFGVB = 0 + kWeird, // the signal is believed to originate from an anomalous deposit (spike) + kDiWeird, // the signal is anomalous, and neighbors another anomalous signal + kHasSwitchToGain6, // at least one data frame is in G6 + kHasSwitchToGain1, // at least one data frame is in G1 + // + kUnknown // to ease the interface with functions returning flags. + }; + + // ES recHit flags + enum ESFlags { + kESGood, + kESDead, + kESHot, + kESPassBX, + kESTwoGoodRatios, + kESBadRatioFor12, + kESBadRatioFor23Upper, + kESBadRatioFor23Lower, + kESTS1Largest, + kESTS3Largest, + kESTS3Negative, + kESSaturated, + kESTS2Saturated, + kESTS3Saturated, + kESTS13Sigmas, + kESTS15Sigmas + }; + + EcalRecHit() : energy_(0), time_(0), flagBits_(0) {} + // by default a recHit is greated with no flag + explicit EcalRecHit(const DetId& id, float energy, float time, uint32_t extra = 0, uint32_t flagBits = 0) + : id_(id), energy_(energy), time_(time), flagBits_(flagBits), extra_(extra) {} + + float energy() const { return energy_; } + void setEnergy(float energy) { energy_ = energy; } + float time() const { return time_; } + void setTime(float time) { time_ = time; } + const DetId& detid() const { return id_; } + + /// get the id + // For the moment not returning a specific id for subdetector + // @TODO why this method?! should use detid() + DetId id() const { return DetId(detid()); } + + bool isRecovered() const { + return checkFlag(kLeadingEdgeRecovered) || checkFlag(kNeighboursRecovered) || checkFlag(kTowerRecovered); + } - EcalRecHit() : energy_(0), time_(0), flagBits_(0) {} - // by default a recHit is greated with no flag - explicit EcalRecHit(const DetId& id, float energy, float time, uint32_t extra = 0, uint32_t flagBits = 0) - : id_(id), energy_(energy), time_(time), flagBits_(flagBits), extra_(extra) {} + bool isTimeValid() const { return (this->timeError() > 0); } - float energy() const { return energy_; } - void setEnergy(float energy) { energy_ = energy; } - float time() const { return time_; } - void setTime(float time) { time_ = time; } - const DetId& detid() const { return id_; } + bool isTimeErrorValid() const { + if (!isTimeValid()) + return false; - /// get the id - // For the moment not returning a specific id for subdetector - // @TODO why this method?! should use detid() - DetId id() const { return DetId(detid()); } + if (timeError() >= 10000) + return false; - bool isRecovered() const { - return checkFlag(kLeadingEdgeRecovered) || checkFlag(kNeighboursRecovered) || checkFlag(kTowerRecovered); - } + return true; + } - bool isTimeValid() const { return (this->timeError() > 0); } + static inline uint32_t getMasked(uint32_t value, uint32_t offset, uint32_t width) { + return (value >> offset) & ((1 << width) - 1); + } - bool isTimeErrorValid() const { - if (!isTimeValid()) - return false; + static inline uint32_t setMasked(uint32_t value, uint32_t x, uint32_t offset, uint32_t width) { + const uint32_t mask = ((1 << width) - 1) << offset; + value &= ~mask; + value |= (x & ((1U << width) - 1)) << offset; + return value; + } - if (timeError() >= 10000) - return false; + static inline int getPower10(float e) { + static constexpr float p10[] = {1.e-2f, 1.e-1f, 1.f, 1.e1f, 1.e2f, 1.e3f, 1.e4f, 1.e5f, 1.e6f}; + int b = e < p10[4] ? 0 : 5; + for (; b < 9; ++b) + if (e < p10[b]) + break; + return b; + } - return true; - } - - static inline uint32_t getMasked(uint32_t value, uint32_t offset, uint32_t width) { - return (value >> offset) & ((1 << width) - 1); - } - - static inline uint32_t setMasked(uint32_t value, uint32_t x, uint32_t offset, uint32_t width) { - const uint32_t mask = ((1 << width) - 1) << offset; - value &= ~mask; - value |= (x & ((1U << width) - 1)) << offset; - return value; - } - - static inline int getPower10(float e) { - static constexpr float p10[] = {1.e-2f, 1.e-1f, 1.f, 1.e1f, 1.e2f, 1.e3f, 1.e4f, 1.e5f, 1.e6f}; - int b = e < p10[4] ? 0 : 5; - for (; b < 9; ++b) - if (e < p10[b]) - break; - return b; - } - - /* the new bit structure + /* the new bit structure * 0..6 - chi2 in time events (chi2()), offset=0, width=7 * 8..20 - energy uncertainty, offset=8, width=13 * 24..31 - timeError(), offset=24, width=8 */ - float chi2() const { - uint32_t rawChi2 = getMasked(extra_, 0, 7); - return (float)rawChi2 / (float)((1 << 7) - 1) * 64.; - } - - void setChi2(float chi2) { - // bound the max value of the chi2 - if (chi2 > 64) - chi2 = 64; - - // use 7 bits - uint32_t rawChi2 = lround(chi2 / 64. * ((1 << 7) - 1)); - extra_ = setMasked(extra_, rawChi2, 0, 7); - } - - float energyError() const { - uint32_t rawEnergy = getMasked(extra_, 8, 13); - uint16_t exponent = rawEnergy >> 10; - uint16_t significand = ~(0xE << 9) & rawEnergy; - return (float)significand * pow(10, exponent - 5); - } - - // set the energy uncertainty - // (only energy >= 0 will be stored) - void setEnergyError(float energy) { - uint32_t rawEnergy = 0; - if (energy > 0.001) { - uint16_t exponent = getPower10(energy); - static constexpr float ip10[] = {1.e5f, 1.e4f, 1.e3f, 1.e2f, 1.e1f, 1.e0f, 1.e-1f, 1.e-2f, 1.e-3f, 1.e-4}; - uint16_t significand = lround(energy * ip10[exponent]); - // use 13 bits (3 exponent, 10 significand) - rawEnergy = exponent << 10 | significand; - /* here for doc and regression test + float chi2() const { + uint32_t rawChi2 = getMasked(extra_, 0, 7); + return (float)rawChi2 / (float)((1 << 7) - 1) * 64.; + } + + void setChi2(float chi2) { + // bound the max value of the chi2 + if (chi2 > 64) + chi2 = 64; + + // use 7 bits + uint32_t rawChi2 = lround(chi2 / 64. * ((1 << 7) - 1)); + extra_ = setMasked(extra_, rawChi2, 0, 7); + } + + float energyError() const { + uint32_t rawEnergy = getMasked(extra_, 8, 13); + uint16_t exponent = rawEnergy >> 10; + uint16_t significand = ~(0xE << 9) & rawEnergy; + return (float)significand * pow(10, exponent - 5); + } + + // set the energy uncertainty + // (only energy >= 0 will be stored) + void setEnergyError(float energy) { + uint32_t rawEnergy = 0; + if (energy > 0.001) { + uint16_t exponent = getPower10(energy); + static constexpr float ip10[] = {1.e5f, 1.e4f, 1.e3f, 1.e2f, 1.e1f, 1.e0f, 1.e-1f, 1.e-2f, 1.e-3f, 1.e-4}; + uint16_t significand = lround(energy * ip10[exponent]); + // use 13 bits (3 exponent, 10 significand) + rawEnergy = exponent << 10 | significand; + /* here for doc and regression test uint16_t exponent_old = lround(floor(log10(energy))) + 3; uint16_t significand_old = lround(energy/pow(10, exponent - 5)); std::cout << energy << ' ' << exponent << ' ' << significand @@ -158,88 +159,90 @@ class EcalRecHit { assert(exponent==exponent_old); assert(significand==significand_old); */ - } + } - extra_ = setMasked(extra_, rawEnergy, 8, 13); - } + extra_ = setMasked(extra_, rawEnergy, 8, 13); + } - float timeError() const { - uint32_t timeErrorBits = getMasked(extra_, 24, 8); - // all bits off --> time reco bailed out (return negative value) - if ((0xFF & timeErrorBits) == 0x00) - return -1; - // all bits on --> time error over 5 ns (return large value) - if ((0xFF & timeErrorBits) == 0xFF) - return 10000; + float timeError() const { + uint32_t timeErrorBits = getMasked(extra_, 24, 8); + // all bits off --> time reco bailed out (return negative value) + if ((0xFF & timeErrorBits) == 0x00) + return -1; + // all bits on --> time error over 5 ns (return large value) + if ((0xFF & timeErrorBits) == 0xFF) + return 10000; + + float LSB = 1.26008; + uint8_t exponent = timeErrorBits >> 5; + uint8_t significand = timeErrorBits & ~(0x7 << 5); + return pow(2., exponent) * significand * LSB / 1000.; + } - float LSB = 1.26008; - uint8_t exponent = timeErrorBits >> 5; - uint8_t significand = timeErrorBits & ~(0x7 << 5); - return pow(2., exponent) * significand * LSB / 1000.; - } + void setTimeError(uint8_t timeErrBits) { extra_ = setMasked(extra_, timeErrBits & 0xFF, 24, 8); } - void setTimeError(uint8_t timeErrBits) { extra_ = setMasked(extra_, timeErrBits & 0xFF, 24, 8); } + /// set the flags (from Flags or ESFlags) + void setFlag(int flag) { flagBits_ |= (0x1 << flag); } + void unsetFlag(int flag) { flagBits_ &= ~(0x1 << flag); } - /// set the flags (from Flags or ESFlags) - void setFlag(int flag) { flagBits_ |= (0x1 << flag); } - void unsetFlag(int flag) { flagBits_ &= ~(0x1 << flag); } + /// check if the flag is true + bool checkFlag(int flag) const { return flagBits_ & (0x1 << flag); } - /// check if the flag is true - bool checkFlag(int flag) const { return flagBits_ & (0x1 << flag); } + /// check if one of the flags in a set is true + bool checkFlags(const std::vector& flagsvec) const { + for (std::vector::const_iterator flagPtr = flagsvec.begin(); flagPtr != flagsvec.end(); + ++flagPtr) { // check if one of the flags is up - /// check if one of the flags in a set is true - bool checkFlags(const std::vector& flagsvec) const { - for (std::vector::const_iterator flagPtr = flagsvec.begin(); flagPtr != flagsvec.end(); - ++flagPtr) { // check if one of the flags is up + if (checkFlag(*flagPtr)) + return true; + } - if (checkFlag(*flagPtr)) - return true; + return false; } - return false; - } + uint32_t flagsBits() const { return flagBits_; } - uint32_t flagsBits() const { return flagBits_; } + /// apply a bitmask to our flags. Experts only + bool checkFlagMask(uint32_t mask) const { return flagBits_ & mask; } - /// apply a bitmask to our flags. Experts only - bool checkFlagMask(uint32_t mask) const { return flagBits_ & mask; } + /// DEPRECATED provided for temporary backward compatibility + Flags recoFlag() const { + for (int i = kUnknown;; --i) { + if (checkFlag(i)) + return Flags(i); + if (i == 0) + break; + } - /// DEPRECATED provided for temporary backward compatibility - Flags recoFlag() const { - for (int i = kUnknown;; --i) { - if (checkFlag(i)) - return Flags(i); - if (i == 0) - break; + // no flag assigned, assume good + return kGood; } - // no flag assigned, assume good - return kGood; - } - - // For CC Timing reco - float nonCorrectedTime() const { - uint8_t jitterErrorBits = getMasked(extra_, 24, 8); - float encBits = static_cast(jitterErrorBits); - float decTimeDif = ecalcctiming::clockToNS * (ecalcctiming::encodingOffest - encBits / ecalcctiming::encodingValue); - float nonCorrectedTime = - (encBits > 1 && encBits < 254) ? ecalcctiming::nonCorrectedSlope * time_ + decTimeDif : -30.0; - return nonCorrectedTime; - } - -private: - // from calorechit - DetId id_; - float energy_; - float time_; + // For CC Timing reco + float nonCorrectedTime() const { + uint8_t jitterErrorBits = getMasked(extra_, 24, 8); + float encBits = static_cast(jitterErrorBits); + float decTimeDif = + ecalcctiming::clockToNS * (ecalcctiming::encodingOffest - encBits / ecalcctiming::encodingValue); + float nonCorrectedTime = + (encBits > 1 && encBits < 254) ? ecalcctiming::nonCorrectedSlope * time_ + decTimeDif : -30.0; + return nonCorrectedTime; + } - /// store rechit condition (see Flags enum) in a bit-wise way - uint32_t flagBits_; + private: + // from calorechit + DetId id_; + float energy_; + float time_; - // packed uint32_t for timeError, chi2, energyError - uint32_t extra_; -}; + /// store rechit condition (see Flags enum) in a bit-wise way + uint32_t flagBits_; -std::ostream& operator<<(std::ostream& s, const EcalRecHit& hit); + // packed uint32_t for timeError, chi2, energyError + uint32_t extra_; + }; + std::ostream& operator<<(std::ostream& s, const EcalRecHit& hit); +} // namespace io_v1 +using EcalRecHit = io_v1::EcalRecHit; #endif diff --git a/DataFormats/EcalRecHit/interface/EcalRecHitComparison.h b/DataFormats/EcalRecHit/interface/EcalRecHitComparison.h index 11d781796d3cc..f707f3e5f090d 100644 --- a/DataFormats/EcalRecHit/interface/EcalRecHitComparison.h +++ b/DataFormats/EcalRecHit/interface/EcalRecHitComparison.h @@ -5,15 +5,16 @@ //ordering capability mandatory for lazy getter framework // Comparison operators -inline bool operator<(const EcalRecHit& one, const EcalRecHit& other) { - if (one.detid() == other.detid()) { - return one.energy() < other.energy(); +namespace io_v1 { + inline bool operator<(const EcalRecHit& one, const EcalRecHit& other) { + if (one.detid() == other.detid()) { + return one.energy() < other.energy(); + } + return one.detid() < other.detid(); } - return one.detid() < other.detid(); -} -inline bool operator<(const EcalRecHit& one, const uint32_t& detid) { return one.detid() < detid; } - -inline bool operator<(const uint32_t& detid, const EcalRecHit& other) { return detid < other.detid(); } + inline bool operator<(const EcalRecHit& one, const uint32_t& detid) { return one.detid() < detid; } + inline bool operator<(const uint32_t& detid, const EcalRecHit& other) { return detid < other.detid(); } +} // namespace io_v1 #endif diff --git a/DataFormats/EcalRecHit/interface/EcalRecHitFwd.h b/DataFormats/EcalRecHit/interface/EcalRecHitFwd.h index 6f8e6f8e2e70c..be0a6fa491187 100644 --- a/DataFormats/EcalRecHit/interface/EcalRecHitFwd.h +++ b/DataFormats/EcalRecHit/interface/EcalRecHitFwd.h @@ -1,6 +1,9 @@ #ifndef DataFormats_EcalRecHit_EcalRecHitFwd_h #define DataFormats_EcalRecHit_EcalRecHitFwd_h -class EcalRecHit; +namespace io_v1 { + class EcalRecHit; +} +using EcalRecHit = io_v1::EcalRecHit; #endif diff --git a/DataFormats/EcalRecHit/src/EcalRecHit.cc b/DataFormats/EcalRecHit/src/EcalRecHit.cc index f01316953c5c4..678492ad436f3 100644 --- a/DataFormats/EcalRecHit/src/EcalRecHit.cc +++ b/DataFormats/EcalRecHit/src/EcalRecHit.cc @@ -6,13 +6,15 @@ #include #include -std::ostream& operator<<(std::ostream& s, const EcalRecHit& hit) { - if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalBarrel) - return s << EBDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns"; - else if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalEndcap) - return s << EEDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns"; - else if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalPreshower) - return s << ESDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns"; - else - return s << "EcalRecHit undefined subdetector"; -} +namespace io_v1 { + std::ostream& operator<<(std::ostream& s, const EcalRecHit& hit) { + if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalBarrel) + return s << EBDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns"; + else if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalEndcap) + return s << EEDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns"; + else if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalPreshower) + return s << ESDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns"; + else + return s << "EcalRecHit undefined subdetector"; + } +} // namespace io_v1 diff --git a/DataFormats/EcalRecHit/src/classes_def.xml b/DataFormats/EcalRecHit/src/classes_def.xml index d7327bf1d9808..f5bcfc98665d5 100644 --- a/DataFormats/EcalRecHit/src/classes_def.xml +++ b/DataFormats/EcalRecHit/src/classes_def.xml @@ -11,33 +11,31 @@ - - - - + + - - + + - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + diff --git a/DataFormats/METReco/src/classes_def.xml b/DataFormats/METReco/src/classes_def.xml index efa04e0d8c561..de66197fad8e9 100644 --- a/DataFormats/METReco/src/classes_def.xml +++ b/DataFormats/METReco/src/classes_def.xml @@ -169,7 +169,7 @@ - + @@ -192,7 +192,7 @@ - + diff --git a/DataFormats/PatCandidates/src/classes_def_objects.xml b/DataFormats/PatCandidates/src/classes_def_objects.xml index dd1e2c2c5f761..12123aad7b27d 100644 --- a/DataFormats/PatCandidates/src/classes_def_objects.xml +++ b/DataFormats/PatCandidates/src/classes_def_objects.xml @@ -17,7 +17,7 @@ - + @@ -90,7 +90,7 @@ - +