ATLAS Offline Software
Loading...
Searching...
No Matches
TrigEgammaMonitorTopoAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <utility>
6
10
11using namespace Trig;
12
13
14TrigEgammaMonitorTopoAlgorithm::TrigEgammaMonitorTopoAlgorithm( const std::string& name, ISvcLocator* pSvcLocator ):
15 TrigEgammaMonitorBaseAlgorithm( name, pSvcLocator )
16{}
17
19
22
24
26{
27 ATH_MSG_INFO("TrigEgammaMonitorTopoAlgorithm::initialize()...");
28
30
31 ATH_CHECK(m_offElectronKey.initialize());
32 ATH_CHECK(m_offPhotonKey.initialize());
33
34 return StatusCode::SUCCESS;
35}
36
38
39StatusCode TrigEgammaMonitorTopoAlgorithm::fillHistograms( const EventContext& ctx ) const
40{
41
42 ATH_MSG_DEBUG("Executing TrigEgammaMonitorTopoAlgorithm");
43
44 if(isHLTTruncated()){
45 ATH_MSG_DEBUG("HLTResult truncated, skip trigger analysis");
46 return StatusCode::SUCCESS;
47 }
48
49 // Open the offline electron container
52
53 if(!offElectrons.isValid())
54 {
55 ATH_MSG_DEBUG("Failed to retrieve offline Electrons ");
56 return StatusCode::SUCCESS;
57 }
58
59 if(!offPhotons.isValid())
60 {
61 ATH_MSG_DEBUG("Failed to retrieve offline Photons ");
62 return StatusCode::SUCCESS;
63 }
64
65
66 for ( auto &d : m_trigListConfig)
67 {
68 std::string trigger_num = d.at("trigger_num");
69 std::string trigger_den = d.at("trigger_den");
70
71 auto monGroup_online = getGroup( trigger_num + "_Efficiency_HLT" );
72 auto monGroup_offline = getGroup( trigger_num + "_Efficiency_Offline" );
73
74 std::vector<float> mass_vec, mass_off_vec, match_mass_vec, match_mass_off_vec;
75 std::vector<float> dphi_vec, dphi_off_vec, match_dphi_vec, match_dphi_off_vec;
76
77 auto mass_col = Monitored::Collection( "mass" , mass_vec );
78 auto mass_off_col = Monitored::Collection( "mass" , mass_off_vec );
79 auto match_mass_col = Monitored::Collection( "match_mass" , match_mass_vec );
80 auto match_mass_off_col = Monitored::Collection( "match_mass" , match_mass_off_vec );
81 auto dphi_col = Monitored::Collection( "dphi" , dphi_vec );
82 auto dphi_off_col = Monitored::Collection( "dphi" , dphi_off_vec );
83 auto match_dphi_col = Monitored::Collection( "match_dphi" , match_dphi_vec );
84 auto match_dphi_off_col = Monitored::Collection( "match_dphi" , match_dphi_off_vec );
85
86
87 std::vector<Legs> legs_den_vec, legs_num_vec;
88
89 make_legs( trigger_num , d.at("leg0_key"), d.at("leg1_key"), legs_num_vec);
90 make_legs( trigger_den , d.at("leg0_key"), d.at("leg1_key"), legs_den_vec);
91
92
93 // Fill denominator histograms
94 for (auto &legs : legs_den_vec){
95 // Fill online mass
96 if( legs.leg0 && legs.leg1 ){
97 mass_vec.push_back( (legs.leg0->p4() + legs.leg1->p4()).M() );
98 dphi_vec.push_back( legs.leg0->p4().DeltaPhi(legs.leg1->p4()) );
99
100 const xAOD::IParticle *leg0_off, *leg1_off =nullptr;
101 if( match( *offElectrons, legs.leg0, leg0_off) &&
102 match( *offElectrons, legs.leg1, leg1_off))
103 {
104 if (! (leg0_off == leg1_off)){ // should not be the same electron
105 mass_off_vec.push_back( (leg0_off->p4() + leg1_off->p4()).M() );
106 dphi_off_vec.push_back( leg0_off->p4().DeltaPhi(leg1_off->p4()) );
107 }
108 }
109 }
110 } // Loop over denominator legs
111
112
113 // Fill denominator histograms
114 for (auto &legs : legs_num_vec){
115
116 // Fill online mass
117 if( legs.leg0 && legs.leg1 ){
118 match_mass_vec.push_back( (legs.leg0->p4() + legs.leg1->p4()).M() );
119 match_dphi_vec.push_back( legs.leg0->p4().DeltaPhi(legs.leg1->p4()) );
120
121 const xAOD::IParticle *leg0_off, *leg1_off =nullptr;
122 if( match( *offElectrons, legs.leg0, leg0_off) &&
123 match( *offElectrons, legs.leg1, leg1_off))
124 {
125 if (! (leg0_off == leg1_off)){ // should not be the same electron
126 match_mass_off_vec.push_back( (leg0_off->p4() + leg1_off->p4()).M() );
127 match_dphi_off_vec.push_back( leg0_off->p4().DeltaPhi(leg1_off->p4()) );
128 }
129 }
130 }
131
132 }// Loop over numerator legs
133
134 fill(monGroup_online, mass_col, match_mass_col, dphi_col, match_dphi_col);
135 fill(monGroup_offline, mass_off_col, match_mass_off_col, dphi_off_col, match_dphi_off_col);
136
137 }// Loop over all triggers
138
139 return StatusCode::SUCCESS;
140}
141
143
145 const xAOD::IParticle *part_on ,
146 const xAOD::IParticle *&part_off) const
147{
148 part_off=nullptr;
149 float min_deltaR = 999;
150 for (auto part : container){
151 float dR = part_on->p4().DeltaR(part->p4());
152 if ( dR < min_deltaR ){
153 part_off = part;
154 min_deltaR = dR;
155 }
156 }
157 return ( (min_deltaR < m_dR) && part_off);
158}
159
161
162void TrigEgammaMonitorTopoAlgorithm::make_legs( const std::string& trigger,
163 std::string key_leg0,
164 std::string key_leg1,
165 std::vector<Legs> &legs_vec ) const
166{
167 // Configure TDT to get each leg. only electrons that fired this triggers (e.g: e26_lhtight_e15_etcut_(Zee))
168 // are retrieved (passed by HLT and has at least one Electron online object)
170 frd_leg0.reset();
171 frd_leg0.setChainGroup(trigger);
172 frd_leg0.setCondition(TrigDefs::Physics); // Only fired trigger
173 frd_leg0.setRequireSGKey( TrigEgammaMonitorBaseAlgorithm::match()->key(std::move(key_leg0)));
174 frd_leg0.setRestrictRequestToLeg(0);
175
177 frd_leg1.reset();
178 frd_leg1.setChainGroup(trigger);
179 frd_leg1.setCondition(TrigDefs::Physics); // Only fired trigger
180 frd_leg1.setRequireSGKey( TrigEgammaMonitorBaseAlgorithm::match()->key(std::move(key_leg1)));
181 frd_leg1.setRestrictRequestToLeg(1);
182
183 // Get all combinations given by the L1
184 auto vec_leg0=tdt()->features<xAOD::IParticleContainer>(frd_leg0);
185 auto vec_leg1=tdt()->features<xAOD::IParticleContainer>(frd_leg1);
186
187 ATH_MSG_DEBUG("We have " << vec_leg0.size() << " combinations for leg0 from " << trigger);
188 ATH_MSG_DEBUG("We have " << vec_leg1.size() << " combinations for leg1 from " << trigger);
189
190 for ( auto & leg0_feat : vec_leg0){
191
192 for ( auto & leg1_feat : vec_leg1){
193 // Check if all links are valid
194 if ( !leg0_feat.isValid() || !leg1_feat.isValid() )
195 continue;
196 //auto leg0 = static_cast<xAOD::Egamma>(*leg0_feat.link);
197 //auto leg1 = static_cast<xAOD::Egamma>(*leg1_feat.link);
198 auto leg0 = (*leg0_feat.link);
199 auto leg1 = (*leg1_feat.link);
200
201 if (leg0 == leg1) continue;
202
203 legs_vec.push_back( Legs{leg0 , leg1} );
204 } // Loop over leg 1
205 } // Loop over leg 0
206}
207
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
const ToolHandle< GenericMonitoringTool > & getGroup(const std::string &name) const
Get a specific monitoring tool from the tool handle array.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigEgammaMonitorBaseAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
const ToolHandle< TrigEgammaMatchingToolMT > & match() const
Get the e/g match tool.
float dR(const float, const float, const float, const float) const
Get delta R.
const ToolHandle< Trig::TrigDecisionTool > & tdt() const
Get the TDT.
virtual StatusCode initialize() override
initialize
virtual StatusCode fillHistograms(const EventContext &ctx) const override
=========================================================================
TrigEgammaMonitorTopoAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< float > m_dR
Min Delta R between online and offline.
bool match(const xAOD::IParticleContainer &container, const xAOD::IParticle *part_on, const xAOD::IParticle *&part_off) const
=========================================================================
virtual ~TrigEgammaMonitorTopoAlgorithm() override
=========================================================================
SG::ReadHandleKey< xAOD::PhotonContainer > m_offPhotonKey
void make_legs(const std::string &trigger, std::string key_leg0, std::string key_leg1, std::vector< Legs > &) const
Get all combinations.
Gaudi::Property< std::vector< std::map< std::string, std::string > > > m_trigListConfig
List of configurations.
SG::ReadHandleKey< xAOD::ElectronContainer > m_offElectronKey
Event Wise offline ElectronContainer Access and end iterator.
virtual StatusCode initialize() override
=========================================================================
FeatureRequestDescriptor & setCondition(const unsigned int condition)
Set the Condition: TrigDefs::Physics - (default), only returns features from paths through the naviga...
void reset()
Reset the FeatureRequestDescriptor to its default configuration.
FeatureRequestDescriptor & setChainGroup(const std::string &chainGroupName)
Set the desired Chain or Chain Group.
FeatureRequestDescriptor & setRestrictRequestToLeg(const int restrictToLegIndex)
Set to -1 by default, indicating that all legs of multi-leg chains are searched.
FeatureRequestDescriptor & setRequireSGKey(const std::string &containerSGKey)
Set the StoreGate key filter.
Class providing the definition of the 4-vector interface.
virtual FourMom_t p4() const =0
The full 4-momentum of the particle.
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable > > &&variables) const
Fills a vector of variables to a group by reference.
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
The common trigger namespace for trigger analysis tools.
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.