7#include "art/Framework/Core/EDAnalyzer.h"
8#include "art/Framework/Core/ModuleMacros.h"
10#include "lardataobj/RecoBase/PFParticle.h"
11#include "lardataobj/RecoBase/Shower.h"
12#include "lardataobj/RecoBase/Track.h"
50 void analyze(
const art::Event& evt);
92 const art::Event& evt,
109#include "art/Framework/Principal/Event.h"
110#include "art/Framework/Principal/Handle.h"
111#include "art/Framework/Services/Registry/ServiceHandle.h"
112#include "art_root_io/TFileDirectory.h"
113#include "art_root_io/TFileService.h"
114#include "canvas/Persistency/Common/FindManyP.h"
115#include "fhiclcpp/ParameterSet.h"
116#include "messagefacility/MessageLogger/MessageLogger.h"
118#include "lardataobj/RecoBase/PFParticleMetadata.h"
127 fhicl::ParameterSet
const& pset)
128 :
art::EDAnalyzer(pset)
151 if (!pfParticleHandle.isValid()) {
152 mf::LogDebug(
"ConsolidatedPFParticleAnalysisTemplate")
153 <<
" Failed to find the PFParticles." << std::endl;
167 std::vector<art::Ptr<recob::PFParticle>> crParticles;
168 std::vector<art::Ptr<recob::PFParticle>> nuParticles;
176 std::vector<art::Ptr<recob::Track>> tracks;
177 std::vector<art::Ptr<recob::Shower>> showers;
181 std::cout <<
"Consolidated event summary:" << std::endl;
182 std::cout <<
" - Number of primary cosmic-ray PFParticles : " << crParticles.size()
184 std::cout <<
" - Number of neutrino final-state PFParticles : " << nuParticles.size()
186 std::cout <<
" ... of which are track-like : " << tracks.size() << std::endl;
187 std::cout <<
" ... of which are showers-like : " << showers.size() << std::endl;
196 for (
unsigned int i = 0; i < pfParticleHandle->size(); ++i) {
197 const art::Ptr<recob::PFParticle> pParticle(pfParticleHandle, i);
198 if (!pfParticleMap.insert(PFParticleIdMap::value_type(pParticle->Self(), pParticle)).second) {
199 throw cet::exception(
"ConsolidatedPFParticleAnalysisTemplate")
200 <<
" Unable to get PFParticle ID map, the input PFParticle collection has repeat IDs!";
208 const art::Event& evt,
212 art::FindManyP<larpandoraobj::PFParticleMetadata> pfPartToMetadataAssoc(
215 for (
unsigned int i = 0; i < pfParticleHandle->size(); ++i) {
216 const std::vector<art::Ptr<larpandoraobj::PFParticleMetadata>>& pfParticleMetadataList(
217 pfPartToMetadataAssoc.at(i));
218 if (!pfParticleMetadataList.empty()) {
219 const art::Ptr<recob::PFParticle> pParticle(pfParticleHandle, i);
220 for (
unsigned int j = 0; j < pfParticleMetadataList.size(); ++j) {
221 const art::Ptr<larpandoraobj::PFParticleMetadata>& pfParticleMetadata(
222 pfParticleMetadataList.at(j));
223 const larpandoraobj::PFParticleMetadata::PropertiesMap& pfParticlePropertiesMap(
224 pfParticleMetadata->GetPropertiesMap());
225 if (!pfParticlePropertiesMap.empty())
226 std::cout <<
" Found PFParticle " << pParticle->Self() <<
" with: " << std::endl;
227 for (larpandoraobj::PFParticleMetadata::PropertiesMap::const_iterator it =
228 pfParticlePropertiesMap.begin();
229 it != pfParticlePropertiesMap.end();
231 std::cout <<
" - " << it->first <<
" = " << it->second << std::endl;
244 for (PFParticleIdMap::const_iterator it = pfParticleMap.begin(); it != pfParticleMap.end();
246 const art::Ptr<recob::PFParticle> pParticle(it->second);
249 if (!pParticle->IsPrimary())
continue;
252 const int pdg(pParticle->PdgCode());
253 const bool isNeutrino(std::abs(pdg) == pandora::NU_E || std::abs(pdg) == pandora::NU_MU ||
254 std::abs(pdg) == pandora::NU_TAU);
258 crParticles.push_back(pParticle);
264 if (!nuParticles.empty()) {
265 throw cet::exception(
"ConsolidatedPFParticleAnalysisTemplate")
266 <<
" This event contains multiple reconstructed neutrinos!";
270 for (
const size_t daughterId : pParticle->Daughters()) {
271 if (pfParticleMap.find(daughterId) == pfParticleMap.end())
272 throw cet::exception(
"ConsolidatedPFParticleAnalysisTemplate")
273 <<
" Invalid PFParticle collection!";
275 nuParticles.push_back(pfParticleMap.at(daughterId));
285 const art::Event& evt,
290 art::FindManyP<recob::Track> pfPartToTrackAssoc(pfParticleHandle, evt,
m_trackLabel);
291 art::FindManyP<recob::Shower> pfPartToShowerAssoc(pfParticleHandle, evt,
m_showerLabel);
293 for (
const art::Ptr<recob::PFParticle>& pParticle : particles) {
294 const std::vector<art::Ptr<recob::Track>> associatedTracks(
295 pfPartToTrackAssoc.at(pParticle.key()));
296 const std::vector<art::Ptr<recob::Shower>> associatedShowers(
297 pfPartToShowerAssoc.at(pParticle.key()));
298 const unsigned int nTracks(associatedTracks.size());
299 const unsigned int nShowers(associatedShowers.size());
302 if (nTracks == 0 && nShowers == 0) {
303 mf::LogDebug(
"ConsolidatedPFParticleAnalysisTemplate")
304 <<
" No tracks or showers were associated to PFParticle " << pParticle->Self()
310 if (nTracks == 1 && nShowers == 0) {
311 tracks.push_back(associatedTracks.front());
316 if (nTracks == 0 && nShowers == 1) {
317 showers.push_back(associatedShowers.front());
321 throw cet::exception(
"ConsolidatedPFParticleAnalysisTemplate")
322 <<
" There were " << nTracks <<
" tracks and " << nShowers
323 <<
" showers associated with PFParticle " << pParticle->Self();
ConsolidatedPFParticleAnalysisTemplate class.
std::map< size_t, art::Ptr< recob::PFParticle > > PFParticleIdMap
std::string m_trackLabel
The label for the track producer from PFParticles.
void PrintOutScores(const art::Event &evt, const PFParticleHandle &pfParticleHandle) const
Print out scores in PFParticleMetadata.
bool m_printOutScores
Option to investigate the associations to scores for PFParticles.
std::vector< art::Ptr< recob::Shower > > ShowerVector
ConsolidatedPFParticleAnalysisTemplate(fhicl::ParameterSet const &pset)
Constructor.
std::string m_pandoraLabel
The label for the pandora producer.
std::string m_showerLabel
The label for the shower producer from PFParticles.
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
std::vector< art::Ptr< recob::Track > > TrackVector
void analyze(const art::Event &evt)
Analyze an event!
void GetPFParticleIdMap(const PFParticleHandle &pfParticleHandle, PFParticleIdMap &pfParticleMap)
Produce a mapping from PFParticle ID to the art ptr to the PFParticle itself for fast navigation.
void CollectTracksAndShowers(const PFParticleVector &particles, const PFParticleHandle &pfParticleHandle, const art::Event &evt, TrackVector &tracks, ShowerVector &showers)
Collect associated tracks and showers to particles in an input particle vector.
art::Handle< std::vector< recob::PFParticle > > PFParticleHandle
void reconfigure(fhicl::ParameterSet const &pset)
Configure memeber variables using FHiCL parameters.
void GetFinalStatePFParticleVectors(const PFParticleIdMap &pfParticleMap, PFParticleVector &crParticles, PFParticleVector &nuParticles)
Produce a mapping from PFParticle ID to the art ptr to the PFParticle itself for fast navigation.