LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
detsim::SimDriftElectrons Class Reference
Inheritance diagram for detsim::SimDriftElectrons:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Classes

struct  ChannelBookKeeping
 

Public Types

using ModuleType = EDProducer
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 SimDriftElectrons (fhicl::ParameterSet const &pset)
 
void produce (art::Event &evt) override
 
void beginJob () override
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
void fillProductDescriptions ()
 
void registerProducts (ProductDescriptions &productsToRegister)
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
std::unique_ptr< Worker > makeWorker (WorkerParams const &wp)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Protected Member Functions

ConsumesCollector & consumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Private Types

typedef std::unordered_map< raw::ChannelID_t, ChannelBookKeepingChannelMap_t
 

Private Attributes

art::InputTag fSimModuleLabel
 
CLHEP::RandGauss fRandGauss
 
double fElectronLifetime
 
double fElectronClusterSize
 
int fMinNumberOfElCluster
 
double fLongitudinalDiffusion
 
double fTransverseDiffusion
 
double fLifetimeCorr_const
 
double fLDiff_const
 
double fTDiff_const
 
double fRecipDriftVel [3]
 
bool fStoreDriftedElectronClusters
 
std::vector< ChannelMap_tfChannelMaps
 
size_t fNCryostats
 
std::vector< size_t > fNTPCs
 
std::vector< double > fLongDiff
 
std::vector< double > fTransDiff1
 
std::vector< double > fTransDiff2
 
std::vector< double > fnElDiff
 
std::vector< double > fnEnDiff
 
double fDriftClusterPos [3]
 
art::ServiceHandle< geo::Geometry const > fGeometry
 Handle to the Geometry service. More...
 

Detailed Description

Definition at line 89 of file SimDriftElectrons_module.cc.

Member Typedef Documentation

Definition at line 125 of file SimDriftElectrons_module.cc.

Definition at line 17 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::detail::Producer::Table = Modifier::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 26 of file Producer.h.

Constructor & Destructor Documentation

detsim::SimDriftElectrons::SimDriftElectrons ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 150 of file SimDriftElectrons_module.cc.

References art::detail::EngineCreator::createEngine(), fRandGauss, fSimModuleLabel, and fStoreDriftedElectronClusters.

151  : art::EDProducer{pset}
152  , fSimModuleLabel{pset.get<art::InputTag>("SimulationLabel")}
153  // create a default random engine; obtain the random seed from
154  // NuRandomService, unless overridden in configuration with key
155  // "Seed"
157  -> registerAndSeedEngine(createEngine(0), pset, "Seed")}
158  , fStoreDriftedElectronClusters{pset.get<bool>("StoreDriftedElectronClusters", false)}
159  {
160  produces<std::vector<sim::SimChannel>>();
161  if (fStoreDriftedElectronClusters) { produces<std::vector<sim::SimDriftedElectronCluster>>(); }
162  }
base_engine_t & createEngine(seed_t seed)

Member Function Documentation

void detsim::SimDriftElectrons::beginJob ( )
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 165 of file SimDriftElectrons_module.cc.

References e, sim::LArG4Parameters::ElectronClusterSize(), fElectronClusterSize, fElectronLifetime, fGeometry, fLDiff_const, fLifetimeCorr_const, fLongitudinalDiffusion, fMinNumberOfElCluster, fNCryostats, fNTPCs, fRecipDriftVel, fTDiff_const, fTransverseDiffusion, sim::LArG4Parameters::LongitudinalDiffusion(), MF_LOG_DEBUG, sim::LArG4Parameters::MinNumberOfElCluster(), n, geo::GeometryCore::Ncryostats(), geo::GeometryCore::NTPC(), and sim::LArG4Parameters::TransverseDiffusion().

