Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:06:50

0001 // -*- C++ -*-
0002 #ifndef RIVET_BeamConstraint_HH
0003 #define RIVET_BeamConstraint_HH
0004 
0005 #include "Rivet/Tools/Beams.hh"
0006 #include "Rivet/Tools/ParticleName.hh"
0007 
0008 namespace Rivet {
0009 
0010 
0011   /// @defgroup beam_constraints Standalone beam-compatibility functions
0012   /// @{
0013 
0014 
0015   /// @brief Find whether ParticleName @a p is compatible with the template ParticleName @a allowed
0016   ///
0017   /// Effectively this is asking whether @a p is a subset of @a allowed.
0018   inline bool compatibleBeamID(PdgId p, PdgId allowed) {
0019     return (allowed == PID::ANY || p == allowed);
0020   }
0021 
0022   /// @brief Find whether PdgIdPair @a pair is compatible with the template PdgIdPair @a allowedpair
0023   ///
0024   /// This assesses whether either of the two possible pairings of @a pair's
0025   /// constituents is compatible.
0026   inline bool compatibleBeamIDs(const PdgIdPair& pair, const PdgIdPair& allowedpair) {
0027     const bool oneToOne = compatibleBeamID(pair.first, allowedpair.first);
0028     const bool twoToTwo = compatibleBeamID(pair.second, allowedpair.second);
0029     const bool oneToTwo = compatibleBeamID(pair.first, allowedpair.second);
0030     const bool twoToOne = compatibleBeamID(pair.second, allowedpair.first);
0031     return (oneToOne && twoToTwo) || (oneToTwo && twoToOne);
0032   }
0033 
0034   /// Check particle compatibility of two Particle pairs
0035   inline bool compatibleBeamIDs(const ParticlePair& ppair, const PdgIdPair& allowedpair) {
0036     return compatibleBeamIDs(PID::make_pdgid_pair(ppair.first.pid(), ppair.second.pid()), allowedpair);
0037   }
0038 
0039   /// Check particle compatibility of two Particle pairs
0040   inline bool compatibleBeamIDs(const ParticlePair& a, const ParticlePair& b) {
0041     return compatibleBeamIDs(PID::make_pdgid_pair(a.first.pid(), a.second.pid()),
0042                              PID::make_pdgid_pair(b.first.pid(), b.second.pid()) );
0043   }
0044 
0045 
0046   /// Check the energy compatibility of two pairs of particle energies
0047   inline bool compatibleBeamEnergies(const pair<double,double>& energies,
0048                                      const pair<double,double>& allowedenergies, const double reltol=1e-3) {
0049     const bool oneToOne = fuzzyEquals(energies.first,  allowedenergies.first,  reltol);
0050     const bool twoToTwo = fuzzyEquals(energies.second, allowedenergies.second, reltol);
0051     const bool oneToTwo = fuzzyEquals(energies.first,  allowedenergies.second, reltol);
0052     const bool twoToOne = fuzzyEquals(energies.second, allowedenergies.first,  reltol);
0053     const bool absDiffOneToOne = abs(energies.first - allowedenergies.first)   < 1*GeV;
0054     const bool absDiffTwoToTwo = abs(energies.second - allowedenergies.second) < 1*GeV;
0055     const bool absDiffOneToTwo = abs(energies.first - allowedenergies.second)  < 1*GeV;
0056     const bool absDiffTwoToOne = abs(energies.second - allowedenergies.first)  < 1*GeV;
0057     return (oneToOne && twoToTwo) || (oneToTwo && twoToOne) ||
0058            (absDiffOneToOne && absDiffTwoToTwo) || (absDiffOneToTwo && absDiffTwoToOne);
0059   }
0060 
0061   /// Check the energy compatibility of a pair of particles
0062   inline bool compatibleBeamEnergies(const ParticlePair& ppair,
0063                                      const pair<double,double>& allowedenergies, double reltol=1e-3) {
0064     return compatibleBeamEnergies(make_pair(ppair.first.E(), ppair.second.E()), allowedenergies, reltol);
0065   }
0066 
0067   /// Check the energy compatibility of two Particle pairs
0068   inline bool compatibleBeamEnergies(const ParticlePair& ppair,
0069                                      const ParticlePair& allowedppair, double reltol=1e-3) {
0070     return compatibleBeamEnergies(make_pair(ppair.first.E(), ppair.second.E()),
0071                                   make_pair(allowedppair.first.E(), allowedppair.second.E()), reltol);
0072   }
0073 
0074 
0075   /// Check the sqrt(s) compatibility of two massless opposing beams
0076   inline bool compatibleBeamEnergy(const pair<double,double>& energies, double allowedsqrts, double reltol=1e-3) {
0077     return fuzzyEquals(sqrtS(energies.first, energies.second), allowedsqrts, reltol);
0078   }
0079 
0080   /// Check the sqrt(s) compatibility of two massless opposing beams
0081   inline bool compatibleBeamEnergy(const ParticlePair& ppair,
0082                                    const pair<double,double>& allowedenergies, double reltol=1e-3) {
0083     return fuzzyEquals(sqrtS(ppair), sqrtS(allowedenergies), reltol);
0084   }
0085 
0086   /// Check the sqrt(s) compatibility of a Particle pair
0087   inline bool compatibleBeamEnergy(const ParticlePair& ppair,
0088                                    const double allowedsqrts, double reltol=1e-3) {
0089     return fuzzyEquals(sqrtS(ppair), allowedsqrts, reltol);
0090   }
0091 
0092 
0093   /// Check the particle ID and beam-energy compatibility of two Particle pairs
0094   inline bool compatibleBeams(const ParticlePair& ppair, const PdgIdPair& allowedpids, double allowedsqrts) {
0095     return compatibleBeamIDs(ppair, allowedpids) && compatibleBeamEnergy(ppair, allowedsqrts);
0096   }
0097 
0098   /// Check the particle ID and beam-energy compatibility of two Particle pairs
0099   inline bool compatibleBeams(const ParticlePair& ppair, const PdgIdPair& allowedpids, const pair<double,double>& allowedenergies) {
0100     return compatibleBeamIDs(ppair, allowedpids) && compatibleBeamEnergies(ppair, allowedenergies);
0101   }
0102 
0103   /// Check the particle ID and beam-energy compatibility of two Particle pairs
0104   inline bool compatibleBeams(const ParticlePair& a, const ParticlePair& b) {
0105     return compatibleBeamIDs(a, b) && compatibleBeamEnergies(a, b);
0106   }
0107 
0108   /// @}
0109 
0110 
0111 
0112   // /// Find whether PdgIdPair @a pair is compatible with at least one template beam pair in a set @a allowedpairs
0113   // inline bool anyCompatibleBeamIDs(const PdgIdPair& pair, const set<PdgIdPair>& allowedpairs) {
0114   //   for (const PdgIdPair& bp : allowedpairs)
0115   //     if (compatibleBeamIDs(pair, bp)) return true;
0116   //   return false;
0117   // }
0118 
0119   // /// Return the intersection of two sets of {PdgIdPair}s.
0120   // inline set<PdgIdPair> intersection(const set<PdgIdPair>& a, const set<PdgIdPair>& b) {
0121   //   set<PdgIdPair> ret;
0122   //   for (set<PdgIdPair>::const_iterator bp = a.begin(); bp != a.end(); ++bp) {
0123   //     if (compatibleBeamIDs(*bp, b)) ret.insert(*bp);
0124   //   }
0125   //   return ret;
0126   // }
0127 
0128 
0129 
0130 }
0131 
0132 #endif