File indexing completed on 2025-08-05 08:17:50
0001 #include "PHG4PSTOFDetector.h"
0002
0003 #include <phparameter/PHParameters.h>
0004 #include <phparameter/PHParametersContainer.h>
0005
0006 #include <g4main/PHG4Detector.h> // for PHG4Detector
0007
0008 #include <Geant4/G4Box.hh>
0009 #include <Geant4/G4Colour.hh>
0010 #include <Geant4/G4LogicalVolume.hh>
0011 #include <Geant4/G4PVPlacement.hh>
0012 #include <Geant4/G4RotationMatrix.hh> // for G4RotationMatrix
0013 #include <Geant4/G4String.hh> // for G4String
0014 #include <Geant4/G4SystemOfUnits.hh>
0015 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
0016 #include <Geant4/G4VisAttributes.hh>
0017
0018 #include <cmath>
0019 #include <iostream> // for operator<<, endl, bas...
0020 #include <utility> // for pair
0021
0022 class G4Material;
0023 class PHCompositeNode;
0024
0025 PHG4PSTOFDetector::PHG4PSTOFDetector(PHG4Subsystem *subsys, PHCompositeNode *Node, PHParametersContainer *params, const std::string &dnam)
0026 : PHG4Detector(subsys, Node, dnam)
0027 , paramscontainer(params)
0028 {
0029 const PHParameters *par = paramscontainer->GetParameters(-1);
0030 IsActive = par->get_int_param("active");
0031 IsAbsorberActive = par->get_int_param("absorberactive");
0032 nmod = par->get_int_param("modules");
0033 nrows = par->get_int_param("rows");
0034 }
0035
0036
0037
0038 int PHG4PSTOFDetector::IsInPSTOF(G4VPhysicalVolume *volume) const
0039 {
0040
0041 std::map<G4VPhysicalVolume *, int>::const_iterator iter = active_phys_vols.find(volume);
0042
0043 if (iter != active_phys_vols.end())
0044 {
0045 return iter->second;
0046 }
0047
0048 return 0;
0049 }
0050
0051 void PHG4PSTOFDetector::ConstructMe(G4LogicalVolume *logicWorld)
0052 {
0053 G4Material *Glass = GetDetectorMaterial("G4_GLASS_PLATE");
0054 G4Box *pstof_box = new G4Box("pstof_box", 0.8 * cm, 6 * cm, 5 * cm);
0055
0056 G4LogicalVolume *pstof_log_vol = new G4LogicalVolume(pstof_box, Glass, G4String("PSTOF_box"), nullptr, nullptr, nullptr);
0057 G4VisAttributes *pstofVisAtt = new G4VisAttributes();
0058 pstofVisAtt->SetVisibility(true);
0059 pstofVisAtt->SetForceSolid(true);
0060 pstofVisAtt->SetColour(G4Colour::Blue());
0061 pstof_log_vol->SetVisAttributes(pstofVisAtt);
0062
0063 for (int irow = 0; irow < nrows; irow++)
0064 {
0065 int rowtype = irow % 2;
0066 double phi = irow * (2.0 * M_PI / nrows);
0067
0068 for (int imod = 0; imod < nmod; imod++)
0069 {
0070 const PHParameters *par = paramscontainer->GetParameters(imod);
0071 double z = NAN;
0072 double r = NAN;
0073 if (rowtype == 0)
0074 {
0075 z = par->get_double_param("z_mod_0") * cm;
0076 r = par->get_double_param("r_mod_0") * cm;
0077 }
0078 else
0079 {
0080 z = par->get_double_param("z_mod_1") * cm;
0081 r = par->get_double_param("r_mod_1") * cm;
0082 }
0083
0084
0085
0086 double theta = atan2(z, r);
0087
0088 G4RotationMatrix *rotm = new G4RotationMatrix();
0089 rotm->rotateZ(-phi);
0090 rotm->rotateY(theta);
0091
0092 double x = r * cos(phi);
0093 double y = r * sin(phi);
0094
0095 int modnum = nmod * irow + imod;
0096 G4VPhysicalVolume *vol = new G4PVPlacement(rotm, G4ThreeVector(x, y, z), pstof_log_vol, "PSTOF", logicWorld, false, modnum, OverlapCheck());
0097 if (IsActive)
0098 {
0099 active_phys_vols[vol] = modnum;
0100
0101 }
0102 }
0103 }
0104
0105 return;
0106 }
0107
0108 void PHG4PSTOFDetector::Print(const std::string &what) const
0109 {
0110 std::cout << "PSTOF Detector:" << std::endl;
0111 if (what == "ALL" || what == "VOLUME")
0112 {
0113 std::cout << "Version 0.1" << std::endl;
0114 }
0115 return;
0116 }