test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackClusterRemover.cc
Go to the documentation of this file.
6 
8 
12 
13 
18 
20 
23 
25 
26 #include<limits>
27 
28 namespace {
29 
30  class TrackClusterRemover final : public edm::global::EDProducer<> {
31  public:
32  TrackClusterRemover(const edm::ParameterSet& iConfig) ;
33  ~TrackClusterRemover(){}
34  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
35  private:
36 
37  virtual void produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const override;
38 
41 
42  using QualityMaskCollection = std::vector<unsigned char>;
43 
44  const float maxChi2_;
45  const int minNumberOfLayersWithMeasBeforeFiltering_;
46  const reco::TrackBase::TrackQuality trackQuality_;
47 
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  };
62 
63  void TrackClusterRemover::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
65  desc.add<edm::InputTag>("trajectories",edm::InputTag());
66  desc.add<edm::InputTag>("trackClassifier",edm::InputTag("","QualityMasks"));
67  desc.add<edm::InputTag>("pixelClusters",edm::InputTag("siPixelClusters"));
68  desc.add<edm::InputTag>("stripClusters",edm::InputTag("siStripClusters"));
69  desc.add<edm::InputTag>("oldClusterRemovalInfo",edm::InputTag());
70 
71  desc.add<std::string>("TrackQuality","highPurity");
72  desc.add<double>("maxChi2",30.);
73  desc.add<int>("minNumberOfLayersWithMeasBeforeFiltering",0);
74  // old mode
75  desc.add<edm::InputTag>("overrideTrkQuals",edm::InputTag());
76 
77  descriptions.add("trackClusterRemover", desc);
78 
79  }
80 
81  TrackClusterRemover::TrackClusterRemover(const edm::ParameterSet& iConfig) :
82  maxChi2_(iConfig.getParameter<double>("maxChi2")),
83  minNumberOfLayersWithMeasBeforeFiltering_(iConfig.getParameter<int>("minNumberOfLayersWithMeasBeforeFiltering")),
84  trackQuality_(reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"))),
85 
86  trajectories_(iConfig.getParameter<edm::InputTag>("trajectories"),consumesCollector()),
87  pixelClusters_(consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<edm::InputTag>("pixelClusters"))),
88  stripClusters_(consumes<edmNew::DetSetVector<SiStripCluster> >(iConfig.getParameter<edm::InputTag>("stripClusters")))
89  {
90 
91  produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster> > >();
92  produces<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster> > >();
93 
94  // old mode
95  auto const & overrideTrkQuals = iConfig.getParameter<edm::InputTag>("overrideTrkQuals");
96  if ( !overrideTrkQuals.label().empty() )
97  overrideTrkQuals_ = consumes<edm::ValueMap<int> >(overrideTrkQuals);
98 
99  auto const & classifier = iConfig.getParameter<edm::InputTag>("trackClassifier");
100  if ( !classifier.label().empty())
101  srcQuals = consumes<QualityMaskCollection>(classifier);
102 
103  auto const & oldClusterRemovalInfo = iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo");
104  if (!oldClusterRemovalInfo.label().empty()) {
105  oldPxlMaskToken_ = consumes<PixelMaskContainer>(oldClusterRemovalInfo);
106  oldStrMaskToken_ = consumes<StripMaskContainer>(oldClusterRemovalInfo);
107  }
108 
109  }
110 
111 
112  void
113  TrackClusterRemover::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const
114  {
115 
116 
118  iEvent.getByToken(pixelClusters_, pixelClusters);
120  iEvent.getByToken(stripClusters_, stripClusters);
121 
122 
123  std::vector<bool> collectedStrips;
124  std::vector<bool> collectedPixels;
125 
126  if(!oldPxlMaskToken_.isUninitialized()) {
129  iEvent.getByToken(oldPxlMaskToken_ ,oldPxlMask);
130  iEvent.getByToken(oldStrMaskToken_ ,oldStrMask);
131  LogDebug("TrackClusterRemover")<<"to merge in, "<<oldStrMask->size()<<" strp and "<<oldPxlMask->size()<<" pxl";
132  // std::cout <<"TrackClusterRemover "<<"to merge in, "<<oldStrMask->size()<<" strp and "<<oldPxlMask->size()<<" pxl" << std::endl;
133  oldStrMask->copyMaskTo(collectedStrips);
134  oldPxlMask->copyMaskTo(collectedPixels);
135  assert(stripClusters->dataSize()>=collectedStrips.size());
136  collectedStrips.resize(stripClusters->dataSize(), false);
137  //std::cout << "TrackClusterRemover " <<"total strip already to skip: "
138  // <<std::count(collectedStrips.begin(),collectedStrips.end(),true) <<std::endl;
139 
140  }else {
141  collectedStrips.resize(stripClusters->dataSize(), false);
142  collectedPixels.resize(pixelClusters->dataSize(), false);
143  }
144 
145 
146 
147 
148  // loop over trajectories, filter, mask clusters../
149 
150  unsigned char qualMask = ~0;
151  if (trackQuality_!=reco::TrackBase::undefQuality) qualMask = 1<<trackQuality_;
152 
153 
154  auto const & tracks = trajectories_.tracks(iEvent);
155  auto const & trajs = trajectories_.trajectories(iEvent);
156  auto s = tracks.size();
157 
158  assert(s==trajs.size());
159 
160  QualityMaskCollection oldStyle;
161  QualityMaskCollection const * pquals=nullptr;
162 
163  if (!overrideTrkQuals_.isUninitialized()) {
165  iEvent.getByToken(overrideTrkQuals_,quals);
166  assert(s==(*quals).size());
167 
168  oldStyle.resize(s,0);
169  for (auto i=0U; i<s; ++i) if ( (*quals).get(i) > 0 ) oldStyle[i] = (255)&(*quals).get(i);
170  pquals = &oldStyle;
171  }
172 
173  if (!srcQuals.isUninitialized()) {
175  iEvent.getByToken(srcQuals, hqual);
176  pquals = hqual.product();
177  }
178 
179  // if (!pquals) std::cout << "no qual collection" << std::endl;
180 
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  const Trajectory &tj = trajs[i];
187  const auto & tms = tj.measurements();
188  for (auto const & tm : tms) {
189  auto const & hit = *tm.recHit();
190  if (!hit.isValid()) continue;
191  if ( tm.estimate() > maxChi2_ ) continue; // skip outliers
192  auto const & thit = reinterpret_cast<BaseTrackerRecHit const&>(hit);
193  auto const & cluster = thit.firstClusterRef();
194  if (cluster.isStrip()) collectedStrips[cluster.key()]=true;
195  else collectedPixels[cluster.key()]=true;
196  if (trackerHitRTTI::isMatched(thit))
197  collectedStrips[reinterpret_cast<SiStripMatchedRecHit2D const&>(hit).stereoClusterRef().key()]=true;
198  }
199  }
200 
201 
202  // std::cout << " => collectedStrips: " << collectedStrips.size() << std::endl;
203 
204  auto removedStripClusterMask =
205  std::make_unique<StripMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiStripCluster>>(stripClusters),collectedStrips);
206  LogDebug("TrackClusterRemover")<<"total strip to skip: "<<std::count(collectedStrips.begin(),collectedStrips.end(),true);
207  // std::cout << "TrackClusterRemover " <<"total strip to skip: "<<std::count(collectedStrips.begin(),collectedStrips.end(),true) <<std::endl;
208  iEvent.put(std::move(removedStripClusterMask));
209 
210  auto removedPixelClusterMask=
211  std::make_unique<PixelMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiPixelCluster>>(pixelClusters),collectedPixels);
212  LogDebug("TrackClusterRemover")<<"total pxl to skip: "<<std::count(collectedPixels.begin(),collectedPixels.end(),true);
213  iEvent.put(std::move(removedPixelClusterMask));
214 
215 
216 
217  }
218 
219 
220 }
221 
222 
225 DEFINE_FWK_MODULE(TrackClusterRemover);
226 
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
TrackQuality
track quality
Definition: TrackBase.h:151
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:527
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
DataContainer const & measurements() const
Definition: Trajectory.h:250
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
def move
Definition: eostools.py:510
bool isMatched(TrackingRecHit const &hit)
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
tuple tracks
Definition: testEve_cfg.py:39
virtual void produce(StreamID, Event &, EventSetup const &) const =0
string const
Definition: compareJSON.py:14
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:505
Pixel cluster – collection of neighboring pixels above threshold.