Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:13

0001 /*!
0002  * \file PHG4MicromegasSubsystem.cc
0003  * \author Hugo Pereira Da Costa <hugo.pereira-da-costa@cea.fr>
0004  */
0005 
0006 #include "PHG4MicromegasSubsystem.h"
0007 
0008 #include "PHG4MicromegasDetector.h"
0009 #include "PHG4MicromegasDisplayAction.h"
0010 #include "PHG4MicromegasSteppingAction.h"
0011 
0012 #include <phparameter/PHParameters.h>
0013 
0014 #include <g4main/PHG4HitContainer.h>
0015 #include <g4main/PHG4SteppingAction.h>
0016 
0017 #include <phool/PHCompositeNode.h>
0018 #include <phool/PHIODataNode.h>
0019 #include <phool/PHNode.h>
0020 #include <phool/PHNodeIterator.h>
0021 #include <phool/PHObject.h>
0022 #include <phool/getClass.h>
0023 
0024 //_______________________________________________________________________
0025 PHG4MicromegasSubsystem::PHG4MicromegasSubsystem(const std::string &name, int layerno)
0026   : PHG4DetectorSubsystem(name, layerno)
0027 {
0028   // call base class method which will set up parameter infrastructure
0029   // and call our SetDefaultParameters() method
0030   InitializeParameters();
0031 
0032   SuperDetector(name);
0033 }
0034 
0035 //_______________________________________________________________________
0036 PHG4MicromegasSubsystem::~PHG4MicromegasSubsystem()
0037 {
0038   delete m_DisplayAction;
0039 }
0040 
0041 //_______________________________________________________________________
0042 int PHG4MicromegasSubsystem::InitRunSubsystem(PHCompositeNode *topNode)
0043 {
0044   PHNodeIterator iter(topNode);
0045   auto dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0046   PHNodeIterator dstIter(dstNode);
0047   if (GetParams()->get_int_param("active"))
0048   {
0049     std::set<std::string> nodes;
0050     auto detNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", SuperDetector()));
0051     if (!detNode)
0052     {
0053       detNode = new PHCompositeNode(SuperDetector());
0054       dstNode->addNode(detNode);
0055     }
0056 
0057     // create hit output nodes
0058     std::string detector_suffix = SuperDetector();
0059     if (detector_suffix == "NONE" || detector_suffix.empty())
0060     {
0061       detector_suffix = Name();
0062     }
0063 
0064     m_HitNodeName = "G4HIT_" + detector_suffix;
0065     nodes.insert(m_HitNodeName);
0066     m_SupportNodeName = "G4HIT_SUPPORT_" + detector_suffix;
0067     if (GetParams()->get_int_param("supportactive"))
0068     {
0069       nodes.insert(m_SupportNodeName);
0070     }
0071 
0072     for (const auto &g4hitnodename : nodes)
0073     {
0074       auto g4_hits = findNode::getClass<PHG4HitContainer>(detNode, g4hitnodename);
0075       if (!g4_hits)
0076       {
0077         g4_hits = new PHG4HitContainer(g4hitnodename);
0078         detNode->addNode(new PHIODataNode<PHObject>(g4_hits, g4hitnodename, "PHObject"));
0079       }
0080     }
0081   }
0082 
0083   // create detector
0084   m_DisplayAction = new PHG4MicromegasDisplayAction(Name());
0085   m_Detector = new PHG4MicromegasDetector(this, topNode, GetParams(), Name());
0086   m_Detector->set_first_layer(GetLayer());
0087 
0088   m_Detector->Verbosity(Verbosity());
0089   m_Detector->SuperDetector(SuperDetector());
0090   m_Detector->OverlapCheck(CheckOverlap());
0091 
0092   // create stepping action if detector is active
0093   if (GetParams()->get_int_param("active"))
0094   {
0095     m_SteppingAction = new PHG4MicromegasSteppingAction(m_Detector, GetParams());
0096     m_SteppingAction->SetHitNodeName("G4HIT", m_HitNodeName);
0097     m_SteppingAction->SetHitNodeName("G4HIT_SUPPORT", m_SupportNodeName);
0098   }
0099   return 0;
0100 }
0101 
0102 //_______________________________________________________________________
0103 int PHG4MicromegasSubsystem::process_event(PHCompositeNode *topNode)
0104 {
0105   // pass top node to stepping action so that it gets
0106   // relevant nodes needed internally
0107   if (m_SteppingAction)
0108   {
0109     m_SteppingAction->SetInterfacePointers(topNode);
0110   }
0111   return 0;
0112 }
0113 
0114 //_______________________________________________________________________
0115 void PHG4MicromegasSubsystem::Print(const std::string &what) const
0116 {
0117   if (m_Detector)
0118   {
0119     m_Detector->Print(what);
0120   }
0121 }
0122 
0123 //_______________________________________________________________________
0124 PHG4Detector *PHG4MicromegasSubsystem::GetDetector() const
0125 {
0126   return m_Detector;
0127 }
0128 
0129 //_______________________________________________________________________
0130 void PHG4MicromegasSubsystem::SetDefaultParameters()
0131 {
0132   set_default_int_param("apply_survey", 1);
0133 }
0134