10#include <background/modules/BeamBkgHitRateMonitor/BeamBkgHitRateMonitorModule.h>
11#include <background/modules/BeamBkgHitRateMonitor/PXDHitRateCounter.h>
12#include <background/modules/BeamBkgHitRateMonitor/SVDHitRateCounter.h>
13#include <background/modules/BeamBkgHitRateMonitor/CDCHitRateCounter.h>
14#include <background/modules/BeamBkgHitRateMonitor/TOPHitRateCounter.h>
15#include <background/modules/BeamBkgHitRateMonitor/ARICHHitRateCounter.h>
16#include <background/modules/BeamBkgHitRateMonitor/ECLHitRateCounter.h>
17#include <background/modules/BeamBkgHitRateMonitor/KLMHitRateCounter.h>
20#include <framework/logging/Logger.h>
22#include <framework/io/RootIOUtilities.h>
23#include <framework/core/RandomNumbers.h>
24#include <framework/core/Environment.h>
25#include <framework/core/ModuleParam.templateDetails.h>
26#include <framework/database/Database.h>
27#include <framework/utilities/EnvironmentVariables.h>
29#include <boost/python.hpp>
30#include <boost/algorithm/string.hpp>
51 setDescription(
"A module for off-line monitoring of beam background hit rates.");
59 string(
"beamBkgHitRates.root"));
66 "trigger types for event selection (see TRGSummary.h for definitions). "
67 "Empty list means all trigger types.",
70 "if true, write to ntuple also empty time stamps",
false);
72 "TOP: time offset of hits (to be subtracted) [ns]", 25.0);
74 "TOP: time window in which to count hits [ns]", 100.0);
76 "SVDShaperDigits collection name",
string(
""));
78 "Energy cur on SVD Cluster charge in electrons", 15000.);
80 "If true, also SVD hot strips are counted as active",
false);
82 "If true, also SVD FADC-masked strips are counted as active",
false);
84 "Additional dictionary of "
85 "name->value pairs to be added to the file metadata to describe the data",
88 "CDC: lower edge of the time window for small cells [tdc count = ns]",
91 "CDC: upper edge of the time window for small cells [tdc count = ns]",
94 "CDC: lower edge of the time window for normal cells [tdc count = ns]",
97 "CDC: upper edge of the time window for normal cells [tdc count = ns]",
100 "CDC: flag to enable the bad wire treatment",
true);
102 "CDC: flag to enable the CDC background hit (crosstakl, noise) filter",
true);
104 "CDC: flag to enable to mark background flag on CDCHit (set 0x100 bit for CDCHit::m_status).",
false);
106 "Detectors to be included in the output tree, if empty, all detectors are included",
m_detectors);
112 if (monitor)
delete monitor;
128 std::string detectors;
129 for (
const auto& detector :
m_detectors) detectors += detector +
" ";
130 if (detectors.find(
"PXD") != string::npos or detectors.empty()) {
135 if (detectors.find(
"SVD") != string::npos or detectors.empty()) {
142 if (detectors.find(
"CDC") != string::npos or detectors.empty()) {
150 if (detectors.find(
"TOP") != string::npos or detectors.empty()) {
155 if (detectors.find(
"ARICH") != string::npos or detectors.empty()) {
160 if (detectors.find(
"ECL") != string::npos or detectors.empty()) {
165 if (detectors.find(
"KLM") != string::npos or detectors.empty()) {
173 B2FATAL(
"Cannot open output file '" <<
m_outputFileName <<
"' for writing");
180 m_persistent =
new TTree(
"persistent",
"persistent data");
189 monitor->initialize(
m_tree);
193 m_trgAll =
new TH1F(
"trgAll",
"trigger types of all events", 16, -0.5, 15.5);
194 m_trgAll->SetXTitle(
"type of trigger timing source");
195 m_trgSel =
new TH1F(
"trgSel",
"trigger types of selected events", 16, -0.5, 15.5);
196 m_trgSel->SetXTitle(
"type of trigger timing source");
239 monitor->accumulate(utime);
256 monitor->normalize(utime);
267 trigs +=
" trigger type " + std::to_string(trgType.first) +
": " +
268 std::to_string(trgType.second) +
" events\n";
271 <<
" events selected for beam background hit rate monitoring.\n"
305 if (trgType == type) {
381 std::string lfn =
m_file->GetName();
382 lfn = std::filesystem::absolute(lfn).string();
384 if (!format.empty()) {
385 auto format_filename = boost::python::import(
"B2Tools.format").attr(
"format_filename");
Class for monitoring beam background hit rates of ARICH.
Class for monitoring beam background hit rates of CDC.
Class for monitoring beam background hit rates of ECL.
Class for monitoring beam background hit rates of EKLM.
Class for monitoring beam background hit rates of PXD.
Class for monitoring beam background hit rates of SVD.
Class for monitoring beam background hit rates of TOP.
unsigned m_numEventsSelected
number of selected events in a run
unsigned long m_experimentLow
Lowest experiment number.
unsigned long m_experimentHigh
Highest experiment number.
std::vector< std::string > m_detectors
detectors to be included in the output tree
unsigned long m_eventLow
Lowest event number in lowest run.
int m_cdcTimeWindowLowerEdgeNormalCell
CDC: lower edge of the time window for normal cells [tdc count = ns].
unsigned m_allEventsSelected
number of selected events in all runs
TTree * m_tree
root tree pointer
std::string m_svdShaperDigitsName
SVD: name of the SVDShaperDigits collection.
unsigned m_utimeFirst
unix time of the first event in the run input stream
double m_topTimeWindow
TOP: time window in which to count hits [ns].
std::vector< Background::HitRateBase * > m_monitors
rate monitors
virtual void initialize() override
Initialize the Module.
unsigned long m_runLow
Lowest run number.
unsigned m_utimeMax
maximal unix time of events in the run
bool m_cdcEnableMarkBackgroundHit
CDC: flag to enable to mark background flag on CDCHit (set 0x100 bit for CDCHit::m_status).
virtual void event() override
Event processor.
TH1F * m_trgAll
trigger types of all events
bool m_cdcEnableBadWireTreatment
CDC: flag to enable the bad wire treatment.
virtual void endRun() override
End-of-run action.
BeamBkgHitRateMonitorModule()
Constructor.
StoreObjPtr< TRGSummary > m_trgSummary
trigger summary
virtual void terminate() override
Termination action.
FileMetaData m_outputFileMetaData
output file meta data branch
bool m_svdIgnoreHotStripsPayload
SVD: count hot strips as active.
unsigned long m_runHigh
Highest run number.
StoreObjPtr< EventMetaData > m_eventMetaData
event meta data object
int m_numEvents
number of events in the time stamp
std::vector< int > m_trgTypes
trigger types to be selected
bool isEventSelected()
event selection
int m_cdcTimeWindowUpperEdgeNormalCell
CDC: upper edge of the time window for normal cells [tdc count = ns].
virtual void beginRun() override
Called when entering a new run.
void setFileMetaData()
Set output FileMetaData object.
TFile * m_file
root file pointer
unsigned m_timeStamp
time stamp (unix time)
double m_svdThrCharge
SVD: energy cut on cluster charge.
bool m_writeEmptyTimeStamps
if true write to ntuple also empty time stamps
int m_time
time in seconds w.r.t the first event of the run
int m_cdcTimeWindowUpperEdgeSmallCell
CDC: upper edge of the time window for small cells [tdc count = ns].
void collectFileMetaData()
Collect file meta data: LFN's, low and high experiment, run and event numbers.
TH1F * m_trgSel
trigger types of selected events
int m_cdcTimeWindowLowerEdgeSmallCell
CDC: lower edge of the time window for small cells [tdc count = ns].
bool m_svdIgnoreMaskedStripsPayload
SVD: count FADC-masked strips as active.
bool m_cdcEnableBackgroundHitFilter
CDC: flag to enable the CDC background hit (crosstakl, noise) filter.
std::map< unsigned, int > m_eventCounts
number of events in time stamps
std::string m_treeName
output tree name
unsigned long m_eventHigh
Highest event number in highest run.
virtual ~BeamBkgHitRateMonitorModule()
Destructor.
std::map< std::string, std::string > m_additionalDataDescription
additional metadata description
std::map< TRGSummary::ETimingType, unsigned > m_trgTypesCount
trigger type counters
std::vector< std::string > m_parentLfns
Vector of parent file LFNs.
double m_topTimeOffset
TOP: time offset of hits [ns].
unsigned m_utimeMin
minimal unix time of events in the run
StoreObjPtr< FileMetaData > m_fileMetaData
file metadata
std::string m_outputFileName
output file name
TTree * m_persistent
root tree pointer (for FileMetaData)
unsigned int getNumberOfMCEvents() const
Number of generated events (from EventInfoSetter).
static Environment & Instance()
Static method to get a reference to the Environment instance.
void setDescription(const std::string &description)
Sets the description of the module.
static std::string getSeed()
Get the random number generator seed.
@ TTYP_DPHY
delayed physics events for background
@ TTYP_POIS
poisson random trigger
@ TTYP_NONE
reserved (not defined yet)
@ TTYP_RAND
random trigger events
Class to store variables with their name which were sent to the logging service.
static std::string get(const std::string &name, const std::string &fallback="")
Get the value of an environment variable or the given fallback value if the variable is not set.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
static Database & Instance()
Instance of a singleton Database.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
void setCreationData(FileMetaData &metadata)
Fill the creation info of a file meta data: site, user, data.
Abstract base class for different kinds of events.