CMS 3D CMS Logo

PixelVertexProducerFromSoA.cc
Go to the documentation of this file.
23 
24 #undef PIXVERTEX_DEBUG_PRODUCE
25 
27 public:
28  using IndToEdm = std::vector<uint16_t>;
29 
30  explicit PixelVertexProducerFromSoA(const edm::ParameterSet &iConfig);
31  ~PixelVertexProducerFromSoA() override = default;
32 
33  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
34 
35 private:
36  void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override;
37 
42 };
43 
45  : tokenVertex_(consumes<ZVertexHeterogeneous>(conf.getParameter<edm::InputTag>("src"))),
46  tokenBeamSpot_(consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("beamSpot"))),
47  tokenTracks_(consumes<reco::TrackCollection>(conf.getParameter<edm::InputTag>("TrackCollection"))),
48  tokenIndToEdm_(consumes<IndToEdm>(conf.getParameter<edm::InputTag>("TrackCollection"))) {
49  produces<reco::VertexCollection>();
50 }
51 
54 
55  desc.add<edm::InputTag>("TrackCollection", edm::InputTag("pixelTracks"));
56  desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
57  desc.add<edm::InputTag>("src", edm::InputTag("pixelVerticesSoA"));
58 
59  descriptions.add("pixelVertexFromSoA", desc);
60 }
61 
63  auto vertexes = std::make_unique<reco::VertexCollection>();
64 
65  auto tracksHandle = iEvent.getHandle(tokenTracks_);
66  auto tracksSize = tracksHandle->size();
67  auto const &indToEdm = iEvent.get(tokenIndToEdm_);
68  auto bsHandle = iEvent.getHandle(tokenBeamSpot_);
69 
70  float x0 = 0, y0 = 0, z0 = 0, dxdz = 0, dydz = 0;
71  std::vector<int32_t> itrk;
72  itrk.reserve(64); // avoid first relocations
73  if (!bsHandle.isValid()) {
74  edm::LogWarning("PixelVertexProducer") << "No beamspot found. returning vertexes with (0,0,Z) ";
75  } else {
76  const reco::BeamSpot &bs = *bsHandle;
77  x0 = bs.x0();
78  y0 = bs.y0();
79  z0 = bs.z0();
80  dxdz = bs.dxdz();
81  dydz = bs.dydz();
82  }
83 
84  auto const &soa = *(iEvent.get(tokenVertex_).get());
85 
86  int nv = soa.nvFinal;
87 
88 #ifdef PIXVERTEX_DEBUG_PRODUCE
89  std::cout << "converting " << nv << " vertices "
90  << " from " << indToEdm.size() << " tracks" << std::endl;
91 #endif // PIXVERTEX_DEBUG_PRODUCE
92 
93  std::set<uint16_t> uind; // for verifing index consistency
94  for (int j = nv - 1; j >= 0; --j) {
95  auto i = soa.sortInd[j]; // on gpu sorted in ascending order....
96  assert(i < nv);
97  uind.insert(i);
98  assert(itrk.empty());
99  auto z = soa.zv[i];
100  auto x = x0 + dxdz * z;
101  auto y = y0 + dydz * z;
102  z += z0;
104  err(2, 2) = 1.f / soa.wv[i];
105  err(2, 2) *= 2.; // artifically inflate error
106  //Copy also the tracks (no intention to be efficient....)
107  for (auto k = 0U; k < indToEdm.size(); ++k) {
108  if (soa.idv[k] == int16_t(i))
109  itrk.push_back(k);
110  }
111  auto nt = itrk.size();
112  if (nt == 0) {
113 #ifdef PIXVERTEX_DEBUG_PRODUCE
114  std::cout << "vertex " << i << " with no tracks..." << std::endl;
115 #endif // PIXVERTEX_DEBUG_PRODUCE
116  continue;
117  }
118  if (nt < 2) {
119  itrk.clear();
120  continue;
121  } // remove outliers
122  (*vertexes).emplace_back(reco::Vertex::Point(x, y, z), err, soa.chi2[i], soa.ndof[i], nt);
123  auto &v = (*vertexes).back();
124  v.reserve(itrk.size());
125  for (auto it : itrk) {
126  assert(it < int(indToEdm.size()));
127  auto k = indToEdm[it];
128  if (k > tracksSize) {
129  edm::LogWarning("PixelVertexProducer") << "oops track " << it << " does not exists on CPU " << k;
130  continue;
131  }
132  auto tk = reco::TrackRef(tracksHandle, k);
133  v.add(tk);
134  }
135  itrk.clear();
136  }
137 
138  LogDebug("PixelVertexProducer") << ": Found " << vertexes->size() << " vertexes\n";
139  for (unsigned int i = 0; i < vertexes->size(); ++i) {
140  LogDebug("PixelVertexProducer") << "Vertex number " << i << " has " << (*vertexes)[i].tracksSize()
141  << " tracks with a position of " << (*vertexes)[i].z() << " +- "
142  << std::sqrt((*vertexes)[i].covariance(2, 2));
143  }
144 
145  // legacy logic....
146  if (vertexes->empty() && bsHandle.isValid()) {
147  const reco::BeamSpot &bs = *bsHandle;
148 
149  GlobalError bse(bs.rotatedCovariance3D());
150  if ((bse.cxx() <= 0.) || (bse.cyy() <= 0.) || (bse.czz() <= 0.)) {
152  we(0, 0) = 10000;
153  we(1, 1) = 10000;
154  we(2, 2) = 10000;
155  vertexes->push_back(reco::Vertex(bs.position(), we, 0., 0., 0));
156 
157  edm::LogInfo("PixelVertexProducer") << "No vertices found. Beamspot with invalid errors " << bse.matrix()
158  << "\nWill put Vertex derived from dummy-fake BeamSpot into Event.\n"
159  << (*vertexes)[0].x() << "\n"
160  << (*vertexes)[0].y() << "\n"
161  << (*vertexes)[0].z() << "\n";
162  } else {
163  vertexes->push_back(reco::Vertex(bs.position(), bs.rotatedCovariance3D(), 0., 0., 0));
164 
165  edm::LogInfo("PixelVertexProducer") << "No vertices found. Will put Vertex derived from BeamSpot into Event:\n"
166  << (*vertexes)[0].x() << "\n"
167  << (*vertexes)[0].y() << "\n"
168  << (*vertexes)[0].z() << "\n";
169  }
170  } else if (vertexes->empty() && !bsHandle.isValid()) {
171  edm::LogWarning("PixelVertexProducer") << "No beamspot and no vertex found. No vertex returned.";
172  }
173 
174  iEvent.put(std::move(vertexes));
175 }
176 
ConfigurationDescriptions.h
ZVertexSoA::wv
float wv[MAXVTX]
Definition: ZVertexSoA.h:16
edm::StreamID
Definition: StreamID.h:30
TrackExtra.h
DDAxes::y
PixelVertexProducerFromSoA::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PixelVertexProducerFromSoA.cc:52
AlgebraicSymMatrix33
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
Definition: AlgebraicROOTObjects.h:21
mps_fire.i
i
Definition: mps_fire.py:428
ESHandle.h
align::BeamSpot
Definition: StructureType.h:95
PixelVertexProducerFromSoA::tokenVertex_
edm::EDGetTokenT< ZVertexHeterogeneous > tokenVertex_
Definition: PixelVertexProducerFromSoA.cc:38
PixelVertexProducerFromSoA::tokenBeamSpot_
edm::EDGetTokenT< reco::BeamSpot > tokenBeamSpot_
Definition: PixelVertexProducerFromSoA.cc:39
nt
int nt
Definition: AMPTWrapper.h:42
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::Vertex::Error
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
cms::cuda::assert
assert(be >=bs)
PixelVertexProducerFromSoA
Definition: PixelVertexProducerFromSoA.cc:26
gpuVertexFinder::soa
ZVertexSoA * soa
Definition: gpuVertexFinder.cc:21
HeterogeneousSoA
Definition: HeterogeneousSoA.h:13
jets_cff.vertexes
vertexes
Definition: jets_cff.py:714
DDAxes::x
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
PixelVertexProducerFromSoA::produce
void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Definition: PixelVertexProducerFromSoA.cc:62
MakerMacros.h
cms::cuda::bs
bs
Definition: HistoContainer.h:76
PixelVertexProducerFromSoA::PixelVertexProducerFromSoA
PixelVertexProducerFromSoA(const edm::ParameterSet &iConfig)
Definition: PixelVertexProducerFromSoA.cc:44
TrackerTopologyRcd.h
Track.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
PixelVertexProducerFromSoA::tokenTracks_
edm::EDGetTokenT< reco::TrackCollection > tokenTracks_
Definition: PixelVertexProducerFromSoA.cc:40
OrphanHandle.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::BeamSpot
Definition: BeamSpot.h:21
DDAxes::z
IdealMagneticFieldRecord.h
ZVertexSoA::zv
float zv[MAXVTX]
Definition: ZVertexSoA.h:15
BeamSpotPI::dxdz
Definition: BeamSpotPayloadInspectorHelper.h:37
HLTMuonOfflineAnalyzer_cfi.z0
z0
Definition: HLTMuonOfflineAnalyzer_cfi.py:98
dqmdumpme.k
k
Definition: dqmdumpme.py:60
ParameterSetDescription.h
EDGetToken.h
PixelVertexProducerFromSoA::~PixelVertexProducerFromSoA
~PixelVertexProducerFromSoA() override=default
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
BeamSpotPI::dydz
Definition: BeamSpotPayloadInspectorHelper.h:38
ModuleDef.h
iEvent
int iEvent
Definition: GenABIO.cc:224
GlobalErrorBase< double, ErrorMatrixTag >
ZVertexHeterogeneous.h
ZVertexSoA::nvFinal
uint32_t nvFinal
Definition: ZVertexSoA.h:21
edm::EventSetup
Definition: EventSetup.h:58
ZVertexSoA::idv
int16_t idv[MAXTRACKS]
Definition: ZVertexSoA.h:14
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
InputTag.h
VertexFwd.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
reco::Vertex::Point
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
eostools.move
def move(src, dest)
Definition: eostools.py:511
Vertex.h
ZVertexSoA::chi2
float chi2[MAXVTX]
Definition: ZVertexSoA.h:17
ZVertexSoA::ndof
int32_t ndof[MAXTRACKS]
Definition: ZVertexSoA.h:19
PixelVertexProducerFromSoA::IndToEdm
std::vector< uint16_t > IndToEdm
Definition: PixelVertexProducerFromSoA.cc:28
EventSetup.h
ConsumesCollector.h
ParameterSet.h
EDProducer.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
ZVertexSoA::sortInd
uint16_t sortInd[MAXVTX]
Definition: ZVertexSoA.h:20
edm::InputTag
Definition: InputTag.h:15
PixelVertexProducerFromSoA::tokenIndToEdm_
edm::EDGetTokenT< IndToEdm > tokenIndToEdm_
Definition: PixelVertexProducerFromSoA.cc:41
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
reco::Vertex
Definition: Vertex.h:35