File indexing completed on 2025-09-17 09:13:36
0001
0002 #ifndef RIVET_FastJets_HH
0003 #define RIVET_FastJets_HH
0004
0005 #include "Rivet/Jet.hh"
0006 #include "Rivet/Particle.hh"
0007 #include "Rivet/Projection.hh"
0008 #include "Rivet/Projections/JetFinder.hh"
0009 #include "Rivet/Projections/FinalState.hh"
0010 #include "Rivet/Tools/RivetFastJet.hh"
0011
0012 #include "fastjet/SISConePlugin.hh"
0013 #include "fastjet/ATLASConePlugin.hh"
0014 #include "fastjet/CMSIterativeConePlugin.hh"
0015 #include "fastjet/CDFJetCluPlugin.hh"
0016 #include "fastjet/CDFMidPointPlugin.hh"
0017 #include "fastjet/D0RunIIConePlugin.hh"
0018 #include "fastjet/TrackJetPlugin.hh"
0019 #include "fastjet/JadePlugin.hh"
0020 #include "fastjet/contrib/VariableRPlugin.hh"
0021
0022 #include "Rivet/Projections/PxConePlugin.hh"
0023 #include "Rivet/Tools/TypeTraits.hh"
0024
0025 namespace Rivet {
0026
0027 typedef std::shared_ptr<fastjet::JetDefinition::Plugin> FJPluginPtr;
0028
0029
0030 class FastJets : public JetFinder {
0031 public:
0032
0033 using JetFinder::operator =;
0034
0035
0036
0037
0038
0039
0040
0041
0042 FastJets(const FinalState& fsp,
0043 const fastjet::JetDefinition& jdef,
0044 JetMuons usemuons=JetMuons::ALL,
0045 JetInvisibles useinvis=JetInvisibles::NONE,
0046 fastjet::AreaDefinition* adef=nullptr)
0047 : JetFinder(fsp, usemuons, useinvis), _jdef(jdef),
0048 _adef(adef), _cuts(Cuts::OPEN)
0049 {
0050 _initBase();
0051 }
0052
0053
0054
0055
0056 FastJets(const FinalState& fsp,
0057 const fastjet::JetDefinition& jdef,
0058 const Cut& c,
0059 JetMuons usemuons=JetMuons::ALL,
0060 JetInvisibles useinvis=JetInvisibles::NONE,
0061 fastjet::AreaDefinition* adef=nullptr)
0062 : JetFinder(fsp, usemuons, useinvis), _jdef(jdef),
0063 _adef(adef), _cuts(c)
0064 {
0065 _initBase();
0066 }
0067
0068
0069
0070
0071 FastJets(const FinalState& fsp,
0072 const fastjet::JetDefinition& jdef,
0073 fastjet::AreaDefinition* adef,
0074 JetMuons usemuons=JetMuons::ALL,
0075 JetInvisibles useinvis=JetInvisibles::NONE)
0076 : FastJets(fsp, jdef, usemuons, useinvis, adef)
0077 { }
0078
0079
0080
0081
0082
0083 FastJets(const FinalState& fsp,
0084 const fastjet::JetDefinition& jdef,
0085 fastjet::AreaDefinition* adef,
0086 const Cut& c,
0087 JetMuons usemuons=JetMuons::ALL,
0088 JetInvisibles useinvis=JetInvisibles::NONE)
0089 : FastJets(fsp, jdef, c, usemuons, useinvis, adef)
0090 { }
0091
0092
0093
0094
0095
0096 FastJets(const FinalState& fsp,
0097 fastjet::JetAlgorithm type,
0098 fastjet::RecombinationScheme recom, double rparameter,
0099 JetMuons usemuons=JetMuons::ALL,
0100 JetInvisibles useinvis=JetInvisibles::NONE,
0101 fastjet::AreaDefinition* adef=nullptr)
0102 : FastJets(fsp, fastjet::JetDefinition(type, rparameter, recom), usemuons, useinvis, adef)
0103 { }
0104
0105
0106
0107
0108 FastJets(const FinalState& fsp,
0109 fastjet::JetAlgorithm type,
0110 fastjet::RecombinationScheme recom, double rparameter,
0111 const Cut& c,
0112 JetMuons usemuons=JetMuons::ALL,
0113 JetInvisibles useinvis=JetInvisibles::NONE,
0114 fastjet::AreaDefinition* adef=nullptr)
0115 : FastJets(fsp, fastjet::JetDefinition(type, rparameter, recom), c, usemuons, useinvis, adef)
0116 { }
0117
0118
0119
0120
0121 FastJets(const FinalState& fsp,
0122 fastjet::JetAlgorithm type,
0123 fastjet::RecombinationScheme recom, double rparameter,
0124 fastjet::AreaDefinition* adef,
0125 JetMuons usemuons=JetMuons::ALL,
0126 JetInvisibles useinvis=JetInvisibles::NONE)
0127 : FastJets(fsp, type, recom, rparameter, usemuons, useinvis, adef)
0128 { }
0129
0130
0131
0132
0133 FastJets(const FinalState& fsp,
0134 fastjet::JetAlgorithm type,
0135 fastjet::RecombinationScheme recom, double rparameter,
0136 fastjet::AreaDefinition* adef,
0137 const Cut& c,
0138 JetMuons usemuons=JetMuons::ALL,
0139 JetInvisibles useinvis=JetInvisibles::NONE)
0140 : FastJets(fsp, type, recom, rparameter, c, usemuons, useinvis, adef)
0141 { }
0142
0143
0144
0145
0146 FastJets(const FinalState& fsp,
0147 FJPluginPtr plugin,
0148 JetMuons usemuons=JetMuons::ALL,
0149 JetInvisibles useinvis=JetInvisibles::NONE,
0150 fastjet::AreaDefinition* adef=nullptr)
0151 : FastJets(fsp, fastjet::JetDefinition(plugin.get()), usemuons, useinvis, adef)
0152 {
0153 _plugin = plugin;
0154 }
0155
0156
0157
0158
0159 FastJets(const FinalState& fsp,
0160 FJPluginPtr plugin,
0161 const Cut& c,
0162 JetMuons usemuons=JetMuons::ALL,
0163 JetInvisibles useinvis=JetInvisibles::NONE,
0164 fastjet::AreaDefinition* adef=nullptr)
0165 : FastJets(fsp, fastjet::JetDefinition(plugin.get()), c, usemuons, useinvis, adef)
0166 {
0167 _plugin = plugin;
0168 }
0169
0170
0171
0172
0173 FastJets(const FinalState& fsp,
0174 FJPluginPtr plugin,
0175 fastjet::AreaDefinition* adef,
0176 JetMuons usemuons=JetMuons::ALL,
0177 JetInvisibles useinvis=JetInvisibles::NONE)
0178 : FastJets(fsp, plugin, usemuons, useinvis, adef)
0179 { }
0180
0181
0182
0183
0184 FastJets(const FinalState& fsp,
0185 FJPluginPtr plugin,
0186 fastjet::AreaDefinition* adef,
0187 const Cut& c,
0188 JetMuons usemuons=JetMuons::ALL,
0189 JetInvisibles useinvis=JetInvisibles::NONE)
0190 : FastJets(fsp, plugin, c, usemuons, useinvis, adef)
0191 { }
0192
0193
0194
0195
0196
0197
0198
0199
0200 FastJets(const FinalState& fsp,
0201 JetAlg alg, double rparameter=-1,
0202 JetMuons usemuons=JetMuons::ALL,
0203 JetInvisibles useinvis=JetInvisibles::NONE,
0204 fastjet::AreaDefinition* adef=nullptr)
0205 : JetFinder(fsp, usemuons, useinvis),
0206 _adef(adef), _cuts(Cuts::OPEN)
0207 {
0208 _initBase();
0209 _initJdef(alg, rparameter);
0210 }
0211
0212
0213
0214
0215
0216
0217
0218
0219 FastJets(const FinalState& fsp,
0220 JetAlg alg, double rparameter,
0221 const Cut& c,
0222 JetMuons usemuons=JetMuons::ALL,
0223 JetInvisibles useinvis=JetInvisibles::NONE,
0224 fastjet::AreaDefinition* adef=nullptr)
0225 : JetFinder(fsp, usemuons, useinvis), _adef(adef), _cuts(c)
0226 {
0227 _initBase();
0228 _initJdef(alg, rparameter);
0229 }
0230
0231
0232
0233
0234 RIVET_DEFAULT_PROJ_CLONE(FastJets);
0235
0236
0237
0238
0239
0240 using Projection::operator =;
0241
0242
0243
0244
0245
0246
0247 static fastjet::JetDefinition mkJetDef(JetAlg alg, double rparameter);
0248
0249
0250
0251 template<JetAlg JETALG, typename... Args>
0252 static FJPluginPtr mkPlugin(Args&&... args){
0253 return std::make_shared<mapJetAlg2Plugin_t<JETALG>>(std::forward<Args>(args)...);
0254 }
0255
0256
0257 static FJPluginPtr mkPlugin(JetAlg alg, double rparameter=-1);
0258
0259
0260 static PseudoJets mkClusterInputs(const Particles& fsparticles, const Particles& tagparticles=Particles());
0261
0262 static Jet mkJet(const PseudoJet& pj, const Particles& fsparticles, const Particles& tagparticles=Particles());
0263
0264 static Jets mkJets(const PseudoJets& pjs, const Particles& fsparticles=Particles(), const Particles& tagparticles=Particles());
0265
0266
0267
0268
0269
0270
0271
0272 typedef std::pair<PseudoJets, Particles> PJetsParts;
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284 template <
0285 typename CONTAINER,
0286 typename = std::enable_if_t<
0287 is_citerable_v<CONTAINER>,
0288 Jet
0289 >
0290 >
0291 static CONTAINER reclusterJets(const CONTAINER &jetsIn, const fastjet::JetDefinition &jDef){
0292 PJetsParts reclusteredConsts = reclusterJetsParts(jetsIn, jDef);
0293 return mkTaggedJets(jetsIn, reclusteredConsts);
0294 }
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304 template <
0305 typename CONTAINER,
0306 typename = std::enable_if_t<
0307 is_citerable_v<CONTAINER>,
0308 Jet
0309 >
0310 >
0311 static CONTAINER reclusterJets(const CONTAINER &jetsIn, const fastjet::JetDefinition &jDef, const fastjet::Filter &filter){
0312 PJetsParts reclusteredConsts = reclusterJetsParts(jetsIn, jDef);
0313 ifilterPseudoJets(reclusteredConsts.first, filter);
0314 return mkTaggedJets(jetsIn, reclusteredConsts);
0315 }
0316
0317
0318
0319
0320 template <
0321 typename CONTAINER,
0322 typename = std::enable_if_t<
0323 is_citerable_v<CONTAINER>,
0324 Jet
0325 >
0326 >
0327 static CONTAINER reclusterJets(const CONTAINER &jetsIn, const FJPluginPtr &jetAlg){
0328 const fastjet::JetDefinition jDef(jetAlg.get());
0329 return reclusterJets(jetsIn, jDef);
0330 }
0331
0332
0333
0334
0335
0336
0337
0338 template <
0339 typename CONTAINER,
0340 typename = std::enable_if_t<
0341 is_citerable_v<CONTAINER>,
0342 Jet
0343 >
0344 >
0345 static CONTAINER reclusterJets(const CONTAINER &jetsIn, const FJPluginPtr &jetAlg, const fastjet::Filter &filter){
0346 const fastjet::JetDefinition jDef(jetAlg.get());
0347 return reclusterJets(jetsIn, jDef, filter);
0348 }
0349
0350
0351
0352
0353 template <
0354 JetAlg JETALG, typename... Args, typename CONTAINER,
0355 typename = std::enable_if_t<
0356 is_citerable_v<CONTAINER>,
0357 Jet
0358 >
0359 >
0360 static CONTAINER reclusterJets(const CONTAINER &jetsIn, Args&&... args){
0361 if constexpr (JETALG<JetAlg::SISCONE){
0362 const fastjet::JetDefinition jDef = mkJetDef(JETALG, std::forward<Args>(args)...);
0363 return reclusterJets(jetsIn, jDef);
0364 } else {
0365 const FJPluginPtr plugin = mkPlugin<JETALG>(std::forward<Args>(args)...);
0366 return reclusterJets(jetsIn, plugin);
0367 }
0368 throw std::invalid_argument( "Unknown jet algorithm: "+to_string(int(JETALG)) );
0369 }
0370
0371
0372
0373
0374
0375
0376
0377 template <
0378 JetAlg JETALG, typename... Args, typename CONTAINER,
0379 typename = std::enable_if_t<
0380 is_citerable_v<CONTAINER>,
0381 Jet
0382 >
0383 >
0384 static CONTAINER reclusterJets(const CONTAINER &jetsIn, const fastjet::Filter &filter, Args&&... args){
0385 if constexpr (JETALG<JetAlg::SISCONE){
0386 const fastjet::JetDefinition jDef = mkJetDef(JETALG, std::forward<Args>(args)...);
0387 return reclusterJets(jetsIn, jDef, filter);
0388 } else {
0389 const FJPluginPtr plugin = mkPlugin<JETALG>(std::forward<Args>(args)...);
0390 return reclusterJets(jetsIn, plugin, filter);
0391 }
0392 throw std::invalid_argument( "Unknown jet algorithm: "+to_string(int(JETALG)) );
0393 }
0394
0395
0396
0397
0398 template <typename T, typename U, typename... Args>
0399 static std::map<T, U> reclusterJets(const std::map<T, U> &jetsMap, Args&&... args){
0400 std::map<T, U> rtn;
0401 for ( auto const &[key, jetsIn] : jetsMap ) rtn[key] = reclusterJets(jetsIn, std::forward<Args>(args)...);
0402 return rtn;
0403 }
0404
0405
0406
0407
0408 template <JetAlg JETALG, typename T, typename U, typename... Args>
0409 static std::map<T, U> reclusterJets(const std::map<T, U> &jetsMap, Args&&... args){
0410 std::map<T, U> rtn;
0411 for ( auto const &[key, jetsIn] : jetsMap ) rtn[key] = reclusterJets<JETALG>(jetsIn, std::forward<Args>(args)...);
0412 return rtn;
0413 }
0414
0415
0416
0417
0418
0419 void reset();
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429 void useJetArea(fastjet::AreaDefinition* adef) {
0430 _adef.reset(adef);
0431 }
0432
0433
0434 void clearJetArea() {
0435 _adef.reset();
0436 }
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448 void addTrf(fastjet::Transformer* trf) {
0449 _trfs.push_back(shared_ptr<fastjet::Transformer>(trf));
0450 }
0451
0452
0453
0454
0455
0456 template<typename TRFS, typename TRF=typename TRFS::value_type>
0457 typename std::enable_if<Derefable<TRF>::value, void>::type
0458 addTrfs(const TRFS& trfs) {
0459 for (auto& trf : trfs) addTrf(trf);
0460 }
0461
0462
0463
0464
0465 void addFilter(fastjet::Filter* filter) {
0466 addTrf(filter);
0467 }
0468
0469
0470
0471
0472 template<typename FILTERS, typename FILTER=typename FILTERS::value_type>
0473 typename std::enable_if<Derefable<FILTER>::value, void>::type
0474 addFilters(const FILTERS& filters) {
0475 addTrfs(filters);
0476 }
0477
0478
0479 void clearTrfs() {
0480 _trfs.clear();
0481 }
0482
0483
0484
0485
0486
0487
0488
0489
0490 Jets _jets() const;
0491
0492
0493
0494 PseudoJets pseudojets(double ptmin=0.0) const;
0495
0496
0497 PseudoJets pseudojetsByPt(double ptmin=0.0) const {
0498 return sorted_by_pt(pseudojets(ptmin));
0499 }
0500
0501
0502 PseudoJets pseudojetsByE(double ptmin=0.0) const {
0503 return sorted_by_E(pseudojets(ptmin));
0504 }
0505
0506
0507 PseudoJets pseudojetsByRapidity(double ptmin=0.0) const {
0508 return sorted_by_rapidity(pseudojets(ptmin));
0509 }
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519 const shared_ptr<fastjet::ClusterSequence> clusterSeq() const {
0520 return _cseq;
0521 }
0522
0523
0524
0525 const shared_ptr<fastjet::ClusterSequenceArea> clusterSeqArea() const {
0526 return areaDef() ? dynamic_pointer_cast<fastjet::ClusterSequenceArea>(_cseq) : nullptr;
0527 }
0528
0529
0530 const fastjet::JetDefinition& jetDef() const {
0531 return _jdef;
0532 }
0533
0534
0535
0536
0537
0538 const shared_ptr<fastjet::AreaDefinition> areaDef() const {
0539 return _adef;
0540 }
0541
0542
0543
0544
0545 protected:
0546
0547
0548 void _initBase();
0549
0550
0551 void _initJdef(JetAlg alg, double rparameter){
0552 MSG_DEBUG("JetAlg = " << static_cast<int>(alg));
0553 MSG_DEBUG("R parameter = " << rparameter);
0554 if ( alg < JetAlg::SISCONE ){
0555 _jdef = mkJetDef(alg, rparameter);
0556 } else {
0557 _plugin = mkPlugin(alg, rparameter);
0558 _jdef = fastjet::JetDefinition(_plugin.get());
0559 }
0560 }
0561
0562
0563 static Jets mkTaggedJets(const Jets &jetsIn, const PJetsParts &pJetsParts);
0564
0565
0566 static PJetsParts reclusterJetsParts(const Jets &jetsIn, const fastjet::JetDefinition &jDef);
0567
0568 protected:
0569
0570
0571 void project(const Event& e);
0572
0573
0574 CmpState compare(const Projection& p) const;
0575
0576 public:
0577
0578
0579 void calc(const Particles& fsparticles, const Particles& tagparticles=Particles());
0580
0581
0582 protected:
0583
0584
0585 fastjet::JetDefinition _jdef;
0586
0587
0588 std::shared_ptr<fastjet::AreaDefinition> _adef;
0589
0590
0591 std::shared_ptr<fastjet::ClusterSequence> _cseq;
0592
0593
0594 Cut _cuts;
0595
0596
0597 FJPluginPtr _plugin;
0598
0599
0600 std::vector< std::shared_ptr<fastjet::Transformer> > _trfs;
0601
0602
0603 static const std::map<JetAlg, std::pair<fastjet::JetAlgorithm, fastjet::RecombinationScheme>> jetAlgMap;
0604
0605
0606
0607 template<JetAlg, typename X> struct mapJetAlg2Plugin;
0608
0609
0610 template<typename X> struct mapJetAlg2Plugin<JetAlg::SISCONE, X>{ using type = fastjet::SISConePlugin; };
0611 template<typename X> struct mapJetAlg2Plugin<JetAlg::PXCONE, X>{ using type = Rivet::PxConePlugin; };
0612 template<typename X> struct mapJetAlg2Plugin<JetAlg::CDFJETCLU, X>{ using type = fastjet::CDFJetCluPlugin; };
0613 template<typename X> struct mapJetAlg2Plugin<JetAlg::CDFMIDPOINT, X>{ using type = fastjet::CDFMidPointPlugin; };
0614 template<typename X> struct mapJetAlg2Plugin<JetAlg::D0ILCONE, X>{ using type = fastjet::D0RunIIConePlugin; };
0615 template<typename X> struct mapJetAlg2Plugin<JetAlg::JADE, X>{ using type = fastjet::JadePlugin; };
0616 template<typename X> struct mapJetAlg2Plugin<JetAlg::TRACKJET, X>{ using type = fastjet::TrackJetPlugin; };
0617 template<typename X> struct mapJetAlg2Plugin<JetAlg::VARIABLER, X>{ using type = fastjet::contrib::VariableRPlugin; };
0618
0619
0620 template<JetAlg JETALG>
0621 using mapJetAlg2Plugin_t = typename mapJetAlg2Plugin<JETALG, void>::type;
0622
0623
0624 mutable std::map<int, vector<double> > _yscales;
0625
0626
0627 Particles _fsparticles, _tagparticles;
0628
0629 };
0630
0631 }
0632
0633 #endif