Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 
0002 #include "PHG4ProcessMap.h"
0003 #include "PHG4MCProcessDefs.h"
0004 
0005 #include <Geant4/G4VProcess.hh>
0006 
0007 #include <iomanip>
0008 #include <iostream>
0009 #include <string>
0010 
0011 //
0012 // private methods
0013 //
0014 
0015 //_____________________________________________________________________________
0016 bool PHG4ProcessMap::IsDefined(int subType)
0017 {
0018   return !(fMap.find(subType) == fMap.end());
0019 }
0020 
0021 //
0022 // public methods
0023 //
0024 
0025 //_____________________________________________________________________________
0026 bool PHG4ProcessMap::Add(int subType, PHG4MCProcess mcProcess)
0027 {
0028   if (!IsDefined(subType))
0029   {
0030     // insert into map
0031     // only in case it is not yet here
0032     fMap[subType] = mcProcess;
0033     return true;
0034   }
0035   return false;
0036 }
0037 
0038 //_____________________________________________________________________________
0039 void PHG4ProcessMap::PrintAll() const
0040 {
0041   if (fMap.empty())
0042   {
0043     return;
0044   }
0045 
0046   std::cout << "Dump of PHG4ProcessMap - " << fMap.size()
0047             << " entries:" << std::endl;
0048   int counter = 0;
0049   for (auto [subType, codes] : fMap)
0050   {
0051     // TO DO: get process sub-type name
0052     std::cout << "Map element " << std::setw(3) << counter++ << "   "
0053               << subType << "   " << PHG4MCProcessName[codes] << std::endl;
0054   }
0055 }
0056 
0057 //_____________________________________________________________________________
0058 void PHG4ProcessMap::Clear()
0059 {
0060   if (fMap.size())
0061   {
0062     fMap.clear();
0063   }
0064 }
0065 
0066 //_____________________________________________________________________________
0067 PHG4MCProcess
0068 PHG4ProcessMap::GetMCProcess(const G4VProcess* process) const
0069 {
0070   if (!process)
0071   {
0072     return kPNoProcess;
0073   }
0074 
0075   auto i = fMap.find(process->GetProcessSubType());
0076   if (i == fMap.end())
0077   {
0078     std::string text = "Unknown process code for ";
0079     text += process->GetProcessName();
0080     std::cerr << "PHG4ProcessMap::GetCodes " << text.c_str() << std::endl;
0081     return kPNoProcess;
0082   }
0083   else
0084   {
0085     return (*i).second;
0086   }
0087 }
0088 
0089 //_____________________________________________________________________________
0090 std::string_view PHG4ProcessMap::GetMCProcessName(const G4VProcess* process) const
0091 {
0092   if (!process)
0093   {
0094     return PHG4MCProcessName[kPNoProcess];
0095   }
0096 
0097   return PHG4MCProcessName[GetMCProcess(process)];
0098 }