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 
49 using namespace std;
50 
52  const PixelClusterParameterEstimator* pixelCPE,
53  const StripClusterParameterEstimator* stripCPE,
54  const SiStripRecHitMatcher* hitMatcher,
55  const TrackerGeometry* trackerGeom,
56  const GeometricSearchTracker* geometricSearchTracker,
57  const SiStripQuality *stripQuality,
58  int stripQualityFlags,
59  int stripQualityDebugFlags,
60  const SiPixelQuality *pixelQuality,
61  const SiPixelFedCabling *pixelCabling,
62  int pixelQualityFlags,
63  int pixelQualityDebugFlags,
64  const SiStripRegionCabling * stripRegionCabling,
65  bool isRegional):
66  MeasurementTrackerImpl(conf,pixelCPE,stripCPE,hitMatcher,trackerGeom,geometricSearchTracker,
67  stripQuality,stripQualityFlags,stripQualityDebugFlags,
68  pixelQuality,pixelCabling,pixelQualityFlags,pixelQualityDebugFlags,
69  isRegional)
70  , category_("OnDemandMeasurementTracker")
71  , StayPacked_(true)
72  , StripOnDemand_(true)
73  , PixelOnDemand_(false)
74  , theStripRegionCabling(stripRegionCabling)
75 {
76  // the constructor does construct the regular MeasurementTracker
77  // then a smart copy of the DetMap is made into DetODMap: this could be avoided with modification to MeasurementDet interface
78  // the elementIndex to be defined in the refgetter is mapped to the detId
79  // flags are set to initialize the DetODMap
80 
81  std::map<SiStripRegionCabling::ElementIndex, std::vector< DetODContainer::const_iterator> > local_mapping;
82  for (DetContainer::iterator it=theDetMap.begin(); it!= theDetMap.end();++it)
83  {
84  DetODContainer::iterator inserted = theDetODMap.insert(make_pair(it->first,DetODStatus(it->second))).first;
85 
86 
87  GeomDet::SubDetector subdet = it->second->geomDet().subDetector();
89  inserted->second.index = -1;
90  inserted->second.kind = DetODStatus::Pixel;
91  }//pixel module
92  else if (subdet == GeomDetEnumerators::TIB || subdet == GeomDetEnumerators::TOB ||
93  subdet == GeomDetEnumerators::TID || subdet == GeomDetEnumerators::TEC )
94  {
95  //set flag to false
96  if (typeid(*it->second) == typeid(TkStripMeasurementDet)) {
97  const TkStripMeasurementDet & sdet = static_cast<const TkStripMeasurementDet &>(*it->second);
98  inserted->second.index = sdet.index();
99  inserted->second.kind = DetODStatus::Strip;
100  } else {
101  inserted->second.kind = DetODStatus::Glued;
102  }
103 
104  //what will be the element index in the refgetter
105  GlobalPoint center = it->second->geomDet().position();
106  double eta = center.eta();
107  double phi = center.phi();
108  uint32_t id = it->first;
112  LogDebug(category_)<<"region selected (from "<<id<<" center) is:\n"
113  <<"position: "<<center
115  <<"\n center position index: "<<theStripRegionCabling->positionIndex(SiStripRegionCabling::Position(eta,phi)).first<<
119  <<"\n eta: "<<eta
120  <<"\n phi: "<<phi
121  <<"\n subedet: "<<SiStripRegionCabling::subdetFromDetId(id)
122  <<" layer: "<<SiStripRegionCabling::layerFromDetId(id);
123 
124  // register those in a map
125  //to be able to know what are the detid in a given elementIndex
126  local_mapping[eIndex].push_back(inserted);
127  }//strip module
128  else{
129  //abort
130  edm::LogError(category_)<<"not a tracker geomdet in constructor: "<<it->first;
131  throw MeasurementDetException("OnDemandMeasurementTracker dealing with a non tracker GeomDet.");
132  }//abort
133  }//loop over DetMap
134  //move into a vector
135  region_mapping.reserve(local_mapping.size());
136  for( auto eIt= local_mapping.begin();
137  eIt!=local_mapping.end();++eIt)
138  region_mapping.push_back(std::make_pair((*eIt).first,(*eIt).second));
139 }
140 
142  RefGetter & aGetter, StMeasurementDetSet &stData ) const
143 {
144  // define is supposed to be call by an EDProducer module, which wil put the RefGetter in the event
145  // so that reference can be made to it.
146  // the lazy getter is retrieved by the calling module and passed along with the event
147  // the map is cleared, except for pixel
148  // then the known elementIndex are defined to the RefGetter. no unpacking is done at this time
149  // the defined region range is registered in the DetODMap for further use.
150  stData.resetOnDemandStrips();
151 
152  //define all the elementindex in the refgetter
153  for(auto eIt= region_mapping.begin();
154  eIt!=region_mapping.end();++eIt){
155  std::pair<unsigned int, unsigned int> region_range;
156 
157  //before update of the refgetter
158  region_range.first = aGetter.size();
159  //update the refegetter with the elementindex
160  theStripRegionCabling->updateSiStripRefGetter<SiStripCluster> (aGetter, aLazyGetterH, eIt->first);
161  //after update of the refgetter
162  region_range.second = aGetter.size();
163 
164  LogDebug(category_)<<"between index: "<<region_range.first<<" "<<region_range.second
165  <<"\n"<<dumpRegion(region_range,aGetter,StayPacked_);
166 
167  //now assign to each measurement det for that element index
168  for (auto dIt=eIt->second.begin();
169  dIt!=eIt->second.end();++dIt){
170  const DetODStatus & elem = (*dIt)->second;
171  if (elem.kind == DetODStatus::Strip) {
172  stData.defineStrip(elem.index, region_range);
173  }
174  LogDebug(category_)<<"detId: "<<(*dIt)->first<<" in region range: "<<region_range.first<<" "<<region_range.second;
175  }//loop over MeasurementDet attached to that elementIndex
176  }//loop over know elementindex
177 }
178 
179 #include <sstream>
180 
181 std::string OnDemandMeasurementTracker::dumpCluster(const std::vector<SiStripCluster> ::const_iterator & begin,const std::vector<SiStripCluster> ::const_iterator & end)const
182 {
183  // dumpCluster is a printout of all the clusters between the iterator. returns a string
184  std::string tab=" ";
185  std::stringstream ss;
186  std::vector<SiStripCluster> ::const_iterator it = begin;
187  unsigned int i=0;
188  for (;it!=end;++it){
189  ss<<tab<<i++<<") center: "<<it->barycenter()<<",id: "<<it->geographicalId()<<" with: "<<it->amplitudes().size()<<" strips\n"<<tab<<tab<<"{";
190  for (unsigned int is=0;is!=it->amplitudes().size();++is){
191  ss<<it->amplitudes()[is]<<" ";
192  }ss<<"}\n";
193  }
194  return ss.str();
195 }
196 
197 std::string OnDemandMeasurementTracker::dumpRegion(std::pair<unsigned int,unsigned int> indexes,
198  const RefGetter & theGetter,
199  bool stayPacked)const
200 {
201  // dumpRegion is a printout of all the clusters in a region defined on the RefGetter. returns a string
202  std::stringstream ss;
203  ss<<"cluster between: "<<indexes.first<<" and: "<<indexes.second<<"\n";
204  for (unsigned int iRegion = indexes.first; iRegion != indexes.second; ++iRegion){
205  uint32_t reg = SiStripRegionCabling::region((theGetter)[iRegion].region());
208 
209  ss<<"Clusters for region:["<<iRegion<<"]"
210  <<"\n element index: "<<(theGetter)[iRegion].region()
211  <<"\n region absolute index: "<<reg
212  <<"\n region position index: "<<posI.first<<" "<<posI.second
213  <<"\n region position: "<<pos.first<<" "<<pos.second
214  <<"\n"<< (stayPacked? " hidden to avoid unpacking." : dumpCluster((theGetter)[iRegion].begin(),(theGetter)[iRegion].end()));
215  }
216  return ss.str();
217 }
218 
219 void OnDemandMeasurementTracker::assign(const TkStripMeasurementDet * smdet,
220  const MeasurementTrackerEvent &data) const {
221  // assign is using the handle to the refgetter and the region index range to update the MeasurementDet with their clusters
222 
225  StMeasurementDetSet & rwdata = const_cast<StMeasurementDetSet &>(data.stripData());
226 
227  DetId id = smdet->rawId();
228 
229  LogDebug(category_)<<"assigning: "<<id.rawId();
230 
231  rwdata.setUpdated(smdet->index());
232 
233  if (!data.stripData().rawInactiveStripDetIds().empty() && std::binary_search(data.stripData().rawInactiveStripDetIds().begin(), data.stripData().rawInactiveStripDetIds().end(), id)) {
234  smdet->setActiveThisEvent(rwdata, false);
235  return;
236  }
237 
238  //retrieve the region range index for this module
239  const std::pair<unsigned int,unsigned int> & indexes = data.stripData().regionRange(smdet->index());
240 
241  //this printout will trigger unpacking. no problem. it is done on the next regular line (find(id.rawId())
242  LogDebug(category_)<<"between index: "<<indexes.first<<" and: "<<indexes.second
243  <<"\nretrieved for module: "<<id.rawId()
244  <<"\n"<<dumpRegion(indexes,data.stripData().refGetter());
245 
246  //look for iterator range in the regions defined for that module
247  for (unsigned int iRegion = indexes.first; iRegion != indexes.second; ++iRegion){
248  RefGetter::record_pair range = data.stripData().refGetter()[iRegion].find(id.rawId());
249  if (range.first!=range.second){
250  // found something not empty
251  //update the measurementDet
252  smdet->update(rwdata, range.first, range.second);
253  LogDebug(category_)<<"Valid clusters for: "<<id.rawId()
254  <<"\nnumber of regions defined here: "<< indexes.second-indexes.first
255  <<"\n"<<dumpCluster(range.first,range.second);
256  /* since theStripsToSkip is a "static" pointer of the MT, no need to set it at all time.
257  if (selfUpdateSkipClusters_){
258  //assign skip clusters
259  smdet->setClusterToSkip(&theStripsToSkip);
260  }
261  */
262  //and you are done
263  return;}
264  }//loop over regions, between indexes
265 
266  //if reached. no cluster are found. set the TkStripMeasurementDet to be empty
267  smdet->setEmpty(rwdata);
268 
269 }
270 
271 
272 
273 const MeasurementDet *
275 {
276  // overloaded from MeasurementTracker
277  // find the detid. if not found throw exception
278  // if already updated: always for pixel or strip already queried. return it
279  DetODContainer::const_iterator it = theDetODMap.find(id);
280  if ( it != theDetODMap.end()) {
281  switch (it->second.kind) {
282  case DetODStatus::Pixel:
283  // nothing to do
284  break;
285  case DetODStatus::Strip: {
286  const TkStripMeasurementDet* theConcreteDet = static_cast<const TkStripMeasurementDet*>(it->second.mdet);
287  assert(data.stripData().stripDefined(theConcreteDet->index()));
288  if (!data.stripData().stripUpdated(theConcreteDet->index())) assign(theConcreteDet, data);
289  }
290  break;
291  case DetODStatus::Glued: {
292  const TkGluedMeasurementDet* theConcreteDet = static_cast<const TkGluedMeasurementDet*>(it->second.mdet);
293  int imono = theConcreteDet->monoDet()->index(), istereo = theConcreteDet->stereoDet()->index();
294  assert(data.stripData().stripDefined(imono) && data.stripData().stripDefined(istereo));
295  if (!data.stripData().stripUpdated(imono)) assign(theConcreteDet->monoDet(), data);
296  if (!data.stripData().stripUpdated(istereo)) assign(theConcreteDet->stereoDet(), data);
297  }
298  break;
299  }
300  return it->second.mdet;
301  }
302  else{
303  //throw excpetion
304  edm::LogError(category_)<<"failed to find the MeasurementDet for: "<<id.rawId();
305  throw MeasurementDetException("failed to find the MeasurementDet for: <see message logger>");
306  }
307  return 0;
308 }
309 
310 
#define LogDebug(id)
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
const MeasurementDet * idToDetBare(const DetId &id, const MeasurementTrackerEvent &data) const
MeasurementTrackerImpl interface.
int i
Definition: DBlmapReader.cc:9
void define(const edm::Handle< edm::LazyGetter< SiStripCluster > > &, RefGetter &, StMeasurementDetSet &) const
OnDemandMeasurementTracker specific function to be called to define the region in the RefGetter accor...
const PositionIndex positionIndex(const uint32_t) const
const SiStripRegionCabling * theStripRegionCabling
the cabling region tool to update a RefGetter
void assign(const TkStripMeasurementDet *csmdet, const MeasurementTrackerEvent &data) const
assigne the cluster iterator to the TkStipMeasurementDet (const_cast in the way)
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
uint32_t size() const
Return the number of contained &#39;region_ref&#39;s (one per Region).
Definition: RefGetter.h:127
std::pair< typename record_type::const_iterator, typename record_type::const_iterator > record_pair
Definition: RefGetter.h:27
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
const StMeasurementDetSet & stripData() const
void defineStrip(int i, std::pair< unsigned int, unsigned int > range)
const bool stripUpdated(int i) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
const std::pair< unsigned int, unsigned int > & regionRange(int i) 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
tuple tab
Definition: accesses.py:4
#define end
Definition: vmac.h:37
bool first
Definition: L1TdeRCT.cc:79
tuple conf
Definition: dbtoconf.py:185
std::string category_
log category
std::vector< uint32_t > & rawInactiveStripDetIds()
Definition: DetId.h:18
const Position position(const uint32_t) const
static const uint32_t layerFromDetId(const uint32_t detid)
T eta() const
Definition: PV3DBase.h:76
bool find(uint32_t) const
Returns true if region already defined.
Definition: RefGetter.h:170
const uint32_t region(const Position) const
#define begin
Definition: vmac.h:30
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const edm::RefGetter< SiStripCluster > & refGetter() const
volatile std::atomic< bool > shutdown_flag false
std::pair< uint32_t, uint32_t > PositionIndex
std::string dumpRegion(std::pair< unsigned int, unsigned int > indexes, const RefGetter &theGetter, bool stayUnpacked=false) const
const bool stripDefined(int i) const
Definition: DDAxes.h:10