Belle II Software development
AsicBackgroundLibraryCreator Class Referenceabstract

Finds ASICs with single signal hit, records info to the library. More...

#include <AsicBackgroundLibraryCreator.h>

Inheritance diagram for AsicBackgroundLibraryCreator:
Findlet< const CDCWireHit, const CDCTrack > CompositeProcessingSignalListener ProcessingSignalListener

Public Types

using IOTypes = std::tuple< AIOTypes... >
 Types that should be served to apply on invokation.
 
using IOVectors = std::tuple< std::vector< AIOTypes >... >
 Vector types that should be served to apply on invokation.
 

Public Member Functions

 AsicBackgroundLibraryCreator ()=default
 Default constructor.
 
void initialize () final
 Access database here, open library for writing:
 
void beginRun () final
 Reload channel map if needed.
 
std::string getDescription () final
 Short description of the findlet.
 
void exposeParameters (ModuleParamList *moduleParamList, const std::string &prefix) final
 Expose the parameters to a module.
 
void apply (const std::vector< CDCWireHit > &wireHits, const std::vector< CDCTrack > &tracks) final
 Main algorithm marking hit as background.
 
void terminate () final
 write out the library
 
virtual void apply (ToVector< AIOTypes > &... ioVectors)=0
 Main function executing the algorithm.
 
void beginEvent () override
 Receive and dispatch signal for the start of a new event.
 
void endRun () override
 Receive and dispatch signal for the end of the run.
 

Protected Types

using ToVector = typename ToVectorImpl< T >::Type
 Short hand for ToRangeImpl.
 

Protected Member Functions

void addProcessingSignalListener (ProcessingSignalListener *psl)
 Register a processing signal listener to be notified.
 
int getNProcessingSignalListener ()
 Get the number of currently registered listeners.
 

Private Types

using Super = Findlet< const CDCWireHit, const CDCTrack >
 Type of the base class.
 

Private Member Functions

void selectAsic (const std::vector< const CDCWireHit * > &wireHits, const std::vector< CDCTrack > &tracks)
 Algorithm to select suitable ASIC for library creation.
 

Private Attributes

std::unique_ptr< DBArray< CDCChannelMap > > m_channelMapFromDB
 Channel map retrieved from DB.
 
std::map< int, std::pair< int, int > > m_map
 map from ewire to board/channel ID
 
std::string m_library_name {"CDCAsicLibrary.root"}
 output library name
 
size_t m_minimal_hit_number {1}
 min. number of hits in ASIC for background check
 
double m_distance_signal_max {0.25}
 maximal distance from track to signal hit
 
double m_distance_background_min {0.5}
 minimal distance from track to background hit
 
bool m_use_axial_hits_only {false}
 use axial layers only
 
bool m_write_extra_vars {false}
 extra vars to the library
 
size_t m_minimal_hits_on_track {40}
 min. number of hits on the track
 
std::unique_ptr< Recorderm_recorder
 Recorder for the root output.
 
asicChannel m_asic_info [8]
 all 8 channels
 
UChar_t m_board {0}
 signal boardID
 
UChar_t m_channel {0}
 signal channelID
 
UChar_t m_n_hit {0}
 For debuging, store also number of channels with hits.
 
float m_dist_signal {0}
 Distance to signal hit.
 
float m_dist_bg {0}
 min. distance to non-linked hits
 
Short_t m_adc_sig {0}
 ADC of the signal.
 
Short_t m_adc_max_bg {0}
 Max. ADC background.
 
UShort_t m_n_hit_track {0}
 Number of hits on the track.
 
std::vector< ProcessingSignalListener * > m_subordinaryProcessingSignalListeners
 References to subordinary signal processing listener contained in this findlet.
 
bool m_initialized = false
 Flag to keep track whether initialization happend before.
 
bool m_terminated = false
 Flag to keep track whether termination happend before.
 
std::string m_initializedAs
 Name of the type during initialisation.
 

Detailed Description

Finds ASICs with single signal hit, records info to the library.

Definition at line 29 of file AsicBackgroundLibraryCreator.h.

Member Typedef Documentation

◆ IOTypes

using IOTypes = std::tuple<AIOTypes...>
inherited

Types that should be served to apply on invokation.

Definition at line 30 of file Findlet.h.

◆ IOVectors

using IOVectors = std::tuple< std::vector<AIOTypes>... >
inherited

Vector types that should be served to apply on invokation.

