Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "PHG4OuterHcalSubsystem.h"
0002 
0003 #include "PHG4HcalDefs.h"
0004 #include "PHG4OuterHcalDetector.h"
0005 #include "PHG4OuterHcalDisplayAction.h"
0006 #include "PHG4OuterHcalSteppingAction.h"
0007 
0008 #include <phparameter/PHParameters.h>
0009 
0010 #include <g4main/PHG4DisplayAction.h>  // for PHG4DisplayAction
0011 #include <g4main/PHG4HitContainer.h>
0012 #include <g4main/PHG4SteppingAction.h>  // for PHG4SteppingAction
0013 
0014 #include <phool/PHCompositeNode.h>
0015 #include <phool/PHIODataNode.h>    // for PHIODataNode
0016 #include <phool/PHNode.h>          // for PHNode
0017 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0018 #include <phool/PHObject.h>        // for PHObject
0019 #include <phool/getClass.h>
0020 
0021 #include <cmath>     // for NAN
0022 #include <iostream>  // for operator<<, basic_ostream
0023 #include <set>       // for set
0024 #include <sstream>
0025 
0026 class PHG4Detector;
0027 
0028 //_______________________________________________________________________
0029 PHG4OuterHcalSubsystem::PHG4OuterHcalSubsystem(const std::string &name, const int lyr)
0030   : PHG4DetectorSubsystem(name, lyr)
0031 {
0032   InitializeParameters();
0033 }
0034 
0035 //_______________________________________________________________________
0036 PHG4OuterHcalSubsystem::~PHG4OuterHcalSubsystem()
0037 {
0038   delete m_DisplayAction;
0039 }
0040 
0041 //_______________________________________________________________________
0042 int PHG4OuterHcalSubsystem::InitRunSubsystem(PHCompositeNode *topNode)
0043 {
0044   PHNodeIterator iter(topNode);
0045   PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0046 
0047   // create display settings before detector
0048   m_DisplayAction = new PHG4OuterHcalDisplayAction(Name());
0049 
0050   // create detector
0051   m_Detector = new PHG4OuterHcalDetector(this, topNode, GetParams(), Name());
0052   m_Detector->SuperDetector(SuperDetector());
0053   m_Detector->OverlapCheck(CheckOverlap());
0054 
0055   if (GetParams()->get_int_param("active"))
0056   {
0057     std::set<std::string> nodes;
0058     PHNodeIterator dstIter(dstNode);
0059     PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", SuperDetector()));
0060     if (!DetNode)
0061     {
0062       DetNode = new PHCompositeNode(SuperDetector());
0063       dstNode->addNode(DetNode);
0064     }
0065     std::ostringstream nodename;
0066     if (SuperDetector() != "NONE")
0067     {
0068       nodename << "G4HIT_" << SuperDetector();
0069     }
0070     else
0071     {
0072       nodename << "G4HIT_" << Name();
0073     }
0074     nodes.insert(nodename.str());
0075     if (GetParams()->get_int_param("absorberactive"))
0076     {
0077       nodename.str("");
0078       if (SuperDetector() != "NONE")
0079       {
0080         nodename << "G4HIT_ABSORBER_" << SuperDetector();
0081       }
0082       else
0083       {
0084         nodename << "G4HIT_ABSORBER_" << Name();
0085       }
0086       nodes.insert(nodename.str());
0087     }
0088     for (auto &node : nodes)
0089     {
0090       PHG4HitContainer *g4_hits = findNode::getClass<PHG4HitContainer>(topNode, node);
0091       if (!g4_hits)
0092       {
0093         g4_hits = new PHG4HitContainer(node);
0094         DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, node, "PHObject"));
0095       }
0096     }
0097     // create stepping action
0098     m_SteppingAction = new PHG4OuterHcalSteppingAction(m_Detector, GetParams());
0099     m_SteppingAction->InitWithNode(topNode);
0100   }
0101   else
0102   {
0103     if (GetParams()->get_int_param("blackhole"))
0104     {
0105       m_SteppingAction = new PHG4OuterHcalSteppingAction(m_Detector, GetParams());
0106       m_SteppingAction->InitWithNode(topNode);
0107     }
0108   }
0109 
0110   return 0;
0111 }
0112 
0113 //_______________________________________________________________________
0114 int PHG4OuterHcalSubsystem::process_event(PHCompositeNode *topNode)
0115 {
0116   // pass top node to stepping action so that it gets
0117   // relevant nodes needed internally
0118   if (m_SteppingAction)
0119   {
0120     m_SteppingAction->SetInterfacePointers(topNode);
0121   }
0122   return 0;
0123 }
0124 
0125 void PHG4OuterHcalSubsystem::Print(const std::string &what) const
0126 {
0127   std::cout << "Outer Hcal Parameters: " << std::endl;
0128   GetParams()->Print();
0129   if (m_Detector)
0130   {
0131     m_Detector->Print(what);
0132   }
0133   return;
0134 }
0135 
0136 //_______________________________________________________________________
0137 PHG4Detector *PHG4OuterHcalSubsystem::GetDetector() const
0138 {
0139   return m_Detector;
0140 }
0141 
0142 void PHG4OuterHcalSubsystem::SetLightCorrection(const double inner_radius, const double inner_corr, const double outer_radius, const double outer_corr)
0143 {
0144   set_double_param("light_balance_inner_corr", inner_corr);
0145   set_double_param("light_balance_inner_radius", inner_radius);
0146   set_double_param("light_balance_outer_corr", outer_corr);
0147   set_double_param("light_balance_outer_radius", outer_radius);
0148   return;
0149 }
0150 
0151 void PHG4OuterHcalSubsystem::SetDefaultParameters()
0152 {
0153   set_default_double_param("inner_radius", 183.3);
0154   set_default_double_param("light_balance_inner_corr", NAN);
0155   set_default_double_param("light_balance_inner_radius", NAN);
0156   set_default_double_param("light_balance_outer_corr", NAN);
0157   set_default_double_param("light_balance_outer_radius", NAN);
0158   set_default_double_param("phistart", NAN);
0159   set_default_double_param("scinti_eta_coverage_neg", 1.1);
0160   set_default_double_param("scinti_eta_coverage_pos", 1.1);
0161   // some math issue in the code does not subtract the magnet cutout correctly
0162   // (maybe some factor of 2 in a G4 volume creation)
0163   // The engineering drawing values are:
0164   //  set_default_double_param("magnet_cutout_radius", 195.31);
0165   //  set_default_double_param("magnet_cutout_scinti_radius", 195.96);
0166   // seting this to these values results in the correct edges
0167   // (verified by looking at the G4 hit coordinates of the inner edges)
0168   set_default_double_param("magnet_cutout_radius", 195.72);
0169   set_default_double_param("magnet_cutout_scinti_radius", 197.04);
0170   set_default_double_param("outer_radius", 264.71);
0171   set_default_double_param("place_x", 0.);
0172   set_default_double_param("place_y", 0.);
0173   set_default_double_param("place_z", 0.);
0174   set_default_double_param("rot_x", 0.);
0175   set_default_double_param("rot_y", 0.);
0176   set_default_double_param("rot_z", 0.);
0177   set_default_double_param("tmin", -20.);
0178   set_default_double_param("tmax", 60.);
0179   set_default_double_param("dt", 100.);
0180   set_default_double_param("scinti_eta_coverage", 1.1);
0181   set_default_double_param("scinti_gap", 0.85);
0182   set_default_double_param("scinti_gap_neighbor", 0.1);
0183   set_default_double_param("scinti_inner_radius", 183.89);
0184   // some math issue in the code subtracts 0.1mm+ so the scintillator
0185   // does not end at 263.27 as per drawing but at 263.26
0186   // adding 0.125mm compensates for this (so 263.2825 gives the desired 263.27
0187   set_default_double_param("scinti_outer_radius", 263.2825);
0188   set_default_double_param("scinti_tile_thickness", 0.7);
0189   set_default_double_param("size_z", 304.91 * 2);
0190   set_default_double_param("steplimits", NAN);
0191   set_default_double_param("tilt_angle", -11.23);  // engineering drawing
0192                                                    // corresponds very closely to 4 crossinge (-11.7826 deg)
0193 
0194   set_default_int_param("field_check", 0);
0195   set_default_int_param("light_scint_model", 1);
0196   set_default_int_param("magnet_cutout_first_scinti", 8);  // tile start at 0, drawing tile starts at 1
0197   set_default_int_param("etabins", 24);
0198   set_default_int_param("saveg4hit", 1);
0199 
0200   // if ncross is set (and tilt_angle is NAN) tilt_angle is calculated
0201   // from number of crossings
0202   set_default_int_param("ncross", 0);
0203   set_default_int_param("n_towers", 64);
0204   set_default_int_param(PHG4HcalDefs::scipertwr, 5);
0205   set_default_int_param("n_scinti_tiles", 12);
0206 
0207   set_default_string_param("material", "Steel_1006");
0208   std::string defaultmapfilename;
0209   const char *Calibroot = getenv("CALIBRATIONROOT");
0210   if (Calibroot)
0211   {
0212     defaultmapfilename = Calibroot;
0213     defaultmapfilename += "/HCALOUT/tilemap/oHCALMaps092021.root";
0214   }
0215   set_default_string_param("MapFileName", defaultmapfilename);
0216   set_default_string_param("MapHistoName", "hCombinedMap");
0217 }