LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
sim::MergeSimSourcesUtility Class Reference

#include "MergeSimSources.h"

Public Member Functions

 MergeSimSourcesUtility (std::vector< int > const &)
 
void Reset ()
 
void MergeMCParticles (std::vector< simb::MCParticle > &, const std::vector< simb::MCParticle > &, size_t)
 
void MergeSimChannels (std::vector< sim::SimChannel > &, const std::vector< sim::SimChannel > &, size_t)
 
void MergeAuxDetSimChannels (std::vector< sim::AuxDetSimChannel > &, const std::vector< sim::AuxDetSimChannel > &, size_t)
 
void MergeSimPhotons (std::vector< sim::SimPhotons > &, const std::vector< sim::SimPhotons > &)
 
void MergeSimPhotonsLite (std::vector< sim::SimPhotonsLite > &, const std::vector< sim::SimPhotonsLite > &)
 
void MergeSimEnergyDeposits (std::vector< sim::SimEnergyDeposit > &, const std::vector< sim::SimEnergyDeposit > &, size_t) const
 
void MergeAuxDetHits (std::vector< sim::AuxDetHit > &, const std::vector< sim::AuxDetHit > &, size_t) const
 
void MergeParticleAncestryMaps (std::vector< sim::ParticleAncestryMap > &, const sim::ParticleAncestryMap &, size_t) const
 
const std::vector< std::vector< size_t > > & GetMCParticleListMap ()
 

Private Member Functions

void UpdateG4TrackIDRange (std::pair< int, int >, size_t)
 

Static Private Member Functions

static sim::SimEnergyDeposit offsetSimEnergyDepositTrackID (sim::SimEnergyDeposit const &, int)
 
static sim::AuxDetHit offsetAuxDetHitTrackID (sim::AuxDetHit const &, int)
 
static sim::ParticleAncestryMap offsetParticleAncestryMapTrackID (sim::ParticleAncestryMap const &, int)
 

Private Attributes

std::vector< int > fG4TrackIDOffsets
 
std::vector< std::pair< int, int > > fG4TrackIDRanges
 
std::vector< std::vector< size_t > > fMCParticleListMap
 

Detailed Description

Definition at line 29 of file MergeSimSources.h.

Constructor & Destructor Documentation

sim::MergeSimSourcesUtility::MergeSimSourcesUtility ( std::vector< int > const &  )

Title: MergeSimSources Utility Class Author: Wes Ketchum (wketc.nosp@m.hum@.nosp@m.lanl..nosp@m.gov)

Description: Class that merges different simulation sources together to created a combined sim list. Typically just merges vectors/maps/etc together. But, if anything as a G4 trackID, applies a user-defined offset to those IDs.

Definition at line 18 of file MergeSimSources.cxx.

References Reset().

19  : fG4TrackIDOffsets(offsets)
20 {
21  Reset();
22 }
std::vector< int > fG4TrackIDOffsets

Member Function Documentation

const std::vector<std::vector<size_t> >& sim::MergeSimSourcesUtility::GetMCParticleListMap ( )
inline

Definition at line 65 of file MergeSimSources.h.

References fMCParticleListMap.

65 { return fMCParticleListMap; }
std::vector< std::vector< size_t > > fMCParticleListMap
void sim::MergeSimSourcesUtility::MergeAuxDetHits ( std::vector< sim::AuxDetHit > &  ,
const std::vector< sim::AuxDetHit > &  ,
size_t   
) const

Definition at line 190 of file MergeSimSources.cxx.

References util::begin(), util::end(), fG4TrackIDOffsets, and offsetAuxDetHitTrackID().

193 {
194 
195  int const offset = fG4TrackIDOffsets.at(source_index);
196  auto const offsetAuxDetHitID = [offset](sim::AuxDetHit const& adh) {
198  };
199 
200  dest.reserve(dest.size() + src.size());
201  std::transform(begin(src), end(src), back_inserter(dest), offsetAuxDetHitID);
202 }
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
std::vector< int > fG4TrackIDOffsets
static sim::AuxDetHit offsetAuxDetHitTrackID(sim::AuxDetHit const &, int)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
void sim::MergeSimSourcesUtility::MergeAuxDetSimChannels ( std::vector< sim::AuxDetSimChannel > &  merged_vector,
const std::vector< sim::AuxDetSimChannel > &  input_vector,
size_t  source_index 
)

