File indexing completed on 2025-08-06 08:19:03
0001 #include "PHG4sPHENIXMagnetSubsystem.h"
0002
0003 #include "PHG4HcalDefs.h"
0004 #include "PHG4sPHENIXMagnetDetector.h"
0005 #include "PHG4sPHENIXMagnetDisplayAction.h"
0006 #include "PHG4sPHENIXMagnetSteppingAction.h"
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 <cmath> // for NAN
0022 #include <iostream> // for operator<<, basic_ostream
0023 #include <set> // for set
0024 #include <sstream>
0025
0026 class PHG4Detector;
0027
0028
0029 PHG4sPHENIXMagnetSubsystem::PHG4sPHENIXMagnetSubsystem(const std::string &name, const int lyr)
0030 : PHG4DetectorSubsystem(name, lyr)
0031 {
0032 InitializeParameters();
0033 }
0034
0035
0036 PHG4sPHENIXMagnetSubsystem::~PHG4sPHENIXMagnetSubsystem()
0037 {
0038 delete m_DisplayAction;
0039 }
0040
0041
0042 int PHG4sPHENIXMagnetSubsystem::InitRunSubsystem(PHCompositeNode *topNode)
0043 {
0044 PHNodeIterator iter(topNode);
0045 PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0046
0047
0048 m_DisplayAction = new PHG4sPHENIXMagnetDisplayAction(Name());
0049
0050
0051 m_Detector = new PHG4sPHENIXMagnetDetector(this, topNode, GetParams(), Name(), GetLayer());
0052 m_Detector->SuperDetector(SuperDetector());
0053 m_Detector->OverlapCheck(CheckOverlap());
0054
0055 if (GetParams()->get_int_param("active"))
0056 {
0057 std::set<std::string> nodes;
0058 PHNodeIterator dstIter(dstNode);
0059 PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", SuperDetector()));
0060 if (!DetNode)
0061 {
0062 DetNode = new PHCompositeNode(SuperDetector());
0063 dstNode->addNode(DetNode);
0064 }
0065 std::ostringstream nodename;
0066 if (SuperDetector() != "NONE")
0067 {
0068 nodename << "G4HIT_" << SuperDetector();
0069 }
0070 else
0071 {
0072 nodename << "G4HIT_" << Name();
0073 }
0074 nodes.insert(nodename.str());
0075
0076 for (auto &node : nodes)
0077 {
0078 PHG4HitContainer *g4_hits = findNode::getClass<PHG4HitContainer>(topNode, node);
0079 if (!g4_hits)
0080 {
0081 g4_hits = new PHG4HitContainer(node);
0082 DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, node, "PHObject"));
0083 }
0084 }
0085
0086 m_SteppingAction = new PHG4sPHENIXMagnetSteppingAction(m_Detector, GetParams());
0087 m_SteppingAction->InitWithNode(topNode);
0088 }
0089 else
0090 {
0091 if (GetParams()->get_int_param("blackhole"))
0092 {
0093 m_SteppingAction = new PHG4sPHENIXMagnetSteppingAction(m_Detector, GetParams());
0094 m_SteppingAction->InitWithNode(topNode);
0095 }
0096 }
0097
0098 return 0;
0099 }
0100
0101
0102 int PHG4sPHENIXMagnetSubsystem::process_event(PHCompositeNode *topNode)
0103 {
0104
0105
0106 if (m_SteppingAction)
0107 {
0108 m_SteppingAction->SetInterfacePointers(topNode);
0109 }
0110 return 0;
0111 }
0112
0113 void PHG4sPHENIXMagnetSubsystem::Print(const std::string &what) const
0114 {
0115 std::cout << "sPHENIX Magnet Parameters: " << std::endl;
0116 GetParams()->Print();
0117 if (m_Detector)
0118 {
0119 m_Detector->Print(what);
0120 }
0121 return;
0122 }
0123
0124
0125 PHG4Detector *PHG4sPHENIXMagnetSubsystem::GetDetector() const
0126 {
0127 return m_Detector;
0128 }
0129
0130 void PHG4sPHENIXMagnetSubsystem::SetDefaultParameters()
0131 {
0132 set_default_int_param("use_g4steps", 0);
0133 return;
0134 }