Belle II Software release-09-00-00
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 {
31
32 public:
33
38
43 {}
44
49 virtual void initialize() override;
50
54 virtual void event() override;
55
56 private:
57
58 std::string m_PXDDigitsName;
60 std::string m_CDCHitsName;
61 std::string m_TOPDigitsName;
62 std::string m_ARICHDigitsName;
63 std::string m_KLMDigitsName;
65 std::string m_extensionName;
68 std::vector<std::string> m_components;
70 bool m_addPXD = false;
71 bool m_addSVD = false;
72 bool m_addCDC = false;
73 bool m_addTOP = false;
74 bool m_addARICH = false;
75 bool m_addKLM = false;
80 template <class Digit>
81 void registerDigits(const std::string& name)
82 {
83 StoreArray<Digit> digits(name);
84 digits.isOptional();
85 StoreArray<Digit> tmp; // just to get the default name
86 std::string nameBG = tmp.getName() + m_extensionName;
87 StoreArray<Digit> bgDigits(nameBG);
88 bgDigits.isOptional();
89 B2DEBUG(20, "optional input: " << digits.getName() << " " << bgDigits.getName());
90 }
91
96 template <class Digit>
97 void addBGDigits(const std::string& name)
98 {
99 // simulated digits
100 StoreArray<Digit> digits(name);
101 if (!digits.isValid()) {
102 B2DEBUG(20, digits.getName() << " are not valid");
103 return;
104 }
105
106 // background digits
107 StoreArray<Digit> tmp; // just to get the default name
108 std::string nameBG = tmp.getName() + m_extensionName;
109 StoreArray<Digit> bgDigits(nameBG);
110 if (!bgDigits.isValid()) {
111 B2DEBUG(20, bgDigits.getName() << " are not valid");
112 return;
113 }
114
115 // map unique channel ID with simulated digits
116 std::multimap<unsigned, Digit*> multimap;
117 for (auto& digit : digits) {
118 unsigned id = digit.getUniqueChannelID();
119 // multimap.emplace(id, &digit); /* Clang doesn't know this member! */
120 multimap.insert(std::pair<unsigned, Digit*>(id, &digit));
121 }
122
123 int size = digits.getEntries(); // for debug print
124
125 // add BG digits to simulated ones
126 typedef typename std::multimap<unsigned, Digit*>::iterator Iterator;
127 for (const auto& bgDigit : bgDigits) {
128 bool pileup = false;
129 unsigned id = bgDigit.getUniqueChannelID();
130 std::pair<Iterator, Iterator> range = multimap.equal_range(id);
131 for (Iterator it = range.first; it != range.second; ++it) {
132 auto* digit = it->second;
133 pileup = digit->addBGDigit(&bgDigit) == DigitBase::c_DontAppend;
134 if (pileup) break; // BG digit merged with simulated one
135 }
136 if (!pileup) digits.appendNew(bgDigit)->adjustAppendedBGDigit(); // BG digit not merged, therefore append and possibly modify
137 }
138
139 // debug printout
140 int diff = size + bgDigits.getEntries() - digits.getEntries();
141 B2DEBUG(20, digits.getName() << ": before " << size
142 << " + " << bgDigits.getEntries() << "(BG)"
143 << ", after " << digits.getEntries()
144 << ", merged " << diff);
145
146 }
147
148 };
149
151} // Belle2 namespace
152
Overlay of measured background with simulated data (Digits or Clusters)
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
virtual ~BGOverlayExecutorModule()
Destructor.
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
Base class for Modules.
Definition: Module.h:72
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 wether 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
Iteratior for m_map.
Abstract base class for different kinds of events.