QwAnalysis
shorttree.cc
Go to the documentation of this file.
1 /*------------------------------------------------------------------------*//*!
2 
3  \file shortnode.cc
4  \ingroup QwTracking
5 
6  \author Wolfgang Wander <wwc@hermes.desy.de>
7  \author Burnham Stokes <bestokes@jlab.org>
8  \author Wouter Deconinck <wdconinc@mit.edu>
9 
10  \date 2009-09-04 18:06:23
11 
12  \brief Definition of a shorttree, the short version of a treenode
13 
14 *//*-------------------------------------------------------------------------*/
15 
16 #include "shorttree.h"
17 
18 // Qweak headers
19 #include "globals.h"
20 #include "QwLog.h"
21 
22 // Qweak tree headers
23 #include "shortnode.h"
24 
25 namespace QwTracking {
26 
27 // Default size
28 unsigned int shorttree::fDefaultSize = MAX_LAYERS;
29 
30 // Reset debug level
31 int shorttree::fDebug = 0;
32 
33 /**
34  * Default constructor, initializes the son pointer to null
35  * @param size Size of the bit pattern
36  */
37 shorttree::shorttree(unsigned int size)
38 {
39  // Set the size
40  fSize = size;
41  fBit = new int[fSize];
42  for (unsigned int i = 0; i < fSize; i++) fBit[i] = 0;
43 
44  // Initialize pointers
45  for (int i = 0; i < 4; i++)
46  son[i] = 0;
47 }
48 
49 /**
50  * Destructor deletes the memory occupied by the sons
51  */
53 {
54  // Delete the bit pattern
55  delete[] fBit;
56 }
57 
58 /**
59  * Print some debugging information
60  */
61 void shorttree::Print(bool recursive, int indent)
62 {
63  // Print this node
64  std::string indentation;
65  for (int i = 0; i < indent; i++) indentation += " ";
66  QwOut << this << ": " << *this << QwLog::endl;
67  // Bit pattern
68  for (unsigned int i = 0; i < fSize; i++) {
69  QwOut << indentation;
70  for (int j = 0; j < (1 << (fMinLevel + 1)); j++) {
71  if (j == fBit[i]) QwOut << "|";
72  else QwOut << ".";
73  }
74  QwOut << QwLog::endl;
75  }
76 
77  // Descend to the sons of this node
78  for (int i = 0; recursive && i < 4; i++) {
79  shortnode* node = this->son[i];
80  if (node) {
81  QwOut << indentation << "son " << i << ": ";
82  node->Print(recursive,indent+1);
83  }
84  }
85 }
86 
87 /**
88  * Stream some info about the short tree
89  * @param stream Stream as lhs of the operator
90  * @param st Short tree as rhs of the operator
91  * @return Stream as result of the operator
92  */
93 std::ostream& operator<< (std::ostream& stream, const shorttree& st)
94 {
95  stream << "(" << st.fMinLevel << "," << "*" << ") ";
96  for (unsigned int i = 0; i < st.fSize; i++)
97  stream << st.fBit[i] << ",";
98  stream << " width = " << st.fWidth;
99  return stream;
100 }
101 
102 } // namespace QwTracking
unsigned int size() const
Get size of the bit array.
Definition: shorttree.h:81
int * fBit
Hit pattern, one bin specified per detector layer.
Definition: shorttree.h:64
#define QwOut
Predefined log drain for explicit output.
Definition: QwLog.h:35
static unsigned int fDefaultSize
Default size.
Definition: shorttree.h:81
int fWidth
Width in bins of the hit pattern.
Definition: shorttree.h:67
void Print(bool recursive=false, int indent=0)
Print some debugging information.
Definition: shorttree.cc:61
~shorttree()
Destructor.
Definition: shorttree.cc:52
unsigned int fSize
Definition: shorttree.h:76
int fMinLevel
Minimum level at which this node is valid.
Definition: shorttree.h:61
A logfile class, based on an identical class in the Hermes analyzer.
shortnode * son[4]
Each tree has four son nodes.
Definition: shorttree.h:72
Similar to a treenode.
Definition: shorttree.h:44
Definition of a shortnode, the short version of a nodenode.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Similar to a nodenode.
Definition: shortnode.h:38
shorttree(unsigned int size=fDefaultSize)
Default constructor.
Definition: shorttree.cc:37
#define MAX_LAYERS
Definition: globals.h:8
std::ostream & operator<<(std::ostream &stream, const shortnode &sn)
Definition: shortnode.cc:93
void Print(bool recursive=false, int indent=0)
Print some debugging information.
Definition: shortnode.cc:67
static int fDebug
Debug level.
Definition: shorttree.h:87