8#include <tracking/trackFindingCDC/display/CDCSVGPlotter.h>
9#include <tracking/trackFindingCDC/display/SVGPrimitivePlotter.h>
10#include <tracking/trackFindingCDC/display/Styling.h>
12#include <tracking/trackingUtilities/rootification/StoreWrappedObjPtr.h>
14#include <tracking/trackFindingCDC/filters/axialSegmentPair/MCAxialSegmentPairFilter.h>
15#include <tracking/trackFindingCDC/filters/segmentPair/MCSegmentPairFilter.h>
16#include <tracking/trackFindingCDC/filters/segmentTriple/MCSegmentTripleFilter.h>
17#include <tracking/trackFindingCDC/mclookup/CDCMCSegment2DLookUp.h>
19#include <tracking/trackingUtilities/eventdata/tracks/CDCTrack.h>
20#include <tracking/trackingUtilities/eventdata/tracks/CDCSegmentTriple.h>
21#include <tracking/trackingUtilities/eventdata/tracks/CDCAxialSegmentPair.h>
22#include <tracking/trackingUtilities/eventdata/tracks/CDCSegmentPair.h>
23#include <tracking/trackingUtilities/eventdata/segments/CDCSegment2D.h>
24#include <tracking/trackingUtilities/eventdata/segments/CDCWireHitCluster.h>
25#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
27#include <tracking/trackingUtilities/geometry/Vector3D.h>
28#include <tracking/trackingUtilities/geometry/Vector2D.h>
30#include <tracking/trackingUtilities/utilities/ReversedRange.h>
32#include <tracking/dataobjects/RecoTrack.h>
34#include <framework/datastore/StoreArray.h>
36#include <cdc/dataobjects/CDCSimHit.h>
37#include <cdc/dataobjects/CDCHit.h>
39#include <mdst/dataobjects/MCParticle.h>
48using namespace TrackFindingCDC;
49using namespace TrackingUtilities;
52 template<
bool a_drawTrajectory,
class AObject>
53 struct DrawTrajectoryHelper;
55 template<
class AObject>
56 struct DrawTrajectoryHelper<true, AObject> {
58 static void draw(EventDataPlotter& plotter, AObject&
object,
const AttributeMap& attributeMap)
60 plotter.drawTrajectory(
object, attributeMap);
64 template<
class AObject>
65 struct DrawTrajectoryHelper<false, AObject> {
67 static void draw(EventDataPlotter& plotter, AObject&
object,
const AttributeMap& attributeMap)
69 plotter.draw(
object, attributeMap);
76 class FlightTimeOrder {
79 bool operator()(
const CDCSimHit* x,
const CDCSimHit* y)
const
81 return (x->getFlightTime() < y->getFlightTime());
86static void printDataStoreContent()
88 B2INFO(
"Current content of the DataStore:");
89 B2INFO(
"StoreArrays:");
94 B2INFO(
"StoreObjPtr:");
100const AttributeMap c_defaultSVGAttributes({
101 {
"stroke",
"orange"},
102 {
"stroke-width",
"0.55"},
104 {
"transform",
"translate(0, 1120) scale(1,-1)"}
116 int default_width = 1120;
117 int default_height = 1120;
136 AttributeMap attributeMap;
137 attributeMap.emplace(
"stroke", stroke);
143 AttributeMap attributeMap;
144 attributeMap.emplace(
"stroke", stroke);
150 AttributeMap attributeMap;
151 attributeMap.emplace(
"stroke", stroke);
161 const std::string& stroke,
162 const std::string& strokeWidth)
165 if (stroke !=
"") styling.
setStroke(stroke);
171 const std::string& stroke,
172 const std::string& strokeWidth)
174 B2INFO(
"Drawing simulated hits");
176 if (not storeArray) {
177 B2WARNING(
"StoreArray " << storeArrayName <<
" not present");
178 printDataStoreContent();
181 std::vector<CDCSimHit> simHitsRelatedToHits;
182 for (
const CDCHit& hit : storeArray) {
183 simHitsRelatedToHits.push_back(*hit.getRelated<
CDCSimHit>(
"CDCSimHits"));
185 B2INFO(
"#CDCSimHits: " << storeArray.
getEntries());
197 const std::string& stroke,
198 const std::string& strokeWidth)
201 if (stroke !=
"") styling.
setStroke(stroke);
207 const std::string& stroke,
208 const std::string& strokeWidth)
211 if (stroke !=
"") styling.
setStroke(stroke);
217 const std::string& stroke,
218 const std::string& strokeWidth)
221 if (stroke !=
"") styling.
setStroke(stroke);
223 const bool drawTrajectories =
true;
228 const std::string& stroke,
229 const std::string& strokeWidth)
232 if (stroke !=
"") styling.
setStroke(stroke);
238 const std::string& stroke,
239 const std::string& strokeWidth)
242 if (stroke !=
"") styling.
setStroke(stroke);
248 const std::string& stroke,
249 const std::string& strokeWidth)
252 if (stroke !=
"") styling.
setStroke(stroke);
258 const std::string& stroke,
259 const std::string& strokeWidth)
262 if (stroke !=
"") styling.
setStroke(stroke);
264 const bool drawTrajectories =
true;
269 const std::string& stroke,
270 const std::string& strokeWidth)
273 if (stroke !=
"") styling.
setStroke(stroke);
279 const std::string& stroke,
280 const std::string& strokeWidth)
283 if (stroke !=
"") styling.
setStroke(stroke);
285 const bool drawTrajectories =
true;
290 const std::string& stroke,
291 const std::string& strokeWidth)
294 if (stroke !=
"") styling.
setStroke(stroke);
300 const std::string& stroke,
301 const std::string& strokeWidth)
304 if (stroke !=
"") styling.
setStroke(stroke);
306 const bool drawTrajectories =
true;
311 const std::string& stroke,
312 const std::string& strokeWidth)
315 if (stroke !=
"") styling.
setStroke(stroke);
317 const bool drawTrajectories =
true;
322 const std::string& stroke,
323 const std::string& strokeWidth)
325 B2INFO(
"Drawing simulated hits connected by tof");
327 if (not hitStoreArray) {
328 B2WARNING(
"StoreArray " << hitStoreArrayName <<
" not present");
329 printDataStoreContent();
332 std::vector<CDCSimHit*> simHits;
333 for (
const CDCHit& hit : hitStoreArray) {
334 simHits.push_back(hit.getRelated<
CDCSimHit>());
338 std::map<int, std::set<CDCSimHit*, FlightTimeOrder>> simHitsByMcParticleId;
341 if (mcParticle !=
nullptr) {
343 simHitsByMcParticleId[mcTrackId].insert(simHit);
347 AttributeMap defaultAttributeMap = {{
"stroke", stroke}, {
"stroke-width", strokeWidth}};
349 for (
const auto& mcParticleIdAndSimHits : simHitsByMcParticleId) {
350 const std::set<CDCSimHit*, FlightTimeOrder>& simHitsForMcParticle =
351 mcParticleIdAndSimHits.second;
353 auto drawConnectSimHits = [
this, &defaultAttributeMap](
CDCSimHit * fromSimHit,
CDCSimHit * toSimHit) {
357 if (fromHit ==
nullptr)
return false;
358 if (toHit ==
nullptr)
return false;
367 Vector3D toDisplacement(toSimHit->getPosTrack() - toSimHit->getPosWire());
372 bool falseOrder =
false;
373 if (fromSimHit->
getArrayIndex() > toSimHit->getArrayIndex()) {
375 bool toReassigned = toHit->getRelatedWithWeight<
MCParticle>().second < 0;
376 if (not fromReassigned and not toReassigned) {
381 AttributeMap attributeMap = defaultAttributeMap;
383 attributeMap[
"stroke"] =
"red";
384 attributeMap[
"stroke-width"] =
"1.0";
386 draw(fromRecoHit2D, attributeMap);
387 draw(toRecoHit2D, attributeMap);
390 const float fromX = fromPos.
x();
391 const float fromY = fromPos.
y();
394 const float toX = toPos.
x();
395 const float toY = toPos.
y();
401 std::ignore = std::adjacent_find(simHitsForMcParticle.begin(),
402 simHitsForMcParticle.end(),
419template<
class ACDCHitCollection>
422 B2INFO(
"Draw wrong right left passage information from " << hitCollectionsStoreObjName);
424 if (not storedHitCollections) {
425 B2WARNING(hitCollectionsStoreObjName <<
"does not exist in current DataStore");
426 printDataStoreContent();
430 std::vector<ACDCHitCollection>& hitCollections = *storedHitCollections;
431 B2INFO(
"#HitCollections: " << hitCollections.size());
436 for (
const ACDCHitCollection& hitCollection : hitCollections) {
439 double rlPurity = mcHitCollectionLookUp.
getRLPurity(&hitCollection);
443 if (rlPurity < 0.5 and hitCollection.getAutomatonCell().hasAliasFlag())
continue;
446 if (correctRLVote < 0 and hitCollection.getAutomatonCell().hasReverseFlag())
continue;
449 for (
const auto& recoHit : hitCollection) {
450 ERightLeft rlInfo = recoHit.getRLInfo();
451 const CDCHit* hit = recoHit.getWireHit().getHit();
452 ERightLeft mcRLInfo = mcHitLookUp.
getRLInfo(hit);
454 if (fbInfo == EForwardBackward::c_Backward) {
455 mcRLInfo = reversed(mcRLInfo);
458 std::string color =
"orange";
459 if (mcRLInfo != ERightLeft::c_Right and mcRLInfo != ERightLeft::c_Left) {
461 }
else if (mcRLInfo == rlInfo) {
463 }
else if (mcRLInfo == -rlInfo) {
467 AttributeMap attributeMap{{
"stroke", color}};
476 const std::string& stroke,
477 const std::string& strokeWidth)
479 B2INFO(
"Draw axial to axial segment pairs");
481 if (not storedSegments) {
482 B2WARNING(segmentsStoreObjName <<
"does not exist in current DataStore");
483 printDataStoreContent();
487 std::vector<CDCSegment2D>& segments = *storedSegments;
488 B2INFO(
"#Segments: " << segments.size());
490 std::vector<const CDCAxialSegment2D*> axialSegments;
491 for (
const CDCAxialSegment2D& segment : segments) {
492 if (segment.isAxial()) axialSegments.push_back(&segment);
496 std::vector<CDCAxialSegmentPair> mcAxialSegmentPairs;
497 for (
const CDCAxialSegment2D* fromSegment : axialSegments) {
498 for (
const CDCAxialSegment2D* toSegment : axialSegments) {
499 if (fromSegment == toSegment)
continue;
500 mcAxialSegmentPairs.emplace_back(fromSegment, toSegment);
501 Weight mcWeight = mcAxialSegmentPairFilter(mcAxialSegmentPairs.back());
503 if (std::isnan(mcWeight)) {
504 mcAxialSegmentPairs.pop_back();
508 B2INFO(
"# Axial segment pairs: " << mcAxialSegmentPairs.size());
510 if (stroke !=
"") styling.
setStroke(stroke);
511 if (strokeWidth !=
"") styling.
setStroke(strokeWidth);
516 const std::string& stroke,
517 const std::string& strokeWidth)
519 B2INFO(
"Draw axial to stero segment pairs");
521 if (not storedSegments) {
522 B2WARNING(segmentsStoreObjName <<
"does not exist in current DataStore");
523 printDataStoreContent();
527 std::vector<CDCSegment2D>& segments = *storedSegments;
528 B2INFO(
"#Segments: " << segments.size());
530 std::vector<const CDCAxialSegment2D*> axialSegments;
531 std::vector<const CDCStereoSegment2D*> stereoSegments;
532 for (
const CDCAxialSegment2D& segment : segments) {
533 if (segment.isAxial()) {
534 axialSegments.push_back(&segment);
536 stereoSegments.push_back(&segment);
541 std::vector<CDCSegmentPair> mcSegmentPairs;
542 for (
const CDCAxialSegment2D* axialSegment : axialSegments) {
543 for (
const CDCStereoSegment2D* stereoSegment : stereoSegments) {
546 mcSegmentPairs.emplace_back(axialSegment, stereoSegment);
547 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
549 if (std::isnan(mcWeight)) {
550 mcSegmentPairs.pop_back();
555 mcSegmentPairs.emplace_back(stereoSegment, axialSegment);
556 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
558 if (std::isnan(mcWeight)) {
559 mcSegmentPairs.pop_back();
564 B2INFO(
"# Segment pairs: " << mcSegmentPairs.size());
566 if (stroke !=
"") styling.
setStroke(stroke);
567 if (strokeWidth !=
"") styling.
setStroke(strokeWidth);
572 const std::string& stroke,
573 const std::string& strokeWidth)
575 B2INFO(
"Draw segment triples");
577 if (not storedSegments) {
578 B2WARNING(segmentsStoreObjName <<
"does not exist in current DataStore");
579 printDataStoreContent();
583 std::vector<CDCSegment2D>& segments = *storedSegments;
584 B2INFO(
"#Segment " << segments.size());
586 std::vector<const CDCAxialSegment2D*> axialSegments;
587 std::vector<const CDCStereoSegment2D*> stereoSegments;
589 if (segment.isAxial()) {
590 axialSegments.push_back(&segment);
592 stereoSegments.push_back(&segment);
597 std::vector<CDCSegmentTriple> mcSegmentTriples;
598 for (
const CDCAxialSegment2D* startSegment : axialSegments) {
599 for (
const CDCStereoSegment2D* middleSegment : stereoSegments) {
600 for (
const CDCAxialSegment2D* endSegment : axialSegments) {
601 if (startSegment == endSegment)
continue;
602 mcSegmentTriples.emplace_back(startSegment, middleSegment, endSegment);
603 Weight mcWeight = mcSegmentTripleFilter(mcSegmentTriples.back());
605 if (std::isnan(mcWeight)) {
606 mcSegmentTriples.pop_back();
611 B2INFO(
"# Segment triples: " << mcSegmentTriples.size());
613 if (stroke !=
"") styling.
setStroke(stroke);
614 if (strokeWidth !=
"") styling.
setStroke(strokeWidth);
623 float width = boundingBox.
getWidth();
625 int totalPoints = 1120 * 1120;
626 float svgHeight = roundf(
sqrt(totalPoints * height / width));
627 float svgWidth = roundf(
sqrt(totalPoints * width / height));
637template <
class AItem,
bool a_drawTrajectories>
641 if (a_drawTrajectories) {
642 B2INFO(
"Drawing trajectories from StoreArray: " << storeArrayName);
644 B2INFO(
"Drawing StoreArray: " << storeArrayName);
647 using StoreItem =
typename std::remove_cv<AItem>::type;
649 if (not storeArray) {
650 B2WARNING(storeArrayName <<
" not present in the DataStore");
651 printDataStoreContent();
655 B2INFO(
"with " << storeArray.getEntries() <<
" entries");
657 B2INFO(
"Attributes are");
658 B2INFO(styling.
info());
661template <
class AItem,
bool a_drawTrajectories>
665 if (a_drawTrajectories) {
666 B2INFO(
"Drawing trajectories for vector from DataStore: " << storeObjName);
668 B2INFO(
"Drawing vector from DataStore: " << storeObjName);
671 using StoreItem =
typename std::remove_cv<AItem>::type;
672 StoreWrappedObjPtr<std::vector<StoreItem>> storeVector(storeObjName);
673 if (not storeVector) {
674 B2WARNING(storeObjName <<
" not present in the DataStore");
675 B2INFO(
"Current content of the DataStore:");
676 printDataStoreContent();
680 const std::vector<StoreItem>& vector = *storeVector;
681 B2INFO(
"with " << vector.size() <<
" entries");
683 B2INFO(
"Attributes are");
684 B2INFO(styling.
info());
687template <
bool a_drawTrajectory,
class AIterable,
class AStyling>
690 unsigned int index = -1;
691 for (
const auto& item : items) {
694 AttributeMap attributeMap = styling.map(index, item);
699template <
bool a_drawTrajectory,
class AObject>
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
B2Vector3D getPosWire() const
The method to get position on wire.
B2Vector3D getPosTrack() const
The method to get position on the track.
Class representing the sense wire arrangement in the whole of the central drift chamber.
EDurability
Durability types.
static DataStore & Instance()
Instance of singleton Store.
A Class to store the Monte Carlo particle information.
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
std::pair< T *, float > getRelatedWithWeight(const std::string &name="", const std::string &namedRelation="") const
Get first related object & weight of relation pointing from/to an array.
Accessor to arrays stored in the data store.
int getEntries() const
Get the number of objects in the array.
A two dimensional rectangle that keeps track of the extend of a drawing.
float getWidth() const
Getter for the width of the bounding box rectangle.
float getHeight() const
Getter for the height of the bounding box rectangle.
Interface class to the Monte Carlo information for collections of hits.
TrackingUtilities::EForwardBackward isForwardOrBackwardToMCTrack(const ACDCHitCollection *ptrHits) const
Returns the orientation of the collection of hits relative to its matched track.
int getCorrectRLVote(const ACDCHitCollection *ptrHits) const
Getter for the difference of correct versus incorrect right left passage information.
double getRLPurity(const ACDCHitCollection *ptrHits) const
Getter for the right left passge purity which respects the forward backward reconstruction.
Interface class to the Monte Carlo information for individual hits.
static const CDCMCHitLookUp & getInstance()
Getter for the singletone instance.
TrackingUtilities::ERightLeft getRLInfo(const CDCHit *ptrHit) const
Returns the true right left passage information.
void drawInteractionPoint()
Draws the interaction point.
void drawWires(const CDC::CDCWireTopology &cdcWireTopology)
Draws the wires.
CDCSVGPlotter * clone()
Make a copy of the current status of the plotter.
void drawAxialSegmentPairs(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draw the axial to axial segment pairs.
void drawSegmentTriples(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draw the axial, stereo, axial segment triples.
void drawRecoTrackTrajectories(const std::string &storeArrayName, const std::string &stroke, const std::string &strokeWidth)
Draw RecoTracks trajectories.
void drawIterable(const AIterable &items, AStyling &styling)
Draw every element of an iterable object.
void drawMCAxialSegmentPairs(const std::string &segmentsStoreObjName, const std::string &stroke, const std::string &strokeWidth)
Draws the Monte Carlo true CDCAxialSegmentPairs.
void drawSimHitsConnectByToF(const std::string &simHitStoreArrayName, const std::string &stroke, const std::string &strokeWidth)
Draw the CDCSimHits connected in the order of their getFlightTime for each Monte Carlo particle.
void draw(const AObject &object, const AttributeMap &attributeMap)
Draws the object or its trajectory with the given attributes.
void drawHits(const std::string &storeArrayName, const std::string &stroke, const std::string &strokeWidth)
Draws CDCHits.
void drawWrongRLHits(const std::string &storeObjName)
Draw the CDCRLWireHits in the ACDCHitCollection colored by the match of the right left passage inform...
CDCSVGPlotter(bool animate=false, bool forwardFade=false)
Constructor.
void drawInnerCDCWall(const std::string &stroke)
Draws the inner CDCWall.
void drawWrongRLHitsInTracks(const std::string &tracksStoreObjName)
Draw the CDCRLWireHits in the CDCTracks colored by the match of the right left passage information.
void drawTrackTrajectories(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draws trajectories of the tracks.
void drawOuterCDCWall(const std::string &stroke)
Draws the outer CDCWall.
void drawSuperLayerBoundaries(const std::string &stroke)
Draws the individual super layer boundaries.
void drawMCSegmentTriples(const std::string &segmentsStoreObjName, const std::string &stroke, const std::string &strokeWidth)
Draws the Monte Carlo true CDCSegmentTriples.
void drawSegmentTripleTrajectories(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draw the trajectories of the axial, stereo, axial segment triples.
void drawMCSegmentPairs(const std::string &segmentsStoreObjName, const std::string &stroke, const std::string &strokeWidth)
Draws the Monte Carlo true CDCSegmentPairs.
std::string saveFile(const std::string &fileName="display.svg")
Save the current dom object representation to disk.
void drawStoreArray(const std::string &storeArrayName, Styling< AItem > &styling)
Function Template for drawing the elements of a given StoreArray.
void drawWrongRLHitsInSegments(const std::string &segmentsStoreObjName)
Draw the CDCRLWireHits in the CDCSegments colored by the match of the right left passage information.
void drawSegmentTrajectories(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draws SegmentTrajectories.
void drawMCParticleTrajectories(const std::string &storeArrayName, const std::string &stroke, const std::string &strokeWidth)
Draw MCParticles.
void drawSegmentPairs(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draw the axial to stereo segment pairs.
void drawClusters(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draws CDCWireHitClusters.
void drawTracks(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draws CDCTracks.
void drawStoreVector(const std::string &storeObjName, Styling< AItem > &styling)
Function Template for drawing the elements of a given StoreVector.
void drawRecoTracks(const std::string &storeArrayName, const std::string &stroke, const std::string &strokeWidth)
Draw RecoTracks.
EventDataPlotter m_eventdataPlotter
The plotter instance to translate event data objects to svg expressions.
void drawSegments(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draws CDCSegments.
void drawSimHits(const std::string &storeArrayName, const std::string &stroke, const std::string &strokeWidth)
Draws CDCSimHits.
This Class handles the mapping from the colormapping-method name given as a string to the actual colo...
This Class handles the mapping from the colormapping-method name given as a string to the actual colo...
This Class handles the mapping from the colormapping-method name given as a string to the actual ACol...
void setStrokeWidth(const std::string &mappingName)
Legacy method to set the mapping on how to match a object to the stroke width.
void setStroke(const std::string &mappingName)
Legacy method to set the mapping on how to match a object to the stroke color.
Class template for coloring objects with stroke colors prepared to be the default color cycle.
void startGroup(const AttributeMap &attributeMap=AttributeMap())
Indicates the start of a group of drawn elements.
Implementation of a styling from fixed attribute map.
void setStrokeWidth(const std::string &value)
Legacy - Sets the stroke width to the fixed value.
void setStroke(const std::string &value)
Legacy - Sets the stroke color to the fixed value.
Filter for the construction of axial to axial segment pairs based on simple criteria.
Filter for the construction of axial to stereo segment pairs based on MC information.
Filter for the construction of segment triples based on Monte Carlo information.
A concrete plotter that can draw primitive objects to standalone SVG files.
Interface for a mapping of object and an index to styling attributes.
virtual std::string info()
Informal string summarizing the translation from the object to the styling attributes.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Class representing a two dimensional reconstructed hit in the central drift chamber.
Vector2D getRecoPos2D() const
Getter for the position in the reference plane.
A reconstructed sequence of two dimensional hits in one super layer.
Class representing a hit wire in the central drift chamber.
This class is for convenience access and registration of objects, that are stored inside the StoreWra...
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
double x() const
Getter for the x coordinate.
double y() const
Getter for the y coordinate.
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
double sqrt(double a)
sqrt for double
HepGeom::Vector3D< double > Vector3D
3D Vector
Abstract base class for different kinds of events.