LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
util.hh
Go to the documentation of this file.
1 // Utility functions
2 
3 #ifndef artg4tk_util_util_hh
4 #define artg4tk_util_util_hh
5 
6 #include <functional>
7 #include <string>
8 #include <vector>
9 
10 #include "Geant4/G4SDManager.hh"
11 
12 class G4LogicalVolume;
13 class G4VisAttributes;
14 
15 namespace artg4tk {
16 
17  // This function either returns or creates an SD as necessary, based on
18  // the string passed in. If the G4SDManager hasn't created an SD based on
19  // that string before, it will now.
20  // class T must be a class that inherits from G4VSensitive detector
21  //(that's what the 2nd line enforces). If it doesn't, then the templated
22  // class will not generate a method for you.
23 
24  // To get a new RingSD, put something *like* this line in your service:
25  // RingSD* mysd = getSensitiveDetector<RingSD>("myRings");
26 
27  template <typename T>
30  {
31  T* SDptr = 0;
32  G4SDManager* fSDM = G4SDManager::GetSDMpointer();
33  if ((SDptr = static_cast<T*>(fSDM->FindSensitiveDetector(name))) == NULL)
34  SDptr = new T(name);
35  return SDptr;
36  }
37 
38  // Set visual attributes
39  void setVisAtts(G4LogicalVolume* lv, bool display, const std::vector<double>& rgba);
40  void setVisAtts(G4LogicalVolume* lv,
41  bool display,
42  const std::vector<double>& rgba,
43  std::function<void(G4VisAttributes*)> func);
44 
45  // Put a number in a name
46  std::string addNumberToName(const std::string& name, int number);
47 
48  // Find a file base path
49  // Look for environment variable. If it is not set, then look for $MRB_BUILDDIR and add package
50  // name
51  std::string basePath(const std::string& envVar, const std::string& pkgName);
52 }
53 
54 #endif /* artg4tk_util_util_hh */
std::string addNumberToName(const std::string &name, int number)
Definition: util.cc:51
double value
Definition: spectrum.C:18
std::string basePath(const std::string &envVar, const std::string &pkgName)
Definition: util.cc:62
void setVisAtts(G4LogicalVolume *lv, bool display, const std::vector< double > &rgba)
Definition: util.cc:44
std::enable_if< std::is_base_of< G4VSensitiveDetector, T >::value, T * >::type getSensitiveDetector(G4String name)
Definition: util.hh:29