Belle II Software  release-06-00-14
TTDDQMModule.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 <rawdata/modules/TTDDQM/TTDDQMModule.h>
10 #include <TDirectory.h>
11 
12 using namespace std;
13 using namespace Belle2;
14 
15 //-----------------------------------------------------------------
16 // Register the Module
17 //-----------------------------------------------------------------
18 REG_MODULE(TTDDQM)
19 
20 //-----------------------------------------------------------------
21 // Implementation
22 //-----------------------------------------------------------------
23 
24 TTDDQMModule::TTDDQMModule() : HistoModule(), m_EventLevelTriggerTimeInfo()
25 {
26  //Set module properties
27  setDescription("Monitor TTD Trigger and Injection");
28  // his DQM module can be run offline or online
29  // if included in online DQM, binning should be reviewed (size!) and
30  // adapted to the binning of the corresponding sub detector (or GDL) histograms
31  // it may replace some of the histograms currently filled by sub-detectors
32  setPropertyFlags(c_ParallelProcessingCertified);
33  addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of the directory where histograms will be placed",
34  std::string("TTD"));
35 
36 }
37 
38 void TTDDQMModule::defineHisto()
39 {
40  TDirectory* oldDir = gDirectory;
41  if (m_histogramDirectoryName != "") {
42  oldDir->mkdir(m_histogramDirectoryName.c_str());// do not rely on return value, might be ZERO
43  oldDir->cd(m_histogramDirectoryName.c_str());//changing to the right directory
44  }
45 
46  hTrigAfterInjLER = new TH2I("hTTDTrigAfterInjLER",
47  "Triggers for LER veto tuning;Time since last injection in #mus;Time within beam cycle in #mus", 500, 0, 30000, 100, 0,
48  5120 / 508.);
49  hTrigAfterInjHER = new TH2I("hTTDTrigAfterInjHER",
50  "Triggers for HER veto tuning;Time since last injection in #mus;Time within beam cycle in #mus", 500, 0, 30000, 100, 0,
51  5120 / 508.);
52 
53  hTriggersDeltaT = new TH1I("hTTDTriggersDeltaT",
54  "#delta Trigger Time since previous trigger;#delta t in #mus;Triggers/Time (0.5 #mus bins)", 100000, 0, 50000);
55  hTriggersPerBunch = new TH1I("hTTDTriggerBunch", "Triggers per Bunch;Bunch(rel);Triggers per 4 Bunches)", 1280, 0, 1280 * 4);
56 
57  hBunchInjHER = new TH1I("hTTDBunchInjHER", "Last Injected Bunch HER;Bunch(rel);Counts per 4 Bunches", 1280, 0, 1280 * 4);
58  hBunchInjLER = new TH1I("hTTDBunchInjLER", "Last Injected Bunch LER;Bunch(rel);Counts per 4 Bunches", 1280, 0, 1280 * 4);
59 
60  hTrigBunchInjLER = new TH2I("hTTDTrigBunchInjLER",
61  "Correlation between triggered bunch and injected bunch in LER;Injected Bunch(rel);Triggered Bunch(rel)", 256, 0, 1280 * 4, 256, 0,
62  1280 * 4);
63  hTrigBunchInjHER = new TH2I("hTTDTrigBunchInjHer",
64  "Correlation between triggered bunch and injected bunch in HER;Injected Bunch(rel);Triggered Bunch(rel)", 256, 0, 1280 * 4, 256, 0,
65  1280 * 4);
66 
67  // cd back to root directory
68  oldDir->cd();
69 }
70 
71 void TTDDQMModule::initialize()
72 {
73  REG_HISTOGRAM
74  m_EventLevelTriggerTimeInfo.isRequired();
75 }
76 
77 void TTDDQMModule::beginRun()
78 {
79  // all ptr are set in defineHisto, thus no need for nullptr check
80  hTrigAfterInjLER->Reset();
81  hTrigAfterInjHER->Reset();
82  hTriggersDeltaT->Reset();
83  hTriggersPerBunch->Reset();
84  hBunchInjHER->Reset();
85  hBunchInjLER->Reset();
86  hTrigBunchInjLER->Reset();
87  hTrigBunchInjHER->Reset();
88 }
89 
90 void TTDDQMModule::event()
91 {
92 
93  if (m_EventLevelTriggerTimeInfo->isValid()) {
94  // TODO conversion of clock ticks to time not yet done in EventLevelTriggerTimeInfo
95  // all values are given in clock ticks of RF clock/4, thus one tick correspond to 4 bunches
96  // ~ 508 MHz RF -> 127 = 508/4 (clock ticks)
97  // 5120 possible bunch positions from RF and ring circumference -> 1280 = 5120/4 (in ticks)
98  // use an int and not the real fraction number to avoid binning effects for getting inexact time
99  // any bunch number is currently relative and not matching the SKB number (offset differs for LER, HER)
100  // time after injection is time after prekick signal, real injection happens ~90us afterwards (offset differs for LER, HER)
101  hTriggersDeltaT->Fill(m_EventLevelTriggerTimeInfo->getTimeSincePrevTrigger() / 127.);
102  int triggered_bunch_in_ticks = m_EventLevelTriggerTimeInfo->getBunchNumber();
103  hTriggersPerBunch->Fill(triggered_bunch_in_ticks * 4);
104 
105 
106  if (m_EventLevelTriggerTimeInfo->hasInjection()) {
107  auto time_since_inj_in_ticks = m_EventLevelTriggerTimeInfo->getTimeSinceLastInjection();// in clock ticks
108  // 127MHz clock ticks to us, inexact rounding, use integer to avoid binning effects
109  float time_since_inj_in_us = time_since_inj_in_ticks / 127.;
110  // swapped? 1280-1-injected_bunch_in_ticks?
111  int injected_bunch_in_ticks = ((time_since_inj_in_ticks - triggered_bunch_in_ticks + 1280) % 1280);
112 
113  if (m_EventLevelTriggerTimeInfo->isHER()) {
114  hTrigAfterInjHER->Fill(time_since_inj_in_us, time_since_inj_in_us - int(time_since_inj_in_us / (5120 / 508.)) * (5120 / 508.));
115  hBunchInjHER->Fill(injected_bunch_in_ticks * 4);
116  hTrigBunchInjHER->Fill(injected_bunch_in_ticks * 4, triggered_bunch_in_ticks * 4);
117  } else {
118  hTrigAfterInjLER->Fill(time_since_inj_in_us, time_since_inj_in_us - int(time_since_inj_in_us / (5120 / 508.)) * (5120 / 508.));
119  hBunchInjLER->Fill(injected_bunch_in_ticks * 4);
120  hTrigBunchInjLER->Fill(injected_bunch_in_ticks * 4, triggered_bunch_in_ticks * 4);
121  }
122  }
123  }
124 }
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
TTD Injection DQM module.
Definition: TTDDQMModule.h:33
#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.