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 
18 
20 
25 
31 
34 
40 
41 #include <iostream>
42 #include <typeinfo>
43 #include <map>
44 
47 
50 
51 using namespace std;
52 
54  const PixelClusterParameterEstimator* pixelCPE,
55  const StripClusterParameterEstimator* stripCPE,
56  const SiStripRecHitMatcher* hitMatcher,
57  const TrackerGeometry* trackerGeom,
58  const GeometricSearchTracker* geometricSearchTracker,
59  const SiStripQuality *stripQuality,
60  int stripQualityFlags,
61  int stripQualityDebugFlags,
62  const SiPixelQuality *pixelQuality,
63  const SiPixelFedCabling *pixelCabling,
64  int pixelQualityFlags,
65  int pixelQualityDebugFlags,
66  const SiStripRegionCabling * stripRegionCabling,
67  bool isRegional):
68  MeasurementTracker(conf,pixelCPE,stripCPE,hitMatcher,trackerGeom,geometricSearchTracker,
69  stripQuality,stripQualityFlags,stripQualityDebugFlags,
70  pixelQuality,pixelCabling,pixelQualityFlags,pixelQualityDebugFlags,
71  isRegional)
72  , category_("OnDemandMeasurementTracker")
73  , StayPacked_(true)
74  , StripOnDemand_(true)
75  , PixelOnDemand_(false)
76  , theStripRegionCabling(stripRegionCabling)
77 {
78  // the constructor does construct the regular MeasurementTracker
79  // then a smart copy of the DetMap is made into DetODMap: this could be avoided with modification to MeasurementDet interface
80  // the elementIndex to be defined in the refgetter is mapped to the detId
81  // flags are set to initialize the DetODMap
82 
83  for (DetContainer::iterator it=theDetMap.begin(); it!= theDetMap.end();++it)
84  {
85  DetODContainer::iterator inserted = theDetODMap.insert(make_pair(it->first,DetODStatus(const_cast<MeasurementDet*>(it->second)))).first;
86 
87 
88  GeomDet::SubDetector subdet = it->second->geomDet().subDetector();
90  //special flag treatement for pixels
91  //one can never be updated and not defined. except if we don't need to care about them: pixels
92  inserted->second.defined=false;
93  inserted->second.updated=true;
94  }//pixel module
95  else if (subdet == GeomDetEnumerators::TIB || subdet == GeomDetEnumerators::TOB ||
96  subdet == GeomDetEnumerators::TID || subdet == GeomDetEnumerators::TEC )
97  {
98  //set flag to false
99  inserted->second.defined=false;
100  inserted->second.updated=false;
101 
102  //what will be the element index in the refgetter
103  GlobalPoint center = it->second->geomDet().position();
104  double eta = center.eta();
105  double phi = center.phi();
106  uint32_t id = it->first.rawId();
110  LogDebug(category_)<<"region selected (from "<<id<<" center) is:\n"
111  <<"position: "<<center
113  <<"\n center position index: "<<theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi)).first<<
117  <<"\n eta: "<<eta
118  <<"\n phi: "<<phi
119  <<"\n subedet: "<<SiStripRegionCabling::subdetFromDetId(id)
120  <<" layer: "<<SiStripRegionCabling::layerFromDetId(id);
121 
122  // register those in a map
123  //to be able to know what are the detid in a given elementIndex
124  region_mapping[eIndex].push_back(inserted);
125  }//strip module
126  else{
127  //abort
128  edm::LogError(category_)<<"not a tracker geomdet in constructor: "<<it->first.rawId();
129  throw MeasurementDetException("OnDemandMeasurementTracker dealing with a non tracker GeomDet.");
130  }//abort
131  }//loop over DetMap
132 }
133 
134 
136  std::auto_ptr< RefGetter > & theGetter ) const
137 {
138  // define is supposed to be call by an EDProducer module, which wil put the RefGetter in the event
139  // so that reference can be made to it.
140  // the lazy getter is retrieved by the calling module and passed along with the event
141  // the map is cleared, except for pixel
142  // then the known elementIndex are defined to the RefGetter. no unpacking is done at this time
143  // the defined region range is registered in the DetODMap for further use.
144 
145  //clear all defined tags to start from scratch (except for pixel)
146  for (DetODContainer::iterator it=theDetODMap.begin(); it!= theDetODMap.end();++it)
147  {
148  if (it->second.updated && !it->second.defined) continue; //special treatement for pixels
149  it->second.defined= false;
150  it->second.updated = false;
151  }
152 
153  //define all the elementindex in the refgetter
154  for( std::map<SiStripRegionCabling::ElementIndex, std::vector<DetODContainer::iterator> >::iterator eIt= region_mapping.begin();
155  eIt!=region_mapping.end();++eIt){
156  std::pair<unsigned int, unsigned int> region_range;
157 
158  //before update of the refgetter
159  region_range.first = theGetter->size();
160  //update the refegetter with the elementindex
162  //after update of the refgetter
163  region_range.second = theGetter->size();
164 
165  LogDebug(category_)<<"between index: "<<region_range.first<<" "<<region_range.second
166  <<"\n"<<dumpRegion(region_range,*theGetter,StayPacked_);
167 
168  //now assign to each measurement det for that element index
169  for (std::vector<DetODContainer::iterator>::iterator dIt=eIt->second.begin();
170  dIt!=eIt->second.end();++dIt){
171  (*dIt)->second.region_range = region_range;
172  (*dIt)->second.defined=true;
173  LogDebug(category_)<<"detId: "<<(*dIt)->first.rawId()<<" in region range: "<<region_range.first<<" "<<region_range.second;
174  }//loop over MeasurementDet attached to that elementIndex
175  }//loop over know elementindex
176 }
177 
179 {
180  bool oncePerEvent= edm::Service<UpdaterService>()->checkOnce("OnDemandMeasurementTracker::updateStrips::"+name_);
181  bool failedToGet = false;
182  if (!oncePerEvent)
183  failedToGet = theRefGetterH.failedToGet() || theLazyGetterH.failedToGet();
184 
185  if (oncePerEvent || failedToGet)
186  {
187  LogDebug(category_)<<"Updating siStrip on event: "<< (unsigned int) event.id().run() <<" : "<<(unsigned int) event.id().event();
188 
189  //get the ref getter back from the event
190  std::string stripClusterProducer = pset_.getParameter<std::string>("stripClusterProducer");
191  event.getByLabel(stripClusterProducer,theRefGetterH);
192 
193  std::string stripLazyGetter = pset_.getParameter<std::string>("stripLazyGetterProducer");
194  event.getByLabel(stripLazyGetter,theLazyGetterH);
195  }
196 }
197 
199 {
200  // update is supposed to be called by any module that is useing the MeasurementTracker
201  // after checking the the event has not yet been seen
202  // update the pixel using MeasurementTracekr specific function
203  // retreive the RefGetter from the event: the very one that has been pass to define(...) and put into the event
204 
205  if (!PixelOnDemand_) {
206  LogDebug(category_)<<"pixel are not OnDemand. updating them a la MeasurmentTracker.";
208  else{
209  edm::LogError(category_)<<"trying to update siPixel as on-demand. Not Implemented yet.";
210  }
211 
212  if (!StripOnDemand_) {
213  LogDebug(category_)<<"strip are not OnDemand. updating them a la MeasurmentTracker.";
215  else{
216  LogDebug(category_)<<"strip are OnDemand. updating them a la OnDemandMeasurmentTracker.";
217  updateStrips(event);
218  }
219 }
220 
221 #include <sstream>
222 
223 std::string OnDemandMeasurementTracker::dumpCluster(const std::vector<SiStripCluster> ::const_iterator & begin,const std::vector<SiStripCluster> ::const_iterator & end)const
224 {
225  // dumpCluster is a printout of all the clusters between the iterator. returns a string
226  std::string tab=" ";
227  std::stringstream ss;
228  std::vector<SiStripCluster> ::const_iterator it = begin;
229  unsigned int i=0;
230  for (;it!=end;++it){
231  ss<<tab<<i++<<") center: "<<it->barycenter()<<",id: "<<it->geographicalId()<<" with: "<<it->amplitudes().size()<<" strips\n"<<tab<<tab<<"{";
232  for (unsigned int is=0;is!=it->amplitudes().size();++is){
233  ss<<it->amplitudes()[is]<<" ";
234  }ss<<"}\n";
235  }
236  return ss.str();
237 }
238 
239 std::string OnDemandMeasurementTracker::dumpRegion(std::pair<unsigned int,unsigned int> indexes,
240  const RefGetter & theGetter,
241  bool stayPacked)const
242 {
243  // dumpRegion is a printout of all the clusters in a region defined on the RefGetter. returns a string
244  std::stringstream ss;
245  ss<<"cluster between: "<<indexes.first<<" and: "<<indexes.second<<"\n";
246  for (unsigned int iRegion = indexes.first; iRegion != indexes.second; ++iRegion){
247  uint32_t reg = SiStripRegionCabling::region((theGetter)[iRegion].region());
250 
251  ss<<"Clusters for region:["<<iRegion<<"]"
252  <<"\n element index: "<<(theGetter)[iRegion].region()
253  <<"\n region absolute index: "<<reg
254  <<"\n region position index: "<<posI.first<<" "<<posI.second
255  <<"\n region position: "<<pos.first<<" "<<pos.second
256  <<"\n"<< (stayPacked? " hidden to avoid unpacking." : dumpCluster((theGetter)[iRegion].begin(),(theGetter)[iRegion].end()));
257  }
258  return ss.str();
259 }
260 
262  DetODContainer::iterator * alreadyFound)const {
263  // assign is using the handle to the refgetter and the region index range to update the MeasurementDet with their clusters
264 
265  TkStripMeasurementDet * smdet = const_cast<TkStripMeasurementDet *>(csmdet);
266  DetId id = smdet->geomDet().geographicalId();
267 
268  LogDebug(category_)<<"assigning: "<<id.rawId();
269 
270  // what is the iterator. do not look again if already found and provided with
271  DetODContainer::iterator elementInMap;
272  if (alreadyFound){ elementInMap=*alreadyFound;}
273  else{ elementInMap = theDetODMap.find(id);}
274 
275  if ( elementInMap != theDetODMap.end()){
276  //flag it as updated
277  elementInMap->second.updated = true;
278  //retrieve the region range index for this module
279  std::pair<unsigned int,unsigned int> & indexes =elementInMap->second.region_range;
280 
281  //this printout will trigger unpacking. no problem. it is done on the next regular line (find(id.rawId())
282  LogDebug(category_)<<"between index: "<<indexes.first<<" and: "<<indexes.second
283  <<"\nretrieved for module: "<<id.rawId()
284  <<"\n"<<dumpRegion(indexes,*theRefGetterH);
285 
286  //look for iterator range in the regions defined for that module
287  for (unsigned int iRegion = indexes.first; iRegion != indexes.second; ++iRegion){
288  RefGetter::record_pair range = (*theRefGetterH)[iRegion].find(id.rawId());
289  if (range.first!=range.second){
290  // found something not empty
291  //update the measurementDet
292  smdet->update(range.first, range.second, theLazyGetterH, id);
293  LogDebug(category_)<<"Valid clusters for: "<<id.rawId()
294  <<"\nnumber of regions defined here: "<< indexes.second-indexes.first
295  <<"\n"<<dumpCluster(range.first,range.second);
296  //and you are done
297  return;}
298  }//loop over regions, between indexes
299 
300  //if reached. no cluster are found. set the TkStripMeasurementDet to be empty
301  smdet->setEmpty();
302 
303  }//found in the map
304  else{
305  //throw excpetion
306  edm::LogError(category_)<<"failed to find the MeasurementDet for: "<<id.rawId();
307  throw MeasurementDetException("failed to find the MeasurementDet for: <see message logger>");
308  }
309 }
310 
311 
312 
313 const MeasurementDet*
315 {
316  // overloaded from MeasurementTracker
317  // find the detid. if not found throw exception
318  // if already updated: always for pixel or strip already queried. return it
319  DetODContainer::iterator it = theDetODMap.find(id);
320  if ( it != theDetODMap.end()) {
321 
322  //it has already been queried. and so already updated: nothing to be done here (valid for pixels too)
323  if (it->second.updated){LogDebug(category_)<<"found id: "<<id.rawId()<<" as aleardy updated."; return it->second.mdet;}
324 
325  if (StripOnDemand_){
326  //check glued or single
327  std::vector< const GeomDet*> comp = it->second.mdet->geomDet().components();
328  if (!comp.empty()){
329  //glued det
330  LogDebug(category_)<<"updating glued id: "<<id.rawId()<<" ("<<comp.size()<<").";
331  //cast to specific type
332  TkGluedMeasurementDet* theConcreteDet = dynamic_cast<TkGluedMeasurementDet*>(it->second.mdet);
333  //FIXME. do not require the dynamic cast, since we know what we do here
334  // const TkGluedMeasurementDet* theConcreteDet = (const TkGluedMeasurementDet*) it->second.mdet;
335  if (!theConcreteDet){
336  edm::LogError(category_)<<"failed to cast to glued measurement det:"<<it->first.rawId();
337  throw MeasurementDetException("failed to cast. see log file.");}
338 
339  // update the two components
340  //update the mono
341  assign(theConcreteDet->monoDet());
342  //update the stereo
343  assign(theConcreteDet->stereoDet());
344 
345  //flag the glued det as updated (components are flagged in assign)
346  it->second.updated=true;
347  }//glued det
348  else{
349  //single layer
350  LogDebug(category_)<<"updating singel id: "<<id.rawId();
351  //cast to specific type
352  TkStripMeasurementDet* theConcreteDet = dynamic_cast<TkStripMeasurementDet*>(it->second.mdet);
353  //FIXME. do not require the dynamic cast, since we know what we do here
354  // const TkStripMeasurementDet* theConcreteDet = (const TkStripMeasurementDet*)it->second.mdet;
355  if (!theConcreteDet){
356  edm::LogError(category_)<<"failed to cast to strip measurement det:"<<it->first.rawId();
357  throw MeasurementDetException("failed to cast. see log file.");}
358 
359  //update the single layer
360  assign(theConcreteDet,&it);
361  }//single det
362  }
363  //eventually return it
364  return it->second.mdet;
365  }//found in the DetODMap
366  else{
367  //throw excpetion
368  edm::LogError(category_)<<"failed to find the MeasurementDet for: "<<id.rawId();
369  throw MeasurementDetException("failed to find the MeasurementDet for: <see message logger>");
370  }
371  return 0;
372 }
373 
374 
#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
int i
Definition: DBlmapReader.cc:9
edm::Handle< edm::LazyGetter< SiStripCluster > > theLazyGetterH
std::map< SiStripRegionCabling::ElementIndex, std::vector< DetODContainer::iterator > > region_mapping
mapping of elementIndex -&gt; iterator to the DetODMap: to know what are the regions that needs to be de...
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
void updateStrips(const edm::Event &) const
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
virtual const GeomDet & geomDet() const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
std::pair< typename record_type::const_iterator, typename record_type::const_iterator > record_pair
Definition: RefGetter.h:26
const TkStripMeasurementDet * monoDet() const
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
dictionary map
Definition: Association.py:160
U second(std::pair< T, U > const &p)
void updatePixels(const edm::Event &) const
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
static const SubDet subdetFromDetId(const uint32_t detid)
bool StayPacked_
internal flag to avoid unpacking things with LogDebug on
std::pair< double, double > Position
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:74
#define end
Definition: vmac.h:38
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:79
tuple conf
Definition: dbtoconf.py:185
bool StripOnDemand_
internal flag to do strip on demand (not configurable) true by default
void update(const detset &detSet, const edm::Handle< edmNew::DetSetVector< SiStripCluster > > h, unsigned int id)
bool failedToGet() const
Definition: HandleBase.h:80
std::string category_
log category
Definition: DetId.h:20
const Position position(const uint32_t) const
const edm::ParameterSet & pset_
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:70
const uint32_t region(const Position) const
edm::EventID id() const
Definition: EventBase.h:56
#define begin
Definition: vmac.h:31
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< uint32_t, uint32_t > PositionIndex
const std::string name_
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