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);
216 const std::string& stroke,
217 const std::string& strokeWidth)
220 if (stroke !=
"") styling.
setStroke(stroke);
222 const bool drawTrajectories =
true;
227 const std::string& stroke,
228 const std::string& strokeWidth)
231 if (stroke !=
"") styling.
setStroke(stroke);
237 const std::string& stroke,
238 const std::string& strokeWidth)
241 if (stroke !=
"") styling.
setStroke(stroke);
247 const std::string& stroke,
248 const std::string& strokeWidth)
251 if (stroke !=
"") styling.
setStroke(stroke);
257 const std::string& stroke,
258 const std::string& strokeWidth)
261 if (stroke !=
"") styling.
setStroke(stroke);
263 const bool drawTrajectories =
true;
268 const std::string& stroke,
269 const std::string& strokeWidth)
272 if (stroke !=
"") styling.
setStroke(stroke);
278 const std::string& stroke,
279 const std::string& strokeWidth)
282 if (stroke !=
"") styling.
setStroke(stroke);
284 const bool drawTrajectories =
true;
289 const std::string& stroke,
290 const std::string& strokeWidth)
293 if (stroke !=
"") styling.
setStroke(stroke);
299 const std::string& stroke,
300 const std::string& strokeWidth)
303 if (stroke !=
"") styling.
setStroke(stroke);
305 const bool drawTrajectories =
true;
310 const std::string& stroke,
311 const std::string& strokeWidth)
314 if (stroke !=
"") styling.
setStroke(stroke);
316 const bool drawTrajectories =
true;
321 const std::string& stroke,
322 const std::string& strokeWidth)
324 B2INFO(
"Drawing simulated hits connected by tof");
326 if (not hitStoreArray) {
327 B2WARNING(
"StoreArray " << hitStoreArrayName <<
" not present");
328 printDataStoreContent();
331 std::vector<CDCSimHit*> simHits;
332 for (
const CDCHit& hit : hitStoreArray) {
333 simHits.push_back(hit.getRelated<
CDCSimHit>());
337 std::map<int, std::set<CDCSimHit*, FlightTimeOrder>> simHitsByMcParticleId;
340 if (mcParticle !=
nullptr) {
342 simHitsByMcParticleId[mcTrackId].insert(simHit);
346 AttributeMap defaultAttributeMap = {{
"stroke", stroke}, {
"stroke-width", strokeWidth}};
348 for (
const auto& mcParticleIdAndSimHits : simHitsByMcParticleId) {
349 const std::set<CDCSimHit*, FlightTimeOrder>& simHitsForMcParticle =
350 mcParticleIdAndSimHits.second;
352 auto drawConnectSimHits = [
this, &defaultAttributeMap](
CDCSimHit * fromSimHit,
CDCSimHit * toSimHit) {
356 if (fromHit ==
nullptr)
return false;
357 if (toHit ==
nullptr)
return false;
366 ROOT::Math::XYZVector toDisplacement(toSimHit->getPosTrack() - toSimHit->getPosWire());
368 CDCRecoHit2D fromRecoHit2D(fromRLWireHit, VectorUtil::getXYVector(fromDisplacement));
369 CDCRecoHit2D toRecoHit2D(toRLWireHit, VectorUtil::getXYVector(toDisplacement));
371 bool falseOrder =
false;
372 if (fromSimHit->
getArrayIndex() > toSimHit->getArrayIndex()) {
374 bool toReassigned = toHit->getRelatedWithWeight<
MCParticle>().second < 0;
375 if (not fromReassigned and not toReassigned) {
380 AttributeMap attributeMap = defaultAttributeMap;
382 attributeMap[
"stroke"] =
"red";
383 attributeMap[
"stroke-width"] =
"1.0";
385 draw(fromRecoHit2D, attributeMap);
386 draw(toRecoHit2D, attributeMap);
388 const ROOT::Math::XYVector fromPos = fromRecoHit2D.
getRecoPos2D();
389 const float fromX = fromPos.x();
390 const float fromY = fromPos.y();
392 const ROOT::Math::XYVector toPos = toRecoHit2D.
getRecoPos2D();
393 const float toX = toPos.x();
394 const float toY = toPos.y();
400 std::ignore = std::adjacent_find(simHitsForMcParticle.begin(),
401 simHitsForMcParticle.end(),
418template<
class ACDCHitCollection>
421 B2INFO(
"Draw wrong right left passage information from " << hitCollectionsStoreObjName);
423 if (not storedHitCollections) {
424 B2WARNING(hitCollectionsStoreObjName <<
"does not exist in current DataStore");
425 printDataStoreContent();
429 std::vector<ACDCHitCollection>& hitCollections = *storedHitCollections;
430 B2INFO(
"#HitCollections: " << hitCollections.size());
435 for (
const ACDCHitCollection& hitCollection : hitCollections) {
438 double rlPurity = mcHitCollectionLookUp.
getRLPurity(&hitCollection);
442 if (rlPurity < 0.5 and hitCollection.getAutomatonCell().hasAliasFlag())
continue;
445 if (correctRLVote < 0 and hitCollection.getAutomatonCell().hasReverseFlag())
continue;
448 for (
const auto& recoHit : hitCollection) {
449 ERightLeft rlInfo = recoHit.getRLInfo();
450 const CDCHit* hit = recoHit.getWireHit().getHit();
451 ERightLeft mcRLInfo = mcHitLookUp.
getRLInfo(hit);
453 if (fbInfo == EForwardBackward::c_Backward) {
454 mcRLInfo = reversed(mcRLInfo);
457 std::string color =
"orange";
458 if (mcRLInfo != ERightLeft::c_Right and mcRLInfo != ERightLeft::c_Left) {
460 }
else if (mcRLInfo == rlInfo) {
462 }
else if (mcRLInfo == -rlInfo) {
466 AttributeMap attributeMap{{
"stroke", color}};
475 const std::string& stroke,
476 const std::string& strokeWidth)
478 B2INFO(
"Draw axial to axial segment pairs");
480 if (not storedSegments) {
481 B2WARNING(segmentsStoreObjName <<
"does not exist in current DataStore");
482 printDataStoreContent();
486 std::vector<CDCSegment2D>& segments = *storedSegments;
487 B2INFO(
"#Segments: " << segments.size());
489 std::vector<const CDCAxialSegment2D*> axialSegments;
490 for (
const CDCAxialSegment2D& segment : segments) {
491 if (segment.isAxial()) axialSegments.push_back(&segment);
495 std::vector<CDCAxialSegmentPair> mcAxialSegmentPairs;
496 for (
const CDCAxialSegment2D* fromSegment : axialSegments) {
497 for (
const CDCAxialSegment2D* toSegment : axialSegments) {
498 if (fromSegment == toSegment)
continue;
499 mcAxialSegmentPairs.emplace_back(fromSegment, toSegment);
500 Weight mcWeight = mcAxialSegmentPairFilter(mcAxialSegmentPairs.back());
502 if (std::isnan(mcWeight)) {
503 mcAxialSegmentPairs.pop_back();
507 B2INFO(
"# Axial segment pairs: " << mcAxialSegmentPairs.size());
509 if (stroke !=
"") styling.
setStroke(stroke);
510 if (strokeWidth !=
"") styling.
setStroke(strokeWidth);
515 const std::string& stroke,
516 const std::string& strokeWidth)
518 B2INFO(
"Draw axial to stero segment pairs");
520 if (not storedSegments) {
521 B2WARNING(segmentsStoreObjName <<
"does not exist in current DataStore");
522 printDataStoreContent();
526 std::vector<CDCSegment2D>& segments = *storedSegments;
527 B2INFO(
"#Segments: " << segments.size());
529 std::vector<const CDCAxialSegment2D*> axialSegments;
530 std::vector<const CDCStereoSegment2D*> stereoSegments;
531 for (
const CDCAxialSegment2D& segment : segments) {
532 if (segment.isAxial()) {
533 axialSegments.push_back(&segment);
535 stereoSegments.push_back(&segment);
540 std::vector<CDCSegmentPair> mcSegmentPairs;
541 for (
const CDCAxialSegment2D* axialSegment : axialSegments) {
542 for (
const CDCStereoSegment2D* stereoSegment : stereoSegments) {
545 mcSegmentPairs.emplace_back(axialSegment, stereoSegment);
546 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
548 if (std::isnan(mcWeight)) {
549 mcSegmentPairs.pop_back();
554 mcSegmentPairs.emplace_back(stereoSegment, axialSegment);
555 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
557 if (std::isnan(mcWeight)) {
558 mcSegmentPairs.pop_back();
563 B2INFO(
"# Segment pairs: " << mcSegmentPairs.size());
565 if (stroke !=
"") styling.
setStroke(stroke);
566 if (strokeWidth !=
"") styling.
setStroke(strokeWidth);
571 const std::string& stroke,
572 const std::string& strokeWidth)
574 B2INFO(
"Draw segment triples");
576 if (not storedSegments) {
577 B2WARNING(segmentsStoreObjName <<
"does not exist in current DataStore");
578 printDataStoreContent();
582 std::vector<CDCSegment2D>& segments = *storedSegments;
583 B2INFO(
"#Segment " << segments.size());
585 std::vector<const CDCAxialSegment2D*> axialSegments;
586 std::vector<const CDCStereoSegment2D*> stereoSegments;
588 if (segment.isAxial()) {
589 axialSegments.push_back(&segment);
591 stereoSegments.push_back(&segment);
596 std::vector<CDCSegmentTriple> mcSegmentTriples;
597 for (
const CDCAxialSegment2D* startSegment : axialSegments) {
598 for (
const CDCStereoSegment2D* middleSegment : stereoSegments) {
599 for (
const CDCAxialSegment2D* endSegment : axialSegments) {
600 if (startSegment == endSegment)
continue;
601 mcSegmentTriples.emplace_back(startSegment, middleSegment, endSegment);
602 Weight mcWeight = mcSegmentTripleFilter(mcSegmentTriples.back());
604 if (std::isnan(mcWeight)) {
605 mcSegmentTriples.pop_back();
610 B2INFO(
"# Segment triples: " << mcSegmentTriples.size());
612 if (stroke !=
"") styling.
setStroke(stroke);
613 if (strokeWidth !=
"") styling.
setStroke(strokeWidth);
622 float width = boundingBox.
getWidth();
624 int totalPoints = 1120 * 1120;
625 float svgHeight = roundf(
sqrt(totalPoints * height / width));
626 float svgWidth = roundf(
sqrt(totalPoints * width / height));
636template <
class AItem,
bool a_drawTrajectories>
640 if (a_drawTrajectories) {
641 B2INFO(
"Drawing trajectories from StoreArray: " << storeArrayName);
643 B2INFO(
"Drawing StoreArray: " << storeArrayName);
646 using StoreItem =
typename std::remove_cv<AItem>::type;
648 if (not storeArray) {
649 B2WARNING(storeArrayName <<
" not present in the DataStore");
650 printDataStoreContent();
654 B2INFO(
"with " << storeArray.getEntries() <<
" entries");
656 B2INFO(
"Attributes are");
657 B2INFO(styling.
info());
660template <
class AItem,
bool a_drawTrajectories>
664 if (a_drawTrajectories) {
665 B2INFO(
"Drawing trajectories for vector from DataStore: " << storeObjName);
667 B2INFO(
"Drawing vector from DataStore: " << storeObjName);
670 using StoreItem =
typename std::remove_cv<AItem>::type;
671 StoreWrappedObjPtr<std::vector<StoreItem>> storeVector(storeObjName);
672 if (not storeVector) {
673 B2WARNING(storeObjName <<
" not present in the DataStore");
674 B2INFO(
"Current content of the DataStore:");
675 printDataStoreContent();
679 const std::vector<StoreItem>& vector = *storeVector;
680 B2INFO(
"with " << vector.size() <<
" entries");
682 B2INFO(
"Attributes are");
683 B2INFO(styling.
info());
686template <
bool a_drawTrajectory,
class AIterable,
class AStyling>
689 unsigned int index = -1;
690 for (
const auto& item : items) {
693 AttributeMap attributeMap = styling.map(index, item);
698template <
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.
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.