CMS 3D CMS Logo

TrackClusterRemover.cc
Go to the documentation of this file.
6 
8 
12 
17 
19 
22 
24 
26 
27 #include <limits>
28 
29 namespace {
30 
31  class TrackClusterRemover final : public edm::global::EDProducer<> {
32  public:
33  TrackClusterRemover(const edm::ParameterSet& iConfig);
34  ~TrackClusterRemover() override {}
35  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
36 
37  private:
38  void produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const override;
39 
42 
43  using QualityMaskCollection = std::vector<unsigned char>;
44 
45  const unsigned char maxChi2x5_;
47  const reco::TrackBase::TrackQuality trackQuality_;
48 
49  const TrackCollectionTokens trajectories_;
51 
54 
55  edm::EDGetTokenT<PixelMaskContainer> oldPxlMaskToken_;
56  edm::EDGetTokenT<StripMaskContainer> oldStrMaskToken_;
57 
58  // backward compatibility during transition period
59  edm::EDGetTokenT<edm::ValueMap<int>> overrideTrkQuals_;
60  };
61 
64  desc.add<edm::InputTag>("trajectories", edm::InputTag());
65  desc.add<edm::InputTag>("trackClassifier", edm::InputTag("", "QualityMasks"));
66  desc.add<edm::InputTag>("pixelClusters", edm::InputTag("siPixelClusters"));
67  desc.add<edm::InputTag>("stripClusters", edm::InputTag("siStripClusters"));
68  desc.add<edm::InputTag>("oldClusterRemovalInfo", edm::InputTag());
69 
70  desc.add<std::string>("TrackQuality", "highPurity");
71  desc.add<double>("maxChi2", 30.);
72  desc.add<int>("minNumberOfLayersWithMeasBeforeFiltering", 0);
73  // old mode
74  desc.add<edm::InputTag>("overrideTrkQuals", edm::InputTag());
75 
76  descriptions.add("trackClusterRemover", desc);
77  }
78 
79  TrackClusterRemover::TrackClusterRemover(const edm::ParameterSet& iConfig)
80  : maxChi2x5_(Traj2TrackHits::toChi2x5(iConfig.getParameter<double>("maxChi2"))),
82  iConfig.getParameter<int>("minNumberOfLayersWithMeasBeforeFiltering")),
83  trackQuality_(reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"))),
84 
85  trajectories_(iConfig.getParameter<edm::InputTag>("trajectories"), consumesCollector())
86 
87  {
88  auto const& pixelClusters = iConfig.getParameter<edm::InputTag>("pixelClusters");
89  auto const& stripClusters = iConfig.getParameter<edm::InputTag>("stripClusters");
90 
91  if (pixelClusters.label().empty() && stripClusters.label().empty())
93  << "Configuration Error: TrackClusterRemover used without input cluster collections";
94  if (!pixelClusters.label().empty()) {
95  pixelClusters_ = consumes<edmNew::DetSetVector<SiPixelCluster>>(pixelClusters);
96  produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster>>>();
97  }
98  if (!stripClusters.label().empty()) {
99  stripClusters_ = consumes<edmNew::DetSetVector<SiStripCluster>>(stripClusters);
100  produces<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster>>>();
101  }
102  // old mode
103  auto const& overrideTrkQuals = iConfig.getParameter<edm::InputTag>("overrideTrkQuals");
104  if (!overrideTrkQuals.label().empty())
105  overrideTrkQuals_ = consumes<edm::ValueMap<int>>(overrideTrkQuals);
106 
107  auto const& classifier = iConfig.getParameter<edm::InputTag>("trackClassifier");
108  if (!classifier.label().empty())
109  srcQuals = consumes<QualityMaskCollection>(classifier);
110 
111  auto const& oldClusterRemovalInfo = iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo");
112  if (!oldClusterRemovalInfo.label().empty()) {
113  oldPxlMaskToken_ = consumes<PixelMaskContainer>(oldClusterRemovalInfo);
114  oldStrMaskToken_ = consumes<StripMaskContainer>(oldClusterRemovalInfo);
115  }
116  }
117 
118  void TrackClusterRemover::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
120  if (!pixelClusters_.isUninitialized())
121  iEvent.getByToken(pixelClusters_, pixelClusters);
123  if (!stripClusters_.isUninitialized())
124  iEvent.getByToken(stripClusters_, stripClusters);
125 
126  std::vector<bool> collectedStrips;
127  std::vector<bool> collectedPixels;
128 
129  if (!oldPxlMaskToken_.isUninitialized()) {
132  iEvent.getByToken(oldPxlMaskToken_, oldPxlMask);
133  iEvent.getByToken(oldStrMaskToken_, oldStrMask);
134  LogDebug("TrackClusterRemover") << "to merge in, " << oldStrMask->size() << " strp, " << oldPxlMask->size()
135  << " pxl";
136 
137  // std::cout <<"TrackClusterRemover "<<"to merge in, "<<oldStrMask->size()<<" strp and "<<oldPxlMask->size()<<" pxl" << std::endl;
138  oldStrMask->copyMaskTo(collectedStrips);
139  oldPxlMask->copyMaskTo(collectedPixels);
140  if (!stripClusters_.isUninitialized()) {
141  assert(stripClusters->dataSize() >= collectedStrips.size());
142  collectedStrips.resize(stripClusters->dataSize(), false);
143  //std::cout << "TrackClusterRemover " <<"total strip already to skip: "
144  // <<std::count(collectedStrips.begin(),collectedStrips.end(),true) <<std::endl;
145  }
146  } else {
147  if (!stripClusters_.isUninitialized())
148  collectedStrips.resize(stripClusters->dataSize(), false);
149  if (!pixelClusters_.isUninitialized())
150  collectedPixels.resize(pixelClusters->dataSize(), false);
151  }
152 
153  // loop over trajectories, filter, mask clusters../
154 
155  unsigned char qualMask = ~0;
156  if (trackQuality_ != reco::TrackBase::undefQuality)
157  qualMask = 1 << trackQuality_;
158 
159  auto const& tracks = trajectories_.tracks(iEvent);
160  auto s = tracks.size();
161 
162  // assert(s==trajs.size());
163 
164  QualityMaskCollection oldStyle;
165  QualityMaskCollection const* pquals = nullptr;
166 
167  if (!overrideTrkQuals_.isUninitialized()) {
169  iEvent.getByToken(overrideTrkQuals_, quals);
170  assert(s == (*quals).size());
171 
172  oldStyle.resize(s, 0);
173  for (auto i = 0U; i < s; ++i)
174  if ((*quals).get(i) > 0)
175  oldStyle[i] = (255) & (*quals).get(i);
176  pquals = &oldStyle;
177  }
178 
179  if (!srcQuals.isUninitialized()) {
181  iEvent.getByToken(srcQuals, hqual);
182  pquals = hqual.product();
183  }
184  // if (!pquals) std::cout << "no qual collection" << std::endl;
185  for (auto i = 0U; i < s; ++i) {
186  const reco::Track& track = tracks[i];
187  bool goodTk = (pquals) ? (*pquals)[i] & qualMask : track.quality(trackQuality_);
188  if (!goodTk)
189  continue;
191  continue;
192 
193  auto const& chi2sX5 = track.extra()->chi2sX5();
194  assert(chi2sX5.size() == track.recHitsSize());
195  auto hb = track.recHitsBegin();
196  for (unsigned int h = 0; h < track.recHitsSize(); h++) {
197  auto recHit = *(hb + h);
198  auto const& hit = *recHit;
200  continue;
201  if (chi2sX5[h] > maxChi2x5_)
202  continue; // skip outliers
203  auto const& thit = reinterpret_cast<BaseTrackerRecHit const&>(hit);
204  auto const& cluster = thit.firstClusterRef();
205  if (!stripClusters_.isUninitialized() && cluster.isStrip())
206  collectedStrips[cluster.key()] = true;
207  if (!pixelClusters_.isUninitialized() && cluster.isPixel())
208  collectedPixels[cluster.key()] = true;
209  if (trackerHitRTTI::isMatched(thit))
210  collectedStrips[reinterpret_cast<SiStripMatchedRecHit2D const&>(hit).stereoClusterRef().key()] = true;
211  }
212  }
213 
214  // std::cout << " => collectedStrips: " << collectedStrips.size() << std::endl;
215  if (!stripClusters_.isUninitialized()) {
216  auto removedStripClusterMask = std::make_unique<StripMaskContainer>(
218  LogDebug("TrackClusterRemover") << "total strip to skip: "
219  << std::count(collectedStrips.begin(), collectedStrips.end(), true);
220  // std::cout << "TrackClusterRemover " <<"total strip to skip: "<<std::count(collectedStrips.begin(),collectedStrips.end(),true) <<std::endl;
221  iEvent.put(std::move(removedStripClusterMask));
222  }
223  if (!pixelClusters_.isUninitialized()) {
224  auto removedPixelClusterMask = std::make_unique<PixelMaskContainer>(
226  LogDebug("TrackClusterRemover") << "total pxl to skip: "
227  << std::count(collectedPixels.begin(), collectedPixels.end(), true);
228  iEvent.put(std::move(removedPixelClusterMask));
229  }
230  }
231 
232 } // namespace
233 
236 DEFINE_FWK_MODULE(TrackClusterRemover);
#define LogDebug(id)
T getParameter(std::string const &) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
const TrackExtraRef & extra() const
reference to "extra" object
Definition: Track.h:139
bool isFromDet(TrackingRecHit const &hit)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
TrackQuality
track quality
Definition: TrackBase.h:150
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:97
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:513
virtual void produce(StreamID, Event &, EventSetup const &) const =0
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool isMatched(TrackingRecHit const &hit)
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T const * product() const
Definition: Handle.h:69
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:483
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:531
std::string const & label() const
Definition: InputTag.h:36
fixed size matrix
HLT enums.
def move(src, dest)
Definition: eostools.py:511