Definition at line 53 of file Findlet.h.

◆ Super

using Super = Findlet<const CDCWireHit, const CDCTrack >
private

Type of the base class.

Definition at line 32 of file AsicBackgroundLibraryCreator.h.

◆ ToVector

using ToVector = typename ToVectorImpl<T>::Type
protectedinherited

Short hand for ToRangeImpl.

Definition at line 49 of file Findlet.h.

Member Function Documentation

◆ addProcessingSignalListener()

void addProcessingSignalListener ( ProcessingSignalListener psl)
protectedinherited

Register a processing signal listener to be notified.

Definition at line 55 of file CompositeProcessingSignalListener.cc.

56{
58}
std::vector< ProcessingSignalListener * > m_subordinaryProcessingSignalListeners
References to subordinary signal processing listener contained in this findlet.

◆ apply()

void apply ( const std::vector< CDCWireHit > &  wireHits,
const std::vector< CDCTrack > &  tracks 
)
final

Main algorithm marking hit as background.

Definition at line 110 of file AsicBackgroundLibraryCreator.cc.

111{
112
113 map< pair<int, int>, vector<const CDCWireHit*>> groupedByAsic;
114 for (const CDCWireHit& wireHit : wireHits) {
115 auto eWire = wireHit.getWireID().getEWire();
116 B2ASSERT("Channel map NOT found for the channel", m_map.count(eWire) > 0);
117 auto board = m_map[eWire].first;
118 auto channel = m_map[eWire].second;
119 auto asicID = pair<int, int>(board, channel / 8); // ASIC are groups of 8 channels
120 groupedByAsic[asicID].push_back(&wireHit);
121 };
122 for (auto& asicList : groupedByAsic) {
123 selectAsic(asicList.second, tracks);
124 };
125
126 return;
127}
std::map< int, std::pair< int, int > > m_map
map from ewire to board/channel ID
void selectAsic(const std::vector< const CDCWireHit * > &wireHits, const std::vector< CDCTrack > &tracks)
Algorithm to select suitable ASIC for library creation.
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55

◆ beginEvent()

void beginEvent ( )
overridevirtualinherited

Receive and dispatch signal for the start of a new event.

Reimplemented from ProcessingSignalListener.

Reimplemented in SpacePointTagger< Belle2::CKFToPXDResult, Belle2::PXDCluster >, SpacePointTagger< Belle2::CKFToSVDResult, Belle2::SVDCluster >, BaseEventTimeExtractor< RecoTrack * >, BaseEventTimeExtractor< TrackFindingCDC::CDCWireHit & >, SharingHitsMatcher< Belle2::TrackFindingCDC::CDCTrack, Belle2::TrackFindingCDC::CDCSegment2D >, MCSymmetric< BaseAxialSegmentPairFilter >, MCSymmetric< BaseFacetFilter >, MCSymmetric< BaseFacetRelationFilter >, MCSymmetric< BaseSegmentPairFilter >, MCSymmetric< BaseSegmentPairRelationFilter >, MCSymmetric< BaseSegmentRelationFilter >, MCSymmetric< BaseSegmentTripleFilter >, MCSymmetric< BaseSegmentTripleRelationFilter >, MCSymmetric< BaseTrackRelationFilter >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCFacet >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCWireHit, true >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegment2D >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCTrack >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegmentPair >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegmentTriple >, RecoTrackStorer, ROIFinder, and SVDHoughTracking.

Definition at line 31 of file CompositeProcessingSignalListener.cc.

32{
35 psl->beginEvent();
36 }
37}
Interface for an algorithm part that needs to receive the module processing signals.
virtual void beginEvent()
Receive signal for the start of a new event.

◆ beginRun()

void beginRun ( )
finalvirtual

Reload channel map if needed.

Reimplemented from ProcessingSignalListener.

Definition at line 90 of file AsicBackgroundLibraryCreator.cc.

91{
93 // Load map from DB:
94 for (const auto& cm : (*m_channelMapFromDB)) {
95 const int isl = cm.getISuperLayer();
96 const int il = cm.getILayer();
97 const int iw = cm.getIWire();
98 const int iBoard = cm.getBoardID();
99 const int iCh = cm.getBoardChannel();
100 const WireID wireId(isl, il, iw);
101 m_map[wireId.getEWire()] = std::pair<int, int>(iBoard, iCh);
102 }
103}
std::unique_ptr< DBArray< CDCChannelMap > > m_channelMapFromDB
Channel map retrieved from DB.
void beginRun() override
Receive and dispatch signal for the beginning of a new run.
Class to identify a wire inside the CDC.
Definition: WireID.h:34

