CMS 3D CMS Logo

MeasurementTrackerEventProducer.cc
Go to the documentation of this file.
2 
6 
11 
12 #include <algorithm>
13 
15  : measurementTrackerToken_(
16  esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("measurementTracker")))),
17  switchOffPixelsIfEmpty_(iConfig.getParameter<bool>("switchOffPixelsIfEmpty")) {
18  std::vector<edm::InputTag> inactivePixelDetectorTags(
19  iConfig.getParameter<std::vector<edm::InputTag>>("inactivePixelDetectorLabels"));
20  for (auto& t : inactivePixelDetectorTags)
21  theInactivePixelDetectorLabels.push_back(consumes<DetIdCollection>(t));
22 
23  std::vector<edm::InputTag> badPixelFEDChannelCollectionTags =
24  iConfig.getParameter<std::vector<edm::InputTag>>("badPixelFEDChannelCollectionLabels");
25  if (!badPixelFEDChannelCollectionTags.empty()) {
26  for (auto& t : badPixelFEDChannelCollectionTags)
27  theBadPixelFEDChannelsLabels.push_back(consumes<PixelFEDChannelCollection>(t));
28  pixelCablingMapToken_ = esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("pixelCablingMapLabel")));
29  }
30 
31  std::vector<edm::InputTag> inactiveStripDetectorTags(
32  iConfig.getParameter<std::vector<edm::InputTag>>("inactiveStripDetectorLabels"));
33  for (auto& t : inactiveStripDetectorTags)
34  theInactiveStripDetectorLabels.push_back(consumes<DetIdVector>(t));
35 
36  //the measurement tracking is set to skip clusters, the other option is set from outside
37  edm::InputTag skip = iConfig.getParameter<edm::InputTag>("skipClusters");
39  LogDebug("MeasurementTracker") << "skipping clusters: " << selfUpdateSkipClusters_;
40  isPhase2_ = false;
41  useVectorHits_ = false;
42 
43  if (!iConfig.getParameter<std::string>("stripClusterProducer").empty()) {
44  theStripClusterLabel = consumes<edmNew::DetSetVector<SiStripCluster>>(
45  edm::InputTag(iConfig.getParameter<std::string>("stripClusterProducer")));
47  theStripClusterMask = consumes<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster>>>(
48  iConfig.getParameter<edm::InputTag>("skipClusters"));
49  }
50  if (!iConfig.getParameter<std::string>("pixelClusterProducer").empty()) {
51  thePixelClusterLabel = consumes<edmNew::DetSetVector<SiPixelCluster>>(
52  edm::InputTag(iConfig.getParameter<std::string>("pixelClusterProducer")));
54  thePixelClusterMask = consumes<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster>>>(
55  iConfig.getParameter<edm::InputTag>("skipClusters"));
56  }
57  if (!iConfig.getParameter<std::string>("Phase2TrackerCluster1DProducer").empty()) {
58  thePh2OTClusterLabel = consumes<edmNew::DetSetVector<Phase2TrackerCluster1D>>(
59  edm::InputTag(iConfig.getParameter<std::string>("Phase2TrackerCluster1DProducer")));
60  isPhase2_ = true;
61  }
62  if (!(iConfig.getParameter<edm::InputTag>("vectorHits") == edm::InputTag("") ||
63  iConfig.getParameter<edm::InputTag>("vectorHitsRej") == edm::InputTag(""))) {
64  thePh2OTVectorHitsLabel = consumes<VectorHitCollection>(iConfig.getParameter<edm::InputTag>("vectorHits"));
65  thePh2OTVectorHitsRejLabel = consumes<VectorHitCollection>(iConfig.getParameter<edm::InputTag>("vectorHitsRej"));
66  isPhase2_ = true;
67  useVectorHits_ = true;
68  }
69 
70  produces<MeasurementTrackerEvent>();
71 }
72 
75 
76  desc.add<std::string>("measurementTracker", "");
77  desc.add<edm::InputTag>("skipClusters", edm::InputTag());
78  desc.add<std::string>("pixelClusterProducer", "siPixelClusters");
79  desc.add<std::string>("stripClusterProducer", "siStripClusters");
80  desc.add<std::string>("Phase2TrackerCluster1DProducer", "");
81  desc.add<edm::InputTag>("vectorHits", edm::InputTag(""));
82  desc.add<edm::InputTag>("vectorHitsRej", edm::InputTag(""));
83 
84  desc.add<std::vector<edm::InputTag>>("inactivePixelDetectorLabels",
85  std::vector<edm::InputTag>{{edm::InputTag("siPixelDigis")}})
86  ->setComment("One or more DetIdCollections of modules to mask on the fly for a given event");
87  desc.add<std::vector<edm::InputTag>>("badPixelFEDChannelCollectionLabels", std::vector<edm::InputTag>())
88  ->setComment("One or more PixelFEDChannelCollections of modules+ROCs to mask on the fly for a given event");
89  desc.add<std::string>("pixelCablingMapLabel", "");
90 
91  desc.add<std::vector<edm::InputTag>>("inactiveStripDetectorLabels",
92  std::vector<edm::InputTag>{{edm::InputTag("siStripDigis")}})
93  ->setComment("One or more DetIdVectors of modules to mask on the fly for a given event");
94 
95  desc.add<bool>("switchOffPixelsIfEmpty", true)->setComment("let's keep it like this, for cosmics");
96 
97  descriptions.add("measurementTrackerEventDefault", desc);
98 }
99 
102 
103  // create new data structures from templates
104  auto stripData = std::make_unique<StMeasurementDetSet>(measurementTracker.stripDetConditions());
105  auto pixelData = std::make_unique<PxMeasurementDetSet>(measurementTracker.pixelDetConditions());
106  auto phase2OTData = std::make_unique<Phase2OTMeasurementDetSet>(measurementTracker.phase2DetConditions());
107 
108  std::vector<bool> stripClustersToSkip;
109  std::vector<bool> pixelClustersToSkip;
110  std::vector<bool> phase2ClustersToSkip;
111  // fill them
112  updateStrips(iEvent, *stripData, stripClustersToSkip);
114  *pixelData,
115  pixelClustersToSkip,
116  dynamic_cast<const TrackerGeometry&>(*(measurementTracker.geomTracker())),
117  iSetup);
118  updatePhase2OT(iEvent, *phase2OTData);
119  updateStacks(iEvent, *phase2OTData);
120 
121  // put into MTE
122  // put into event
123  //
124 
125  const VectorHitCollection* phase2OTVectorHits = useVectorHits_ ? &iEvent.get(thePh2OTVectorHitsLabel) : nullptr;
126  const VectorHitCollection* phase2OTVectorHitsRej = useVectorHits_ ? &iEvent.get(thePh2OTVectorHitsRejLabel) : nullptr;
127  iEvent.put(std::make_unique<MeasurementTrackerEvent>(measurementTracker,
128  stripData.release(),
129  pixelData.release(),
130  phase2OTData.release(),
131  phase2OTVectorHits,
132  phase2OTVectorHitsRej,
133  stripClustersToSkip,
134  pixelClustersToSkip,
135  phase2ClustersToSkip));
136 }
137 
139  PxMeasurementDetSet& thePxDets,
140  std::vector<bool>& pixelClustersToSkip,
141  const TrackerGeometry& trackerGeom,
142  const edm::EventSetup& iSetup) const {
143  // start by clearinng everything
144  thePxDets.setEmpty();
145 
146  std::vector<uint32_t> rawInactiveDetIds;
147  if (!theInactivePixelDetectorLabels.empty()) {
150  if (event.getByToken(tk, detIds)) {
151  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
152  } else {
153  static std::atomic<bool> iFailedAlready{false};
154  bool expected = false;
155  if (iFailedAlready.compare_exchange_strong(expected, true, std::memory_order_acq_rel)) {
156  edm::LogError("MissingProduct")
157  << "I fail to get the list of inactive pixel modules, because of 4.2/4.4 event content change.";
158  }
159  }
160  }
161  if (!rawInactiveDetIds.empty())
162  std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
163  // mark as inactive if in rawInactiveDetIds
164  int i = 0, endDet = thePxDets.size();
165  unsigned int idp = 0;
166  for (auto id : rawInactiveDetIds) {
167  if (id == idp)
168  continue; // skip multiple id
169  idp = id;
170  i = thePxDets.find(id, i);
171  assert(i != endDet && id == thePxDets.id(i));
172  thePxDets.setActiveThisEvent(i, false);
173  }
174  }
175 
176  if (!theBadPixelFEDChannelsLabels.empty()) {
177  auto const& cablingMap = iSetup.getData(pixelCablingMapToken_);
178 
179  edm::Handle<PixelFEDChannelCollection> pixelFEDChannelCollectionHandle;
181  if (not event.getByToken(tk, pixelFEDChannelCollectionHandle))
182  continue;
183  int i = 0;
184  for (const auto& disabledChannels : *pixelFEDChannelCollectionHandle) {
186  for (const auto& ch : disabledChannels) {
187  const sipixelobjects::PixelROC *roc_first = nullptr, *roc_last = nullptr;
188  sipixelobjects::CablingPathToDetUnit path = {ch.fed, ch.link, 0};
189  // PixelFEDChannelCollection addresses the ROCs by their 'idInDetUnit' (from 0 to 15), ROCs also know their on 'idInDetUnit',
190  // however the cabling map uses a numbering [1,numberOfROCs], see sipixelobjects::PixelFEDLink::roc(unsigned int id), not necessarily sorted in the same direction.
191  // PixelFEDChannelCollection MUST be filled such that ch.roc_first (ch.roc_last) correspond to the lowest (highest) 'idInDetUnit' in the channel
192  assert(ch.roc_last >= ch.roc_first);
193  for (path.roc = 1; path.roc <= (ch.roc_last - ch.roc_first) + 1; ++path.roc) {
194  const sipixelobjects::PixelROC* roc = cablingMap.findItem(path);
195  if (roc == nullptr)
196  continue;
197  assert(roc->rawId() == disabledChannels.detId());
198  if (roc->idInDetUnit() == ch.roc_first)
199  roc_first = roc;
200  if (roc->idInDetUnit() == ch.roc_last)
201  roc_last = roc;
202  }
203  if (roc_first == nullptr || roc_last == nullptr) {
204  edm::LogError("PixelFEDChannelCollection")
205  << "Do not find either roc_first or roc_last in the cabling map.";
206  continue;
207  }
208  const PixelGeomDetUnit* theGeomDet =
209  dynamic_cast<const PixelGeomDetUnit*>(trackerGeom.idToDet(roc_first->rawId()));
210  PixelTopology const* topology = &(theGeomDet->specificTopology());
212  topology->rowsperroc() / 2, topology->colsperroc() / 2}; //corresponding to center of ROC row, col
214  LocalPoint lp1 = topology->localPosition(MeasurementPoint(global.row, global.col));
215  global = roc_last->toGlobal(sipixelobjects::LocalPixel(local));
216  LocalPoint lp2 = topology->localPosition(MeasurementPoint(global.row, global.col));
217  LocalPoint ll(std::min(lp1.x(), lp2.x()), std::min(lp1.y(), lp2.y()), std::min(lp1.z(), lp2.z()));
218  LocalPoint ur(std::max(lp1.x(), lp2.x()), std::max(lp1.y(), lp2.y()), std::max(lp1.z(), lp2.z()));
219  positions.push_back(std::make_pair(ll, ur));
220  } // loop on channels
221  if (not positions.empty()) {
222  i = thePxDets.find(disabledChannels.detId(), i);
223  assert(i != thePxDets.size() && thePxDets.id(i) == disabledChannels.detId());
224  thePxDets.addBadFEDChannelPositions(i, positions);
225  }
226  } // loop on DetId-s
227  } // loop on labels
228  } // if collection labels are populated
229 
230  // Pixel Clusters
231  if (thePixelClusterLabel.isUninitialized()) { //clusters have not been produced
233  thePxDets.setActiveThisEvent(false);
234  }
235  } else {
237  if (event.getByToken(thePixelClusterLabel, pixelClusters)) {
238  const edmNew::DetSetVector<SiPixelCluster>* pixelCollection = pixelClusters.product();
239 
240  if (switchOffPixelsIfEmpty_ && pixelCollection->empty()) {
241  thePxDets.setActiveThisEvent(false);
242  } else {
243  //std::cout <<"updatePixels "<<pixelCollection->dataSize()<<std::endl;
244  pixelClustersToSkip.resize(pixelCollection->dataSize());
245  std::fill(pixelClustersToSkip.begin(), pixelClustersToSkip.end(), false);
246 
249  //and get the collection of pixel ref to skip
250  event.getByToken(thePixelClusterMask, pixelClusterMask);
251  LogDebug("MeasurementTracker") << "getting pxl refs to skip";
252  if (pixelClusterMask.failedToGet())
253  edm::LogError("MeasurementTracker") << "not getting the pixel clusters to skip";
254  if (pixelClusterMask->refProd().id() != pixelClusters.id()) {
255  edm::LogError("ProductIdMismatch")
256  << "The pixel masking does not point to the proper collection of clusters: "
257  << pixelClusterMask->refProd().id() << "!=" << pixelClusters.id();
258  }
259  pixelClusterMask->copyMaskTo(pixelClustersToSkip);
260  }
261 
262  // FIXME: should check if lower_bound is better
263  int i = 0, endDet = thePxDets.size();
265  ed = pixelCollection->end();
266  it != ed;
267  ++it) {
269  unsigned int id = set.id();
270  while (id != thePxDets.id(i)) {
271  ++i;
272  if (endDet == i)
273  throw "we have a problem!!!!";
274  }
275  // push cluster range in det
276  if (thePxDets.isActive(i)) {
277  thePxDets.update(i, set);
278  }
279  }
280  }
281  } else {
283  labelsForToken(thePixelClusterLabel, labels);
284  edm::LogWarning("MeasurementTrackerEventProducer")
285  << "input pixel clusters collection " << labels.module << " is not valid";
286  }
287  }
288 }
289 
291  StMeasurementDetSet& theStDets,
292  std::vector<bool>& stripClustersToSkip) const {
293  typedef edmNew::DetSet<SiStripCluster> StripDetSet;
294 
295  std::vector<uint32_t> rawInactiveDetIds;
296  getInactiveStrips(event, rawInactiveDetIds);
297 
298  // Strip Clusters
299  //first clear all of them
300  theStDets.setEmpty();
301 
303  return; //clusters have not been produced
304 
305  const int endDet = theStDets.size();
306 
307  // mark as inactive if in rawInactiveDetIds
308  int i = 0;
309  unsigned int idp = 0;
310  for (auto id : rawInactiveDetIds) {
311  if (id == idp)
312  continue; // skip multiple id
313  idp = id;
314  i = theStDets.find(id, i);
315  assert(i != endDet && id == theStDets.id(i));
316  theStDets.setActiveThisEvent(i, false);
317  }
318 
319  //========= actually load cluster =============
320  {
322  if (event.getByToken(theStripClusterLabel, clusterHandle)) {
324 
327  //and get the collection of pixel ref to skip
328  LogDebug("MeasurementTracker") << "getting strp refs to skip";
329  event.getByToken(theStripClusterMask, stripClusterMask);
330  if (stripClusterMask.failedToGet())
331  edm::LogError("MeasurementTracker") << "not getting the strip clusters to skip";
332  if (stripClusterMask->refProd().id() != clusterHandle.id()) {
333  edm::LogError("ProductIdMismatch")
334  << "The strip masking does not point to the proper collection of clusters: "
335  << stripClusterMask->refProd().id() << "!=" << clusterHandle.id();
336  }
337  stripClusterMask->copyMaskTo(stripClustersToSkip);
338  }
339 
340  theStDets.handle() = clusterHandle;
341  int i = 0;
342  // cluster and det and in order (both) and unique so let's use set intersection
343  for (auto j = 0U; j < (*clusterCollection).size(); ++j) {
344  unsigned int id = (*clusterCollection).id(j);
345  while (id != theStDets.id(i)) { // eventually change to lower_bound
346  ++i;
347  if (endDet == i)
348  throw "we have a problem in strips!!!!";
349  }
350 
351  // push cluster range in det
352  if (theStDets.isActive(i))
353  theStDets.update(i, j);
354  }
355  } else {
357  labelsForToken(theStripClusterLabel, labels);
358  edm::LogWarning("MeasurementTrackerEventProducer")
359  << "input strip cluster collection " << labels.module << " is not valid";
360  }
361  }
362 }
363 
364 //FIXME: just a temporary solution for phase2!
366  Phase2OTMeasurementDetSet& thePh2OTDets) const {
367  thePh2OTDets.setEmpty();
368 
369  // Phase2OT Clusters
370  if (isPhase2_) {
371  if (thePh2OTClusterLabel.isUninitialized()) { //clusters have not been produced
372  thePh2OTDets.setActiveThisEvent(false);
373  } else {
375  if (event.getByToken(thePh2OTClusterLabel, phase2OTClusters)) {
376  const edmNew::DetSetVector<Phase2TrackerCluster1D>* phase2OTCollection = phase2OTClusters.product();
377 
378  int i = 0, endDet = thePh2OTDets.size();
380  ed = phase2OTCollection->end();
381  it != ed;
382  ++it) {
384  unsigned int id = set.id();
385  while (id != thePh2OTDets.id(i)) {
386  ++i;
387  if (endDet == i)
388  throw "we have a problem!!!!";
389  }
390  // push cluster range in det
391  if (thePh2OTDets.isActive(i)) {
392  thePh2OTDets.update(i, set);
393  }
394  }
395  } else {
397  labelsForToken(thePh2OTClusterLabel, labels);
398  edm::LogWarning("MeasurementTrackerEventProducer")
399  << "input Phase2TrackerCluster1D collection " << labels.module << " is not valid";
400  }
401  }
402  }
403  return;
404 }
405 
407  std::vector<uint32_t>& rawInactiveDetIds) const {
408  if (!theInactiveStripDetectorLabels.empty()) {
411  if (event.getByToken(tk, detIds)) {
412  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
413  }
414  }
415  if (!rawInactiveDetIds.empty())
416  std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
417  }
418 }
419 
std::vector< std::pair< LocalPoint, LocalPoint > > BadFEDChannelPositions
size_type dataSize() const
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
id_type id() const
Definition: DetSetNew.h:61
ProductID id() const
Definition: HandleBase.cc:29
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void updatePixels(const edm::Event &, PxMeasurementDetSet &thePxDets, std::vector< bool > &pixelClustersToSkip, const TrackerGeometry &trackerGeom, const edm::EventSetup &iSetup) const
unsigned int id(int i) const
T z() const
Definition: PV3DBase.h:61
unsigned int id(int i) const
T const * product() const
Definition: Handle.h:70
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:98
edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > pixelCablingMapToken_
MeasurementTrackerEventProducer(const edm::ParameterSet &iConfig)
void update(int i, const StripDetset &detSet)
edm::EDGetTokenT< edmNew::DetSetVector< Phase2TrackerCluster1D > > thePh2OTClusterLabel
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Log< level::Error, false > LogError
assert(be >=bs)
bool isActive(int i) const
const edm::Handle< edmNew::DetSetVector< Phase2TrackerCluster1D > > & handle() const
identify pixel inside single ROC
Definition: LocalPixel.h:7
const_iterator end(bool update=false) const
global coordinates (row and column in DetUnit, as in PixelDigi)
Definition: GlobalPixel.h:6
std::vector< edm::EDGetTokenT< PixelFEDChannelCollection > > theBadPixelFEDChannelsLabels
bool failedToGet() const
Definition: HandleBase.h:72
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
void updateStrips(const edm::Event &, StMeasurementDetSet &theStDets, std::vector< bool > &stripClustersToSkip) const
int iEvent
Definition: GenABIO.cc:224
unsigned int id(int i) const
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 ...
GlobalPixel toGlobal(const LocalPixel &loc) const
Definition: PixelROC.h:55
edm::EDGetTokenT< VectorHitCollection > thePh2OTVectorHitsRejLabel
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void updatePhase2OT(const edm::Event &, Phase2OTMeasurementDetSet &thePh2OTDets) const
std::vector< edm::EDGetTokenT< DetIdVector > > theInactiveStripDetectorLabels
void update(int i, const PixelDetSet &detSet)
void addBadFEDChannelPositions(int i, BadFEDChannelPositions &positions)
const TrackerGeomDet * idToDet(DetId) const override
const_iterator begin() const
Definition: EDCollection.h:118
void updateStacks(const edm::Event &, Phase2OTMeasurementDetSet &theStDets) const
void produce(edm::Event &, const edm::EventSetup &) override
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator begin(bool update=false) const
edm::EDGetTokenT< edm::ContainerMask< edmNew::DetSetVector< SiPixelCluster > > > thePixelClusterMask
row and collumn in ROC representation
Definition: LocalPixel.h:13
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::ESGetToken< MeasurementTracker, CkfComponentsRecord > measurementTrackerToken_
void setActiveThisEvent(bool active)
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > theStripClusterLabel
HLT enums.
int find(unsigned int jd, int i=0) const
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
void getInactiveStrips(const edm::Event &event, std::vector< uint32_t > &rawInactiveDetIds) const
edm::EDGetTokenT< VectorHitCollection > thePh2OTVectorHitsLabel
void setActiveThisEvent(bool active)
edm::Handle< edmNew::DetSetVector< SiStripCluster > > & handle()
Log< level::Warning, false > LogWarning
const edm::Handle< edmNew::DetSetVector< SiPixelCluster > > & handle() const
int find(unsigned int jd, int i=0) const
const_iterator end() const
Definition: EDCollection.h:123
void update(int i, const Phase2DetSet &detSet)
bool isActive(int i) const
uint32_t rawId() const
return the DetUnit to which this ROC belongs to.
Definition: PixelROC.h:34
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > thePixelClusterLabel
edm::EDGetTokenT< edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > > theStripClusterMask
std::vector< edm::EDGetTokenT< DetIdCollection > > theInactivePixelDetectorLabels
Definition: event.py:1
#define LogDebug(id)