8#include <tracking/trackFindingCDC/display/EventDataPlotter.h>
10#include <tracking/trackFindingCDC/display/SVGPrimitivePlotter.h>
11#include <tracking/trackFindingCDC/display/BoundingBox.h>
13#include <tracking/trackingUtilities/eventdata/tracks/CDCSegmentPair.h>
14#include <tracking/trackingUtilities/eventdata/tracks/CDCAxialSegmentPair.h>
15#include <tracking/trackingUtilities/eventdata/tracks/CDCSegmentTriple.h>
16#include <tracking/trackingUtilities/eventdata/tracks/CDCTrack.h>
18#include <tracking/trackingUtilities/eventdata/segments/CDCWireHitCluster.h>
19#include <tracking/trackingUtilities/eventdata/segments/CDCSegment2D.h>
20#include <tracking/trackingUtilities/eventdata/segments/CDCSegment3D.h>
22#include <tracking/trackingUtilities/eventdata/hits/CDCTangent.h>
23#include <tracking/trackingUtilities/eventdata/hits/CDCRecoHit3D.h>
24#include <tracking/trackingUtilities/eventdata/hits/CDCRecoHit2D.h>
25#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
27#include <cdc/topology/CDCWireTopology.h>
29#include <tracking/trackingUtilities/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>
45using namespace TrackFindingCDC;
46using namespace TrackingUtilities;
50 AttributeMap{{
"stroke",
"orange"}, {
"stroke-width",
"0.55"}, {
"fill",
"none"}}))
52, m_forwardFade(forwardFade)
63 B2ASSERT(
"EventDataPlotter initialized with nullptr. Using default backend SVGPrimitivePlotter.",
78 return primitivePlotter.
save(fileName);
88 return primitivePlotter.
clear();
172 primitivePlotter.
startGroup(groupAttributeMap);
186 const CDCHit& hit = *ptrHit;
203 const Circle2D interactionPoint(center, radius);
205 AttributeMap attributeMap{{
"fill",
"black"}, {
"stroke-width",
"0"}};
207 draw(interactionPoint, attributeMap);
223 primitivePlotter.
drawCircle(centerX, centerY, innerR, attributeMap);
239 primitivePlotter.
drawCircle(centerX, centerY, outerR, attributeMap);
252 float outerR = wireSuperLayer.getInnerCylindricalR();
253 primitivePlotter.
drawCircle(centerX, centerY, outerR, attributeMap);
267 primitivePlotter.
drawLine(startX, startY, endX, endY, attributeMap);
276 float radius = circle.
radius();
278 if (not attributeMap.count(
"fill") or attributeMap[
"fill"] !=
"") {
279 if (attributeMap.count(
"stroke")) {
280 attributeMap[
"fill"] = attributeMap[
"stroke"];
281 attributeMap.erase(
"stroke");
290 primitivePlotter.
drawCircle(x, y, radius, attributeMap);
296 const float wireRadius = 0.25;
311 for (
const CDCWire& wire : wireLayer) {
323 wireSuperLayer.isAxial() ?
"black" :
"gray"
330 superLayerAttributeMap.insert(defaultSuperLayerAttributeMap.begin(),
331 defaultSuperLayerAttributeMap.end());
332 draw(wireSuperLayer, superLayerAttributeMap);
345 ROOT::Math::XYZVector position = simHit.
getPosTrack();
346 float x = position.X();
347 float y = position.Y();
350 primitivePlotter.
drawCircle(x, y, radius, attributeMap);
353 const float momentumToArrowLength = 1.5;
355 ROOT::Math::XYZVector momentum = simHit.
getMomentum();
356 float endX = x + momentum.X() * momentumToArrowLength;
357 float endY = y + momentum.Y() * momentumToArrowLength;
359 primitivePlotter.
drawArrow(x, y, endX, endY, attributeMap);
368 draw(wireHit, attributeMap);
381 float x = refPos.
x();
382 float y = refPos.
y();
385 if (fabs(radius) < 100) {
386 primitivePlotter.
drawCircle(x, y, radius, attributeMap);
405 float x = refPos2D.
x();
406 float y = refPos2D.
y();
408 primitivePlotter.
drawCircle(x, y, radius, attributeMap);
410 if (not recoPos2D.
hasNAN()) {
411 float supportPointRadius = 0.2;
412 Circle2D supportPoint(recoPos2D, supportPointRadius);
413 draw(supportPoint, attributeMap);
426 const float fromX = fromPos.
x();
427 const float fromY = fromPos.
y();
430 const float toX = toPos.
x();
431 const float toY = toPos.
y();
433 primitivePlotter.
drawLine(fromX, fromY, toX, toY, attributeMap);
435 float touchPointRadius = 0.015;
436 const Circle2D fromTouchPoint(fromPos, touchPointRadius);
437 draw(fromTouchPoint, attributeMap);
439 const Circle2D toTouchPoint(toPos, touchPointRadius);
440 draw(toTouchPoint, attributeMap);
460 defaultAttributeMap[
"stroke"] =
"red";
461 }
else if (charge < 0) {
462 defaultAttributeMap[
"stroke"] =
"blue";
464 defaultAttributeMap[
"stroke"] =
"green";
468 attributeMap.insert(defaultAttributeMap.begin(), defaultAttributeMap.end());
471 if (trajectoryExit.
hasNAN()) {
479 if (trajectoryExit.
hasNAN()) {
484 float centerX = center.
x();
485 float centerY = center.
y();
487 primitivePlotter.
drawCircle(centerX, centerY, radius);
492 float startX = start.x();
493 float startY = start.y();
495 float endX = trajectoryExit.
x();
496 float endY = trajectoryExit.
y();
498 const int curvature = -charge;
499 const bool sweepFlag = curvature > 0;
503 const bool longArc = (trajectory2D.
calcArcLength2D(trajectoryExit) > 0) ? false :
true;
515 if (trajectoryExit.
hasNAN()) {
516 B2WARNING(
"Could not compute point off exit in a straight line case.");
519 float startX = start.x();
520 float startY = start.y();
522 float endX = trajectoryExit.
x();
523 float endY = trajectoryExit.
y();
524 primitivePlotter.
drawLine(startX, startY, endX, endY, attributeMap);
561 if (not ptrFromSegment or not ptrToSegment)
return;
566 const Vector2D& fromPos = fromSegment.back().getWire().getRefPos2D();
567 const Vector2D& toPos = toSegment.front().getWire().getRefPos2D();
570 B2WARNING(
"Center of mass of first segment in a pair contains NAN values.");
575 B2WARNING(
"Center of mass of second segment in a pair contains NAN values.");
579 const float fromX = fromPos.
x();
580 const float fromY = fromPos.
y();
582 const float toX = toPos.
x();
583 const float toY = toPos.
y();
585 primitivePlotter.
drawArrow(fromX, fromY, toX, toY, attributeMap);
596 if (not ptrFromSegment or not ptrToSegment)
return;
601 const Vector2D& fromPos = fromSegment.back().getWire().getRefPos2D();
602 const Vector2D& toPos = toSegment.front().getWire().getRefPos2D();
605 B2WARNING(
"Center of mass of first segment in a pair contains NAN values.");
610 B2WARNING(
"Center of mass of second segment in a pair contains NAN values.");
614 const float fromX = fromPos.
x();
615 const float fromY = fromPos.
y();
617 const float toX = toPos.
x();
618 const float toY = toPos.
y();
620 primitivePlotter.
drawArrow(fromX, fromY, toX, toY, attributeMap);
632 if (not ptrStartSegment or not ptrMiddleSegment or not ptrEndSegment)
return;
638 const Vector2D& startBackPos2D = startSegment.back().getRefPos2D();
639 const Vector2D& middleFrontPos2D = middleSegment.front().getRefPos2D();
640 const Vector2D& middleBackPos2D = middleSegment.back().getRefPos2D();
641 const Vector2D& endFrontPos2D = endSegment.front().getRefPos2D();
643 if (startBackPos2D.
hasNAN()) {
644 B2WARNING(
"Back position of start segment in a triple contains NAN values.");
648 if (middleFrontPos2D.
hasNAN()) {
649 B2WARNING(
"Front position of middle segment in a triple contains NAN values.");
653 if (middleBackPos2D.
hasNAN()) {
654 B2WARNING(
"Back position of middle segment in a triple contains NAN values.");
658 if (endFrontPos2D.
hasNAN()) {
659 B2WARNING(
"Front position of end segment in a triple contains NAN values.");
663 const float startBackX = startBackPos2D.
x();
664 const float startBackY = startBackPos2D.
y();
666 const float middleFrontX = middleFrontPos2D.
x();
667 const float middleFrontY = middleFrontPos2D.
y();
669 primitivePlotter.
drawArrow(startBackX, startBackY, middleFrontX, middleFrontY, attributeMap);
671 const float middleBackX = middleBackPos2D.
x();
672 const float middleBackY = middleBackPos2D.
y();
674 const float endFrontX = endFrontPos2D.
x();
675 const float endFrontY = endFrontPos2D.
y();
677 primitivePlotter.
drawArrow(middleBackX, middleBackY, endFrontX, endFrontY, attributeMap);
697 const CDCHit& hit = *ptrHit;
712 draw(trajectory2D, attributeMap);
718 draw(segment.getTrajectory2D(), attributeMap);
729 draw(track.getStartTrajectory3D().getTrajectory2D(), attributeMap);
741 std::vector<std::array<float, 2>> points;
742 std::vector<std::array<float, 2>> tangents;
746 if (!recoHit->useInFit())
755 const auto* fittedResult = trackPoint->getFitterInfo();
756 if (not fittedResult) {
757 B2WARNING(
"Skipping unfitted track point");
760 const genfit::MeasuredStateOnPlane& state = fittedResult->getFittedState();
761 state.getPosMomCov(pos, mom, cov);
762 }
catch (
const genfit::Exception&) {
763 B2WARNING(
"Skipping state with strange pos, mom or cov");
772 points.push_back({{x, y}});
773 tangents.push_back({{px, py}});
775 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.
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.
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
const std::vector< CDCWireSuperLayer > & getWireSuperLayers() const
Getter for the underlying storing superlayer vector.
Class representing a sense wire in the central drift chamber.
const ROOT::Math::XYVector & getRefPos2D() const
Getter for the wire reference position for 2D tracking Gives the wire's reference position projected ...
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.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
A two dimensional rectangle that keeps track of the extend of a drawing.
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.
void draw(const TrackingUtilities::Circle2D &circle, AttributeMap attributeMap=AttributeMap())
Draws a filled circle.
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 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".
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.
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 !
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 ROOT::Math::XYVector & getRefPos2D() const
The two dimensional reference position (z=0) of the underlying wire.
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.
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 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.
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,...
HepGeom::Vector3D< double > Vector3D
3D Vector
Abstract base class for different kinds of events.