Belle II Software development
EventDataPlotter.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <tracking/trackFindingCDC/display/EventDataPlotter.h>
9
10#include <tracking/trackFindingCDC/display/SVGPrimitivePlotter.h>
11#include <tracking/trackFindingCDC/display/BoundingBox.h>
12
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>
17
18#include <tracking/trackingUtilities/eventdata/segments/CDCWireHitCluster.h>
19#include <tracking/trackingUtilities/eventdata/segments/CDCSegment2D.h>
20#include <tracking/trackingUtilities/eventdata/segments/CDCSegment3D.h>
21
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>
26
27#include <cdc/topology/CDCWireTopology.h>
28
29#include <tracking/trackingUtilities/geometry/Circle2D.h>
30
31#include <cdc/dataobjects/CDCSimHit.h>
32#include <cdc/dataobjects/CDCHit.h>
33
34#include <framework/logging/Logger.h>
35
36#include <tracking/dataobjects/RecoTrack.h>
37#include <mdst/dataobjects/MCParticle.h>
38
39#include <TMatrixDSym.h>
40
41#include <cmath>
42
43using namespace Belle2;
44using namespace CDC;
45using namespace TrackFindingCDC;
46using namespace TrackingUtilities;
47
48EventDataPlotter::EventDataPlotter(bool animate, bool forwardFade)
50 AttributeMap{{"stroke", "orange"}, {"stroke-width", "0.55"}, {"fill", "none"}}))
51, m_animate(animate)
52, m_forwardFade(forwardFade)
53{
54}
55
56EventDataPlotter::EventDataPlotter(std::unique_ptr<PrimitivePlotter> ptrPrimitivePlotter,
57 bool animate,
58 bool forwardFade)
59 : m_ptrPrimitivePlotter(std::move(ptrPrimitivePlotter))
60 , m_animate(animate)
61 , m_forwardFade(forwardFade)
62{
63 B2ASSERT("EventDataPlotter initialized with nullptr. Using default backend SVGPrimitivePlotter.",
65}
66
68 : m_ptrPrimitivePlotter(eventDataPlotter.m_ptrPrimitivePlotter->clone())
69 , m_animate(eventDataPlotter.m_animate)
70 , m_forwardFade(eventDataPlotter.m_forwardFade)
71{
72}
73
74const std::string EventDataPlotter::save(const std::string& fileName)
75{
77 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
78 return primitivePlotter.save(fileName);
79 } else {
80 return "";
81 }
82}
83
85{
87 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
88 return primitivePlotter.clear();
89 }
90}
91
93{
95 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
96 return primitivePlotter.getBoundingBox();
97 } else {
98 return BoundingBox(0, 0, 0, 0);
99 }
100}
101
103{
105 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
106 return primitivePlotter.setBoundingBox(boundingBox);
107 }
108}
109
111{
113 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
114 return primitivePlotter.getCanvasWidth();
115 } else {
116 return NAN;
117 }
118}
119
121{
123 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
124 return primitivePlotter.getCanvasHeight();
125 } else {
126 return NAN;
127 }
128}
129
131{
133 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
134 primitivePlotter.setCanvasWidth(width);
135 }
136}
137
139{
141 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
142 primitivePlotter.setCanvasHeight(height);
143 }
144}
145
147{
149 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
150 primitivePlotter.startGroup(attributeMap);
151 }
152}
153
155{
157 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
158 primitivePlotter.endGroup();
159 }
160}
161
163{
164 // In case the event should be animated
165 // uncover the group of elements at the time of flight of the CDCSimHit.
166 if (not m_ptrPrimitivePlotter) return;
167 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
168
169 if (m_animate) {
170 float tof = simHit.getFlightTime();
171 AttributeMap groupAttributeMap{{"_showAt", getAnimationTimeFromNanoSeconds(tof)}};
172 primitivePlotter.startGroup(groupAttributeMap);
173
174 } else {
175 primitivePlotter.startGroup();
176 }
177}
178
180{
181 if (not m_ptrPrimitivePlotter) return;
182 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
183
184 if (m_animate) {
185 if (ptrHit) {
186 const CDCHit& hit = *ptrHit;
187 const CDCSimHit* ptrSimHit = hit.getRelated<CDCSimHit>();
188 if (ptrSimHit) {
189 const CDCSimHit& simHit = *ptrSimHit;
190 startAnimationGroup(simHit);
191 return;
192 }
193 }
194 }
195 primitivePlotter.startGroup();
196}
197
199{
200 Vector2D center(0.0, 0.0);
201 float radius = 1.0;
202
203 const Circle2D interactionPoint(center, radius);
204
205 AttributeMap attributeMap{{"fill", "black"}, {"stroke-width", "0"}};
206
207 draw(interactionPoint, attributeMap);
208}
209
211{
212 if (not m_ptrPrimitivePlotter) return;
213 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
214
215 const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
216
217 const CDCWireSuperLayer& wireSuperLayer = wireTopology.getWireSuperLayers().front();
218
219 float centerX = 0.0;
220 float centerY = 0.0;
221 float innerR = wireSuperLayer.getInnerCylindricalR();
222
223 primitivePlotter.drawCircle(centerX, centerY, innerR, attributeMap);
224}
225
227{
228 if (not m_ptrPrimitivePlotter) return;
229 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
230
231 const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
232
233 const CDCWireSuperLayer& wireSuperLayer = wireTopology.getWireSuperLayers().back();
234
235 float centerX = 0.0;
236 float centerY = 0.0;
237 float outerR = wireSuperLayer.getOuterCylindricalR();
238
239 primitivePlotter.drawCircle(centerX, centerY, outerR, attributeMap);
240}
241
243{
244 if (not m_ptrPrimitivePlotter) return;
245 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
246
247 const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
248
249 for (const CDCWireSuperLayer& wireSuperLayer : wireTopology.getWireSuperLayers()) {
250 float centerX = 0.0;
251 float centerY = 0.0;
252 float outerR = wireSuperLayer.getInnerCylindricalR();
253 primitivePlotter.drawCircle(centerX, centerY, outerR, attributeMap);
254 }
255 drawOuterCDCWall(attributeMap);
256}
257
259 float startY,
260 float endX,
261 float endY,
262 const AttributeMap& attributeMap)
263{
264 if (not m_ptrPrimitivePlotter) return;
265 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
266
267 primitivePlotter.drawLine(startX, startY, endX, endY, attributeMap);
268}
269
271void EventDataPlotter::draw(const Circle2D& circle, AttributeMap attributeMap)
272{
273 if (not m_ptrPrimitivePlotter) return;
274 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
275
276 float radius = circle.radius();
277
278 if (not attributeMap.count("fill") or attributeMap["fill"] != "") {
279 if (attributeMap.count("stroke")) {
280 attributeMap["fill"] = attributeMap["stroke"];
281 attributeMap.erase("stroke");
282 }
283 }
284
285 const Vector2D& pos = circle.center();
286
287 float x = pos.x();
288 float y = pos.y();
289
290 primitivePlotter.drawCircle(x, y, radius, attributeMap);
291}
292
294void EventDataPlotter::draw(const CDCWire& wire, const AttributeMap& attributeMap)
295{
296 const float wireRadius = 0.25;
297 const Vector2D& refPos = wire.getRefPos2D();
298
299 draw(Circle2D(refPos, wireRadius), attributeMap);
300}
301
303void EventDataPlotter::draw(const CDCWireSuperLayer& wireSuperLayer,
304 const AttributeMap& attributeMap)
305{
306 if (not m_ptrPrimitivePlotter) return;
307 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
308
309 primitivePlotter.startGroup(attributeMap);
310 for (const CDCWireLayer& wireLayer : wireSuperLayer) {
311 for (const CDCWire& wire : wireLayer) {
312 draw(wire);
313 }
314 }
315 primitivePlotter.endGroup();
316}
317
319void EventDataPlotter::draw(const CDCWireTopology& wireTopology, AttributeMap attributeMap)
320{
321 for (const CDCWireSuperLayer& wireSuperLayer : wireTopology.getWireSuperLayers()) {
322 AttributeMap defaultSuperLayerAttributeMap{{"fill",
323 wireSuperLayer.isAxial() ? "black" : "gray"
324 },
325 {"stroke", "none"}};
326
327 AttributeMap superLayerAttributeMap(attributeMap);
328
329 // Insert the values as defaults. Does not overwrite attributes with the same name.
330 superLayerAttributeMap.insert(defaultSuperLayerAttributeMap.begin(),
331 defaultSuperLayerAttributeMap.end());
332 draw(wireSuperLayer, superLayerAttributeMap);
333 }
334}
335
337void EventDataPlotter::draw(const CDCSimHit& simHit, const AttributeMap& attributeMap)
338{
339 if (not m_ptrPrimitivePlotter) return;
340 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
341
342 startAnimationGroup(simHit);
343
344 // Draw hit position as a small circle
345 ROOT::Math::XYZVector position = simHit.getPosTrack();
346 float x = position.X();
347 float y = position.Y();
348 float radius = 0.2;
349
350 primitivePlotter.drawCircle(x, y, radius, attributeMap);
351
352 // Draw momentum as an arrow proportional to the transverse component of the momentum
353 const float momentumToArrowLength = 1.5;
354
355 ROOT::Math::XYZVector momentum = simHit.getMomentum();
356 float endX = x + momentum.X() * momentumToArrowLength;
357 float endY = y + momentum.Y() * momentumToArrowLength;
358
359 primitivePlotter.drawArrow(x, y, endX, endY, attributeMap);
360
361 primitivePlotter.endGroup();
362}
363
365void EventDataPlotter::draw(const CDCHit& hit, const AttributeMap& attributeMap)
366{
367 CDCWireHit wireHit(&hit);
368 draw(wireHit, attributeMap);
369}
370
372void EventDataPlotter::draw(const CDCWireHit& wireHit, const AttributeMap& attributeMap)
373{
374 if (not m_ptrPrimitivePlotter) return;
375 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
376
377 startAnimationGroup(wireHit.getHit());
378
379 const Vector2D& refPos = wireHit.getRefPos2D();
380
381 float x = refPos.x();
382 float y = refPos.y();
383 float radius = wireHit.getRefDriftLength();
384
385 if (fabs(radius) < 100) {
386 primitivePlotter.drawCircle(x, y, radius, attributeMap);
387 }
388
389 primitivePlotter.endGroup();
390}
391
393void EventDataPlotter::draw(const CDCRecoHit2D& recoHit2D, const AttributeMap& attributeMap)
394{
395 if (not m_ptrPrimitivePlotter) return;
396 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
397
398 const CDCWireHit& wireHit = recoHit2D.getWireHit();
399
400 startAnimationGroup(wireHit.getHit());
401
402 const Vector2D& refPos2D = wireHit.getRefPos2D();
403 const Vector2D& recoPos2D = recoHit2D.getRecoPos2D();
404
405 float x = refPos2D.x();
406 float y = refPos2D.y();
407 float radius = wireHit.getRefDriftLength();
408 primitivePlotter.drawCircle(x, y, radius, attributeMap);
409
410 if (not recoPos2D.hasNAN()) {
411 float supportPointRadius = 0.2;
412 Circle2D supportPoint(recoPos2D, supportPointRadius);
413 draw(supportPoint, attributeMap);
414 }
415
416 primitivePlotter.endGroup();
417}
418
420void EventDataPlotter::draw(const CDCTangent& tangent, const AttributeMap& attributeMap)
421{
422 if (not m_ptrPrimitivePlotter) return;
423 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
424
425 const Vector2D fromPos = tangent.getFromRecoPos2D();
426 const float fromX = fromPos.x();
427 const float fromY = fromPos.y();
428
429 const Vector2D toPos = tangent.getToRecoPos2D();
430 const float toX = toPos.x();
431 const float toY = toPos.y();
432
433 primitivePlotter.drawLine(fromX, fromY, toX, toY, attributeMap);
434
435 float touchPointRadius = 0.015;
436 const Circle2D fromTouchPoint(fromPos, touchPointRadius);
437 draw(fromTouchPoint, attributeMap);
438
439 const Circle2D toTouchPoint(toPos, touchPointRadius);
440 draw(toTouchPoint, attributeMap);
441}
442
444 const AttributeMap& attributeMap)
445{
446 draw(recoHit3D.getRecoHit2D(), attributeMap);
447}
448
450void EventDataPlotter::draw(const CDCTrajectory2D& trajectory2D, AttributeMap attributeMap)
451{
452 if (not m_ptrPrimitivePlotter) return;
453 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
454
455 AttributeMap defaultAttributeMap{};
456
457 // Make the default color charge dependent
458 int charge = trajectory2D.getChargeSign();
459 if (charge > 0) {
460 defaultAttributeMap["stroke"] = "red";
461 } else if (charge < 0) {
462 defaultAttributeMap["stroke"] = "blue";
463 } else {
464 defaultAttributeMap["stroke"] = "green";
465 }
466
467 // Add attributes if not present
468 attributeMap.insert(defaultAttributeMap.begin(), defaultAttributeMap.end());
469
470 Vector2D trajectoryExit = trajectory2D.getOuterExit();
471 if (trajectoryExit.hasNAN()) {
472 // Curlers do not leave the CDC
473 // Stop the trajectory at the inner wall to be able to
474 // see the start point
475 trajectoryExit = trajectory2D.getInnerExit();
476 }
477
478 if (trajectory2D.getLocalCircle()->isCircle()) {
479 if (trajectoryExit.hasNAN()) {
480 // No exit point out of the cdc could be detected.
481 // Draw full circle
482 const float radius = trajectory2D.getLocalCircle()->absRadius();
483 const Vector2D center = trajectory2D.getGlobalCircle().center();
484 float centerX = center.x();
485 float centerY = center.y();
486
487 primitivePlotter.drawCircle(centerX, centerY, radius);
488
489 } else {
490 const float radius = trajectory2D.getLocalCircle()->absRadius();
491 const Vector2D start = trajectory2D.getSupport();
492 float startX = start.x();
493 float startY = start.y();
494
495 float endX = trajectoryExit.x();
496 float endY = trajectoryExit.y();
497
498 const int curvature = -charge;
499 const bool sweepFlag = curvature > 0;
500
501 // check if exit point is on the close or
502 // on the far side of the circle
503 const bool longArc = (trajectory2D.calcArcLength2D(trajectoryExit) > 0) ? false : true;
504 primitivePlotter.drawCircleArc(startX,
505 startY,
506 endX,
507 endY,
508 radius,
509 longArc,
510 sweepFlag,
511 attributeMap);
512 }
513 } else {
514 // trajectory is a straight line
515 if (trajectoryExit.hasNAN()) {
516 B2WARNING("Could not compute point off exit in a straight line case.");
517 } else {
518 const Vector2D start = trajectory2D.getSupport();
519 float startX = start.x();
520 float startY = start.y();
521
522 float endX = trajectoryExit.x();
523 float endY = trajectoryExit.y();
524 primitivePlotter.drawLine(startX, startY, endX, endY, attributeMap);
525 }
526 }
527}
528
529void EventDataPlotter::draw(const CDCWireHitCluster& wireHitCluster, const AttributeMap& attributeMap)
530{
531 drawRange(wireHitCluster, attributeMap);
532}
533
534void EventDataPlotter::draw(const CDCSegment2D& segment2D, const AttributeMap& attributeMap)
535{
536 if (m_forwardFade) {
537 drawRangeWithFade(segment2D, attributeMap);
538 } else {
539 drawRange(segment2D, attributeMap);
540 }
541}
542
543void EventDataPlotter::draw(const CDCSegment3D& segment3D, const AttributeMap& attributeMap)
544{
545 if (m_forwardFade) {
546 drawRange(segment3D, attributeMap);
547 } else {
548 drawRange(segment3D, attributeMap);
549 }
550}
551
552void EventDataPlotter::draw(const CDCAxialSegmentPair& axialSegmentPair,
553 const AttributeMap& attributeMap)
554{
555 if (not m_ptrPrimitivePlotter) return;
556 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
557
558 const CDCSegment2D* ptrFromSegment = axialSegmentPair.getStartSegment();
559 const CDCSegment2D* ptrToSegment = axialSegmentPair.getEndSegment();
560
561 if (not ptrFromSegment or not ptrToSegment) return;
562
563 const CDCSegment2D& fromSegment = *ptrFromSegment;
564 const CDCSegment2D& toSegment = *ptrToSegment;
565
566 const Vector2D& fromPos = fromSegment.back().getWire().getRefPos2D();
567 const Vector2D& toPos = toSegment.front().getWire().getRefPos2D();
568
569 if (fromPos.hasNAN()) {
570 B2WARNING("Center of mass of first segment in a pair contains NAN values.");
571 return;
572 }
573
574 if (toPos.hasNAN()) {
575 B2WARNING("Center of mass of second segment in a pair contains NAN values.");
576 return;
577 }
578
579 const float fromX = fromPos.x();
580 const float fromY = fromPos.y();
581
582 const float toX = toPos.x();
583 const float toY = toPos.y();
584
585 primitivePlotter.drawArrow(fromX, fromY, toX, toY, attributeMap);
586}
587
588void EventDataPlotter::draw(const CDCSegmentPair& segmentPair, const AttributeMap& attributeMap)
589{
590 if (not m_ptrPrimitivePlotter) return;
591 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
592
593 const CDCSegment2D* ptrFromSegment = segmentPair.getFromSegment();
594 const CDCSegment2D* ptrToSegment = segmentPair.getToSegment();
595
596 if (not ptrFromSegment or not ptrToSegment) return;
597
598 const CDCSegment2D& fromSegment = *ptrFromSegment;
599 const CDCSegment2D& toSegment = *ptrToSegment;
600
601 const Vector2D& fromPos = fromSegment.back().getWire().getRefPos2D();
602 const Vector2D& toPos = toSegment.front().getWire().getRefPos2D();
603
604 if (fromPos.hasNAN()) {
605 B2WARNING("Center of mass of first segment in a pair contains NAN values.");
606 return;
607 }
608
609 if (toPos.hasNAN()) {
610 B2WARNING("Center of mass of second segment in a pair contains NAN values.");
611 return;
612 }
613
614 const float fromX = fromPos.x();
615 const float fromY = fromPos.y();
616
617 const float toX = toPos.x();
618 const float toY = toPos.y();
619
620 primitivePlotter.drawArrow(fromX, fromY, toX, toY, attributeMap);
621}
622
623void EventDataPlotter::draw(const CDCSegmentTriple& segmentTriple, const AttributeMap& attributeMap)
624{
625 if (not m_ptrPrimitivePlotter) return;
626 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
627
628 const CDCSegment2D* ptrStartSegment = segmentTriple.getStartSegment();
629 const CDCSegment2D* ptrMiddleSegment = segmentTriple.getMiddleSegment();
630 const CDCSegment2D* ptrEndSegment = segmentTriple.getEndSegment();
631
632 if (not ptrStartSegment or not ptrMiddleSegment or not ptrEndSegment) return;
633
634 const CDCSegment2D& startSegment = *ptrStartSegment;
635 const CDCSegment2D& middleSegment = *ptrMiddleSegment;
636 const CDCSegment2D& endSegment = *ptrEndSegment;
637
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();
642
643 if (startBackPos2D.hasNAN()) {
644 B2WARNING("Back position of start segment in a triple contains NAN values.");
645 return;
646 }
647
648 if (middleFrontPos2D.hasNAN()) {
649 B2WARNING("Front position of middle segment in a triple contains NAN values.");
650 return;
651 }
652
653 if (middleBackPos2D.hasNAN()) {
654 B2WARNING("Back position of middle segment in a triple contains NAN values.");
655 return;
656 }
657
658 if (endFrontPos2D.hasNAN()) {
659 B2WARNING("Front position of end segment in a triple contains NAN values.");
660 return;
661 }
662
663 const float startBackX = startBackPos2D.x();
664 const float startBackY = startBackPos2D.y();
665
666 const float middleFrontX = middleFrontPos2D.x();
667 const float middleFrontY = middleFrontPos2D.y();
668
669 primitivePlotter.drawArrow(startBackX, startBackY, middleFrontX, middleFrontY, attributeMap);
670
671 const float middleBackX = middleBackPos2D.x();
672 const float middleBackY = middleBackPos2D.y();
673
674 const float endFrontX = endFrontPos2D.x();
675 const float endFrontY = endFrontPos2D.y();
676
677 primitivePlotter.drawArrow(middleBackX, middleBackY, endFrontX, endFrontY, attributeMap);
678}
679
680void EventDataPlotter::draw(const CDCTrack& track, const AttributeMap& attributeMap)
681{
682 if (m_forwardFade) {
683 drawRangeWithFade(track, attributeMap);
684 } else {
685 drawRange(track, attributeMap);
686 }
687}
688
689void EventDataPlotter::draw(const RecoTrack& recoTrack, const AttributeMap& attributeMap)
690{
691 if (not m_ptrPrimitivePlotter) return;
692 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
693
694 primitivePlotter.startGroup(attributeMap);
695 for (const CDCHit* ptrHit : recoTrack.getCDCHitList()) {
696 if (ptrHit) {
697 const CDCHit& hit = *ptrHit;
698 draw(hit);
699 }
700 }
701 primitivePlotter.endGroup();
702}
703
704void EventDataPlotter::drawTrajectory(const MCParticle& mcParticle, const AttributeMap& attributeMap)
705{
706 if (not mcParticle.isPrimaryParticle()) return;
707 Vector3D pos(mcParticle.getVertex());
708 Vector3D mom(mcParticle.getMomentum());
709 double charge = mcParticle.getCharge();
710 double time = mcParticle.getProductionTime();
711 CDCTrajectory2D trajectory2D(pos.xy(), time, mom.xy(), charge);
712 draw(trajectory2D, attributeMap);
713}
714
716 const AttributeMap& attributeMap)
717{
718 draw(segment.getTrajectory2D(), attributeMap);
719}
720
722 const AttributeMap& attributeMap)
723{
724 draw(segmentTriple.getTrajectory3D().getTrajectory2D(), attributeMap);
725}
726
727void EventDataPlotter::drawTrajectory(const CDCTrack& track, const AttributeMap& attributeMap)
728{
729 draw(track.getStartTrajectory3D().getTrajectory2D(), attributeMap);
730}
731
732void EventDataPlotter::drawTrajectory(const RecoTrack& recoTrack, const AttributeMap& attributeMap)
733{
734 if (not m_ptrPrimitivePlotter) return;
735 PrimitivePlotter& primitivePlotter = *m_ptrPrimitivePlotter;
736
737 primitivePlotter.startGroup(attributeMap);
738
739 bool fitSuccessful = not recoTrack.getRepresentations().empty() and recoTrack.wasFitSuccessful();
740 if (fitSuccessful) {
741 std::vector<std::array<float, 2>> points;
742 std::vector<std::array<float, 2>> tangents;
743
744 for (auto recoHit : recoTrack.getRecoHitInformations()) {
745 // skip for reco hits which have not been used in the fit (and therefore have no fitted information on the plane
746 if (!recoHit->useInFit())
747 continue;
748
749 TVector3 pos;
750 TVector3 mom;
751 TMatrixDSym cov;
752
753 try {
754 const auto* trackPoint = recoTrack.getCreatedTrackPoint(recoHit);
755 const auto* fittedResult = trackPoint->getFitterInfo();
756 if (not fittedResult) {
757 B2WARNING("Skipping unfitted track point");
758 continue;
759 }
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");
764 continue;
765 }
766
767 float x = pos.X();
768 float y = pos.Y();
769 float px = mom.X();
770 float py = mom.Y();
771
772 points.push_back({{x, y}});
773 tangents.push_back({{px, py}});
774 }
775 primitivePlotter.drawCurve(points, tangents, attributeMap);
776 }
777
778 primitivePlotter.endGroup();
779}
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition CDCHit.h:40
Example Detector.
Definition CDCSimHit.h:21
double getFlightTime() const
The method to get flight time.
Definition CDCSimHit.h:183
B2Vector3D getPosTrack() const
The method to get position on the track.
Definition CDCSimHit.h:216
B2Vector3D getMomentum() const
The method to get momentum.
Definition CDCSimHit.h:192
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.
Definition CDCWire.h:50
const ROOT::Math::XYVector & getRefPos2D() const
Getter for the wire reference position for 2D tracking Gives the wire's reference position projected ...
Definition CDCWire.h:221
A Class to store the Monte Carlo particle information.
Definition MCParticle.h:32
ROOT::Math::XYZVector getVertex() const
Return production vertex position, shorthand for getProductionVertex().
Definition MCParticle.h:172
float getCharge() const
Return the particle charge defined in TDatabasePDG.
Definition MCParticle.cc:36
float getProductionTime() const
Return production time in ns.
Definition MCParticle.h:148
ROOT::Math::XYZVector getMomentum() const
Return momentum.
Definition MCParticle.h:187
This is the Reconstruction Event-Data Model Track.
Definition RecoTrack.h:79
const std::vector< genfit::AbsTrackRep * > & getRepresentations() const
Return a list of track representations. You are not allowed to modify or delete them!
Definition RecoTrack.h:638
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
Definition RecoTrack.cc:336
std::vector< Belle2::RecoTrack::UsedCDCHit * > getCDCHitList() const
Return an unsorted list of cdc hits.
Definition RecoTrack.h:455
const genfit::TrackPoint * getCreatedTrackPoint(const RecoHitInformation *recoHitInformation) const
Get a pointer to the TrackPoint that was created from this hit.
Definition RecoTrack.cc:230
std::vector< RecoHitInformation * > getRecoHitInformations(bool getSorted=false) const
Return a list of all RecoHitInformations associated with the RecoTrack.
Definition RecoTrack.cc:557
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.
Definition BoundingBox.h:21
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.
Definition CDCTangent.h:40
const Vector2D & getFromRecoPos2D() const
Getter for the touching point of the tangent to the first drift circle.
Definition CDCTangent.h:63
Vector2D getToRecoPos2D() const
Getter for the touching point of the tangent to the second drift circle.
Definition CDCTangent.h:70
Class representing a sequence of three dimensional reconstructed hits.
Definition CDCTrack.h:39
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.
Class representing a hit wire in the central drift chamber.
Definition CDCWireHit.h:58
const CDCHit * getHit() const
Getter for the CDCHit pointer into the StoreArray.
Definition CDCWireHit.h:162
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
Definition CDCWireHit.h:227
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.
Definition Circle2D.h:26
double radius() const
Getter for the signed radius.
Definition Circle2D.h:197
Vector2D center() const
Getter for the central point of the circle.
Definition Circle2D.h:221
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...
Definition Vector2D.h:36
double x() const
Getter for the x coordinate.
Definition Vector2D.h:626
bool hasNAN() const
Checks if one of the coordinates is NAN.
Definition Vector2D.h:169
double y() const
Getter for the y coordinate.
Definition Vector2D.h:641
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
Definition Vector3D.h:513
bool isPrimaryParticle() const
Check if particle is a primary particle which was created by the generator (and not,...
Definition MCParticle.h:585
HepGeom::Vector3D< double > Vector3D
3D Vector
Definition Cell.h:34
Abstract base class for different kinds of events.
STL namespace.