Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 08:29:09

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 - 2024, Sylvester Joosten, Wouter Deconinck, Dmitry Romanov, Christopher Dilks, Dmitry Kalinkin
0003 
0004 #include <edm4eic/TrackParametersCollection.h>
0005 #include <edm4eic/TrajectoryCollection.h>
0006 #include <edm4hep/MCParticleCollection.h>
0007 #include <edm4hep/Vector3f.h>
0008 #include <edm4hep/utils/vector_utils.h>
0009 #include <podio/ObjectID.h>
0010 #include <podio/RelationRange.h>
0011 #include <podio/detail/Link.h>
0012 #include <podio/detail/LinkCollectionImpl.h>
0013 #include <cmath>
0014 #include <memory>
0015 #include <tuple>
0016 #include <vector>
0017 
0018 #include "TracksToParticles.h"
0019 
0020 namespace eicrecon {
0021 
0022 void TracksToParticles::init() {}
0023 
0024 void TracksToParticles::process(const TracksToParticles::Input& input,
0025                                 const TracksToParticles::Output& output) const {
0026   const auto [tracks, track_assocs]     = input;
0027   auto [parts, part_links, part_assocs] = output;
0028 
0029   for (const auto& track : *tracks) {
0030     auto trajectory = track.getTrajectory();
0031     for (const auto& trk : trajectory.getTrackParameters()) {
0032       const auto mom        = edm4hep::utils::sphericalToVector(1.0 / std::abs(trk.getQOverP()),
0033                                                                 trk.getTheta(), trk.getPhi());
0034       const auto charge_rec = std::copysign(1., trk.getQOverP());
0035 
0036       debug("Converting track: index={:<4} momentum={:<8.3f} theta={:<8.3f} phi={:<8.2f} "
0037             "charge={:<4}",
0038             trk.getObjectID().index, edm4hep::utils::magnitude(mom),
0039             edm4hep::utils::anglePolar(mom), edm4hep::utils::angleAzimuthal(mom), charge_rec);
0040 
0041       auto rec_part = parts->create();
0042       rec_part.addToTracks(track);
0043       rec_part.setType(0);
0044       rec_part.setEnergy(edm4hep::utils::magnitude(mom));
0045       rec_part.setMomentum(mom);
0046       rec_part.setCharge(charge_rec);
0047       rec_part.setMass(0.);
0048       rec_part.setGoodnessOfPID(0); // assume no PID until proven otherwise
0049       rec_part.setReferencePoint(track.getPosition());
0050       // rec_part.covMatrix()  // @TODO: covariance matrix on 4-momentum
0051 
0052       for (auto track_assoc : *track_assocs) {
0053         if (track_assoc.getRec() == track) {
0054           trace("Found track association: index={} -> index={}, weight={}",
0055                 track_assoc.getRec().getObjectID().index, track_assoc.getSim().getObjectID().index,
0056                 track_assoc.getWeight());
0057           auto part_link = part_links->create();
0058           part_link.setFrom(rec_part);
0059           part_link.setTo(track_assoc.getSim());
0060           part_link.setWeight(track_assoc.getWeight());
0061           auto part_assoc = part_assocs->create();
0062           part_assoc.setRec(rec_part);
0063           part_assoc.setSim(track_assoc.getSim());
0064           part_assoc.setWeight(track_assoc.getWeight());
0065         }
0066       }
0067     }
0068   }
0069 }
0070 } // namespace eicrecon