166  {
167  // Define the physical constants we'll use.
168 
169  auto const detProp =
171  fElectronLifetime = detProp.ElectronLifetime(); // Electron lifetime as returned by the
172  // DetectorProperties service assumed to be in us;
173  for (int i = 0; i < 3; ++i) {
174  double driftVelocity = detProp.DriftVelocity(detProp.Efield(i),
175  detProp.Temperature()) *
176  1.e-3; // Drift velocity as returned by the DetectorProperties service
177  // assumed to be in cm/us. Multiply by 1.e-3 to convert into
178  // LArSoft standard velocity units, cm/ns;
179 
180  fRecipDriftVel[i] = 1. / driftVelocity;
181  }
182 
183  // To-do: Move the parameters we fetch from "LArG4" to detector properties.
185  fElectronClusterSize = paramHandle->ElectronClusterSize();
187  fLongitudinalDiffusion = paramHandle->LongitudinalDiffusion(); // cm^2/ns units
188  fTransverseDiffusion = paramHandle->TransverseDiffusion(); // cm^2/ns units
189 
190  MF_LOG_DEBUG("SimDriftElectrons")
191  << " e lifetime (ns): " << fElectronLifetime
192  << "\n Temperature (K): " << detProp.Temperature()
193  << "\n Drift velocity (cm/ns): " << 1. / fRecipDriftVel[0] << " " << 1. / fRecipDriftVel[1]
194  << " " << 1. / fRecipDriftVel[2];
195 
196  // Opposite of lifetime. Convert from us to standard LArSoft time units, ns;
198  fLDiff_const = std::sqrt(2. * fLongitudinalDiffusion);
199  fTDiff_const = std::sqrt(2. * fTransverseDiffusion);
200 
201  // For this detector's geometry, save the number of cryostats and the number of TPCs
202  // within each cryostat.
204  fNTPCs.resize(fNCryostats);
205  for (size_t n = 0; n < fNCryostats; ++n)
207  }
unsigned int NTPC(CryostatID const &cryoid=details::cryostat_zero) const
Returns the total number of TPCs in the specified cryostat.
Definition: GeometryCore.h:416
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
Definition: GeometryCore.h:303
art::ServiceHandle< geo::Geometry const > fGeometry
Handle to the Geometry service.
double TransverseDiffusion() const
double ElectronClusterSize() const
int MinNumberOfElCluster() const
#define MF_LOG_DEBUG(id)
Char_t n[5]
double LongitudinalDiffusion() const
Float_t e
Definition: plot.C:35
The data type to uniquely identify a cryostat.
Definition: geo_types.h:187
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::consumes ( InputTag const &  tag)
protectedinherited

Definition at line 61 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumes().

