CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/RecoTracker/MeasurementDet/plugins/TkStripMeasurementDet.cc

Go to the documentation of this file.
00001 #include "TkStripMeasurementDet.h"
00002 #include "TrackingTools/TransientTrackingRecHit/interface/InvalidTransientRecHit.h"
00003 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00004 #include "TrackingTools/MeasurementDet/interface/MeasurementDetException.h"
00005 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00006 #include "StripClusterAboveU.h"
00007 #include "RecoTracker/TransientTrackingRecHit/interface/TSiStripRecHit2DLocalPos.h"
00008 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00009 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00010 #include "TrackingTools/PatternTools/interface/TrajMeasLessEstim.h"
00011 
00012 #include <typeinfo>
00013 // #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimator.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00016 
00017 TkStripMeasurementDet::TkStripMeasurementDet( const GeomDet* gdet,
00018                                               const StripClusterParameterEstimator* cpe,
00019                                               bool regional) : 
00020     MeasurementDet (gdet),
00021     isRegional(regional),
00022     empty(true),
00023     activeThisEvent_(true), activeThisPeriod_(true),
00024     theCPE(cpe)
00025   {
00026     theStripGDU = dynamic_cast<const StripGeomDetUnit*>(gdet);
00027     if (theStripGDU == 0) {
00028       throw MeasurementDetException( "TkStripMeasurementDet constructed with a GeomDet which is not a StripGeomDetUnit");
00029     }
00030 
00031     //intialize the detId !
00032     id_ = gdet->geographicalId().rawId();
00033     //initalize the total number of strips
00034     totalStrips_ =  specificGeomDet().specificTopology().nstrips();
00035   }
00036 
00037 std::vector<TrajectoryMeasurement> 
00038 TkStripMeasurementDet::
00039 fastMeasurements( const TrajectoryStateOnSurface& stateOnThisDet, 
00040                   const TrajectoryStateOnSurface& startingState, 
00041                   const Propagator&, 
00042                   const MeasurementEstimator& est) const
00043 { 
00044   std::vector<TrajectoryMeasurement> result;
00045 
00046   if (isActive() == false) {
00047     LogDebug("TkStripMeasurementDet")<<" found an inactive module "<<id_;
00048     result.push_back( TrajectoryMeasurement( stateOnThisDet, 
00049                 InvalidTransientRecHit::build(&geomDet(), TrackingRecHit::inactive), 
00050                 0.F));
00051     return result;
00052   }
00053  
00054   float utraj =  theStripGDU->specificTopology().measurementPosition( stateOnThisDet.localPosition()).x();
00055   float uerr;
00056   //  if (theClusterRange.first == theClusterRange.second) { // empty
00057   if (empty  == true){
00058     LogDebug("TkStripMeasurementDet") << " DetID " << id_ << " empty ";
00059     if (stateOnThisDet.hasError()){
00060     uerr= sqrt(theStripGDU->specificTopology().measurementError(stateOnThisDet.localPosition(),stateOnThisDet.localError().positionError()).uu());
00061      if (testStrips(utraj,uerr)) {
00062         result.push_back( TrajectoryMeasurement( stateOnThisDet, InvalidTransientRecHit::build(&geomDet(), TrackingRecHit::missing), 0.F));
00063      } else { 
00064         result.push_back( TrajectoryMeasurement( stateOnThisDet, InvalidTransientRecHit::build(&geomDet(), TrackingRecHit::inactive), 0.F));
00065      }
00066     }else{
00067       result.push_back( TrajectoryMeasurement( stateOnThisDet, InvalidTransientRecHit::build(&geomDet(), TrackingRecHit::missing), 0.F));
00068     }
00069     return result;
00070   }
00071   
00072   if(!isRegional){//old implemetation with DetSet
00073     new_const_iterator rightCluster = 
00074       std::find_if( detSet_.begin(), detSet_.end(), StripClusterAboveU( utraj)); //FIXME
00075 
00076     if ( rightCluster != detSet_.begin()) {
00077       // there are hits on the left of the utraj
00078       new_const_iterator leftCluster = rightCluster;
00079       while ( --leftCluster >=  detSet_.begin()) {
00080         if (isMasked(*leftCluster)) continue;
00081         SiStripClusterRef clusterref = edmNew::makeRefTo( handle_, leftCluster ); 
00082         if (accept(clusterref)){
00083         RecHitContainer recHits = buildRecHits(clusterref,stateOnThisDet); 
00084         bool isCompatible(false);
00085         for(RecHitContainer::const_iterator recHit=recHits.begin();recHit!=recHits.end();++recHit){       
00086           std::pair<bool,double> diffEst = est.estimate(stateOnThisDet, **recHit);
00087           if ( diffEst.first ) {
00088             result.push_back( TrajectoryMeasurement( stateOnThisDet, *recHit, 
00089                                                      diffEst.second));
00090             isCompatible = true;
00091           }
00092         }
00093         if(!isCompatible) break; // exit loop on first incompatible hit
00094         }
00095         else LogDebug("TkStripMeasurementDet")<<"skipping this str from last iteration on"<<geomDet().geographicalId().rawId()<<" key: "<<clusterref.key();
00096       }
00097     }
00098     
00099     for ( ; rightCluster != detSet_.end(); rightCluster++) {
00100       if (isMasked(*rightCluster)) continue;
00101       SiStripClusterRef clusterref = edmNew::makeRefTo( handle_, rightCluster ); 
00102       if (accept(clusterref)){
00103       RecHitContainer recHits = buildRecHits(clusterref,stateOnThisDet); 
00104       bool isCompatible(false);
00105       for(RecHitContainer::const_iterator recHit=recHits.begin();recHit!=recHits.end();++recHit){         
00106         std::pair<bool,double> diffEst = est.estimate(stateOnThisDet, **recHit);
00107         if ( diffEst.first ) {
00108           result.push_back( TrajectoryMeasurement( stateOnThisDet, *recHit, 
00109                                                    diffEst.second));
00110           isCompatible = true;
00111         }
00112       }
00113       if(!isCompatible) break; // exit loop on first incompatible hit
00114       }
00115       else LogDebug("TkStripMeasurementDet")<<"skipping this str from last iteration on"<<geomDet().geographicalId().rawId()<<" key: "<<clusterref.key();
00116     }
00117   }// end block with DetSet
00118   else{
00119     LogDebug("TkStripMeasurementDet")<<" finding left/ right";
00120     result.reserve(size());
00121     unsigned int rightCluster = beginClusterI_;
00122     for (; rightCluster!= endClusterI_;++rightCluster){
00123       SiStripRegionalClusterRef clusterref = edm::makeRefToLazyGetter(regionalHandle_,rightCluster);
00124       if (clusterref->barycenter() > utraj) break;
00125     }
00126 
00127     unsigned int leftCluster = 1;
00128     for (unsigned int iReadBackWard=1; iReadBackWard<=(rightCluster-beginClusterI_) ; ++iReadBackWard){
00129         leftCluster=rightCluster-iReadBackWard;
00130         SiStripRegionalClusterRef clusterref = edm::makeRefToLazyGetter(regionalHandle_,leftCluster);
00131         if (isMasked(*clusterref)) continue;
00132         if (accept(clusterref)){
00133         RecHitContainer recHits = buildRecHits(clusterref,stateOnThisDet); 
00134         bool isCompatible(false);
00135         for(RecHitContainer::const_iterator recHit=recHits.begin();recHit!=recHits.end();++recHit){       
00136           std::pair<bool,double> diffEst = est.estimate(stateOnThisDet, **recHit);
00137           if ( diffEst.first ) {
00138             result.push_back( TrajectoryMeasurement( stateOnThisDet, *recHit, 
00139                                                      diffEst.second));
00140             isCompatible = true;
00141           }
00142         }
00143         if(!isCompatible) break; // exit loop on first incompatible hit
00144         }
00145         else LogDebug("TkStripMeasurementDet")<<"skipping this reg str from last iteration on"<<geomDet().geographicalId().rawId()<<" key: "<<clusterref.key();
00146     }
00147     
00148     
00149     for ( ; rightCluster != endClusterI_; ++rightCluster) {
00150       SiStripRegionalClusterRef clusterref = edm::makeRefToLazyGetter(regionalHandle_,rightCluster);
00151       if (isMasked(*clusterref)) continue;
00152       if (accept(clusterref)){
00153       RecHitContainer recHits = buildRecHits(clusterref,stateOnThisDet); 
00154       bool isCompatible(false);
00155       for(RecHitContainer::const_iterator recHit=recHits.begin();recHit!=recHits.end();++recHit){         
00156         std::pair<bool,double> diffEst = est.estimate(stateOnThisDet, **recHit);
00157         if ( diffEst.first ) {
00158           result.push_back( TrajectoryMeasurement( stateOnThisDet, *recHit, 
00159                                                    diffEst.second));
00160           isCompatible = true;
00161         }
00162       }
00163       if(!isCompatible) break; // exit loop on first incompatible hit
00164       }
00165       else LogDebug("TkStripMeasurementDet")<<"skipping this reg str from last iteration on"<<geomDet().geographicalId().rawId()<<" key: "<<clusterref.key();
00166     }
00167   }
00168 
00169 
00170   if ( result.empty()) {
00171     // create a TrajectoryMeasurement with an invalid RecHit and zero estimate
00172     if (stateOnThisDet.hasError()){
00173     uerr= sqrt(theStripGDU->specificTopology().measurementError(stateOnThisDet.localPosition(),stateOnThisDet.localError().positionError()).uu());
00174      if (testStrips(utraj,uerr)) {
00175        //LogDebug("TkStripMeasurementDet") << " DetID " << id_ << " empty after search, but active ";
00176        result.push_back( TrajectoryMeasurement( stateOnThisDet, InvalidTransientRecHit::build(&geomDet(), TrackingRecHit::missing), 0.F));
00177      } else { 
00178        //LogDebug("TkStripMeasurementDet") << " DetID " << id_ << " empty after search, and inactive ";
00179        result.push_back( TrajectoryMeasurement( stateOnThisDet, InvalidTransientRecHit::build(&geomDet(), TrackingRecHit::inactive), 0.F));
00180      }
00181     }else{
00182       result.push_back( TrajectoryMeasurement( stateOnThisDet, InvalidTransientRecHit::build(&geomDet(), TrackingRecHit::missing), 0.F));
00183     }
00184   }
00185   else {
00186     //LogDebug("TkStripMeasurementDet") << " DetID " << id_ << " full: " << (result.size()) << " compatible hits";
00187     // sort results according to estimator value
00188     if ( result.size() > 1) {
00189       sort( result.begin(), result.end(), TrajMeasLessEstim());
00190     }
00191   }
00192   return result;
00193 }
00194 
00195 
00196 TransientTrackingRecHit::RecHitPointer
00197 TkStripMeasurementDet::buildRecHit( const SiStripClusterRef& cluster,
00198                                     const TrajectoryStateOnSurface& ltp) const
00199 {
00200   const GeomDetUnit& gdu( specificGeomDet());
00201   LocalValues lv = theCPE->localParameters( *cluster, gdu, ltp);
00202   return TSiStripRecHit2DLocalPos::build( lv.first, lv.second, &geomDet(), cluster, theCPE);
00203 }
00204 
00205 TransientTrackingRecHit::RecHitPointer
00206 TkStripMeasurementDet::buildRecHit( const SiStripRegionalClusterRef& cluster,
00207                                     const TrajectoryStateOnSurface& ltp) const
00208 {
00209   const GeomDetUnit& gdu( specificGeomDet());
00210   LocalValues lv = theCPE->localParameters( *cluster, gdu, ltp);
00211   return TSiStripRecHit2DLocalPos::build( lv.first, lv.second, &geomDet(), cluster, theCPE);
00212 }
00213 
00214 
00215 
00216 TkStripMeasurementDet::RecHitContainer 
00217 TkStripMeasurementDet::buildRecHits( const SiStripClusterRef& cluster,
00218                                      const TrajectoryStateOnSurface& ltp) const
00219 {
00220   const GeomDetUnit& gdu( specificGeomDet());
00221   VLocalValues vlv = theCPE->localParametersV( *cluster, gdu, ltp);
00222   RecHitContainer res;
00223   for(VLocalValues::const_iterator it=vlv.begin();it!=vlv.end();++it){
00224     res.push_back(TSiStripRecHit2DLocalPos::build( it->first, it->second, &geomDet(), cluster, theCPE));
00225   }
00226   return res; 
00227 }
00228 
00229 
00230 TkStripMeasurementDet::RecHitContainer 
00231 TkStripMeasurementDet::buildRecHits( const SiStripRegionalClusterRef& cluster,
00232                                      const TrajectoryStateOnSurface& ltp) const
00233 {
00234   const GeomDetUnit& gdu( specificGeomDet());
00235   VLocalValues vlv = theCPE->localParametersV( *cluster, gdu, ltp);
00236   RecHitContainer res;
00237   for(VLocalValues::const_iterator it=vlv.begin();it!=vlv.end();++it){
00238     res.push_back(TSiStripRecHit2DLocalPos::build( it->first, it->second, &geomDet(), cluster, theCPE));
00239   }
00240   return res; 
00241 }
00242 
00243 
00244 
00245 TkStripMeasurementDet::RecHitContainer 
00246 TkStripMeasurementDet::recHits( const TrajectoryStateOnSurface& ts) const
00247 {
00248   RecHitContainer result;
00249   if (empty == true) return result;
00250   if (isActive() == false) return result; // GIO
00251 
00252   if(!isRegional){//old implemetation with DetSet
00253     result.reserve(detSet_.size());
00254     for ( new_const_iterator ci = detSet_.begin(); ci != detSet_.end(); ++ ci ) {
00255       if (isMasked(*ci)) continue;
00256       // for ( ClusterIterator ci=theClusterRange.first; ci != theClusterRange.second; ci++) {
00257       SiStripClusterRef  cluster = edmNew::makeRefTo( handle_, ci ); 
00258       if (accept(cluster))
00259         result.push_back( buildRecHit( cluster, ts));
00260       else LogDebug("TkStripMeasurementDet")<<"skipping this str from last iteration on"<<geomDet().geographicalId().rawId()<<" key: "<<cluster.key();
00261     }
00262   }else{
00263     result.reserve(size());
00264     for (unsigned int ci = beginClusterI_ ; ci!= endClusterI_;++ci){
00265       SiStripRegionalClusterRef clusterRef = edm::makeRefToLazyGetter(regionalHandle_,ci);
00266       if (isMasked(*clusterRef)) continue;
00267       if (accept(clusterRef))
00268         result.push_back( buildRecHit( clusterRef, ts));
00269       else LogDebug("TkStripMeasurementDet")<<"skipping this reg str from last iteration on"<<geomDet().geographicalId().rawId()<<" key: "<<clusterRef.key();
00270       }
00271   }
00272   return result;
00273 
00274 }
00275 
00276 template<class ClusterRefT>
00277 void
00278 TkStripMeasurementDet::buildSimpleRecHit( const ClusterRefT& cluster,
00279                                           const TrajectoryStateOnSurface& ltp,
00280                                           std::vector<SiStripRecHit2D>& res ) const
00281 {
00282   const GeomDetUnit& gdu( specificGeomDet());
00283   VLocalValues vlv = theCPE->localParametersV( *cluster, gdu, ltp);
00284   for(VLocalValues::const_iterator it=vlv.begin();it!=vlv.end();++it){
00285     res.push_back(SiStripRecHit2D( it->first, it->second, geomDet().geographicalId(), cluster));
00286   }
00287 }
00288 
00289 
00290 void 
00291 TkStripMeasurementDet::simpleRecHits( const TrajectoryStateOnSurface& ts, std::vector<SiStripRecHit2D> &result) const
00292 {
00293   if (empty || !isActive()) return;
00294 
00295   if(!isRegional){//old implemetation with DetSet
00296     result.reserve(detSet_.size());
00297     for ( new_const_iterator ci = detSet_.begin(); ci != detSet_.end(); ++ ci ) {
00298       if (isMasked(*ci)) continue;
00299       // for ( ClusterIterator ci=theClusterRange.first; ci != theClusterRange.second; ci++) {
00300       SiStripClusterRef  cluster = edmNew::makeRefTo( handle_, ci ); 
00301       if (accept(cluster))
00302         buildSimpleRecHit( cluster, ts,result);
00303       else LogDebug("TkStripMeasurementDet")<<"skipping this str from last iteration on"<<geomDet().geographicalId().rawId()<<" key: "<<cluster.key();
00304     }
00305   }else{
00306     result.reserve(size());
00307     for (unsigned int ci = beginClusterI_ ; ci!= endClusterI_;++ci){
00308       SiStripRegionalClusterRef clusterRef = edm::makeRefToLazyGetter(regionalHandle_,ci);
00309       if (isMasked(*clusterRef)) continue;
00310       if (accept(clusterRef))
00311         buildSimpleRecHit( clusterRef, ts,result);
00312       else LogDebug("TkStripMeasurementDet")<<"skipping this reg str from last iteration on"<<geomDet().geographicalId().rawId()<<" key: "<<clusterRef.key();
00313     }
00314   }
00315 }
00316 
00317 
00318 void
00319 TkStripMeasurementDet::set128StripStatus(bool good, int idx) { 
00320    if (idx == -1) {
00321        std::fill(bad128Strip_, bad128Strip_+6, !good);
00322        hasAny128StripBad_ = !good;
00323    } else {
00324        bad128Strip_[idx] = !good;
00325        if (good == false) {
00326             hasAny128StripBad_ = false;
00327        } else { // this should not happen, as usually you turn on all fibers
00328                 // and then turn off the bad ones, and not vice-versa,
00329                 // so I don't care if it's not optimized
00330             hasAny128StripBad_ = true;
00331             for (int i = 0; i < (totalStrips_ >> 7); i++) {
00332                 if (bad128Strip_[i] == false) hasAny128StripBad_ = false;
00333             }
00334        }    
00335    }
00336     
00337 }
00338 
00339 bool
00340 TkStripMeasurementDet::testStrips(float utraj, float uerr) const {
00341     int16_t start = (int16_t) std::max<float>(utraj - 3*uerr, 0);
00342     int16_t end   = (int16_t) std::min<float>(utraj + 3*uerr, totalStrips_);
00343 
00344     if (start >= end) { // which means either end <=0 or start >= totalStrips_
00345         /* LogDebug("TkStripMeasurementDet") << "Testing module " << id_ <<","<<
00346             " U = " << utraj << " +/- " << uerr << 
00347             "; Range [" << (utraj - 3*uerr) << ", " << (utraj + 3*uerr) << "] " << 
00348             ": YOU'RE COMPLETELY OFF THE MODULE."; */
00349         //return false; 
00350         return true;  // Wolfgang thinks this way is better
00351                       // and solves some problems with grouped ckf
00352     } 
00353 
00354     typedef std::vector<BadStripBlock>::const_iterator BSBIT;
00355 
00356     int16_t bad = 0, largestBadBlock = 0;
00357     for (BSBIT bsbc = badStripBlocks_.begin(), bsbe = badStripBlocks_.end(); bsbc != bsbe; ++bsbc) {
00358         if (bsbc->last  < start) continue;
00359         if (bsbc->first > end)   break;
00360         int16_t thisBad = std::min(bsbc->last, end) - std::max(bsbc->first, start);
00361         if (thisBad > largestBadBlock) largestBadBlock = thisBad;
00362         bad += thisBad;
00363     }
00364 
00365     bool ok = (bad < (end-start)) && 
00366               (uint16_t(bad) <= badStripCuts_.maxBad) && 
00367               (uint16_t(largestBadBlock) <= badStripCuts_.maxConsecutiveBad);
00368 
00369 //    if (bad) {   
00370 //       edm::LogWarning("TkStripMeasurementDet") << "Testing module " << id_ <<" (subdet: "<< SiStripDetId(id_).subdetId() << ")" <<
00371 //            " U = " << utraj << " +/- " << uerr << 
00372 //            "; Range [" << (utraj - 3*uerr) << ", " << (utraj + 3*uerr) << "] " << 
00373 //            "= [" << start << "," << end << "]" <<
00374 //            " total strips:" << (end-start) << ", good:" << (end-start-bad) << ", bad:" << bad << ", largestBadBlock: " << largestBadBlock << 
00375 //            ". " << (ok ? "OK" : "NO"); 
00376 //    }
00377     return ok;
00378 }
00379