CMS 3D CMS Logo

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