CMS 3D CMS Logo

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