218 const std::vector<art::Ptr<simb::MCTruth>> truthVec =
particleInventory->MCTruthVector_Ps();
220 std::cout << std::setprecision(1) << std::fixed;
222 for (
auto const &truth : truthVec) {
223 std::cout <<
"Truth: " << truth << std::endl;
224 if (truth->NeutrinoSet()) {
225 const simb::MCNeutrino neutrino = truth->GetNeutrino();
226 std::cout <<
"Neutrino: " << neutrino << std::endl;
228 const simb::MCParticle
nu = neutrino.Nu();
229 std::cout <<
"X: " << nu.Vx() <<
" Y: " << nu.Vy() <<
" Z " << nu.Vz() << std::endl;
233 std::cout << std::setprecision(2) << std::fixed;
236 std::map<int, art::Ptr<simb::MCTruth>> particleTruthMap;
238 for (
auto const &[trackId, particle] : trueParticlesMap) {
246 auto hitHandles =
evt.getMany<std::vector<recob::Hit>>();
249 auto vertexHandles =
evt.getMany<std::vector<recob::Vertex>>();
252 art::Handle<std::vector<recob::Hit>> hitHandle;
253 art::Handle<std::vector<recob::PFParticle>> pfpHandle;
254 art::Handle<std::vector<recob::Slice>> sliceHandle;
255 art::Handle<std::vector<recob::Vertex>> vertexHandle;
258 std::vector<art::Ptr<recob::Hit>> allHits;
260 art::fill_ptr_vector(allHits, hitHandle);
263 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(
evt);
264 std::map<art::Ptr<simb::MCTruth>,
int> truthHitMap =
265 GetTruthHitMap(clockData, trueParticlesMap, particleTruthMap, allHits);
268 std::map<std::string, std::map<art::Ptr<simb::MCTruth>,
unsigned int>> pfpTruthNuCounterMap;
269 std::map<std::string, std::map<art::Ptr<simb::MCTruth>,
unsigned int>> pfpTruthSliceCounterMap;
270 std::map<std::string, std::map<art::Ptr<simb::MCTruth>, SliceMatch>> pfpTruthSliceMatchMap;
274 for (
auto const &truth : truthVec) {
275 pfpTruthNuCounterMap[fPFParticleLabel][truth] = 0;
276 pfpTruthSliceCounterMap[fPFParticleLabel][truth] = 0;
280 for (
auto const fPFParticleLabel : fPFParticleLabels) {
283 std::cout <<
"On PFParticleLabel: " << fPFParticleLabel << std::endl;
287 std::vector<art::Ptr<recob::Slice>> pfpSliceVec;
288 if (
evt.getByLabel(fPFParticleLabel, sliceHandle))
289 art::fill_ptr_vector(pfpSliceVec, sliceHandle);
291 std::vector<art::Ptr<recob::PFParticle>> pfps;
292 if (
evt.getByLabel(fPFParticleLabel, pfpHandle))
293 art::fill_ptr_vector(pfps, pfpHandle);
295 art::FindOneP<recob::Vertex> fopfv(pfpHandle,
evt, fPFParticleLabel);
296 if (fopfv.isValid() && fopfv.size() > 0) {
297 evt.get(fopfv.at(0).id(), vertexHandle);
298 if (!vertexHandle.isValid()) {
299 std::cout <<
"Vertex handle not valid" << std::endl;
304 art::FindManyP<recob::Hit> fmSliceHits(pfpSliceVec,
evt, fPFParticleLabel);
305 if (!fmSliceHits.isValid() || fmSliceHits.size() == 0) {
306 std::cout <<
"FindMany Slice Hits not valid" << std::endl;
309 art::FindManyP<recob::PFParticle> fmSlicePFPs(pfpSliceVec,
evt, fPFParticleLabel);
310 if (!fmSlicePFPs.isValid()) {
311 std::cout <<
"FindMany Slice PFPs not valid" << std::endl;
315 art::FindManyP<larpandoraobj::PFParticleMetadata> fmpfpmd(pfps,
evt, fPFParticleLabel);
316 if (!fmpfpmd.isValid()) {
317 std::cout <<
"PFP MetaData handle not valid" << std::endl;
323 std::map<long unsigned int, art::Ptr<recob::PFParticle>> pfpMap;
324 std::map<long unsigned int, float> pfpNuScoreMap;
325 std::vector<art::Ptr<recob::PFParticle>> pfpNeutrinoVec;
327 for (
auto const &pfp : pfps) {
329 long unsigned int pfpID = pfp->Self();
333 if (pfp->PdgCode() == 12 || pfp->PdgCode() == 14) {
334 pfpNeutrinoVec.push_back(pfp);
335 if (fmpfpmd.size() == 0) {
336 std::cout <<
"PFP neutrino has no metadata" << std::endl;
341 const std::vector<art::Ptr<larpandoraobj::PFParticleMetadata>> pfpMetaVec =
343 for (
auto const pfpMeta : pfpMetaVec) {
345 pfpMeta->GetPropertiesMap();
346 pfpNuScoreMap[pfpID] = propertiesMap.at(
"NuScore");
354 for (
const auto &pfpSlice : pfpSliceVec) {
356 std::vector<art::Ptr<recob::Hit>> sliceHits = fmSliceHits.at(pfpSlice.key());
357 std::vector<art::Ptr<recob::PFParticle>> slicePFPs = fmSlicePFPs.at(pfpSlice.key());
359 bool isNeutrinoSlice(
false);
361 long unsigned int pfpNu(-999);
363 for (
auto const &pfp : slicePFPs) {
364 if (pfp->PdgCode() == 12 || pfp->PdgCode() == 14) {
366 nuScore = pfpNuScoreMap[pfpNu];
367 isNeutrinoSlice =
true;
373 float purity(-999), completeness(-999);
375 clockData, sliceHits, particleTruthMap, truthHitMap, completeness, purity);
378 if (trueMatch.isNull())
382 std::cout <<
"True Match: " << trueMatch <<
" with completeness: " << completeness
383 <<
" and purity: " << purity <<
" and score: " << nuScore << std::endl;
386 ++pfpTruthSliceCounterMap[fPFParticleLabel][trueMatch];
387 if (isNeutrinoSlice) {
388 ++pfpTruthNuCounterMap[fPFParticleLabel][trueMatch];
389 if (trueMatch->NeutrinoSet()) {
397 if (completeness > pfpTruthSliceMatchMap[fPFParticleLabel][trueMatch].mComp) {
398 if (isNeutrinoSlice) {
400 art::Ptr<recob::PFParticle> pfpNeutrino = pfpMap.at(pfpNu);
401 art::Ptr<recob::Vertex> pfpVertex = fopfv.at(pfpNeutrino.key());
402 double pfpVtx[3] = {-999, -999, -999};
403 pfpVertex->XYZ(pfpVtx);
405 SliceMatch match(pfpNu, pfpNeutrino->PdgCode(), completeness, purity, nuScore, pfpVtx);
407 pfpTruthSliceMatchMap[fPFParticleLabel][trueMatch] = match;
410 double pfpVtx[3] = {-999, -999, -999};
411 SliceMatch match(-999, -999, completeness, purity, -999, pfpVtx);
412 pfpTruthSliceMatchMap[fPFParticleLabel][trueMatch] = match;
421 for (
auto const &truth : truthVec) {
426 if (!truth->NeutrinoSet())
430 const simb::MCNeutrino neutrino = truth->GetNeutrino();
431 const simb::MCParticle nu = neutrino.Nu();
432 const simb::MCParticle lepton = neutrino.Lepton();
435 CCNC = neutrino.CCNC();
440 QSqr = neutrino.QSqr();
442 Theta = neutrino.Theta();
454 for (
auto const &[particleId, truthIter] : particleTruthMap) {
455 if (truthIter != truth)
457 const simb::MCParticle *particle = trueParticlesMap.at(particleId);
459 if (particle->Process() !=
"primary")
462 if (particle->PdgCode() == 2212 && (particle->E() - particle->Mass()) > 0.021) {
464 }
else if (
std::abs(particle->PdgCode()) == 211) {
466 }
else if (
std::abs(particle->PdgCode()) == 111) {
472 std::cout <<
"\nTruth: " << truth << std::endl;
475 for (
auto const fPFParticleLabel : fPFParticleLabels) {
478 if (pfpTruthSliceCounterMap[fPFParticleLabel].at(truth)) {
480 SliceMatch match = pfpTruthSliceMatchMap[fPFParticleLabel][truth];
482 nuSlices[fPFParticleLabel] = pfpTruthSliceCounterMap[fPFParticleLabel][truth];
483 nuNeutrinos[fPFParticleLabel] = pfpTruthNuCounterMap[fPFParticleLabel][truth];
487 bestNuPdg[fPFParticleLabel] = match.mRecoPdg;
508 std::cout <<
"PFParticleLabel: " << fPFParticleLabel << std::endl;
511 <<
" and Nu Neutrinos: " <<
nuNeutrinos[fPFParticleLabel]
512 <<
" with best Nu Pdg: " <<
bestNuPdg[fPFParticleLabel]
513 <<
"\nCompleteness: " <<
bestNuComp[fPFParticleLabel]
515 <<
" and score: " <<
bestNuScore[fPFParticleLabel] << std::endl;
std::map< std::string, float > pfpVertexDistZ
std::vector< std::string > fPFParticleLabels
art::ServiceHandle< cheat::ParticleInventoryService > particleInventory
std::map< std::string, int > eventPFPSlices
std::map< art::Ptr< simb::MCTruth >, int > GetTruthHitMap(const detinfo::DetectorClocksData &clockData, const sim::ParticleList &trueParticlesMap, const std::map< int, art::Ptr< simb::MCTruth >> &particleTruthMap, const std::vector< art::Ptr< recob::Hit >> &allHits)
std::map< std::string, float > PropertiesMap
std::map< std::string, float > pfpVertexDistX
std::map< std::string, std::vector< float > > eventNeutrinoScores
art::Ptr< simb::MCTruth > GetSliceTruthMatchHits(const detinfo::DetectorClocksData &clockData, const std::vector< art::Ptr< recob::Hit >> &sliceHits, const std::map< int, art::Ptr< simb::MCTruth >> &particleTruthMap, const std::map< art::Ptr< simb::MCTruth >, int > &truthHitMap, float &completeness, float &purity)
std::map< std::string, float > bestNuPurity
std::map< std::string, std::vector< float > > eventCosmicScores
std::map< std::string, float > pfpVertexDistMag
std::map< std::string, int > nuNeutrinos
std::map< std::string, float > pfpVertexDistY
std::map< std::string, float > bestNuComp
std::map< std::string, float > pfpVertexZ
std::map< std::string, bool > nuMatchNeutrino
std::map< std::string, float > bestNuScore
std::map< std::string, int > nuSlices
std::map< std::string, float > pfpVertexX
std::map< std::string, float > pfpVertexY
std::map< std::string, int > eventPFPNeutrinos
BEGIN_PROLOG could also be cout
std::map< std::string, int > bestNuPdg