Belle II Software  release-05-02-19
EventDataPlotter.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/display/PrimitivePlotter.h>
13 
14 #include <framework/datastore/StoreArray.h>
15 
16 #include <memory>
17 
18 namespace Belle2 {
23  class MCParticle;
24  class RecoTrack;
25  class CDCHit;
26  class CDCSimHit;
27 
28  namespace TrackFindingCDC {
29 
30  class BoundingBox;
31 
32  class Circle2D;
33 
34  class CDCWireTopology;
35  class CDCWireSuperLayer;
36  class CDCWire;
37 
38  class CDCTrajectory2D;
39 
40  class CDCWireHit;
41  class CDCTangent;
42  class CDCRecoHit2D;
43  class CDCRecoHit3D;
44 
45  class CDCWireHitCluster;
46  class CDCSegment2D;
47  class CDCSegment3D;
48 
49  class CDCSegmentPair;
50  class CDCAxialSegmentPair;
51  class CDCSegmentTriple;
52 
53  class CDCTrack;
54 
56  class EventDataPlotter {
57 
58 
59  public:
62 
63  public:
65  explicit EventDataPlotter(bool animate = false, bool forwardFade = false);
66 
72  explicit EventDataPlotter(std::unique_ptr<PrimitivePlotter> ptrPrimitivePlotter,
73  bool animate = false,
74  bool forwardFade = false);
75 
77  EventDataPlotter(const EventDataPlotter& eventDataPlotter);
78 
79  public:
90  const std::string save(const std::string& fileName);
91 
93  void clear();
94 
95  public:
97  BoundingBox getBoundingBox() const;
98 
100  void setBoundingBox(const BoundingBox& boundingBox);
101 
103  float getCanvasWidth() const;
104 
106  float getCanvasHeight() const;
107 
114  void setCanvasWidth(float width);
115 
122  void setCanvasHeight(float height);
123 
127  void startGroup(const AttributeMap& attributeMap = AttributeMap());
128 
132  void endGroup();
133 
134  public:
136  std::string getAnimationTimeFromNanoSeconds(float nanoseconds)
137  {
138  return std::to_string(nanoseconds) + "s";
139  }
140 
141  private:
143  void startAnimationGroup(const Belle2::CDCSimHit& simHit);
144 
146  void startAnimationGroup(const Belle2::CDCHit* ptrHit);
147 
148  public:
150  void drawInteractionPoint();
151 
153  void drawInnerCDCWall(const AttributeMap& attributeMap = AttributeMap());
154 
156  void drawOuterCDCWall(const AttributeMap& attributeMap = AttributeMap());
157 
159  void drawSuperLayerBoundaries(const AttributeMap& attributeMap = AttributeMap());
160 
162  void drawLine(float startX,
163  float startY,
164  float endX,
165  float endY,
166  const AttributeMap& attributeMap = AttributeMap());
167 
168  public:
169  // Drawing methods for the variuous event data objects.
170 
172  void draw(const Belle2::TrackFindingCDC::Circle2D& circle,
173  AttributeMap attributeMap = AttributeMap());
174 
176  void draw(const Belle2::TrackFindingCDC::CDCWire& wire,
177  const AttributeMap& attributeMap = AttributeMap());
178 
180  void draw(const Belle2::TrackFindingCDC::CDCWireSuperLayer& wireSuperLayer,
181  const AttributeMap& attributeMap = AttributeMap());
182 
184  void draw(const Belle2::TrackFindingCDC::CDCWireTopology& wireTopology,
185  AttributeMap attributeMap = AttributeMap());
186 
188  void draw(const Belle2::CDCSimHit& simHit,
189  const AttributeMap& attributeMap = AttributeMap());
190 
192  void draw(const Belle2::CDCHit& hit,
193  const AttributeMap& attributeMap = AttributeMap());
194 
196  void draw(const Belle2::TrackFindingCDC::CDCWireHit& wireHit,
197  const AttributeMap& attributeMap = AttributeMap());
198 
200  void draw(const Belle2::TrackFindingCDC::CDCRecoHit2D& recoHit2D,
201  const AttributeMap& attributeMap = AttributeMap());
202 
204  void draw(const Belle2::TrackFindingCDC::CDCRecoHit3D& recoHit3D,
205  const AttributeMap& attributeMap = AttributeMap());
206 
208  void draw(const Belle2::TrackFindingCDC::CDCTangent& tangent,
209  const AttributeMap& attributeMap = AttributeMap());
210 
212  void draw(const CDCTrajectory2D& trajectory2D, AttributeMap attributeMap = AttributeMap());
213 
215  void draw(const CDCWireHitCluster& wireHitCluster, const AttributeMap& attributeMap = AttributeMap());
216 
218  void draw(const CDCSegment2D& segment2D, const AttributeMap& attributeMap = AttributeMap());
219 
221  void draw(const CDCSegment3D& segment3D, const AttributeMap& attributeMap = AttributeMap());
222 
224  void draw(const CDCAxialSegmentPair& axialSegmentPair, const AttributeMap& attributeMap = AttributeMap());
225 
227  void draw(const CDCSegmentPair& segmentPair, const AttributeMap& attributeMap = AttributeMap());
228 
230  void draw(const CDCSegmentTriple& segmentTriple, const AttributeMap& attributeMap = AttributeMap());
231 
233  void draw(const CDCTrack& track, const AttributeMap& attributeMap = AttributeMap());
234 
236  void draw(const RecoTrack& recoTrack, const AttributeMap& attributeMap = AttributeMap());
237 
239  void drawTrajectory(const MCParticle& mcParticle, const AttributeMap& attributeMap = AttributeMap());
240 
242  void drawTrajectory(const CDCSegment2D& segment, const AttributeMap& attributeMap = AttributeMap());
243 
245  void drawTrajectory(const CDCSegmentTriple& segmentTriple, const AttributeMap& attributeMap = AttributeMap());
246 
248  void drawTrajectory(const CDCTrack& track, const AttributeMap& attributeMap = AttributeMap());
249 
251  void drawTrajectory(const RecoTrack& recoTrack, const AttributeMap& attributeMap = AttributeMap());
252 
254  template<class T>
255  void draw(const T* ptr, const AttributeMap& attributeMap = AttributeMap())
256  {
257  if (ptr) draw(*ptr, attributeMap);
258  }
259 
261  template<class T>
262  void draw(const StoreArray<T>& storeArray, const AttributeMap& attributeMap = AttributeMap())
263  {
264  if (not storeArray) return;
265  drawRange(storeArray, attributeMap);
266  }
267 
269  template<class ARange>
270  void drawRange(const ARange& range, const AttributeMap& attributeMap = AttributeMap())
271  {
272  if (not m_ptrPrimitivePlotter) return;
273  PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
274  primitivePlotter.startGroup(attributeMap);
275  for (const auto& element : range) {
276  draw(element);
277  }
278  primitivePlotter.endGroup();
279  }
280 
282  template<class ARange>
283  void drawRangeWithFade(const ARange& range, const AttributeMap& attributeMap = AttributeMap())
284  {
285  if (not m_ptrPrimitivePlotter) return;
286  PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
287  primitivePlotter.startGroup(attributeMap);
288  float opacity = 1;
289  float endOpacity = 0.5;
290  int n = std::distance(std::begin(range), std::end(range));
291  if (n == 0) return;
292  float opacityFactor = std::pow(endOpacity / opacity, 1.0 / (n - 1));
293  for (const auto& element : range) {
294  const auto opacity_str = std::to_string(opacity);
295  AttributeMap elementAttributeMap{{"opacity", opacity_str}};
296  draw(element, elementAttributeMap);
297  opacity *= opacityFactor;
298  }
299  primitivePlotter.endGroup();
300  }
301 
302  private:
304  std::unique_ptr<PrimitivePlotter> m_ptrPrimitivePlotter;
305 
307  bool m_animate = false;
308 
310  bool m_forwardFade = false;
311 
312  };
313  }
315 }
Belle2::TrackFindingCDC::EventDataPlotter::startAnimationGroup
void startAnimationGroup(const Belle2::CDCSimHit &simHit)
Start a group in the underlying plotter with an animation uncovering the elements at the time of flig...
Definition: EventDataPlotter.cc:162
Belle2::TrackFindingCDC::CDCRecoHit3D
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:62
Belle2::TrackFindingCDC::CDCTrack
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:51
Belle2::TrackFindingCDC::EventDataPlotter::m_animate
bool m_animate
Memory for the flag if the event data should be animated. If animation is supported is backend depend...
Definition: EventDataPlotter.h:315
Belle2::TrackFindingCDC::CDCSegmentPair
Class representing a pair of one reconstructed axial segement and one stereo segment in adjacent supe...
Definition: CDCSegmentPair.h:44
Belle2::TrackFindingCDC::PrimitivePlotter::endGroup
virtual void endGroup()
Indicates the end of a group of drawn elements.
Definition: PrimitivePlotter.cc:102
Belle2::CDCHit
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:51
Belle2::TrackFindingCDC::EventDataPlotter::m_ptrPrimitivePlotter
std::unique_ptr< PrimitivePlotter > m_ptrPrimitivePlotter
Reference to the primitivePlotter instance used as backend for the draw commands.
Definition: EventDataPlotter.h:312
Belle2::TrackFindingCDC::EventDataPlotter::setCanvasWidth
void setCanvasWidth(float width)
Setter for the canvas width in pixels.
Definition: EventDataPlotter.cc:130
Belle2::TrackFindingCDC::EventDataPlotter::EventDataPlotter
EventDataPlotter(bool animate=false, bool forwardFade=false)
Default constructor for ROOT compatibility. Uses an SVGPrimitivePlotter as backend.
Belle2::TrackFindingCDC::EventDataPlotter::drawRange
void drawRange(const ARange &range, const AttributeMap &attributeMap=AttributeMap())
Draws a range iterable collection of drawable elements.
Definition: EventDataPlotter.h:278
Belle2::TrackFindingCDC::Circle2D
A two dimensional circle in its natural representation using center and radius as parameters.
Definition: Circle2D.h:36
Belle2::TrackFindingCDC::CDCSegment3D
A segment consisting of three dimensional reconstructed hits.
Definition: CDCSegment3D.h:36
Belle2::CDCSimHit
Example Detector.
Definition: CDCSimHit.h:33
Belle2::TrackFindingCDC::PrimitivePlotter::AttributeMap
Belle2::TrackFindingCDC::AttributeMap AttributeMap
A map type for attributes names to values for additional drawing information.
Definition: PrimitivePlotter.h:39
Belle2::TrackFindingCDC::EventDataPlotter::getCanvasWidth
float getCanvasWidth() const
Getter for the canvas width in pixels.
Definition: EventDataPlotter.cc:110
Belle2::TrackFindingCDC::CDCTrajectory2D
Particle trajectory as it is seen in xy projection represented as a circle.
Definition: CDCTrajectory2D.h:46
Belle2::TrackFindingCDC::EventDataPlotter::save
const std::string save(const std::string &fileName)
Saves the current plot stead to a file.
Definition: EventDataPlotter.cc:74
Belle2::TrackFindingCDC::EventDataPlotter::draw
void draw(const Belle2::TrackFindingCDC::Circle2D &circle, AttributeMap attributeMap=AttributeMap())
Draws a filled circle.
Belle2::TrackFindingCDC::EventDataPlotter::m_forwardFade
bool m_forwardFade
Memory for the flag whether the orientation of tracks segments etc should be shown as diming opacity.
Definition: EventDataPlotter.h:318
Belle2::TrackFindingCDC::EventDataPlotter::drawTrajectory
void drawTrajectory(const MCParticle &mcParticle, const AttributeMap &attributeMap=AttributeMap())
Draws the trajectory that is represented by the MC particle.
Belle2::TrackFindingCDC::EventDataPlotter::startGroup
void startGroup(const AttributeMap &attributeMap=AttributeMap())
Indicates the start of a group of drawn elements.
Definition: EventDataPlotter.cc:146
Belle2::TrackFindingCDC::EventDataPlotter::drawOuterCDCWall
void drawOuterCDCWall(const AttributeMap &attributeMap=AttributeMap())
Draw the outer wall of the CDC.
Definition: EventDataPlotter.cc:226
Belle2::TrackFindingCDC::EventDataPlotter::clear
void clear()
Clears all drawed elements from the plotter.
Definition: EventDataPlotter.cc:84
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::TrackFindingCDC::EventDataPlotter::endGroup
void endGroup()
Indicates the end of a group of drawn elements.
Definition: EventDataPlotter.cc:154
Belle2::TrackFindingCDC::EventDataPlotter::AttributeMap
PrimitivePlotter::AttributeMap AttributeMap
Forward the Attributre map from the primitive plotter.
Definition: EventDataPlotter.h:69
Belle2::TrackFindingCDC::EventDataPlotter::getAnimationTimeFromNanoSeconds
std::string getAnimationTimeFromNanoSeconds(float nanoseconds)
Converts a time given in nanoseconds to a time sting of the from "%fs".
Definition: EventDataPlotter.h:144
Belle2::TrackFindingCDC::PrimitivePlotter::startGroup
virtual void startGroup(const AttributeMap &attributeMap=AttributeMap())
Indicates the start of a group of drawn elements.
Definition: PrimitivePlotter.cc:97
Belle2::TrackFindingCDC::CDCRecoHit2D
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:57
Belle2::TrackFindingCDC::CDCAxialSegmentPair
Class representing a pair of reconstructed axial segements in adjacent superlayer.
Definition: CDCAxialSegmentPair.h:41
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::CDCTangent
Class representating a linear track piece between two oriented wire hits.
Definition: CDCTangent.h:50
Belle2::TrackFindingCDC::EventDataPlotter::drawSuperLayerBoundaries
void drawSuperLayerBoundaries(const AttributeMap &attributeMap=AttributeMap())
Draw the super layer bounds of the CDC.
Definition: EventDataPlotter.cc:242
Belle2::TrackFindingCDC::EventDataPlotter::drawRangeWithFade
void drawRangeWithFade(const ARange &range, const AttributeMap &attributeMap=AttributeMap())
Draws a range iterable collection of drawable elements.
Definition: EventDataPlotter.h:291
Belle2::TrackFindingCDC::CDCWireHitCluster
An aggregation of CDCWireHits.
Definition: CDCWireHitCluster.h:31
Belle2::TrackFindingCDC::PrimitivePlotter
A base class for plots of primitive objects.
Definition: PrimitivePlotter.h:35
Belle2::TrackFindingCDC::EventDataPlotter::setCanvasHeight
void setCanvasHeight(float height)
Setter for the canvas height in pixels The canvas height denotes the size of the image being produced...
Definition: EventDataPlotter.cc:138
Belle2::TrackFindingCDC::CDCWireSuperLayer
Class representating a sense wire superlayer in the central drift chamber.
Definition: CDCWireSuperLayer.h:53
Belle2::TrackFindingCDC::EventDataPlotter::drawLine
void drawLine(float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap())
Draws a straight Line.
Definition: EventDataPlotter.cc:258
Belle2::TrackFindingCDC::CDCWire
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:60
Belle2::TrackFindingCDC::CDCSegment2D
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:40
Belle2::TrackFindingCDC::EventDataPlotter::drawInteractionPoint
void drawInteractionPoint()
Marks the position of the interaction point with a filled circle.
Definition: EventDataPlotter.cc:198
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::TrackFindingCDC::EventDataPlotter::getBoundingBox
BoundingBox getBoundingBox() const
Getter for the current bounding box.
Definition: EventDataPlotter.cc:92
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::TrackFindingCDC::CDCWireHit
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:65
Belle2::TrackFindingCDC::CDCSegmentTriple
Class representing a triple of reconstructed segements in adjacent superlayer.
Definition: CDCSegmentTriple.h:42
Belle2::TrackFindingCDC::CDCWireTopology
Class representating the sense wire arrangement in the whole of the central drift chamber.
Definition: CDCWireTopology.h:54
Belle2::TrackFindingCDC::EventDataPlotter::setBoundingBox
void setBoundingBox(const BoundingBox &boundingBox)
Setter for the bounding box of all drawed objects.
Definition: EventDataPlotter.cc:102
Belle2::TrackFindingCDC::EventDataPlotter::getCanvasHeight
float getCanvasHeight() const
Getter for the canvas height in pixels.
Definition: EventDataPlotter.cc:120
Belle2::TrackFindingCDC::EventDataPlotter::drawInnerCDCWall
void drawInnerCDCWall(const AttributeMap &attributeMap=AttributeMap())
Draw the inner wall of the CDC.
Definition: EventDataPlotter.cc:210