LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
OpDetPhotonTable.cxx
Go to the documentation of this file.
1 //
6 // Implementation of the OpDetPhotonTable class.
7 //
8 // See comments in the OpDetPhotonTable.h file.
9 //
10 // Ben Jones, MIT, 11/12/12
11 //
12 
16 
18 
19 namespace larg4 {
21 
22  //--------------------------------------------------
24  {
25  fDetectedPhotons.clear();
27  }
29 
30  //--------------------------------------------------
32  {
33  if (!TheOpDetPhotonTable) { TheOpDetPhotonTable = new OpDetPhotonTable; }
34  return TheOpDetPhotonTable;
35  }
36 
37  //--------------------------------------------------
38  void OpDetPhotonTable::AddPhoton(size_t opchannel, sim::OnePhoton&& photon, bool Reflected)
39  {
40  if (opchannel >= fDetectedPhotons.size()) {
41 
42  std::cerr << "<<" << __PRETTY_FUNCTION__ << ">>"
43  << "\033[93m"
44  << "Invalid channel: " << opchannel << "\033[00m" << std::endl;
45  throw std::exception();
46  }
47  if (!Reflected)
48  fDetectedPhotons.at(opchannel).push_back(photon);
49  else
50  fReflectedDetectedPhotons.at(opchannel).push_back(photon);
51  }
52 
53  //--------------------------------------------------
54  void OpDetPhotonTable::AddLitePhoton(int opchannel, int time, int nphotons, bool Reflected)
55  {
56  if (!Reflected)
57  fLitePhotons[opchannel][time] += nphotons;
58  else
59  fReflectedLitePhotons[opchannel][time] += nphotons;
60  }
61 
62  //--------------------------------------------------
63  void OpDetPhotonTable::AddPhoton(std::map<int, std::map<int, int>>* StepPhotonTable,
64  bool Reflected)
65  {
66  for (auto it = StepPhotonTable->begin(); it != StepPhotonTable->end(); it++) {
67  for (auto in_it = it->second.begin(); in_it != it->second.end(); in_it++) {
68  if (!Reflected)
69  fLitePhotons[it->first][in_it->first] += in_it->second;
70  else
71  fReflectedLitePhotons[it->first][in_it->first] += in_it->second;
72  }
73  }
74  }
75 
76  //--------------------------------------------------- cOpDetBacktrackerRecord population
77  //J Stock. 11 Oct 2016
79  {
80  // std::cout << "DEBUG: Adding to " << (Reflected?"Reflected":"Direct") << " cOpDetBTR" << std::endl;
81  if (!Reflected)
83  else
86  }
87 
88  //--------------------------------------------------- cOpDetBacktrackerRecord population
90  std::vector<sim::OpDetBacktrackerRecord>& RecordsCol,
91  std::map<int, int>& ChannelMap,
93  {
94  int iChan = soc.OpDetNum();
95  std::map<int, int>::iterator channelPosition = ChannelMap.find(iChan);
96  if (channelPosition == ChannelMap.end()) {
97  ChannelMap[iChan] = RecordsCol.size();
98  RecordsCol.emplace_back(std::move(soc));
99  }
100  else {
101  unsigned int idtest = channelPosition->second;
102  auto const& timePDclockSDPsMap = soc.timePDclockSDPsMap();
103  for (auto const& timePDclockSDP : timePDclockSDPsMap) {
104  for (auto const& sdp : timePDclockSDP.second) {
105  double xyz[3] = {sdp.x, sdp.y, sdp.z};
106  RecordsCol.at(idtest).AddScintillationPhotons(
107  sdp.trackID, timePDclockSDP.first, sdp.numPhotons, xyz, sdp.energy);
108  } //end sdp : timesdp.second
109  } //end const timesdp : timeSDPMap
110  } // if chanPos == cOpChan else
111 
112  // std::cout << "DEBUG: Add to " << iChan << " to cOpDetBTR. Now " << RecordsCol.size() << " in size " << std::endl;
113  } //END void OpDetPhotonTable::AdOpDetBacktrackerRecords
114 
115  //--------------------------------------------------
116  // cOpDetBacktrackerRecord return.
117  std::vector<sim::OpDetBacktrackerRecord> OpDetPhotonTable::YieldOpDetBacktrackerRecords()
118  {
119  // we give the result to the caller, and don't retain it
120  std::vector<sim::OpDetBacktrackerRecord> result;
121  // std::cout << "DEBUG: result.size() = " << result.size() << std::endl;
122  // std::cout << "DEBUG: cOpDetBTRCol.size() = " << cOpDetBacktrackerRecordsCol.size() << std::endl;
123  std::swap(result, cOpDetBacktrackerRecordsCol);
124  // std::cout << "DEBUG: std::swap(result, cOpDetBacktrackerRecordsCol);" << std::endl;
125  // std::cout << "DEBUG: result.size() = " << result.size() << std::endl;
126  // std::cout << "DEBUG: cOpDetBTRCol.size() = " << cOpDetBacktrackerRecordsCol.size() << std::endl;
127  cOpChannelToSOCMap.clear();
128  return result;
129  } // OpDetPhotonTable::YieldOpDetBacktrackerRecords()
130 
131  //--------------------------------------------------
132  // cReflectedOpDetBacktrackerRecord return.
133  std::vector<sim::OpDetBacktrackerRecord> OpDetPhotonTable::YieldReflectedOpDetBacktrackerRecords()
134  {
135  // we give the result to the caller, and don't retain it
136  std::vector<sim::OpDetBacktrackerRecord> result;
137  // std::cout << "DEBUG: result.size() = " << result.size() << std::endl;
138  // std::cout << "DEBUG: cReflOpDetBTRCol.size() = " << cReflectedOpDetBacktrackerRecordsCol.size() << std::endl;
139  std::swap(result, cReflectedOpDetBacktrackerRecordsCol);
140  // std::cout << "DEBUG: result.size() = " << result.size() << std::endl;
141  // std::cout << "DEBUG: cReflOpDetBTRCol.size() = " << cReflectedOpDetBacktrackerRecordsCol.size() << std::endl;
143  return result;
144  } // OpDetPhotonTable::YieldOpDetBacktrackerRecords()
145 
146  //--------------------------------------------------
147  void OpDetPhotonTable::ClearTable(const size_t nch)
148  {
149  if (fDetectedPhotons.size() != nch) fDetectedPhotons.resize(nch);
150  for (size_t i = 0; i < fDetectedPhotons.size(); ++i) {
151  fDetectedPhotons.at(i).clear();
152  fDetectedPhotons.at(i).SetChannel(i);
153  //fDetectedPhotons.at(i).reserve(10000); // Just a guess on minimum # photons
154  }
155  if (fReflectedDetectedPhotons.size() != nch) fReflectedDetectedPhotons.resize(nch);
156  for (size_t i = 0; i < fReflectedDetectedPhotons.size(); ++i) {
157  fReflectedDetectedPhotons.at(i).clear();
158  fReflectedDetectedPhotons.at(i).SetChannel(i);
159  //fDetectedPhotons.at(i).reserve(10000); // Just a guess on minimum # photons
160  }
161 
162  for (auto it = fLitePhotons.begin(); it != fLitePhotons.end(); ++it)
163  (it->second).clear();
164  for (auto it = fReflectedLitePhotons.begin(); it != fReflectedLitePhotons.end(); ++it)
165  (it->second).clear();
166  fLitePhotons.clear();
167  fReflectedLitePhotons.clear();
168  }
169 
170  //--------------------------------------------------
172  {
173  if (opchannel >= fDetectedPhotons.size()) {
174  std::cerr << "<<" << __PRETTY_FUNCTION__ << ">>"
175  << "Invalid channel Number: " << opchannel << std::endl;
176  }
177  return fDetectedPhotons.at(opchannel);
178  }
179 
180  //--------------------------------------------------
182  {
183  if (opchannel >= fReflectedDetectedPhotons.size()) {
184  std::cerr << "<<" << __PRETTY_FUNCTION__ << ">>"
185  << "Invalid channel Number: " << opchannel << std::endl;
186  }
187  return fReflectedDetectedPhotons.at(opchannel);
188  }
189 
190  //--------------------------------------------------
192  int n_elec,
193  double scint_yield,
194  double energy,
195  float start_x,
196  float start_y,
197  float start_z,
198  float end_x,
199  float end_y,
200  float end_z,
201  double start_time,
202  double end_time,
203  int trackid,
204  int pdgcode,
205  int g4trackid,
206  std::string const& vol)
207  {
208  fSimEDepCol[vol].emplace_back(n_photon,
209  n_elec,
210  scint_yield,
211  energy,
212  geo::Point_t{start_x, start_y, start_z},
213  geo::Point_t{end_x, end_y, end_z},
214  start_time,
215  end_time,
216  trackid,
217  pdgcode,
218  g4trackid);
219  }
220 
221  //--------------------------------------------------
223  {
224  fSimEDepCol.clear();
225  }
226 
227  //--------------------------------------------------
228  std::unordered_map<std::string, std::vector<sim::SimEnergyDeposit>> const&
230  {
231  return fSimEDepCol;
232  }
233 
234  //--------------------------------------------------
235  std::unordered_map<std::string, std::vector<sim::SimEnergyDeposit>>
237  {
238  auto data{std::move(fSimEDepCol)};
240  return data;
241  }
242 
243 }
intermediate_table::iterator iterator
std::vector< sim::OpDetBacktrackerRecord > YieldReflectedOpDetBacktrackerRecords()
All information of a photon entering the sensitive optical detector volume.
Definition: SimPhotons.h:60
Geant4 interface.
OpDetPhotonTable * TheOpDetPhotonTable
std::unordered_map< std::string, std::vector< sim::SimEnergyDeposit > > YieldSimEnergyDeposits()
Yields the map of energy deposits by volume name, and resets the internal one.
sim::SimPhotons & GetReflectedPhotonsForOpChannel(size_t opchannel)
Energy deposited on a readout Optical Detector by simulated tracks.
sim::SimPhotons & GetPhotonsForOpChannel(size_t opchannel)
std::map< int, std::map< int, int > > fLitePhotons
Simulation objects for optical detectors.
int OpDetNum() const
Returns the readout Optical Detector this object describes.
std::unordered_map< std::string, std::vector< sim::SimEnergyDeposit > > const & GetSimEnergyDeposits() const
Returns the map of energy deposits by volume name.
void AddPhoton(size_t opchannel, sim::OnePhoton &&photon, bool Reflected=false)
std::vector< sim::OpDetBacktrackerRecord > cReflectedOpDetBacktrackerRecordsCol
std::vector< sim::SimPhotons > fReflectedDetectedPhotons
double energy
Definition: plottest35.C:25
void AddOpDetBacktrackerRecord(sim::OpDetBacktrackerRecord soc, bool Reflected=false)
void AddLitePhoton(int opchannel, int time, int nphotons, bool Reflected=false)
static OpDetPhotonTable * Instance(bool LitePhotons=false)
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
Collection of photons which recorded on one channel.
Definition: SimPhotons.h:127
std::vector< sim::OpDetBacktrackerRecord > YieldOpDetBacktrackerRecords()
std::unordered_map< std::string, std::vector< sim::SimEnergyDeposit > > fSimEDepCol
contains information for a single step in the detector simulation
std::vector< sim::OpDetBacktrackerRecord > cOpDetBacktrackerRecordsCol
void ClearTable(size_t nch=0)
void AddEnergyDeposit(int n_photon, int n_elec, double scint_yield, double energy, float start_x, float start_y, float start_z, float end_x, float end_y, float end_z, double start_time, double end_time, int trackid, int pdgcode, int g4trackid, std::string const &vol="EMPTY")
std::vector< sim::SimPhotons > fDetectedPhotons
std::map< int, std::map< int, int > > fReflectedLitePhotons
timePDclockSDPs_t const & timePDclockSDPsMap() const
Returns all the deposited energy information as stored.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::map< int, int > cOpChannelToSOCMap
std::map< int, int > cReflectedOpChannelToSOCMap