Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DATAFORMATS_CALORECHIT_CALORECHIT_H
0002 #define DATAFORMATS_CALORECHIT_CALORECHIT_H 1
0003 
0004 #include "DataFormats/DetId/interface/DetId.h"
0005 #include <ostream>
0006 
0007 #ifdef __CUDA_ARCH__
0008 __constant__
0009 #else
0010 constexpr
0011 #endif
0012     uint32_t calo_rechit_masks[] = {0x00000000u, 0x00000001u, 0x00000003u, 0x00000007u, 0x0000000fu, 0x0000001fu,
0013                                     0x0000003fu, 0x0000007fu, 0x000000ffu, 0x000001ffu, 0x000003ffu, 0x000007ffu,
0014                                     0x00000fffu, 0x00001fffu, 0x00003fffu, 0x00007fffu, 0x0000ffffu, 0x0001ffffu,
0015                                     0x0003ffffu, 0x0007ffffu, 0x000fffffu, 0x001fffffu, 0x003fffffu, 0x007fffffu,
0016                                     0x00ffffffu, 0x01ffffffu, 0x03ffffffu, 0x07ffffffu, 0x0fffffffu, 0x1fffffffu,
0017                                     0x3fffffffu, 0x7fffffffu, 0xffffffffu};
0018 
0019 /** \class CaloRecHit
0020  * 
0021  *\author J. Mans - Minnesota
0022  */
0023 class CaloRecHit {
0024 public:
0025   constexpr CaloRecHit() : energy_(0), time_(0), flags_(0), aux_(0) {}
0026   constexpr explicit CaloRecHit(const DetId& id, float energy, float time, uint32_t flags = 0, uint32_t aux = 0)
0027       : id_(id), energy_(energy), time_(time), flags_(flags), aux_(aux) {}
0028 
0029   constexpr float energy() const { return energy_; }
0030   constexpr void setEnergy(float energy) { energy_ = energy; }
0031   constexpr float time() const { return time_; }
0032   constexpr void setTime(float time) { time_ = time; }
0033   constexpr const DetId& detid() const { return id_; }
0034   constexpr uint32_t flags() const { return flags_; }
0035   constexpr void setFlags(uint32_t flags) { flags_ = flags; }
0036   constexpr void setFlagField(uint32_t value, int base, int width = 1) {
0037     value &= calo_rechit_masks[std::max(std::min(width, 32), 0)];
0038     value <<= std::max(std::min(base, 31), 0);
0039     // clear out the relevant bits
0040     uint32_t clear = calo_rechit_masks[std::max(std::min(width, 32), 0)];
0041     clear = clear << std::max(std::min(base, 31), 0);
0042     clear ^= 0xFFFFFFFFu;
0043     flags_ &= clear;
0044     flags_ |= value;
0045   }
0046   constexpr uint32_t flagField(int base, int width = 1) const {
0047     return (flags_ >> std::max(std::min(base, 31), 0)) & calo_rechit_masks[std::max(std::min(width, 32), 0)];
0048   }
0049   constexpr void setAux(uint32_t value) { aux_ = value; }
0050   constexpr uint32_t aux() const { return aux_; }
0051 
0052 private:
0053   DetId id_;
0054   float energy_;
0055   float time_;
0056   uint32_t flags_;
0057   uint32_t aux_;
0058 };
0059 
0060 std::ostream& operator<<(std::ostream& s, const CaloRecHit& hit);
0061 
0062 #endif