File indexing completed on 2025-08-05 08:17:44
0001 #include "PHG4ConeSubsystem.h"
0002
0003 #include "PHG4ConeDetector.h"
0004 #include "PHG4ConeDisplayAction.h"
0005 #include "PHG4ConeSteppingAction.h"
0006
0007 #include <phparameter/PHParameters.h>
0008
0009 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
0010 #include <g4main/PHG4HitContainer.h>
0011 #include <g4main/PHG4SteppingAction.h>
0012
0013 #include <phool/PHCompositeNode.h>
0014 #include <phool/PHIODataNode.h> // for PHIODataNode
0015 #include <phool/PHNode.h> // for PHNode
0016 #include <phool/PHNodeIterator.h> // for PHNodeIterator
0017 #include <phool/PHObject.h> // for PHObject
0018 #include <phool/getClass.h>
0019
0020 #include <cmath> // for tan, atan, exp, M_PI
0021 #include <sstream>
0022
0023 class PHG4Detector;
0024
0025
0026 PHG4ConeSubsystem::PHG4ConeSubsystem(const std::string &name, const int lyr)
0027 : PHG4DetectorSubsystem(name, lyr)
0028 {
0029 m_ColorArray.fill(NAN);
0030 InitializeParameters();
0031 }
0032
0033
0034 PHG4ConeSubsystem::~PHG4ConeSubsystem()
0035 {
0036 delete m_DisplayAction;
0037 }
0038
0039
0040 int PHG4ConeSubsystem::InitRunSubsystem(PHCompositeNode *topNode)
0041 {
0042
0043 PHG4ConeDisplayAction *disp_action = new PHG4ConeDisplayAction(Name(), GetParams());
0044 if (std::isfinite(m_ColorArray[0]) &&
0045 std::isfinite(m_ColorArray[1]) &&
0046 std::isfinite(m_ColorArray[2]) &&
0047 std::isfinite(m_ColorArray[3]))
0048 {
0049 disp_action->SetColor(m_ColorArray[0], m_ColorArray[1], m_ColorArray[2], m_ColorArray[3]);
0050 }
0051 m_DisplayAction = disp_action;
0052
0053
0054 m_Detector = new PHG4ConeDetector(this, topNode, GetParams(), Name(), GetLayer());
0055 m_Detector->SuperDetector(SuperDetector());
0056 m_Detector->OverlapCheck(CheckOverlap());
0057 if (GetParams()->get_int_param("active"))
0058 {
0059 PHNodeIterator iter(topNode);
0060 PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0061 PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "RUN"));
0062
0063 std::string nodename;
0064 if (SuperDetector() != "NONE")
0065 {
0066 PHNodeIterator iter_dst(dstNode);
0067 PHCompositeNode *superSubNode = dynamic_cast<PHCompositeNode *>(iter_dst.findFirst("PHCompositeNode", SuperDetector()));
0068 if (!superSubNode)
0069 {
0070 superSubNode = new PHCompositeNode(SuperDetector());
0071 dstNode->addNode(superSubNode);
0072 }
0073 dstNode = superSubNode;
0074 PHNodeIterator iter_run(runNode);
0075 superSubNode = dynamic_cast<PHCompositeNode *>(iter_run.findFirst("PHCompositeNode", SuperDetector()));
0076 if (!superSubNode)
0077 {
0078 superSubNode = new PHCompositeNode(SuperDetector());
0079 runNode->addNode(superSubNode);
0080 }
0081 nodename = "G4HIT_" + SuperDetector();
0082 }
0083 else
0084 {
0085 nodename = "G4HIT_" + Name();
0086 }
0087
0088 PHG4HitContainer *cone_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename);
0089 if (!cone_hits)
0090 {
0091 dstNode->addNode(new PHIODataNode<PHObject>(cone_hits = new PHG4HitContainer(nodename), nodename, "PHObject"));
0092 }
0093
0094 m_SteppingAction = new PHG4ConeSteppingAction(m_Detector);
0095 }
0096 return 0;
0097 }
0098
0099
0100 int PHG4ConeSubsystem::process_event(PHCompositeNode *topNode)
0101 {
0102
0103
0104 if (m_SteppingAction)
0105 {
0106 m_SteppingAction->SetInterfacePointers(topNode);
0107 }
0108 return 0;
0109 }
0110
0111
0112 PHG4Detector *PHG4ConeSubsystem::GetDetector() const
0113 {
0114 return m_Detector;
0115 }
0116
0117
0118 void PHG4ConeSubsystem::Set_eta_range(const double etaMin, const double etaMax)
0119 {
0120 double thetaMin = 2 * atan(exp(-etaMax));
0121 double thetaMax = 2 * atan(exp(-etaMin));
0122
0123 double z1 = get_double_param("place_z") - get_double_param("length");
0124 double z2 = get_double_param("place_z") + get_double_param("length");
0125
0126 set_double_param("rmin1", z1 * tan(thetaMin));
0127 set_double_param("rmax1", z1 * tan(thetaMax));
0128
0129 set_double_param("rmin2", z2 * tan(thetaMin));
0130 set_double_param("rmax2", z2 * tan(thetaMax));
0131 }
0132
0133 void PHG4ConeSubsystem::SetDefaultParameters()
0134 {
0135 set_default_double_param("place_x", 0.);
0136 set_default_double_param("place_y", 0.);
0137 set_default_double_param("place_z", 0.);
0138
0139 set_default_double_param("length", NAN);
0140 set_default_double_param("rmin1", NAN);
0141 set_default_double_param("rmax1", NAN);
0142 set_default_double_param("rmin2", NAN);
0143 set_default_double_param("rmax2", NAN);
0144 set_default_double_param("sphi", 0.);
0145 set_default_double_param("dphi", 360.);
0146 set_default_double_param("rot_x", 0);
0147 set_default_double_param("rot_y", 0);
0148 set_default_double_param("rot_z", 0);
0149
0150 set_default_string_param("material", "WorldMaterial");
0151 }
0152
0153 void PHG4ConeSubsystem::SetR1(const double min, const double max)
0154 {
0155 set_double_param("rmin1", min);
0156 set_double_param("rmax1", max);
0157 }
0158
0159 void PHG4ConeSubsystem::SetR2(const double min, const double max)
0160 {
0161 set_double_param("rmin2", min);
0162 set_double_param("rmax2", max);
0163 }
0164
0165 void PHG4ConeSubsystem::SetZlength(const double a)
0166 {
0167 set_double_param("length", a);
0168 }
0169
0170 void PHG4ConeSubsystem::SetPhi(const double a, const double b)
0171 {
0172 set_double_param("sphi", a);
0173 set_double_param("dphi", b);
0174 }
0175
0176 void PHG4ConeSubsystem::SetPlaceZ(const double dbl)
0177 {
0178 set_double_param("place_z", dbl);
0179 }
0180
0181 void PHG4ConeSubsystem::SetPlace(const double place_x, const double place_y, const double place_z)
0182 {
0183 set_double_param("place_x", place_x);
0184 set_double_param("place_y", place_y);
0185 set_double_param("place_z", place_z);
0186 }
0187
0188 void PHG4ConeSubsystem::SetZRot(const double dbl)
0189 {
0190 set_double_param("rot_z", dbl);
0191 }
0192
0193 void PHG4ConeSubsystem::SetMaterial(const std::string &mat)
0194 {
0195 set_string_param("material", mat);
0196 }