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