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.
5 
9 
10 
15 
17 
20 
24 
25 
26 namespace {
27 
28  class TrackClusterRemover : public edm::stream::EDProducer<> {
29  public:
30  TrackClusterRemover(const edm::ParameterSet& iConfig) ;
31  ~TrackClusterRemover(){}
32  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override ;
33  private:
34 
35 
36 
39 
40 
41  bool mergeOld_;
42 
43  bool filterTracks_ = false;
44  int minNumberOfLayersWithMeasBeforeFiltering_=0;
45  float maxChi2_;
46  reco::TrackBase::TrackQuality trackQuality_;
47 
48 
50 
53 
54  edm::EDGetTokenT<PixelMaskContainer> oldPxlMaskToken_;
55  edm::EDGetTokenT<StripMaskContainer> oldStrMaskToken_;
56  std::vector< edm::EDGetTokenT<edm::ValueMap<int> > > overrideTrkQuals_;
57 
58 
59 
60  };
61 
62 
63  TrackClusterRemover::TrackClusterRemover(const edm::ParameterSet& iConfig) :
64  maxChi2_(iConfig.getParameter<double>("maxChi2"))
65  {
66 
67  produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster> > >();
68  produces<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster> > >();
69 
70 
71  trajectories_ = consumes<TrajTrackAssociationCollection> (iConfig.getParameter<edm::InputTag>("trajectories") );
72  pixelClusters_ = consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<edm::InputTag>("pixelClusters"));
73  stripClusters_ = consumes<edmNew::DetSetVector<SiStripCluster> >(iConfig.getParameter<edm::InputTag>("stripClusters"));
74 
75 
76  if (iConfig.exists("overrideTrkQuals")) {
77  edm::InputTag overrideTrkQuals = iConfig.getParameter<edm::InputTag>("overrideTrkQuals");
78  if ( !(overrideTrkQuals==edm::InputTag("")) )
79  overrideTrkQuals_.push_back( consumes<edm::ValueMap<int> >(overrideTrkQuals) );
80  }
81 
82  trackQuality_=reco::TrackBase::undefQuality;
83  filterTracks_=false;
84  if (iConfig.exists("TrackQuality")){
85  filterTracks_=true;
86  std::string trackQuality = iConfig.getParameter<std::string>("TrackQuality");
87  if ( !trackQuality.empty() ) {
88  trackQuality_=reco::TrackBase::qualityByName( trackQuality );
89  minNumberOfLayersWithMeasBeforeFiltering_ = iConfig.existsAs<int>("minNumberOfLayersWithMeasBeforeFiltering") ?
90  iConfig.getParameter<int>("minNumberOfLayersWithMeasBeforeFiltering") : 0;
91  }
92  }
93 
94  if ( iConfig.exists("oldClusterRemovalInfo") ) {
95  edm::InputTag oldClusterRemovalInfo = iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo");
96  mergeOld_ = ( (oldClusterRemovalInfo==edm::InputTag("")) ? false : true );
97  } else
98  mergeOld_ = false;
99 
100  if (mergeOld_) {
101  oldPxlMaskToken_ = consumes<PixelMaskContainer>(iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo"));
102  oldStrMaskToken_ = consumes<StripMaskContainer>(iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo"));
103  }
104 
105  }
106 
107 
108  void
109  TrackClusterRemover::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
110  {
111 
112 
114  iEvent.getByToken(pixelClusters_, pixelClusters);
116  iEvent.getByToken(stripClusters_, stripClusters);
117 
118 
119  std::vector<bool> collectedStrips;
120  std::vector<bool> collectedPixels;
121 
122  if(mergeOld_) {
125  iEvent.getByToken(oldPxlMaskToken_ ,oldPxlMask);
126  iEvent.getByToken(oldStrMaskToken_ ,oldStrMask);
127  LogDebug("TrackClusterRemover")<<"to merge in, "<<oldStrMask->size()<<" strp and "<<oldPxlMask->size()<<" pxl";
128  oldStrMask->copyMaskTo(collectedStrips);
129  oldPxlMask->copyMaskTo(collectedPixels);
130  assert(stripClusters->dataSize()>=collectedStrips.size());
131  collectedStrips.resize(stripClusters->dataSize(), false);
132  }else {
133  collectedStrips.resize(stripClusters->dataSize(), false);
134  collectedPixels.resize(pixelClusters->dataSize(), false);
135  }
136 
137 
138 
139 
140  // loop over trajectories, filter, mask clusters../
141 
142  edm::Handle<TrajTrackAssociationCollection> trajectories_totrack;
143  iEvent.getByToken(trajectories_,trajectories_totrack);
144 
145  std::vector<edm::Handle<edm::ValueMap<int> > > quals;
146 
147  if ( overrideTrkQuals_.size() > 0) {
148  quals.resize(1);
149  iEvent.getByToken(overrideTrkQuals_[0],quals[0]);
150  }
151 
152  for (auto const & asst : *trajectories_totrack){
153  const reco::Track & track = *(asst.val);
154  if (filterTracks_) {
155  bool goodTk = true;
156  if ( quals.size()!=0) {
157  int qual=(*(quals[0]))[asst.val];
158  if ( qual < 0 ) {goodTk=false;}
159  //note that this does not work for some trackquals (goodIterative or undefQuality)
160  else
161  goodTk = ( qual & (1<<trackQuality_))>>trackQuality_;
162  }
163  else
164  goodTk=(track.quality(trackQuality_));
165  if ( !goodTk) continue;
166  if(track.hitPattern().trackerLayersWithMeasurement() < minNumberOfLayersWithMeasBeforeFiltering_) continue;
167  }
168  const Trajectory &tj = *(asst.key);
169  const auto & tms = tj.measurements();
170  for (auto const & tm : tms) {
171  auto const & hit = *tm.recHit();
172  if (!hit.isValid()) continue;
173  if ( tm.estimate() > maxChi2_ ) continue; // skip outliers
174  auto const & thit = reinterpret_cast<BaseTrackerRecHit const&>(hit);
175  auto const & cluster = thit.firstClusterRef();
176  if (cluster.isStrip()) collectedStrips[cluster.key()]=true;
177  else collectedPixels[cluster.key()]=true;
178  if (trackerHitRTTI::isMatched(thit))
179  collectedStrips[reinterpret_cast<SiStripMatchedRecHit2D const&>(hit).stereoClusterRef().key()]=true;
180  }
181  }
182 
183 
184  std::auto_ptr<StripMaskContainer> removedStripClusterMask(
185  new StripMaskContainer(edm::RefProd<edmNew::DetSetVector<SiStripCluster> >(stripClusters),collectedStrips));
186  LogDebug("TrackClusterRemover")<<"total strip to skip: "<<std::count(collectedStrips.begin(),collectedStrips.end(),true);
187  // std::cout << "TrackClusterRemover " <<"total strip to skip: "<<std::count(collectedStrips_.begin(),collectedStrips_.end(),true) <<std::endl;
188  iEvent.put( removedStripClusterMask );
189 
190  std::auto_ptr<PixelMaskContainer> removedPixelClusterMask(
191  new PixelMaskContainer(edm::RefProd<edmNew::DetSetVector<SiPixelCluster> >(pixelClusters),collectedPixels));
192  LogDebug("TrackClusterRemover")<<"total pxl to skip: "<<std::count(collectedPixels.begin(),collectedPixels.end(),true);
193  iEvent.put( removedPixelClusterMask );
194 
195 
196 
197  }
198 
199 
200 }
201 
202 
205 DEFINE_FWK_MODULE(TrackClusterRemover);
206 
#define LogDebug(id)
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
virtual void produce(Event &, EventSetup const &)=0
TrackQuality
track quality
Definition: TrackBase.h:133
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:477
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
DataContainer const & measurements() const
Definition: Trajectory.h:203
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
bool isMatched(TrackingRecHit const &hit)
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:108
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:384
string const
Definition: compareJSON.py:14
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:551