CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

l1tVertexFinder::InputData::InputData ( )

Constructor and destructor.

Definition at line 21 of file InputData.cc.

21 {}
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.

References cms::cuda::assert(), l1tVertexFinder::AlgoSettings::debug(), TrackerGeometry::dets(), Exception, newFWLiteAna::found, edm::Event::getByToken(), edm::EventSetup::getData(), mps_fire::i, l1tVertexFinder::Vertex::insert(), TrackerTopology::isLower(), edm::HandleBase::isValid(), parents, l1tVertexFinder::TP::physicsCollision(), TrackerTopology::stack(), DetId::subdetId(), StripSubdetector::TID, StripSubdetector::TOB, cmsswSequenceInfo::tp, l1tVertexFinder::TP::useForAlgEff(), l1tVertexFinder::TP::useForVertexReco(), and l1tVertexFinder::AlgoSettings::vx_minTracks().

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
std::vector< Vertex > vertices_
Definition: InputData.h:81
TPRegexp parents
Definition: eve_filter.cc:21
double vz() const
Vertex z position [cm].
Definition: Vertex.h:38
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
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)
bool isLower(const DetId &id) const
bool getData(T &iHolder) const
Definition: EventSetup.h:122
void insert(TP &tp)
Assign TP to this vertex.
Definition: Vertex.h:28
TPPtrToRefMap tpPtrToRefMap_
Definition: InputData.h:86
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
bool isValid() const
Definition: HandleBase.h:70
double pT() const
Sum of fitted tracks transverse momentum [GeV].
Definition: Vertex.h:32
Log< level::Info, false > LogInfo
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
double z0() const
Vertex z0 position [cm].
Definition: Vertex.h:34
uint32_t stack(const DetId &id) const
std::vector< Vertex > recoVertices_
Definition: InputData.h:82
void computeParameters()
Compute vertex parameters.
Definition: Vertex.cc:6
unsigned int numTracks() const
Number of tracks originating from this vertex.
Definition: Vertex.h:26
static constexpr auto TID
l1tVertexFinder::InputData::~InputData ( )

Definition at line 185 of file InputData.cc.

185 {}

Member Function Documentation

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

Definition at line 74 of file InputData.h.

References genPt_.

74 { return genPt_; }
const float l1tVertexFinder::InputData::genPt_PU ( ) const
inline

Definition at line 75 of file InputData.h.

References genPt_PU_.

75 { return genPt_PU_; }
const Vertex& l1tVertexFinder::InputData::getGenVertex ( ) const
inline

Get primary vertex information (vertex from gen particles)

Definition at line 66 of file InputData.h.

References genVertex_.

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

66 { return genVertex_; }
const Vertex& l1tVertexFinder::InputData::getHepMCVertex ( ) const
inline

Get primary vertex information (vertex from HepMCProduct)

Definition at line 64 of file InputData.h.

References hepMCVertex_.

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

64 { return hepMCVertex_; }
const std::vector<Vertex>& l1tVertexFinder::InputData::getPileUpVertices ( ) const
inline

Get pile-up vertices information.

Definition at line 70 of file InputData.h.

References vertices_.

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

70 { return vertices_; }
std::vector< Vertex > vertices_
Definition: InputData.h:81
const Vertex& l1tVertexFinder::InputData::getPrimaryVertex ( ) const
inline

Get primary vertex information (vertex from tracking particles)

Definition at line 68 of file InputData.h.

References vertex_.

68 { return vertex_; }
const std::vector<Vertex>& l1tVertexFinder::InputData::getRecoPileUpVertices ( ) const
inline

Get reconstructable pile-up vertices information.

Definition at line 72 of file InputData.h.

References recoVertices_.

72 { return recoVertices_; }
std::vector< Vertex > recoVertices_
Definition: InputData.h:82
const TPPtrToRefMap& l1tVertexFinder::InputData::getTPPtrToRefMap ( ) const
inline

Get the TrackingParticle to TP translation map.

Definition at line 62 of file InputData.h.

References tpPtrToRefMap_.

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

62 { return tpPtrToRefMap_; }
TPPtrToRefMap tpPtrToRefMap_
Definition: InputData.h:86

Member Data Documentation

float l1tVertexFinder::InputData::genPt_
private

Definition at line 87 of file InputData.h.

Referenced by genPt().

float l1tVertexFinder::InputData::genPt_PU_
private

Definition at line 88 of file InputData.h.

Referenced by genPt_PU().

Vertex l1tVertexFinder::InputData::genVertex_
private

Definition at line 79 of file InputData.h.

Referenced by getGenVertex().

Vertex l1tVertexFinder::InputData::hepMCVertex_
private

Definition at line 78 of file InputData.h.

Referenced by getHepMCVertex().

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

Definition at line 82 of file InputData.h.

Referenced by getRecoPileUpVertices().

TPPtrToRefMap l1tVertexFinder::InputData::tpPtrToRefMap_
private

Definition at line 86 of file InputData.h.

Referenced by getTPPtrToRefMap().

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

Definition at line 84 of file InputData.h.

Vertex l1tVertexFinder::InputData::vertex_
private

Definition at line 80 of file InputData.h.

Referenced by getPrimaryVertex().

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

Definition at line 81 of file InputData.h.

Referenced by getPileUpVertices().