ATLAS Offline Software
Loading...
Searching...
No Matches
PileUpMTAlg.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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 atomic_output(const atomic_output&) = delete;
42
43 bool init(const std::string& filename) {
44 using namespace std::chrono;
45 std::lock_guard lck{m_mtx};
46 if (m_file != nullptr) {
47 return true;
48 }
49 m_file = std::fopen(filename.c_str(), "a");
50 if (m_file == nullptr) {
51 return false;
52 }
53 auto time = system_clock::now();
54 auto header = std::format("FILE CREATED ON {:%Y-%m-%d} at {:%H:%M:%S %Z}\n",
55 time, time);
56 std::fputs(header.c_str(), m_file);
57 return true;
58 }
60 std::lock_guard lck{m_mtx};
61 if (m_file != nullptr) {
62 std::fclose(m_file);
63 m_file = nullptr;
64 }
65 }
66
67 void print(const std::string& str) {
68 std::lock_guard lck{m_mtx};
69 std::fputs(str.c_str(), m_file);
70 std::fflush(m_file);
71 }
72};
73
74class PileUpMTAlg : public AthAlgorithm {
75 public:
76 PileUpMTAlg(const std::string& name, ISvcLocator* pSvcLocator);
77 virtual ~PileUpMTAlg();
78
80
81 // IS EXECUTED:
82 virtual StatusCode initialize() override; // once, before any input is loaded
83 virtual StatusCode execute() override; // per event
84 virtual StatusCode finalize() override; // once, after all events processed
85
86 // Make this algorithm clonable
87 virtual bool isClonable() const override { return true; }
88 // virtual unsigned int cardinality() const override { return m_cardinality; }
89
98
99 private:
100 ServiceHandle<IMinbiasSvc> m_lowptMBSvc{this, "LowPtMinbiasSvc", "",
101 "MinbiasSvc for low pT minbias"};
102 ServiceHandle<IMinbiasSvc> m_highptMBSvc{this, "HighPtMinbiasSvc", "",
103 "MinbiasSvc for high pT minbias"};
104 ServiceHandle<IMinbiasSvc> m_cavernMBSvc{this, "CavernMinbiasSvc", "",
105 "MinbiasSvc for cavern background"};
107 this, "BeamHaloMinbiasSvc", "", "MinbiasSvc for beam halo background"};
109 this, "BeamGasMinbiasSvc", "", "MinbiasSvc for beam gas background"};
110 ServiceHandle<IBeamIntensity> m_beamInt{this, "BeamIntSvc", "FlatBM",
111 "Beam intensity service"};
113 this, "BeamLumiSvc", "LumiProfileSvc", "Beam luminosity service"};
114 ServiceHandle<IAthRNGSvc> m_rngSvc{this, "RNGSvc", "AthRNGSvc/PileupRNG",
115 "RNG service for pile-up digitization"};
116 ToolHandleArray<IPileUpTool> m_puTools{
117 this, "PileUpTools", {}, "Pileup tools"};
118 Gaudi::Property<bool> m_writeTrace{this, "WriteTrace", false, "Write trace of pileup events used"};
119 Gaudi::Property<int> m_skippedHSEvents{this, "SkippedHSEvents", 0,
120 "Number of skipped HS events"};
121 Gaudi::Property<float> m_avgMu{this, "AverageMu", 200, "Average mu"};
122 Gaudi::Property<float> m_fracLowPt{this, "FracLowPt", 0.,
123 "Fraction of pileup that has low pT"};
124 Gaudi::Property<float> m_fracHighPt{this, "FracHighPt", 0.,
125 "Fraction of pileup that has high pT"};
126 Gaudi::Property<float> m_numCavern{
127 this, "NumCavern", 0., "Number of cavern background events per BC"};
128 Gaudi::Property<float> m_numBeamGas{
129 this, "NumBeamGas", 0., "Number of beam gas background events per BC"};
130 Gaudi::Property<float> m_numBeamHalo{
131 this, "NumBeamHalo", 0., "Number of beam halo background events per BC"};
132 Gaudi::Property<int> m_BCSpacing{this, "BCSpacing", 25,
133 "Bunch crossing spacing in ns"};
134 Gaudi::Property<int> m_earliestDeltaBC{
135 this, "EarliestDeltaBC", -32,
136 "Earliest bunch crossing to consider (as delta)"};
137 Gaudi::Property<int> m_latestDeltaBC{
138 this, "LatestDeltaBC", +6,
139 "Latest bunch crossing to consider (as delta)"};
141 this, "SkipEvtIdxSvc", "SkipEventIdxSvc",
142 "Skipped event index (run / lb num) provider"};
144 this, "BeamSpotKey", "BeamSpotData", "Beam spot info key"};
146 this, "EventInfoKey", "OverlayEvent", "Overlay EventInfo key"};
148 // Utilities
149 StatusCode get_ei(StoreGateSvc& sg,
150 std::unique_ptr<const xAOD::EventInfo>& ei,
151 std::unique_ptr<xAOD::EventAuxInfo>& eiAux,
152 bool pileup = false) const;
153 inline unsigned int get_BCID(int bc, unsigned int central_BCID) const {
154 constexpr int maxBCPerOrbit = 3564; // FIXME may need update
155 return static_cast<unsigned int>((bc + static_cast<int>(central_BCID)) %
156 maxBCPerOrbit);
157 }
158 StatusCode add_subevt(const std::vector<std::uint32_t>& bcid,
162 xAOD::EventInfo::PileUpType puType, int bc,
163 const EventContext& ctx, unsigned long subevt_id,
164 std::vector<std::uint64_t>& trace);
165 inline static atomic_output m_pileupTrace ATLAS_THREAD_SAFE{};
166 inline static bool m_skiptrace_written ATLAS_THREAD_SAFE = false;
167};
168
169#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:87
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
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...
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.
atomic_output(const atomic_output &)=delete
atomic_output & operator=(const atomic_output &)=delete
bool init(const std::string &filename)
Definition PileUpMTAlg.h:43
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:67
PileUpType
Enumerator describing the types of pileup events.