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
215void CDCSVGPlotter::drawSegmentTrajectories(const std::string& storeObjName,
216 const std::string& stroke,
217 const std::string& strokeWidth)
218{
220 if (stroke != "") styling.setStroke(stroke);
221 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
222 const bool drawTrajectories = true;
224}
225
226void CDCSVGPlotter::drawAxialSegmentPairs(const std::string& storeObjName,
227 const std::string& stroke,
228 const std::string& strokeWidth)
229{
231 if (stroke != "") styling.setStroke(stroke);
232 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
233 drawStoreVector<const CDCAxialSegmentPair>(storeObjName, styling);
234}
235
236void CDCSVGPlotter::drawSegmentPairs(const std::string& storeObjName,
237 const std::string& stroke,
238 const std::string& strokeWidth)
239{
241 if (stroke != "") styling.setStroke(stroke);
242 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
243 drawStoreVector<const CDCSegmentPair>(storeObjName, styling);
244}
245
246void CDCSVGPlotter::drawSegmentTriples(const std::string& storeObjName,
247 const std::string& stroke,
248 const std::string& strokeWidth)
249{
251 if (stroke != "") styling.setStroke(stroke);
252 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
253 drawStoreVector<const CDCSegmentTriple>(storeObjName, styling);
254}
255
256void CDCSVGPlotter::drawSegmentTripleTrajectories(const std::string& storeObjName,
257 const std::string& stroke,
258 const std::string& strokeWidth)
259{
261 if (stroke != "") styling.setStroke(stroke);
262 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
263 const bool drawTrajectories = true;
265}
266
267void CDCSVGPlotter::drawTracks(const std::string& storeObjName,
268 const std::string& stroke,
269 const std::string& strokeWidth)
270{
272 if (stroke != "") styling.setStroke(stroke);
273 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
274 drawStoreVector<const CDCTrack>(storeObjName, styling);
275}
276
277void CDCSVGPlotter::drawTrackTrajectories(const std::string& storeObjName,
278 const std::string& stroke,
279 const std::string& strokeWidth)
280{
282 if (stroke != "") styling.setStroke(stroke);
283 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
284 const bool drawTrajectories = true;
286}
287
288void CDCSVGPlotter::drawRecoTracks(const std::string& storeArrayName,
289 const std::string& stroke,
290 const std::string& strokeWidth)
291{
293 if (stroke != "") styling.setStroke(stroke);
294 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
295 drawStoreArray<const RecoTrack>(storeArrayName, styling);
296}
297
298void CDCSVGPlotter::drawRecoTrackTrajectories(const std::string& storeArrayName,
299 const std::string& stroke,
300 const std::string& strokeWidth)
301{
303 if (stroke != "") styling.setStroke(stroke);
304 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
305 const bool drawTrajectories = true;
307}
308
309void CDCSVGPlotter::drawMCParticleTrajectories(const std::string& storeArrayName,
310 const std::string& stroke,
311 const std::string& strokeWidth)
312{
314 if (stroke != "") styling.setStroke(stroke);
315 if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
316 const bool drawTrajectories = true;
318}
319
320void CDCSVGPlotter::drawSimHitsConnectByToF(const std::string& hitStoreArrayName,
321 const std::string& stroke,
322 const std::string& strokeWidth)
323{
324 B2INFO("Drawing simulated hits connected by tof");
325 StoreArray<CDCHit> hitStoreArray(hitStoreArrayName);
326 if (not hitStoreArray) {
327 B2WARNING("StoreArray " << hitStoreArrayName << " not present");
328 printDataStoreContent();
329 return;
330 }
331 std::vector<CDCSimHit*> simHits;
332 for (const CDCHit& hit : hitStoreArray) {
333 simHits.push_back(hit.getRelated<CDCSimHit>());
334 }
335
336 // group them by their mcparticle id
337 std::map<int, std::set<CDCSimHit*, FlightTimeOrder>> simHitsByMcParticleId;
338 for (CDCSimHit* simHit : simHits) {
339 MCParticle* mcParticle = simHit->getRelated<MCParticle>();
340 if (mcParticle != nullptr) {
341 int mcTrackId = mcParticle->getArrayIndex();
342 simHitsByMcParticleId[mcTrackId].insert(simHit);
343 }
344 }
345
346 AttributeMap defaultAttributeMap = {{"stroke", stroke}, {"stroke-width", strokeWidth}};
347
348 for (const auto& mcParticleIdAndSimHits : simHitsByMcParticleId) {
349 const std::set<CDCSimHit*, FlightTimeOrder>& simHitsForMcParticle =
350 mcParticleIdAndSimHits.second;
351
352 auto drawConnectSimHits = [this, &defaultAttributeMap](CDCSimHit * fromSimHit, CDCSimHit * toSimHit) {
353
354 CDCHit* fromHit = fromSimHit->getRelated<CDCHit>();
355 CDCHit* toHit = toSimHit->getRelated<CDCHit>();
356 if (fromHit == nullptr) return false;
357 if (toHit == nullptr) return false;
358
359 CDCWireHit fromWireHit(fromHit);
360 CDCWireHit toWireHit(toHit);
361
362 CDCRLWireHit fromRLWireHit(&fromWireHit);
363 CDCRLWireHit toRLWireHit(&toWireHit);
364
365 ROOT::Math::XYZVector fromDisplacement(fromSimHit->getPosTrack() - fromSimHit->getPosWire());
366 ROOT::Math::XYZVector toDisplacement(toSimHit->getPosTrack() - toSimHit->getPosWire());
367
368 CDCRecoHit2D fromRecoHit2D(fromRLWireHit, VectorUtil::getXYVector(fromDisplacement));
369 CDCRecoHit2D toRecoHit2D(toRLWireHit, VectorUtil::getXYVector(toDisplacement));
370
371 bool falseOrder = false;
372 if (fromSimHit->getArrayIndex() > toSimHit->getArrayIndex()) {
373 bool fromReassigned = fromHit->getRelatedWithWeight<MCParticle>().second < 0;
374 bool toReassigned = toHit->getRelatedWithWeight<MCParticle>().second < 0;
375 if (not fromReassigned and not toReassigned) {
376 falseOrder = true;
377 }
378 }
379
380 AttributeMap attributeMap = defaultAttributeMap;
381 if (falseOrder) {
382 attributeMap["stroke"] = "red";
383 attributeMap["stroke-width"] = "1.0";
384 }
385 draw(fromRecoHit2D, attributeMap);
386 draw(toRecoHit2D, attributeMap);
387
388 const ROOT::Math::XYVector fromPos = fromRecoHit2D.getRecoPos2D();
389 const float fromX = fromPos.x();
390 const float fromY = fromPos.y();
391
392 const ROOT::Math::XYVector toPos = toRecoHit2D.getRecoPos2D();
393 const float toX = toPos.x();
394 const float toY = toPos.y();
395
396 m_eventdataPlotter.drawLine(fromX, fromY, toX, toY, attributeMap);
397 return false;
398 };
399
400 std::ignore = std::adjacent_find(simHitsForMcParticle.begin(),
401 simHitsForMcParticle.end(),
402 drawConnectSimHits);
403 }
404}
405
406void CDCSVGPlotter::drawWrongRLHitsInSegments(const std::string& segmentsStoreObjName)
407{
408 this->drawWrongRLHits<CDCSegment2D>(segmentsStoreObjName);
409}
410
411void CDCSVGPlotter::drawWrongRLHitsInTracks(const std::string& tracksStoreObjName)
412{
413 this->drawWrongRLHits<CDCTrack>(tracksStoreObjName);
414}
415
416// doxygen really doesn't like these templated functions so shut it down
417// @cond doxygen_ignore
418template<class ACDCHitCollection>
419void CDCSVGPlotter::drawWrongRLHits(const std::string& hitCollectionsStoreObjName)
420{
421 B2INFO("Draw wrong right left passage information from " << hitCollectionsStoreObjName);
422 StoreWrappedObjPtr<std::vector<ACDCHitCollection>> storedHitCollections(hitCollectionsStoreObjName);
423 if (not storedHitCollections) {
424 B2WARNING(hitCollectionsStoreObjName << "does not exist in current DataStore");
425 printDataStoreContent();
426 return;
427 }
428
429 std::vector<ACDCHitCollection>& hitCollections = *storedHitCollections;
430 B2INFO("#HitCollections: " << hitCollections.size());
431
432 const CDCMCHitCollectionLookUp<ACDCHitCollection> mcHitCollectionLookUp;
433 const CDCMCHitLookUp& mcHitLookUp = CDCMCHitLookUp::getInstance();
434
435 for (const ACDCHitCollection& hitCollection : hitCollections) {
436 EForwardBackward fbInfo = mcHitCollectionLookUp.isForwardOrBackwardToMCTrack(&hitCollection);
437
438 double rlPurity = mcHitCollectionLookUp.getRLPurity(&hitCollection);
439 int correctRLVote = mcHitCollectionLookUp.getCorrectRLVote(&hitCollection);
440
441 // Skip the impure alias
442 if (rlPurity < 0.5 and hitCollection.getAutomatonCell().hasAliasFlag()) continue;
443
444 // Skip the bad reverse
445 if (correctRLVote < 0 and hitCollection.getAutomatonCell().hasReverseFlag()) continue;
446
448 for (const auto& recoHit : hitCollection) {
449 ERightLeft rlInfo = recoHit.getRLInfo();
450 const CDCHit* hit = recoHit.getWireHit().getHit();
451 ERightLeft mcRLInfo = mcHitLookUp.getRLInfo(hit);
452
453 if (fbInfo == EForwardBackward::c_Backward) {
454 mcRLInfo = reversed(mcRLInfo);
455 }
456
457 std::string color = "orange";
458 if (mcRLInfo != ERightLeft::c_Right and mcRLInfo != ERightLeft::c_Left) {
459 color = "violet";
460 } else if (mcRLInfo == rlInfo) {
461 color = "green";
462 } else if (mcRLInfo == -rlInfo) {
463 color = "red";
464 }
465
466 AttributeMap attributeMap{{"stroke", color}};
467 m_eventdataPlotter.draw(recoHit, attributeMap);
468 }
469 m_eventdataPlotter.endGroup();
470 }
471}
472// @endcond
473
474void CDCSVGPlotter::drawMCAxialSegmentPairs(const std::string& segmentsStoreObjName,
475 const std::string& stroke,
476 const std::string& strokeWidth)
477{
478 B2INFO("Draw axial to axial segment pairs");
479 StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
480 if (not storedSegments) {
481 B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
482 printDataStoreContent();
483 return;
484 }
485
486 std::vector<CDCSegment2D>& segments = *storedSegments;
487 B2INFO("#Segments: " << segments.size());
488
489 std::vector<const CDCAxialSegment2D*> axialSegments;
490 for (const CDCAxialSegment2D& segment : segments) {
491 if (segment.isAxial()) axialSegments.push_back(&segment);
492 }
493
494 MCAxialSegmentPairFilter mcAxialSegmentPairFilter;
495 std::vector<CDCAxialSegmentPair> mcAxialSegmentPairs;
496 for (const CDCAxialSegment2D* fromSegment : axialSegments) {
497 for (const CDCAxialSegment2D* toSegment : axialSegments) {
498 if (fromSegment == toSegment) continue;
499 mcAxialSegmentPairs.emplace_back(fromSegment, toSegment);
500 Weight mcWeight = mcAxialSegmentPairFilter(mcAxialSegmentPairs.back());
501 // Remove segment pairs that are not true
502 if (std::isnan(mcWeight)) {
503 mcAxialSegmentPairs.pop_back();
504 }
505 }
506 }
507 B2INFO("# Axial segment pairs: " << mcAxialSegmentPairs.size());
509 if (stroke != "") styling.setStroke(stroke);
510 if (strokeWidth != "") styling.setStroke(strokeWidth);
511 drawIterable(mcAxialSegmentPairs, styling);
512}
513
514void CDCSVGPlotter::drawMCSegmentPairs(const std::string& segmentsStoreObjName,
515 const std::string& stroke,
516 const std::string& strokeWidth)
517{
518 B2INFO("Draw axial to stero segment pairs");
519 StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
520 if (not storedSegments) {
521 B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
522 printDataStoreContent();
523 return;
524 }
525
526 std::vector<CDCSegment2D>& segments = *storedSegments;
527 B2INFO("#Segments: " << segments.size());
528
529 std::vector<const CDCAxialSegment2D*> axialSegments;
530 std::vector<const CDCStereoSegment2D*> stereoSegments;
531 for (const CDCAxialSegment2D& segment : segments) {
532 if (segment.isAxial()) {
533 axialSegments.push_back(&segment);
534 } else {
535 stereoSegments.push_back(&segment);
536 }
537 }
538
539 MCSegmentPairFilter mcSegmentPairFilter;
540 std::vector<CDCSegmentPair> mcSegmentPairs;
541 for (const CDCAxialSegment2D* axialSegment : axialSegments) {
542 for (const CDCStereoSegment2D* stereoSegment : stereoSegments) {
543 // Axial first
544 {
545 mcSegmentPairs.emplace_back(axialSegment, stereoSegment);
546 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
547 // Remove segment pairs that are not true
548 if (std::isnan(mcWeight)) {
549 mcSegmentPairs.pop_back();
550 }
551 }
552 // Stereo first
553 {
554 mcSegmentPairs.emplace_back(stereoSegment, axialSegment);
555 Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
556 // Remove segment pairs that are not true
557 if (std::isnan(mcWeight)) {
558 mcSegmentPairs.pop_back();
559 }
560 }
561 }
562 }
563 B2INFO("# Segment pairs: " << mcSegmentPairs.size());
565 if (stroke != "") styling.setStroke(stroke);
566 if (strokeWidth != "") styling.setStroke(strokeWidth);
567 drawIterable(mcSegmentPairs, styling);
568}
569
570void CDCSVGPlotter::drawMCSegmentTriples(const std::string& segmentsStoreObjName,
571 const std::string& stroke,
572 const std::string& strokeWidth)
573{
574 B2INFO("Draw segment triples");
575 StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
576 if (not storedSegments) {
577 B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
578 printDataStoreContent();
579 return;
580 }
581
582 std::vector<CDCSegment2D>& segments = *storedSegments;
583 B2INFO("#Segment " << segments.size());
584
585 std::vector<const CDCAxialSegment2D*> axialSegments;
586 std::vector<const CDCStereoSegment2D*> stereoSegments;
587 for (const CDCSegment2D& segment : segments) {
588 if (segment.isAxial()) {
589 axialSegments.push_back(&segment);
590 } else {
591 stereoSegments.push_back(&segment);
592 }
593 }
594
595 MCSegmentTripleFilter mcSegmentTripleFilter;
596 std::vector<CDCSegmentTriple> mcSegmentTriples;
597 for (const CDCAxialSegment2D* startSegment : axialSegments) {
598 for (const CDCStereoSegment2D* middleSegment : stereoSegments) {
599 for (const CDCAxialSegment2D* endSegment : axialSegments) {
600 if (startSegment == endSegment) continue;
601 mcSegmentTriples.emplace_back(startSegment, middleSegment, endSegment);
602 Weight mcWeight = mcSegmentTripleFilter(mcSegmentTriples.back());
603 // Remove segment pairs that are not true
604 if (std::isnan(mcWeight)) {
605 mcSegmentTriples.pop_back();
606 }
607 }
608 }
609 }
610 B2INFO("# Segment triples: " << mcSegmentTriples.size());
612 if (stroke != "") styling.setStroke(stroke);
613 if (strokeWidth != "") styling.setStroke(strokeWidth);
614 drawIterable(mcSegmentTriples, styling);
615}
616
617std::string CDCSVGPlotter::saveFile(const std::string& fileName)
618{
619 TrackFindingCDC::BoundingBox boundingBox = m_eventdataPlotter.getBoundingBox();
620
621 float height = boundingBox.getHeight();
622 float width = boundingBox.getWidth();
623
624 int totalPoints = 1120 * 1120;
625 float svgHeight = roundf(sqrt(totalPoints * height / width));
626 float svgWidth = roundf(sqrt(totalPoints * width / height));
627
628 m_eventdataPlotter.setCanvasHeight(svgHeight);
629 m_eventdataPlotter.setCanvasWidth(svgWidth);
630
631 return (m_eventdataPlotter.save(fileName));
632}
633
634// doxygen really doesn't like these templated functions so shut it down
635// @cond doxygen_ignore
636template <class AItem, bool a_drawTrajectories>
637void CDCSVGPlotter::drawStoreArray(const std::string& storeArrayName,
638 Styling<AItem>& styling)
639{
640 if (a_drawTrajectories) {
641 B2INFO("Drawing trajectories from StoreArray: " << storeArrayName);
642 } else {
643 B2INFO("Drawing StoreArray: " << storeArrayName);
644 }
645
646 using StoreItem = typename std::remove_cv<AItem>::type;
647 StoreArray<StoreItem> storeArray(storeArrayName);
648 if (not storeArray) {
649 B2WARNING(storeArrayName << " not present in the DataStore");
650 printDataStoreContent();
651 return;
652 }
653
654 B2INFO("with " << storeArray.getEntries() << " entries");
655 drawIterable<a_drawTrajectories>(storeArray, styling);
656 B2INFO("Attributes are");
657 B2INFO(styling.info());
658}
659
660template <class AItem, bool a_drawTrajectories>
661void CDCSVGPlotter::drawStoreVector(const std::string& storeObjName,
662 Styling<AItem>& styling)
663{
664 if (a_drawTrajectories) {
665 B2INFO("Drawing trajectories for vector from DataStore: " << storeObjName);
666 } else {
667 B2INFO("Drawing vector from DataStore: " << storeObjName);
668 }
669
670 using StoreItem = typename std::remove_cv<AItem>::type;
671 StoreWrappedObjPtr<std::vector<StoreItem>> storeVector(storeObjName);
672 if (not storeVector) {
673 B2WARNING(storeObjName << " not present in the DataStore");
674 B2INFO("Current content of the DataStore:");
675 printDataStoreContent();
676 return;
677 }
678
679 const std::vector<StoreItem>& vector = *storeVector;
680 B2INFO("with " << vector.size() << " entries");
681 drawIterable<a_drawTrajectories>(reversedRange(vector), styling);
682 B2INFO("Attributes are");
683 B2INFO(styling.info());
684}
685
686template <bool a_drawTrajectory, class AIterable, class AStyling>
687void CDCSVGPlotter::drawIterable(const AIterable& items, AStyling& styling)
688{
689 unsigned int index = -1;
690 for (const auto& item : items) {
691
692 ++index;
693 AttributeMap attributeMap = styling.map(index, item);
694 draw<a_drawTrajectory>(item, attributeMap);
695 }
696}
697
698template <bool a_drawTrajectory, class AObject>
699void CDCSVGPlotter::draw(const AObject& object, const AttributeMap& attributeMap)
700{
701 DrawTrajectoryHelper<a_drawTrajectory, const AObject>::draw(m_eventdataPlotter,
702 object,
703 attributeMap);
704}
705// @endcond
706
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.
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.