File indexing completed on 2025-08-05 08:17:40
0001 #include "BeamLineMagnetSubsystem.h"
0002
0003 #include "BeamLineMagnetDetector.h"
0004 #include "BeamLineMagnetDisplayAction.h"
0005 #include "BeamLineMagnetSteppingAction.h"
0006 #include "PHG4DetectorSubsystem.h" // for PHG4DetectorSubsystem
0007
0008 #include <phparameter/PHParameters.h>
0009
0010 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
0011 #include <g4main/PHG4HitContainer.h>
0012 #include <g4main/PHG4SteppingAction.h> // for PHG4SteppingAction
0013
0014 #include <phool/PHCompositeNode.h>
0015 #include <phool/PHIODataNode.h> // for PHIODataNode
0016 #include <phool/PHNode.h> // for PHNode
0017 #include <phool/PHNodeIterator.h> // for PHNodeIterator
0018 #include <phool/PHObject.h> // for PHObject
0019 #include <phool/getClass.h>
0020
0021 #include <iostream> // for operator<<, endl, basic_ostream
0022 #include <set> // for set
0023
0024 class PHG4Detector;
0025
0026
0027 BeamLineMagnetSubsystem::BeamLineMagnetSubsystem(const std::string &na, const int lyr)
0028 : PHG4DetectorSubsystem(na, lyr)
0029 {
0030 InitializeParameters();
0031 }
0032
0033
0034 BeamLineMagnetSubsystem::~BeamLineMagnetSubsystem()
0035 {
0036 delete m_DisplayAction;
0037 }
0038
0039
0040 int BeamLineMagnetSubsystem::InitRunSubsystem(PHCompositeNode *topNode)
0041 {
0042 PHNodeIterator iter(topNode);
0043 PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0044
0045 BeamLineMagnetDisplayAction *displayaction = new BeamLineMagnetDisplayAction(Name());
0046 m_DisplayAction = displayaction;
0047
0048 m_Detector = new BeamLineMagnetDetector(this, topNode, GetParams(), Name(), GetLayer());
0049 m_Detector->SuperDetector(SuperDetector());
0050 m_Detector->OverlapCheck(CheckOverlap());
0051 m_Detector->Verbosity(Verbosity());
0052
0053 if (GetParams()->get_int_param("active"))
0054 {
0055 std::set<std::string> nodes;
0056 PHNodeIterator dstIter(dstNode);
0057 PHCompositeNode *DetNode = dstNode;
0058 if (SuperDetector() != "NONE" || SuperDetector().empty())
0059 {
0060
0061 PHNodeIterator iter_dst(dstNode);
0062 DetNode = dynamic_cast<PHCompositeNode *>(iter_dst.findFirst("PHCompositeNode", SuperDetector()));
0063 if (!DetNode)
0064 {
0065 DetNode = new PHCompositeNode(SuperDetector());
0066 dstNode->addNode(DetNode);
0067 }
0068 }
0069
0070 std::string detector_suffix = SuperDetector();
0071 if (detector_suffix == "NONE")
0072 {
0073 detector_suffix = Name();
0074 }
0075
0076 m_HitNodeName = "G4HIT_" + detector_suffix;
0077 nodes.insert(m_HitNodeName);
0078 m_AbsorberNodeName = "G4HIT_ABSORBER_" + detector_suffix;
0079 if (GetParams()->get_int_param("absorberactive"))
0080 {
0081 nodes.insert(m_AbsorberNodeName);
0082 }
0083 for (const auto &node : nodes)
0084 {
0085 PHG4HitContainer *g4_hits = findNode::getClass<PHG4HitContainer>(topNode, node);
0086 if (!g4_hits)
0087 {
0088 g4_hits = new PHG4HitContainer(node);
0089 DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, node, "PHObject"));
0090 }
0091 }
0092 m_SteppingAction = new BeamLineMagnetSteppingAction(m_Detector, GetParams());
0093 m_SteppingAction->SetHitNodeName("G4HIT", m_HitNodeName);
0094 m_SteppingAction->SetHitNodeName("G4HIT_ABSORBER", m_AbsorberNodeName);
0095 }
0096 else if (GetParams()->get_int_param("blackhole"))
0097 {
0098 m_SteppingAction = new BeamLineMagnetSteppingAction(m_Detector, GetParams());
0099 }
0100 return 0;
0101 }
0102
0103
0104 int BeamLineMagnetSubsystem::process_event(PHCompositeNode *topNode)
0105 {
0106
0107
0108 if (m_SteppingAction)
0109 {
0110 m_SteppingAction->SetInterfacePointers(topNode);
0111 }
0112 return 0;
0113 }
0114
0115
0116 PHG4Detector *BeamLineMagnetSubsystem::GetDetector() const
0117 {
0118 return m_Detector;
0119 }
0120
0121 void BeamLineMagnetSubsystem::SetDefaultParameters()
0122 {
0123 set_default_string_param("magtype", "");
0124
0125 set_default_double_param("field_x", 0.);
0126 set_default_double_param("field_y", 0.);
0127 set_default_double_param("field_z", 0.);
0128 set_default_double_param("fieldgradient", 0.);
0129
0130 set_default_double_param("field_global_position_x", 0.);
0131 set_default_double_param("field_global_position_y", 0.);
0132 set_default_double_param("field_global_position_z", 0.);
0133 set_default_double_param("field_global_rot_x", 0.);
0134 set_default_double_param("field_global_rot_y", 0.);
0135 set_default_double_param("field_global_rot_z", 0.);
0136
0137 set_default_double_param("length", 100);
0138 set_default_double_param("place_x", 0.);
0139 set_default_double_param("place_y", 0.);
0140 set_default_double_param("place_z", 0.);
0141 set_default_double_param("rot_x", 0.);
0142 set_default_double_param("rot_y", 0.);
0143 set_default_double_param("rot_z", 0.);
0144 set_default_double_param("inner_radius", 4);
0145 set_default_double_param("outer_radius", 100);
0146 set_default_double_param("skin_thickness", 0.);
0147 }
0148
0149 void BeamLineMagnetSubsystem::Print(const std::string & ) const
0150 {
0151 std::cout << Name() << " Parameters: " << std::endl;
0152 if (!BeginRunExecuted())
0153 {
0154 std::cout << "Need to execute BeginRun() before parameter printout is meaningful" << std::endl;
0155 std::cout << "To do so either run one or more events or on the command line execute: " << std::endl;
0156 std::cout << "Fun4AllServer *se = Fun4AllServer::instance();" << std::endl;
0157 std::cout << "PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");" << std::endl;
0158 std::cout << "g4->InitRun(se->topNode());" << std::endl;
0159 std::cout << "BeamLineMagnetSubsystem *cyl = (PHG4BeamLineMagnetSubsystem *) g4->getSubsystem(\"" << Name() << "\");" << std::endl;
0160 std::cout << "cyl->Print()" << std::endl;
0161 return;
0162 }
0163 GetParams()->Print();
0164 return;
0165 }