CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
PreMixingTrackingParticleWorker Class Reference
Inheritance diagram for PreMixingTrackingParticleWorker:
PreMixingWorker

Public Member Functions

void addPileups (PileUpEventPrincipal const &pep, edm::EventSetup const &iSetup) override
 
void addSignals (edm::Event const &iEvent, edm::EventSetup const &iSetup) override
 
void initializeEvent (edm::Event const &iEvent, edm::EventSetup const &iSetup) override
 
 PreMixingTrackingParticleWorker (const edm::ParameterSet &ps, edm::ProducerBase &producer, edm::ConsumesCollector &&iC)
 
void put (edm::Event &iEvent, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > const &ps, int bunchSpacing) override
 
 ~PreMixingTrackingParticleWorker () override=default
 
- Public Member Functions inherited from PreMixingWorker
virtual void beginLuminosityBlock (edm::LuminosityBlock const &iLumi, edm::EventSetup const &iSetup)
 
virtual void beginRun (edm::Run const &iRun, edm::EventSetup const &iSetup)
 
virtual void endRun ()
 
virtual void finalizeBunchCrossing (edm::Event &iEvent, edm::EventSetup const &iSetup, int bunchCrossing)
 
virtual void initializeBunchCrossing (edm::Event const &iEvent, edm::EventSetup const &iSetup, int bunchCrossing)
 
 PreMixingWorker ()=default
 
virtual ~PreMixingWorker ()=default
 

Private Member Functions

void add (const std::vector< TrackingParticle > &particles, const std::vector< TrackingVertex > &vertices)
 

Private Attributes

std::unique_ptr< std::vector< TrackingParticle > > NewTrackList_
 
std::unique_ptr< std::vector< TrackingVertex > > NewVertexList_
 
std::string TrackingParticleCollectionDM_
 
edm::InputTag TrackingParticlePileInputTag_
 
TrackingParticleRefProd TrackListRef_
 
edm::EDGetTokenT< std::vector< TrackingParticle > > TrackSigToken_
 
TrackingVertexRefProd VertexListRef_
 
edm::EDGetTokenT< std::vector< TrackingVertex > > VtxSigToken_
 

Detailed Description

Definition at line 15 of file PreMixingTrackingParticleWorker.cc.

Constructor & Destructor Documentation

PreMixingTrackingParticleWorker::PreMixingTrackingParticleWorker ( const edm::ParameterSet ps,
edm::ProducerBase producer,
edm::ConsumesCollector &&  iC 
)

Definition at line 47 of file PreMixingTrackingParticleWorker.cc.

References edm::ProductRegistryHelper::produces(), and TrackingParticleCollectionDM_.

50  : TrackSigToken_(iC.consumes<std::vector<TrackingParticle>>(ps.getParameter<edm::InputTag>("labelSig"))),
51  VtxSigToken_(iC.consumes<std::vector<TrackingVertex>>(ps.getParameter<edm::InputTag>("labelSig"))),
54  producer.produces<std::vector<TrackingParticle>>(TrackingParticleCollectionDM_);
55  producer.produces<std::vector<TrackingVertex>>(TrackingParticleCollectionDM_);
56 }
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
edm::EDGetTokenT< std::vector< TrackingParticle > > TrackSigToken_
edm::EDGetTokenT< std::vector< TrackingVertex > > VtxSigToken_
PreMixingTrackingParticleWorker::~PreMixingTrackingParticleWorker ( )
overridedefault

Member Function Documentation

void PreMixingTrackingParticleWorker::add ( const std::vector< TrackingParticle > &  particles,
const std::vector< TrackingVertex > &  vertices 
)
private

Definition at line 98 of file PreMixingTrackingParticleWorker.cc.

References NewTrackList_, NewVertexList_, HiIsolationCommonParameters_cff::track, TrackListRef_, VertexListRef_, and extraflags_cff::vtx.

Referenced by addPileups(), addSignals(), and counter.Counter::register().