Definition at line 95 of file MergeSimSources.cxx.

References util::abs(), fG4TrackIDOffsets, and UpdateG4TrackIDRange().

99 {
100  if (source_index >= fG4TrackIDOffsets.size())
101  std::runtime_error("ERROR in MergeSimSourcesUtility: Source index out of range!");
102 
103  merged_vector.reserve(merged_vector.size() + input_vector.size());
104 
105  std::pair<int, int> range_trackID(std::numeric_limits<int>::max(),
106  std::numeric_limits<int>::min());
107 
108  for (auto const& simchannel : input_vector) {
110  std::find(merged_vector.begin(), merged_vector.end(), simchannel);
111 
112  if (it == merged_vector.end()) {
113  merged_vector.emplace_back(simchannel.AuxDetID(), simchannel.AuxDetSensitiveID());
114  it = merged_vector.end() - 1;
115  }
116 
117  // re-make the AuxDetSimChannel with both pairs of AuxDetIDEs
118  int offset = fG4TrackIDOffsets[source_index];
119  std::vector<sim::AuxDetIDE> all_ides = it->AuxDetIDEs();
120  for (const sim::AuxDetIDE& ide : simchannel.AuxDetIDEs()) {
121  all_ides.emplace_back(ide, offset);
122 
123  auto tid = std::abs(ide.trackID) + offset;
124 
125  if (tid < range_trackID.first) range_trackID.first = tid;
126  if (tid > range_trackID.second) range_trackID.second = tid;
127  }
128 
129  *it = sim::AuxDetSimChannel(
130  simchannel.AuxDetID(), std::move(all_ides), simchannel.AuxDetSensitiveID());
131  }
132 
133  UpdateG4TrackIDRange(range_trackID, source_index);
134 }
intermediate_table::iterator iterator
void UpdateG4TrackIDRange(std::pair< int, int >, size_t)
constexpr auto abs(T v)
Returns the absolute value of the argument.
Collection of particles crossing one auxiliary detector cell.
std::vector< int > fG4TrackIDOffsets
MC truth information to make RawDigits and do back tracking.
void sim::MergeSimSourcesUtility::MergeMCParticles ( std::vector< simb::MCParticle > &  merged_vector,
const std::vector< simb::MCParticle > &  input_vector,
size_t  source_index 
)

Definition at line 34 of file MergeSimSources.cxx.

References util::abs(), fG4TrackIDOffsets, fMCParticleListMap, and UpdateG4TrackIDRange().

38 {
39 
40  if (source_index >= fG4TrackIDOffsets.size())
41  std::runtime_error("ERROR in MergeSimSourcesUtility: Source index out of range!");
42 
43  fMCParticleListMap[source_index].resize(input_vector.size());
44  merged_vector.reserve(merged_vector.size() + input_vector.size());
45 
46  std::pair<int, int> range_trackID(std::numeric_limits<int>::max(),
47  std::numeric_limits<int>::min());
48 
49  for (size_t i_p = 0; i_p < input_vector.size(); i_p++) {
50  merged_vector.emplace_back(input_vector[i_p], fG4TrackIDOffsets[source_index]);
51 
52  fMCParticleListMap[source_index][i_p] = merged_vector.size() - 1;
53 
54  if (std::abs(merged_vector.back().TrackId()) < range_trackID.first)
55  range_trackID.first = std::abs(merged_vector.back().TrackId());
56  if (std::abs(merged_vector.back().TrackId()) > range_trackID.second)
57  range_trackID.second = std::abs(merged_vector.back().TrackId());
58  }
59 
60  UpdateG4TrackIDRange(range_trackID, source_index);
61 }
void UpdateG4TrackIDRange(std::pair< int, int >, size_t)
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::vector< int > fG4TrackIDOffsets
std::vector< std::vector< size_t > > fMCParticleListMap
void sim::MergeSimSourcesUtility::MergeParticleAncestryMaps ( std::vector< sim::ParticleAncestryMap > &  ,
const sim::ParticleAncestryMap ,
size_t   
) const

Definition at line 204 of file MergeSimSources.cxx.

