diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/CMakeLists.txt b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/CMakeLists.txt index 4b3e6626bc51a436849a4c8ce25f1e846b7e7079..52add9985b461a344605c82ef6dddf382734a041 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/CMakeLists.txt +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/CMakeLists.txt @@ -1,4 +1,4 @@ -# $Id: CMakeLists.txt 740788 2016-04-16 14:22:45Z krasznaa $ +# $Id: CMakeLists.txt 785662 2016-11-22 08:48:18Z guirriec $ ################################################################################ # Package: ParticleJetTools ################################################################################ @@ -6,33 +6,60 @@ # Declare the package name: atlas_subdir( ParticleJetTools ) + # Declare the package's dependencies: -atlas_depends_on_subdirs( - PUBLIC - Control/AthToolSupport/AsgTools - Event/EventPrimitives - Event/xAOD/xAODJet - Event/xAOD/xAODTruth - GaudiKernel - PhysicsAnalysis/MCTruthClassifier - Reconstruction/Jet/JetInterface - Reconstruction/Jet/JetRec - PRIVATE - Control/AthAnalysisBaseComps - Control/AthContainers - Generators/TruthUtils ) +if( XAOD_STANDALONE ) + atlas_depends_on_subdirs( + PUBLIC + Control/AthToolSupport/AsgTools + Event/EventPrimitives + Event/xAOD/xAODJet + Event/xAOD/xAODTruth + PhysicsAnalysis/MCTruthClassifier + Reconstruction/Jet/JetInterface + Reconstruction/Jet/JetRec + PRIVATE + Control/AthContainers + Generators/TruthUtils ) +else() + atlas_depends_on_subdirs( + PUBLIC + Control/AthToolSupport/AsgTools + Event/EventPrimitives + Event/xAOD/xAODJet + Event/xAOD/xAODTruth + GaudiKernel + PhysicsAnalysis/MCTruthClassifier + Reconstruction/Jet/JetInterface + Reconstruction/Jet/JetRec + PRIVATE + Control/AthAnalysisBaseComps + Control/AthContainers + Generators/TruthUtils ) +endif() # Component(s) in the package: -atlas_add_library( ParticleJetToolsLib - ParticleJetTools/*.h Root/*.cxx src/*.cxx - PUBLIC_HEADERS ParticleJetTools - LINK_LIBRARIES AsgTools EventPrimitives xAODJet xAODTruth GaudiKernel - JetInterface MCTruthClassifierLib JetRecLib - PRIVATE_LINK_LIBRARIES AthAnalysisBaseComps AthContainers TruthUtils ) - -atlas_add_component( ParticleJetTools - src/components/*.cxx - LINK_LIBRARIES ParticleJetToolsLib ) +if( XAOD_STANDALONE ) + atlas_add_library( ParticleJetToolsLib + ParticleJetTools/*.h Root/*.cxx src/*.cxx + PUBLIC_HEADERS ParticleJetTools + LINK_LIBRARIES AsgTools EventPrimitives xAODJet xAODTruth + JetInterface MCTruthClassifierLib JetRecLib + PRIVATE_LINK_LIBRARIES AthContainers TruthUtils ) +else() + atlas_add_library( ParticleJetToolsLib + ParticleJetTools/*.h Root/*.cxx src/*.cxx + PUBLIC_HEADERS ParticleJetTools + LINK_LIBRARIES AsgTools EventPrimitives xAODJet xAODTruth GaudiKernel + JetInterface MCTruthClassifierLib JetRecLib + PRIVATE_LINK_LIBRARIES AthAnalysisBaseCompsLib AthContainers TruthUtils ) +endif() + +if( NOT XAOD_STANDALONE ) + atlas_add_component( ParticleJetTools + src/components/*.cxx + LINK_LIBRARIES GaudiKernel ParticleJetToolsLib ) +endif() atlas_add_dictionary( ParticleJetToolsDict ParticleJetTools/ParticleJetToolsDict.h @@ -42,3 +69,4 @@ atlas_add_dictionary( ParticleJetToolsDict # Install files from the package: atlas_install_python_modules( python/*.py ) atlas_install_joboptions( share/*.py ) + diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/CopyTruthJetParticles.h b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/CopyTruthJetParticles.h index b05d75ba2d5dce2186f2aba2e62d7812f08fb58d..611b8589ae3e21d4d3ad2d16b71e21a96eccefff 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/CopyTruthJetParticles.h +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/CopyTruthJetParticles.h @@ -40,6 +40,9 @@ private: bool m_includeMu; //!< Include muons in particles bool m_includePromptLeptons; //!< Include particles from prompt decays, i.e. not from hadrons // bool m_includeTau; //!< Include particles from tau decays + // -- added for dark jet clustering -- // + bool m_includeSM; //!< Include SM particles + bool m_includeDark; //!< Include dark hadrons bool isPrompt( const xAOD::TruthParticle* tp, std::map<const xAOD::TruthParticle*,MCTruthPartClassifier::ParticleOrigin>& originMap ) const; diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/IJetTruthMatching.h b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/IJetTruthMatching.h index c9d4e1324ea04b6973092d54d29baca49ec42404..b6770d47618e6561c13c9c9bde8444fd31b4ae62 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/IJetTruthMatching.h +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/IJetTruthMatching.h @@ -18,6 +18,8 @@ // Gaudi #include "AsgTools/IAsgTool.h" #include "xAODJet/Jet.h" +#include <map> +#include <string> class Jet; @@ -38,6 +40,35 @@ namespace Analysis ASG_TOOL_INTERFACE(IJetTruthMatching) public: + struct MatchInfo { + // Predefined name to label the jets passing the matching. + int jetLabel = 0; + + // Number of MC Events in the McEventCollection + int NEventInCollection = 0; + + // Barcode of the matched parton (to be able to find the parton in the McEventColl) + int barcode = 0; + + // pdg code of the parton/baryon the jet has been matched to (which was closest) + int pdg = 0; + + // Keep track of distances to quarks. + std::map<std::string, double> distanceToQuarks; + + // Position of the lowest lying B hadron vertex decay + //Eigen::Vector3d BDecVtx; + //int Bpdg + + double deltaRMinTo (const std::string& key) const + { + auto it = distanceToQuarks.find (key); + if (it != distanceToQuarks.end()) + return it->second; + return 9999; + } + }; + /** Virtual destructor */ virtual ~IJetTruthMatching(){}; @@ -45,15 +76,12 @@ namespace Analysis // static const InterfaceID& interfaceID() { return IID_IJetTruthMatching; }; /** Method to truth tag a jet: */ - virtual bool matchJet(const xAOD::Jet& myJet) = 0; + virtual bool matchJet(const xAOD::Jet& myJet, + MatchInfo* info = nullptr) const = 0; //virtual bool matchJet(const Jet& myJet) = 0; /** print parameter settings of the truth match tool */ - virtual void m_printParameterSettings() = 0; - - /** Return the name to label the jets passing the matching: */ - virtual const int& jetLabel() const = 0; - + virtual void printParameterSettings() const = 0; }; } // end of namespace diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetQuarkLabel.h b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetQuarkLabel.h index a4171ee5046390214b5596631dc1a99e4bc647f5..a2e7e5ace1e4b1c0debc087b77ed5d65392d851d 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetQuarkLabel.h +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetQuarkLabel.h @@ -39,8 +39,8 @@ class JetQuarkLabel : public asg::AsgTool, virtual public IJetTruthMatching { public: JetQuarkLabel(const std::string& name); virtual ~JetQuarkLabel(); - StatusCode initialize(); - StatusCode finalize(); + virtual StatusCode initialize() override; + virtual StatusCode finalize() override; /* Method to truth tag a jet. * NB: for this particular algorithm, matchJet is TRUE if the jet is matched @@ -48,31 +48,11 @@ class JetQuarkLabel : public asg::AsgTool, virtual public IJetTruthMatching { * longer a job option. */ - virtual bool matchJet(const xAOD::Jet& myJet); + virtual bool matchJet(const xAOD::Jet& myJet, + MatchInfo* info = nullptr) const override; - virtual void m_printParameterSettings(); + virtual void printParameterSettings() const override; - /** NEXT METHODS ARE ONLY ACCESSIBLE AFTER CASTING!! */ - - /** Return barcode */ - int barcode() const; - - /** Return pdg to match */ - int pdgCode() const; - - /** Return the predefined name to label the jets passing the matching: */ - inline const int& jetLabel() const { return m_jetLabel; } - - /** Return the min distance to quarks: */ - double deltaRMinTo(const std::string&) const; - inline const std::map<std::string, double>& distanceToQuarks() const { return m_distanceToQuarks; } - - /** Return the B decay vertex position: */ - inline const Eigen::Vector3d& BDecVtx() const { return m_BDecVtx; } - int Bpdg() const { return m_Bpdg; } - - /** Get the number of MC Events in the McEventCollection: */ - inline int NEventInCollection() const { return m_NEventInCollection; } inline void EventSelection(short s) { m_inTime = s; } inline short EventSelection() const { return m_inTime; } @@ -82,21 +62,10 @@ class JetQuarkLabel : public asg::AsgTool, virtual public IJetTruthMatching { double m_ptCut; //!< pT cut for partons bool m_noDoc; short m_inTime; - bool m_testJet(const xAOD::Jet&, const xAOD::TruthEventContainer*); - int m_jetLabel; //!< label to use for matching jets - std::map<std::string, double> m_distanceToQuarks; //!< keep track of distances to quarks - Eigen::Vector3d m_BDecVtx; //!< positon of the lowest lying B hadron vertex decay - int m_pdg; //!< pdg code of the parton/baryon the jet has been matched to (which was closest) - int m_barcode; //!< barcode of the matched parton (to be able to find the parton in the McEventColl) - int m_Bpdg; - int m_NEventInCollection; + bool testJet(const xAOD::Jet&, const xAOD::TruthEventContainer*, + MatchInfo* info) const; }; -/** Return barcode */ -inline int JetQuarkLabel::barcode() const { return m_barcode; } - -/** Return pdg to match */ -inline int JetQuarkLabel::pdgCode() const { return m_pdg; } } #endif // TRUTHMATCHTOOLS_JETQUARKLABEL_H diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetTrackAssociation.h b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetTrackAssociation.h new file mode 100644 index 0000000000000000000000000000000000000000..fc9bd067954388dde824ff53df38cdb66507bc08 --- /dev/null +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetTrackAssociation.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// author: cpollard@cern.ch + +#ifndef JETTRACKTOOLS_JETTRACKASSOCIATION_H +#define JETTRACKTOOLS_JETTRACKASSOCIATION_H + +#include "AsgTools/AsgTool.h" +#include "JetInterface/IJetModifier.h" +#include "xAODTracking/TrackParticle.h" + +#include <vector> +#include <string> + +namespace Analysis { + + class JetTrackAssociation : public asg::AsgTool, public IJetModifier { + ASG_TOOL_INTERFACE(JetTrackAssociation) + ASG_TOOL_CLASS(JetTrackAssociation, IJetModifier) + public: + + JetTrackAssociation(const std::string& name); + + int modify(xAOD::JetContainer& jets) const; + + // obvs to be provided by the deriving class + virtual const std::vector<std::vector<const xAOD::TrackParticle*> >* + match(xAOD::JetContainer&) const = 0; + + + private: + std::string m_outputCollectionName; + }; + +} +#endif diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetTrackCenterOfMassAssociation.h b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetTrackCenterOfMassAssociation.h new file mode 100644 index 0000000000000000000000000000000000000000..44df8b86afa0f41aadd6b4d366dc80efe18a6320 --- /dev/null +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetTrackCenterOfMassAssociation.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// author: jie.yu@cern.ch + +#ifndef JETTRACKTOOLS_JETTRACKCENTEROFMASSASSOCIATION_H +#define JETTRACKTOOLS_JETTRACKCENTEROFMASSASSOCIATION_H + +#include "ParticleJetTools/JetTrackAssociation.h" + +#include <vector> +#include <string> + +namespace Analysis { + + class JetTrackCenterOfMassAssociation : public JetTrackAssociation { + ASG_TOOL_CLASS2(JetTrackCenterOfMassAssociation, JetTrackAssociation, IJetModifier) + public: + + JetTrackCenterOfMassAssociation(const std::string& name); + + const std::vector<std::vector<const xAOD::TrackParticle*> >* + match(xAOD::JetContainer&) const; + + inline double getAngleSize(const double& par_R) const{ + double result = acos(1-par_R*0.5); + return result; + } + + + private: + std::string m_inputTrackCollectionName; + double m_trackMatchCone; + double m_parentJetCone; + }; + +} +#endif + diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetTrackShrinkingConeAssociation.h b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetTrackShrinkingConeAssociation.h new file mode 100644 index 0000000000000000000000000000000000000000..589e37d578b306e3e2561e403e722392e1987ed7 --- /dev/null +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetTrackShrinkingConeAssociation.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// author: cpollard@cern.ch + +#ifndef JETTRACKTOOLS_JETTRACKSHRINKINGCONEASSOCIATION_H +#define JETTRACKTOOLS_JETTRACKSHRINKINGCONEASSOCIATION_H + +#include "ParticleJetTools/JetTrackAssociation.h" + +#include <vector> +#include <string> + +namespace Analysis { + + class JetTrackShrinkingConeAssociation : public JetTrackAssociation { + ASG_TOOL_CLASS2(JetTrackShrinkingConeAssociation, JetTrackAssociation, IJetModifier) + public: + + JetTrackShrinkingConeAssociation(const std::string& name); + + const std::vector<std::vector<const xAOD::TrackParticle*> >* + match(xAOD::JetContainer&) const; + + inline double coneSize(double pt) const { + return (m_coneSizeFitPar1 + exp(m_coneSizeFitPar2 + m_coneSizeFitPar3*pt)); + } + + + private: + std::string m_inputTrackCollectionName; + double m_coneSizeFitPar1; + double m_coneSizeFitPar2; + double m_coneSizeFitPar3; + }; + +} +#endif + diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleJetToolsDict.h b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleJetToolsDict.h index b8023abc9f9ad45c3de280c7728f30954e881825..71d2ce9960fd4c3b0297b14af9738e91906a166d 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleJetToolsDict.h +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleJetToolsDict.h @@ -11,5 +11,8 @@ #include "ParticleJetTools/CopyFlavorLabelTruthParticles.h" #include "ParticleJetTools/CopyTruthJetParticles.h" #include "ParticleJetTools/ParticleJetDeltaRLabelTool.h" +#include "ParticleJetTools/JetTrackAssociation.h" +#include "ParticleJetTools/JetTrackCenterOfMassAssociation.h" +#include "ParticleJetTools/JetTrackShrinkingConeAssociation.h" #endif diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleToJetAssociator.h b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleToJetAssociator.h index ec868f12ada1ef2ee3a9a6710d3282c9990b6f60..a67e5e38dfb4d32e8d43a551824858263eacffad 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleToJetAssociator.h +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleToJetAssociator.h @@ -57,10 +57,10 @@ class ParticleToJetAssociator : public asg::AsgTool { static const InterfaceID& interfaceID() { return IID_ParticleToJetAssociator; }; #endif - /** AlgTool initailize method */ - StatusCode initialize(); + /** AlgTool initialize method */ + virtual StatusCode initialize() override; /** AlgTool finalize method */ - StatusCode finalize(); + virtual StatusCode finalize() override; // template<typename ConstituentType, typename coll> void associateParticlesToJets( // JetCollection* SGParticleJetContainer, @@ -74,9 +74,9 @@ class ParticleToJetAssociator : public asg::AsgTool { std::vector<ConstituentType*> associateParticlesToJets(jetcollection_t* theJets, const coll* particleContainer, - const std::string& constituentName); + const std::string& constituentName) const; - inline double getConeSize(double pt) { //!< helper method to get the cone size for a given jet pT + inline double getConeSize(double pt) const { //!< helper method to get the cone size for a given jet pT return (m_coneSizeFitPar1 + exp(m_coneSizeFitPar2 + m_coneSizeFitPar3*pt)); } @@ -175,7 +175,7 @@ template<typename ConstituentType, typename coll> inline std::vector<ConstituentType*> ParticleToJetAssociator::associateParticlesToJets(jetcollection_t* theJets, const coll* particleContainer, - const std::string& constituentName) { + const std::string& constituentName) const { std::vector<ConstituentType*> vecTrackConst; ATH_MSG_VERBOSE("Number of Jets : " << theJets->size()); diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/CopyTruthJetParticles.cxx b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/CopyTruthJetParticles.cxx index 14c9d74de25afbf4002957969f857fc8b7b43e38..a10b37ba17174b27de3dcafe820b562f3872c9bb 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/CopyTruthJetParticles.cxx +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/CopyTruthJetParticles.cxx @@ -33,6 +33,12 @@ CopyTruthJetParticles::CopyTruthJetParticles(const std::string& name) declareProperty("IncludeMuons", m_includeMu=false, "Include muons in the output collection"); declareProperty("IncludePromptLeptons", m_includePromptLeptons=true, "Include leptons from prompt decays (i.e. not from hadron decays) in the output collection"); // declareProperty("IncludeTauLeptons", m_includeTau=true, "Include leptons from tau decays in the output collection"); + + // -- added for dark jet clustering -- // + declareProperty("IncludeSMParts", m_includeSM=true, "Include SM particles in the output collection"); + declareProperty("IncludeDarkHads", m_includeDark=false, "Include dark hadrons in the output collection"); + // ----------------------------------- // + declareProperty("MaxAbsEta", m_maxAbsEta); declareProperty("BarCodeOffset", m_barcodeOffset); declareProperty("BarCodeFromMetadata", m_barcodeFromMetadata); @@ -51,7 +57,11 @@ bool CopyTruthJetParticles::classifyJetInput(const xAOD::TruthParticle* tp, int if (tp->barcode()>=barcodeOffset) return false; // Particle is from G4 int pdgid = tp->pdgId(); if (pdgid==21 && tp->e()==0) return false; // Work around for an old generator bug - if ( tp->status() %1000 !=1 ) return false; // Stable! + + // -- changed for dark jet clustering -- // + //if ( tp->status() %1000 !=1 ) return false; // Stable! + if ( tp->status()%1000!=1 && !m_includeDark ) return false; // dark hadrons will not be status 1 + // ----------------------------------- // // Easy classifiers by PDG ID if (!m_includeNu && MC::isNonInteracting(pdgid)) return false; @@ -72,6 +82,18 @@ bool CopyTruthJetParticles::classifyJetInput(const xAOD::TruthParticle* tp, int // } } + // -- added for dark jet clustering -- // + // new classifiers to account for dark particles + // for dark jets: ignore SM particles; include only "stable" dark hadrons + if (!m_includeSM && abs(tp->pdgId()) < 4.9e6) return false; + if (m_includeDark) { + if (abs(tp->pdgId()) <= 4900101) return false; // ignore Xd, qd, gd + if (abs(tp->child()->pdgId()) >= 4.9e6) return false; // ignore "non-stable" dark hadrons (decaying to dark sector) -- "stable" if decaying to SM + } + // for SM jets: ignore dark particles - probably unnecessary bc of status requirement above + if (!m_includeDark && abs(tp->pdgId()) >= 4.9e6) return false; + // ----------------------------------- // + if(!m_includePromptLeptons && abs(pdgid)==22 && ( isPrompt( tp, originMap ) || getPartOrigin( tp, originMap )==FSRPhot ) ) { // Only exclude photons within deltaR of leptons (if m_photonCone<0, exclude all photons) if(m_photonCone>0) { diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetConeLabeling.cxx b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetConeLabeling.cxx index 262e7c7b9d314545b023f84f5255f94aa386b1b3..c4b3445ed8924266ef07b077b8849e5b87ab0154 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetConeLabeling.cxx +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetConeLabeling.cxx @@ -78,16 +78,14 @@ namespace Analysis { if (!m_jetTruthMatchTool.empty() && doTruthInfo) { //TruthInfo* truthInfo = new TruthInfo("TruthInfo"); - jetIsMatched = m_jetTruthMatchTool->matchJet( jet ); - JetQuarkLabel* jql = dynamic_cast<JetQuarkLabel*>(&(*m_jetTruthMatchTool)); // & gets the pointer out of the ToolHandle to cast it! - if(jql) { - jet.setAttribute("TruthLabelDeltaR_B",jql->deltaRMinTo("B")); - jet.setAttribute("TruthLabelDeltaR_C",jql->deltaRMinTo("C")); - jet.setAttribute("TruthLabelDeltaR_T",jql->deltaRMinTo("T")); - } + Analysis::IJetTruthMatching::MatchInfo info; + jetIsMatched = m_jetTruthMatchTool->matchJet( jet, &info ); + jet.setAttribute("TruthLabelDeltaR_B",info.deltaRMinTo("B")); + jet.setAttribute("TruthLabelDeltaR_C",info.deltaRMinTo("C")); + jet.setAttribute("TruthLabelDeltaR_T",info.deltaRMinTo("T")); // if ( jetIsMatched ) { - thisJetTruthLabel = m_jetTruthMatchTool->jetLabel(); + thisJetTruthLabel = info.jetLabel; //if(thisJetTruthLabel=="B") { //jet.set_pdgId(PDG::b);// AA - need jet input //if (jql) { diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetQuarkLabel.cxx b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetQuarkLabel.cxx index 4e39379d614cb4c9a87b4ef57d80967ea6f0676e..cad19fc6543020e1ecfc57773eb08ea45acfdbb6 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetQuarkLabel.cxx +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetQuarkLabel.cxx @@ -34,12 +34,7 @@ JetQuarkLabel::JetQuarkLabel(const std::string& name) m_deltaRCut(0.3), m_ptCut(5.*GeVtoMeV), m_noDoc(true), - m_inTime(-1), - m_jetLabel(0), - m_pdg(0), - m_barcode(0), - m_Bpdg(0), - m_NEventInCollection(0) + m_inTime(-1) { declareProperty("McEventCollection", m_mcEventCollection); declareProperty("deltaRCut", m_deltaRCut); @@ -58,9 +53,11 @@ StatusCode JetQuarkLabel::finalize() { return StatusCode::SUCCESS; } - bool JetQuarkLabel::matchJet(const xAOD::Jet& myJet) +bool JetQuarkLabel::matchJet(const xAOD::Jet& myJet, + MatchInfo* info /*= nullptr*/) const { - m_jetLabel = 0; + if (info) + *info = MatchInfo(); /* ----------------------------------------------------------------------------------- */ /* Retrieve McEventCollection */ @@ -72,7 +69,7 @@ StatusCode JetQuarkLabel::finalize() { ATH_MSG_DEBUG(m_mcEventCollection << " not found in StoreGate."); return false; } - return m_testJet(myJet,myMcEventCollection); + return testJet(myJet,myMcEventCollection); */ //retrieve xAOD::TruthEvent @@ -82,12 +79,13 @@ StatusCode JetQuarkLabel::finalize() { ATH_MSG_DEBUG(m_mcEventCollection << " not found in StoreGate."); return false; } - return m_testJet(myJet,truthEventContainer); + return testJet(myJet,truthEventContainer, info); } - bool JetQuarkLabel::m_testJet(const xAOD::Jet& myJet, - const xAOD::TruthEventContainer* truthEventContainer) + bool JetQuarkLabel::testJet(const xAOD::Jet& myJet, + const xAOD::TruthEventContainer* truthEventContainer, + MatchInfo* info) const { TLorentzVector jet_hlv = myJet.p4(); @@ -96,13 +94,10 @@ StatusCode JetQuarkLabel::finalize() { - m_NEventInCollection = truthEventContainer->size(); + int NEventInCollection = truthEventContainer->size(); + if (info) + info->NEventInCollection =NEventInCollection; - m_barcode = 0; - m_pdg = 0; - m_Bpdg = 0; - m_BDecVtx = Eigen::Vector3d(); - m_distanceToQuarks.clear(); // Tag only jet in the ID acceptance : not anymore... // Labelling might be usefull also outside ID acceptance if (fabs(myJet.eta()) > 2.5) return false; // @@ -220,17 +215,21 @@ StatusCode JetQuarkLabel::finalize() { } nLab++; } - ATH_MSG_DEBUG("Number of events in the EventCollection : " << m_NEventInCollection << " and used for labelling " << nLab); + ATH_MSG_DEBUG("Number of events in the EventCollection : " << NEventInCollection << " and used for labelling " << nLab); - m_distanceToQuarks.insert(std::make_pair("B",deltaRB)); - m_distanceToQuarks.insert(std::make_pair("C",deltaRC)); - m_distanceToQuarks.insert(std::make_pair("T",deltaRT)); //it is not a quark ! + if (info) { + info->distanceToQuarks.insert(std::make_pair("B",deltaRB)); + info->distanceToQuarks.insert(std::make_pair("C",deltaRC)); + info->distanceToQuarks.insert(std::make_pair("T",deltaRT)); //it is not a quark ! + } ATH_MSG_VERBOSE("DeltaR " << deltaRB << " " << deltaRC << " " << deltaRT); if (deltaRB < m_deltaRCut) { - m_pdg = 5; - m_barcode = barcb; - m_jetLabel = 5; - ATH_MSG_VERBOSE("Jet matched with a b "<<m_barcode<<" after FSR, dR: " << deltaRB); + if (info) { + info->pdg = 5; + info->barcode = barcb; + info->jetLabel = 5; + } + ATH_MSG_VERBOSE("Jet matched with a b "<<barcb<<" after FSR, dR: " << deltaRB); //JBdV Try Herwig !!! If Bhadron --> quark, the corresponding decay vertex is the primary !! // (but the the following Hadron vertices are OK) if (LabellingParticle == 0) { @@ -274,10 +273,12 @@ StatusCode JetQuarkLabel::finalize() { ATH_MSG_VERBOSE("b quark child " << pdg << " barcode = " << (*thisChild)->barcode()); if (deltaRbB < deltaRbBmin) { if ((*thisChild)->hasDecayVtx()) { - m_BDecVtx[0] = (*thisChild)->decayVtx()->position().x(); - m_BDecVtx[1] = (*thisChild)->decayVtx()->position().y(); - m_BDecVtx[2] = (*thisChild)->decayVtx()->position().z(); - m_Bpdg = pdg; + if (info) { + info->BDecVtx[0] = (*thisChild)->decayVtx()->position().x(); + info->BDecVtx[1] = (*thisChild)->decayVtx()->position().y(); + info->BDecVtx[2] = (*thisChild)->decayVtx()->position().z(); + info->Bpdg = pdg; + } std::vector<ElementLink<xAOD::TruthParticleContainer> >::const_iterator goodChildEL = (*thisChild)->decayVertex()->outgoingParticles().begin(); std::vector<ElementLink<xAOD::TruthParticleContainer> >::const_iterator goodChildE = (*thisChild)->decayVertex()->outgoingParticles().begin(); //HepMC::GenVertex::particle_iterator goodChild = (*thisChild)->end_vertex()->particles_begin(HepMC::children); @@ -296,11 +297,13 @@ StatusCode JetQuarkLabel::finalize() { } } if ((*goodbChild)->end_vertex()) { - m_BDecVtx[0] = (*goodbChild)->end_vertex()->position().x(); - m_BDecVtx[1] = (*goodbChild)->end_vertex()->position().y(); - m_BDecVtx[2] = (*goodbChild)->end_vertex()->position().z(); - ATH_MSG_VERBOSE( "Trying to recover pdg Good Child = " << (*goodbChild)->pdg_id() - << " Decay vertex " << m_BDecVtx[0] << " " << m_BDecVtx[1] << " " << m_BDecVtx[2] ); + if (info) { + info->BDecVtx[0] = (*goodbChild)->end_vertex()->position().x(); + info->BDecVtx[1] = (*goodbChild)->end_vertex()->position().y(); + info->BDecVtx[2] = (*goodbChild)->end_vertex()->position().z(); + ATH_MSG_VERBOSE( "Trying to recover pdg Good Child = " << (*goodbChild)->pdg_id() + << " Decay vertex " << info->BDecVtx[0] << " " << info->BDecVtx[1] << " " << info->BDecVtx[2] ); + } break; } } @@ -321,10 +324,12 @@ StatusCode JetQuarkLabel::finalize() { " px = " << theBHad->momentum().px() << " py = " << theBHad->momentum().py() << " pz = " << theBHad->momentum().pz() ); - ATH_MSG_VERBOSE( - " vx = " << m_BDecVtx[0] - << " vy = " << m_BDecVtx[1] - << " vz = " << m_BDecVtx[2] ); + if (info) { + ATH_MSG_VERBOSE( + " vx = " << info->BDecVtx[0] + << " vy = " << info->BDecVtx[1] + << " vz = " << info->BDecVtx[2] ); + } } } } @@ -333,34 +338,32 @@ StatusCode JetQuarkLabel::finalize() { // return true; } else if (deltaRC < m_deltaRCut) { - m_pdg = 4; - m_barcode = barcc; - m_jetLabel = 4; - ATH_MSG_VERBOSE("Jet matched with a c "<<m_barcode<<" after FSR, dR: " << deltaRC); + if (info) { + info->pdg = 4; + info->barcode = barcc; + info->jetLabel = 4; + } + ATH_MSG_VERBOSE("Jet matched with a c "<<barcc<<" after FSR, dR: " << deltaRC); return true; } else if (deltaRT < m_deltaRCut) { ATH_MSG_VERBOSE("Jet matched with a tau dR: " << deltaRT); - m_pdg = 15; - m_jetLabel = 15; + if (info) { + info->pdg = 15; + info->jetLabel = 15; + } return true; } else { - m_pdg = 0; - m_barcode = 0; - m_jetLabel = 0; + if (info) { + info->pdg = 0; + info->barcode = 0; + info->jetLabel = 0; + } return true; } return false; } -void JetQuarkLabel::m_printParameterSettings() { -} - -double JetQuarkLabel::deltaRMinTo(const std::string& key) const { - double dR = 9999.; - std::map<std::string, double>::const_iterator posI = m_distanceToQuarks.find(key); - std::map<std::string, double>::const_iterator posE = m_distanceToQuarks.end(); - if(posI!=posE) dR = posI->second; - return dR; +void JetQuarkLabel::printParameterSettings() const { } -} +} // namespace Analysis diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTrackAssociation.cxx b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTrackAssociation.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d7f9cc680c58cfc7d77b629570be2e9c44d34067 --- /dev/null +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTrackAssociation.cxx @@ -0,0 +1,29 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// author: cpollard@cern.ch + +#include "ParticleJetTools/JetTrackAssociation.h" + +using namespace std; +using namespace xAOD; +using namespace Analysis; + +JetTrackAssociation::JetTrackAssociation(const string& name) + : AsgTool(name) { + + declareProperty("outputCollectionName", m_outputCollectionName); + + return; + } + +int JetTrackAssociation::modify(JetContainer& jets) const { + + const vector<vector<const TrackParticle*> >* matches = match(jets); + + for (unsigned int iJet = 0; iJet < jets.size(); iJet++) + jets[iJet]->setAssociatedObjects<TrackParticle>(m_outputCollectionName, (*matches)[iJet]); + + return 0; +} diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTrackCenterOfMassAssociation.cxx b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTrackCenterOfMassAssociation.cxx new file mode 100644 index 0000000000000000000000000000000000000000..373b49e6034215c0ed88ae5cb84231af7ccf6df0 --- /dev/null +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTrackCenterOfMassAssociation.cxx @@ -0,0 +1,94 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// author: jie.yu@cern.ch + +#include "ParticleJetTools/JetTrackCenterOfMassAssociation.h" +#include "AsgTools/Check.h" +#include "TLorentzVector.h" + +using namespace std; +using namespace xAOD; +using namespace Analysis; + +JetTrackCenterOfMassAssociation::JetTrackCenterOfMassAssociation(const string& name) + : JetTrackAssociation(name) { + + declareProperty("inputTrackCollectionName", m_inputTrackCollectionName); + declareProperty("trackMatchCone", m_trackMatchCone = 0.8); + declareProperty("parentJetCone", m_parentJetCone = 1.0); + + return; + } + + +const std::vector<std::vector<const xAOD::TrackParticle*> >* +JetTrackCenterOfMassAssociation::match(xAOD::JetContainer& jets) const { + + // up limit of the delta angle in center-of-mass frame + double trackAngleMax = getAngleSize( m_trackMatchCone ); + + vector<vector<const xAOD::TrackParticle*> >* matchedtracks = + new vector<vector<const xAOD::TrackParticle*> >(jets.size()); + + const xAOD::TrackParticleContainer* tracks = NULL; + if (evtStore()->retrieve( tracks, m_inputTrackCollectionName ).isFailure() ) + ATH_MSG_FATAL("JetTrackCenterOfMassAssociation: " + "failed to retrieve track collection \"" + + m_inputTrackCollectionName + "\""); + + for (xAOD::TrackParticleContainer::const_iterator track_itr = tracks->begin(); + track_itr != tracks->end(); ++track_itr) { + + const xAOD::TrackParticle& track = **track_itr; + + double deltaAngleMatch = 999.; + int matchjetidx = -1; + for (unsigned int iJet = 0; iJet < jets.size(); iJet++) { + const xAOD::Jet& jet = *jets[iJet]; + + bool foundEL = jet.isAvailable< ElementLink< xAOD::JetContainer > >("Parent"); + if ( ! foundEL ){ + ATH_MSG_WARNING("PARTICLE to JET center-of-mass Associator: PARENT jet not available."); + continue; + } + ElementLink< xAOD::JetContainer > assoParentJet = jet.auxdata< ElementLink< xAOD::JetContainer > >("Parent"); + if ( ! assoParentJet.isValid()){ + ATH_MSG_WARNING("PARTICLE to JET center-of-mass Associator: Unable to get parent link Null ptr is returned."); + continue; + } + const xAOD::Jet* parentJet = *(assoParentJet); + double jetMass = parentJet->m(); + if (jetMass < 1000. ) jetMass = 1000.; + + TLorentzVector tlv_parentj(0, 0, 0, 0); + tlv_parentj.SetPtEtaPhiM(parentJet->pt(), parentJet->eta(), parentJet->phi(), jetMass); + TVector3 t3_boost = -1. * tlv_parentj.BoostVector(); + + TLorentzVector tlv_subj(0, 0, 0, 0); + tlv_subj.SetPtEtaPhiM(jet.pt(), jet.eta(), jet.phi(), jet.m()); + + TLorentzVector tlv_track(0, 0, 0, 0); + tlv_track.SetPtEtaPhiM(track.pt(), track.eta(), track.phi(), track.m()); + + double dR = tlv_track.DeltaR(tlv_parentj); + + // the track is first matched to the parent jet by requiring dR < parent-jet-Cone + if (dR < m_parentJetCone){ + tlv_track.Boost( t3_boost ); + tlv_subj.Boost( t3_boost ); + double angleSubTrk = tlv_subj.Angle(tlv_track.Vect()); + if ( angleSubTrk < deltaAngleMatch){ + deltaAngleMatch = angleSubTrk; + matchjetidx = iJet; + } + } + } + + if (matchjetidx >= 0 && deltaAngleMatch < trackAngleMax) + (*matchedtracks)[matchjetidx].push_back(&track); + } + + return matchedtracks; +} diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTrackShrinkingConeAssociation.cxx b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTrackShrinkingConeAssociation.cxx new file mode 100644 index 0000000000000000000000000000000000000000..48baa94367bb319f7786243a24549f435b7dc7f8 --- /dev/null +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTrackShrinkingConeAssociation.cxx @@ -0,0 +1,68 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// author: cpollard@cern.ch + +#include "ParticleJetTools/JetTrackShrinkingConeAssociation.h" +#include "AsgTools/Check.h" + +using namespace std; +using namespace xAOD; +using namespace Analysis; + +JetTrackShrinkingConeAssociation::JetTrackShrinkingConeAssociation(const string& name) + : JetTrackAssociation(name) { + + declareProperty("inputTrackCollectionName", m_inputTrackCollectionName); + declareProperty("coneSizeFitPar1", m_coneSizeFitPar1); + declareProperty("coneSizeFitPar2", m_coneSizeFitPar2); + declareProperty("coneSizeFitPar3", m_coneSizeFitPar3); + + return; + } + + +const std::vector<std::vector<const xAOD::TrackParticle*> >* +JetTrackShrinkingConeAssociation::match(xAOD::JetContainer& jets) const { + + vector<vector<const xAOD::TrackParticle*> >* matchedtracks = + new vector<vector<const xAOD::TrackParticle*> >(jets.size()); + + const xAOD::TrackParticleContainer* tracks = NULL; + if (evtStore()->retrieve( tracks, m_inputTrackCollectionName ).isFailure() ) + ATH_MSG_FATAL("JetTrackShrinkingConeAssociation: " + "failed to retrieve track collection \"" + + m_inputTrackCollectionName + "\""); + + for (xAOD::TrackParticleContainer::const_iterator track_itr = tracks->begin(); + track_itr != tracks->end(); ++track_itr) { + + const xAOD::TrackParticle& track = **track_itr; + + double maxpt = 0; + int matchjetidx = -1; + for (unsigned int iJet = 0; iJet < jets.size(); iJet++) { + const xAOD::Jet& jet = *jets[iJet]; + double pt = jet.pt(); + + double match_dr = coneSize(pt); + double dr = jet.p4().DeltaR(track.p4()); + + // TODO + // what about largest cone size? + if (dr > match_dr) + continue; + + // TODO + // closest jet or highest-pT jet if track matched to 2? + if (pt > maxpt) + matchjetidx = iJet; + } + + if (matchjetidx >= 0) + (*matchedtracks)[matchjetidx].push_back(&track); + } + + return matchedtracks; +} diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/cmt/requirements b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/cmt/requirements index c235cb645014f46ce2a585c34664951e5010a5f4..a5accff139a8eb62664e08ab7861e1207fdecbf9 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/cmt/requirements +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/cmt/requirements @@ -10,6 +10,7 @@ use JetInterface JetInterface-* Reconstruction/Jet use EventPrimitives EventPrimitives-* Event use xAODJet xAODJet-* Event/xAOD use xAODTruth xAODTruth-* Event/xAOD +use xAODTracking xAODTracking-* Event/xAOD use AsgTools AsgTools-* Control/AthToolSupport use AtlasReflex AtlasReflex-* External @@ -19,12 +20,13 @@ private use AthAnalysisBaseComps AthAnalysisBaseComps-* Control use AthContainers AthContainers-* Control use TruthUtils TruthUtils-* Generators - +use AtlasROOT AtlasROOT-* External + end_private #library ParticleJetTools *.cxx components/*.cxx -apply_pattern dual_use_library files="HadronUtils.cxx ../Root/JetQuarkLabel.cxx ../Root/JetConeLabeling.cxx ../Root/ParticleToJetAssociator.cxx ../Root/JetPartonTruthLabel.cxx ../Root/CopyTruthParticles.cxx ../Root/CopyFlavorLabelTruthParticles.cxx ../Root/CopyBosonTopLabelTruthParticles.cxx ../Root/CopyTruthPartons.cxx ../Root/CopyTruthJetParticles.cxx ../Root/JetFlavourInfo.cxx ../Root/ParticleJetDeltaRLabelTool.cxx" +apply_pattern dual_use_library files="HadronUtils.cxx ../Root/JetQuarkLabel.cxx ../Root/JetConeLabeling.cxx ../Root/ParticleToJetAssociator.cxx ../Root/JetPartonTruthLabel.cxx ../Root/CopyTruthParticles.cxx ../Root/CopyFlavorLabelTruthParticles.cxx ../Root/CopyBosonTopLabelTruthParticles.cxx ../Root/CopyTruthPartons.cxx ../Root/CopyTruthJetParticles.cxx ../Root/JetFlavourInfo.cxx ../Root/ParticleJetDeltaRLabelTool.cxx ../Root/JetTrackAssociation.cxx ../Root/JetTrackCenterOfMassAssociation.cxx ../Root/JetTrackShrinkingConeAssociation.cxx" apply_pattern declare_python_modules files="*.py" apply_pattern declare_joboptions files="*.py" apply_pattern lcgdict dict=ParticleJetTools \ diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/python/DefaultTools.py b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/python/DefaultTools.py index 30f8451dbca959172cb5ef78c20c63b0752dff4e..d5c6542f4057f371617af1604f441607f2ac3be4 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/python/DefaultTools.py +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/python/DefaultTools.py @@ -19,6 +19,8 @@ def declareDefaultTools(): from ParticleJetTools.ParticleJetToolsConf import CopyTruthJetParticles from ParticleJetTools.ParticleJetToolsConf import ParticleJetDeltaRLabelTool + ghostScaleFactor = 1e-40 + #-------------------------------------------------------------- # Truth selection. #-------------------------------------------------------------- @@ -56,6 +58,7 @@ def declareDefaultTools(): jtm += ParticleJetDeltaRLabelTool( "jetdrlabeler", LabelName = "HadronConeExclTruthLabelID", + DoubleLabelName = "HadronConeExclTruthLabelID", BLabelName = "ConeExclBHadronsFinal", CLabelName = "ConeExclCHadronsFinal", TauLabelName = "ConeExclTausFinal", @@ -72,6 +75,7 @@ def declareDefaultTools(): jtm += ParticleJetDeltaRLabelTool( "trackjetdrlabeler", LabelName = "HadronConeExclTruthLabelID", + DoubleLabelName = "HadronConeExclTruthLabelID", BLabelName = "ConeExclBHadronsFinal", CLabelName = "ConeExclCHadronsFinal", TauLabelName = "ConeExclTausFinal", @@ -107,7 +111,7 @@ def declareDefaultTools(): Label = "GhostTruth", InputContainer = jtm.truthpartcopy.OutputName, OutputContainer = "PseudoJetGhostTruth", - GhostScale = 1.e-20, + GhostScale = ghostScaleFactor, SkipNegativeEnergy = True, ) @@ -119,7 +123,7 @@ def declareDefaultTools(): Label = "Ghost" + ptype, OutputContainer = "PseudoJetGhost" + ptype, SkipNegativeEnergy = True, - GhostScale = 1e-20 + GhostScale = ghostScaleFactor, )