62  {
63  return collector_.consumes<T, BT>(tag);
64  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ProductToken< T > consumes(InputTag const &)
ConsumesCollector & art::ModuleBase::consumesCollector ( )
protectedinherited

Definition at line 57 of file ModuleBase.cc.

References art::ModuleBase::collector_.

58  {
59  return collector_;
60  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename T , BranchType BT>
void art::ModuleBase::consumesMany ( )
protectedinherited

Definition at line 75 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumesMany().

76  {
77  collector_.consumesMany<T, BT>();
78  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::consumesView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::consumesView ( InputTag const &  tag)
inherited

Definition at line 68 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumesView().

69  {
70  return collector_.consumesView<T, BT>(tag);
71  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ViewToken< Element > consumesView(InputTag const &)
void art::detail::Producer::doBeginJob ( SharedResources const &  resources)
inherited

Definition at line 22 of file Producer.cc.

References art::detail::Producer::beginJobWithFrame(), and art::detail::Producer::setupQueues().

23  {
24  setupQueues(resources);
25  ProcessingFrame const frame{ScheduleID{}};
26  beginJobWithFrame(frame);
27  }
virtual void setupQueues(SharedResources const &)=0
virtual void beginJobWithFrame(ProcessingFrame const &)=0
bool art::detail::Producer::doBeginRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited

Definition at line 65 of file Producer.cc.

References art::detail::Producer::beginRunWithFrame(), art::RangeSet::forRun(), art::RunPrincipal::makeRun(), r, art::RunPrincipal::runID(), and art::ModuleContext::scheduleID().

66  {
67  auto r = rp.makeRun(mc, RangeSet::forRun(rp.runID()));
68  ProcessingFrame const frame{mc.scheduleID()};
69  beginRunWithFrame(r, frame);
70  r.commitProducts();
71  return true;
72  }
TRandom r
Definition: spectrum.C:23
virtual void beginRunWithFrame(Run &, ProcessingFrame const &)=0
static RangeSet forRun(RunID)
Definition: RangeSet.cc:51
bool art::detail::Producer::doBeginSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited

Definition at line 85 of file Producer.cc.

References art::detail::Producer::beginSubRunWithFrame(), art::RangeSet::forSubRun(), art::SubRunPrincipal::makeSubRun(), art::ModuleContext::scheduleID(), and art::SubRunPrincipal::subRunID().

86  {
87  auto sr = srp.makeSubRun(mc, RangeSet::forSubRun(srp.subRunID()));
88  ProcessingFrame const frame{mc.scheduleID()};
89  beginSubRunWithFrame(sr, frame);
90  sr.commitProducts();
91  return true;
92  }
virtual void beginSubRunWithFrame(SubRun &, ProcessingFrame const &)=0
static RangeSet forSubRun(SubRunID)
Definition: RangeSet.cc:57
void art::detail::Producer::doEndJob ( )
inherited

Definition at line 30 of file Producer.cc.

References art::detail::Producer::endJobWithFrame().

31  {
32  ProcessingFrame const frame{ScheduleID{}};
33  endJobWithFrame(frame);
34  }
virtual void endJobWithFrame(ProcessingFrame const &)=0
bool art::detail::Producer::doEndRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited

Definition at line 75 of file Producer.cc.

References art::detail::Producer::endRunWithFrame(), art::RunPrincipal::makeRun(), r, art::ModuleContext::scheduleID(), and art::Principal::seenRanges().

76  {
77  auto r = rp.makeRun(mc, rp.seenRanges());
78  ProcessingFrame const frame{mc.scheduleID()};
79  endRunWithFrame(r, frame);
80  r.commitProducts();
81  return true;
82  }
TRandom r
Definition: spectrum.C:23
virtual void endRunWithFrame(Run &, ProcessingFrame const &)=0
bool art::detail::Producer::doEndSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited

Definition at line 95 of file Producer.cc.

References art::detail::Producer::endSubRunWithFrame(), art::SubRunPrincipal::makeSubRun(), art::ModuleContext::scheduleID(), and art::Principal::seenRanges().

96  {
97  auto sr = srp.makeSubRun(mc, srp.seenRanges());
98  ProcessingFrame const frame{mc.scheduleID()};
99  endSubRunWithFrame(sr, frame);
100  sr.commitProducts();
101  return true;
102  }
virtual void endSubRunWithFrame(SubRun &, ProcessingFrame const &)=0
bool art::detail::Producer::doEvent ( EventPrincipal ep,
ModuleContext const &  mc,
std::atomic< std::size_t > &  counts_run,
std::atomic< std::size_t > &  counts_passed,
std::atomic< std::size_t > &  counts_failed 
)
inherited

Definition at line 105 of file Producer.cc.

References art::detail::Producer::checkPutProducts_, e, art::EventPrincipal::makeEvent(), art::detail::Producer::produceWithFrame(), and art::ModuleContext::scheduleID().

110  {
111  auto e = ep.makeEvent(mc);
112  ++counts_run;
113  ProcessingFrame const frame{mc.scheduleID()};
114  produceWithFrame(e, frame);
115  e.commitProducts(checkPutProducts_, &expectedProducts<InEvent>());
116  ++counts_passed;
117  return true;
118  }
bool const checkPutProducts_
Definition: Producer.h:70
Float_t e
Definition: plot.C:35
virtual void produceWithFrame(Event &, ProcessingFrame const &)=0
void art::detail::Producer::doRespondToCloseInputFile ( FileBlock const &  fb)
inherited

Definition at line 44 of file Producer.cc.

References art::detail::Producer::respondToCloseInputFileWithFrame().

45  {
46  ProcessingFrame const frame{ScheduleID{}};
48  }
virtual void respondToCloseInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToCloseOutputFiles ( FileBlock const &  fb)
inherited

Definition at line 58 of file Producer.cc.

References art::detail::Producer::respondToCloseOutputFilesWithFrame().

59  {
60  ProcessingFrame const frame{ScheduleID{}};
62  }
virtual void respondToCloseOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToOpenInputFile ( FileBlock const &  fb)
inherited

Definition at line 37 of file Producer.cc.

References art::detail::Producer::respondToOpenInputFileWithFrame().

38  {
39  ProcessingFrame const frame{ScheduleID{}};
41  }
virtual void respondToOpenInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToOpenOutputFiles ( FileBlock const &  fb)
inherited

Definition at line 51 of file Producer.cc.

References art::detail::Producer::respondToOpenOutputFilesWithFrame().

52  {
53  ProcessingFrame const frame{ScheduleID{}};
55  }
virtual void respondToOpenOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::Modifier::fillProductDescriptions ( )
inherited

Definition at line 10 of file Modifier.cc.

References art::ProductRegistryHelper::fillDescriptions(), and art::ModuleBase::moduleDescription().

11  {
13  }
void fillDescriptions(ModuleDescription const &md)
ModuleDescription const & moduleDescription() const
Definition: ModuleBase.cc:13
std::array< std::vector< ProductInfo >, NumBranchTypes > const & art::ModuleBase::getConsumables ( ) const
inherited

Definition at line 43 of file ModuleBase.cc.

References art::ModuleBase::collector_, and art::ConsumesCollector::getConsumables().

44  {
45  return collector_.getConsumables();
46  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables() const
std::unique_ptr< Worker > art::ModuleBase::makeWorker ( WorkerParams const &  wp)
inherited

Definition at line 37 of file ModuleBase.cc.

References art::ModuleBase::doMakeWorker(), and art::NumBranchTypes.

38  {
39  return doMakeWorker(wp);
40  }
virtual std::unique_ptr< Worker > doMakeWorker(WorkerParams const &wp)=0
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::mayConsume ( InputTag const &  tag)
protectedinherited

Definition at line 82 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsume().

83  {
84  return collector_.mayConsume<T, BT>(tag);
85  }
ProductToken< T > mayConsume(InputTag const &)
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename T , BranchType BT>
void art::ModuleBase::mayConsumeMany ( )
protectedinherited

Definition at line 96 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsumeMany().

97  {
98  collector_.mayConsumeMany<T, BT>();
99  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::mayConsumeView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::mayConsumeView ( InputTag const &  tag)
inherited

Definition at line 89 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsumeView().

90  {
91  return collector_.mayConsumeView<T, BT>(tag);
92  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ViewToken< Element > mayConsumeView(InputTag const &)
ModuleDescription const & art::ModuleBase::moduleDescription ( ) const
inherited

Definition at line 13 of file ModuleBase.cc.

References art::errors::LogicError.

Referenced by art::OutputModule::doRespondToOpenInputFile(), art::OutputModule::doWriteEvent(), art::Modifier::fillProductDescriptions(), art::OutputModule::makePlugins_(), art::OutputWorker::OutputWorker(), reco::shower::LArPandoraModularShowerCreation::produce(), art::Modifier::registerProducts(), and art::OutputModule::registerProducts().

14  {
15  if (md_.has_value()) {
16  return *md_;
17  }
18 
20  "There was an error while calling moduleDescription().\n"}
21  << "The moduleDescription() base-class member function cannot be called\n"
22  "during module construction. To determine which module is "
23  "responsible\n"
24  "for calling it, find the '<module type>:<module "
25  "label>@Construction'\n"
26  "tag in the message prefix above. Please contact artists@fnal.gov\n"
27  "for guidance.\n";
28  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::optional< ModuleDescription > md_
Definition: ModuleBase.h:55
void detsim::SimDriftElectrons::produce ( art::Event evt)
overridevirtual
Todo:
think about effects of drift between planes.
Todo:
think about effects of drift between planes
Todo:
check on what happens if we allow the tdc value to be
Todo:
beyond the end of the expected number of ticks

Implements art::EDProducer.

Definition at line 210 of file SimDriftElectrons_module.cc.

References util::abs(), sim::SimChannel::AddIonizationElectrons(), detsim::SimDriftElectrons::ChannelBookKeeping::channelIndex, geo::vect::coord(), geo::CryostatID::Cryostat, DEFINE_ART_MODULE, geo::TPCGeo::DriftAxisWithSign(), e, energy, fChannelMaps, fDriftClusterPos, fElectronClusterSize, fGeometry, fLDiff_const, fLifetimeCorr_const, fLongDiff, fMinNumberOfElCluster, fNCryostats, fnElDiff, fnEnDiff, fRandGauss, fRecipDriftVel, fSimModuleLabel, fStoreDriftedElectronClusters, fTDiff_const, fTransDiff1, fTransDiff2, Get, art::ProductRetriever::getByLabel(), geo::CryostatID::getInvalidID(), geo::TPCID::getInvalidID(), MF_LOG_DEBUG, larsim::Utils::SCE::out_of_bounds(), geo::GeometryCore::PositionToCryostatID(), geo::GeometryCore::PositionToTPCID(), pmtana::sign(), detsim::SimDriftElectrons::ChannelBookKeeping::stepList, geo::to_int(), geo::vect::toPoint(), geo::TPCID::TPC, geo::GeometryCore::TPC(), xx, geo::Y, and geo::Z.

211  {
212  // Fetch the SimEnergyDeposit objects for this event.
213  typedef art::Handle<std::vector<sim::SimEnergyDeposit>> energyDepositHandle_t;
214  energyDepositHandle_t energyDepositHandle;
215  // If there aren't any energy deposits for this event, don't panic. It's possible
216  // someone is doing a study with events outside the TPC, or where there are only
217  // non-ionizing particles, or something like that.
218  if (!event.getByLabel(fSimModuleLabel, energyDepositHandle)) return;
219 
220  // Define the container for the SimChannel objects that will be transferred to the
221  // art::Event after the put statement below.
222  std::unique_ptr<std::vector<sim::SimChannel>> channels(new std::vector<sim::SimChannel>);
223  // Container for the SimDriftedElectronCluster objects
224  std::unique_ptr<std::vector<sim::SimDriftedElectronCluster>>
225  SimDriftedElectronClusterCollection(new std::vector<sim::SimDriftedElectronCluster>);
226 
227  // Clear the channel maps from the last event. Remember, fChannelMaps is an
228  // array[cryo][tpc] of maps.
229  size_t cryo = 0;
230  fChannelMaps.resize(fNCryostats);
231  for (auto& cryoData : fChannelMaps) { // each, a vector of maps
232  cryoData.clear();
233  }
234 
235  auto const clockData =
237  auto const& tpcClock = clockData.TPCClock();
238 
239  auto const detProp =
241  // We're going through the input vector by index, rather than by iterator, because we
242  // need the index number to compute the associations near the end of this method.
243  auto const& energyDeposits = *energyDepositHandle;
244  auto energyDepositsSize = energyDeposits.size();
245 
246  // For each energy deposit in this event
247  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
248  for (size_t edIndex = 0; edIndex < energyDepositsSize; ++edIndex) {
249  auto const& energyDeposit = energyDeposits[edIndex];
250 
251  // "xyz" is the position of the energy deposit in world coordinates. Note that the
252  // units of distance in sim::SimEnergyDeposit are supposed to be cm.
253  auto const mp = energyDeposit.MidPoint();
254  std::array<double, 3> xyz;
255  mp.GetCoordinates(data(xyz));
256 
257  // From the position in world coordinates, determine the cryostat and tpc. If
258  // somehow the step is outside a tpc (e.g., cosmic rays in rock) just move on to the
259  // next one.
260  unsigned int cryostat = 0;
261  cryostat = fGeometry->PositionToCryostatID(mp).Cryostat;
262  if (cryostat == geo::CryostatID::getInvalidID()) {
263  mf::LogWarning("SimDriftElectrons") << "step " // << energyDeposit << "\n"
264  << "cannot be found in a cryostat\n";
265  continue;
266  }
267 
268  geo::TPCID tpcid;
269  tpcid = fGeometry->PositionToTPCID(mp);
270  if (tpcid.TPC == geo::TPCID::getInvalidID()) {
271  mf::LogWarning("SimDriftElectrons") << "step " // << energyDeposit << "\n"
272  << "cannot be found in a TPC\n";
273  continue;
274  }
275 
276  geo::TPCGeo const& tpcGeo = fGeometry->TPC(tpcid);
277  unsigned int const nplanes = wireReadoutGeom.Nplanes(tpcid);
278 
279  // The drift direction can be either in the positive or negative direction in any
280  // coordinate x, y or z.
281 
282  // Define charge drift direction: driftcoordinate (x, y or z) and driftsign
283  // (positive or negative). Also define coordinates perpendicular to drift direction.
284 
285  auto const [axis, sign] = tpcGeo.DriftAxisWithSign();
286 
287  // For axis == geo::Coordinate::X
288  int driftcoordinate = 0;
289  int transversecoordinate1 = 1;
290  int transversecoordinate2 = 2;
291  if (axis == geo::Coordinate::Y) {
292  transversecoordinate1 = 0;
293  driftcoordinate = 1;
294  transversecoordinate2 = 2;
295  }
296  else if (axis == geo::Coordinate::Z) {
297  transversecoordinate1 = 0;
298  transversecoordinate2 = 1;
299  driftcoordinate = 2;
300  }
301 
302  int const driftsign = to_int(sign); // 1: +x, +y or +z, -1: -x, -y or -z
303 
304  // Check for charge deposits behind charge readout planes
305  auto const& plane_location = wireReadoutGeom.FirstPlane(tpcid).GetCenter();
306  auto const plane_location_coord = geo::vect::coord(plane_location, driftcoordinate);
307  if (driftsign == 1 && plane_location_coord < xyz[driftcoordinate]) continue;
308  if (driftsign == -1 && plane_location_coord > xyz[driftcoordinate]) continue;
309 
311  // Center of plane is also returned in cm units
312  double DriftDistance = std::abs(xyz[driftcoordinate] - plane_location_coord);
313 
314  // Space-charge effect (SCE): Get SCE {x,y,z} offsets for particular location in TPC
315  geo::Vector_t posOffsets{0.0, 0.0, 0.0};
316  double posOffsetxyz[3] = {0.0, 0.0, 0.0}; // need this array for the driftcoordinate and
317  // transversecoordinates
318  auto const* SCE = lar::providerFrom<spacecharge::SpaceChargeService>();
319  if (SCE->EnableSimSpatialSCE() == true) {
320  posOffsets = SCE->GetPosOffsets(mp);
321  if (larsim::Utils::SCE::out_of_bounds(posOffsets)) { continue; }
322  posOffsetxyz[0] = posOffsets.X();
323  posOffsetxyz[1] = posOffsets.Y();
324  posOffsetxyz[2] = posOffsets.Z();
325  }
326 
327  double avegagetransversePos1 = 0.;
328  double avegagetransversePos2 = 0.;
329 
330  DriftDistance += -1. * posOffsetxyz[driftcoordinate];
331  avegagetransversePos1 = xyz[transversecoordinate1] + posOffsetxyz[transversecoordinate1];
332  avegagetransversePos2 = xyz[transversecoordinate2] + posOffsetxyz[transversecoordinate2];
333 
334  // Space charge distortion could push the energy deposit beyond the wire plane (see
335  // issue #15131). Given that we don't have any subtlety in the simulation of this
336  // region, bringing the deposit exactly on the plane should be enough for the time
337  // being.
338  if (DriftDistance < 0.) DriftDistance = 0.;
339 
340  // Drift time in ns
341  double TDrift = DriftDistance * fRecipDriftVel[0];
342 
343  if (nplanes == 2 &&
344  driftcoordinate == 0) { // special case for ArgoNeuT (Nplanes = 2 and drift direction =
345  // x): plane 0 is the second wire plane
346  double const pitch = wireReadoutGeom.PlanePitch(tpcid, 0, 1);
347  TDrift = ((DriftDistance - pitch) * fRecipDriftVel[0] + pitch * fRecipDriftVel[1]);
348  }
349 
350  const int nIonizedElectrons = energyDeposit.NumElectrons();
351  const double lifetimecorrection = TMath::Exp(TDrift / fLifetimeCorr_const);
352  const double energy = energyDeposit.Energy();
353 
354  // if we have no electrons (too small energy or too large recombination)
355  // we are done already here
356  if (nIonizedElectrons <= 0) {
357  MF_LOG_DEBUG("SimDriftElectrons")
358  << "step " // << energyDeposit << "\n"
359  << "No electrons drifted to readout, " << energy << " MeV lost.";
360  continue;
361  }
362 
363  // includes the effect of lifetime: lifetimecorrection = exp[-tdrift/tau]
364  const double nElectrons = nIonizedElectrons * lifetimecorrection;
365 
366  // Longitudinal & transverse diffusion sigma (cm)
367  double SqrtT = std::sqrt(TDrift);
368  double LDiffSig = SqrtT * fLDiff_const;
369  double TDiffSig = SqrtT * fTDiff_const;
370  double electronclsize = fElectronClusterSize;
371 
372  // Number of electron clusters.
373  int nClus = (int)std::ceil(nElectrons / electronclsize);
374  if (nClus < fMinNumberOfElCluster) {
375  electronclsize = nElectrons / fMinNumberOfElCluster;
376  if (electronclsize < 1.0) { electronclsize = 1.0; }
377  nClus = (int)std::ceil(nElectrons / electronclsize);
378  }
379 
380  // Empty and resize the electron-cluster vectors.
381  fLongDiff.clear();
382  fTransDiff1.clear();
383  fTransDiff2.clear();
384  fnElDiff.clear();
385  fnEnDiff.clear();
386  fLongDiff.resize(nClus);
387  fTransDiff1.resize(nClus);
388  fTransDiff2.resize(nClus);
389  fnElDiff.resize(nClus, electronclsize);
390  fnEnDiff.resize(nClus);
391 
392  // fix the number of electrons in the last cluster, that has a smaller size
393  fnElDiff.back() = nElectrons - (nClus - 1) * electronclsize;
394 
395  for (size_t xx = 0; xx < fnElDiff.size(); ++xx) {
396  if (nElectrons > 0)
397  fnEnDiff[xx] = energy / nElectrons * fnElDiff[xx];
398  else
399  fnEnDiff[xx] = 0.;
400  }
401 
402  // Smear drift times by longitudinal diffusion
403  if (LDiffSig > 0.0)
404  fRandGauss.fireArray(nClus, &fLongDiff[0], 0., LDiffSig);
405  else
406  fLongDiff.assign(nClus, 0.0);
407 
408  if (TDiffSig > 0.0) {
409  // Smear the coordinates in plane perpendicular to drift direction by the transverse diffusion
410  fRandGauss.fireArray(nClus, &fTransDiff1[0], avegagetransversePos1, TDiffSig);
411  fRandGauss.fireArray(nClus, &fTransDiff2[0], avegagetransversePos2, TDiffSig);
412  }
413  else {
414  fTransDiff1.assign(nClus, avegagetransversePos1);
415  fTransDiff2.assign(nClus, avegagetransversePos2);
416  }
417 
418  // make a collection of electrons for each plane
419  for (unsigned int p = 0; p < nplanes; ++p) {
420  // FIXME (KJK): Shouldn't this be the location for each plane we're iterating
421  // through? Right now it uses whatever value of plane_location_coord was set
422  // above.
423  fDriftClusterPos[driftcoordinate] = plane_location_coord;
424 
425  // Drift nClus electron clusters to the induction plane
426  for (int k = 0; k < nClus; ++k) {
427 
428  // Correct drift time for longitudinal diffusion and plane
429  double TDiff = TDrift + fLongDiff[k] * fRecipDriftVel[0];
430 
431  // Take into account different Efields between planes. Also take into account
432  // special case for ArgoNeuT (Nplanes = 2 and drift direction = x): plane 0 is
433  // the second wire plane
434  for (unsigned int ip = 0; ip < p; ++ip) {
435  TDiff += wireReadoutGeom.PlanePitch(tpcid, ip + 1, ip) *
436  fRecipDriftVel[(nplanes == 2 && driftcoordinate == 0) ? ip + 2 : ip + 1];
437  }
438 
439  fDriftClusterPos[transversecoordinate1] = fTransDiff1[k];
440  fDriftClusterPos[transversecoordinate2] = fTransDiff2[k];
441 
443 
444  // grab the nearest channel to the fDriftClusterPos position
445  try {
446  raw::ChannelID_t channel = wireReadoutGeom.NearestChannel(
447  geo::vect::toPoint(fDriftClusterPos), geo::PlaneID{tpcid, p});
448 
451  // Add potential decay/capture/etc delay effect, simTime.
452  auto const simTime = energyDeposit.Time();
453  unsigned int tdc = tpcClock.Ticks(clockData.G4ToElecTime(TDiff + simTime));
454 
455  // Find whether we already have this channel in our map.
456  ChannelMap_t& channelDataMap = fChannelMaps[cryostat];
457  auto search = channelDataMap.find(channel);
458 
459  // We will find (or create) the pointer to a sim::SimChannel.
460  size_t channelIndex = 0;
461 
462  // Have we created the sim::SimChannel corresponding to channel ID?
463  if (search == channelDataMap.end()) {
464  // We haven't. Initialize the bookkeeping information for this channel.
465  ChannelBookKeeping bookKeeping;
466 
467  // Add a new channel to the end of the list we'll write out after we've
468  // processed this event.
469  bookKeeping.channelIndex = channels->size();
470  channels->emplace_back(channel);
471  channelIndex = bookKeeping.channelIndex;
472 
473  // Initialize a vector with the index of the step that created this channel.
474  bookKeeping.stepList.push_back(edIndex);
475 
476  // Save the bookkeeping information for this channel.
477  channelDataMap[channel] = bookKeeping;
478  }
479  else {
480  // We've created this SimChannel for a previous energy deposit. Get its
481  // address.
482 
483  auto& bookKeeping = search->second;
484  channelIndex = bookKeeping.channelIndex;
485 
486  // Has this step contributed to this channel before?
487  auto& stepList = bookKeeping.stepList;
488  if (!std::binary_search(stepList.begin(), stepList.end(), edIndex)) {
489  // No, so add this step's index to the list.
490  stepList.push_back(edIndex);
491  }
492  }
493 
494  sim::SimChannel* channelPtr = &(channels->at(channelIndex));
495 
496  // Add the electron clusters and energy to the
497  // sim::SimChannel
498  channelPtr->AddIonizationElectrons(energyDeposit.TrackID(),
499  tdc,
500  fnElDiff[k],
501  data(xyz),
502  fnEnDiff[k],
503  energyDeposit.OrigTrackID());
505  SimDriftedElectronClusterCollection->emplace_back(
506  fnElDiff[k],
507  TDiff + simTime, // timing
508  geo::Point_t{mp.X(), mp.Y(), mp.Z()}, // mean position of the deposited energy
509  geo::Point_t{fDriftClusterPos[0],
510  fDriftClusterPos[1],
511  fDriftClusterPos[2]}, // final position of the drifted cluster
512  geo::Point_t{
513  LDiffSig, TDiffSig, TDiffSig}, // Longitudinal (X) and transverse (Y,Z) diffusion
514  fnEnDiff[k], // deposited energy that originated this cluster
515  energyDeposit.TrackID());
516  }
517  catch (cet::exception& e) {
518  mf::LogDebug("SimDriftElectrons")
519  << "unable to drift electrons from point (" << xyz[0] << "," << xyz[1] << ","
520  << xyz[2] << ") with exception " << e;
521  } // end try to determine channel
522  } // end loop over clusters
523  } // end loop over planes
524  } // for each sim::SimEnergyDeposit
525 
526  // Write the sim::SimChannel collection.
527  event.put(std::move(channels));
528  if (fStoreDriftedElectronClusters) event.put(std::move(SimDriftedElectronClusterCollection));
529  }
Double_t xx
Definition: macro.C:12
Energy deposited on a readout channel by simulated tracks.
Definition: SimChannel.h:136
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:160
bool out_of_bounds(geo::Vector_t const &offset)
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
The data type to uniquely identify a Plane.
Definition: geo_types.h:364
Geometry information for a single TPC.
Definition: TPCGeo.h:33
constexpr auto abs(T v)
Returns the absolute value of the argument.
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:195
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
DriftAxis DriftAxisWithSign() const
Returns the expected drift direction based on geometry.
Definition: TPCGeo.h:78
art::ServiceHandle< geo::Geometry const > fGeometry
Handle to the Geometry service.
static constexpr CryostatID_t getInvalidID()
Return the value of the invalid ID as a r-value.
Definition: geo_types.h:244
static constexpr TPCID_t getInvalidID()
Return the value of the invalid TPC ID as a r-value.
Definition: geo_types.h:359
double energy
Definition: plottest35.C:25
constexpr int to_int(Coordinate const coord) noexcept
Enumerate the possible plane projections.
Definition: geo_types.h:124
Point_t toPoint(Point const &p)
Convert the specified point into a geo::Point_t.
The data type to uniquely identify a TPC.
Definition: geo_types.h:306
std::vector< ChannelMap_t > fChannelMaps
int sign(double val)
Definition: UtilFunc.cxx:104
CryostatID PositionToCryostatID(Point_t const &point) const
Returns the ID of the cryostat at specified location.
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
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
#define MF_LOG_DEBUG(id)
void AddIonizationElectrons(TrackID_t trackID, TDC_t tdc, double numberElectrons, double const *xyz, double energy, TrackID_t origTrackID=util::kBogusI)
Add ionization electrons and energy to this channel.
Definition: SimChannel.cxx:49
std::unordered_map< raw::ChannelID_t, ChannelBookKeeping > ChannelMap_t
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:315
TPCGeo const & TPC(TPCID const &tpcid=details::tpc_zero) const
Returns the specified TPC.
Definition: GeometryCore.h:448
Float_t e
Definition: plot.C:35
TPCID PositionToTPCID(Point_t const &point) const
Returns the ID of the TPC at specified location.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Event finding and building.
void art::Modifier::registerProducts ( ProductDescriptions productsToRegister)
inherited

Definition at line 16 of file Modifier.cc.

References art::ModuleBase::moduleDescription(), and art::ProductRegistryHelper::registerProducts().

17  {
18  ProductRegistryHelper::registerProducts(productsToRegister,
20  }
void registerProducts(ProductDescriptions &productsToRegister, ModuleDescription const &md)
ModuleDescription const & moduleDescription() const
Definition: ModuleBase.cc:13
void art::ModuleBase::setModuleDescription ( ModuleDescription const &  md)
inherited

Definition at line 31 of file ModuleBase.cc.

References art::ModuleBase::md_.

32  {
33  md_ = md;
34  }
std::optional< ModuleDescription > md_
Definition: ModuleBase.h:55
void art::ModuleBase::sortConsumables ( std::string const &  current_process_name)
inherited

Definition at line 49 of file ModuleBase.cc.

References art::ModuleBase::collector_, and art::ConsumesCollector::sortConsumables().

50  {
51  // Now that we know we have seen all the consumes declarations,
52  // sort the results for fast lookup later.
53  collector_.sortConsumables(current_process_name);
54  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
void sortConsumables(std::string const &current_process_name)

Member Data Documentation

std::vector<ChannelMap_t> detsim::SimDriftElectrons::fChannelMaps
private

Definition at line 128 of file SimDriftElectrons_module.cc.

Referenced by produce().

double detsim::SimDriftElectrons::fDriftClusterPos[3]
private

Definition at line 143 of file SimDriftElectrons_module.cc.

Referenced by produce().

double detsim::SimDriftElectrons::fElectronClusterSize
private

Definition at line 104 of file SimDriftElectrons_module.cc.

Referenced by beginJob(), and produce().

double detsim::SimDriftElectrons::fElectronLifetime
private

Definition at line 103 of file SimDriftElectrons_module.cc.

Referenced by beginJob().

art::ServiceHandle<geo::Geometry const> detsim::SimDriftElectrons::fGeometry
private

Handle to the Geometry service.

Definition at line 145 of file SimDriftElectrons_module.cc.

Referenced by beginJob(), and produce().

double detsim::SimDriftElectrons::fLDiff_const
private

Definition at line 110 of file SimDriftElectrons_module.cc.

Referenced by beginJob(), and produce().

double detsim::SimDriftElectrons::fLifetimeCorr_const
private

Definition at line 109 of file SimDriftElectrons_module.cc.

Referenced by beginJob(), and produce().

std::vector<double> detsim::SimDriftElectrons::fLongDiff
private

Definition at line 137 of file SimDriftElectrons_module.cc.

Referenced by produce().

double detsim::SimDriftElectrons::fLongitudinalDiffusion
private

Definition at line 106 of file SimDriftElectrons_module.cc.

Referenced by beginJob().

int detsim::SimDriftElectrons::fMinNumberOfElCluster
private

Definition at line 105 of file SimDriftElectrons_module.cc.

Referenced by beginJob(), and produce().

size_t detsim::SimDriftElectrons::fNCryostats
private

Definition at line 133 of file SimDriftElectrons_module.cc.

Referenced by beginJob(), and produce().

std::vector<double> detsim::SimDriftElectrons::fnElDiff
private

Definition at line 140 of file SimDriftElectrons_module.cc.

Referenced by produce().

std::vector<double> detsim::SimDriftElectrons::fnEnDiff
private

Definition at line 141 of file SimDriftElectrons_module.cc.

Referenced by produce().

std::vector<size_t> detsim::SimDriftElectrons::fNTPCs
private

Definition at line 134 of file SimDriftElectrons_module.cc.

Referenced by beginJob().

CLHEP::RandGauss detsim::SimDriftElectrons::fRandGauss
private

Definition at line 101 of file SimDriftElectrons_module.cc.

Referenced by produce(), and SimDriftElectrons().

double detsim::SimDriftElectrons::fRecipDriftVel[3]
private

Definition at line 112 of file SimDriftElectrons_module.cc.

Referenced by beginJob(), and produce().

art::InputTag detsim::SimDriftElectrons::fSimModuleLabel
private

Definition at line 99 of file SimDriftElectrons_module.cc.

Referenced by produce(), and SimDriftElectrons().

bool detsim::SimDriftElectrons::fStoreDriftedElectronClusters
private

Definition at line 114 of file SimDriftElectrons_module.cc.

Referenced by produce(), and SimDriftElectrons().

double detsim::SimDriftElectrons::fTDiff_const
private

Definition at line 111 of file SimDriftElectrons_module.cc.

Referenced by beginJob(), and produce().

std::vector<double> detsim::SimDriftElectrons::fTransDiff1
private

Definition at line 138 of file SimDriftElectrons_module.cc.

Referenced by produce().

std::vector<double> detsim::SimDriftElectrons::fTransDiff2
private

Definition at line 139 of file SimDriftElectrons_module.cc.

Referenced by produce().

double detsim::SimDriftElectrons::fTransverseDiffusion
private

Definition at line 107 of file SimDriftElectrons_module.cc.

Referenced by beginJob().


The documentation for this class was generated from the following file: