Belle II Software  release-08-01-10
NeuroTrigger Class Reference

Class to represent the CDC Neurotrigger. More...

#include <NeuroTrigger.h>

Collaboration diagram for NeuroTrigger:

Classes

struct  Parameters
 Struct to keep neurotrigger parameters. More...
 

Public Member Functions

 NeuroTrigger ()
 Default constructor.
 
virtual ~NeuroTrigger ()
 Default destructor.
 
void initialize (const Parameters &p)
 Set parameters and get some network independent parameters.
 
void initialize (const NeuroTriggerParameters &p)
 
std::vector< unsigned > getRangeIndices (const NeuroTriggerParameters &p, unsigned isector)
 Get indices for sector ranges in parameter lists.
 
std::vector< unsigned > getRangeIndices (const Parameters &p, unsigned isector)
 
void save (const std::string &filename, const std::string &arrayname="MLPs")
 Save MLPs to file. More...
 
bool loadIDHist (const std::string &filename)
 function to load idhist from file
 
bool load (const std::string &filename, const std::string &arrayname="MLPs")
 Load MLPs from file. More...
 
void setConstants ()
 Loads parameters from the geometry and precalculates some constants that will be needed.
 
void setPrecision (const std::vector< unsigned > &precision)
 set fixed point precision
 
void initializeCollections (std::string hitCollectionName, std::string eventTimeName, const std::string &et_option)
 set the hit collection and event time to required and store the hit collection name
 
void initializeCollections (std::string hitCollectionName)
 
CDCTriggerMLPoperator[] (unsigned index)
 return reference to a neural network
 
const CDCTriggerMLPoperator[] (unsigned index) const
 return const reference to a neural network
 
unsigned nSectors () const
 return number of neural networks
 
void addMLP (const CDCTriggerMLP &newMLP)
 add an MLP to the list of networks
 
std::vector< int > selectMLPs (float phi0, float invpt, float theta)
 Select all matching expert MLPs based on the given track parameters. More...
 
std::vector< int > selectMLPsTrain (float phi0, float invpt, float theta)
 Select all matching expert MLPs based on the given track parameters. More...
 
int selectMLPbyPattern (std::vector< int > &MLPs, unsigned long pattern, const bool neurotrackinputmode)
 Select one MLP from a list of sector indices. More...
 
void updateTrack (const CDCTriggerTrack &track)
 Calculate 2D phi position and arclength for the given track and store them.
 
void updateTrackFix (const CDCTriggerTrack &track)
 Calculate 2D phi position and arclength for the given track and store them.
 
double getRelId (const CDCTriggerSegmentHit &hit)
 Calculate phi position of a hit relative to 2D track (scaled to number of wires).
 
int getLowestTime (unsigned isector, RelationVector< CDCTriggerSegmentHit > Hits, bool onlyAxials)
 helper function to get the fastest priority time of given ts array
 
void getEventTime (unsigned isector, const CDCTriggerTrack &track, std::string et_option, const bool)
 Read out the event time and store it. More...
 
void getEventTime (unsigned isector, const CDCTriggerTrack &track)
 DEPRECATED!! Read out the event time and store it. More...
 
std::string get_et_option ()
 Return value of m_et_option.
 
unsigned long getInputPattern (unsigned isector, const CDCTriggerTrack &track, const bool neurotrackinputmode)
 Calculate input pattern for MLP. More...
 
unsigned long getCompleteHitPattern (unsigned isector, const CDCTriggerTrack &track, const bool neurotrackinputmode)
 Get complete hit pattern of neurotrack. More...
 
unsigned long getPureDriftThreshold (unsigned isector, const CDCTriggerTrack &track, const bool neurotrackinputmode)
 Get the drift threshold bits, where the time of the TS was outside of the accepted time window and thus shifted to the allowed maximum within the borders. More...
 
std::vector< unsigned > selectHitsHWSim (unsigned isector, const CDCTriggerTrack &track)
 Select hits for each super layer from the ones related to input track. More...
 
