Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "PHG4BlockSubsystem.h"
0002 
0003 #include "PHG4BlockDetector.h"
0004 #include "PHG4BlockDisplayAction.h"
0005 #include "PHG4BlockGeomContainer.h"
0006 #include "PHG4BlockGeomv1.h"
0007 #include "PHG4BlockSteppingAction.h"
0008 
0009 #include <phparameter/PHParameters.h>
0010 
0011 #include <g4main/PHG4DisplayAction.h>  // for PHG4DisplayAction
0012 #include <g4main/PHG4HitContainer.h>
0013 #include <g4main/PHG4SteppingAction.h>  // for PHG4SteppingAction
0014 
0015 #include <phool/PHCompositeNode.h>
0016 #include <phool/PHIODataNode.h>    // for PHIODataNode
0017 #include <phool/PHNode.h>          // for PHNode
0018 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0019 #include <phool/PHObject.h>        // for PHObject
0020 #include <phool/getClass.h>
0021 
0022 #include <cmath>  // for NAN
0023 #include <sstream>
0024 
0025 class PHG4BlockGeom;
0026 class PHG4Detector;
0027 
0028 //_______________________________________________________________________
0029 PHG4BlockSubsystem::PHG4BlockSubsystem(const std::string &name, const int lyr)
0030   : PHG4DetectorSubsystem(name, lyr)
0031 {
0032   m_ColorArray.fill({std::numeric_limits<double>::quiet_NaN()});
0033   InitializeParameters();
0034 }
0035 
0036 //_______________________________________________________________________
0037 PHG4BlockSubsystem::~PHG4BlockSubsystem()
0038 {
0039   delete m_DisplayAction;
0040 }
0041 
0042 //_______________________________________________________________________
0043 int PHG4BlockSubsystem::InitRunSubsystem(PHCompositeNode *topNode)
0044 {
0045   PHNodeIterator iter(topNode);
0046   PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0047 
0048   // create display settings before detector (detector adds its volumes to it)
0049   PHG4BlockDisplayAction *disp_action = new PHG4BlockDisplayAction(Name(), GetParams());
0050   if (std::isfinite(m_ColorArray[0]) &&
0051       std::isfinite(m_ColorArray[1]) &&
0052       std::isfinite(m_ColorArray[2]) &&
0053       std::isfinite(m_ColorArray[3]))
0054   {
0055     disp_action->SetColor(m_ColorArray[0], m_ColorArray[1], m_ColorArray[2], m_ColorArray[3]);
0056   }
0057   m_DisplayAction = disp_action;
0058   // create detector
0059   m_Detector = new PHG4BlockDetector(this, topNode, GetParams(), Name(), GetLayer());
0060   m_Detector->SuperDetector(SuperDetector());
0061   m_Detector->OverlapCheck(CheckOverlap());
0062   if (GetParams()->get_int_param("active"))
0063   {
0064     std::ostringstream nodename;
0065     std::ostringstream geonode;
0066     if (SuperDetector() != "NONE")
0067     {
0068       nodename << "G4HIT_" << SuperDetector();
0069       geonode << "BLOCKGEOM_" << SuperDetector();
0070     }
0071     else
0072     {
0073       nodename << "G4HIT_" << Name();
0074       geonode << "BLOCKGEOM_" << Name();
0075     }
0076 
0077     // create hit list
0078     PHG4HitContainer *block_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename.str());
0079     if (!block_hits)
0080     {
0081       dstNode->addNode(new PHIODataNode<PHObject>(block_hits = new PHG4HitContainer(nodename.str()), nodename.str(), "PHObject"));
0082     }
0083 
0084     block_hits->AddLayer(GetLayer());
0085     PHG4BlockGeomContainer *geocont = findNode::getClass<PHG4BlockGeomContainer>(topNode,
0086                                                                                  geonode.str());
0087     if (!geocont)
0088     {
0089       geocont = new PHG4BlockGeomContainer();
0090       PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "RUN"));
0091       PHIODataNode<PHObject> *newNode = new PHIODataNode<PHObject>(geocont, geonode.str(), "PHObject");
0092       runNode->addNode(newNode);
0093     }
0094 
0095     PHG4BlockGeom *geom = new PHG4BlockGeomv1(GetLayer(),
0096                                               GetParams()->get_double_param("size_x"),
0097                                               GetParams()->get_double_param("size_y"),
0098                                               GetParams()->get_double_param("size_z"),
0099                                               GetParams()->get_double_param("place_x"),
0100                                               GetParams()->get_double_param("place_y"),
0101                                               GetParams()->get_double_param("place_z"),
0102                                               GetParams()->get_double_param("rot_z"));
0103     geocont->AddLayerGeom(GetLayer(), geom);
0104 
0105     m_SteppingAction = new PHG4BlockSteppingAction(m_Detector, GetParams());
0106   }
0107   else if (GetParams()->get_int_param("blackhole"))
0108   {
0109     m_SteppingAction = new PHG4BlockSteppingAction(m_Detector, GetParams());
0110   }
0111 
0112   return 0;
0113 }
0114 
0115 //_______________________________________________________________________
0116 int PHG4BlockSubsystem::process_event(PHCompositeNode *topNode)
0117 {
0118   // pass top node to stepping action so that it gets
0119   // relevant nodes needed internally
0120   if (m_SteppingAction)
0121   {
0122     m_SteppingAction->SetInterfacePointers(topNode);
0123   }
0124   return 0;
0125 }
0126 
0127 //_______________________________________________________________________
0128 PHG4Detector *
0129 PHG4BlockSubsystem::GetDetector() const
0130 {
0131   return m_Detector;
0132 }
0133 
0134 void PHG4BlockSubsystem::SetDefaultParameters()
0135 {
0136   set_default_double_param("place_x", 0.);
0137   set_default_double_param("place_y", 0.);
0138   set_default_double_param("place_z", 0.);
0139   set_default_double_param("rot_x", 0.);
0140   set_default_double_param("rot_y", 0.);
0141   set_default_double_param("rot_z", 0.);
0142   set_default_double_param("steplimits", std::numeric_limits<double>::quiet_NaN());
0143   set_default_double_param("size_x", 10.);
0144   set_default_double_param("size_y", 10.);
0145   set_default_double_param("size_z", 10.);
0146 
0147   set_default_int_param("use_g4steps", 0);
0148 
0149   set_default_string_param("material", "G4_Galactic");
0150 }