Belle II Software  release-08-01-10
SVDEventInfoSetterModule.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 <svd/modules/svdSimulation/SVDEventInfoSetterModule.h>
10 #include <root/TRandom.h>
11 #include <mdst/dataobjects/TRGSummary.h>
12 
13 using namespace std;
14 using namespace Belle2;
15 
16 //-----------------------------------------------------------------
17 // Register the Module
18 //-----------------------------------------------------------------
19 REG_MODULE(SVDEventInfoSetter);
20 
21 //-----------------------------------------------------------------
22 // Implementation
23 //-----------------------------------------------------------------
24 
25 SVDEventInfoSetterModule::SVDEventInfoSetterModule() : Module()
26 {
27  //Set module properties
29  "Sets the SVD event information. Use this "
30  "module to fill SVDEventInfo object which tells the digitizer "
31  "the conditions for creating ShaperDigits."
32  );
33 
35 
36  //Parameter definition for SVDModeByte, TriggerType and cross-talk
37  addParam("SVDEventInfo", m_svdEventInfoName, "SVDEventInfo name", string("SVDEventInfoSim"));
38  addParam("runType", m_runType, "Defines the run type: raw/transparent/zero-suppressed/z-s+hit time finding", int(2));
39  addParam("eventType", m_eventType, "Defines the event type: TTD event (global run)/standalone event (local run)", int(0));
40  addParam("daqMode", m_daqMode,
41  "Defines the DAQ mode: = 2 for the default 6-sample mode, = 1 for the 3-sample mode, = 3 for the 3-mixed-6 sample mode. ", int(2));
42  addParam("fixedTriggerBin", m_fixedTriggerBin,
43  "Trigger bin 0/1/2/3 - useful for timing studies. The default is random if SimClockState is not valid.", int(999));
44  addParam("triggerType", m_triggerType, "Defines the trigger type, default: CDC trigger", uint8_t(3));
45  addParam("crossTalk", m_xTalk, "Defines the cross-talk flag for the event", bool(false));
46  addParam("relativeShift", m_relativeShift, "Relative shift between 3- and 6-sample events, in units of APV clock / 4", int(0));
47  addParam("useDB", m_useDB, "default = False. If true reads the DAQMode from SVDGlobalConfigParameters", bool(false));
48  addParam("TRGSummaryName", m_objTrgSummaryName, "TRGSummary name", m_objTrgSummaryName);
49 
50  // default ModeByte settings: 10 0 10 000 (144)
51 }
52 
54 
56 {
57  if (m_useDB) {
58  if (!m_svdGlobalConfig.isValid()) {
59  B2WARNING("No valid SVDGlobalConfigParameters for the requested IoV, simulating a 6-sample event");
60  m_daqMode = 2; //6-sample event
61  m_relativeShift = 0; // not needed later in reconstruction
62  } else {
63  m_relativeShift = m_svdGlobalConfig->getRelativeTimeShift();
64  int nFrames = m_svdGlobalConfig->getNrFrames();
65  if (nFrames == 3) m_daqMode = 1;
66  else if (nFrames == 6) m_daqMode = 2;
67  else if (nFrames == 9) m_daqMode = 3;
68  else
69  B2ERROR("Invalid number of frames (" << nFrames << ") in SVDGlobalConfigParamters");
70  }
71  }
72 }
73 
75 {
76  //Register the EventInfo in the data store
78 
79  m_simClockState.isOptional();
80 
81 // TO BE ADDED(?): some functions than can check the validity of the given parameters
82 }
83 
85 {
86  if (m_fixedTriggerBin >= 0 && m_fixedTriggerBin <= 3) {
87  B2DEBUG(25, "using fixed triggerBin");
89  } else {
90  if (m_simClockState.isValid())
91  m_triggerBin = m_simClockState->getSVDTriggerBin();
92  else {
93  const int triggerBinsInAPVclock = 4;
94  m_triggerBin = gRandom->Integer(triggerBinsInAPVclock);
95  B2DEBUG(25, "no SimClockState -> random generation of trigger bin");
96  }
97  }
98 
99 
105 
106  B2DEBUG(25, " triggerBin = " << m_triggerBin);
107 
108  m_svdEventInfoPtr.create();
109  m_svdEventInfoPtr->setAPVClock(m_hwClock);
110  m_svdEventInfoPtr->setModeByte(m_SVDModeByte);
111  m_svdEventInfoPtr->setMatchModeByte(m_ModeByteMatch);
112  m_svdEventInfoPtr->setTriggerType(m_SVDTriggerType);
113  m_svdEventInfoPtr->setMatchTriggerType(m_TriggerTypeMatch);
114  m_svdEventInfoPtr->setCrossTalk(m_xTalk);
115  m_svdEventInfoPtr->setRelativeShift(m_relativeShift);
116 
117  int nAPVsamples = 6;
118 
119  if (m_daqMode == 1) nAPVsamples = 3;
120  else if (m_daqMode == 3) {
121 
123 
124  if (storeTRGSummary.isValid()) {
125  int trgQuality = storeTRGSummary->getTimQuality();
126 
127  if (trgQuality == TRGSummary::ETimingQuality::TTYQ_FINE or trgQuality == TRGSummary::ETimingQuality::TTYQ_SFIN)
128  nAPVsamples = 3;
129  } else B2DEBUG(25, "DAQMode = 3, but no valid TRGSummary! We simulate a 6-sample event");
130  }
131 
132  m_svdEventInfoPtr->setNSamples(nAPVsamples);
133 
134  if (nAPVsamples == 3)
135  B2DEBUG(25, " relativeShift = " << m_relativeShift);
136 
137 }
138 
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:72
Base class for Modules.
Definition: Module.h:72
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
bool m_xTalk
Cross-talk flag to be set.
StoreObjPtr< SVDEventInfo > m_svdEventInfoPtr
Output object.
virtual void initialize() override
Initializes the Module.
virtual void event() override
Stores the SVD event info into the DataStore.
uint8_t m_triggerType
Trigger type content to be set.
virtual void beginRun() override
Reads Detector Configuration from DB daqMode and relativeShift.
bool m_ModeByteMatch
SVDModeByte matching flag to be set.
DBObjPtr< HardwareClockSettings > m_hwClock
systems clock
std::string m_svdEventInfoName
Name of the SVDEventInfo object.
DBObjPtr< SVDGlobalConfigParameters > m_svdGlobalConfig
SVD Global Configuration payload.
int m_relativeShift
latency difference between the 3- and 6-sample acquired events
SVDTriggerType m_SVDTriggerType
SVDTriggerType object.
SVDModeByte m_SVDModeByte
SVDModeByte object.
bool m_TriggerTypeMatch
SVDTriggerType matching flag to be set.
virtual ~SVDEventInfoSetterModule()
Destructor.
std::string m_objTrgSummaryName
Name of the StoreObjectPrt TRGSummary.
bool m_useDB
if true reads the configuration from SVDGlobalConfigParameters payload
StoreObjPtr< SimClockState > m_simClockState
generated hardware clock state
void setTriggerBin(baseType triggerBin)
Set the triggerBin id.
Definition: SVDModeByte.h:169
void setDAQMode(baseType daqMode)
Set the daqMode id.
Definition: SVDModeByte.h:172
void setEventType(baseType eventType)
Set the eventType id.
Definition: SVDModeByte.h:175
void setRunType(baseType runType)
Set the runType id.
Definition: SVDModeByte.h:178
void setType(baseType type)
Set the unique type.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
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.