CMS 3D CMS Logo

OnDemandMeasurementTracker.cc

Go to the documentation of this file.
00001 #include "RecoTracker/MeasurementDet/interface/OnDemandMeasurementTracker.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/SiStripDetId/interface/StripSubdetector.h"
00015 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00016 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00017 #include "DataFormats/SiStripCluster/interface/SiStripClusterCollection.h"
00018 
00019 #include "TrackingTools/MeasurementDet/interface/MeasurementDetException.h"
00020 
00021 #include "RecoLocalTracker/SiPixelRecHits/interface/CPEFromDetPosition.h"
00022 #include "RecoLocalTracker/ClusterParameterEstimator/interface/PixelClusterParameterEstimator.h"
00023 #include "RecoLocalTracker/Records/interface/TrackerCPERecord.h"
00024 #include "RecoLocalTracker/SiStripRecHitConverter/interface/SiStripRecHitMatcher.h"
00025 #include "RecoLocalTracker/SiStripRecHitConverter/interface/StripCPE.h"  
00026 
00027 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
00028 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00029 #include "RecoTracker/MeasurementDet/interface/TkStripMeasurementDet.h"
00030 #include "RecoTracker/MeasurementDet/interface/TkPixelMeasurementDet.h"
00031 #include "RecoTracker/MeasurementDet/interface/TkGluedMeasurementDet.h"
00032 
00033 #include "Utilities/Timing/interface/TimingReport.h"
00034 
00035 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00036 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
00037 
00038 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00039 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00040 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00041 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00042 #include "CalibTracker/Records/interface/SiStripRegionCablingRcd.h"
00043 
00044 #include <iostream>
00045 #include <typeinfo>
00046 #include <map>
00047 
00048 #include <DataFormats/GeometrySurface/interface/BoundPlane.h>
00049 #include "DataFormats/Math/interface/deltaR.h"
00050 
00051 #include "FWCore/ServiceRegistry/interface/Service.h"
00052 #include "FWCore/Services/interface/UpdaterService.h"
00053 
00054 using namespace std;
00055 
00056 OnDemandMeasurementTracker::OnDemandMeasurementTracker(const edm::ParameterSet&              conf,
00057                                                        const PixelClusterParameterEstimator* pixelCPE,
00058                                                        const StripClusterParameterEstimator* stripCPE,
00059                                                        const SiStripRecHitMatcher*  hitMatcher,
00060                                                        const TrackerGeometry*  trackerGeom,
00061                                                        const GeometricSearchTracker* geometricSearchTracker,
00062                                                        const SiStripQuality *stripQuality,
00063                                                        int   qualityFlags,
00064                                                        int   qualityDebugFlags,
00065                                                        const SiStripRegionCabling * stripRegionCabling,
00066                                                        bool isRegional):
00067   MeasurementTracker(conf,pixelCPE,stripCPE,hitMatcher,trackerGeom,geometricSearchTracker,
00068         stripQuality,qualityFlags,qualityDebugFlags,isRegional)
00069   , category_("OnDemandMeasurementTracker")
00070   , StayPacked_(true)
00071   , StripOnDemand_(true)
00072   , PixelOnDemand_(false)
00073   , theStripRegionCabling(stripRegionCabling)
00074 {
00075   //  the constructor does construct the regular MeasurementTracker
00076   //  then a smart copy of the DetMap is made into DetODMap: this could be avoided with modification to MeasurementDet interface
00077   //  the elementIndex to be defined in the refgetter is mapped to the detId
00078   //  flags are set to initialize the DetODMap
00079 
00080   for (DetContainer::iterator it=theDetMap.begin(); it!= theDetMap.end();++it)
00081     {
00082       DetODContainer::iterator inserted = theDetODMap.insert(make_pair(it->first,DetODStatus(const_cast<MeasurementDet*>(it->second)))).first;
00083 
00084 
00085       GeomDet::SubDetector subdet = it->second->geomDet().subDetector();
00086       if (subdet == GeomDetEnumerators::PixelBarrel  || subdet == GeomDetEnumerators::PixelEndcap ){
00087         //special flag treatement for pixels
00088         //one can never be updated and not defined. except if we don't need to care about them: pixels
00089         inserted->second.defined=false;
00090         inserted->second.updated=true;
00091       }//pixel module
00092       else if (subdet == GeomDetEnumerators::TIB || subdet == GeomDetEnumerators::TOB ||
00093           subdet == GeomDetEnumerators::TID || subdet == GeomDetEnumerators::TEC )
00094         {
00095           //set flag to false
00096           inserted->second.defined=false;
00097           inserted->second.updated=false;
00098 
00099           //what will be the element index in the refgetter
00100           GlobalPoint center = it->second->geomDet().position();
00101           double eta = center.eta();
00102           double phi = center.phi();
00103           uint32_t id = it->first.rawId();
00104           SiStripRegionCabling::ElementIndex eIndex = theStripRegionCabling->elementIndex(SiStripRegionCabling::Position(eta,phi),
00105                                                                                           SiStripRegionCabling::subdetFromDetId(id),
00106                                                                                           SiStripRegionCabling::layerFromDetId(id));
00107           LogDebug(category_)<<"region selected (from "<<id<<" center) is:\n"
00108                              <<"position: "<<center
00109                              <<"\n center absolute index: "<<theStripRegionCabling->region(theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi)))
00110                              <<"\n center position index: "<<theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi)).first<<
00111             " "<<theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi)).second
00112                              <<"\n center postion: "<<theStripRegionCabling->position(theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi))).first<<
00113             " "<<theStripRegionCabling->position(theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi))).second
00114                              <<"\n eta: "<<eta
00115                              <<"\n phi: "<<phi
00116                              <<"\n subedet: "<<SiStripRegionCabling::subdetFromDetId(id)
00117                              <<" layer: "<<SiStripRegionCabling::layerFromDetId(id);
00118 
00119           //      register those in a map
00120           //to be able to know what are the detid in a given elementIndex
00121           region_mapping[eIndex].push_back(inserted);
00122         }//strip module
00123       else{
00124         //abort
00125         edm::LogError(category_)<<"not a tracker geomdet in constructor: "<<it->first.rawId();
00126         throw MeasurementDetException("OnDemandMeasurementTracker dealing with a non tracker GeomDet.");
00127       }//abort
00128     }//loop over DetMap
00129 }
00130 
00131 
00132 void OnDemandMeasurementTracker::define( const edm::Handle< LazyGetter> & theLazyGetterH,
00133                                          std::auto_ptr< RefGetter > &  theGetter ) const
00134 {
00135   //  define is supposed to be call by an EDProducer module, which wil put the RefGetter in the event
00136   //  so that reference can be made to it.
00137   //  the lazy getter is retrieved by the calling module and passed along with the event
00138   //  the map is cleared, except for pixel
00139   //  then the known elementIndex are defined to the RefGetter. no unpacking is done at this time
00140   //  the defined region range is registered in the DetODMap for further use.
00141 
00142   //clear all defined tags to start from scratch (except for pixel)
00143   for (DetODContainer::iterator it=theDetODMap.begin(); it!= theDetODMap.end();++it)
00144     {
00145       if (it->second.updated && !it->second.defined) continue; //special treatement for pixels
00146       it->second.defined= false; 
00147       it->second.updated = false;
00148     }
00149 
00150   //define all the elementindex in the refgetter
00151   for( std::map<SiStripRegionCabling::ElementIndex, std::vector<DetODContainer::iterator> >::iterator eIt= region_mapping.begin();
00152        eIt!=region_mapping.end();++eIt){
00153     std::pair<uint, uint> region_range; 
00154     
00155     //before update of the refgetter
00156     region_range.first = theGetter->size();
00157     //update the refegetter with the elementindex
00158     theStripRegionCabling->updateSiStripRefGetter<SiStripCluster> (*theGetter, theLazyGetterH, eIt->first);
00159     //after update of the refgetter
00160     region_range.second = theGetter->size();
00161 
00162     LogDebug(category_)<<"between index: "<<region_range.first<<" "<<region_range.second
00163                        <<"\n"<<dumpRegion(region_range,*theGetter,StayPacked_);
00164     
00165     //now assign to each measurement det for that element index
00166     for (std::vector<DetODContainer::iterator>::iterator dIt=eIt->second.begin();
00167          dIt!=eIt->second.end();++dIt){
00168       (*dIt)->second.region_range = region_range;
00169       (*dIt)->second.defined=true;
00170       LogDebug(category_)<<"detId: "<<(*dIt)->first.rawId()<<" in region range: "<<region_range.first<<" "<<region_range.second;
00171     }//loop over MeasurementDet attached to that elementIndex
00172   }//loop over know elementindex
00173 }
00174 
00175 void OnDemandMeasurementTracker::updateStrips( const edm::Event& event) const 
00176 {
00177   bool oncePerEvent= edm::Service<UpdaterService>()->checkOnce("OnDemandMeasurementTracker::updateStrips::"+name_);
00178   bool failedToGet = false;
00179   if (!oncePerEvent)
00180     failedToGet = theRefGetterH.failedToGet() || theLazyGetterH.failedToGet();
00181 
00182   if (oncePerEvent || failedToGet)
00183     {
00184       LogDebug(category_)<<"Updating siStrip on event: "<< (uint) event.id().run() <<" : "<<(uint) event.id().event();
00185       
00186       //get the ref getter back from the event
00187       std::string stripClusterProducer = pset_.getParameter<std::string>("stripClusterProducer");
00188       event.getByLabel(stripClusterProducer,theRefGetterH);
00189       
00190       std::string stripLazyGetter = pset_.getParameter<std::string>("stripLazyGetterProducer");
00191       event.getByLabel(stripLazyGetter,theLazyGetterH);
00192     }
00193 }
00194 
00195 void OnDemandMeasurementTracker::update( const edm::Event& event) const
00196 {
00197   //  update is supposed to be called by any module that is useing the MeasurementTracker
00198   //  after checking the the event has not yet been seen
00199   //  update the pixel using MeasurementTracekr specific function
00200   //  retreive the RefGetter from the event: the very one that has been pass to define(...) and put into the event
00201 
00202   if (!PixelOnDemand_) {
00203     LogDebug(category_)<<"pixel are not OnDemand. updating them a la MeasurmentTracker.";
00204     MeasurementTracker::updatePixels(event);}
00205   else{
00206     edm::LogError(category_)<<"trying to update siPixel as on-demand. Not Implemented yet.";
00207   }
00208 
00209   if (!StripOnDemand_) {
00210     LogDebug(category_)<<"strip are not OnDemand. updating them a la MeasurmentTracker.";
00211     MeasurementTracker::updateStrips(event);}
00212   else{
00213     LogDebug(category_)<<"strip are OnDemand. updating them a la OnDemandMeasurmentTracker."; 
00214     updateStrips(event);
00215   }
00216 }
00217 
00218 #include <sstream>
00219 
00220 std::string OnDemandMeasurementTracker::dumpCluster(const std::vector<SiStripCluster> ::const_iterator & begin,const  std::vector<SiStripCluster> ::const_iterator & end)const
00221 {
00222   //  dumpCluster is a printout of all the clusters between the iterator. returns a string
00223   std::string tab="      ";
00224   std::stringstream ss;
00225   std::vector<SiStripCluster> ::const_iterator it = begin;
00226   uint i=0;
00227   for (;it!=end;++it){
00228     ss<<tab<<i++<<") center: "<<it->barycenter()<<",id: "<<it->geographicalId()<<" with: "<<it->amplitudes().size()<<" strips\n"<<tab<<tab<<"{";
00229     for (uint is=0;is!=it->amplitudes().size();++is){
00230       ss<<it->amplitudes()[is]<<" ";
00231     }ss<<"}\n";
00232   }
00233   return ss.str();
00234 }
00235 
00236 std::string OnDemandMeasurementTracker::dumpRegion(std::pair<uint,uint> indexes,
00237                                              const RefGetter & theGetter,
00238                                              bool stayPacked)const
00239 {
00240   //  dumpRegion is a printout of all the clusters in a region defined on the RefGetter. returns a string
00241   std::stringstream ss;
00242   ss<<"cluster between: "<<indexes.first<<" and: "<<indexes.second<<"\n";
00243   for (uint iRegion = indexes.first; iRegion != indexes.second; ++iRegion){    
00244     uint32_t reg = SiStripRegionCabling::region((theGetter)[iRegion].region());
00245     SiStripRegionCabling::Position pos = theStripRegionCabling->position(reg);
00246     SiStripRegionCabling::PositionIndex posI = theStripRegionCabling->positionIndex(reg);
00247     
00248     ss<<"Clusters for region:["<<iRegion<<"]"
00249       <<"\n element index: "<<(theGetter)[iRegion].region()
00250       <<"\n region absolute index: "<<reg
00251       <<"\n region position index: "<<posI.first<<" "<<posI.second
00252       <<"\n region position: "<<pos.first<<" "<<pos.second
00253       <<"\n"<< (stayPacked? " hidden to avoid unpacking." : dumpCluster((theGetter)[iRegion].begin(),(theGetter)[iRegion].end()));
00254   }
00255   return ss.str();
00256 }
00257 
00258 void OnDemandMeasurementTracker::assign(const TkStripMeasurementDet * csmdet,
00259                                   DetODContainer::iterator * alreadyFound)const {
00260   //  assign is using the handle to the refgetter and the region index range to update the MeasurementDet with their clusters
00261   
00262   TkStripMeasurementDet * smdet = const_cast<TkStripMeasurementDet *>(csmdet);
00263   DetId id = smdet->geomDet().geographicalId();
00264   
00265   LogDebug(category_)<<"assigning: "<<id.rawId();
00266 
00267   // what is the iterator. do not look again if already found and provided with
00268   DetODContainer::iterator elementInMap;
00269   if (alreadyFound){ elementInMap=*alreadyFound;}
00270   else{ elementInMap = theDetODMap.find(id);}
00271   
00272   if  ( elementInMap != theDetODMap.end()){
00273     //flag it as updated
00274     elementInMap->second.updated = true;
00275     //retrieve the region range index for this module
00276     std::pair<uint,uint> & indexes =elementInMap->second.region_range;
00277 
00278     //this printout will trigger unpacking. no problem. it is done on the next regular line (find(id.rawId())
00279     LogDebug(category_)<<"between index: "<<indexes.first<<" and: "<<indexes.second
00280                        <<"\nretrieved for module: "<<id.rawId()
00281                        <<"\n"<<dumpRegion(indexes,*theRefGetterH);
00282     
00283     //look for iterator range in the regions defined for that module
00284     for (uint iRegion = indexes.first; iRegion != indexes.second; ++iRegion){
00285       RefGetter::record_pair range = (*theRefGetterH)[iRegion].find(id.rawId());
00286       if (range.first!=range.second){
00287         //      found something not empty
00288         //update the measurementDet
00289         smdet->update(range.first, range.second, theLazyGetterH, id);
00290         LogDebug(category_)<<"Valid clusters for: "<<id.rawId()
00291                            <<"\nnumber of regions defined here: "<< indexes.second-indexes.first
00292                            <<"\n"<<dumpCluster(range.first,range.second);
00293         //and you are done
00294         return;}
00295     }//loop over regions, between indexes
00296 
00297     //if reached. no cluster are found. set the TkStripMeasurementDet to be empty
00298     smdet->setEmpty();
00299 
00300   }//found in the map
00301   else{
00302     //throw excpetion
00303     edm::LogError(category_)<<"failed to find the MeasurementDet for: "<<id.rawId();
00304     throw MeasurementDetException("failed to find the MeasurementDet for: <see message logger>");
00305   }
00306 }
00307 
00308 
00309 
00310 const MeasurementDet* 
00311 OnDemandMeasurementTracker::idToDet(const DetId& id) const
00312 {
00313   //  overloaded from MeasurementTracker
00314   //  find the detid. if not found throw exception
00315   //  if already updated: always for pixel or strip already queried. return it
00316   DetODContainer::iterator it = theDetODMap.find(id);
00317   if ( it != theDetODMap.end()) {
00318     
00319     //it has already been queried. and so already updated: nothing to be done here (valid for pixels too)
00320     if (it->second.updated){LogDebug(category_)<<"found id: "<<id.rawId()<<" as aleardy updated."; return it->second.mdet;}
00321     
00322     if (StripOnDemand_){
00323       //check glued or single
00324       std::vector< const GeomDet*> comp = it->second.mdet->geomDet().components();
00325       if (!comp.empty()){
00326         //glued det
00327         LogDebug(category_)<<"updating glued id: "<<id.rawId()<<" ("<<comp.size()<<").";
00328         //cast to specific type
00329         TkGluedMeasurementDet*  theConcreteDet = dynamic_cast<TkGluedMeasurementDet*>(it->second.mdet);
00330         //FIXME. do not require the dynamic cast, since we know what we do here
00331         //              const TkGluedMeasurementDet*  theConcreteDet = (const TkGluedMeasurementDet*) it->second.mdet;
00332         if (!theConcreteDet){
00333           edm::LogError(category_)<<"failed to cast to glued measurement det:"<<it->first.rawId();
00334           throw MeasurementDetException("failed to cast. see log file.");}
00335                 
00336         //      update the two components
00337         //update the mono
00338         assign(theConcreteDet->monoDet());
00339         //update the stereo
00340         assign(theConcreteDet->stereoDet());
00341               
00342         //flag the glued det as updated (components are flagged in assign)
00343         it->second.updated=true;
00344       }//glued det
00345       else{
00346         //single layer 
00347         LogDebug(category_)<<"updating singel id: "<<id.rawId();
00348         //cast to specific type
00349         TkStripMeasurementDet*  theConcreteDet = dynamic_cast<TkStripMeasurementDet*>(it->second.mdet);
00350         //FIXME. do not require the dynamic cast, since we know what we do here
00351         //              const TkStripMeasurementDet*  theConcreteDet = (const TkStripMeasurementDet*)it->second.mdet;
00352         if (!theConcreteDet){
00353           edm::LogError(category_)<<"failed to cast to strip measurement det:"<<it->first.rawId();
00354           throw MeasurementDetException("failed to cast. see log file.");}
00355 
00356         //update the single layer
00357         assign(theConcreteDet,&it);
00358       }//single det
00359     }
00360     //eventually return it
00361     return it->second.mdet;
00362   }//found in the DetODMap
00363   else{
00364     //throw excpetion
00365     edm::LogError(category_)<<"failed to find the MeasurementDet for: "<<id.rawId();
00366     throw MeasurementDetException("failed to find the MeasurementDet for: <see message logger>");
00367   }
00368   return 0;
00369 }
00370 
00371 

Generated on Tue Jun 9 17:45:29 2009 for CMSSW by  doxygen 1.5.4