Rivet API documentation

Rivet 4.1.3
BeamConstraint.hh
1// -*- C++ -*-
2#ifndef RIVET_BeamConstraint_HH
3#define RIVET_BeamConstraint_HH
4
5#include "Rivet/Tools/Beams.hh"
6#include "Rivet/Tools/ParticleName.hh"
7
8namespace Rivet {
9
10
13
14
18 inline bool compatibleBeamID(PdgId p, PdgId allowed) {
19 return (allowed == PID::ANY || p == allowed);
20 }
21
26 inline bool compatibleBeamIDs(const PdgIdPair& pair, const PdgIdPair& allowedpair) {
27 const bool oneToOne = compatibleBeamID(pair.first, allowedpair.first);
28 const bool twoToTwo = compatibleBeamID(pair.second, allowedpair.second);
29 const bool oneToTwo = compatibleBeamID(pair.first, allowedpair.second);
30 const bool twoToOne = compatibleBeamID(pair.second, allowedpair.first);
31 return (oneToOne && twoToTwo) || (oneToTwo && twoToOne);
32 }
33
35 inline bool compatibleBeamIDs(const ParticlePair& ppair, const PdgIdPair& allowedpair) {
36 return compatibleBeamIDs(PID::make_pdgid_pair(ppair.first.pid(), ppair.second.pid()), allowedpair);
37 }
38
40 inline bool compatibleBeamIDs(const ParticlePair& a, const ParticlePair& b) {
41 return compatibleBeamIDs(PID::make_pdgid_pair(a.first.pid(), a.second.pid()),
42 PID::make_pdgid_pair(b.first.pid(), b.second.pid()));
43 }
44
45
47 inline bool compatibleBeamEnergies(const pair<double, double>& energies,
48 const pair<double, double>& allowedenergies,
49 const double reltol = 1e-3) {
50 const bool oneToOne = fuzzyEquals(energies.first, allowedenergies.first, reltol);
51 const bool twoToTwo = fuzzyEquals(energies.second, allowedenergies.second, reltol);
52 const bool oneToTwo = fuzzyEquals(energies.first, allowedenergies.second, reltol);
53 const bool twoToOne = fuzzyEquals(energies.second, allowedenergies.first, reltol);
54 const bool absDiffOneToOne = abs(energies.first - allowedenergies.first) < 1 * GeV;
55 const bool absDiffTwoToTwo = abs(energies.second - allowedenergies.second) < 1 * GeV;
56 const bool absDiffOneToTwo = abs(energies.first - allowedenergies.second) < 1 * GeV;
57 const bool absDiffTwoToOne = abs(energies.second - allowedenergies.first) < 1 * GeV;
58 return (oneToOne && twoToTwo) || (oneToTwo && twoToOne) || (absDiffOneToOne && absDiffTwoToTwo)
59 || (absDiffOneToTwo && absDiffTwoToOne);
60 }
61
63 inline bool compatibleBeamEnergies(const ParticlePair& ppair,
64 const pair<double, double>& allowedenergies,
65 double reltol = 1e-3) {
66 return compatibleBeamEnergies(make_pair(ppair.first.E(), ppair.second.E()), allowedenergies, reltol);
67 }
68
70 inline bool compatibleBeamEnergies(const ParticlePair& ppair,
71 const ParticlePair& allowedppair,
72 double reltol = 1e-3) {
73 return compatibleBeamEnergies(make_pair(ppair.first.E(), ppair.second.E()),
74 make_pair(allowedppair.first.E(), allowedppair.second.E()), reltol);
75 }
76
77
79 inline bool compatibleBeamEnergy(const pair<double, double>& energies,
80 double allowedsqrts,
81 double reltol = 1e-3) {
82 return fuzzyEquals(sqrtS(energies.first, energies.second), allowedsqrts, reltol);
83 }
84
86 inline bool compatibleBeamEnergy(const ParticlePair& ppair,
87 const pair<double, double>& allowedenergies,
88 double reltol = 1e-3) {
89 return fuzzyEquals(sqrtS(ppair), sqrtS(allowedenergies), reltol);
90 }
91
93 inline bool compatibleBeamEnergy(const ParticlePair& ppair,
94 const double allowedsqrts,
95 double reltol = 1e-3) {
96 return fuzzyEquals(sqrtS(ppair), allowedsqrts, reltol);
97 }
98
99
101 inline bool compatibleBeams(const ParticlePair& ppair, const PdgIdPair& allowedpids, double allowedsqrts) {
102 return compatibleBeamIDs(ppair, allowedpids) && compatibleBeamEnergy(ppair, allowedsqrts);
103 }
104
106 inline bool compatibleBeams(const ParticlePair& ppair,
107 const PdgIdPair& allowedpids,
108 const pair<double, double>& allowedenergies) {
109 return compatibleBeamIDs(ppair, allowedpids) && compatibleBeamEnergies(ppair, allowedenergies);
110 }
111
113 inline bool compatibleBeams(const ParticlePair& a, const ParticlePair& b) {
114 return compatibleBeamIDs(a, b) && compatibleBeamEnergies(a, b);
115 }
116
118
119
120 // /// Find whether PdgIdPair @a pair is compatible with at least one template beam pair in a set @a allowedpairs
121 // inline bool anyCompatibleBeamIDs(const PdgIdPair& pair, const set<PdgIdPair>& allowedpairs) {
122 // for (const PdgIdPair& bp : allowedpairs)
123 // if (compatibleBeamIDs(pair, bp)) return true;
124 // return false;
125 // }
126
127 // /// Return the intersection of two sets of {PdgIdPair}s.
128 // inline set<PdgIdPair> intersection(const set<PdgIdPair>& a, const set<PdgIdPair>& b) {
129 // set<PdgIdPair> ret;
130 // for (set<PdgIdPair>::const_iterator bp = a.begin(); bp != a.end(); ++bp) {
131 // if (compatibleBeamIDs(*bp, b)) ret.insert(*bp);
132 // }
133 // return ret;
134 // }
135
136
137}
138
139#endif
bool compatibleBeamEnergy(const pair< double, double > &energies, double allowedsqrts, double reltol=1e-3)
Check the sqrt(s) compatibility of two massless opposing beams.
Definition BeamConstraint.hh:79
bool compatibleBeams(const ParticlePair &ppair, const PdgIdPair &allowedpids, double allowedsqrts)
Check the particle ID and beam-energy compatibility of two Particle pairs.
Definition BeamConstraint.hh:101
bool compatibleBeamEnergies(const pair< double, double > &energies, const pair< double, double > &allowedenergies, const double reltol=1e-3)
Check the energy compatibility of two pairs of particle energies.
Definition BeamConstraint.hh:47
bool compatibleBeamID(PdgId p, PdgId allowed)
Find whether ParticleName p is compatible with the template ParticleName allowed.
Definition BeamConstraint.hh:18
bool compatibleBeamIDs(const PdgIdPair &pair, const PdgIdPair &allowedpair)
Find whether PdgIdPair pair is compatible with the template PdgIdPair allowedpair.
Definition BeamConstraint.hh:26
double sqrtS(double ea, double eb)
Get beam centre-of-mass energy from a pair of beam energies.
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:819
Definition LHCbCommon.hh:9
std::pair< Particle, Particle > ParticlePair
Typedef for a pair of Particle objects.
Definition Particle.hh:43
std::enable_if_t< std::is_arithmetic_v< N1 > &&std::is_arithmetic_v< N2 > &&(std::is_floating_point_v< N1 >||std::is_floating_point_v< N2 >), bool > fuzzyEquals(N1 a, N2 b, double tolerance=1e-5)
Compare two numbers for equality with a degree of fuzziness.
Definition MathUtils.hh:66