ATLAS Offline Software
Loading...
Searching...
No Matches
JetCnvTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6
9
10
11#include "JetCnvTool.h"
12
13namespace xAODMaker {
14
15
16 JetCnvTool::JetCnvTool( const std::string& type,
17 const std::string& name,
18 const IInterface* parent )
19 : AthAlgTool( type, name, parent ) {
20
21 // Declare the interface(s) provided by the tool:
22 declareInterface< IJetCnvTool >( this );
23 }
24
34 StatusCode JetCnvTool::convert( const JetCollection* aodCont,
35 xAOD::JetContainer* xaodCont,
37 bool constitSearch) const
38 {
39
40
42 JetCollection::const_iterator itE = aodCont->end();
43
44 std::vector< std::string > momentKeys ;
45
46 if( it != itE ) {
47 momentKeys= (*it)->getMomentKeys();
48
49 if( xaodConstitCont.isDefault() &&
50 (*it)->begin() != (*it)->end() )
51 {
52 // try to retrieve its name from SG and the original jet
53
54 // this doesn't work : getConstituents() is protected
55 // std::string key = (*it)->navigableBase().getConstituents()[0].key();
56 // StatusCode sc = evtStore()->retrieve(xaodConstitCont, key);
57 // if(sc.isFailure() ) ATH_MSG_DEBUG("Could not retrieve xaod constiuents with key "<< key );
58
59 SG::DataProxy* proxy = evtStore()->proxy( (*it)->getContainer( (*it)->begin() ) );
60 if(proxy) {
61 xaodConstitCont.toIdentifiedObject (proxy->name());
62 if( !xaodConstitCont ) ATH_MSG_DEBUG("Could not retrieve xaod constiuents with key "<< proxy->name() );
63 }
64 }
65 }
66
67
68 for( ; it!= itE; ++it){
69 const Jet * jet = *it;
70 Jet::const_iterator cit = jet->begin();
71 Jet::const_iterator citE = jet->end();
72
73 xAOD::Jet* xjet = new xAOD::Jet();
74 xaodCont->push_back( xjet );
75
76 xjet->setJetP4( xAOD::JetFourMom_t(jet->pt(), jet->eta(), jet->phi(), jet->m() ) );
77
78 // convert constituents if we have a valid xaod constituent container.
79 // If constitSearch is false, this assumes the ordering
80 // in aod and xaod containers are the same !
81 if(xaodConstitCont) {
82 for( ; cit!= citE; ++cit){
83 if (constitSearch) {
84 double min_dr2 = 0.1 * 0.1;
85 int iconstit = -1;
86 int ip = 0;
87 for (const xAOD::IParticle* p : *xaodConstitCont) {
88 double deta = p->eta() - (*cit)->eta();
89 double dphi = TVector2::Phi_mpi_pi (p->phi() - (*cit)->phi());
90 double dr2 = deta*deta + dphi*dphi;
91 if (dr2 < min_dr2) {
92 min_dr2 = dr2;
93 iconstit = ip;
94 }
95 ++ip;
96 }
97 if (iconstit >= 0)
98 xjet->addConstituent
99 (ElementLink<xAOD::IParticleContainer> (xaodConstitCont.key(), iconstit));
100 }
101 else {
102 size_t index;
103 if( jet->getIndex( cit , index) )
104 xjet->addConstituent
105 (ElementLink<xAOD::IParticleContainer> (xaodConstitCont.key(), index));
106 }
107 }
108 }
109
110 for(size_t i=0;i<momentKeys.size(); i++){
111 xjet->setAttribute<float>( momentKeys[i], jet->getMoment( momentKeys[i]) );
112 }
113 ATH_MSG_DEBUG( "Converted " << jet << " into "<< xjet << " pt="<< xjet->pt()<< " numConst="<< xjet->numConstituents() );
114
117 xjet->setJetP4( s, xAOD::JetFourMom_t( jet->pt(aod_s), jet->eta(aod_s) , jet->phi(aod_s), jet->m(aod_s) ) );
120 xjet->setJetP4( s, xAOD::JetFourMom_t( jet->pt(aod_s), jet->eta(aod_s) , jet->phi(aod_s), jet->m(aod_s) ) );
121
122 P4SignalState::State aod_constit_s = jet->constituentSignalState() ;
123 xjet->setConstituentsSignalState( (xAOD::JetConstitScale) aod_constit_s );
124
125 // // Track assoc if any :
126 // const Analysis::TrackAssociation * trackA = jet-> getAssociation<Analysis::TrackAssociation>("TrackAssoc");
127 // if (trackA) {
128 // Analysis::TrackAssociation::object_iter trk_it = trackA->begin();
129 // Analysis::TrackAssociation::object_iter trk_itE= trackA->end();
130 // size_t trk_index;
131 // for( ; trk_it != trk_itE ; ++trk_it){
132 // if( trackA->getIndex( trk_it, trk_index) )
133 // if( (*it)->pt() > m_trackMinPt && (m_jetvtxtrkHelper->trackInfo(*it).selected() ) )
134 // preSelTracks.push_back(*it);
135
136 }
137
138 return StatusCode::SUCCESS;
139 }
140
141
142}
143
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
ServiceHandle< StoreGateSvc > & evtStore()
bool isDefault() const
Test to see if we're in the default state.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
navigable_t::object_iter const_iterator
JetCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
virtual StatusCode convert(const JetCollection *aodCont, xAOD::JetContainer *xaodCont, DataLink< xAOD::IParticleContainer > xaodConstitCont=DataLink< xAOD::IParticleContainer >(), bool constitSearch=false) const override
Function that fills an existing xAOD::MuonRoIContainer.
Class providing the definition of the 4-vector interface.
void setAttribute(const std::string &name, const T &v)
void addConstituent(const ElementLink< IParticleContainer > &link, float weight=1.0)
Add a constituent directly in the ElementLink format.
Definition Jet_v1.cxx:111
size_t numConstituents() const
Number of constituents in this jets (this is valid even when reading a file where the constituents ha...
Definition Jet_v1.cxx:153
void setJetP4(const JetFourMom_t &p4)
Definition Jet_v1.cxx:171
void setConstituentsSignalState(JetConstitScale t)
Set the state at which constituents were when this jet was found. This function is called by jet buil...
Definition Jet_v1.cxx:141
virtual double pt() const
The transverse momentum ( ) of the particle.
Definition Jet_v1.cxx:44
Definition index.py:1
Jet_v1 Jet
Definition of the current "jet version".
JetScale
Definition JetTypes.h:26
@ JetEMScaleMomentum
Definition JetTypes.h:28
@ JetConstitScaleMomentum
Definition JetTypes.h:29
JetContainer_v1 JetContainer
Definition of the current "jet container version".
JetConstitScale
Definition JetTypes.h:20
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17