CMS 3D CMS Logo

PreMixingTrackingParticleWorker.cc
Go to the documentation of this file.
7 
11 
14 
16 public:
18  ~PreMixingTrackingParticleWorker() override = default;
19 
20  void initializeEvent(edm::Event const &iEvent, edm::EventSetup const &iSetup) override;
21  void addSignals(edm::Event const &iEvent, edm::EventSetup const &iSetup) override;
22  void addPileups(PileUpEventPrincipal const &pep, edm::EventSetup const &iSetup) override;
23  void put(edm::Event &iEvent,
24  edm::EventSetup const &iSetup,
25  std::vector<PileupSummaryInfo> const &ps,
26  int bunchSpacing) override;
27 
28 private:
29  void add(const std::vector<TrackingParticle> &particles, const std::vector<TrackingVertex> &vertices);
30 
33 
34  edm::InputTag TrackingParticlePileInputTag_; // InputTag for pileup tracks
35 
36  std::string TrackingParticleCollectionDM_; // secondary name to be given to
37  // new TrackingParticle
38 
39  std::unique_ptr<std::vector<TrackingParticle>> NewTrackList_;
40  std::unique_ptr<std::vector<TrackingVertex>> NewVertexList_;
43 };
44 
46  edm::ProducesCollector producesCollector,
48  : TrackSigToken_(iC.consumes<std::vector<TrackingParticle>>(ps.getParameter<edm::InputTag>("labelSig"))),
49  VtxSigToken_(iC.consumes<std::vector<TrackingVertex>>(ps.getParameter<edm::InputTag>("labelSig"))),
50  TrackingParticlePileInputTag_(ps.getParameter<edm::InputTag>("pileInputTag")),
51  TrackingParticleCollectionDM_(ps.getParameter<std::string>("collectionDM")) {
52  producesCollector.produces<std::vector<TrackingParticle>>(TrackingParticleCollectionDM_);
53  producesCollector.produces<std::vector<TrackingVertex>>(TrackingParticleCollectionDM_);
54 }
55 
57  NewTrackList_ = std::make_unique<std::vector<TrackingParticle>>();
58  NewVertexList_ = std::make_unique<std::vector<TrackingVertex>>();
59 
60  // need RefProds in order to re-key the particle<->vertex refs
61  // TODO: try to remove const_cast, requires making Event non-const in
62  // BMixingModule::initializeEvent
64  const_cast<edm::Event &>(iEvent).getRefBeforePut<std::vector<TrackingParticle>>(TrackingParticleCollectionDM_);
66  const_cast<edm::Event &>(iEvent).getRefBeforePut<std::vector<TrackingVertex>>(TrackingParticleCollectionDM_);
67 }
68 
71  iEvent.getByToken(TrackSigToken_, tracks);
72 
74  iEvent.getByToken(VtxSigToken_, vtxs);
75 
76  if (tracks.isValid() && vtxs.isValid()) {
77  add(*tracks, *vtxs);
78  }
79 }
80 
82  LogDebug("PreMixingTrackingParticleWorker") << "\n===============> adding pileups from event "
83  << pep.principal().id() << " for bunchcrossing " << pep.bunchCrossing();
84 
86  pep.getByLabel(TrackingParticlePileInputTag_, inputHandle);
87 
89  pep.getByLabel(TrackingParticlePileInputTag_, inputVHandle);
90 
91  if (inputHandle.isValid() && inputVHandle.isValid()) {
92  add(*inputHandle, *inputVHandle);
93  }
94 }
95 
96 void PreMixingTrackingParticleWorker::add(const std::vector<TrackingParticle> &particles,
97  const std::vector<TrackingVertex> &vertices) {
98  const size_t StartingIndexV = NewVertexList_->size();
99  const size_t StartingIndexT = NewTrackList_->size();
100 
101  // grab Vertices, store copy, preserving indices. Easier to loop over
102  // vertices first - fewer links
103  for (const auto &vtx : vertices) {
104  NewVertexList_->push_back(vtx);
105  }
106 
107  // grab tracks, store copy
108  for (const auto &track : particles) {
109  const auto &oldRef = track.parentVertex();
110  auto newRef = TrackingVertexRef(VertexListRef_, oldRef.index() + StartingIndexV);
111  NewTrackList_->push_back(track);
112 
113  auto &Ntrack = NewTrackList_->back(); // modify copy
114 
115  Ntrack.setParentVertex(newRef);
116  Ntrack.clearDecayVertices();
117 
118  // next, loop over daughter vertices, same strategy
119  for (auto const &vertexRef : track.decayVertices()) {
120  auto newRef = TrackingVertexRef(VertexListRef_, vertexRef.index() + StartingIndexV);
121  Ntrack.addDecayVertex(newRef);
122  }
123  }
124 
125  // Now that tracks are handled, go back and put correct Refs in vertices
126  // Operate only on the added pileup vertices, and leave the already-existing
127  // vertices untouched
128  std::vector<decltype(TrackingParticleRef().index())> sourceTrackIndices;
129  std::vector<decltype(TrackingParticleRef().index())> daughterTrackIndices;
130  for (size_t iVertex = StartingIndexV; iVertex != NewVertexList_->size(); ++iVertex) {
131  auto &vertex = (*NewVertexList_)[iVertex];
132 
133  // Need to copy the indices before clearing the vectors
134  sourceTrackIndices.reserve(vertex.sourceTracks().size());
135  daughterTrackIndices.reserve(vertex.daughterTracks().size());
136  for (auto const &ref : vertex.sourceTracks())
137  sourceTrackIndices.push_back(ref.index());
138  for (auto const &ref : vertex.daughterTracks())
139  daughterTrackIndices.push_back(ref.index());
140 
141  vertex.clearParentTracks();
142  vertex.clearDaughterTracks();
143 
144  for (auto index : sourceTrackIndices) {
145  auto newRef = TrackingParticleRef(TrackListRef_, index + StartingIndexT);
146  vertex.addParentTrack(newRef);
147  }
148 
149  // next, loop over daughter tracks, same strategy
150  for (auto index : daughterTrackIndices) {
151  auto newRef = TrackingParticleRef(TrackListRef_, index + StartingIndexT);
152  vertex.addDaughterTrack(newRef);
153  }
154 
155  sourceTrackIndices.clear();
156  daughterTrackIndices.clear();
157  }
158 }
159 
161  edm::EventSetup const &iSetup,
162  std::vector<PileupSummaryInfo> const &ps,
163  int bunchSpacing) {
164  edm::LogInfo("PreMixingTrackingParticleWorker") << "total # Merged Tracks: " << NewTrackList_->size();
167 }
168 
edm::RefProd< TrackingParticleCollection >
PreMixingTrackingParticleWorker::initializeEvent
void initializeEvent(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: PreMixingTrackingParticleWorker.cc:56
PreMixingTrackingParticleWorker::TrackSigToken_
edm::EDGetTokenT< std::vector< TrackingParticle > > TrackSigToken_
Definition: PreMixingTrackingParticleWorker.cc:31
Handle.h
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
MessageLogger.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
PreMixingTrackingParticleWorker::NewTrackList_
std::unique_ptr< std::vector< TrackingParticle > > NewTrackList_
Definition: PreMixingTrackingParticleWorker.cc:39
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
PileUpEventPrincipal::bunchCrossing
int bunchCrossing() const
Definition: PileUpEventPrincipal.h:30
TrackingVertex.h
PileUpEventPrincipal
Definition: PileUpEventPrincipal.h:19
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
PreMixingTrackingParticleWorker
Definition: PreMixingTrackingParticleWorker.cc:15
edm::Handle
Definition: AssociativeIterator.h:50
edm::EventPrincipal::id
EventID const & id() const
Definition: EventPrincipal.h:92
PreMixingTrackingParticleWorker::TrackListRef_
TrackingParticleRefProd TrackListRef_
Definition: PreMixingTrackingParticleWorker.cc:41
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
PreMixingTrackingParticleWorker::VtxSigToken_
edm::EDGetTokenT< std::vector< TrackingVertex > > VtxSigToken_
Definition: PreMixingTrackingParticleWorker.cc:32
ProducesCollector.h
PreMixingTrackingParticleWorker::put
void put(edm::Event &iEvent, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > const &ps, int bunchSpacing) override
Definition: PreMixingTrackingParticleWorker.cc:160
HLTEgPhaseIITestSequence_cff.bunchSpacing
bunchSpacing
Definition: HLTEgPhaseIITestSequence_cff.py:1574
PreMixingWorker.h
TrackingParticle
Monte Carlo truth information used for tracking validation.
Definition: TrackingParticle.h:29
PileUpEventPrincipal::principal
edm::EventPrincipal const & principal()
Definition: PileUpEventPrincipal.h:24
TrackingVertexRef
edm::Ref< TrackingVertexCollection > TrackingVertexRef
Definition: TrackingVertexContainer.h:9
PileUpEventPrincipal.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:159
TrackingVertex
Definition: TrackingVertex.h:22
PreMixingTrackingParticleWorker::addSignals
void addSignals(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: PreMixingTrackingParticleWorker.cc:69
PreMixingTrackingParticleWorker::TrackingParticleCollectionDM_
std::string TrackingParticleCollectionDM_
Definition: PreMixingTrackingParticleWorker.cc:36
iEvent
int iEvent
Definition: GenABIO.cc:224
PreMixingTrackingParticleWorker::NewVertexList_
std::unique_ptr< std::vector< TrackingVertex > > NewVertexList_
Definition: PreMixingTrackingParticleWorker.cc:40
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::ProducesCollector::produces
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
Definition: ProducesCollector.h:52
PreMixingTrackingParticleWorker::TrackingParticlePileInputTag_
edm::InputTag TrackingParticlePileInputTag_
Definition: PreMixingTrackingParticleWorker.cc:34
PreMixingTrackingParticleWorker::add
void add(const std::vector< TrackingParticle > &particles, const std::vector< TrackingVertex > &vertices)
Definition: PreMixingTrackingParticleWorker.cc:96
edm::EventSetup
Definition: EventSetup.h:58
PreMixingTrackingParticleWorker::~PreMixingTrackingParticleWorker
~PreMixingTrackingParticleWorker() override=default
PreMixingWorkerFactory.h
TrackingParticle.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ProducesCollector
Definition: ProducesCollector.h:43
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:18
PreMixingTrackingParticleWorker::addPileups
void addPileups(PileUpEventPrincipal const &pep, edm::EventSetup const &iSetup) override
Definition: PreMixingTrackingParticleWorker.cc:81
DEFINE_PREMIXING_WORKER
#define DEFINE_PREMIXING_WORKER(TYPE)
Definition: PreMixingWorkerFactory.h:16
PreMixingTrackingParticleWorker::VertexListRef_
TrackingVertexRefProd VertexListRef_
Definition: PreMixingTrackingParticleWorker.cc:42
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
PreMixingWorker
Definition: PreMixingWorker.h:14
ConsumesCollector.h
ParameterSet.h
PileUpEventPrincipal::getByLabel
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
Definition: PileUpEventPrincipal.h:33
TrackingParticleRef
edm::Ref< TrackingParticleCollection > TrackingParticleRef
Definition: TrackingParticleFwd.h:12
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
PreMixingTrackingParticleWorker::PreMixingTrackingParticleWorker
PreMixingTrackingParticleWorker(const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &&iC)
Definition: PreMixingTrackingParticleWorker.cc:45
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7