00001 #include "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/ClusterParameterEstimator/interface/PixelClusterParameterEstimator.h"
00022 #include "RecoLocalTracker/Records/interface/TrackerCPERecord.h"
00023 #include "RecoLocalTracker/SiStripRecHitConverter/interface/SiStripRecHitMatcher.h"
00024 #include "RecoLocalTracker/SiStripRecHitConverter/interface/StripCPE.h"
00025
00026 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
00027 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00028 #include "TkStripMeasurementDet.h"
00029 #include "TkPixelMeasurementDet.h"
00030 #include "TkGluedMeasurementDet.h"
00031
00032 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00033 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
00034
00035 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00036 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00037 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00038 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00039 #include "CalibTracker/Records/interface/SiStripRegionCablingRcd.h"
00040
00041 #include <iostream>
00042 #include <typeinfo>
00043 #include <map>
00044
00045 #include <DataFormats/GeometrySurface/interface/BoundPlane.h>
00046 #include "DataFormats/Math/interface/deltaR.h"
00047
00048 #include "FWCore/ServiceRegistry/interface/Service.h"
00049 #include "FWCore/Services/interface/UpdaterService.h"
00050
00051 using namespace std;
00052
00053 OnDemandMeasurementTracker::OnDemandMeasurementTracker(const edm::ParameterSet& conf,
00054 const PixelClusterParameterEstimator* pixelCPE,
00055 const StripClusterParameterEstimator* stripCPE,
00056 const SiStripRecHitMatcher* hitMatcher,
00057 const TrackerGeometry* trackerGeom,
00058 const GeometricSearchTracker* geometricSearchTracker,
00059 const SiStripQuality *stripQuality,
00060 int stripQualityFlags,
00061 int stripQualityDebugFlags,
00062 const SiPixelQuality *pixelQuality,
00063 const SiPixelFedCabling *pixelCabling,
00064 int pixelQualityFlags,
00065 int pixelQualityDebugFlags,
00066 const SiStripRegionCabling * stripRegionCabling,
00067 bool isRegional):
00068 MeasurementTrackerImpl(conf,pixelCPE,stripCPE,hitMatcher,trackerGeom,geometricSearchTracker,
00069 stripQuality,stripQualityFlags,stripQualityDebugFlags,
00070 pixelQuality,pixelCabling,pixelQualityFlags,pixelQualityDebugFlags,
00071 isRegional)
00072 , category_("OnDemandMeasurementTracker")
00073 , StayPacked_(true)
00074 , StripOnDemand_(true)
00075 , PixelOnDemand_(false)
00076 , theStripRegionCabling(stripRegionCabling)
00077 {
00078
00079
00080
00081
00082
00083 for (DetContainer::iterator it=theDetMap.begin(); it!= theDetMap.end();++it)
00084 {
00085 DetODContainer::iterator inserted = theDetODMap.insert(make_pair(it->first,DetODStatus(const_cast<MeasurementDet*>(it->second)))).first;
00086
00087
00088 GeomDet::SubDetector subdet = it->second->geomDet().subDetector();
00089 if (subdet == GeomDetEnumerators::PixelBarrel || subdet == GeomDetEnumerators::PixelEndcap ){
00090
00091
00092 inserted->second.defined=false;
00093 inserted->second.updated=true;
00094 }
00095 else if (subdet == GeomDetEnumerators::TIB || subdet == GeomDetEnumerators::TOB ||
00096 subdet == GeomDetEnumerators::TID || subdet == GeomDetEnumerators::TEC )
00097 {
00098
00099 inserted->second.defined=false;
00100 inserted->second.updated=false;
00101
00102
00103 GlobalPoint center = it->second->geomDet().position();
00104 double eta = center.eta();
00105 double phi = center.phi();
00106 uint32_t id = it->first.rawId();
00107 SiStripRegionCabling::ElementIndex eIndex = theStripRegionCabling->elementIndex(SiStripRegionCabling::Position(eta,phi),
00108 SiStripRegionCabling::subdetFromDetId(id),
00109 SiStripRegionCabling::layerFromDetId(id));
00110 LogDebug(category_)<<"region selected (from "<<id<<" center) is:\n"
00111 <<"position: "<<center
00112 <<"\n center absolute index: "<<theStripRegionCabling->region(theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi)))
00113 <<"\n center position index: "<<theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi)).first<<
00114 " "<<theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi)).second
00115 <<"\n center postion: "<<theStripRegionCabling->position(theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi))).first<<
00116 " "<<theStripRegionCabling->position(theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi))).second
00117 <<"\n eta: "<<eta
00118 <<"\n phi: "<<phi
00119 <<"\n subedet: "<<SiStripRegionCabling::subdetFromDetId(id)
00120 <<" layer: "<<SiStripRegionCabling::layerFromDetId(id);
00121
00122
00123
00124 region_mapping[eIndex].push_back(inserted);
00125 }
00126 else{
00127
00128 edm::LogError(category_)<<"not a tracker geomdet in constructor: "<<it->first.rawId();
00129 throw MeasurementDetException("OnDemandMeasurementTracker dealing with a non tracker GeomDet.");
00130 }
00131 }
00132 if (theInactiveStripDetectorLabels.size()!=0)
00133 theRawInactiveStripDetIds.reserve(200);
00134 }
00135
00136
00137 void OnDemandMeasurementTracker::define( const edm::Handle< LazyGetter> & theLazyGetterH,
00138 std::auto_ptr< RefGetter > & theGetter ) const
00139 {
00140
00141
00142
00143
00144
00145
00146
00147
00148 for (DetODContainer::iterator it=theDetODMap.begin(); it!= theDetODMap.end();++it)
00149 {
00150 if (it->second.updated && !it->second.defined) continue;
00151 it->second.defined= false;
00152 it->second.updated = false;
00153 }
00154
00155
00156 for( std::map<SiStripRegionCabling::ElementIndex, std::vector<DetODContainer::iterator> >::iterator eIt= region_mapping.begin();
00157 eIt!=region_mapping.end();++eIt){
00158 std::pair<unsigned int, unsigned int> region_range;
00159
00160
00161 region_range.first = theGetter->size();
00162
00163 theStripRegionCabling->updateSiStripRefGetter<SiStripCluster> (*theGetter, theLazyGetterH, eIt->first);
00164
00165 region_range.second = theGetter->size();
00166
00167 LogDebug(category_)<<"between index: "<<region_range.first<<" "<<region_range.second
00168 <<"\n"<<dumpRegion(region_range,*theGetter,StayPacked_);
00169
00170
00171 for (std::vector<DetODContainer::iterator>::iterator dIt=eIt->second.begin();
00172 dIt!=eIt->second.end();++dIt){
00173 (*dIt)->second.region_range = region_range;
00174 (*dIt)->second.defined=true;
00175 LogDebug(category_)<<"detId: "<<(*dIt)->first.rawId()<<" in region range: "<<region_range.first<<" "<<region_range.second;
00176 }
00177 }
00178 }
00179
00180 void OnDemandMeasurementTracker::updateStrips( const edm::Event& event) const
00181 {
00182 bool oncePerEvent= edm::Service<UpdaterService>()->checkOnce("OnDemandMeasurementTracker::updateStrips::"+name_);
00183 bool failedToGet = false;
00184 if (!oncePerEvent)
00185 failedToGet = theRefGetterH.failedToGet() || theLazyGetterH.failedToGet();
00186
00187 if (oncePerEvent || failedToGet)
00188 {
00189 LogDebug(category_)<<"Updating siStrip on event: "<< (unsigned int) event.id().run() <<" : "<<(unsigned int) event.id().event();
00190
00191
00192 std::string stripClusterProducer = pset_.getParameter<std::string>("stripClusterProducer");
00193 event.getByLabel(stripClusterProducer,theRefGetterH);
00194
00195 std::string stripLazyGetter = pset_.getParameter<std::string>("stripLazyGetterProducer");
00196 event.getByLabel(stripLazyGetter,theLazyGetterH);
00197
00198
00199 if (selfUpdateSkipClusters_){
00200 theSkipClusterRefs=true;
00201 event.getByLabel(pset_.getParameter<edm::InputTag>("skipClusters"),theStripClusterRefs);
00202 }
00203
00204
00205 theRawInactiveStripDetIds.clear();
00206 getInactiveStrips(event,theRawInactiveStripDetIds);
00207 }
00208 }
00209
00210 void OnDemandMeasurementTracker::update( const edm::Event& event) const
00211 {
00212
00213
00214
00215
00216
00217 if (!PixelOnDemand_) {
00218 LogDebug(category_)<<"pixel are not OnDemand. updating them a la MeasurmentTracker.";
00219 MeasurementTrackerImpl::updatePixels(event);}
00220 else{
00221 edm::LogError(category_)<<"trying to update siPixel as on-demand. Not Implemented yet.";
00222 }
00223
00224 if (!StripOnDemand_) {
00225 LogDebug(category_)<<"strip are not OnDemand. updating them a la MeasurmentTracker.";
00226 MeasurementTrackerImpl::updateStrips(event);}
00227 else{
00228 LogDebug(category_)<<"strip are OnDemand. updating them a la OnDemandMeasurmentTracker.";
00229 updateStrips(event);
00230 }
00231 }
00232
00233 #include <sstream>
00234
00235 std::string OnDemandMeasurementTracker::dumpCluster(const std::vector<SiStripCluster> ::const_iterator & begin,const std::vector<SiStripCluster> ::const_iterator & end)const
00236 {
00237
00238 std::string tab=" ";
00239 std::stringstream ss;
00240 std::vector<SiStripCluster> ::const_iterator it = begin;
00241 unsigned int i=0;
00242 for (;it!=end;++it){
00243 ss<<tab<<i++<<") center: "<<it->barycenter()<<",id: "<<it->geographicalId()<<" with: "<<it->amplitudes().size()<<" strips\n"<<tab<<tab<<"{";
00244 for (unsigned int is=0;is!=it->amplitudes().size();++is){
00245 ss<<it->amplitudes()[is]<<" ";
00246 }ss<<"}\n";
00247 }
00248 return ss.str();
00249 }
00250
00251 std::string OnDemandMeasurementTracker::dumpRegion(std::pair<unsigned int,unsigned int> indexes,
00252 const RefGetter & theGetter,
00253 bool stayPacked)const
00254 {
00255
00256 std::stringstream ss;
00257 ss<<"cluster between: "<<indexes.first<<" and: "<<indexes.second<<"\n";
00258 for (unsigned int iRegion = indexes.first; iRegion != indexes.second; ++iRegion){
00259 uint32_t reg = SiStripRegionCabling::region((theGetter)[iRegion].region());
00260 SiStripRegionCabling::Position pos = theStripRegionCabling->position(reg);
00261 SiStripRegionCabling::PositionIndex posI = theStripRegionCabling->positionIndex(reg);
00262
00263 ss<<"Clusters for region:["<<iRegion<<"]"
00264 <<"\n element index: "<<(theGetter)[iRegion].region()
00265 <<"\n region absolute index: "<<reg
00266 <<"\n region position index: "<<posI.first<<" "<<posI.second
00267 <<"\n region position: "<<pos.first<<" "<<pos.second
00268 <<"\n"<< (stayPacked? " hidden to avoid unpacking." : dumpCluster((theGetter)[iRegion].begin(),(theGetter)[iRegion].end()));
00269 }
00270 return ss.str();
00271 }
00272
00273 void OnDemandMeasurementTracker::assign(const TkStripMeasurementDet * csmdet,
00274 DetODContainer::iterator * alreadyFound)const {
00275
00276
00277 TkStripMeasurementDet * smdet = const_cast<TkStripMeasurementDet *>(csmdet);
00278 DetId id = smdet->geomDet().geographicalId();
00279
00280 LogDebug(category_)<<"assigning: "<<id.rawId();
00281
00282
00283 DetODContainer::iterator elementInMap;
00284 if (alreadyFound){ elementInMap=*alreadyFound;}
00285 else{ elementInMap = theDetODMap.find(id);}
00286
00287 if ( elementInMap != theDetODMap.end()){
00288
00289 elementInMap->second.updated = true;
00290
00291 if (!theRawInactiveStripDetIds.empty() && std::binary_search(theRawInactiveStripDetIds.begin(), theRawInactiveStripDetIds.end(), id)) {
00292 smdet->setActiveThisEvent(false);
00293 return;
00294 }
00295
00296
00297 std::pair<unsigned int,unsigned int> & indexes =elementInMap->second.region_range;
00298
00299
00300 LogDebug(category_)<<"between index: "<<indexes.first<<" and: "<<indexes.second
00301 <<"\nretrieved for module: "<<id.rawId()
00302 <<"\n"<<dumpRegion(indexes,*theRefGetterH);
00303
00304
00305 for (unsigned int iRegion = indexes.first; iRegion != indexes.second; ++iRegion){
00306 RefGetter::record_pair range = (*theRefGetterH)[iRegion].find(id.rawId());
00307 if (range.first!=range.second){
00308
00309
00310 smdet->update(range.first, range.second, theLazyGetterH, id);
00311 LogDebug(category_)<<"Valid clusters for: "<<id.rawId()
00312 <<"\nnumber of regions defined here: "<< indexes.second-indexes.first
00313 <<"\n"<<dumpCluster(range.first,range.second);
00314 if (selfUpdateSkipClusters_){
00315
00316 edmNew::DetSetVector<TkStripMeasurementDet::SiStripRegionalClusterRef>::const_iterator f=theStripClusterRefs->find(id);
00317 if (f!=theStripClusterRefs->end())
00318 smdet->setRegionalClustersToSkip(f->begin(),f->end());
00319 else
00320 smdet->unset();
00321 }
00322
00323 return;}
00324 }
00325
00326
00327 smdet->setEmpty();
00328
00329 }
00330 else{
00331
00332 edm::LogError(category_)<<"failed to find the MeasurementDet for: "<<id.rawId();
00333 throw MeasurementDetException("failed to find the MeasurementDet for: <see message logger>");
00334 }
00335 }
00336
00337
00338
00339 const MeasurementDet*
00340 OnDemandMeasurementTracker::idToDet(const DetId& id) const
00341 {
00342
00343
00344
00345 DetODContainer::iterator it = theDetODMap.find(id);
00346 if ( it != theDetODMap.end()) {
00347
00348
00349 if (it->second.updated){LogDebug(category_)<<"found id: "<<id.rawId()<<" as aleardy updated."; return it->second.mdet;}
00350
00351 if (StripOnDemand_){
00352
00353 std::vector< const GeomDet*> comp = it->second.mdet->geomDet().components();
00354 if (!comp.empty()){
00355
00356 LogDebug(category_)<<"updating glued id: "<<id.rawId()<<" ("<<comp.size()<<").";
00357
00358 TkGluedMeasurementDet* theConcreteDet = static_cast<TkGluedMeasurementDet*>(it->second.mdet);
00359
00360
00361
00362 assign(theConcreteDet->monoDet());
00363
00364 assign(theConcreteDet->stereoDet());
00365
00366
00367 it->second.updated=true;
00368 }
00369 else{
00370
00371 LogDebug(category_)<<"updating singel id: "<<id.rawId();
00372
00373 TkStripMeasurementDet* theConcreteDet = static_cast<TkStripMeasurementDet*>(it->second.mdet);
00374
00375
00376 assign(theConcreteDet,&it);
00377 }
00378 }
00379
00380 return it->second.mdet;
00381 }
00382 else{
00383
00384 edm::LogError(category_)<<"failed to find the MeasurementDet for: "<<id.rawId();
00385 throw MeasurementDetException("failed to find the MeasurementDet for: <see message logger>");
00386 }
00387 return 0;
00388 }
00389
00390