LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
sim::MCRecoEdep Class Reference

#include "MCRecoEdep.h"

Public Member Functions

 MCRecoEdep (fhicl::ParameterSet const &pset)
 Default constructor with fhicl parameters. More...
 
void MakeMCEdep (const std::vector< sim::SimChannel > &schArray)
 
bool ExistTrack (const unsigned int track_id) const
 
int TrackToEdepIndex (unsigned int track_id) const
 Converts a track ID to MCEdep array index. Returns -1 if no corresponding array found . More...
 
const std::vector< sim::MCEdep > & GetEdepArrayAt (size_t edep_index) const
 Returns a vector of MCEdep object at the given index. More...
 
const std::map< unsigned int, size_t > TrackIndexMap () const
 Returns a map of track id <-> MCEdep vector index. More...
 
void Clear ()
 

Protected Member Functions

std::vector< sim::MCEdep > & __GetEdepArray__ (unsigned int track_id)
 

Protected Attributes

bool _debug_mode
 
bool _save_mchit
 
std::map< unsigned int, size_t > _track_index
 
std::vector< std::vector< sim::MCEdep > > _mc_edeps
 

Detailed Description

Definition at line 107 of file MCRecoEdep.h.

Constructor & Destructor Documentation

sim::MCRecoEdep::MCRecoEdep ( fhicl::ParameterSet const &  pset)

Default constructor with fhicl parameters.

Definition at line 33 of file MCRecoEdep.cxx.

References fhicl::ParameterSet::get().

35  {
36  _debug_mode = pset.get<bool>("DebugMode");
37  _save_mchit = pset.get<bool>("SaveMCHit");
38  }

Member Function Documentation

std::vector< sim::MCEdep > & sim::MCRecoEdep::__GetEdepArray__ ( unsigned int  track_id)
protected

Definition at line 47 of file MCRecoEdep.cxx.

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  }
bool ExistTrack(const unsigned int track_id) const
Definition: MCRecoEdep.h:117
std::vector< std::vector< sim::MCEdep > > _mc_edeps
Definition: MCRecoEdep.h:147
std::map< unsigned int, size_t > _track_index
Definition: MCRecoEdep.h:146
void sim::MCRecoEdep::Clear ( )
inline

Definition at line 134 of file MCRecoEdep.h.

Referenced by MCReco::produce().

134  {
135  _mc_edeps.clear();
136  _track_index.clear();
137  std::vector<std::vector<sim::MCEdep>>().swap(_mc_edeps);
138  std::map<unsigned int,size_t>().swap(_track_index);
139  }
std::vector< std::vector< sim::MCEdep > > _mc_edeps
Definition: MCRecoEdep.h:147
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)
std::map< unsigned int, size_t > _track_index
Definition: MCRecoEdep.h:146
bool sim::MCRecoEdep::ExistTrack ( const unsigned int  track_id) const
inline

Definition at line 117 of file MCRecoEdep.h.

118  { return (_track_index.find(track_id) != _track_index.end()); }
std::map< unsigned int, size_t > _track_index
Definition: MCRecoEdep.h:146
const std::vector< sim::MCEdep > & sim::MCRecoEdep::GetEdepArrayAt ( size_t  edep_index) const

Returns a vector of MCEdep object at the given index.

Definition at line 40 of file MCRecoEdep.cxx.

Referenced by sim::MCTrackRecoAlg::Reconstruct(), and sim::MCShowerRecoAlg::Reconstruct().

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  }
std::vector< std::vector< sim::MCEdep > > _mc_edeps
Definition: MCRecoEdep.h:147
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void sim::MCRecoEdep::MakeMCEdep ( const std::vector< sim::SimChannel > &  schArray)

Definition at line 55 of file MCRecoEdep.cxx.

References geo::GeometryCore::ChannelToWire(), sim::details::createPlaneIndexMap(), sim::MCEdep::deps, and edep.

Referenced by MCReco::produce().

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  }
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.
Double_t edep
Definition: macro.C:13
std::vector< std::vector< sim::MCEdep > > _mc_edeps
Definition: MCRecoEdep.h:147
std::vector< sim::MCEdep > & __GetEdepArray__(unsigned int track_id)
Definition: MCRecoEdep.cxx:47
std::map< unsigned int, size_t > _track_index
Definition: MCRecoEdep.h:146
const std::map<unsigned int,size_t> sim::MCRecoEdep::TrackIndexMap ( ) const
inline

Returns a map of track id <-> MCEdep vector index.

Definition at line 131 of file MCRecoEdep.h.

132  { return _track_index; }
std::map< unsigned int, size_t > _track_index
Definition: MCRecoEdep.h:146
int sim::MCRecoEdep::TrackToEdepIndex ( unsigned int  track_id) const
inline

Converts a track ID to MCEdep array index. Returns -1 if no corresponding array found .

Definition at line 121 of file MCRecoEdep.h.

Referenced by sim::MCTrackRecoAlg::Reconstruct(), and sim::MCShowerRecoAlg::Reconstruct().

122  {
123  auto iter = _track_index.find(track_id);
124  return (iter == _track_index.end() ? -1 : (int)((*iter).second));
125  }
std::map< unsigned int, size_t > _track_index
Definition: MCRecoEdep.h:146

Member Data Documentation

bool sim::MCRecoEdep::_debug_mode
protected

Definition at line 144 of file MCRecoEdep.h.

std::vector<std::vector<sim::MCEdep> > sim::MCRecoEdep::_mc_edeps
protected

Definition at line 147 of file MCRecoEdep.h.

bool sim::MCRecoEdep::_save_mchit
protected

Definition at line 145 of file MCRecoEdep.h.

std::map<unsigned int,size_t> sim::MCRecoEdep::_track_index
protected

Definition at line 146 of file MCRecoEdep.h.


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