File indexing completed on 2025-08-05 08:20:46
0001 #include "PHG4SpacalPrototypeSubsystem.h"
0002
0003 #include "PHG4SpacalPrototypeDetector.h"
0004 #include "PHG4SpacalPrototypeSteppingAction.h"
0005
0006 #include <phparameter/PHParameters.h>
0007
0008 #include <g4detectors/PHG4DetectorSubsystem.h> // for PHG4DetectorSubsystem
0009
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 <iostream> // for operator<<, basic_ost...
0021 #include <sstream>
0022
0023 class PHG4Detector;
0024
0025 using namespace std;
0026
0027
0028 PHG4SpacalPrototypeSubsystem::PHG4SpacalPrototypeSubsystem(const std::string& na)
0029 : PHG4DetectorSubsystem(na, 0)
0030 , detector_(nullptr)
0031 , steppingAction_(nullptr)
0032 {
0033 InitializeParameters();
0034 }
0035
0036
0037 int PHG4SpacalPrototypeSubsystem::InitRunSubsystem(PHCompositeNode* topNode)
0038 {
0039 PHNodeIterator iter(topNode);
0040 PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
0041
0042 if (Verbosity() > 0)
0043 cout
0044 << "PHG4SpacalPrototypeSubsystem::InitRun - use PHG4SpacalPrototypeDetector"
0045 << endl;
0046 detector_ = new PHG4SpacalPrototypeDetector(this, topNode, GetParams(), Name());
0047
0048 detector_->SetActive(GetParams()->get_int_param("active"));
0049 detector_->SetAbsorberActive(GetParams()->get_int_param("absorberactive"));
0050 detector_->SuperDetector(SuperDetector());
0051 detector_->OverlapCheck(CheckOverlap());
0052
0053 if (GetParams()->get_int_param("active"))
0054 {
0055 ostringstream nodename;
0056 if (SuperDetector() != "NONE")
0057 {
0058 nodename << "G4HIT_" << SuperDetector();
0059 }
0060 else
0061 {
0062 nodename << "G4HIT_" << Name();
0063 }
0064 PHG4HitContainer* cylinder_hits = findNode::getClass<PHG4HitContainer>(
0065 topNode, nodename.str());
0066 if (!cylinder_hits)
0067 {
0068 dstNode->addNode(
0069 new PHIODataNode<PHObject>(
0070 cylinder_hits = new PHG4HitContainer(nodename.str()),
0071 nodename.str(), "PHObject"));
0072 }
0073 cylinder_hits->AddLayer(0);
0074 if (GetParams()->get_int_param("absorberactive"))
0075 {
0076 nodename.str("");
0077 if (SuperDetector() != "NONE")
0078 {
0079 nodename << "G4HIT_ABSORBER_" << SuperDetector();
0080 }
0081 else
0082 {
0083 nodename << "G4HIT_ABSORBER_" << Name();
0084 }
0085 PHG4HitContainer* cylinder_hits =
0086 findNode::getClass<PHG4HitContainer>(topNode, nodename.str());
0087 if (!cylinder_hits)
0088 {
0089 cylinder_hits = new PHG4HitContainer(nodename.str());
0090 dstNode->addNode(new PHIODataNode<PHObject>(cylinder_hits, nodename.str(), "PHObject"));
0091 }
0092 cylinder_hits->AddLayer(0);
0093 }
0094 steppingAction_ = new PHG4SpacalPrototypeSteppingAction(detector_);
0095 }
0096
0097 return 0;
0098 }
0099
0100
0101 int PHG4SpacalPrototypeSubsystem::process_event(PHCompositeNode* topNode)
0102 {
0103
0104
0105 if (steppingAction_)
0106 {
0107 steppingAction_->SetInterfacePointers(topNode);
0108 }
0109 return 0;
0110 }
0111
0112
0113 PHG4Detector*
0114 PHG4SpacalPrototypeSubsystem::GetDetector(void) const
0115 {
0116 return detector_;
0117 }
0118
0119 void PHG4SpacalPrototypeSubsystem::Print(const std::string& what) const
0120 {
0121 detector_->Print(what);
0122 cout << Name() << " Parameters: " << endl;
0123 if (!BeginRunExecuted())
0124 {
0125 cout << "Need to execute BeginRun() before parameter printout is meaningful" << endl;
0126 cout << "To do so either run one or more events or on the command line execute: " << endl;
0127 cout << "Fun4AllServer *se = Fun4AllServer::instance();" << endl;
0128 cout << "PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");" << endl;
0129 cout << "g4->InitRun(se->topNode());" << endl;
0130 cout << "PHG4SpacalPrototypeSubsystem *sys = (PHG4SpacalPrototypeSubsystem *) g4->getSubsystem(\"" << Name() << "\");" << endl;
0131 cout << "sys->Print()" << endl;
0132 return;
0133 }
0134 GetParams()->Print();
0135 return;
0136 }
0137
0138 void PHG4SpacalPrototypeSubsystem::SetDefaultParameters()
0139 {
0140 set_default_double_param("xpos", 0.);
0141 set_default_double_param("ypos", 0.);
0142 set_default_double_param("zpos", 0.);
0143 set_default_double_param("z_rotation_degree", 0.);
0144 set_default_int_param("construction_verbose", 0.);
0145 return;
0146 }