EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Example03DisplayAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Example03DisplayAction.cc
2 
4 #include <g4main/PHG4Utils.h>
5 
6 #include <phparameter/PHParameters.h>
7 
8 #include <Geant4/G4Colour.hh> // for G4Colour
9 #include <Geant4/G4LogicalVolume.hh>
10 #include <Geant4/G4VisAttributes.hh>
11 
12 #include <cmath> // for isfinite
13 
14 using namespace std;
15 
17  : PHG4DisplayAction(name)
18  , m_Params(pars)
19  , m_MyVolume(nullptr)
20  , m_VisAtt(nullptr)
21  , m_Colour(nullptr)
22 {
23 }
24 
26 {
27  delete m_VisAtt;
28  delete m_Colour;
29 }
30 
31 void G4Example03DisplayAction::ApplyDisplayAction(G4VPhysicalVolume *physvol)
32 {
33  // check if vis attributes exist, if so someone else has set them and we do nothing
34  if (m_MyVolume->GetVisAttributes())
35  {
36  return;
37  }
38  m_VisAtt = new G4VisAttributes();
39  if (m_Params->get_int_param("blackhole"))
40  {
41  PHG4Utils::SetColour(m_VisAtt, "BlackHole");
42  m_VisAtt->SetVisibility(false);
43  m_VisAtt->SetForceSolid(false);
44  }
45  else
46  {
48  m_VisAtt->SetVisibility(true);
49  m_VisAtt->SetForceSolid(true);
50  }
51  if (m_Colour)
52  {
53  m_VisAtt->SetColour(m_Colour->GetRed(),
54  m_Colour->GetGreen(),
55  m_Colour->GetBlue(),
56  m_Colour->GetAlpha());
57  m_VisAtt->SetVisibility(true);
58  m_VisAtt->SetForceSolid(true);
59  }
60  m_MyVolume->SetVisAttributes(m_VisAtt);
61  return;
62 }
63 
64 void G4Example03DisplayAction::SetColor(const double red, const double green, const double blue, const double alpha)
65 {
66  if (isfinite(red) && isfinite(green) && isfinite(blue) && isfinite(alpha))
67  {
68  m_Colour = new G4Colour(red, green, blue, alpha);
69  }
70  return;
71 }