References fG4TrackIDOffsets, and offsetParticleAncestryMapTrackID().

208 {
209  const int offset = fG4TrackIDOffsets.at(source_index);
210 
211  dest.reserve(dest.size() + 1);
212  dest.push_back(offsetParticleAncestryMapTrackID(src, offset));
213 }
static sim::ParticleAncestryMap offsetParticleAncestryMapTrackID(sim::ParticleAncestryMap const &, int)
std::vector< int > fG4TrackIDOffsets
void sim::MergeSimSourcesUtility::MergeSimChannels ( std::vector< sim::SimChannel > &  merged_vector,
const std::vector< sim::SimChannel > &  input_vector,
size_t  source_index 
)

Definition at line 63 of file MergeSimSources.cxx.

References util::abs(), fG4TrackIDOffsets, and UpdateG4TrackIDRange().

66 {
67  if (source_index >= fG4TrackIDOffsets.size())
68  std::runtime_error("ERROR in MergeSimSourcesUtility: Source index out of range!");
69 
70  merged_vector.reserve(merged_vector.size() + input_vector.size());
71 
72  std::pair<int, int> range_trackID(std::numeric_limits<int>::max(),
73  std::numeric_limits<int>::min());
74 
75  for (auto const& simchannel : input_vector) {
77  std::find(merged_vector.begin(), merged_vector.end(), simchannel);
78 
79  if (it == merged_vector.end()) {
80  merged_vector.emplace_back(simchannel.Channel());
81  it = merged_vector.end() - 1;
82  }
83 
84  std::pair<int, int> thisrange =
85  it->MergeSimChannel(simchannel, fG4TrackIDOffsets[source_index]);
86  if (std::abs(thisrange.first) < std::abs(range_trackID.first))
87  range_trackID.first = std::abs(thisrange.first);
88  if (std::abs(thisrange.second) > std::abs(range_trackID.second))
89  range_trackID.second = std::abs(thisrange.second);
90  }
91 
92  UpdateG4TrackIDRange(range_trackID, source_index);
93 }
intermediate_table::iterator iterator
void UpdateG4TrackIDRange(std::pair< int, int >, size_t)
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::vector< int > fG4TrackIDOffsets
void sim::MergeSimSourcesUtility::MergeSimEnergyDeposits ( std::vector< sim::SimEnergyDeposit > &  ,
const std::vector< sim::SimEnergyDeposit > &  ,
size_t   
) const

Definition at line 175 of file MergeSimSources.cxx.

References util::begin(), edep, util::end(), fG4TrackIDOffsets, and offsetSimEnergyDepositTrackID().

179 {
180 
181  int const offset = fG4TrackIDOffsets.at(source_index);
182  auto const offsetEDepID = [offset](sim::SimEnergyDeposit const& edep) {
184  };
185 
186  dest.reserve(dest.size() + src.size());
187  std::transform(begin(src), end(src), back_inserter(dest), offsetEDepID);
188 }
static sim::SimEnergyDeposit offsetSimEnergyDepositTrackID(sim::SimEnergyDeposit const &, int)
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
std::vector< int > fG4TrackIDOffsets
Double_t edep
Definition: macro.C:13
Energy deposition in the active material.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
void sim::MergeSimSourcesUtility::MergeSimPhotons ( std::vector< sim::SimPhotons > &  merged_vector,
const std::vector< sim::SimPhotons > &  input_vector 
)

Definition at line 136 of file MergeSimSources.cxx.

138 {
139 
140  merged_vector.reserve(merged_vector.size() + input_vector.size());
141 
142  for (auto const& simphotons : input_vector) {
144  std::find(merged_vector.begin(), merged_vector.end(), simphotons);
145 
146  if (it == merged_vector.end()) {
147  merged_vector.emplace_back(simphotons.OpChannel());
148  it = merged_vector.end() - 1;
149  }
150 
151  *it += simphotons;
152  }
153 }
intermediate_table::iterator iterator
void sim::MergeSimSourcesUtility::MergeSimPhotonsLite ( std::vector< sim::SimPhotonsLite > &  merged_vector,
const std::vector< sim::SimPhotonsLite > &  input_vector 
)

Definition at line 155 of file MergeSimSources.cxx.

