Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-27 07:02:49

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Whitney Armstrong, Sylvester Joosten
0003 
0004 #ifndef EDM4EIC_UTILS_ANALYSIS_HH
0005 #define EDM4EIC_UTILS_ANALYSIS_HH
0006 
0007 #include <algorithm>
0008 #include <cmath>
0009 #include <exception>
0010 #include <limits>
0011 #include <string>
0012 #include <vector>
0013 
0014 #include <Math/Vector4D.h>
0015 
0016 #include <edm4eic/ReconstructedParticleCollection.h>
0017 #include <edm4eic/ReconstructedParticleData.h>
0018 #include <edm4eic/TrackParametersCollection.h>
0019 
0020 namespace edm4eic {
0021 
0022 /** Four momentum from track and mass.
0023  * Get a vector of 4-momenta from raw tracking info, using an externally
0024  * provided particle mass assumption.
0025  */
0026 inline auto
0027 momenta_from_tracking(const std::vector<edm4eic::TrackParametersData>& tracks,
0028                       const double mass) {
0029   std::vector<ROOT::Math::PxPyPzMVector> momenta{tracks.size()};
0030   // transform our raw tracker info into proper 4-momenta
0031   std::transform(tracks.begin(), tracks.end(), momenta.begin(),
0032                  [mass](const auto& track) {
0033                    // make sure we don't divide by zero
0034                    if (fabs(track.qOverP) < 1e-9) {
0035                      return ROOT::Math::PxPyPzMVector{};
0036                    }
0037                    const double p = fabs(1. / track.qOverP);
0038                    const double px = p * cos(track.phi) * sin(track.theta);
0039                    const double py = p * sin(track.phi) * sin(track.theta);
0040                    const double pz = p * cos(track.theta);
0041                    return ROOT::Math::PxPyPzMVector{px, py, pz, mass};
0042                  });
0043   return momenta;
0044 }
0045 } // namespace edm4eic
0046 #endif