CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DataFormats/TrackerRecHit2D/src/SiStripRecHit1D.cc

Go to the documentation of this file.
00001 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
00002 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00003 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
00004 
00005 SiStripRecHit1D::SiStripRecHit1D( const LocalPoint& pos, const LocalError& err,
00006                                   const DetId& id,
00007                                   ClusterRef const & cluster):
00008   RecHit1D(id),pos_(pos),err_(err),
00009   cluster_(cluster),
00010   clusterRegional_(),
00011   sigmaPitch_(-1.)
00012  {}
00013 
00014 
00015 SiStripRecHit1D::SiStripRecHit1D( const LocalPoint& pos, const LocalError& err,
00016                                   const DetId& id,
00017                                   ClusterRegionalRef const& cluster): 
00018   RecHit1D(id),pos_(pos),err_(err),
00019   cluster_(),
00020   clusterRegional_(cluster),
00021   sigmaPitch_(-1.) {}
00022 
00023 SiStripRecHit1D::SiStripRecHit1D(const SiStripRecHit2D* hit2D):
00024   RecHit1D(hit2D->geographicalId()),pos_(hit2D->localPosition()),err_(),
00025   cluster_(),clusterRegional_(),sigmaPitch_(-1)
00026 {
00027   err_ = LocalError (hit2D->localPositionError().xx(),0.,DBL_MAX);
00028   if(hit2D->cluster().isNonnull()) cluster_ = hit2D->cluster();
00029   if(hit2D->cluster_regional().isNonnull()) clusterRegional_ = hit2D->cluster_regional();
00030 }
00031 
00032 
00033 bool SiStripRecHit1D::hasPositionAndError() const {
00034     return (err_.xx() != 0) || (err_.yy() != 0) || (err_.xy() != 0) ||
00035            (pos_.x()  != 0) || (pos_.y()  != 0) || (pos_.z()  != 0);
00036 }
00037 
00038 LocalPoint SiStripRecHit1D::localPosition() const {
00039     if (!hasPositionAndError()) throwExceptionUninitialized("localPosition");
00040     return pos_;
00041 }
00042 
00043 LocalError SiStripRecHit1D::localPositionError() const{ 
00044     if (!hasPositionAndError()) throwExceptionUninitialized("localPositionError");
00045     return err_;
00046 }
00047 
00048 void 
00049 SiStripRecHit1D::getKfComponents( KfComponentsHolder & holder ) const 
00050 {
00051    if (!hasPositionAndError()) throwExceptionUninitialized("getKfComponents");
00052    AlgebraicVector1 & pars = holder.params<1>();
00053    pars[0] = pos_.x(); 
00054 
00055    AlgebraicSymMatrix11 & errs = holder.errors<1>();
00056    errs(0,0) = err_.xx();
00057 
00058    AlgebraicMatrix15 & proj = holder.projection<1>();
00059    proj(0,3) = 1;
00060 
00061    holder.measuredParams<1>() = AlgebraicVector1( holder.tsosLocalParameters().At(3) );
00062    holder.measuredErrors<1>() = holder.tsosLocalErrors().Sub<AlgebraicSymMatrix11>( 3, 3 );
00063 }
00064 
00065 
00066 
00067 bool 
00068 SiStripRecHit1D::sharesInput( const TrackingRecHit* other, 
00069                               SharedInputType what) const
00070 {
00071   //here we exclude non si-strip subdetectors
00072   if( ((geographicalId().rawId()) >> (DetId::kSubdetOffset) ) != ( (other->geographicalId().rawId())>> (DetId::kSubdetOffset)) ) return false;
00073 
00074   //Protection against invalid hits
00075   if(! other->isValid()) return false;
00076 
00077   const std::type_info & otherType = typeid(*other);
00078   if (otherType == typeid(SiStripRecHit2D)) {
00079     const SiStripRecHit2D* otherCast = static_cast<const SiStripRecHit2D*>(other);
00080     // as 'null == null' is true, we can't just "or" the two equality tests: one of the two refs is always null! (gpetrucc)
00081     if (cluster_.isNonnull()) {
00082       return (cluster_ == otherCast->cluster());
00083     } else {
00084       return (clusterRegional_ == otherCast->cluster_regional());
00085     }
00086   } else if (otherType == typeid(SiStripRecHit1D)) {
00087     const SiStripRecHit1D* otherCast = static_cast<const SiStripRecHit1D*>(other);
00088     // as 'null == null' is true, we can't just "or" the two equality tests: one of the two refs is always null! (gpetrucc)
00089     if (cluster_.isNonnull()) {
00090       return (cluster_ == otherCast->cluster());
00091     } else {
00092       return (clusterRegional_ == otherCast->cluster_regional());
00093     }
00094   } else if (otherType == typeid(ProjectedSiStripRecHit2D)) {
00095     const SiStripRecHit2D* otherCast = & (static_cast<const ProjectedSiStripRecHit2D*>(other)->originalHit());
00096     // as 'null == null' is true, we can't just "or" the two equality tests: one of the two refs is always null! (gpetrucc)
00097     if (cluster_.isNonnull()) {
00098       return (cluster_ == otherCast->cluster());
00099     } else {
00100       return (clusterRegional_ == otherCast->cluster_regional());
00101     }
00102   } else if ((otherType == typeid(SiStripMatchedRecHit2D)) && (what == all)) {
00103     return false; 
00104   } else {
00105     // last resort, recur to 'recHits()', even if it returns a vector by value
00106     std::vector<const TrackingRecHit*> otherHits = other->recHits();
00107     int ncomponents=otherHits.size();
00108     if(ncomponents==0)return false;
00109     else if(ncomponents==1)return sharesInput(otherHits.front(),what);
00110     else if (ncomponents>1){
00111       if(what == all )return false;
00112       else{
00113         for(int i=0;i<ncomponents;i++){
00114           if(sharesInput(otherHits[i],what))return true;
00115         }
00116         return false;
00117       }
00118     }
00119     return false;
00120   }
00121 }
00122 
00123 
00124 std::vector<const TrackingRecHit*> SiStripRecHit1D::recHits() const {
00125   std::vector<const TrackingRecHit*> nullvector;
00126   return nullvector; 
00127 }
00128 std::vector<TrackingRecHit*> SiStripRecHit1D::recHits() {
00129   std::vector<TrackingRecHit*> nullvector;
00130   return nullvector; 
00131 }
00132 
00133 void
00134 SiStripRecHit1D::throwExceptionUninitialized(const char *where) const
00135 {
00136    throw cms::Exception("SiStripRecHit1D") << 
00137      "Trying to access " << where << " for a RecHit that was read from disk, but since CMSSW_2_1_X local positions are transient.\n" <<
00138      "If you want to get coarse position/error estimation from disk, please set: ComputeCoarseLocalPositionFromDisk = True \n " <<
00139      " to the TransientTrackingRecHitBuilder you are using from RecoTracker/TransientTrackingRecHit/python/TTRHBuilders_cff.py";
00140 }