CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoTracker/MeasurementDet/plugins/MeasurementTrackerImpl.cc

Go to the documentation of this file.
00001 #include "MeasurementTrackerImpl.h"
00002 
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 
00006 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00007 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00008 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00009 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00010 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00011 
00012 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00013 
00014 #include "DataFormats/DetId/interface/DetIdCollection.h"
00015 
00016 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00017 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00018 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00019 #include "DataFormats/SiStripCluster/interface/SiStripClusterCollection.h"
00020 
00021 #include "TrackingTools/MeasurementDet/interface/MeasurementDetException.h"
00022 
00023 #include "RecoLocalTracker/ClusterParameterEstimator/interface/PixelClusterParameterEstimator.h"
00024 #include "RecoLocalTracker/Records/interface/TrackerCPERecord.h"
00025 #include "RecoLocalTracker/SiStripRecHitConverter/interface/SiStripRecHitMatcher.h"
00026 #include "RecoLocalTracker/SiStripRecHitConverter/interface/StripCPE.h"  
00027 
00028 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
00029 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00030 #include "TkStripMeasurementDet.h"
00031 #include "TkPixelMeasurementDet.h"
00032 #include "TkGluedMeasurementDet.h"
00033 
00034 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00035 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
00036 
00037 #include "FWCore/ServiceRegistry/interface/Service.h"
00038 #include "FWCore/Services/interface/UpdaterService.h"
00039 
00040 #include <iostream>
00041 #include <typeinfo>
00042 #include <map>
00043 #include <algorithm>
00044 
00045 
00046 // here just while testing
00047 
00048 #if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ > 4)
00049 #include <x86intrin.h>
00050 
00051 #else
00052 
00053 #ifdef __SSE2__
00054 #include <mmintrin.h>
00055 #include <emmintrin.h>
00056 #endif
00057 #ifdef __SSE3__
00058 #include <pmmintrin.h>
00059 #endif
00060 #ifdef __SSE4_1__
00061 #include <smmintrin.h>
00062 #endif
00063 
00064 #endif
00065 
00066 
00067 //
00068 
00069 using namespace std;
00070 
00071 namespace {
00072 
00073   struct CmpTKD {
00074     bool operator()(MeasurementDet* rh, MeasurementDet* lh) {
00075       return rh->geomDet().geographicalId().rawId() < lh->geomDet().geographicalId().rawId();
00076     }
00077   };
00078 
00079   template<typename TKD>
00080   void sortTKD( std::vector<TKD*> & det) {
00081     std::sort(det.begin(),det.end(),CmpTKD());
00082   }
00083 }
00084 
00085 
00086 MeasurementTrackerImpl::MeasurementTrackerImpl(const edm::ParameterSet&              conf,
00087                                        const PixelClusterParameterEstimator* pixelCPE,
00088                                        const StripClusterParameterEstimator* stripCPE,
00089                                        const SiStripRecHitMatcher*  hitMatcher,
00090                                        const TrackerGeometry*  trackerGeom,
00091                                        const GeometricSearchTracker* geometricSearchTracker,
00092                                        const SiStripQuality *stripQuality,
00093                                        int   stripQualityFlags,
00094                                        int   stripQualityDebugFlags,
00095                                        const SiPixelQuality *pixelQuality,
00096                                        const SiPixelFedCabling *pixelCabling,
00097                                        int   pixelQualityFlags,
00098                                        int   pixelQualityDebugFlags,
00099                                        bool isRegional) :
00100   MeasurementTracker(trackerGeom,geometricSearchTracker),
00101   pset_(conf),
00102   name_(conf.getParameter<std::string>("ComponentName")),
00103   thePixelCPE(pixelCPE),theStripCPE(stripCPE),theHitMatcher(hitMatcher),
00104   theInactivePixelDetectorLabels(conf.getParameter<std::vector<edm::InputTag> >("inactivePixelDetectorLabels")),
00105   theInactiveStripDetectorLabels(conf.getParameter<std::vector<edm::InputTag> >("inactiveStripDetectorLabels")),
00106   isRegional_(isRegional)
00107 {
00108   this->initialize();
00109   this->initializeStripStatus(stripQuality, stripQualityFlags, stripQualityDebugFlags);
00110   this->initializePixelStatus(pixelQuality, pixelCabling, pixelQualityFlags, pixelQualityDebugFlags);
00111   //the measurement tracking is set to skip clusters, the other option is set from outside
00112   selfUpdateSkipClusters_=conf.exists("skipClusters");
00113   if (selfUpdateSkipClusters_)
00114     {
00115              edm::InputTag skip=conf.getParameter<edm::InputTag>("skipClusters");
00116              if (skip==edm::InputTag("")) selfUpdateSkipClusters_=false;
00117     }
00118 
00119 
00120   LogDebug("MeasurementTracker")<<"skipping clusters: "<<selfUpdateSkipClusters_;
00121 }
00122 
00123 MeasurementTrackerImpl::~MeasurementTrackerImpl()
00124 {
00125   for(vector<TkPixelMeasurementDet*>::const_iterator it=thePixelDets.begin(); it!=thePixelDets.end(); ++it){
00126     delete *it;
00127   }
00128 
00129   for(vector<TkStripMeasurementDet*>::const_iterator it=theStripDets.begin(); it!=theStripDets.end(); ++it){
00130     delete *it;
00131   }
00132 
00133   for(vector<TkGluedMeasurementDet*>::const_iterator it=theGluedDets.begin(); it!=theGluedDets.end(); ++it){
00134     delete *it;
00135   }
00136 }
00137 
00138 
00139 void MeasurementTrackerImpl::initialize() const
00140 {  
00141   addPixelDets( theTrackerGeom->detsPXB());
00142   addPixelDets( theTrackerGeom->detsPXF());
00143   addStripDets( theTrackerGeom->detsTIB());
00144   addStripDets( theTrackerGeom->detsTID());
00145   addStripDets( theTrackerGeom->detsTOB());
00146   addStripDets( theTrackerGeom->detsTEC());  
00147 
00148   sortTKD(theStripDets);
00149   sortTKD(thePixelDets);
00150   sortTKD(theGluedDets);
00151 
00152 }
00153 
00154 
00155 void MeasurementTrackerImpl::addPixelDets( const TrackingGeometry::DetContainer& dets) const
00156 {
00157   for (TrackerGeometry::DetContainer::const_iterator gd=dets.begin();
00158        gd != dets.end(); gd++) {
00159     addPixelDet(*gd, thePixelCPE);
00160   }  
00161 }
00162 
00163 void MeasurementTrackerImpl::addStripDets( const TrackingGeometry::DetContainer& dets) const
00164 {
00165   for (TrackerGeometry::DetContainer::const_iterator gd=dets.begin();
00166        gd != dets.end(); gd++) {
00167 
00168     const GeomDetUnit* gdu = dynamic_cast<const GeomDetUnit*>(*gd);
00169 
00170     //    StripSubdetector stripId( (**gd).geographicalId());
00171     //     bool isDetUnit( gdu != 0);
00172     //     cout << "StripSubdetector glued? " << stripId.glued() 
00173     //   << " is DetUnit? " << isDetUnit << endl;
00174 
00175     if (gdu != 0) {
00176       addStripDet(*gd, theStripCPE);
00177     }
00178     else {
00179       const GluedGeomDet* gluedDet = dynamic_cast<const GluedGeomDet*>(*gd);
00180       if (gluedDet == 0) {
00181         throw MeasurementDetException("MeasurementTracker ERROR: GeomDet neither DetUnit nor GluedDet");
00182       }
00183       addGluedDet(gluedDet, theHitMatcher);
00184     }  
00185   }
00186 }
00187 
00188 void MeasurementTrackerImpl::addStripDet( const GeomDet* gd,
00189                                       const StripClusterParameterEstimator* cpe) const
00190 {
00191   try {
00192     TkStripMeasurementDet* det = new TkStripMeasurementDet( gd, cpe,isRegional_);
00193     theStripDets.push_back(det);
00194     theDetMap[gd->geographicalId()] = det;
00195   }
00196   catch(MeasurementDetException& err){
00197     edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what() ;
00198   }
00199 }
00200 
00201 void MeasurementTrackerImpl::addPixelDet( const GeomDet* gd,
00202                                       const PixelClusterParameterEstimator* cpe) const
00203 {
00204   TkPixelMeasurementDet* det = new TkPixelMeasurementDet( gd, cpe);
00205   thePixelDets.push_back(det);
00206   theDetMap[gd->geographicalId()] = det;
00207 }
00208 
00209 void MeasurementTrackerImpl::addGluedDet( const GluedGeomDet* gd,
00210                                       const SiStripRecHitMatcher* matcher) const
00211 {
00212   const MeasurementDet* monoDet = idToDet( gd->monoDet()->geographicalId());
00213   if (monoDet == 0) {
00214     addStripDet(gd->monoDet(), theStripCPE);  // in case glued det comes before components
00215     monoDet = idToDet( gd->monoDet()->geographicalId());
00216   }
00217 
00218   const MeasurementDet* stereoDet = idToDet( gd->stereoDet()->geographicalId());
00219   if (stereoDet == 0) {
00220     addStripDet(gd->stereoDet(), theStripCPE);  // in case glued det comes before components
00221     stereoDet = idToDet( gd->stereoDet()->geographicalId());
00222   }
00223 
00224   if (monoDet == 0 || stereoDet == 0) {
00225     edm::LogError("MeasurementDet") << "MeasurementTracker ERROR: GluedDet components not found as MeasurementDets ";
00226     throw MeasurementDetException("MeasurementTracker ERROR: GluedDet components not found as MeasurementDets");
00227   }
00228 
00229   TkGluedMeasurementDet* det = new TkGluedMeasurementDet( gd, theHitMatcher,
00230                                                           monoDet, stereoDet);
00231   theGluedDets.push_back( det);
00232   theDetMap[gd->geographicalId()] = det;
00233 }
00234 
00235 void MeasurementTrackerImpl::update( const edm::Event& event) const
00236 {
00237   updatePixels(event);
00238   updateStrips(event);
00239   
00240   /*
00241   for (std::vector<TkStripMeasurementDet*>::const_iterator i=theStripDets.begin();
00242        i!=theStripDets.end(); i++) {
00243     if( (*i)->isEmpty()){
00244       std::cout << "stripDet id, #hits: " 
00245                 <<  (*i)->geomDet().geographicalId().rawId() << " , "
00246                 << 0 << std::endl;
00247     }else{
00248       std::cout << "stripDet id, #hits: " 
00249                 <<  (*i)->geomDet().geographicalId().rawId() << " , "
00250                 << (*i)->size() << std::endl;
00251     }
00252   }
00253   */
00254 }
00255 void MeasurementTrackerImpl::setClusterToSkip(const edm::InputTag & cluster, const edm::Event& event) const
00256 {
00257   LogDebug("MeasurementTracker")<<"setClusterToSkip";
00258   if (selfUpdateSkipClusters_)
00259     edm::LogError("MeasurementTracker")<<"this mode of operation is not supported, either the measurement tracker is set to skip clusters, or is being told to skip clusters. not both";
00260 
00261   edm::Handle<edmNew::DetSetVector<SiPixelClusterRefNew> > pixelClusterRefs;
00262   event.getByLabel(cluster,pixelClusterRefs);
00263   for (std::vector<TkPixelMeasurementDet*>::const_iterator i=thePixelDets.begin();
00264        i!=thePixelDets.end(); i++) {
00265     edmNew::DetSetVector<SiPixelClusterRefNew>::const_iterator f=pixelClusterRefs->find((**i).geomDet().geographicalId().rawId());
00266     if (f!=pixelClusterRefs->end())
00267       (**i).setClusterToSkip(f->begin(),f->end());
00268     else
00269       (**i).unset();
00270   }
00271 
00272   edm::Handle<edmNew::DetSetVector<TkStripMeasurementDet::SiStripClusterRef> > stripClusterRefs;
00273   event.getByLabel(cluster,stripClusterRefs);
00274   for (std::vector<TkStripMeasurementDet*>::const_iterator i=theStripDets.begin();
00275        i!=theStripDets.end(); i++){
00276     edmNew::DetSetVector<TkStripMeasurementDet::SiStripClusterRef>::const_iterator f=stripClusterRefs->find((**i).geomDet().geographicalId().rawId());
00277     if (f!=stripClusterRefs->end())
00278       (**i).setClusterToSkip(f->begin(),f->end());
00279     else
00280       (**i).unset();
00281   }
00282 }
00283 
00284 void MeasurementTrackerImpl::unsetClusterToSkip() const {
00285   LogDebug("MeasurementTracker")<<"unsetClusterToSkip";
00286   if (selfUpdateSkipClusters_)
00287     edm::LogError("MeasurementTracker")<<"this mode of operation is not supported, either the measurement tracker is set to skip clusters, or is being told to skip clusters. not both";
00288 
00289   for (std::vector<TkPixelMeasurementDet*>::const_iterator i=thePixelDets.begin();
00290        i!=thePixelDets.end(); i++) {
00291     (**i).unset();
00292   }
00293   for (std::vector<TkStripMeasurementDet*>::const_iterator i=theStripDets.begin();
00294        i!=theStripDets.end(); i++){
00295     (**i).unset();
00296   }
00297 }
00298 
00299 void MeasurementTrackerImpl::updatePixels( const edm::Event& event) const
00300 {
00301   // avoid to update twice from the same event
00302   if (!edm::Service<UpdaterService>()->checkOnce("MeasurementTrackerImpl::updatePixels::"+name_)) return;
00303 
00304   typedef edmNew::DetSet<SiPixelCluster> PixelDetSet;
00305 
00306   bool switchOffPixelsIfEmpty = (!pset_.existsAs<bool>("switchOffPixelsIfEmpty")) ||
00307                                 (pset_.getParameter<bool>("switchOffPixelsIfEmpty"));
00308 
00309   std::vector<uint32_t> rawInactiveDetIds; 
00310   if (!theInactivePixelDetectorLabels.empty()) {
00311     edm::Handle<DetIdCollection> detIds;
00312     for (std::vector<edm::InputTag>::const_iterator itt = theInactivePixelDetectorLabels.begin(), edt = theInactivePixelDetectorLabels.end(); 
00313             itt != edt; ++itt) {
00314       if (event.getByLabel(*itt, detIds)){
00315         rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
00316       }else{
00317         static bool iFailedAlready=false;
00318         if (!iFailedAlready){
00319           edm::LogError("MissingProduct")<<"I fail to get the list of inactive pixel modules, because of 4.2/4.4 event content change.";
00320           iFailedAlready=true;
00321         }
00322       }
00323     }
00324     if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
00325   }
00326   // Pixel Clusters
00327   std::string pixelClusterProducer = pset_.getParameter<std::string>("pixelClusterProducer");
00328   if( pixelClusterProducer.empty() ) { //clusters have not been produced
00329     for (std::vector<TkPixelMeasurementDet*>::const_iterator i=thePixelDets.begin();
00330          i!=thePixelDets.end(); i++) {
00331       if (switchOffPixelsIfEmpty) {
00332         (**i).setActiveThisEvent(false);
00333       }else{
00334         (**i).setEmpty();
00335       }
00336     }
00337   }else{  
00338 
00339     edm::Handle<edmNew::DetSetVector<SiPixelClusterRefNew> > pixelClusterRefs;
00340     if (selfUpdateSkipClusters_){
00341       //and get the collection of pixel ref to skip
00342       event.getByLabel(pset_.getParameter<edm::InputTag>("skipClusters"),pixelClusterRefs);
00343       LogDebug("MeasurementTracker")<<"getting pxl refs to skip";
00344       if (pixelClusterRefs.failedToGet())edm::LogError("MeasurementTracker")<<"not getting the pixel clusters to skip";
00345     }
00346 
00347     edm::Handle<edmNew::DetSetVector<SiPixelCluster> > pixelClusters;
00348     event.getByLabel(pixelClusterProducer, pixelClusters);
00349     const  edmNew::DetSetVector<SiPixelCluster>* pixelCollection = pixelClusters.product();
00350    
00351     if (switchOffPixelsIfEmpty && pixelCollection->empty()) {
00352         for (std::vector<TkPixelMeasurementDet*>::const_iterator i=thePixelDets.begin();
00353              i!=thePixelDets.end(); i++) {
00354               (**i).setActiveThisEvent(false);
00355         }
00356     } else { 
00357 
00358     for (std::vector<TkPixelMeasurementDet*>::const_iterator i=thePixelDets.begin();
00359          i!=thePixelDets.end(); i++) {
00360 
00361       // foreach det get cluster range
00362       unsigned int id = (**i).geomDet().geographicalId().rawId();
00363       if (!rawInactiveDetIds.empty() && std::binary_search(rawInactiveDetIds.begin(), rawInactiveDetIds.end(), id)) {
00364         (**i).setActiveThisEvent(false); continue;
00365       }
00366       //FIXME
00367       //fill the set with what needs to be skipped
00368       edmNew::DetSetVector<SiPixelCluster>::const_iterator it = pixelCollection->find( id );
00369       if ( it != pixelCollection->end() ){            
00370         // push cluster range in det
00371         (**i).update( *it, pixelClusters, id );
00372         if (selfUpdateSkipClusters_){
00373           edmNew::DetSetVector<SiPixelClusterRefNew>::const_iterator f=pixelClusterRefs->find(id);
00374           if (f!=pixelClusterRefs->end())
00375             (**i).setClusterToSkip(f->begin(),f->end());
00376           else
00377             (**i).unset();
00378         }
00379       }else{
00380         (**i).setEmpty();
00381       }
00382     }
00383     }
00384   }
00385 
00386 
00387   
00388 }
00389 
00390 void MeasurementTrackerImpl::getInactiveStrips(const edm::Event& event,
00391                                                std::vector<uint32_t> & rawInactiveDetIds) const {
00392   if (!theInactiveStripDetectorLabels.empty()) {
00393     edm::Handle<DetIdCollection> detIds;
00394     for (std::vector<edm::InputTag>::const_iterator itt = theInactiveStripDetectorLabels.begin(), edt = theInactiveStripDetectorLabels.end(); 
00395          itt != edt; ++itt) {
00396       event.getByLabel(*itt, detIds);
00397       rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
00398     }
00399     if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
00400   }
00401 }
00402 
00403 void MeasurementTrackerImpl::updateStrips( const edm::Event& event) const
00404 {
00405   // avoid to update twice from the same event
00406   if (!edm::Service<UpdaterService>()->checkOnce("MeasurementTrackerImpl::updateStrips::"+name_)) return;
00407 
00408   typedef edmNew::DetSet<SiStripCluster>   StripDetSet;
00409 
00410   std::vector<uint32_t> rawInactiveDetIds;
00411   getInactiveStrips(event,rawInactiveDetIds);
00412 
00413   // Strip Clusters
00414   std::string stripClusterProducer = pset_.getParameter<std::string>("stripClusterProducer");
00415   //first clear all of them
00416 
00417   {
00418     std::vector<TkStripMeasurementDet*>::const_iterator end = theStripDets.end()-200;
00419     for (std::vector<TkStripMeasurementDet*>::const_iterator i=theStripDets.begin();
00420          i!=end; i++) {
00421       (**i).setEmpty();
00422 #ifdef __SSE2__
00423       _mm_prefetch(((char *)(*(i+200))),_MM_HINT_T0); 
00424 #endif
00425     }
00426    for (std::vector<TkStripMeasurementDet*>::const_iterator i=end;
00427          i!=theStripDets.end(); i++)
00428       (**i).setEmpty();
00429   }
00430   if( !stripClusterProducer.compare("") ) { //clusters have not been produced
00431   }else{
00432     //=========  actually load cluster =============
00433     if(!isRegional_){
00434         edm::Handle<edmNew::DetSetVector<TkStripMeasurementDet::SiStripClusterRef> > stripClusterRefs;
00435         if (selfUpdateSkipClusters_){
00436           //and get the collection of pixel ref to skip
00437           LogDebug("MeasurementTracker")<<"getting strp refs to skip";
00438           event.getByLabel(pset_.getParameter<edm::InputTag>("skipClusters"),stripClusterRefs);
00439           if (stripClusterRefs.failedToGet())edm::LogError("MeasurementTracker")<<"not getting the strip clusters to skip";
00440         }
00441 
00442       edm::Handle<edmNew::DetSetVector<SiStripCluster> > clusterHandle;
00443       event.getByLabel(stripClusterProducer, clusterHandle);
00444       const edmNew::DetSetVector<SiStripCluster>* clusterCollection = clusterHandle.product();
00445 
00446       std::vector<TkStripMeasurementDet*>::const_iterator i=theStripDets.begin();
00447       std::vector<TkStripMeasurementDet*>::const_iterator endDet=theStripDets.end();
00448       edmNew::DetSetVector<SiStripCluster>::const_iterator it = (*clusterCollection).begin();
00449       edmNew::DetSetVector<SiStripCluster>::const_iterator endColl = (*clusterCollection).end();
00450       // cluster and det and in order (both) and unique so let's use set intersection
00451       for (;it!=endColl; ++it) {
00452         StripDetSet detSet = *it;
00453         unsigned int id = detSet.id();
00454         while ( id != (**i).rawId()) { // eventually change to lower_range
00455           ++i;
00456           if (i==endDet) throw "we have a problem!!!!";
00457         }
00458 
00459         if (!rawInactiveDetIds.empty() && std::binary_search(rawInactiveDetIds.begin(), rawInactiveDetIds.end(), id)) {
00460             (**i).setActiveThisEvent(false); continue;
00461         }
00462         // push cluster range in det
00463 
00464         (**i).update( detSet, clusterHandle, id );
00465         if (selfUpdateSkipClusters_){
00466           edmNew::DetSetVector<TkStripMeasurementDet::SiStripClusterRef>::const_iterator f=stripClusterRefs->find(id);
00467           if (f!=stripClusterRefs->end())
00468             (**i).setClusterToSkip(f->begin(),f->end());
00469           else
00470             (**i).unset();
00471         }
00472       }
00473     }else{
00474 
00475       edm::Handle<edmNew::DetSetVector<TkStripMeasurementDet::SiStripRegionalClusterRef> > stripClusterRefs;
00476       if(selfUpdateSkipClusters_){
00477         LogDebug("MeasurementTracker")<<"getting reg strp refs to skip";
00478         event.getByLabel(pset_.getParameter<edm::InputTag>("skipClusters"),stripClusterRefs);
00479         if (stripClusterRefs.failedToGet())edm::LogError("MeasurementTracker")<<"not getting the strip clusters to skip";
00480       }
00481 
00482       //then set the not-empty ones only
00483       edm::Handle<edm::RefGetter<SiStripCluster> > refClusterHandle;
00484       event.getByLabel(stripClusterProducer, refClusterHandle);
00485       
00486       std::string lazyGetter = pset_.getParameter<std::string>("stripLazyGetterProducer");
00487       edm::Handle<edm::LazyGetter<SiStripCluster> > lazyClusterHandle;
00488       event.getByLabel(lazyGetter,lazyClusterHandle);
00489 
00490       uint32_t tmpId=0;
00491       vector<SiStripCluster>::const_iterator beginIterator;
00492       edm::RefGetter<SiStripCluster>::const_iterator iregion = refClusterHandle->begin();
00493       for(;iregion!=refClusterHandle->end();++iregion) {
00494         const edm::RegionIndex<SiStripCluster>& region = *iregion;
00495         vector<SiStripCluster>::const_iterator icluster = region.begin();
00496         const vector<SiStripCluster>::const_iterator endIterator = region.end();
00497         tmpId = icluster->geographicalId();
00498         beginIterator = icluster;
00499 
00500         //std::cout << "== tmpId ad inizio loop dentro region: " << tmpId << std::endl;
00501 
00502         for (;icluster!=endIterator;icluster++) {
00503           //std::cout << "===== cluster id,pos " 
00504           //  << icluster->geographicalId() << " , " << icluster->barycenter()
00505           //  << std::endl;
00506           //std::cout << "=====making ref in recHits() " << std::endl;
00507           if( icluster->geographicalId() != tmpId){ 
00508             //std::cout << "geo!=tmpId" << std::endl;
00509             //we should find a way to avoid this casting. it is slow
00510             //create also another map for TkStripMeasurementDet ??
00511 
00512             // the following castings are really ugly. To be corrected ASAP
00513             const TkStripMeasurementDet* theConcreteDet = 
00514               dynamic_cast<const TkStripMeasurementDet*>(idToDet(DetId(tmpId)));
00515             
00516             if(theConcreteDet == 0)
00517               throw MeasurementDetException("failed casting to TkStripMeasurementDet*");            
00518             TkStripMeasurementDet*  theConcreteDetUpdatable = 
00519               const_cast<TkStripMeasurementDet*>(theConcreteDet);
00520             theConcreteDetUpdatable->update(beginIterator,icluster,lazyClusterHandle,tmpId);
00521             if (selfUpdateSkipClusters_){
00522               edmNew::DetSetVector<TkStripMeasurementDet::SiStripRegionalClusterRef>::const_iterator f=stripClusterRefs->find(tmpId);
00523               if (f!=stripClusterRefs->end())
00524                 theConcreteDetUpdatable->setRegionalClustersToSkip(f->begin(),f->end());
00525               else
00526                 theConcreteDetUpdatable->unset();
00527             }
00528             //cannot we avoid to update the det with detId of itself??
00529 
00530             tmpId = icluster->geographicalId();
00531             beginIterator = icluster;
00532             if( icluster == (endIterator-1)){
00533               const TkStripMeasurementDet* theConcreteDet = 
00534               dynamic_cast<const TkStripMeasurementDet*>(idToDet(DetId(tmpId)));
00535               
00536               if(theConcreteDet == 0)
00537               throw MeasurementDetException("failed casting to TkStripMeasurementDet*");            
00538               TkStripMeasurementDet*  theConcreteDetUpdatable = 
00539               const_cast<TkStripMeasurementDet*>(theConcreteDet);
00540               theConcreteDetUpdatable->update(icluster,endIterator,lazyClusterHandle,tmpId);
00541               if (selfUpdateSkipClusters_){
00542                 edmNew::DetSetVector<TkStripMeasurementDet::SiStripRegionalClusterRef>::const_iterator f=stripClusterRefs->find(tmpId);
00543                 if (f!=stripClusterRefs->end())
00544                   theConcreteDetUpdatable->setRegionalClustersToSkip(f->begin(),f->end());
00545                 else
00546                   theConcreteDetUpdatable->unset();
00547               }
00548             }   
00549           }else if( icluster == (endIterator-1)){          
00550             const TkStripMeasurementDet* theConcreteDet = 
00551               dynamic_cast<const TkStripMeasurementDet*>(idToDet(DetId(tmpId)));
00552             
00553             if(theConcreteDet == 0)
00554               throw MeasurementDetException("failed casting to TkStripMeasurementDet*");            
00555             TkStripMeasurementDet*  theConcreteDetUpdatable = 
00556               const_cast<TkStripMeasurementDet*>(theConcreteDet);
00557             //std::cout << "=== option3. fill det with id,#clust: " << tmpId  << " , " 
00558             //      << iregion->end() - beginIterator << std::endl;
00559             theConcreteDetUpdatable->update(beginIterator,endIterator,lazyClusterHandle,tmpId);  
00560             if (selfUpdateSkipClusters_){
00561               edmNew::DetSetVector<TkStripMeasurementDet::SiStripRegionalClusterRef>::const_iterator f=stripClusterRefs->find(tmpId);
00562               if (f!=stripClusterRefs->end())
00563                 theConcreteDetUpdatable->setRegionalClustersToSkip(f->begin(),f->end());
00564               else
00565                 theConcreteDetUpdatable->unset();
00566             }    
00567           }
00568         }//end loop cluster in one ragion
00569       }
00570     }//end of block for updating with regional clusters 
00571   }
00572 }
00573 
00574 
00575 
00576 const MeasurementDet* 
00577 MeasurementTrackerImpl::idToDet(const DetId& id) const
00578 {
00579   std::map<DetId,MeasurementDet*>::const_iterator it = theDetMap.find(id);
00580   if(it !=theDetMap.end()) {
00581     return it->second;
00582   }else{
00583     //throw exception;
00584   }
00585   
00586   return 0; //to avoid compile warning
00587 }
00588 
00589 void MeasurementTrackerImpl::initializeStripStatus(const SiStripQuality *quality, int qualityFlags, int qualityDebugFlags) const {
00590   TkStripMeasurementDet::BadStripCuts badStripCuts[4];
00591   if (qualityFlags & BadStrips) {
00592      edm::ParameterSet cutPset = pset_.getParameter<edm::ParameterSet>("badStripCuts");
00593      badStripCuts[SiStripDetId::TIB-3] = TkStripMeasurementDet::BadStripCuts(cutPset.getParameter<edm::ParameterSet>("TIB"));
00594      badStripCuts[SiStripDetId::TOB-3] = TkStripMeasurementDet::BadStripCuts(cutPset.getParameter<edm::ParameterSet>("TOB"));
00595      badStripCuts[SiStripDetId::TID-3] = TkStripMeasurementDet::BadStripCuts(cutPset.getParameter<edm::ParameterSet>("TID"));
00596      badStripCuts[SiStripDetId::TEC-3] = TkStripMeasurementDet::BadStripCuts(cutPset.getParameter<edm::ParameterSet>("TEC"));
00597   }
00598 
00599   if ((quality != 0) && (qualityFlags != 0))  {
00600     edm::LogInfo("MeasurementTracker") << "qualityFlags = " << qualityFlags;
00601     unsigned int on = 0, tot = 0; 
00602     unsigned int foff = 0, ftot = 0, aoff = 0, atot = 0; 
00603     for (std::vector<TkStripMeasurementDet*>::const_iterator i=theStripDets.begin();
00604          i!=theStripDets.end(); i++) {
00605       uint32_t detid = ((**i).geomDet().geographicalId()).rawId();
00606       if (qualityFlags & BadModules) {
00607           bool isOn = quality->IsModuleUsable(detid);
00608           (*i)->setActive(isOn);
00609           tot++; on += (unsigned int) isOn;
00610           if (qualityDebugFlags & BadModules) {
00611             edm::LogInfo("MeasurementTracker")<< "MeasurementTrackerImpl::initializeStripStatus : detid " << detid << " is " << (isOn ?  "on" : "off");
00612           }
00613        } else {
00614           (*i)->setActive(true);
00615        }
00616        // first turn all APVs and fibers ON
00617        (*i)->set128StripStatus(true); 
00618        if (qualityFlags & BadAPVFibers) {
00619           short badApvs   = quality->getBadApvs(detid);
00620           short badFibers = quality->getBadFibers(detid);
00621           for (int j = 0; j < 6; j++) {
00622              atot++;
00623              if (badApvs & (1 << j)) {
00624                 (*i)->set128StripStatus(false, j);
00625                 aoff++;
00626              }
00627           }
00628           for (int j = 0; j < 3; j++) {
00629              ftot++;
00630              if (badFibers & (1 << j)) {
00631                 (*i)->set128StripStatus(false, 2*j);
00632                 (*i)->set128StripStatus(false, 2*j+1);
00633                 foff++;
00634              }
00635           }
00636           (*i)->setMaskBad128StripBlocks((qualityFlags & MaskBad128StripBlocks) != 0);
00637        } 
00638        std::vector<TkStripMeasurementDet::BadStripBlock> &badStrips = (*i)->getBadStripBlocks();
00639        badStrips.clear();
00640        if (qualityFlags & BadStrips) {
00641             SiStripBadStrip::Range range = quality->getRange(detid);
00642             for (SiStripBadStrip::ContainerIterator bit = range.first; bit != range.second; ++bit) {
00643                 badStrips.push_back(quality->decode(*bit));
00644             }
00645             (*i)->setBadStripCuts(badStripCuts[SiStripDetId(detid).subdetId()-3]);
00646        }
00647     }
00648     if (qualityDebugFlags & BadModules) {
00649         edm::LogInfo("MeasurementTracker StripModuleStatus") << 
00650             " Total modules: " << tot << ", active " << on <<", inactive " << (tot - on);
00651     }
00652     if (qualityDebugFlags & BadAPVFibers) {
00653         edm::LogInfo("MeasurementTracker StripAPVStatus") << 
00654             " Total APVs: " << atot << ", active " << (atot-aoff) <<", inactive " << (aoff);
00655         edm::LogInfo("MeasurementTracker StripFiberStatus") << 
00656             " Total Fibers: " << ftot << ", active " << (ftot-foff) <<", inactive " << (foff);
00657     }
00658   } else {
00659     for (std::vector<TkStripMeasurementDet*>::const_iterator i=theStripDets.begin();
00660          i!=theStripDets.end(); i++) {
00661       (*i)->setActive(true);          // module ON
00662       (*i)->set128StripStatus(true);  // all APVs and fibers ON
00663     }
00664   }
00665 }
00666 
00667 void MeasurementTrackerImpl::initializePixelStatus(const SiPixelQuality *quality, const SiPixelFedCabling *pixelCabling, int qualityFlags, int qualityDebugFlags) const {
00668   if ((quality != 0) && (qualityFlags != 0))  {
00669     edm::LogInfo("MeasurementTracker") << "qualityFlags = " << qualityFlags;
00670     unsigned int on = 0, tot = 0, badrocs = 0; 
00671     for (std::vector<TkPixelMeasurementDet*>::const_iterator i=thePixelDets.begin();
00672          i!=thePixelDets.end(); i++) {
00673       uint32_t detid = ((**i).geomDet().geographicalId()).rawId();
00674       if (qualityFlags & BadModules) {
00675           bool isOn = quality->IsModuleUsable(detid);
00676           (*i)->setActive(isOn);
00677           tot++; on += (unsigned int) isOn;
00678           if (qualityDebugFlags & BadModules) {
00679             edm::LogInfo("MeasurementTracker")<< "MeasurementTrackerImpl::initializePixelStatus : detid " << detid << " is " << (isOn ?  "on" : "off");
00680           }
00681        } else {
00682           (*i)->setActive(true);
00683        }
00684        if ((qualityFlags & BadROCs) && (quality->getBadRocs(detid) != 0)) {
00685           std::vector<LocalPoint> badROCs = quality->getBadRocPositions(detid, *theTrackerGeom, pixelCabling);
00686           badrocs += badROCs.size();
00687           (*i)->setBadRocPositions(badROCs);
00688        } else {
00689           (*i)->clearBadRocPositions();  
00690        }
00691     }
00692     if (qualityDebugFlags & BadModules) {
00693         edm::LogInfo("MeasurementTracker PixelModuleStatus") << 
00694             " Total modules: " << tot << ", active " << on <<", inactive " << (tot - on);
00695     }
00696     if (qualityDebugFlags & BadROCs) {
00697         edm::LogInfo("MeasurementTracker PixelROCStatus") << " Total of bad ROCs: " << badrocs ;
00698     }
00699   } else {
00700     for (std::vector<TkPixelMeasurementDet*>::const_iterator i=thePixelDets.begin();
00701          i!=thePixelDets.end(); i++) {
00702       (*i)->setActive(true);          // module ON
00703     }
00704   }
00705 }
00706