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 32 of file InputData.h.

Constructor & Destructor Documentation

◆ InputData() [1/2]

l1tVertexFinder::InputData::InputData ( )

Constructor and destructor.

Definition at line 20 of file InputData.cc.

20 {}

◆ 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 22 of file InputData.cc.

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().

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

◆ ~InputData()

l1tVertexFinder::InputData::~InputData ( )

Definition at line 184 of file InputData.cc.

184 {}

Member Function Documentation

◆ genPt()

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

Definition at line 71 of file InputData.h.

References genPt_.

71 { return genPt_; }

◆ genPt_PU()

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

Definition at line 72 of file InputData.h.

References genPt_PU_.

72 { return genPt_PU_; }

◆ getGenVertex()

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

Get primary vertex information (vertex from gen particles)

Definition at line 63 of file InputData.h.

References genVertex_.

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

63 { return genVertex_; }

◆ getHepMCVertex()

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

Get primary vertex information (vertex from HepMCProduct)

Definition at line 61 of file InputData.h.

References hepMCVertex_.

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

61 { return hepMCVertex_; }

◆ getPileUpVertices()

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

Get pile-up vertices information.

Definition at line 67 of file InputData.h.

References vertices_.

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

67 { return vertices_; }
std::vector< Vertex > vertices_
Definition: InputData.h:78

◆ getPrimaryVertex()

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

Get primary vertex information (vertex from tracking particles)

Definition at line 65 of file InputData.h.

References vertex_.

65 { return vertex_; }

◆ getRecoPileUpVertices()

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

Get reconstructable pile-up vertices information.

Definition at line 69 of file InputData.h.

References recoVertices_.

69 { return recoVertices_; }
std::vector< Vertex > recoVertices_
Definition: InputData.h:79

◆ getTPPtrToRefMap()

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

Get the TrackingParticle to TP translation map.

Definition at line 59 of file InputData.h.

References tpPtrToRefMap_.

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

59 { return tpPtrToRefMap_; }
TPPtrToRefMap tpPtrToRefMap_
Definition: InputData.h:83

Member Data Documentation

◆ genPt_

float l1tVertexFinder::InputData::genPt_
private

Definition at line 84 of file InputData.h.

Referenced by genPt().

◆ genPt_PU_

float l1tVertexFinder::InputData::genPt_PU_
private

Definition at line 85 of file InputData.h.

Referenced by genPt_PU().

◆ genVertex_

Vertex l1tVertexFinder::InputData::genVertex_
private

Definition at line 76 of file InputData.h.

Referenced by getGenVertex().

◆ hepMCVertex_

Vertex l1tVertexFinder::InputData::hepMCVertex_
private

Definition at line 75 of file InputData.h.

Referenced by getHepMCVertex().

◆ recoVertices_

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

Definition at line 79 of file InputData.h.

Referenced by getRecoPileUpVertices().

◆ tpPtrToRefMap_

TPPtrToRefMap l1tVertexFinder::InputData::tpPtrToRefMap_
private

Definition at line 83 of file InputData.h.

Referenced by getTPPtrToRefMap().

◆ vAllStubs_

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

Definition at line 81 of file InputData.h.

◆ vertex_

Vertex l1tVertexFinder::InputData::vertex_
private

Definition at line 77 of file InputData.h.

Referenced by getPrimaryVertex().

◆ vertices_

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

Definition at line 78 of file InputData.h.

Referenced by getPileUpVertices().