CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MeasurementTrackerEventProducer.cc
Go to the documentation of this file.
2 
5 
10 
12  measurementTrackerLabel_(iConfig.getParameter<std::string>("measurementTracker")),
13  pset_(iConfig),
14  theInactivePixelDetectorLabels(iConfig.getParameter<std::vector<edm::InputTag> >("inactivePixelDetectorLabels")),
15  theInactiveStripDetectorLabels(iConfig.getParameter<std::vector<edm::InputTag> >("inactiveStripDetectorLabels"))
16 {
17  //the measurement tracking is set to skip clusters, the other option is set from outside
18  selfUpdateSkipClusters_=iConfig.exists("skipClusters");
20  {
21  edm::InputTag skip=iConfig.getParameter<edm::InputTag>("skipClusters");
22  if (skip==edm::InputTag("")) selfUpdateSkipClusters_=false;
23  }
24  LogDebug("MeasurementTracker")<<"skipping clusters: "<<selfUpdateSkipClusters_;
25 
26  produces<MeasurementTrackerEvent>();
27 }
28 
29 void
31 {
32  edm::ESHandle<MeasurementTracker> measurementTracker;
33  iSetup.get<CkfComponentsRecord>().get(measurementTrackerLabel_, measurementTracker);
34 
35  // create new data structures from templates
36  std::auto_ptr<StMeasurementDetSet> stripData(new StMeasurementDetSet(measurementTracker->stripDetConditions()));
37  std::auto_ptr<PxMeasurementDetSet> pixelData(new PxMeasurementDetSet(measurementTracker->pixelDetConditions()));
38  //std::cout << "Created new strip data @" << &* stripData << std::endl;
39  std::vector<bool> stripClustersToSkip;
40  std::vector<bool> pixelClustersToSkip;
41 
42  // fill them
43  updateStrips(iEvent, *stripData, stripClustersToSkip);
44  updatePixels(iEvent, *pixelData, pixelClustersToSkip);
45 
46  // put into MTE
47  std::auto_ptr<MeasurementTrackerEvent> out(new MeasurementTrackerEvent(*measurementTracker, stripData.release(), pixelData.release(), stripClustersToSkip, pixelClustersToSkip));
48 
49  // put into event
50  iEvent.put(out);
51 }
52 
53 void
54 MeasurementTrackerEventProducer::updatePixels( const edm::Event& event, PxMeasurementDetSet & thePxDets, std::vector<bool> & pixelClustersToSkip ) const
55 {
56  // start by clearinng everything
57  thePxDets.setEmpty();
58 
59  bool switchOffPixelsIfEmpty = (!pset_.existsAs<bool>("switchOffPixelsIfEmpty")) ||
60  (pset_.getParameter<bool>("switchOffPixelsIfEmpty"));
61  std::vector<uint32_t> rawInactiveDetIds;
62  if (!theInactivePixelDetectorLabels.empty()) {
64  for (std::vector<edm::InputTag>::const_iterator itt = theInactivePixelDetectorLabels.begin(), edt = theInactivePixelDetectorLabels.end();
65  itt != edt; ++itt) {
66  if (event.getByLabel(*itt, detIds)){
67  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
68  }else{
69  static std::atomic<bool> iFailedAlready{false};
70  bool expected = false;
71  if (iFailedAlready.compare_exchange_strong(expected,true,std::memory_order_acq_rel)){
72  edm::LogError("MissingProduct")<<"I fail to get the list of inactive pixel modules, because of 4.2/4.4 event content change.";
73  }
74  }
75  }
76  if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
77  // mark as inactive if in rawInactiveDetIds
78  int i=0, endDet = thePxDets.size();
79  unsigned int idp=0;
80  for ( auto id : rawInactiveDetIds) {
81  if (id==idp) continue; // skip multiple id
82  idp=id;
83  i=thePxDets.find(id,i);
84  assert(i!=endDet && id == thePxDets.id(i));
85  thePxDets.setActiveThisEvent(i,false);
86  }
87  }
88 
89  // Pixel Clusters
90  std::string pixelClusterProducer = pset_.getParameter<std::string>("pixelClusterProducer");
91  if( pixelClusterProducer.empty() ) { //clusters have not been produced
92  if (switchOffPixelsIfEmpty) {
93  thePxDets.setActiveThisEvent(false);
94  }
95  }else{
96 
98  event.getByLabel(pixelClusterProducer, pixelClusters);
99 
100  const edmNew::DetSetVector<SiPixelCluster>* pixelCollection = pixelClusters.product();
101 
102  if (switchOffPixelsIfEmpty && pixelCollection->empty()) {
103  thePxDets.setActiveThisEvent(false);
104  } else {
105 
106  //std::cout <<"updatePixels "<<pixelCollection->dataSize()<<std::endl;
107  pixelClustersToSkip.resize(pixelCollection->dataSize());
108  std::fill(pixelClustersToSkip.begin(),pixelClustersToSkip.end(),false);
109 
112  //and get the collection of pixel ref to skip
113  event.getByLabel(pset_.getParameter<edm::InputTag>("skipClusters"),pixelClusterMask);
114  LogDebug("MeasurementTracker")<<"getting pxl refs to skip";
115  if (pixelClusterMask.failedToGet())edm::LogError("MeasurementTracker")<<"not getting the pixel clusters to skip";
116  if (pixelClusterMask->refProd().id()!=pixelClusters.id()){
117  edm::LogError("ProductIdMismatch")<<"The pixel masking does not point to the proper collection of clusters: "<<pixelClusterMask->refProd().id()<<"!="<<pixelClusters.id();
118  }
119  pixelClusterMask->copyMaskTo(pixelClustersToSkip);
120  }
121 
122 
123  // FIXME: should check if lower_bound is better
124  int i = 0, endDet = thePxDets.size();
125  for (edmNew::DetSetVector<SiPixelCluster>::const_iterator it = pixelCollection->begin(), ed = pixelCollection->end(); it != ed; ++it) {
127  unsigned int id = set.id();
128  while ( id != thePxDets.id(i)) {
129  ++i;
130  if (endDet==i) throw "we have a problem!!!!";
131  }
132  // push cluster range in det
133  if ( thePxDets.isActive(i) ) {
134  thePxDets.update(i,set);
135  }
136  }
137  }
138  }
139 
140 }
141 
142 void
143 MeasurementTrackerEventProducer::updateStrips( const edm::Event& event, StMeasurementDetSet & theStDets, std::vector<bool> & stripClustersToSkip ) const
144 {
145  typedef edmNew::DetSet<SiStripCluster> StripDetSet;
146 
147  std::vector<uint32_t> rawInactiveDetIds;
148  getInactiveStrips(event,rawInactiveDetIds);
149 
150  // Strip Clusters
151  std::string stripClusterProducer = pset_.getParameter<std::string>("stripClusterProducer");
152  //first clear all of them
153  theStDets.setEmpty();
154 
155 
156  if( !stripClusterProducer.compare("") ) return; //clusters have not been produced
157 
158  const int endDet = theStDets.size();
159 
160 
161  // mark as inactive if in rawInactiveDetIds
162  int i=0;
163  unsigned int idp=0;
164  for ( auto id : rawInactiveDetIds) {
165  if (id==idp) continue; // skip multiple id
166  idp=id;
167  i=theStDets.find(id,i);
168  assert(i!=endDet && id == theStDets.id(i));
169  theStDets.setActiveThisEvent(i,false);
170  }
171 
172  //========= actually load cluster =============
173  if(!theStDets.isRegional()){
175  event.getByLabel(stripClusterProducer, clusterHandle);
176  const edmNew::DetSetVector<SiStripCluster>* clusterCollection = clusterHandle.product();
177 
178 
181  //and get the collection of pixel ref to skip
182  LogDebug("MeasurementTracker")<<"getting strp refs to skip";
183  event.getByLabel(pset_.getParameter<edm::InputTag>("skipClusters"),stripClusterMask);
184  if (stripClusterMask.failedToGet()) edm::LogError("MeasurementTracker")<<"not getting the strip clusters to skip";
185  if (stripClusterMask->refProd().id()!=clusterHandle.id()){
186  edm::LogError("ProductIdMismatch")<<"The strip masking does not point to the proper collection of clusters: "<<stripClusterMask->refProd().id()<<"!="<<clusterHandle.id();
187  }
188  stripClusterMask->copyMaskTo(stripClustersToSkip);
189  }
190 
191  theStDets.handle() = clusterHandle;
192  int i=0;
193  // cluster and det and in order (both) and unique so let's use set intersection
194  for ( auto j = 0U; j< (*clusterCollection).size(); ++j) {
195  unsigned int id = (*clusterCollection).id(j);
196  while ( id != theStDets.id(i)) { // eventually change to lower_bound
197  ++i;
198  if (endDet==i) throw "we have a problem in strips!!!!";
199  }
200 
201  // push cluster range in det
202  if ( theStDets.isActive(i) )
203  theStDets.update(i,j);
204  }
205 
206  }else{ // regional
207  throw cms::Exception("NotSupported") << "Regional non-on-demand unpacking is not supported." << std::endl;
208 #if 0
209  //then set the not-empty ones only
211  event.getByLabel(stripClusterProducer, refClusterHandle);
212 
213  std::string lazyGetter = pset_.getParameter<std::string>("stripLazyGetterProducer");
215  event.getByLabel(lazyGetter,lazyClusterHandle);
216 
219  LogDebug("MeasurementTracker")<<"getting reg strp refs to skip";
220  event.getByLabel(pset_.getParameter<edm::InputTag>("skipClusters"),stripClusterMask);
221  if (stripClusterMask.failedToGet())edm::LogError("MeasurementTracker")<<"not getting the strip clusters to skip";
222  if (stripClusterMask->refProd().id()!=lazyClusterHandle.id()){
223  edm::LogError("ProductIdMismatch")<<"The strip masking does not point to the proper collection of clusters: "<<stripClusterMask->refProd().id()<<"!="<<lazyClusterHandle.id();
224  }
225  stripClusterMask->copyMaskTo(stripClustersToSkip);
226  }
227 
228  theStDets.regionalHandle() = lazyClusterHandle;
229 
230  uint32_t tmpId=0;
231  std::vector<SiStripCluster>::const_iterator beginIterator;
232  edm::RefGetter<SiStripCluster>::const_iterator iregion = refClusterHandle->begin();
233  for(;iregion!=refClusterHandle->end();++iregion) {
234  const edm::RegionIndex<SiStripCluster>& region = *iregion;
235  std::vector<SiStripCluster>::const_iterator icluster = region.begin();
236  const std::vector<SiStripCluster>::const_iterator endIterator = region.end();
237  tmpId = icluster->geographicalId();
238  beginIterator = icluster;
239 
240  //std::cout << "== tmpId ad inizio loop dentro region: " << tmpId << std::endl;
241 
242  for (;icluster!=endIterator;icluster++) {
243  //std::cout << "===== cluster id,pos "
244  // << icluster->geographicalId() << " , " << icluster->barycenter()
245  // << std::endl;
246  //std::cout << "=====making ref in recHits() " << std::endl;
247  if( icluster->geographicalId() != tmpId){
248  //std::cout << "geo!=tmpId" << std::endl;
249 
250  //cannot we avoid to update the det with detId of itself?? (sure we can!, done!)
251  theStDets.update(concreteDetUpdatable(tmpId)->index(),beginIterator,icluster);
252 
253  tmpId = icluster->geographicalId();
254  beginIterator = icluster;
255  if( icluster == (endIterator-1)){
256  theStDets.update(concreteDetUpdatable(tmpId)->index(),icluster,endIterator);
257  }
258  }else if( icluster == (endIterator-1)){
259  theStDets.update(concreteDetUpdatable(tmpId)->index(),beginIterator,endIterator);
260  }
261  }//end loop cluster in one ragion
262  }
263 #endif
264  }//end of block for updating with regional clusters
265 
266 }
267 
268 void
269 MeasurementTrackerEventProducer::getInactiveStrips(const edm::Event& event,std::vector<uint32_t> & rawInactiveDetIds) const
270 {
271  if (!theInactiveStripDetectorLabels.empty()) {
273  for (std::vector<edm::InputTag>::const_iterator itt = theInactiveStripDetectorLabels.begin(), edt = theInactiveStripDetectorLabels.end();
274  itt != edt; ++itt) {
275  event.getByLabel(*itt, detIds);
276  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
277  }
278  if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
279  }
280 
281 }
282 
283 
284 
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
size_type dataSize() const
string fill
Definition: lumiContext.py:319
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:184
ProductID id() const
Definition: HandleBase.cc:15
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const_iterator end() const
Get off the end iterator.
Definition: LazyGetter.h:191
MeasurementTrackerEventProducer(const edm::ParameterSet &iConfig)
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::Handle< edm::LazyGetter< SiStripCluster > > & regionalHandle()
void updateStrips(const edm::Event &, StMeasurementDetSet &theStDets, std::vector< bool > &stripClustersToSkip) const
void update(int i, const StripDetset &detSet)
const edm::Handle< edmNew::DetSetVector< SiPixelCluster > > & handle() const
void updatePixels(const edm::Event &, PxMeasurementDetSet &thePxDets, std::vector< bool > &pixelClustersToSkip) const
unsigned int id(int i) const
unsigned int id(int i) const
int find(unsigned int jd, int i=0) const
int iEvent
Definition: GenABIO.cc:243
void setActiveThisEvent(int i, bool active)
Turn on/off the module for reconstruction for one events. This per-event flag is cleared by any call ...
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
const std::vector< edm::InputTag > theInactiveStripDetectorLabels
bool isActive(int i) const
void getInactiveStrips(const edm::Event &event, std::vector< uint32_t > &rawInactiveDetIds) const
int j
Definition: DBlmapReader.cc:9
const std::vector< edm::InputTag > theInactivePixelDetectorLabels
void update(int i, const PixelDetSet &detSet)
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
const_iterator begin() const
Get begin iterator.
Definition: LazyGetter.h:182
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
tuple out
Definition: dbtoconf.py:99
bool failedToGet() const
Definition: HandleBase.h:80
boost::indirect_iterator< typename collection_type::const_iterator > const_iterator
Definition: RefGetter.h:25
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: Handle.h:81
bool isActive(int i) const
void setActiveThisEvent(bool active)
const_iterator end(bool update=true) const
id_type id() const
Definition: DetSetNew.h:80
int find(unsigned int jd, int i=0) const
edm::Handle< edmNew::DetSetVector< SiStripCluster > > & handle()
virtual void produce(edm::Event &, const edm::EventSetup &)
const_iterator begin(bool update=true) const