15 #include "fhiclcpp/types/Atom.h"
16 #include "fhiclcpp/types/Table.h"
17 #include "fhiclcpp/types/Name.h"
18 #include "fhiclcpp/types/Comment.h"
19 #include "messagefacility/MessageLogger/MessageLogger.h"
22 #include "art/Framework/Core/EDAnalyzer.h"
23 #include "art/Framework/Core/ModuleMacros.h"
24 #include "art/Framework/Principal/Event.h"
25 #include "art/Framework/Principal/Handle.h"
26 #include "canvas/Persistency/Common/FindManyP.h"
27 #include "canvas/Utilities/InputTag.h"
43 size_t StringLength(
const T&
value) {
44 std::ostringstream sstr;
46 return sstr.str().length();
57 template <
typename STREAM,
typename CONT>
58 void PrintCompactIndexTable(
59 STREAM& log,
const CONT& Indices,
unsigned int IndicesPerLine,
60 std::string IndentStr =
"")
62 unsigned int Padding = StringLength(Indices.back());
64 typename CONT::const_iterator iIndex = Indices.begin(),
66 size_t RangeStart = *iIndex, RangeStop = RangeStart;
67 std::ostringstream output_line;
68 size_t nItemsInLine = 0;
69 while (++iIndex != iend) {
71 if (*iIndex == RangeStop + 1) {
77 if (nItemsInLine) output_line <<
" ";
78 if (RangeStart == RangeStop) {
79 output_line << std::setw(Padding) << RangeStart;
83 char fill = (RangeStart + 1 == RangeStop)?
' ':
'-';
84 output_line << std::setw(Padding) << RangeStart
86 << std::setw(Padding) << std::setfill(fill) << RangeStop
91 RangeStart = RangeStop = *iIndex;
95 if (nItemsInLine >= IndicesPerLine) {
97 log << IndentStr << output_line.str() <<
"\n";
104 log << IndentStr << output_line.str();
106 if (nItemsInLine) log <<
" ";
107 if (RangeStart == RangeStop)
108 log << std::setw(Padding) << RangeStart;
110 char fill = (RangeStart + 1 == RangeStop)?
' ':
'-';
111 log << std::setw(Padding) << RangeStart
113 << std::setw(Padding) << std::setfill(fill) << RangeStop
114 << std::setfill(
' ');
132 template <
typename STREAM,
typename CONT,
typename GETINDEX>
133 void PrintCompactIndexTable(
134 STREAM& log,
const CONT& Objects,
unsigned int IndicesPerLine,
135 GETINDEX IndexExtractor, std::string IndentStr)
137 if ((IndicesPerLine == 0) || Objects.empty())
return;
139 std::vector<size_t> Indices;
140 Indices.reserve(Objects.size());
141 std::transform(Objects.begin(), Objects.end(), std::back_inserter(Indices),
143 std::sort(Indices.begin(), Indices.end());
144 PrintCompactIndexTable(log, Indices, IndicesPerLine, IndentStr);
159 template <
typename STREAM,
typename T>
160 inline void PrintAssociatedIndexTable(
161 STREAM& log,
const std::vector<art::Ptr<T>>& Objects,
162 unsigned int IndicesPerLine, std::string IndentStr =
""
164 PrintCompactIndexTable(
165 log, Objects, IndicesPerLine, std::mem_fn(&art::Ptr<T>::key),
182 template <
typename STREAM,
typename T>
183 inline void PrintAssociatedIDTable(
184 STREAM& log,
const std::vector<art::Ptr<T>>& Objects,
185 unsigned int IndicesPerLine, std::string IndentStr =
""
187 PrintCompactIndexTable(
188 log, Objects, IndicesPerLine,
189 [](
const art::Ptr<T>& ptr) {
return ptr->ID(); },
237 Name(
"TrackModuleLabel"),
238 Comment(
"input tag for the tracks to be dumped")
241 Name(
"OutputCategory"),
242 Comment(
"name of the category used for message facility output"),
247 Comment(
"number of points along the trajectory printed"),
251 Name(
"SpacePointAssociations"),
252 Comment(
"prints the number of space points associated to the track"),
256 Name(
"PrintSpacePoints"),
257 Comment(
"prints the index of all space points associated to the track"),
261 Name(
"HitAssociations"),
262 Comment(
"prints the number of hits associated to the track"),
267 Comment(
"prints the index of all hits associated to the track"),
271 Name(
"ParticleAssociations"),
272 Comment(
"prints the number of PF particles associated to the track"),
313 : EDAnalyzer (config)
315 , fOutputCategory (config().OutputCategory())
316 , fPrintWayPoints (config().WayPoints())
317 , fPrintNHits (config().HitAssociations())
318 , fPrintNSpacePoints(config().SpacePointAssociations())
319 , fPrintNParticles (config().ParticleAssociations())
320 , fPrintHits (config().PrintHits())
321 , fPrintSpacePoints (config().PrintSpacePoints())
322 , fPrintParticles (config().ParticleAssociations())
333 <<
"The event contains " <<
Tracks->size() <<
" '"
336 std::unique_ptr<art::FindManyP<recob::Hit>> pHits(
341 if (pHits && !pHits->isValid()) {
342 throw art::Exception(art::errors::ProductNotFound)
347 std::unique_ptr<art::FindManyP<recob::SpacePoint>> pSpacePoints(
352 if (pSpacePoints && !pSpacePoints->isValid()) {
353 throw art::Exception(art::errors::ProductNotFound)
358 std::unique_ptr<art::FindManyP<recob::PFParticle>> pPFParticles(
363 if (pPFParticles && !pPFParticles->isValid()) {
364 throw art::Exception(art::errors::ProductNotFound)
365 <<
"No particle-flow particle associated with '"
369 for (
unsigned int iTrack = 0; iTrack <
Tracks->size(); ++iTrack) {
376 if (pHits || pSpacePoints || pPFParticles) {
377 log <<
"\n associated with:";
379 log <<
" " << pHits->at(iTrack).size() <<
" hits;";
381 log <<
" " << pSpacePoints->at(iTrack).size() <<
" space points;";
383 log <<
" " << pPFParticles->at(iTrack).size() <<
" PF particles;";
387 const auto&
Hits = pHits->at(iTrack);
388 log <<
"\n hit indices (" <<
Hits.size() <<
"):\n";
389 PrintAssociatedIndexTable(log,
Hits, 10 ,
" ");
393 const auto& SpacePoints = pSpacePoints->at(iTrack);
394 log <<
"\n space point IDs (" << SpacePoints.size() <<
"):\n";
395 PrintAssociatedIDTable
396 (log, SpacePoints, 10 ,
" ");
400 const auto& PFParticles = pPFParticles->at(iTrack);
401 log <<
"\n particle indices (" << PFParticles.size() <<
"):\n";
403 PrintAssociatedIndexTable
404 (log, PFParticles, 10 ,
" ");
416 mf::LogVerbatim log(fOutputCategory);
418 <<
"Track #" << iTrack <<
" ID: " << track.
ID()
419 << std::fixed << std::setprecision(3)
420 <<
" theta: " << track.
Theta() <<
" rad, phi: " << track.
Phi()
421 <<
" rad, length: " << track.
Length() <<
" cm"
422 <<
"\n start at: ( " << track.
Vertex().X()
423 <<
" ; " << track.
Vertex().Y()
424 <<
" ; " << track.
Vertex().Z()
428 <<
"\n end at: ( " << track.
End().X()
429 <<
" ; " << track.
End().Y()
430 <<
" ; " << track.
End().Z()
436 << nPoints <<
" trajectory points";
438 if (fPrintWayPoints > 0) {
440 log <<
"\n passes through:";
441 unsigned int skip = std::max(nPoints / fPrintWayPoints, 1U);
442 unsigned int iPoint = 0;
443 while ((iPoint += skip) < nPoints) {
445 log <<
"\n [#" << iPoint <<
"] ("
446 << point.X() <<
", " << point.Y() <<
", " << point.Z()
void DumpTrack(unsigned int iTrack, recob::Track const &track) const
Dumps information about the specified track.
fhicl::Atom< unsigned int > WayPoints
bool fPrintNSpacePoints
prints the number of associated space points
BEGIN_PROLOG pandoraGausReCaloCryo0 TrackModuleLabel
fhicl::Atom< std::string > OutputCategory
Declaration of signal hit object.
Point_t const & LocationAtPoint(size_t i) const
fhicl::Atom< bool > PrintHits
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Vector_t VertexDirection() const
process_name use argoneut_mc_hitfinder track
void analyze(const art::Event &evt)
Does the printing.
fhicl::Atom< bool > ParticleAssociations
art::EDAnalyzer::Table< Config > Parameters
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
double Length(size_t p=0) const
Access to various track properties.
art::InputTag fTrackModuleLabel
name of module that produced the tracks
fhicl::Atom< bool > PrintSpacePoints
bool fPrintNHits
prints the number of associated hits
double Theta() const
Access to spherical or geographical angles at vertex or at any point.
fhicl::Atom< bool > SpacePointAssociations
fhicl::Atom< bool > HitAssociations
Point_t const & Vertex() const
fhicl::Atom< art::InputTag > TrackModuleLabel
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
BEGIN_PROLOG vertical distance to the surface Name
Provides recob::Track data product.
bool fPrintHits
prints the index of associated hits
art::PtrVector< recob::Hit > Hits
Prints the content of all the tracks on screen.
DumpTracks(Parameters const &config)
Default constructor.
Vector_t EndDirection() const
bool fPrintNParticles
prints the number of associated PFParticles
std::string fOutputCategory
category for LogInfo output
Point_t const & End() const
bool fPrintParticles
prints the index of associated PFParticles
bool fPrintSpacePoints
prints the index of associated space points
unsigned int fPrintWayPoints
number of printed way points
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track: