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 TrackingUtilities::CDCWireHit, const TrackingUtilities::CDCTrack > CompositeProcessingSignalListener ProcessingSignalListener

Public Types

using IOTypes
 Types that should be served to apply on invocation.
 
using IOTypes
 Types that should be served to apply on invocation.
 
using IOVectors
 Vector types that should be served to apply on invocation.
 
using IOVectors
 Vector types that should be served to apply on invocation.
 

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< TrackingUtilities::CDCWireHit > &wireHits, const std::vector< TrackingUtilities::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
 Short hand for ToRangeImpl.
 
using ToVector
 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 = TrackingUtilities::Findlet<const TrackingUtilities::CDCWireHit, const TrackingUtilities::CDCTrack >
 Type of the base class.
 

Private Member Functions

void selectAsic (const std::vector< const TrackingUtilities::CDCWireHit * > &wireHits, const std::vector< TrackingUtilities::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< TrackingUtilities::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 debugging, 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 happened before.
 
bool m_terminated = false
 Flag to keep track whether termination happened 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 31 of file AsicBackgroundLibraryCreator.h.

Member Typedef Documentation

◆ IOTypes [1/2]

using IOTypes
inherited

Types that should be served to apply on invocation.

Definition at line 30 of file Findlet.h.

◆ IOTypes [2/2]

using IOTypes
inherited

Types that should be served to apply on invocation.

Definition at line 30 of file Findlet.h.

◆ IOVectors [1/2]

using IOVectors
inherited

Vector types that should be served to apply on invocation.

Definition at line 53 of file Findlet.h.

◆ IOVectors [2/2]

using IOVectors
inherited

Vector types that should be served to apply on invocation.

Definition at line 53 of file Findlet.h.

◆ Super

Type of the base class.

Definition at line 35 of file AsicBackgroundLibraryCreator.h.

◆ ToVector [1/2]

using ToVector
protectedinherited

Short hand for ToRangeImpl.

Definition at line 49 of file Findlet.h.

◆ ToVector [2/2]

using ToVector
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< TrackingUtilities::CDCWireHit > & wireHits,
const std::vector< TrackingUtilities::CDCTrack > & tracks )
final

Main algorithm marking hit as background.

Definition at line 114 of file AsicBackgroundLibraryCreator.cc.

115{
116
117 std::map< std::pair<int, int>, std::vector<const CDCWireHit*>> groupedByAsic;
118 for (const CDCWireHit& wireHit : wireHits) {
119 auto eWire = wireHit.getWireID().getEWire();
120 B2ASSERT("Channel map NOT found for the channel", m_map.count(eWire) > 0);
121 auto board = m_map[eWire].first;
122 auto channel = m_map[eWire].second;
123 auto asicID = std::pair<int, int>(board, channel / 8); // ASIC are groups of 8 channels
124 groupedByAsic[asicID].push_back(&wireHit);
125 };
126 for (auto& asicList : groupedByAsic) {
127 selectAsic(asicList.second, tracks);
128 };
129
130 return;
131}
void selectAsic(const std::vector< const TrackingUtilities::CDCWireHit * > &wireHits, const std::vector< TrackingUtilities::CDCTrack > &tracks)
Algorithm to select suitable ASIC for library creation.
std::map< int, std::pair< int, int > > m_map
map from ewire to board/channel ID

◆ beginEvent()

void beginEvent ( )
overridevirtualinherited

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

Reimplemented from ProcessingSignalListener.

