29 if (trackSelectionAlgorithm ==
"filter") {
31 }
else if (trackSelectionAlgorithm ==
"filterWithThreshold") {
34 throw VertexException(
"PrimaryVertexProducer: unknown track selection algorithm: " + trackSelectionAlgorithm);
40 if (clusteringAlgorithm ==
"gap") {
43 }
else if (clusteringAlgorithm ==
"DA") {
48 else if (clusteringAlgorithm ==
"DA_vect") {
51 }
else if (clusteringAlgorithm ==
"DA2D_vect") {
58 throw VertexException(
"PrimaryVertexProducer: unknown clustering algorithm: " + clusteringAlgorithm);
68 conf.
getParameter<std::vector<edm::ParameterSet> >(
"vertexCollections");
70 for (std::vector<edm::ParameterSet>::const_iterator algoconf =
vertexCollections.begin();
75 if (fitterAlgorithm ==
"KalmanVertexFitter") {
77 }
else if (fitterAlgorithm ==
"AdaptiveVertexFitter") {
80 throw VertexException(
"PrimaryVertexProducer: unknown algorithm: " + fitterAlgorithm);
83 algorithm.minNdof = algoconf->getParameter<
double>(
"minNdof");
84 algorithm.useBeamConstraint = algoconf->getParameter<
bool>(
"useBeamConstraint");
89 produces<reco::VertexCollection>(
algorithm.label);
96 throw VertexException(
"PrimaryVertexProducer: No algorithm specified. ");
99 "PrimaryVertexProducer: Running in Recovery mode and more than one algorithm specified. Please " 100 "only one algorithm.");
124 if (recoBeamSpotHandle.
isValid()) {
127 edm::LogError(
"UnusableBeamSpot") <<
"No beam spot available from EventSetup";
132 if ((beamVertexState.
error().
cxx() <= 0.) || (beamVertexState.
error().
cyy() <= 0.) ||
133 (beamVertexState.
error().
czz() <= 0.)) {
142 for (
auto const& old : oldVertices) {
143 if (!(old.isFake())) {
146 auto result = std::make_unique<reco::VertexCollection>();
161 std::vector<reco::TransientTrack> t_tks;
170 t_tks = (*theB).build(tks,
beamSpot);
173 std::cout <<
"RecoVertex/PrimaryVertexProducer" 174 <<
"Found: " << t_tks.size() <<
" reconstructed tracks" 185 std::cout <<
" clustering returned " <<
clusters.size() <<
" clusters from " << seltks.size()
186 <<
" selected tracks" << std::endl;
191 auto result = std::make_unique<reco::VertexCollection>();
194 std::vector<TransientVertex>
pvs;
195 for (
std::vector<std::vector<reco::TransientTrack> >::const_iterator iclus =
clusters.begin();
201 double meantime = 0.;
204 for (
const auto& tk : *iclus) {
205 const double time = tk.timeExt();
206 const double err = tk.dtErrorExt();
207 const double inverr =
err > 0. ? 1.0 /
err : 0.;
208 const double w = inverr * inverr;
213 meantime = sumwt / sumw;
214 double sumsq = sumwt2 - sumwt * sumwt / sumw;
215 double chisq = iclus->size() > 1 ? sumsq / double(iclus->size() - 1) : sumsq /
double(iclus->size());
216 vartime = chisq / sumw;
220 if (
algorithm->useBeamConstraint && validBS && (iclus->size() > 1)) {
222 }
else if (!(
algorithm->useBeamConstraint) && (iclus->size() > 1)) {
227 if (
f4D and
v.isValid()) {
228 auto err =
v.positionError().matrix4D();
230 auto trkWeightMap3d =
v.weightMap();
231 v =
TransientVertex(
v.position(), meantime,
err,
v.originalTracks(),
v.totalChiSquared(),
v.degreesOfFreedom());
232 v.weightMap(trkWeightMap3d);
240 std::cout <<
"=" <<
v.position().x() <<
" " <<
v.position().y() <<
" " <<
v.position().z();
243 std::cout <<
" cluster size = " << (*iclus).size() << std::endl;
245 std::cout <<
"Invalid fitted vertex, cluster size=" << (*iclus).size() << std::endl;
249 if (
v.isValid() && (
v.degreesOfFreedom() >=
algorithm->minNdof) &&
250 (!validBS || (*(
algorithm->vertexSelector))(
v, beamVertexState)))
255 std::cout <<
"PrimaryVertexProducerAlgorithm::vertices candidates =" <<
pvs.size() << std::endl;
260 <<
"more than half of candidate vertices lost " <<
pvs.size() <<
' ' <<
clusters.size();
262 if (
pvs.empty() && seltks.size() > 5)
264 <<
"no vertex found with " << seltks.size() <<
" tracks and " <<
clusters.size() <<
" vertex-candidates";
267 if (
pvs.size() > 1) {
272 for (std::vector<TransientVertex>::const_iterator
iv =
pvs.begin();
iv !=
pvs.end();
iv++) {
279 if ((bse.cxx() <= 0.) || (bse.cyy() <= 0.) || (bse.czz() <= 0.)) {
286 std::cout <<
"RecoVertex/PrimaryVertexProducer: " 287 <<
"Beamspot with invalid errors " << bse.matrix() << std::endl;
288 std::cout <<
"Will put Vertex derived from dummy-fake BeamSpot into Event.\n";
293 std::cout <<
"RecoVertex/PrimaryVertexProducer: " 294 <<
" will put Vertex derived from BeamSpot into Event.\n";
301 for (reco::VertexCollection::const_iterator
v = vColl.begin();
v != vColl.end(); ++
v) {
302 std::cout <<
"recvtx " << ivtx++ <<
"#trk " << std::setw(3) <<
v->tracksSize() <<
" chi2 " << std::setw(4)
303 <<
v->chi2() <<
" ndof " << std::setw(3) <<
v->ndof() <<
" x " << std::setw(6) <<
v->position().x()
304 <<
" dx " << std::setw(6) <<
v->xError() <<
" y " << std::setw(6) <<
v->position().y() <<
" dy " 305 << std::setw(6) <<
v->yError() <<
" z " << std::setw(6) <<
v->position().z() <<
" dz " << std::setw(6)
308 std::cout <<
" t " << std::setw(6) <<
v->t() <<
" dt " << std::setw(6) <<
v->tError();
323 vpsd1.
add<
double>(
"maxDistanceToBeam", 1.0);
325 vpsd1.
add<
bool>(
"useBeamConstraint",
false);
327 vpsd1.
add<
double>(
"chi2cutoff", 2.5);
328 vpsd1.
add<
double>(
"minNdof", 0.0);
329 std::vector<edm::ParameterSet> temp1;
339 temp1.push_back(temp2);
349 temp1.push_back(temp2);
351 desc.addVPSet(
"vertexCollections", vpsd1, temp1);
353 desc.addUntracked<
bool>(
"verbose",
false);
357 psd0.
add<
int>(
"numTracksThreshold", 0);
358 psd0.
add<
int>(
"maxNumTracksThreshold", 10000000);
359 psd0.
add<
double>(
"minPtTight", 0.0);
382 desc.add<
bool>(
"isRecoveryIteration",
false);
385 descriptions.
add(
"primaryVertexProducer",
desc);
T getParameter(std::string const &) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< reco::BeamSpot > bsToken
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > theTTBToken
std::vector< algo > algorithms
~PrimaryVertexProducer() override
edm::EDGetTokenT< reco::VertexCollection > recoveryVtxToken
T const * product() const
edm::EDGetTokenT< reco::TrackCollection > trkToken
TrackClusterizerInZ * theTrackClusterizer
std::vector< Vertex > VertexCollection
collection of Vertex objects
Log< level::Error, false > LogError
edm::EDGetTokenT< edm::ValueMap< float > > trkTimesToken
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< edm::ValueMap< float > > trkTimeResosToken
static void fillPSetDescription(edm::ParameterSetDescription &desc)
virtual std::vector< std::vector< reco::TransientTrack > > clusterize(const std::vector< reco::TransientTrack > &tracks) const =0
void addParameter(std::string const &name, T const &value)
GlobalError error() const
TrackFilterForPVFindingBase * theTrackFilter
#define DEFINE_FWK_MODULE(type)
const AlgebraicSymMatrix33 matrix() const
bool getData(T &iHolder) const
virtual std::vector< reco::TransientTrack > select(const std::vector< reco::TransientTrack > &tracks) const =0
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillPSetDescription(edm::ParameterSetDescription &desc)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::Event &, const edm::EventSetup &) override
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
PrimaryVertexProducer(const edm::ParameterSet &)
static void fillPSetDescription(edm::ParameterSetDescription &desc)