OpDetPhotonTable.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file OpDetPhotonTable.cxx
3 //
4 /// \author bjpjones@mit.edu
5 ////////////////////////////////////////////////////////////////////////
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 
31  //--------------------------------------------------
33  {
34  if(!TheOpDetPhotonTable){
35  TheOpDetPhotonTable = new OpDetPhotonTable;
36  }
37  return TheOpDetPhotonTable;
38  }
39 
40 
41 
42  //--------------------------------------------------
43  void OpDetPhotonTable::AddPhoton(size_t opchannel, sim::OnePhoton&& photon, bool Reflected)
44  {
45  if( opchannel >= fDetectedPhotons.size() ) {
46 
47  std::cerr << "<<" << __PRETTY_FUNCTION__ << ">>"
48  << "\033[93m"
49  << "Invalid channel: " << opchannel
50  << "\033[00m"
51  << std::endl;
52  throw std::exception();
53  }
54  if (!Reflected)
55  fDetectedPhotons.at(opchannel).push_back(photon);
56  else
57  fReflectedDetectedPhotons.at(opchannel).push_back(photon);
58  }
59 
60  //--------------------------------------------------
61  void OpDetPhotonTable::AddLitePhoton( int opchannel, int time, int nphotons, bool Reflected)
62  {
63  if (!Reflected)
64  fLitePhotons[opchannel][time] += nphotons;
65  else
66  fReflectedLitePhotons[opchannel][time] += nphotons;
67  }
68 
69  //--------------------------------------------------
70  void OpDetPhotonTable::AddPhoton(std::map<int, std::map<int, int>>* StepPhotonTable, bool Reflected)
71  {
72  for(auto it = StepPhotonTable->begin(); it!=StepPhotonTable->end(); it++)
73  {
74  for(auto in_it = it->second.begin(); in_it!=it->second.end(); in_it++)
75  {
76  if (!Reflected)
77  fLitePhotons[it->first][in_it->first]+= in_it->second;
78  else
79  fReflectedLitePhotons[it->first][in_it->first]+= in_it->second;
80  }
81  }
82  }
83 
84  //--------------------------------------------------- cOpDetBacktrackerRecord population
85  //J Stock. 11 Oct 2016
87 // std::cout << "DEBUG: Adding to " << (Reflected?"Reflected":"Direct") << " cOpDetBTR" << std::endl;
88  if (!Reflected)
90  else
92  }
93 
94  //--------------------------------------------------- cOpDetBacktrackerRecord population
95  void OpDetPhotonTable::AddOpDetBacktrackerRecord(std::vector< sim::OpDetBacktrackerRecord > & RecordsCol,
96  std::map<int, int> & ChannelMap,
98  int iChan = soc.OpDetNum();
99  std::map<int, int>::iterator channelPosition = ChannelMap.find(iChan);
100  if (channelPosition == ChannelMap.end() ){
101  ChannelMap[iChan] = RecordsCol.size();
102  RecordsCol.emplace_back(std::move(soc));
103  }else{
104  unsigned int idtest = channelPosition->second;
105  auto const& timePDclockSDPsMap = soc.timePDclockSDPsMap();
106  for(auto const& timePDclockSDP : timePDclockSDPsMap){
107  for(auto const& sdp : timePDclockSDP.second){
108  double xyz[3] = {sdp.x, sdp.y, sdp.z};
109  RecordsCol.at(idtest).AddScintillationPhotons(
110  sdp.trackID,
111  timePDclockSDP.first,
112  sdp.numPhotons,
113  xyz,
114  sdp.energy);
115  }//end sdp : timesdp.second
116  }//end const timesdp : timeSDPMap
117  }// if chanPos == cOpChan else
118 
119 
120 // std::cout << "DEBUG: Add to " << iChan << " to cOpDetBTR. Now " << RecordsCol.size() << " in size " << std::endl;
121  }//END void OpDetPhotonTable::AdOpDetBacktrackerRecords
122 
123 
124  //--------------------------------------------------
125  // cOpDetBacktrackerRecord return.
126  std::vector<sim::OpDetBacktrackerRecord> OpDetPhotonTable::YieldOpDetBacktrackerRecords() {
127  // we give the result to the caller, and don't retain it
128  std::vector<sim::OpDetBacktrackerRecord> result;
129 // std::cout << "DEBUG: result.size() = " << result.size() << std::endl;
130 // std::cout << "DEBUG: cOpDetBTRCol.size() = " << cOpDetBacktrackerRecordsCol.size() << std::endl;
132 // std::cout << "DEBUG: std::swap(result, cOpDetBacktrackerRecordsCol);" << std::endl;
133 // std::cout << "DEBUG: result.size() = " << result.size() << std::endl;
134 // std::cout << "DEBUG: cOpDetBTRCol.size() = " << cOpDetBacktrackerRecordsCol.size() << std::endl;
135  cOpChannelToSOCMap.clear();
136  return result;
137  } // OpDetPhotonTable::YieldOpDetBacktrackerRecords()
138 
139  //--------------------------------------------------
140  // cReflectedOpDetBacktrackerRecord return.
141  std::vector<sim::OpDetBacktrackerRecord> OpDetPhotonTable::YieldReflectedOpDetBacktrackerRecords() {
142  // we give the result to the caller, and don't retain it
143  std::vector<sim::OpDetBacktrackerRecord> result;
144 // std::cout << "DEBUG: result.size() = " << result.size() << std::endl;
145 // std::cout << "DEBUG: cReflOpDetBTRCol.size() = " << cReflectedOpDetBacktrackerRecordsCol.size() << std::endl;
147 // std::cout << "DEBUG: result.size() = " << result.size() << std::endl;
148 // std::cout << "DEBUG: cReflOpDetBTRCol.size() = " << cReflectedOpDetBacktrackerRecordsCol.size() << std::endl;
150  return result;
151  } // OpDetPhotonTable::YieldOpDetBacktrackerRecords()
152 
153 
154  //--------------------------------------------------
155  void OpDetPhotonTable::ClearTable(const size_t nch)
156  {
157  if(fDetectedPhotons.size() != nch) fDetectedPhotons.resize(nch);
158  for(size_t i=0; i<fDetectedPhotons.size(); ++i) {
159  fDetectedPhotons.at(i).clear();
160  fDetectedPhotons.at(i).SetChannel(i);
161  //fDetectedPhotons.at(i).reserve(10000); // Just a guess on minimum # photons
162  }
163  if(fReflectedDetectedPhotons.size() != nch) fReflectedDetectedPhotons.resize(nch);
164  for(size_t i=0; i<fReflectedDetectedPhotons.size(); ++i) {
165  fReflectedDetectedPhotons.at(i).clear();
166  fReflectedDetectedPhotons.at(i).SetChannel(i);
167  //fDetectedPhotons.at(i).reserve(10000); // Just a guess on minimum # photons
168  }
169 
170  for(auto it=fLitePhotons.begin(); it!=fLitePhotons.end(); ++it)
171  (it->second).clear();
172  for(auto it=fReflectedLitePhotons.begin(); it!=fReflectedLitePhotons.end(); ++it)
173  (it->second).clear();
174  fLitePhotons.clear();
175  fReflectedLitePhotons.clear();
176  }
177 
178  //--------------------------------------------------
180  {
181  if(opchannel >= fDetectedPhotons.size()) {
182  std::cerr << "<<" << __PRETTY_FUNCTION__ << ">>"
183  << "Invalid channel Number: " << opchannel
184  << std::endl;
185  }
186  return fDetectedPhotons.at(opchannel);
187  }
188 
189  //--------------------------------------------------
191  {
192  if(opchannel >= fReflectedDetectedPhotons.size()) {
193  std::cerr << "<<" << __PRETTY_FUNCTION__ << ">>"
194  << "Invalid channel Number: " << opchannel
195  << std::endl;
196  }
197  return fReflectedDetectedPhotons.at(opchannel);
198  }
199 
200 
201  //--------------------------------------------------
202  void OpDetPhotonTable::AddEnergyDeposit(int n_photon, int n_elec, double scint_yield,
203  double energy,
204  float start_x,float start_y, float start_z,
205  float end_x,float end_y,float end_z,
206  double start_time,double end_time,
207  int trackid,int pdgcode,
208  std::string const& vol)
209  {
210  fSimEDepCol[vol].emplace_back(n_photon, n_elec, 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,end_time,
215  trackid,pdgcode);
216  }
217 
218  //--------------------------------------------------
220  { fSimEDepCol.clear(); }
221 
222 
223  //--------------------------------------------------
224  std::unordered_map< std::string,std::vector<sim::SimEnergyDeposit> > const& OpDetPhotonTable::GetSimEnergyDeposits() const
225  { return fSimEDepCol; }
226 
227  //--------------------------------------------------
228  std::unordered_map< std::string,std::vector<sim::SimEnergyDeposit> > OpDetPhotonTable::YieldSimEnergyDeposits()
229  {
230  auto data { std::move(fSimEDepCol) };
232  return data;
233  }
234 
235 
236 }
intermediate_table::iterator iterator
std::vector< sim::OpDetBacktrackerRecord > YieldReflectedOpDetBacktrackerRecords()
std::map< int, std::map< int, int > > fLitePhotons
static QCString result
std::string string
Definition: nybbler.cc:12
All information of a photon entering the sensitive optical detector volume.
Definition: SimPhotons.h:64
Geant4 interface.
OpDetPhotonTable * TheOpDetPhotonTable
std::map< int, std::map< int, int > > fReflectedLitePhotons
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)
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)
void swap(Handle< T > &a, Handle< T > &b)
def move(depos, offset)
Definition: depos.py:107
std::vector< sim::SimPhotons > fReflectedDetectedPhotons
void AddOpDetBacktrackerRecord(sim::OpDetBacktrackerRecord soc, bool Reflected=false)
void AddLitePhoton(int opchannel, int time, int nphotons, bool Reflected=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:184
static OpDetPhotonTable * Instance(bool LitePhotons=false)
std::vector< sim::OpDetBacktrackerRecord > cReflectedOpDetBacktrackerRecordsCol
Collection of photons which recorded on one channel.
Definition: SimPhotons.h:136
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
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, std::string const &vol="EMPTY")
std::vector< sim::OpDetBacktrackerRecord > cOpDetBacktrackerRecordsCol
void ClearTable(size_t nch=0)
std::vector< sim::SimPhotons > fDetectedPhotons
timePDclockSDPs_t const & timePDclockSDPsMap() const
Returns all the deposited energy information as stored.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
std::map< int, int > cOpChannelToSOCMap
std::map< int, int > cReflectedOpChannelToSOCMap