Reimplemented in DATCONFPGAFindlet, SpacePointTagger< AResult, ACluster >, SpacePointTagger< Belle2::CKFToPXDResult, Belle2::PXDCluster >, SpacePointTagger< Belle2::CKFToSVDResult, Belle2::SVDCluster >, MCSymmetric< BaseAxialSegmentPairFilter >, MCSymmetric< BaseAxialSegmentPairFilter >, MCSymmetric< BaseFacetFilter >, MCSymmetric< BaseFacetFilter >, MCSymmetric< BaseFacetRelationFilter >, MCSymmetric< BaseFacetRelationFilter >, MCSymmetric< BaseSegmentPairFilter >, MCSymmetric< BaseSegmentPairFilter >, MCSymmetric< BaseSegmentPairRelationFilter >, MCSymmetric< BaseSegmentPairRelationFilter >, MCSymmetric< BaseSegmentRelationFilter >, MCSymmetric< BaseSegmentRelationFilter >, MCSymmetric< BaseSegmentTripleFilter >, MCSymmetric< BaseSegmentTripleFilter >, MCSymmetric< BaseSegmentTripleRelationFilter >, MCSymmetric< BaseSegmentTripleRelationFilter >, MCSymmetric< BaseTrackRelationFilter >, MCSymmetric< BaseTrackRelationFilter >, MonopoleStereoHitFinder, MonopoleStereoHitFinderQuadratic, SegmentCreatorMCTruth, SegmentFinderFacetAutomaton, SegmentTrackCombiner, SegmentTrackTruthVarSet, StereoHitFinder, StereoHitTruthVarSet, TrackFinderAutomaton, TrackFinderSegmentPairAutomaton, TrackFinderSegmentTripleAutomaton, TruthAxialSegmentPairVarSet, TruthSegmentVarSet, TruthTrackVarSet, WireHitMCMultiLoopBlocker, FindletStoreArrayInput< TWrappedFindlet >, SharingHitsMatcher< ACollectorItem, ACollectionItem >, SharingHitsMatcher< Belle2::TrackingUtilities::CDCTrack, Belle2::TrackingUtilities::CDCSegment2D >, StoreVectorSwapper< IOType, a_alwaysWrite >, StoreVectorSwapper< Belle2::TrackingUtilities::CDCFacet >, StoreVectorSwapper< Belle2::TrackingUtilities::CDCSegment2D >, StoreVectorSwapper< Belle2::TrackingUtilities::CDCSegmentPair >, StoreVectorSwapper< Belle2::TrackingUtilities::CDCSegmentTriple >, StoreVectorSwapper< Belle2::TrackingUtilities::CDCTrack >, StoreVectorSwapper< Belle2::TrackingUtilities::CDCWireHit, true >, RecoTrackStorer, ROIFinder, and SVDHoughTracking.

Definition at line 31 of file CompositeProcessingSignalListener.cc.

32{
35 psl->beginEvent();
36 }
37}
virtual void beginEvent()
Receive signal for the start of a new event.
ProcessingSignalListener()
Allow default construction.

◆ beginRun()

void beginRun ( )
finalvirtual

Reload channel map if needed.

Reimplemented from ProcessingSignalListener.

Definition at line 94 of file AsicBackgroundLibraryCreator.cc.

95{
97 // Load map from DB:
98 for (const auto& cm : (*m_channelMapFromDB)) {
99 const int isl = cm.getISuperLayer();
100 const int il = cm.getILayer();
101 const int iw = cm.getIWire();
102 const int iBoard = cm.getBoardID();
103 const int iCh = cm.getBoardChannel();
104 const WireID wireId(isl, il, iw);
105 m_map[wireId.getEWire()] = std::pair<int, int>(iBoard, iCh);
106 }
107}
std::unique_ptr< DBArray< CDCChannelMap > > m_channelMapFromDB
Channel map retrieved from DB.

◆ 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 CompositeProcessingSignalListener.

Definition at line 133 of file AsicBackgroundLibraryCreator.cc.