99  {
100  const size_t StartingIndexV = NewVertexList_->size();
101  const size_t StartingIndexT = NewTrackList_->size();
102 
103  // grab Vertices, store copy, preserving indices. Easier to loop over
104  // vertices first - fewer links
105  for (const auto &vtx : vertices) {
106  NewVertexList_->push_back(vtx);
107  }
108 
109  // grab tracks, store copy
110  for (const auto &track : particles) {
111  const auto &oldRef = track.parentVertex();
112  auto newRef = TrackingVertexRef(VertexListRef_, oldRef.index() + StartingIndexV);
113  NewTrackList_->push_back(track);
114 
115  auto &Ntrack = NewTrackList_->back(); // modify copy
116 
117  Ntrack.setParentVertex(newRef);
118  Ntrack.clearDecayVertices();
119 
120  // next, loop over daughter vertices, same strategy
121  for (auto const &vertexRef : track.decayVertices()) {
122  auto newRef = TrackingVertexRef(VertexListRef_, vertexRef.index() + StartingIndexV);
123  Ntrack.addDecayVertex(newRef);
124  }
125  }
126 
127  // Now that tracks are handled, go back and put correct Refs in vertices
128  // Operate only on the added pileup vertices, and leave the already-existing
129  // vertices untouched
130  std::vector<decltype(TrackingParticleRef().index())> sourceTrackIndices;
131  std::vector<decltype(TrackingParticleRef().index())> daughterTrackIndices;
132  for (size_t iVertex = StartingIndexV; iVertex != NewVertexList_->size(); ++iVertex) {
133  auto &vertex = (*NewVertexList_)[iVertex];
134 
135  // Need to copy the indices before clearing the vectors
136  sourceTrackIndices.reserve(vertex.sourceTracks().size());
137  daughterTrackIndices.reserve(vertex.daughterTracks().size());
138  for (auto const &ref : vertex.sourceTracks())
139  sourceTrackIndices.push_back(ref.index());
140  for (auto const &ref : vertex.daughterTracks())
141  daughterTrackIndices.push_back(ref.index());
142 
143  vertex.clearParentTracks();
144  vertex.clearDaughterTracks();
145 
146  for (auto index : sourceTrackIndices) {
147  auto newRef = TrackingParticleRef(TrackListRef_, index + StartingIndexT);
148  vertex.addParentTrack(newRef);
149  }
150 
151  // next, loop over daughter tracks, same strategy
152  for (auto index : daughterTrackIndices) {
153  auto newRef = TrackingParticleRef(TrackListRef_, index + StartingIndexT);
154  vertex.addDaughterTrack(newRef);
155  }
156 
157  sourceTrackIndices.clear();
158  daughterTrackIndices.clear();
159  }
160 }
std::unique_ptr< std::vector< TrackingParticle > > NewTrackList_
std::unique_ptr< std::vector< TrackingVertex > > NewVertexList_
edm::Ref< TrackingVertexCollection > TrackingVertexRef
edm::Ref< TrackingParticleCollection > TrackingParticleRef
void PreMixingTrackingParticleWorker::addPileups ( PileUpEventPrincipal const &  pep,
edm::EventSetup const &  iSetup 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 83 of file PreMixingTrackingParticleWorker.cc.

References add(), PileUpEventPrincipal::bunchCrossing(), PileUpEventPrincipal::getByLabel(), edm::EventPrincipal::id(), edm::HandleBase::isValid(), LogDebug, PileUpEventPrincipal::principal(), and TrackingParticlePileInputTag_.

83  {
84  LogDebug("PreMixingTrackingParticleWorker") << "\n===============> adding pileups from event "
85  << pep.principal().id() << " for bunchcrossing " << pep.bunchCrossing();
86 
88  pep.getByLabel(TrackingParticlePileInputTag_, inputHandle);
89 
91  pep.getByLabel(TrackingParticlePileInputTag_, inputVHandle);
92 
93  if (inputHandle.isValid() && inputVHandle.isValid()) {
94  add(*inputHandle, *inputVHandle);
95  }
96 }
#define LogDebug(id)
void add(const std::vector< TrackingParticle > &particles, const std::vector< TrackingVertex > &vertices)
bool isValid() const
Definition: HandleBase.h:74
void PreMixingTrackingParticleWorker::addSignals ( edm::Event const &  iEvent,
edm::EventSetup const &  iSetup 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 71 of file PreMixingTrackingParticleWorker.cc.

References add(), edm::Event::getByToken(), edm::HandleBase::isValid(), l1t::tracks, TrackSigToken_, and VtxSigToken_.

71  {
73  iEvent.getByToken(TrackSigToken_, tracks);
74 
76  iEvent.getByToken(VtxSigToken_, vtxs);
77 
78  if (tracks.isValid() && vtxs.isValid()) {
79  add(*tracks, *vtxs);
80  }
81 }
edm::EDGetTokenT< std::vector< TrackingParticle > > TrackSigToken_
void add(const std::vector< TrackingParticle > &particles, const std::vector< TrackingVertex > &vertices)
int iEvent
Definition: GenABIO.cc:224
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< std::vector< TrackingVertex > > VtxSigToken_
void PreMixingTrackingParticleWorker::initializeEvent ( edm::Event const &  iEvent,
edm::EventSetup const &  iSetup 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 58 of file PreMixingTrackingParticleWorker.cc.

References iEvent, NewTrackList_, NewVertexList_, TrackingParticleCollectionDM_, TrackListRef_, and VertexListRef_.

58  {
59  NewTrackList_ = std::make_unique<std::vector<TrackingParticle>>();
60  NewVertexList_ = std::make_unique<std::vector<TrackingVertex>>();
61 
62  // need RefProds in order to re-key the particle<->vertex refs
63  // TODO: try to remove const_cast, requires making Event non-const in
64  // BMixingModule::initializeEvent
66  const_cast<edm::Event &>(iEvent).getRefBeforePut<std::vector<TrackingParticle>>(TrackingParticleCollectionDM_);
68  const_cast<edm::Event &>(iEvent).getRefBeforePut<std::vector<TrackingVertex>>(TrackingParticleCollectionDM_);
69 }
std::unique_ptr< std::vector< TrackingParticle > > NewTrackList_
std::unique_ptr< std::vector< TrackingVertex > > NewVertexList_
int iEvent
Definition: GenABIO.cc:224
void PreMixingTrackingParticleWorker::put ( edm::Event iEvent,
edm::EventSetup const &  iSetup,
std::vector< PileupSummaryInfo > const &  ps,
int  bunchSpacing 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 162 of file PreMixingTrackingParticleWorker.cc.

References DEFINE_PREMIXING_WORKER, eostools::move(), NewTrackList_, NewVertexList_, edm::Event::put(), and TrackingParticleCollectionDM_.

165  {
166  edm::LogInfo("PreMixingTrackingParticleWorker") << "total # Merged Tracks: " << NewTrackList_->size();
169 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
std::unique_ptr< std::vector< TrackingParticle > > NewTrackList_
std::unique_ptr< std::vector< TrackingVertex > > NewVertexList_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

std::unique_ptr<std::vector<TrackingParticle> > PreMixingTrackingParticleWorker::NewTrackList_
private

Definition at line 41 of file PreMixingTrackingParticleWorker.cc.

Referenced by add(), initializeEvent(), and put().

std::unique_ptr<std::vector<TrackingVertex> > PreMixingTrackingParticleWorker::NewVertexList_
private

Definition at line 42 of file PreMixingTrackingParticleWorker.cc.

Referenced by add(), initializeEvent(), and put().

std::string PreMixingTrackingParticleWorker::TrackingParticleCollectionDM_
private
edm::InputTag PreMixingTrackingParticleWorker::TrackingParticlePileInputTag_
private

Definition at line 36 of file PreMixingTrackingParticleWorker.cc.

Referenced by addPileups().

TrackingParticleRefProd PreMixingTrackingParticleWorker::TrackListRef_
private

Definition at line 43 of file PreMixingTrackingParticleWorker.cc.

Referenced by add(), and initializeEvent().

edm::EDGetTokenT<std::vector<TrackingParticle> > PreMixingTrackingParticleWorker::TrackSigToken_
private

Definition at line 33 of file PreMixingTrackingParticleWorker.cc.

Referenced by addSignals().

TrackingVertexRefProd PreMixingTrackingParticleWorker::VertexListRef_
private

Definition at line 44 of file PreMixingTrackingParticleWorker.cc.

Referenced by add(), and initializeEvent().

edm::EDGetTokenT<std::vector<TrackingVertex> > PreMixingTrackingParticleWorker::VtxSigToken_
private

Definition at line 34 of file PreMixingTrackingParticleWorker.cc.

Referenced by addSignals().