CMS 3D CMS Logo

DigiSimLinkPruner.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SimTracker/TrackAssociation
4 // Class: DigiSimLinkPruner
5 //
13 //
14 // Original Author: Enrico Lusiani
15 // Created: Fri, 14 May 2021 08:46:10 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
37 
38 #include <unordered_set>
39 
40 namespace {
41 
42  template <typename T>
43  std::vector<edm::DetSet<T>> pruneByTpAssoc(
44  const edm::DetSetVector<T>& simLinkColl,
45  const std::unordered_set<UniqueSimTrackId, UniqueSimTrackIdHash>& selectedIds) {
46  std::vector<edm::DetSet<T>> linkVector;
47 
48  for (auto&& detSet : simLinkColl) {
49  edm::DetSet<T> newDetSet(detSet.detId());
50 
51  for (auto&& simLink : detSet) {
52  UniqueSimTrackId trkid(simLink.SimTrackId(), simLink.eventId());
53  if (selectedIds.count(trkid) > 0) {
54  newDetSet.push_back(simLink);
55  }
56  }
57 
58  linkVector.push_back(std::move(newDetSet));
59  }
60 
61  return linkVector;
62  }
63 
64 } // namespace
65 
66 //
67 // class declaration
68 //
69 
71 public:
72  explicit DigiSimLinkPruner(const edm::ParameterSet&);
73 
74  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
75 
76 private:
77  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
78 
79  // ----------member data ---------------------------
84 };
85 
87  : trackingParticleToken_(
88  consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticles"))),
89  sipixelSimLinksToken_(
90  consumes<edm::DetSetVector<PixelDigiSimLink>>(iConfig.getParameter<edm::InputTag>("pixelSimLinkSrc"))) {
91  produces<edm::DetSetVector<PixelDigiSimLink>>("siPixel");
92 
93  if (iConfig.existsAs<edm::InputTag>("stripSimLinkSrc")) {
95  consumes<edm::DetSetVector<StripDigiSimLink>>(iConfig.getParameter<edm::InputTag>("stripSimLinkSrc"));
96  produces<edm::DetSetVector<StripDigiSimLink>>("siStrip");
97  }
98 
99  if (iConfig.existsAs<edm::InputTag>("phase2OTSimLinkSrc")) {
101  consumes<edm::DetSetVector<PixelDigiSimLink>>(iConfig.getParameter<edm::InputTag>("phase2OTSimLinkSrc"));
102  produces<edm::DetSetVector<PixelDigiSimLink>>("siphase2OT");
103  }
104 }
105 
106 // ------------ method called to produce the data ------------
108  using namespace edm;
109 
110  auto const& tpColl = iEvent.get(trackingParticleToken_);
111 
112  std::unordered_set<UniqueSimTrackId, UniqueSimTrackIdHash> selectedIds;
113  for (TrackingParticleCollection::size_type itp = 0; itp < tpColl.size(); ++itp) {
114  auto const& trackingParticle = tpColl[itp];
115 
116  // SimTracks inside TrackingParticle
117 
118  EncodedEventId eid(trackingParticle.eventId());
119 
120  for (auto const& trk : trackingParticle.g4Tracks()) {
121  selectedIds.emplace(trk.trackId(), eid);
122  }
123  }
124 
125  auto const& sipixelLinkColl = iEvent.get(sipixelSimLinksToken_);
126 
127  auto sipixelLinkVector = pruneByTpAssoc(sipixelLinkColl, selectedIds);
128 
129  auto sipixelOut = std::make_unique<edm::DetSetVector<PixelDigiSimLink>>(sipixelLinkVector);
130  iEvent.put(std::move(sipixelOut), "siPixel");
131 
133  auto const& sistripLinkColl = iEvent.get(sistripSimLinksToken_);
134 
135  auto sistripLinkVector = pruneByTpAssoc(sistripLinkColl, selectedIds);
136 
137  auto sistripOut = std::make_unique<edm::DetSetVector<StripDigiSimLink>>(sistripLinkVector);
138  iEvent.put(std::move(sistripOut), "siStrip");
139  }
140 
142  auto const& siphase2OTLinkColl = iEvent.get(siphase2OTSimLinksToken_);
143 
144  auto siphase2OTLinkVector = pruneByTpAssoc(siphase2OTLinkColl, selectedIds);
145 
146  auto siphase2OTOut = std::make_unique<edm::DetSetVector<PixelDigiSimLink>>(siphase2OTLinkVector);
147  iEvent.put(std::move(siphase2OTOut), "siphase2OT");
148  }
149 }
150 
151 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
154  desc.add<edm::InputTag>("trackingParticles");
155  desc.add<edm::InputTag>("pixelSimLinkSrc", edm::InputTag("simSiPixelDigis"));
156  desc.addOptional<edm::InputTag>("stripSimLinkSrc");
157  desc.addOptional<edm::InputTag>("phase2OTSimLinkSrc");
158 
159  descriptions.add("digiSimLinkPrunerDefault", desc);
160 }
161 
162 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void push_back(const T &t)
Definition: DetSet.h:66
std::pair< uint32_t, EncodedEventId > UniqueSimTrackId
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
uint16_t size_type
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > siphase2OTSimLinksToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::DetSetVector< StripDigiSimLink > > sistripSimLinksToken_
DigiSimLinkPruner(const edm::ParameterSet &)
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > sipixelSimLinksToken_
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HLT enums.
std::vector< TrackingParticle > TrackingParticleCollection
def move(src, dest)
Definition: eostools.py:511