ATLAS Offline Software
TrigTLAMonitorAlgorithm.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRIGTLAMONITORING_TRIGTLAMONITORALGORITHM_H
6 #define TRIGTLAMONITORING_TRIGTLAMONITORALGORITHM_H
7 
10 
12 
13 #include "xAODJet/JetContainer.h"
14 #include "xAODMuon/MuonContainer.h"
18 
20  public:
21  TrigTLAMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator );
22  virtual ~TrigTLAMonitorAlgorithm();
23  virtual StatusCode initialize() override;
24  virtual StatusCode fillHistograms( const EventContext& ctx ) const override;
25 
26  private:
27  Gaudi::Property<std::vector<std::string>> m_allChains{this,"AllChains",{}};
28 
29  SG::ReadHandleKey<xAOD::JetContainer > m_jetContainerKey {this,"JetContainerName" ,"HLT_AntiKt4EMTopoJets_subjesIS_TLA" , "Jet Container Name"};
30  SG::ReadHandleKey<xAOD::JetContainer > m_pfjetContainerKey {this,"PFJetContainerName" ,"HLT_AntiKt4EMPFlowJets_subresjesgscIS_ftf_TLA", "Particle Flow Jet Container Name"};
31  SG::ReadHandleKey<xAOD::PhotonContainer> m_photonContainerKey{this,"PhotonContainerName","HLT_egamma_Photons_TLA" , "Photon Container Name"};
32  SG::ReadHandleKey<xAOD::MuonContainer > m_muonContainerKey {this,"MuonContainerName" ,"HLT_MuonsCB_RoI_TLA" , "Muon Container Name"};
33  SG::ReadHandleKey<xAOD::TrackParticleContainer> m_trackParticleContainerKey{this,"TrackContainerName" ,"HLT_IDTrack_FS_FTF" , "Track Container Name"};
34  SG::ReadHandleKey<xAOD::TrigCompositeContainer> m_tcEventInfoContainerKey {this,"TCEventInfoContainerName","HLT_TCEventInfo_TLA" , "TCEventInfo Container Name"};
35 
36  PublicToolHandle<Trig::TrigDecisionTool> m_trigDecisionTool{this,"TriggerDecisionTool","Trigger decision tool"};
37 
39 
44  template <typename T>
45  StatusCode readContainer(SG::ReadHandle<T> & container, SG::ReadHandleKey<T> key, const EventContext& ctx) const;
46 
48 
53  template <typename T>
54  StatusCode fillEventInfoHistogram(SG::ReadHandle<DataVector<xAOD::TrigComposite_v1> > tcEventInfo, const std::string& varname, const std::string& prefix) const;
55 
57 
66  template <class T>
67  StatusCode fillParticleHistograms(SG::ReadHandle<DataVector<T>> particles, const std::string& prefix, const std::string& trigName) const;
68 
70 
80  template<class C, typename T>
81  StatusCode fillObjectVariableHistogram(SG::ReadHandle<DataVector<C>> container, const std::string& varname, const std::string& prefix , const std::string& trigName, T default_val=-1) const;
82 
84  // The first element (corresponding to the hard scatter vertex) is filled.
92  template <typename T>
93  StatusCode fillJetTrackVariableHistogram(SG::ReadHandle<xAOD::JetContainer> jets, const std::string& varname, const std::string& prefix, const std::string& trigName, T default_val=-1) const;
94 
96 
103  template <typename U, typename T>
104  StatusCode fill2DHistogram(const std::string& varname1, U var1, const std::string& varname2, T var2, const std::string& prefix) const;
105 
107 
113  StatusCode fillJetPtCalibStatesHistograms(SG::ReadHandle<xAOD::JetContainer> jets, const std::string& calibState, const std::string& prefix, const std::string& trigName) const;
114 
116 
125  StatusCode fillDeltaRHistograms(const xAOD::IParticle* p0, const xAOD::IParticle* p1, const std::string& prefix, const std::string& trigName) const;
126 };
127 
128 
129 /*************************************************
130 * Implementation of templated methods *
131 **************************************************/
132 
133 template <typename T>
135 
136  container = SG::makeHandle( key, ctx );
137  if (! container.isValid() ) {
138  ATH_MSG_ERROR("evtStore() does not contain Collection with name "<< key);
139  return StatusCode::FAILURE;
140  }
141 
142  return StatusCode::SUCCESS;
143 }
144 
145 
146 template <typename T>
148 
150 
151  for(auto tcEI : *tcEventInfo) {
152  auto status = tcEI->getDetail<T>(varname, variable);
153  if (!status) ATH_MSG_WARNING("No "<<varname<<" for this event");
154  else {
155  fill("TrigTLAMonitor", variable);
156  ATH_MSG_DEBUG("Retrieved EventInfo variable: "<<varname<<" = "<<variable);
157  }
158  }
159 
160  return StatusCode::SUCCESS;
161 }
162 
163 
164 template <class T>
166 
167  // histograms
168  Monitored::Scalar<int > n ("n"+prefix+"_"+trigName,0 );
169  Monitored::Scalar<double> pt (prefix+"pt_" +trigName,0.0);
170  Monitored::Scalar<double> eta (prefix+"eta_" +trigName,0.0);
171  Monitored::Scalar<double> phi (prefix+"phi_" +trigName,0.0);
172 
173  Monitored::Scalar<double> pt0 (prefix+"0pt_" +trigName,0.0);
174  Monitored::Scalar<double> eta0(prefix+"0eta_"+trigName,0.0);
175  Monitored::Scalar<double> phi0(prefix+"0phi_"+trigName,0.0);
176 
177  // fill
178  n = particles->size();
179  fill("TrigTLAMonitor", n);
180 
181  for(const T* particle : *particles) {
182  pt = particle->pt()/1e3;
183  eta = particle->eta();
184  phi = particle->phi();
185  fill("TrigTLAMonitor",pt );
186  fill("TrigTLAMonitor",eta);
187  fill("TrigTLAMonitor",phi);
188  }
189 
190  // fill leading particle
191  if(particles->size()>0) {
192  pt0 =particles->at(0)->pt ()/1e3;
193  eta0=particles->at(0)->eta();
194  phi0=particles->at(0)->phi();
195  fill("TrigTLAMonitor",pt0 );
196  fill("TrigTLAMonitor",eta0);
197  fill("TrigTLAMonitor",phi0);
198  }
199 
200  return StatusCode::SUCCESS;
201 
202 }
203 
204 
205 template<class C,typename T>
206 StatusCode TrigTLAMonitorAlgorithm::fillObjectVariableHistogram(SG::ReadHandle<DataVector<C>> container, const std::string& varname, const std::string& prefix , const std::string& trigName, T default_val) const {
207 
208  // change var name to avoid confilcts with Monitoring standards ("var_trigname")
209  std::string hname = varname;
210  std::replace( hname.begin(), hname.end(), '_', '-' );
211 
212  Monitored::Scalar<T> mon_var (prefix+hname+"_"+trigName,default_val);
214 
215  unsigned cnt(0);
216  for(const auto element : *container) {
217  mon_var = accessor(*element);
218  fill("TrigTLAMonitor", mon_var);
219  if (cnt < 5) ATH_MSG_DEBUG(prefix<<" "<<varname<<" = "<<mon_var);
220  cnt++;
221  }
222  return StatusCode::SUCCESS;
223 }
224 
225 
226 template <typename T>
227 StatusCode TrigTLAMonitorAlgorithm::fillJetTrackVariableHistogram(SG::ReadHandle<xAOD::JetContainer> jets, const std::string& varname, const std::string& prefix, const std::string& trigName, T default_val) const {
228 
229  std::vector<T> variable_vec;
230  Monitored::Scalar<T> variable (prefix+varname+"_"+trigName,default_val);
231 
232  unsigned cnt(0);
233  for(auto jet : *jets) {
234  auto status = jet->getAttribute<std::vector<T>>(varname, variable_vec);
235  if (!status){
236  ATH_MSG_WARNING("Failed retrieving "<<varname<<" for "<<prefix);
237  }
238  variable = variable_vec.at(0);
239  fill("TrigTLAMonitor",variable);
240  if (cnt < 3) ATH_MSG_DEBUG(prefix<<" "<<varname<<" = "<<variable);
241  cnt++;
242  }
243 
244  return StatusCode::SUCCESS;
245 }
246 
247 
248 template <typename U, typename T>
249 StatusCode TrigTLAMonitorAlgorithm::fill2DHistogram(const std::string& varname1, U var1, const std::string& varname2, T var2, const std::string& prefix) const{
250 
251  Monitored::Scalar<U> mon_var1(prefix+"_"+varname1, var1);
252  Monitored::Scalar<T> mon_var2(prefix+"_"+varname2, var2);
253  ATH_MSG_DEBUG("Filling 2D histogram. "<<varname1<<" = "<<var1<<" ; "<<varname2<<" = "<<var2);
254  fill("TrigTLAMonitor", mon_var1, mon_var2);
255 
256  return StatusCode::SUCCESS;
257 }
258 
259 
260 #endif
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
TrigTLAMonitorAlgorithm::~TrigTLAMonitorAlgorithm
virtual ~TrigTLAMonitorAlgorithm()
Definition: TrigTLAMonitorAlgorithm.cxx:12
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
TrigTLAMonitorAlgorithm::readContainer
StatusCode readContainer(SG::ReadHandle< T > &container, SG::ReadHandleKey< T > key, const EventContext &ctx) const
Retrieve a container of type T.
Definition: TrigTLAMonitorAlgorithm.h:134
TrigTLAMonitorAlgorithm::m_jetContainerKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetContainerKey
Definition: TrigTLAMonitorAlgorithm.h:29
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
dqt_zlumi_pandas.hname
string hname
Definition: dqt_zlumi_pandas.py:279
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
InDetAccessor::phi0
@ phi0
Definition: InDetAccessor.h:33
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
test_pyathena.pt
pt
Definition: test_pyathena.py:11
TrigTLAMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: TrigTLAMonitorAlgorithm.cxx:32
TrigTLAMonitorAlgorithm::fill2DHistogram
StatusCode fill2DHistogram(const std::string &varname1, U var1, const std::string &varname2, T var2, const std::string &prefix) const
A generic function to fill 2D histogram.
Definition: TrigTLAMonitorAlgorithm.h:249
TrigDecisionTool.h
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
TrigTLAMonitorAlgorithm::m_trigDecisionTool
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecisionTool
Definition: TrigTLAMonitorAlgorithm.h:36
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
TrigTLAMonitorAlgorithm::fillJetTrackVariableHistogram
StatusCode fillJetTrackVariableHistogram(SG::ReadHandle< xAOD::JetContainer > jets, const std::string &varname, const std::string &prefix, const std::string &trigName, T default_val=-1) const
Fill jet track variable to 1D histograms. Jet track variables are vectors where each element correspo...
Definition: TrigTLAMonitorAlgorithm.h:227
TrigTLAMonitorAlgorithm::fillJetPtCalibStatesHistograms
StatusCode fillJetPtCalibStatesHistograms(SG::ReadHandle< xAOD::JetContainer > jets, const std::string &calibState, const std::string &prefix, const std::string &trigName) const
Fill jet pT to 1D histograms at different calibration scales.
Definition: TrigTLAMonitorAlgorithm.cxx:183
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TrigTLAMonitorAlgorithm::fillParticleHistograms
StatusCode fillParticleHistograms(SG::ReadHandle< DataVector< T >> particles, const std::string &prefix, const std::string &trigName) const
Fill kinematic histograms for a given particle of type T
Definition: TrigTLAMonitorAlgorithm.h:165
TrigTLAMonitorAlgorithm::m_photonContainerKey
SG::ReadHandleKey< xAOD::PhotonContainer > m_photonContainerKey
Definition: TrigTLAMonitorAlgorithm.h:31
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
TrigTLAMonitorAlgorithm
Definition: TrigTLAMonitorAlgorithm.h:19
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
beamspotman.n
n
Definition: beamspotman.py:731
TrigTLAMonitorAlgorithm::fillObjectVariableHistogram
StatusCode fillObjectVariableHistogram(SG::ReadHandle< DataVector< C >> container, const std::string &varname, const std::string &prefix, const std::string &trigName, T default_val=-1) const
Fill Analysis Object feature histogram`.
Definition: TrigTLAMonitorAlgorithm.h:206
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
AthMonitorAlgorithm.h
TrigTLAMonitorAlgorithm::m_pfjetContainerKey
SG::ReadHandleKey< xAOD::JetContainer > m_pfjetContainerKey
Definition: TrigTLAMonitorAlgorithm.h:30
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
python.selection.variable
variable
Definition: selection.py:33
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.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
TrigTLAMonitorAlgorithm::m_tcEventInfoContainerKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_tcEventInfoContainerKey
Definition: TrigTLAMonitorAlgorithm.h:34
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigCompositeContainer.h
TrigTLAMonitorAlgorithm::TrigTLAMonitorAlgorithm
TrigTLAMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigTLAMonitorAlgorithm.cxx:8
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrigTLAMonitorAlgorithm::m_allChains
Gaudi::Property< std::vector< std::string > > m_allChains
Definition: TrigTLAMonitorAlgorithm.h:27
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
MuonContainer.h
TrigTLAMonitorAlgorithm::m_trackParticleContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticleContainerKey
Definition: TrigTLAMonitorAlgorithm.h:33
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37
JetContainer.h
trigbs_pickEvents.cnt
cnt
Definition: trigbs_pickEvents.py:71
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrigTLAMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: TrigTLAMonitorAlgorithm.cxx:15
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
merge.status
status
Definition: merge.py:17
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
PhotonContainer.h
TrigTLAMonitorAlgorithm::m_muonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonContainerKey
Definition: TrigTLAMonitorAlgorithm.h:32
TrackParticleContainer.h
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
TRTCalib_cfilter.p0
p0
Definition: TRTCalib_cfilter.py:129
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
TrigTLAMonitorAlgorithm::fillEventInfoHistogram
StatusCode fillEventInfoHistogram(SG::ReadHandle< DataVector< xAOD::TrigComposite_v1 > > tcEventInfo, const std::string &varname, const std::string &prefix) const
Fill an event info variable to a 1D histogram.
Definition: TrigTLAMonitorAlgorithm.h:147
TrigTLAMonitorAlgorithm::fillDeltaRHistograms
StatusCode fillDeltaRHistograms(const xAOD::IParticle *p0, const xAOD::IParticle *p1, const std::string &prefix, const std::string &trigName) const
Fill kinematic histograms for a given particle of type T
Definition: TrigTLAMonitorAlgorithm.cxx:170