8#include <tracking/trackFindingCDC/display/EventDataPlotter.h>
10#include <tracking/trackFindingCDC/display/SVGPrimitivePlotter.h>
11#include <tracking/trackFindingCDC/display/BoundingBox.h>
13#include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentPair.h>
14#include <tracking/trackFindingCDC/eventdata/tracks/CDCAxialSegmentPair.h>
15#include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentTriple.h>
16#include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
18#include <tracking/trackFindingCDC/eventdata/segments/CDCWireHitCluster.h>
19#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
20#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment3D.h>
22#include <tracking/trackFindingCDC/eventdata/hits/CDCTangent.h>
23#include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit3D.h>
24#include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit2D.h>
25#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
27#include <tracking/trackFindingCDC/topology/CDCWireTopology.h>
29#include <tracking/trackFindingCDC/geometry/Circle2D.h>
31#include <cdc/dataobjects/CDCSimHit.h>
32#include <cdc/dataobjects/CDCHit.h>
34#include <framework/logging/Logger.h>
36#include <tracking/dataobjects/RecoTrack.h>
37#include <mdst/dataobjects/MCParticle.h>
39#include <TMatrixDSym.h>
44using namespace TrackFindingCDC;
48 AttributeMap{{
"stroke",
"orange"}, {
"stroke-width",
"0.55"}, {
"fill",
"none"}}))
50, m_forwardFade(forwardFade)
57 : m_ptrPrimitivePlotter(
std::move(ptrPrimitivePlotter))
59 , m_forwardFade(forwardFade)
61 B2ASSERT(
"EventDataPlotter initialized with nullptr. Using default backend SVGPrimitivePlotter.",
66 : m_ptrPrimitivePlotter(eventDataPlotter.m_ptrPrimitivePlotter->clone())
67 , m_animate(eventDataPlotter.m_animate)
68 , m_forwardFade(eventDataPlotter.m_forwardFade)
76 return primitivePlotter.
save(fileName);
86 return primitivePlotter.
clear();
170 primitivePlotter.
startGroup(groupAttributeMap);
184 const CDCHit& hit = *ptrHit;
201 const Circle2D interactionPoint(center, radius);
203 AttributeMap attributeMap{{
"fill",
"black"}, {
"stroke-width",
"0"}};
205 draw(interactionPoint, attributeMap);
221 primitivePlotter.
drawCircle(centerX, centerY, innerR, attributeMap);
237 primitivePlotter.
drawCircle(centerX, centerY, outerR, attributeMap);
250 float outerR = wireSuperLayer.getInnerCylindricalR();
251 primitivePlotter.
drawCircle(centerX, centerY, outerR, attributeMap);
265 primitivePlotter.
drawLine(startX, startY, endX, endY, attributeMap);
274 float radius = circle.
radius();
276 if (not attributeMap.count(
"fill") or attributeMap[
"fill"] !=
"") {
277 if (attributeMap.count(
"stroke")) {
278 attributeMap[
"fill"] = attributeMap[
"stroke"];
279 attributeMap.erase(
"stroke");
288 primitivePlotter.
drawCircle(x, y, radius, attributeMap);
294 const float wireRadius = 0.25;
309 for (
const CDCWire& wire : wireLayer) {
321 wireSuperLayer.isAxial() ?
"black" :
"gray"
328 superLayerAttributeMap.insert(defaultSuperLayerAttributeMap.begin(),
329 defaultSuperLayerAttributeMap.end());
330 draw(wireSuperLayer, superLayerAttributeMap);
343 ROOT::Math::XYZVector position = simHit.
getPosTrack();
344 float x = position.X();
345 float y = position.Y();
348 primitivePlotter.
drawCircle(x, y, radius, attributeMap);
351 const float momentumToArrowLength = 1.5;
353 ROOT::Math::XYZVector momentum = simHit.
getMomentum();
354 float endX = x + momentum.X() * momentumToArrowLength;
355 float endY = y + momentum.Y() * momentumToArrowLength;
357 primitivePlotter.
drawArrow(x, y, endX, endY, attributeMap);
366 draw(wireHit, attributeMap);
379 float x = refPos.
x();
380 float y = refPos.
y();
383 if (fabs(radius) < 100) {
384 primitivePlotter.
drawCircle(x, y, radius, attributeMap);
403 float x = refPos2D.
x();
404 float y = refPos2D.
y();
406 primitivePlotter.
drawCircle(x, y, radius, attributeMap);
408 if (not recoPos2D.
hasNAN()) {
409 float supportPointRadius = 0.2;
410 Circle2D supportPoint(recoPos2D, supportPointRadius);
411 draw(supportPoint, attributeMap);
424 const float fromX = fromPos.
x();
425 const float fromY = fromPos.
y();
428 const float toX = toPos.
x();
429 const float toY = toPos.
y();
431 primitivePlotter.
drawLine(fromX, fromY, toX, toY, attributeMap);
433 float touchPointRadius = 0.015;
434 const Circle2D fromTouchPoint(fromPos, touchPointRadius);
435 draw(fromTouchPoint, attributeMap);
437 const Circle2D toTouchPoint(toPos, touchPointRadius);
438 draw(toTouchPoint, attributeMap);
458 defaultAttributeMap[
"stroke"] =
"red";
459 }
else if (charge < 0) {
460 defaultAttributeMap[
"stroke"] =
"blue";
462 defaultAttributeMap[
"stroke"] =
"green";
466 attributeMap.insert(defaultAttributeMap.begin(), defaultAttributeMap.end());
469 if (trajectoryExit.
hasNAN()) {
477 if (trajectoryExit.
hasNAN()) {
482 float centerX = center.
x();
483 float centerY = center.
y();
485 primitivePlotter.
drawCircle(centerX, centerY, radius);
490 float startX = start.x();
491 float startY = start.y();
493 float endX = trajectoryExit.
x();
494 float endY = trajectoryExit.
y();
496 const int curvature = -charge;
497 const bool sweepFlag = curvature > 0;
501 const bool longArc = (trajectory2D.
calcArcLength2D(trajectoryExit) > 0) ?
false :
true;
513 if (trajectoryExit.
hasNAN()) {
514 B2WARNING(
"Could not compute point off exit in a straight line case.");
517 float startX = start.x();
518 float startY = start.y();
520 float endX = trajectoryExit.
x();
521 float endY = trajectoryExit.
y();
522 primitivePlotter.
drawLine(startX, startY, endX, endY, attributeMap);
559 if (not ptrFromSegment or not ptrToSegment)
return;
564 const Vector2D& fromPos = fromSegment.back().getWire().getRefPos2D();
565 const Vector2D& toPos = toSegment.front().getWire().getRefPos2D();
568 B2WARNING(
"Center of mass of first segment in a pair contains NAN values.");
573 B2WARNING(
"Center of mass of second segment in a pair contains NAN values.");
577 const float fromX = fromPos.
x();
578 const float fromY = fromPos.
y();
580 const float toX = toPos.
x();
581 const float toY = toPos.
y();
583 primitivePlotter.
drawArrow(fromX, fromY, toX, toY, attributeMap);
594 if (not ptrFromSegment or not ptrToSegment)
return;
599 const Vector2D& fromPos = fromSegment.back().getWire().getRefPos2D();
600 const Vector2D& toPos = toSegment.front().getWire().getRefPos2D();
603 B2WARNING(
"Center of mass of first segment in a pair contains NAN values.");
608 B2WARNING(
"Center of mass of second segment in a pair contains NAN values.");
612 const float fromX = fromPos.
x();
613 const float fromY = fromPos.
y();
615 const float toX = toPos.
x();
616 const float toY = toPos.
y();
618 primitivePlotter.
drawArrow(fromX, fromY, toX, toY, attributeMap);
630 if (not ptrStartSegment or not ptrMiddleSegment or not ptrEndSegment)
return;
636 const Vector2D& startBackPos2D = startSegment.back().getRefPos2D();
637 const Vector2D& middleFrontPos2D = middleSegment.front().getRefPos2D();
638 const Vector2D& middleBackPos2D = middleSegment.back().getRefPos2D();
639 const Vector2D& endFrontPos2D = endSegment.front().getRefPos2D();
641 if (startBackPos2D.
hasNAN()) {
642 B2WARNING(
"Back position of start segment in a triple contains NAN values.");
646 if (middleFrontPos2D.
hasNAN()) {
647 B2WARNING(
"Front position of middle segment in a triple contains NAN values.");
651 if (middleBackPos2D.
hasNAN()) {
652 B2WARNING(
"Back position of middle segment in a triple contains NAN values.");
656 if (endFrontPos2D.
hasNAN()) {
657 B2WARNING(
"Front position of end segment in a triple contains NAN values.");
661 const float startBackX = startBackPos2D.
x();
662 const float startBackY = startBackPos2D.
y();
664 const float middleFrontX = middleFrontPos2D.
x();
665 const float middleFrontY = middleFrontPos2D.
y();
667 primitivePlotter.
drawArrow(startBackX, startBackY, middleFrontX, middleFrontY, attributeMap);
669 const float middleBackX = middleBackPos2D.
x();
670 const float middleBackY = middleBackPos2D.
y();
672 const float endFrontX = endFrontPos2D.
x();
673 const float endFrontY = endFrontPos2D.
y();
675 primitivePlotter.
drawArrow(middleBackX, middleBackY, endFrontX, endFrontY, attributeMap);
695 const CDCHit& hit = *ptrHit;
710 draw(trajectory2D, attributeMap);
716 draw(segment.getTrajectory2D(), attributeMap);
727 draw(track.getStartTrajectory3D().getTrajectory2D(), attributeMap);
739 std::vector<std::array<float, 2>> points;
740 std::vector<std::array<float, 2>> tangents;
744 if (!recoHit->useInFit())
753 const auto* fittedResult = trackPoint->getFitterInfo();
754 if (not fittedResult) {
755 B2WARNING(
"Skipping unfitted track point");
758 const genfit::MeasuredStateOnPlane& state = fittedResult->getFittedState();
759 state.getPosMomCov(pos, mom, cov);
760 }
catch (
const genfit::Exception&) {
761 B2WARNING(
"Skipping state with strange pos, mom or cov");
770 points.push_back({{x, y}});
771 tangents.push_back({{px, py}});
773 primitivePlotter.
drawCurve(points, tangents, attributeMap);
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
double getFlightTime() const
The method to get flight time.
B2Vector3D getPosTrack() const
The method to get position on the track.
B2Vector3D getMomentum() const
The method to get momentum.
A Class to store the Monte Carlo particle information.
ROOT::Math::XYZVector getVertex() const
Return production vertex position, shorthand for getProductionVertex().
float getCharge() const
Return the particle charge defined in TDatabasePDG.
float getProductionTime() const
Return production time in ns.
ROOT::Math::XYZVector getMomentum() const
Return momentum.
This is the Reconstruction Event-Data Model Track.
const std::vector< genfit::AbsTrackRep * > & getRepresentations() const
Return a list of track representations. You are not allowed to modify or delete them!
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
std::vector< Belle2::RecoTrack::UsedCDCHit * > getCDCHitList() const
Return an unsorted list of cdc hits.
const genfit::TrackPoint * getCreatedTrackPoint(const RecoHitInformation *recoHitInformation) const
Get a pointer to the TrackPoint that was created from this hit.
std::vector< RecoHitInformation * > getRecoHitInformations(bool getSorted=false) const
Return a list of all RecoHitInformations associated with the RecoTrack.
A two dimensional rectangle that keeps track of the extend of a drawing.
Class representing a pair of reconstructed axial segments in adjacent superlayer.
const CDCAxialSegment2D * getEndSegment() const
Getter for the end segment.
const CDCAxialSegment2D * getStartSegment() const
Getter for the start segment.
Class representing a two dimensional reconstructed hit in the central drift chamber.
const CDCWireHit & getWireHit() const
Getter for the wire hit associated with the reconstructed hit.
Vector2D getRecoPos2D() const
Getter for the position in the reference plane.
Class representing a three dimensional reconstructed hit.
CDCRecoHit2D getRecoHit2D() const
Constructs a two dimensional reconstructed hit by carrying out the stereo ! projection to the wire re...
A reconstructed sequence of two dimensional hits in one super layer.
A segment consisting of three dimensional reconstructed hits.
Class representing a pair of one reconstructed axial segment and one stereo segment in adjacent super...
const CDCSegment2D * getToSegment() const
Getter for the to segment.
const CDCSegment2D * getFromSegment() const
Getter for the from segment.
Class representing a triple of reconstructed segments in adjacent superlayer.
const CDCStereoSegment2D * getMiddleSegment() const
Getter for the middle stereo segment.
const CDCAxialSegment2D * getEndSegment() const
Getter for the end axial segment.
const CDCTrajectory3D & getTrajectory3D() const
Getter for the three dimensional helix trajectory.
const CDCAxialSegment2D * getStartSegment() const
Getter for the start axial segment.
Class representing a linear track piece between two oriented wire hits.
const Vector2D & getFromRecoPos2D() const
Getter for the touching point of the tangent to the first drift circle.
Vector2D getToRecoPos2D() const
Getter for the touching point of the tangent to the second drift circle.
Class representing a sequence of three dimensional reconstructed hits.
Particle trajectory as it is seen in xy projection represented as a circle.
PerigeeCircle getGlobalCircle() const
Getter for the circle in global coordinates.
Vector2D getOuterExit(double factor=1) const
Calculates the point where the trajectory meets the outer wall of the CDC.
double calcArcLength2D(const Vector2D &point) const
Calculate the travel distance from the start position of the trajectory.
ESign getChargeSign() const
Gets the charge sign of the trajectory.
Vector2D getSupport() const
Get the support point of the trajectory in global coordinates.
const UncertainPerigeeCircle & getLocalCircle() const
Getter for the circle in local coordinates.
Vector2D getInnerExit() const
Calculates the point where the trajectory meets the inner wall of the CDC.
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
An aggregation of CDCWireHits.
Class representing a hit wire in the central drift chamber.
const CDCHit * getHit() const
Getter for the CDCHit pointer into the StoreArray.
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
const Vector2D & getRefPos2D() const
The two dimensional reference position (z=0) of the underlying wire.
Class representing a sense wire layer in the central drift chamber.
Class representing a sense wire superlayer in the central drift chamber.
double getInnerCylindricalR() const
Getter for the inner radius of the layer as retrieved from the CDCGeometryPar by the inner most layer...
double getOuterCylindricalR() const
Getter for the outer radius of the layer as retrieved from the CDCGeometryPar by the outer most layer...
Class representing the sense wire arrangement in the whole of the central drift chamber.
const std::vector< Belle2::TrackFindingCDC::CDCWireSuperLayer > & getWireSuperLayers() const
Getter for the underlying storing superlayer vector.
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
Class representing a sense wire in the central drift chamber.
const Vector2D & getRefPos2D() const
Getter for the wire reference position for 2D tracking Gives the wire's reference position projected ...
A two dimensional circle in its natural representation using center and radius as parameters.
double radius() const
Getter for the signed radius.
Vector2D center() const
Getter for the central point of the circle.
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 drawn objects.
bool m_forwardFade
Memory for the flag whether the orientation of tracks segments etc should be shown as dimming 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 Attribute 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.
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 drawn 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 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 string of the from "%fs".
Vector2D center() const
Getter for the center of the circle. If it was a line both components will be infinity.
bool isCircle() const
Indicates if the perigee parameters represent a closed circle.
double absRadius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
A base class for plots of primitive objects.
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 drawn objects.
float getCanvasWidth()
Getter for the canvas width in pixels.
virtual void drawCurve(const std::vector< std::array< float, 2 > > &points, const std::vector< std::array< float, 2 > > &tangents, const AttributeMap &attributeMap=AttributeMap())
Adds a smooth curve to the plot.
const BoundingBox & getBoundingBox() const
Getter for the bounding box of all drawn objects.
virtual void startGroup(const AttributeMap &attributeMap=AttributeMap())
Indicates the start of a group of drawn elements.
void setCanvasWidth(float width)
Setter for the canvas width in pixels.
virtual void drawCircleArc(float startX, float startY, float endX, float endY, float radius, bool longArc, bool sweepFlag, const AttributeMap &attributeMap=AttributeMap())
Adds a circle arc to the plot.
virtual void drawArrow(float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap())
Adds an arrow to the plot.
virtual const std::string save(const std::string &fileName)
Saves the current plot state to a file.
float getCanvasHeight()
Getter for the canvas height in pixels.
virtual void clear()
Clears all drawn elements from the plotter.
virtual void drawLine(float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap())
Adds a line to the plot.
virtual void drawCircle(float centerX, float centerY, float radius, const AttributeMap &attributeMap=AttributeMap())
Adds a circle to the plot.
virtual void endGroup()
Indicates the end of a group of drawn elements.
A concrete plotter that can draw primitive objects to standalone SVG files.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
double x() const
Getter for the x coordinate.
bool hasNAN() const
Checks if one of the coordinates is NAN.
double y() const
Getter for the y coordinate.
A three dimensional vector.
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
bool isPrimaryParticle() const
Check if particle is a primary particle which was created by the generator (and not,...
Abstract base class for different kinds of events.