File indexing completed on 2024-04-06 12:04:53
0001 #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
0002 #include <limits>
0003 namespace reco {
0004
0005 void PFRecHit::addNeighbour(short x, short y, short z, unsigned int ref) {
0006
0007
0008
0009
0010
0011
0012
0013
0014 unsigned short absx = std::abs(x);
0015 unsigned short absy = std::abs(y);
0016 unsigned short absz = std::abs(z);
0017
0018 unsigned short bitmask = 0;
0019
0020 if (x > 0)
0021 bitmask = bitmask | 1;
0022 bitmask = bitmask | (absx << 1);
0023 if (y > 0)
0024 bitmask = bitmask | (1 << 4);
0025 bitmask = bitmask | (absy << 5);
0026 if (z > 0)
0027 bitmask = bitmask | (1 << 8);
0028 bitmask = bitmask | (absz << 9);
0029
0030 auto pos = neighbours_.size();
0031 if (z == 0) {
0032 pos = neighbours8_++;
0033
0034 if (absx + absy == 1)
0035 pos = neighbours4_++;
0036 }
0037 neighbours_.insert(neighbours_.begin() + pos, ref);
0038 neighbourInfos_.insert(neighbourInfos_.begin() + pos, bitmask);
0039
0040 assert(neighbours4_ < 5);
0041 assert(neighbours8_ < 9);
0042 assert(neighbours4_ <= neighbours8_);
0043 assert(neighbours8_ <= neighbours_.size());
0044 }
0045
0046 unsigned int PFRecHit::getNeighbour(short x, short y, short z) const {
0047 unsigned short absx = abs(x);
0048 unsigned short absy = abs(y);
0049 unsigned short absz = abs(z);
0050
0051 unsigned short bitmask = 0;
0052
0053 if (x > 0)
0054 bitmask = bitmask | 1;
0055 bitmask = bitmask | (absx << 1);
0056 if (y > 0)
0057 bitmask = bitmask | (1 << 4);
0058 bitmask = bitmask | (absy << 5);
0059 if (z > 0)
0060 bitmask = bitmask | (1 << 8);
0061 bitmask = bitmask | (absz << 9);
0062
0063 for (unsigned int i = 0; i < neighbourInfos_.size(); ++i) {
0064 if (neighbourInfos_[i] == bitmask)
0065 return neighbours_[i];
0066 }
0067 return std::numeric_limits<unsigned int>::max();
0068 }
0069
0070 }
0071
0072 std::ostream& operator<<(std::ostream& out, const reco::PFRecHit& hit) {
0073 if (!out)
0074 return out;
0075
0076 out << "hit id:" << hit.detId() << " l:" << hit.layer() << " E:" << hit.energy() << " t:" << hit.time();
0077 if (hit.hasCaloCell()) {
0078 auto const& pos = hit.positionREP();
0079 out << " rep:" << pos.rho() << "," << pos.eta() << "," << pos.phi() << "|";
0080 }
0081 return out;
0082 }