Belle II Software  release-08-01-10
BGOverlayExecutorModule.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 // Own header.
10 #include <background/modules/BGOverlayExecutor/BGOverlayExecutorModule.h>
11 
12 // framework - DataStore
13 #include <framework/datastore/StoreObjPtr.h>
14 
15 // framework aux
16 #include <framework/logging/Logger.h>
17 
18 // detector Digits, Clusters or waveforms
19 #include <pxd/dataobjects/PXDDigit.h>
20 #include <svd/dataobjects/SVDShaperDigit.h>
21 #include <cdc/dataobjects/CDCHit.h>
22 #include <top/dataobjects/TOPDigit.h>
23 #include <arich/dataobjects/ARICHDigit.h>
24 #include <klm/dataobjects/KLMDigit.h>
25 #include <framework/dataobjects/BackgroundInfo.h>
26 
27 using namespace std;
28 using namespace Belle2;
29 
30 //-----------------------------------------------------------------
31 // Register module
32 //-----------------------------------------------------------------
33 
34 REG_MODULE(BGOverlayExecutor);
35 
36 //-----------------------------------------------------------------
37 // Implementation
38 //-----------------------------------------------------------------
39 
40 BGOverlayExecutorModule::BGOverlayExecutorModule() : Module()
41 
42 {
43  // module description
44  setDescription("Overlay of measured background with simulated data");
46 
47  // Add parameters
48  addParam("bkgInfoName", m_BackgroundInfoInstanceName, "name of the BackgroundInfo StoreObjPtr", string(""));
49  addParam("PXDDigitsName", m_PXDDigitsName,
50  "name of PXD collection to overlay with BG", string(""));
51  addParam("SVDShaperDigitsName", m_SVDShaperDigitsName,
52  "name of SVD collection to overlay with BG", string(""));
53  addParam("CDCHitsName", m_CDCHitsName,
54  "name of CDC collection to overlay with BG", string(""));
55  addParam("TOPDigitsName", m_TOPDigitsName,
56  "name of TOP collection to overlay with BG", string(""));
57  addParam("ARICHDigitsName", m_ARICHDigitsName,
58  "name of ARICH collection to overlay with BG", string(""));
59  addParam("KLMDigitsName", m_KLMDigitsName,
60  "name of KLM collection to overlay with BG", string(""));
61  addParam("components", m_components,
62  "Detector components to be included in overlay (empty list means all)", m_components);
63 }
64 
65 
67 {
68  // get name of extension that is used in BGOverlayInput for BG collections
70  if (bkgInfo.isValid()) {
71  if (bkgInfo->getMethod() == BackgroundInfo::c_Overlay) {
72  m_extensionName = bkgInfo->getExtensionName();
73  } else {
74  B2ERROR("BGOverlayExecutor: no BGOverlayInput module in the path");
75  }
76  } else {
77  B2ERROR("BGOverlayExecutor: no BGOverlayInput module in the path");
78  }
79 
80  // registration in datastore (all as optional input - see template function)
81  registerDigits<PXDDigit>(m_PXDDigitsName);
82  registerDigits<SVDShaperDigit>(m_SVDShaperDigitsName);
83  registerDigits<CDCHit>(m_CDCHitsName);
84  registerDigits<TOPDigit>(m_TOPDigitsName);
85  registerDigits<ARICHDigit>(m_ARICHDigitsName);
86  registerDigits<KLMDigit>(m_KLMDigitsName);
87 
88  // toggle ON the components from the list
89  if (m_components.empty()) {
90  m_addPXD = true;
91  m_addSVD = true;
92  m_addCDC = true;
93  m_addTOP = true;
94  m_addARICH = true;
95  m_addKLM = true;
96  } else {
97  for (const auto& component : m_components) {
98  if (component == "PXD") m_addPXD = true;
99  else if (component == "SVD") m_addSVD = true;
100  else if (component == "CDC") m_addCDC = true;
101  else if (component == "TOP") m_addTOP = true;
102  else if (component == "ARICH") m_addARICH = true;
103  else if (component == "ECL") continue; // not relevant - overlay implemented in ECLDigitizer
104  else if (component == "KLM") m_addKLM = true;
105  else B2ERROR("Unknown detector component '" << component << "'");
106  }
107  }
108 
109 }
110 
111 
113 {
114  /* note: dataobject must inherit from DigitBase */
115 
116  if (m_addPXD) addBGDigits<PXDDigit>(m_PXDDigitsName);
117  if (m_addSVD) addBGDigits<SVDShaperDigit>(m_SVDShaperDigitsName);
118  if (m_addCDC) addBGDigits<CDCHit>(m_CDCHitsName);
119  if (m_addTOP) addBGDigits<TOPDigit>(m_TOPDigitsName);
120  if (m_addARICH) addBGDigits<ARICHDigit>(m_ARICHDigitsName);
121  //Compressed waveforms are loaded to the datastore by BGOverlayInputModule and unpacked and overlayed in ECLDigitizerModule
122  if (m_addKLM) addBGDigits<KLMDigit>(m_KLMDigitsName);
123 }
std::string m_CDCHitsName
name of CDC collection to overlay with BG
std::string m_KLMDigitsName
name of KLM collection to overlay with BG
bool m_addCDC
if true add BG digits of CDC
std::vector< std::string > m_components
detector components included in overlay
std::string m_BackgroundInfoInstanceName
name BackgroundInfo name
bool m_addKLM
if true add BG digits of KLM
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
bool m_addSVD
if true add BG digits of SVD
std::string m_ARICHDigitsName
name of ARICH collection to overlay with BG
bool m_addTOP
if true add BG digits of TOP
std::string m_extensionName
name added to default branch names
bool m_addPXD
if true add BG digits of PXD
std::string m_TOPDigitsName
name of TOP collection to overlay with BG
bool m_addARICH
if true add BG digits of ARICH
std::string m_PXDDigitsName
name of PXD collection to overlay with BG
std::string m_SVDShaperDigitsName
name of SVD collection to overlay with BG
@ c_Persistent
Object is available during entire execution time.
Definition: DataStore.h:60
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
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.