Belle II Software release-09-00-00
CDCSVGPlotter.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/CDCSVGPlotter.h>
9#include <tracking/trackFindingCDC/display/SVGPrimitivePlotter.h>
10#include <tracking/trackFindingCDC/display/Styling.h>
11
12#include <tracking/trackFindingCDC/rootification/StoreWrappedObjPtr.h>
13
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>
18
19#include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
20#include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentTriple.h>
21#include <tracking/trackFindingCDC/eventdata/tracks/CDCAxialSegmentPair.h>
22#include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentPair.h>
23#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
24#include <tracking/trackFindingCDC/eventdata/segments/CDCWireHitCluster.h>
25#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
26
27#include <tracking/trackFindingCDC/geometry/Vector3D.h>
28#include <tracking/trackFindingCDC/geometry/Vector2D.h>
29
30#include <tracking/trackFindingCDC/utilities/ReversedRange.h>
31
32#include <tracking/dataobjects/RecoTrack.h>
33
34#include <framework/datastore/StoreArray.h>
35
36#include <cdc/dataobjects/CDCSimHit.h>
37#include <cdc/dataobjects/CDCHit.h>
38
39#include <mdst/dataobjects/MCParticle.h>
40
41#include <cmath>
42
43using namespace Belle2;
44using namespace TrackFindingCDC;
45
46namespace {
47 template<bool a_drawTrajectory, class AObject>
48 struct DrawTrajectoryHelper;
49
50 template<class AObject>
51 struct DrawTrajectoryHelper<true, AObject> {
52 public:
53 static void draw(EventDataPlotter& plotter, AObject& object, const AttributeMap& attributeMap)
54 {
55 plotter.drawTrajectory(object, attributeMap);
56 }
57 };
58
59 template<class AObject>
60 struct DrawTrajectoryHelper<false, AObject> {
61 public:
62 static void draw(EventDataPlotter& plotter, AObject& object, const AttributeMap& attributeMap)
63 {
64 plotter.draw(object, attributeMap);
65 }
66 };
67}
68
69namespace {
71 class FlightTimeOrder {
72 public:
74 bool operator()(const CDCSimHit* x, const CDCSimHit* y) const
75 {
76 return (x->getFlightTime() < y->getFlightTime());
77 }
78 };
79}
80
81static void printDataStoreContent()
82{
83 B2INFO("Current content of the DataStore:");
84 B2INFO("StoreArrays:");
85 for (auto n : DataStore::Instance().getListOfArrays(TObject::Class(), DataStore::EDurability(0))) {
86 B2INFO(n);
87 }
88 B2INFO("");
89 B2INFO("StoreObjPtr:");
90 for (auto n : DataStore::Instance().getListOfObjects(TObject::Class(), DataStore::EDurability(0))) {
91 B2INFO(n);
92 }
93}
94
95const AttributeMap c_defaultSVGAttributes({
96 {"stroke", "orange"},
97 {"stroke-width", "0.55"},
98 {"fill", "none"},
99 {"transform", "translate(0, 1120) scale(1,-1)"}
100});
101
102CDCSVGPlotter::CDCSVGPlotter(bool animate, bool forwardFade) :
103 m_eventdataPlotter(std::make_unique<SVGPrimitivePlotter>(c_defaultSVGAttributes), animate, forwardFade)
104{
105 int top = -112;
106 int left = -112;
107 int right = 112;
108 int bottom = 112;
109
110 TrackFindingCDC::BoundingBox default_bound(left, bottom, right, top);
111 int default_width = 1120;
112 int default_height = 1120;
113
114 m_eventdataPlotter.setBoundingBox(default_bound);
115 m_eventdataPlotter.setCanvasHeight(default_height);
116 m_eventdataPlotter.setCanvasWidth(default_width);
117}
118
120{
121 return (new CDCSVGPlotter(*this));
122}
123
125{
127}
128
129void CDCSVGPlotter::drawSuperLayerBoundaries(const std::string& stroke)
130{
131 AttributeMap attributeMap;
132 attributeMap.emplace("stroke", stroke);
134}
135
136void CDCSVGPlotter::drawOuterCDCWall(const std::string& stroke)
137{
138 AttributeMap attributeMap;
139 attributeMap.emplace("stroke", stroke);
141}
142
143void CDCSVGPlotter::drawInnerCDCWall(const std::string& stroke)
144{
145 AttributeMap attributeMap;
146 attributeMap.emplace("stroke", stroke);
148}
149
150void CDCSVGPlotter::drawWires(const CDCWireTopology& cdcWireTopology)
151{
152 m_eventdataPlotter.draw(cdcWireTopology);
153}
154
155void CDCSVGPlotter::drawHits(const std::string& storeArrayName,
156 const std::string& stroke,
157 const std::string& strokeWidth)
158{
159 ChooseableHitStyling styling;
160 if (stroke != "") styling.setStroke(stroke);
161 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
162 drawStoreArray<const CDCHit>(storeArrayName, styling);
163}
164
165void CDCSVGPlotter::drawSimHits(const std::string& storeArrayName,
166 const std::string& stroke,
167 const std::string& strokeWidth)
168{
169 B2INFO("Drawing simulated hits");
170 StoreArray<CDCHit> storeArray(storeArrayName);
171 if (not storeArray) {
172 B2WARNING("StoreArray " << storeArrayName << " not present");
173 printDataStoreContent();
174 return;
175 }
176 std::vector<CDCSimHit> simHitsRelatedToHits;
177 for (const CDCHit& hit : storeArray) {
178 simHitsRelatedToHits.push_back(*hit.getRelated<CDCSimHit>("CDCSimHits"));
179 }
180 B2INFO("#CDCSimHits: " << storeArray.getEntries());
182 if (stroke != "") {
183 styling.setStroke("orange");
184 } else {
185 styling.setStroke(stroke);
186 }
187 styling.setStrokeWidth(strokeWidth);
188 drawIterable(simHitsRelatedToHits, styling);
189}
190
191void CDCSVGPlotter::drawClusters(const std::string& storeObjName,
192 const std::string& stroke,
193 const std::string& strokeWidth)
194{
196 if (stroke != "") styling.setStroke(stroke);
197 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
198 drawStoreVector<const CDCWireHitCluster>(storeObjName, styling);
199}
200
201void CDCSVGPlotter::drawSegments(const std::string& storeObjName,
202 const std::string& stroke,
203 const std::string& strokeWidth)
204{
206 if (stroke != "") styling.setStroke(stroke);
207 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
208 drawStoreVector<const CDCSegment2D>(storeObjName, styling);
209}
210
211void CDCSVGPlotter::drawSegmentTrajectories(const std::string& storeObjName,
212 const std::string& stroke,
213 const std::string& strokeWidth)
214{
216 if (stroke != "") styling.setStroke(stroke);
217 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
218 const bool drawTrajectories = true;
219 drawStoreVector<const CDCSegment2D, drawTrajectories>(storeObjName, styling);
220}
221
222void CDCSVGPlotter::drawAxialSegmentPairs(const std::string& storeObjName,
223 const std::string& stroke,
224 const std::string& strokeWidth)
225{
227 if (stroke != "") styling.setStroke(stroke);
228 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
229 drawStoreVector<const CDCAxialSegmentPair>(storeObjName, styling);
230}
231
232void CDCSVGPlotter::drawSegmentPairs(const std::string& storeObjName,
233 const std::string& stroke,
234 const std::string& strokeWidth)
235{
237 if (stroke != "") styling.setStroke(stroke);
238 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
239 drawStoreVector<const CDCSegmentPair>(storeObjName, styling);
240}
241
242void CDCSVGPlotter::drawSegmentTriples(const std::string& storeObjName,
243 const std::string& stroke,
244 const std::string& strokeWidth)
245{
247 if (stroke != "") styling.setStroke(stroke);
248 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
249 drawStoreVector<const CDCSegmentTriple>(storeObjName, styling);
250}
251
252void CDCSVGPlotter::drawSegmentTripleTrajectories(const std::string& storeObjName,
253 const std::string& stroke,
254 const std::string& strokeWidth)
255{
257 if (stroke != "") styling.setStroke(stroke);
258 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
259 const bool drawTrajectories = true;
260 drawStoreVector<const CDCSegmentTriple, drawTrajectories>(storeObjName, styling);
261}
262
263void CDCSVGPlotter::drawTracks(const std::string& storeObjName,
264 const std::string& stroke,
265 const std::string& strokeWidth)
266{
268 if (stroke != "") styling.setStroke(stroke);
269 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
270 drawStoreVector<const CDCTrack>(storeObjName, styling);
271}
272
273void CDCSVGPlotter::drawTrackTrajectories(const std::string& storeObjName,
274 const std::string& stroke,
275 const std::string& strokeWidth)
276{
278 if (stroke != "") styling.setStroke(stroke);
279 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
280 const bool drawTrajectories = true;
281 drawStoreVector<const CDCTrack, drawTrajectories>(storeObjName, styling);
282}
283
284void CDCSVGPlotter::drawRecoTracks(const std::string& storeArrayName,
285 const std::string& stroke,
286 const std::string& strokeWidth)
287{
289 if (stroke != "") styling.setStroke(stroke);
290 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
291 drawStoreArray<const RecoTrack>(storeArrayName, styling);
292}
293
294void CDCSVGPlotter::drawRecoTrackTrajectories(const std::string& storeArrayName,
295 const std::string& stroke,
296 const std::string& strokeWidth)
297{
299 if (stroke != "") styling.setStroke(stroke);
300 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
301 const bool drawTrajectories = true;
302 drawStoreArray<const RecoTrack, drawTrajectories>(storeArrayName, styling);
303}
304
305void CDCSVGPlotter::drawMCParticleTrajectories(const std::string& storeArrayName,
306 const std::string& stroke,
307 const std::string& strokeWidth)
308{
310 if (stroke != "") styling.setStroke(stroke);
311 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
312 const bool drawTrajectories = true;
313 drawStoreArray<const MCParticle, drawTrajectories>(storeArrayName, styling);
314}
315
316void CDCSVGPlotter::drawSimHitsConnectByToF(const std::string& hitStoreArrayName,
317 const std::string& stroke,
318 const std::string& strokeWidth)
319{
320 B2INFO("Drawing simulated hits connected by tof");
321 StoreArray<CDCHit> hitStoreArray(hitStoreArrayName);
322 if (not hitStoreArray) {
323 B2WARNING("StoreArray " << hitStoreArrayName << " not present");
324 printDataStoreContent();
325 return;
326 }
327 std::vector<CDCSimHit*> simHits;
328 for (const CDCHit& hit : hitStoreArray) {
329 simHits.push_back(hit.getRelated<CDCSimHit>());
330 }
331
332 // group them by their mcparticle id
333 std::map<int, std::set<CDCSimHit*, FlightTimeOrder>> simHitsByMcParticleId;
334 for (CDCSimHit* simHit : simHits) {
335 MCParticle* mcParticle = simHit->getRelated<MCParticle>();
336 if (mcParticle != nullptr) {
337 int mcTrackId = mcParticle->getArrayIndex();
338 simHitsByMcParticleId[mcTrackId].insert(simHit);
339 }
340 }
341
342 AttributeMap defaultAttributeMap = {{"stroke", stroke}, {"stroke-width", strokeWidth}};
343
344 for (const auto& mcParticleIdAndSimHits : simHitsByMcParticleId) {
345 const std::set<CDCSimHit*, FlightTimeOrder>& simHitsForMcParticle =
346 mcParticleIdAndSimHits.second;
347
348 auto drawConnectSimHits = [this, &defaultAttributeMap](CDCSimHit * fromSimHit, CDCSimHit * toSimHit) {
349
350 CDCHit* fromHit = fromSimHit->getRelated<CDCHit>();
351 CDCHit* toHit = toSimHit->getRelated<CDCHit>();
352 if (fromHit == nullptr) return false;
353 if (toHit == nullptr) return false;
354
355 CDCWireHit fromWireHit(fromHit);
356 CDCWireHit toWireHit(toHit);
357
358 CDCRLWireHit fromRLWireHit(&fromWireHit);
359 CDCRLWireHit toRLWireHit(&toWireHit);
360
361 Vector3D fromDisplacement(fromSimHit->getPosTrack() - fromSimHit->getPosWire());
362 Vector3D toDisplacement(toSimHit->getPosTrack() - toSimHit->getPosWire());
363
364 CDCRecoHit2D fromRecoHit2D(fromRLWireHit, fromDisplacement.xy());
365 CDCRecoHit2D toRecoHit2D(toRLWireHit, toDisplacement.xy());
366
367 bool falseOrder = false;
368 if (fromSimHit->getArrayIndex() > toSimHit->getArrayIndex()) {
369 bool fromReassigned = fromHit->getRelatedWithWeight<MCParticle>().second < 0;
370 bool toReassigned = toHit->getRelatedWithWeight<MCParticle>().second < 0;
371 if (not fromReassigned and not toReassigned) {
372 falseOrder = true;
373 }
374 }
375
376 AttributeMap attributeMap = defaultAttributeMap;
377 if (falseOrder) {
378 attributeMap["stroke"] = "red";
379 attributeMap["stroke-width"] = "1.0";
380 }
381 draw(fromRecoHit2D, attributeMap);
382 draw(toRecoHit2D, attributeMap);
383
384 const Vector2D fromPos = fromRecoHit2D.getRecoPos2D();
385 const float fromX = fromPos.x();
386 const float fromY = fromPos.y();
387
388 const Vector2D toPos = toRecoHit2D.getRecoPos2D();
389 const float toX = toPos.x();
390 const float toY = toPos.y();
391
392 m_eventdataPlotter.drawLine(fromX, fromY, toX, toY, attributeMap);
393 return false;
394 };
395
396 // cppcheck-suppress ignoredReturnValue
397 std::adjacent_find(simHitsForMcParticle.begin(),
398 simHitsForMcParticle.end(),
399 drawConnectSimHits);
400 }
401}
402
403void CDCSVGPlotter::drawWrongRLHitsInSegments(const std::string& segmentsStoreObjName)
404{
405 this->drawWrongRLHits<CDCSegment2D>(segmentsStoreObjName);
406}
407
408void CDCSVGPlotter::drawWrongRLHitsInTracks(const std::string& tracksStoreObjName)
409{
410 this->drawWrongRLHits<CDCTrack>(tracksStoreObjName);
411}
412
413// doxygen really doesn't like these templated functions so shut it down
414// @cond doxygen_ignore
415template<class ACDCHitCollection>
416void CDCSVGPlotter::drawWrongRLHits(const std::string& hitCollectionsStoreObjName)
417{
418 B2INFO("Draw wrong right left passage information from " << hitCollectionsStoreObjName);
419 StoreWrappedObjPtr<std::vector<ACDCHitCollection>> storedHitCollections(hitCollectionsStoreObjName);
420 if (not storedHitCollections) {
421 B2WARNING(hitCollectionsStoreObjName << "does not exist in current DataStore");
422 printDataStoreContent();
423 return;
424 }
425
426 std::vector<ACDCHitCollection>& hitCollections = *storedHitCollections;
427 B2INFO("#HitCollections: " << hitCollections.size());
428
429 const CDCMCHitCollectionLookUp<ACDCHitCollection> mcHitCollectionLookUp;
430 const CDCMCHitLookUp& mcHitLookUp = CDCMCHitLookUp::getInstance();
431
432 for (const ACDCHitCollection& hitCollection : hitCollections) {
433 EForwardBackward fbInfo = mcHitCollectionLookUp.isForwardOrBackwardToMCTrack(&hitCollection);
434
435 double rlPurity = mcHitCollectionLookUp.getRLPurity(&hitCollection);
436 int correctRLVote = mcHitCollectionLookUp.getCorrectRLVote(&hitCollection);
437
438 // Skip the impure alias
439 if (rlPurity < 0.5 and hitCollection.getAutomatonCell().hasAliasFlag()) continue;
440
441 // Skip the bad reverse
442 if (correctRLVote < 0 and hitCollection.getAutomatonCell().hasReverseFlag()) continue;
443
445 for (const auto& recoHit : hitCollection) {
446 ERightLeft rlInfo = recoHit.getRLInfo();
447 const CDCHit* hit = recoHit.getWireHit().getHit();
448 ERightLeft mcRLInfo = mcHitLookUp.getRLInfo(hit);
449
450 if (fbInfo == EForwardBackward::c_Backward) {
451 mcRLInfo = reversed(mcRLInfo);
452 }
453
454 std::string color = "orange";
455 if (mcRLInfo != ERightLeft::c_Right and mcRLInfo != ERightLeft::c_Left) {
456 color = "violet";
457 } else if (mcRLInfo == rlInfo) {
458 color = "green";
459 } else if (mcRLInfo == -rlInfo) {
460 color = "red";
461 }
462
463 AttributeMap attributeMap{{"stroke", color}};
464 m_eventdataPlotter.draw(recoHit, attributeMap);
465 }
467 }
468}
469// @endcond
470
471void CDCSVGPlotter::drawMCAxialSegmentPairs(const std::string& segmentsStoreObjName,
472 const std::string& stroke,
473 const std::string& strokeWidth)
474{
475 B2INFO("Draw axial to axial segment pairs");
476 StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
477 if (not storedSegments) {
478 B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
479 printDataStoreContent();
480 return;
481 }
482
483 std::vector<CDCSegment2D>& segments = *storedSegments;
484 B2INFO("#Segments: " << segments.size());
485
486 std::vector<const CDCAxialSegment2D*> axialSegments;
487 for (const CDCAxialSegment2D& segment : segments) {
488 if (segment.isAxial()) axialSegments.push_back(&segment);
489 }
490
491 MCAxialSegmentPairFilter mcAxialSegmentPairFilter;
492 std::vector<CDCAxialSegmentPair> mcAxialSegmentPairs;
493 for (const CDCAxialSegment2D* fromSegment : axialSegments) {
494 for (const CDCAxialSegment2D* toSegment : axialSegments) {
495 if (fromSegment == toSegment) continue;
496 mcAxialSegmentPairs.emplace_back(fromSegment, toSegment);
497 Weight mcWeight = mcAxialSegmentPairFilter(mcAxialSegmentPairs.back());
498 // Remove segment pairs that are not true
499 if (std::isnan(mcWeight)) {
500 mcAxialSegmentPairs.pop_back();
501 }
502 }
503 }
504 B2INFO("# Axial segment pairs: " << mcAxialSegmentPairs.size());
506 if (stroke != "") styling.setStroke(stroke);
507 if (strokeWidth != "") styling.setStroke(strokeWidth);
508 drawIterable(mcAxialSegmentPairs, styling);
509}
510
511void CDCSVGPlotter::drawMCSegmentPairs(const std::string& segmentsStoreObjName,
512 const std::string& stroke,
513 const std::string& strokeWidth)
514{
515 B2INFO("Draw axial to stero segment pairs");
516 StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
517 if (not storedSegments) {
518 B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
519 printDataStoreContent();
520 return;
521 }
522
523 std::vector<CDCSegment2D>& segments = *storedSegments;
524 B2INFO("#Segments: " << segments.size());
525
526 std::vector<const CDCAxialSegment2D*> axialSegments;
527 std::vector<const CDCStereoSegment2D*> stereoSegments;
528 for (const CDCAxialSegment2D& segment : segments) {
529 if (segment.isAxial()) {
530 axialSegments.push_back(&segment);
531 } else {
532 stereoSegments.push_back(&segment);
533 }
534 }
535
536 MCSegmentPairFilter mcSegmentPairFilter;
537 std::vector<CDCSegmentPair> mcSegmentPairs;
538 for (const CDCAxialSegment2D* axialSegment : axialSegments) {
539 for (const CDCStereoSegment2D* stereoSegment : stereoSegments) {
540 // Axial first
541 {
542 mcSegmentPairs.emplace_back(axialSegment, stereoSegment);
543 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
544 // Remove segment pairs that are not true
545 if (std::isnan(mcWeight)) {
546 mcSegmentPairs.pop_back();
547 }
548 }
549 // Stereo first
550 {
551 mcSegmentPairs.emplace_back(stereoSegment, axialSegment);
552 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
553 // Remove segment pairs that are not true
554 if (std::isnan(mcWeight)) {
555 mcSegmentPairs.pop_back();
556 }
557 }
558 }
559 }
560 B2INFO("# Segment pairs: " << mcSegmentPairs.size());
562 if (stroke != "") styling.setStroke(stroke);
563 if (strokeWidth != "") styling.setStroke(strokeWidth);
564 drawIterable(mcSegmentPairs, styling);
565}
566
567void CDCSVGPlotter::drawMCSegmentTriples(const std::string& segmentsStoreObjName,
568 const std::string& stroke,
569 const std::string& strokeWidth)
570{
571 B2INFO("Draw segment triples");
572 StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
573 if (not storedSegments) {
574 B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
575 printDataStoreContent();
576 return;
577 }
578
579 std::vector<CDCSegment2D>& segments = *storedSegments;
580 B2INFO("#Segment " << segments.size());
581
582 std::vector<const CDCAxialSegment2D*> axialSegments;
583 std::vector<const CDCStereoSegment2D*> stereoSegments;
584 for (const CDCSegment2D& segment : segments) {
585 if (segment.isAxial()) {
586 axialSegments.push_back(&segment);
587 } else {
588 stereoSegments.push_back(&segment);
589 }
590 }
591
592 MCSegmentTripleFilter mcSegmentTripleFilter;
593 std::vector<CDCSegmentTriple> mcSegmentTriples;
594 for (const CDCAxialSegment2D* startSegment : axialSegments) {
595 for (const CDCStereoSegment2D* middleSegment : stereoSegments) {
596 for (const CDCAxialSegment2D* endSegment : axialSegments) {
597 if (startSegment == endSegment) continue;
598 mcSegmentTriples.emplace_back(startSegment, middleSegment, endSegment);
599 Weight mcWeight = mcSegmentTripleFilter(mcSegmentTriples.back());
600 // Remove segment pairs that are not true
601 if (std::isnan(mcWeight)) {
602 mcSegmentTriples.pop_back();
603 }
604 }
605 }
606 }
607 B2INFO("# Segment triples: " << mcSegmentTriples.size());
609 if (stroke != "") styling.setStroke(stroke);
610 if (strokeWidth != "") styling.setStroke(strokeWidth);
611 drawIterable(mcSegmentTriples, styling);
612}
613
614std::string CDCSVGPlotter::saveFile(const std::string& fileName)
615{
617
618 float height = boundingBox.getHeight();
619 float width = boundingBox.getWidth();
620
621 int totalPoints = 1120 * 1120;
622 float svgHeight = roundf(sqrt(totalPoints * height / width));
623 float svgWidth = roundf(sqrt(totalPoints * width / height));
624
627
628 return (m_eventdataPlotter.save(fileName));
629}
630
631// doxygen really doesn't like these templated functions so shut it down
632// @cond doxygen_ignore
633template <class AItem, bool a_drawTrajectories>
634void CDCSVGPlotter::drawStoreArray(const std::string& storeArrayName,
635 Styling<AItem>& styling)
636{
637 if (a_drawTrajectories) {
638 B2INFO("Drawing trajectories from StoreArray: " << storeArrayName);
639 } else {
640 B2INFO("Drawing StoreArray: " << storeArrayName);
641 }
642
643 using StoreItem = typename std::remove_cv<AItem>::type;
644 StoreArray<StoreItem> storeArray(storeArrayName);
645 if (not storeArray) {
646 B2WARNING(storeArrayName << " not present in the DataStore");
647 printDataStoreContent();
648 return;
649 }
650
651 B2INFO("with " << storeArray.getEntries() << " entries");
652 drawIterable<a_drawTrajectories>(storeArray, styling);
653 B2INFO("Attributes are");
654 B2INFO(styling.info());
655}
656
657template <class AItem, bool a_drawTrajectories>
658void CDCSVGPlotter::drawStoreVector(const std::string& storeObjName,
659 Styling<AItem>& styling)
660{
661 if (a_drawTrajectories) {
662 B2INFO("Drawing trajectories for vector from DataStore: " << storeObjName);
663 } else {
664 B2INFO("Drawing vector from DataStore: " << storeObjName);
665 }
666
667 using StoreItem = typename std::remove_cv<AItem>::type;
668 StoreWrappedObjPtr<std::vector<StoreItem>> storeVector(storeObjName);
669 if (not storeVector) {
670 B2WARNING(storeObjName << " not present in the DataStore");
671 B2INFO("Current content of the DataStore:");
672 printDataStoreContent();
673 return;
674 }
675
676 const std::vector<StoreItem>& vector = *storeVector;
677 B2INFO("with " << vector.size() << " entries");
678 drawIterable<a_drawTrajectories>(reversedRange(vector), styling);
679 B2INFO("Attributes are");
680 B2INFO(styling.info());
681}
682
683template <bool a_drawTrajectory, class AIterable, class AStyling>
684void CDCSVGPlotter::drawIterable(const AIterable& items, AStyling& styling)
685{
686 unsigned int index = -1;
687 for (const auto& item : items) {
688
689 ++index;
690 AttributeMap attributeMap = styling.map(index, item);
691 draw<a_drawTrajectory>(item, attributeMap);
692 }
693}
694
695template <bool a_drawTrajectory, class AObject>
696void CDCSVGPlotter::draw(const AObject& object, const AttributeMap& attributeMap)
697{
698 DrawTrajectoryHelper<a_drawTrajectory, const AObject>::draw(m_eventdataPlotter,
699 object,
700 attributeMap);
701}
702// @endcond
703
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
B2Vector3D getPosWire() const
The method to get position on wire.
Definition: CDCSimHit.h:199
B2Vector3D getPosTrack() const
The method to get position on the track.
Definition: CDCSimHit.h:217
EDurability
Durability types.
Definition: DataStore.h:58
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:244
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.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
A two dimensional rectangle that keeps track of the extend of a drawing.
Definition: BoundingBox.h:21
float getWidth() const
Getter for the width of the bounding box rectangle.
Definition: BoundingBox.h:63
float getHeight() const
Getter for the height of the bounding box rectangle.
Definition: BoundingBox.h:67
Interface class to the Monte Carlo information for collections of hits.
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 informations.
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.
ERightLeft getRLInfo(const CDCHit *ptrHit) const
Returns the true right left passage information.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Definition: CDCRLWireHit.h:41
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:47
Vector2D getRecoPos2D() const
Getter for the position in the reference plane.
Definition: CDCRecoHit2D.h:238
Helper class to generated the svg image from the various tracking objects.
Definition: CDCSVGPlotter.h:23
void drawInteractionPoint()
Draws the interaction point.
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 informations.
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 informations...
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.
void drawWires(const CDCWireTopology &cdcWireTopology)
Draws the wires.
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:39
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55
Class representating the sense wire arrangement in the whole of the central drift chamber.
This Class handles the mapping from the colormapping-method name given as a string to the actual colo...
Definition: Styling.h:234
This Class handles the mapping from the colormapping-method name given as a string to the actual colo...
Definition: Styling.h:198
This Class handles the mapping from the colormapping-method name given as a string to the actual ACol...
Definition: Styling.h:216
void setStrokeWidth(const std::string &mappingName)
Legacy method to set the mapping on how to match a object to the stroke width.
Definition: Styling.h:173
void setStroke(const std::string &mappingName)
Legacy method to set the mapping on how to match a object to the stroke color.
Definition: Styling.h:163
Class template for coloring objects with stroke colors prepared to be the default color cycle.
Definition: Styling.h:185
A class that can plot event related data types.
void drawInteractionPoint()
Marks the position of the interaction point with a filled circle.
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 drawed objects.
void drawOuterCDCWall(const AttributeMap &attributeMap=AttributeMap())
Draw the outer wall of the CDC.
void drawInnerCDCWall(const AttributeMap &attributeMap=AttributeMap())
Draw the inner wall of the CDC.
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.
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.
void drawSuperLayerBoundaries(const AttributeMap &attributeMap=AttributeMap())
Draw the super layer bounds of the CDC.
void draw(const Belle2::TrackFindingCDC::Circle2D &circle, AttributeMap attributeMap=AttributeMap())
Draws a filled circle.
void drawLine(float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap())
Draws a straight Line.
void endGroup()
Indicates the end of a group of drawn elements.
Implementation of a styling from fixed attribute map.
Definition: Styling.h:54
void setStrokeWidth(const std::string &value)
Legacy - Sets the stroke width to the fixed value.
Definition: Styling.h:87
void setStroke(const std::string &value)
Legacy - Sets the stroke color to the fixed value.
Definition: Styling.h:81
Filter for the constuction of axial to axial segment pairs based on simple criterions.
Filter for the constuction of axial to stereo segment pairs based on MC information.
Filter for the constuction of segment triples based on monte carlo information.
A concrete plotter that can draw primitive objects to standalone SVG files.
This class is for convenience access and registration of objects, that are stored inside the StoreWra...
Interface for a mapping of object and an index to styling attributes.
Definition: Styling.h:32
virtual std::string info()
Informal string summarizing the translation from the object to the styling attributes.
Definition: Styling.h:46
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:32
double x() const
Getter for the x coordinate.
Definition: Vector2D.h:595
double y() const
Getter for the y coordinate.
Definition: Vector2D.h:605
A three dimensional vector.
Definition: Vector3D.h:33
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
Definition: Vector3D.h:508
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:25
Abstract base class for different kinds of events.
STL namespace.