158 {
159 
160  merged_vector.reserve(merged_vector.size() + input_vector.size());
161 
162  for (auto const& simphotons : input_vector) {
164  std::find(merged_vector.begin(), merged_vector.end(), simphotons);
165 
166  if (it == merged_vector.end()) {
167  merged_vector.emplace_back(simphotons.OpChannel);
168  it = merged_vector.end() - 1;
169  }
170 
171  *it += simphotons;
172  }
173 }
intermediate_table::iterator iterator
sim::AuxDetHit sim::MergeSimSourcesUtility::offsetAuxDetHitTrackID ( sim::AuxDetHit const &  adh,
int  offset 
)
staticprivate

Definition at line 271 of file MergeSimSources.cxx.

References sim::AuxDetHit::GetEnergyDeposited(), sim::AuxDetHit::GetEntryT(), sim::AuxDetHit::GetEntryX(), sim::AuxDetHit::GetEntryY(), sim::AuxDetHit::GetEntryZ(), sim::AuxDetHit::GetExitMomentumX(), sim::AuxDetHit::GetExitMomentumY(), sim::AuxDetHit::GetExitMomentumZ(), sim::AuxDetHit::GetExitT(), sim::AuxDetHit::GetExitX(), sim::AuxDetHit::GetExitY(), sim::AuxDetHit::GetExitZ(), sim::AuxDetHit::GetID(), and sim::AuxDetHit::GetTrackID().

Referenced by MergeAuxDetHits().

273 {
274 
275  auto tid = (adh.GetTrackID() >= 0) ? (adh.GetTrackID() + offset) : (adh.GetTrackID() - offset);
276 
277  return sim::AuxDetHit{
278  adh.GetID(), // copy number
279  tid, // g4 track id
280  adh.GetEnergyDeposited(),
281  adh.GetEntryX(),
282  adh.GetEntryY(),
283  adh.GetEntryZ(),
284  adh.GetEntryT(),
285  adh.GetExitX(),
286  adh.GetExitY(),
287  adh.GetExitZ(),
288  adh.GetExitT(),
289  adh.GetExitMomentumX(),
290  adh.GetExitMomentumY(),
291  adh.GetExitMomentumZ(),
292  };
293 } // sim::MergeSimSourcesUtility::offsetAuxDetHitTrackID()
unsigned int GetID() const
Definition: AuxDetHit.h:123
sim::ParticleAncestryMap sim::MergeSimSourcesUtility::offsetParticleAncestryMapTrackID ( sim::ParticleAncestryMap const &  pam,
int  offset 
)
staticprivate

Definition at line 295 of file MergeSimSources.cxx.

References sim::ParticleAncestryMap::GetMap().

Referenced by MergeParticleAncestryMaps().

298 {
299  std::map<int, std::set<int>> newMap;
300 
301  for (auto const& [ancestor, descendants] : pam.GetMap()) {
302  const int newAnc = (ancestor >= 0) ? ancestor + offset : ancestor - offset;
303 
304  for (auto const& descendant : descendants) {
305  const int newDesc = (descendant >= 0) ? descendant + offset : descendant - offset;
306  newMap[newAnc].insert(newDesc);
307  }
308  }
309 
310  return sim::ParticleAncestryMap(newMap);
311 }
sim::SimEnergyDeposit sim::MergeSimSourcesUtility::offsetSimEnergyDepositTrackID ( sim::SimEnergyDeposit const &  edep,
int  offset 
)
staticprivate

Definition at line 247 of file MergeSimSources.cxx.

References sim::SimEnergyDeposit::End(), sim::SimEnergyDeposit::Energy(), sim::SimEnergyDeposit::NumElectrons(), sim::SimEnergyDeposit::NumPhotons(), sim::SimEnergyDeposit::OrigTrackID(), sim::SimEnergyDeposit::PdgCode(), sim::SimEnergyDeposit::ScintYieldRatio(), sim::SimEnergyDeposit::Start(), sim::SimEnergyDeposit::T0(), sim::SimEnergyDeposit::T1(), and sim::SimEnergyDeposit::TrackID().

Referenced by MergeSimEnergyDeposits().

