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
13 
14 // framework libraries
18 
22 
23 #include "fhiclcpp/types/Atom.h"
25 #include "fhiclcpp/types/Name.h"
26 #include "fhiclcpp/types/Comment.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  */
49  public:
50 
51  struct Config {
52  using Name = fhicl::Name;
54 
56  Name("particles"),
57  Comment
58  ("collections of particle flow objects to be made into showers")
59  };
60 
61  }; // struct Config
62 
64 
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>>
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 // -----------------------------------------------------------------------------
171 
172 // -----------------------------------------------------------------------------
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
ChannelGroupService::Name Name
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
static Config * config
Definition: config.cpp:1054
def move(depos, offset)
Definition: depos.py:107
Creates some dummy showers and associations to PFParticle objects.
virtual void produce(art::Event &event) override
#define Comment
std::vector< art::InputTag > particleTags
List of PFParticle tags.
LArSoft-specific namespace.
std::vector< art::Ptr< recob::PFParticle > > collectPFOs(art::Event const &event) const
Returns a list of PFParticle objects to be made into showers.
Event finding and building.