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
edm::DetSet::push_back
void push_back(const T &t)
Definition: DetSet.h:66
edm::DetSetVector
Definition: DetSetVector.h:61
edm::StreamID
Definition: StreamID.h:30
edm::DetSet
Definition: DetSet.h:23
edm::EDGetTokenT< TrackingParticleCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
UniqueSimTrackId
std::pair< uint32_t, EncodedEventId > UniqueSimTrackId
Definition: UniqueSimTrackId.h:9
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
EncodedEventId
Definition: EncodedEventId.h:11
MakerMacros.h
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
DigiSimLinkPruner::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: DigiSimLinkPruner.cc:107
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
DigiSimLinkPruner::sistripSimLinksToken_
edm::EDGetTokenT< edm::DetSetVector< StripDigiSimLink > > sistripSimLinksToken_
Definition: DigiSimLinkPruner.cc:82
DigiSimLinkPruner::DigiSimLinkPruner
DigiSimLinkPruner(const edm::ParameterSet &)
Definition: DigiSimLinkPruner.cc:86
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
DigiSimLinkPruner::sipixelSimLinksToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > sipixelSimLinksToken_
Definition: DigiSimLinkPruner.cc:81
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
runTauDisplay.eid
eid
Definition: runTauDisplay.py:298
DigiSimLinkPruner::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: DigiSimLinkPruner.cc:152
edm::EventSetup
Definition: EventSetup.h:58
DetSetVector.h
DigiSimLinkPruner::siphase2OTSimLinksToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > siphase2OTSimLinksToken_
Definition: DigiSimLinkPruner.cc:83
TrackingParticle.h
UniqueSimTrackId.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
DigiSimLinkPruner::trackingParticleToken_
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleToken_
Definition: DigiSimLinkPruner.cc:80
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:9
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
StreamID.h
edm::InputTag
Definition: InputTag.h:15
DigiSimLinkPruner
Definition: DigiSimLinkPruner.cc:70