Belle II Software  release-06-02-00
BeamBkgTagSetterModule.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 include
10 #include <background/modules/BeamBkgTagSetter/BeamBkgTagSetterModule.h>
11 
12 
13 // framework - DataStore
14 #include <framework/datastore/DataStore.h>
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/datastore/StoreObjPtr.h>
17 
18 // framework aux
19 #include <framework/logging/Logger.h>
20 
21 // MetaData
22 #include <framework/dataobjects/EventMetaData.h>
23 
24 using namespace std;
25 
26 namespace Belle2 {
32  //-----------------------------------------------------------------
33  // Register module
34  //-----------------------------------------------------------------
35 
36  REG_MODULE(BeamBkgTagSetter)
37 
38  //-----------------------------------------------------------------
39  // Implementation
40  //-----------------------------------------------------------------
41 
43  m_backgroundTag(BackgroundMetaData::bg_none), m_fileType(BackgroundMetaData::c_Usual)
44 
45  {
46  // set module description (e.g. insert text)
47  setDescription("Sets beam background tag variable in SimHits and "
48  "adds BackgroundMetaData branch in persistent tree; "
49  "returns true if at least one of the SimHit store arrays "
50  "has entries. Return value can be used to discard empty "
51  "events at output.");
52 
53  // parallel processing certificate
54  setPropertyFlags(c_ParallelProcessingCertified);
55 
56  // Add parameters
57  addParam("backgroundType", m_backgroundType,
58  "one of: " + m_bgTypes.getBGTypes());
59  addParam("realTime", m_realTime,
60  "equivalent time of superKEKB running in [ns] to obtain this sample");
61  addParam("specialFor", m_specialFor,
62  "tag ordinary file (default) or additional file ('ECL' or 'PXD')",
63  string(""));
64  addParam("Phase", m_phase,
65  "specify the Phase: 1 for Phase 1, 2 for Phase 2, 3 for Physics Run or Phase 3", 3);
66 
67  }
68 
69  BeamBkgTagSetterModule::~BeamBkgTagSetterModule()
70  {
71  }
72 
73  void BeamBkgTagSetterModule::initialize()
74  {
75  if (m_realTime <= 0) B2FATAL("invalid realTime: " << m_realTime);
76 
77  m_backgroundTag = m_bgTypes.getTag(m_backgroundType);
78  if (m_backgroundTag == 0) {
79  B2ERROR("Unknown beam background type: " << m_backgroundType << "\n"
80  "Possible are: " + m_bgTypes.getBGTypes());
81  m_backgroundTag = BackgroundMetaData::bg_other;
82  }
83 
84  if (m_specialFor != "") {
85  if (m_specialFor == "ECL") {m_fileType = BackgroundMetaData::c_ECL;}
86  else if (m_specialFor == "PXD") {m_fileType = BackgroundMetaData::c_PXD;}
87  else {B2ERROR("specialFor " << m_specialFor << "not supported");}
88  }
89 
90  // set BackgroundMetaData
91  StoreObjPtr<BackgroundMetaData> bkgMetaData("", DataStore::c_Persistent);
92  bkgMetaData.registerInDataStore();
93  if (!bkgMetaData.isValid())
94  bkgMetaData.create();
95  bkgMetaData->setBackgroundType(m_backgroundType);
96  bkgMetaData->setBackgroundTag(m_backgroundTag);
97  bkgMetaData->setRealTime(m_realTime);
98  bkgMetaData->setFileType(m_fileType);
99 
100  // registration of detector simHits
101  m_pxdSimHits.isOptional();
102  m_svdSimHits.isOptional();
103  m_cdcSimHits.isOptional();
104  m_topSimHits.isOptional();
105  m_arichSimHits.isOptional();
106  m_eclSimHits.isOptional();
107  m_eclHits.isOptional();
108  m_bklmSimHits.isOptional();
109  m_eklmSimHits.isOptional();
110 
111  // registration of beast simHits
112  m_diaSimHits.isOptional();
113  m_clw2SimHits.isOptional();
114  m_clw1SimHits.isOptional();
115  m_fngSimHits.isOptional();
116  m_plmSimHits.isOptional();
117  m_pinSimHits.isOptional();
118  m_he3SimHits.isOptional();
119  m_tpcSimHits.isOptional();
120  m_sciSimHits.isOptional();
121  m_bgoSimHits.isOptional();
122  m_csiSimHits.isOptional();
123  }
124 
125  void BeamBkgTagSetterModule::beginRun()
126  {
127  }
128 
129  void BeamBkgTagSetterModule::event()
130  {
131  int n = 0;
132  if (m_phase == 2 || m_phase == 3) {
133  n += setBackgroundTag(m_pxdSimHits);
134  n += setBackgroundTag(m_svdSimHits);
135  n += setBackgroundTag(m_cdcSimHits);
136  n += setBackgroundTag(m_topSimHits);
137  n += setBackgroundTag(m_arichSimHits);
138  n += setBackgroundTag(m_eclSimHits);
139  n += setBackgroundTag(m_eclHits);
140  n += setBackgroundTag(m_bklmSimHits);
141  n += setBackgroundTag(m_eklmSimHits);
142  }
143  // BEAST addition
144  if (m_phase == 1 || m_phase == 2) {
145  n += setBackgroundTag(m_diaSimHits);
146  if (m_phase == 1) {
147  n += setBackgroundTag(m_clw1SimHits);
148  n += setBackgroundTag(m_csiSimHits);
149  n += setBackgroundTag(m_bgoSimHits);
150  }
151  if (m_phase == 2) {
152  n += setBackgroundTag(m_clw2SimHits);
153  n += setBackgroundTag(m_fngSimHits);
154  n += setBackgroundTag(m_plmSimHits);
155  }
156  n += setBackgroundTag(m_pinSimHits);
157  n += setBackgroundTag(m_he3SimHits);
158  n += setBackgroundTag(m_tpcSimHits);
159  n += setBackgroundTag(m_sciSimHits);
160  }
161 
162  if (m_fileType == BackgroundMetaData::c_ECL) n = m_eclHits.getEntries();
163  if (m_fileType == BackgroundMetaData::c_PXD) n = m_pxdSimHits.getEntries();
164 
165  setReturnValue(n > 0);
166 
167  StoreObjPtr<EventMetaData> evtMetaData;
168  B2INFO("Exp " << evtMetaData->getExperiment() <<
169  " Run " << evtMetaData->getRun() <<
170  " Event " << evtMetaData->getEvent() <<
171  " number of SimHits = " << n);
172 
173  }
174 
175 
176  void BeamBkgTagSetterModule::endRun()
177  {
178  }
179 
180  void BeamBkgTagSetterModule::terminate()
181  {
182  }
183 
184 
186 } // end Belle2 namespace
187 
Metadata information about the beam background file.
A module that sets m_backgroundTag variable in SimHits (see BackgroundMetaData.h).
Base class for Modules.
Definition: Module.h:72
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:110
#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.