test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFRecHit.cc
Go to the documentation of this file.
2 using namespace reco;
3 using namespace std;
4 
5 #include "vdt/vdtMath.h"
6 #include "Math/GenVector/etaMax.h"
7 
8 const unsigned PFRecHit::nCorners_ = 4;
9 
10 namespace {
11 
12  // an implementation of Eta_FromRhoZ of root libraries using vdt
13  template<typename Scalar>
14  inline Scalar Eta_FromRhoZ_fast(Scalar rho, Scalar z) {
15  using namespace ROOT::Math;
16  // value to control Taylor expansion of sqrt
17  const Scalar big_z_scaled =
18  std::pow(std::numeric_limits<Scalar>::epsilon(),static_cast<Scalar>(-.25));
19  if (rho > 0) {
20  Scalar z_scaled = z/rho;
21  if (std::fabs(z_scaled) < big_z_scaled) {
22  return vdt::fast_log(z_scaled+std::sqrt(z_scaled*z_scaled+1.0));
23  } else {
24  // apply correction using first order Taylor expansion of sqrt
25  return z>0 ? vdt::fast_log(2.0*z_scaled + 0.5/z_scaled) : -vdt::fast_log(-2.0*z_scaled);
26  }
27  }
28  // case vector has rho = 0
29  else if (z==0) {
30  return 0;
31  }
32  else if (z>0) {
33  return z + etaMax<Scalar>();
34  }
35  else {
36  return z - etaMax<Scalar>();
37  }
38  }
39 
40  inline void calculateREP(const math::XYZPoint& pos, double& rho, double& eta, double& phi) {
41  const double z = pos.z();
42  rho = pos.Rho();
43  eta = Eta_FromRhoZ_fast<double>(rho,z);
44  phi = (pos.x()==0 && pos.y()==0) ? 0 : vdt::fast_atan2(pos.y(), pos.x());
45  }
46 
47 }
48 
50  detId_(0),
52  energy_(0.),
53  time_(-1.),
54  depth_(0),
55  position_(math::XYZPoint(0.,0.,0.))
56 {
57 
58  cornersxyz_.reserve( nCorners_ );
59  for(unsigned i=0; i<nCorners_; i++) {
60  cornersxyz_.push_back( position_ );
61  }
63 }
64 
65 
66 PFRecHit::PFRecHit(unsigned detId,
67  PFLayer::Layer layer,
68  double energy,
69  const math::XYZPoint& position,
70  const math::XYZVector& axisxyz,
71  const vector< math::XYZPoint >& cornersxyz) :
72  detId_(detId),
73  layer_(layer),
74  energy_(energy),
75  time_(-1.),
76  depth_(0),
77  position_(position),
78  axisxyz_(axisxyz),
79  cornersxyz_(cornersxyz)
80 {
82 }
83 
84 PFRecHit::PFRecHit(unsigned detId,
85  PFLayer::Layer layer,
86  double energy,
87  double posx, double posy, double posz,
88  double axisx, double axisy, double axisz) :
89 
90  detId_(detId),
91  layer_(layer),
92  energy_(energy),
93  time_(-1.),
94  depth_(0),
95  position_(posx, posy, posz),
96  axisxyz_(axisx, axisy, axisz) {
97 
98  cornersxyz_.reserve( nCorners_ );
99  for(unsigned i=0; i<nCorners_; i++) {
100  cornersxyz_.push_back( position_ );
101  }
102 
104 
105 }
106 
107 
108 
109 
110 void PFRecHit::setNWCorner( double posx, double posy, double posz ) {
111  setCorner(0, posx, posy, posz);
112 }
113 
114 
115 void PFRecHit::setSWCorner( double posx, double posy, double posz ) {
116  setCorner(1, posx, posy, posz);
117 }
118 
119 
120 void PFRecHit::setSECorner( double posx, double posy, double posz ) {
121  setCorner(2, posx, posy, posz);
122 }
123 
124 
125 void PFRecHit::setNECorner( double posx, double posy, double posz ) {
126  setCorner(3, posx, posy, posz);
127 }
128 
129 
130 void PFRecHit::setCorner( unsigned i, double posx, double posy, double posz ) {
131  assert( cornersxyz_.size() == nCorners_);
132  assert( i<cornersxyz_.size() );
133  double rho(0), eta(0), phi(0);
134 
135  cornersxyz_[i] = math::XYZPoint( posx, posy, posz);
136  const auto& corner = cornersxyz_[i];
137  calculateREP(corner, rho, eta, phi);
138  cornersrep_[i] = REPPoint( rho,
139  eta,
140  phi );
141 }
142 
143 void
145  double rho(0), eta(0), phi(0);
146  calculateREP(position_,rho,eta,phi);
147 
148  positionrep_.SetCoordinates( rho,
149  eta,
150  phi );
151  cornersrep_.resize(cornersxyz_.size());
152  for( unsigned i = 0; i < cornersxyz_.size(); ++i ) {
153  const auto& corner = cornersxyz_[i];
154  calculateREP(corner,rho,eta,phi);
155  cornersrep_[i].SetCoordinates( rho,
156  eta,
157  phi );
158  }
159 }
160 
161 void PFRecHit::addNeighbour(short x,short y,short z,const PFRecHitRef& ref) {
162  //bitmask interface to accomodate more advanced naighbour finding [i.e in z as well]
163  //bit 0 side for eta [0 for <=0 , 1 for >0]
164  //bits 1,2,3 : abs(eta) wrt the center
165  //bit 4 side for phi
166  //bits 5,6,7 : abs(phi) wrt the center
167  //bit 8 side for z
168  //bits 9,10,11 : abs(z) wrt the center
169 
170  unsigned short absx = std::abs(x);
171  unsigned short absy = std::abs(y);
172  unsigned short absz = std::abs(z);
173 
174  unsigned short bitmask=0;
175 
176 
177  if (x>0)
178  bitmask = bitmask | 1 ;
179  bitmask = bitmask | (absx << 1);
180  if (y>0)
181  bitmask = bitmask | (1<<4) ;
182  bitmask = bitmask | (absy << 5);
183  if (z>0)
184  bitmask = bitmask | (1<<8) ;
185  bitmask = bitmask | (absz << 9);
186 
187  neighbours_.push_back(ref);
188  neighbourInfos_.push_back(bitmask);
189 
190  if (z==0) {
191  neighbours8_.push_back(ref);
192  //find only the 4 neighbours
193  if (absx+absy==1)
194  neighbours4_.push_back(ref);
195  }
196 }
197 
198 
199 const PFRecHitRef PFRecHit::getNeighbour(short x,short y,short z) {
200  unsigned short absx = abs(x);
201  unsigned short absy = abs(y);
202  unsigned short absz = abs(z);
203 
204  unsigned short bitmask=0;
205 
206  if (x>0)
207  bitmask = bitmask | 1 ;
208  bitmask = bitmask | (absx << 1);
209  if (y>0)
210  bitmask = bitmask | (1<<4) ;
211  bitmask = bitmask | (absy << 5);
212  if (z>0)
213  bitmask = bitmask | (1<<8) ;
214  bitmask = bitmask | (absz << 9);
215 
216  for (unsigned int i=0;i<neighbourInfos_.size();++i) {
217  if (neighbourInfos_[i] == bitmask)
218  return neighbours_[i];
219  }
220  return PFRecHitRef();
221 }
222 
223 
224 void PFRecHit::size(double& deta, double& dphi) const {
225 
226  double minphi=9999;
227  double maxphi=-9999;
228  double mineta=9999;
229  double maxeta=-9999;
230  for ( unsigned ic=0; ic<cornersxyz_.size(); ++ic ) {
231  double eta = cornersxyz_[ic].Eta();
232  double phi = cornersxyz_[ic].Phi();
233 
234  if(phi>maxphi) maxphi=phi;
235  if(phi<minphi) minphi=phi;
236  if(eta>maxeta) maxeta=eta;
237  if(eta<mineta) mineta=eta;
238  }
239 
240  deta = maxeta - mineta;
241  dphi = maxphi - minphi;
242 }
243 
244 
245 ostream& reco::operator<<(ostream& out, const reco::PFRecHit& hit) {
246 
247  if(!out) return out;
248 
249  // reco::PFRecHit& nshit = const_cast<reco::PFRecHit& >(hit);
250  // const reco::PFRecHit::REPPoint& posrep = nshit.positionREP();
251 
252  const math::XYZPoint& posxyz = hit.position();
253 
254  out<<"hit id:"<<hit.detId()
255  <<" l:"<<hit.layer()
256  <<" E:"<<hit.energy()
257  <<" t:"<<hit.time()
258  <<" rep:"<<posxyz.Rho()<<","<<posxyz.Eta()<<","<<posxyz.Phi()<<"| N:";
259  return out;
260 }
void setSECorner(double posx, double posy, double posz)
Definition: PFRecHit.cc:120
int i
Definition: DBlmapReader.cc:9
static const char layer_[]
std::vector< math::XYZPoint > cornersxyz_
rechit cell corners
Definition: PFRecHit.h:207
void setNECorner(double posx, double posy, double posz)
Definition: PFRecHit.cc:125
double Scalar
Definition: Definitions.h:27
PFRecHitRefVector neighbours4_
Definition: PFRecHit.h:217
unsigned detId() const
rechit detId
Definition: PFRecHit.h:111
assert(m_qm.get())
void addNeighbour(short x, short y, short z, const PFRecHitRef &)
Definition: PFRecHit.cc:161
std::vector< unsigned short > neighbourInfos_
Definition: PFRecHit.h:214
PFLayer::Layer layer() const
rechit layer
Definition: PFRecHit.h:114
void setSWCorner(double posx, double posy, double posz)
Definition: PFRecHit.cc:115
const PFRecHitRef getNeighbour(short x, short y, short z)
Definition: PFRecHit.cc:199
std::ostream & operator<<(std::ostream &, BeamSpot beam)
Definition: BeamSpot.cc:71
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:35
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
layer definition for PFRecHit and PFCluster
Definition: PFLayer.h:21
void size(double &deta, double &dphi) const
Definition: PFRecHit.cc:224
edm::Ref< PFRecHitCollection > PFRecHitRef
persistent reference to PFRecHit objects
Definition: PFRecHitFwd.h:15
void setNWCorner(double posx, double posy, double posz)
Definition: PFRecHit.cc:110
Layer
layer definition
Definition: PFLayer.h:31
const math::XYZPoint & position() const
rechit cell centre x, y, z
Definition: PFRecHit.h:136
void calculatePositionREP()
Definition: PFRecHit.cc:144
ROOT::Math::PositionVector3D< ROOT::Math::CylindricalEta3D< double > > REPPoint
Definition: PFRecHit.h:43
PFRecHitRefVector neighbours8_
Definition: PFRecHit.h:218
math::XYZPoint position_
rechit cell centre: x, y, z
Definition: PFRecHit.h:198
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
PFRecHitRefVector neighbours_
indices to existing neighbours (1 common side)
Definition: PFRecHit.h:213
std::vector< REPPoint > cornersrep_
rechit cell corners rho/eta/phi
Definition: PFRecHit.h:210
double energy() const
rechit energy
Definition: PFRecHit.h:117
static int position[264][3]
Definition: ReadPGInfo.cc:509
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:69
REPPoint positionrep_
rechit cell centre: rho, eta, phi (transient)
Definition: PFRecHit.h:201
static const unsigned nCorners_
number of corners
Definition: PFRecHit.h:222
double time() const
timing for cleaned hits
Definition: PFRecHit.h:121
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void setCorner(unsigned i, double posx, double posy, double posz)
set position of one of the corners
Definition: PFRecHit.cc:130
PFRecHit()
default constructor. Sets energy and position to zero
Definition: PFRecHit.cc:49