Belle II Software development
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
43// for std::ignore
44#include <utility>
45
46using namespace Belle2;
47using namespace TrackFindingCDC;
48
49namespace {
50 template<bool a_drawTrajectory, class AObject>
51 struct DrawTrajectoryHelper;
52
53 template<class AObject>
54 struct DrawTrajectoryHelper<true, AObject> {
55 public:
56 static void draw(EventDataPlotter& plotter, AObject& object, const AttributeMap& attributeMap)
57 {
58 plotter.drawTrajectory(object, attributeMap);
59 }
60 };
61
62 template<class AObject>
63 struct DrawTrajectoryHelper<false, AObject> {
64 public:
65 static void draw(EventDataPlotter& plotter, AObject& object, const AttributeMap& attributeMap)
66 {
67 plotter.draw(object, attributeMap);
68 }
69 };
70}
71
72namespace {
74 class FlightTimeOrder {
75 public:
77 bool operator()(const CDCSimHit* x, const CDCSimHit* y) const
78 {
79 return (x->getFlightTime() < y->getFlightTime());
80 }
81 };
82}
83
84static void printDataStoreContent()
85{
86 B2INFO("Current content of the DataStore:");
87 B2INFO("StoreArrays:");
88 for (auto n : DataStore::Instance().getListOfArrays(TObject::Class(), DataStore::EDurability(0))) {
89 B2INFO(n);
90 }
91 B2INFO("");
92 B2INFO("StoreObjPtr:");
93 for (auto n : DataStore::Instance().getListOfObjects(TObject::Class(), DataStore::EDurability(0))) {
94 B2INFO(n);
95 }
96}
97
98const AttributeMap c_defaultSVGAttributes({
99 {"stroke", "orange"},
100 {"stroke-width", "0.55"},
101 {"fill", "none"},
102 {"transform", "translate(0, 1120) scale(1,-1)"}
103});
104
105CDCSVGPlotter::CDCSVGPlotter(bool animate, bool forwardFade) :
106 m_eventdataPlotter(std::make_unique<SVGPrimitivePlotter>(c_defaultSVGAttributes), animate, forwardFade)
107{
108 int top = -112;
109 int left = -112;
110 int right = 112;
111 int bottom = 112;
112
113 TrackFindingCDC::BoundingBox default_bound(left, bottom, right, top);
114 int default_width = 1120;
115 int default_height = 1120;
116
117 m_eventdataPlotter.setBoundingBox(default_bound);
118 m_eventdataPlotter.setCanvasHeight(default_height);
119 m_eventdataPlotter.setCanvasWidth(default_width);
120}
121
123{
124 return (new CDCSVGPlotter(*this));
125}
126
128{
130}
131
132void CDCSVGPlotter::drawSuperLayerBoundaries(const std::string& stroke)
133{
134 AttributeMap attributeMap;
135 attributeMap.emplace("stroke", stroke);
137}
138
139void CDCSVGPlotter::drawOuterCDCWall(const std::string& stroke)
140{
141 AttributeMap attributeMap;
142 attributeMap.emplace("stroke", stroke);
144}
145
146void CDCSVGPlotter::drawInnerCDCWall(const std::string& stroke)
147{
148 AttributeMap attributeMap;
149 attributeMap.emplace("stroke", stroke);
151}
152
153void CDCSVGPlotter::drawWires(const CDCWireTopology& cdcWireTopology)
154{
155 m_eventdataPlotter.draw(cdcWireTopology);
156}
157
158void CDCSVGPlotter::drawHits(const std::string& storeArrayName,
159 const std::string& stroke,
160 const std::string& strokeWidth)
161{
162 ChooseableHitStyling styling;
163 if (stroke != "") styling.setStroke(stroke);
164 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
165 drawStoreArray<const CDCHit>(storeArrayName, styling);
166}
167
168void CDCSVGPlotter::drawSimHits(const std::string& storeArrayName,
169 const std::string& stroke,
170 const std::string& strokeWidth)
171{
172 B2INFO("Drawing simulated hits");
173 StoreArray<CDCHit> storeArray(storeArrayName);
174 if (not storeArray) {
175 B2WARNING("StoreArray " << storeArrayName << " not present");
176 printDataStoreContent();
177 return;
178 }
179 std::vector<CDCSimHit> simHitsRelatedToHits;
180 for (const CDCHit& hit : storeArray) {
181 simHitsRelatedToHits.push_back(*hit.getRelated<CDCSimHit>("CDCSimHits"));
182 }
183 B2INFO("#CDCSimHits: " << storeArray.getEntries());
185 if (stroke != "") {
186 styling.setStroke("orange");
187 } else {
188 styling.setStroke(stroke);
189 }
190 styling.setStrokeWidth(strokeWidth);
191 drawIterable(simHitsRelatedToHits, styling);
192}
193
194void CDCSVGPlotter::drawClusters(const std::string& storeObjName,
195 const std::string& stroke,
196 const std::string& strokeWidth)
197{
199 if (stroke != "") styling.setStroke(stroke);
200 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
201 drawStoreVector<const CDCWireHitCluster>(storeObjName, styling);
202}
203
204void CDCSVGPlotter::drawSegments(const std::string& storeObjName,
205 const std::string& stroke,
206 const std::string& strokeWidth)
207{
209 if (stroke != "") styling.setStroke(stroke);
210 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
211 drawStoreVector<const CDCSegment2D>(storeObjName, styling);
212}
213
214void CDCSVGPlotter::drawSegmentTrajectories(const std::string& storeObjName,
215 const std::string& stroke,
216 const std::string& strokeWidth)
217{
219 if (stroke != "") styling.setStroke(stroke);
220 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
221 const bool drawTrajectories = true;
222 drawStoreVector<const CDCSegment2D, drawTrajectories>(storeObjName, styling);
223}
224
225void CDCSVGPlotter::drawAxialSegmentPairs(const std::string& storeObjName,
226 const std::string& stroke,
227 const std::string& strokeWidth)
228{
230 if (stroke != "") styling.setStroke(stroke);
231 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
232 drawStoreVector<const CDCAxialSegmentPair>(storeObjName, styling);
233}
234
235void CDCSVGPlotter::drawSegmentPairs(const std::string& storeObjName,
236 const std::string& stroke,
237 const std::string& strokeWidth)
238{
240 if (stroke != "") styling.setStroke(stroke);
241 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
242 drawStoreVector<const CDCSegmentPair>(storeObjName, styling);
243}
244
245void CDCSVGPlotter::drawSegmentTriples(const std::string& storeObjName,
246 const std::string& stroke,
247 const std::string& strokeWidth)
248{
250 if (stroke != "") styling.setStroke(stroke);
251 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
252 drawStoreVector<const CDCSegmentTriple>(storeObjName, styling);
253}
254
255void CDCSVGPlotter::drawSegmentTripleTrajectories(const std::string& storeObjName,
256 const std::string& stroke,
257 const std::string& strokeWidth)
258{
260 if (stroke != "") styling.setStroke(stroke);
261 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
262 const bool drawTrajectories = true;
263 drawStoreVector<const CDCSegmentTriple, drawTrajectories>(storeObjName, styling);
264}
265
266void CDCSVGPlotter::drawTracks(const std::string& storeObjName,
267 const std::string& stroke,
268 const std::string& strokeWidth)
269{
271 if (stroke != "") styling.setStroke(stroke);
272 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
273 drawStoreVector<const CDCTrack>(storeObjName, styling);
274}
275
276void CDCSVGPlotter::drawTrackTrajectories(const std::string& storeObjName,
277 const std::string& stroke,
278 const std::string& strokeWidth)
279{
281 if (stroke != "") styling.setStroke(stroke);
282 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
283 const bool drawTrajectories = true;
284 drawStoreVector<const CDCTrack, drawTrajectories>(storeObjName, styling);
285}
286
287void CDCSVGPlotter::drawRecoTracks(const std::string& storeArrayName,
288 const std::string& stroke,
289 const std::string& strokeWidth)
290{
292 if (stroke != "") styling.setStroke(stroke);
293 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
294 drawStoreArray<const RecoTrack>(storeArrayName, styling);
295}
296
297void CDCSVGPlotter::drawRecoTrackTrajectories(const std::string& storeArrayName,
298 const std::string& stroke,
299 const std::string& strokeWidth)
300{
302 if (stroke != "") styling.setStroke(stroke);
303 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
304 const bool drawTrajectories = true;
305 drawStoreArray<const RecoTrack, drawTrajectories>(storeArrayName, styling);
306}
307
308void CDCSVGPlotter::drawMCParticleTrajectories(const std::string& storeArrayName,
309 const std::string& stroke,
310 const std::string& strokeWidth)
311{
313 if (stroke != "") styling.setStroke(stroke);
314 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
315 const bool drawTrajectories = true;
316 drawStoreArray<const MCParticle, drawTrajectories>(storeArrayName, styling);
317}
318
319void CDCSVGPlotter::drawSimHitsConnectByToF(const std::string& hitStoreArrayName,
320 const std::string& stroke,
321 const std::string& strokeWidth)
322{
323 B2INFO("Drawing simulated hits connected by tof");
324 StoreArray<CDCHit> hitStoreArray(hitStoreArrayName);
325 if (not hitStoreArray) {
326 B2WARNING("StoreArray " << hitStoreArrayName << " not present");
327 printDataStoreContent();
328 return;
329 }
330 std::vector<CDCSimHit*> simHits;
331 for (const CDCHit& hit : hitStoreArray) {
332 simHits.push_back(hit.getRelated<CDCSimHit>());
333 }
334
335 // group them by their mcparticle id
336 std::map<int, std::set<CDCSimHit*, FlightTimeOrder>> simHitsByMcParticleId;
337 for (CDCSimHit* simHit : simHits) {
338 MCParticle* mcParticle = simHit->getRelated<MCParticle>();
339 if (mcParticle != nullptr) {
340 int mcTrackId = mcParticle->getArrayIndex();
341 simHitsByMcParticleId[mcTrackId].insert(simHit);
342 }
343 }
344
345 AttributeMap defaultAttributeMap = {{"stroke", stroke}, {"stroke-width", strokeWidth}};
346
347 for (const auto& mcParticleIdAndSimHits : simHitsByMcParticleId) {
348 const std::set<CDCSimHit*, FlightTimeOrder>& simHitsForMcParticle =
349 mcParticleIdAndSimHits.second;
350
351 auto drawConnectSimHits = [this, &defaultAttributeMap](CDCSimHit * fromSimHit, CDCSimHit * toSimHit) {
352
353 CDCHit* fromHit = fromSimHit->getRelated<CDCHit>();
354 CDCHit* toHit = toSimHit->getRelated<CDCHit>();
355 if (fromHit == nullptr) return false;
356 if (toHit == nullptr) return false;
357
358 CDCWireHit fromWireHit(fromHit);
359 CDCWireHit toWireHit(toHit);
360
361 CDCRLWireHit fromRLWireHit(&fromWireHit);
362 CDCRLWireHit toRLWireHit(&toWireHit);
363
364 Vector3D fromDisplacement(fromSimHit->getPosTrack() - fromSimHit->getPosWire());
365 Vector3D toDisplacement(toSimHit->getPosTrack() - toSimHit->getPosWire());
366
367 CDCRecoHit2D fromRecoHit2D(fromRLWireHit, fromDisplacement.xy());
368 CDCRecoHit2D toRecoHit2D(toRLWireHit, toDisplacement.xy());
369
370 bool falseOrder = false;
371 if (fromSimHit->getArrayIndex() > toSimHit->getArrayIndex()) {
372 bool fromReassigned = fromHit->getRelatedWithWeight<MCParticle>().second < 0;
373 bool toReassigned = toHit->getRelatedWithWeight<MCParticle>().second < 0;
374 if (not fromReassigned and not toReassigned) {
375 falseOrder = true;
376 }
377 }
378
379 AttributeMap attributeMap = defaultAttributeMap;
380 if (falseOrder) {
381 attributeMap["stroke"] = "red";
382 attributeMap["stroke-width"] = "1.0";
383 }
384 draw(fromRecoHit2D, attributeMap);
385 draw(toRecoHit2D, attributeMap);
386
387 const Vector2D fromPos = fromRecoHit2D.getRecoPos2D();
388 const float fromX = fromPos.x();
389 const float fromY = fromPos.y();
390
391 const Vector2D toPos = toRecoHit2D.getRecoPos2D();
392 const float toX = toPos.x();
393 const float toY = toPos.y();
394
395 m_eventdataPlotter.drawLine(fromX, fromY, toX, toY, attributeMap);
396 return false;
397 };
398
399 std::ignore = std::adjacent_find(simHitsForMcParticle.begin(),
400 simHitsForMcParticle.end(),
401 drawConnectSimHits);
402 }
403}
404
405void CDCSVGPlotter::drawWrongRLHitsInSegments(const std::string& segmentsStoreObjName)
406{
407 this->drawWrongRLHits<CDCSegment2D>(segmentsStoreObjName);
408}
409
410void CDCSVGPlotter::drawWrongRLHitsInTracks(const std::string& tracksStoreObjName)
411{
412 this->drawWrongRLHits<CDCTrack>(tracksStoreObjName);
413}
414
415// doxygen really doesn't like these templated functions so shut it down
416// @cond doxygen_ignore
417template<class ACDCHitCollection>
418void CDCSVGPlotter::drawWrongRLHits(const std::string& hitCollectionsStoreObjName)
419{
420 B2INFO("Draw wrong right left passage information from " << hitCollectionsStoreObjName);
421 StoreWrappedObjPtr<std::vector<ACDCHitCollection>> storedHitCollections(hitCollectionsStoreObjName);
422 if (not storedHitCollections) {
423 B2WARNING(hitCollectionsStoreObjName << "does not exist in current DataStore");
424 printDataStoreContent();
425 return;
426 }
427
428 std::vector<ACDCHitCollection>& hitCollections = *storedHitCollections;
429 B2INFO("#HitCollections: " << hitCollections.size());
430
431 const CDCMCHitCollectionLookUp<ACDCHitCollection> mcHitCollectionLookUp;
432 const CDCMCHitLookUp& mcHitLookUp = CDCMCHitLookUp::getInstance();
433
434 for (const ACDCHitCollection& hitCollection : hitCollections) {
435 EForwardBackward fbInfo = mcHitCollectionLookUp.isForwardOrBackwardToMCTrack(&hitCollection);
436
437 double rlPurity = mcHitCollectionLookUp.getRLPurity(&hitCollection);
438 int correctRLVote = mcHitCollectionLookUp.getCorrectRLVote(&hitCollection);
439
440 // Skip the impure alias
441 if (rlPurity < 0.5 and hitCollection.getAutomatonCell().hasAliasFlag()) continue;
442
443 // Skip the bad reverse
444 if (correctRLVote < 0 and hitCollection.getAutomatonCell().hasReverseFlag()) continue;
445
447 for (const auto& recoHit : hitCollection) {
448 ERightLeft rlInfo = recoHit.getRLInfo();
449 const CDCHit* hit = recoHit.getWireHit().getHit();
450 ERightLeft mcRLInfo = mcHitLookUp.getRLInfo(hit);
451
452 if (fbInfo == EForwardBackward::c_Backward) {
453 mcRLInfo = reversed(mcRLInfo);
454 }
455
456 std::string color = "orange";
457 if (mcRLInfo != ERightLeft::c_Right and mcRLInfo != ERightLeft::c_Left) {
458 color = "violet";
459 } else if (mcRLInfo == rlInfo) {
460 color = "green";
461 } else if (mcRLInfo == -rlInfo) {
462 color = "red";
463 }
464
465 AttributeMap attributeMap{{"stroke", color}};
466 m_eventdataPlotter.draw(recoHit, attributeMap);
467 }
469 }
470}
471// @endcond
472
473void CDCSVGPlotter::drawMCAxialSegmentPairs(const std::string& segmentsStoreObjName,
474 const std::string& stroke,
475 const std::string& strokeWidth)
476{
477 B2INFO("Draw axial to axial segment pairs");
478 StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
479 if (not storedSegments) {
480 B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
481 printDataStoreContent();
482 return;
483 }
484
485 std::vector<CDCSegment2D>& segments = *storedSegments;
486 B2INFO("#Segments: " << segments.size());
487
488 std::vector<const CDCAxialSegment2D*> axialSegments;
489 for (const CDCAxialSegment2D& segment : segments) {
490 if (segment.isAxial()) axialSegments.push_back(&segment);
491 }
492
493 MCAxialSegmentPairFilter mcAxialSegmentPairFilter;
494 std::vector<CDCAxialSegmentPair> mcAxialSegmentPairs;
495 for (const CDCAxialSegment2D* fromSegment : axialSegments) {
496 for (const CDCAxialSegment2D* toSegment : axialSegments) {
497 if (fromSegment == toSegment) continue;
498 mcAxialSegmentPairs.emplace_back(fromSegment, toSegment);
499 Weight mcWeight = mcAxialSegmentPairFilter(mcAxialSegmentPairs.back());
500 // Remove segment pairs that are not true
501 if (std::isnan(mcWeight)) {
502 mcAxialSegmentPairs.pop_back();
503 }
504 }
505 }
506 B2INFO("# Axial segment pairs: " << mcAxialSegmentPairs.size());
508 if (stroke != "") styling.setStroke(stroke);
509 if (strokeWidth != "") styling.setStroke(strokeWidth);
510 drawIterable(mcAxialSegmentPairs, styling);
511}
512
513void CDCSVGPlotter::drawMCSegmentPairs(const std::string& segmentsStoreObjName,
514 const std::string& stroke,
515 const std::string& strokeWidth)
516{
517 B2INFO("Draw axial to stero segment pairs");
518 StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
519 if (not storedSegments) {
520 B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
521 printDataStoreContent();
522 return;
523 }
524
525 std::vector<CDCSegment2D>& segments = *storedSegments;
526 B2INFO("#Segments: " << segments.size());
527
528 std::vector<const CDCAxialSegment2D*> axialSegments;
529 std::vector<const CDCStereoSegment2D*> stereoSegments;
530 for (const CDCAxialSegment2D& segment : segments) {
531 if (segment.isAxial()) {
532 axialSegments.push_back(&segment);
533 } else {
534 stereoSegments.push_back(&segment);
535 }
536 }
537
538 MCSegmentPairFilter mcSegmentPairFilter;
539 std::vector<CDCSegmentPair> mcSegmentPairs;
540 for (const CDCAxialSegment2D* axialSegment : axialSegments) {
541 for (const CDCStereoSegment2D* stereoSegment : stereoSegments) {
542 // Axial first
543 {
544 mcSegmentPairs.emplace_back(axialSegment, stereoSegment);
545 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
546 // Remove segment pairs that are not true
547 if (std::isnan(mcWeight)) {
548 mcSegmentPairs.pop_back();
549 }
550 }
551 // Stereo first
552 {
553 mcSegmentPairs.emplace_back(stereoSegment, axialSegment);
554 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
555 // Remove segment pairs that are not true
556 if (std::isnan(mcWeight)) {
557 mcSegmentPairs.pop_back();
558 }
559 }
560 }
561 }
562 B2INFO("# Segment pairs: " << mcSegmentPairs.size());
564 if (stroke != "") styling.setStroke(stroke);
565 if (strokeWidth != "") styling.setStroke(strokeWidth);
566 drawIterable(mcSegmentPairs, styling);
567}
568
569void CDCSVGPlotter::drawMCSegmentTriples(const std::string& segmentsStoreObjName,
570 const std::string& stroke,
571 const std::string& strokeWidth)
572{
573 B2INFO("Draw segment triples");
574 StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
575 if (not storedSegments) {
576 B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
577 printDataStoreContent();
578 return;
579 }
580
581 std::vector<CDCSegment2D>& segments = *storedSegments;
582 B2INFO("#Segment " << segments.size());
583
584 std::vector<const CDCAxialSegment2D*> axialSegments;
585 std::vector<const CDCStereoSegment2D*> stereoSegments;
586 for (const CDCSegment2D& segment : segments) {
587 if (segment.isAxial()) {
588 axialSegments.push_back(&segment);
589 } else {
590 stereoSegments.push_back(&segment);
591 }
592 }
593
594 MCSegmentTripleFilter mcSegmentTripleFilter;
595 std::vector<CDCSegmentTriple> mcSegmentTriples;
596 for (const CDCAxialSegment2D* startSegment : axialSegments) {
597 for (const CDCStereoSegment2D* middleSegment : stereoSegments) {
598 for (const CDCAxialSegment2D* endSegment : axialSegments) {
599 if (startSegment == endSegment) continue;
600 mcSegmentTriples.emplace_back(startSegment, middleSegment, endSegment);
601 Weight mcWeight = mcSegmentTripleFilter(mcSegmentTriples.back());
602 // Remove segment pairs that are not true
603 if (std::isnan(mcWeight)) {
604 mcSegmentTriples.pop_back();
605 }
606 }
607 }
608 }
609 B2INFO("# Segment triples: " << mcSegmentTriples.size());
611 if (stroke != "") styling.setStroke(stroke);
612 if (strokeWidth != "") styling.setStroke(strokeWidth);
613 drawIterable(mcSegmentTriples, styling);
614}
615
616std::string CDCSVGPlotter::saveFile(const std::string& fileName)
617{
619
620 float height = boundingBox.getHeight();
621 float width = boundingBox.getWidth();
622
623 int totalPoints = 1120 * 1120;
624 float svgHeight = roundf(sqrt(totalPoints * height / width));
625 float svgWidth = roundf(sqrt(totalPoints * width / height));
626
629
630 return (m_eventdataPlotter.save(fileName));
631}
632
633// doxygen really doesn't like these templated functions so shut it down
634// @cond doxygen_ignore
635template <class AItem, bool a_drawTrajectories>
636void CDCSVGPlotter::drawStoreArray(const std::string& storeArrayName,
637 Styling<AItem>& styling)
638{
639 if (a_drawTrajectories) {
640 B2INFO("Drawing trajectories from StoreArray: " << storeArrayName);
641 } else {
642 B2INFO("Drawing StoreArray: " << storeArrayName);
643 }
644
645 using StoreItem = typename std::remove_cv<AItem>::type;
646 StoreArray<StoreItem> storeArray(storeArrayName);
647 if (not storeArray) {
648 B2WARNING(storeArrayName << " not present in the DataStore");
649 printDataStoreContent();
650 return;
651 }
652
653 B2INFO("with " << storeArray.getEntries() << " entries");
654 drawIterable<a_drawTrajectories>(storeArray, styling);
655 B2INFO("Attributes are");
656 B2INFO(styling.info());
657}
658
659template <class AItem, bool a_drawTrajectories>
660void CDCSVGPlotter::drawStoreVector(const std::string& storeObjName,
661 Styling<AItem>& styling)
662{
663 if (a_drawTrajectories) {
664 B2INFO("Drawing trajectories for vector from DataStore: " << storeObjName);
665 } else {
666 B2INFO("Drawing vector from DataStore: " << storeObjName);
667 }
668
669 using StoreItem = typename std::remove_cv<AItem>::type;
670 StoreWrappedObjPtr<std::vector<StoreItem>> storeVector(storeObjName);
671 if (not storeVector) {
672 B2WARNING(storeObjName << " not present in the DataStore");
673 B2INFO("Current content of the DataStore:");
674 printDataStoreContent();
675 return;
676 }
677
678 const std::vector<StoreItem>& vector = *storeVector;
679 B2INFO("with " << vector.size() << " entries");
680 drawIterable<a_drawTrajectories>(reversedRange(vector), styling);
681 B2INFO("Attributes are");
682 B2INFO(styling.info());
683}
684
685template <bool a_drawTrajectory, class AIterable, class AStyling>
686void CDCSVGPlotter::drawIterable(const AIterable& items, AStyling& styling)
687{
688 unsigned int index = -1;
689 for (const auto& item : items) {
690
691 ++index;
692 AttributeMap attributeMap = styling.map(index, item);
693 draw<a_drawTrajectory>(item, attributeMap);
694 }
695}
696
697template <bool a_drawTrajectory, class AObject>
698void CDCSVGPlotter::draw(const AObject& object, const AttributeMap& attributeMap)
699{
700 DrawTrajectoryHelper<a_drawTrajectory, const AObject>::draw(m_eventdataPlotter,
701 object,
702 attributeMap);
703}
704// @endcond
705
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 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.
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 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.
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 representing 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 drawn 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 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.
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 handling of orientation relate...
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.