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