◆ endRun()

void endRun ( )
overridevirtualinherited

Receive and dispatch signal for the end of the run.

Reimplemented from ProcessingSignalListener.

Definition at line 39 of file CompositeProcessingSignalListener.cc.

40{
42 psl->endRun();
43 }
45}
virtual void endRun()
Receive signal for the end of the run.

◆ exposeParameters()

void exposeParameters ( ModuleParamList moduleParamList,
const std::string &  prefix 
)
finalvirtual

Expose the parameters to a module.

Reimplemented from Findlet< const CDCWireHit, const CDCTrack >.

Definition at line 129 of file AsicBackgroundLibraryCreator.cc.

130{
131 Super::exposeParameters(moduleParamList, prefix);
132 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "minimalHitNumberASIC"),
134 "Required number of hits per ASIC for library creation",
136
137 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "AsicLibraryFileName"),
139 "ASIC library file name",
141
142 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "maximalDistanceSignal"),
144 "maximal distance in cm from track to signal hit",
146
147 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "minimalDistanceBackground"),
149 "minimal distance in cm from track to background hit",
151
152 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "useAxialHitsOnly"),
154 "use axial layers only",
156
157 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "writeExtraVars"),
159 "Write extra variables to the library",
161
162 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "minimalHitsOnTrack"),
164 "Required number of hits on track for library creation",
166
167 // set some defaults:
168 moduleParamList->getParameter<std::string>("inputTracks").setDefaultValue("CDCTrackVector");
169 moduleParamList->getParameter<std::string>("inputWireHits").setDefaultValue("CDCWireHitVector");
170}
double m_distance_signal_max
maximal distance from track to signal hit
size_t m_minimal_hits_on_track
min. number of hits on the track
double m_distance_background_min
minimal distance from track to background hit
size_t m_minimal_hit_number
min. number of hits in ASIC for background check
virtual void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix)
Forward prefixed parameters of this findlet to the module parameter list.
Definition: Findlet.h:69
ModuleParam< T > & getParameter(const std::string &name) const
Returns a reference to a parameter.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.

◆ getDescription()

std::string getDescription ( )
finalvirtual

Short description of the findlet.

Reimplemented from Findlet< const CDCWireHit, const CDCTrack >.

Definition at line 105 of file AsicBackgroundLibraryCreator.cc.

106{
107 return "Finds suitable ASICs with a single hit attached to a track and uses them to create the library";
108}

◆ getNProcessingSignalListener()

int getNProcessingSignalListener ( )
protectedinherited

Get the number of currently registered listeners.

Definition at line 60 of file CompositeProcessingSignalListener.cc.

61{
63}

◆ initialize()

void initialize ( )
finalvirtual

Access database here, open library for writing:

Reimplemented from ProcessingSignalListener.

Definition at line 56 of file AsicBackgroundLibraryCreator.cc.

57{
59 // database:
60 m_channelMapFromDB = std::make_unique<DBArray<CDCChannelMap>> ();
61
62 if ((*m_channelMapFromDB).isValid()) {
63 B2DEBUG(29, "CDC Channel map is valid");
64 } else {
65 B2FATAL("CDC Channel map is not valid");
66 }
67
68 // Library for writing
69
70 auto leavesCreator = [this](TTree & tree) {
72 tree.Branch("Dist", &m_dist_signal, "DistSig/f:DistBg/f");
73 tree.Branch("ADC", &m_adc_sig, "ADC_Sig/S:ADC_bg/S");
74 tree.Branch("Track", &m_n_hit_track, "tr_nhit/S");
75 }
76 tree.Branch("Board", &m_board, "board/b");
77 tree.Branch("Channel", &m_channel, "channel/b");
78 tree.Branch("Nhit", &m_n_hit, "nhit/b");
79 tree.Branch("Asic", &m_asic_info[0],
80 "TDC0/S:ADC0/S:TOT0/S:TDC1/S:ADC1/S:TOT1/S:TDC2/S:ADC2/S:TOT2/S:TDC3/S:ADC3/S:TOT3/S:TDC4/S:ADC4/S:TOT4/S:TDC5/S:ADC5/S:TOT5/S:TDC6/S:ADC6/S:TOT6/S:TDC7/S:ADC7/S:TOT7/S");
81 return;
82 };
83
84 m_recorder.reset(new Recorder(
85 leavesCreator
87 , "ASIC"));
88}
UChar_t m_n_hit
For debuging, store also number of channels with hits.
std::unique_ptr< Recorder > m_recorder
Recorder for the root output.
void initialize() override
Receive and dispatch signal before the start of the event processing.
Class to fill a tree from a set of variables.
Definition: Recorder.h:29

