LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
LArVoxelReadout.h
Go to the documentation of this file.
1 
42 #ifndef LArG4_LArVoxelReadout_h
43 #define LArG4_LArVoxelReadout_h
44 
45 #include <stdint.h>
46 #include <vector>
47 #include <algorithm> // std::max()
48 
49 #include "Geant4/G4VSensitiveDetector.hh"
50 #include "Geant4/G4PVPlacement.hh"
51 #include "Geant4/globals.hh"
52 
61 
62 // Forward declarations
63 class G4HCofThisEvent;
64 class G4TouchableHistory;
65 class G4Step;
66 namespace CLHEP { class HEPRandomEngine; }
67 
68 namespace larg4 {
69 
71  struct TPCID_t {
72  unsigned short int Cryostat, TPC;
73  bool operator< (const TPCID_t& than) const
74  {
75  return (Cryostat < than.Cryostat)
76  || ((Cryostat == than.Cryostat) && (TPC < than.TPC));
77  } // operator< ()
78  }; // TPCID_t
79 
93  template <class IDTYPE>
94  class G4PVPlacementWithID: public G4PVPlacement {
95  public:
96  typedef IDTYPE ID_t;
97 
98  ID_t ID;
99 
101  G4PVPlacementWithID(const G4Transform3D& Transform3D, const G4String &pName,
102  G4LogicalVolume* pLogical, G4VPhysicalVolume* pMother,
103  G4bool pMany, G4int pCopyNo, G4bool pSurfChk = false,
104  ID_t id = ID_t()
105  ):
106  G4PVPlacement
107  (Transform3D, pName, pLogical, pMother, pMany, pCopyNo, pSurfChk),
108  ID(id)
109  {}
110 
112  virtual ~G4PVPlacementWithID() {}
113  }; // G4PVPlacementWithID<>
114 
117 
118 
157  class LArVoxelReadout : public G4VSensitiveDetector
158  {
159  public:
161  typedef std::map<unsigned int, sim::SimChannel> ChannelMap_t;
162 
164  struct Setup_t {
165 
167  CLHEP::HepRandomEngine* propGen = nullptr;
168 
170  double offPlaneMargin = 0.0;
171  }; // struct Setup_t
172 
173 
175  LArVoxelReadout(std::string const& name);
176 
179  (std::string const& name, unsigned int cryostat, unsigned int tpc);
180 
181  // Destructor
182  virtual ~LArVoxelReadout();
183 
185  void Setup(Setup_t const& setupData);
186 
188  void SetSingleTPC(unsigned int cryostat, unsigned int tpc);
189 
191  void SetDiscoverTPC();
192 
193  // Required for classes that inherit from G4VSensitiveDetector.
194  //
195  // Called at start and end of each event.
196  virtual void Initialize(G4HCofThisEvent*);
197  virtual void EndOfEvent(G4HCofThisEvent*);
198 
199  // Called to clear any accumulated information.
200  virtual void clear();
201 
202  // The key method of this class. It's called by Geant4 for each
203  // step within the read-out geometry. It accumulates the energy
204  // in the G4Step in the LArVoxelList.
205  virtual G4bool ProcessHits( G4Step*, G4TouchableHistory* );
206 
207  // Empty methods; they have to be defined, but they're rarely
208  // used in Geant4 applications.
209  virtual void DrawAll();
210  virtual void PrintAll();
211 
212  // Independent method; clears the vector of SimChannels as well as the
213  // channel number to SimChannel map. Has to be separate from the
214  // clear method above because that run is run for every G4 event, ie
215  // each MCTruth in the art::Event, while we want to only run this at
216  // the end of the G4 processing for each art::Event.
217  void ClearSimChannels();
218 
220  std::vector<sim::SimChannel> GetSimChannels() const;
221 
223  std::vector<sim::SimChannel> GetSimChannels
224  (unsigned short cryo, unsigned short tpc) const;
225 
227  const ChannelMap_t& GetSimChannelMap() const;
229  ChannelMap_t& GetSimChannelMap();
231 
233  const ChannelMap_t& GetSimChannelMap
235  (unsigned short cryo, unsigned short tpc) const;
236  ChannelMap_t& GetSimChannelMap(unsigned short cryo, unsigned short tpc);
238 
239 
240  private:
241 
252  { fOffPlaneMargin = std::max(margin, 0.0); }
253 
255  void SetRandomEngines(CLHEP::HepRandomEngine* pPropGen);
256 
257 
296  geo::Point_t RecoverOffPlaneDeposit
297  (geo::Point_t const& pos, geo::PlaneGeo const& plane) const;
298 
299  void DriftIonizationElectrons(G4ThreeVector stepMidPoint,
300  const double simTime,
301  int trackID,
302  unsigned short int cryostat, unsigned short int tpc);
303 
304  bool Has(std::vector<unsigned short int> v, unsigned short int tpc) const
305  {
306  for (auto c: v) if (c == tpc) return true;
307  return false;
308  }
309 
310  // Used in electron-cluster calculations
311  // External parameters for the electron-cluster calculation.
312  // obtained from LArG4Parameters, LArProperties, and DetectorProperties services
313  double fDriftVelocity[3];
319  // for c2: unused private data members
320  //double fSampleRate;
321  //int fTriggerOffset;
323  std::vector<unsigned short int> fSkipWireSignalInTPCs;
325  double fOffPlaneMargin = 0.0;
326 
327  std::vector<std::vector<ChannelMap_t>> fChannelMaps;
330  unsigned int fTPC;
331  unsigned int fCstat;
332  bool bSingleTPC;
333 
334  CLHEP::HepRandomEngine* fPropGen = nullptr;
335 
337 
338  //these are the things for doing the separated EDeps
339  void ProcessStep(G4Step*);
340 
341  G4ThreeVector fStepStart;
342  G4ThreeVector fStepEnd;
343  size_t fNSteps;
344  };
345 
346 }
347 
348 #endif // LArG4_LArVoxelReadout_h
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.
bool operator<(CryostatID const &a, CryostatID const &b)
Order cryostats with increasing ID.
Definition: geo_types.h:413
void Initialize()
Definition: errprop.cc:101
art::ServiceHandle< sim::LArG4Parameters > fLgpHandle
Handle to the LArG4 parameters service.
Geant4 interface.
art::ServiceHandle< geo::Geometry > fGeoHandle
Handle to the Geometry service.
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.
Int_t max
Definition: plot.C:27
std::vector< unsigned short int > fSkipWireSignalInTPCs
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.
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.
void PrintAll(std::string someText, const std::vector< simb::MCParticle * > &mcpList)
Definition: Utils.cxx:4774
virtual ~G4PVPlacementWithID()
Virtual destructor: does nothing more.
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.
Singleton to access a unified treatment of ionization and scintillation in LAr.
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.
::detinfo::ElecClock fClock
TPC electronics clock.
Transports energy depositions from GEANT4 to TPC channels.
unsigned short int TPC
Class representing the time measured by an electronics clock.
Definition: ElecClock.h:91
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:187
art framework interface to geometry description
vec_iX clear()
Encapsulate the construction of a single detector plane.