CMS 3D CMS Logo

TrackClusterRemoverPhase2.cc
Go to the documentation of this file.
6 
8 
11 
16 
18 
21 
23 
25 
26 #include <limits>
27 
28 /* This is a copy of the TrackClusterRemover
29  * for Phase2 Tk upgrade
30  * FIXME:: changing with new phase2 pixel DataFormats!
31  * FIXME:: still to be factorized
32  */
33 
34 namespace {
35 
36  class TrackClusterRemoverPhase2 final : public edm::global::EDProducer<> {
37  public:
38  TrackClusterRemoverPhase2(const edm::ParameterSet& iConfig);
39  ~TrackClusterRemoverPhase2() override {}
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
41 
42  private:
43  void produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const override;
44 
47 
48  using QualityMaskCollection = std::vector<unsigned char>;
49 
50  const unsigned char maxChi2_;
52  const reco::TrackBase::TrackQuality trackQuality_;
53 
54  const TrackCollectionTokens tracks_;
56 
59 
60  edm::EDGetTokenT<PixelMaskContainer> oldPxlMaskToken_;
61  edm::EDGetTokenT<Phase2OTMaskContainer> oldPh2OTMaskToken_;
62 
63  // backward compatibility during transition period
64  edm::EDGetTokenT<edm::ValueMap<int>> overrideTrkQuals_;
65  };
66 
69  desc.add<edm::InputTag>("trajectories", edm::InputTag());
70  desc.add<edm::InputTag>("trackClassifier", edm::InputTag("", "QualityMasks"));
71  desc.add<edm::InputTag>("phase2pixelClusters", edm::InputTag("siPixelClusters"));
72  desc.add<edm::InputTag>("phase2OTClusters", edm::InputTag("siPhase2Clusters"));
73  desc.add<edm::InputTag>("oldClusterRemovalInfo", edm::InputTag());
74 
75  desc.add<std::string>("TrackQuality", "highPurity");
76  desc.add<double>("maxChi2", 30.);
77  desc.add<int>("minNumberOfLayersWithMeasBeforeFiltering", 0);
78  // old mode
79  desc.add<edm::InputTag>("overrideTrkQuals", edm::InputTag());
80 
81  descriptions.add("phase2trackClusterRemover", desc);
82  }
83 
84  TrackClusterRemoverPhase2::TrackClusterRemoverPhase2(const edm::ParameterSet& iConfig)
85  : maxChi2_(Traj2TrackHits::toChi2x5(iConfig.getParameter<double>("maxChi2"))),
87  iConfig.getParameter<int>("minNumberOfLayersWithMeasBeforeFiltering")),
88  trackQuality_(reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"))),
89 
90  tracks_(iConfig.getParameter<edm::InputTag>("trajectories"), consumesCollector()),
91  pixelClusters_(
92  consumes<edmNew::DetSetVector<SiPixelCluster>>(iConfig.getParameter<edm::InputTag>("phase2pixelClusters"))),
93  phase2OTClusters_(consumes<edmNew::DetSetVector<Phase2TrackerCluster1D>>(
94  iConfig.getParameter<edm::InputTag>("phase2OTClusters"))) {
95  produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster>>>();
96  produces<edm::ContainerMask<edmNew::DetSetVector<Phase2TrackerCluster1D>>>();
97 
98  // old mode
99  auto const& overrideTrkQuals = iConfig.getParameter<edm::InputTag>("overrideTrkQuals");
100  if (!overrideTrkQuals.label().empty())
101  overrideTrkQuals_ = consumes<edm::ValueMap<int>>(overrideTrkQuals);
102 
103  auto const& classifier = iConfig.getParameter<edm::InputTag>("trackClassifier");
104  if (!classifier.label().empty())
105  srcQuals = consumes<QualityMaskCollection>(classifier);
106 
107  auto const& oldClusterRemovalInfo = iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo");
108  if (!oldClusterRemovalInfo.label().empty()) {
109  oldPxlMaskToken_ = consumes<PixelMaskContainer>(oldClusterRemovalInfo);
110  oldPh2OTMaskToken_ = consumes<Phase2OTMaskContainer>(oldClusterRemovalInfo);
111  }
112  }
113 
114  void TrackClusterRemoverPhase2::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
116  iEvent.getByToken(pixelClusters_, pixelClusters);
118  iEvent.getByToken(phase2OTClusters_, phase2OTClusters);
119 
120  std::vector<bool> collectedPixels;
121  std::vector<bool> collectedPhase2OTs;
122 
123  if (!oldPxlMaskToken_.isUninitialized()) {
126  iEvent.getByToken(oldPxlMaskToken_, oldPxlMask);
127  iEvent.getByToken(oldPh2OTMaskToken_, oldPh2OTMask);
128  LogDebug("TrackClusterRemoverPhase2")
129  << "to merge in, " << oldPxlMask->size() << " phase2 pixel and " << oldPh2OTMask->size() << " phase2 OT";
130  oldPxlMask->copyMaskTo(collectedPixels);
131  oldPh2OTMask->copyMaskTo(collectedPhase2OTs);
132  assert(phase2OTClusters->dataSize() >= collectedPhase2OTs.size());
133  collectedPhase2OTs.resize(phase2OTClusters->dataSize(), false);
134 
135  } else {
136  collectedPixels.resize(pixelClusters->dataSize(), false);
137  collectedPhase2OTs.resize(phase2OTClusters->dataSize(), false);
138  }
139 
140  // loop over trajectories, filter, mask clusters../
141 
142  unsigned char qualMask = ~0;
143  if (trackQuality_ != reco::TrackBase::undefQuality)
144  qualMask = 1 << trackQuality_;
145 
146  auto const& tracks = tracks_.tracks(iEvent);
147  auto s = tracks.size();
148 
149  QualityMaskCollection oldStyle;
150  QualityMaskCollection const* pquals = nullptr;
151 
152  if (!overrideTrkQuals_.isUninitialized()) {
154  iEvent.getByToken(overrideTrkQuals_, quals);
155  assert(s == (*quals).size());
156 
157  oldStyle.resize(s, 0);
158  for (auto i = 0U; i < s; ++i)
159  if ((*quals).get(i) > 0)
160  oldStyle[i] = (255) & (*quals).get(i);
161  pquals = &oldStyle;
162  }
163 
164  if (!srcQuals.isUninitialized()) {
166  iEvent.getByToken(srcQuals, hqual);
167  pquals = hqual.product();
168  }
169 
170  for (auto i = 0U; i < s; ++i) {
171  const reco::Track& track = tracks[i];
172  bool goodTk = (pquals) ? (*pquals)[i] & qualMask : track.quality(trackQuality_);
173  if (!goodTk)
174  continue;
175  if (track.hitPattern().trackerLayersWithMeasurement() < minNumberOfLayersWithMeasBeforeFiltering_)
176  continue;
177  auto const& chi2sX5 = track.extra()->chi2sX5();
178  assert(chi2sX5.size() == track.recHitsSize());
179  auto hb = track.recHitsBegin();
180  for (unsigned int h = 0; h < track.recHitsSize(); h++) {
181  auto hit = *(hb + h);
182  if (!hit->isValid())
183  continue;
184  if (chi2sX5[h] > maxChi2_)
185  continue; // skip outliers
186  auto const& thit = reinterpret_cast<BaseTrackerRecHit const&>(*hit);
187  auto const& cluster = thit.firstClusterRef();
188  // FIXME when we will get also Phase2 pixel
189  if (cluster.isPixel())
190  collectedPixels[cluster.key()] = true;
191  else if (cluster.isPhase2())
192  collectedPhase2OTs[cluster.key()] = true;
193  }
194  }
195 
196  auto removedPixelClusterMask = std::make_unique<PixelMaskContainer>(
198  LogDebug("TrackClusterRemoverPhase2")
199  << "total pxl to skip: " << std::count(collectedPixels.begin(), collectedPixels.end(), true);
200  iEvent.put(std::move(removedPixelClusterMask));
201 
202  auto removedPhase2OTClusterMask = std::make_unique<Phase2OTMaskContainer>(
204  LogDebug("TrackClusterRemoverPhase2")
205  << "total ph2OT to skip: " << std::count(collectedPhase2OTs.begin(), collectedPhase2OTs.end(), true);
206  iEvent.put(std::move(removedPhase2OTClusterMask));
207  }
208 
209 } // namespace
210 
213 DEFINE_FWK_MODULE(TrackClusterRemoverPhase2);
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:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
HLT_2018_cff.overrideTrkQuals
overrideTrkQuals
Definition: HLT_2018_cff.py:8684
LumiMonitor_cff.pixelClusters
pixelClusters
Definition: LumiMonitor_cff.py:10
ContainerMask.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
Phase2TrackerCluster1D
Definition: Phase2TrackerCluster1D.h:10
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
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
SiPixelCluster
Pixel cluster – collection of neighboring pixels above threshold.
Definition: SiPixelCluster.h:27
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::global::EDProducerBase::fillDescriptions
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Definition: EDProducerBase.cc:255
edm::Handle
Definition: AssociativeIterator.h:50
HLT_2018_cff.oldClusterRemovalInfo
oldClusterRemovalInfo
Definition: HLT_2018_cff.py:8682
HLTEgPhaseIITestSequence_cff.phase2OTClusters
phase2OTClusters
Definition: HLTEgPhaseIITestSequence_cff.py:722
edmNew
Definition: DetSet2RangeMap.h:11
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
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_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
Traj2TrackHits
Definition: Traj2TrackHits.h:16
ModuleDef.h
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
hcalSimParameters_cfi.hb
hb
Definition: hcalSimParameters_cfi.py:57
InputTag.h
ValueMap.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
edmNew::DetSetVector
Definition: DetSetNew.h:13
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
TrackCollectionTokens.h
DetId.h
Phase2TrackerCluster1D.h
edm::ValueMap< int >
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
ParameterSet.h
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:126
EDProducer.h
edm::Event
Definition: Event.h:73
DetSetVectorNew.h
edm::InputTag
Definition: InputTag.h:15
hit
Definition: SiStripHitEffFromCalibTree.cc:88