File indexing completed on 2025-08-05 08:17:43
0001 #include "PHG4CEmcTestBeamSubsystem.h"
0002 #include "PHG4CEmcTestBeamDetector.h"
0003
0004 #include "PHG4CEmcTestBeamSteppingAction.h"
0005 #include "PHG4EventActionClearZeroEdep.h"
0006
0007 #include <g4main/PHG4HitContainer.h>
0008 #include <g4main/PHG4Subsystem.h> // for PHG4Subsystem
0009
0010 #include <phool/PHCompositeNode.h>
0011 #include <phool/PHIODataNode.h> // for PHIODataNode
0012 #include <phool/PHNode.h> // for PHNode
0013 #include <phool/PHNodeIterator.h> // for PHNodeIterator
0014 #include <phool/PHObject.h> // for PHObject
0015 #include <phool/getClass.h>
0016
0017 #include <Geant4/G4SystemOfUnits.hh>
0018 #include <Geant4/G4Types.hh> // for G4double
0019
0020 #include <sstream>
0021
0022 class PHG4Detector;
0023 class PHG4SteppingAction;
0024
0025 using namespace std;
0026
0027
0028 PHG4CEmcTestBeamSubsystem::PHG4CEmcTestBeamSubsystem(const std::string& name, const int lyr)
0029 : PHG4Subsystem(name)
0030 , detector_(nullptr)
0031 , steppingAction_(nullptr)
0032 , eventAction_(nullptr)
0033 , place_in_x(0)
0034 , place_in_y(0)
0035 , place_in_z(0)
0036 , rot_in_x(0)
0037 , rot_in_y(0)
0038 , rot_in_z(0)
0039 , active(0)
0040 , absorberactive(0)
0041 , layer(lyr)
0042 , blackhole(0)
0043 , detector_type(name)
0044 , superdetector("NONE")
0045 {
0046
0047
0048 ostringstream nam;
0049 nam << name << "_" << lyr;
0050 Name(nam.str());
0051 for (double& i : dimension)
0052 {
0053 i = 100.0 * cm;
0054 }
0055 }
0056
0057
0058 int PHG4CEmcTestBeamSubsystem::Init(PHCompositeNode* topNode)
0059 {
0060 PHNodeIterator iter(topNode);
0061 PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
0062
0063
0064 detector_ = new PHG4CEmcTestBeamDetector(this, topNode, Name(), layer);
0065 detector_->SetPlace(place_in_x, place_in_y, place_in_z);
0066 detector_->SetXRot(rot_in_x);
0067 detector_->SetYRot(rot_in_y);
0068 detector_->SetZRot(rot_in_z);
0069 detector_->SetActive(active);
0070 detector_->SetAbsorberActive(absorberactive);
0071 detector_->BlackHole(blackhole);
0072 detector_->SuperDetector(superdetector);
0073 detector_->OverlapCheck(CheckOverlap());
0074 if (active)
0075 {
0076 ostringstream nodename;
0077 if (superdetector != "NONE")
0078 {
0079 nodename << "G4HIT_" << superdetector;
0080 }
0081 else
0082 {
0083 nodename << "G4HIT_" << detector_type << "_" << layer;
0084 }
0085
0086 PHG4HitContainer* block_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename.str());
0087 if (!block_hits)
0088 {
0089 dstNode->addNode(new PHIODataNode<PHObject>(block_hits = new PHG4HitContainer(nodename.str()), nodename.str(), "PHObject"));
0090 }
0091 if (absorberactive)
0092 {
0093 nodename.str("");
0094 if (superdetector != "NONE")
0095 {
0096 nodename << "G4HIT_ABSORBER_" << superdetector;
0097 }
0098 else
0099 {
0100 nodename << "G4HIT_ABSORBER_" << detector_type << "_" << layer;
0101 }
0102 }
0103 block_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename.str());
0104 if (!block_hits)
0105 {
0106 dstNode->addNode(new PHIODataNode<PHObject>(block_hits = new PHG4HitContainer(nodename.str()), nodename.str(), "PHObject"));
0107 }
0108
0109 steppingAction_ = new PHG4CEmcTestBeamSteppingAction(detector_);
0110
0111 eventAction_ = new PHG4EventActionClearZeroEdep(topNode, nodename.str());
0112 }
0113 if (blackhole && !active)
0114 {
0115 steppingAction_ = new PHG4CEmcTestBeamSteppingAction(detector_);
0116 }
0117 return 0;
0118 }
0119
0120
0121 int PHG4CEmcTestBeamSubsystem::process_event(PHCompositeNode* topNode)
0122 {
0123
0124
0125 if (steppingAction_)
0126 {
0127 steppingAction_->SetInterfacePointers(topNode);
0128 }
0129 return 0;
0130 }
0131
0132
0133 PHG4Detector* PHG4CEmcTestBeamSubsystem::GetDetector() const
0134 {
0135 return detector_;
0136 }
0137
0138
0139 PHG4SteppingAction* PHG4CEmcTestBeamSubsystem::GetSteppingAction() const
0140 {
0141 return steppingAction_;
0142 }
0143
0144 void PHG4CEmcTestBeamSubsystem::SetPlace(const G4double place_x, const G4double place_y, const G4double place_z)
0145 {
0146 place_in_x = place_x * cm;
0147 place_in_y = place_y * cm;
0148 place_in_z = place_z * cm;
0149 }
0150
0151 void PHG4CEmcTestBeamSubsystem::SetPlaceZ(const G4double dbl)
0152 {
0153 place_in_z = dbl * cm;
0154 }
0155
0156 void PHG4CEmcTestBeamSubsystem::SetXRot(const G4double dbl)
0157 {
0158 rot_in_x = dbl * deg;
0159 }
0160
0161 void PHG4CEmcTestBeamSubsystem::SetYRot(const G4double dbl)
0162 {
0163 rot_in_y = dbl * deg;
0164 }
0165
0166 void PHG4CEmcTestBeamSubsystem::SetZRot(const G4double dbl)
0167 {
0168 rot_in_z = dbl * deg;
0169 }