Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
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
 
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)
 

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 25 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.

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 57 of file MergeSimSources.h.

57 { 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 188 of file MergeSimSources.cxx.

192  {
193 
194  int const offset = fG4TrackIDOffsets.at(source_index);
195  auto const offsetAuxDetHitID = [offset](sim::AuxDetHit const& adh)
197 
198  dest.reserve(dest.size() + src.size());
199  std::transform(begin(src), end(src), back_inserter(dest), offsetAuxDetHitID);
200 
201 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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:72
void sim::MergeSimSourcesUtility::MergeAuxDetSimChannels ( std::vector< sim::AuxDetSimChannel > &  merged_vector,
const std::vector< sim::AuxDetSimChannel > &  input_vector,
size_t  source_index 
)

Definition at line 94 of file MergeSimSources.cxx.

97 {
98  if(source_index >= fG4TrackIDOffsets.size())
99  std::runtime_error("ERROR in MergeSimSourcesUtility: Source index out of range!");
100 
101  merged_vector.reserve( merged_vector.size() + input_vector.size() );
102 
103  std::pair<int,int> range_trackID(std::numeric_limits<int>::max(),
105 
106  for(auto const& simchannel : input_vector){
107  std::vector<sim::AuxDetSimChannel>::iterator it = std::find(merged_vector.begin(),merged_vector.end(),simchannel);
108 
109  if(it==merged_vector.end()){
110  merged_vector.emplace_back(simchannel.AuxDetID(), simchannel.AuxDetSensitiveID());
111  it = merged_vector.end() - 1;
112  }
113 
114  // re-make the AuxDetSimChannel with both pairs of AuxDetIDEs
115  int offset = fG4TrackIDOffsets[source_index];
116  std::vector<sim::AuxDetIDE> all_ides = it->AuxDetIDEs();
117  for (const sim::AuxDetIDE &ide: simchannel.AuxDetIDEs()) {
118  all_ides.emplace_back(ide, offset);
119 
120  auto tid = std::abs(ide.trackID)+offset;
121 
122  if( tid < range_trackID.first )
123  range_trackID.first = tid;
124  if( tid > range_trackID.second )
125  range_trackID.second = tid;
126  }
127 
128 
129  *it = sim::AuxDetSimChannel(simchannel.AuxDetID(), std::move(all_ides), simchannel.AuxDetSensitiveID());
130  }
131 
132  UpdateG4TrackIDRange(range_trackID,source_index);
133 }
intermediate_table::iterator iterator
void UpdateG4TrackIDRange(std::pair< int, int >, size_t)
Collection of particles crossing one auxiliary detector cell.
T abs(T value)
std::vector< int > fG4TrackIDOffsets
def move(depos, offset)
Definition: depos.py:107
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
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 35 of file MergeSimSources.cxx.

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(),
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 
61  UpdateG4TrackIDRange(range_trackID,source_index);
62 }
void UpdateG4TrackIDRange(std::pair< int, int >, size_t)
T abs(T value)
std::vector< int > fG4TrackIDOffsets
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
std::vector< std::vector< size_t > > fMCParticleListMap
void sim::MergeSimSourcesUtility::MergeSimChannels ( std::vector< sim::SimChannel > &  merged_vector,
const std::vector< sim::SimChannel > &  input_vector,
size_t  source_index 
)

Definition at line 64 of file MergeSimSources.cxx.

67 {
68  if(source_index >= fG4TrackIDOffsets.size())
69  std::runtime_error("ERROR in MergeSimSourcesUtility: Source index out of range!");
70 
71  merged_vector.reserve( merged_vector.size() + input_vector.size() );
72 
73  std::pair<int,int> range_trackID(std::numeric_limits<int>::max(),
75 
76  for(auto const& simchannel : input_vector){
77  std::vector<sim::SimChannel>::iterator it = 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 = it->MergeSimChannel(simchannel,fG4TrackIDOffsets[source_index]);
85  if( std::abs(thisrange.first) < std::abs(range_trackID.first))
86  range_trackID.first = std::abs(thisrange.first);
87  if( std::abs(thisrange.second) > std::abs(range_trackID.second))
88  range_trackID.second = std::abs(thisrange.second);
89  }
90 
91  UpdateG4TrackIDRange(range_trackID,source_index);
92 }
intermediate_table::iterator iterator
void UpdateG4TrackIDRange(std::pair< int, int >, size_t)
T abs(T value)
std::vector< int > fG4TrackIDOffsets
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
void sim::MergeSimSourcesUtility::MergeSimEnergyDeposits ( std::vector< sim::SimEnergyDeposit > &  ,
const std::vector< sim::SimEnergyDeposit > &  ,
size_t   
) const

Definition at line 172 of file MergeSimSources.cxx.

176  {
177 
178  int const offset = fG4TrackIDOffsets.at(source_index);
179  auto const offsetEDepID = [offset](sim::SimEnergyDeposit const& edep)
181 
182  dest.reserve(dest.size() + src.size());
183  std::transform(begin(src), end(src), back_inserter(dest), offsetEDepID);
184 
185 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
static sim::SimEnergyDeposit offsetSimEnergyDepositTrackID(sim::SimEnergyDeposit const &, int)
std::vector< int > fG4TrackIDOffsets
Energy deposition in the active material.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
void sim::MergeSimSourcesUtility::MergeSimPhotons ( std::vector< sim::SimPhotons > &  merged_vector,
const std::vector< sim::SimPhotons > &  input_vector 
)

Definition at line 135 of file MergeSimSources.cxx.

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

Definition at line 153 of file MergeSimSources.cxx.

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

Definition at line 258 of file MergeSimSources.cxx.

259 {
260 
261  auto tid = (adh.GetTrackID()>=0) ? (adh.GetTrackID() + offset) : (adh.GetTrackID() - offset);
262 
263  return sim::AuxDetHit{
264  adh.GetID(), // copy number
265  tid, // g4 track id
266  adh.GetEnergyDeposited(),
267  adh.GetEntryX(),
268  adh.GetEntryY(),
269  adh.GetEntryZ(),
270  adh.GetEntryT(),
271  adh.GetExitX(),
272  adh.GetExitY(),
273  adh.GetExitZ(),
274  adh.GetExitT(),
275  adh.GetExitMomentumX(),
276  adh.GetExitMomentumY(),
277  adh.GetExitMomentumZ(),
278  };
279 } // sim::MergeSimSourcesUtility::offsetAuxDetHitTrackID()
unsigned int GetID() const
Definition: AuxDetHit.h:177
sim::SimEnergyDeposit sim::MergeSimSourcesUtility::offsetSimEnergyDepositTrackID ( sim::SimEnergyDeposit const &  edep,
int  offset 
)
staticprivate

Definition at line 237 of file MergeSimSources.cxx.

238 {
239 
240  auto tid = (edep.TrackID()>=0) ? (edep.TrackID() + offset) : (edep.TrackID() - offset);
241 
242  return sim::SimEnergyDeposit{
243  edep.NumPhotons(), // np
244  edep.NumElectrons(), // ne
245  edep.ScintYieldRatio(), // sy
246  edep.Energy(), // e
247  edep.Start(), // start
248  edep.End(), // end
249  edep.T0(), // t0
250  edep.T1(), // t1
251  tid, // id
252  edep.PdgCode() // pdg
253  };
254 } // sim::MergeSimSourcesUtility::offsetTrackID()
Energy deposition in the active material.
void sim::MergeSimSourcesUtility::Reset ( void  )

Definition at line 24 of file MergeSimSources.cxx.

25 {
26  fG4TrackIDRanges.clear();
27  fG4TrackIDRanges.resize(fG4TrackIDOffsets.size(),
28  std::make_pair(std::numeric_limits<int>::max(),
30  fMCParticleListMap.clear();
32  std::vector<size_t>());
33 }
std::vector< int > fG4TrackIDOffsets
std::vector< std::pair< int, int > > fG4TrackIDRanges
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
std::vector< std::vector< size_t > > fMCParticleListMap
void sim::MergeSimSourcesUtility::UpdateG4TrackIDRange ( std::pair< int, int >  newrange,
size_t  source_index 
)
private

Definition at line 204 of file MergeSimSources.cxx.

205 {
206  if(source_index >= fG4TrackIDOffsets.size())
207  std::runtime_error("ERROR in MergeSimSourcesUtility: Source index out of range!");
208 
209  if( newrange.first >= fG4TrackIDRanges[source_index].first &&
210  newrange.second <= fG4TrackIDRanges[source_index].second)
211  return;
212 
213  for(size_t i=0; i<fG4TrackIDRanges.size(); i++){
214  if(i==source_index) continue;
215 
216  if( (newrange.first >= fG4TrackIDRanges[i].first && newrange.first <= fG4TrackIDRanges[i].second) ||
217  (newrange.second >= fG4TrackIDRanges[i].first && newrange.second <= fG4TrackIDRanges[i].second) )
218  {
219  std::stringstream ss;
220  ss << "ERROR in MergeSimSourcesUtility: Source trackIDs overlap!"
221  << "\n\t" << i << "\t" << fG4TrackIDRanges[i].first << " " << fG4TrackIDRanges[i].second
222  << "\n\t" << "n\t" << newrange.first << " " << newrange.second;
223  throw std::runtime_error(ss.str());
224  }
225  }
226 
227  if(newrange.first < fG4TrackIDRanges[source_index].first)
228  fG4TrackIDRanges[source_index].first = newrange.first;
229  if(newrange.second > fG4TrackIDRanges[source_index].second)
230  fG4TrackIDRanges[source_index].second = newrange.second;
231 
232 
233 }
std::vector< int > fG4TrackIDOffsets
std::vector< std::pair< int, int > > fG4TrackIDRanges

Member Data Documentation

std::vector<int> sim::MergeSimSourcesUtility::fG4TrackIDOffsets
private

Definition at line 61 of file MergeSimSources.h.

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

Definition at line 62 of file MergeSimSources.h.

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

Definition at line 64 of file MergeSimSources.h.


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