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::ProducesCollector, 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::PreMixingTrackingParticleWorker ( const edm::ParameterSet ps,
edm::ProducesCollector  producesCollector,
edm::ConsumesCollector &&  iC 
)

Definition at line 45 of file PreMixingTrackingParticleWorker.cc.

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

48  : TrackSigToken_(iC.consumes<std::vector<TrackingParticle>>(ps.getParameter<edm::InputTag>("labelSig"))),
49  VtxSigToken_(iC.consumes<std::vector<TrackingVertex>>(ps.getParameter<edm::InputTag>("labelSig"))),
52  producesCollector.produces<std::vector<TrackingParticle>>(TrackingParticleCollectionDM_);
53  producesCollector.produces<std::vector<TrackingVertex>>(TrackingParticleCollectionDM_);
54 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< std::vector< TrackingParticle > > TrackSigToken_
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
edm::EDGetTokenT< std::vector< TrackingVertex > > VtxSigToken_

◆ ~PreMixingTrackingParticleWorker()

PreMixingTrackingParticleWorker::~PreMixingTrackingParticleWorker ( )
overridedefault

Member Function Documentation

◆ add()

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

Definition at line 96 of file PreMixingTrackingParticleWorker.cc.

References NewTrackList_, NewVertexList_, ecalTrigSettings_cff::particles, HLT_2023v12_cff::track, TrackListRef_, trackerHitRTTI::vector, bphysicsOniaDQM_cfi::vertex, VertexListRef_, AlignmentTracksFromVertexSelector_cfi::vertices, and L1BJetProducer_cff::vtx.

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

97  {
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 }
std::unique_ptr< std::vector< TrackingParticle > > NewTrackList_
std::unique_ptr< std::vector< TrackingVertex > > NewVertexList_
edm::Ref< TrackingVertexCollection > TrackingVertexRef
edm::Ref< TrackingParticleCollection > TrackingParticleRef

◆ addPileups()

void PreMixingTrackingParticleWorker::addPileups ( PileUpEventPrincipal const &  pep,
edm::EventSetup const &  iSetup 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 81 of file PreMixingTrackingParticleWorker.cc.

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

81  {
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 }
void add(const std::vector< TrackingParticle > &particles, const std::vector< TrackingVertex > &vertices)
bool isValid() const
Definition: HandleBase.h:70
#define LogDebug(id)

◆ addSignals()

void PreMixingTrackingParticleWorker::addSignals ( edm::Event const &  iEvent,
edm::EventSetup const &  iSetup 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 69 of file PreMixingTrackingParticleWorker.cc.

References add(), iEvent, edm::HandleBase::isValid(), DiMuonV_cfg::tracks, TrackSigToken_, and VtxSigToken_.

69  {
71  iEvent.getByToken(TrackSigToken_, tracks);
72 
74  iEvent.getByToken(VtxSigToken_, vtxs);
75 
76  if (tracks.isValid() && vtxs.isValid()) {
77  add(*tracks, *vtxs);
78  }
79 }
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:70
edm::EDGetTokenT< std::vector< TrackingVertex > > VtxSigToken_

◆ initializeEvent()

void PreMixingTrackingParticleWorker::initializeEvent ( edm::Event const &  iEvent,
edm::EventSetup const &  iSetup 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 56 of file PreMixingTrackingParticleWorker.cc.

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

56  {
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 }
std::unique_ptr< std::vector< TrackingParticle > > NewTrackList_
std::unique_ptr< std::vector< TrackingVertex > > NewVertexList_
int iEvent
Definition: GenABIO.cc:224

◆ put()

void PreMixingTrackingParticleWorker::put ( edm::Event iEvent,
edm::EventSetup const &  iSetup,
std::vector< PileupSummaryInfo > const &  ps,
int  bunchSpacing 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 160 of file PreMixingTrackingParticleWorker.cc.

References iEvent, eostools::move(), NewTrackList_, NewVertexList_, and TrackingParticleCollectionDM_.

163  {
164  edm::LogInfo("PreMixingTrackingParticleWorker") << "total # Merged Tracks: " << NewTrackList_->size();
167 }
std::unique_ptr< std::vector< TrackingParticle > > NewTrackList_
std::unique_ptr< std::vector< TrackingVertex > > NewVertexList_
int iEvent
Definition: GenABIO.cc:224
Log< level::Info, false > LogInfo
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ NewTrackList_

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

Definition at line 39 of file PreMixingTrackingParticleWorker.cc.

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

◆ NewVertexList_

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

Definition at line 40 of file PreMixingTrackingParticleWorker.cc.

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

◆ TrackingParticleCollectionDM_

std::string PreMixingTrackingParticleWorker::TrackingParticleCollectionDM_
private

◆ TrackingParticlePileInputTag_

edm::InputTag PreMixingTrackingParticleWorker::TrackingParticlePileInputTag_
private

Definition at line 34 of file PreMixingTrackingParticleWorker.cc.

Referenced by addPileups().

◆ TrackListRef_

TrackingParticleRefProd PreMixingTrackingParticleWorker::TrackListRef_
private

Definition at line 41 of file PreMixingTrackingParticleWorker.cc.

Referenced by add(), and initializeEvent().

◆ TrackSigToken_

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

Definition at line 31 of file PreMixingTrackingParticleWorker.cc.

Referenced by addSignals().

◆ VertexListRef_

TrackingVertexRefProd PreMixingTrackingParticleWorker::VertexListRef_
private

Definition at line 42 of file PreMixingTrackingParticleWorker.cc.

Referenced by add(), and initializeEvent().

◆ VtxSigToken_

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

Definition at line 32 of file PreMixingTrackingParticleWorker.cc.

Referenced by addSignals().