CMS 3D CMS Logo

TrackClusterRemover.cc
Go to the documentation of this file.
6 
8 
12 
17 
19 
22 
24 
26 
27 #include <limits>
28 
29 namespace {
30 
31  class TrackClusterRemover final : public edm::global::EDProducer<> {
32  public:
33  TrackClusterRemover(const edm::ParameterSet& iConfig);
34  ~TrackClusterRemover() override {}
35  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
36 
37  private:
38  void produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const override;
39 
42 
43  using QualityMaskCollection = std::vector<unsigned char>;
44 
45  const unsigned char maxChi2x5_;
47  const reco::TrackBase::TrackQuality trackQuality_;
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 
64  desc.add<edm::InputTag>("trajectories", edm::InputTag());
65  desc.add<edm::InputTag>("trackClassifier", edm::InputTag("", "QualityMasks"));
66  desc.add<edm::InputTag>("pixelClusters", edm::InputTag("siPixelClusters"));
67  desc.add<edm::InputTag>("stripClusters", edm::InputTag("siStripClusters"));
68  desc.add<edm::InputTag>("oldClusterRemovalInfo", edm::InputTag());
69 
70  desc.add<std::string>("TrackQuality", "highPurity");
71  desc.add<double>("maxChi2", 30.);
72  desc.add<int>("minNumberOfLayersWithMeasBeforeFiltering", 0);
73  // old mode
74  desc.add<edm::InputTag>("overrideTrkQuals", edm::InputTag());
75 
76  descriptions.add("trackClusterRemover", desc);
77  }
78 
79  TrackClusterRemover::TrackClusterRemover(const edm::ParameterSet& iConfig)
80  : maxChi2x5_(Traj2TrackHits::toChi2x5(iConfig.getParameter<double>("maxChi2"))),
82  iConfig.getParameter<int>("minNumberOfLayersWithMeasBeforeFiltering")),
83  trackQuality_(reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"))),
84 
85  trajectories_(iConfig.getParameter<edm::InputTag>("trajectories"), consumesCollector())
86 
87  {
88  auto const& pixelClusters = iConfig.getParameter<edm::InputTag>("pixelClusters");
89  auto const& stripClusters = iConfig.getParameter<edm::InputTag>("stripClusters");
90 
91  if (pixelClusters.label().empty() && stripClusters.label().empty())
93  << "Configuration Error: TrackClusterRemover used without input cluster collections";
94  if (!pixelClusters.label().empty()) {
95  pixelClusters_ = consumes<edmNew::DetSetVector<SiPixelCluster>>(pixelClusters);
96  produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster>>>();
97  }
98  if (!stripClusters.label().empty()) {
99  stripClusters_ = consumes<edmNew::DetSetVector<SiStripCluster>>(stripClusters);
100  produces<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster>>>();
101  }
102  // old mode
103  auto const& overrideTrkQuals = iConfig.getParameter<edm::InputTag>("overrideTrkQuals");
104  if (!overrideTrkQuals.label().empty())
105  overrideTrkQuals_ = consumes<edm::ValueMap<int>>(overrideTrkQuals);
106 
107  auto const& classifier = iConfig.getParameter<edm::InputTag>("trackClassifier");
108  if (!classifier.label().empty())
109  srcQuals = consumes<QualityMaskCollection>(classifier);
110 
111  auto const& oldClusterRemovalInfo = iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo");
112  if (!oldClusterRemovalInfo.label().empty()) {
113  oldPxlMaskToken_ = consumes<PixelMaskContainer>(oldClusterRemovalInfo);
114  oldStrMaskToken_ = consumes<StripMaskContainer>(oldClusterRemovalInfo);
115  }
116  }
117 
118  void TrackClusterRemover::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
120  if (!pixelClusters_.isUninitialized())
121  iEvent.getByToken(pixelClusters_, pixelClusters);
123  if (!stripClusters_.isUninitialized())
124  iEvent.getByToken(stripClusters_, stripClusters);
125 
126  std::vector<bool> collectedStrips;
127  std::vector<bool> collectedPixels;
128 
129  if (!oldPxlMaskToken_.isUninitialized()) {
132  iEvent.getByToken(oldPxlMaskToken_, oldPxlMask);
133  iEvent.getByToken(oldStrMaskToken_, oldStrMask);
134  LogDebug("TrackClusterRemover") << "to merge in, " << oldStrMask->size() << " strp, " << oldPxlMask->size()
135  << " pxl";
136 
137  // std::cout <<"TrackClusterRemover "<<"to merge in, "<<oldStrMask->size()<<" strp and "<<oldPxlMask->size()<<" pxl" << std::endl;
138  oldStrMask->copyMaskTo(collectedStrips);
139  oldPxlMask->copyMaskTo(collectedPixels);
140  if (!stripClusters_.isUninitialized()) {
141  assert(stripClusters->dataSize() >= collectedStrips.size());
142  collectedStrips.resize(stripClusters->dataSize(), false);
143  //std::cout << "TrackClusterRemover " <<"total strip already to skip: "
144  // <<std::count(collectedStrips.begin(),collectedStrips.end(),true) <<std::endl;
145  }
146  } else {
147  if (!stripClusters_.isUninitialized())
148  collectedStrips.resize(stripClusters->dataSize(), false);
149  if (!pixelClusters_.isUninitialized())
150  collectedPixels.resize(pixelClusters->dataSize(), false);
151  }
152 
153  // loop over trajectories, filter, mask clusters../
154 
155  unsigned char qualMask = ~0;
156  if (trackQuality_ != reco::TrackBase::undefQuality)
157  qualMask = 1 << trackQuality_;
158 
159  auto const& tracks = trajectories_.tracks(iEvent);
160  auto s = tracks.size();
161 
162  // assert(s==trajs.size());
163 
164  QualityMaskCollection oldStyle;
165  QualityMaskCollection const* pquals = nullptr;
166 
167  if (!overrideTrkQuals_.isUninitialized()) {
169  iEvent.getByToken(overrideTrkQuals_, quals);
170  assert(s == (*quals).size());
171 
172  oldStyle.resize(s, 0);
173  for (auto i = 0U; i < s; ++i)
174  if ((*quals).get(i) > 0)
175  oldStyle[i] = (255) & (*quals).get(i);
176  pquals = &oldStyle;
177  }
178 
179  if (!srcQuals.isUninitialized()) {
181  iEvent.getByToken(srcQuals, hqual);
182  pquals = hqual.product();
183  }
184  // if (!pquals) std::cout << "no qual collection" << std::endl;
185  for (auto i = 0U; i < s; ++i) {
186  const reco::Track& track = tracks[i];
187  bool goodTk = (pquals) ? (*pquals)[i] & qualMask : track.quality(trackQuality_);
188  if (!goodTk)
189  continue;
190  if (track.hitPattern().trackerLayersWithMeasurement() < minNumberOfLayersWithMeasBeforeFiltering_)
191  continue;
192 
193  auto const& chi2sX5 = track.extra()->chi2sX5();
194  assert(chi2sX5.size() == track.recHitsSize());
195  auto hb = track.recHitsBegin();
196  for (unsigned int h = 0; h < track.recHitsSize(); h++) {
197  auto recHit = *(hb + h);
198  auto const& hit = *recHit;
200  continue;
201  if (chi2sX5[h] > maxChi2x5_)
202  continue; // skip outliers
203  auto const& thit = reinterpret_cast<BaseTrackerRecHit const&>(hit);
204  auto const& cluster = thit.firstClusterRef();
205  if (!stripClusters_.isUninitialized() && cluster.isStrip())
206  collectedStrips[cluster.key()] = true;
207  if (!pixelClusters_.isUninitialized() && cluster.isPixel())
208  collectedPixels[cluster.key()] = true;
209  if (trackerHitRTTI::isMatched(thit))
210  collectedStrips[reinterpret_cast<SiStripMatchedRecHit2D const&>(hit).stereoClusterRef().key()] = true;
211  }
212  }
213 
214  // std::cout << " => collectedStrips: " << collectedStrips.size() << std::endl;
215  if (!stripClusters_.isUninitialized()) {
216  auto removedStripClusterMask = std::make_unique<StripMaskContainer>(
218  LogDebug("TrackClusterRemover") << "total strip to skip: "
219  << 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 = std::make_unique<PixelMaskContainer>(
226  LogDebug("TrackClusterRemover") << "total pxl to skip: "
227  << std::count(collectedPixels.begin(), collectedPixels.end(), true);
228  iEvent.put(std::move(removedPixelClusterMask));
229  }
230  }
231 
232 } // namespace
233 
236 DEFINE_FWK_MODULE(TrackClusterRemover);
TrackCollectionTokens
Definition: TrackCollectionTokens.h:13
ConfigurationDescriptions.h
edm::RefProd
Definition: EDProductfwd.h:25
ClusterRemovalInfo.h
edm::StreamID
Definition: StreamID.h:30
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11779
HLT_FULL_cff.oldClusterRemovalInfo
oldClusterRemovalInfo
Definition: HLT_FULL_cff.py:10079
LumiMonitor_cff.pixelClusters
pixelClusters
Definition: LumiMonitor_cff.py:10
ContainerMask.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
edm::EDGetTokenT< QualityMaskCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
reco::TrackBase::undefQuality
Definition: TrackBase.h:151
SiPixelCluster.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
cms::cuda::assert
assert(be >=bs)
reco::TrackBase::TrackQuality
TrackQuality
track quality
Definition: TrackBase.h:150
FastTrackerRecHitMaskProducer_cfi.minNumberOfLayersWithMeasBeforeFiltering_
minNumberOfLayersWithMeasBeforeFiltering_
Definition: FastTrackerRecHitMaskProducer_cfi.py:5
edm::ContainerMask
Definition: ContainerMask.h:36
edm::global::EDProducerBase::produce
virtual void produce(StreamID, Event &, EventSetup const &) const =0
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::global::EDProducerBase::fillDescriptions
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Definition: EDProducerBase.cc:278
edm::Handle
Definition: AssociativeIterator.h:50
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
edm::Exception
Definition: EDMException.h:77
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
reco::Track
Definition: Track.h:27
ProductID.h
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
h
Traj2TrackHits.h
ParameterSetDescription.h
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_FULL_cff.stripClusters
stripClusters
Definition: HLT_FULL_cff.py:10080
trackerHitRTTI::isMatched
bool isMatched(TrackingRecHit const &hit)
Definition: trackerHitRTTI.h:33
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
SiStripCluster.h
Event.h
Traj2TrackHits
Definition: Traj2TrackHits.h:16
ModuleDef.h
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::isFromDet
bool isFromDet(TrackingRecHit const &hit)
Definition: trackerHitRTTI.h:36
edm::EventSetup
Definition: EventSetup.h:57
hcalSimParameters_cfi.hb
hb
Definition: hcalSimParameters_cfi.py:60
InputTag.h
ValueMap.h
edmNew::DetSetVector
Definition: DetSetNew.h:13
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
TrackCollectionTokens.h
DetId.h
edm::ValueMap< int >
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterSet.h
SiStripMatchedRecHit2D.h
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:153
EDProducer.h
edm::Event
Definition: Event.h:73
edm::errors::Configuration
Definition: EDMException.h:36
DetSetVectorNew.h
edm::InputTag
Definition: InputTag.h:15
HLT_FULL_cff.overrideTrkQuals
overrideTrkQuals
Definition: HLT_FULL_cff.py:10081
hit
Definition: SiStripHitEffFromCalibTree.cc:88