QwAnalysis
VQwTrackingElement.h
Go to the documentation of this file.
1 /*!
2  * \file VQwTrackingElement.h
3  * \brief Definition of virtual base class for all tracking elements
4  *
5  * \author Wouter Deconinck
6  * \date 2009-12-08
7  */
8 
9 #ifndef VQWTRACKINGELEMENT_H
10 #define VQWTRACKINGELEMENT_H
11 
12 // System headers
13 #include <vector>
14 
15 // ROOT headers
16 #include <TObject.h>
17 #include <TClonesArray.h>
18 
19 // Qweak headers
20 #include "QwTypes.h"
21 #include "QwLog.h"
22 #include "QwDetectorInfo.h"
23 
24 /**
25  * \class VQwTrackingElement
26  * \ingroup QwTracking
27  * \brief Virtual base class for all tracking elements
28  *
29  * This is the virtual base class of all tracking elements, such as QwTrack,
30  * QwPartialTrack, or QwTreeLine. This class contains the identifying
31  * information of the detector where the tracking element resides. All other
32  * classes that contain tracking information should inherit from this class.
33  *
34  * When components of VQwTrackingElement are ill-defined (for example, the
35  * direction in case of partial tracks), they are set to their null value.
36  */
37 class VQwTrackingElement: public TObject {
38 
39  public:
40 
41  /// \brief Default constructor
43  : TObject(),fDetectorInfo(0),
47  : TObject(that),fDetectorInfo(that.fDetectorInfo),
48  fRegion(that.fRegion), fPackage(that.fPackage), fOctant(that.fOctant),
49  fDirection(that.fDirection), fPlane(that.fPlane), fElement(that.fElement) { };
50  /// \brief Virtual destructor
51  virtual ~VQwTrackingElement() {};
52 
53  /// \brief Assignment operator
56  fRegion = that.fRegion;
57  fPackage = that.fPackage;
58  fOctant = that.fOctant;
59  fDirection = that.fDirection;
60  fPlane = that.fPlane;
61  fElement = that.fElement;
62  return *this;
63  };
64 
65  /// \brief Get the detector info pointer
66  const QwDetectorInfo* GetDetectorInfo () const { return fDetectorInfo; };
67  /// \brief Set the detector info pointer
68  void SetDetectorInfo(const QwDetectorInfo *detectorinfo) { fDetectorInfo = detectorinfo; };
69 
70  /// \brief Get the region
71  EQwRegionID GetRegion() const { return fRegion; };
72  /// \brief Set the region
73  void SetRegion(EQwRegionID region) { fRegion = region; };
74 
75  /// \brief Get the package
76  EQwDetectorPackage GetPackage() const { return fPackage; };
77  /// \brief Set the package
78  void SetPackage(EQwDetectorPackage package) { fPackage = package; };
79 
80  /// \brief Get the octant number
81  int GetOctant() const { return fOctant; };
82  /// \brief Set the octant number
83  void SetOctant(int octant) { fOctant = octant; };
84 
85  /// \brief Get the direction
86  EQwDirectionID GetDirection() const { return fDirection; };
87  /// \brief Set the direction
88  void SetDirection(EQwDirectionID direction) { fDirection = direction; };
89 
90  /// \brief Get the plane number
91  int GetPlane() const { return fPlane; };
92  /// \brief Set the plane number
93  void SetPlane(int plane) { fPlane = plane; };
94 
95  /// \brief Get the element number
96  int GetElement() const { return fElement; };
97  /// \brief Set the element number
98  void SetElement(int element) { fElement = element; };
99 
100  /// \brief Copy the geometry info from another object
103  fRegion = e.fRegion;
104  fPackage = e.fPackage;
105  fOctant = e.fOctant;
107  fPlane = e.fPlane;
108  fElement = e.fElement;
109  };
110 
111  protected:
112 
113  // This will stay empty until we have completely moved away from Det to the
114  // QwDetectorInfo class for geometry propagation. Then it will contain the
115  // detector info of the first (not necessarily only) detector location.
116  const QwDetectorInfo* fDetectorInfo; //! ///< Detector info pointer
117 
118  // There is a lot of overlap with QwDetectorID here, but as long as there
119  // are still int in QwDetectorInfo we should use the standard types here.
120  EQwRegionID fRegion; ///< Region
122  int fOctant; ///< Octant number
123  EQwDirectionID fDirection; ///< Direction
124  int fPlane; ///< Plane number
125  int fElement; ///< Element number
126 
128 
129 }; // class VQwTrackingElement
130 
131 
132 /// Storage of tracking results
133 /// - static TClonesArray:
134 /// Pros: - new/delete cost reduced from O(n^2) to O(n) by preallocation
135 /// Cons: - static array prevents multiple simultaneous events
136 /// - could be prevented by using Clear() instead of delete, and
137 /// with a non-static global list
138 /// - nesting is difficult
139 /// - local TClonesArray:
140 /// Pros: - new/delete cost reduced from O(n^2) to O(n) by preallocation
141 /// - multiple events each have own preallocated list, so Clear()
142 /// should be used
143 /// Cons: - nesting is still difficult
144 /// - std::vector<TObject*>:
145 /// Pros: - handled transparently by recent ROOT versions (> 4, it seems)
146 /// - easier integration with non-ROOT QwAnalysis structures
147 /// Cons: - preallocation not included, O(n^2) cost due to new/delete,
148 /// but not copying full object, only pointers
149 /// - need to store the actual objects somewhere else, these are
150 /// just references
151 ///
152 /// In all cases there still seems to be a problem with the ROOT TBrowser
153 /// when two identical branches with TClonesArrays are in the same tree.
154 /// When drawing leafs from the second branch, the first branch is drawn.
155 
156 #define MAX_NUM_ELEMENTS 1000
157 
158 template <class T>
159 class VQwTrackingElementContainer: public std::vector<T*> {
160 
161  public:
162 
163  /// Constructor
165 
166  /// Create a new tree line
168  T* element = new T();
169  Add(element);
170  return element;
171  }
172 
173  /// Add an existing element as a copy
174  void Add(T* element) {
175  fList.push_back(new T(element));
176  }
177 
178  /// Add a list of existing tree lines as a copy
179  void AddList(T* list) {
180  for (T *element = list; element; element = element->next)
181  Add(element);
182  }
183 
184  /// Clear the list of tree lines
185  void Clear(Option_t *option = "") {
186  for (typename std::vector<T*>::iterator element = fList.begin();
187  element != fList.end(); element++)
188  delete *element;
189  fList.clear();
190  }
191 
192  /// Reset the list of tree lines
193  void Reset(Option_t *option = "") {
194  Clear(option);
195  }
196 
197  /// Print the list of tree lines
198  void Print(Option_t* option = "") const {
199  for (typename std::vector<T*>::const_iterator element = fList.begin();
200  element != fList.end(); element++)
201  QwMessage << **element << QwLog::endl;
202  }
203 
204  /// Get the number of tree lines
205  Int_t GetNumberOfElements() const {
206  return fList.size();
207  };
208 
209  private:
210 
211  std::vector<T*> fList; ///< Array of pointers to elements
212 
213 }; // class VQwTrackingElementContainer
214 
215 #endif // VQWTRACKINGELEMENT_H
EQwDirectionID fDirection
Direction.
int fElement
Element number.
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
void SetPlane(int plane)
Set the plane number.
T * CreateNew()
Create a new tree line.
EQwDetectorPackage fPackage
Package.
void SetElement(int element)
Set the element number.
int fPlane
Plane number.
void Print(Option_t *option="") const
Print the list of tree lines.
int GetElement() const
Get the element number.
void SetRegion(EQwRegionID region)
Set the region.
int fOctant
Octant number.
VQwTrackingElementContainer()
Constructor.
void AddList(T *list)
Add a list of existing tree lines as a copy.
int GetOctant() const
Get the octant number.
ClassDef(VQwTrackingElement, 1)
static const double e
Definition: QwUnits.h:91
EQwRegionID fRegion
///&lt; Detector info pointer
void SetPackage(EQwDetectorPackage package)
Set the package.
EQwDetectorPackage
Definition: QwTypes.h:70
EQwRegionID GetRegion() const
Get the region.
std::vector< T * > fList
Array of pointers to elements.
int GetPlane() const
Get the plane number.
VQwTrackingElement & operator=(const VQwTrackingElement &that)
Assignment operator.
void Reset(Option_t *option="")
Reset the list of tree lines.
void Add(T *element)
Add an existing element as a copy.
EQwRegionID
Definition: QwTypes.h:16
A logfile class, based on an identical class in the Hermes analyzer.
void SetOctant(int octant)
Set the octant number.
static const double T
Magnetic field: base unit is T.
Definition: QwUnits.h:111
void SetGeometryTo(const VQwTrackingElement &e)
Copy the geometry info from another object.
VQwTrackingElement()
Default constructor.
VQwTrackingElement(const VQwTrackingElement &that)
void SetDetectorInfo(const QwDetectorInfo *detectorinfo)
Set the detector info pointer.
void SetDirection(EQwDirectionID direction)
Set the direction.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
const QwDetectorInfo * fDetectorInfo
const QwDetectorInfo * GetDetectorInfo() const
Get the detector info pointer.
EQwDirectionID
Definition: QwTypes.h:41
virtual ~VQwTrackingElement()
Virtual destructor.
void Clear(Option_t *option="")
Clear the list of tree lines.
EQwDirectionID GetDirection() const
Get the direction.
Int_t GetNumberOfElements() const
Get the number of tree lines.
EQwDetectorPackage GetPackage() const
Get the package.
Virtual base class for all tracking elements.