CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OnDemandMeasurementTracker.cc
Go to the documentation of this file.
2 
5 
11 
13 
19 
21 
26 
29 #include "TkStripMeasurementDet.h"
30 #include "TkPixelMeasurementDet.h"
31 #include "TkGluedMeasurementDet.h"
32 
35 
41 
42 #include <iostream>
43 #include <typeinfo>
44 #include <map>
45 
48 
51 
52 using namespace std;
53 
55  const PixelClusterParameterEstimator* pixelCPE,
56  const StripClusterParameterEstimator* stripCPE,
57  const SiStripRecHitMatcher* hitMatcher,
58  const TrackerGeometry* trackerGeom,
59  const GeometricSearchTracker* geometricSearchTracker,
60  const SiStripQuality *stripQuality,
61  int stripQualityFlags,
62  int stripQualityDebugFlags,
63  const SiPixelQuality *pixelQuality,
64  const SiPixelFedCabling *pixelCabling,
65  int pixelQualityFlags,
66  int pixelQualityDebugFlags,
67  const SiStripRegionCabling * stripRegionCabling,
68  bool isRegional):
69  MeasurementTrackerImpl(conf,pixelCPE,stripCPE,hitMatcher,trackerGeom,geometricSearchTracker,
70  stripQuality,stripQualityFlags,stripQualityDebugFlags,
71  pixelQuality,pixelCabling,pixelQualityFlags,pixelQualityDebugFlags,
72  isRegional)
73  , category_("OnDemandMeasurementTracker")
74  , StayPacked_(true)
75  , StripOnDemand_(true)
76  , PixelOnDemand_(false)
77  , theStripRegionCabling(stripRegionCabling)
78 {
79  // the constructor does construct the regular MeasurementTracker
80  // then a smart copy of the DetMap is made into DetODMap: this could be avoided with modification to MeasurementDet interface
81  // the elementIndex to be defined in the refgetter is mapped to the detId
82  // flags are set to initialize the DetODMap
83 
84  std::map<SiStripRegionCabling::ElementIndex, std::vector< DetODContainer::const_iterator> > local_mapping;
85 
86  for (DetContainer::iterator it=theDetMap.begin(); it!= theDetMap.end();++it)
87  {
88  DetODContainer::iterator inserted = theDetODMap.insert(make_pair(it->first,DetODStatus(const_cast<MeasurementDet*>(it->second)))).first;
89 
90 
91  GeomDet::SubDetector subdet = it->second->geomDet().subDetector();
93  //special flag treatement for pixels
94  //one can never be updated and not defined. except if we don't need to care about them: pixels
95  inserted->second.defined=false;
96  inserted->second.updated=true;
97  }//pixel module
98  else if (subdet == GeomDetEnumerators::TIB || subdet == GeomDetEnumerators::TOB ||
99  subdet == GeomDetEnumerators::TID || subdet == GeomDetEnumerators::TEC )
100  {
101  //set flag to false
102  inserted->second.defined=false;
103  inserted->second.updated=false;
104 
105  //what will be the element index in the refgetter
106  GlobalPoint center = it->second->geomDet().position();
107  double eta = center.eta();
108  double phi = center.phi();
109  uint32_t id = it->first;
113  LogDebug(category_)<<"region selected (from "<<id<<" center) is:\n"
114  <<"position: "<<center
116  <<"\n center position index: "<<theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi)).first<<
120  <<"\n eta: "<<eta
121  <<"\n phi: "<<phi
122  <<"\n subedet: "<<SiStripRegionCabling::subdetFromDetId(id)
123  <<" layer: "<<SiStripRegionCabling::layerFromDetId(id);
124 
125  // register those in a map
126  //to be able to know what are the detid in a given elementIndex
127  local_mapping[eIndex].push_back(inserted);
128  }//strip module
129  else{
130  //abort
131  edm::LogError(category_)<<"not a tracker geomdet in constructor: "<<it->first;
132  throw MeasurementDetException("OnDemandMeasurementTracker dealing with a non tracker GeomDet.");
133  }//abort
134  }//loop over DetMap
135  if (theInactiveStripDetectorLabels.size()!=0)
136  theRawInactiveStripDetIds.reserve(200);
137 
138  //move into a vector
139  region_mapping.reserve(local_mapping.size());
140  for( auto eIt= local_mapping.begin();
141  eIt!=local_mapping.end();++eIt)
142  region_mapping.push_back(std::make_pair((*eIt).first,(*eIt).second));
143 }
144 
145 
147  std::auto_ptr< RefGetter > & aGetter ) const
148 {
149  // define is supposed to be call by an EDProducer module, which wil put the RefGetter in the event
150  // so that reference can be made to it.
151  // the lazy getter is retrieved by the calling module and passed along with the event
152  // the map is cleared, except for pixel
153  // then the known elementIndex are defined to the RefGetter. no unpacking is done at this time
154  // the defined region range is registered in the DetODMap for further use.
155 
156  //clear all defined tags to start from scratch (except for pixel)
157  for (DetODContainer::iterator it=theDetODMap.begin(); it!= theDetODMap.end();++it)
158  {
159  if (it->second.updated && !it->second.defined) continue; //special treatement for pixels
160  it->second.defined= false;
161  it->second.updated = false;
162  }
163 
164  // nedeed??
165  theStDets.setLazyGetter(aLazyGetterH);
166 
167 
168  //define all the elementindex in the refgetter
169  for(auto eIt= region_mapping.begin();
170  eIt!=region_mapping.end();++eIt){
171  std::pair<unsigned int, unsigned int> region_range;
172 
173  //before update of the refgetter
174  region_range.first = aGetter->size();
175  //update the refegetter with the elementindex
176  theStripRegionCabling->updateSiStripRefGetter<SiStripCluster> (*aGetter, aLazyGetterH, eIt->first);
177  //after update of the refgetter
178  region_range.second = aGetter->size();
179 
180  LogDebug(category_)<<"between index: "<<region_range.first<<" "<<region_range.second
181  <<"\n"<<dumpRegion(region_range,*aGetter,StayPacked_);
182 
183  //now assign to each measurement det for that element index
184  for (auto dIt=eIt->second.begin();
185  dIt!=eIt->second.end();++dIt){
186  DetODStatus & elem = const_cast<DetODStatus &>((*dIt)->second);
187  elem.region_range = region_range;
188  elem.defined=true;
189  LogDebug(category_)<<"detId: "<<(*dIt)->first<<" in region range: "<<region_range.first<<" "<<region_range.second;
190  }//loop over MeasurementDet attached to that elementIndex
191  }//loop over know elementindex
192 }
193 
195 {
196  bool oncePerEvent= edm::Service<UpdaterService>()->checkOnce("OnDemandMeasurementTracker::updateStrips::"+name_);
197  bool failedToGet = false;
198  if (!oncePerEvent)
199  failedToGet = theRefGetterH.failedToGet() || theLazyGetterH.failedToGet();
200 
201  if (oncePerEvent || failedToGet)
202  {
203  LogDebug(category_)<<"Updating siStrip on event: "<< (unsigned int) event.id().run() <<" : "<<(unsigned int) event.id().event();
204 
205  //get the ref getter back from the event
206  std::string stripClusterProducer = pset_.getParameter<std::string>("stripClusterProducer");
207  event.getByLabel(stripClusterProducer,theRefGetterH);
208 
209  std::string stripLazyGetter = pset_.getParameter<std::string>("stripLazyGetterProducer");
210  event.getByLabel(stripLazyGetter,theLazyGetterH);
211 
213 
214 
215  //get the skip clusters
217  theSkipClusterRefs=true;
218  event.getByLabel(pset_.getParameter<edm::InputTag>("skipClusters"),theStripClusterMask);
220  } else {
221  theStDets.clusterToSkip().clear();
222  }
223 
224  //get the detid that are inactive
227  }
228 }
229 
231 {
232  // update is supposed to be called by any module that is useing the MeasurementTracker
233  // after checking the the event has not yet been seen
234  // update the pixel using MeasurementTracekr specific function
235  // retreive the RefGetter from the event: the very one that has been pass to define(...) and put into the event
236 
237  if (!PixelOnDemand_) {
238  LogDebug(category_)<<"pixel are not OnDemand. updating them a la MeasurmentTracker.";
240  else{
241  edm::LogError(category_)<<"trying to update siPixel as on-demand. Not Implemented yet.";
242  }
243 
244  if (!StripOnDemand_) {
245  LogDebug(category_)<<"strip are not OnDemand. updating them a la MeasurmentTracker.";
247  else{
248  LogDebug(category_)<<"strip are OnDemand. updating them a la OnDemandMeasurmentTracker.";
249  updateStrips(event);
250  }
251 }
252 
253 #include <sstream>
254 
255 std::string OnDemandMeasurementTracker::dumpCluster(const std::vector<SiStripCluster> ::const_iterator & begin,const std::vector<SiStripCluster> ::const_iterator & end)const
256 {
257  // dumpCluster is a printout of all the clusters between the iterator. returns a string
258  std::string tab=" ";
259  std::stringstream ss;
260  std::vector<SiStripCluster> ::const_iterator it = begin;
261  unsigned int i=0;
262  for (;it!=end;++it){
263  ss<<tab<<i++<<") center: "<<it->barycenter()<<",id: "<<it->geographicalId()<<" with: "<<it->amplitudes().size()<<" strips\n"<<tab<<tab<<"{";
264  for (unsigned int is=0;is!=it->amplitudes().size();++is){
265  ss<<it->amplitudes()[is]<<" ";
266  }ss<<"}\n";
267  }
268  return ss.str();
269 }
270 
271 std::string OnDemandMeasurementTracker::dumpRegion(std::pair<unsigned int,unsigned int> indexes,
272  const RefGetter & theGetter,
273  bool stayPacked)const
274 {
275  // dumpRegion is a printout of all the clusters in a region defined on the RefGetter. returns a string
276  std::stringstream ss;
277  ss<<"cluster between: "<<indexes.first<<" and: "<<indexes.second<<"\n";
278  for (unsigned int iRegion = indexes.first; iRegion != indexes.second; ++iRegion){
279  uint32_t reg = SiStripRegionCabling::region((theGetter)[iRegion].region());
282 
283  ss<<"Clusters for region:["<<iRegion<<"]"
284  <<"\n element index: "<<(theGetter)[iRegion].region()
285  <<"\n region absolute index: "<<reg
286  <<"\n region position index: "<<posI.first<<" "<<posI.second
287  <<"\n region position: "<<pos.first<<" "<<pos.second
288  <<"\n"<< (stayPacked? " hidden to avoid unpacking." : dumpCluster((theGetter)[iRegion].begin(),(theGetter)[iRegion].end()));
289  }
290  return ss.str();
291 }
292 
294  DetODContainer::iterator * alreadyFound) const {
295  // assign is using the handle to the refgetter and the region index range to update the MeasurementDet with their clusters
296 
297  TkStripMeasurementDet * smdet = const_cast<TkStripMeasurementDet *>(csmdet);
298  DetId id = smdet->rawId();
299 
300  LogDebug(category_)<<"assigning: "<<id.rawId();
301 
302  // what is the iterator. do not look again if already found and provided with
303  DetODContainer::iterator elementInMap;
304  if (alreadyFound){ elementInMap=*alreadyFound;}
305  else{ elementInMap = theDetODMap.find(id);}
306 
307  if ( elementInMap != theDetODMap.end()){
308  //flag it as updated
309  elementInMap->second.updated = true;
310 
311  if (!theRawInactiveStripDetIds.empty() && std::binary_search(theRawInactiveStripDetIds.begin(), theRawInactiveStripDetIds.end(), id)) {
312  smdet->setActiveThisEvent(false);
313  return;
314  }
315 
316  //retrieve the region range index for this module
317  std::pair<unsigned int,unsigned int> & indexes =elementInMap->second.region_range;
318 
319  //this printout will trigger unpacking. no problem. it is done on the next regular line (find(id.rawId())
320  LogDebug(category_)<<"between index: "<<indexes.first<<" and: "<<indexes.second
321  <<"\nretrieved for module: "<<id.rawId()
322  <<"\n"<<dumpRegion(indexes,*theRefGetterH);
323 
324  //look for iterator range in the regions defined for that module
325  for (unsigned int iRegion = indexes.first; iRegion != indexes.second; ++iRegion){
326  RefGetter::record_pair range = (*theRefGetterH)[iRegion].find(id.rawId());
327  if (range.first!=range.second){
328  // found something not empty
329  //update the measurementDet
330  smdet->update(range.first, range.second);
331  LogDebug(category_)<<"Valid clusters for: "<<id.rawId()
332  <<"\nnumber of regions defined here: "<< indexes.second-indexes.first
333  <<"\n"<<dumpCluster(range.first,range.second);
334  /* since theStripsToSkip is a "static" pointer of the MT, no need to set it at all time.
335  if (selfUpdateSkipClusters_){
336  //assign skip clusters
337  smdet->setClusterToSkip(&theStripsToSkip);
338  }
339  */
340  //and you are done
341  return;}
342  }//loop over regions, between indexes
343 
344  //if reached. no cluster are found. set the TkStripMeasurementDet to be empty
345  smdet->setEmpty();
346 
347  }//found in the map
348  else{
349  //throw excpetion
350  edm::LogError(category_)<<"failed to find the MeasurementDet for: "<<id.rawId();
351  throw MeasurementDetException("failed to find the MeasurementDet for: <see message logger>");
352  }
353 }
354 
355 
356 
357 const MeasurementDet*
359 {
360  // overloaded from MeasurementTracker
361  // find the detid. if not found throw exception
362  // if already updated: always for pixel or strip already queried. return it
363  DetODContainer::iterator it = theDetODMap.find(id);
364  if ( it != theDetODMap.end()) {
365 
366  //it has already been queried. and so already updated: nothing to be done here (valid for pixels too)
367  if (it->second.updated){
368  LogDebug(category_)<<"found id: "<<id.rawId()<<" as aleardy updated.";
369  return it->second.mdet;
370  }
371 
372  if (StripOnDemand_){
373  //check glued or single
374  if (it->second.glued){
375  //glued det
376  LogDebug(category_)<<"updating glued id: "<<id.rawId();
377  //cast to specific type
378  TkGluedMeasurementDet* theConcreteDet = static_cast<TkGluedMeasurementDet*>(it->second.mdet);
379 
380  // update the two components
381  //update the mono
382  assign(theConcreteDet->monoDet());
383  //update the stereo
384  assign(theConcreteDet->stereoDet());
385 
386  //flag the glued det as updated (components are flagged in assign)
387  it->second.updated=true;
388  }//glued det
389  else{
390  //single layer
391  LogDebug(category_)<<"updating singel id: "<<id.rawId();
392  //cast to specific type
393  TkStripMeasurementDet* theConcreteDet = static_cast<TkStripMeasurementDet*>(it->second.mdet);
394 
395  //update the single layer
396  assign(theConcreteDet,&it);
397  }//single det
398  }
399  //eventually return it
400  return it->second.mdet;
401  }//found in the DetODMap
402  else{
403  //throw excpetion
404  edm::LogError(category_)<<"failed to find the MeasurementDet for: "<<id.rawId();
405  throw MeasurementDetException("failed to find the MeasurementDet for: <see message logger>");
406  }
407  return 0;
408 }
409 
410 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
static const ElementIndex elementIndex(const uint32_t region, const SubDet, const uint32_t layer)
OnDemandMeasurementTracker(const edm::ParameterSet &conf, const PixelClusterParameterEstimator *pixelCPE, const StripClusterParameterEstimator *stripCPE, const SiStripRecHitMatcher *hitMatcher, const TrackerGeometry *trackerGeom, const GeometricSearchTracker *geometricSearchTracker, const SiStripQuality *stripQuality, int stripQualityFlags, int stripQualityDebugFlags, const SiPixelQuality *pixelQuality, const SiPixelFedCabling *pixelCabling, int pixelQualityFlags, int pixelQualityDebugFlags, const SiStripRegionCabling *stripRegionCabling, bool isRegional=false)
constructor
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
void update(const detset &detSet)
int i
Definition: DBlmapReader.cc:9
edm::Handle< edm::LazyGetter< SiStripCluster > > theLazyGetterH
bool PixelOnDemand_
internal flag to do pixel on demand (not configurable) false by default
edm::Handle< edm::RefGetter< SiStripCluster > > theRefGetterH
the handle is retrieved from the event to make reference to cluster in it
const PositionIndex positionIndex(const uint32_t) const
void update(const edm::Event &) const
MeasurementTracker overloaded function.
const SiStripRegionCabling * theStripRegionCabling
the cabling region tool to update a RefGetter
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
void updateStrips(const edm::Event &) const
std::vector< bool > & clusterToSkip() const
std::pair< typename record_type::const_iterator, typename record_type::const_iterator > record_pair
Definition: RefGetter.h:27
const TkStripMeasurementDet * monoDet() const
const std::vector< edm::InputTag > theInactiveStripDetectorLabels
std::string dumpCluster(const std::vector< SiStripCluster >::const_iterator &begin, const std::vector< SiStripCluster >::const_iterator &end) const
some printouts, exclusively under LogDebug
T eta() const
U second(std::pair< T, U > const &p)
std::vector< uint32_t > theRawInactiveStripDetIds
edm::Handle< edm::ContainerMask< edm::LazyGetter< SiStripCluster > > > theStripClusterMask
void updateSiStripRefGetter(edm::RefGetter< T > &refgetter, const edm::Handle< edm::LazyGetter< T > > &lazygetter, const ElementIndex) const
DetODContainer theDetODMap
mapping of detid -&gt; MeasurementDet+flags+region_range
void updatePixels(const edm::Event &) const
static const SubDet subdetFromDetId(const uint32_t detid)
bool StayPacked_
internal flag to avoid unpacking things with LogDebug on
std::pair< double, double > Position
#define end
Definition: vmac.h:38
const edm::ParameterSet & pset_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool first
Definition: L1TdeRCT.cc:94
void getInactiveStrips(const edm::Event &event, std::vector< uint32_t > &rawInactiveDetIds) const
void setActiveThisEvent(bool active)
Turn on/off the module for reconstruction for one events. This per-event flag is cleared by any call ...
tuple conf
Definition: dbtoconf.py:185
bool StripOnDemand_
internal flag to do strip on demand (not configurable) true by default
std::string category_
log category
Definition: DetId.h:20
const Position position(const uint32_t) const
static const uint32_t layerFromDetId(const uint32_t detid)
a class that holds flags, region_range (in RefGetter) for a given MeasurementDet
T eta() const
Definition: PV3DBase.h:75
void setLazyGetter(edm::Handle< LazyGetter > const &lg)
const uint32_t region(const Position) const
edm::EventID id() const
Definition: EventBase.h:56
#define begin
Definition: vmac.h:31
unsigned int rawId() const
void updateStrips(const edm::Event &event) const
void assign(const TkStripMeasurementDet *csmdet, DetODContainer::iterator *alreadyFound=0) const
assigne the cluster iterator to the TkStipMeasurementDet (const_cast in the way)
const TkStripMeasurementDet * stereoDet() const
std::pair< unsigned int, unsigned int > region_range
std::pair< uint32_t, uint32_t > PositionIndex
std::string dumpRegion(std::pair< unsigned int, unsigned int > indexes, const RefGetter &theGetter, bool stayUnpacked=false) const
virtual const MeasurementDet * idToDet(const DetId &id) const
MeasurementDetSystem interface.
void define(const edm::Handle< edm::LazyGetter< SiStripCluster > > &, std::auto_ptr< RefGetter > &) const
OnDemandMeasurementTracker specific function to be called to define the region in the RefGetter accor...
Definition: DDAxes.h:10
StMeasurementDetSet theStDets