Belle II Software  release-08-01-10
EventDataPlotter.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #pragma once
9 
10 #include <tracking/trackFindingCDC/display/PrimitivePlotter.h>
11 
12 #include <framework/datastore/StoreArray.h>
13 
14 #include <memory>
15 
16 namespace Belle2 {
21  class MCParticle;
22  class RecoTrack;
23  class CDCHit;
24  class CDCSimHit;
25 
26  namespace TrackFindingCDC {
27 
28  class BoundingBox;
29 
30  class Circle2D;
31 
32  class CDCWireTopology;
33  class CDCWireSuperLayer;
34  class CDCWire;
35 
36  class CDCTrajectory2D;
37 
38  class CDCWireHit;
39  class CDCTangent;
40  class CDCRecoHit2D;
41  class CDCRecoHit3D;
42 
43  class CDCWireHitCluster;
44  class CDCSegment2D;
45  class CDCSegment3D;
46 
47  class CDCSegmentPair;
48  class CDCAxialSegmentPair;
49  class CDCSegmentTriple;
50 
51  class CDCTrack;
52 
55 
56 
57  public:
60 
61  public:
63  explicit EventDataPlotter(bool animate = false, bool forwardFade = false);
64 
70  explicit EventDataPlotter(std::unique_ptr<PrimitivePlotter> ptrPrimitivePlotter,
71  bool animate = false,
72  bool forwardFade = false);
73 
75  EventDataPlotter(const EventDataPlotter& eventDataPlotter);
76 
77  public:
88  const std::string save(const std::string& fileName);
89 
91  void clear();
92 
93  public:
96 
98  void setBoundingBox(const BoundingBox& boundingBox);
99 
101  float getCanvasWidth() const;
102 
104  float getCanvasHeight() const;
105 
112  void setCanvasWidth(float width);
113 
120  void setCanvasHeight(float height);
121 
125  void startGroup(const AttributeMap& attributeMap = AttributeMap());
126 
130  void endGroup();
131 
132  public:
134  std::string getAnimationTimeFromNanoSeconds(float nanoseconds)
135  {
136  return std::to_string(nanoseconds) + "s";
137  }
138 
139  private:
141  void startAnimationGroup(const Belle2::CDCSimHit& simHit);
142 
144  void startAnimationGroup(const Belle2::CDCHit* ptrHit);
145 
146  public:
148  void drawInteractionPoint();
149 
151  void drawInnerCDCWall(const AttributeMap& attributeMap = AttributeMap());
152 
154  void drawOuterCDCWall(const AttributeMap& attributeMap = AttributeMap());
155 
157  void drawSuperLayerBoundaries(const AttributeMap& attributeMap = AttributeMap());
158 
160  void drawLine(float startX,
161  float startY,
162  float endX,
163  float endY,
164  const AttributeMap& attributeMap = AttributeMap());
165 
166  public:
167  // Drawing methods for the variuous event data objects.
168 
170  void draw(const Belle2::TrackFindingCDC::Circle2D& circle,
171  AttributeMap attributeMap = AttributeMap());
172 
174  void draw(const Belle2::TrackFindingCDC::CDCWire& wire,
175  const AttributeMap& attributeMap = AttributeMap());
176 
178  void draw(const Belle2::TrackFindingCDC::CDCWireSuperLayer& wireSuperLayer,
179  const AttributeMap& attributeMap = AttributeMap());
180 
182  void draw(const Belle2::TrackFindingCDC::CDCWireTopology& wireTopology,
183  AttributeMap attributeMap = AttributeMap());
184 
186  void draw(const Belle2::CDCSimHit& simHit,
187  const AttributeMap& attributeMap = AttributeMap());
188 
190  void draw(const Belle2::CDCHit& hit,
191  const AttributeMap& attributeMap = AttributeMap());
192 
194  void draw(const Belle2::TrackFindingCDC::CDCWireHit& wireHit,
195  const AttributeMap& attributeMap = AttributeMap());
196 
198  void draw(const Belle2::TrackFindingCDC::CDCRecoHit2D& recoHit2D,
199  const AttributeMap& attributeMap = AttributeMap());
200 
202  void draw(const Belle2::TrackFindingCDC::CDCRecoHit3D& recoHit3D,
203  const AttributeMap& attributeMap = AttributeMap());
204 
206  void draw(const Belle2::TrackFindingCDC::CDCTangent& tangent,
207  const AttributeMap& attributeMap = AttributeMap());
208 
210  void draw(const CDCTrajectory2D& trajectory2D, AttributeMap attributeMap = AttributeMap());
211 
213  void draw(const CDCWireHitCluster& wireHitCluster, const AttributeMap& attributeMap = AttributeMap());
214 
216  void draw(const CDCSegment2D& segment2D, const AttributeMap& attributeMap = AttributeMap());
217 
219  void draw(const CDCSegment3D& segment3D, const AttributeMap& attributeMap = AttributeMap());
220 
222  void draw(const CDCAxialSegmentPair& axialSegmentPair, const AttributeMap& attributeMap = AttributeMap());
223 
225  void draw(const CDCSegmentPair& segmentPair, const AttributeMap& attributeMap = AttributeMap());
226 
228  void draw(const CDCSegmentTriple& segmentTriple, const AttributeMap& attributeMap = AttributeMap());
229 
231  void draw(const CDCTrack& track, const AttributeMap& attributeMap = AttributeMap());
232 
234  void draw(const RecoTrack& recoTrack, const AttributeMap& attributeMap = AttributeMap());
235 
237  void drawTrajectory(const MCParticle& mcParticle, const AttributeMap& attributeMap = AttributeMap());
238 
240  void drawTrajectory(const CDCSegment2D& segment, const AttributeMap& attributeMap = AttributeMap());
241 
243  void drawTrajectory(const CDCSegmentTriple& segmentTriple, const AttributeMap& attributeMap = AttributeMap());
244 
246  void drawTrajectory(const CDCTrack& track, const AttributeMap& attributeMap = AttributeMap());
247 
249  void drawTrajectory(const RecoTrack& recoTrack, const AttributeMap& attributeMap = AttributeMap());
250 
252  template<class T>
253  void draw(const T* ptr, const AttributeMap& attributeMap = AttributeMap())
254  {
255  if (ptr) draw(*ptr, attributeMap);
256  }
257 
259  template<class T>
260  void draw(const StoreArray<T>& storeArray, const AttributeMap& attributeMap = AttributeMap())
261  {
262  if (not storeArray) return;
263  drawRange(storeArray, attributeMap);
264  }
265 
267  template<class ARange>
268  void drawRange(const ARange& range, const AttributeMap& attributeMap = AttributeMap())
269  {
270  if (not m_ptrPrimitivePlotter) return;
271  PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
272  primitivePlotter.startGroup(attributeMap);
273  for (const auto& element : range) {
274  draw(element);
275  }
276  primitivePlotter.endGroup();
277  }
278 
280  template<class ARange>
281  void drawRangeWithFade(const ARange& range, const AttributeMap& attributeMap = AttributeMap())
282  {
283  if (not m_ptrPrimitivePlotter) return;
284  PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
285  primitivePlotter.startGroup(attributeMap);
286  float opacity = 1;
287  float endOpacity = 0.5;
288  int n = std::distance(std::begin(range), std::end(range));
289  if (n == 0) return;
290  float opacityFactor = std::pow(endOpacity / opacity, 1.0 / (n - 1));
291  for (const auto& element : range) {
292  const auto opacity_str = std::to_string(opacity);
293  AttributeMap elementAttributeMap{{"opacity", opacity_str}};
294  draw(element, elementAttributeMap);
295  opacity *= opacityFactor;
296  }
297  primitivePlotter.endGroup();
298  }
299 
300  private:
302  std::unique_ptr<PrimitivePlotter> m_ptrPrimitivePlotter;
303 
305  bool m_animate = false;
306 
308  bool m_forwardFade = false;
309 
310  };
311  }
313 }
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
Example Detector.
Definition: CDCSimHit.h:21
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
A two dimensional rectangle that keeps track of the extend of a drawing.
Definition: BoundingBox.h:21
Class representing a pair of reconstructed axial segements in adjacent superlayer.
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:47
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:52
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:39
A segment consisting of three dimensional reconstructed hits.
Definition: CDCSegment3D.h:26
Class representing a pair of one reconstructed axial segement and one stereo segment in adjacent supe...
Class representing a triple of reconstructed segements in adjacent superlayer.
Class representating a linear track piece between two oriented wire hits.
Definition: CDCTangent.h:40
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:41
Particle trajectory as it is seen in xy projection represented as a circle.
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55
Class representating a sense wire superlayer in the central drift chamber.
Class representating the sense wire arrangement in the whole of the central drift chamber.
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:58
A two dimensional circle in its natural representation using center and radius as parameters.
Definition: Circle2D.h:26
A class that can plot event related data types.
void drawInteractionPoint()
Marks the position of the interaction point with a filled circle.
float getCanvasHeight() const
Getter for the canvas height in pixels.
void setCanvasHeight(float height)
Setter for the canvas height in pixels The canvas height denotes the size of the image being produced...
void setBoundingBox(const BoundingBox &boundingBox)
Setter for the bounding box of all drawed objects.
bool m_forwardFade
Memory for the flag whether the orientation of tracks segments etc should be shown as diming opacity.
void drawOuterCDCWall(const AttributeMap &attributeMap=AttributeMap())
Draw the outer wall of the CDC.
void drawTrajectory(const MCParticle &mcParticle, const AttributeMap &attributeMap=AttributeMap())
Draws the trajectory that is represented by the MC particle.
void drawInnerCDCWall(const AttributeMap &attributeMap=AttributeMap())
Draw the inner wall of the CDC.
float getCanvasWidth() const
Getter for the canvas width in pixels.
PrimitivePlotter::AttributeMap AttributeMap
Forward the Attributre map from the primitive plotter.
void drawRange(const ARange &range, const AttributeMap &attributeMap=AttributeMap())
Draws a range iterable collection of drawable elements.
void startGroup(const AttributeMap &attributeMap=AttributeMap())
Indicates the start of a group of drawn elements.
bool m_animate
Memory for the flag if the event data should be animated. If animation is supported is backend depend...
void setCanvasWidth(float width)
Setter for the canvas width in pixels.
void draw(const T *ptr, const AttributeMap &attributeMap=AttributeMap())
Allow the drawing of pointers checking if the pointer is nonzero.
const std::string save(const std::string &fileName)
Saves the current plot stead to a file.
BoundingBox getBoundingBox() const
Getter for the current bounding box.
std::unique_ptr< PrimitivePlotter > m_ptrPrimitivePlotter
Reference to the primitivePlotter instance used as backend for the draw commands.
EventDataPlotter(bool animate=false, bool forwardFade=false)
Default constructor for ROOT compatibility. Uses an SVGPrimitivePlotter as backend.
void clear()
Clears all drawed elements from the plotter.
void drawSuperLayerBoundaries(const AttributeMap &attributeMap=AttributeMap())
Draw the super layer bounds of the CDC.
void drawRangeWithFade(const ARange &range, const AttributeMap &attributeMap=AttributeMap())
Draws a range iterable collection of drawable elements.
void draw(const Belle2::TrackFindingCDC::Circle2D &circle, AttributeMap attributeMap=AttributeMap())
Draws a filled circle.
void draw(const StoreArray< T > &storeArray, const AttributeMap &attributeMap=AttributeMap())
Draw store array.
void drawLine(float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap())
Draws a straight Line.
void startAnimationGroup(const Belle2::CDCSimHit &simHit)
Start a group in the underlying plotter with an animation uncovering the elements at the time of flig...
void endGroup()
Indicates the end of a group of drawn elements.
std::string getAnimationTimeFromNanoSeconds(float nanoseconds)
Converts a time given in nanoseconds to a time sting of the from "%fs".
A base class for plots of primitive objects.
virtual void startGroup(const AttributeMap &attributeMap=AttributeMap())
Indicates the start of a group of drawn elements.
Belle2::TrackFindingCDC::AttributeMap AttributeMap
A map type for attributes names to values for additional drawing information.
virtual void endGroup()
Indicates the end of a group of drawn elements.
Abstract base class for different kinds of events.