CMS 3D CMS Logo

InputData.cc
Go to the documentation of this file.
14 
15 #include <map>
16 
17 using namespace std;
18 
19 namespace l1tVertexFinder {
20 
21  InputData::InputData() {}
22 
23  InputData::InputData(const edm::Event& iEvent,
24  const edm::EventSetup& iSetup,
25  const AnalysisSettings& settings,
26  const edm::EDGetTokenT<edm::HepMCProduct> hepMCToken,
27  const edm::EDGetTokenT<edm::View<reco::GenParticle>> genParticlesToken,
30  const edm::EDGetTokenT<DetSetVec> stubToken,
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 
120  vertex_.computeParameters();
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
184 
185  InputData::~InputData() {}
186 
187 } // end namespace l1tVertexFinder
l1tVertexFinder
Definition: AlgoSettings.h:10
mps_fire.i
i
Definition: mps_fire.py:428
l1tVertexFinder::AnalysisSettings
Definition: AnalysisSettings.h:15
TrackerGeometry.h
AnalysisSettings.h
TrackerTopology::isLower
bool isLower(const DetId &id) const
Definition: TrackerTopology.cc:195
edm::EDGetTokenT< edm::HepMCProduct >
TrackerTopology
Definition: TrackerTopology.h:16
pos
Definition: PixelAliasList.h:18
edmNew::DetSetVector::const_iterator
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetSetVectorNew.h:197
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
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
TTClusterAssociationMap.h
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
l1tVertexFinder::TP
Definition: TP.h:16
DetId
Definition: DetId.h:17
TrackerTopology.h
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
edm::View
Definition: CaloClusterFwd.h:14
TrackerDigiGeometryRecord.h
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
Event.h
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
l1tVertexFinder::InputData::SortVertexByPt
Definition: InputData.h:52
iEvent
int iEvent
Definition: GenABIO.cc:224
TTStubAssociationMap.h
edm::EventSetup
Definition: EventSetup.h:58
TrackerGeometry::dets
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: TrackerGeometry.h:62
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd >
InputTag.h
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
TrackingParticle.h
std
Definition: JetResolutionObject.h:76
HltBtagValidation_cff.Vertex
Vertex
Definition: HltBtagValidation_cff.py:32
edm::ValueMap
Definition: ValueMap.h:107
Exception
Definition: hltDiff.cc:245
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
EventSetup.h
l1tVertexFinder::Vertex
Definition: Vertex.h:10
InputData.h
SimTrack.h
l1tVertexFinder::AlgoSettings::debug
unsigned int debug() const
Definition: AlgoSettings.h:71
parents
TPRegexp parents
Definition: eve_filter.cc:21
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::Log
Definition: MessageLogger.h:70
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
l1tVertexFinder::AlgoSettings::vx_minTracks
unsigned int vx_minTracks() const
Definition: AlgoSettings.h:39
TrackerGeometry
Definition: TrackerGeometry.h:14
edmNew::DetSet::const_iterator
const data_type * const_iterator
Definition: DetSetNew.h:31
EncodedEventId.h