Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-09 08:25:49

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2026 Wouter Deconinck, Barak Schmookler, Stephen Maple
0003 
0004 #pragma once
0005 
0006 #include <Math/Vector4D.h>
0007 #include <Math/LorentzRotation.h>
0008 #include <Math/LorentzVector.h>
0009 #include <Math/RotationX.h>
0010 #include <Math/RotationY.h>
0011 #include <Math/Boost.h>
0012 
0013 using ROOT::Math::PxPyPzEVector;
0014 
0015 namespace eicrecon {
0016 
0017 using ROOT::Math::LorentzRotation;
0018 
0019 inline LorentzRotation determine_boost(PxPyPzEVector ei, PxPyPzEVector pi) {
0020 
0021   using ROOT::Math::Boost;
0022   using ROOT::Math::RotationX;
0023   using ROOT::Math::RotationY;
0024 
0025   // Save original input for constructing target "head-on" boost
0026   PxPyPzEVector eo = ei;
0027   PxPyPzEVector po = pi;
0028 
0029   // Step 1: Boost to CM frame
0030   const auto cmBoost = (ei + pi).BoostToCM();
0031   const Boost boost_from_og_to_cm(cmBoost);
0032 
0033   ei = boost_from_og_to_cm(ei);
0034   pi = boost_from_og_to_cm(pi);
0035 
0036   // Step 2: Rotate so pi is aligned along +z
0037   RotationY rotAboutY(-1.0 * atan2(pi.Px(), pi.Pz()));
0038   RotationX rotAboutX(+1.0 * atan2(pi.Py(), pi.Pz()));
0039 
0040   ei = rotAboutX(rotAboutY(ei));
0041   pi = rotAboutX(rotAboutY(pi));
0042 
0043   // Step 3: Construct "ideal" head-on configuration (same energies, back-to-back along z)
0044   double e_energy = eo.E();
0045   double p_energy = po.E();
0046   double e_pz     = -eo.P();
0047   double p_pz     = +po.P();
0048 
0049   PxPyPzEVector eh(0, 0, e_pz, e_energy);
0050   PxPyPzEVector ph(0, 0, p_pz, p_energy);
0051 
0052   // Step 4: Boost to the frame where those particles look like the current ei/pi
0053   const auto hoBoost = (eh + ph).BoostToCM();    // CM of head-on frame
0054   const Boost boost_from_cm_to_headon(-hoBoost); // Boost from CM to head-on
0055 
0056   // Final transformation = headon boost * rotations * CM boost
0057   LorentzRotation tf;
0058   tf *= boost_from_cm_to_headon;
0059   tf *= rotAboutX;
0060   tf *= rotAboutY;
0061   tf *= boost_from_og_to_cm;
0062 
0063   return tf;
0064 }
0065 
0066 inline PxPyPzEVector apply_boost(const LorentzRotation& tf, const PxPyPzEVector& part) {
0067 
0068   // Step 5: Apply boosts and rotations to any particle 4-vector
0069   // (here too, choices will have to be made as to what the 4-vector is for reconstructed particles)
0070 
0071   // Boost and rotate particle 4-momenta into the headon frame
0072   return tf(part);
0073 }
0074 
0075 } // namespace eicrecon