32 , fWireReadoutGeom(wireReadoutGeom)
33 , fG4ModuleLabel(config.G4ModuleLabel())
34 , fSimChannelModuleLabel(config.SimChannelModuleLabel())
35 , fHitLabel(config.DefaultHitModuleLabel())
36 , fMinHitEnergyFraction(config.MinHitEnergyFraction())
37 , fOverrideRealData(config.OverrideRealData())
38 , fHitTimeRMS(config.HitTimeRMS())
67 std::vector<const sim::IDE*> ideps;
70 for (
auto mapitr = tdcidemap.begin(); mapitr != tdcidemap.end(); mapitr++) {
72 const std::vector<sim::IDE>& idevec =
75 for (
size_t iv = 0; iv < idevec.size(); ++iv) {
76 if (
abs(idevec[iv].trackID) == id) ideps.push_back(&(idevec[iv]));
87 std::vector<const sim::IDE*> ide_Ps;
91 for (
const auto& item :
sc->TDCIDEMap()) {
94 for (
const sim::IDE& ide : item.second) {
95 if (
abs(ide.
trackID) == id) ide_Ps.push_back(&ide);
110 return (a->Channel() < channel);
112 return ((ilb !=
fSimChannels.end()) && ((*ilb)->Channel() == channel)) ?
121 throw cet::exception(
"BackTracker") <<
"No sim::SimChannel corresponding " 122 <<
"to channel: " << channel <<
"\n";
129 const double hit_start_time,
130 const double hit_end_time)
const 133 if (!schannel)
return {};
135 std::vector<sim::TrackIDE> trackIDEs;
140 int start_tdc = clockData.
TPCTick2TDC(hit_start_time);
142 if (start_tdc < 0) start_tdc = 0;
143 if (end_tdc < 0) end_tdc = 0;
148 for (
size_t e = 0;
e < simides.size(); ++
e)
152 if (totalE < 1.
e-5) totalE = 1.;
155 for (
size_t e = 0;
e < simides.size(); ++
e) {
162 info.
energy = simides[
e].energy;
165 trackIDEs.push_back(info);
185 std::vector<int> retVec;
187 retVec.push_back(trackIDE.trackID);
198 std::vector<sim::TrackIDE> eveIDEs;
199 std::vector<sim::TrackIDE> trackIDEs =
HitToTrackIDEs(clockData, hit);
200 std::map<int, std::pair<double, double>> eveToEMap;
202 for (
const auto& trackIDE : trackIDEs) {
204 std::make_pair(trackIDE.energy, trackIDE.numElectrons));
205 if (check.second ==
false) {
206 check.first->second.first += trackIDE.energy;
207 check.first->second.second += trackIDE.numElectrons;
209 totalE += trackIDE.energy;
211 eveIDEs.reserve(eveToEMap.size());
212 for (
const auto& eveToE : eveToEMap) {
215 eveTrackIDE_tmp.
trackID = eveToE.first;
216 eveTrackIDE_tmp.
energy = eveToE.second.first;
220 eveIDEs.push_back(eveTrackIDE_tmp);
236 std::vector<art::Ptr<recob::Hit>> hitList;
237 std::vector<sim::TrackIDE> trackIDE;
238 for (
auto itr = hitsIn.begin(); itr != hitsIn.end(); ++itr) {
245 for (
auto itr_trakIDE = trackIDE.begin(); itr_trakIDE != trackIDE.end(); ++itr_trakIDE) {
247 hitList.push_back(hit);
258 std::vector<int>
const& tkIds,
266 std::vector<std::pair<int, art::Ptr<recob::Hit>>> hitList;
267 std::vector<sim::TrackIDE> tids;
268 for (
auto itr = hitsIn.begin(); itr != hitsIn.end(); ++itr) {
275 for (
auto itid = tids.begin(); itid != tids.end(); ++itid) {
276 for (
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
277 if (itid->trackID == *itkid) {
279 hitList.push_back(std::make_pair(*itkid, hit));
286 std::vector<std::vector<art::Ptr<recob::Hit>>> truHits;
288 std::vector<art::Ptr<recob::Hit>> tmpHits;
289 for (
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
291 for (
auto itr = hitList.begin(); itr != hitList.end(); ++itr) {
292 if (*itkid == (*itr).first) tmpHits.push_back((*itr).second);
294 truHits.push_back(tmpHits);
306 if (start_tdc < 0) start_tdc = 0;
307 if (end_tdc < 0) end_tdc = 0;
317 std::vector<const sim::IDE*> retVec;
320 if (start_tdc < 0) start_tdc = 0;
321 if (end_tdc < 0) end_tdc = 0;
323 if (start_tdc > end_tdc) {
throw; }
328 std::vector<const std::pair<unsigned short, std::vector<sim::IDE>>*> tdcIDEMap_SortedPointers;
329 for (
auto& pair : tdcIDEMap) {
330 tdcIDEMap_SortedPointers.push_back(&pair);
338 auto pairSort = [](
auto& a,
auto& b) {
return a->first < b->first; };
340 tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), pairSort)) {
341 std::sort(tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), pairSort);
344 std::vector<sim::IDE> dummyVec;
347 std::pair<double, std::vector<sim::IDE>> start_tdcPair =
348 std::make_pair(start_tdc, dummyVec);
350 std::pair<double, std::vector<sim::IDE>> end_tdcPair = std::make_pair(end_tdc, dummyVec);
351 auto start_tdcPair_P = &start_tdcPair;
352 auto end_tdcPair_P = &end_tdcPair;
353 auto mapFirst = std::lower_bound(
354 tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), start_tdcPair_P, pairSort);
357 auto mapLast = std::upper_bound(
358 tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), end_tdcPair_P, pairSort);
359 for (
auto& mapitr = mapFirst; mapitr != mapLast; ++mapitr) {
360 for (
auto& ide : (*mapitr)->second) {
361 retVec.push_back(&ide);
370 std::vector<double> xyz(3, 0.0);
372 for (
auto const& ide : ides) {
373 double weight = ide.numElectrons;
375 xyz[0] += (weight * ide.x);
376 xyz[1] += (weight * ide.y);
377 xyz[2] += (weight * ide.z);
380 throw cet::exception(
"BackTracker") <<
"No sim::IDEs providing non-zero number of electrons" 381 <<
" can't determine originating location from truth\n";
391 std::vector<sim::IDE> ides;
392 for (
auto ide_P : ide_Ps) {
393 ides.push_back(*ide_P);
407 std::set<int>
const& trackIds,
413 for (
const auto& tIDE : hitTrackIDEs) {
414 if (trackIds.find(tIDE.trackID) != trackIds.end()) {
420 if (hits.size() > 0) {
return double(
double(desired) /
double(hits.size())); }
426 std::set<int>
const& trackIds,
429 double totalCharge = 0., desired = 0.;
431 totalCharge +=
hit->Integral();
433 for (
const auto& trackIDE : trackIDEs) {
434 if (trackIds.find(trackIDE.trackID) != trackIds.end()) {
435 desired +=
hit->Integral();
440 if (totalCharge > 0.0) {
return (desired / totalCharge); }
446 std::set<int>
const& trackIds,
452 int desired = 0, total = 0;
456 for (
const auto& trackIDE : hitTrackIDEs) {
457 if (trackIds.find(trackIDE.trackID) != trackIds.end() &&
465 for (
const auto&
hit : allHits) {
470 for (
const auto& hitIDE : hitTrackIDEs) {
471 if (trackIds.find(hitIDE.trackID) != trackIds.end() &&
478 if (total >= 0) {
return double(
double(desired) /
double(total)); }
485 std::set<int>
const& trackIds,
490 double desired = 0., total = 0.;
493 for (
const auto& hitIDE : hitTrackIDEs) {
494 if (trackIds.find(hitIDE.trackID) != trackIds.end() &&
496 desired +=
hit->Integral();
502 for (
const auto&
hit : allHits) {
503 if (
hit->View() != view && view !=
geo::k3D) {
continue; }
505 for (
const auto& hitIDE : hitTrackIDEs) {
506 if (trackIds.find(hitIDE.trackID) != trackIds.end() &&
508 total +=
hit->Integral();
514 if (total > 0.) {
return desired / total; }
526 std::vector<sim::TrackIDE> trackIDEs =
528 for (
const auto& ide : trackIDEs) {
529 tids.insert(ide.trackID);
539 std::set<int> eveIds;
542 for (
const auto& ide : ides) {
543 eveIds.insert(ide.trackID);
555 std::vector<std::vector<std::vector<int>>> numHits(
fGeom->
Ncryostats());
556 std::vector<std::vector<std::vector<double>>> hitWeight(
fGeom->
Ncryostats());
557 std::vector<std::vector<std::vector<std::vector<double>>>> hitPos(
fGeom->
Ncryostats());
559 for (
size_t c = 0; c < numHits.size(); ++c) {
564 for (
size_t t = 0; t < numHits[c].size(); ++t) {
572 for (
auto const& hit_ptr :
hits) {
577 std::vector<double> hitOrigin =
HitToXYZ(clockData, hit_ptr);
578 geo::Point_t const worldLoc{hitOrigin[0], hitOrigin[1], hitOrigin[2]};
581 auto const [cstat, tpc] = std::make_tuple(tpcid.Cryostat, tpcid.TPC);
586 hitPos[cstat][tpc][hit.
WireID().
Plane] = hitOrigin;
593 std::vector<double> xyz(3);
594 for (
size_t c = 0; c < numHits.size(); ++c) {
595 for (
size_t t = 0; t < numHits[c].size(); ++t) {
596 for (
size_t p = 0; p < numHits[c][t].size(); ++p) {
598 if (numHits[c][t][p] == 1) {
600 xyz[0] += hitPos[c][t][p][0];
601 xyz[1] += hitPos[c][t][p][1];
602 xyz[2] += hitPos[c][t][p][2];
612 <<
"No hits to determine originating location from truth\n";
TrackID_t trackID
Geant4 supplied track ID.
const art::InputTag fHitLabel
const geo::GeometryCore * fGeom
std::vector< art::Ptr< sim::SimChannel > > fSimChannels
std::vector< std::vector< art::Ptr< recob::Hit > > > TrackIdsToHits_Ps(detinfo::DetectorClocksData const &clockData, std::vector< int > const &tkIds, std::vector< art::Ptr< recob::Hit >> const &hitsIn) const
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
art::Ptr< sim::SimChannel > FindSimChannelPtr(raw::ChannelID_t channel) const
Returns the cached sim::SimChannel on the specified channel.
std::vector< sim::TrackIDE > HitToEveTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
unsigned int NTPC(CryostatID const &cryoid=details::cryostat_zero) const
Returns the total number of TPCs in the specified cryostat.
const art::InputTag fSimChannelModuleLabel
float numElectrons
number of electrons from the particle detected on the wires
constexpr auto abs(T v)
Returns the absolute value of the argument.
const double fMinHitEnergyFraction
CryostatID_t Cryostat
Index of cryostat.
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
geo::WireID const & WireID() const
Initial tdc tick for hit.
float energy
energy from the particle with this trackID [MeV]
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
pure virtual base interface for detector clocks
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
3-dimensional objects, potentially hits, clusters, prongs, etc.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Access the description of the physical detector geometry.
const geo::WireReadoutGeom * fWireReadoutGeom
std::vector< double > HitToXYZ(detinfo::DetectorClocksData const &clockData, const recob::Hit &hit) const
Ionization at a point of the TPC sensitive volume.
static const int NoParticleId
Interface for a class providing readout channel mapping to geometry.
art::Ptr< sim::SimChannel > FindSimChannel(raw::ChannelID_t channel) const
Returns the cached sim::SimChannel on the specified channel.
std::vector< art::Ptr< recob::Hit > > TrackIdToHits_Ps(detinfo::DetectorClocksData const &clockData, int tkId, std::vector< art::Ptr< recob::Hit >> const &hitsIn) const
std::set< int > GetSetOfTrackIds() const
double HitCollectionPurity(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits) const
float energyFrac
fraction of hit energy from the particle with this trackID
const cheat::ParticleInventory * fPartInv
The data type to uniquely identify a TPC.
PlaneID_t Plane
Index of the plane within its TPC.
Description of the physical geometry of one entire detector.
Definition of data types for geometry description.
float PeakTimeMinusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
Detector simulation of raw signals on wires.
unsigned int Nplanes(TPCID const &tpcid=details::tpc_zero) const
Returns the total number of planes in the specified TPC.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
std::vector< sim::TrackIDE > ChannelToTrackIDEs(detinfo::DetectorClocksData const &clockData, raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time) const
std::set< int > GetSetOfEveIds() const
double HitChargeCollectionPurity(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits) const
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
code to link reconstructed objects back to the MC truth information
int trackID
Geant4 supplied trackID.
const bool fOverrideRealData
BackTracker(const fhiclConfig &config, const cheat::ParticleInventory *partInv, geo::GeometryCore const *geom, geo::WireReadoutGeom const *wireReadoutGeom)
Contains all timing reference information for the detector.
View_t View(raw::ChannelID_t const channel) const
Returns the view (wire orientation) on the specified TPC channel.
std::vector< sim::IDE > TrackIDsAndEnergies(TDC_t startTDC, TDC_t endTDC) const
Return all the recorded energy deposition within a time interval.
std::vector< int > HitToTrackIds(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
double HitCollectionEfficiency(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits, std::vector< art::Ptr< recob::Hit >> const &allhits, geo::View_t const &view) const
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
const art::InputTag fG4ModuleLabel
2D representation of charge deposited in the TDC/wire plane
float PeakTimePlusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
TPCID_t TPC
Index of the TPC within its cryostat.
std::vector< sim::IDE > HitToAvgSimIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
int TrackIdToEveTrackId(const int &tid) const
Ionization energy from a Geant4 track.
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
std::vector< double > SimIDEsToXYZ(std::vector< sim::IDE > const &ides) const
double HitChargeCollectionEfficiency(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits, std::vector< art::Ptr< recob::Hit >> const &allhits, geo::View_t const &view) const
double TPCTick2TDC(double const tick) const
Tools and modules for checking out the basics of the Monte Carlo.
TPCID PositionToTPCID(Point_t const &point) const
Returns the ID of the TPC at specified location.
Interface to geometry for wire readouts .
cet::coded_exception< error, detail::translate > exception
The data type to uniquely identify a cryostat.
std::vector< const sim::IDE * > HitToSimIDEs_Ps(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
std::vector< double > SpacePointHitsToWeightedXYZ(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit >> const &hits) const