Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "PHG4MvtxSubsystem.h"
0002 
0003 #include "PHG4MvtxDefs.h"
0004 #include "PHG4MvtxDetector.h"
0005 #include "PHG4MvtxDisplayAction.h"
0006 #include "PHG4MvtxSteppingAction.h"
0007 
0008 #include <mvtx/SegmentationAlpide.h>  // for Alpide constants
0009 
0010 #include <phparameter/PHParameters.h>
0011 #include <phparameter/PHParametersContainer.h>
0012 
0013 #include <g4detectors/PHG4DetectorGroupSubsystem.h>  // for PHG4DetectorGrou...
0014 
0015 #include <g4main/PHG4DisplayAction.h>  // for PHG4DisplayAction
0016 #include <g4main/PHG4HitContainer.h>
0017 #include <g4main/PHG4SteppingAction.h>  // for PHG4SteppingAction
0018 
0019 #include <phool/PHCompositeNode.h>
0020 #include <phool/PHIODataNode.h>    // for PHIODataNode
0021 #include <phool/PHNode.h>          // for PHNode
0022 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0023 #include <phool/PHObject.h>        // for PHObject
0024 #include <phool/getClass.h>
0025 #include <phool/phool.h>  // for PHWHERE
0026 
0027 #include <cstdlib>   // for getenv
0028 #include <iostream>  // for operator<<, basi...
0029 #include <set>       // for _Rb_tree_const_i...
0030 #include <sstream>
0031 #include <utility>  // for pair
0032 
0033 class PHG4Detector;
0034 
0035 //_______________________________________________________________________
0036 PHG4MvtxSubsystem::PHG4MvtxSubsystem(const std::string& name, const int _n_layers)
0037   : PHG4DetectorGroupSubsystem(name)
0038   , n_layers(_n_layers)
0039   , detector_type(name)
0040 {
0041   for (unsigned int iLyr = 0; iLyr < n_layers; ++iLyr)
0042   {
0043     AddDetId(iLyr);
0044   }
0045 
0046   InitializeParameters();
0047 
0048   // put the layers into name so we get unique names
0049   // for multiple layers
0050   Name(name);
0051   SuperDetector(name);
0052 }
0053 
0054 //_______________________________________________________________________
0055 PHG4MvtxSubsystem::~PHG4MvtxSubsystem()
0056 {
0057   delete m_DisplayAction;
0058 }
0059 
0060 //_______________________________________________________________________
0061 int PHG4MvtxSubsystem::InitRunSubsystem(PHCompositeNode* topNode)
0062 {
0063   if (Verbosity() > 0)
0064   {
0065     std::cout << "PHG4MvtxSubsystem::Init started" << std::endl;
0066   }
0067 
0068   PHNodeIterator iter(topNode);
0069   PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
0070 
0071   // create display settings before detector (detector adds its volumes to it)
0072   m_DisplayAction = new PHG4MvtxDisplayAction(Name());
0073   // create detector
0074   // These values are set from the calling macro using the setters defined in the .h file
0075   if (Verbosity())
0076   {
0077     std::cout << "    create Mvtx detector with " << n_layers << " layers." << std::endl;
0078   }
0079   m_Detector = new PHG4MvtxDetector(this, topNode, GetParamsContainer(), Name(), m_ApplyMisalignment, m_misalignmentFile);
0080   m_Detector->Verbosity(Verbosity());
0081   m_Detector->SuperDetector(SuperDetector());
0082   m_Detector->Detector(detector_type);
0083   m_Detector->OverlapCheck(CheckOverlap());
0084 
0085   if (Verbosity())
0086   {
0087     std::cout << "    ------ created detector " << Name() << std::endl;
0088     GetParamsContainer()->Print();
0089   }
0090   // loop all layer to find atleast one active layer
0091   int active = 0;
0092   int supportactive = 0;
0093   int blackhole = 0;
0094   for (std::set<int>::const_iterator parContainerIter = GetDetIds().first; parContainerIter != GetDetIds().second; ++parContainerIter)
0095   {
0096     if (active || GetParamsContainer()->GetParameters(*parContainerIter)->get_int_param("active"))
0097     {
0098       active = 1;
0099     }
0100     if (supportactive || GetParamsContainer()->GetParameters(*parContainerIter)->get_int_param("supportactive"))
0101     {
0102       supportactive = 1;
0103     }
0104     if (blackhole || GetParamsContainer()->GetParameters(*parContainerIter)->get_int_param("blackhole"))
0105     {
0106       blackhole = 1;
0107     }
0108   }
0109   if (active)
0110   {
0111     std::set<std::string> nodes;
0112     PHNodeIterator dstIter(dstNode);
0113     PHCompositeNode* detNode = dstNode;
0114     if (SuperDetector() != "NONE" && !SuperDetector().empty())
0115     {
0116       detNode = dynamic_cast<PHCompositeNode*>(dstIter.findFirst("PHCompositeNode", SuperDetector()));
0117       if (!detNode)
0118       {
0119         detNode = new PHCompositeNode(SuperDetector());
0120         dstNode->addNode(detNode);
0121       }
0122     }
0123 
0124     std::string detector_suffix = SuperDetector();
0125     if (detector_suffix == "NONE" || detector_suffix.empty())
0126     {
0127       detector_suffix = Name();
0128     }
0129 
0130     m_HitNodeName = "G4HIT_" + detector_suffix;
0131     nodes.insert(m_HitNodeName);
0132     m_SupportNodeName = "G4HIT_SUPPORT_" + detector_suffix;
0133     if (supportactive)
0134     {
0135       nodes.insert(m_SupportNodeName);
0136     }
0137     for (const auto& nodename : nodes)
0138     {
0139       PHG4HitContainer* g4_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename);
0140       if (!g4_hits)
0141       {
0142         g4_hits = new PHG4HitContainer(nodename);
0143         if (Verbosity())
0144         {
0145           std::cout << PHWHERE << "creating hits node " << nodename << std::endl;
0146         }
0147         detNode->addNode(new PHIODataNode<PHObject>(g4_hits, nodename, "PHObject"));
0148       }
0149     }
0150 
0151     // create stepping action
0152     m_SteppingAction = new PHG4MvtxSteppingAction(m_Detector, GetParamsContainer());
0153     m_SteppingAction->SetHitNodeName("G4HIT", m_HitNodeName);
0154     m_SteppingAction->SetHitNodeName("G4HIT_SUPPORT", m_SupportNodeName);
0155     m_SteppingAction->Verbosity(Verbosity());
0156   }
0157   else
0158   {
0159     if (blackhole)
0160     {
0161       m_SteppingAction = new PHG4MvtxSteppingAction(m_Detector, GetParamsContainer());
0162     }
0163   }
0164   return 0;
0165 }
0166 
0167 //_______________________________________________________________________
0168 int PHG4MvtxSubsystem::process_event(PHCompositeNode* topNode)
0169 {
0170   // pass top node to stepping action so that it gets
0171   // relevant nodes needed internally
0172   if (m_SteppingAction)
0173   {
0174     m_SteppingAction->SetInterfacePointers(topNode);
0175   }
0176   return 0;
0177 }
0178 
0179 //_______________________________________________________________________
0180 PHG4Detector* PHG4MvtxSubsystem::GetDetector() const
0181 {
0182   return m_Detector;
0183 }
0184 
0185 //_______________________________________________________________________
0186 void PHG4MvtxSubsystem::SetDefaultParameters()
0187 {
0188   for (std::set<int>::const_iterator lyr_it = GetDetIds().first; lyr_it != GetDetIds().second; ++lyr_it)
0189   {
0190     const int& ilyr = *lyr_it;
0191     const double rLr = PHG4MvtxDefs::mvtxdat[ilyr][PHG4MvtxDefs::kRmd];
0192     double turbo = radii2Turbo(PHG4MvtxDefs::mvtxdat[ilyr][PHG4MvtxDefs::kRmn], rLr, PHG4MvtxDefs::mvtxdat[ilyr][PHG4MvtxDefs::kRmx], SegmentationAlpide::SensorSizeRows * 10.);
0193 
0194     set_default_int_param(ilyr, "active", 1);  // non-automatic initialization in PHG4DetectorGroupSubsystem
0195     set_default_int_param(ilyr, "layer", ilyr);
0196     set_default_int_param(ilyr, "N_staves", PHG4MvtxDefs::mvtxdat[ilyr][PHG4MvtxDefs::kNStave]);
0197 
0198     set_default_double_param(ilyr, "layer_nominal_radius", rLr);
0199     set_default_double_param(ilyr, "phitilt", turbo);
0200     set_default_double_param(ilyr, "phi0", PHG4MvtxDefs::mvtxdat[ilyr][PHG4MvtxDefs::kPhi0]);
0201     set_default_string_param(ilyr, "material", "G4_AIR");  // default - almost nothing
0202   }
0203 
0204   set_default_string_param(PHG4MvtxDefs::GLOBAL, "stave_geometry_file", "ITS.gdml");  // default - almost nothing
0205   char* calibrationsroot = getenv("CALIBRATIONROOT");
0206   std::string end_wheels_sideS = "ITS_ibEndWheelSideA.gdml";
0207   std::string end_wheels_sideN = "ITS_ibEndWheelSideC.gdml";
0208   if (calibrationsroot != nullptr)
0209   {
0210     end_wheels_sideS = std::string(calibrationsroot) + std::string("/Tracking/geometry/") + end_wheels_sideS;
0211     end_wheels_sideN = std::string(calibrationsroot) + std::string("/Tracking/geometry/") + end_wheels_sideN;
0212   }
0213 }