CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Attributes
l1tVertexFinder::InputData Class Reference

#include <InputData.h>

Classes

struct  SortVertexByPt
 
struct  SortVertexByZ0
 

Public Member Functions

const float genPt () const
 
const float genPt_PU () const
 
const VertexgetGenVertex () const
 Get primary vertex information (vertex from gen particles) More...
 
const VertexgetHepMCVertex () const
 Get primary vertex information (vertex from HepMCProduct) More...
 
const std::vector< Vertex > & getPileUpVertices () const
 Get pile-up vertices information. More...
 
const VertexgetPrimaryVertex () const
 Get primary vertex information (vertex from tracking particles) More...
 
const std::vector< Vertex > & getRecoPileUpVertices () const
 Get reconstructable pile-up vertices information. More...
 
const TPPtrToRefMapgetTPPtrToRefMap () const
 Get the TrackingParticle to TP translation map. More...
 
 InputData ()
 Constructor and destructor. More...
 
 InputData (const edm::Event &iEvent, const edm::EventSetup &iSetup, const AnalysisSettings &settings, const edm::EDGetTokenT< edm::HepMCProduct > hepMCToken, const edm::EDGetTokenT< edm::View< reco::GenParticle >> genParticlesToken, const edm::EDGetTokenT< edm::View< TrackingParticle >> tpToken, const edm::EDGetTokenT< edm::ValueMap< l1tVertexFinder::TP >> tpValueMapToken, const edm::EDGetTokenT< DetSetVec > stubToken, const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken, const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tGeomToken)
 
 ~InputData ()
 

Private Attributes

float genPt_
 
float genPt_PU_
 
Vertex genVertex_
 
Vertex hepMCVertex_
 
std::vector< VertexrecoVertices_
 
TPPtrToRefMap tpPtrToRefMap_
 
std::vector< StubvAllStubs_
 
Vertex vertex_
 
std::vector< Vertexvertices_
 

Detailed Description

Definition at line 35 of file InputData.h.

Constructor & Destructor Documentation

◆ InputData() [1/2]

l1tVertexFinder::InputData::InputData ( )

Constructor and destructor.

Definition at line 21 of file InputData.cc.

21 {}

◆ InputData() [2/2]

l1tVertexFinder::InputData::InputData ( const edm::Event iEvent,
const edm::EventSetup iSetup,
const AnalysisSettings settings,
const edm::EDGetTokenT< edm::HepMCProduct hepMCToken,
const edm::EDGetTokenT< edm::View< reco::GenParticle >>  genParticlesToken,
const edm::EDGetTokenT< edm::View< TrackingParticle >>  tpToken,
const edm::EDGetTokenT< edm::ValueMap< l1tVertexFinder::TP >>  tpValueMapToken,
const edm::EDGetTokenT< DetSetVec stubToken,
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd tTopoToken,
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord tGeomToken 
)

Definition at line 23 of file InputData.cc.

