LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
MCRecoEdep.cxx
Go to the documentation of this file.
1 //
3 // MCRecoEdep source
4 //
6 
7 #ifndef MCRECOEDEP_CC
8 #define MCRECOEDEP_CC
9 
10 #include "MCRecoEdep.h"
11 
12 // #include "Utilities/DetectorProperties.h"
13 
14 namespace sim {
15 
16  namespace details {
17  std::map<geo::PlaneID, size_t> createPlaneIndexMap(){
19  std::map<geo::PlaneID, size_t> m;
20  size_t i = 0;
21  for(auto const& pid : geom->IteratePlaneIDs()){
22  m[pid] = i;
23  i++;
24  }
25  return m;
26  }
27  }
28  //const unsigned short MCEdepHit::kINVALID_USHORT = std::numeric_limits<unsigned short>::max();
29 
30  //const short MCEdep::kINVALID_SHORT = std::numeric_limits<short>::max();
31 
32  //##################################################################
34  //##################################################################
35  {
36  _debug_mode = pset.get<bool>("DebugMode");
37  _save_mchit = pset.get<bool>("SaveMCHit");
38  }
39 
40  const std::vector<sim::MCEdep>& MCRecoEdep::GetEdepArrayAt(size_t edep_index) const
41  {
42  if(edep_index >= _mc_edeps.size())
43  throw cet::exception(__FUNCTION__) << Form("Track ID %zu not found!",edep_index);
44  return _mc_edeps.at(edep_index);
45  }
46 
47  std::vector<sim::MCEdep>& MCRecoEdep::__GetEdepArray__(unsigned int track_id)
48  {
49  if(ExistTrack(track_id)) return _mc_edeps.at((*_track_index.find(track_id)).second);
50  _track_index.insert(std::pair<unsigned int,size_t>(track_id,_mc_edeps.size()));
51  _mc_edeps.push_back(std::vector<sim::MCEdep>());
52  return (*(_mc_edeps.rbegin()));
53  }
54 
55  void MCRecoEdep::MakeMCEdep(const std::vector<sim::SimChannel>& schArray)
56  {
57  _mc_edeps.clear();
58  _track_index.clear();
59 
61 // const detinfo::DetectorProperties* detp = lar::providerFrom<detinfo::DetectorPropertiesService>();
62 
63  // Key map to identify a unique particle energy deposition point
64  std::map<std::pair<UniquePosition, unsigned int>, int> hit_index_m;
65 
66  auto pindex = details::createPlaneIndexMap();
67 
68  if(_debug_mode) std::cout<<"Processing "<<schArray.size()<<" channels..."<<std::endl;
69  // Loop over channels
70  for(size_t i=0; i<schArray.size(); ++i) {
71 
72  // Get data to loop over
73  auto const& sch = schArray[i];
74  const auto &sch_map(sch.TDCIDEMap());
75  // Channel
76  UInt_t ch = sch.Channel();
77  // Loop over ticks
78  for(auto tdc_iter = sch_map.begin(); tdc_iter!=sch_map.end(); ++tdc_iter) {
79  // for c2: hit_time is unused
80  //unsigned short hit_time = (*tdc_iter).first;
81  // Loop over IDEs
82  for(auto const &ide : (*tdc_iter).second) {
83 
84  int track_id = ide.trackID;
85  if(track_id < 0) track_id = track_id * (-1);
86  unsigned int real_track_id = track_id;
87 
88  UniquePosition pos(ide.x, ide.y, ide.z);
89 
90  int hit_index = -1;
91  auto key = std::make_pair(pos, real_track_id);
92  auto hit_index_track_iter = hit_index_m.find(key);
93  if(hit_index_track_iter == hit_index_m.end()) {
94  int new_hit_index = this->__GetEdepArray__(real_track_id).size();
95  hit_index_m[key]= new_hit_index;
96  }
97  else {
98  hit_index = (*hit_index_track_iter).second;
99  }
100  auto const pid = geom->ChannelToWire(ch)[0].planeID();
101  auto const channel_id = pindex[pid];
102  double charge = ide.numElectrons;
103  if(hit_index < 0) {
104  // This particle energy deposition is never recorded so far. Create a new Edep
105  //float charge = ide.numElectrons * detp->ElectronsToADC();
106  this->__GetEdepArray__(real_track_id).emplace_back(pos, pid, pindex.size(), ide.energy, charge, channel_id);
107  } else {
108  // Append charge to the relevant edep (@ hit_index)
109  //float charge = ide.numElectrons * detp->ElectronsToADC();
110  MCEdep &edep = this->__GetEdepArray__(real_track_id).at(hit_index);
111  edep.deps[channel_id].charge += charge;
112  edep.deps[channel_id].energy += ide.energy;
113  }
114  } // end looping over ides in this tick
115  } // end looping over ticks in this channel
116  }// end looping over channels
117 
118  if(_debug_mode) {
119  std::cout<< Form(" Collected %zu particles' energy depositions...",_mc_edeps.size()) << std::endl;
120  // for c2: disable the entire loop instead of just the print statement
121  //for(auto const& track_id_index : _track_index ) {
122  //auto track_id = track_id_index.first;
123  //auto edep_index = track_id_index.second;
124  // std::cout<< Form(" Track ID: %d ... %zu Edep!", track_id, edep_index) << std::endl;
125  //}
126  std::cout<<std::endl;
127  }
128  }
129 }
130 
131 #endif
void MakeMCEdep(const std::vector< sim::SimChannel > &schArray)
Definition: MCRecoEdep.cxx:55
std::map< geo::PlaneID, size_t > createPlaneIndexMap()
Definition: MCRecoEdep.cxx:17
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
const std::vector< sim::MCEdep > & GetEdepArrayAt(size_t edep_index) const
Returns a vector of MCEdep object at the given index.
Definition: MCRecoEdep.cxx:40
IteratorBox< plane_id_iterator,&GeometryCore::begin_plane_id,&GeometryCore::end_plane_id > IteratePlaneIDs() const
Enables ranged-for loops on all plane IDs of the detector.
MCRecoEdep(fhicl::ParameterSet const &pset)
Default constructor with fhicl parameters.
Definition: MCRecoEdep.cxx:33
T get(std::string const &key) const
Definition: ParameterSet.h:231
Double_t edep
Definition: macro.C:13
Monte Carlo Simulation.
std::vector< sim::MCEdep > & __GetEdepArray__(unsigned int track_id)
Definition: MCRecoEdep.cxx:47
std::vector< deposit > deps
Definition: MCRecoEdep.h:95
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33