All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DumpParticleIDs_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpParticleIDs_module.cc
3  * @brief Dump ParticleID objects.
4  * @author H. Greenlee
5  * @date Oct. 14, 2021
6  */
7 
8 // C//C++ standard libraries
9 #include <string>
10 
11 // support libraries
12 #include "fhiclcpp/types/Atom.h"
13 #include "fhiclcpp/types/Name.h"
14 #include "fhiclcpp/types/Comment.h"
15 
16 // art libraries
17 #include "art/Framework/Core/EDAnalyzer.h"
18 #include "art/Framework/Core/ModuleMacros.h"
19 #include "art/Framework/Principal/Event.h"
20 #include "canvas/Utilities/InputTag.h"
21 
22 // ... plus see below ...
23 
24 namespace pid {
25 
26  /**
27  * @brief Prints the content of all the partidle IDs on screen
28  *
29  * This analyser prints the content of all the particle IDs into the
30  * LogInfo/LogVerbatim stream.
31  *
32  * Configuration parameters
33  * =========================
34  *
35  * - *ParticleIDModuleLabel* (string): label of the producer used to create the
36  * anab::ParticleID collection
37  * - *OutputCategory* (string, default: "DumpParticleIDs"): the category
38  * used for the output (useful for filtering)
39  *
40  */
41  class DumpParticleIDs: public art::EDAnalyzer {
42  public:
43 
44  struct Config {
45  using Name = fhicl::Name;
46  using Comment = fhicl::Comment;
47 
48  fhicl::Atom<art::InputTag> ParticleIDModuleLabel{
49  Name("ParticleIDModuleLabel"),
50  Comment("tag of the producer used to create the anab::ParticleID collection")
51  };
52 
53  fhicl::Atom<std::string> OutputCategory{
54  Name("OutputCategory"),
55  Comment("the messagefacility category used for the output"),
56  "DumpParticleIDs"
57  };
58 
59  }; // Config
60 
61  using Parameters = art::EDAnalyzer::Table<Config>;
62 
63 
64  /// Default constructor
65  explicit DumpParticleIDs(Parameters const& config);
66 
67  /// Does the printing
68  void analyze (const art::Event& evt) override;
69 
70  private:
71 
72  art::InputTag const fParticleIDsModuleLabel; ///< name of module that produced the pids
73  std::string const fOutputCategory; ///< category for LogInfo output
74 
75  }; // class DumpParticleIDs
76 
77 } // namespace pid
78 
79 
80 //------------------------------------------------------------------------------
81 //--- module implementation
82 //---
83 // C//C++ standard libraries
84 #include <memory> // std::unique_ptr<>
85 
86 // support libraries
87 #include "messagefacility/MessageLogger/MessageLogger.h"
88 
89 // art libraries
90 #include "art/Framework/Principal/Handle.h"
91 
92 // LArSoft includes
94 
95 
96 namespace pid {
97 
98  //-------------------------------------------------
100  : EDAnalyzer (config)
101  , fParticleIDsModuleLabel (config().ParticleIDModuleLabel())
102  , fOutputCategory (config().OutputCategory())
103  {}
104 
105 
106  //-------------------------------------------------
107  void DumpParticleIDs::analyze(const art::Event& evt) {
108 
109  // fetch the data to be dumped on screen
110  auto const& ParticleIDs = evt.getProduct<std::vector<anab::ParticleID>>(fParticleIDsModuleLabel);
111 
112  mf::LogInfo(fOutputCategory)
113  << "The event contains " << ParticleIDs.size() << " '"
114  << fParticleIDsModuleLabel.encode() << "' particle IDs";
115 
116  unsigned int ipid = 0;
117  for (const anab::ParticleID& pid: ParticleIDs) {
118 
119  // print a header for the cluster
120  mf::LogVerbatim log(fOutputCategory);
121  log << "ParticleID #" << ipid << '\n';
122  log << "Plane ID = " << pid.PlaneID() << '\n';
123  auto scores = pid.ParticleIDAlgScores();
124  log << "Number of algorithms = " << scores.size() << '\n';
125  int ialg = 0;
126  for(const anab::sParticleIDAlgScores score: scores) {
127  log << " ParticleID #" << ipid << ", Algorithm " << ialg << '\n'
128  << " Algorithm name = " << score.fAlgName << '\n'
129  << " Variable type = " << score.fVariableType << '\n'
130  << " TrackDirection = " << score.fTrackDir << '\n'
131  << " NDF = " << score.fNdf << '\n'
132  << " Assumed PDG = " << score.fAssumedPdg << '\n'
133  << " Value = " << score.fValue << '\n'
134  << " Plane Mask = " << score.fPlaneMask << '\n';
135  ++ialg;
136  }
137 
138  ++ipid;
139  } // for pids
140 
141  } // DumpParticleIDs::analyze()
142 
143  DEFINE_ART_MODULE(DumpParticleIDs)
144 
145 } // namespace pid
fhicl::Atom< art::InputTag > ParticleIDModuleLabel
void analyze(const art::Event &evt) override
Does the printing.
BEGIN_PROLOG or score(default)}sbnd_crttrackmatchingalg_crID
Prints the content of all the partidle IDs on screen.
std::string const fOutputCategory
category for LogInfo output
BEGIN_PROLOG vertical distance to the surface Name
art::EDAnalyzer::Table< Config > Parameters
art::InputTag const fParticleIDsModuleLabel
name of module that produced the pids
physics analyzers analysistree true physics analyzers analysistree pandora physics analyzers analysistree pandoraTrack physics analyzers analysistree pandoraCalo physics analyzers analysistree ParticleIDModuleLabel
fhicl::Atom< std::string > OutputCategory
TCEvent evt
Definition: DataStructs.cxx:8
DumpParticleIDs(Parameters const &config)
Default constructor.