32  {
33  // Get the tracker geometry info needed to unpack the stub info.
34  const TrackerTopology& tTopo = iSetup.getData(tTopoToken);
35  const TrackerGeometry& tGeom = iSetup.getData(tGeomToken);
36 
37  // Get stub info, by looping over modules and then stubs inside each module.
38  // Also get the association map from stubs to tracking particles.
39  edm::Handle<DetSetVec> ttStubHandle;
40  iEvent.getByToken(stubToken, ttStubHandle);
41 
42  std::set<DetId> lStubDetIds;
43  for (DetSetVec::const_iterator p_module = ttStubHandle->begin(); p_module != ttStubHandle->end(); p_module++) {
44  for (DetSet::const_iterator p_ttstub = p_module->begin(); p_ttstub != p_module->end(); p_ttstub++) {
45  lStubDetIds.insert(p_ttstub->getDetId());
46  }
47  }
48 
49  std::map<DetId, DetId> stubGeoDetIdMap;
50  for (auto gd = tGeom.dets().begin(); gd != tGeom.dets().end(); gd++) {
51  DetId detid = (*gd)->geographicalId();
52  if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
53  continue; // only run on OT
54  if (!tTopo.isLower(detid))
55  continue; // loop on the stacks: choose the lower arbitrarily
56  DetId stackDetid = tTopo.stack(detid); // Stub module detid
57 
58  if (lStubDetIds.count(stackDetid) > 0) {
59  assert(stubGeoDetIdMap.count(stackDetid) == 0);
60  stubGeoDetIdMap[stackDetid] = detid;
61  }
62  }
63  assert(lStubDetIds.size() == stubGeoDetIdMap.size());
64 
65  // Get TrackingParticle info
67  edm::Handle<edm::ValueMap<TP>> tpValueMapHandle;
68  iEvent.getByToken(tpToken, tpHandle);
69  iEvent.getByToken(tpValueMapToken, tpValueMapHandle);
70  edm::ValueMap<TP> tpValueMap = *tpValueMapHandle;
71 
72  for (unsigned int i = 0; i < tpHandle->size(); i++) {
73  if (tpValueMap[tpHandle->refAt(i)].use()) {
74  tpPtrToRefMap_[tpHandle->ptrAt(i)] = tpHandle->refAt(i);
75  }
76  }
77 
78  // Find the various vertices
79  genPt_ = 0.;
80  genPt_PU_ = 0.;
81  for (const auto& [edmPtr, edmRef] : tpPtrToRefMap_) {
82  TP tp = tpValueMap[edmRef];
83  if (tp.physicsCollision()) {
84  genPt_ += tp->pt();
85  } else {
86  genPt_PU_ += tp->pt();
87  }
88  if (settings.debug() > 0) {
89  edm::LogInfo("InputData") << "InputData::genPt in the event " << genPt_;
90  }
91 
92  if (tp.useForAlgEff()) {
93  vertex_.insert(tp);
94  } else if (tp.useForVertexReco()) {
95  bool found = false;
96  for (unsigned int i = 0; i < vertices_.size(); ++i) {
97  if (tp->vz() == vertices_[i].vz()) {
98  vertices_[i].insert(tp);
99  found = true;
100  break;
101  }
102  }
103  if (!found) {
104  Vertex vertex(tp->vz());
105  vertex.insert(tp);
106  vertices_.push_back(vertex);
107  }
108  }
109  }
110 
111  for (const Vertex& vertex : vertices_) {
112  if (vertex.numTracks() >= settings.vx_minTracks())
113  recoVertices_.push_back(vertex);
114  }
115 
116  if (settings.debug() > 0)
117  edm::LogInfo("InputData") << "InputData::" << vertices_.size() << " pileup vertices in the event, "
118  << recoVertices_.size() << " reconstructable";
119 
121  if (settings.debug() > 2)
122  edm::LogInfo("InputData") << "InputData::Vertex " << vertex_.z0() << " containing " << vertex_.numTracks()
123  << " total pT " << vertex_.pT();
124 
125  for (unsigned int i = 0; i < vertices_.size(); ++i) {
126  vertices_[i].computeParameters();
127  }
128 
129  for (unsigned int i = 0; i < recoVertices_.size(); ++i) {
130  recoVertices_[i].computeParameters();
131  }
132 
133  std::sort(vertices_.begin(), vertices_.end(), SortVertexByPt());
134  std::sort(recoVertices_.begin(), recoVertices_.end(), SortVertexByPt());
135 
136  // Form the HepMC and GenParticle based vertices
138  iEvent.getByToken(hepMCToken, HepMCEvt);
139 
140  edm::Handle<edm::View<reco::GenParticle>> GenParticleHandle;
141  iEvent.getByToken(genParticlesToken, GenParticleHandle);
142 
143  if (!HepMCEvt.isValid() && !GenParticleHandle.isValid()) {
144  throw cms::Exception("Neither the edm::HepMCProduct nor the generator particles are available.");
145  }
146  if (HepMCEvt.isValid()) {
147  const HepMC::GenEvent* MCEvt = HepMCEvt->GetEvent();
148  for (HepMC::GenEvent::vertex_const_iterator ivertex = MCEvt->vertices_begin(); ivertex != MCEvt->vertices_end();
149  ++ivertex) {
150  bool hasParentVertex = false;
151 
152  // Loop over the parents looking to see if they are coming from a production vertex
153  for (HepMC::GenVertex::particle_iterator iparent = (*ivertex)->particles_begin(HepMC::parents);
154  iparent != (*ivertex)->particles_end(HepMC::parents);
155  ++iparent)
156  if ((*iparent)->production_vertex()) {
157  hasParentVertex = true;
158  break;
159  }
160 
161  // Reject those vertices with parent vertices
162  if (hasParentVertex)
163  continue;
164  // Get the position of the vertex
165  HepMC::FourVector pos = (*ivertex)->position();
166  const double mm = 0.1; // [mm] --> [cm]
167  hepMCVertex_ = Vertex(pos.z() * mm);
168  break; // there should be one single primary vertex
169  } // end loop over gen vertices
170  }
171  if (GenParticleHandle.isValid()) {
172  for (const auto& genpart : *GenParticleHandle) {
173  if ((genpart.status() != 1) || (genpart.numberOfMothers() == 0)) // not stable or one of the incoming hadrons
174  continue;
175  genVertex_ = Vertex(genpart.vz());
176  break;
177  }
178  }
179  if ((hepMCVertex_.vz() == 0.0) && (genVertex_.vz() == 0.0)) {
180  throw cms::Exception("Neither the HepMC vertex nor the generator particle vertex were found.");
181  }
182 
183  } // end InputData::InputData

