ATLAS Offline Software
ViewCreatorCentredOnJetWithPVConstraintROITool.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "AthViews/ViewHelper.h"
7 #include "CxxUtils/phihelper.h"
9 
10 #include "xAODJet/JetContainer.h"
12 
14  const std::string& name,
15  const IInterface* parent)
16  : base_class(type, name, parent)
17 {}
18 
19 
22  ATH_CHECK( m_vertexReadHandleKey.initialize() );
23 
24  // FIXME: We have to renounce to the Vertex RedHandleKey due to problems in the scheduler's sanity checks
25  // 'Strongly connected components found in DF realm' (see ATR-21298)
26  // Short term way of avoiding the issue
27  renounce( m_vertexReadHandleKey );
28 
29  return StatusCode::SUCCESS;
30 }
31 
32 
34  const EventContext& ctx ) const {
35 
36  // ===================================================================================== //
37  // Retrieve Primary Vertex... only 1 in the event
39  ATH_CHECK( vertexContainerHandle.isValid() );
40 
41  const xAOD::VertexContainer *vertexContainer = vertexContainerHandle.get();
42  ATH_MSG_DEBUG( "I'm working with " << vertexContainer->size() << " vertices" );
43 
44  const xAOD::Vertex* primaryVertex = getPrimaryVertex( vertexContainer );
45  if ( primaryVertex == nullptr ) {
46  ATH_MSG_ERROR( "No primary vertex has been found for this event!" );
47  return StatusCode::FAILURE;
48  }
49  ATH_MSG_DEBUG( " ** PV = (" << primaryVertex->x() <<
50  "," << primaryVertex->y() <<
51  "," << primaryVertex->z() << ")" );
52 
53  // ===================================================================================== //
54  // ===================================================================================== //
55  // Create output RoI collection
56 
58  // ===================================================================================== //
59 
60  for ( TrigCompositeUtils::Decision* outputDecision : decisions ) {
61  const std::vector< TrigCompositeUtils::LinkInfo< xAOD::JetContainer >> myFeature = TrigCompositeUtils::findLinks< xAOD::JetContainer >(outputDecision, TrigCompositeUtils::featureString(), TrigDefs::lastFeatureOfType);
62 
63  if (myFeature.size() != 1) {
64  ATH_MSG_ERROR("Did not find exactly one most-recent xAOD::Jet '" << TrigCompositeUtils::featureString() << "' for Decision object index " << outputDecision->index()
65  << ", found " << myFeature.size());
66  return StatusCode::FAILURE;
67  }
68  ATH_CHECK(myFeature.at(0).isValid());
69 
70  const xAOD::Jet *myJet = *(myFeature.at(0).link);
71  double jetPt = myJet->p4().Et();
72  double jetEta = myJet->eta();
73  double jetPhi = myJet->phi();
74 
75  ATH_MSG_DEBUG("JET -- pt=" << jetPt <<
76  " eta=" << jetEta <<
77  " phi=" << jetPhi );
78 
79  // create ROIs
80  ATH_MSG_DEBUG("Creating RoI");
81  ATH_MSG_DEBUG( " ** Imposing Z constraint while building RoI" );
82  double etaMinus = jetEta - m_roiEtaWidth;
83  double etaPlus = jetEta + m_roiEtaWidth;
84 
85  double phiMinus = CxxUtils::wrapToPi( jetPhi - m_roiPhiWidth );
86  double phiPlus = CxxUtils::wrapToPi( jetPhi + m_roiPhiWidth );
87 
88  double zMinus = primaryVertex->z() - m_roiZWidth;
89  double zPlus = primaryVertex->z() + m_roiZWidth;
90 
91  TrigRoiDescriptor *newROI = new TrigRoiDescriptor( jetEta,etaMinus, etaPlus,
92  jetPhi, phiMinus, phiPlus,
93  primaryVertex->z(),zMinus,zPlus );
94 
95  roisWriteHandle->push_back( newROI );
96  const ElementLink< TrigRoiDescriptorCollection > roiEL = ElementLink< TrigRoiDescriptorCollection >( *roisWriteHandle, roisWriteHandle->size() - 1, ctx );
97 
98  outputDecision->setObjectLink( TrigCompositeUtils::roiString(), roiEL );
99  outputDecision->setObjectLink( m_prmVtxLink.value(),
101 
102  ATH_MSG_DEBUG("PRINTING DECISION");
103  ATH_MSG_DEBUG( *outputDecision );
104  }
105 
106  return StatusCode::SUCCESS;
107 }
108 
110  // In case we need more complex selection
111  if ( vertexContainer->size() == 0 ) {
112  ATH_MSG_WARNING( "Vertex Container has size 0! This can't be right!" );
113  return nullptr;
114  }
115 
116  for ( unsigned int i(0); i<vertexContainer->size(); i++ ) {
117  const xAOD::Vertex *vertex = vertexContainer->at(i);
118  if ( vertex->vertexType() != xAOD::VxType::VertexType::PriVtx ) continue;
119  return vertex;
120  }
121 
122  ATH_MSG_DEBUG( "None of the vertexes in the vertex container is a primary vertex!" );
123  ATH_MSG_DEBUG( "Using dummy vertex!" );
124  return vertexContainer->at(0);
125 }
xAOD::Vertex_v1::x
float x() const
Returns the x position.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CxxUtils::wrapToPi
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition: phihelper.h:24
ViewCreatorCentredOnJetWithPVConstraintROITool::m_roiPhiWidth
Gaudi::Property< double > m_roiPhiWidth
Definition: ViewCreatorCentredOnJetWithPVConstraintROITool.h:51
xAOD::Jet_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition: Jet_v1.cxx:54
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
ViewCreatorCentredOnJetWithPVConstraintROITool.h
ViewHelper.h
ViewCreatorCentredOnJetWithPVConstraintROITool::m_prmVtxLink
Gaudi::Property< std::string > m_prmVtxLink
Definition: ViewCreatorCentredOnJetWithPVConstraintROITool.h:60
ViewCreatorCentredOnJetWithPVConstraintROITool::m_roiEtaWidth
Gaudi::Property< double > m_roiEtaWidth
Definition: ViewCreatorCentredOnJetWithPVConstraintROITool.h:48
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
ViewCreatorCentredOnJetWithPVConstraintROITool::m_roisWriteHandleKey
SG::WriteHandleKey< TrigRoiDescriptorCollection > m_roisWriteHandleKey
Definition: ViewCreatorCentredOnJetWithPVConstraintROITool.h:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ViewCreatorCentredOnJetWithPVConstraintROITool::initialize
virtual StatusCode initialize() override
Definition: ViewCreatorCentredOnJetWithPVConstraintROITool.cxx:20
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::Vertex_v1::z
float z() const
Returns the z position.
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
TrigCompositeUtils::createAndStoreNoAux
SG::WriteHandle< CONT > createAndStoreNoAux(const SG::WriteHandleKey< CONT > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Creates and right away records the Container CONT with the key.
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:81
ViewCreatorCentredOnJetWithPVConstraintROITool::ViewCreatorCentredOnJetWithPVConstraintROITool
ViewCreatorCentredOnJetWithPVConstraintROITool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ViewCreatorCentredOnJetWithPVConstraintROITool.cxx:13
xAOD::Jet_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: Jet_v1.cxx:49
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:886
ViewCreatorCentredOnJetWithPVConstraintROITool::m_vertexReadHandleKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexReadHandleKey
Definition: ViewCreatorCentredOnJetWithPVConstraintROITool.h:57
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ViewCreatorCentredOnJetWithPVConstraintROITool::getPrimaryVertex
const xAOD::Vertex * getPrimaryVertex(const xAOD::VertexContainer *) const
Definition: ViewCreatorCentredOnJetWithPVConstraintROITool.cxx:109
phihelper.h
Helper for azimuthal angle calculations.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
ViewCreatorCentredOnJetWithPVConstraintROITool::attachROILinks
virtual StatusCode attachROILinks(TrigCompositeUtils::DecisionContainer &decisions, const EventContext &ctx) const override
Tool interface method.
Definition: ViewCreatorCentredOnJetWithPVConstraintROITool.cxx:33
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
SG::WriteHandle< TrigRoiDescriptorCollection >
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Jet_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: Jet_v1.cxx:71
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
JetContainer.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::Vertex_v1::y
float y() const
Returns the y position.
JetAuxContainer.h
TrigCompositeUtils::roiString
const std::string & roiString()
Definition: TrigCompositeUtilsRoot.cxx:878
TrigRoiDescriptor
Athena::TPCnvVers::Current TrigRoiDescriptor
Definition: TrigSteeringEventTPCnv.cxx:68
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
ViewCreatorCentredOnJetWithPVConstraintROITool::m_roiZWidth
Gaudi::Property< double > m_roiZWidth
Definition: ViewCreatorCentredOnJetWithPVConstraintROITool.h:54
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrigRoiDescriptorCollection.h