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() override{}
36  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
37  private:
38 
39  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 
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 
90  {
91 
92 
93  auto const & pixelClusters = iConfig.getParameter<edm::InputTag>("pixelClusters");
94  auto const & stripClusters = iConfig.getParameter<edm::InputTag>("stripClusters");
95 
96  if (pixelClusters.label().empty() && stripClusters.label().empty() ) throw edm::Exception(edm::errors::Configuration) << "Configuration Error: TrackClusterRemover used without input cluster collections";
97  if ( !pixelClusters.label().empty() ){
98  pixelClusters_ = consumes<edmNew::DetSetVector<SiPixelCluster> >(pixelClusters);
99  produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster> > >();
100  }
101  if ( !stripClusters.label().empty() ){
102  stripClusters_ = consumes<edmNew::DetSetVector<SiStripCluster> >(stripClusters);
103  produces<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster> > >();
104  }
105  // old mode
106  auto const & overrideTrkQuals = iConfig.getParameter<edm::InputTag>("overrideTrkQuals");
107  if ( !overrideTrkQuals.label().empty() )
108  overrideTrkQuals_ = consumes<edm::ValueMap<int> >(overrideTrkQuals);
109 
110  auto const & classifier = iConfig.getParameter<edm::InputTag>("trackClassifier");
111  if ( !classifier.label().empty())
112  srcQuals = consumes<QualityMaskCollection>(classifier);
113 
114  auto const & oldClusterRemovalInfo = iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo");
115  if (!oldClusterRemovalInfo.label().empty()) {
116  oldPxlMaskToken_ = consumes<PixelMaskContainer>(oldClusterRemovalInfo);
117  oldStrMaskToken_ = consumes<StripMaskContainer>(oldClusterRemovalInfo);
118  }
119 
120  }
121 
122 
123  void
124  TrackClusterRemover::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const
125  {
126 
127 
129  if(!pixelClusters_.isUninitialized()) iEvent.getByToken(pixelClusters_, pixelClusters);
131  if(!stripClusters_.isUninitialized()) iEvent.getByToken(stripClusters_, stripClusters);
132 
133 
134  std::vector<bool> collectedStrips;
135  std::vector<bool> collectedPixels;
136 
137  if(!oldPxlMaskToken_.isUninitialized()) {
140  iEvent.getByToken(oldPxlMaskToken_ ,oldPxlMask);
141  iEvent.getByToken(oldStrMaskToken_ ,oldStrMask);
142  LogDebug("TrackClusterRemover")<<"to merge in, "<<oldStrMask->size()<<" strp, "<<oldPxlMask->size()<<" pxl";
143 
144  // std::cout <<"TrackClusterRemover "<<"to merge in, "<<oldStrMask->size()<<" strp and "<<oldPxlMask->size()<<" pxl" << std::endl;
145  oldStrMask->copyMaskTo(collectedStrips);
146  oldPxlMask->copyMaskTo(collectedPixels);
147  if(!stripClusters_.isUninitialized()){
148  assert(stripClusters->dataSize()>=collectedStrips.size());
149  collectedStrips.resize(stripClusters->dataSize(), false);
150  //std::cout << "TrackClusterRemover " <<"total strip already to skip: "
151  // <<std::count(collectedStrips.begin(),collectedStrips.end(),true) <<std::endl;
152  }
153  }else {
154  if(!stripClusters_.isUninitialized()) collectedStrips.resize(stripClusters->dataSize(), false);
155  if(!pixelClusters_.isUninitialized()) collectedPixels.resize(pixelClusters->dataSize(), false);
156  }
157 
158 
159 
160 
161  // loop over trajectories, filter, mask clusters../
162 
163  unsigned char qualMask = ~0;
164  if (trackQuality_!=reco::TrackBase::undefQuality) qualMask = 1<<trackQuality_;
165 
166 
167  auto const & tracks = trajectories_.tracks(iEvent);
168  auto s = tracks.size();
169 
170  // assert(s==trajs.size());
171 
172  QualityMaskCollection oldStyle;
173  QualityMaskCollection const * pquals=nullptr;
174 
175  if (!overrideTrkQuals_.isUninitialized()) {
177  iEvent.getByToken(overrideTrkQuals_,quals);
178  assert(s==(*quals).size());
179 
180  oldStyle.resize(s,0);
181  for (auto i=0U; i<s; ++i) if ( (*quals).get(i) > 0 ) oldStyle[i] = (255)&(*quals).get(i);
182  pquals = &oldStyle;
183  }
184 
185  if (!srcQuals.isUninitialized()) {
187  iEvent.getByToken(srcQuals, hqual);
188  pquals = hqual.product();
189  }
190  // if (!pquals) std::cout << "no qual collection" << std::endl;
191  for (auto i=0U; i<s; ++i){
192  const reco::Track & track = tracks[i];
193  bool goodTk = (pquals) ? (*pquals)[i] & qualMask : track.quality(trackQuality_);
194  if ( !goodTk) continue;
195  if(track.hitPattern().trackerLayersWithMeasurement() < minNumberOfLayersWithMeasBeforeFiltering_) continue;
196 
197  auto const & chi2sX5 = track.extra()->chi2sX5();
198  assert(chi2sX5.size()==track.recHitsSize());
199  auto hb = track.recHitsBegin();
200  for(unsigned int h=0;h<track.recHitsSize();h++){
201  auto recHit = *(hb+h);
202  auto const & hit = *recHit;
203  if (!hit.isValid()) continue;
204  if ( chi2sX5[h] > maxChi2x5_ ) continue; // skip outliers
205  auto const & thit = reinterpret_cast<BaseTrackerRecHit const&>(hit);
206  auto const & cluster = thit.firstClusterRef();
207  if(!stripClusters_.isUninitialized() && cluster.isStrip()) collectedStrips[cluster.key()]=true;
208  if(!pixelClusters_.isUninitialized() && cluster.isPixel()) collectedPixels[cluster.key()]=true;
209  if (trackerHitRTTI::isMatched(thit))
210  collectedStrips[reinterpret_cast<SiStripMatchedRecHit2D const&>(hit).stereoClusterRef().key()]=true;
211  }
212  }
213 
214 
215  // std::cout << " => collectedStrips: " << collectedStrips.size() << std::endl;
216  if(!stripClusters_.isUninitialized()){
217  auto removedStripClusterMask =
218  std::make_unique<StripMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiStripCluster>>(stripClusters),collectedStrips);
219  LogDebug("TrackClusterRemover")<<"total strip to skip: "<<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=
225  std::make_unique<PixelMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiPixelCluster>>(pixelClusters),collectedPixels);
226  LogDebug("TrackClusterRemover")<<"total pxl to skip: "<<std::count(collectedPixels.begin(),collectedPixels.end(),true);
227  iEvent.put(std::move(removedPixelClusterMask));
228  }
229 
230  }
231 
232 
233 }
234 
235 
238 DEFINE_FWK_MODULE(TrackClusterRemover);
239 
#define LogDebug(id)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
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:519
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:518
virtual void produce(StreamID, Event &, EventSetup const &) const =0
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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:446
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:510
std::string const & label() const
Definition: InputTag.h:36
fixed size matrix
HLT enums.
virtual OmniClusterRef const & firstClusterRef() const =0
def move(src, dest)
Definition: eostools.py:510