LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArVoxelReadout.h
Go to the documentation of this file.
1 
52 #ifndef LArG4_LArVoxelReadout_h
53 #define LArG4_LArVoxelReadout_h
54 
55 #include <algorithm> // std::max()
56 #include <stddef.h>
57 #include <vector>
58 
59 #include "Geant4/G4PVPlacement.hh"
60 #include "Geant4/G4VSensitiveDetector.hh"
61 
67 namespace detinfo {
68  class DetectorClocksData;
69  class DetectorPropertiesData;
70 }
71 
72 // Forward declarations
73 class G4HCofThisEvent;
74 class G4TouchableHistory;
75 class G4Step;
76 
77 namespace CLHEP {
78  class HepRandomEngine;
79 }
80 
81 namespace larg4 {
82 
84  struct TPCID_t {
85  unsigned short int Cryostat, TPC;
86  bool operator<(const TPCID_t& than) const
87  {
88  return (Cryostat < than.Cryostat) || ((Cryostat == than.Cryostat) && (TPC < than.TPC));
89  } // operator< ()
90  }; // TPCID_t
91 
105  template <class IDTYPE>
106  class G4PVPlacementWithID : public G4PVPlacement {
107  public:
108  typedef IDTYPE ID_t;
109 
110  ID_t ID;
111 
113  G4PVPlacementWithID(const G4Transform3D& Transform3D,
114  const G4String& pName,
115  G4LogicalVolume* pLogical,
116  G4VPhysicalVolume* pMother,
117  G4bool pMany,
118  G4int pCopyNo,
119  G4bool pSurfChk = false,
120  ID_t id = ID_t())
121  : G4PVPlacement(Transform3D, pName, pLogical, pMother, pMany, pCopyNo, pSurfChk), ID(id)
122  {}
123 
125  virtual ~G4PVPlacementWithID() {}
126  }; // G4PVPlacementWithID<>
127 
130 
169  class LArVoxelReadout : public G4VSensitiveDetector {
170  public:
172  typedef std::map<unsigned int, sim::SimChannel> ChannelMap_t;
173 
175  struct Setup_t {
176 
178  CLHEP::HepRandomEngine* propGen = nullptr;
179 
181  double offPlaneMargin = 0.0;
182  }; // struct Setup_t
183 
185  LArVoxelReadout(std::string const& name);
186 
188  LArVoxelReadout(std::string const& name, unsigned int cryostat, unsigned int tpc);
189 
191  void Setup(Setup_t const& setupData);
192 
194  void SetSingleTPC(unsigned int cryostat, unsigned int tpc);
195 
197  void SetDiscoverTPC();
198 
199  // Required for classes that inherit from G4VSensitiveDetector.
200  //
201  // Called at start and end of each event.
202  virtual void Initialize(G4HCofThisEvent*);
203  virtual void EndOfEvent(G4HCofThisEvent*);
204 
205  // Called to clear any accumulated information.
206  virtual void clear();
207 
208  // The key method of this class. It's called by Geant4 for each
209  // step within the read-out geometry. It accumulates the energy
210  // in the G4Step in the LArVoxelList.
211  virtual G4bool ProcessHits(G4Step*, G4TouchableHistory*);
212 
213  // Empty methods; they have to be defined, but they're rarely
214  // used in Geant4 applications.
215  virtual void DrawAll();
216  virtual void PrintAll();
217 
218  // Independent method; clears the vector of SimChannels as well as the
219  // channel number to SimChannel map. Has to be separate from the
220  // clear method above because that run is run for every G4 event, ie
221  // each MCTruth in the art::Event, while we want to only run this at
222  // the end of the G4 processing for each art::Event.
223  void ClearSimChannels();
224 
226  std::vector<sim::SimChannel> GetSimChannels() const;
227 
229  std::vector<sim::SimChannel> GetSimChannels(unsigned short cryo, unsigned short tpc) const;
230 
232  const ChannelMap_t& GetSimChannelMap() const;
234  ChannelMap_t& GetSimChannelMap();
236 
238  const ChannelMap_t& GetSimChannelMap(unsigned short cryo, unsigned short tpc) const;
240  ChannelMap_t& GetSimChannelMap(unsigned short cryo, unsigned short tpc);
242 
243  private:
244  // N.B. This code is not thread-safe, as it presupposes that there
245  // is a "current" clock-data object. Such a pattern should be
246  // avoided for the users of larg4.
248 
249  void SetClockData(detinfo::DetectorClocksData const* const clockData) noexcept
250  {
251  fClockData = clockData;
252  }
253 
254  void SetPropertiesData(detinfo::DetectorPropertiesData const* const detProp) noexcept
255  {
256  fDetProp = detProp;
257  }
258 
268  void SetOffPlaneChargeRecoveryMargin(double margin) { fOffPlaneMargin = std::max(margin, 0.0); }
269 
271  void SetRandomEngines(CLHEP::HepRandomEngine* pPropGen);
272 
311  geo::Point_t RecoverOffPlaneDeposit(geo::Point_t const& pos, geo::PlaneGeo const& plane) const;
312 
313  void DriftIonizationElectrons(detinfo::DetectorClocksData const& clockData,
314  G4ThreeVector stepMidPoint,
315  const double simTime,
316  int trackID,
317  unsigned short int cryostat,
318  unsigned short int tpc,
319  int origTrackID);
320 
321  bool Has(std::vector<unsigned short int> v, unsigned short int tpc) const
322  {
323  for (auto c : v)
324  if (c == tpc) return true;
325  return false;
326  }
327 
328  // Used in electron-cluster calculations
329  // External parameters for the electron-cluster calculation.
330  // obtained from LArG4Parameters, LArProperties, and DetectorProperties services
331  double fDriftVelocity[3];
338  std::vector<unsigned short int> fSkipWireSignalInTPCs;
340  double fOffPlaneMargin = 0.0;
341 
342  std::vector<std::vector<ChannelMap_t>> fChannelMaps;
346  unsigned int fTPC;
347  unsigned int fCstat;
348  bool bSingleTPC;
349 
350  CLHEP::HepRandomEngine* fPropGen = nullptr;
351 
352  detinfo::DetectorClocksData const* fClockData{nullptr};
353  detinfo::DetectorPropertiesData const* fDetProp{nullptr};
354 
355  //these are the things for doing the separated EDeps
356  void ProcessStep(G4Step*);
357 
358  G4ThreeVector fStepStart;
359  G4ThreeVector fStepEnd;
360  size_t fNSteps;
361  };
362 
363 }
364 
365 #endif // LArG4_LArVoxelReadout_h
void PrintAll(detinfo::DetectorPropertiesData const &detProp, std::string someText)
Definition: Utils.cxx:5367
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.
art::ServiceHandle< sim::LArG4Parameters const > fLgpHandle
Handle to the LArG4 parameters service.
art::ServiceHandle< geo::Geometry const > fGeoHandle
Handle to the Geometry service.
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.
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.
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:78
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
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.
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
art framework interface to geometry description
vec_iX clear()