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 42 of file PreMixingTrackingParticleWorker.cc.

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

42  :
43  TrackSigToken_(iC.consumes<std::vector<TrackingParticle> >(ps.getParameter<edm::InputTag>("labelSig"))),
44  VtxSigToken_ (iC.consumes<std::vector<TrackingVertex> >(ps.getParameter<edm::InputTag>("labelSig"))),
47 {
48  producer.produces< std::vector<TrackingParticle> >(TrackingParticleCollectionDM_);
49  producer.produces< std::vector<TrackingVertex> >(TrackingParticleCollectionDM_);
50 }
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 89 of file PreMixingTrackingParticleWorker.cc.

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

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

89  {
90  const size_t StartingIndexV = NewVertexList_->size();
91  const size_t StartingIndexT = NewTrackList_->size();
92 
93  // grab Vertices, store copy, preserving indices. Easier to loop over vertices first - fewer links
94  for(const auto& vtx: vertices) {
95  NewVertexList_->push_back(vtx);
96  }
97 
98  // grab tracks, store copy
99  for(const auto& track: particles) {
100  const auto& oldRef=track.parentVertex();
101  auto newRef=TrackingVertexRef( VertexListRef_, oldRef.index()+StartingIndexV );
102  NewTrackList_->push_back(track);
103 
104  auto & Ntrack = NewTrackList_->back(); //modify copy
105 
106  Ntrack.setParentVertex( newRef );
107  Ntrack.clearDecayVertices();
108 
109  // next, loop over daughter vertices, same strategy
110  for( auto const& vertexRef : track.decayVertices() ) {
111  auto newRef=TrackingVertexRef( VertexListRef_, vertexRef.index()+StartingIndexV );
112  Ntrack.addDecayVertex(newRef);
113  }
114  }
115 
116  // Now that tracks are handled, go back and put correct Refs in vertices
117  // Operate only on the added pileup vertices, and leave the already-existing vertices untouched
118  std::vector<decltype(TrackingParticleRef().index())> sourceTrackIndices;
119  std::vector<decltype(TrackingParticleRef().index())> daughterTrackIndices;
120  for(size_t iVertex = StartingIndexV; iVertex != NewVertexList_->size(); ++iVertex) {
121  auto& vertex = (*NewVertexList_)[iVertex];
122 
123  // Need to copy the indices before clearing the vectors
124  sourceTrackIndices.reserve(vertex.sourceTracks().size());
125  daughterTrackIndices.reserve(vertex.daughterTracks().size());
126  for(auto const& ref: vertex.sourceTracks()) sourceTrackIndices.push_back(ref.index());
127  for(auto const& ref: vertex.daughterTracks()) daughterTrackIndices.push_back(ref.index());
128 
129  vertex.clearParentTracks();
130  vertex.clearDaughterTracks();
131 
132  for( auto index : sourceTrackIndices ) {
133  auto newRef=TrackingParticleRef( TrackListRef_, index+StartingIndexT );
134  vertex.addParentTrack(newRef);
135  }
136 
137  // next, loop over daughter tracks, same strategy
138  for( auto index : daughterTrackIndices ) {
139  auto newRef=TrackingParticleRef( TrackListRef_, index+StartingIndexT );
140  vertex.addDaughterTrack(newRef);
141  }
142 
143  sourceTrackIndices.clear();
144  daughterTrackIndices.clear();
145  }
146 }
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 75 of file PreMixingTrackingParticleWorker.cc.

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

75  {
76  LogDebug("PreMixingTrackingParticleWorker") <<"\n===============> adding pileups from event "<<pep.principal().id()<<" for bunchcrossing "<<pep.bunchCrossing();
77 
79  pep.getByLabel(TrackingParticlePileInputTag_, inputHandle);
80 
82  pep.getByLabel(TrackingParticlePileInputTag_, inputVHandle);
83 
84  if(inputHandle.isValid() && inputVHandle.isValid()) {
85  add(*inputHandle, *inputVHandle);
86  }
87 }
#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 63 of file PreMixingTrackingParticleWorker.cc.

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

63  {
65  iEvent.getByToken(TrackSigToken_, tracks);
66 
68  iEvent.getByToken(VtxSigToken_, vtxs);
69 
70  if(tracks.isValid() && vtxs.isValid()) {
71  add(*tracks, *vtxs);
72  }
73 }
edm::EDGetTokenT< std::vector< TrackingParticle > > TrackSigToken_
void add(const std::vector< TrackingParticle > &particles, const std::vector< TrackingVertex > &vertices)
int iEvent
Definition: GenABIO.cc:230
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 53 of file PreMixingTrackingParticleWorker.cc.

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

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

Implements PreMixingWorker.

Definition at line 148 of file PreMixingTrackingParticleWorker.cc.

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

148  {
149  edm::LogInfo("PreMixingTrackingParticleWorker") << "total # Merged Tracks: " << NewTrackList_->size() ;
152 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
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 36 of file PreMixingTrackingParticleWorker.cc.

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

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

Definition at line 37 of file PreMixingTrackingParticleWorker.cc.

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

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

Definition at line 31 of file PreMixingTrackingParticleWorker.cc.

Referenced by addPileups().

TrackingParticleRefProd PreMixingTrackingParticleWorker::TrackListRef_
private

Definition at line 38 of file PreMixingTrackingParticleWorker.cc.

Referenced by add(), and initializeEvent().

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

Definition at line 28 of file PreMixingTrackingParticleWorker.cc.

Referenced by addSignals().

TrackingVertexRefProd PreMixingTrackingParticleWorker::VertexListRef_
private

Definition at line 39 of file PreMixingTrackingParticleWorker.cc.

Referenced by add(), and initializeEvent().

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

Definition at line 29 of file PreMixingTrackingParticleWorker.cc.

Referenced by addSignals().