Belle II Software development
HitColorMapping.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/HitColorMapping.h>
9#include <tracking/trackFindingCDC/display/Colors.h>
10
11#include <tracking/trackFindingCDC/mclookup/CDCMCHitLookUp.h>
12#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
13#include <tracking/trackingUtilities/utilities/VectorRange.h>
14
15#include <cdc/dataobjects/CDCHit.h>
16#include <cdc/dataobjects/CDCSimHit.h>
17#include <mdst/dataobjects/MCParticle.h>
18
19#include <set>
20#include <sstream>
21
22using namespace Belle2;
23using namespace TrackFindingCDC;
24using namespace TrackingUtilities;
25
27const std::string c_bkgHitColor = "orange";
28
30const std::string c_missingPDGColor = "lime";
31
33const std::map<int, std::string> c_colorByPDGCode = {
34 { -999, "orange"},
35 {11, "blue"},
36 { -11, "blue"},
37 {13, "turquoise"},
38 { -13, "turquoise"},
39 {15, "cyan"},
40 { -15, "cyan"},
41 {22, "violet"},
42 {211, "green"},
43 { -211, "green"},
44 {321, "olive"},
45 { -321, "olive"},
46 {2212, "red"},
47 { -2212, "red"},
48};
49
50std::string ZeroDriftLengthColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
51{
52 CDCWireHit wirehit(&hit);
53 if (wirehit.getRefDriftLength() == 0) {
54 return "red";
55 } else {
56 return c_bkgHitColor;
57 }
58}
59
60std::string ZeroDriftLengthStrokeWidthMap::map(int index __attribute__((unused)), const CDCHit& hit)
61{
62 CDCWireHit wirehit(&hit, nullptr);
63 if (wirehit.getRefDriftLength() == 0) {
64 return "1";
65 } else {
66 return "0.2";
67 }
68}
69
71{
72 if (not m_storedWireHits) {
73 B2WARNING("CDCWireHitVector could not be found on the DataStore. Cannot plot the taken flags.");
74 }
75}
76
77std::string TakenFlagColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
78{
79 if (m_storedWireHits) {
80 const std::vector<CDCWireHit>& wireHits = *m_storedWireHits;
81 ConstVectorRange<CDCWireHit> wireHitRange{std::equal_range(wireHits.begin(), wireHits.end(), hit)};
82
83 if (not wireHitRange.empty()) {
84 const CDCWireHit& wireHit = wireHitRange.front();
85 if (wireHit.getAutomatonCell().hasTakenFlag()) {
86 return "red";
87 }
88 }
89 }
90 return c_bkgHitColor;
91}
92
93std::string RLColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
94{
95 const CDCMCHitLookUp& mcHitLookUp = mcHitLookUp.getInstance();
96 short int rlInfo = mcHitLookUp.getRLInfo(&hit);
97 if (rlInfo == 1) {
98 return ("green");
99 } else if (rlInfo == -1) {
100 return ("red");
101 } else {
102 return (c_bkgHitColor);
103 }
104}
105
106std::string RLColorMap::info()
107{
108 return "Local right left passage variable: green <-> right, red <-> left, orange <-> not determinable.\n";
109}
110
111std::string PosFlagColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
112{
113 CDCSimHit* simHit = hit.getRelated<CDCSimHit>("CDCSimHits");
114 int posFlag = simHit->getPosFlag();
115 if (posFlag == 0) {
116 return ("green"); // right
117 } else if (posFlag == 1) {
118 return ("red"); // left
119 } else {
120 return (c_bkgHitColor);
121 }
122}
123
125{
126 return "PosFlag variable of the related CDCSimHit: green <-> 0 (Right), red <-> 1 (Left), orange <-> determinable.\n";
127}
128
129std::string BackgroundTagColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
130{
131 CDCSimHit* cdcSimHit = hit.getRelated<CDCSimHit>("CDCSimHits");
132 short backgroundtag = cdcSimHit->getBackgroundTag();
133 switch (backgroundtag) {
134 case BackgroundMetaData::BG_TAG::bg_none: return "orange";
136 case BackgroundMetaData::BG_TAG::bg_Coulomb_HER: return "darkred";
137 case BackgroundMetaData::BG_TAG::bg_RBB_LER: return "blue";
138 case BackgroundMetaData::BG_TAG::bg_RBB_HER: return "darkblue";
140 case BackgroundMetaData::BG_TAG::bg_Touschek_HER: return "darkgreen";
141 case BackgroundMetaData::BG_TAG::bg_twoPhoton: return "violet";
142 case BackgroundMetaData::BG_TAG::bg_RBB_gamma: return "skyblue";
143 case BackgroundMetaData::BG_TAG::bg_RBB_LER_far: return "turquoise";
144 case BackgroundMetaData::BG_TAG::bg_RBB_HER_far: return "darkturquoise";
145 case BackgroundMetaData::BG_TAG::bg_Touschek_LER_far: return "olivergreen";
146 case BackgroundMetaData::BG_TAG::bg_Touschek_HER_far: return "darkolivegreen";
147 case BackgroundMetaData::BG_TAG::bg_SynchRad_LER: return "goldenrod";
148 case BackgroundMetaData::BG_TAG::bg_SynchRad_HER: return "darkgoldenrod";
150 case BackgroundMetaData::BG_TAG::bg_BHWide_HER: return "darkcyan";
151 case BackgroundMetaData::BG_TAG::bg_other: return "orange";
152 default:
153 B2INFO("Background tag " << backgroundtag << " not associated with a color.\n");
154 return ("orange");
155 }
156}
157
159{
160 return ("Background tag color coding is:\n"
161 "bg_Coulomb_HER: darkred\n"
162 "bg_Coulomb_LER: red\n"
163 "bg_RBB_HER: darkblue\n"
164 "bg_RBB_HER_far: darkturquoise\n"
165 "bg_RBB_LER: blue\n"
166 "bg_RBB_LER_far: turquoise\n"
167 "bg_SynchRad_HER: darkgoldenrod\n"
168 "bg_SynchRad_LER: goldenrod\n"
169 "bg_Touschek_HER: darkgreen\n"
170 "bg_Touschek_HER_far: darkolivegreen\n"
171 "bg_Touschek_LER: green\n"
172 "bg_Touschek_LER_far: olivergreen\n"
173 "bg_RBB_gamma: skyblue\n"
174 "bg_none: orange\n"
175 "bg_other: orange\n"
176 "bg_twoPhoton: violet\n"
177 );
178}
179
180std::string MCSegmentIdColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
181{
183 mcHitLookUp.getInstance();
184 Index inTrackiSegment = mcHitLookUp.getInTrackSegmentId(&hit);
185
186 if (inTrackiSegment < 0) {
187 return (c_bkgHitColor);
188 } else {
189 // values are all fractions of their respective scale
190 double hue = 50 * inTrackiSegment % 360 / 360.0;
191 double saturation = 0.75, lightness = 0.5;
192 std::array<double, 3> rgb = Colors::hlsToRgb(hue, lightness, saturation);
193 std::ostringstream oss;
194 std::string color;
195 oss << "rgb(" << rgb[0] * 100 << "%, " << rgb[1] * 100 << "%, " << rgb[2] * 100 << "%)";
196 color = oss.str();
197 return color;
198 }
199}
200
201std::string TOFColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
202{
203 CDCSimHit* simHit = hit.getRelated<CDCSimHit>("CDCSimHits");
204 double timeOfFlight = simHit->getFlightTime();
205 return timeOfFlightToColor(timeOfFlight);
206}
207
208std::string TOFColorMap::timeOfFlightToColor(const double timeOfFlight)
209{
210 //values are all fractions of their respective scale
211
212 //Full color circle in 3 nanoseconds
213 double hue = fmod(360 / 3.0 * timeOfFlight, 360) / 360;
214 double saturation = 0.75, lightness = 0.5;
215 std::array<double, 3> rgb = Colors::hlsToRgb(hue, lightness, saturation);
216 std::ostringstream oss;
217 std::string color;
218 oss << "rgb(" << rgb[0] * 100 << "%, " << rgb[1] * 100 << "%, " << rgb[2] * 100 << "%)";
219 color = oss.str();
220 return color;
221}
222
223std::string ReassignedSecondaryMap::map(int index __attribute__((unused)), const CDCHit& hit)
224{
225 RelationVector<MCParticle> relatedMCParticles =
226 hit.getRelationsWith<MCParticle>("MCParticles");
227 if (relatedMCParticles.size() == 0) {
228 return c_bkgHitColor;
229 } else {
230 double mcRelationWeight = relatedMCParticles.weight(0);
231 if (mcRelationWeight > 0) {
232 return "green";
233 } else {
234 return "red";
235 }
236 }
237}
238
240 : m_colors(Colors::getList())
241 , m_iColor(0)
242 , m_usedColors()
243{
244}
245
247{
248 std::ostringstream oss;
249 for (const std::pair<int, std::string> colorForMCParticleID : m_usedColors) {
250 oss << "MCParticle " << colorForMCParticleID.first << " -> " << colorForMCParticleID.second << "\n";
251 }
252 return oss.str();
253}
254
255std::string MCParticleColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
256{
257 MCParticle* mcParticle = hit.getRelated<MCParticle>("MCParticles");
258 if (mcParticle != nullptr) {
259 int mcParticleId = mcParticle->getArrayIndex();
260 if (m_usedColors.count(mcParticleId) == 1) {
261 return m_usedColors[mcParticleId];
262 } else {
263 ++m_iColor;
264 std::string color = m_colors[m_iColor % m_colors.size()];
265 m_usedColors.emplace(mcParticleId, color);
266 return color;
267 }
268 } else {
269 return c_bkgHitColor;
270 }
271}
272
273std::string MCPDGCodeColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
274{
275 MCParticle* mcParticle = hit.getRelated<MCParticle>("MCParticles");
276 int pdgCode = mcParticle != nullptr ? mcParticle->getPDG() : -999;
277
278 auto itFound = c_colorByPDGCode.find(pdgCode);
279 if (itFound != c_colorByPDGCode.end()) {
280 return itFound->second;
281 } else {
282 B2WARNING("Unknown PDG code " << pdgCode);
283 return c_missingPDGColor;
284 }
285}
286
288{
289 std::ostringstream oss;
290 oss << "\nLegend:";
291
292 std::map<std::string, std::set<int>> pdgCodeByColor;
293
294 for (auto item : c_colorByPDGCode) {
295 pdgCodeByColor[item.second].insert(item.first);
296 }
297
298 for (auto item : pdgCodeByColor) {
299 oss << '\n' << item.first << "->[";
300 oss << join(", ", item.second);
301 oss << ']';
302 }
303 oss << '\n';
304 return oss.str();
305}
306
307std::string MCPrimaryColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
308{
309 MCParticle* mcParticle = hit.getRelated<MCParticle>("MCParticles");
310 if (mcParticle != nullptr) {
311 unsigned short int primaryFlag = 1;
312 bool isPrimary = mcParticle->hasStatus(primaryFlag);
313 int secondaryProcess = mcParticle->getSecondaryPhysicsProcess();
314
315 if (isPrimary) {
316 return "blue";
317 } else if (secondaryProcess > 200) {
318 return "green"; // decay in flight
319 } else {
320 return "red";
321 }
322 } else {
323 return c_bkgHitColor;
324 }
325}
326
328{
329 return "Legend:\n"
330 "blue->primary\n"
331 "green->secondary decay in flight\n"
332 "orange->beam background\n";
333}
334
335std::string SimHitPDGCodeColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
336{
337 CDCSimHit* simHit = hit.getRelated<CDCSimHit>("CDCSimHits");
338 int pdgCode = simHit != nullptr ? simHit->getPDGCode() : -999;
339 auto itFound = c_colorByPDGCode.find(pdgCode);
340 if (itFound != c_colorByPDGCode.end()) {
341 return itFound->second;
342 } else {
343 B2WARNING("Unknown PDG code " << pdgCode);
344 return c_missingPDGColor;
345 }
346}
347
349{
350 std::ostringstream oss;
351 oss << "\nLegend:";
352
353 std::map<std::string, std::set<int>> pdgCodeByColor;
354
355 for (auto item : c_colorByPDGCode) {
356 pdgCodeByColor[item.second].insert(item.first);
357 }
358
359 for (auto item : pdgCodeByColor) {
360 oss << '\n' << item.first << "->[";
361 oss << join(", ", item.second);
362 oss << ']';
363 }
364 oss << '\n';
365 return oss.str();
366}
367
368std::string SimHitIsBkgColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
369{
370 CDCSimHit* simHit = hit.getRelated<CDCSimHit>("CDCSimHits");
371 bool bkgTag = simHit->getBackgroundTag();
372 if (bkgTag) {
373 return "gray";
374 } else {
375 return "red";
376 }
377}
378
379std::string NLoopsColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
380{
381 const CDCMCHitLookUp& mcHitLookUp = mcHitLookUp.getInstance();
382
383 int nLoops = mcHitLookUp.getNLoops(&hit);
384
385 if (nLoops < 0) {
386 return c_bkgHitColor;
387 }
388 return Colors::getWheelColor(70 * nLoops);
389}
@ bg_RBB_HER_far
Radiative Bhabha far HER.
@ bg_BHWide_LER
Wide angle radiative Bhabha LER.
@ bg_RBB_LER
Radiative Bhabha LER.
@ bg_Touschek_HER_far
Touschek far HER.
@ bg_BHWide_HER
Wide angle radiative Bhabha HER.
@ bg_SynchRad_HER
Synchrotron radiation HER.
@ bg_Touschek_LER_far
Touschek far LER.
@ bg_RBB_HER
Radiative Bhabha HER.
@ bg_SynchRad_LER
Synchrotron radiation LER.
@ bg_RBB_LER_far
Radiative Bhabha far LER.
@ bg_other
Other type of background.
@ bg_RBB_gamma
Gammas from radiative Bhabha.
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
int getPDGCode() const
The method to get PDG code.
Definition CDCSimHit.h:177
double getFlightTime() const
The method to get flight time.
Definition CDCSimHit.h:183
int getPosFlag() const
The method to get old left/right info.
Definition CDCSimHit.h:222
A Class to store the Monte Carlo particle information.
Definition MCParticle.h:32
bool hasStatus(unsigned short int bitmask) const
Return if specific status bit is set.
Definition MCParticle.h:118
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition MCParticle.h:233
int getPDG() const
Return PDG code of particle.
Definition MCParticle.h:101
int getSecondaryPhysicsProcess() const
Returns the physics process type of a secondary particle.
Definition MCParticle.h:286
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
float weight(int index) const
Get weight with index.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
RelationVector< T > getRelationsWith(const std::string &name="", const std::string &namedRelation="") const
Get the relations between this object and another store array.
virtual unsigned short getBackgroundTag() const
Get background tag.
Definition SimHitBase.h:46
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string info() override
Informal string summarizing the translation from CDCSimHit::getBackgroundTag.
Interface class to the Monte Carlo information for individual hits.
TrackingUtilities::Index getInTrackSegmentId(const CDCHit *ptrHit) const
Returns the id of the segment in the track.
TrackingUtilities::Index getNLoops(const CDCHit *ptrHit) const
Returns the number of loops the track traversed until this hit.
static const CDCMCHitLookUp & getInstance()
Getter for the singletone instance.
TrackingUtilities::ERightLeft getRLInfo(const CDCHit *ptrHit) const
Returns the true right left passage information.
Utility functions related to colors.
Definition Colors.h:22
static std::string getWheelColor(int degree)
Get a color from the wheel of colors.
Definition Colors.cc:71
static std::array< double, 3 > hlsToRgb(double h, double l, double s)
Transforms a Color given in the HLS System to RGB.
Definition Colors.cc:56
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string info() override
Informal string summarizing the translation from pdg codes to colors.
int m_iColor
Index of the color to be used next.
std::map< int, std::string > m_usedColors
Mapping of the already used colors by the MCParticle::getArrayId to map later CDCHits to the same col...
std::vector< std::string > m_colors
List of colors to be cycled.
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string info() override
Informal string summarizing the translation from CDCSimHit::getBackgroundTag.
MCParticleColorMap()
Constructor setting up a Monte Carlo id to color map which is continuously filled as new during the e...
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string info() override
Informal string summarizing the translation from secondary process codes to colors.
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string map(int index, const CDCHit &hit) override
Function call to map a segments object from the local finder to a color.
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string info() override
Informal string summarizing the translation from CDCSimHit::getPosFlag variable to colors.
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string info() override
Informal string summarizing the translation from right left passage variable to colors.
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string info() override
Informal string summarizing the translation from pdg codes to colors.
std::string timeOfFlightToColor(const double timeOfFlight)
Translates the given floating point time of flight to a color.
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
TakenFlagColorMap()
Constructor checking if the CDCWireHits caring the taken flag are accessible.
TrackingUtilities::StoreWrappedObjPtr< std::vector< TrackingUtilities::CDCWireHit > > m_storedWireHits
Memory of the handle to the CDCWireHits on the DataStore.
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a color.
std::string map(int index, const CDCHit &hit) override
Function call to map the CDCHit id and object to a stroke width.
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
Class representing a hit wire in the central drift chamber.
Definition CDCWireHit.h:58
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
Definition CDCWireHit.h:227
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Definition CDCWireHit.h:289
Abstract base class for different kinds of events.