Belle II Software prerelease-11-00-00a
BGOverlayExecutorModule.h
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#pragma once
10
11#include <framework/core/Module.h>
12#include <framework/datastore/StoreArray.h>
13#include <framework/dataobjects/DigitBase.h>
14#include <string>
15#include <map>
16#include <vector>
17
18namespace Belle2 {
23
31
32 public:
33
38
43 virtual void initialize() override;
44
48 virtual void event() override;
49
50 private:
51
52 std::string m_PXDDigitsName;
54 std::string m_CDCHitsName;
55 std::string m_TOPDigitsName;
56 std::string m_ARICHDigitsName;
57 std::string m_KLMDigitsName;
58
59 std::string m_extensionName;
61
62 std::vector<std::string> m_components;
63
64 bool m_addPXD = false;
65 bool m_addSVD = false;
66 bool m_addCDC = false;
67 bool m_addTOP = false;
68 bool m_addARICH = false;
69 bool m_addKLM = false;
70
74 template <class Digit>
75 void registerDigits(const std::string& name)
76 {
77 StoreArray<Digit> digits(name);
78 digits.isOptional();
79 StoreArray<Digit> tmp; // just to get the default name
80 std::string nameBG = tmp.getName() + m_extensionName;
81 StoreArray<Digit> bgDigits(nameBG);
82 bgDigits.isOptional();
83 B2DEBUG(20, "optional input: " << digits.getName() << " " << bgDigits.getName());
84 }
85
90 template <class Digit>
91 void addBGDigits(const std::string& name)
92 {
93 // simulated digits
94 StoreArray<Digit> digits(name);
95 if (!digits.isValid()) {
96 B2DEBUG(20, digits.getName() << " are not valid");
97 return;
98 }
99
100 // background digits
101 StoreArray<Digit> tmp; // just to get the default name
102 std::string nameBG = tmp.getName() + m_extensionName;
103 StoreArray<Digit> bgDigits(nameBG);
104 if (!bgDigits.isValid()) {
105 B2DEBUG(20, bgDigits.getName() << " are not valid");
106 return;
107 }
108
109 // map unique channel ID with simulated digits
110 std::multimap<unsigned, Digit*> multimap;
111 for (auto& digit : digits) {
112 unsigned id = digit.getUniqueChannelID();
113 // multimap.emplace(id, &digit); /* Clang doesn't know this member! */
114 multimap.insert(std::pair<unsigned, Digit*>(id, &digit));
115 }
116
117 int size = digits.getEntries(); // for debug print
118
119 // add BG digits to simulated ones
120 typedef typename std::multimap<unsigned, Digit*>::iterator Iterator;
121 for (const auto& bgDigit : bgDigits) {
122 bool pileup = false;
123 unsigned id = bgDigit.getUniqueChannelID();
124 std::pair<Iterator, Iterator> range = multimap.equal_range(id);
125 for (Iterator it = range.first; it != range.second; ++it) {
126 auto* digit = it->second;
127 pileup = digit->addBGDigit(&bgDigit) == DigitBase::c_DontAppend;
128 if (pileup) break; // BG digit merged with simulated one
129 }
130 if (!pileup) digits.appendNew(bgDigit)->adjustAppendedBGDigit(); // BG digit not merged, therefore append and possibly modify
131 }
132
133 // debug printout
134 B2DEBUG(20, digits.getName() << ": before " << size
135 << " + " << bgDigits.getEntries() << "(BG)"
136 << ", after " << digits.getEntries()
137 << ", merged " << size + bgDigits.getEntries() - digits.getEntries());
138
139 }
140
141 };
142
144} // Belle2 namespace
145
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
void registerDigits(const std::string &name)
Register simulated and BG digits (both as optional input)
std::string m_extensionName
name added to default branch names
void addBGDigits(const std::string &name)
Add BG digits to simulated ones.
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_DontAppend
do not append BG digit to digits
Definition DigitBase.h:33
Module()
Constructor.
Definition Module.cc:30
const std::string & getName() const
Return name under which the object is saved in the DataStore.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
bool isValid() const
Check whether the array was registered.
Definition StoreArray.h:288
int getEntries() const
Get the number of objects in the array.
Definition StoreArray.h:216
map< unsigned, size_t >::const_iterator Iterator
Iterator for m_map.
Abstract base class for different kinds of events.