File indexing completed on 2025-12-17 09:22:08
0001 #include "PHG4EICMvtxSubsystem.h"
0002
0003 #include "PHG4EICMvtxDetector.h"
0004 #include "PHG4EICMvtxSteppingAction.h"
0005 #include "PHG4MvtxDefs.h"
0006 #include "PHG4MvtxDisplayAction.h"
0007
0008 #include <phparameter/PHParameters.h>
0009 #include <phparameter/PHParametersContainer.h>
0010
0011 #include <g4detectors/PHG4DetectorGroupSubsystem.h> // for PHG4DetectorGrou...
0012
0013 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
0014 #include <g4main/PHG4HitContainer.h>
0015 #include <g4main/PHG4SteppingAction.h> // for PHG4SteppingAction
0016
0017 #include <phool/PHCompositeNode.h>
0018 #include <phool/PHIODataNode.h> // for PHIODataNode
0019 #include <phool/PHNode.h> // for PHNode
0020 #include <phool/PHNodeIterator.h> // for PHNodeIterator
0021 #include <phool/PHObject.h> // for PHObject
0022 #include <phool/getClass.h>
0023 #include <phool/phool.h> // for PHWHERE
0024
0025 #include <mvtx/SegmentationAlpide.h> // for Alpide constants
0026
0027 #include <iostream> // for operator<<, basi...
0028 #include <set> // for _Rb_tree_const_i...
0029 #include <sstream>
0030 #include <utility> // for pair
0031
0032 class PHG4Detector;
0033
0034
0035 PHG4EICMvtxSubsystem::PHG4EICMvtxSubsystem(const std::string& name, const int _n_layers)
0036 : PHG4DetectorGroupSubsystem(name)
0037 , n_layers(_n_layers)
0038 , detector_type(name)
0039 {
0040 for (unsigned int iLyr = 0; iLyr < n_layers; ++iLyr)
0041 {
0042 AddDetId(iLyr);
0043 }
0044
0045 InitializeParameters();
0046
0047
0048
0049 Name(name);
0050 SuperDetector(name);
0051 }
0052
0053
0054 PHG4EICMvtxSubsystem::~PHG4EICMvtxSubsystem()
0055 {
0056 delete m_DisplayAction;
0057 }
0058
0059
0060 int PHG4EICMvtxSubsystem::InitRunSubsystem(PHCompositeNode* topNode)
0061 {
0062 if (Verbosity() > 0)
0063 {
0064 std::cout << "PHG4EICMvtxSubsystem::Init started" << std::endl;
0065 }
0066
0067 PHNodeIterator iter(topNode);
0068 PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
0069
0070
0071 m_DisplayAction = new PHG4MvtxDisplayAction(Name());
0072
0073
0074 if (Verbosity())
0075 {
0076 std::cout << " create Mvtx detector with " << n_layers << " layers." << std::endl;
0077 }
0078 m_Detector = new PHG4EICMvtxDetector(this, topNode, GetParamsContainer(), Name());
0079 m_Detector->Verbosity(Verbosity());
0080 m_Detector->SuperDetector(SuperDetector());
0081 m_Detector->Detector(detector_type);
0082 m_Detector->OverlapCheck(CheckOverlap());
0083 if (Verbosity())
0084 {
0085 std::cout << " ------ created detector " << Name() << std::endl;
0086 GetParamsContainer()->Print();
0087 }
0088
0089 int active = 0;
0090
0091 int absorberactive = 0;
0092 int blackhole = 0;
0093 for (std::set<int>::const_iterator parContainerIter = GetDetIds().first; parContainerIter != GetDetIds().second; ++parContainerIter)
0094 {
0095 if (active || GetParamsContainer()->GetParameters(*parContainerIter)->get_int_param("active"))
0096 {
0097 active = 1;
0098 }
0099 if (absorberactive || GetParamsContainer()->GetParameters(*parContainerIter)->get_int_param("absorberactive"))
0100 {
0101 absorberactive = 1;
0102 }
0103 if (blackhole || GetParamsContainer()->GetParameters(*parContainerIter)->get_int_param("blackhole"))
0104 {
0105 blackhole = 1;
0106 }
0107 }
0108 if (active)
0109 {
0110 PHNodeIterator dstIter(dstNode);
0111 PHCompositeNode* detNode = dynamic_cast<PHCompositeNode*>(dstIter.findFirst("PHCompositeNode", SuperDetector()));
0112 if (!detNode)
0113 {
0114 detNode = new PHCompositeNode(SuperDetector());
0115 dstNode->addNode(detNode);
0116 }
0117 std::ostringstream nodename;
0118 if (SuperDetector() != "NONE")
0119 {
0120 nodename << "G4HIT_" << SuperDetector();
0121 }
0122 else
0123 {
0124 nodename << "G4HIT_" << detector_type;
0125 }
0126
0127 PHG4HitContainer* block_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename.str());
0128 if (!block_hits)
0129 {
0130 detNode->addNode(new PHIODataNode<PHObject>(block_hits = new PHG4HitContainer(nodename.str()), nodename.str(), "PHObject"));
0131 }
0132 if (Verbosity())
0133 {
0134 std::cout << PHWHERE << "creating hits node " << nodename.str() << std::endl;
0135 }
0136
0137 if (absorberactive)
0138 {
0139 nodename.str("");
0140 if (SuperDetector() != "NONE")
0141 {
0142 nodename << "G4HIT_ABSORBER_" << SuperDetector();
0143 }
0144 else
0145 {
0146 nodename << "G4HIT_ABSORBER_" << detector_type;
0147 }
0148 block_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename.str());
0149 if (!block_hits)
0150 {
0151 detNode->addNode(new PHIODataNode<PHObject>(block_hits = new PHG4HitContainer(nodename.str()), nodename.str(), "PHObject"));
0152 }
0153 if (Verbosity())
0154 {
0155 std::cout << PHWHERE << "creating hits node " << nodename.str() << std::endl;
0156 }
0157 }
0158
0159
0160 steppingAction_ = new PHG4EICMvtxSteppingAction(m_Detector);
0161 steppingAction_->Verbosity(Verbosity());
0162 }
0163 else
0164 {
0165 if (blackhole)
0166 {
0167 steppingAction_ = new PHG4EICMvtxSteppingAction(m_Detector);
0168 }
0169 }
0170 return 0;
0171 }
0172
0173
0174 int PHG4EICMvtxSubsystem::process_event(PHCompositeNode* topNode)
0175 {
0176
0177
0178 if (steppingAction_)
0179 {
0180 steppingAction_->SetInterfacePointers(topNode);
0181 }
0182 return 0;
0183 }
0184
0185
0186 PHG4Detector* PHG4EICMvtxSubsystem::GetDetector() const
0187 {
0188 return m_Detector;
0189 }
0190
0191
0192 PHG4SteppingAction* PHG4EICMvtxSubsystem::GetSteppingAction() const
0193 {
0194 return steppingAction_;
0195 }
0196
0197
0198 void PHG4EICMvtxSubsystem::SetDefaultParameters()
0199 {
0200 for (std::set<int>::const_iterator lyr_it = GetDetIds().first; lyr_it != GetDetIds().second; ++lyr_it)
0201 {
0202 const int& ilyr = *lyr_it;
0203 const double rLr = PHG4MvtxDefs::mvtxdat[ilyr][PHG4MvtxDefs::kRmd];
0204 double turbo = radii2Turbo(PHG4MvtxDefs::mvtxdat[ilyr][PHG4MvtxDefs::kRmn], rLr, PHG4MvtxDefs::mvtxdat[ilyr][PHG4MvtxDefs::kRmx], SegmentationAlpide::SensorSizeRows * 10.);
0205
0206 set_default_int_param(ilyr, "active", 1);
0207 set_default_int_param(ilyr, "layer", ilyr);
0208 set_default_int_param(ilyr, "N_staves", PHG4MvtxDefs::mvtxdat[ilyr][PHG4MvtxDefs::kNStave]);
0209
0210 set_default_double_param(ilyr, "layer_nominal_radius", rLr);
0211 set_default_double_param(ilyr, "phitilt", turbo);
0212 set_default_double_param(ilyr, "phi0", PHG4MvtxDefs::mvtxdat[ilyr][PHG4MvtxDefs::kPhi0]);
0213 set_default_string_param(ilyr, "material", "G4_AIR");
0214 }
0215
0216 set_default_string_param(PHG4MvtxDefs::GLOBAL, "stave_geometry_file", "ITS.gdml");
0217
0218
0219
0220
0221
0222 }