CMS 3D CMS Logo

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