Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:17:53

0001 #include "PHG4ZDCSubsystem.h"
0002 
0003 #include "PHG4ZDCDetector.h"
0004 #include "PHG4ZDCDisplayAction.h"
0005 #include "PHG4ZDCSteppingAction.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>  // for PHG4SteppingAction
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 <fstream>
0021 #include <set>  // for set
0022 #include <sstream>
0023 
0024 class PHG4Detector;
0025 
0026 //_______________________________________________________________________
0027 PHG4ZDCSubsystem::PHG4ZDCSubsystem(const std::string& name, const int lyr)
0028   : PHG4DetectorSubsystem(name, lyr)
0029 {
0030   InitializeParameters();
0031 }
0032 
0033 //_______________________________________________________________________
0034 PHG4ZDCSubsystem::~PHG4ZDCSubsystem()
0035 {
0036   delete m_DisplayAction;
0037 }
0038 
0039 //_______________________________________________________________________
0040 int PHG4ZDCSubsystem::InitRunSubsystem(PHCompositeNode* topNode)
0041 {
0042   PHNodeIterator iter(topNode);
0043   PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
0044 
0045   // create display settings before detector
0046   m_DisplayAction = new PHG4ZDCDisplayAction(Name());
0047   // create detector
0048   m_Detector = new PHG4ZDCDetector(this, topNode, GetParams(), Name(), GetLayer());
0049 
0050   m_Detector->SuperDetector(SuperDetector());
0051   m_Detector->OverlapCheck(CheckOverlap());
0052   m_Detector->Verbosity(Verbosity());
0053 
0054   if (GetParams()->get_int_param("active"))
0055   {
0056     std::set<std::string> nodes;
0057     PHNodeIterator dstIter(dstNode);
0058     PHCompositeNode* DetNode = dstNode;
0059     if (SuperDetector() != "NONE" && !SuperDetector().empty())
0060     {
0061       PHNodeIterator iter_dst(dstNode);
0062       DetNode = dynamic_cast<PHCompositeNode*>(iter_dst.findFirst("PHCompositeNode", SuperDetector()));
0063 
0064       if (!DetNode)
0065       {
0066         DetNode = new PHCompositeNode(SuperDetector());
0067         dstNode->addNode(DetNode);
0068       }
0069     }
0070     // create hit output nodes
0071     std::string detector_suffix = SuperDetector();
0072     if (detector_suffix == "NONE" || detector_suffix.empty())
0073     {
0074       detector_suffix = Name();
0075     }
0076 
0077     m_HitNodeName = "G4HIT_" + detector_suffix;
0078     nodes.insert(m_HitNodeName);
0079     m_AbsorberNodeName = "G4HIT_ABSORBER_" + detector_suffix;
0080     if (GetParams()->get_int_param("absorberactive"))
0081     {
0082       nodes.insert(m_AbsorberNodeName);
0083     }
0084     m_SupportNodeName = "G4HIT_SUPPORT_" + detector_suffix;
0085     if (GetParams()->get_int_param("supportactive"))
0086     {
0087       nodes.insert(m_SupportNodeName);
0088     }
0089 
0090     for (const auto& nodename : nodes)
0091     {
0092       PHG4HitContainer* g4_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename);
0093       if (!g4_hits)
0094       {
0095         g4_hits = new PHG4HitContainer(nodename);
0096         DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, nodename, "PHObject"));
0097       }
0098     }
0099     // create stepping action
0100     m_SteppingAction = new PHG4ZDCSteppingAction(m_Detector, GetParams());
0101     m_SteppingAction->SetHitNodeName("G4HIT", m_HitNodeName);
0102     m_SteppingAction->SetHitNodeName("G4HIT_ABSORBER", m_AbsorberNodeName);
0103     m_SteppingAction->SetHitNodeName("G4HIT_SUPPORT", m_SupportNodeName);
0104   }
0105   else if (GetParams()->get_int_param("blackhole"))
0106   {
0107     m_SteppingAction = new PHG4ZDCSteppingAction(m_Detector, GetParams());
0108   }
0109   return 0;
0110 }
0111 
0112 //_______________________________________________________________________
0113 int PHG4ZDCSubsystem::process_event(PHCompositeNode* topNode)
0114 {
0115   // pass top node to stepping action so that it gets
0116   // relevant nodes needed internally
0117   if (m_SteppingAction)
0118   {
0119     m_SteppingAction->SetInterfacePointers(topNode);
0120   }
0121   return 0;
0122 }
0123 
0124 //_______________________________________________________________________
0125 PHG4Detector* PHG4ZDCSubsystem::GetDetector() const
0126 {
0127   return m_Detector;
0128 }
0129 
0130 void PHG4ZDCSubsystem::SetDefaultParameters()
0131 {
0132   set_default_double_param("place_x", 0.);
0133   set_default_double_param("place_y", 0.);
0134   set_default_double_param("place_z", 1843.0);
0135   set_default_double_param("rot_x", 0.);
0136   set_default_double_param("rot_y", 0.);
0137   set_default_double_param("rot_z", 0.);
0138   return;
0139 }