CMS 3D CMS Logo

MuonReducedTrackExtraProducer.cc
Go to the documentation of this file.
5 
7  : muonToken_(consumes<edm::View<reco::Muon>>(pset.getParameter<edm::InputTag>("muonTag"))),
8  outputClusters_(pset.getParameter<bool>("outputClusters")),
9  selector_(pset.getParameter<std::string>("cut")),
10  trackExtraOutToken_(produces<reco::TrackExtraCollection>()),
11  trackingRecHitsOutToken_(produces<TrackingRecHitCollection>()),
12  associationOutToken_(produces<edm::Association<reco::TrackExtraCollection>>()) {
13  std::vector<edm::InputTag> trackExtraTags = pset.getParameter<std::vector<edm::InputTag>>("trackExtraTags");
14  for (edm::InputTag const& tag : trackExtraTags) {
15  trackExtraTokens_.push_back(consumes<reco::TrackExtraCollection>(tag));
16  }
17 
18  std::vector<edm::InputTag> trackExtraAssocTags = pset.getParameter<std::vector<edm::InputTag>>("trackExtraAssocs");
19  for (edm::InputTag const& tag : trackExtraAssocTags) {
21  }
22 
23  if (outputClusters_) {
25  consumes<edmNew::DetSetVector<SiPixelCluster>>(pset.getParameter<edm::InputTag>("pixelClusterTag"));
27  consumes<edmNew::DetSetVector<SiStripCluster>>(pset.getParameter<edm::InputTag>("stripClusterTag"));
28 
29  pixelClusterOutToken_ = produces<edmNew::DetSetVector<SiPixelCluster>>();
30  stripClusterOutToken_ = produces<edmNew::DetSetVector<SiStripCluster>>();
31  }
32 }
33 
36  desc.setComment(
37  "Produces reduced set of TrackExtras and corresponding TrackingRecHits and (optionally) Pixe/Strip clusters "
38  "associated to a muon track.");
39  desc.add<edm::InputTag>("muonTag", edm::InputTag("muons"));
40  desc.add<std::vector<edm::InputTag>>("trackExtraTags",
41  {edm::InputTag("generalTracks"),
42  edm::InputTag("globalMuons"),
43  edm::InputTag("tevMuons", "firstHit"),
44  edm::InputTag("tevMuons", "picky"),
45  edm::InputTag("tevMuons", "dyt")});
46  desc.add<std::vector<edm::InputTag>>("trackExtraAssocs", {});
47  desc.add<edm::InputTag>("pixelClusterTag", edm::InputTag("siPixelClusters"));
48  desc.add<edm::InputTag>("stripClusterTag", edm::InputTag("siStripClusters"));
49  desc.add<std::string>("cut", "pt > 3.0");
50  desc.add<bool>("outputClusters", true);
51  descriptions.add("muonReducedTrackExtras", desc);
52 }
53 
55  auto muons = event.getHandle(muonToken_);
56 
57  std::vector<edm::Handle<reco::TrackExtraCollection>> trackExtrasV(trackExtraTokens_.size());
58  for (unsigned int i = 0; i < trackExtraTokens_.size(); ++i) {
59  event.getByToken(trackExtraTokens_[i], trackExtrasV[i]);
60  }
61 
62  std::vector<edm::Handle<edm::Association<reco::TrackExtraCollection>>> trackExtraAssocs(trackExtraAssocs_.size());
63  for (unsigned int i = 0; i < trackExtraAssocs_.size(); ++i) {
64  event.getByToken(trackExtraAssocs_[i], trackExtraAssocs[i]);
65  }
66 
67  std::map<edm::ProductID, std::vector<bool>> idxstokeep;
68  for (auto const& trackExtras : trackExtrasV) {
69  idxstokeep[trackExtras.id()].resize(trackExtras->size(), false);
70  }
71 
72  //loop over muons and mark track extras to keep
73  for (auto const& muon : *muons) {
74  if (!selector_(muon)) {
75  continue;
76  }
77  reco::TrackExtraRef trackExtra = muon.bestTrack()->extra();
78  // check recursively through association maps if present
79  for (auto const& assoc : trackExtraAssocs) {
80  if (!assoc->contains(trackExtra.id())) {
81  continue;
82  }
83  reco::TrackExtraRef const& trackExtraOut = (*assoc)[trackExtra];
84  if (trackExtraOut.isNonnull()) {
85  trackExtra = trackExtraOut;
86  }
87  }
88  auto idxs = idxstokeep.find(trackExtra.id());
89  if (idxs != idxstokeep.end()) {
90  idxs->second[trackExtra.key()] = true;
91  }
92  }
93 
94  //output collections for TrackExtras and TrackingRecHits and the association map
95  reco::TrackExtraCollection trackExtrasOut;
96  TrackingRecHitCollection trackingRecHitsOut;
99 
100  //refprod for the output TrackExtraCollection
101  edm::RefProd<reco::TrackExtraCollection> trackExtraRefProd = event.getRefBeforePut(trackExtraOutToken_);
102  //refprod for the output TrackingRecHitCollection
103  edm::RefProd<TrackingRecHitCollection> hitRefProd = event.getRefBeforePut(trackingRecHitsOutToken_);
104 
105  association.setRef(trackExtraRefProd);
106 
109 
110  //indexes of pixel/strip clusters to keep
111  std::vector<bool> pixelClustersToKeep;
112  std::vector<bool> stripClustersToKeep;
113 
114  if (outputClusters_) {
115  event.getByToken(pixelClusterToken_, pixelClusters);
116  event.getByToken(stripClusterToken_, stripClusters);
117 
118  pixelClustersToKeep.resize(pixelClusters->dataSize(), false);
119  stripClustersToKeep.resize(stripClusters->dataSize(), false);
120  }
121 
124 
125  //loop over track extras and fill output together with TrackingRechits
126  //as well as marking pixel and strip clusters to keep
127  for (auto const& trackExtras : trackExtrasV) {
128  const std::vector<bool>& idxs = idxstokeep.at(trackExtras.id());
129  //indices for association (-1 for null association)
130  std::vector<int> associdxs(trackExtras->size(), -1);
131  for (unsigned int i = 0; i < trackExtras->size(); ++i) {
132  if (!idxs[i]) {
133  continue;
134  }
135  const reco::TrackExtra& trackExtra = (*trackExtras)[i];
136 
137  //fill association idx
138  associdxs[i] = trackExtrasOut.size();
139 
140  //fill TrackExtra
141  trackExtrasOut.emplace_back(trackExtra.outerPosition(),
142  trackExtra.outerMomentum(),
143  trackExtra.outerOk(),
144  trackExtra.innerPosition(),
145  trackExtra.innerMomentum(),
146  trackExtra.innerOk(),
147  trackExtra.outerStateCovariance(),
148  trackExtra.outerDetId(),
149  trackExtra.innerStateCovariance(),
150  trackExtra.innerDetId(),
151  trackExtra.seedDirection(),
152  trackExtra.seedRef());
153 
154  //rekey refs to TrackingRecHits
155  reco::TrackExtra& trackExtraOut = trackExtrasOut.back();
156  trackExtraOut.setHits(hitRefProd, trackingRecHitsOut.size(), trackExtra.recHitsSize());
157  for (auto const& hit : trackExtra.recHits()) {
158  if (outputClusters_) {
159  //mark clusters to keep
160  TrackerSingleRecHit const* singleHit = dynamic_cast<TrackerSingleRecHit const*>(&*hit);
161  if (singleHit != nullptr) {
162  SiPixelClusterRef const& pixelRef = singleHit->cluster_pixel();
163  if (pixelRef.isNonnull() && pixelRef.id() == pixelClusters.id()) {
164  pixelClustersToKeep[pixelRef.key()] = true;
165  }
166  SiStripClusterRef const& stripRef = singleHit->cluster_strip();
167  if (stripRef.isNonnull() && stripRef.id() == stripClusters.id()) {
168  stripClustersToKeep[stripRef.key()] = true;
169  }
170  SiStripMatchedRecHit2D const* matched2DHit = dynamic_cast<SiStripMatchedRecHit2D const*>(singleHit);
171  if (matched2DHit != nullptr) {
172  SiStripClusterRef const& monoRef = matched2DHit->monoClusterRef().cluster_strip();
173  SiStripClusterRef const& stereoRef = matched2DHit->stereoClusterRef().cluster_strip();
174  if (monoRef.isNonnull() && monoRef.id() == stripClusters.id()) {
175  stripClustersToKeep[monoRef.key()] = true;
176  }
177  if (stereoRef.isNonnull() && stereoRef.id() == stripClusters.id()) {
178  stripClustersToKeep[stereoRef.key()] = true;
179  }
180  }
181  }
182  }
183  //fill output hit
184  trackingRecHitsOut.push_back(hit->clone());
185  }
186  }
187  assocfiller.insert(trackExtras, associdxs.begin(), associdxs.end());
188  }
189 
190  assocfiller.fill();
191 
192  if (outputClusters_) {
193  //output collections for clusters
194  edmNew::DetSetVector<SiPixelCluster> pixelClustersOut;
195  edmNew::DetSetVector<SiStripCluster> stripClustersOut;
196  //mapping of indices from input to output collections
197  std::unordered_map<unsigned int, unsigned int> pixelClusterIdxMap;
198  std::unordered_map<unsigned int, unsigned int> stripClusterIdxMap;
199 
200  //fill output clusters
201  //this indexes the internal data array of the DetSetVector
202  unsigned int iIndex = 0;
203  //loop over edmNew:::DetSet<T>
204  for (auto setIter = pixelClusters->begin(), setIterEnd = pixelClusters->end(); setIter != setIterEnd; ++setIter) {
205  //fill items from this DetSet
206  typename edmNew::DetSetVector<SiPixelCluster>::FastFiller ff(pixelClustersOut, setIter->detId());
207  for (auto iter = setIter->begin(), iterEnd = setIter->end(); iter != iterEnd; ++iter, ++iIndex) {
208  if (pixelClustersToKeep[iIndex]) {
209  ff.push_back(*iter);
210  const unsigned int oIndex = pixelClusterIdxMap.size();
211  pixelClusterIdxMap[iIndex] = oIndex;
212  }
213  }
214  }
215 
216  iIndex = 0;
217  for (auto setIter = stripClusters->begin(), setIterEnd = stripClusters->end(); setIter != setIterEnd; ++setIter) {
218  //fill items from this DetSet
219  typename edmNew::DetSetVector<SiStripCluster>::FastFiller ff(stripClustersOut, setIter->detId());
220  for (auto iter = setIter->begin(), iterEnd = setIter->end(); iter != iterEnd; ++iter, ++iIndex) {
221  if (stripClustersToKeep[iIndex]) {
222  ff.push_back(*iter);
223  const unsigned int oIndex = stripClusterIdxMap.size();
224  stripClusterIdxMap[iIndex] = oIndex;
225  }
226  }
227  }
228 
230  event.emplace(pixelClusterOutToken_, std::move(pixelClustersOut));
232  event.emplace(stripClusterOutToken_, std::move(stripClustersOut));
233 
234  //rekey cluster references in output hit collection
235  for (auto& hit : trackingRecHitsOut) {
236  TrackerSingleRecHit* singleHit = dynamic_cast<TrackerSingleRecHit*>(&hit);
237  if (singleHit != nullptr) {
238  SiPixelClusterRef const& pixelRef = singleHit->cluster_pixel();
239  if (pixelRef.isNonnull() && pixelRef.id() == pixelClusters.id()) {
240  SiPixelClusterRef const pixelRefOut(pixelClustersOutH, pixelClusterIdxMap.at(pixelRef.key()));
241  singleHit->setClusterPixelRef(pixelRefOut);
242  }
243  SiStripClusterRef const& stripRef = singleHit->cluster_strip();
244  if (stripRef.isNonnull() && stripRef.id() == stripClusters.id()) {
245  SiStripClusterRef const stripRefOut(stripClustersOutH, stripClusterIdxMap.at(stripRef.key()));
246  singleHit->setClusterStripRef(stripRefOut);
247  }
248  SiStripMatchedRecHit2D* matched2DHit = dynamic_cast<SiStripMatchedRecHit2D*>(singleHit);
249  if (matched2DHit != nullptr) {
250  SiStripClusterRef const& monoRef = matched2DHit->monoClusterRef().cluster_strip();
251  SiStripClusterRef const& stereoRef = matched2DHit->stereoClusterRef().cluster_strip();
252  if (monoRef.isNonnull() && monoRef.id() == stripClusters.id()) {
253  SiStripClusterRef const monoRefOut(stripClustersOutH, stripClusterIdxMap.at(monoRef.key()));
254  matched2DHit->monoClusterRef() = OmniClusterRef(monoRefOut);
255  }
256  if (stereoRef.isNonnull() && stereoRef.id() == stripClusters.id()) {
257  SiStripClusterRef const stereoRefOut(stripClustersOutH, stripClusterIdxMap.at(stereoRef.key()));
258  matched2DHit->stereoClusterRef() = OmniClusterRef(stereoRefOut);
259  }
260  }
261  }
262  }
263  }
264 
265  event.emplace(trackExtraOutToken_, std::move(trackExtrasOut));
266  event.emplace(trackingRecHitsOutToken_, std::move(trackingRecHitsOut));
267  event.emplace(associationOutToken_, std::move(association));
268 }
edm::RefProd< reco::TrackExtraCollection >
MuonReducedTrackExtraProducer::trackExtraTokens_
std::vector< edm::EDGetTokenT< reco::TrackExtraCollection > > trackExtraTokens_
Definition: MuonReducedTrackExtraProducer.h:31
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
MuonReducedTrackExtraProducer::MuonReducedTrackExtraProducer
MuonReducedTrackExtraProducer(const edm::ParameterSet &)
Definition: MuonReducedTrackExtraProducer.cc:6
MuonReducedTrackExtraProducer::trackingRecHitsOutToken_
const edm::EDPutTokenT< TrackingRecHitCollection > trackingRecHitsOutToken_
Definition: MuonReducedTrackExtraProducer.h:38
electrons_cff.bool
bool
Definition: electrons_cff.py:366
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
mps_fire.i
i
Definition: mps_fire.py:428
Muon.h
edm::Association::Filler
Definition: Association.h:78
LumiMonitor_cff.pixelClusters
pixelClusters
Definition: LumiMonitor_cff.py:10
sistrip::View
View
Definition: ConstantsForView.h:26
muon
Definition: MuonCocktails.h:17
MuonReducedTrackExtraProducer::outputClusters_
const bool outputClusters_
Definition: MuonReducedTrackExtraProducer.h:35
MuonReducedTrackExtraProducer::pixelClusterToken_
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > pixelClusterToken_
Definition: MuonReducedTrackExtraProducer.h:33
reco::TrackExtra::innerOk
bool innerOk() const
returns true if the innermost hit is valid
Definition: TrackExtra.h:83
slimmedMuons_cfi.trackExtraAssocs
trackExtraAssocs
Definition: slimmedMuons_cfi.py:19
slimmedTrackExtras_cff.trackExtraTags
trackExtraTags
Definition: slimmedTrackExtras_cff.py:7
MuonReducedTrackExtraProducer::stripClusterToken_
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > stripClusterToken_
Definition: MuonReducedTrackExtraProducer.h:34
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
SiPixelCluster
Pixel cluster – collection of neighboring pixels above threshold.
Definition: SiPixelCluster.h:28
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::Handle
Definition: AssociativeIterator.h:50
OmniClusterRef
Definition: OmniClusterRef.h:12
MuonReducedTrackExtraProducer::selector_
const StringCutObjectSelector< reco::Muon > selector_
Definition: MuonReducedTrackExtraProducer.h:36
reco::TrackExtra::outerMomentum
const Vector & outerMomentum() const
momentum vector at outermost hit position
Definition: TrackExtra.h:75
Muon
Definition: Muon.py:1
reco::TrackExtra::outerStateCovariance
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: TrackExtra.cc:41
edm::Ref< TrackExtraCollection >
trackingPlots.assoc
assoc
Definition: trackingPlots.py:183
MuonReducedTrackExtraProducer::associationOutToken_
const edm::EDPutTokenT< edm::Association< reco::TrackExtraCollection > > associationOutToken_
Definition: MuonReducedTrackExtraProducer.h:41
reco::TrackExtra
Definition: TrackExtra.h:26
reco::TrackExtra::outerDetId
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: TrackExtra.h:118
reco::TrackExtra::seedDirection
const PropagationDirection & seedDirection() const
Definition: TrackExtra.h:122
OmniClusterRef::cluster_strip
ClusterStripRef cluster_strip() const
Definition: OmniClusterRef.h:44
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
reco::TrackExtra::innerDetId
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: TrackExtra.h:120
alignCSCRings.ff
ff
Definition: alignCSCRings.py:148
reco::TrackExtra::innerMomentum
const Vector & innerMomentum() const
momentum vector at innermost hit position
Definition: TrackExtra.h:81
reco::TrackExtraCollection
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
TrackerSingleRecHit::cluster_pixel
ClusterPixelRef cluster_pixel() const
Definition: TrackerSingleRecHit.h:47
MuonReducedTrackExtraProducer::pixelClusterOutToken_
edm::EDPutTokenT< edmNew::DetSetVector< SiPixelCluster > > pixelClusterOutToken_
Definition: MuonReducedTrackExtraProducer.h:39
TrackerSingleRecHit::cluster_strip
ClusterStripRef cluster_strip() const
Definition: TrackerSingleRecHit.h:49
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HLT_FULL_cff.stripClusters
stripClusters
Definition: HLT_FULL_cff.py:10026
edm::ParameterSet
Definition: ParameterSet.h:47
reco::TrackExtra::innerStateCovariance
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: TrackExtra.cc:47
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
reco::TrackExtra::outerOk
bool outerOk() const
returns true if the outermost hit is valid
Definition: TrackExtra.h:77
SiStripMatchedRecHit2D::stereoClusterRef
OmniClusterRef const & stereoClusterRef() const
Definition: SiStripMatchedRecHit2D.h:34
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
reco::TrackExtra::outerPosition
const Point & outerPosition() const
outermost hit position
Definition: TrackExtra.h:73
MuonReducedTrackExtraProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MuonReducedTrackExtraProducer.cc:54
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:58
MuonReducedTrackExtraProducer::trackExtraAssocs_
std::vector< edm::EDGetTokenT< edm::Association< reco::TrackExtraCollection > > > trackExtraAssocs_
Definition: MuonReducedTrackExtraProducer.h:32
SiStripMatchedRecHit2D::monoClusterRef
OmniClusterRef const & monoClusterRef() const
Definition: SiStripMatchedRecHit2D.h:35
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::TrackExtraBase::setHits
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
Definition: TrackExtraBase.h:30
reco::TrackExtraBase::recHitsSize
unsigned int recHitsSize() const
number of RecHits
Definition: TrackExtraBase.h:44
edmNew::DetSetVector
Definition: DetSetNew.h:13
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
MuonReducedTrackExtraProducer::muonToken_
const edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
Definition: MuonReducedTrackExtraProducer.h:30
std
Definition: JetResolutionObject.h:76
edm::OrphanHandle
Definition: EDProductfwd.h:39
SiStripMatchedRecHit2D
Definition: SiStripMatchedRecHit2D.h:8
TrackerSingleRecHit::setClusterStripRef
void setClusterStripRef(ClusterStripRef const &ref)
Definition: TrackerSingleRecHit.h:65
TrackerSingleRecHit::setClusterPixelRef
void setClusterPixelRef(ClusterPixelRef const &ref)
Definition: TrackerSingleRecHit.h:64
TrackerSingleRecHit
Definition: TrackerSingleRecHit.h:11
hgcal::association
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
Definition: LCToCPAssociatorByEnergyScoreImpl.h:44
edm::OwnVector::push_back
void push_back(D *&d)
Definition: OwnVector.h:326
MuonReducedTrackExtraProducer::trackExtraOutToken_
const edm::EDPutTokenT< reco::TrackExtraCollection > trackExtraOutToken_
Definition: MuonReducedTrackExtraProducer.h:37
edmNew::DetSetVector::FastFiller
Definition: DetSetVectorNew.h:202
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
reco::TrackExtra::seedRef
const edm::RefToBase< TrajectorySeed > & seedRef() const
Definition: TrackExtra.h:129
TrackerSingleRecHit.h
SiStripMatchedRecHit2D.h
event
Definition: event.py:1
MuonReducedTrackExtraProducer.h
edm::Event
Definition: Event.h:73
MuonReducedTrackExtraProducer::stripClusterOutToken_
edm::EDPutTokenT< edmNew::DetSetVector< SiStripCluster > > stripClusterOutToken_
Definition: MuonReducedTrackExtraProducer.h:40
SiStripCluster
Definition: SiStripCluster.h:8
reco::TrackExtra::innerPosition
const Point & innerPosition() const
innermost hit position
Definition: TrackExtra.h:79
edm::OwnVector::size
size_type size() const
Definition: OwnVector.h:300
edm::InputTag
Definition: InputTag.h:15
reco::TrackExtraBase::recHits
auto recHits() const
accessor to RecHits
Definition: TrackExtraBase.h:47
hit
Definition: SiStripHitEffFromCalibTree.cc:88
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::OwnVector< TrackingRecHit >
MuonReducedTrackExtraProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: MuonReducedTrackExtraProducer.cc:34