Belle II Software  release-05-02-19
TOPCalPulseGeneratorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 // Own include
12 #include <top/modules/TOPDoublePulseGenerator/TOPCalPulseGeneratorModule.h>
13 #include <top/geometry/TOPGeometryPar.h>
14 
15 // framework - DataStore
16 #include <framework/datastore/StoreArray.h>
17 
18 // framework aux
19 #include <framework/logging/Logger.h>
20 
21 // root
22 #include <TRandom.h>
23 
24 
25 using namespace std;
26 
27 namespace Belle2 {
33  using namespace TOP;
34 
35  //-----------------------------------------------------------------
36  // Register module
37  //-----------------------------------------------------------------
38 
39  REG_MODULE(TOPCalPulseGenerator)
40 
41  //-----------------------------------------------------------------
42  // Implementation
43  //-----------------------------------------------------------------
44 
46 
47  {
48  // set module description
49  setDescription("Realistic generator of calibration double pulses. "
50  "Needs TOPDigitizer to digitize");
51  setPropertyFlags(c_ParallelProcessingCertified);
52 
53  // Add parameters
54  addParam("moduleIDs", m_moduleIDs,
55  "list of slots for which to generate cal pulse, empty list means all slots.",
56  m_moduleIDs);
57  m_asicChannels.push_back(0);
58  addParam("asicChannels", m_asicChannels,
59  "ASIC calibration channels (0 - 7), empty list means all channels.",
60  m_asicChannels);
61  addParam("amplitude", m_amplitude,
62  "amplitude of cal pulse [ADC counts]", 700.0);
63 
64  }
65 
66  TOPCalPulseGeneratorModule::~TOPCalPulseGeneratorModule()
67  {
68  }
69 
70  void TOPCalPulseGeneratorModule::initialize()
71  {
72  // Output
73 
74  m_calPulses.registerInDataStore();
75 
76  // prepare vectors to loop on
77 
78  const auto* geo = TOPGeometryPar::Instance()->getGeometry();
79 
80  if (m_moduleIDs.empty()) {
81  for (const auto& module : geo->getModules()) {
82  m_moduleIDs.push_back(module.getModuleID());
83  }
84  } else {
85  for (auto moduleID : m_moduleIDs) {
86  if (!geo->isModuleIDValid(moduleID))
87  B2ERROR("Invalid module ID found in input list: " << moduleID);
88  }
89  }
90 
91  if (m_asicChannels.empty()) {
92  for (unsigned ch = 0; ch < 8; ch++) m_asicChannels.push_back(ch);
93  } else {
94  for (unsigned ch : m_asicChannels) {
95  if (ch > 7)
96  B2ERROR("Invalid ASIC channel found in input list: " << ch);
97  }
98  }
99 
100  }
101 
102 
103  void TOPCalPulseGeneratorModule::beginRun()
104  {
105  }
106 
107 
108  void TOPCalPulseGeneratorModule::event()
109  {
110 
111  const auto& chMapper = TOPGeometryPar::Instance()->getChannelMapper();
112  const auto& tdc = TOPGeometryPar::Instance()->getGeometry()->getNominalTDC();
113  double windowWidth = tdc.getSyncTimeBase() / 2;
114 
115  for (auto moduleID : m_moduleIDs) {
116  for (unsigned asic = 0; asic < 64; asic++) {
117  for (auto asicChannel : m_asicChannels) {
118  unsigned channel = asic * 8 + asicChannel;
119  auto pixelID = chMapper.getPixelID(channel);
120  double time = windowWidth + gRandom->Uniform(windowWidth);
121  m_calPulses.appendNew(moduleID, channel, pixelID, time, m_amplitude);
122  }
123  }
124  }
125 
126  }
127 
128 
129  void TOPCalPulseGeneratorModule::endRun()
130  {
131  }
132 
133  void TOPCalPulseGeneratorModule::terminate()
134  {
135  }
136 
137 
138 
140 } // end Belle2 namespace
141 
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::asicChannel
record to be used to store ASIC info
Definition: CDCCrossTalkClasses.h:23
Belle2::TOPCalPulseGeneratorModule
Generator of calibration pulses Output to TOPSimCalPulses.
Definition: TOPCalPulseGeneratorModule.h:38