File indexing completed on 2025-01-18 09:57:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #ifndef __FASTJET_CONTRIB_MEASUREDEFINITION_HH__
0026 #define __FASTJET_CONTRIB_MEASUREDEFINITION_HH__
0027
0028 #include "fastjet/PseudoJet.hh"
0029 #include <cmath>
0030 #include <vector>
0031 #include <list>
0032 #include <limits>
0033
0034 #include "TauComponents.hh"
0035
0036 FASTJET_BEGIN_NAMESPACE
0037
0038 namespace contrib{
0039
0040
0041
0042
0043
0044 class DefaultMeasure;
0045 class NormalizedMeasure;
0046 class UnnormalizedMeasure;
0047 class NormalizedCutoffMeasure;
0048 class UnnormalizedCutoffMeasure;
0049
0050
0051
0052 class ConicalMeasure;
0053 class OriginalGeometricMeasure;
0054 class ModifiedGeometricMeasure;
0055 class ConicalGeometricMeasure;
0056 class XConeMeasure;
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 class LightLikeAxis;
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 class MeasureDefinition {
0081
0082 public:
0083
0084
0085 virtual std::string description() const = 0;
0086
0087
0088 virtual MeasureDefinition* create() const = 0;
0089
0090
0091
0092
0093
0094
0095 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const {
0096 return jet_numerator(particle,axis);
0097 }
0098
0099
0100
0101 virtual double beam_distance_squared(const fastjet::PseudoJet& particle) const {
0102 return beam_numerator(particle);
0103 }
0104
0105
0106 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const = 0;
0107
0108 virtual double beam_numerator(const fastjet::PseudoJet& particle) const = 0;
0109
0110
0111 virtual double denominator(const fastjet::PseudoJet& particle) const = 0;
0112
0113
0114
0115 virtual std::vector<fastjet::PseudoJet> get_one_pass_axes(int n_jets,
0116 const std::vector<fastjet::PseudoJet>& inputs,
0117 const std::vector<fastjet::PseudoJet>& seedAxes,
0118 int nAttempts = 1000,
0119 double accuracy = 0.0001
0120 ) const;
0121
0122 public:
0123
0124
0125 double result(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) const {
0126 return component_result(particles,axes).tau();
0127 }
0128
0129
0130 inline double operator() (const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) const {
0131 return result(particles,axes);
0132 }
0133
0134
0135 TauComponents component_result(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) const;
0136
0137
0138 TauPartition get_partition(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) const;
0139
0140
0141 TauComponents component_result_from_partition(const TauPartition& partition, const std::vector<fastjet::PseudoJet>& axes) const;
0142
0143
0144
0145
0146 virtual ~MeasureDefinition(){}
0147
0148 protected:
0149
0150
0151 TauMode _tau_mode;
0152
0153
0154 bool _useAxisScaling;
0155
0156
0157 MeasureDefinition() : _tau_mode(UNDEFINED_SHAPE), _useAxisScaling(true) {}
0158
0159
0160
0161 void setTauMode(TauMode tau_mode) {
0162 _tau_mode = tau_mode;
0163 }
0164
0165
0166 void setAxisScaling(bool useAxisScaling) {
0167 _useAxisScaling = useAxisScaling;
0168 }
0169
0170
0171 bool has_denominator() const { return (_tau_mode == NORMALIZED_JET_SHAPE || _tau_mode == NORMALIZED_EVENT_SHAPE);}
0172
0173 bool has_beam() const {return (_tau_mode == UNNORMALIZED_EVENT_SHAPE || _tau_mode == NORMALIZED_EVENT_SHAPE);}
0174
0175
0176 fastjet::PseudoJet lightFrom(const fastjet::PseudoJet& input) const {
0177 double length = sqrt(pow(input.px(),2) + pow(input.py(),2) + pow(input.pz(),2));
0178 return fastjet::PseudoJet(input.px()/length,input.py()/length,input.pz()/length,1.0);
0179 }
0180
0181
0182 static inline double sq(double x) {return x*x;}
0183
0184 };
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200 enum DefaultMeasureType {
0201 pt_R,
0202 E_theta,
0203 lorentz_dot,
0204 perp_lorentz_dot
0205 };
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216 class DefaultMeasure : public MeasureDefinition {
0217
0218 public:
0219
0220
0221 virtual std::string description() const;
0222
0223 virtual DefaultMeasure* create() const {return new DefaultMeasure(*this);}
0224
0225
0226 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const {
0227 return angleSquared(particle, axis);
0228 }
0229
0230
0231 virtual double beam_distance_squared(const fastjet::PseudoJet& ) const {
0232 return _RcutoffSq;
0233 }
0234
0235
0236 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const{
0237 double jet_dist = angleSquared(particle, axis);
0238 if (jet_dist > 0.0) {
0239 return energy(particle) * std::pow(jet_dist,_beta/2.0);
0240 } else {
0241 return 0.0;
0242 }
0243 }
0244
0245
0246 virtual double beam_numerator(const fastjet::PseudoJet& particle) const {
0247 return energy(particle) * std::pow(_Rcutoff,_beta);
0248 }
0249
0250
0251 virtual double denominator(const fastjet::PseudoJet& particle) const {
0252 return energy(particle) * std::pow(_R0,_beta);
0253 }
0254
0255
0256 virtual std::vector<fastjet::PseudoJet> get_one_pass_axes(int n_jets,
0257 const std::vector<fastjet::PseudoJet>& inputs,
0258 const std::vector<fastjet::PseudoJet>& seedAxes,
0259 int nAttempts,
0260 double accuracy
0261 ) const;
0262
0263 protected:
0264 double _beta;
0265 double _R0;
0266 double _Rcutoff;
0267 double _RcutoffSq;
0268 DefaultMeasureType _measure_type;
0269
0270
0271
0272 DefaultMeasure(double beta, double R0, double Rcutoff, DefaultMeasureType measure_type = pt_R)
0273 : MeasureDefinition(), _beta(beta), _R0(R0), _Rcutoff(Rcutoff), _RcutoffSq(sq(Rcutoff)), _measure_type(measure_type)
0274 {
0275 if (beta <= 0) throw Error("DefaultMeasure: You must choose beta > 0.");
0276 if (R0 <= 0) throw Error("DefaultMeasure: You must choose R0 > 0.");
0277 if (Rcutoff <= 0) throw Error("DefaultMeasure: You must choose Rcutoff > 0.");
0278 }
0279
0280
0281 void setDefaultMeasureType(DefaultMeasureType measure_type) {
0282 _measure_type = measure_type;
0283 }
0284
0285
0286 double energy(const PseudoJet& jet) const;
0287
0288 double angleSquared(const PseudoJet& jet1, const PseudoJet& jet2) const;
0289
0290
0291 std::string measure_type_name() const {
0292 if (_measure_type == pt_R) return "pt_R";
0293 else if (_measure_type == E_theta) return "E_theta";
0294 else if (_measure_type == lorentz_dot) return "lorentz_dot";
0295 else if (_measure_type == perp_lorentz_dot) return "perp_lorentz_dot";
0296 else return "Measure Type Undefined";
0297 }
0298
0299
0300 template <int N> std::vector<LightLikeAxis> UpdateAxesFast(const std::vector <LightLikeAxis> & old_axes,
0301 const std::vector <fastjet::PseudoJet> & inputJets,
0302 double accuracy) const;
0303
0304
0305 std::vector<LightLikeAxis> UpdateAxes(const std::vector <LightLikeAxis> & old_axes,
0306 const std::vector <fastjet::PseudoJet> & inputJets,
0307 double accuracy) const;
0308 };
0309
0310
0311
0312
0313
0314
0315
0316
0317 class NormalizedCutoffMeasure : public DefaultMeasure {
0318
0319 public:
0320
0321
0322 NormalizedCutoffMeasure(double beta, double R0, double Rcutoff, DefaultMeasureType measure_type = pt_R)
0323 : DefaultMeasure(beta, R0, Rcutoff, measure_type) {
0324 setTauMode(NORMALIZED_JET_SHAPE);
0325 }
0326
0327
0328 virtual std::string description() const;
0329
0330
0331 virtual NormalizedCutoffMeasure* create() const {return new NormalizedCutoffMeasure(*this);}
0332
0333 };
0334
0335
0336
0337
0338
0339
0340
0341 class NormalizedMeasure : public NormalizedCutoffMeasure {
0342
0343 public:
0344
0345
0346 NormalizedMeasure(double beta, double R0, DefaultMeasureType measure_type = pt_R)
0347 : NormalizedCutoffMeasure(beta, R0, std::numeric_limits<double>::max(), measure_type) {
0348 _RcutoffSq = std::numeric_limits<double>::max();
0349 setTauMode(NORMALIZED_JET_SHAPE);
0350 }
0351
0352
0353 virtual std::string description() const;
0354
0355 virtual NormalizedMeasure* create() const {return new NormalizedMeasure(*this);}
0356
0357 };
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368 class UnnormalizedCutoffMeasure : public DefaultMeasure {
0369
0370 public:
0371
0372
0373
0374
0375 UnnormalizedCutoffMeasure(double beta, double Rcutoff, DefaultMeasureType measure_type = pt_R)
0376 : DefaultMeasure(beta, std::numeric_limits<double>::quiet_NaN(), Rcutoff, measure_type) {
0377 setTauMode(UNNORMALIZED_EVENT_SHAPE);
0378 }
0379
0380
0381 virtual std::string description() const;
0382
0383 virtual UnnormalizedCutoffMeasure* create() const {return new UnnormalizedCutoffMeasure(*this);}
0384
0385 };
0386
0387
0388
0389
0390
0391
0392
0393
0394 class UnnormalizedMeasure : public UnnormalizedCutoffMeasure {
0395
0396 public:
0397
0398
0399
0400 UnnormalizedMeasure(double beta, DefaultMeasureType measure_type = pt_R)
0401 : UnnormalizedCutoffMeasure(beta, std::numeric_limits<double>::max(), measure_type) {
0402 _RcutoffSq = std::numeric_limits<double>::max();
0403 setTauMode(UNNORMALIZED_JET_SHAPE);
0404 }
0405
0406
0407 virtual std::string description() const;
0408
0409
0410 virtual UnnormalizedMeasure* create() const {return new UnnormalizedMeasure(*this);}
0411
0412 };
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424 class ConicalMeasure : public MeasureDefinition {
0425
0426 public:
0427
0428
0429 ConicalMeasure(double beta, double Rcutoff)
0430 : MeasureDefinition(), _beta(beta), _Rcutoff(Rcutoff), _RcutoffSq(sq(Rcutoff)) {
0431 if (beta <= 0) throw Error("ConicalMeasure: You must choose beta > 0.");
0432 if (Rcutoff <= 0) throw Error("ConicalMeasure: You must choose Rcutoff > 0.");
0433 setTauMode(UNNORMALIZED_EVENT_SHAPE);
0434 }
0435
0436
0437 virtual std::string description() const;
0438
0439 virtual ConicalMeasure* create() const {return new ConicalMeasure(*this);}
0440
0441
0442 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const {
0443 PseudoJet lightAxis = lightFrom(axis);
0444 return particle.squared_distance(lightAxis);
0445 }
0446
0447
0448 virtual double beam_distance_squared(const fastjet::PseudoJet& ) const {
0449 return _RcutoffSq;
0450 }
0451
0452
0453
0454 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const {
0455 PseudoJet lightAxis = lightFrom(axis);
0456 double jet_dist = particle.squared_distance(lightAxis)/_RcutoffSq;
0457 double jet_perp = particle.perp();
0458
0459 if (_beta == 2.0) {
0460 return jet_perp * jet_dist;
0461 } else {
0462 return jet_perp * pow(jet_dist,_beta/2.0);
0463 }
0464 }
0465
0466
0467 virtual double beam_numerator(const fastjet::PseudoJet& particle) const {
0468 return particle.perp();
0469 }
0470
0471
0472 virtual double denominator(const fastjet::PseudoJet& ) const {
0473 return std::numeric_limits<double>::quiet_NaN();
0474 }
0475
0476 protected:
0477 double _beta;
0478 double _Rcutoff;
0479 double _RcutoffSq;
0480 };
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494 class OriginalGeometricMeasure : public MeasureDefinition {
0495
0496 public:
0497
0498 OriginalGeometricMeasure(double Rcutoff)
0499 : MeasureDefinition(), _Rcutoff(Rcutoff), _RcutoffSq(sq(Rcutoff)) {
0500 if (Rcutoff <= 0) throw Error("OriginalGeometricMeasure: You must choose Rcutoff > 0.");
0501 setTauMode(UNNORMALIZED_EVENT_SHAPE);
0502 setAxisScaling(false);
0503 }
0504
0505
0506 virtual std::string description() const;
0507
0508 virtual OriginalGeometricMeasure* create() const {return new OriginalGeometricMeasure(*this);}
0509
0510
0511
0512
0513 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const {
0514 return dot_product(lightFrom(axis), particle)/_RcutoffSq;
0515 }
0516
0517
0518 virtual double beam_numerator(const fastjet::PseudoJet& particle) const {
0519 fastjet::PseudoJet beam_a(0,0,1,1);
0520 fastjet::PseudoJet beam_b(0,0,-1,1);
0521 double min_perp = std::min(dot_product(beam_a, particle),dot_product(beam_b, particle));
0522 return min_perp;
0523 }
0524
0525
0526 virtual double denominator(const fastjet::PseudoJet& ) const {
0527 return std::numeric_limits<double>::quiet_NaN();
0528 }
0529
0530 protected:
0531 double _Rcutoff;
0532 double _RcutoffSq;
0533
0534 };
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545 class ModifiedGeometricMeasure : public MeasureDefinition {
0546
0547 public:
0548
0549 ModifiedGeometricMeasure(double Rcutoff)
0550 : MeasureDefinition(), _Rcutoff(Rcutoff), _RcutoffSq(sq(Rcutoff)) {
0551 if (Rcutoff <= 0) throw Error("ModifiedGeometricMeasure: You must choose Rcutoff > 0.");
0552 setTauMode(UNNORMALIZED_EVENT_SHAPE);
0553 setAxisScaling(false);
0554 }
0555
0556
0557 virtual std::string description() const;
0558
0559 virtual ModifiedGeometricMeasure* create() const {return new ModifiedGeometricMeasure(*this);}
0560
0561
0562
0563
0564 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const {
0565 return dot_product(lightFrom(axis), particle)/_RcutoffSq;
0566 }
0567
0568
0569 virtual double beam_numerator(const fastjet::PseudoJet& particle) const {
0570 fastjet::PseudoJet lightParticle = lightFrom(particle);
0571 return 0.5*particle.mperp()*lightParticle.pt();
0572 }
0573
0574
0575 virtual double denominator(const fastjet::PseudoJet& ) const {
0576 return std::numeric_limits<double>::quiet_NaN();
0577 }
0578
0579 protected:
0580 double _Rcutoff;
0581 double _RcutoffSq;
0582
0583
0584 };
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594 class ConicalGeometricMeasure : public MeasureDefinition {
0595
0596 public:
0597
0598
0599 ConicalGeometricMeasure(double jet_beta, double beam_gamma, double Rcutoff)
0600 : MeasureDefinition(), _jet_beta(jet_beta), _beam_gamma(beam_gamma), _Rcutoff(Rcutoff), _RcutoffSq(sq(Rcutoff)){
0601 if (jet_beta <= 0) throw Error("ConicalGeometricMeasure: You must choose beta > 0.");
0602 if (beam_gamma <= 0) throw Error("ConicalGeometricMeasure: You must choose gamma > 0.");
0603 if (Rcutoff <= 0) throw Error("ConicalGeometricMeasure: You must choose Rcutoff > 0.");
0604 setTauMode(UNNORMALIZED_EVENT_SHAPE);
0605 }
0606
0607
0608 virtual std::string description() const;
0609
0610 virtual ConicalGeometricMeasure* create() const {return new ConicalGeometricMeasure(*this);}
0611
0612
0613 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const {
0614 fastjet::PseudoJet lightAxis = lightFrom(axis);
0615 double pseudoRsquared = 2.0*dot_product(lightFrom(axis),particle)/(lightAxis.pt()*particle.pt());
0616 return pseudoRsquared;
0617 }
0618
0619
0620 virtual double beam_distance_squared(const fastjet::PseudoJet& ) const {
0621 return _RcutoffSq;
0622 }
0623
0624
0625 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const {
0626 double jet_dist = jet_distance_squared(particle,axis)/_RcutoffSq;
0627 if (jet_dist > 0.0) {
0628 fastjet::PseudoJet lightParticle = lightFrom(particle);
0629 double weight = (_beam_gamma == 1.0) ? 1.0 : std::pow(0.5*lightParticle.pt(),_beam_gamma - 1.0);
0630 return particle.pt() * weight * std::pow(jet_dist,_jet_beta/2.0);
0631 } else {
0632 return 0.0;
0633 }
0634 }
0635
0636
0637 virtual double beam_numerator(const fastjet::PseudoJet& particle) const {
0638 fastjet::PseudoJet lightParticle = lightFrom(particle);
0639 double weight = (_beam_gamma == 1.0) ? 1.0 : std::pow(0.5*lightParticle.pt(),_beam_gamma - 1.0);
0640 return particle.pt() * weight;
0641 }
0642
0643
0644 virtual double denominator(const fastjet::PseudoJet& ) const {
0645 return std::numeric_limits<double>::quiet_NaN();
0646 }
0647
0648 protected:
0649 double _jet_beta;
0650 double _beam_gamma;
0651 double _Rcutoff;
0652 double _RcutoffSq;
0653
0654 };
0655
0656
0657
0658
0659
0660
0661
0662
0663 class XConeMeasure : public ConicalGeometricMeasure {
0664
0665 public:
0666
0667 XConeMeasure(double jet_beta, double R)
0668 : ConicalGeometricMeasure(jet_beta,
0669 1.0,
0670 R
0671 ) { }
0672
0673
0674 virtual std::string description() const;
0675
0676 virtual XConeMeasure* create() const {return new XConeMeasure(*this);}
0677
0678 };
0679
0680
0681
0682
0683
0684
0685
0686
0687 class LightLikeAxis {
0688
0689 public:
0690
0691 LightLikeAxis() : _rap(0.0), _phi(0.0), _weight(0.0), _mom(0.0) {}
0692
0693 LightLikeAxis(double my_rap, double my_phi, double my_weight, double my_mom) :
0694 _rap(my_rap), _phi(my_phi), _weight(my_weight), _mom(my_mom) {}
0695
0696
0697 double rap() const {return _rap;}
0698
0699 double phi() const {return _phi;}
0700
0701 double weight() const {return _weight;}
0702
0703 double mom() const {return _mom;}
0704
0705
0706 void set_rap(double my_set_rap) {_rap = my_set_rap;}
0707
0708 void set_phi(double my_set_phi) {_phi = my_set_phi;}
0709
0710 void set_weight(double my_set_weight) {_weight = my_set_weight;}
0711
0712 void set_mom(double my_set_mom) {_mom = my_set_mom;}
0713
0714 void reset(double my_rap, double my_phi, double my_weight, double my_mom) {_rap=my_rap; _phi=my_phi; _weight=my_weight; _mom=my_mom;}
0715
0716
0717 fastjet::PseudoJet ConvertToPseudoJet();
0718
0719
0720 double DistanceSq(const fastjet::PseudoJet& input) const {
0721 return DistanceSq(input.rap(),input.phi());
0722 }
0723
0724
0725 double Distance(const fastjet::PseudoJet& input) const {
0726 return std::sqrt(DistanceSq(input));
0727 }
0728
0729
0730 double DistanceSq(const LightLikeAxis& input) const {
0731 return DistanceSq(input.rap(),input.phi());
0732 }
0733
0734
0735 double Distance(const LightLikeAxis& input) const {
0736 return std::sqrt(DistanceSq(input));
0737 }
0738
0739 private:
0740 double _rap;
0741 double _phi;
0742 double _weight;
0743 double _mom;
0744
0745
0746 double DistanceSq(double rap2, double phi2) const {
0747 double rap1 = _rap;
0748 double phi1 = _phi;
0749
0750 double distRap = rap1-rap2;
0751 double distPhi = std::fabs(phi1-phi2);
0752 if (distPhi > M_PI) {distPhi = 2.0*M_PI - distPhi;}
0753 return distRap*distRap + distPhi*distPhi;
0754 }
0755
0756
0757 double Distance(double rap2, double phi2) const {
0758 return std::sqrt(DistanceSq(rap2,phi2));
0759 }
0760
0761 };
0762
0763
0764
0765
0766
0767
0768
0769
0770
0771
0772
0773
0774
0775
0776
0777
0778
0779
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830
0831
0832
0833
0834
0835
0836
0837
0838
0839
0840
0841
0842
0843
0844
0845
0846
0847
0848
0849 }
0850
0851 FASTJET_END_NAMESPACE
0852
0853 #endif