ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoredAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "MonitoredAlg.h"
7#include "TestTools/random.h"
8
9#include <vector>
10#include <cmath>
11
12MonitoredAlg::MonitoredAlg(const std::string& name, ISvcLocator* pSvcLocator) :
13 AthAlgorithm(name, pSvcLocator)
14{
15}
16
18{
19 // Only try to retrieve the tool if one has been set
20 if (!m_monTool.empty()) CHECK(m_monTool.retrieve());
21
22 return StatusCode::SUCCESS;
23}
24
26class Track {
27public:
28 Track(double eta, double phi, double pt) : m_eta(eta), m_phi(phi), m_pt(pt) {}
29 double eta() const { return m_eta; }
30 double phi() const { return m_phi; }
31 double pt() const { return m_pt; }
32private:
33 double m_eta{0}, m_phi{0}, m_pt{0};
34};
35
36
38{
39 std::vector<Track> tracks;
40
41 // In case you want to measure the execution time
42 auto timer = Monitored::Timer("TIME_execute");
43
44 auto count = Monitored::Scalar<int>("nTracks", 0); // explicit type
45
46 // Access via member
47 auto eta = Monitored::Collection("eta", tracks, &Track::eta);
48
49 // Access via function/lambda
50 auto absphi = Monitored::Collection("AbsPhi", tracks, []( const Track& t ) { return abs(t.phi()); });
51
52 auto mon = Monitored::Group(m_monTool, count, eta, absphi, timer);
53
54 count = Athena_test::randi_seed (m_seed, 11, 1); // random number of tracks
55
56 // Creating some random tracks
57 for (int i=0; i<count; ++i) {
58 float eta = Athena_test::randf_seed (m_seed, 3.0, -3.0);
60 float pt = Athena_test::randf_seed (m_seed, 100);
61 tracks.push_back(Track(eta, phi, pt));
62 }
63
64 return StatusCode::SUCCESS;
65}
66
67
68
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define CHECK(...)
Evaluate an expression and check for errors.
Header file to be included by clients of the Monitored infrastructure.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
uint32_t m_seed
ToolHandle< GenericMonitoringTool > m_monTool
StatusCode execute()
MonitoredAlg(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize()
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
A monitored timer.
double m_phi
double eta() const
double m_eta
double m_pt
double phi() const
Track(double eta, double phi, double pt)
double pt() const
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
float randf_seed(uint32_t &seed, float rmax, float rmin=0)
Generate a floating-point random number between rmin and rmax.
Definition random.h:53
int randi_seed(uint32_t &seed, int rmax, int rmin=0)
Generate an integer random number between rmin and rmax.
Definition random.h:61
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Very simple random numbers for regression testing.