00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "fastjet/Error.hh"
00033 #include "fastjet/PseudoJet.hh"
00034 #include "fastjet/ClusterSequence.hh"
00035 #include "fastjet/ClusterSequenceAreaBase.hh"
00036 #include<valarray>
00037 #include<iostream>
00038 #include<sstream>
00039 #include<cmath>
00040 #include<algorithm>
00041
00042 FASTJET_BEGIN_NAMESPACE
00043
00044 using namespace std;
00045
00046
00047
00048
00049 PseudoJet::PseudoJet(const double px, const double py, const double pz, const double E) {
00050
00051 _E = E ;
00052 _px = px;
00053 _py = py;
00054 _pz = pz;
00055
00056 this->_finish_init();
00057
00058
00059 _reset_indices();
00060
00061 }
00062
00063
00064
00066 void PseudoJet::_finish_init () {
00067 _kt2 = this->px()*this->px() + this->py()*this->py();
00068 _phi = pseudojet_invalid_phi;
00069 }
00070
00071
00072 void PseudoJet::_set_rap_phi() const {
00073
00074 if (_kt2 == 0.0) {
00075 _phi = 0.0; }
00076 else {
00077 _phi = atan2(this->py(),this->px());
00078 }
00079 if (_phi < 0.0) {_phi += twopi;}
00080 if (_phi >= twopi) {_phi -= twopi;}
00081 if (this->E() == abs(this->pz()) && _kt2 == 0) {
00082
00083
00084
00085
00086 double MaxRapHere = MaxRap + abs(this->pz());
00087 if (this->pz() >= 0.0) {_rap = MaxRapHere;} else {_rap = -MaxRapHere;}
00088 } else {
00089
00090
00091
00092 double effective_m2 = max(0.0,m2());
00093 double E_plus_pz = _E + abs(_pz);
00094
00095 _rap = 0.5*log((_kt2 + effective_m2)/(E_plus_pz*E_plus_pz));
00096 if (_pz > 0) {_rap = - _rap;}
00097 }
00098
00099 }
00100
00101
00102
00103
00104 valarray<double> PseudoJet::four_mom() const {
00105 valarray<double> mom(4);
00106 mom[0] = _px;
00107 mom[1] = _py;
00108 mom[2] = _pz;
00109 mom[3] = _E ;
00110 return mom;
00111 }
00112
00113
00114
00115
00116 double PseudoJet::operator () (int i) const {
00117 switch(i) {
00118 case X:
00119 return px();
00120 case Y:
00121 return py();
00122 case Z:
00123 return pz();
00124 case T:
00125 return e();
00126 default:
00127 ostringstream err;
00128 err << "PseudoJet subscripting: bad index (" << i << ")";
00129 throw Error(err.str());
00130 }
00131 return 0.;
00132 }
00133
00134
00135
00136 double PseudoJet::pseudorapidity() const {
00137 if (px() == 0.0 && py() ==0.0) return MaxRap;
00138 if (pz() == 0.0) return 0.0;
00139
00140 double theta = atan(perp()/pz());
00141 if (theta < 0) theta += pi;
00142 return -log(tan(theta/2));
00143 }
00144
00145
00146
00147 PseudoJet operator+ (const PseudoJet & jet1, const PseudoJet & jet2) {
00148
00149 return PseudoJet(jet1.px()+jet2.px(),
00150 jet1.py()+jet2.py(),
00151 jet1.pz()+jet2.pz(),
00152 jet1.E() +jet2.E() );
00153 }
00154
00155
00156
00157 PseudoJet operator- (const PseudoJet & jet1, const PseudoJet & jet2) {
00158
00159 return PseudoJet(jet1.px()-jet2.px(),
00160 jet1.py()-jet2.py(),
00161 jet1.pz()-jet2.pz(),
00162 jet1.E() -jet2.E() );
00163 }
00164
00165
00166
00167 PseudoJet operator* (double coeff, const PseudoJet & jet) {
00168
00169
00170 PseudoJet coeff_times_jet(jet);
00171 coeff_times_jet *= coeff;
00172 return coeff_times_jet;
00173 }
00174
00175
00176
00177 PseudoJet operator* (const PseudoJet & jet, double coeff) {
00178 return coeff*jet;
00179 }
00180
00181
00182
00183 PseudoJet operator/ (const PseudoJet & jet, double coeff) {
00184 return (1.0/coeff)*jet;
00185 }
00186
00187
00189 void PseudoJet::operator*=(double coeff) {
00190 _px *= coeff;
00191 _py *= coeff;
00192 _pz *= coeff;
00193 _E *= coeff;
00194 _kt2*= coeff*coeff;
00195
00196 }
00197
00198
00200 void PseudoJet::operator/=(double coeff) {
00201 (*this) *= 1.0/coeff;
00202 }
00203
00204
00205
00207 void PseudoJet::operator+=(const PseudoJet & other_jet) {
00208 _px += other_jet._px;
00209 _py += other_jet._py;
00210 _pz += other_jet._pz;
00211 _E += other_jet._E ;
00212 _finish_init();
00213 }
00214
00215
00216
00218 void PseudoJet::operator-=(const PseudoJet & other_jet) {
00219 _px -= other_jet._px;
00220 _py -= other_jet._py;
00221 _pz -= other_jet._pz;
00222 _E -= other_jet._E ;
00223 _finish_init();
00224 }
00225
00226
00227
00230
00231
00232
00233 PseudoJet & PseudoJet::boost(const PseudoJet & prest) {
00234
00235 if (prest.px() == 0.0 && prest.py() == 0.0 && prest.pz() == 0.0)
00236 return *this;
00237
00238 double m = prest.m();
00239 assert(m != 0);
00240
00241 double pf4 = ( px()*prest.px() + py()*prest.py()
00242 + pz()*prest.pz() + E()*prest.E() )/m;
00243 double fn = (pf4 + E()) / (prest.E() + m);
00244 _px += fn*prest.px();
00245 _py += fn*prest.py();
00246 _pz += fn*prest.pz();
00247 _E = pf4;
00248
00249 _finish_init();
00250 return *this;
00251 }
00252
00253
00254
00257
00258
00259
00260 PseudoJet & PseudoJet::unboost(const PseudoJet & prest) {
00261
00262 if (prest.px() == 0.0 && prest.py() == 0.0 && prest.pz() == 0.0)
00263 return *this;
00264
00265 double m = prest.m();
00266 assert(m != 0);
00267
00268 double pf4 = ( -px()*prest.px() - py()*prest.py()
00269 - pz()*prest.pz() + E()*prest.E() )/m;
00270 double fn = (pf4 + E()) / (prest.E() + m);
00271 _px -= fn*prest.px();
00272 _py -= fn*prest.py();
00273 _pz -= fn*prest.pz();
00274 _E = pf4;
00275
00276 _finish_init();
00277 return *this;
00278 }
00279
00280
00281
00283 bool have_same_momentum(const PseudoJet & jeta, const PseudoJet & jetb) {
00284 return jeta.px() == jetb.px()
00285 && jeta.py() == jetb.py()
00286 && jeta.pz() == jetb.pz()
00287 && jeta.E() == jetb.E();
00288 }
00289
00290
00291
00293 PseudoJet PtYPhiM(double pt, double y, double phi, double m) {
00294 double ptm = sqrt(pt*pt+m*m);
00295 return PseudoJet(pt*cos(phi), pt*sin(phi), ptm*sinh(y), ptm*cosh(y));
00296 }
00297
00298
00299
00300
00301 double PseudoJet::kt_distance(const PseudoJet & other) const {
00302
00303 double distance = min(_kt2, other._kt2);
00304 double dphi = abs(phi() - other.phi());
00305 if (dphi > pi) {dphi = twopi - dphi;}
00306 double drap = rap() - other.rap();
00307 distance = distance * (dphi*dphi + drap*drap);
00308 return distance;
00309 }
00310
00311
00312
00313
00314 double PseudoJet::plain_distance(const PseudoJet & other) const {
00315 double dphi = abs(phi() - other.phi());
00316 if (dphi > pi) {dphi = twopi - dphi;}
00317 double drap = rap() - other.rap();
00318 return (dphi*dphi + drap*drap);
00319 }
00320
00321
00324 double PseudoJet::delta_phi_to(const PseudoJet & other) const {
00325 double dphi = other.phi() - phi();
00326 if (dphi > pi) dphi -= twopi;
00327 if (dphi < -pi) dphi += twopi;
00328 return dphi;
00329 }
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 bool PseudoJet::has_associated_cluster_sequence() const{
00343 return (_associated_csw()) && (_associated_csw->is_alive());
00344 }
00345
00346
00347
00348
00349 const ClusterSequence* PseudoJet::associated_cluster_sequence() const{
00350 if (! has_associated_cluster_sequence()) return NULL;
00351
00352 return _associated_csw->cs();
00353 }
00354
00355
00356
00357
00358
00359
00360
00361
00362 const ClusterSequence * PseudoJet::validated_cs() const {
00363 if (!_associated_csw())
00364 throw Error("you requested information about the internal structure of a jet, but it is not associated with a ClusterSequence.");
00365 if (!_associated_csw->is_alive())
00366 throw Error("you requested information about the internal structure of a jet, but its associated ClusterSequence has gone out of scope.");
00367 return _associated_csw->cs();
00368 }
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 bool PseudoJet::has_partner(PseudoJet &partner) const{
00379 return validated_cs()->has_partner(*this, partner);
00380 }
00381
00382
00383
00384
00385
00386
00387
00388
00389 bool PseudoJet::has_child(PseudoJet &child) const{
00390 return validated_cs()->has_child(*this, child);
00391 }
00392
00393
00394
00395
00396
00397
00398
00399
00400 bool PseudoJet::has_parents(PseudoJet &parent1, PseudoJet &parent2) const{
00401 return validated_cs()->has_parents(*this, parent1, parent2);
00402 }
00403
00404
00405
00406
00407
00408
00409
00410 bool PseudoJet::contains(const PseudoJet &constituent) const{
00411 return validated_cs()->object_in_jet(constituent, *this);
00412 }
00413
00414
00415
00416
00417
00418
00419
00420 bool PseudoJet::is_inside(const PseudoJet &jet) const{
00421 return validated_cs()->object_in_jet(*this, jet);
00422 }
00423
00424
00425
00426
00427
00428 vector<PseudoJet> PseudoJet::constituents() const{
00429 return validated_cs()->constituents(*this);
00430 }
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445 std::vector<PseudoJet> PseudoJet::exclusive_subjets (const double & dcut) const {
00446 return validated_cs()->exclusive_subjets(*this, dcut);
00447 }
00448
00449
00450
00451
00452
00453
00454
00455
00456 int PseudoJet::n_exclusive_subjets(const double & dcut) const {
00457 return validated_cs()->n_exclusive_subjets(*this, dcut);
00458 }
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469 std::vector<PseudoJet> PseudoJet::exclusive_subjets (int nsub) const {
00470 return validated_cs()->exclusive_subjets(*this, nsub);
00471 }
00472
00473
00474
00475
00476
00477
00478
00479 double PseudoJet::exclusive_subdmerge(int nsub) const {
00480 return validated_cs()->exclusive_subdmerge(*this, nsub);
00481 }
00482
00483
00484
00485
00486
00487
00488
00489
00490 double PseudoJet::exclusive_subdmerge_max(int nsub) const {
00491 return validated_cs()->exclusive_subdmerge_max(*this, nsub);
00492 }
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502 const ClusterSequenceAreaBase * PseudoJet::validated_csab() const {
00503 const ClusterSequenceAreaBase *csab = dynamic_cast<const ClusterSequenceAreaBase*>(validated_cs());
00504 if (csab == NULL) throw Error("you requested jet-area related information, but the PseudoJet does not have associated area information.");
00505 return csab;
00506 }
00507
00508
00509
00510
00511 bool PseudoJet::has_area() const{
00512 if (! has_associated_cluster_sequence()) return false;
00513 return (dynamic_cast<const ClusterSequenceAreaBase*>(_associated_csw->cs()) != NULL);
00514 }
00515
00516
00517
00518
00519 double PseudoJet::area() const{
00520 return validated_csab()->area(*this);
00521 }
00522
00523
00524
00525
00526
00527 double PseudoJet::area_error() const{
00528 return validated_csab()->area_error(*this);
00529 }
00530
00531
00532
00533
00534 PseudoJet PseudoJet::area_4vector() const{
00535 return validated_csab()->area_4vector(*this);
00536 }
00537
00538
00539
00540
00541 bool PseudoJet::is_pure_ghost() const{
00542 return validated_csab()->is_pure_ghost(*this);
00543 }
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00555 PseudoJet::InexistentExtraInfo::InexistentExtraInfo() : Error("you attempted to perform a dynamic cast of a PseudoJet's extra info, but the extra info pointer was null")
00556 {}
00557
00558
00559
00560
00561
00562 void sort_indices(vector<int> & indices,
00563 const vector<double> & values) {
00564 IndexedSortHelper index_sort_helper(&values);
00565 sort(indices.begin(), indices.end(), index_sort_helper);
00566 }
00567
00568
00569
00570
00574 template<class T> vector<T> objects_sorted_by_values(
00575 const vector<T> & objects,
00576 const vector<double> & values) {
00577
00578 assert(objects.size() == values.size());
00579
00580
00581 vector<int> indices(values.size());
00582 for (size_t i = 0; i < indices.size(); i++) {indices[i] = i;}
00583
00584
00585 sort_indices(indices, values);
00586
00587
00588 vector<T> objects_sorted(objects.size());
00589
00590
00591 for (size_t i = 0; i < indices.size(); i++) {
00592 objects_sorted[i] = objects[indices[i]];
00593 }
00594
00595 return objects_sorted;
00596 }
00597
00598
00600 vector<PseudoJet> sorted_by_pt(const vector<PseudoJet> & jets) {
00601 vector<double> minus_kt2(jets.size());
00602 for (size_t i = 0; i < jets.size(); i++) {minus_kt2[i] = -jets[i].kt2();}
00603 return objects_sorted_by_values(jets, minus_kt2);
00604 }
00605
00606
00608 vector<PseudoJet> sorted_by_rapidity(const vector<PseudoJet> & jets) {
00609 vector<double> rapidities(jets.size());
00610 for (size_t i = 0; i < jets.size(); i++) {rapidities[i] = jets[i].rap();}
00611 return objects_sorted_by_values(jets, rapidities);
00612 }
00613
00614
00616 vector<PseudoJet> sorted_by_E(const vector<PseudoJet> & jets) {
00617 vector<double> energies(jets.size());
00618 for (size_t i = 0; i < jets.size(); i++) {energies[i] = -jets[i].E();}
00619 return objects_sorted_by_values(jets, energies);
00620 }
00621
00622
00624 vector<PseudoJet> sorted_by_pz(const vector<PseudoJet> & jets) {
00625 vector<double> pz(jets.size());
00626 for (size_t i = 0; i < jets.size(); i++) {pz[i] = jets[i].pz();}
00627 return objects_sorted_by_values(jets, pz);
00628 }
00629
00630
00631 FASTJET_END_NAMESPACE
00632