1007 art::ServiceHandle<cheat::BackTrackerService> backtracker;
1008 art::ServiceHandle<cheat::ParticleInventoryService> inventory_service;
1009 auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(
evt);
1011 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(
evt, clock_data);
1015 std::vector<std::vector<art::Ptr<recob::Slice>>> sliceList;
1016 std::vector<art::FindManyP<recob::Hit>> sliceHitList;
1017 std::vector<art::FindManyP<recob::PFParticle>> slicePFParticleList;
1018 std::vector<art::FindManyP<sbn::VertexHit>> sliceVertexHitList;
1021 art::Handle<std::vector<recob::Slice>> slice_handle;
1023 sliceList.emplace_back();
1024 art::fill_ptr_vector(sliceList.back(), slice_handle);
1031 std::vector<art::Ptr<recob::Slice>>
slices;
1032 std::vector<std::vector<art::Ptr<recob::Hit>>> sliceHits;
1034 std::vector<std::vector<art::Ptr<recob::PFParticle>>> sliceParticles;
1035 std::vector<std::vector<std::vector<art::Ptr<recob::Hit>>>> sliceParticleHits;
1036 std::vector<std::vector<std::vector<art::Ptr<recob::Vertex>>>> sliceParticleVertexs;
1038 std::vector<std::vector<art::Ptr<sbn::VertexHit>>> sliceVertexHits;
1039 std::vector<std::vector<art::Ptr<recob::Vertex>>> sliceVertexHitVtxs;
1040 std::vector<std::vector<art::Ptr<recob::Hit>>> sliceVertexHitHits;
1041 std::vector<std::vector<art::Ptr<recob::SpacePoint>>> sliceVertexHitSPs;
1042 std::vector<std::vector<art::Ptr<sbn::Stub>>> sliceStubs;
1043 std::vector<std::vector<unsigned>> sliceStubHitInds;
1044 std::vector<std::vector<std::vector<art::Ptr<recob::Hit>>>> sliceStubHits;
1045 std::vector<std::vector<art::Ptr<recob::PFParticle>>> sliceStubPFPs;
1046 std::vector<std::vector<std::vector<art::Ptr<recob::Hit>>>> sliceStubPFPHits;
1048 for (
unsigned i = 0; i < sliceList.size(); i++) {
1049 slices.insert(slices.end(), sliceList[i].begin(), sliceList[i].end());
1050 for (
unsigned j = 0; j < sliceList[i].size(); j++) {
1051 sliceHits.push_back(sliceHitList[i].at(j));
1052 sliceParticles.push_back(slicePFParticleList[i].at(j));
1054 sliceParticleHits.emplace_back();
1055 art::FindManyP<recob::Cluster> sliceParticleClusters(sliceParticles.back(),
evt,
fPFParticleTags.at(i));
1056 for (
unsigned i_pfp = 0; i_pfp < sliceParticles.back().size(); i_pfp++) {
1057 sliceParticleHits.back().emplace_back();
1058 const std::vector<art::Ptr<recob::Cluster>> &thisParticleClusters = sliceParticleClusters.at(i_pfp);
1059 art::FindManyP<recob::Hit> clusterHits(thisParticleClusters,
evt,
fPFParticleTags.at(i));
1060 for (
unsigned i_clus = 0; i_clus < thisParticleClusters.size(); i_clus++) {
1061 sliceParticleHits.back().back().insert(sliceParticleHits.back().back().end(), clusterHits.at(i_clus).begin(), clusterHits.at(i_clus).end());
1065 sliceParticleVertexs.emplace_back();
1066 art::FindManyP<recob::Vertex> findSliceParticleVertexs(sliceParticles.back(),
evt,
fPFParticleTags.at(i));
1067 for (
unsigned i_pfp = 0; i_pfp < sliceParticles.back().size(); i_pfp++) {
1068 sliceParticleVertexs.back().push_back(findSliceParticleVertexs.at(i_pfp));
1071 sliceVertexHits.push_back(sliceVertexHitList[i].at(j));
1073 art::FindManyP<recob::Vertex> vertexHitVtxs(sliceVertexHits.back(),
evt,
fVertexHitTags.at(i));
1074 sliceVertexHitVtxs.emplace_back();
1075 for (
unsigned i_vhit = 0; i_vhit < sliceVertexHits.back().size(); i_vhit++) {
1076 sliceVertexHitVtxs.back().push_back(vertexHitVtxs.at(i_vhit).at(0));
1079 art::FindManyP<recob::Hit> vertexHitHits(sliceVertexHits.back(),
evt,
fVertexHitTags.at(i));
1080 sliceVertexHitHits.emplace_back();
1081 for (
unsigned i_vhit = 0; i_vhit < sliceVertexHits.back().size(); i_vhit++) {
1082 sliceVertexHitHits.back().push_back(vertexHitHits.at(i_vhit).at(0));
1085 art::Ptr<recob::SpacePoint> nullSP;
1086 art::FindManyP<recob::SpacePoint> vertexHitSPs(sliceVertexHitHits.back(),
evt,
fPFParticleTags.at(i));
1087 sliceVertexHitSPs.emplace_back();
1088 for (
unsigned i_sp = 0; i_sp < sliceVertexHitHits.back().size(); i_sp++) {
1089 const std::vector<art::Ptr<recob::SpacePoint>> &this_sp = vertexHitSPs.at(i_sp);
1090 if (this_sp.size()) sliceVertexHitSPs.back().push_back(this_sp.at(0));
1091 else sliceVertexHitSPs.back().push_back(nullSP);
1095 art::FindManyP<sbn::Stub> vertexStubs(sliceVertexHits.back(),
evt,
fStubTags.at(i));
1096 sliceStubs.emplace_back();
1097 sliceStubHitInds.emplace_back();
1098 for (
unsigned i_stub = 0; i_stub < sliceVertexHits.back().size(); i_stub++) {
1099 const std::vector<art::Ptr<sbn::Stub>> &this_vh = vertexStubs.at(i_stub);
1100 for (
unsigned i_vh_stub = 0; i_vh_stub < this_vh.size(); i_vh_stub++) {
1101 sliceStubs.back().push_back(this_vh.at(i_vh_stub));
1102 sliceStubHitInds.back().push_back(i_stub);
1106 art::FindManyP<recob::Hit> vertexStubHits(sliceStubs.back(),
evt,
fStubTags.at(i));
1107 sliceStubHits.emplace_back();
1108 for (
unsigned i_stub = 0; i_stub < sliceStubs.back().size(); i_stub++) {
1109 sliceStubHits.back().push_back(vertexStubHits.at(i_stub));
1112 art::FindManyP<recob::PFParticle> vertexStubPFPs(sliceStubs.back(),
evt,
fStubTags.at(i));
1113 art::Ptr<recob::PFParticle> nullPFP;
1114 sliceStubPFPs.emplace_back();
1115 for (
unsigned i_stub = 0; i_stub < sliceStubs.back().size(); i_stub++) {
1116 const std::vector<art::Ptr<recob::PFParticle>> &thisStubPFP = vertexStubPFPs.at(i_stub);
1117 if (thisStubPFP.size()) sliceStubPFPs.back().push_back(thisStubPFP.at(0));
1118 else sliceStubPFPs.back().push_back(nullPFP);
1121 sliceStubPFPHits.emplace_back();
1122 for (
unsigned i_stub = 0; i_stub < sliceStubPFPs.back().size(); i_stub++) {
1124 for (
unsigned i_pfp = 0; i_pfp < sliceParticles.back().size(); i_pfp++) {
1125 if (sliceStubPFPs.back()[i_stub] == sliceParticles.back()[i_pfp]) {
1126 sliceStubPFPHits.back().push_back(sliceParticleHits.back()[i_pfp]);
1132 sliceStubPFPHits.back().emplace_back();
1140 art::Handle<std::vector<simb::MCTruth>> trueNuHandle;
1141 evt.getByLabel(
"generator", trueNuHandle);
1142 std::vector<art::Ptr<simb::MCTruth>> trueNus;
1143 art::fill_ptr_vector(trueNus, trueNuHandle);
1145 art::Handle<std::vector<simb::MCParticle>> trueParticleHandle;
1146 evt.getByLabel(
"largeant", trueParticleHandle);
1147 std::vector<art::Ptr<simb::MCParticle>> trueParticles;
1148 art::fill_ptr_vector(trueParticles, trueParticleHandle);
1151 art::FindManyP<simb::MCParticle, sim::GeneratedParticleInfo> truth_to_particles(trueNus,
evt,
"largeant");
1159 for (
unsigned i_nu = 0; i_nu < trueNus.size(); i_nu++) {
1160 const simb::MCTruth &
nu = *trueNus[i_nu];
1162 TVector3 true_vertex = nu.NeutrinoSet() ? nu.GetNeutrino().Nu().Position().Vect() : nu.GetParticle(0).Position().Vect();
1163 if (!
InFV(true_vertex))
continue;
1169 for (
unsigned i_g4 = 0; i_g4 < trueParticles.size(); i_g4++) {
1170 const simb::MCParticle &particle = *trueParticles[i_g4];
1171 art::Ptr<simb::MCTruth> truth = inventory_service->TrackIdToMCTruth_P(particle.TrackId());
1172 if (truth == trueNus[i_nu]) {
1173 std::vector<const sim::IDE*> particle_ides(backtracker->TrackIdToSimIDEs_Ps(particle.TrackId()));
1174 for (
const sim::IDE *ide: particle_ides) visE += ide->energy;
1178 int slice_match = -1;
1180 for (
unsigned i_slice = 0; i_slice < slices.size(); i_slice++) {
1183 float matchingE = 0.;
1186 for (
unsigned i_match = 0; i_match < matches.size(); i_match++) {
1187 totalE += matches[i_match].second;
1190 for (
unsigned i_g4 = 0; i_g4 < trueParticles.size(); i_g4++) {
1191 for (
unsigned i_match = 0; i_match < matches.size(); i_match++) {
1192 if (matches[i_match].
first == trueParticles[i_g4]->TrackId()) {
1193 art::Ptr<simb::MCTruth> truth = inventory_service->TrackIdToMCTruth_P(trueParticles[i_g4]->TrackId());
1194 if (truth == trueNus[i_nu]) {
1195 matchingE += matches[i_match].second;
1204 if (matchingE / visE > 0.5) {
1205 if (matchingE / totalE > 0.5) slice_match = i_slice;
1210 if (slice_match < 0)
continue;
1215 const std::vector<art::Ptr<recob::PFParticle>> thisSliceParticles = sliceParticles.at(slice_match);
1216 const std::vector<std::vector<art::Ptr<recob::Hit>>> thisSliceParticleHits = sliceParticleHits.at(slice_match);
1217 const std::vector<std::vector<art::Ptr<recob::Vertex>>> thisSliceParticleVertexs = sliceParticleVertexs.at(slice_match);
1219 const std::vector<art::Ptr<sbn::VertexHit>> &thisVertexHits = sliceVertexHits.at(slice_match);
1220 const std::vector<art::Ptr<recob::Hit>> &thisVertexHitHits = sliceVertexHitHits.at(slice_match);
1221 const std::vector<art::Ptr<recob::SpacePoint>> &thisVertexHitSPs = sliceVertexHitSPs.at(slice_match);
1222 const std::vector<art::Ptr<recob::Vertex>> &thisVertexHitVtxs = sliceVertexHitVtxs.at(slice_match);
1224 const std::vector<art::Ptr<sbn::Stub>> &thisStubs = sliceStubs.at(slice_match);
1225 const std::vector<std::vector<art::Ptr<recob::Hit>>> &thisStubHits = sliceStubHits.at(slice_match);
1226 const std::vector<unsigned> &thisStubHitInds = sliceStubHitInds.at(slice_match);
1227 const std::vector<art::Ptr<recob::PFParticle>> &thisStubPFPs = sliceStubPFPs.at(slice_match);
1228 const std::vector<std::vector<art::Ptr<recob::Hit>>> &thisStubPFPHits = sliceStubPFPHits.at(slice_match);
1231 std::vector<sbn::StubInfo> thisStubInfos;
1232 for (
unsigned i = 0; i < thisStubs.size(); i++) {
1233 thisStubInfos.emplace_back();
1237 newStub.
stub = *thisStubs[i];
1238 newStub.
pfp = thisStubPFPs.at(i);
1239 newStub.
hits = thisStubHits.at(i);
1240 newStub.
vhit = thisVertexHits.at(thisStubHitInds[i]);
1241 newStub.
vhit_hit = thisVertexHitHits.at(thisStubHitInds[i]);
1244 (
void) thisVertexHitSPs;
1245 (
void) thisVertexHitVtxs;
1255 art::Ptr<recob::Vertex> vert;
1256 for (
unsigned i_pfp = 0; i_pfp < thisSliceParticles.size(); i_pfp++) {
1257 if (thisSliceParticles[i_pfp]->
IsPrimary() &&
1258 thisSliceParticleVertexs.at(i_pfp).size()) {
1259 vert = thisSliceParticleVertexs.at(i_pfp).at(0);
1264 double badpos[3] {-999., -999., -999.};
1269 std::vector<std::vector<std::pair<int, float>>> thisSlicePFPMatches;
1270 for (
unsigned i_pfp = 0; i_pfp < thisSliceParticles.size(); i_pfp++) {
1273 std::sort(matches.begin(), matches.end(),
1274 [](
auto const &lhs,
auto const &rhs) {
1275 return lhs.second > rhs.second;
1277 thisSlicePFPMatches.push_back(matches);
1284 FillNeutrino(nu, nu_vert, thisSliceParticles, thisSlicePFPMatches, truth_to_particles.at(i_nu), truth_to_particles.data(i_nu), *geo, dprop);
1287 FillVertexHits(thisVertexHits, thisVertexHitHits, dprop, clock_data, trueParticles);
1289 FillStubs(thisStubInfos, thisStubHitInds, geo, dprop, clock_data, trueParticles);
1291 FillStubPFPs(thisStubPFPs, thisStubPFPHits, clock_data, trueParticles);
std::vector< std::string > fStubTags
Internal struct: contains information on stub and other associated data products. ...
bool IsPrimary(const caf::SRTrueParticleProxy &p)
Whether this is a primary particle or generated by a secondary interaction.
Definition of vertex object for LArSoft.
std::vector< std::string > fPFParticleTags
std::vector< art::Ptr< recob::Hit > > hits
std::vector< std::pair< int, float > > AllTrueParticleIDEnergyMatches(const detinfo::DetectorClocksData &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
std::vector< std::string > fVertexHitTags
Ionization at a point of the TPC sensitive volume.
void FillVertexHits(const std::vector< art::Ptr< sbn::VertexHit >> &hits, const std::vector< art::Ptr< recob::Hit >> &hit_hits, const detinfo::DetectorPropertiesData &dprop, const detinfo::DetectorClocksData &clock_data, const std::vector< art::Ptr< simb::MCParticle >> &trueParticles)
art::Ptr< recob::Hit > vhit_hit
Description of geometry of one entire detector.
void FillStubPFPs(const std::vector< art::Ptr< recob::PFParticle >> &stub_pfps, const std::vector< std::vector< art::Ptr< recob::Hit >>> &stub_pfp_hits, const detinfo::DetectorClocksData &clock_data, const std::vector< art::Ptr< simb::MCParticle >> &trueParticles)
void FillNeutrino(const simb::MCTruth &nu, const recob::Vertex &vert, const std::vector< art::Ptr< recob::PFParticle >> &slice_pfps, const std::vector< std::vector< std::pair< int, float >>> &slice_pfp_matches, const std::vector< art::Ptr< simb::MCParticle >> &g4_mcparticles, const std::vector< const sim::GeneratedParticleInfo * > &infos, const geo::GeometryCore &geo, const detinfo::DetectorPropertiesData &dprop)
std::vector< TCSlice > slices
void FillMeta(const art::Event &evt)
art::Ptr< sbn::VertexHit > vhit
void FillStubs(const std::vector< sbn::StubInfo > &stubs, const std::vector< unsigned > &stub_hit_inds, const geo::GeometryCore *geo, const detinfo::DetectorPropertiesData &dprop, const detinfo::DetectorClocksData &clock_data, const std::vector< art::Ptr< simb::MCParticle >> &trueParticles)
void FillSlice(const std::vector< art::Ptr< recob::PFParticle >> &slice_particles)
art::Ptr< recob::PFParticle > pfp