18 #include "messagefacility/MessageLogger/MessageLogger.h"
57 double numberElectrons,
67 if ((numberElectrons < std::numeric_limits<double>::epsilon())
68 || (energy <= std::numeric_limits<double>::epsilon()))
71 MF_LOG_ERROR(
"SimChannel")
72 <<
"AddIonizationElectrons() trying to add to TDC #"
78 <<
" MeV of energy from track ID="
90 std::vector<sim::IDE> idelist;
91 idelist.emplace_back(trackID,
99 fTDCIDEs.emplace(itr, tdc, std::move(idelist) );
105 for(
auto& ide : itr->second){
107 if (ide.origTrackID != origTrackID)
continue;
110 double weight = ide.numElectrons + numberElectrons;
111 ide.x = (ide.x * ide.numElectrons + xyz[0]*numberElectrons)/weight;
112 ide.y = (ide.y * ide.numElectrons + xyz[1]*numberElectrons)/weight;
113 ide.z = (ide.z * ide.numElectrons + xyz[2]*numberElectrons)/weight;
114 ide.numElectrons = weight;
115 ide.energy = ide.energy + energy;
123 itr->second.emplace_back(trackID,
150 for(
auto ide : itr->second){
151 charge += ide.numElectrons;
172 for(
auto ide : itr->second ){
173 energy += ide.energy;
189 if(startTDC > endTDC ){
190 mf::LogWarning(
"SimChannel") <<
"requested tdc range is bogus: "
191 << startTDC <<
" " << endTDC
192 <<
" return empty vector";
196 std::map<TrackID_t, sim::IDE> idToIDE;
205 if(itr->first > endTDC)
break;
208 auto const& idelist = itr->second;
210 for(
auto const& ide : idelist){
211 auto itTrkIDE = idToIDE.find(ide.trackID);
212 if( itTrkIDE != idToIDE.end() ){
214 sim::IDE& trackIDE = itTrkIDE->second;
217 double const nel2 = ide.numElectrons;
218 double const en1 = trackIDE.
energy;
219 double const en2 = ide.energy;
220 double const energy = en1 + en2;
221 double const weight = nel1 + nel2;
224 trackIDE.
x = (ide.x*nel2 + trackIDE.
x*nel1)/weight;
225 trackIDE.
y = (ide.y*nel2 + trackIDE.
y*nel1)/weight;
226 trackIDE.
z = (ide.z*nel2 + trackIDE.
z*nel1)/weight;
231 idToIDE[ide.trackID] =
sim::IDE(ide);
239 std::vector<sim::IDE> ides;
240 ides.reserve(idToIDE.size());
241 for(
auto const& itr : idToIDE){
242 ides.push_back(itr.second);
254 std::vector<sim::TrackIDE> trackIDEs;
256 if(startTDC > endTDC ){
257 mf::LogWarning(
"SimChannel::TrackIDEs") <<
"requested tdc range is bogus: "
258 << startTDC <<
" " << endTDC
259 <<
" return empty vector";
265 for (
auto const& ide : ides)
266 totalE += ide.energy;
269 if(totalE < 1.
e-5) totalE = 1.;
272 for (
auto const& ide : ides){
274 trackIDEs.emplace_back(ide.trackID, ide.energy/totalE, ide.energy, ide.numElectrons, ide.origTrackID);
284 std::pair<SimChannel::TrackID_t,SimChannel::TrackID_t>
289 throw std::runtime_error(
"ERROR SimChannel Merge: Trying to merge different channels!");
291 std::pair<TrackID_t,TrackID_t> range_trackID(std::numeric_limits<int>::max(),
292 std::numeric_limits<int>::min());
294 for(
auto const& itr : channel.
TDCIDEMap()){
296 auto tdc = itr.first;
297 auto const& ides = itr.second;
303 std::vector<sim::IDE>* curIDEVec;
305 itrthis->first != tdc){
306 fTDCIDEs.emplace_back(tdc, std::vector<sim::IDE>());
307 curIDEVec = &(
fTDCIDEs.back().second);
310 curIDEVec = &(itrthis->second);
312 for(
auto const& ide : ides){
313 curIDEVec->emplace_back(ide, offset);
315 if( tid < range_trackID.first )
316 range_trackID.first = tid;
317 if( tid > range_trackID.second )
318 range_trackID.second = tid;
324 return range_trackID;
333 {
return a.first < b.first; }
337 {
return a_tdc < b.first; }
341 {
return a.first < b_tdc; }
348 return std::lower_bound
355 return std::lower_bound
356 (fTDCIDEs.begin(), fTDCIDEs.end(), tdc,
CompareByTDC());
TrackID_t trackID
Geant4 supplied track ID.
process_name opflash particleana ie ie ie z
std::pair< TrackID_t, TrackID_t > MergeSimChannel(const SimChannel &channel, int offset)
Merges the deposits from another channel into this one.
float z
z position of ionization [cm]
BEGIN_PROLOG TPC Trig offset(g4 rise time) ProjectToHeight
Energy deposited on a readout channel by simulated tracks.
process_name opflash particleana ie x
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].
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.
process_name opflash particleana ie ie y
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.
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)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
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.