LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
MergeSimSources.cxx
Go to the documentation of this file.
1 
12 #include <algorithm>
13 #include <stdexcept>
14 #include <sstream>
15 
16 #include "MergeSimSources.h"
17 
19 {
20  fG4TrackIDOffsets = offsets;
21  Reset();
22 }
23 
25 {
26  fG4TrackIDRanges.resize(fG4TrackIDOffsets.size(),
27  std::make_pair(std::numeric_limits<int>::max(),
30  std::vector<size_t>());
31 }
32 
33 void sim::MergeSimSourcesUtility::MergeMCParticles( std::vector<simb::MCParticle>& merged_vector,
34  const std::vector<simb::MCParticle>& input_vector,
35  size_t source_index)
36 {
37 
38  if(source_index >= fG4TrackIDOffsets.size())
39  std::runtime_error("ERROR in MergeSimSourcesUtility: Source index out of range!");
40 
41  fMCParticleListMap[source_index].resize(input_vector.size());
42  merged_vector.reserve(merged_vector.size() + input_vector.size());
43 
44  std::pair<int,int> range_trackID(std::numeric_limits<int>::max(),
46 
47  for(size_t i_p=0; i_p<input_vector.size(); i_p++){
48  merged_vector.emplace_back(input_vector[i_p],fG4TrackIDOffsets[source_index]);
49 
50  fMCParticleListMap[source_index][i_p] = merged_vector.size() - 1;
51 
52  if(merged_vector.back().TrackId() < range_trackID.first)
53  range_trackID.first = merged_vector.back().TrackId();
54  if(merged_vector.back().TrackId() > range_trackID.second)
55  range_trackID.second = merged_vector.back().TrackId();
56 
57  }
58 
59  UpdateG4TrackIDRange(range_trackID,source_index);
60 }
61 
62 void sim::MergeSimSourcesUtility::MergeSimChannels(std::vector<sim::SimChannel>& merged_vector,
63  const std::vector<sim::SimChannel>& input_vector,
64  size_t source_index)
65 {
66  if(source_index >= fG4TrackIDOffsets.size())
67  std::runtime_error("ERROR in MergeSimSourcesUtility: Source index out of range!");
68 
69  merged_vector.reserve( merged_vector.size() + input_vector.size() );
70 
71  std::pair<int,int> range_trackID(std::numeric_limits<int>::max(),
73 
74  for(auto const& simchannel : input_vector){
75  std::vector<sim::SimChannel>::iterator it = std::find(merged_vector.begin(),merged_vector.end(),simchannel);
76 
77  if(it==merged_vector.end()){
78  merged_vector.emplace_back(simchannel.Channel());
79  it = merged_vector.end() - 1;
80  }
81 
82  std::pair<int,int> thisrange = it->MergeSimChannel(simchannel,fG4TrackIDOffsets[source_index]);
83  if(thisrange.first < range_trackID.first) range_trackID.first = thisrange.first;
84  if(thisrange.second > range_trackID.second) range_trackID.second = thisrange.second;
85  }
86 
87  UpdateG4TrackIDRange(range_trackID,source_index);
88 }
89 
90 void sim::MergeSimSourcesUtility::MergeAuxDetSimChannels(std::vector<sim::AuxDetSimChannel>& merged_vector,
91  const std::vector<sim::AuxDetSimChannel>& input_vector,
92  size_t source_index)
93 {
94  if(source_index >= fG4TrackIDOffsets.size())
95  std::runtime_error("ERROR in MergeSimSourcesUtility: Source index out of range!");
96 
97  merged_vector.reserve( merged_vector.size() + input_vector.size() );
98 
99  std::pair<int,int> range_trackID(std::numeric_limits<int>::max(),
101 
102  for(auto const& simchannel : input_vector){
103  std::vector<sim::AuxDetSimChannel>::iterator it = std::find(merged_vector.begin(),merged_vector.end(),simchannel);
104 
105  if(it==merged_vector.end()){
106  merged_vector.emplace_back(simchannel.AuxDetID(), simchannel.AuxDetSensitiveID());
107  it = merged_vector.end() - 1;
108  }
109 
110  std::pair<int,int> thisrange = it->MergeAuxDetSimChannel(simchannel,fG4TrackIDOffsets[source_index]);
111  if(thisrange.first < range_trackID.first) range_trackID.first = thisrange.first;
112  if(thisrange.second > range_trackID.second) range_trackID.second = thisrange.second;
113  }
114 
115  UpdateG4TrackIDRange(range_trackID,source_index);
116 }
117 
118 void sim::MergeSimSourcesUtility::MergeSimPhotons( std::vector<sim::SimPhotons>& merged_vector,
119  const std::vector<sim::SimPhotons>& input_vector)
120 {
121 
122  merged_vector.reserve( merged_vector.size() + input_vector.size() );
123 
124  for(auto const& simphotons : input_vector){
125  std::vector<sim::SimPhotons>::iterator it = std::find(merged_vector.begin(),merged_vector.end(),simphotons);
126 
127  if(it==merged_vector.end()){
128  merged_vector.emplace_back(simphotons.OpChannel());
129  it = merged_vector.end() - 1;
130  }
131 
132  *it += simphotons;
133  }
134 }
135 
136 void sim::MergeSimSourcesUtility::MergeSimPhotonsLite( std::vector<sim::SimPhotonsLite>& merged_vector,
137  const std::vector<sim::SimPhotonsLite>& input_vector)
138 {
139 
140  merged_vector.reserve( merged_vector.size() + input_vector.size() );
141 
142  for(auto const& simphotons : input_vector){
143  std::vector<sim::SimPhotonsLite>::iterator it = std::find(merged_vector.begin(),merged_vector.end(),simphotons);
144 
145  if(it==merged_vector.end()){
146  merged_vector.emplace_back(simphotons.OpChannel);
147  it = merged_vector.end() - 1;
148  }
149 
150  *it += simphotons;
151  }
152 }
153 
154 void sim::MergeSimSourcesUtility::UpdateG4TrackIDRange(std::pair<int,int> newrange, size_t source_index)
155 {
156  if(source_index >= fG4TrackIDOffsets.size())
157  std::runtime_error("ERROR in MergeSimSourcesUtility: Source index out of range!");
158 
159  if( newrange.first >= fG4TrackIDRanges[source_index].first &&
160  newrange.second <= fG4TrackIDRanges[source_index].second)
161  return;
162 
163  for(size_t i=0; i<fG4TrackIDRanges.size(); i++){
164  if(i==source_index) continue;
165 
166  if( (newrange.first >= fG4TrackIDRanges[i].first && newrange.first <= fG4TrackIDRanges[i].second) ||
167  (newrange.second >= fG4TrackIDRanges[i].first && newrange.second <= fG4TrackIDRanges[i].second) )
168  {
169  std::stringstream ss;
170  ss << "ERROR in MergeSimSourcesUtility: Source trackIDs overlap!"
171  << "\n\t" << i << "\t" << fG4TrackIDRanges[i].first << " " << fG4TrackIDRanges[i].second
172  << "\n\t" << "n\t" << newrange.first << " " << newrange.second;
173  throw std::runtime_error(ss.str());
174  }
175  }
176 
177  if(newrange.first < fG4TrackIDRanges[source_index].first)
178  fG4TrackIDRanges[source_index].first = newrange.first;
179  if(newrange.second > fG4TrackIDRanges[source_index].second)
180  fG4TrackIDRanges[source_index].second = newrange.second;
181 
182 
183 }
void MergeSimPhotonsLite(std::vector< sim::SimPhotonsLite > &, const std::vector< sim::SimPhotonsLite > &)
void MergeSimChannels(std::vector< sim::SimChannel > &, const std::vector< sim::SimChannel > &, size_t)
void UpdateG4TrackIDRange(std::pair< int, int >, size_t)
intermediate_table::iterator iterator
MergeSimSourcesUtility(std::vector< int > const &)
void MergeSimPhotons(std::vector< sim::SimPhotons > &, const std::vector< sim::SimPhotons > &)
Float_t ss
Definition: plot.C:23
void MergeAuxDetSimChannels(std::vector< sim::AuxDetSimChannel > &, const std::vector< sim::AuxDetSimChannel > &, size_t)
Int_t max
Definition: plot.C:27
std::vector< int > fG4TrackIDOffsets
std::vector< std::pair< int, int > > fG4TrackIDRanges
void MergeMCParticles(std::vector< simb::MCParticle > &, const std::vector< simb::MCParticle > &, size_t)
Int_t min
Definition: plot.C:26
std::vector< std::vector< size_t > > fMCParticleListMap