CMS 3D CMS Logo

PFRecHit.cc

Go to the documentation of this file.
00001 #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
00002 
00003 using namespace reco;
00004 using namespace std;
00005 
00006 const unsigned    PFRecHit::nNeighbours_ = 8;
00007 const unsigned    PFRecHit::nCorners_ = 4;
00008 
00009 PFRecHit::PFRecHit() : 
00010   detId_(0),
00011   layer_(PFLayer::NONE),
00012   energy_(0.), 
00013   // seedState_(-1), 
00014   position_(math::XYZPoint(0.,0.,0.)),
00015   posrep_(REPPoint(0.,0.,0.)) {
00016 
00017   cornersxyz_.reserve( nCorners_ );
00018   for(unsigned i=0; i<nCorners_; i++) { 
00019     cornersxyz_.push_back( position_ );    
00020   }
00021 
00022   cornersrep_.reserve( nCorners_ );
00023   for ( unsigned i=0; i<nCorners_; ++i ) {
00024     cornersrep_.push_back( 
00025       REPPoint(cornersxyz_[i].Rho(),
00026                cornersxyz_[i].Eta(),
00027                cornersxyz_[i].Phi() ) );
00028   }
00029 
00030 }
00031 
00032 
00033 PFRecHit::PFRecHit(unsigned detId,
00034                    PFLayer::Layer layer, 
00035                    double energy, 
00036                    const math::XYZPoint& position,
00037                    const math::XYZVector& axisxyz,
00038                    const vector< math::XYZPoint >& cornersxyz) : 
00039   detId_(detId),
00040   layer_(layer),
00041   energy_(energy), 
00042   // seedState_(-1), 
00043   position_(position),
00044   posrep_( position.Rho(), position.Eta(), position.Phi() ),
00045   axisxyz_(axisxyz),
00046   cornersxyz_(cornersxyz) 
00047 {
00048   cornersrep_.reserve( nCorners_ );
00049   for ( unsigned i=0; i<nCorners_; ++i ) {
00050     cornersrep_.push_back( 
00051       REPPoint(cornersxyz_[i].Rho(),
00052                cornersxyz_[i].Eta(),
00053                cornersxyz_[i].Phi() ) );
00054   }
00055 }
00056 
00057 PFRecHit::PFRecHit(unsigned detId,
00058                    PFLayer::Layer layer,
00059                    double energy, 
00060                    double posx, double posy, double posz, 
00061                    double axisx, double axisy, double axisz) :
00062 
00063   detId_(detId),
00064   layer_(layer),
00065   energy_(energy), 
00066   // seedState_(-1), 
00067   position_(posx, posy, posz),
00068   posrep_( position_.Rho(), 
00069            position_.Eta(), 
00070            position_.Phi() ),  
00071   axisxyz_(axisx, axisy, axisz) {
00072   
00073 
00074   cornersxyz_.reserve( nCorners_ );
00075   for(unsigned i=0; i<nCorners_; i++) { 
00076     cornersxyz_.push_back( position_ );    
00077   } 
00078 
00079   cornersrep_.reserve( nCorners_ );
00080   for ( unsigned i=0; i<nCorners_; ++i ) {
00081     cornersrep_.push_back( 
00082       REPPoint(cornersxyz_[i].Rho(),
00083                cornersxyz_[i].Eta(),
00084                cornersxyz_[i].Phi() ) );
00085   }
00086  
00087 }    
00088 
00089 
00090 PFRecHit::PFRecHit(const PFRecHit& other) :
00091   detId_(other.detId_), 
00092   layer_(other.layer_), 
00093   energy_(other.energy_), 
00094   // seedState_(other.seedState_),
00095   position_(other.position_), 
00096   posrep_(other.posrep_),
00097   axisxyz_(other.axisxyz_),
00098   cornersxyz_(other.cornersxyz_),
00099   cornersrep_(other.cornersrep_),
00100   //   neighbours_(other.neighbours_),
00101   neighbours4_(other.neighbours4_),
00102   neighbours8_(other.neighbours8_),
00103   neighboursIds4_(other.neighboursIds4_),
00104   neighboursIds8_(other.neighboursIds8_)
00105 {}
00106 
00107 
00108 PFRecHit::~PFRecHit() 
00109 {}
00110 
00111 
00112 const PFRecHit::REPPoint& 
00113 PFRecHit::positionREP() const {
00114   //   if( posrep_ == REPPoint() ) {
00115   //     posrep_.SetCoordinates( position_.Rho(), position_.Eta(), position_.Phi() );
00116   //   }
00117   return posrep_;
00118 }
00119 
00120 
00121 void 
00122 PFRecHit::calculatePositionREP() {
00123   posrep_.SetCoordinates( position_.Rho(),  position_.Eta(),  position_.Phi() );
00124   for ( unsigned i=0; i<nCorners_; ++i ) {
00125     cornersrep_[i].SetCoordinates(cornersxyz_[i].Rho(),cornersxyz_[i].Eta(),cornersxyz_[i].Phi() );
00126   }
00127 }
00128 
00129 
00130 // void PFRecHit::setNeighbours( const vector< unsigned >& neighbours ) {
00131 //   if( neighbours.size() != nNeighbours_ ) 
00132 //     throw cms::Exception("CellNeighbourVector") 
00133 //       << "number of neighbours must be nNeighbours_";
00134   
00135 // //   neighbours_.clear(); 
00136 // //   neighboursIds4_.clear(); 
00137 // //   neighboursIds8_.clear(); 
00138 //   neighbours4_.clear(); 
00139 //   neighbours8_.clear(); 
00140   
00141 // //   neighboursIds4_.reserve( PFRecHit::nNeighbours_ ); 
00142 // //   neighboursIds8_.reserve( PFRecHit::nNeighbours_ ); 
00143 
00144 //   // space is reserved, but this vectors will not always have size 4 or 8.
00145 //   // they contain the indices to the neighbours that are present in the rechit
00146 //   // collection 
00147 //   neighbours4_.reserve( PFRecHit::nNeighbours_ ); 
00148 //   neighbours8_.reserve( PFRecHit::nNeighbours_ ); 
00149    
00150 // //   neighboursIds_.reserve(nNeighbours_); 
00151 // //   neighbours_.reserve(nNeighbours_); 
00152 
00153 // //   neighbours_ = neighbours;
00154 
00155 //   for(unsigned i=0; i<neighbours.size(); i++) {
00156 //     if( neighbours[i] ) {
00157 //       neighbours8_.push_back( neighbours[i] );      
00158 // //       neighboursIds8_.push_back( neighbours[i]->detId() );  
00159 //       if( !(i%2) ) {
00160 //      neighbours4_.push_back( neighbours[i] );
00161 // //   neighboursIds4_.push_back( neighbours[i]->detId() );  
00162 //       }
00163 //     }
00164 //   }
00165 // }
00166 
00167 
00168 void PFRecHit::add4Neighbour(unsigned index) {
00169   neighbours4_.push_back( index );
00170   neighbours8_.push_back( index );
00171 } 
00172 
00173 void PFRecHit::add8Neighbour(unsigned index) {
00174   neighbours8_.push_back( index );
00175 } 
00176 
00177 
00178 
00179 
00180 // void PFRecHit::findPtrsToNeighbours( const std::map<unsigned,  
00181 //                                   reco::PFRecHit* >& allhits ) {
00182 
00183 //   neighbours4_.clear();
00184 //   neighbours8_.clear();
00185   
00186 //   typedef std::map<unsigned, reco::PFRecHit* >::const_iterator IDH;
00187 
00188 //   for(unsigned inid = 0; inid<neighboursIds8_.size(); inid++) {
00189     
00190 //     IDH ineighbour = allhits.find( neighboursIds8_[inid] );
00191 //     if( ineighbour != allhits.end() ) {
00192 //       neighbours8_.push_back( ineighbour->second );
00193 //     }
00194 //   }
00195 
00196 
00197 //   for(unsigned inid = 0; inid<neighboursIds4_.size(); inid++) {
00198     
00199 //     IDH ineighbour = allhits.find( neighboursIds4_[inid] );
00200 //     if( ineighbour != allhits.end() ) {
00201 //       neighbours4_.push_back( ineighbour->second );
00202 //     }
00203 //   }
00204 
00205 // }
00206 
00207 
00208 void PFRecHit::setNWCorner( double posx, double posy, double posz ) {
00209   setCorner(0, posx, posy, posz);
00210 }
00211 
00212 
00213 void PFRecHit::setSWCorner( double posx, double posy, double posz ) {
00214   setCorner(1, posx, posy, posz);
00215 }
00216 
00217 
00218 void PFRecHit::setSECorner( double posx, double posy, double posz ) {
00219   setCorner(2, posx, posy, posz);
00220 }
00221 
00222 
00223 void PFRecHit::setNECorner( double posx, double posy, double posz ) {
00224   setCorner(3, posx, posy, posz);
00225 }
00226 
00227 
00228 void PFRecHit::setCorner( unsigned i, double posx, double posy, double posz ) {
00229   assert( cornersxyz_.size() == nCorners_);
00230   assert( cornersrep_.size() == nCorners_);
00231   assert( i<cornersxyz_.size() );
00232 
00233   cornersxyz_[i] = math::XYZPoint( posx, posy, posz);
00234   cornersrep_[i] = REPPoint(cornersxyz_[i].Rho(),
00235                             cornersxyz_[i].Eta(),
00236                             cornersxyz_[i].Phi() );
00237 }
00238 
00239 
00240 bool PFRecHit::isNeighbour4(unsigned id) const {
00241 
00242   for(unsigned i=0; i<neighbours4_.size(); i++ )
00243     if( id == neighbours4_[i] ) return true;
00244 
00245   return false;           
00246 }
00247 
00248 
00249 bool PFRecHit::isNeighbour8(unsigned id) const {
00250   
00251   for(unsigned i=0; i<neighbours8_.size(); i++ )
00252     if( id == neighbours8_[i] ) return true;
00253 
00254   return false;           
00255 }
00256 
00257 
00258 void PFRecHit::size(double& deta, double& dphi) const {
00259 
00260   double minphi=9999;
00261   double maxphi=-9999;
00262   double mineta=9999;
00263   double maxeta=-9999;
00264   for ( unsigned ic=0; ic<cornersrep_.size(); ++ic ) { 
00265     double eta = cornersrep_[ic].Eta();
00266     double phi = cornersrep_[ic].Phi();
00267     
00268     if(phi>maxphi) maxphi=phi;
00269     if(phi<minphi) minphi=phi;
00270     if(eta>maxeta) maxeta=eta;
00271     if(eta<mineta) mineta=eta;    
00272   }
00273 
00274   deta = maxeta - mineta;
00275   dphi = maxphi - minphi;
00276 }
00277 
00278 
00279 ostream& reco::operator<<(ostream& out, const reco::PFRecHit& hit) {
00280 
00281   if(!out) return out;
00282 
00283   //   reco::PFRecHit& nshit = const_cast<reco::PFRecHit& >(hit);
00284   //   const reco::PFRecHit::REPPoint& posrep = nshit.positionREP();
00285   
00286   const  math::XYZPoint& posxyz = hit.position();
00287 
00288   out<<"hit id:"<<hit.detId()
00289      <<" l:"<<hit.layer()
00290      <<" E:"<<hit.energy()
00291      <<" rep:"<<posxyz.Rho()<<","<<posxyz.Eta()<<","<<posxyz.Phi()<<"| N:";
00292   //     <<" SEED: "<<hit.seedState_;
00293   for(unsigned i=0; i<hit.neighbours8_.size(); i++ ) {
00294     out<<hit.neighbours8_[i]<<" ";
00295   }
00296   
00297 
00298   //   out<<endl;
00299   //   out<<"neighbours "<<endl;
00300   //   for(unsigned i=0; i<hit.neighbours8_.size(); i++ ) {
00301   //     out<<"\t"<< hit.neighbours8_[i]->detId()<<endl;
00302   //   }
00303   //   out<<"--"<<endl;
00304   //   for(unsigned i=0; i<hit.neighboursIds8_.size(); i++ ) {
00305   //     out<<"\t"<< (hit.neighboursIds8_[i])<<endl;
00306   //   }
00307   
00308   //   bool printcorners = false;
00309 
00310   //   if(printcorners) {
00311     
00312   //     out<<endl<<"corners : "<<endl;
00313   //     const std::vector< math::XYZPoint >& corners = hit.getCornersXYZ();
00314   //     for(unsigned i=0; i<corners.size(); i++) {
00315   //       out<<"\t"<<corners[i].X()<<","<<corners[i].Y()<<","<<corners[i].Z()<<endl;
00316   //     }
00317   //   }  
00318 
00319   return out;
00320 }

Generated on Tue Jun 9 17:31:23 2009 for CMSSW by  doxygen 1.5.4