Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4PSTOFDetector.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4PSTOFDetector.cc
1 #include "PHG4PSTOFDetector.h"
2 
3 #include <phparameter/PHParameters.h>
4 #include <phparameter/PHParametersContainer.h>
5 
6 #include <g4main/PHG4Detector.h> // for PHG4Detector
7 
8 #include <Geant4/G4Box.hh>
9 #include <Geant4/G4Colour.hh>
10 #include <Geant4/G4LogicalVolume.hh>
11 #include <Geant4/G4PVPlacement.hh>
12 #include <Geant4/G4RotationMatrix.hh> // for G4RotationMatrix
13 #include <Geant4/G4String.hh> // for G4String
14 #include <Geant4/G4SystemOfUnits.hh>
15 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
16 #include <Geant4/G4VisAttributes.hh>
17 
18 #include <cmath>
19 #include <iostream> // for operator<<, endl, bas...
20 #include <utility> // for pair
21 
22 class G4Material;
23 class PHCompositeNode;
24 
26  : PHG4Detector(subsys, Node, dnam)
27  , paramscontainer(params)
28 {
29  const PHParameters *par = paramscontainer->GetParameters(-1);
30  IsActive = par->get_int_param("active");
31  IsAbsorberActive = par->get_int_param("absorberactive");
32  nmod = par->get_int_param("modules");
33  nrows = par->get_int_param("rows");
34 }
35 
36 //_______________________________________________________________
37 //_______________________________________________________________
39 {
40  // G4AssemblyVolumes naming convention:
41  std::map<G4VPhysicalVolume *, int>::const_iterator iter = active_phys_vols.find(volume);
42 
43  if (iter != active_phys_vols.end())
44  {
45  return iter->second;
46  }
47 
48  return 0;
49 }
50 
51 void PHG4PSTOFDetector::ConstructMe(G4LogicalVolume *logicWorld)
52 {
53  G4Material *Glass = GetDetectorMaterial("G4_GLASS_PLATE");
54  G4Box *pstof_box = new G4Box("pstof_box", 0.8 * cm, 6 * cm, 5 * cm);
55 
56  G4LogicalVolume *pstof_log_vol = new G4LogicalVolume(pstof_box, Glass, G4String("PSTOF_box"), nullptr, nullptr, nullptr);
57  G4VisAttributes *pstofVisAtt = new G4VisAttributes();
58  pstofVisAtt->SetVisibility(true);
59  pstofVisAtt->SetForceSolid(true);
60  pstofVisAtt->SetColour(G4Colour::Blue());
61  pstof_log_vol->SetVisAttributes(pstofVisAtt);
62 
63  for (int irow = 0; irow < nrows; irow++)
64  {
65  int rowtype = irow % 2; // odd or even row
66  double phi = irow * (2.0 * M_PI / nrows);
67 
68  for (int imod = 0; imod < nmod; imod++)
69  {
70  const PHParameters *par = paramscontainer->GetParameters(imod);
71  double z = NAN;
72  double r = NAN;
73  if (rowtype == 0)
74  {
75  z = par->get_double_param("z_mod_0") * cm;
76  r = par->get_double_param("r_mod_0") * cm;
77  }
78  else
79  {
80  z = par->get_double_param("z_mod_1") * cm;
81  r = par->get_double_param("r_mod_1") * cm;
82  }
83 
84  // amount to rotate
85  //double theta = atan2(z+z_offset[rowtype][itof],tof_radius+y_offset[rowtype][itof]);
86  double theta = atan2(z, r);
87 
88  G4RotationMatrix *rotm = new G4RotationMatrix();
89  rotm->rotateZ(-phi);
90  rotm->rotateY(theta);
91 
92  double x = r * cos(phi);
93  double y = r * sin(phi);
94 
95  int modnum = nmod * irow + imod;
96  G4VPhysicalVolume *vol = new G4PVPlacement(rotm, G4ThreeVector(x, y, z), pstof_log_vol, "PSTOF", logicWorld, false, modnum, OverlapCheck());
97  if (IsActive)
98  {
99  active_phys_vols[vol] = modnum;
100  // active_phys_vols.insert(vol);
101  }
102  }
103  }
104 
105  return;
106 }
107 
108 void PHG4PSTOFDetector::Print(const std::string &what) const
109 {
110  std::cout << "PSTOF Detector:" << std::endl;
111  if (what == "ALL" || what == "VOLUME")
112  {
113  std::cout << "Version 0.1" << std::endl;
114  }
115  return;
116 }