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/trackFindingCDC/eventdata/hits/CDCWireHit.h>
13#include <tracking/trackFindingCDC/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;
24
26const std::string c_bkgHitColor = "orange";
27
29const std::string c_missingPDGColor = "lime";
30
32const std::map<int, std::string> c_colorByPDGCode = {
33 { -999, "orange"},
34 {11, "blue"},
35 { -11, "blue"},
36 {13, "turquoise"},
37 { -13, "turquoise"},
38 {15, "cyan"},
39 { -15, "cyan"},
40 {22, "violet"},
41 {211, "green"},
42 { -211, "green"},
43 {321, "olive"},
44 { -321, "olive"},
45 {2212, "red"},
46 { -2212, "red"},
47};
48
49std::string ZeroDriftLengthColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
50{
51 CDCWireHit wirehit(&hit);
52 if (wirehit.getRefDriftLength() == 0) {
53 return "red";
54 } else {
55 return c_bkgHitColor;
56 }
57}
58
59std::string ZeroDriftLengthStrokeWidthMap::map(int index __attribute__((unused)), const CDCHit& hit)
60{
61 CDCWireHit wirehit(&hit, nullptr);
62 if (wirehit.getRefDriftLength() == 0) {
63 return "1";
64 } else {
65 return "0.2";
66 }
67}
68
70{
71 if (not m_storedWireHits) {
72 B2WARNING("CDCWireHitVector could not be found on the DataStore. Cannot plot the taken flags.");
73 }
74}
75
76std::string TakenFlagColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
77{
78 if (m_storedWireHits) {
79 const std::vector<CDCWireHit>& wireHits = *m_storedWireHits;
80 ConstVectorRange<CDCWireHit> wireHitRange{std::equal_range(wireHits.begin(), wireHits.end(), hit)};
81
82 if (not wireHitRange.empty()) {
83 const CDCWireHit& wireHit = wireHitRange.front();
84 if (wireHit.getAutomatonCell().hasTakenFlag()) {
85 return "red";
86 }
87 }
88 }
89 return c_bkgHitColor;
90}
91
92std::string RLColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
93{
94 const CDCMCHitLookUp& mcHitLookUp = mcHitLookUp.getInstance();
95 short int rlInfo = mcHitLookUp.getRLInfo(&hit);
96 if (rlInfo == 1) {
97 return ("green");
98 } else if (rlInfo == -1) {
99 return ("red");
100 } else {
101 return (c_bkgHitColor);
102 }
103}
104
105std::string RLColorMap::info()
106{
107 return "Local right left passage variable: green <-> right, red <-> left, orange <-> not determinable.\n";
108}
109
110std::string PosFlagColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
111{
112 CDCSimHit* simHit = hit.getRelated<CDCSimHit>("CDCSimHits");
113 int posFlag = simHit->getPosFlag();
114 if (posFlag == 0) {
115 return ("green"); // right
116 } else if (posFlag == 1) {
117 return ("red"); // left
118 } else {
119 return (c_bkgHitColor);
120 }
121}
122
124{
125 return "PosFlag variable of the related CDCSimHit: green <-> 0 (Right), red <-> 1 (Left), orange <-> determinable.\n";
126}
127
128std::string BackgroundTagColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
129{
130 CDCSimHit* cdcSimHit = hit.getRelated<CDCSimHit>("CDCSimHits");
131 short backgroundtag = cdcSimHit->getBackgroundTag();
132 switch (backgroundtag) {
133 case BackgroundMetaData::BG_TAG::bg_none: return "orange";
135 case BackgroundMetaData::BG_TAG::bg_Coulomb_HER: return "darkred";
136 case BackgroundMetaData::BG_TAG::bg_RBB_LER: return "blue";
137 case BackgroundMetaData::BG_TAG::bg_RBB_HER: return "darkblue";
139 case BackgroundMetaData::BG_TAG::bg_Touschek_HER: return "darkgreen";
140 case BackgroundMetaData::BG_TAG::bg_twoPhoton: return "violet";
141 case BackgroundMetaData::BG_TAG::bg_RBB_gamma: return "skyblue";
142 case BackgroundMetaData::BG_TAG::bg_RBB_LER_far: return "turquoise";
143 case BackgroundMetaData::BG_TAG::bg_RBB_HER_far: return "darkturquoise";
144 case BackgroundMetaData::BG_TAG::bg_Touschek_LER_far: return "olivergreen";
145 case BackgroundMetaData::BG_TAG::bg_Touschek_HER_far: return "darkolivegreen";
146 case BackgroundMetaData::BG_TAG::bg_SynchRad_LER: return "goldenrod";
147 case BackgroundMetaData::BG_TAG::bg_SynchRad_HER: return "darkgoldenrod";
149 case BackgroundMetaData::BG_TAG::bg_BHWide_HER: return "darkcyan";
150 case BackgroundMetaData::BG_TAG::bg_other: return "orange";
151 default:
152 B2INFO("Background tag " << backgroundtag << " not associated with a color.\n");
153 return ("orange");
154 }
155}
156
158{
159 return ("Background tag color coding is:\n"
160 "bg_Coulomb_HER: darkred\n"
161 "bg_Coulomb_LER: red\n"
162 "bg_RBB_HER: darkblue\n"
163 "bg_RBB_HER_far: darkturquoise\n"
164 "bg_RBB_LER: blue\n"
165 "bg_RBB_LER_far: turquoise\n"
166 "bg_SynchRad_HER: darkgoldenrod\n"
167 "bg_SynchRad_LER: goldenrod\n"
168 "bg_Touschek_HER: darkgreen\n"
169 "bg_Touschek_HER_far: darkolivegreen\n"
170 "bg_Touschek_LER: green\n"
171 "bg_Touschek_LER_far: olivergreen\n"
172 "bg_RBB_gamma: skyblue\n"
173 "bg_none: orange\n"
174 "bg_other: orange\n"
175 "bg_twoPhoton: violet\n"
176 );
177}
178
179std::string MCSegmentIdColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
180{
182 mcHitLookUp.getInstance();
183 TrackFindingCDC::Index inTrackiSegment = mcHitLookUp.getInTrackSegmentId(&hit);
184
185 if (inTrackiSegment < 0) {
186 return (c_bkgHitColor);
187 } else {
188 // values are all fractions of their respective scale
189 double hue = 50 * inTrackiSegment % 360 / 360.0;
190 double saturation = 0.75, lightness = 0.5;
191 std::array<double, 3> rgb = Colors::hlsToRgb(hue, lightness, saturation);
192 std::ostringstream oss;
193 std::string color;
194 oss << "rgb(" << rgb[0] * 100 << "%, " << rgb[1] * 100 << "%, " << rgb[2] * 100 << "%)";
195 color = oss.str();
196 return color;
197 }
198}
199
200std::string TOFColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
201{
202 CDCSimHit* simHit = hit.getRelated<CDCSimHit>("CDCSimHits");
203 double timeOfFlight = simHit->getFlightTime();
204 return timeOfFlightToColor(timeOfFlight);
205}
206
207std::string TOFColorMap::timeOfFlightToColor(const double timeOfFlight)
208{
209 //values are all fractions of their respective scale
210
211 //Full color circle in 3 nanoseconds
212 double hue = fmod(360 / 3.0 * timeOfFlight, 360) / 360;
213 double saturation = 0.75, lightness = 0.5;
214 std::array<double, 3> rgb = Colors::hlsToRgb(hue, lightness, saturation);
215 std::ostringstream oss;
216 std::string color;
217 oss << "rgb(" << rgb[0] * 100 << "%, " << rgb[1] * 100 << "%, " << rgb[2] * 100 << "%)";
218 color = oss.str();
219 return color;
220}
221
222std::string ReassignedSecondaryMap::map(int index __attribute__((unused)), const CDCHit& hit)
223{
224 RelationVector<MCParticle> relatedMCParticles =
225 hit.getRelationsWith<MCParticle>("MCParticles");
226 if (relatedMCParticles.size() == 0) {
227 return c_bkgHitColor;
228 } else {
229 double mcRelationWeight = relatedMCParticles.weight(0);
230 if (mcRelationWeight > 0) {
231 return "green";
232 } else {
233 return "red";
234 }
235 }
236}
237
239 : m_colors(Colors::getList())
240 , m_iColor(0)
241 , m_usedColors()
242{
243}
244
246{
247 std::ostringstream oss;
248 for (const std::pair<int, std::string> colorForMCParticleID : m_usedColors) {
249 oss << "MCParticle " << colorForMCParticleID.first << " -> " << colorForMCParticleID.second << "\n";
250 }
251 return oss.str();
252}
253
254std::string MCParticleColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
255{
256 MCParticle* mcParticle = hit.getRelated<MCParticle>("MCParticles");
257 if (mcParticle != nullptr) {
258 int mcParticleId = mcParticle->getArrayIndex();
259 if (m_usedColors.count(mcParticleId) == 1) {
260 return m_usedColors[mcParticleId];
261 } else {
262 ++m_iColor;
263 std::string color = m_colors[m_iColor % m_colors.size()];
264 m_usedColors.emplace(mcParticleId, color);
265 return color;
266 }
267 } else {
268 return c_bkgHitColor;
269 }
270}
271
272std::string MCPDGCodeColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
273{
274 MCParticle* mcParticle = hit.getRelated<MCParticle>("MCParticles");
275 int pdgCode = mcParticle != nullptr ? mcParticle->getPDG() : -999;
276
277 auto itFound = c_colorByPDGCode.find(pdgCode);
278 if (itFound != c_colorByPDGCode.end()) {
279 return itFound->second;
280 } else {
281 B2WARNING("Unknown PDG code " << pdgCode);
282 return c_missingPDGColor;
283 }
284}
285
287{
288 std::ostringstream oss;
289 oss << "\nLegend:";
290
291 std::map<std::string, std::set<int>> pdgCodeByColor;
292
293 for (auto item : c_colorByPDGCode) {
294 pdgCodeByColor[item.second].insert(item.first);
295 }
296
297 for (auto item : pdgCodeByColor) {
298 oss << '\n' << item.first << "->[";
299 oss << join(", ", item.second);
300 oss << ']';
301 }
302 oss << '\n';
303 return oss.str();
304}
305
306std::string MCPrimaryColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
307{
308 MCParticle* mcParticle = hit.getRelated<MCParticle>("MCParticles");
309 if (mcParticle != nullptr) {
310 unsigned short int primaryFlag = 1;
311 bool isPrimary = mcParticle->hasStatus(primaryFlag);
312 int secondaryProcess = mcParticle->getSecondaryPhysicsProcess();
313
314 if (isPrimary) {
315 return "blue";
316 } else if (secondaryProcess > 200) {
317 return "green"; // decay in flight
318 } else {
319 return "red";
320 }
321 } else {
322 return c_bkgHitColor;
323 }
324}
325
327{
328 return "Legend:\n"
329 "blue->primary\n"
330 "green->secondary decay in flight\n"
331 "orange->beam background\n";
332}
333
334std::string SimHitPDGCodeColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
335{
336 CDCSimHit* simHit = hit.getRelated<CDCSimHit>("CDCSimHits");
337 int pdgCode = simHit != nullptr ? simHit->getPDGCode() : -999;
338 auto itFound = c_colorByPDGCode.find(pdgCode);
339 if (itFound != c_colorByPDGCode.end()) {
340 return itFound->second;
341 } else {
342 B2WARNING("Unknown PDG code " << pdgCode);
343 return c_missingPDGColor;
344 }
345}
346
348{
349 std::ostringstream oss;
350 oss << "\nLegend:";
351
352 std::map<std::string, std::set<int>> pdgCodeByColor;
353
354 for (auto item : c_colorByPDGCode) {
355 pdgCodeByColor[item.second].insert(item.first);
356 }
357
358 for (auto item : pdgCodeByColor) {
359 oss << '\n' << item.first << "->[";
360 oss << join(", ", item.second);
361 oss << ']';
362 }
363 oss << '\n';
364 return oss.str();
365}
366
367std::string SimHitIsBkgColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
368{
369 CDCSimHit* simHit = hit.getRelated<CDCSimHit>("CDCSimHits");
370 bool bkgTag = simHit->getBackgroundTag();
371 if (bkgTag) {
372 return "gray";
373 } else {
374 return "red";
375 }
376}
377
378std::string NLoopsColorMap::map(int index __attribute__((unused)), const CDCHit& hit)
379{
380 const CDCMCHitLookUp& mcHitLookUp = mcHitLookUp.getInstance();
381
382 int nLoops = mcHitLookUp.getNLoops(&hit);
383
384 if (nLoops < 0) {
385 return c_bkgHitColor;
386 }
387 return Colors::getWheelColor(70 * nLoops);
388}
@ 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:178
double getFlightTime() const
The method to get flight time.
Definition: CDCSimHit.h:184
int getPosFlag() const
The method to get old left/right info.
Definition: CDCSimHit.h:223
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:129
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:244
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:112
int getSecondaryPhysicsProcess() const
Returns the physics process type of a secondary particle.
Definition: MCParticle.h:297
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.
virtual unsigned short getBackgroundTag() const
Get background tag.
Definition: SimHitBase.h:46
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
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.
Index getInTrackSegmentId(const CDCHit *ptrHit) const
Returns the id of the segment in the track.
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.
ERightLeft getRLInfo(const CDCHit *ptrHit) const
Returns the true right left passage information.
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
Definition: CDCWireHit.h:224
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Definition: CDCWireHit.h:286
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 continously filled as new during the ev...
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 seconday 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.
A pair of iterators usable with the range base for loop.
Definition: Range.h:25
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 accessable.
StoreWrappedObjPtr< std::vector< 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.
Abstract base class for different kinds of events.