ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4TrajectoryDrawByEncounteredVolume.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4TrajectoryDrawByEncounteredVolume.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // John Allison February 2016, based on
28 // G4TrajectoryDrawByVolume.hh Jane Tinslay March 2006
29 
32 #include "G4VTrajectory.hh"
33 #include "G4VisTrajContext.hh"
34 #include "G4VTrajectoryPoint.hh"
35 #include "G4AttValue.hh"
36 #include "G4RichTrajectory.hh"
37 
40  :G4VTrajectoryModel(name, context)
41  ,fDefault(G4Colour::Grey())
42 {}
43 
45 
46 void
47 G4TrajectoryDrawByEncounteredVolume::Draw(const G4VTrajectory& traj, const G4bool& /*visible*/) const
48 {
49  try
50  {
51  const G4RichTrajectory& richTrajectory = dynamic_cast<const G4RichTrajectory&>(traj);
52 
53  G4Colour colour(fDefault);
54  G4String soughtPVName("none");
55 
56  for (const auto& item: fMap.GetBasicMap()) {
57  soughtPVName = item.first;
58  for (G4int iPoint = 0; iPoint < richTrajectory.GetPointEntries(); iPoint++) {
59  G4VTrajectoryPoint* point = richTrajectory.GetPoint(iPoint);
60  if (!point) continue;
61  std::vector<G4AttValue>* attValues = point->CreateAttValues();
62  std::vector<G4AttValue>::const_iterator iAtt;
63  for (iAtt = attValues->begin(); iAtt != attValues->end(); ++iAtt) {
64  if (iAtt->GetName() == "PostVPath" &&
65  iAtt->GetValue().contains(soughtPVName)) break;
66  }
67  if (iAtt != attValues->end()) { // Required value found
68  fMap.GetColour(soughtPVName, colour);
69  break; // First found pvname determines colour.
70  }
71  }
72  }
73 
74  G4VisTrajContext myContext(GetContext());
75 
76  myContext.SetLineColour(colour);
77 
78  if (GetVerbose()) {
79  G4cout
80  << "G4TrajectoryDrawByEncounteredVolume drawer named " << Name()
81  << ", drawing trajectory touching physical volume " << soughtPVName
82  << ", with configuration:" << G4endl;
83  myContext.Print(G4cout);
84  }
85 
86  G4TrajectoryDrawerUtils::DrawLineAndPoints(richTrajectory, myContext);
87 
88  }
89 
90  catch (const std::bad_cast&)
91  {
93  ed << "Requires G4RichTrajectory - \"/vis/scene/add/trajectories rich\"";
95  ("G4TrajectoryDrawByEncounteredVolume::Draw(const G4VTrajectory& traj,...",
96  "modeling0125",
97  JustWarning, ed);
98  return;
99  }
100 }
101 
102 void
104 {
105  G4Colour myColour;
106 
107  // Will not modify default colour if colour key does not exist
108  if (!G4Colour::GetColour(colour, myColour)) {
110  ed << "G4Colour with key "<<colour<<" does not exist ";
112  ("G4TrajectoryDrawByEncounteredParticleID::SetDefault(const G4String& colour)",
113  "modeling0123", JustWarning, ed);
114  return;
115  }
116 
117  SetDefault(myColour);
118 }
119 
120 void
122 {
123  fDefault = colour;
124 }
125 
126 void
128 {
129  fMap.Set(pvname, colour);
130 }
131 
132 void
134 {
135  fMap[pvname] = colour;
136 }
137 
138 void
140 {
141  ostr
142  << "G4TrajectoryDrawByEncounteredVolume model "<< Name()
143  << ", colour scheme: "
144  << ", Default " << fDefault
145  << std::endl;
146 
147  fMap.Print(ostr);
148 
149  ostr << "Default configuration:" << std::endl;
150  GetContext().Print(ostr);
151 }