ATLAS Offline Software
DisplacedJetPromptHypoAlg.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "AthViews/ViewHelper.h"
9 
22 
23 DisplacedJetPromptHypoAlg::DisplacedJetPromptHypoAlg(const std::string& name, ISvcLocator* pSvcLocator) :
24 ::HypoBase(name, pSvcLocator)
25 {
26 }
27 
29 {
30  ATH_CHECK(m_jetContainerKey.initialize());
32  ATH_CHECK(m_vtxKey.initialize());
33  ATH_CHECK(m_countsKey.initialize());
35 
36  ATH_CHECK(m_hypoTools.retrieve());
37 
38  return StatusCode::SUCCESS;
39 }
40 
41 StatusCode 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 
75  SG::ReadCondHandle<InDet::BeamSpotData> beamSpotHandle { m_beamSpotKey, context };
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
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 }
grepfile.info
info
Definition: grepfile.py:38
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DisplacedJetPromptHypoAlg::DisplacedJetPromptHypoAlg
DisplacedJetPromptHypoAlg()
DisplacedJetPromptHypoAlg::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: DisplacedJetPromptHypoAlg.h:41
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
DisplacedJetPromptHypoAlg::m_drcut
Gaudi::Property< float > m_drcut
Definition: DisplacedJetPromptHypoAlg.h:38
TrigCompositeUtils::DecisionContainer
xAOD::TrigCompositeContainer DecisionContainer
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigCompositeContainer.h:21
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
xAOD::TrigComposite
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:16
DisplacedJetPromptHypoAlg::m_stdTracksKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_stdTracksKey
Definition: DisplacedJetPromptHypoAlg.h:34
TrigCompositeUtils::newDecisionIn
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.
Definition: TrigCompositeUtilsRoot.cxx:46
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:904
skel.it
it
Definition: skel.GENtoEVGEN.py:396
DataVector::get
const T * get(size_type n) const
Access an element, as an rvalue.
HypoBase::decisionInput
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:16
DisplacedJetPromptHypoAlg::initialize
virtual StatusCode initialize() override
Definition: DisplacedJetPromptHypoAlg.cxx:28
TrigCompositeUtils::createAndStore
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
Definition: TrigCompositeUtilsRoot.cxx:30
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
ViewHelper.h
HypoBase::decisionOutput
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:20
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
DisplacedJetPromptHypoAlg::m_hypoTools
ToolHandleArray< DisplacedJetPromptHypoTool > m_hypoTools
Definition: DisplacedJetPromptHypoAlg.h:32
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DisplacedJetPromptHypoAlg::m_min_trk_pt
Gaudi::Property< float > m_min_trk_pt
Definition: DisplacedJetPromptHypoAlg.h:39
xAOD::TrigComposite_v1::setObjectLink
bool setObjectLink(const std::string &name, const ElementLink< CONTAINER > &link)
Set the link to an object.
HypoBase::hypoBaseOutputProcessing
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:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
DisplacedJetPromptHypoAlg::m_jetContainerKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetContainerKey
Definition: DisplacedJetPromptHypoAlg.h:33
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:101
TrigCompositeUtils::DecisionAuxContainer
xAOD::TrigCompositeAuxContainer DecisionAuxContainer
Definition: TrigCompositeAuxContainer.h:20
DisplacedJetPromptHypoTool::Info
Definition: DisplacedJetPromptHypoTool.h:28
P4Helpers.h
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:884
DisplacedJetBeamspotInfo
Definition: DisplacedJetBeamspotInfo.h:12
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
HypoBase
Hypothesis algorithms take the output of reco algorithms and the decision from the preceeding InputMa...
Definition: HypoBase.h:13
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
DisplacedJetPromptHypoAlg::m_countsKey
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_countsKey
Definition: DisplacedJetPromptHypoAlg.h:36
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
DisplacedJetPromptHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: DisplacedJetPromptHypoAlg.cxx:41
python.PyAthena.v
v
Definition: PyAthena.py:154
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TrigCompositeUtils::linkToPrevious
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
Definition: TrigCompositeUtilsRoot.cxx:139
TrigCompositeUtils::LinkInfo
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition: LinkInfo.h:28
TrigCompositeUtils::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
DisplacedJetPromptHypoTool.h
TrigCompositeUtils::findLink
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...
TrigCompositeUtils::allFailed
bool allFailed(const Decision *d)
return true if there is no positive decision stored
Definition: TrigCompositeUtilsRoot.cxx:103
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
DisplacedJetPromptHypoAlg::m_vtxKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vtxKey
Definition: DisplacedJetPromptHypoAlg.h:35
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:880
DisplacedJetPromptHypoAlg.h