Belle II Software  release-05-01-25
CDCSVGPlotter.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: dschneider, Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/display/CDCSVGPlotter.h>
11 #include <tracking/trackFindingCDC/display/SVGPrimitivePlotter.h>
12 #include <tracking/trackFindingCDC/display/Styling.h>
13 
14 #include <tracking/trackFindingCDC/rootification/StoreWrappedObjPtr.h>
15 
16 #include <tracking/trackFindingCDC/filters/axialSegmentPair/MCAxialSegmentPairFilter.h>
17 #include <tracking/trackFindingCDC/filters/segmentPair/MCSegmentPairFilter.h>
18 #include <tracking/trackFindingCDC/filters/segmentTriple/MCSegmentTripleFilter.h>
19 #include <tracking/trackFindingCDC/mclookup/CDCMCSegment2DLookUp.h>
20 
21 #include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
22 #include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentTriple.h>
23 #include <tracking/trackFindingCDC/eventdata/tracks/CDCAxialSegmentPair.h>
24 #include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentPair.h>
25 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
26 #include <tracking/trackFindingCDC/eventdata/segments/CDCWireHitCluster.h>
27 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
28 
29 #include <tracking/trackFindingCDC/geometry/Vector3D.h>
30 #include <tracking/trackFindingCDC/geometry/Vector2D.h>
31 
32 #include <tracking/trackFindingCDC/utilities/ReversedRange.h>
33 
34 #include <tracking/dataobjects/RecoTrack.h>
35 
36 #include <framework/datastore/StoreArray.h>
37 
38 #include <cdc/dataobjects/CDCSimHit.h>
39 #include <cdc/dataobjects/CDCHit.h>
40 
41 #include <mdst/dataobjects/MCParticle.h>
42 
43 #include <cmath>
44 
45 using namespace Belle2;
46 using namespace TrackFindingCDC;
47 
48 namespace {
49  template<bool a_drawTrajectory, class AObject>
50  struct DrawTrajectoryHelper;
51 
52  template<class AObject>
53  struct DrawTrajectoryHelper<true, AObject> {
54  public:
55  static void draw(EventDataPlotter& plotter, AObject& object, const AttributeMap& attributeMap)
56  {
57  plotter.drawTrajectory(object, attributeMap);
58  }
59  };
60 
61  template<class AObject>
62  struct DrawTrajectoryHelper<false, AObject> {
63  public:
64  static void draw(EventDataPlotter& plotter, AObject& object, const AttributeMap& attributeMap)
65  {
66  plotter.draw(object, attributeMap);
67  }
68  };
69 }
70 
71 namespace {
73  class FlightTimeOrder {
74  public:
76  bool operator()(const CDCSimHit* x, const CDCSimHit* y) const
77  {
78  return (x->getFlightTime() < y->getFlightTime());
79  }
80  };
81 }
82 
83 static void printDataStoreContent()
84 {
85  B2INFO("Current content of the DataStore:");
86  B2INFO("StoreArrays:");
87  for (auto n : DataStore::Instance().getListOfArrays(TObject::Class(), DataStore::EDurability(0))) {
88  B2INFO(n);
89  }
90  B2INFO("");
91  B2INFO("StoreObjPtr:");
92  for (auto n : DataStore::Instance().getListOfObjects(TObject::Class(), DataStore::EDurability(0))) {
93  B2INFO(n);
94  }
95 }
96 
97 const AttributeMap c_defaultSVGAttributes({
98  {"stroke", "orange"},
99  {"stroke-width", "0.55"},
100  {"fill", "none"},
101  {"transform", "translate(0, 1120) scale(1,-1)"}
102 });
103 
104 CDCSVGPlotter::CDCSVGPlotter(bool animate, bool forwardFade) :
105  m_eventdataPlotter(std::make_unique<SVGPrimitivePlotter>(c_defaultSVGAttributes), animate, forwardFade)
106 {
107  int top = -112;
108  int left = -112;
109  int right = 112;
110  int bottom = 112;
111 
112  TrackFindingCDC::BoundingBox default_bound(left, bottom, right, top);
113  int default_width = 1120;
114  int default_height = 1120;
115 
116  m_eventdataPlotter.setBoundingBox(default_bound);
117  m_eventdataPlotter.setCanvasHeight(default_height);
118  m_eventdataPlotter.setCanvasWidth(default_width);
119 }
120 
122 {
123  return (new CDCSVGPlotter(*this));
124 }
125 
127 {
129 }
130 
131 void CDCSVGPlotter::drawSuperLayerBoundaries(const std::string& stroke)
132 {
133  AttributeMap attributeMap;
134  attributeMap.emplace("stroke", stroke);
136 }
137 
138 void CDCSVGPlotter::drawOuterCDCWall(const std::string& stroke)
139 {
140  AttributeMap attributeMap;
141  attributeMap.emplace("stroke", stroke);
142  m_eventdataPlotter.drawOuterCDCWall(attributeMap);
143 }
144 
145 void CDCSVGPlotter::drawInnerCDCWall(const std::string& stroke)
146 {
147  AttributeMap attributeMap;
148  attributeMap.emplace("stroke", stroke);
149  m_eventdataPlotter.drawInnerCDCWall(attributeMap);
150 }
151 
152 void CDCSVGPlotter::drawWires(const CDCWireTopology& cdcWireTopology)
153 {
154  m_eventdataPlotter.draw(cdcWireTopology);
155 }
156 
157 void CDCSVGPlotter::drawHits(const std::string& storeArrayName,
158  const std::string& stroke,
159  const std::string& strokeWidth)
160 {
161  ChooseableHitStyling styling;
162  if (stroke != "") styling.setStroke(stroke);
163  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
164  drawStoreArray<const CDCHit>(storeArrayName, styling);
165 }
166 
167 void CDCSVGPlotter::drawSimHits(const std::string& storeArrayName,
168  const std::string& stroke,
169  const std::string& strokeWidth)
170 {
171  B2INFO("Drawing simulated hits");
172  StoreArray<CDCHit> storeArray(storeArrayName);
173  if (not storeArray) {
174  B2WARNING("StoreArray " << storeArrayName << " not present");
175  printDataStoreContent();
176  return;
177  }
178  std::vector<CDCSimHit> simHitsRelatedToHits;
179  for (const CDCHit& hit : storeArray) {
180  // cppcheck-suppress useStlAlgorithm
181  simHitsRelatedToHits.push_back(*hit.getRelated<CDCSimHit>("CDCSimHits"));
182  }
183  B2INFO("#CDCSimHits: " << storeArray.getEntries());
185  if (stroke != "") {
186  styling.setStroke("orange");
187  } else {
188  styling.setStroke(stroke);
189  }
190  styling.setStrokeWidth(strokeWidth);
191  drawIterable(simHitsRelatedToHits, styling);
192 }
193 
194 void CDCSVGPlotter::drawClusters(const std::string& storeObjName,
195  const std::string& stroke,
196  const std::string& strokeWidth)
197 {
199  if (stroke != "") styling.setStroke(stroke);
200  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
201  drawStoreVector<const CDCWireHitCluster>(storeObjName, styling);
202 }
203 
204 void CDCSVGPlotter::drawSegments(const std::string& storeObjName,
205  const std::string& stroke,
206  const std::string& strokeWidth)
207 {
208  ChooseableSegmentStyling styling;
209  if (stroke != "") styling.setStroke(stroke);
210  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
211  drawStoreVector<const CDCSegment2D>(storeObjName, styling);
212 }
213 
214 void CDCSVGPlotter::drawSegmentTrajectories(const std::string& storeObjName,
215  const std::string& stroke,
216  const std::string& strokeWidth)
217 {
219  if (stroke != "") styling.setStroke(stroke);
220  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
221  const bool drawTrajectories = true;
222  drawStoreVector<const CDCSegment2D, drawTrajectories>(storeObjName, styling);
223 }
224 
225 void CDCSVGPlotter::drawAxialSegmentPairs(const std::string& storeObjName,
226  const std::string& stroke,
227  const std::string& strokeWidth)
228 {
230  if (stroke != "") styling.setStroke(stroke);
231  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
232  drawStoreVector<const CDCAxialSegmentPair>(storeObjName, styling);
233 }
234 
235 void CDCSVGPlotter::drawSegmentPairs(const std::string& storeObjName,
236  const std::string& stroke,
237  const std::string& strokeWidth)
238 {
240  if (stroke != "") styling.setStroke(stroke);
241  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
242  drawStoreVector<const CDCSegmentPair>(storeObjName, styling);
243 }
244 
245 void CDCSVGPlotter::drawSegmentTriples(const std::string& storeObjName,
246  const std::string& stroke,
247  const std::string& strokeWidth)
248 {
250  if (stroke != "") styling.setStroke(stroke);
251  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
252  drawStoreVector<const CDCSegmentTriple>(storeObjName, styling);
253 }
254 
255 void CDCSVGPlotter::drawSegmentTripleTrajectories(const std::string& storeObjName,
256  const std::string& stroke,
257  const std::string& strokeWidth)
258 {
260  if (stroke != "") styling.setStroke(stroke);
261  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
262  const bool drawTrajectories = true;
263  drawStoreVector<const CDCSegmentTriple, drawTrajectories>(storeObjName, styling);
264 }
265 
266 void CDCSVGPlotter::drawTracks(const std::string& storeObjName,
267  const std::string& stroke,
268  const std::string& strokeWidth)
269 {
271  if (stroke != "") styling.setStroke(stroke);
272  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
273  drawStoreVector<const CDCTrack>(storeObjName, styling);
274 }
275 
276 void CDCSVGPlotter::drawTrackTrajectories(const std::string& storeObjName,
277  const std::string& stroke,
278  const std::string& strokeWidth)
279 {
281  if (stroke != "") styling.setStroke(stroke);
282  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
283  const bool drawTrajectories = true;
284  drawStoreVector<const CDCTrack, drawTrajectories>(storeObjName, styling);
285 }
286 
287 void CDCSVGPlotter::drawRecoTracks(const std::string& storeArrayName,
288  const std::string& stroke,
289  const std::string& strokeWidth)
290 {
292  if (stroke != "") styling.setStroke(stroke);
293  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
294  drawStoreArray<const RecoTrack>(storeArrayName, styling);
295 }
296 
297 void CDCSVGPlotter::drawRecoTrackTrajectories(const std::string& storeArrayName,
298  const std::string& stroke,
299  const std::string& strokeWidth)
300 {
302  if (stroke != "") styling.setStroke(stroke);
303  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
304  const bool drawTrajectories = true;
305  drawStoreArray<const RecoTrack, drawTrajectories>(storeArrayName, styling);
306 }
307 
308 void CDCSVGPlotter::drawMCParticleTrajectories(const std::string& storeArrayName,
309  const std::string& stroke,
310  const std::string& strokeWidth)
311 {
313  if (stroke != "") styling.setStroke(stroke);
314  if (strokeWidth != "") styling.setStrokeWidth(strokeWidth);
315  const bool drawTrajectories = true;
316  drawStoreArray<const MCParticle, drawTrajectories>(storeArrayName, styling);
317 }
318 
319 void CDCSVGPlotter::drawSimHitsConnectByToF(const std::string& hitStoreArrayName,
320  const std::string& stroke,
321  const std::string& strokeWidth)
322 {
323  B2INFO("Drawing simulated hits connected by tof");
324  StoreArray<CDCHit> hitStoreArray(hitStoreArrayName);
325  if (not hitStoreArray) {
326  B2WARNING("StoreArray " << hitStoreArrayName << " not present");
327  printDataStoreContent();
328  return;
329  }
330  std::vector<CDCSimHit*> simHits;
331  for (const CDCHit& hit : hitStoreArray) {
332  // cppcheck-suppress useStlAlgorithm
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  Vector3D fromDisplacement(fromSimHit->getPosTrack() - fromSimHit->getPosWire());
366  Vector3D toDisplacement(toSimHit->getPosTrack() - toSimHit->getPosWire());
367 
368  CDCRecoHit2D fromRecoHit2D(fromRLWireHit, fromDisplacement.xy());
369  CDCRecoHit2D toRecoHit2D(toRLWireHit, toDisplacement.xy());
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 Vector2D fromPos = fromRecoHit2D.getRecoPos2D();
389  const float fromX = fromPos.x();
390  const float fromY = fromPos.y();
391 
392  const Vector2D 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  // cppcheck-suppress ignoredReturnValue
401  std::adjacent_find(simHitsForMcParticle.begin(),
402  simHitsForMcParticle.end(),
403  drawConnectSimHits);
404  }
405 }
406 
407 void CDCSVGPlotter::drawWrongRLHitsInSegments(const std::string& segmentsStoreObjName)
408 {
409  this->drawWrongRLHits<CDCSegment2D>(segmentsStoreObjName);
410 }
411 
412 void CDCSVGPlotter::drawWrongRLHitsInTracks(const std::string& tracksStoreObjName)
413 {
414  this->drawWrongRLHits<CDCTrack>(tracksStoreObjName);
415 }
416 
417 template<class ACDCHitCollection>
418 void CDCSVGPlotter::drawWrongRLHits(const std::string& hitCollectionsStoreObjName)
419 {
420  B2INFO("Draw wrong right left passage information from " << hitCollectionsStoreObjName);
421  StoreWrappedObjPtr<std::vector<ACDCHitCollection>> storedHitCollections(hitCollectionsStoreObjName);
422  if (not storedHitCollections) {
423  B2WARNING(hitCollectionsStoreObjName << "does not exist in current DataStore");
424  printDataStoreContent();
425  return;
426  }
427 
428  std::vector<ACDCHitCollection>& hitCollections = *storedHitCollections;
429  B2INFO("#HitCollections: " << hitCollections.size());
430 
431  const CDCMCHitCollectionLookUp<ACDCHitCollection> mcHitCollectionLookUp;
432  const CDCMCHitLookUp& mcHitLookUp = CDCMCHitLookUp::getInstance();
433 
434  for (const ACDCHitCollection& hitCollection : hitCollections) {
435  EForwardBackward fbInfo = mcHitCollectionLookUp.isForwardOrBackwardToMCTrack(&hitCollection);
436 
437  double rlPurity = mcHitCollectionLookUp.getRLPurity(&hitCollection);
438  int correctRLVote = mcHitCollectionLookUp.getCorrectRLVote(&hitCollection);
439 
440  // Skip the impure alias
441  if (rlPurity < 0.5 and hitCollection.getAutomatonCell().hasAliasFlag()) continue;
442 
443  // Skip the bad reverse
444  if (correctRLVote < 0 and hitCollection.getAutomatonCell().hasReverseFlag()) continue;
445 
447  for (const auto& recoHit : hitCollection) {
448  ERightLeft rlInfo = recoHit.getRLInfo();
449  const CDCHit* hit = recoHit.getWireHit().getHit();
450  ERightLeft mcRLInfo = mcHitLookUp.getRLInfo(hit);
451 
452  if (fbInfo == EForwardBackward::c_Backward) {
453  mcRLInfo = reversed(mcRLInfo);
454  }
455 
456  std::string color = "orange";
457  if (mcRLInfo != ERightLeft::c_Right and mcRLInfo != ERightLeft::c_Left) {
458  color = "violet";
459  } else if (mcRLInfo == rlInfo) {
460  color = "green";
461  } else if (mcRLInfo == -rlInfo) {
462  color = "red";
463  }
464 
465  AttributeMap attributeMap{{"stroke", color}};
466  m_eventdataPlotter.draw(recoHit, attributeMap);
467  }
469  }
470 }
471 
472 void CDCSVGPlotter::drawMCAxialSegmentPairs(const std::string& segmentsStoreObjName,
473  const std::string& stroke,
474  const std::string& strokeWidth)
475 {
476  B2INFO("Draw axial to axial segment pairs");
477  StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
478  if (not storedSegments) {
479  B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
480  printDataStoreContent();
481  return;
482  }
483 
484  std::vector<CDCSegment2D>& segments = *storedSegments;
485  B2INFO("#Segments: " << segments.size());
486 
487  std::vector<const CDCAxialSegment2D*> axialSegments;
488  for (const CDCAxialSegment2D& segment : segments) {
489  if (segment.isAxial()) axialSegments.push_back(&segment);
490  }
491 
492  MCAxialSegmentPairFilter mcAxialSegmentPairFilter;
493  std::vector<CDCAxialSegmentPair> mcAxialSegmentPairs;
494  for (const CDCAxialSegment2D* fromSegment : axialSegments) {
495  for (const CDCAxialSegment2D* toSegment : axialSegments) {
496  if (fromSegment == toSegment) continue;
497  mcAxialSegmentPairs.emplace_back(fromSegment, toSegment);
498  Weight mcWeight = mcAxialSegmentPairFilter(mcAxialSegmentPairs.back());
499  // Remove segment pairs that are not true
500  if (std::isnan(mcWeight)) {
501  mcAxialSegmentPairs.pop_back();
502  }
503  }
504  }
505  B2INFO("# Axial segment pairs: " << mcAxialSegmentPairs.size());
507  if (stroke != "") styling.setStroke(stroke);
508  if (strokeWidth != "") styling.setStroke(strokeWidth);
509  drawIterable(mcAxialSegmentPairs, styling);
510 }
511 
512 void CDCSVGPlotter::drawMCSegmentPairs(const std::string& segmentsStoreObjName,
513  const std::string& stroke,
514  const std::string& strokeWidth)
515 {
516  B2INFO("Draw axial to stero segment pairs");
517  StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
518  if (not storedSegments) {
519  B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
520  printDataStoreContent();
521  return;
522  }
523 
524  std::vector<CDCSegment2D>& segments = *storedSegments;
525  B2INFO("#Segments: " << segments.size());
526 
527  std::vector<const CDCAxialSegment2D*> axialSegments;
528  std::vector<const CDCStereoSegment2D*> stereoSegments;
529  for (const CDCAxialSegment2D& segment : segments) {
530  if (segment.isAxial()) {
531  axialSegments.push_back(&segment);
532  } else {
533  stereoSegments.push_back(&segment);
534  }
535  }
536 
537  MCSegmentPairFilter mcSegmentPairFilter;
538  std::vector<CDCSegmentPair> mcSegmentPairs;
539  for (const CDCAxialSegment2D* axialSegment : axialSegments) {
540  for (const CDCStereoSegment2D* stereoSegment : stereoSegments) {
541  // Axial first
542  {
543  mcSegmentPairs.emplace_back(axialSegment, stereoSegment);
544  Weight mcWeight = mcSegmentPairFilter(mcSegmentPairs.back());
545  // Remove segment pairs that are not true
546  if (std::isnan(mcWeight)) {
547  mcSegmentPairs.pop_back();
548  }
549  }
550  // Stereo first
551  {
552  mcSegmentPairs.emplace_back(stereoSegment, axialSegment);
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  }
560  }
561  B2INFO("# Segment pairs: " << mcSegmentPairs.size());
563  if (stroke != "") styling.setStroke(stroke);
564  if (strokeWidth != "") styling.setStroke(strokeWidth);
565  drawIterable(mcSegmentPairs, styling);
566 }
567 
568 void CDCSVGPlotter::drawMCSegmentTriples(const std::string& segmentsStoreObjName,
569  const std::string& stroke,
570  const std::string& strokeWidth)
571 {
572  B2INFO("Draw segment triples");
573  StoreWrappedObjPtr<std::vector<CDCSegment2D>> storedSegments(segmentsStoreObjName);
574  if (not storedSegments) {
575  B2WARNING(segmentsStoreObjName << "does not exist in current DataStore");
576  printDataStoreContent();
577  return;
578  }
579 
580  std::vector<CDCSegment2D>& segments = *storedSegments;
581  B2INFO("#Segment " << segments.size());
582 
583  std::vector<const CDCAxialSegment2D*> axialSegments;
584  std::vector<const CDCStereoSegment2D*> stereoSegments;
585  for (const CDCSegment2D& segment : segments) {
586  if (segment.isAxial()) {
587  axialSegments.push_back(&segment);
588  } else {
589  stereoSegments.push_back(&segment);
590  }
591  }
592 
593  MCSegmentTripleFilter mcSegmentTripleFilter;
594  std::vector<CDCSegmentTriple> mcSegmentTriples;
595  for (const CDCAxialSegment2D* startSegment : axialSegments) {
596  for (const CDCStereoSegment2D* middleSegment : stereoSegments) {
597  for (const CDCAxialSegment2D* endSegment : axialSegments) {
598  if (startSegment == endSegment) continue;
599  mcSegmentTriples.emplace_back(startSegment, middleSegment, endSegment);
600  Weight mcWeight = mcSegmentTripleFilter(mcSegmentTriples.back());
601  // Remove segment pairs that are not true
602  if (std::isnan(mcWeight)) {
603  mcSegmentTriples.pop_back();
604  }
605  }
606  }
607  }
608  B2INFO("# Segment triples: " << mcSegmentTriples.size());
610  if (stroke != "") styling.setStroke(stroke);
611  if (strokeWidth != "") styling.setStroke(strokeWidth);
612  drawIterable(mcSegmentTriples, styling);
613 }
614 
615 std::string CDCSVGPlotter::saveFile(const std::string& fileName)
616 {
618 
619  float height = boundingBox.getHeight();
620  float width = boundingBox.getWidth();
621 
622  int totalPoints = 1120 * 1120;
623  float svgHeight = roundf(sqrt(totalPoints * height / width));
624  float svgWidth = roundf(sqrt(totalPoints * width / height));
625 
628 
629  return (m_eventdataPlotter.save(fileName));
630 }
631 
632 template <class AItem, bool a_drawTrajectories>
633 void CDCSVGPlotter::drawStoreArray(const std::string& storeArrayName,
634  Styling<AItem>& styling)
635 {
636  if (a_drawTrajectories) {
637  B2INFO("Drawing trajectories from StoreArray: " << storeArrayName);
638  } else {
639  B2INFO("Drawing StoreArray: " << storeArrayName);
640  }
641 
642  using StoreItem = typename std::remove_cv<AItem>::type;
643  StoreArray<StoreItem> storeArray(storeArrayName);
644  if (not storeArray) {
645  B2WARNING(storeArrayName << " not present in the DataStore");
646  printDataStoreContent();
647  return;
648  }
649 
650  B2INFO("with " << storeArray.getEntries() << " entries");
651  drawIterable<a_drawTrajectories>(storeArray, styling);
652  B2INFO("Attributes are");
653  B2INFO(styling.info());
654 }
655 
656 template <class AItem, bool a_drawTrajectories>
657 void CDCSVGPlotter::drawStoreVector(const std::string& storeObjName,
658  Styling<AItem>& styling)
659 {
660  if (a_drawTrajectories) {
661  B2INFO("Drawing trajectories for vector from DataStore: " << storeObjName);
662  } else {
663  B2INFO("Drawing vector from DataStore: " << storeObjName);
664  }
665 
666  using StoreItem = typename std::remove_cv<AItem>::type;
667  StoreWrappedObjPtr<std::vector<StoreItem>> storeVector(storeObjName);
668  if (not storeVector) {
669  B2WARNING(storeObjName << " not present in the DataStore");
670  B2INFO("Current content of the DataStore:");
671  printDataStoreContent();
672  return;
673  }
674 
675  const std::vector<StoreItem>& vector = *storeVector;
676  B2INFO("with " << vector.size() << " entries");
677  drawIterable<a_drawTrajectories>(reversedRange(vector), styling);
678  B2INFO("Attributes are");
679  B2INFO(styling.info());
680 }
681 
682 template <bool a_drawTrajectory, class AIterable, class AStyling>
683 void CDCSVGPlotter::drawIterable(const AIterable& items, AStyling& styling)
684 {
685  unsigned int index = -1;
686  for (const auto& item : items) {
687 
688  ++index;
689  AttributeMap attributeMap = styling.map(index, item);
690  draw<a_drawTrajectory>(item, attributeMap);
691  }
692 }
693 
694 template <bool a_drawTrajectory, class AObject>
695 void CDCSVGPlotter::draw(const AObject& object, const AttributeMap& attributeMap)
696 {
697  DrawTrajectoryHelper<a_drawTrajectory, const AObject>::draw(m_eventdataPlotter,
698  object,
699  attributeMap);
700 }
Belle2::TrackFindingCDC::FixedStyling::setStroke
void setStroke(const std::string &value)
Legacy - Sets the stroke color to the fixed value.
Definition: Styling.h:91
Belle2::TrackFindingCDC::CDCSVGPlotter::drawWrongRLHitsInSegments
void drawWrongRLHitsInSegments(const std::string &segmentsStoreObjName)
Draw the CDCRLWireHits in the CDCSegments colored by the match of the right left passage informations...
Definition: CDCSVGPlotter.cc:407
Belle2::TrackFindingCDC::CDCSVGPlotter::drawHits
void drawHits(const std::string &storeArrayName, const std::string &stroke, const std::string &strokeWidth)
Draws CDCHits.
Definition: CDCSVGPlotter.cc:157
Belle2::TrackFindingCDC::CDCSVGPlotter::m_eventdataPlotter
EventDataPlotter m_eventdataPlotter
The plotter instance to translate event data objects to svg expressions.
Definition: CDCSVGPlotter.h:332
Belle2::TrackFindingCDC::CDCSVGPlotter::drawClusters
void drawClusters(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draws CDCWireHitClusters.
Definition: CDCSVGPlotter.cc:194
Belle2::RelationsInterface::getRelatedWithWeight
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.
Definition: RelationsObject.h:333
Belle2::CDCSimHit::getPosTrack
TVector3 getPosTrack() const
The method to get position on the track.
Definition: CDCSimHit.h:234
Belle2::TrackFindingCDC::Vector2D
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:37
Belle2::TrackFindingCDC::CDCSVGPlotter::drawRecoTrackTrajectories
void drawRecoTrackTrajectories(const std::string &storeArrayName, const std::string &stroke, const std::string &strokeWidth)
Draw RecoTracks trajectories.
Definition: CDCSVGPlotter.cc:297
Belle2::DataStore::Instance
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
Belle2::TrackFindingCDC::CDCRecoHit2D::getRecoPos2D
Vector2D getRecoPos2D() const
Getter for the position in the reference plane.
Definition: CDCRecoHit2D.h:248
Belle2::TrackFindingCDC::CDCSVGPlotter::drawMCAxialSegmentPairs
void drawMCAxialSegmentPairs(const std::string &segmentsStoreObjName, const std::string &stroke, const std::string &strokeWidth)
Draws the Monte Carlo true CDCAxialSegmentPairs.
Definition: CDCSVGPlotter.cc:472
Belle2::TrackFindingCDC::ChooseableSegmentStyling
This Class handles the mapping from the colormapping-method name given as a string to the actual ACol...
Definition: Styling.h:226
Belle2::TrackFindingCDC::CDCSVGPlotter::clone
CDCSVGPlotter * clone()
Make a copy of the current status of the plotter.
Definition: CDCSVGPlotter.cc:121
Belle2::TrackFindingCDC::Vector2D::y
double y() const
Getter for the y coordinate.
Definition: Vector2D.h:619
Belle2::TrackFindingCDC::ChooseableStyling::setStrokeWidth
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:183
Belle2::CDCHit
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:51
Belle2::TrackFindingCDC::MCAxialSegmentPairFilter
Filter for the constuction of axial to axial segment pairs based on simple criterions.
Definition: MCAxialSegmentPairFilter.h:34
Belle2::TrackFindingCDC::CDCSVGPlotter::drawMCSegmentPairs
void drawMCSegmentPairs(const std::string &segmentsStoreObjName, const std::string &stroke, const std::string &strokeWidth)
Draws the Monte Carlo true CDCSegmentPairs.
Definition: CDCSVGPlotter.cc:512
Belle2::TrackFindingCDC::CDCSVGPlotter::drawMCParticleTrajectories
void drawMCParticleTrajectories(const std::string &storeArrayName, const std::string &stroke, const std::string &strokeWidth)
Draw MCParticles.
Definition: CDCSVGPlotter.cc:308
Belle2::TrackFindingCDC::EventDataPlotter::setCanvasWidth
void setCanvasWidth(float width)
Setter for the canvas width in pixels.
Definition: EventDataPlotter.cc:130
Belle2::TrackFindingCDC::CDCSVGPlotter::drawSegmentTriples
void drawSegmentTriples(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draw the axial, stereo, axial segment triples.
Definition: CDCSVGPlotter.cc:245
Belle2::TrackFindingCDC::StoreWrappedObjPtr
This class is for convenience access and registration of objects, that are stored inside the StoreWra...
Definition: StoreWrappedObjPtr.h:40
Belle2::TrackFindingCDC::CDCSVGPlotter
Helper class to generated the svg image from the various tracking objects.
Definition: CDCSVGPlotter.h:33
Belle2::TrackFindingCDC::CDCSVGPlotter::drawWrongRLHits
void drawWrongRLHits(const std::string &storeObjName)
Draw the CDCRLWireHits in the ACDCHitCollection colored by the match of the right left passage inform...
Belle2::RelationsInterface::getRelated
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
Definition: RelationsObject.h:280
Belle2::TrackFindingCDC::Styling::info
virtual std::string info()
Informal string summarizing the translation from the object to the styling attributes.
Definition: Styling.h:56
Belle2::TrackFindingCDC::CDCSVGPlotter::drawSimHitsConnectByToF
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.
Definition: CDCSVGPlotter.cc:319
Belle2::CDCSimHit
Example Detector.
Definition: CDCSimHit.h:33
Belle2::MCParticle::getArrayIndex
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:255
Belle2::TrackFindingCDC::CDCSVGPlotter::drawStoreArray
void drawStoreArray(const std::string &storeArrayName, Styling< AItem > &styling)
Function Template for drawing the elements of a given StoreArray.
Belle2::TrackFindingCDC::EventDataPlotter::save
const std::string save(const std::string &fileName)
Saves the current plot stead to a file.
Definition: EventDataPlotter.cc:74
Belle2::TrackFindingCDC::EventDataPlotter::draw
void draw(const Belle2::TrackFindingCDC::Circle2D &circle, AttributeMap attributeMap=AttributeMap())
Draws a filled circle.
Belle2::TrackFindingCDC::CDCSVGPlotter::drawInteractionPoint
void drawInteractionPoint()
Draws the interaction point.
Definition: CDCSVGPlotter.cc:126
Belle2::TrackFindingCDC::CDCSVGPlotter::drawAxialSegmentPairs
void drawAxialSegmentPairs(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draw the axial to axial segment pairs.
Definition: CDCSVGPlotter.cc:225
Belle2::TrackFindingCDC::EventDataPlotter::startGroup
void startGroup(const AttributeMap &attributeMap=AttributeMap())
Indicates the start of a group of drawn elements.
Definition: EventDataPlotter.cc:146
Belle2::TrackFindingCDC::EventDataPlotter::drawOuterCDCWall
void drawOuterCDCWall(const AttributeMap &attributeMap=AttributeMap())
Draw the outer wall of the CDC.
Definition: EventDataPlotter.cc:226
Belle2::TrackFindingCDC::CDCSVGPlotter::drawWires
void drawWires(const CDCWireTopology &cdcWireTopology)
Draws the wires.
Definition: CDCSVGPlotter.cc:152
Belle2::TrackFindingCDC::EventDataPlotter::endGroup
void endGroup()
Indicates the end of a group of drawn elements.
Definition: EventDataPlotter.cc:154
Belle2::TrackFindingCDC::CDCSVGPlotter::drawTrackTrajectories
void drawTrackTrajectories(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draws trajectories of the tracks.
Definition: CDCSVGPlotter.cc:276
Belle2::TrackFindingCDC::MCSegmentTripleFilter
Filter for the constuction of segment triples based on monte carlo information.
Definition: MCSegmentTripleFilter.h:37
Belle2::TrackFindingCDC::CDCRecoHit2D
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:57
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::BoundingBox::getWidth
float getWidth() const
Getter for the width of the bounding box rectangle.
Definition: BoundingBox.h:73
Belle2::TrackFindingCDC::CDCSVGPlotter::drawSegmentTrajectories
void drawSegmentTrajectories(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draws SegmentTrajectories.
Definition: CDCSVGPlotter.cc:214
Belle2::TrackFindingCDC::CDCRLWireHit
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Definition: CDCRLWireHit.h:51
Belle2::TrackFindingCDC::Vector3D
A three dimensional vector.
Definition: Vector3D.h:34
Belle2::TrackFindingCDC::EventDataPlotter::drawSuperLayerBoundaries
void drawSuperLayerBoundaries(const AttributeMap &attributeMap=AttributeMap())
Draw the super layer bounds of the CDC.
Definition: EventDataPlotter.cc:242
Belle2::TrackFindingCDC::BoundingBox::getHeight
float getHeight() const
Getter for the height of the bounding box rectangle.
Definition: BoundingBox.h:77
Belle2::TrackFindingCDC::FixedStyling::setStrokeWidth
void setStrokeWidth(const std::string &value)
Legacy - Sets the stroke width to the fixed value.
Definition: Styling.h:97
Belle2::TrackFindingCDC::ChooseableRecoTrackStyling
This Class handles the mapping from the colormapping-method name given as a string to the actual colo...
Definition: Styling.h:208
Belle2::TrackFindingCDC::CDCSVGPlotter::drawWrongRLHitsInTracks
void drawWrongRLHitsInTracks(const std::string &tracksStoreObjName)
Draw the CDCRLWireHits in the CDCTracks colored by the match of the right left passage informations.
Definition: CDCSVGPlotter.cc:412
Belle2::TrackFindingCDC::CDCSVGPlotter::drawSegments
void drawSegments(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draws CDCSegments.
Definition: CDCSVGPlotter.cc:204
Belle2::TrackFindingCDC::ChooseableHitStyling
This Class handles the mapping from the colormapping-method name given as a string to the actual colo...
Definition: Styling.h:244
Belle2::RelationsInterface::getArrayIndex
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
Definition: RelationsObject.h:387
Belle2::TrackFindingCDC::CDCSVGPlotter::drawInnerCDCWall
void drawInnerCDCWall(const std::string &stroke)
Draws the inner CDCWall.
Definition: CDCSVGPlotter.cc:145
Belle2::TrackFindingCDC::CDCSVGPlotter::drawSuperLayerBoundaries
void drawSuperLayerBoundaries(const std::string &stroke)
Draws the individual super layer boundaries.
Definition: CDCSVGPlotter.cc:131
Belle2::TrackFindingCDC::CDCSVGPlotter::drawRecoTracks
void drawRecoTracks(const std::string &storeArrayName, const std::string &stroke, const std::string &strokeWidth)
Draw RecoTracks.
Definition: CDCSVGPlotter.cc:287
Belle2::CDCSimHit::getPosWire
TVector3 getPosWire() const
The method to get position on wire.
Definition: CDCSimHit.h:216
Belle2::TrackFindingCDC::CDCSVGPlotter::drawTracks
void drawTracks(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draws CDCTracks.
Definition: CDCSVGPlotter.cc:266
Belle2::TrackFindingCDC::Vector3D::xy
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
Definition: Vector3D.h:500
Belle2::TrackFindingCDC::Vector2D::x
double x() const
Getter for the x coordinate.
Definition: Vector2D.h:609
Belle2::TrackFindingCDC::EventDataPlotter::setCanvasHeight
void setCanvasHeight(float height)
Setter for the canvas height in pixels The canvas height denotes the size of the image being produced...
Definition: EventDataPlotter.cc:138
Belle2::TrackFindingCDC::CDCMCHitLookUp::getInstance
static const CDCMCHitLookUp & getInstance()
Getter for the singletone instance.
Definition: CDCMCHitLookUp.cc:32
Belle2::TrackFindingCDC::EventDataPlotter::drawLine
void drawLine(float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap())
Draws a straight Line.
Definition: EventDataPlotter.cc:258
Belle2::TrackFindingCDC::CDCSVGPlotter::drawSimHits
void drawSimHits(const std::string &storeArrayName, const std::string &stroke, const std::string &strokeWidth)
Draws CDCSimHits.
Definition: CDCSVGPlotter.cc:167
Belle2::TrackFindingCDC::CDCSVGPlotter::drawMCSegmentTriples
void drawMCSegmentTriples(const std::string &segmentsStoreObjName, const std::string &stroke, const std::string &strokeWidth)
Draws the Monte Carlo true CDCSegmentTriples.
Definition: CDCSVGPlotter.cc:568
Belle2::TrackFindingCDC::CDCSegment2D
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:40
Belle2::TrackFindingCDC::DefaultColorCycleStyling
Class template for coloring objects with stroke colors prepared to be the default color cycle.
Definition: Styling.h:195
Belle2::TrackFindingCDC::SVGPrimitivePlotter
A concrete plotter that can draw primitive objects to standalone SVG files.
Definition: SVGPrimitivePlotter.h:31
Belle2::TrackFindingCDC::EventDataPlotter::drawInteractionPoint
void drawInteractionPoint()
Marks the position of the interaction point with a filled circle.
Definition: EventDataPlotter.cc:198
Belle2::TrackFindingCDC::CDCSVGPlotter::drawSegmentPairs
void drawSegmentPairs(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draw the axial to stereo segment pairs.
Definition: CDCSVGPlotter.cc:235
Belle2::TrackFindingCDC::CDCSVGPlotter::draw
void draw(const AObject &object, const AttributeMap &attributeMap)
Draws the object or its trajectory with the given attributes.
Belle2::TrackFindingCDC::CDCSVGPlotter::CDCSVGPlotter
CDCSVGPlotter(bool animate=false, bool forwardFade=false)
Constructor.
Definition: CDCSVGPlotter.cc:104
Belle2::TrackFindingCDC::BoundingBox
A two dimensional rectangle that keeps track of the extend of a drawing.
Definition: BoundingBox.h:31
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::TrackFindingCDC::EventDataPlotter::getBoundingBox
BoundingBox getBoundingBox() const
Getter for the current bounding box.
Definition: EventDataPlotter.cc:92
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::TrackFindingCDC::CDCWireHit
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:65
Belle2::TrackFindingCDC::MCSegmentPairFilter
Filter for the constuction of axial to stereo segment pairs based on MC information.
Definition: MCSegmentPairFilter.h:32
Belle2::TrackFindingCDC::Styling
Interface for a mapping of object and an index to styling attributes.
Definition: CDCSVGPlotter.h:30
Belle2::TrackFindingCDC::CDCSVGPlotter::saveFile
std::string saveFile(const std::string &fileName="display.svg")
Save the current dom object representation to disk.
Definition: CDCSVGPlotter.cc:615
Belle2::TrackFindingCDC::CDCSVGPlotter::drawOuterCDCWall
void drawOuterCDCWall(const std::string &stroke)
Draws the outer CDCWall.
Definition: CDCSVGPlotter.cc:138
Belle2::TrackFindingCDC::CDCWireTopology
Class representating the sense wire arrangement in the whole of the central drift chamber.
Definition: CDCWireTopology.h:54
Belle2::TrackFindingCDC::CDCSVGPlotter::drawStoreVector
void drawStoreVector(const std::string &storeObjName, Styling< AItem > &styling)
Function Template for drawing the elements of a given StoreVector.
Belle2::TrackFindingCDC::ChooseableStyling::setStroke
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:173
Belle2::TrackFindingCDC::EventDataPlotter::setBoundingBox
void setBoundingBox(const BoundingBox &boundingBox)
Setter for the bounding box of all drawed objects.
Definition: EventDataPlotter.cc:102
Belle2::TrackFindingCDC::CDCSVGPlotter::drawIterable
void drawIterable(const AIterable &items, AStyling &styling)
Draw every element of an iterable object.
Belle2::DataStore::EDurability
EDurability
Durability types.
Definition: DataStore.h:60
Belle2::TrackFindingCDC::EventDataPlotter::drawInnerCDCWall
void drawInnerCDCWall(const AttributeMap &attributeMap=AttributeMap())
Draw the inner wall of the CDC.
Definition: EventDataPlotter.cc:210
Belle2::TrackFindingCDC::FixedStyling
Implementation of a styling from fixed attribute map.
Definition: Styling.h:64
Belle2::TrackFindingCDC::CDCSVGPlotter::drawSegmentTripleTrajectories
void drawSegmentTripleTrajectories(const std::string &storeObjName, const std::string &stroke, const std::string &strokeWidth)
Draw the trajectories of the axial, stereo, axial segment triples.
Definition: CDCSVGPlotter.cc:255