QwAnalysis
|
Creates and manages the treesearch pattern database. More...
#include <QwTrackingTree.h>
Public Member Functions | |
QwTrackingTree (unsigned int numlayers) | |
Default constructor. More... | |
virtual | ~QwTrackingTree () |
Destructor. More... | |
void | SetDebugLevel (const int debuglevel) |
Set the debug level. More... | |
void | SetMaxSlope (const double maxslope) |
Set the maximum allowed slope. More... | |
void | Print (const Option_t *options=0) const |
Print the full tree and hash table. More... | |
void | PrintTree () const |
Print the full tree. More... | |
void | PrintHashTable () const |
Print the hash table. More... | |
void | SetGeometry (const QwGeometry &geometry) |
int | consistent (treenode *testnode, int level, QwDetectorInfo *detector) |
Determines whether the pattern is geometrically possible. More... | |
treenode * | existent (treenode *node, int hash) |
Search for a node in the search tree. More... | |
treenode * | nodeexists (nodenode *nd, treenode *tr) |
void | marklin (treenode *father, int level, QwDetectorInfo *detector) |
Recursively generate the treesearch pattern database. More... | |
long | writetree (const string &filename, treenode *tn, int levels, int tlayers, double width) |
This function initializes the output file. It then calls the iterative _writetree function to fill the output file. More... | |
QwTrackingTreeRegion * | readtree (const string &filename, int levels, int tlayers, double rwidth, bool skipreading) |
QwTrackingTreeRegion * | inittree (const string &filename, int levels, int tlayer, double width, QwDetectorInfo *detector, bool regenerate) |
![]() | |
VQwTrackingElement () | |
Default constructor. More... | |
VQwTrackingElement (const VQwTrackingElement &that) | |
virtual | ~VQwTrackingElement () |
Virtual destructor. More... | |
VQwTrackingElement & | operator= (const VQwTrackingElement &that) |
Assignment operator. More... | |
const QwDetectorInfo * | GetDetectorInfo () const |
Get the detector info pointer. More... | |
void | SetDetectorInfo (const QwDetectorInfo *detectorinfo) |
Set the detector info pointer. More... | |
EQwRegionID | GetRegion () const |
Get the region. More... | |
void | SetRegion (EQwRegionID region) |
Set the region. More... | |
EQwDetectorPackage | GetPackage () const |
Get the package. More... | |
void | SetPackage (EQwDetectorPackage package) |
Set the package. More... | |
int | GetOctant () const |
Get the octant number. More... | |
void | SetOctant (int octant) |
Set the octant number. More... | |
EQwDirectionID | GetDirection () const |
Get the direction. More... | |
void | SetDirection (EQwDirectionID direction) |
Set the direction. More... | |
int | GetPlane () const |
Get the plane number. More... | |
void | SetPlane (int plane) |
Set the plane number. More... | |
int | GetElement () const |
Get the element number. More... | |
void | SetElement (int element) |
Set the element number. More... | |
void | SetGeometryTo (const VQwTrackingElement &e) |
Copy the geometry info from another object. More... | |
Private Member Functions | |
int | _writetree (treenode *tn, FILE *fp, int32_t tlayers) |
Recursive method for pulling in the concise treesearch search database. More... | |
int | _readtree (FILE *file, shorttree *stb, shortnode **father, int32_t tlayers) |
Recursive method to read the concise treesearch database from disk. More... | |
treenode * | _inittree (int32_t tlayer, QwDetectorInfo *detector) |
Recursive method to initialize and generate the treesearch database. More... | |
Private Attributes | |
QwGeometry | fGeometry |
Detector (or set of detectors) represented by this search tree. More... | |
int | fDebug |
Debug level. More... | |
unsigned int | fNumLayers |
Number of detector planes. More... | |
unsigned int & | fNumPlanes |
Number of planes in the region 2 HDCs. More... | |
unsigned int & | fNumWires |
Number of wires in a region 3 VDC group. More... | |
unsigned int | fHashSize |
Length of the hash table (as member field) More... | |
double | fMaxSlope |
Maximum allowed slope for tracks in this detector. More... | |
int | fNumPatterns |
Number of valid patterns in the tree. More... | |
int | fRef |
Reference. More... | |
int | fMaxRef |
Maximum number of references in the cached tree file. More... | |
int | fMaxLevel |
treenode * | fFather |
Father node: the main entry point to the tree. More... | |
treenode ** | fHashTable |
Static Private Attributes | |
static const std::string | fgTreeDir |
Name of the tree directory (in $QWSCRATCH), as static member field. More... | |
Additional Inherited Members | |
![]() | |
ClassDef (VQwTrackingElement, 1) | |
![]() | |
const QwDetectorInfo * | fDetectorInfo |
EQwRegionID | fRegion |
///< Detector info pointer More... | |
EQwDetectorPackage | fPackage |
Package. More... | |
int | fOctant |
Octant number. More... | |
EQwDirectionID | fDirection |
Direction. More... | |
int | fPlane |
Plane number. More... | |
int | fElement |
Element number. More... | |
Creates and manages the treesearch pattern database.
The QwTrackingTree class contains the code for creating the tree search database.
The pattern database is used to determine whether subsets of hits resemble track segments.
PROGRAM: QTR (Qweak Track Reconstruction) AUTHOR: Burnham Stokes bestokes@jlab.org ORIGINAL HRC AUTHOR Wolfgang Wander wwc@hermes.desy.de MODULE: QwTrackingTree
PURPOSE: This module contains the code for creating the tree search database. The code first attempts to pull the database from disk. But, if the required database is not found, the code will generate it from scratch and save a copy of it on disk.
CONTENTS: (brief description for now)
(01) consistent() - this function valids a possible treeline hit pattern by seeing if the pattern is consistent with a straight line trajectory through a detector with a slope less than or equal to the fMaxSlope parameter.
(02) existent() - this function checks if a possible treeline hit pattern is already included in the tree search database. If so, it returns a pointer to the pattern within the database. Otherwise, it returns 0.
(03) nodeexists() - this function checks if a possible treeline hit pattern is already known to a father. If so, it returns a pointer to the pattern within the tree database. Otherwise, it returns 0.
(05) marklin() - this function generates the treesearch database. For a given father, it generates the 2^(treelayers) possible son hit patterns. Each son pattern is checked to see if it is consistent with a trajectory through the chamber. If it is consistent, it is inserted into the treesearch database and then, by a recursive call to marklin(), its sons are generated.
(07) _inittree() - this function initializes the treesearch database and then calls marklin() to generate the database.
(08) _writetree() - a recursive function for pulling in the concise treesearch search database.
(09) writetree() - this function calls _writetree() to write the long version of the treesearch database to a disk file. Later, readtree() will read back this file to form the concise treesearch database (so-called short tree) used by the treesearch algorithm.
(11) _readtree() - a recursive function (called by readtree()) to read the concise treesearch database (so-called short tree) from disk.
(12) readtree() - this function calls _readtree() to read the concise treesearch database from disk.
(13) inittree() - this function creates the treesearch database for one treeline. It first attempts to read the database from a diskfile. If this fails, it calls _inittree() to generate the treesearch database.
(14) [c'tor] - the main function of this module. This function calls inittree() to generate the tree database for each of the treelines.
Definition at line 57 of file QwTrackingTree.h.
QwTrackingTree::QwTrackingTree | ( | unsigned int | numlayers | ) |
Default constructor.
Initializes the search tree.
This function loops over each detector region, orientation, type, and wire direction to call inittree. It also determines a file name for each case.
Definition at line 143 of file QwTrackingTree.cc.
References QwTracking::treenode::fBit, fDebug, fFather, fHashSize, fHashTable, QwTracking::treenode::fMaxLevel, QwTracking::treenode::fMinLevel, fNumLayers, fNumPatterns, QwTracking::treenode::fRef, QwTracking::treenode::fWidth, HSHSIZ, and QwTracking::treenode::size().
|
virtual |
Destructor.
Definition at line 173 of file QwTrackingTree.cc.
References QwLog::endl(), fFather, fHashSize, fHashTable, QwTracking::treenode::GetNext(), QwDebug, and QwVerbose.
|
private |
Recursive method to initialize and generate the treesearch database.
This function performs initilization before calling marklin, the iterative pattern generator. the root treenode is created as the simplest pattern possible, and passed to marklin.
Generate a copy of the father node to start off this tree search database
Clear the hash table
Call the recursive tree generator
Finally, add the father node to the hash table
Definition at line 1153 of file QwTrackingTree.cc.
References QwLog::endl(), fFather, fHashTable, fNumPatterns, marklin(), QwDebug, and QwTracking::treenode::SetNext().
Referenced by inittree().
|
private |
Recursive method to read the concise treesearch database from disk.
This function reads in the tree pattern database from a file.
It uses the shorttree and shortnode objects in order to reduce memory overhead.
file | The opened file |
stb | A shorttree |
father | A list of father nodes |
tlayers | The number of layers(?) |
Go into an infinite loop while reading the file
Read the next record type
read in the node(?) information
... and append the patterns to the father's sons
Read in the sons of this node
some error checking
still some error checking
create a new node
and append the alread read-in tree
'ref' to this node.
Definition at line 1284 of file QwTrackingTree.cc.
References QwLog::endl(), fMaxRef, fRef, QwError, QwWarning, REALSON, REFSON, QwTracking::shortnode::SetNext(), QwTracking::shortnode::SetTree(), and SONEND.
Referenced by readtree().
|
private |
Recursive method for pulling in the concise treesearch search database.
This function iteratively writes the patterns to the database.
tn | Tree node to write to file |
fp | File pointer to write to |
tlayers | Number of layers |
pattern has never been written
set its reference
and write all pattern data
write the sons of this treenode (and their sons, etc)
set the marker for end of sonlist
else - only write a reference to
a former written pattern
Definition at line 1188 of file QwTrackingTree.cc.
References QwTracking::treenode::fBit, QwTracking::treenode::fMinLevel, QwTracking::treenode::fRef, fRef, QwTracking::treenode::fSon, QwTracking::treenode::fWidth, QwTracking::nodenode::GetTree(), QwTracking::nodenode::next(), REALSON, REFSON, and SONEND.
Referenced by writetree().
int QwTrackingTree::consistent | ( | treenode * | testnode, |
int | level, | ||
QwDetectorInfo * | detector | ||
) |
Determines whether the pattern is geometrically possible.
...
testnode | |
level | |
detector |
the acceptable limits at the current plane
the position of the left(min) edge of the last layer
the slopes which set the bounds for acceptable hits.
radial offset between upstream and downstream HDC chambers
the left(min) and right(max) edges of the bin at the current plane
dy is decreased by a larger first layer bin
and increased by a larger last layer bin
get the initial bounding slopes
check if the bin in the 3rd layer is within the bounds
this layer is offset
if the hit is out of bounds, cut the pattern
this hit requires the boundaries to be narrowed
check if the bin in the 2nd layer is within the bounds
this layer is not offset
if the hit is out of bounds, cut the pattern
else, this is a good pattern
Definition at line 215 of file QwTrackingTree.cc.
References QwLog::endl(), QwTracking::treenode::fBit, fGeometry, fMaxSlope, fNumLayers, QwDetectorInfo::GetElementSpacing(), QwDetectorInfo::GetNumberOfElements(), QwDetectorInfo::GetPlaneOffset(), QwDetectorInfo::GetRegion(), QwDetectorInfo::GetType(), QwDetectorInfo::GetZPosition(), kRegionID2, kRegionID3, kTypeDriftHDC, kTypeDriftVDC, Qw::m, QwError, and QwWarning.
Referenced by marklin().
Search for a node in the search tree.
Starting with the hash value, the node is searched in the search tree. When the bits are identical to an entry in the search tree, that entry is returned. Otherwise, when no match is found, null is returned.
node | Node to search for |
hash | Hash value of the node |
Definition at line 437 of file QwTrackingTree.cc.
References QwTracking::treenode::fBit, fHashTable, fNumLayers, and QwTracking::treenode::GetNext().
Referenced by marklin().
QwTrackingTreeRegion * QwTrackingTree::inittree | ( | const string & | filename, |
int | levels, | ||
int | tlayer, | ||
double | width, | ||
QwDetectorInfo * | detector, | ||
bool | regenerate | ||
) |
This function checks whether a pattern database requested by inittree already exists. If not, it will call _inittree to create the database, write it out, then read it in again. To force the generation of new databases, simply remove the old ones from the 'trees' directory. If options are set to create a different level of pattern resolution, this function will automatically create the new databases.
Try to read in an existing database
Generate a new tree database
Write the generated tree to disk for faster access later
Read it in again to get the shorter tree search format
Definition at line 1089 of file QwTrackingTree.cc.
References _inittree(), QwLog::endl(), fMaxLevel, fNumLayers, fNumPatterns, QwError, QwMessage, QwVerbose, readtree(), and writetree().
Referenced by QwTrackingWorker::InitTree().
void QwTrackingTree::marklin | ( | treenode * | father, |
int | level, | ||
QwDetectorInfo * | detector | ||
) |
Recursively generate the treesearch pattern database.
This recursive function generates the treesearch database. For a given father node, it generates the 2^fNumLayers possible son hit patterns. Each son pattern is checked to see if it is consistent with a trajectory through the detector. If it is consistent, it is inserted into the tree search database and then, by a recursive call to this function, its sons are generated. marklin has different code for the different regions due to the significant differences between them.
Reminder about the bit pattern:
HDC planes (spaces between the 5 levels of bin division) for 16 bins in wire coordinate (e.g. 16 wires) and zero distance resolution
VDC wires (spaces between the 4 levels of bin division) for 8 bins in drift distance and zero distance resolution
When constructing the hit patterns, we start from level 0 (i.e. 1 bin). There are 2^fNumLayers possible hit patterns, in order of generation:
The number indicates the bin in this particular level of bin division. For the lowest level 0 there are two bins at every layer. The hit is either in bin 0 or bin 1.
At the next level, there are again 2^fNumLayers possible hit patterns, based on the hit pattern of the previous level. The relation from the hit pattern at the previous level and the 16 binary combinations above to the hit pattern at this level is given by bin at this level = 2^(bin at previous level) - 1 + (combination).
For the level 1 (with 4 bins), and hit pattern 0,0,1,1 at level 0:
This works out as follows:
For the combination 1,0,3,2 this can be visualized as:
Clearly, some of the combinations do not correspond to a straight track. The combination 1,0,3,2 is an example. To throw out these invalid tracks we calculate the largest and smallest bin and compare it to the difference between the first and last bin.
Also, the combination 0,0,2,2 is basically identical to 1,1,3,3 up to a shift. They are therefore treated as identical track candidates.
father | Father node |
level | Level of precision |
detector | Detector info |
Definition at line 553 of file QwTrackingTree.cc.
References consistent(), QwLog::endl(), existent(), QwTracking::treenode::fBit, fHashSize, fHashTable, QwTracking::treenode::fMaxLevel, fMaxLevel, QwTracking::treenode::fMinLevel, fNumLayers, fNumPatterns, fNumPlanes, fNumWires, QwTracking::treenode::fSon, QwTracking::treenode::fWidth, QwDetectorInfo::GetRegion(), QwDetectorInfo::GetType(), kRegionID2, kRegionID3, kTypeDriftHDC, kTypeDriftVDC, Qw::min, nodeexists(), QwError, QwTracking::nodenode::SetNext(), QwTracking::treenode::SetNext(), and QwTracking::nodenode::SetTree().
Referenced by _inittree().
Definition at line 450 of file QwTrackingTree.cc.
References QwLog::endl(), QwTracking::treenode::fBit, fNumLayers, QwTracking::nodenode::GetNext(), QwTracking::nodenode::GetTree(), and QwError.
Referenced by marklin().
|
inline |
Print the full tree and hash table.
Definition at line 72 of file QwTrackingTree.h.
References PrintHashTable(), and PrintTree().
void QwTrackingTree::PrintHashTable | ( | ) | const |
Print the hash table.
Definition at line 119 of file QwTrackingTree.cc.
References QwLog::endl(), fHashSize, fHashTable, QwTracking::treenode::GetNext(), and QwOut.
Referenced by Print().
void QwTrackingTree::PrintTree | ( | ) | const |
Print the full tree.
Definition at line 108 of file QwTrackingTree.cc.
References QwLog::endl(), fHashTable, QwTracking::treenode::Print(), and QwOut.
Referenced by Print().
QwTrackingTreeRegion * QwTrackingTree::readtree | ( | const string & | filename, |
int | levels, | ||
int | tlayers, | ||
double | rwidth, | ||
bool | skipreading | ||
) |
filename | The filename of the file where the tree is stored |
levels | The number of levels |
tlayers | The number of layers |
rwidth | The distance between the wires/strips |
skipreading | Flag to skip the reading of cached trees |
Open the file for reading and complain if this fails
If num and width cannot be read, then the file is invalid
Allocate a shorttree array
Allocate a QwTrackingTreeRegion object
... and fill by recursively calling _readtree
Close the file after reading in the tree
Definition at line 1000 of file QwTrackingTree.cc.
References _readtree(), QwLog::endl(), fMaxRef, fRef, QwTrackingTreeRegion::GetNode(), QwTrackingTreeRegion::IsSearchable(), QwDebug, QwWarning, QwTracking::shortnode::SetNext(), QwTrackingTreeRegion::SetSearchable(), QwTracking::shortnode::SetTree(), and QwTrackingTreeRegion::SetWidth().
Referenced by inittree().
|
inline |
|
inline |
Definition at line 78 of file QwTrackingTree.h.
References fGeometry.
Referenced by QwTrackingWorker::InitTree().
|
inline |
Set the maximum allowed slope.
Definition at line 69 of file QwTrackingTree.h.
References fMaxSlope.
Referenced by QwTrackingWorker::InitTree().
long QwTrackingTree::writetree | ( | const string & | filename, |
treenode * | tn, | ||
int | levels, | ||
int | tlayers, | ||
double | width | ||
) |
This function initializes the output file. It then calls the iterative _writetree function to fill the output file.
Write 4 bytes to fill later with the number of different patterns
... and write whole tree
append marker for end of son list
Now write the total numer of different patterns,
close the file
and return the number of different patterns
Definition at line 1227 of file QwTrackingTree.cc.
References _writetree(), QwLog::endl(), fRef, QwWarning, and SONEND.
Referenced by inittree().
|
private |
Debug level.
Definition at line 123 of file QwTrackingTree.h.
Referenced by QwTrackingTree(), and SetDebugLevel().
|
private |
Father node: the main entry point to the tree.
Definition at line 145 of file QwTrackingTree.h.
Referenced by _inittree(), QwTrackingTree(), and ~QwTrackingTree().
|
private |
Detector (or set of detectors) represented by this search tree.
Definition at line 121 of file QwTrackingTree.h.
Referenced by consistent(), and SetGeometry().
|
staticprivate |
Name of the tree directory (in $QWSCRATCH), as static member field.
Definition at line 118 of file QwTrackingTree.h.
|
private |
Length of the hash table (as member field)
Definition at line 130 of file QwTrackingTree.h.
Referenced by marklin(), PrintHashTable(), QwTrackingTree(), and ~QwTrackingTree().
|
private |
Hash table: the list of all nodes in the tree, organized in linked lists and sorted by hash value; an array of pointers to treenodes.
Definition at line 150 of file QwTrackingTree.h.
Referenced by _inittree(), existent(), marklin(), PrintHashTable(), PrintTree(), QwTrackingTree(), and ~QwTrackingTree().
|
private |
maximum level of the bin division within
the treesearch database, i.e.: resolution = width / (2^maxlevel)
Definition at line 140 of file QwTrackingTree.h.
Referenced by inittree(), and marklin().
|
private |
Maximum number of references in the cached tree file.
Definition at line 138 of file QwTrackingTree.h.
Referenced by _readtree(), and readtree().
|
private |
Maximum allowed slope for tracks in this detector.
Definition at line 132 of file QwTrackingTree.h.
Referenced by consistent(), and SetMaxSlope().
|
private |
Number of detector planes.
Definition at line 126 of file QwTrackingTree.h.
Referenced by consistent(), existent(), inittree(), marklin(), nodeexists(), and QwTrackingTree().
|
private |
Number of valid patterns in the tree.
Definition at line 133 of file QwTrackingTree.h.
Referenced by _inittree(), inittree(), marklin(), and QwTrackingTree().
|
private |
Number of planes in the region 2 HDCs.
Definition at line 127 of file QwTrackingTree.h.
Referenced by marklin().
|
private |
Number of wires in a region 3 VDC group.
Definition at line 128 of file QwTrackingTree.h.
Referenced by marklin().
|
private |
Reference.
Definition at line 136 of file QwTrackingTree.h.
Referenced by _readtree(), _writetree(), readtree(), and writetree().