ATLAS Offline Software
Loading...
Searching...
No Matches
EnhancedBiasWeighter.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 ENHANCEDBIASWEIGHTER_ENHANCEDBIASWEIGHTER_H
6#define ENHANCEDBIASWEIGHTER_ENHANCEDBIASWEIGHTER_H 1
7
8#include "AsgTools/AsgTool.h"
10#include "GaudiKernel/ToolHandle.h"
11#include "Gaudi/Accumulators.h"
12
15
18
19#include <unordered_map>
20#include <mutex>
21
43
48 public:
49 //constructor for athena can be created using special macro
50 //Note: if you add a second interface to your tool, you must use: ASG_TOOL_CLASS2( ToolName, Interface1, Interface2)
52 //add another constructor for non-athena use cases
53 EnhancedBiasWeighter( const std::string& name );
54
55 constexpr static double LHC_FREQUENCY = 11245.5; //<! LHC revolution frequency in Hz
56 constexpr static uint32_t FULL_RING = 2738;
57
59 virtual StatusCode initialize() override;
60 virtual StatusCode finalize() override;
61 //
62
67 virtual StatusCode addBranches(const EventContext& ctx) const override;
68
73 virtual double getEBWeight(const xAOD::EventInfo* eventInfo) const override;
74 virtual double getEBWeight(const EventContext& context) const override;
75
79 virtual double getBunchCrossingRate() const override;
80
87 virtual double getEBLiveTime(const xAOD::EventInfo* eventInfo) const override;
88 virtual double getEBLiveTime(const EventContext& context) const override;
89
94 virtual double getLBLength(const xAOD::EventInfo* eventInfo) const override;
95 virtual double getLBLength(const EventContext& context) const override;
96
103 virtual double getLBLumi(const xAOD::EventInfo* eventInfo) const override;
104 virtual double getLBLumi(const EventContext& context) const override;
105
109 virtual double getAverageLumi() const override;
110
114 virtual double getAverageMu() const override;
115
121 virtual double getDeadtime(const int lumiblock = -1) const override;
122
128 virtual uint32_t getPairedBunches() const override;
129
134 virtual StatusCode getDistanceIntoTrain(const xAOD::EventInfo* eventInfo, uint32_t& distance, const EventContext& ctx) const override;
135
139 virtual uint32_t getRunNumber() const override;
140
148 virtual bool isUnbiasedEvent(const xAOD::EventInfo* eventInfo) const override;
149
155 virtual bool isGoodLB(const xAOD::EventInfo* eventInfo) const override;
156 virtual bool isGoodLB(const EventContext& context) const override;
157
161 virtual bool isMC() const override;
162
169 virtual std::unordered_map<std::string, ChainDetail> parsePrescaleXML(const std::string& prescaleXML) const override;
170
174 virtual const std::vector<int32_t>& getBunchGroups() const override { return m_bunches; }
175
176 private:
177 StatusCode loadWeights();
178 StatusCode loadLumi();
179 StatusCode trackAverages(const xAOD::EventInfo* eventInfo) const;
180 StatusCode trackAverages(const EventContext& context) const;
185 int32_t getEventEBID(const xAOD::EventInfo* eventInfo) const;
186 int32_t getEventEBID(const EventContext& context) const;
187
188 std::string findLocalFile (const std::string& fileName) const;
189
190 SG::ReadCondHandleKey<BunchCrossingCondData> m_bunchCrossingKey{this, "BunchCrossingKey", "BunchCrossingData", "Key BunchCrossing CDO" };
191
192 Gaudi::Property<uint32_t> m_runNumber{this, "RunNumber", 0, "Run we're processing (if data), needed at initialize to locate and read in extra configuration."};
193 Gaudi::Property<bool> m_errorOnMissingEBWeights{this, "ErrorOnMissingEBWeights", false, "If true, Throws error if EB weights are missing."};
194 Gaudi::Property<bool> m_enforceEBGRL{this, "EnforceEBGRL", true, "Each Enhanced Bias run has a 'good run list' style veto on some LB. If this flag is true, events in these LB get weight 0"};
195 Gaudi::Property<bool> m_useBunchCrossingData{this, "UseBunchCrossingData", true, "BunchCrossing data requires CONDBR2 access. Can be disabled here if this is a problem."};
196 Gaudi::Property<bool> m_isMC{this, "IsMC", false, "MC mode? If so we need a cross section and filter efficiency"};
197 Gaudi::Property<double> m_mcCrossSection{this, "MCCrossSection", 0.0, "If running over MC. The process cross section in nb (AMI gives thins in nb)"};
198 Gaudi::Property<double> m_mcFilterEfficiency{this, "MCFilterEfficiency", 1.0, "If running over MC. The process filter efficiency (0.0-1.0)"};
199 Gaudi::Property<double> m_mcKFactor{this, "MCKFactor", 1.0, "If running over MC. The process filter efficiency (0.0-1.0)"};
200 Gaudi::Property<bool> m_mcIgnoreGeneratorWeights{this, "MCIgnoreGeneratorWeights", false, "If running over MC. Flag to ignore the generator weight."};
201 Gaudi::Property<double> m_inelasticCrossSection{this, "InelasticCrossSection", 8e-26, "Inelastic cross section in units cm^2. Default 80 mb at 13 TeV."};
202 Gaudi::Property<std::string> m_weightsDirectory {this, "EBWeightsDirectory", "", "Path to directory with EB XML weights files, if empty they will be read from calibration area"};
203 Gaudi::Property<bool> m_doMultiSliceDiJet{this, "DoMultiSliceDiJet", false, "Enable the HS-softer-than-PU (HSTP) filter; reweight the Slices according to Jet/ETMiss procedure; recommended by PMG for di-jet slices."};
204 Gaudi::Property<double> m_targetLumi{this, "TargetLuminosity", 2e34, "Targer inst. luminosity, assuming full ring."};
205
206 double m_deadtime;
209 std::unordered_map<uint64_t, int32_t> m_eventNumberToIdMap;
210
211 mutable std::unordered_map<uint32_t, float> m_eventLivetime ATLAS_THREAD_SAFE;
212 mutable std::mutex m_mutex;
213 mutable Gaudi::Accumulators::AveragingCounter<double> m_lumiAverage ATLAS_THREAD_SAFE;
214 mutable Gaudi::Accumulators::AveragingCounter<double> m_muAverage ATLAS_THREAD_SAFE;
215
216 std::unordered_map<int32_t, double> m_idToWeightMap;
217 std::unordered_map<int32_t, uint8_t> m_idToUnbiasedMap;
218 std::unordered_map<uint32_t, uint32_t> m_eventsPerLB;
219 std::unordered_map<uint32_t, double> m_lumiPerLB;
220 std::unordered_map<uint32_t, uint8_t> m_goodLB;
221 std::unordered_map<uint32_t, double> m_deadtimePerLB;
222
223 std::vector<int32_t> m_bunches;
224
226};
227
228#endif //> !ENHANCEDBIASWEIGHTER_ENHANCEDBIASWEIGHTER_H
#define ASG_TOOL_CLASS2(CLASSNAME, INT1, INT2)
Replaces the BunchCrossing AlgTool used in run1/2.
Define macros for attributes used to control the static checker.
Gaudi::Property< bool > m_useBunchCrossingData
Gaudi::Property< std::string > m_weightsDirectory
static constexpr uint32_t FULL_RING
Number of bunches in a full ring.
virtual StatusCode getDistanceIntoTrain(const xAOD::EventInfo *eventInfo, uint32_t &distance, const EventContext &ctx) const override
std::vector< int32_t > m_bunches
Number of BCIDs in each bunch group.
ReadLumiBlock m_readLumiBlock
Cache lumi block lengths.
virtual double getEBWeight(const xAOD::EventInfo *eventInfo) const override
StatusCode loadWeights()
Read into memory from XML event weights for this EnhancedBias run.
virtual uint32_t getRunNumber() const override
virtual double getLBLength(const xAOD::EventInfo *eventInfo) const override
virtual uint32_t getPairedBunches() const override
virtual StatusCode initialize() override
Initialize is required by AsgTool base class.
virtual bool isUnbiasedEvent(const xAOD::EventInfo *eventInfo) const override
std::unordered_map< int32_t, uint8_t > m_idToUnbiasedMap
Map a weighting ID to a flag if this weight is from an unbiased (RD) trigger online.
std::unordered_map< uint32_t, float > m_eventLivetime ATLAS_THREAD_SAFE
Cache of per-event livetime as a function of LB [LB -> effective walltime per event].
Gaudi::Property< double > m_mcCrossSection
StatusCode trackAverages(const xAOD::EventInfo *eventInfo) const
Internal function to keep track of the mean instantaneous lumi & mean pileup of the EB/MC sample bein...
std::unordered_map< int32_t, double > m_idToWeightMap
Map a weighting ID to a Enhanced Bias event weight.
uint32_t m_pairedBunches
Online number of paired bunches.
EnhancedBiasWeighter(const std::string &name)
Gaudi::Property< double > m_mcKFactor
virtual double getDeadtime(const int lumiblock=-1) const override
Gaudi::Property< uint32_t > m_runNumber
int32_t getEventEBID(const xAOD::EventInfo *eventInfo) const
Gaudi::Property< bool > m_mcIgnoreGeneratorWeights
std::unordered_map< uint32_t, uint8_t > m_goodLB
Like a Good Run List flag for EnhancedBias runs.
StatusCode loadLumi()
Read into memory this EnhancedBias run's XML.
virtual double getBunchCrossingRate() const override
Gaudi::Property< bool > m_isMC
SG::ReadCondHandleKey< BunchCrossingCondData > m_bunchCrossingKey
Tool to get distance into bunch train.
virtual double getEBLiveTime(const xAOD::EventInfo *eventInfo) const override
std::unordered_map< uint64_t, int32_t > m_eventNumberToIdMap
Map event number to a weighting ID.
virtual StatusCode addBranches(const EventContext &ctx) const override
Decorate the AOD with EnhancedBias weighting quantities such that no CVMFS or DB access is required o...
Gaudi::Property< double > m_mcFilterEfficiency
std::unordered_map< uint32_t, double > m_deadtimePerLB
Map of average deadtime per LB.
virtual bool isMC() const override
static constexpr double LHC_FREQUENCY
virtual double getAverageLumi() const override
virtual double getAverageMu() const override
virtual const std::vector< int32_t > & getBunchGroups() const override
std::string findLocalFile(const std::string &fileName) const
virtual double getLBLumi(const xAOD::EventInfo *eventInfo) const override
Gaudi::Property< bool > m_doMultiSliceDiJet
virtual bool isGoodLB(const xAOD::EventInfo *eventInfo) const override
std::unordered_map< uint32_t, uint32_t > m_eventsPerLB
Map of how many EnhancedBias events were recorded per LB.
double m_deadtime
Online deadtime to correct for in rate prediction.
std::unordered_map< uint32_t, double > m_lumiPerLB
Map of instantaneous luminosity per LB.
Gaudi::Property< bool > m_enforceEBGRL
virtual std::unordered_map< std::string, ChainDetail > parsePrescaleXML(const std::string &prescaleXML) const override
Parse a presscale XML and return a ordered summary of its content To make most use of the XML parsing...
virtual StatusCode finalize() override
Gaudi::Property< bool > m_errorOnMissingEBWeights
Gaudi::Property< double > m_inelasticCrossSection
double m_mcModifiedCrossSection
Product of xsec, filter & kfactor.
Gaudi::Property< double > m_targetLumi
std::mutex m_mutex
Protection for above map.
Define interface of EnhancedBias weighting class.
Helper class to read in lumi block length info from COOL for a run.
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47
EventInfo_v1 EventInfo
Definition of the latest event info version.
Structure to encompass the data stored in a prescales XML generated by the RuleBook.
std::string m_lowerName
std::string m_comment
double m_prescaledEfficiencyErr
double m_eventsPassedWeighted