LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DetectorBase.hh
Go to the documentation of this file.
1 // This file is the header for the @DetectorBase@ class.
2 
3 // h2. Introduction
4 
5 // @DetectorBase@ enforces an interface for the construction and handling of Geant4 detectors.
6 
7 // All _ArtG4_ detector objects MUST inherit from this @DetectorBase@ class.
8 
9 // For your detector to work, you must override the following methods:
10 
11 // * @doBuildLVs@ - This private method, which takes no arguments, constructs the detector logical
12 // volume and returns a pointer to it. The system takes over ownership of this pointer.
13 
14 // * @doPlaceToPVs@ - This private method takes the mother logical volumes as an argument and
15 // performs the functions necessary to place this detector within it. This method then returns a
16 // pointer to the resulting physical volume. The system takes over ownership of this pointer.
17 
18 // There are also some optional methods you can override.:
19 
20 // * @doCallArtProduces@ - This private method is optional, but is necessary if your detector
21 // produces hits. Its argument is a producer, for which you should call produces<T>("name"), where T
22 // is the type you will add to the event (typically a hit collection) and name is an identifier to
23 // distinguish your hits from those of any other detector.
24 
25 // * @doFillEventWithArtHits@ - This private method is optional, but is necessary if your detector
26 // produces hits that will end up in the Art event. The argument is the GEANT hit collection for the
27 // event in question. To add a collection of Art hits to the Art event, you must convert the GEANT
28 // hits into Art hits, and then put your collection into the Art event.
29 
30 // See below for information about each method. Note that many of them you never
31 // call yourself.
32 
33 // h2. Code
34 
35 // Header Guard
36 
37 #ifndef artg4tk_Core_DetectorBase_hh
38 #define artg4tk_Core_DetectorBase_hh
39 
40 // STL includes
41 #include <vector>
42 
43 // Art includes
45 #include "fhiclcpp/ParameterSet.h"
46 
49 
50 // Forward referencing
51 class G4LogicalVolume;
52 class G4VPhysicalVolume;
53 class G4HCofThisEvent;
54 
55 namespace art {
56  class ProducesCollector;
57 }
58 
59 // h3. Declare the @DetectorBase@ class
60 
61 // All offical Art G4 specific code goes into the @artg4tk@ namespace
62 namespace artg4tk {
63 
64  class DetectorBase {
65 
66  // h3. Public members
67 
68  public:
69  // Constructor. Your derived class must call this
70  // constructor. This base class constructor takes,
71  // * The parameter set for the corresponding Art producer module
72  // * The name of this detector
73  // * The category of this detector ("world" if this is the world)
74  // * The category of the mother volume that this detector is placed within ("" if world)
76  std::string myName,
77  std::string category,
78  std::string motherCategory)
79  : _myParams(fhicl::ParameterSet(p))
80  , _myName(myName)
81  , _category(category)
82  , _motherCategory(motherCategory)
83  , _myLVs(0)
84  , _myPVs(0)
85  {
86  // Register ourselves
88  detectorHolder->registerDetector(this);
89  }
90 
91  // Destructor
92  virtual ~DetectorBase() = default;
93 
94  // Intialize after the particle list is set up
95  virtual void initialize(){};
96 
97  // Build and store the logical volume (calls your @doBuild@ method). You
98  // do not need to call this method yourself.
99  void
101  {
102  _myLVs = doBuildLVs();
103  }
104 
105  // Place the detector in the mother volume and store and return the
106  // physical volume (calls your @doPlaceToPVs@ method). You do not need to
107  // call this method yourself.
108  std::vector<G4VPhysicalVolume*>
109  placeToPVs(std::vector<G4LogicalVolume*> motherLVs)
110  {
111  _myPVs = doPlaceToPVs(motherLVs);
112  return _myPVs;
113  }
114 
115  // Tell Art what this detector will put into the event. You do not need to
116  // call this yourself.
117  void
119  {
120  doCallArtProduces(produces_coll);
121  }
122 
123  // Put anything you need to into the event. You do not need to call this
124  // method yourself.
125  void
127  {
128  doFillEventWithArtHits(hc);
129  }
130 
131  // h3. Accessors
132 
133  // Return this detector's Geant Physical Volume
134  std::vector<G4VPhysicalVolume*>
135  pvs() const
136  {
137  return _myPVs;
138  }
139 
140  // Return this detector's Geant Logical Volume
141  std::vector<G4LogicalVolume*>
142  lvs() const
143  {
144  return _myLVs;
145  }
146 
147  // Return the name of this detector
148  std::string const&
149  myName() const
150  {
151  return _myName;
152  }
153 
154  // Return the category of this detector
155  std::string const&
156  category() const
157  {
158  return _category;
159  }
160 
161  // Returnh the mother category for this detector
162  std::string const&
164  {
165  return _motherCategory;
166  }
167 
168  // Return the parameter set for this detector
169  fhicl::ParameterSet const&
170  parameters() const
171  {
172  return _myParams;
173  }
174 
175  private:
176  // h3. Private abstract methods you must override (see list above)
177 
178  // Build the detector logical volume and return it
179  virtual std::vector<G4LogicalVolume*> doBuildLVs() = 0;
180 
181  // Place the detector within the passed in mother logical volume and return
182  // the resulting physical volume
183  virtual std::vector<G4VPhysicalVolume*> doPlaceToPVs(
184  std::vector<G4LogicalVolume*> motherLV) = 0;
185 
186  // h3. Optional private methods you can override (see list above)
187 
188  // Tell Art what you will put into the event.
189  virtual void
191  {}
192 
193  // Convert G4 hits into Art hits. Put them in the event (which you can get
194  // from the DetectorHolder service).
195  virtual void
197  {}
198 
199  // h3. Private data
200 
201  // The parameters from the corresponding producer module
203 
204  // The detector name
205  std::string _myName;
206 
207  // The detector category
208  std::string _category;
209 
210  // The detector mother category
211  std::string _motherCategory;
212 
213  // The detector's Geant logical volumes
214  std::vector<G4LogicalVolume*> _myLVs;
215 
216  // The detectors's Geant physical volumes
217  std::vector<G4VPhysicalVolume*> _myPVs;
218  };
219 }
220 
221 #endif /* artg4tk_Core_DetectorBase_hh */
virtual void initialize()
Definition: DetectorBase.hh:95
fhicl::ParameterSet const & parameters() const
virtual void doFillEventWithArtHits(G4HCofThisEvent *)
std::string _motherCategory
std::vector< G4VPhysicalVolume * > _myPVs
std::string const & myName() const
fhicl::ParameterSet _myParams
std::vector< G4VPhysicalVolume * > placeToPVs(std::vector< G4LogicalVolume * > motherLVs)
parameter set interface
std::vector< G4VPhysicalVolume * > pvs() const
virtual void doCallArtProduces(art::ProducesCollector &produces_coll)
std::string const & motherCategory() const
std::string const & category() const
void fillEventWithArtHits(G4HCofThisEvent *hc)
DetectorBase(fhicl::ParameterSet const &p, std::string myName, std::string category, std::string motherCategory)
Definition: DetectorBase.hh:75
Definition: MVAAlg.h:12
std::vector< G4LogicalVolume * > _myLVs
void callArtProduces(art::ProducesCollector &produces_coll)
std::vector< G4LogicalVolume * > lvs() const