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