ATLAS Offline Software
Loading...
Searching...
No Matches
DisplacedJetPromptHypoAlg.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
9
22
23DisplacedJetPromptHypoAlg::DisplacedJetPromptHypoAlg(const std::string& name, ISvcLocator* pSvcLocator) :
24::HypoBase(name, pSvcLocator)
25{
26}
27
29{
30 ATH_CHECK(m_jetContainerKey.initialize());
31 ATH_CHECK(m_stdTracksKey.initialize());
32 ATH_CHECK(m_vtxKey.initialize());
33 ATH_CHECK(m_countsKey.initialize());
34 ATH_CHECK(m_beamSpotKey.initialize());
35
36 ATH_CHECK(m_hypoTools.retrieve());
37
38 return StatusCode::SUCCESS;
39}
40
41StatusCode DisplacedJetPromptHypoAlg::execute(const EventContext& context) const
42{
43 ATH_MSG_DEBUG ( "Executing " << name() << "..." );
44 auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
45
46 ATH_CHECK( previousDecisionsHandle.isValid() );
47
49 auto decisions = outputHandle.ptr();
50
51 if (previousDecisionsHandle->size() == 0) {
52 ATH_MSG_DEBUG( "No previous decision, nothing to do.");
53 return StatusCode::SUCCESS;
54 } else if (previousDecisionsHandle->size() > 1) {
55 ATH_MSG_ERROR("Found " << previousDecisionsHandle->size() <<" previous decisions.");
56 return StatusCode::FAILURE;
57 }
58
60 TrigCompositeUtils::decisionIDs( previousDecisionsHandle->at(0), prev );
61
62 ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() <<" implicit ReadHandles for previous decisions. Looking for :"<<viewString());
63
64
65 ATH_MSG_DEBUG( "Getting Jets Handle "<<m_jetContainerKey);
66 ATH_MSG_DEBUG("Getting STD Handle "<<m_stdTracksKey);
67 ATH_MSG_DEBUG("Getting vtx Handle "<<m_vtxKey);
68
69 //get containers
70 auto jetsHandle = SG::makeHandle(m_jetContainerKey, context);
71 auto stdHandle = SG::makeHandle(m_stdTracksKey, context);
72 auto vtxHandle = SG::makeHandle(m_vtxKey, context);
73
76
77 ATH_CHECK( jetsHandle.isValid() );
78 ATH_CHECK( stdHandle.isValid() );
79 ATH_CHECK( vtxHandle.isValid() );
80 ATH_CHECK( beamSpotHandle.isValid());
81
82 const xAOD::TrackParticleContainer* stdTracks = stdHandle.get();
83 const xAOD::JetContainer* jets = jetsHandle.get();
84 const xAOD::VertexContainer* vtxs = vtxHandle.get();
85
86 std::map<const xAOD::Jet_v1*, TrigCompositeUtils::Decision*> jet_decisions;
87 std::map<const xAOD::Jet_v1*, xAOD::TrigComposite*> jet_counts;
88 //get primary vertex
89 const xAOD::Vertex_v1* primary_vertex = nullptr;
90
91 for(auto v: *vtxs){
92 if(v->vertexType()==xAOD::VxType::PriVtx){
93 primary_vertex = v;
94 }
95 }
96
97 if(primary_vertex == nullptr){
98 ATH_MSG_DEBUG("missing primary vertex");
99 return StatusCode::SUCCESS;
100 }
101
102 auto countsContainer = std::make_unique< xAOD::TrigCompositeContainer>();
103 auto countsContainerAux = std::make_unique< xAOD::TrigCompositeAuxContainer>();
104 countsContainer->setStore(countsContainerAux.get());
105
106 std::map<TrigCompositeUtils::Decision*, int> count_index_map;
107
108 //create decision objects for each jet
109 //the displaced tracking step wants to run over each jet on its own
110 for(size_t jet_idx=0; jet_idx < jets->size(); jet_idx ++){
112
113 //attach to the previous decision
114 linkToPrevious(jet_dec, previousDecisionsHandle->at(0), context);
115
116 //attach the jet
117 jet_dec->setObjectLink(featureString(), ElementLink<xAOD::JetContainer>(*jetsHandle, jet_idx, context));
118
119 const xAOD::Jet* jet = jetsHandle->at(jet_idx);
120
121 jet_decisions[jet] = jet_dec;
122
123 //create a counts object
124 auto count = new xAOD::TrigComposite();
125 auto count_idx = countsContainer->size();
126
127 countsContainer->push_back(count);
128
129 count_index_map[jet_dec]= count_idx;
130
131 jet_counts[jet] = count;
132 }
133
134 ATH_CHECK(countsHandle.record(std::move(countsContainer), std::move(countsContainerAux)));
135
136 //do jet<->track association
137 std::map<const xAOD::Jet_v1*, std::vector<const xAOD::TrackParticle_v1*>> jets_to_tracks;
138 //association is fairly simple loop over particles and find the closest jet, then add it to that jets vector
139
140
141 for(auto track: *stdTracks){
142 if(track->pt()/Gaudi::Units::GeV < m_min_trk_pt) continue;
143
144 const xAOD::Jet_v1* best_jet = nullptr;
145 double best_dr = 1000.0;
146
147 for(auto jet: *jets){
148 double dr = jet->p4().DeltaR(track->p4());
149
150 if(dr < best_dr && dr <= m_drcut){
151 best_jet = jet;
152 best_dr = dr;
153 }
154 }
155
156 if(best_dr <= m_drcut){
157 //associate track to jet
158 jets_to_tracks[best_jet].push_back(track);
159 }
160 }
161
162 DisplacedJetBeamspotInfo bs(beamSpotHandle.retrieve());
163
164 for(auto j: *jets){
165 DisplacedJetPromptHypoTool::Info info{prev,jet_decisions[j], j, jets_to_tracks[j], primary_vertex, jet_counts[j], bs};
166
167 for(auto &tool:m_hypoTools)
168 {
169 ATH_CHECK(tool->decide(info));
170 }
171 }
172
173 //remove all failed decision objects to reduce number of decisions stored
174 DecisionContainer::iterator it = decisions->begin();
175
176 while(it != decisions->end()){
178 it = decisions->erase(it);
179 }else{
181 int idx = count_index_map[dec];
182 ATH_CHECK(dec->setObjectLink("djtrig_counts", ElementLink<xAOD::TrigCompositeContainer>(*countsHandle, idx, context)));
183
184 ++it;
185 }
186 }
187
188 ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
189 return StatusCode::SUCCESS;
190}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name="")
Helper method to create a Decision object, place it in the container and return a pointer to it.
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
const std::string & hypoAlgNodeName()
const std::string & featureString()
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
const std::string & viewString()
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
ToolHandleArray< DisplacedJetPromptHypoTool > m_hypoTools
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_stdTracksKey
Gaudi::Property< float > m_drcut
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &context) const override
SG::ReadHandleKey< xAOD::JetContainer > m_jetContainerKey
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_countsKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Gaudi::Property< float > m_min_trk_pt
SG::ReadHandleKey< xAOD::VertexContainer > m_vtxKey
const SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > & decisionInput() const
methods for derived classes to access handles of the base class input other read/write handles may be...
Definition HypoBase.cxx:18
const SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > & decisionOutput() const
methods for derived classes to access handles of the base class output other read/write handles may b...
Definition HypoBase.cxx:22
StatusCode hypoBaseOutputProcessing(SG::WriteHandle< TrigCompositeUtils::DecisionContainer > &outputHandle, MSG::Level lvl=MSG::DEBUG) const
Base class function to be called once slice specific code has finished. Handles debug printing and va...
Definition HypoBase.cxx:35
HypoBase(const std::string &name, ISvcLocator *pSvcLocator)
constructor, to be called by sub-class constructors
Definition HypoBase.cxx:12
const_pointer_type retrieve()
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
Class describing a jet.
Definition Jet_v1.h:57
bool setObjectLink(const std::string &name, const ElementLink< CONTAINER > &link)
Set the link to an object.
Class describing a Vertex.
Definition Vertex_v1.h:42
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
const std::string & viewString()
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name)
Helper method to create a Decision object, place it in the container and return a pointer to it.
const std::string & featureString()
xAOD::TrigCompositeAuxContainer DecisionAuxContainer
std::set< DecisionID > DecisionIDContainer
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
const std::string & hypoAlgNodeName()
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
bool allFailed(const Decision *d)
return true if there is no positive decision stored
LinkInfo< T > findLink(const Decision *start, const std::string &linkName, const bool suppressMultipleLinksWarning=false)
Perform a recursive search for ElementLinks of type T and name 'linkName', starting from Decision obj...
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
@ PriVtx
Primary vertex.
Jet_v1 Jet
Definition of the current "jet version".
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22