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 
36 
37 #include <unordered_set>
38 
39 namespace {
40 
41  template <typename T>
42  std::vector<edm::DetSet<T>> pruneByTpAssoc(const edm::DetSetVector<T>& simLinkColl,
43  const std::set<std::pair<uint32_t, EncodedEventId>>& selectedIds) {
44  std::vector<edm::DetSet<T>> linkVector;
45 
46  for (auto&& detSet : simLinkColl) {
47  edm::DetSet<T> newDetSet(detSet.detId());
48 
49  for (auto&& simLink : detSet) {
50  std::pair<uint32_t, EncodedEventId> trkid(simLink.SimTrackId(), simLink.eventId());
51  if (selectedIds.count(trkid) > 0) {
52  newDetSet.push_back(simLink);
53  }
54  }
55 
56  linkVector.push_back(std::move(newDetSet));
57  }
58 
59  return linkVector;
60  }
61 
62 } // namespace
63 
64 //
65 // class declaration
66 //
67 
69 public:
70  explicit DigiSimLinkPruner(const edm::ParameterSet&);
71 
72  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
73 
74 private:
75  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
76 
77  // ----------member data ---------------------------
82 };
83 
86  consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticles"))),
88  consumes<edm::DetSetVector<PixelDigiSimLink>>(iConfig.getParameter<edm::InputTag>("pixelSimLinkSrc"))) {
89  produces<edm::DetSetVector<PixelDigiSimLink>>("siPixel");
90 
91  if (iConfig.existsAs<edm::InputTag>("stripSimLinkSrc")) {
93  consumes<edm::DetSetVector<StripDigiSimLink>>(iConfig.getParameter<edm::InputTag>("stripSimLinkSrc"));
94  produces<edm::DetSetVector<StripDigiSimLink>>("siStrip");
95  }
96 
97  if (iConfig.existsAs<edm::InputTag>("phase2OTSimLinkSrc")) {
99  consumes<edm::DetSetVector<PixelDigiSimLink>>(iConfig.getParameter<edm::InputTag>("phase2OTSimLinkSrc"));
100  produces<edm::DetSetVector<PixelDigiSimLink>>("siphase2OT");
101  }
102 }
103 
104 // ------------ method called to produce the data ------------
106  using namespace edm;
107 
108  auto const& tpColl = iEvent.get(trackingParticleToken_);
109 
110  std::set<std::pair<uint32_t, EncodedEventId>> selectedIds;
111  for (TrackingParticleCollection::size_type itp = 0; itp < tpColl.size(); ++itp) {
112  auto const& trackingParticle = tpColl[itp];
113 
114  // SimTracks inside TrackingParticle
115 
116  EncodedEventId eid(trackingParticle.eventId());
117 
118  for (auto const& trk : trackingParticle.g4Tracks()) {
119  selectedIds.emplace(trk.trackId(), eid);
120  }
121  }
122 
123  auto const& sipixelLinkColl = iEvent.get(sipixelSimLinksToken_);
124 
125  auto sipixelLinkVector = pruneByTpAssoc(sipixelLinkColl, selectedIds);
126 
127  auto sipixelOut = std::make_unique<edm::DetSetVector<PixelDigiSimLink>>(sipixelLinkVector);
128  iEvent.put(std::move(sipixelOut), "siPixel");
129 
131  auto const& sistripLinkColl = iEvent.get(sistripSimLinksToken_);
132 
133  auto sistripLinkVector = pruneByTpAssoc(sistripLinkColl, selectedIds);
134 
135  auto sistripOut = std::make_unique<edm::DetSetVector<StripDigiSimLink>>(sistripLinkVector);
136  iEvent.put(std::move(sistripOut), "siStrip");
137  }
138 
140  auto const& siphase2OTLinkColl = iEvent.get(siphase2OTSimLinksToken_);
141 
142  auto siphase2OTLinkVector = pruneByTpAssoc(siphase2OTLinkColl, selectedIds);
143 
144  auto siphase2OTOut = std::make_unique<edm::DetSetVector<PixelDigiSimLink>>(siphase2OTLinkVector);
145  iEvent.put(std::move(siphase2OTOut), "siphase2OT");
146  }
147 }
148 
149 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
152  desc.add<edm::InputTag>("trackingParticles");
153  desc.add<edm::InputTag>("pixelSimLinkSrc", edm::InputTag("simSiPixelDigis"));
154  desc.addOptional<edm::InputTag>("stripSimLinkSrc");
155  desc.addOptional<edm::InputTag>("phase2OTSimLinkSrc");
156 
157  descriptions.add("digiSimLinkPrunerDefault", desc);
158 }
159 
160 //define this as a plug-in
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
void push_back(const T &t)
Definition: DetSet.h:68
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:161
std::vector< TrackingParticle > TrackingParticleCollection
uint16_t size_type
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > siphase2OTSimLinksToken_
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:326
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
HLT enums.
bool isUninitialized() const
Definition: EDGetToken.h:70
def move(src, dest)
Definition: eostools.py:511