References cms::cuda::assert(), l1tVertexFinder::AlgoSettings::debug(), TrackerGeometry::dets(), Exception, newFWLiteAna::found, edm::EventSetup::getData(), mps_fire::i, iEvent, TrackerTopology::isLower(), edm::HandleBase::isValid(), parents, jetUpdater_cfi::sort, TrackerTopology::stack(), DetId::subdetId(), StripSubdetector::TID, StripSubdetector::TOB, cmsswSequenceInfo::tp, bphysicsOniaDQM_cfi::vertex, HltBtagValidation_cff::Vertex, and l1tVertexFinder::AlgoSettings::vx_minTracks().

◆ ~InputData()

l1tVertexFinder::InputData::~InputData ( )

Definition at line 185 of file InputData.cc.

185 {}

Member Function Documentation

◆ genPt()

const float l1tVertexFinder::InputData::genPt ( ) const
inline

Definition at line 74 of file InputData.h.

74 { return genPt_; }

References genPt_.

◆ genPt_PU()

const float l1tVertexFinder::InputData::genPt_PU ( ) const
inline

Definition at line 75 of file InputData.h.

75 { return genPt_PU_; }

References genPt_PU_.

◆ getGenVertex()

const Vertex& l1tVertexFinder::InputData::getGenVertex ( ) const
inline

Get primary vertex information (vertex from gen particles)

Definition at line 66 of file InputData.h.

66 { return genVertex_; }

References genVertex_.

Referenced by l1tVertexFinder::VertexNTupler::analyze().

◆ getHepMCVertex()

const Vertex& l1tVertexFinder::InputData::getHepMCVertex ( ) const
inline

Get primary vertex information (vertex from HepMCProduct)

Definition at line 64 of file InputData.h.

64 { return hepMCVertex_; }

References hepMCVertex_.

Referenced by l1tVertexFinder::VertexNTupler::analyze().

◆ getPileUpVertices()

const std::vector<Vertex>& l1tVertexFinder::InputData::getPileUpVertices ( ) const
inline

Get pile-up vertices information.

Definition at line 70 of file InputData.h.

70 { return vertices_; }

References vertices_.

Referenced by l1tVertexFinder::VertexNTupler::analyze().

◆ getPrimaryVertex()

const Vertex& l1tVertexFinder::InputData::getPrimaryVertex ( ) const
inline

Get primary vertex information (vertex from tracking particles)

Definition at line 68 of file InputData.h.

68 { return vertex_; }

References vertex_.

◆ getRecoPileUpVertices()

const std::vector<Vertex>& l1tVertexFinder::InputData::getRecoPileUpVertices ( ) const
inline

Get reconstructable pile-up vertices information.

Definition at line 72 of file InputData.h.

72 { return recoVertices_; }

References recoVertices_.

◆ getTPPtrToRefMap()

const TPPtrToRefMap& l1tVertexFinder::InputData::getTPPtrToRefMap ( ) const
inline

Get the TrackingParticle to TP translation map.

Definition at line 62 of file InputData.h.

62 { return tpPtrToRefMap_; }

References tpPtrToRefMap_.

Referenced by l1tVertexFinder::VertexNTupler::analyze().

Member Data Documentation

◆ genPt_

float l1tVertexFinder::InputData::genPt_
private

Definition at line 87 of file InputData.h.

Referenced by genPt().

◆ genPt_PU_

float l1tVertexFinder::InputData::genPt_PU_
private

Definition at line 88 of file InputData.h.

