00001
00002
00003 #ifndef XAODPARTICLEEVENT_VERSIONS_COMPOSITEPARTICLE_V1_H
00004 #define XAODPARTICLEEVENT_VERSIONS_COMPOSITEPARTICLE_V1_H
00005
00006
00007
00008 #include <vector>
00009
00010
00011 #include "AthContainers/ConstDataVector.h"
00012 #include "xAODBase/IParticle.h"
00013 #include "xAODBase/IParticleContainer.h"
00014 #include "AthLinks/ElementLink.h"
00015 #include "xAODMissingET/MissingET.h"
00016 #include "xAODEgamma/Electron.h"
00017 #include "xAODEgamma/Photon.h"
00018 #include "xAODMuon/Muon.h"
00019 #include "xAODTau/TauJet.h"
00020 #include "xAODJet/Jet.h"
00021 #include "xAODTruth/TruthParticle.h"
00022
00023
00024 #include "xAODParticleEvent/IParticleLink.h"
00025 #include "xAODParticleEvent/IParticleLinkContainer.h"
00026
00027
00028
00029 namespace xAOD {
00030
00039 class CompositeParticle_v1 : public IParticle {
00040
00041 public:
00043 CompositeParticle_v1();
00044
00047
00049 virtual double pt() const;
00051 virtual double eta() const;
00053 virtual double phi() const;
00055 virtual double m() const;
00057 virtual double e() const;
00059 virtual double rapidity() const;
00060
00062 typedef IParticle::FourMom_t FourMom_t;
00063
00065 virtual const FourMom_t& p4() const;
00066
00068 virtual Type::ObjectType type() const;
00070
00071
00074
00076 double px() const;
00078 double py() const;
00080 double pz() const;
00083 double et() const;
00084
00085
00087 void setP4( const FourMom_t& vec );
00089 void setPxPyPzE( double px, double py, double pz, double e );
00091 void setPx( double px );
00093 void setPy( double py );
00095 void setPz( double pz );
00097 void setE( double e );
00099
00100
00103
00105 bool hasCharge() const;
00107 float charge() const;
00109 void setCharge( float charge );
00110
00112 bool hasPdgId() const;
00114 int pdgId() const;
00116 void setPdgId( int pdgID );
00117
00119
00120
00128
00130 const FourMom_t& p4( const std::vector<int>& partIndices ) const;
00131
00136 inline const FourMom_t& p4( int partIndexA, int partIndexB ) const {
00137 return this->p4( std::vector<int>{partIndexA, partIndexB} );
00138 }
00140 inline const FourMom_t& p4( int partIndexA, int partIndexB, int partIndexC ) const {
00141 return this->p4( std::vector<int>{partIndexA, partIndexB, partIndexC} );
00142 }
00144 inline const FourMom_t& p4( int partIndexA, int partIndexB, int partIndexC, int partIndexD ) const {
00145 return this->p4( std::vector<int>{partIndexA, partIndexB, partIndexC, partIndexD} );
00146 }
00147
00149 double pt( const std::vector<int>& partIndices ) const;
00151 double eta( const std::vector<int>& partIndices ) const;
00153 double phi( const std::vector<int>& partIndices ) const;
00155 double m( const std::vector<int>& partIndices ) const;
00157 double p( const std::vector<int>& partIndices ) const;
00159 double e( const std::vector<int>& partIndices ) const;
00161 double rapidity( const std::vector<int>& partIndices ) const;
00162
00164 double px( const std::vector<int>& partIndices ) const;
00166 double py( const std::vector<int>& partIndices ) const;
00168 double pz( const std::vector<int>& partIndices ) const;
00171 double et( const std::vector<int>& partIndices ) const;
00172
00173
00174
00176 struct MT {
00177 enum Method {
00178 DEFAULT = 0
00179 };
00180 };
00181
00184 double mt( const std::vector<int>& partIndices, MT::Method method=MT::DEFAULT ) const;
00185
00186
00192 inline double mt( int partIndexA, int partIndexB=-2, MT::Method method=MT::DEFAULT ) const {
00193 if ( partIndexB==-2 ) {
00194 return this->mt( std::vector<int>{partIndexA}, method );
00195 }
00196 return this->mt( std::vector<int>{partIndexA, partIndexB}, method );
00197 }
00198
00200
00201
00202
00203
00207
00218 float weight( const std::vector<std::string>& varNames,
00219 const std::vector<int>& partIndices={} ) const;
00220
00221
00226 inline float weight( const std::string& varNameA ) const {
00227 return this->weight( std::vector<std::string>{varNameA} );
00228 }
00229 inline float weight( const std::string& varNameA,
00230 const std::string& varNameB ) const {
00231 return this->weight( std::vector<std::string>{varNameA,varNameB} );
00232 }
00233 inline float weight( const std::string& varNameA,
00234 const std::string& varNameB,
00235 const std::string& varNameC ) const {
00236 return this->weight( std::vector<std::string>{varNameA,varNameB,varNameC} );
00237 }
00238 inline float weight( const std::string& varNameA,
00239 const std::string& varNameB,
00240 const std::string& varNameC,
00241 const std::string& varNameD ) const {
00242 return this->weight( std::vector<std::string>{varNameA,varNameB,varNameC,varNameD} );
00243 }
00244 inline float weight( const std::string& varNameA,
00245 const std::string& varNameB,
00246 const std::string& varNameC,
00247 const std::string& varNameD,
00248 const std::string& varNameE ) const {
00249 return this->weight( std::vector<std::string>{varNameA,varNameB,varNameC,varNameD,varNameE} );
00250 }
00251
00252
00253 private:
00255 float weightHelper( const xAOD::IParticle* part,
00256 const xAOD::IParticle::ConstAccessor<float>& varAcc ) const;
00257
00258 public:
00260
00261
00262
00263
00266
00270 void addPart( const xAOD::IParticle* part, bool updateFourMom=true );
00271
00275 void addPart( const xAOD::IParticleLink& partLink, bool updateFourMom=true );
00276
00280 void addParts( const xAOD::IParticleLinkContainer& partLinkCont,
00281 bool updateFourMom=true );
00282
00289 void removePart( const xAOD::IParticle* part, bool updateFourMom=true );
00290
00297 void removePart( const xAOD::IParticleLink& partLink, bool updateFourMom=true );
00298
00299
00300
00304 const xAOD::MissingET* missingET() const;
00305
00309 void setMissingET( const xAOD::MissingET* met, bool updateFourMom=true );
00310
00314 void removeMissingET( bool updateFourMom=true );
00315
00316
00318 bool contains( const xAOD::MissingET* met ) const;
00320 bool contains( const xAOD::IParticle* part ) const;
00322 bool contains( const xAOD::IParticleLink& partLink ) const;
00323
00324
00327 std::size_t nParts() const;
00328
00330 std::size_t nCompParts() const;
00331
00333 std::size_t nPhotons() const;
00334
00336 std::size_t nElectrons() const;
00337
00339 std::size_t nMuons() const;
00340
00342 std::size_t nTaus() const;
00343
00345 std::size_t nLeptons() const;
00346
00348 std::size_t nJets() const;
00349
00351 std::size_t nTruthParts() const;
00352
00353
00355 const xAOD::IParticle* part( std::size_t index = 0 ) const;
00356
00358 const xAOD::IParticleLink& partLink( std::size_t index = 0 ) const;
00359
00361 const xAOD::IParticleLinkContainer& partLinks() const;
00362
00363
00371 template<typename CONTTYPE>
00372 ConstDataVector<CONTTYPE>* parts( ) const;
00373
00374
00375
00380 xAOD::CompositeParticle_v1* compPart( const std::vector<int>& partIndices,
00381 const std::vector<int>& otherPartIndices=std::vector<int>{},
00382 bool updateFourMom=true ) const;
00383
00384
00390 xAOD::CompositeParticle_v1* compPart( int partIndexA, int partIndexB, int partIndexC=-2,
00391 bool updateFourMom=true ) const {
00392 if ( partIndexC==-2 ) {
00393 return this->compPart( std::vector<int>{partIndexA, partIndexB}, std::vector<int>{}, updateFourMom );
00394 }
00395 return this->compPart( std::vector<int>{partIndexA, partIndexB, partIndexC}, std::vector<int>{}, updateFourMom );
00396 }
00397
00398
00401 const xAOD::CompositeParticle_v1* compPart( std::size_t index = 0 ) const;
00402
00405 const xAOD::Photon* photon( std::size_t index = 0 ) const;
00406
00409 const xAOD::Electron* electron( std::size_t index = 0 ) const;
00410
00413 const xAOD::Muon* muon( std::size_t index = 0 ) const;
00414
00417 const xAOD::TauJet* tau( std::size_t index = 0 ) const;
00418
00421 const xAOD::Jet* jet( std::size_t index = 0 ) const;
00422
00425 const xAOD::TruthParticle* truthPart( std::size_t index = 0 ) const;
00426
00428
00430
00431
00432
00441
00443 void addOtherPart( const xAOD::IParticle* part );
00444
00446 void addOtherPart( const xAOD::IParticleLink& partLink );
00447
00449 void addOtherParts( const xAOD::IParticleLinkContainer& partLinkCont );
00450
00451
00454 void removeOtherPart( const xAOD::IParticle* part );
00455
00458 void removeOtherPart( const xAOD::IParticleLink& partLink );
00459
00460
00461
00463 bool containsOther( const xAOD::IParticle* part ) const;
00465 bool containsOther( const xAOD::IParticleLink& partLink ) const;
00466
00467
00469 std::size_t nOtherParts() const;
00470
00472 std::size_t nOtherCompParts() const;
00473
00475 std::size_t nOtherPhotons() const;
00476
00478 std::size_t nOtherElectrons() const;
00479
00481 std::size_t nOtherMuons() const;
00482
00484 std::size_t nOtherTaus() const;
00485
00487 std::size_t nOtherLeptons() const;
00488
00490 std::size_t nOtherJets() const;
00491
00493 std::size_t nOtherTruthParts() const;
00494
00495
00497 const xAOD::IParticle* otherPart( std::size_t index = 0 ) const;
00498
00500 const xAOD::IParticleLink& otherPartLink( std::size_t index = 0 ) const;
00501
00503 const xAOD::IParticleLinkContainer& otherPartLinks() const;
00504
00505
00508 const xAOD::CompositeParticle_v1* otherCompPart( std::size_t index = 0 ) const;
00509
00512 const xAOD::Photon* otherPhoton( std::size_t index = 0 ) const;
00513
00516 const xAOD::Electron* otherElectron( std::size_t index = 0 ) const;
00517
00520 const xAOD::Muon* otherMuon( std::size_t index = 0 ) const;
00521
00524 const xAOD::TauJet* otherTau( std::size_t index = 0 ) const;
00525
00528 const xAOD::Jet* otherJet( std::size_t index = 0 ) const;
00529
00532 const xAOD::TruthParticle* otherTruthPart( std::size_t index = 0 ) const;
00533
00535
00537
00538
00544
00546 inline bool getBool( const std::string& varName ) const {
00547 return static_cast<bool>( this->auxdata<char>(varName) );
00548 }
00549
00551 inline int getInt( const std::string& varName ) const {
00552 return this->auxdata<int>(varName);
00553 }
00554
00556 inline unsigned int getUInt( const std::string& varName ) const {
00557 return this->auxdata<unsigned int>(varName);
00558 }
00559
00561 inline float getFloat( const std::string& varName ) const {
00562 return this->auxdata<float>(varName);
00563 }
00564
00566 inline double getDouble( const std::string& varName ) const {
00567 return this->auxdata<double>(varName);
00568 }
00569
00570
00572
00573
00574 protected:
00578 void setPartLinks( const xAOD::IParticleLinkContainer& constitLinks );
00579
00581 void setOtherPartLinks( const xAOD::IParticleLinkContainer& otherPartLinks );
00582
00583
00584 public:
00585
00587 void toPersistent();
00588
00589 private:
00591 mutable FourMom_t m_p4;
00592
00594 mutable bool m_p4Cached;
00595
00596 };
00597
00598
00599 }
00600
00601
00602
00603 inline
00604 const xAOD::CompositeParticle_v1*
00605 xAOD::CompositeParticle_v1::compPart( std::size_t index ) const
00606 {
00607 const xAOD::IParticle* ipart = this->part(index);
00608 if ( ipart->type() != xAOD::Type::CompositeParticle ){ return 0; }
00609 return static_cast<const xAOD::CompositeParticle_v1*>(ipart);
00610 }
00611
00612
00613 inline
00614 const xAOD::Photon*
00615 xAOD::CompositeParticle_v1::photon( std::size_t index ) const
00616 {
00617 const xAOD::IParticle* ipart = this->part(index);
00618 if ( ipart->type() != xAOD::Type::Photon ){ return 0; }
00619 return static_cast<const xAOD::Photon*>(ipart);
00620 }
00621
00622
00623 inline
00624 const xAOD::Electron*
00625 xAOD::CompositeParticle_v1::electron( std::size_t index ) const
00626 {
00627 const xAOD::IParticle* ipart = this->part(index);
00628 if ( ipart->type() != xAOD::Type::Electron ){ return 0; }
00629 return static_cast<const xAOD::Electron*>(ipart);
00630 }
00631
00632
00633 inline
00634 const xAOD::Muon*
00635 xAOD::CompositeParticle_v1::muon( std::size_t index ) const
00636 {
00637 const xAOD::IParticle* ipart = this->part(index);
00638 if ( ipart->type() != xAOD::Type::Muon ){ return 0; }
00639 return static_cast<const xAOD::Muon*>(ipart);
00640 }
00641
00642
00643 inline
00644 const xAOD::TauJet*
00645 xAOD::CompositeParticle_v1::tau( std::size_t index ) const
00646 {
00647 const xAOD::IParticle* ipart = this->part(index);
00648 if ( ipart->type() != xAOD::Type::Tau ){ return 0; }
00649 return static_cast<const xAOD::TauJet*>(ipart);
00650 }
00651
00652
00653 inline
00654 const xAOD::Jet*
00655 xAOD::CompositeParticle_v1::jet( std::size_t index ) const
00656 {
00657 const xAOD::IParticle* ipart = this->part(index);
00658 if ( ipart->type() != xAOD::Type::Jet ){ return 0; }
00659 return static_cast<const xAOD::Jet*>(ipart);
00660 }
00661
00662
00663 inline
00664 const xAOD::TruthParticle*
00665 xAOD::CompositeParticle_v1::truthPart( std::size_t index ) const
00666 {
00667 const xAOD::IParticle* ipart = this->part(index);
00668 if ( ipart->type() != xAOD::Type::TruthParticle ){ return 0; }
00669 return static_cast<const xAOD::TruthParticle*>(ipart);
00670 }
00671
00672
00673
00674 inline
00675 const xAOD::CompositeParticle_v1*
00676 xAOD::CompositeParticle_v1::otherCompPart( std::size_t index ) const
00677 {
00678 const xAOD::IParticle* ipart = this->otherPart(index);
00679 if ( ipart->type() != xAOD::Type::CompositeParticle ){ return 0; }
00680 return static_cast<const xAOD::CompositeParticle_v1*>(ipart);
00681 }
00682
00683
00684 inline
00685 const xAOD::Photon*
00686 xAOD::CompositeParticle_v1::otherPhoton( std::size_t index ) const
00687 {
00688 const xAOD::IParticle* ipart = this->otherPart(index);
00689 if ( ipart->type() != xAOD::Type::Photon ){ return 0; }
00690 return static_cast<const xAOD::Photon*>(ipart);
00691 }
00692
00693
00694 inline
00695 const xAOD::Electron*
00696 xAOD::CompositeParticle_v1::otherElectron( std::size_t index ) const
00697 {
00698 const xAOD::IParticle* ipart = this->otherPart(index);
00699 if ( ipart->type() != xAOD::Type::Electron ){ return 0; }
00700 return static_cast<const xAOD::Electron*>(ipart);
00701 }
00702
00703
00704 inline
00705 const xAOD::Muon*
00706 xAOD::CompositeParticle_v1::otherMuon( std::size_t index ) const
00707 {
00708 const xAOD::IParticle* ipart = this->otherPart(index);
00709 if ( ipart->type() != xAOD::Type::Muon ){ return 0; }
00710 return static_cast<const xAOD::Muon*>(ipart);
00711 }
00712
00713
00714 inline
00715 const xAOD::TauJet*
00716 xAOD::CompositeParticle_v1::otherTau( std::size_t index ) const
00717 {
00718 const xAOD::IParticle* ipart = this->otherPart(index);
00719 if ( ipart->type() != xAOD::Type::Tau ){ return 0; }
00720 return static_cast<const xAOD::TauJet*>(ipart);
00721 }
00722
00723
00724 inline
00725 const xAOD::Jet*
00726 xAOD::CompositeParticle_v1::otherJet( std::size_t index ) const
00727 {
00728 const xAOD::IParticle* ipart = this->otherPart(index);
00729 if ( ipart->type() != xAOD::Type::Jet ){ return 0; }
00730 return static_cast<const xAOD::Jet*>(ipart);
00731 }
00732
00733
00734 inline
00735 const xAOD::TruthParticle*
00736 xAOD::CompositeParticle_v1::otherTruthPart( std::size_t index ) const
00737 {
00738 const xAOD::IParticle* ipart = this->otherPart(index);
00739 if ( ipart->type() != xAOD::Type::TruthParticle ){ return 0; }
00740 return static_cast<const xAOD::TruthParticle*>(ipart);
00741 }
00742
00743
00744
00745
00746 #endif // XAODPARTICLEEVENT_VERSIONS_COMPOSITEPARTICLE_V1_H