51 double numberElectrons,
61 if ((numberElectrons < std::numeric_limits<double>::epsilon()) ||
62 (energy <= std::numeric_limits<double>::epsilon())) {
64 MF_LOG_ERROR(
"SimChannel") <<
"AddIonizationElectrons() trying to add to TDC #" << tdc <<
" " 65 << numberElectrons <<
" electrons with " << energy
66 <<
" MeV of energy from track ID=" << trackID;
75 if (itr ==
fTDCIDEs.end() || itr->first != tdc) {
76 std::vector<sim::IDE> idelist;
77 idelist.emplace_back(trackID, numberElectrons, energy, xyz[0], xyz[1], xyz[2], origTrackID);
78 fTDCIDEs.emplace(itr, tdc, std::move(idelist));
84 for (
auto& ide : itr->second) {
86 if (ide.origTrackID != origTrackID)
continue;
89 double weight = ide.numElectrons + numberElectrons;
90 ide.x = (ide.x * ide.numElectrons + xyz[0] * numberElectrons) / weight;
91 ide.y = (ide.y * ide.numElectrons + xyz[1] * numberElectrons) / weight;
92 ide.z = (ide.z * ide.numElectrons + xyz[2] * numberElectrons) / weight;
94 ide.energy = ide.energy +
energy;
102 itr->second.emplace_back(
103 trackID, numberElectrons, energy, xyz[0], xyz[1], xyz[2], origTrackID);
117 if (itr !=
fTDCIDEs.end() && itr->first == tdc) {
121 for (
auto ide : itr->second) {
122 charge += ide.numElectrons;
138 if (itr !=
fTDCIDEs.end() && itr->first == tdc) {
142 for (
auto ide : itr->second) {
143 energy += ide.energy;
157 if (startTDC > endTDC) {
159 <<
"requested tdc range is bogus: " << startTDC <<
" " << endTDC <<
" return empty vector";
163 std::map<TrackID_t, sim::IDE> idToIDE;
172 if (itr->first > endTDC)
break;
175 auto const& idelist = itr->second;
177 for (
auto const& ide : idelist) {
178 auto itTrkIDE = idToIDE.find(ide.trackID);
179 if (itTrkIDE != idToIDE.end()) {
181 sim::IDE& trackIDE = itTrkIDE->second;
184 double const nel2 = ide.numElectrons;
185 double const en1 = trackIDE.
energy;
186 double const en2 = ide.energy;
187 double const energy = en1 + en2;
188 double const weight = nel1 + nel2;
191 trackIDE.
x = (ide.x * nel2 + trackIDE.
x * nel1) / weight;
192 trackIDE.
y = (ide.y * nel2 + trackIDE.
y * nel1) / weight;
193 trackIDE.
z = (ide.z * nel2 + trackIDE.
z * nel1) / weight;
198 idToIDE[ide.trackID] =
sim::IDE(ide);
206 std::vector<sim::IDE> ides;
207 ides.reserve(idToIDE.size());
208 for (
auto const& itr : idToIDE) {
209 ides.push_back(itr.second);
220 std::vector<sim::TrackIDE> trackIDEs;
222 if (startTDC > endTDC) {
224 <<
"requested tdc range is bogus: " << startTDC <<
" " << endTDC <<
" return empty vector";
230 for (
auto const& ide : ides)
231 totalE += ide.energy;
234 if (totalE < 1.
e-5) totalE = 1.;
237 for (
auto const& ide : ides) {
239 trackIDEs.emplace_back(
240 ide.trackID, ide.energy / totalE, ide.energy, ide.numElectrons, ide.origTrackID);
254 throw std::runtime_error(
"ERROR SimChannel Merge: Trying to merge different channels!");
256 std::pair<TrackID_t, TrackID_t> range_trackID(std::numeric_limits<int>::max(),
257 std::numeric_limits<int>::min());
259 for (
auto const& itr : channel.
TDCIDEMap()) {
261 auto tdc = itr.first;
262 auto const& ides = itr.second;
268 std::vector<sim::IDE>* curIDEVec;
269 if (itrthis ==
fTDCIDEs.end() || itrthis->first != tdc) {
270 fTDCIDEs.emplace_back(tdc, std::vector<sim::IDE>());
271 curIDEVec = &(
fTDCIDEs.back().second);
274 curIDEVec = &(itrthis->second);
276 for (
auto const& ide : ides) {
277 curIDEVec->emplace_back(ide, offset);
278 auto tid =
std::abs(ide.trackID) + offset;
279 if (tid < range_trackID.first) range_trackID.first = tid;
280 if (tid > range_trackID.second) range_trackID.second = tid;
285 return range_trackID;
TrackID_t trackID
Geant4 supplied track ID.
std::pair< TrackID_t, TrackID_t > MergeSimChannel(const SimChannel &channel, int offset)
Merges the deposits from another channel into this one.
raw::ChannelID_t fChannel
readout channel where electrons are collected
float z
z position of ionization [cm]
Namespace for general, non-LArSoft-specific utilities.
Energy deposited on a readout channel by simulated tracks.
std::pair< unsigned short, std::vector< sim::IDE > > TDCIDE
List of energy deposits at the same time (on this channel)
double Energy(TDC_t tdc) const
Returns the total energy on this channel in the specified TDC [MeV].
constexpr auto abs(T v)
Returns the absolute value of the argument.
#define MF_LOG_ERROR(category)
TrackID_t origTrackID
Geant4 supplied track ID (remains true trackID even for shower secondaries/tertiaries etc) ...
constexpr int kBogusI
obviously bogus integer value
float x
x position of ionization [cm]
TDCIDEs_t fTDCIDEs
list of energy deposits for each TDC with signal
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
bool operator()(TDCIDE const &a, TDCIDE const &b) const
double Charge(TDC_t tdc) const
Returns the total number of ionization electrons on this channel in the specified TDC...
Ionization at a point of the TPC sensitive volume.
static const int NoParticleId
float energy
energy deposited by ionization by this track ID and time [MeV]
std::vector< sim::TrackIDE > TrackIDEs(TDC_t startTDC, TDC_t endTDC) const
Returns energies collected for each track within a time interval.
bool operator()(TDCIDE const &a, StoredTDC_t b_tdc) const
TDCIDEs_t::iterator findClosestTDCIDE(StoredTDC_t tdc)
Return the iterator to the first TDCIDE not earlier than tdc.
float y
y position of ionization [cm]
raw::ChannelID_t Channel() const
Returns the readout channel this object describes.
std::vector< sim::IDE > TrackIDsAndEnergies(TDC_t startTDC, TDC_t endTDC) const
Return all the recorded energy deposition within a time interval.
IDE::TrackID_t TrackID_t
Type of track ID (the value comes from Geant4)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
object containing MC truth information necessary for making RawDigits and doing back tracking ...
bool operator()(StoredTDC_t a_tdc, TDCIDE const &b) const
TDCIDEs_t const & TDCIDEMap() const
Returns all the deposited energy information as stored.
constexpr double kBogusD
obviously bogus double value
IDE()
Default constructor (sets "bogus" values)
void AddIonizationElectrons(TrackID_t trackID, TDC_t tdc, double numberElectrons, double const *xyz, double energy, TrackID_t origTrackID=util::kBogusI)
Add ionization electrons and energy to this channel.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Tools and modules for checking out the basics of the Monte Carlo.
float numElectrons
number of electrons at the readout for this track ID and time
TDCIDE::first_type StoredTDC_t
Type for TDC tick used in the internal representation.