Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:19:05

0001 /* vim: set sw=2 ft=cpp: */
0002 
0003 #include "PHG4EPDSubsystem.h"
0004 
0005 #include "PHG4EPDDetector.h"
0006 #include "PHG4EPDDisplayAction.h"
0007 #include "PHG4EPDSteppingAction.h"
0008 
0009 #include <phparameter/PHParameters.h>
0010 
0011 #include <g4detectors/PHG4DetectorSubsystem.h>  // for PHG4DetectorSubsystem
0012 
0013 #include <g4main/PHG4DisplayAction.h>  // for PHG4DisplayAction
0014 #include <g4main/PHG4HitContainer.h>
0015 #include <g4main/PHG4SteppingAction.h>  // for PHG4SteppingAction
0016 
0017 #include <phool/PHCompositeNode.h>
0018 #include <phool/PHIODataNode.h>
0019 #include <phool/PHNode.h>
0020 #include <phool/PHNodeIterator.h>
0021 #include <phool/PHObject.h>
0022 #include <phool/getClass.h>
0023 
0024 #include <set>
0025 #include <string>
0026 
0027 PHG4EPDSubsystem::PHG4EPDSubsystem(std::string const& name)
0028   : PHG4DetectorSubsystem(name)
0029 {
0030   InitializeParameters();
0031 }
0032 
0033 PHG4EPDSubsystem::~PHG4EPDSubsystem()
0034 {
0035   delete m_DisplayAction;
0036 }
0037 
0038 int PHG4EPDSubsystem::InitRunSubsystem(PHCompositeNode* topNode)
0039 {
0040   m_DisplayAction = new PHG4EPDDisplayAction(Name());
0041 
0042   m_Detector = new PHG4EPDDetector(this, topNode, GetParams(), Name());
0043   m_Detector->SuperDetector(SuperDetector());
0044   m_Detector->OverlapCheck(CheckOverlap());
0045 
0046   if (GetParams()->get_int_param("active"))
0047   {
0048     std::set<std::string> nodes;
0049     PHNodeIterator iter(topNode);
0050     PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
0051     PHNodeIterator dstIter(dstNode);
0052     PHCompositeNode* DetNode = dstNode;
0053     if (SuperDetector() != "NONE" && !SuperDetector().empty())
0054     {
0055       PHNodeIterator iter_dst(dstNode);
0056       DetNode = dynamic_cast<PHCompositeNode*>(iter_dst.findFirst("PHCompositeNode", SuperDetector()));
0057 
0058       if (!DetNode)
0059       {
0060         DetNode = new PHCompositeNode(SuperDetector());
0061         dstNode->addNode(DetNode);
0062       }
0063     }
0064     // create hit output nodes
0065     std::string detector_suffix = SuperDetector();
0066     if (detector_suffix == "NONE")
0067     {
0068       detector_suffix = Name();
0069     }
0070 
0071     m_HitNodeName = "G4HIT_" + detector_suffix;
0072     nodes.insert(m_HitNodeName);
0073     m_SupportNodeName = "G4HIT_SUPPORT_" + detector_suffix;
0074     if (GetParams()->get_int_param("supportactive"))
0075     {
0076       nodes.insert(m_SupportNodeName);
0077     }
0078 
0079     for (const auto& nodename : nodes)
0080     {
0081       PHG4HitContainer* g4_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename);
0082       if (!g4_hits)
0083       {
0084         g4_hits = new PHG4HitContainer(nodename);
0085         DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, nodename, "PHObject"));
0086       }
0087     }
0088     // create stepping action
0089     m_SteppingAction = new PHG4EPDSteppingAction(m_Detector, GetParams());
0090     m_SteppingAction->SetHitNodeName("G4HIT", m_HitNodeName);
0091     m_SteppingAction->SetHitNodeName("G4HIT_SUPPORT", m_SupportNodeName);
0092   }
0093   else if (GetParams()->get_int_param("blackhole"))
0094   {
0095     m_SteppingAction = new PHG4EPDSteppingAction(m_Detector, GetParams());
0096   }
0097 
0098   return 0;
0099 }
0100 
0101 int PHG4EPDSubsystem::process_event(PHCompositeNode* topNode)
0102 {
0103   if (m_SteppingAction != nullptr)
0104   {
0105     m_SteppingAction->SetInterfacePointers(topNode);
0106   }
0107   return 0;
0108 }
0109 
0110 PHG4Detector* PHG4EPDSubsystem::GetDetector() const
0111 {
0112   return m_Detector;
0113 }
0114 
0115 void PHG4EPDSubsystem::SetDefaultParameters()
0116 {
0117   set_default_double_param("place_z", 316.);
0118 }