CMS 3D CMS Logo

TrackClusterRemoverPhase2.cc
Go to the documentation of this file.
6 
8 
11 
16 
18 
21 
23 
25 
26 #include <limits>
27 
28 /* This is a copy of the TrackClusterRemover
29  * for Phase2 Tk upgrade
30  * FIXME:: changing with new phase2 pixel DataFormats!
31  * FIXME:: still to be factorized
32  */
33 
34 namespace {
35 
36  class TrackClusterRemoverPhase2 final : public edm::global::EDProducer<> {
37  public:
38  TrackClusterRemoverPhase2(const edm::ParameterSet& iConfig);
39  ~TrackClusterRemoverPhase2() override {}
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
41 
42  private:
43  void produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const override;
44 
47 
48  using QualityMaskCollection = std::vector<unsigned char>;
49 
50  const unsigned char maxChi2_;
52  const reco::TrackBase::TrackQuality trackQuality_;
53 
54  const TrackCollectionTokens tracks_;
56 
59 
60  edm::EDGetTokenT<PixelMaskContainer> oldPxlMaskToken_;
61  edm::EDGetTokenT<Phase2OTMaskContainer> oldPh2OTMaskToken_;
62 
63  // backward compatibility during transition period
64  edm::EDGetTokenT<edm::ValueMap<int>> overrideTrkQuals_;
65  };
66 
69  desc.add<edm::InputTag>("trajectories", edm::InputTag());
70  desc.add<edm::InputTag>("trackClassifier", edm::InputTag("", "QualityMasks"));
71  desc.add<edm::InputTag>("phase2pixelClusters", edm::InputTag("siPixelClusters"));
72  desc.add<edm::InputTag>("phase2OTClusters", edm::InputTag("siPhase2Clusters"));
73  desc.add<edm::InputTag>("oldClusterRemovalInfo", edm::InputTag());
74 
75  desc.add<std::string>("TrackQuality", "highPurity");
76  desc.add<double>("maxChi2", 30.);
77  desc.add<int>("minNumberOfLayersWithMeasBeforeFiltering", 0);
78  // old mode
79  desc.add<edm::InputTag>("overrideTrkQuals", edm::InputTag());
80 
81  descriptions.add("phase2trackClusterRemover", desc);
82  }
83 
84  TrackClusterRemoverPhase2::TrackClusterRemoverPhase2(const edm::ParameterSet& iConfig)
85  : maxChi2_(Traj2TrackHits::toChi2x5(iConfig.getParameter<double>("maxChi2"))),
87  iConfig.getParameter<int>("minNumberOfLayersWithMeasBeforeFiltering")),
88  trackQuality_(reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"))),
89 
90  tracks_(iConfig.getParameter<edm::InputTag>("trajectories"), consumesCollector()),
91  pixelClusters_(
92  consumes<edmNew::DetSetVector<SiPixelCluster>>(iConfig.getParameter<edm::InputTag>("phase2pixelClusters"))),
93  phase2OTClusters_(consumes<edmNew::DetSetVector<Phase2TrackerCluster1D>>(
94  iConfig.getParameter<edm::InputTag>("phase2OTClusters"))) {
95  produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster>>>();
96  produces<edm::ContainerMask<edmNew::DetSetVector<Phase2TrackerCluster1D>>>();
97 
98  // old mode
99  auto const& overrideTrkQuals = iConfig.getParameter<edm::InputTag>("overrideTrkQuals");
100  if (!overrideTrkQuals.label().empty())
101  overrideTrkQuals_ = consumes<edm::ValueMap<int>>(overrideTrkQuals);
102 
103  auto const& classifier = iConfig.getParameter<edm::InputTag>("trackClassifier");
104  if (!classifier.label().empty())
105  srcQuals = consumes<QualityMaskCollection>(classifier);
106 
107  auto const& oldClusterRemovalInfo = iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo");
108  if (!oldClusterRemovalInfo.label().empty()) {
109  oldPxlMaskToken_ = consumes<PixelMaskContainer>(oldClusterRemovalInfo);
110  oldPh2OTMaskToken_ = consumes<Phase2OTMaskContainer>(oldClusterRemovalInfo);
111  }
112  }
113 
114  void TrackClusterRemoverPhase2::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
116  iEvent.getByToken(pixelClusters_, pixelClusters);
118  iEvent.getByToken(phase2OTClusters_, phase2OTClusters);
119 
120  std::vector<bool> collectedPixels;
121  std::vector<bool> collectedPhase2OTs;
122 
123  if (!oldPxlMaskToken_.isUninitialized()) {
126  iEvent.getByToken(oldPxlMaskToken_, oldPxlMask);
127  iEvent.getByToken(oldPh2OTMaskToken_, oldPh2OTMask);
128  LogDebug("TrackClusterRemoverPhase2")
129  << "to merge in, " << oldPxlMask->size() << " phase2 pixel and " << oldPh2OTMask->size() << " phase2 OT";
130  oldPxlMask->copyMaskTo(collectedPixels);
131  oldPh2OTMask->copyMaskTo(collectedPhase2OTs);
132  assert(phase2OTClusters->dataSize() >= collectedPhase2OTs.size());
133  collectedPhase2OTs.resize(phase2OTClusters->dataSize(), false);
134 
135  } else {
136  collectedPixels.resize(pixelClusters->dataSize(), false);
137  collectedPhase2OTs.resize(phase2OTClusters->dataSize(), false);
138  }
139 
140  // loop over trajectories, filter, mask clusters../
141 
142  unsigned char qualMask = ~0;
143  if (trackQuality_ != reco::TrackBase::undefQuality)
144  qualMask = 1 << trackQuality_;
145 
146  auto const& tracks = tracks_.tracks(iEvent);
147  auto s = tracks.size();
148 
149  QualityMaskCollection oldStyle;
150  QualityMaskCollection const* pquals = nullptr;
151 
152  if (!overrideTrkQuals_.isUninitialized()) {
154  iEvent.getByToken(overrideTrkQuals_, quals);
155  assert(s == (*quals).size());
156 
157  oldStyle.resize(s, 0);
158  for (auto i = 0U; i < s; ++i)
159  if ((*quals).get(i) > 0)
160  oldStyle[i] = (255) & (*quals).get(i);
161  pquals = &oldStyle;
162  }
163 
164  if (!srcQuals.isUninitialized()) {
166  iEvent.getByToken(srcQuals, hqual);
167  pquals = hqual.product();
168  }
169 
170  for (auto i = 0U; i < s; ++i) {
171  const reco::Track& track = tracks[i];
172  bool goodTk = (pquals) ? (*pquals)[i] & qualMask : track.quality(trackQuality_);
173  if (!goodTk)
174  continue;
176  continue;
177  auto const& chi2sX5 = track.extra()->chi2sX5();
178  assert(chi2sX5.size() == track.recHitsSize());
179  auto hb = track.recHitsBegin();
180  for (unsigned int h = 0; h < track.recHitsSize(); h++) {
181  auto hit = *(hb + h);
182  if (!hit->isValid())
183  continue;
184  if (chi2sX5[h] > maxChi2_)
185  continue; // skip outliers
186  auto const& thit = reinterpret_cast<BaseTrackerRecHit const&>(*hit);
187  auto const& cluster = thit.firstClusterRef();
188  // FIXME when we will get also Phase2 pixel
189  if (cluster.isPixel())
190  collectedPixels[cluster.key()] = true;
191  else if (cluster.isPhase2())
192  collectedPhase2OTs[cluster.key()] = true;
193  }
194  }
195 
196  auto removedPixelClusterMask = std::make_unique<PixelMaskContainer>(
198  LogDebug("TrackClusterRemoverPhase2")
199  << "total pxl to skip: " << std::count(collectedPixels.begin(), collectedPixels.end(), true);
200  iEvent.put(std::move(removedPixelClusterMask));
201 
202  auto removedPhase2OTClusterMask = std::make_unique<Phase2OTMaskContainer>(
204  LogDebug("TrackClusterRemoverPhase2")
205  << "total ph2OT to skip: " << std::count(collectedPhase2OTs.begin(), collectedPhase2OTs.end(), true);
206  iEvent.put(std::move(removedPhase2OTClusterMask));
207  }
208 
209 } // namespace
210 
213 DEFINE_FWK_MODULE(TrackClusterRemoverPhase2);
#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 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
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
Pixel cluster – collection of neighboring pixels above threshold.
fixed size matrix
HLT enums.
def move(src, dest)
Definition: eostools.py:511