Referenced by genPt_PU().

◆ genVertex_

Vertex l1tVertexFinder::InputData::genVertex_
private

Definition at line 79 of file InputData.h.

Referenced by getGenVertex().

◆ hepMCVertex_

Vertex l1tVertexFinder::InputData::hepMCVertex_
private

Definition at line 78 of file InputData.h.

Referenced by getHepMCVertex().

◆ recoVertices_

std::vector<Vertex> l1tVertexFinder::InputData::recoVertices_
private

Definition at line 82 of file InputData.h.

Referenced by getRecoPileUpVertices().

◆ tpPtrToRefMap_

TPPtrToRefMap l1tVertexFinder::InputData::tpPtrToRefMap_
private

Definition at line 86 of file InputData.h.

Referenced by getTPPtrToRefMap().

◆ vAllStubs_

std::vector<Stub> l1tVertexFinder::InputData::vAllStubs_
private

Definition at line 84 of file InputData.h.

◆ vertex_

Vertex l1tVertexFinder::InputData::vertex_
private

Definition at line 80 of file InputData.h.

Referenced by getPrimaryVertex().

◆ vertices_

std::vector<Vertex> l1tVertexFinder::InputData::vertices_
private

Definition at line 81 of file InputData.h.

Referenced by getPileUpVertices().

mps_fire.i
i
Definition: mps_fire.py:428
l1tVertexFinder::Vertex::insert
void insert(TP &tp)
Assign TP to this vertex.
Definition: Vertex.h:28
l1tVertexFinder::Vertex::numTracks
unsigned int numTracks() const
Number of tracks originating from this vertex.
Definition: Vertex.h:26
TrackerTopology::isLower
bool isLower(const DetId &id) const
Definition: TrackerTopology.cc:195
TrackerTopology
Definition: TrackerTopology.h:16
pos
Definition: PixelAliasList.h:18
l1tVertexFinder::InputData::recoVertices_
std::vector< Vertex > recoVertices_
Definition: InputData.h:82
l1tVertexFinder::Vertex::pT
double pT() const
Sum of fitted tracks transverse momentum [GeV].
Definition: Vertex.h:32
edmNew::DetSetVector::const_iterator
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetSetVectorNew.h:197
DigiToRawDM_cff.TP
TP
Definition: DigiToRawDM_cff.py:51
cms::cuda::assert
assert(be >=bs)
TrackerTopology::stack
uint32_t stack(const DetId &id) const
Definition: TrackerTopology.cc:104
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
l1tVertexFinder::Vertex::z0
double z0() const
Vertex z0 position [cm].
Definition: Vertex.h:34
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
l1tVertexFinder::InputData::genPt_
float genPt_
Definition: InputData.h:87
DetId
Definition: DetId.h:17
l1tVertexFinder::InputData::vertices_
std::vector< Vertex > vertices_
Definition: InputData.h:81
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
l1tVertexFinder::Vertex::computeParameters
void computeParameters()
Compute vertex parameters.
Definition: Vertex.cc:6
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
l1tVertexFinder::InputData::genPt_PU_
float genPt_PU_
Definition: InputData.h:88
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
l1tVertexFinder::Vertex::vz
double vz() const
Vertex z position [cm].
Definition: Vertex.h:38
iEvent
int iEvent
Definition: GenABIO.cc:224
TrackerGeometry::dets
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: TrackerGeometry.h:62
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
HltBtagValidation_cff.Vertex
Vertex
Definition: HltBtagValidation_cff.py:32
l1tVertexFinder::InputData::vertex_
Vertex vertex_
Definition: InputData.h:80
l1tVertexFinder::InputData::hepMCVertex_
Vertex hepMCVertex_
Definition: InputData.h:78
l1tVertexFinder::InputData::tpPtrToRefMap_
TPPtrToRefMap tpPtrToRefMap_
Definition: InputData.h:86
edm::ValueMap
Definition: ValueMap.h:107
Exception
Definition: hltDiff.cc:245
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
l1tVertexFinder::InputData::genVertex_
Vertex genVertex_
Definition: InputData.h:79
parents
TPRegexp parents
Definition: eve_filter.cc:21
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Log
Definition: MessageLogger.h:70
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
TrackerGeometry
Definition: TrackerGeometry.h:14
edmNew::DetSet::const_iterator
const data_type * const_iterator
Definition: DetSetNew.h:31