LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
LArPandoraEventDump_module.cc
Go to the documentation of this file.
1 
10 
11 #include "fhiclcpp/ParameterSet.h"
12 
14 
24 
26 
27 namespace lar_pandora
28 {
29 
31 {
32 public:
33  explicit LArPandoraEventDump(fhicl::ParameterSet const & pset);
34 
35  LArPandoraEventDump(LArPandoraEventDump const &) = delete;
39 
40  void analyze(art::Event const & evt) override;
41 
42 private:
44  const std::map< size_t, art::Ptr< recob::PFParticle > > &pfParticleIdMap,
45  const art::FindManyP<recob::SpacePoint> &pfPartToSpacePointAssoc,
46  const art::FindManyP<recob::Cluster> &pfPartToClusterAssoc,
47  const art::FindManyP<recob::Vertex> &pfPartToVertexAssoc,
48  const art::FindManyP<larpandoraobj::PFParticleMetadata> &pfPartToMetadataAssoc,
49  const art::FindManyP<recob::Track> &pfPartToTrackAssoc,
50  const art::FindManyP<recob::Shower> &pfPartToShowerAssoc,
51  const art::FindManyP<recob::PCAxis> &pfPartToPCAxisAssoc,
52  const int depth);
53 
54  std::string m_PandoraLabel;
55  std::string m_TrackLabel;
56  std::string m_ShowerLabel;
57 };
58 
60 
61 } // namespace lar_pandora
62 
63 //------------------------------------------------------------------------------------------------------------------------------------------
64 // implementation follows
65 
66 namespace lar_pandora
67 {
68 
70  EDAnalyzer(pset),
71  m_PandoraLabel(pset.get<std::string>("PandoraLabel")),
72  m_TrackLabel(pset.get<std::string>("TrackLabel" , m_PandoraLabel)),
73  m_ShowerLabel(pset.get<std::string>("ShowerLabel", m_PandoraLabel))
74 {
75 }
76 
77 //------------------------------------------------------------------------------------------------------------------------------------------
78 
80 {
81  std::cout << std::endl << std::endl;
82  std::cout << std::string(80, '-') << "\r- ";
83  std::cout << "Event " << std::endl;
84  std::cout << evt.id() << std::endl;
85  std::cout << m_PandoraLabel << std::endl;
86  std::cout << std::string(80, '-') << std::endl;
87 
88  // Get the input collections
97 
98  evt.getByLabel(m_PandoraLabel, pfParticleHandle);
99  evt.getByLabel(m_PandoraLabel, spacePointHandle);
100  evt.getByLabel(m_PandoraLabel, clusterHandle);
101  evt.getByLabel(m_PandoraLabel, vertexHandle);
102  evt.getByLabel(m_PandoraLabel, metadataHandle);
103  evt.getByLabel(m_TrackLabel, trackHandle);
104  evt.getByLabel(m_ShowerLabel, showerHandle);
105  evt.getByLabel(m_ShowerLabel, pcAxisHandle);
106 
107  // Get the associations
108  art::FindManyP<recob::SpacePoint> pfPartToSpacePointAssoc(pfParticleHandle, evt, m_PandoraLabel);
109  art::FindManyP<recob::Cluster> pfPartToClusterAssoc( pfParticleHandle, evt, m_PandoraLabel);
110  art::FindManyP<recob::Vertex> pfPartToVertexAssoc( pfParticleHandle, evt, m_PandoraLabel);
111  art::FindManyP<larpandoraobj::PFParticleMetadata> pfPartToMetadataAssoc( pfParticleHandle, evt, m_PandoraLabel);
112  art::FindManyP<recob::Track> pfPartToTrackAssoc( pfParticleHandle, evt, m_TrackLabel);
113  art::FindManyP<recob::Shower> pfPartToShowerAssoc( pfParticleHandle, evt, m_ShowerLabel);
114  art::FindManyP<recob::PCAxis> pfPartToPCAxisAssoc( pfParticleHandle, evt, m_ShowerLabel);
115 
116  art::FindManyP<recob::Hit> spacePointToHitAssoc(spacePointHandle, evt, m_PandoraLabel);
117  art::FindManyP<recob::Hit> clusterToHitAssoc( clusterHandle , evt, m_PandoraLabel);
118  art::FindManyP<recob::Hit> trackToHitAssoc( trackHandle , evt, m_TrackLabel);
119  art::FindManyP<recob::Hit> showerToHitAssoc( showerHandle , evt, m_ShowerLabel);
120 
121  art::FindManyP<recob::PCAxis> showerToPCAxisAssoc(showerHandle, evt, m_ShowerLabel);
122 
123  // Write out the collection sizes
124  std::cout << "N PFParticles : " << pfParticleHandle->size() << std::endl;
125  std::cout << "N SpacePoints : " << spacePointHandle->size() << std::endl;
126  std::cout << "N Clusters : " << clusterHandle->size() << std::endl;
127  std::cout << "N Vertices : " << vertexHandle->size() << std::endl;
128  std::cout << "N Metadata : " << metadataHandle->size() << std::endl;
129  std::cout << "N Tracks : " << trackHandle->size() << std::endl;
130  std::cout << "N Showers : " << showerHandle->size() << std::endl;
131  std::cout << "N PCAxes : " << pcAxisHandle->size() << std::endl;
132  std::cout << std::string(80, '-') << std::endl;
133 
134  // Get the PFParticles ID map
135  std::map< size_t, art::Ptr< recob::PFParticle > > pfParticleIdMap;
136  for (unsigned int i = 0; i < pfParticleHandle->size(); ++i)
137  {
138  art::Ptr<recob::PFParticle> part(pfParticleHandle, i);
139  pfParticleIdMap[part->Self()] = part;
140  }
141 
142  // Output the PFParticle hierarchy
143  for (auto it = pfParticleIdMap.begin(); it != pfParticleIdMap.end(); ++it)
144  {
145  art::Ptr< recob::PFParticle > part = it->second;
146 
147  if (part->IsPrimary())
148  {
149  this->PrintParticle(part, pfParticleIdMap, pfPartToSpacePointAssoc, pfPartToClusterAssoc, pfPartToVertexAssoc,
150  pfPartToMetadataAssoc, pfPartToTrackAssoc, pfPartToShowerAssoc, pfPartToPCAxisAssoc, 0);
151  }
152  }
153 
154  std::cout << std::string(80, '-') << std::endl;
155 }
156 
157 //------------------------------------------------------------------------------------------------------------------------------------------
158 
160  const std::map< size_t, art::Ptr< recob::PFParticle > > &pfParticleIdMap,
161  const art::FindManyP<recob::SpacePoint> &pfPartToSpacePointAssoc,
162  const art::FindManyP<recob::Cluster> &pfPartToClusterAssoc,
163  const art::FindManyP<recob::Vertex> &pfPartToVertexAssoc,
164  const art::FindManyP<larpandoraobj::PFParticleMetadata> &pfPartToMetadataAssoc,
165  const art::FindManyP<recob::Track> &pfPartToTrackAssoc,
166  const art::FindManyP<recob::Shower> &pfPartToShowerAssoc,
167  const art::FindManyP<recob::PCAxis> &pfPartToPCAxisAssoc,
168  const int depth)
169 {
170  const int w(16);
171  const std::string indent(std::string(depth, ' '));
172  const std::string rule(indent + std::string(2 * w, '-'));
173 
174  // Output the basic PFParticle information
175  std::cout << std::endl << rule << std::endl;
176  std::cout << indent << "PFParticle" << std::endl;
177  std::cout << rule << std::endl;
178  std::cout << indent << std::setw(w) << std::left << "- Key" << part.key() << std::endl;
179  std::cout << indent << std::setw(w) << std::left << "- Id" << part->Self() << std::endl;
180 
181  if (part->IsPrimary())
182  {
183  std::cout << indent << std::setw(w) << std::left << "- Primary" << std::endl;
184  }
185  else
186  {
187  std::cout << indent << std::setw(w) << std::left << "- Parent" << part->Parent() << std::endl;
188  }
189 
190  std::cout << indent << std::setw(w) << "- PDG" << part->PdgCode() << std::endl;
191  std::cout << rule << std::endl;
192 
193  // Get the associated objects
194  const std::vector< art::Ptr< recob::SpacePoint > > &spacePoints = pfPartToSpacePointAssoc.at( part.key() );
195  const std::vector< art::Ptr< recob::Cluster > > &clusters = pfPartToClusterAssoc.at( part.key() );
196  const std::vector< art::Ptr< recob::Vertex > > &vertices = pfPartToVertexAssoc.at( part.key() );
197  const std::vector< art::Ptr< larpandoraobj::PFParticleMetadata > > &metadata = pfPartToMetadataAssoc.at( part.key() );
198  const std::vector< art::Ptr< recob::Track > > &tracks = pfPartToTrackAssoc.at( part.key() );
199  const std::vector< art::Ptr< recob::Shower > > &showers = pfPartToShowerAssoc.at( part.key() );
200  const std::vector< art::Ptr< recob::PCAxis > > &pcAxes = pfPartToPCAxisAssoc.at( part.key() );
201 
202  // Output the number of associated objects
203  std::cout << indent << std::setw(w) << std::left << "- # SpacePoint" << spacePoints.size() << std::endl;
204  std::cout << indent << std::setw(w) << std::left << "- # Cluster" << clusters.size() << std::endl;
205  std::cout << indent << std::setw(w) << std::left << "- # Vertex" << vertices.size() << std::endl;
206  std::cout << indent << std::setw(w) << std::left << "- # Track" << tracks.size() << std::endl;
207  std::cout << indent << std::setw(w) << std::left << "- # Shower" << showers.size() << std::endl;
208  std::cout << indent << std::setw(w) << std::left << "- # PCAxis" << pcAxes.size() << std::endl;
209  std::cout << indent << std::setw(w) << std::left << "- # Metadata" << metadata.size() << std::endl;
210 
211  for (unsigned int metadataId = 0; metadataId < metadata.size(); ++metadataId)
212  {
213  for (const auto &propertiesMapEntry : metadata.at(metadataId)->GetPropertiesMap())
214  std::cout << indent << std::setw(w) << std::left << "-- Property " << propertiesMapEntry.first << ", value " << propertiesMapEntry.second << std::endl;
215  }
216 
217  std::cout << rule << std::endl;
218  std::cout << indent << std::setw(w) << std::left << "- # Daughters" << part->NumDaughters() << std::endl;
219  std::cout << rule << std::endl;
220 
221  for (auto &daughterId : part->Daughters())
222  {
223  art::Ptr< recob::PFParticle > daughter = pfParticleIdMap.at(daughterId);
224  this->PrintParticle(daughter, pfParticleIdMap, pfPartToSpacePointAssoc, pfPartToClusterAssoc, pfPartToVertexAssoc,
225  pfPartToMetadataAssoc, pfPartToTrackAssoc, pfPartToShowerAssoc, pfPartToPCAxisAssoc, depth + 4);
226  }
227 }
228 
229 } // namespace lar_pandora
230 
key_type key() const
Definition: Ptr.h:356
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
Definition: PFParticle.h:114
int NumDaughters() const
Returns the number of daughter particles flowing from this one.
Definition: PFParticle.h:89
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
LArPandoraEventDump(fhicl::ParameterSet const &pset)
Declaration of signal hit object.
void PrintParticle(const art::Ptr< recob::PFParticle > &part, const std::map< size_t, art::Ptr< recob::PFParticle > > &pfParticleIdMap, const art::FindManyP< recob::SpacePoint > &pfPartToSpacePointAssoc, const art::FindManyP< recob::Cluster > &pfPartToClusterAssoc, const art::FindManyP< recob::Vertex > &pfPartToVertexAssoc, const art::FindManyP< larpandoraobj::PFParticleMetadata > &pfPartToMetadataAssoc, const art::FindManyP< recob::Track > &pfPartToTrackAssoc, const art::FindManyP< recob::Shower > &pfPartToShowerAssoc, const art::FindManyP< recob::PCAxis > &pfPartToPCAxisAssoc, const int depth)
LArPandoraEventDump & operator=(LArPandoraEventDump const &)=delete
STL namespace.
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:83
Metadata associated with a pandora produced PFParticle.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
size_t Parent() const
Definition: PFParticle.h:96
TString part[npart]
Definition: Style.C:32
std::string indent(std::size_t const i)
bool IsPrimary() const
Returns whether the particle is the root of the flow.
Definition: PFParticle.h:86
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Declaration of cluster object.
Provides recob::Track data product.
void analyze(art::Event const &evt) override
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
Utility object to perform functions of association.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Float_t w
Definition: plot.C:23
EventID id() const
Definition: Event.h:56