Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef RIVET_JETUTILS_HH
0002 #define RIVET_JETUTILS_HH
0003 
0004 #include "Rivet/Jet.hh"
0005 #include "Rivet/Tools/ParticleBaseUtils.hh"
0006 
0007 namespace Rivet {
0008 
0009 
0010   /// @defgroup jetutils Functions for Jets
0011   /// @{
0012 
0013   /// @defgroup jetutils_conv Converting between Jets, Particles and PseudoJets
0014   /// @{
0015 
0016   inline PseudoJets mkPseudoJets(const Particles& ps) {
0017     PseudoJets rtn; rtn.reserve(ps.size());
0018     for (const Particle& p : ps) rtn.push_back(p.pseudojet());
0019     return rtn;
0020   }
0021 
0022   inline PseudoJets mkPseudoJets(const Jets& js) {
0023     PseudoJets rtn; rtn.reserve(js.size());
0024     for (const Jet& j : js) rtn.push_back(j.pseudojet());
0025     return rtn;
0026   }
0027 
0028   inline Jets mkJets(const PseudoJets& pjs) {
0029     Jets rtn; rtn.reserve(pjs.size());
0030     for (const PseudoJet& pj : pjs) rtn.push_back(pj);
0031     return rtn;
0032   }
0033 
0034   /// @}
0035 
0036 
0037   /// @defgroup jetutils_j2bool Jet classifier -> bool functors
0038   /// @{
0039 
0040   /// std::function instantiation for functors taking a Jet and returning a bool
0041   using JetSelector = function<bool(const Jet&)>;
0042   /// std::function instantiation for functors taking two Jets and returning a bool
0043   using JetSorter = function<bool(const Jet&, const Jet&)>;
0044 
0045 
0046   /// Base type for Jet -> bool functors
0047   struct BoolJetFunctor {
0048     virtual bool operator()(const Jet& p) const = 0;
0049     virtual ~BoolJetFunctor() {}
0050   };
0051 
0052 
0053   /// Functor for and-combination of selector logic
0054   struct BoolJetAND : public BoolJetFunctor {
0055     BoolJetAND(const std::vector<JetSelector>& sels) : selectors(sels) {}
0056     BoolJetAND(const JetSelector& a, const JetSelector& b) : selectors({a,b}) {}
0057     BoolJetAND(const JetSelector& a, const JetSelector& b, const JetSelector& c) : selectors({a,b,c}) {}
0058     bool operator()(const Jet& j) const {
0059       for (const JetSelector& sel : selectors) if (!sel(j)) return false;
0060       return true;
0061     }
0062     std::vector<JetSelector> selectors;
0063   };
0064   /// Operator syntactic sugar for AND construction
0065   inline BoolJetAND operator && (const JetSelector& a, const JetSelector& b) {
0066     return BoolJetAND(a, b);
0067   }
0068 
0069 
0070   /// Functor for or-combination of selector logic
0071   struct BoolJetOR : public BoolJetFunctor {
0072     BoolJetOR(const std::vector<JetSelector>& sels) : selectors(sels) {}
0073     BoolJetOR(const JetSelector& a, const JetSelector& b) : selectors({a,b}) {}
0074     BoolJetOR(const JetSelector& a, const JetSelector& b, const JetSelector& c) : selectors({a,b,c}) {}
0075     bool operator()(const Jet& j) const {
0076       for (const JetSelector& sel : selectors) if (sel(j)) return true;
0077       return false;
0078     }
0079     std::vector<JetSelector> selectors;
0080   };
0081   /// Operator syntactic sugar for OR construction
0082   inline BoolJetOR operator || (const JetSelector& a, const JetSelector& b) {
0083     return BoolJetOR(a, b);
0084   }
0085 
0086 
0087   /// Functor for inverting selector logic
0088   struct BoolJetNOT : public BoolJetFunctor {
0089     BoolJetNOT(const JetSelector& sel) : selector(sel) {}
0090     bool operator()(const Jet& j) const { return !selector(j); }
0091     JetSelector selector;
0092   };
0093   /// Operator syntactic sugar for NOT construction
0094   inline BoolJetNOT operator ! (const JetSelector& a) {
0095     return BoolJetNOT(a);
0096   }
0097 
0098 
0099 
0100   /// B-tagging functor, with a tag selection cut as the stored state
0101   struct HasBTag : BoolJetFunctor {
0102     HasBTag(const Cut& c=Cuts::open()) : cut(c) {}
0103     // HasBTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
0104     bool operator() (const Jet& j) const { return j.bTagged(cut); }
0105     // const std::function<bool(const Jet& j)> selector;
0106     const Cut cut;
0107   };
0108   using hasBTag = HasBTag;
0109 
0110   /// C-tagging functor, with a tag selection cut as the stored state
0111   struct HasCTag : BoolJetFunctor {
0112     HasCTag(const Cut& c=Cuts::open()) : cut(c) {}
0113     // HasCTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
0114     bool operator() (const Jet& j) const { return j.cTagged(cut); }
0115     // const std::function<bool(const Jet& j)> selector;
0116     const Cut cut;
0117   };
0118   using hasCTag = HasCTag;
0119 
0120   /// Tau-tagging functor, with a tag selection cut as the stored state
0121   struct HasTauTag : BoolJetFunctor {
0122     HasTauTag(const Cut& c=Cuts::open()) : cut(c) {}
0123     // HasTauTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
0124     bool operator() (const Jet& j) const { return j.tauTagged(cut); }
0125     // const std::function<bool(const Jet& j)> selector;
0126     const Cut cut;
0127   };
0128   using hasTauTag = HasTauTag;
0129 
0130   /// Anti-B/C-tagging functor, with a tag selection cut as the stored state
0131   struct HasNoTag : BoolJetFunctor {
0132     HasNoTag(const Cut& c=Cuts::open(), bool quarktagsonly=false) : cut(c), qtagsonly(quarktagsonly) {}
0133     // HasNoTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
0134     bool operator() (const Jet& j) const { return !j.bTagged(cut) && !j.cTagged(cut) && (qtagsonly || !j.tauTagged(cut)); }
0135     // const std::function<bool(const Jet& j)> selector;
0136     const Cut cut;
0137     bool qtagsonly;
0138   };
0139   using hasNoTag = HasNoTag;
0140 
0141   /// @}
0142 
0143 
0144   /// @defgroup jetutils_filt Unbound functions for filtering jets
0145   /// @{
0146 
0147   /// Filter a jet collection in-place to the subset that passes the supplied Cut
0148   Jets& iselect(Jets& jets, const Cut& c);
0149 
0150 
0151   /// Filter a jet collection in-place to the subset that passes the supplied Cut
0152   inline Jets select(const Jets& jets, const Cut& c) {
0153     Jets rtn = jets;
0154     return iselect(rtn, c);
0155   }
0156 
0157 
0158   /// Filter a jet collection in-place to the subset that passes the supplied Cut
0159   inline Jets select(const Jets& jets, const Cut& c, Jets& out) {
0160     out = select(jets, c);
0161     return out;
0162   }
0163 
0164 
0165 
0166   /// Filter a jet collection in-place to the subset that fails the supplied Cut
0167   Jets& idiscard(Jets& jets, const Cut& c);
0168 
0169 
0170   /// Filter a jet collection in-place to the subset that fails the supplied Cut
0171   inline Jets discard(const Jets& jets, const Cut& c) {
0172     Jets rtn = jets;
0173     return idiscard(rtn, c);
0174   }
0175 
0176 
0177   /// Filter a jet collection in-place to the subset that fails the supplied Cut
0178   inline Jets discard(const Jets& jets, const Cut& c, Jets& out) {
0179     out = discard(jets, c);
0180     return out;
0181   }
0182 
0183   /// @}
0184 
0185 
0186   /// @defgroup jetutils_trim Trimming operations not covered in fastjet
0187   /// @{
0188 
0189   /// Take in PseudoJets, Return Jets with subjet constituents of pt under
0190   /// frac*(jetpt) removed.
0191   /// Mainly useful for reclustered jets.
0192   Jets trimJetsFrac(const PseudoJets& jetsIn, const double frac=0.1);
0193 
0194   /// @}
0195 
0196 
0197 
0198   /// @defgroup jetutils_coll Operations on collections of Jet
0199   /// @note This can't be done on generic collections of ParticleBase -- thanks, C++ :-/
0200   /// @{
0201   namespace Kin {
0202 
0203     /// @todo This shouldn't be necessary, if the sum() function SFINAE picked up be ParticleBase versions...
0204     inline double pT(const Jet& j) {
0205       return j.pT();
0206     }
0207 
0208     inline double sumPt(const Jets& js) {
0209       return sum(js, Kin::pT, 0.0);
0210     }
0211 
0212     inline FourMomentum sumP4(const Jets& js) {
0213       return sum(js, Kin::p4, FourMomentum());
0214     }
0215 
0216     inline Vector3 sumP3(const Jets& js) {
0217       return sum(js, Kin::p3, Vector3());
0218     }
0219 
0220     /// @todo Min dPhi, min dR?
0221     /// @todo Isolation routines?
0222 
0223   }
0224   /// @}
0225 
0226 
0227   // Import Kin namespace into Rivet
0228   using namespace Kin;
0229 
0230 
0231   /// @}
0232 
0233 }
0234 
0235 #endif