File indexing completed on 2024-09-27 07:03:00
0001
0002
0003
0004 #include <edm4eic/ReconstructedParticle.h>
0005 #include <edm4eic/VertexCollection.h>
0006 #include <edm4eic/unit_system.h>
0007 #include <edm4hep/Vector4f.h>
0008 #include <fmt/core.h>
0009 #include <podio/RelationRange.h>
0010 #include <cmath>
0011 #include <functional>
0012 #include <gsl/pointers>
0013 #include <map>
0014
0015 #include "algorithms/reco/PrimaryVertices.h"
0016 #include "algorithms/reco/PrimaryVerticesConfig.h"
0017
0018 namespace eicrecon {
0019
0020
0021
0022
0023
0024 void PrimaryVertices::init() {
0025 }
0026
0027
0028
0029
0030
0031
0032
0033 void PrimaryVertices::process(const PrimaryVertices::Input& input,
0034 const PrimaryVertices::Output& output) const {
0035 const auto [rcvtx] = input;
0036 auto [out_primary_vertices] = output;
0037
0038
0039
0040
0041 std::multimap<int, edm4eic::Vertex, std::greater<int>> primaryVertexMap;
0042
0043
0044
0045 out_primary_vertices->setSubsetCollection();
0046
0047 trace("We have {} candidate vertices", rcvtx->size());
0048
0049 for (const auto& vtx: *rcvtx) {
0050 const auto &v = vtx.getPosition();
0051
0052
0053 if (sqrt( v.x*v.x + v.y*v.y ) / edm4eic::unit::mm > m_cfg.maxVr ||
0054 fabs( v.z ) / edm4eic::unit::mm > m_cfg.maxVz )
0055 continue;
0056
0057 if (vtx.getChi2() > m_cfg.maxChi2) continue;
0058
0059 int N_trk = vtx.getAssociatedParticles().size();
0060 trace( "\t N_trk = {}", N_trk );
0061 primaryVertexMap.insert({N_trk, vtx});
0062 }
0063
0064 bool first = true;
0065
0066 for (auto [N_trk, vertex] : primaryVertexMap) {
0067
0068
0069 if ( N_trk > m_cfg.maxNtrk
0070 || N_trk < m_cfg.minNtrk ){
0071 continue;
0072 }
0073
0074
0075
0076 if (first) {
0077 trace("Max N_trk Candidate:");
0078 trace("\t N_trk = {}", N_trk);
0079 trace("\t Primary vertex has xyz=( {}, {}, {} )", vertex.getPosition().x, vertex.getPosition().y, vertex.getPosition().z);
0080 first = false;
0081 }
0082 out_primary_vertices->push_back(vertex);
0083 }
0084 }
0085 }