Rivet API documentation

Rivet 4.1.3
LHCbCommon.hh
1#ifndef PROJECTIONS_LHCBCOMMON_HH
2#define PROJECTIONS_LHCBCOMMON_HH
3
4#include "Rivet/Projections/FinalState.hh"
5#include "Rivet/Projections/PrimaryParticles.hh"
6#include "Rivet/Projections/UnstableParticles.hh"
7
8
9namespace Rivet {
11
12 namespace LHCb {
13
15 class HVRecoFinalState : public FinalState {
16 protected:
17
18 Rivet::Particles _theHFHadrons;
19 Cut _hfcuts;
20
21 public:
22
23 HVRecoFinalState(const Cut& c = Cuts::abseta > 2.0 && Cuts::abseta < 5.0,
24 const vector<PdgId>& Hadrons = {},
25 const Cut& hadcut = Cuts::OPEN)
26 : FinalState(c), _theHFHadrons(), _hfcuts(hadcut) {
27 setName("LHCb::HVRecoFinalState");
28 // accept only charged heavy-flavour hadrons and prepare Cut for UnstableParticles projection
29 Cut cpid = Cuts::OPEN;
30 for (const PdgId& id : Hadrons) {
31 if (!PID::isHadron(id)) continue;
32 if (PID::threeCharge(id) == 0) continue;
33 if (!PID::isHeavyFlavour(id)) continue;
34 if (cpid == Cuts::OPEN)
35 cpid = (Cuts::pid == id);
36 else
37 cpid = cpid || (Cuts::pid == id);
38 };
39 if ((hadcut == Cuts::OPEN) && (c != Cuts::OPEN)) _hfcuts = c;
40 if (cpid != Cuts::OPEN) _hfcuts = cpid && _hfcuts;
41 const UnstableParticles hvhad(_hfcuts);
42 this->declare(hvhad, "HVHadrons");
43 }
44
45 virtual ~HVRecoFinalState() { }
46
47 virtual void project(const Event& e) {
48 _theHFHadrons.clear();
49 _theHFHadrons = apply<UnstableParticles>(e, "HVHadrons").particles();
50 if (_theHFHadrons.empty()) { //event needs to be vetoed in analyze if no HV hadrons found
51 _theParticles.clear();
52 return;
53 }
54 MSG_DEBUG("Found " << _theHFHadrons.size() << " heavy-flavour hadrons in event");
56 if (_theParticles.empty()) {
57 MSG_DEBUG("No particles in final state.");
58 return;
59 }
60 MSG_DEBUG("Final state contains " << _theParticles.size()
61 << " particles before adding heavy-flavour hadrons");
62 // add heavy flavour hadrons to final state and remove descendants (avoid double-counting)
63 _theParticles = _theParticles + _theHFHadrons;
64 MSG_DEBUG("Added heavy-flavour hadrons to final state, now " << _theParticles.size()
65 << " particles in final state");
66 Particles to_remove = {};
67 for (const Particle& p : _theHFHadrons) {
68 to_remove = to_remove + p.stableDescendants();
69 };
70 MSG_DEBUG("Marked " << to_remove.size()
71 << " stable descendants of heavy-flavour hadrons for removal from final state");
72 // eliminate descendants based on GenParticlePtr (better match?)
73 idiscard(_theParticles, [&](Particle& p) {
74 bool found = false;
75 for (const Particle& r : to_remove)
76 if (p.genParticle() == r.genParticle()) {
77 found = true;
78 break;
79 };
80 return found;
81 });
82 MSG_DEBUG("Removed stable descendants of heavy-flavour hadrons from final state, now "
83 << _theParticles.size() << " particles in final state. Project done!");
84 to_remove.clear();
85 return;
86 }
87
92 return _theHFHadrons;
93 }
94
98 virtual std::unique_ptr<Rivet::Projection> clone() const {
99 return std::unique_ptr<Projection>(new HVRecoFinalState(*this));
100 }
101
103 using Projection::operator=;
104
108 virtual CmpState compare(const Projection& p) const {
109 if (FinalState::compare(p) == CmpState::NEQ) return CmpState::NEQ;
110 const HVRecoFinalState& other = dynamic_cast<const HVRecoFinalState&>(p);
111 if (hasProjection("HVHadrons") != other.hasProjection("HVHadrons")) return CmpState::NEQ;
112 if (hasProjection("HVHadrons")) {
113 const PCmp prevcmp = mkPCmp(other, "HVHadrons");
114 if (prevcmp != CmpState::EQ) return CmpState::NEQ;
115 }
116 const bool hfcutcmp = _hfcuts == other._hfcuts;
117 MSG_TRACE(_hfcuts << " VS " << other._hfcuts << " -> EQ == " << std::boolalpha << hfcutcmp);
118 if (!hfcutcmp) return CmpState::NEQ;
119 // Checks all passed: these FSes are equivalent
120 return CmpState::EQ;
121 }
122 };
123
124
125 }
126}
127
128#endif
virtual void project(const Event &e)
Apply the projection to the event.
FinalState(const Cut &c=Cuts::OPEN)
Construction using Cuts object.
virtual CmpState compare(const Projection &p) const
Compare projections.
virtual CmpState compare(const Projection &p) const
Definition LHCbCommon.hh:108
virtual std::unique_ptr< Rivet::Projection > clone() const
Definition LHCbCommon.hh:98
Particles hfHadrons() const
Definition LHCbCommon.hh:91
virtual void project(const Event &e)
Apply the projection to the event.
Definition LHCbCommon.hh:47
Particle representation, either from a HepMC::GenEvent or reconstructed.
Definition Particle.hh:50
Specialised vector of Particle objects.
Definition Particle.hh:21
std::enable_if_t< std::is_base_of< Projection, PROJ >::value, const PROJ & > apply(const Event &evt, const Projection &proj) const
Apply the supplied projection on event evt.
Definition ProjectionApplier.hh:124
const PROJ & declare(const PROJ &proj, const std::string &name) const
Register a contained projection (user-facing version).
Definition ProjectionApplier.hh:205
bool hasProjection(const std::string &name) const
Does this applier have a projection registered under the name name?
Definition ProjectionApplier.hh:55
Projection()
The default constructor.
friend class Event
Event is a friend.
Definition Projection.hh:33
Cmp< Projection > mkPCmp(const Projection &otherparent, const std::string &pname) const
void setName(const std::string &name)
Used by derived classes to set their name.
Definition Projection.hh:146
Project out all physical-but-decayed particles in an event.
Definition UnstableParticles.hh:26
Jets & idiscard(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
#define MSG_TRACE(x)
Lowest-level, most verbose messaging, using MSG_LVL.
Definition Logging.hh:193
#define MSG_DEBUG(x)
Debug messaging, not enabled by default, using MSG_LVL.
Definition Logging.hh:195
int threeCharge(int pid)
Definition ParticleIdUtils.hh:1020
bool isHeavyFlavour(int pid)
British-spelling alias for isHeavyFlavor.
Definition ParticleIdUtils.hh:709
bool isHadron(int pid)
Definition ParticleIdUtils.hh:415
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:819
Common projections for LHCb specific conditions.
Definition LHCbCommon.hh:12
Definition LHCbCommon.hh:9
Cmp< Projection > PCmp
Typedef for Cmp<Projection>.
Definition Cmp.hh:259