134{
135 Super::exposeParameters(moduleParamList, prefix);
136 moduleParamList->addParameter(prefixed(prefix, "minimalHitNumberASIC"),
138 "Required number of hits per ASIC for library creation",
140
141 moduleParamList->addParameter(prefixed(prefix, "AsicLibraryFileName"),
143 "ASIC library file name",
145
146 moduleParamList->addParameter(prefixed(prefix, "maximalDistanceSignal"),
148 "maximal distance in cm from track to signal hit",
150
151 moduleParamList->addParameter(prefixed(prefix, "minimalDistanceBackground"),
153 "minimal distance in cm from track to background hit",
155
156 moduleParamList->addParameter(prefixed(prefix, "useAxialHitsOnly"),
158 "use axial layers only",
160
161 moduleParamList->addParameter(prefixed(prefix, "writeExtraVars"),
163 "Write extra variables to the library",
165
166 moduleParamList->addParameter(prefixed(prefix, "minimalHitsOnTrack"),
168 "Required number of hits on track for library creation",
170
171 // set some defaults:
172 moduleParamList->getParameter<std::string>("inputTracks").setDefaultValue("CDCTrackVector");
173 moduleParamList->getParameter<std::string>("inputWireHits").setDefaultValue("CDCWireHitVector");
174}
double m_distance_signal_max
maximal distance from track to signal hit
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
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 TrackingUtilities::CDCWireHit, const TrackingUtilities::CDCTrack >.

Definition at line 109 of file AsicBackgroundLibraryCreator.cc.

110{
111 return "Finds suitable ASICs with a single hit attached to a track and uses them to create the library";
112}

◆ 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 60 of file AsicBackgroundLibraryCreator.cc.

61{
63 // database:
64 m_channelMapFromDB = std::make_unique<DBArray<CDCChannelMap>> ();
65
66 if ((*m_channelMapFromDB).isValid()) {
67 B2DEBUG(29, "CDC Channel map is valid");
68 } else {
69 B2FATAL("CDC Channel map is not valid");
70 }
71
72 // Library for writing
73
74 auto leavesCreator = [this](TTree & tree) {
76 tree.Branch("Dist", &m_dist_signal, "DistSig/f:DistBg/f");
77 tree.Branch("ADC", &m_adc_sig, "ADC_Sig/S:ADC_bg/S");
78 tree.Branch("Track", &m_n_hit_track, "tr_nhit/S");
79 }
80 tree.Branch("Board", &m_board, "board/b");
81 tree.Branch("Channel", &m_channel, "channel/b");
82 tree.Branch("Nhit", &m_n_hit, "nhit/b");
83 tree.Branch("Asic", &m_asic_info[0],
84 "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");
85 return;
86 };
87
88 m_recorder.reset(new Recorder(
89 leavesCreator
91 , "ASIC"));
92}
UChar_t m_n_hit
For debugging, store also number of channels with hits.
std::unique_ptr< TrackingUtilities::Recorder > m_recorder
Recorder for the root output.

◆ selectAsic()

void selectAsic ( const std::vector< const TrackingUtilities::CDCWireHit * > & wireHits,
const std::vector< TrackingUtilities::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 182 of file AsicBackgroundLibraryCreator.cc.

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

◆ terminate()

void terminate ( )
finalvirtual

Member Data Documentation

◆ m_adc_max_bg

Short_t m_adc_max_bg {0}
private

Max. ADC background.

Definition at line 123 of file AsicBackgroundLibraryCreator.h.

123{0};

◆ m_adc_sig

Short_t m_adc_sig {0}
private

ADC of the signal.

Definition at line 120 of file AsicBackgroundLibraryCreator.h.

120{0};

◆ m_asic_info

asicChannel m_asic_info[8]
private

all 8 channels

Definition at line 100 of file AsicBackgroundLibraryCreator.h.

◆ m_board

UChar_t m_board {0}
private

signal boardID

Definition at line 103 of file AsicBackgroundLibraryCreator.h.

103{0};

◆ m_channel

UChar_t m_channel {0}
private

signal channelID

Definition at line 106 of file AsicBackgroundLibraryCreator.h.

106{0};

◆ m_channelMapFromDB

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

Channel map retrieved from DB.

Definition at line 67 of file AsicBackgroundLibraryCreator.h.

◆ m_dist_bg

float m_dist_bg {0}
private

min. distance to non-linked hits

Definition at line 117 of file AsicBackgroundLibraryCreator.h.

117{0};

◆ m_dist_signal

float m_dist_signal {0}
private

Distance to signal hit.

Definition at line 114 of file AsicBackgroundLibraryCreator.h.

114{0};

◆ m_distance_background_min

double m_distance_background_min {0.5}
private

minimal distance from track to background hit

Definition at line 82 of file AsicBackgroundLibraryCreator.h.

82{0.5};

◆ m_distance_signal_max

double m_distance_signal_max {0.25}
private

maximal distance from track to signal hit

Definition at line 79 of file AsicBackgroundLibraryCreator.h.

79{0.25};

◆ m_initialized

bool m_initialized = false
privateinherited

Flag to keep track whether initialization happened 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 73 of file AsicBackgroundLibraryCreator.h.

73{"CDCAsicLibrary.root"};

◆ m_map

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

map from ewire to board/channel ID

Definition at line 70 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 76 of file AsicBackgroundLibraryCreator.h.

76{1};

◆ m_minimal_hits_on_track

size_t m_minimal_hits_on_track {40}
private

min. number of hits on the track

Definition at line 92 of file AsicBackgroundLibraryCreator.h.

92{40};

◆ m_n_hit

UChar_t m_n_hit {0}
private

For debugging, store also number of channels with hits.

Definition at line 109 of file AsicBackgroundLibraryCreator.h.

109{0};

◆ m_n_hit_track

UShort_t m_n_hit_track {0}
private

Number of hits on the track.

Definition at line 126 of file AsicBackgroundLibraryCreator.h.

126{0};

◆ m_recorder

std::unique_ptr<TrackingUtilities::Recorder> m_recorder
private

Recorder for the root output.

Definition at line 95 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 60 of file CompositeProcessingSignalListener.h.

◆ m_terminated

bool m_terminated = false
privateinherited

Flag to keep track whether termination happened 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 85 of file AsicBackgroundLibraryCreator.h.

85{false};

◆ m_write_extra_vars

bool m_write_extra_vars {false}
private

extra vars to the library

Definition at line 88 of file AsicBackgroundLibraryCreator.h.

88{false};

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