◆ selectAsic()

void selectAsic ( const std::vector< const CDCWireHit * > &  wireHits,
const std::vector< CDCTrack > &  tracks 
)
private

Algorithm to select suitable ASIC for library creation.

This is abnormal situation, detected for few runs, related to CDC unpacker. Hits are to be marked as background.

Definition at line 178 of file AsicBackgroundLibraryCreator.cc.

179{
180
181 if (wireHits.size() < m_minimal_hit_number) {
182 return;
183 };
184
185 if (wireHits.size() > 8) {
186 B2ERROR("Number of hits per asic should not exceed 8, observe too many hits." << LogVar("nHits", wireHits.size()));
188 return;
189 }
190
191
192 // count taken non-background hits:
193 int count = 0;
194 const CDCWireHit* signal = nullptr;
195 for (auto& hit : wireHits) {
196 if (!(*hit)->hasBackgroundFlag() && (*hit)->hasTakenFlag()) {
197 count += 1;
198 signal = hit;
199 }
200 }
201
202 // require one and only one taken hit
203 if (count != 1) {
204 return;
205 }
206
207
208 // check if only axial hits are used:
209
210 if ((!signal->isAxial()) && m_use_axial_hits_only) {
211 return;
212 }
213
214 // find the track to which this hit belongs
215 const CDCTrack* signalTrack = nullptr;
216 for (auto& track : tracks) {
217 for (auto& hit : track) {
218 if (&hit.getWireHit() == signal) {
219 signalTrack = &track;
220 break;
221 }
222 }
223 if (signalTrack != nullptr) {
224 break;
225 }
226 }
227
228 if (signalTrack == nullptr) {
229 B2DEBUG(29, "AsicBackgroundLibraryCreator::No track found for the signal hit");
230 return;
231 }
232
233 m_n_hit_track = signalTrack->size();
234
236
237 // check the distance from the track to each signal hit
238 const auto& trajectory = signalTrack->getStartTrajectory3D();
239
240 m_dist_bg = 1000.;
241
242 for (auto& hit : wireHits) {
243
244 const float dist = getDist2D(trajectory, hit);
245
246
247 if (hit == signal) {
248 m_dist_signal = dist;
249 if (dist > m_distance_signal_max) return;
250 } else {
251 m_dist_bg = min(m_dist_bg, dist);
252 if (dist < m_distance_background_min) return;
253 }
254 }
255
256
257 // Ok, passes all cuts !
258
259 // reset the library entries
260 for (auto& channel : m_asic_info) {
261 channel.TDC = -1;
262 channel.ADC = -1;
263 channel.TOT = -1;
264 }
265
266 // add to the library
267
268 m_n_hit = wireHits.size();
269
270 m_adc_max_bg = 0;
271 for (auto& hit : wireHits) {
272 auto eWire = hit->getWireID().getEWire();
273 auto channel = m_map[eWire].second;
274 auto asicCH = channel % 8;
275 m_asic_info[asicCH].ADC = hit->getHit()->getADCCount();
276 m_asic_info[asicCH].TDC = hit->getHit()->getTDCCount();
277 m_asic_info[asicCH].TOT = hit->getHit()->getTOT();
278
279 if (hit != signal) {
280 m_adc_max_bg = max(m_adc_max_bg, m_asic_info[asicCH].ADC);
281 }
282 }
283 // also signal hit info
284 auto eWire = signal->getWireID().getEWire();
285 m_channel = m_map[eWire].second;
286 m_board = m_map[eWire].first;
287 m_adc_sig = signal->getHit()->getADCCount();
288
289 // make sure that ADC of the signal is >= than ADC of the background:
290 if (m_adc_sig < m_adc_max_bg) return;
291
292 // write out
293 m_recorder->capture();
294}
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:41
Class to store variables with their name which were sent to the logging service.
Short_t TOT
Time over threshold.

◆ terminate()

void terminate ( )
finalvirtual

