ATLAS Offline Software
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 
11 using namespace Trig;
12 
13 
14 TrigEgammaMonitorTopoAlgorithm::TrigEgammaMonitorTopoAlgorithm( const std::string& name, ISvcLocator* pSvcLocator ):
15  TrigEgammaMonitorBaseAlgorithm( name, pSvcLocator )
16 {}
17 
19 
21 {}
22 
24 
26 {
27  ATH_MSG_INFO("TrigEgammaMonitorTopoAlgorithm::initialize()...");
28 
30 
32  ATH_CHECK(m_offPhotonKey.initialize());
33 
34  return StatusCode::SUCCESS;
35 }
36 
38 
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 
162 void 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 
Trig::FeatureRequestDescriptor::setCondition
FeatureRequestDescriptor & setCondition(const unsigned int condition)
Set the Condition: TrigDefs::Physics - (default), only returns features from paths through the naviga...
Definition: FeatureRequestDescriptor.cxx:83
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
Trig::FeatureRequestDescriptor
Definition: FeatureRequestDescriptor.h:37
TrigEgammaMonitorBaseAlgorithm::dR
float dR(const float, const float, const float, const float) const
Get delta R.
Definition: TrigEgammaMonitorBaseAlgorithm.cxx:272
TrigEgammaMonitorTopoAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
=========================================================================
Definition: TrigEgammaMonitorTopoAlgorithm.cxx:39
TrigEgammaMonitorTopoAlgorithm::m_offPhotonKey
SG::ReadHandleKey< xAOD::PhotonContainer > m_offPhotonKey
Definition: TrigEgammaMonitorTopoAlgorithm.h:47
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trig
The common trigger namespace for trigger analysis tools.
Definition: LArCellMonAlg.h:33
TrigEgammaMonitorTopoAlgorithm::make_legs
void make_legs(const std::string &trigger, std::string key_leg0, std::string key_leg1, std::vector< Legs > &) const
Get all combinations.
Definition: TrigEgammaMonitorTopoAlgorithm.cxx:162
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
hist_file_dump.d
d
Definition: hist_file_dump.py:137
Trig::FeatureRequestDescriptor::setChainGroup
FeatureRequestDescriptor & setChainGroup(const std::string &chainGroupName)
Set the desired Chain or Chain Group.
Definition: FeatureRequestDescriptor.cxx:77
TrigEgammaMonitorTopoAlgorithm::m_dR
Gaudi::Property< float > m_dR
Min Delta R between online and offline.
Definition: TrigEgammaMonitorTopoAlgorithm.h:44
TrigEgammaMonitorBaseAlgorithm::tdt
const ToolHandle< Trig::TrigDecisionTool > & tdt() const
Get the TDT
Definition: TrigEgammaMonitorBaseAlgorithm.h:133
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
TrigEgammaMonitorTopoAlgorithm::m_offElectronKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_offElectronKey
Event Wise offline ElectronContainer Access and end iterator.
Definition: TrigEgammaMonitorTopoAlgorithm.h:46
TrigEgammaMonitorBaseAlgorithm::isHLTTruncated
bool isHLTTruncated() const
Definition: TrigEgammaMonitorBaseAlgorithm.cxx:733
TrigEgammaMonitorTopoAlgorithm::initialize
virtual StatusCode initialize() override
=========================================================================
Definition: TrigEgammaMonitorTopoAlgorithm.cxx:25
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TrigEgammaMonitorTopoAlgorithm::TrigEgammaMonitorTopoAlgorithm
TrigEgammaMonitorTopoAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigEgammaMonitorTopoAlgorithm.cxx:14
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IParticleContainer.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthMonitorAlgorithm::fill
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.
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
Trig::FeatureRequestDescriptor::reset
void reset()
Reset the FeatureRequestDescriptor to its default configuration.
Definition: FeatureRequestDescriptor.cxx:31
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
TrigEgammaMonitorTopoAlgorithm.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trig::FeatureRequestDescriptor::setRestrictRequestToLeg
FeatureRequestDescriptor & setRestrictRequestToLeg(const int restrictToLegIndex)
Set to -1 by default, indicating that all legs of multi-leg chains are searched.
Definition: FeatureRequestDescriptor.cxx:113
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TrigEgammaMonitorTopoAlgorithm::Legs
Definition: TrigEgammaMonitorTopoAlgorithm.h:19
Trig::FeatureRequestDescriptor::setRequireSGKey
FeatureRequestDescriptor & setRequireSGKey(const std::string &containerSGKey)
Set the StoreGate key filter.
Definition: FeatureRequestDescriptor.cxx:92
xAOD::IParticle::p4
virtual FourMom_t p4() const =0
The full 4-momentum of the particle.
TrigEgammaMonitorBaseAlgorithm::match
const ToolHandle< TrigEgammaMatchingToolMT > & match() const
Get the e/g match tool.
Definition: TrigEgammaMonitorBaseAlgorithm.h:135
TrigEgammaMonitorBaseAlgorithm
Definition: TrigEgammaMonitorBaseAlgorithm.h:66
TrigEgammaMonitorBaseAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: TrigEgammaMonitorBaseAlgorithm.cxx:24
TrigEgammaMonitorTopoAlgorithm::~TrigEgammaMonitorTopoAlgorithm
virtual ~TrigEgammaMonitorTopoAlgorithm() override
=========================================================================
Definition: TrigEgammaMonitorTopoAlgorithm.cxx:20
FeatureRequestDescriptor.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
AthMonitorAlgorithm::getGroup
const ToolHandle< GenericMonitoringTool > & getGroup(const std::string &name) const
Get a specific monitoring tool from the tool handle array.
Definition: AthMonitorAlgorithm.cxx:164
TrigEgammaMonitorTopoAlgorithm::m_trigListConfig
Gaudi::Property< std::vector< std::map< std::string, std::string > > > m_trigListConfig
List of configurations.
Definition: TrigEgammaMonitorTopoAlgorithm.h:42
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37