LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
LArVoxelReadout.h
Go to the documentation of this file.
1 
43 #ifndef LArG4_LArVoxelReadout_h
44 #define LArG4_LArVoxelReadout_h
45 
46 #include <algorithm> // std::max()
47 #include <stddef.h>
48 #include <vector>
49 
50 #include "Geant4/G4PVPlacement.hh"
51 #include "Geant4/G4VSensitiveDetector.hh"
52 
58 namespace detinfo {
59  class DetectorClocksData;
60  class DetectorPropertiesData;
61 }
62 
63 // Forward declarations
64 class G4HCofThisEvent;
65 class G4TouchableHistory;
66 class G4Step;
67 
68 namespace CLHEP {
69  class HepRandomEngine;
70 }
71 
72 namespace larg4 {
73 
75  struct TPCID_t {
76  unsigned short int Cryostat, TPC;
77  bool operator<(const TPCID_t& than) const
78  {
79  return (Cryostat < than.Cryostat) || ((Cryostat == than.Cryostat) && (TPC < than.TPC));
80  } // operator< ()
81  }; // TPCID_t
82 
96  template <class IDTYPE>
97  class G4PVPlacementWithID : public G4PVPlacement {
98  public:
99  typedef IDTYPE ID_t;
100 
101  ID_t ID;
102 
104  G4PVPlacementWithID(const G4Transform3D& Transform3D,
105  const G4String& pName,
106  G4LogicalVolume* pLogical,
107  G4VPhysicalVolume* pMother,
108  G4bool pMany,
109  G4int pCopyNo,
110  G4bool pSurfChk = false,
111  ID_t id = ID_t())
112  : G4PVPlacement(Transform3D, pName, pLogical, pMother, pMany, pCopyNo, pSurfChk), ID(id)
113  {}
114 
116  virtual ~G4PVPlacementWithID() {}
117  }; // G4PVPlacementWithID<>
118 
121 
159  class LArVoxelReadout : public G4VSensitiveDetector {
160  public:
162  typedef std::map<unsigned int, sim::SimChannel> ChannelMap_t;
163 
165  struct Setup_t {
166 
168  CLHEP::HepRandomEngine* propGen = nullptr;
169 
171  double offPlaneMargin = 0.0;
172  }; // struct Setup_t
173 
175  LArVoxelReadout(std::string const& name,
176  geo::GeometryCore const* geom,
177  geo::WireReadoutGeom const* wireReadoutGeom,
178  sim::LArG4Parameters const* lgp);
179 
181  LArVoxelReadout(std::string const& name,
182  geo::GeometryCore const* geom,
183  geo::WireReadoutGeom const* wireReadoutGeom,
184  sim::LArG4Parameters const* lgp,
185  unsigned int cryostat,
186  unsigned int tpc);
187 
189  void Setup(Setup_t const& setupData);
190 
192  void SetSingleTPC(unsigned int cryostat, unsigned int tpc);
193 
195  void SetDiscoverTPC();
196 
197  // Required for classes that inherit from G4VSensitiveDetector.
198  //
199  // Called at start and end of each event.
200  virtual void Initialize(G4HCofThisEvent*);
201  virtual void EndOfEvent(G4HCofThisEvent*);
202 
203  // Called to clear any accumulated information.
204  virtual void clear();
205 
206  // The key method of this class. It's called by Geant4 for each
207  // step within the read-out geometry. It accumulates the energy
208  // in the G4Step in the LArVoxelList.
209  virtual G4bool ProcessHits(G4Step*, G4TouchableHistory*);
210 
211  // Empty methods; they have to be defined, but they're rarely
212  // used in Geant4 applications.
213  virtual void DrawAll();
214  virtual void PrintAll();
215 
216  // Independent method; clears the vector of SimChannels as well as the
217  // channel number to SimChannel map. Has to be separate from the
218  // clear method above because that run is run for every G4 event, ie
219  // each MCTruth in the art::Event, while we want to only run this at
220  // the end of the G4 processing for each art::Event.
221  void ClearSimChannels();
222 
224  std::vector<sim::SimChannel> GetSimChannels() const;
225 
227  std::vector<sim::SimChannel> GetSimChannels(unsigned short cryo, unsigned short tpc) const;
228 
230  const ChannelMap_t& GetSimChannelMap() const;
232  ChannelMap_t& GetSimChannelMap();
234 
236  const ChannelMap_t& GetSimChannelMap(unsigned short cryo, unsigned short tpc) const;
238  ChannelMap_t& GetSimChannelMap(unsigned short cryo, unsigned short tpc);
240 
241  private:
242  // N.B. This code is not thread-safe, as it presupposes that there
243  // is a "current" clock-data object. Such a pattern should be
244  // avoided for the users of larg4.
246 
247  void SetClockData(detinfo::DetectorClocksData const* const clockData) noexcept
248  {
249  fClockData = clockData;
250  }
251 
252  void SetPropertiesData(detinfo::DetectorPropertiesData const* const detProp) noexcept
253  {
254  fDetProp = detProp;
255  }
256 
266  void SetOffPlaneChargeRecoveryMargin(double margin) { fOffPlaneMargin = std::max(margin, 0.0); }
267 
269  void SetRandomEngines(CLHEP::HepRandomEngine* pPropGen);
270 
309  geo::Point_t RecoverOffPlaneDeposit(geo::Point_t const& pos, geo::PlaneGeo const& plane) const;
310 
311  void DriftIonizationElectrons(detinfo::DetectorClocksData const& clockData,
312  G4ThreeVector stepMidPoint,
313  const double simTime,
314  int trackID,
315  unsigned short int cryostat,
316  unsigned short int tpc,
317  int origTrackID);
318 
319  bool Has(std::vector<unsigned short int> v, unsigned short int tpc) const
320  {
321  for (auto c : v)
322  if (c == tpc) return true;
323  return false;
324  }
325 
326  // Used in electron-cluster calculations
327  // External parameters for the electron-cluster calculation.
328  // obtained from LArG4Parameters, LArProperties, and DetectorProperties services
329  double fDriftVelocity[3];
336  std::vector<unsigned short int> fSkipWireSignalInTPCs;
338  double fOffPlaneMargin = 0.0;
339 
340  std::vector<std::vector<ChannelMap_t>> fChannelMaps;
344  unsigned int fTPC;
345  unsigned int fCstat;
346  bool bSingleTPC;
347 
348  CLHEP::HepRandomEngine* fPropGen = nullptr;
349 
350  detinfo::DetectorClocksData const* fClockData{nullptr};
351  detinfo::DetectorPropertiesData const* fDetProp{nullptr};
352 
353  //these are the things for doing the separated EDeps
354  void ProcessStep(G4Step*);
355 
356  G4ThreeVector fStepStart;
357  G4ThreeVector fStepEnd;
358  size_t fNSteps;
359  };
360 
361 }
362 
363 #endif // LArG4_LArVoxelReadout_h
void PrintAll(detinfo::DetectorPropertiesData const &detProp, std::string someText)
Definition: Utils.cxx:5370
Store parameters for running LArG4.
unsigned int fTPC
which TPC this LArVoxelReadout corresponds to
Collection of what it takes to set a LArVoxelReadout up.
A G4PVPlacement with an additional identificator.
void Initialize()
Definition: errprop.cc:100
Geant4 interface.
unsigned short int Cryostat
bool bSingleTPC
true if this readout is associated with a single TPC
ID_t ID
Physical Volume identificator.
geo::GeometryCore const * fGeo
std::map< unsigned int, sim::SimChannel > ChannelMap_t
Type of map channel -> sim::SimChannel.
std::vector< unsigned short int > fSkipWireSignalInTPCs
Definitions of geometry vector data types.
Interface for a class providing readout channel mapping to geometry.
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:67
G4PVPlacementWithID< TPCID_t > G4PVPlacementInTPC
A physical volume with a TPC ID.
General LArSoft Utilities.
bool Has(std::vector< unsigned short int > v, unsigned short int tpc) const
Description of the physical geometry of one entire detector.
Definition: GeometryCore.h:91
std::vector< std::vector< ChannelMap_t > > fChannelMaps
Maps of cryostat, tpc to channel data.
Simple structure holding a TPC and cryostat number.
virtual ~G4PVPlacementWithID()
Virtual destructor: does nothing more.
void SetClockData(detinfo::DetectorClocksData const *const clockData) noexcept
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
Contains all timing reference information for the detector.
unsigned int fCstat
and in which cryostat (if bSingleTPC is true)
void SetOffPlaneChargeRecoveryMargin(double margin)
Sets the margin for recovery of charge drifted off-plane.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
G4PVPlacementWithID(const G4Transform3D &Transform3D, const G4String &pName, G4LogicalVolume *pLogical, G4VPhysicalVolume *pMother, G4bool pMany, G4int pCopyNo, G4bool pSurfChk=false, ID_t id=ID_t())
Constructor.
sim::LArG4Parameters const * fLgp
Transports energy depositions from GEANT4 to TPC channels.
unsigned short int TPC
void SetPropertiesData(detinfo::DetectorPropertiesData const *const detProp) noexcept
bool operator<(const TPCID_t &than) const
geo::WireReadoutGeom const * fWireReadoutGeom
vec_iX clear()