Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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     //bitmask interface  to accomodate more advanced naighbour finding [i.e in z as well]
0007     //bit 0 side for eta [0 for <=0 , 1 for >0]
0008     //bits 1,2,3 : abs(eta) wrt the center
0009     //bit 4 side for phi
0010     //bits 5,6,7 : abs(phi) wrt the center
0011     //bit 8 side for z
0012     //bits 9,10,11 : abs(z) wrt the center
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       //find only the 4 neighbours
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 }  // namespace reco
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 }