write out the library

Reimplemented from ProcessingSignalListener.

Definition at line 172 of file AsicBackgroundLibraryCreator.cc.

173{
174 m_recorder->write();
176}
void terminate() override
Receive and dispatch Signal for termination of the event processing.

Member Data Documentation

◆ m_adc_max_bg

Short_t m_adc_max_bg {0}
private

Max. ADC background.

Definition at line 118 of file AsicBackgroundLibraryCreator.h.

◆ m_adc_sig

Short_t m_adc_sig {0}
private

ADC of the signal.

Definition at line 115 of file AsicBackgroundLibraryCreator.h.

◆ m_asic_info

asicChannel m_asic_info[8]
private

all 8 channels

Definition at line 95 of file AsicBackgroundLibraryCreator.h.

◆ m_board

UChar_t m_board {0}
private

signal boardID

Definition at line 98 of file AsicBackgroundLibraryCreator.h.

◆ m_channel

UChar_t m_channel {0}
private

signal channelID

Definition at line 101 of file AsicBackgroundLibraryCreator.h.

◆ m_channelMapFromDB

std::unique_ptr<DBArray<CDCChannelMap> > m_channelMapFromDB
private

Channel map retrieved from DB.

Definition at line 62 of file AsicBackgroundLibraryCreator.h.

◆ m_dist_bg

float m_dist_bg {0}
private

min. distance to non-linked hits

Definition at line 112 of file AsicBackgroundLibraryCreator.h.

◆ m_dist_signal

float m_dist_signal {0}
private

Distance to signal hit.

Definition at line 109 of file AsicBackgroundLibraryCreator.h.

◆ m_distance_background_min

double m_distance_background_min {0.5}
private

minimal distance from track to background hit

Definition at line 77 of file AsicBackgroundLibraryCreator.h.

◆ m_distance_signal_max

double m_distance_signal_max {0.25}
private

maximal distance from track to signal hit

Definition at line 74 of file AsicBackgroundLibraryCreator.h.

◆ m_initialized

bool m_initialized = false
privateinherited

Flag to keep track whether initialization happend before.

Definition at line 52 of file ProcessingSignalListener.h.

◆ m_initializedAs

std::string m_initializedAs
privateinherited

Name of the type during initialisation.

Definition at line 58 of file ProcessingSignalListener.h.

◆ m_library_name

std::string m_library_name {"CDCAsicLibrary.root"}
private

output library name

Definition at line 68 of file AsicBackgroundLibraryCreator.h.

◆ m_map

std::map<int, std::pair<int, int> > m_map
private

map from ewire to board/channel ID

Definition at line 65 of file AsicBackgroundLibraryCreator.h.

◆ m_minimal_hit_number

size_t m_minimal_hit_number {1}
private

min. number of hits in ASIC for background check

Definition at line 71 of file AsicBackgroundLibraryCreator.h.

◆ m_minimal_hits_on_track

size_t m_minimal_hits_on_track {40}
private

min. number of hits on the track

Definition at line 87 of file AsicBackgroundLibraryCreator.h.

◆ m_n_hit

UChar_t m_n_hit {0}
private

For debuging, store also number of channels with hits.

Definition at line 104 of file AsicBackgroundLibraryCreator.h.

◆ m_n_hit_track

UShort_t m_n_hit_track {0}
private

Number of hits on the track.

Definition at line 121 of file AsicBackgroundLibraryCreator.h.

◆ m_recorder

std::unique_ptr<Recorder> m_recorder
private

Recorder for the root output.

Definition at line 90 of file AsicBackgroundLibraryCreator.h.

◆ m_subordinaryProcessingSignalListeners

std::vector<ProcessingSignalListener*> m_subordinaryProcessingSignalListeners
privateinherited

References to subordinary signal processing listener contained in this findlet.

Definition at line 52 of file CompositeProcessingSignalListener.h.

◆ m_terminated

bool m_terminated = false
privateinherited

Flag to keep track whether termination happend before.

Definition at line 55 of file ProcessingSignalListener.h.

◆ m_use_axial_hits_only

bool m_use_axial_hits_only {false}
private

use axial layers only

Definition at line 80 of file AsicBackgroundLibraryCreator.h.

◆ m_write_extra_vars

bool m_write_extra_vars {false}
private

extra vars to the library

Definition at line 83 of file AsicBackgroundLibraryCreator.h.


The documentation for this class was generated from the following files: