ATLAS Offline Software
ViewCreatorMuonSuperROITool.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "AthViews/ViewHelper.h"
7 #include "CxxUtils/phihelper.h"
9 
10 #include "xAODMuon/MuonContainer.h"
12 
13 
15  const std::string& name,
16  const IInterface* parent)
17  : base_class(type, name, parent)
18 {}
19 
20 
23 
24  return StatusCode::SUCCESS;
25 }
26 
27 
29  const EventContext& ctx ) const {
30 
31  // ===================================================================================== //
32  // Create output RoI collection
33 
35  // ===================================================================================== //
36 
37  // Only expect one object in container
38  ATH_MSG_DEBUG("In MuonSuperROITool - got decisions, size: " << decisions.size());
39 
40 
41  // Create SuperRoI to merge the RoIs from each muon
42  std::unique_ptr<TrigRoiDescriptor> superRoI = std::make_unique<TrigRoiDescriptor>();
43  superRoI->setComposite(true);
44  superRoI->manageConstituents(false);
45 
46  // loop over decision objects
47  for (TrigCompositeUtils::Decision* decision : decisions) {
48  ATH_MSG_DEBUG(" Check decisions object ");
49 
50  ATH_MSG_DEBUG("PRINTING DECISION");
51  ATH_MSG_DEBUG( *decision );
52 
53 
54  // find the iParticle for this decision
55  const std::vector<TrigCompositeUtils::LinkInfo<xAOD::IParticleContainer>> myFeature = TrigCompositeUtils::findLinks<xAOD::IParticleContainer>(decision, m_iParticleLinkName, TrigDefs::lastFeatureOfType);
56 
57  // there should be only one
58  if (myFeature.size() != 1) {
59  ATH_MSG_ERROR("Did not find exactly one most-recent xAOD::IParticle '" << m_iParticleLinkName << "' for Decision object index " << decision->index()
60  << ", found " << myFeature.size());
61  return StatusCode::FAILURE;
62  }
63 
64  ATH_CHECK(myFeature.at(0).isValid());
65 
66  // find the muon
67  const ElementLink<xAOD::IParticleContainer> p4EL = myFeature.at(0).link;
68  const xAOD::Muon* muon = dynamic_cast< const xAOD::Muon*>(*p4EL); //get muon of this found object
69 
70  if (!( muon && muon->primaryTrackParticle()) ) {
71  ATH_MSG_ERROR("NO PRIMARY muon from decision object! " << myFeature.at(0).link);
72  return StatusCode::FAILURE;
73  }
74 
75  ATH_MSG_DEBUG("MUON -- pt=" << muon->pt() <<
76  " eta=" << muon->eta() <<
77  " phi=" << muon->phi() );
78 
79 
80  double muonEta{muon->eta()}, muonPhi{muon->phi()};
81 
82  double etaMinus = muonEta - m_roiEtaWidth;
83  double etaPlus = muonEta + m_roiEtaWidth;
84 
85  double phiMinus = CxxUtils::wrapToPi( muonPhi - m_roiPhiWidth );
86  double phiPlus = CxxUtils::wrapToPi( muonPhi + m_roiPhiWidth );
87 
88  double muonZed=0.;
89 
90  std::unique_ptr<TrigRoiDescriptor> newROI = nullptr;
91 
92  if ( muon->primaryTrackParticle() ) {
93  muonZed = muon->primaryTrackParticle()->z0() + muon->primaryTrackParticle()->vz();
94 
95  // create ROIs
96  ATH_MSG_DEBUG("Adding RoI to RoI container");
97  ATH_MSG_DEBUG( "eta " << muonEta << " +/-" << m_roiEtaWidth << " phi " << muonPhi << " +/- " << m_roiPhiWidth << " zed " << muonZed << " +/- " << m_roiZedWidth);
98 
99 
100  double zMinus = muonZed - m_roiZedWidth;
101  double zPlus = muonZed + m_roiZedWidth;
102 
103  zMinus = zMinus < -225. ? -225. : zMinus;
104  zPlus = zPlus > 225. ? 225. : zPlus;
105 
106  ATH_MSG_DEBUG( "eta- " << etaMinus << " eta+ " << etaPlus << " phi- " << phiMinus << " phi+ " << phiPlus << " zed- " << zMinus << " zed+ " << zPlus);
107 
108  superRoI->push_back( new TrigRoiDescriptor( muonEta, etaMinus, etaPlus,
109  muonPhi, phiMinus, phiPlus,
110  muonZed, zMinus, zPlus ) );
111 
112  superRoI->manageConstituents(true);
113 
114  } else {
115  ATH_MSG_DEBUG("Adding RoI to RoI container");
116  ATH_MSG_DEBUG( "eta " << muonEta << " +/-" << m_roiEtaWidth << " phi " << muonPhi << " +/- " << m_roiPhiWidth);
117  ATH_MSG_DEBUG( "eta- " << etaMinus << " eta+ " << etaPlus << " phi- " << phiMinus << " phi+ " << phiPlus);
118 
119  superRoI->push_back( new TrigRoiDescriptor( muonEta, etaMinus, etaPlus,
120  muonPhi, phiMinus, phiPlus) );
121 
122  superRoI->manageConstituents(true);
123 
124  }
125 
126 
127  } //end loop over decisions
128 
129 
130 
131  roisWriteHandle->push_back(superRoI.release());
133 
134 
135  for (TrigCompositeUtils::Decision* decision : decisions) {
136  decision->setObjectLink( TrigCompositeUtils::roiString(), roiEL );
137 
138  ATH_MSG_DEBUG("PRINTING DECISION");
139  ATH_MSG_DEBUG( *decision );
140  }
141  return StatusCode::SUCCESS;
142 }
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
ViewCreatorMuonSuperROITool.h
CxxUtils::wrapToPi
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition: phihelper.h:24
ViewHelper.h
ViewCreatorMuonSuperROITool::initialize
virtual StatusCode initialize() override
Definition: ViewCreatorMuonSuperROITool.cxx:21
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
ViewCreatorMuonSuperROITool::m_roiZedWidth
Gaudi::Property< double > m_roiZedWidth
Definition: ViewCreatorMuonSuperROITool.h:66
MuonAuxContainer.h
ViewCreatorMuonSuperROITool::m_roiPhiWidth
Gaudi::Property< double > m_roiPhiWidth
Definition: ViewCreatorMuonSuperROITool.h:62
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
RoiDescriptor::push_back
void push_back(const IRoiDescriptor *roi)
add a RoiDescriptor
Definition: RoiDescriptor.h:157
ViewCreatorMuonSuperROITool::m_roisWriteHandleKey
SG::WriteHandleKey< TrigRoiDescriptorCollection > m_roisWriteHandleKey
Definition: ViewCreatorMuonSuperROITool.h:41
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
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
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:101
ViewCreatorMuonSuperROITool::ViewCreatorMuonSuperROITool
ViewCreatorMuonSuperROITool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ViewCreatorMuonSuperROITool.cxx:14
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ViewCreatorMuonSuperROITool::m_iParticleLinkName
Gaudi::Property< std::string > m_iParticleLinkName
Definition: ViewCreatorMuonSuperROITool.h:48
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.
ViewCreatorMuonSuperROITool::attachROILinks
virtual StatusCode attachROILinks(TrigCompositeUtils::DecisionContainer &decisions, const EventContext &ctx) const override
Tool interface method.
Definition: ViewCreatorMuonSuperROITool.cxx:28
MuonContainer.h
SG::WriteHandle< TrigRoiDescriptorCollection >
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
ViewCreatorMuonSuperROITool::m_roiEtaWidth
Gaudi::Property< double > m_roiEtaWidth
Definition: ViewCreatorMuonSuperROITool.h:59
RoiDescriptor::setComposite
void setComposite(bool b=true)
Definition: RoiDescriptor.h:138
TrigCompositeUtils::roiString
const std::string & roiString()
Definition: TrigCompositeUtilsRoot.cxx:876
TrigRoiDescriptor
Athena::TPCnvVers::Current TrigRoiDescriptor
Definition: TrigSteeringEventTPCnv.cxx:68
RoiDescriptor::manageConstituents
bool manageConstituents() const
always manage constituents ???
Definition: RoiDescriptor.h:141
TrigRoiDescriptorCollection.h