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