std::vector< unsigned > selectHits (unsigned isector, const CDCTriggerTrack &track, bool returnAllRelevant=false)
 Select best hits for each super layer. More...
 
std::vector< float > getInputVector (unsigned isector, const std::vector< unsigned > &hitIds)
 Calculate input values for MLP. More...
 
std::vector< float > runMLP (unsigned isector, const std::vector< float > &input)
 Run an expert MLP. More...
 
std::vector< float > runMLPFix (unsigned isector, std::vector< float > input)
 Run an expert MLP with fixed point arithmetic.
 

Private Attributes

std::vector< CDCTriggerMLPm_MLPs = {}
 List of networks.
 
double m_radius [9][2] = {}
 Radius of the CDC layers with priority wires (2 per super layer)
 
unsigned m_TSoffset [10] = {}
 Number of track segments up to super layer.
 
double m_idRef [9][2] = {}
 2D phi position of current track scaled to number of wires
 
double m_alpha [9][2] = {}
 2D crossing angle of current track
 
int m_T0 = 0
 Event time of current event / track.
 
bool m_hasT0 = false
 Flag to show if stored event time is valid.
 
std::vector< unsigned > m_precision
 Fixed point precision in bit after radix point. More...
 
StoreArray< CDCTriggerSegmentHitm_segmentHits
 StoreArray containing the input track segment hits.
 
StoreObjPtr< BinnedEventT0m_eventTime
 StoreObjPtr containing the event time.
 
std::string m_hitCollectionName
 Name of the StoreArray containing the input track segment hits.
 
DBObjPtr< CDCTriggerNeuroConfigm_cdctriggerneuroconfig
 get NNT payload from database.
 

Detailed Description

Class to represent the CDC Neurotrigger.

The Neurotrigger consists of one or several Multi Layer Perceptrons. The input values are calculated from track segment hits and a 2D track estimate. The output is a scaled estimate of the z-vertex of the track. In case of several MLPs, each is an expert for a different track parameter region.

See also
Neurotrigger Modules:
NeuroTriggerTrainerModule for preparing training data and training,
NeuroTriggerModule for loading trained networks and using them.

Definition at line 40 of file NeuroTrigger.h.

Member Function Documentation

◆ getCompleteHitPattern()

unsigned long getCompleteHitPattern ( unsigned  isector,
const CDCTriggerTrack track,
const bool  neurotrackinputmode 
)

Get complete hit pattern of neurotrack.

This does the same as the getInputPattern function, but also shows the axial hit bits. This function was made for the simulation of the hardware debug information "TSVector".

Definition at line 679 of file NeuroTrigger.cc.

680 {
681  const CDCTriggerMLP& expert = m_MLPs[isector];
682  unsigned long chitPattern = 0;
683  vector<unsigned> nHits;
684  nHits.assign(9, 0);
685  // loop over axial hits related to input track
687  track.getRelationsTo<CDCTriggerSegmentHit>(m_hitCollectionName);
688  for (unsigned ihit = 0; ihit < axialHits.size(); ++ ihit) {
689  // skip hits with negative relation weight (not selected in finder)
690  if (axialHits.weight(ihit) < 0) {
691  continue;
692  }
693  unsigned short iSL = axialHits[ihit]->getISuperLayer();
694  // // skip stereo hits (should not be related to track, but check anyway)
695  if ((!neurotrackinputmode) && (iSL % 2 == 1)) continue;
696  double relId = getRelId(*axialHits[ihit]);
697  if (expert.isRelevant(relId, iSL)) {
698  if (nHits[iSL] < expert.getMaxHitsPerSL()) {
699  chitPattern |= 1 << (iSL + 9 * nHits[iSL]);
700  ++nHits[iSL];
701  }
702  }
703  }
704  if (!neurotrackinputmode) {
705  // loop over stereo hits
706  for (int ihit = 0; ihit < m_segmentHits.getEntries(); ++ ihit) {
707  unsigned short iSL = m_segmentHits[ihit]->getISuperLayer();
708  // skip axial hits
709  if (iSL % 2 == 0) continue;
710  // get priority time
711  double relId = getRelId(*m_segmentHits[ihit]);
712  if (expert.isRelevant(relId, iSL)) {
713  if (nHits[iSL] < expert.getMaxHitsPerSL()) {
714  chitPattern |= 1 << (iSL + 9 * nHits[iSL]);
715  ++nHits[iSL];
716  }
717  }
718  }
719  }
720  return chitPattern;
721 }
Class to keep all parameters of an expert MLP for the neuro trigger.
Definition: CDCTriggerMLP.h:20
Combination of several CDCHits to a track segment hit for the trigger.
std::vector< CDCTriggerMLP > m_MLPs
List of networks.
Definition: NeuroTrigger.h:294
double getRelId(const CDCTriggerSegmentHit &hit)
Calculate phi position of a hit relative to 2D track (scaled to number of wires).
StoreArray< CDCTriggerSegmentHit > m_segmentHits
StoreArray containing the input track segment hits.
Definition: NeuroTrigger.h:317
std::string m_hitCollectionName
Name of the StoreArray containing the input track segment hits.
Definition: NeuroTrigger.h:321
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
float weight(int index) const
Get weight with index.
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216

