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