All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AssnsChainShowerMaker_module.cc
Go to the documentation of this file.
1 /**
2  * @file AssnsChainShowerMaker_module.cc
3  * @brief Test producer creating a few dummy showers associated with
4  * PFParticle.
5  * @author Gianluca Petrillo (petrillo@fnal.gov)
6  * @date June 26, 2017
7  */
8 
9 // LArSoft libraries
10 #include "art/Persistency/Common/PtrMaker.h"
13 
14 // framework libraries
15 #include "art/Framework/Core/EDProducer.h"
16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Principal/Event.h"
18 
19 #include "canvas/Persistency/Common/Ptr.h"
20 #include "canvas/Persistency/Common/Assns.h"
21 #include "canvas/Utilities/InputTag.h"
22 
23 #include "fhiclcpp/types/Atom.h"
24 #include "fhiclcpp/types/Sequence.h"
25 #include "fhiclcpp/types/Name.h"
26 #include "fhiclcpp/types/Comment.h"
27 #include "messagefacility/MessageLogger/MessageLogger.h"
28 
29 // C/C++ standard libraries
30 #include <utility> // std::move()
31 #include <memory> // std::make_unique()
32 
33 
34 namespace lar {
35  namespace test {
36 
37  // -------------------------------------------------------------------------
38  /**
39  * @brief Creates some dummy showers and associations to PFParticle objects.
40  *
41  * Configuration parameters
42  * =========================
43  *
44  * * *particles* (list of input tags): collections of the particle flow
45  * objects to be made into showers
46  *
47  */
48  class AssnsChainShowerMaker: public art::EDProducer {
49  public:
50 
51  struct Config {
52  using Name = fhicl::Name;
53  using Comment = fhicl::Comment;
54 
55  fhicl::Sequence<art::InputTag> particles{
56  Name("particles"),
57  Comment
58  ("collections of particle flow objects to be made into showers")
59  };
60 
61  }; // struct Config
62 
63  using Parameters = art::EDProducer::Table<Config>;
64 
65  explicit AssnsChainShowerMaker(Parameters const& config)
66  : EDProducer{config}, particleTags(config().particles())
67  {
68  produces<std::vector<recob::Shower>>();
69  produces<art::Assns<recob::PFParticle, recob::Shower>>();
70  }
71 
72  virtual void produce(art::Event& event) override;
73 
74  private:
75  std::vector<art::InputTag> particleTags; ///< List of PFParticle tags.
76 
77  /// Returns a list of PFParticle objects to be made into showers.
78  std::vector<art::Ptr<recob::PFParticle>> collectPFOs
79  (art::Event const& event) const;
80 
81  }; // AssnsChainShowerMaker
82 
83  // -------------------------------------------------------------------------
84 
85 
86  } // namespace test
87 } // namespace lar
88 
89 
90 // -----------------------------------------------------------------------------
92 
93  //
94  // prepare input: merge all hits in a single collection
95  //
96  std::vector<art::Ptr<recob::PFParticle>> particles = collectPFOs(event);
97 
98  //
99  // prepare output
100  //
101  auto showers = std::make_unique<std::vector<recob::Shower>>();
102  auto PFOshowerAssns
103  = std::make_unique<art::Assns<recob::PFParticle, recob::Shower>>();
104 
105  //
106  // create the showers
107  //
108  unsigned int nShowers = particles.size();
109 
110  art::PtrMaker<recob::Shower> ptrMaker(event);
111 
112  for (unsigned int i = 0; i < nShowers; ++i) {
113 
114  //
115  // generate the shower
116  //
117  showers->push_back(recob::Shower(
118  { 0.0, 0.0, 1.0 }, // dcosVtx
119  { 0.1, 0.1, 0.1 }, // dcosVtxErr
120  { 0.0, 0.0, 0.0 }, // xyz
121  { 1.0, 1.0, 1.0 }, // xyzErr
122  { 1.0, 1.0, 1.0 }, // TotalEnergy
123  { 0.1, 0.1, 0.1 }, // TotalEnergyErr
124  { 2.0, 2.0, 2.0 }, // dEdx
125  { 0.1, 0.1, 0.1 }, // dEdxErr
126  0, // bestplane
127  i, // id
128  1.0, // length
129  1.0 // openAngle
130  ));
131 
132  //
133  // generate associations
134  //
135  PFOshowerAssns->addSingle(particles[i], ptrMaker(i));
136 
137  } // for
138 
139  mf::LogInfo("AssnsChainShowerMaker")
140  << "Created " << showers->size() << " showers from " << particles.size()
141  << " particle flow objects and " << PFOshowerAssns->size()
142  << " associations from " << particleTags.size() << " collections";
143 
144  event.put(std::move(showers));
145  event.put(std::move(PFOshowerAssns));
146 
147 } // lar::test::AssnsChainShowerMaker::produce()
148 
149 
150 // -----------------------------------------------------------------------------
151 std::vector<art::Ptr<recob::PFParticle>>
152 lar::test::AssnsChainShowerMaker::collectPFOs(art::Event const& event) const {
153 
154  std::vector<art::Ptr<recob::PFParticle>> allPFOs;
155 
156  for (auto const& tag: particleTags) {
157  auto PFOs = event.getValidHandle<std::vector<recob::PFParticle>>(tag);
158 
159  std::size_t const nPFOs = PFOs->size();
160  for (std::size_t i = 0; i < nPFOs; ++i)
161  allPFOs.emplace_back(PFOs, i);
162 
163  } // for
164 
165  return allPFOs;
166 } // lar::test::AssnsChainShowerMaker::collectHits()
167 
168 
169 // -----------------------------------------------------------------------------
170 DEFINE_ART_MODULE(lar::test::AssnsChainShowerMaker)
171 
172 // -----------------------------------------------------------------------------
BEGIN_PROLOG vertical distance to the surface Name
Creates some dummy showers and associations to PFParticle objects.
virtual void produce(art::Event &event) override
std::vector< art::InputTag > particleTags
List of PFParticle tags.
art::EDProducer::Table< Config > Parameters
BEGIN_PROLOG hitmakerfive clustermakerfour pfparticlemakerthree showermakertwo END_PROLOG hitmakerfive clustermakerfour pfparticlemakerthree sequence::inline_paths sequence::inline_paths sequence::inline_paths showermakers test
std::vector< art::Ptr< recob::PFParticle > > collectPFOs(art::Event const &event) const
Returns a list of PFParticle objects to be made into showers.