◆ getEventTime() [1/2]

void getEventTime ( unsigned  isector,
const CDCTriggerTrack track 
)

DEPRECATED!! Read out the event time and store it.

If there is no valid event time, it can be determined from the shortest priority time of all hit candidates, if the option is enabled for the given sector.

◆ getEventTime() [2/2]

void getEventTime ( unsigned  isector,
const CDCTriggerTrack track,
std::string  et_option,
const bool  neuroinputmode = false 
)

Read out the event time and store it.

It can be given different options in the et_option ("EventTime option") parameter. The different options are: "etf_only" : only ETF info is used, otherwise an error is thrown. "fastestpriority" : event time is estimated by fastest priority time in selected track segments. if something fails, it is set to 0. "zero" : the event time is set to 0. "etf_or_fastestpriority" : the event time is obtained by the ETF, if not possible, the flag "fastestppriority" is used. "etf_or_zero" : the event time is obtained by the ETF, if

       m_T0 = 9999;

find shortest time of related and relevant axial hits RelationVector<CDCTriggerSegmentHit> Hits = track.getRelationsTo<CDCTriggerSegmentHit>(m_hitCollectionName); m_T0 = getLowestTime(isector, Hits, false); if (m_T0 < 9999) { m_hasT0 = true; } else { m_T0 = 0; m_hasT0 = false; }

  m_T0 = 9999;

find shortest time of related and relevant axial hits RelationVector<CDCTriggerSegmentHit> Hits = track.getRelationsTo<CDCTriggerSegmentHit>(m_hitCollectionName); m_T0 = getLowestTime(isector, Hits, true); if (m_T0 < 9999) { m_hasT0 = true; } else { m_T0 = 0; m_hasT0 = false; }

Definition at line 485 of file NeuroTrigger.cc.

◆ getInputPattern()

unsigned long getInputPattern ( unsigned  isector,
const CDCTriggerTrack track,
const bool  neurotrackinputmode 
)

Calculate input pattern for MLP.

Parameters
isectorindex of the MLP that will use the input
trackaxial hit relations are taken from given track
Returns
super layer pattern of hits in the current track

Definition at line 724 of file NeuroTrigger.cc.

◆ getInputVector()

vector< float > getInputVector ( unsigned  isector,
const std::vector< unsigned > &  hitIds 
)

Calculate input values for MLP.

Parameters
isectorindex of the MLP that will use the input
hitIdshit indices to be used for the input
Returns
scaled vector of input values (1 for each input node)

Definition at line 1007 of file NeuroTrigger.cc.

◆ getPureDriftThreshold()

unsigned long getPureDriftThreshold ( unsigned  isector,
const CDCTriggerTrack track,
const bool  neurotrackinputmode 
)