250 {
251 
252  auto tid = (edep.TrackID() >= 0) ? (edep.TrackID() + offset) : (edep.TrackID() - offset);
253  auto orig_tid =
254  (edep.OrigTrackID() >= 0) ? (edep.OrigTrackID() + offset) : (edep.OrigTrackID() - offset);
255 
256  return sim::SimEnergyDeposit{
257  edep.NumPhotons(), // np
258  edep.NumElectrons(), // ne
259  edep.ScintYieldRatio(), // sy
260  edep.Energy(), // e
261  edep.Start(), // start
262  edep.End(), // end
263  edep.T0(), // t0
264  edep.T1(), // t1
265  tid, // id
266  edep.PdgCode(), // pdg
267  orig_tid // orig id
268  };
269 } // sim::MergeSimSourcesUtility::offsetTrackID()
Double_t edep
Definition: macro.C:13
Energy deposition in the active material.
void sim::MergeSimSourcesUtility::Reset ( )

Definition at line 24 of file MergeSimSources.cxx.

References fG4TrackIDOffsets, fG4TrackIDRanges, and fMCParticleListMap.

Referenced by MergeSimSourcesUtility().

25 {
26  fG4TrackIDRanges.clear();
27  fG4TrackIDRanges.resize(
28  fG4TrackIDOffsets.size(),
29  std::make_pair(std::numeric_limits<int>::max(), std::numeric_limits<int>::min()));
30  fMCParticleListMap.clear();
31  fMCParticleListMap.resize(fG4TrackIDOffsets.size(), std::vector<size_t>());
32 }
std::vector< std::pair< int, int > > fG4TrackIDRanges
std::vector< int > fG4TrackIDOffsets
std::vector< std::vector< size_t > > fMCParticleListMap
void sim::MergeSimSourcesUtility::UpdateG4TrackIDRange ( std::pair< int, int >  newrange,
size_t  source_index 
)
private

Definition at line 215 of file MergeSimSources.cxx.

References fG4TrackIDOffsets, and fG4TrackIDRanges.

Referenced by MergeAuxDetSimChannels(), MergeMCParticles(), and MergeSimChannels().

217 {
218  if (source_index >= fG4TrackIDOffsets.size())
219  std::runtime_error("ERROR in MergeSimSourcesUtility: Source index out of range!");
220 
221  if (newrange.first >= fG4TrackIDRanges[source_index].first &&
222  newrange.second <= fG4TrackIDRanges[source_index].second)
223  return;
224 
225  for (size_t i = 0; i < fG4TrackIDRanges.size(); i++) {
226  if (i == source_index) continue;
227 
228  if ((newrange.first >= fG4TrackIDRanges[i].first &&
229  newrange.first <= fG4TrackIDRanges[i].second) ||
230  (newrange.second >= fG4TrackIDRanges[i].first &&
231  newrange.second <= fG4TrackIDRanges[i].second)) {
232  std::stringstream ss;
233  ss << "ERROR in MergeSimSourcesUtility: Source trackIDs overlap!"
234  << "\n\t" << i << "\t" << fG4TrackIDRanges[i].first << " " << fG4TrackIDRanges[i].second
235  << "\n\t"
236  << "n\t" << newrange.first << " " << newrange.second;
237  throw std::runtime_error(ss.str());
238  }
239  }
240 
241  if (newrange.first < fG4TrackIDRanges[source_index].first)
242  fG4TrackIDRanges[source_index].first = newrange.first;
243  if (newrange.second > fG4TrackIDRanges[source_index].second)
244  fG4TrackIDRanges[source_index].second = newrange.second;
245 }
std::vector< std::pair< int, int > > fG4TrackIDRanges
std::vector< int > fG4TrackIDOffsets

Member Data Documentation

std::vector<int> sim::MergeSimSourcesUtility::fG4TrackIDOffsets
private
std::vector<std::pair<int, int> > sim::MergeSimSourcesUtility::fG4TrackIDRanges
private

Definition at line 69 of file MergeSimSources.h.

Referenced by Reset(), and UpdateG4TrackIDRange().

std::vector<std::vector<size_t> > sim::MergeSimSourcesUtility::fMCParticleListMap
private

Definition at line 71 of file MergeSimSources.h.

Referenced by GetMCParticleListMap(), MergeMCParticles(), and Reset().


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