Belle II Software development
DelayDQMModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include "dqm/modules/DelayDQMModule.h"
10#include "TMath.h"
11#include "TDirectory.h"
12
13#include <chrono>
14
15using namespace Belle2;
16
17//-----------------------------------------------------------------
18// Register the Module
19//-----------------------------------------------------------------
20REG_MODULE(DelayDQM);
21
22//-----------------------------------------------------------------
23// Implementation
24//-----------------------------------------------------------------
25
27{
28 //Set module properties
29 setDescription("Processing Delay DQM module");
30 setPropertyFlags(c_ParallelProcessingCertified); // specify this flag if you need parallel processing
31 addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of the directory where histograms will be placed",
32 std::string("DAQ"));
33 addParam("title", m_title, "Prefix for Title (ERECO, HLT, ...)", std::string("Processing "));
34 addParam("useMeta", m_useMeta, "Use time from EvtMetadata or FTSW", false);
35}
36
38{
39// function copied from root-talk
40
41 TAxis* axis = h->GetXaxis();
42 Int_t bins = axis->GetNbins();
43
44 Axis_t from = axis->GetXmin();
45 Axis_t to = axis->GetXmax();
46 Axis_t width = (to - from) / bins;
47 Axis_t* new_bins = new Axis_t[bins + 1];
48
49 for (Int_t i = 0; i <= bins; i++) {
50 new_bins[i] = TMath::Power(10, from + i * width);
51 }
52 axis->Set(bins, new_bins);
53 delete[] new_bins;
54}
55
56//------------------------------------------------------------------
57// Function to define histograms
58//-----------------------------------------------------------------
59
61{
62 // Create a separate histogram directory and cd into it.
63 TDirectory* oldDir = gDirectory;
64 if (m_histogramDirectoryName != "") {
65 oldDir->mkdir(m_histogramDirectoryName.c_str());// do not use return value with ->cd(), it is ZERO if dir already exists
66 oldDir->cd(m_histogramDirectoryName.c_str());
67 }
68 //----------------------------------------------------------------
69
70 m_DelayS = new TH1D("DelayS", (m_title + "Delay;time /s").c_str(), 600, 0, 600);
71 m_DelayMs = new TH1D("DelayMs", (m_title + "Delay;time /ms").c_str(), 200, 0, 2000);
72 m_DelayLog = new TH1D("DelayLog", (m_title + "Delay; time /s").c_str(), 200, -3, 6);
73 BinLogX(m_DelayLog); // set log binning, later Draw with SetLogX
74
75 // cd back to root directory
76 oldDir->cd();
77}
78
79
81{
82 // Required input
83 if (m_useMeta) {
84 m_eventMetaData.isRequired();
85 } else {
86 m_rawFTSW.isOptional(); // actually it would be Required(); but this prevents HLT/ERECO test from working
87 }
88
89 // Register histograms (calls back defineHisto)
90 REG_HISTOGRAM
91}
92
94{
95 // Just to make sure, reset all the histograms.
96 m_DelayMs->Reset();
97 m_DelayS->Reset();
98 m_DelayLog->Reset();
99}
100
101
103{
104 // Calculate the time difference between now and the trigger time
105 // This tells you how much delay we have summed up (it is NOT the processing time!)
107 using namespace std::chrono;
108 nanoseconds ns = duration_cast<nanoseconds> (system_clock::now().time_since_epoch());
109 nanoseconds event_time{};
110 if (m_useMeta) {
111 // We get the time from EventMetaData, which gets the time from TTD (FTSW)
112 // BUT, this time is inaccurate for longer runs, the difference is larger than the effect we
113 // monitor in the histograms!
114 event_time = static_cast<nanoseconds>(m_eventMetaData->getTime());
115 } else {
116 // get the trigger time from the NEW member function in TDD data
117 for (auto& it : m_rawFTSW) {
118 struct timeval tv;
119 it.GetPCTimeVal(0, &tv);
120 event_time = (static_cast<seconds>(tv.tv_sec)) + (static_cast<microseconds>(tv.tv_usec));
121 break;
122 }
123 }
124 auto deltaT = (duration_cast<milliseconds> (ns - event_time)).count();
125 m_DelayMs->Fill(deltaT);
126 m_DelayLog->Fill(1e-3 * deltaT);
127 m_DelayS->Fill(1e-3 * deltaT);
128}
129
void initialize() override final
Initializer.
void defineHisto() override final
Definition of the histograms.
StoreArray< RawFTSW > m_rawFTSW
Input for FTSW.
StoreObjPtr< EventMetaData > m_eventMetaData
Input ptr for EventMetaData.
bool m_useMeta
use time from Meta or FTSW
void event() override final
This method is called for each event.
void BinLogX(TH1 *h)
helper function to replace X axis by a log scaled axis
std::string m_title
Prefix for title (NOT histo name)
TH1D * m_DelayS
Delay between trigger and end of processing in s.
std::string m_histogramDirectoryName
Name of the histogram directory in ROOT file.
TH1D * m_DelayLog
Delay between trigger and end of processing log scale.
TH1D * m_DelayMs
Delay between trigger and end of processing in ms.
void beginRun() override final
Called when entering a new run.
DelayDQMModule()
Constructor.
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.