Get the drift threshold bits, where the time of the TS was outside of the accepted time window and thus shifted to the allowed maximum within the borders.

Note, that to get the same values as from the unpacker, this value has to be combined with the (complement of the) TSVector.

Definition at line 629 of file NeuroTrigger.cc.

◆ load()

bool load ( const std::string &  filename,
const std::string &  arrayname = "MLPs" 
)

Load MLPs from file.

Parameters
filenamename of the TFile to read from
arraynamename of the TObjArray holding the MLPs in the file
Returns
true if the MLPs were loaded correctly

Definition at line 1162 of file NeuroTrigger.cc.

◆ runMLP()

vector< float > runMLP ( unsigned  isector,
const std::vector< float > &  input 
)

Run an expert MLP.

Parameters
isectorindex of the MLP
inputvector of input values
Returns
unscaled output values (z vertex in cm and/or theta in radian)

Definition at line 1041 of file NeuroTrigger.cc.

◆ save()

void save ( const std::string &  filename,
const std::string &  arrayname = "MLPs" 
)

Save MLPs to file.

Parameters
filenamename of the TFile to write to
arraynamename of the TObjArray holding the MLPs in the file

Definition at line 1130 of file NeuroTrigger.cc.

◆ selectHits()

vector< unsigned > selectHits ( unsigned  isector,
const CDCTriggerTrack track,
bool  returnAllRelevant = false 
)

Select best hits for each super layer.

Parameters
isectorindex of the MLP that will use the input
trackaxial hit relations are taken from given track
returnAllRelevantif true, return all relevant hits instead of selecting the best (for making relations)
Returns
list of selected hit indices

Definition at line 869 of file NeuroTrigger.cc.

◆ selectHitsHWSim()

vector< unsigned > selectHitsHWSim ( unsigned  isector,
const CDCTriggerTrack track 
)

Select hits for each super layer from the ones related to input track.

Parameters
isectorindex of the MLP that will use the input
trackall hit relations are taken from given track
returnAllRelevantif true, return all relevant hits instead of selecting the best (for making relations)
Returns
list of selected hit indices

Definition at line 790 of file NeuroTrigger.cc.

◆ selectMLPbyPattern()

int selectMLPbyPattern ( std::vector< int > &  MLPs,
unsigned long  pattern,
const bool  neurotrackinputmode 
)

Select one MLP from a list of sector indices.

The selected expert either matches the given sector pattern, or has no pattern restriction. An unrestricted expert is returned only if there is no exactly matching expert.

Returns
index of the selected MLP, -1 if no matching MLP is found

Definition at line 365 of file NeuroTrigger.cc.

◆ selectMLPs()

vector< int > selectMLPs ( float  phi0,
float  invpt,
float  theta 
)

Select all matching expert MLPs based on the given track parameters.

If the sectors are overlapping, there may be more than one matching expert. During training this is intended, afterwards sectors should be redefined to be unique. For unique geometrical sectors, this function can still find several experts with different sector patterns.

Returns
indices of the selected MLPs, empty if the track does not fit any sector

Definition at line 338 of file NeuroTrigger.cc.

◆ selectMLPsTrain()

vector< int > selectMLPsTrain ( float  phi0,
float  invpt,
float  theta 
)

Select all matching expert MLPs based on the given track parameters.

If the sectors are overlapping, there may be more than one matching expert. During training this is intended, afterwards sectors should be redefined to be unique. For unique geometrical sectors, this function can still find several experts with different sector patterns.

Returns
indices of the selected MLPs, empty if the track does not fit any sector

Definition at line 313 of file NeuroTrigger.cc.

Member Data Documentation

◆ m_precision

std::vector<unsigned> m_precision
private

Fixed point precision in bit after radix point.

8 values:

  • 2D track parameters: omega, phi
  • geometrical values derived from track: crossing angle, reference wire ID
  • scale factor: radian to wire ID
  • MLP values: nodes, weights, activation function LUT input (LUT output = nodes)

Definition at line 314 of file NeuroTrigger.h.


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