Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:19:03

0001 /*!
0002  * \file ${file_name}
0003  * \brief
0004  * \author Jin Huang <jhuang@bnl.gov>
0005  * \version $$Revision: 1.2 $$
0006  * \date $$Date: 2014/08/12 03:49:12 $$
0007  */
0008 #include "PHG4SpacalSubsystem.h"
0009 
0010 #include "PHG4CylinderGeom_Spacalv1.h"  // for PHG4CylinderGeom_Spacalv1
0011 #include "PHG4FullProjSpacalDetector.h"
0012 #include "PHG4FullProjTiltedSpacalDetector.h"
0013 #include "PHG4SpacalDetector.h"
0014 #include "PHG4SpacalDisplayAction.h"
0015 #include "PHG4SpacalSteppingAction.h"
0016 
0017 #include <phparameter/PHParameters.h>
0018 
0019 #include <g4main/PHG4DisplayAction.h>  // for PHG4DisplayAction
0020 #include <g4main/PHG4HitContainer.h>
0021 #include <g4main/PHG4SteppingAction.h>  // for PHG4SteppingAction
0022 
0023 #include <phool/PHCompositeNode.h>
0024 #include <phool/PHIODataNode.h>    // for PHIODataNode
0025 #include <phool/PHNode.h>          // for PHNode
0026 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0027 #include <phool/PHObject.h>        // for PHObject
0028 #include <phool/getClass.h>
0029 
0030 #include <TSystem.h>
0031 
0032 #include <cassert>
0033 #include <cstdlib>
0034 #include <iostream>  // for operator<<, basic_ostream
0035 #include <sstream>
0036 
0037 class PHG4Detector;
0038 
0039 //_______________________________________________________________________
0040 PHG4SpacalSubsystem::PHG4SpacalSubsystem(const std::string& na, const int lyr)
0041   : PHG4DetectorSubsystem(na, lyr)
0042 {
0043   InitializeParameters();
0044 }
0045 
0046 //_______________________________________________________________________
0047 PHG4SpacalSubsystem::~PHG4SpacalSubsystem()
0048 {
0049   delete m_DisplayAction;
0050 }
0051 
0052 //_______________________________________________________________________
0053 int PHG4SpacalSubsystem::InitRunSubsystem(PHCompositeNode* topNode)
0054 {
0055   // create hit list only for active layers
0056   PHNodeIterator iter(topNode);
0057   PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
0058   // create detector
0059   //  _geom.set_layer( layer );
0060   //  if (lengthViaRapidityCoverage)
0061   //    {
0062   //       const double half_length =  PHG4Utils::GetLengthForRapidityCoverage(_geom.get_max_radius());
0063   //       _geom.set_zmin(-half_length);
0064   //       _geom.set_zmax(+half_length);
0065   //    }
0066   // create display settings before detector (detector adds its volumes to it)
0067   m_DisplayAction = new PHG4SpacalDisplayAction(Name());
0068   switch (GetParams()->get_int_param("config"))
0069   {
0070   case PHG4CylinderGeom_Spacalv1::kNonProjective:
0071     if (Verbosity() > 0)
0072     {
0073       std::cout << "PHG4SpacalSubsystem::InitRun - use PHG4SpacalDetector" << std::endl;
0074     }
0075     detector_ = new PHG4SpacalDetector(this, topNode, Name(), GetParams(), GetLayer());
0076     break;
0077 
0078   case PHG4CylinderGeom_Spacalv1::kFullProjective_2DTaper:
0079   case PHG4CylinderGeom_Spacalv1::kFullProjective_2DTaper_SameLengthFiberPerTower:
0080     if (Verbosity() > 0)
0081     {
0082       std::cout << "PHG4SpacalSubsystem::InitRun - use PHG4FullProjSpacalDetector" << std::endl;
0083     }
0084     detector_ = new PHG4FullProjSpacalDetector(this, topNode, Name(), GetParams(), GetLayer());
0085     break;
0086 
0087   case PHG4CylinderGeom_Spacalv1::kFullProjective_2DTaper_Tilted:
0088   case PHG4CylinderGeom_Spacalv1::kFullProjective_2DTaper_Tilted_SameLengthFiberPerTower:
0089     if (Verbosity() > 0)
0090     {
0091       std::cout << "PHG4SpacalSubsystem::InitRun - use PHG4FullProjTiltedSpacalDetector" << std::endl;
0092     }
0093     detector_ = new PHG4FullProjTiltedSpacalDetector(this, topNode, Name(), GetParams(), GetLayer());
0094     break;
0095 
0096   default:
0097     std::cout << "PHG4SpacalSubsystem::InitRun - unknown option exiting" << std::endl;
0098     gSystem->Exit(1);
0099     break;
0100   }
0101 
0102   detector_->SetActive(GetParams()->get_int_param("active"));
0103   detector_->SetAbsorberActive(GetParams()->get_int_param("absorberactive"));
0104   detector_->SuperDetector(SuperDetector());
0105   detector_->OverlapCheck(CheckOverlap());
0106   detector_->CosmicSetup(CosmicSetup());
0107   // the geometry object is set during detector construction, we need it for the
0108   // display to extract the visibility setting for logical volumes
0109   PHG4SpacalDisplayAction* DispAct = dynamic_cast<PHG4SpacalDisplayAction*>(m_DisplayAction);
0110   DispAct->SetGeom(detector_->get_geom());
0111 
0112   if (GetParams()->get_int_param("active"))
0113   {
0114     std::set<std::string> nodes;
0115     PHNodeIterator dstIter(dstNode);
0116     PHCompositeNode* DetNode = dstNode;
0117     if (SuperDetector() != "NONE" && !SuperDetector().empty())
0118     {
0119       PHNodeIterator iter_dst(dstNode);
0120       DetNode = dynamic_cast<PHCompositeNode*>(iter_dst.findFirst("PHCompositeNode", SuperDetector()));
0121       if (!DetNode)
0122       {
0123         DetNode = new PHCompositeNode(SuperDetector());
0124         dstNode->addNode(DetNode);
0125       }
0126     }
0127     std::string detector_suffix = SuperDetector();
0128     if (detector_suffix == "NONE" || detector_suffix.empty())
0129     {
0130       detector_suffix = Name();
0131     }
0132 
0133     m_HitNodeName = "G4HIT_" + detector_suffix;
0134     nodes.insert(m_HitNodeName);
0135     m_AbsorberNodeName = "G4HIT_ABSORBER_" + detector_suffix;
0136     if (GetParams()->get_int_param("absorberactive"))
0137     {
0138       nodes.insert(m_AbsorberNodeName);
0139     }
0140     for (const auto& nodename : nodes)
0141     {
0142       PHG4HitContainer* g4_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename);
0143       if (!g4_hits)
0144       {
0145         g4_hits = new PHG4HitContainer(nodename);
0146         DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, nodename, "PHObject"));
0147       }
0148       g4_hits->AddLayer(GetLayer());
0149     }
0150 
0151     steppingAction_ = new PHG4SpacalSteppingAction(detector_, GetParams());
0152     steppingAction_->InitWithNode(topNode);
0153     const char* calibrationRoot = getenv("CALIBRATIONROOT");
0154     assert(calibrationRoot != nullptr && "Environment variable CALIBRATIONROOT is not set");
0155     std::string filePath = std::string(calibrationRoot) + "/CEMC/LightCollection/Prototype3Module.xml";
0156     steppingAction_->get_light_collection_model().load_data_file(
0157         filePath, "data_grid_light_guide_efficiency", "data_grid_fiber_trans");
0158     steppingAction_->SetHitNodeName("G4HIT", m_HitNodeName);
0159     steppingAction_->SetHitNodeName("G4HIT_ABSORBER", m_AbsorberNodeName);
0160   }
0161   return 0;
0162 }
0163 
0164 //_______________________________________________________________________
0165 int PHG4SpacalSubsystem::process_event(PHCompositeNode* topNode)
0166 {
0167   // pass top node to stepping action so that it gets
0168   // relevant nodes needed internally
0169   if (steppingAction_)
0170   {
0171     steppingAction_->SetInterfacePointers(topNode);
0172   }
0173   return 0;
0174 }
0175 
0176 //_______________________________________________________________________
0177 PHG4Detector* PHG4SpacalSubsystem::GetDetector() const
0178 {
0179   return detector_;
0180 }
0181 
0182 //_______________________________________________________________________
0183 void PHG4SpacalSubsystem::Print(const std::string& what) const
0184 {
0185   detector_->Print(what);
0186   return;
0187 }
0188 
0189 void PHG4SpacalSubsystem::SetDefaultParameters()
0190 {
0191   set_default_double_param("xpos", 0.);  // translation in 3D
0192   set_default_double_param("ypos", 0.);  // translation in 3D
0193   set_default_double_param("zpos", 0.);  // translation in 3D
0194 
0195   set_default_double_param("thickness", 21.00000);
0196   set_default_double_param("radius", 90.);
0197   set_default_double_param("zmin", -149.470000);
0198   set_default_double_param("zmax", 149.470000);
0199   set_default_double_param("tmin", -20.);
0200   set_default_double_param("tmax", 60.);
0201   set_default_double_param("dt", 100.);
0202   set_default_int_param("azimuthal_n_sec", 256);
0203 
0204   set_default_int_param("construction_verbose", 0.);
0205   set_default_int_param("azimuthal_seg_visible", 0.);
0206   set_default_int_param("virualize_fiber", 0.);
0207   set_default_int_param("config", static_cast<int>(PHG4CylinderGeom_Spacalv1::kNonProjective));
0208   set_default_int_param("saveg4hit", 1);
0209 
0210   set_default_double_param("divider_width", 0);       // radial size of the divider between blocks. <=0 means no dividers
0211   set_default_string_param("divider_mat", "G4_AIR");  // materials of the divider. G4_AIR is equivalent to not installing one in the term of material distribution
0212 
0213   return;
0214 }