402 const sim::ParticleList& plist = pi_serv->
ParticleList();
426 std::unordered_map<int, std::vector<recob::Hit> > mapTrackIDtoHits;
427 std::unordered_map<int, double> mapTrackIDtoHitsEnergyPerPlane[3];
428 std::unordered_map<int, double> mapTrackIDtoHitsEnergy;
430 std::unordered_map<int, double> mapTrackIDtoLength;
431 const auto hitListHandle =
evt.getValidHandle< std::vector<recob::Hit> >(
fHitModuleLabel);
432 for (
auto const &
h : *hitListHandle)
434 std::unordered_map<int, double> particleID_E;
442 particleID_E[
id.trackID] +=
id.energy;
444 mapTrackIDtoLength[
id.trackID] =
GetLengthInTPC(clockData, *part);
450 for (
auto const & contrib : particleID_E)
452 if (contrib.second > max_e)
454 max_e = contrib.second;
455 best_id = contrib.first;
461 mapTrackIDtoHits[best_id].push_back(
h);
462 mapTrackIDtoHitsEnergyPerPlane[
h.WireID().Plane][best_id] += max_e;
463 mapTrackIDtoHitsEnergy[best_id] += max_e;
472 std::unordered_map<int, std::vector< recob::Hit >> mapTrackIDtoHits_filtered;
473 for (
auto const &
p : mapTrackIDtoHits)
492 if ((mother == 0) || (mother->
Process() !=
"primary")) { skip =
true; }
499 if (skip) {
continue; }
505 if (skip) {
continue; }
508 std::unordered_map<geo::View_t, size_t> hit_count;
509 for (
auto const &
h :
p.second) { hit_count[
h.View()]++; }
516 mapTrackIDtoHits_filtered.emplace(
p);
522 for (
auto const &
p : mapTrackIDtoHits_filtered)
528 double this_length = mapTrackIDtoLength[
p.first];
530 std::cout <<
" : id " <<
p.first <<
" size " <<
p.second.size() <<
" en: " << mapTrackIDtoHitsEnergy[
p.first] <<
" init en: " << this_energy <<
" PDG: " << this_code <<
" Length: " << this_length <<
std::endl;
551 std::unordered_map<int, int> mapIDEtoRecoTrack;
552 std::unordered_map<int, double> mapIDEtoRecoEnergy;
553 std::unordered_map<int, std::vector< std::pair<int, double > > > mapIDEtoTrackContribs;
555 for (
size_t t = 0;
t < trkHandle->size(); ++
t)
561 std::unordered_map<int, double> trkID_E_perPlane[3];
562 std::unordered_map<int, double> trkID_E;
563 double totE_anyMC_inPlane[3] = { 0, 0, 0 };
564 double totE_anyMC = 0;
565 const auto & hits = hitsFromTracks.at(
t);
566 for (
const auto &
h : hits)
568 size_t plane =
h->WireID().Plane;
571 if (mapTrackIDtoHits_filtered.find(ide.trackID) != mapTrackIDtoHits_filtered.end())
573 trkID_E_perPlane[plane][ide.trackID] += ide.energy;
574 trkID_E[ide.trackID] += ide.energy;
576 totE_anyMC_inPlane[plane] += ide.energy;
577 totE_anyMC += ide.energy;
584 std::array< double, 3 > e_inPlane = {{ 0, 0, 0 }};
585 for (
auto const &
entry : trkID_E)
587 mapIDEtoTrackContribs[
entry.
first].push_back(std::make_pair(
t,
entry.second));
590 if (
entry.second > max_e)
592 max_e =
entry.second;
595 for (
size_t i = 0; i < 3; ++i)
597 e_inPlane[i] = trkID_E_perPlane[i][
entry.
first];
603 mapIDEtoRecoTrack[best_id] = -1;
606 mapIDEtoRecoTrack[best_id] =
t;
608 mapIDEtoRecoEnergy[best_id] = max_e;
611 if ((max_e > 0.5 * totE_anyMC) &&
612 (max_e > 0.5 * mapTrackIDtoHitsEnergy[best_id]))
616 double this_length = mapTrackIDtoLength[best_id];
619 std::cout <<
" id: " << best_id <<
" init energy: " << pi_serv->
TrackIdToParticle_P(best_id)->
E(0) <<
" Length: " << this_length <<
std::endl;
629 for (
size_t i = 0; i < 3; ++i)
631 if (totE_anyMC_inPlane[i] > 0) {
fTrkPurityPerPlane[i] = e_inPlane[i] / totE_anyMC_inPlane[i]; }
634 if (mapTrackIDtoHitsEnergyPerPlane[i][best_id] > 0) {
fTrkCompletnessPerPlane[i] = e_inPlane[i] / mapTrackIDtoHitsEnergyPerPlane[i][best_id]; }
638 fTrkPid = (*trkHandle)[
t].ParticleId();
646 std::vector<const anab::T0*> T0s;
655 std::cout <<
"No T0s found" <<
std::endl;
662 for(
auto const &
pos : (((*trkHandle)[
t].Trajectory()).Trajectory()).Positions()){
663 if (track_step > 9999)
break;
666 double t0Correction = detProp.ConvertTicksToX(
TickT0, this_wire.Plane, this_wire.TPC, this_wire.Cryostat );
677 for(
int track_step = 0; track_step < 10000; ++
track_step){
689 for (
const auto &
h : hits)
691 const auto & sps = spFromHits.at(
h.key());
692 if (sps.empty()) {
continue; }
693 const auto & sp = *sps.front();
697 std::array< double, 3 > hitpos = {{0, 0, 0}};
699 for (
auto const & ide : ides)
701 if (ide.trackID == best_id)
703 hitpos[0] += ide.x * ide.energy;
704 hitpos[1] += ide.y * ide.energy;
705 hitpos[2] += ide.z * ide.energy;
711 hitpos[0] /= hitE; hitpos[1] /= hitE; hitpos[2] /= hitE;
713 double dy = sp.XYZ()[1] - hitpos[1];
714 double dz = sp.XYZ()[2] - hitpos[2];
718 fHitDist3D->Fill(sqrt(dx*dx + dy*dy + dz*dz));
730 for (
auto const &
p : mapTrackIDtoHits_filtered)
745 std::vector<std::pair<int, double>> TrackContribs;
746 TrackContribs = mapIDEtoTrackContribs[
p.first];
747 for (
auto const & tc : TrackContribs){
757 if (track_step > 9999)
break;
761 if( (pos != TVector3(-1,-1,-1)) && (pos != TVector3(0,0,0))){
801 std::cout <<
"------------ reconstructed: " << fNRecoTracks <<
" and then matched to MC particles: " <<
fMatched double E(const int i=0) const
double GetLengthInTPC(detinfo::DetectorClocksData const &clockData, simb::MCParticle part)
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
const simb::MCTrajectory & Trajectory() const
const simb::MCParticle * TrackIdToParticle_P(int id) const
TH1D * fLengthNominatorHist
simb::Origin_t Origin() const
std::vector< int > fTrueTrkRecos
std::vector< int > fTrkIDEs
std::vector< EFilterMode > fFilters
std::string Process() const
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p) const
std::vector< double > fTrueTrkContribs
TH1D * fEnergyDenominatorHist
QCollection::Item first()
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
int PdgCode(Resonance_t res, int Q)
(resonance id, charge) -> PDG code
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::string EndProcess() const
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int id) const
single particles thrown at the detector
float fTrkCompletnessPerPlane[3]
std::vector< double > fTrkContribs
CodeOutputInterface * code
double fTrueTrkEnergyGuess
art::InputTag fTempTrackModuleLabel
const sim::ParticleList & ParticleList() const
TVector3 GetPositionInTPC(detinfo::DetectorClocksData const &clockData, simb::MCParticle part, int MCHit)
art::InputTag fHitModuleLabel
double TotalLength() const
std::vector< sim::IDE > HitToAvgSimIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
art::InputTag fTrackModuleLabel
float fTrkPurityPerPlane[3]
double fTrueTrkdEdX[10000]
TH1D * fDepDenominatorHist
TH1D * fLengthDenominatorHist
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
constexpr Point origin()
Returns a origin position with a point of the specified type.
QTextStream & endl(QTextStream &s)
double fTrueTrkStepE[10000]
double GetdEdX(simb::MCTrajectory traj, size_t this_step)
TH1D * fEnergyNominatorHist