ATLAS Offline Software
Loading...
Searching...
No Matches
PileUpMTAlg.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2022, 2023, 2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef PILEUPMT_PILEUPMTALG_H
6#define PILEUPMT_PILEUPMTALG_H
7
20
21// Example ROOT Includes
22// #include "TTree.h"
23// #include "TH1D.h"
24
25#include <atomic>
26#include <chrono>
27#include <cstdio>
28#include <format>
29#include <string>
30#include <string_view>
31#include <thread>
32
34 private:
35 std::FILE* m_file{};
36 std::mutex m_mtx{};
37
38 public:
39 atomic_output() = default;
40 bool init(const std::string& filename) {
41 using namespace std::chrono;
42 std::lock_guard lck{m_mtx};
43 if (m_file != nullptr) {
44 return true;
45 }
46 m_file = std::fopen(filename.c_str(), "a");
47 if (m_file == nullptr) {
48 return false;
49 }
50 auto time = system_clock::now();
51 auto header = std::format("FILE CREATED ON {:%Y-%m-%d} at {:%H:%M:%S %Z}\n",
52 time, time);
53 std::fputs(header.c_str(), m_file);
54 return true;
55 }
57 std::lock_guard lck{m_mtx};
58 if (m_file != nullptr) {
59 std::fclose(m_file);
60 m_file = nullptr;
61 }
62 }
63
64 void print(const std::string& str) {
65 std::lock_guard lck{m_mtx};
66 std::fputs(str.c_str(), m_file);
67 std::fflush(m_file);
68 }
69};
70
71class PileUpMTAlg : public AthAlgorithm {
72 public:
73 PileUpMTAlg(const std::string& name, ISvcLocator* pSvcLocator);
74 virtual ~PileUpMTAlg();
75
77
78 // IS EXECUTED:
79 virtual StatusCode initialize() override; // once, before any input is loaded
80 virtual StatusCode execute() override; // per event
81 virtual StatusCode finalize() override; // once, after all events processed
82
83 // Make this algorithm clonable
84 virtual bool isClonable() const override { return true; }
85 // virtual unsigned int cardinality() const override { return m_cardinality; }
86
95
96 private:
97 ServiceHandle<IMinbiasSvc> m_lowptMBSvc{this, "LowPtMinbiasSvc", "",
98 "MinbiasSvc for low pT minbias"};
99 ServiceHandle<IMinbiasSvc> m_highptMBSvc{this, "HighPtMinbiasSvc", "",
100 "MinbiasSvc for high pT minbias"};
101 ServiceHandle<IMinbiasSvc> m_cavernMBSvc{this, "CavernMinbiasSvc", "",
102 "MinbiasSvc for cavern background"};
104 this, "BeamHaloMinbiasSvc", "", "MinbiasSvc for beam halo background"};
106 this, "BeamGasMinbiasSvc", "", "MinbiasSvc for beam gas background"};
107 ServiceHandle<IBeamIntensity> m_beamInt{this, "BeamIntSvc", "FlatBM",
108 "Beam intensity service"};
110 this, "BeamLumiSvc", "LumiProfileSvc", "Beam luminosity service"};
111 ServiceHandle<IAthRNGSvc> m_rngSvc{this, "RNGSvc", "AthRNGSvc/PileupRNG",
112 "RNG service for pile-up digitization"};
113 ToolHandleArray<IPileUpTool> m_puTools{
114 this, "PileUpTools", {}, "Pileup tools"};
115 Gaudi::Property<bool> m_writeTrace{this, "WriteTrace", false, "Write trace of pileup events used"};
116 Gaudi::Property<int> m_skippedHSEvents{this, "SkippedHSEvents", 0,
117 "Number of skipped HS events"};
118 Gaudi::Property<float> m_avgMu{this, "AverageMu", 200, "Average mu"};
119 Gaudi::Property<float> m_fracLowPt{this, "FracLowPt", 0.,
120 "Fraction of pileup that has low pT"};
121 Gaudi::Property<float> m_fracHighPt{this, "FracHighPt", 0.,
122 "Fraction of pileup that has high pT"};
123 Gaudi::Property<float> m_numCavern{
124 this, "NumCavern", 0., "Number of cavern background events per BC"};
125 Gaudi::Property<float> m_numBeamGas{
126 this, "NumBeamGas", 0., "Number of beam gas background events per BC"};
127 Gaudi::Property<float> m_numBeamHalo{
128 this, "NumBeamHalo", 0., "Number of beam halo background events per BC"};
129 Gaudi::Property<int> m_BCSpacing{this, "BCSpacing", 25,
130 "Bunch crossing spacing in ns"};
131 Gaudi::Property<int> m_earliestDeltaBC{
132 this, "EarliestDeltaBC", -32,
133 "Earliest bunch crossing to consider (as delta)"};
134 Gaudi::Property<int> m_latestDeltaBC{
135 this, "LatestDeltaBC", +6,
136 "Latest bunch crossing to consider (as delta)"};
138 this, "SkipEvtIdxSvc", "SkipEventIdxSvc",
139 "Skipped event index (run / lb num) provider"};
141 this, "BeamSpotKey", "BeamSpotData", "Beam spot info key"};
143 this, "EventInfoKey", "OverlayEvent", "Overlay EventInfo key"};
145 // Utilities
146 StatusCode get_ei(StoreGateSvc& sg,
147 std::unique_ptr<const xAOD::EventInfo>& ei,
148 std::unique_ptr<xAOD::EventAuxInfo>& eiAux,
149 bool pileup = false) const;
150 inline unsigned int get_BCID(int bc, unsigned int central_BCID) const {
151 constexpr int maxBCPerOrbit = 3564; // FIXME may need update
152 return static_cast<unsigned int>((bc + static_cast<int>(central_BCID)) %
153 maxBCPerOrbit);
154 }
155 StatusCode add_subevt(const std::vector<std::uint32_t>& bcid,
159 xAOD::EventInfo::PileUpType puType, int bc,
160 const EventContext& ctx, unsigned long subevt_id,
161 std::vector<std::uint64_t>& trace);
162 inline static atomic_output m_pileupTrace ATLAS_THREAD_SAFE{};
163 inline static bool m_skiptrace_written ATLAS_THREAD_SAFE = false;
164};
165
166#endif //> !PILEUPMT_PILEUPMTALG_H
provides the relative beam intensity as a function of the bunch xing.
provides the relative beam luminosity as a function of the bunch xing.
a call-back interface for tools that merge pileup events information An IPileUpTool is called back fo...
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Property< int > m_earliestDeltaBC
virtual StatusCode initialize() override
uncomment and implement methods as required
Gaudi::Property< int > m_latestDeltaBC
Gaudi::Property< bool > m_writeTrace
Gaudi::Property< float > m_avgMu
PileUpMTAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< float > m_numCavern
virtual bool isClonable() const override
Definition PileUpMTAlg.h:84
unsigned int get_BCID(int bc, unsigned int central_BCID) const
virtual StatusCode execute() override
virtual ~PileUpMTAlg()
Gaudi::Property< float > m_fracLowPt
static atomic_output m_pileupTrace ATLAS_THREAD_SAFE
ServiceHandle< IBeamLuminosity > m_beamLumi
ToolHandleArray< IPileUpTool > m_puTools
SG::WriteHandleKey< xAOD::EventInfoContainer > m_evtInfoContKey
ServiceHandle< IAthRNGSvc > m_rngSvc
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
StatusCode get_ei(StoreGateSvc &sg, std::unique_ptr< const xAOD::EventInfo > &ei, std::unique_ptr< xAOD::EventAuxInfo > &eiAux, bool pileup=false) const
ServiceHandle< IMinbiasSvc > m_beamgasMBSvc
ServiceHandle< IMinbiasSvc > m_highptMBSvc
Definition PileUpMTAlg.h:99
ServiceHandle< IMinbiasSvc > m_cavernMBSvc
Gaudi::Property< float > m_fracHighPt
SG::WriteHandleKey< xAOD::EventInfo > m_evtInfoKey
ServiceHandle< IBeamIntensity > m_beamInt
ServiceHandle< ISkipEventIdxSvc > m_skipEventIdxSvc
Gaudi::Property< int > m_skippedHSEvents
ServiceHandle< IMinbiasSvc > m_lowptMBSvc
Other useful methods provided by base class are: evtStore() : ServiceHandle to main event data storeg...
Definition PileUpMTAlg.h:97
Gaudi::Property< float > m_numBeamGas
Gaudi::Property< float > m_numBeamHalo
virtual StatusCode finalize() override
StatusCode add_subevt(const std::vector< std::uint32_t > &bcid, SG::WriteHandle< xAOD::EventInfo > &overlaidEvt, SG::WriteHandle< xAOD::EventInfoContainer > &puCont, ServiceHandle< IMinbiasSvc > &mbSvc, xAOD::EventInfo::PileUpType puType, int bc, const EventContext &ctx, unsigned long subevt_id, std::vector< std::uint64_t > &trace)
ServiceHandle< IMinbiasSvc > m_beamhaloMBSvc
Gaudi::Property< int > m_BCSpacing
Property holding a SG store/key/clid from which a WriteHandle is made.
The Athena Transient Store API.
bool init(const std::string &filename)
Definition PileUpMTAlg.h:40
std::FILE * m_file
Definition PileUpMTAlg.h:35
std::mutex m_mtx
Definition PileUpMTAlg.h:36
atomic_output()=default
void print(const std::string &str)
Definition PileUpMTAlg.h:64
PileUpType
Enumerator describing the types of pileup events.