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/utilities/ReversedRange.h>
29#include <tracking/dataobjects/RecoTrack.h>
31#include <framework/datastore/StoreArray.h>
33#include <cdc/dataobjects/CDCSimHit.h>
34#include <cdc/dataobjects/CDCHit.h>
36#include <mdst/dataobjects/MCParticle.h>
38#include <Math/Vector3D.h>
47using namespace TrackFindingCDC;
48using namespace TrackingUtilities;
51 template<
bool a_drawTrajectory,
class AObject>
52 struct DrawTrajectoryHelper;
54 template<
class AObject>
55 struct DrawTrajectoryHelper<true, AObject> {
57 static void draw(EventDataPlotter& plotter, AObject&
object,
const AttributeMap& attributeMap)
59 plotter.drawTrajectory(
object, attributeMap);
63 template<
class AObject>
64 struct DrawTrajectoryHelper<false, AObject> {
66 static void draw(EventDataPlotter& plotter, AObject&
object,
const AttributeMap& attributeMap)
68 plotter.draw(
object, attributeMap);
75 class FlightTimeOrder {
78 bool operator()(
const CDCSimHit* x,
const CDCSimHit* y)
const
80 return (x->getFlightTime() < y->getFlightTime());
85static void printDataStoreContent()
87 B2INFO(
"Current content of the DataStore:");
88 B2INFO(
"StoreArrays:");
93 B2INFO(
"StoreObjPtr:");
99const AttributeMap c_defaultSVGAttributes({
100 {
"stroke",
"orange"},
101 {
"stroke-width",
"0.55"},
103 {
"transform",
"translate(0, 1120) scale(1,-1)"}
115 int default_width = 1120;
116 int default_height = 1120;
135 AttributeMap attributeMap;
136 attributeMap.emplace(
"stroke", stroke);
142 AttributeMap attributeMap;
143 attributeMap.emplace(
"stroke", stroke);
149 AttributeMap attributeMap;
150 attributeMap.emplace(
"stroke", stroke);
160 const std::string& stroke,
161 const std::string& strokeWidth)
164 if (stroke !=
"") styling.
setStroke(stroke);
170 const std::string& stroke,
171 const std::string& strokeWidth)
173 B2INFO(
"Drawing simulated hits");
175 if (not storeArray) {
176 B2WARNING(
"StoreArray " << storeArrayName <<
" not present");
177 printDataStoreContent();
180 std::vector<CDCSimHit> simHitsRelatedToHits;
181 for (
const CDCHit& hit : storeArray) {
182 simHitsRelatedToHits.push_back(*hit.getRelated<
CDCSimHit>(
"CDCSimHits"));
184 B2INFO(
"#CDCSimHits: " << storeArray.
getEntries());
196 const std::string& stroke,
197 const std::string& strokeWidth)
200 if (stroke !=
"") styling.
setStroke(stroke);
206 const std::string& stroke,
207 const std::string& strokeWidth)
210 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);
259 const std::string& stroke,
260 const std::string& strokeWidth)
263 if (stroke !=
"") styling.
setStroke(stroke);
265 const bool drawTrajectories =
true;
270 const std::string& stroke,
271 const std::string& strokeWidth)
274 if (stroke !=
"") styling.
setStroke(stroke);
281 const std::string& stroke,
282 const std::string& strokeWidth)
285 if (stroke !=
"") styling.
setStroke(stroke);
287 const bool drawTrajectories =
true;
292 const std::string& stroke,
293 const std::string& strokeWidth)
296 if (stroke !=
"") styling.
setStroke(stroke);
303 const std::string& stroke,
304 const std::string& strokeWidth)
307 if (stroke !=
"") styling.
setStroke(stroke);
309 const bool drawTrajectories =
true;
315 const std::string& stroke,
316 const std::string& strokeWidth)
319 if (stroke !=
"") styling.
setStroke(stroke);
321 const bool drawTrajectories =
true;
326 const std::string& stroke,
327 const std::string& strokeWidth)
329 B2INFO(
"Drawing simulated hits connected by tof");
331 if (not hitStoreArray) {
332 B2WARNING(
"StoreArray " << hitStoreArrayName <<
" not present");
333 printDataStoreContent();
336 std::vector<CDCSimHit*> simHits;
337 for (
const CDCHit& hit : hitStoreArray) {
338 simHits.push_back(hit.getRelated<
CDCSimHit>());
342 std::map<int, std::set<CDCSimHit*, FlightTimeOrder>> simHitsByMcParticleId;
345 if (mcParticle !=
nullptr) {
347 simHitsByMcParticleId[mcTrackId].insert(simHit);
351 AttributeMap defaultAttributeMap = {{
"stroke", stroke}, {
"stroke-width", strokeWidth}};
353 for (
const auto& mcParticleIdAndSimHits : simHitsByMcParticleId) {
354 const std::set<CDCSimHit*, FlightTimeOrder>& simHitsForMcParticle =
355 mcParticleIdAndSimHits.second;
357 auto drawConnectSimHits = [
this, &defaultAttributeMap](
CDCSimHit * fromSimHit,
CDCSimHit * toSimHit) {
361 if (fromHit ==
nullptr)
return false;
362 if (toHit ==
nullptr)
return false;
371 ROOT::Math::XYZVector toDisplacement(toSimHit->getPosTrack() - toSimHit->getPosWire());
373 CDCRecoHit2D fromRecoHit2D(fromRLWireHit, VectorUtil::getXYVector(fromDisplacement));
374 CDCRecoHit2D toRecoHit2D(toRLWireHit, VectorUtil::getXYVector(toDisplacement));
376 bool falseOrder =
false;
377 if (fromSimHit->
getArrayIndex() > toSimHit->getArrayIndex()) {
379 bool toReassigned = toHit->getRelatedWithWeight<
MCParticle>().second < 0;
380 if (not fromReassigned and not toReassigned) {
385 AttributeMap attributeMap = defaultAttributeMap;
387 attributeMap[
"stroke"] =
"red";
388 attributeMap[
"stroke-width"] =
"1.0";
390 draw(fromRecoHit2D, attributeMap);
391 draw(toRecoHit2D, attributeMap);
393 const ROOT::Math::XYVector fromPos = fromRecoHit2D.
getRecoPos2D();
394 const float fromX = fromPos.x();
395 const float fromY = fromPos.y();
397 const ROOT::Math::XYVector toPos = toRecoHit2D.
getRecoPos2D();
398 const float toX = toPos.x();
399 const float toY = toPos.y();
405 std::ignore = std::adjacent_find(simHitsForMcParticle.begin(),
406 simHitsForMcParticle.end(),
425template<
class ACDCHitCollection>
428 B2INFO(
"Draw wrong right left passage information from " << hitCollectionsStoreObjName);
430 if (not storedHitCollections) {
431 B2WARNING(hitCollectionsStoreObjName <<
"does not exist in current DataStore");
432 printDataStoreContent();
436 std::vector<ACDCHitCollection>& hitCollections = *storedHitCollections;
437 B2INFO(
"#HitCollections: " << hitCollections.size());
442 for (
const ACDCHitCollection& hitCollection : hitCollections) {
445 double rlPurity = mcHitCollectionLookUp.
getRLPurity(&hitCollection);
449 if (rlPurity < 0.5 and hitCollection.getAutomatonCell().hasAliasFlag())
continue;
452 if (correctRLVote < 0 and hitCollection.getAutomatonCell().hasReverseFlag())
continue;
455 for (
const auto& recoHit : hitCollection) {
456 ERightLeft rlInfo = recoHit.getRLInfo();
457 const CDCHit* hit = recoHit.getWireHit().getHit();
458 ERightLeft mcRLInfo = mcHitLookUp.
getRLInfo(hit);
460 if (fbInfo == EForwardBackward::c_Backward) {
461 mcRLInfo = reversed(mcRLInfo);
464 std::string color =
"orange";
465 if (mcRLInfo != ERightLeft::c_Right and mcRLInfo != ERightLeft::c_Left) {
467 }
else if (mcRLInfo == rlInfo) {
469 }
else if (mcRLInfo == -rlInfo) {
473 AttributeMap attributeMap{{
"stroke", color}};
482 const std::string& stroke,
483 const std::string& strokeWidth)
485 B2INFO(
"Draw axial to axial segment pairs");
487 if (not storedSegments) {
488 B2WARNING(segmentsStoreObjName <<
"does not exist in current DataStore");
489 printDataStoreContent();
493 const std::vector<CDCSegment2D>& segments = *storedSegments;
494 B2INFO(
"#Segments: " << segments.size());
496 std::vector<const CDCAxialSegment2D*> axialSegments;
497 for (
const CDCAxialSegment2D& segment : segments) {
498 if (segment.isAxial()) axialSegments.push_back(&segment);
502 std::vector<CDCAxialSegmentPair> mcAxialSegmentPairs;
503 for (
const CDCAxialSegment2D* fromSegment : axialSegments) {
504 for (
const CDCAxialSegment2D* toSegment : axialSegments) {
505 if (fromSegment == toSegment)
continue;
506 mcAxialSegmentPairs.emplace_back(fromSegment, toSegment);
507 Weight mcWeight = mcAxialSegmentPairFilter(mcAxialSegmentPairs.back());
509 if (std::isnan(mcWeight)) {
510 mcAxialSegmentPairs.pop_back();
514 B2INFO(
"# Axial segment pairs: " << mcAxialSegmentPairs.size());
516 if (stroke !=
"") styling.
setStroke(stroke);
517 if (strokeWidth !=
"") styling.
setStroke(strokeWidth);
522 const std::string& stroke,
523 const std::string& strokeWidth)
525 B2INFO(
"Draw axial to stero segment pairs");
527 if (not storedSegments) {
528 B2WARNING(segmentsStoreObjName <<
"does not exist in current DataStore");
529 printDataStoreContent();
533 const std::vector<CDCSegment2D>& segments = *storedSegments;
534 B2INFO(
"#Segments: " << segments.size());
536 std::vector<const CDCAxialSegment2D*> axialSegments;
537 std::vector<const CDCStereoSegment2D*> stereoSegments;
538 for (
const CDCAxialSegment2D& segment : segments) {
539 if (segment.isAxial()) {
540 axialSegments.push_back(&segment);
542 stereoSegments.push_back(&segment);
547 std::vector<CDCSegmentPair> mcSegmentPairs;
548 for (
const CDCAxialSegment2D* axialSegment : axialSegments) {
549 for (
const CDCStereoSegment2D* stereoSegment : stereoSegments) {
552 mcSegmentPairs.emplace_back(axialSegment, stereoSegment);
553 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
555 if (std::isnan(mcWeight)) {
556 mcSegmentPairs.pop_back();
561 mcSegmentPairs.emplace_back(stereoSegment, axialSegment);
562 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
564 if (std::isnan(mcWeight)) {
565 mcSegmentPairs.pop_back();
570 B2INFO(
"# Segment pairs: " << mcSegmentPairs.size());
572 if (stroke !=
"") styling.
setStroke(stroke);
573 if (strokeWidth !=
"") styling.
setStroke(strokeWidth);
578 const std::string& stroke,
579 const std::string& strokeWidth)
581 B2INFO(
"Draw segment triples");
583 if (not storedSegments) {
584 B2WARNING(segmentsStoreObjName <<
"does not exist in current DataStore");
585 printDataStoreContent();
589 const std::vector<CDCSegment2D>& segments = *storedSegments;
590 B2INFO(
"#Segment " << segments.size());
592 std::vector<const CDCAxialSegment2D*> axialSegments;
593 std::vector<const CDCStereoSegment2D*> stereoSegments;
595 if (segment.isAxial()) {
596 axialSegments.push_back(&segment);
598 stereoSegments.push_back(&segment);
603 std::vector<CDCSegmentTriple> mcSegmentTriples;
604 for (
const CDCAxialSegment2D* startSegment : axialSegments) {
605 for (
const CDCStereoSegment2D* middleSegment : stereoSegments) {
606 for (
const CDCAxialSegment2D* endSegment : axialSegments) {
607 if (startSegment == endSegment)
continue;
608 mcSegmentTriples.emplace_back(startSegment, middleSegment, endSegment);
609 Weight mcWeight = mcSegmentTripleFilter(mcSegmentTriples.back());
611 if (std::isnan(mcWeight)) {
612 mcSegmentTriples.pop_back();
617 B2INFO(
"# Segment triples: " << mcSegmentTriples.size());
619 if (stroke !=
"") styling.
setStroke(stroke);
620 if (strokeWidth !=
"") styling.
setStroke(strokeWidth);
629 float width = boundingBox.
getWidth();
631 int totalPoints = 1120 * 1120;
632 float svgHeight = roundf(
sqrt(totalPoints * height / width));
633 float svgWidth = roundf(
sqrt(totalPoints * width / height));
643template <
class AItem,
bool a_drawTrajectories>
647 if (a_drawTrajectories) {
648 B2INFO(
"Drawing trajectories from StoreArray: " << storeArrayName);
650 B2INFO(
"Drawing StoreArray: " << storeArrayName);
653 using StoreItem =
typename std::remove_cv<AItem>::type;
655 if (not storeArray) {
656 B2WARNING(storeArrayName <<
" not present in the DataStore");
657 printDataStoreContent();
661 B2INFO(
"with " << storeArray.getEntries() <<
" entries");
663 B2INFO(
"Attributes are");
664 B2INFO(styling.
info());
667template <
class AItem,
bool a_drawTrajectories>
671 if (a_drawTrajectories) {
672 B2INFO(
"Drawing trajectories for vector from DataStore: " << storeObjName);
674 B2INFO(
"Drawing vector from DataStore: " << storeObjName);
677 using StoreItem =
typename std::remove_cv<AItem>::type;
678 StoreWrappedObjPtr<std::vector<StoreItem>> storeVector(storeObjName);
679 if (not storeVector) {
680 B2WARNING(storeObjName <<
" not present in the DataStore");
681 B2INFO(
"Current content of the DataStore:");
682 printDataStoreContent();
686 const std::vector<StoreItem>& vector = *storeVector;
687 B2INFO(
"with " << vector.size() <<
" entries");
689 B2INFO(
"Attributes are");
690 B2INFO(styling.
info());
693template <
bool a_drawTrajectory,
class AIterable,
class AStyling>
696 unsigned int index = -1;
697 for (
const auto& item : items) {
700 AttributeMap attributeMap = styling.map(index, item);
705template <
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 TrackingUtilities::ERightLeft getRLInfo(const CDCHit *ptrHit)
Returns the true right left passage information.
static const CDCMCHitLookUp & getInstance()
Getter for the singletone instance.
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.
ROOT::Math::XYVector 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...
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.