All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowerCosmicDistance_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: ShowerCosmicDistance
3 // Plugin Type: producer (art v3_03_01)
4 // File: ShowerCosmicDistance_module.cc
5 //
6 // Generated at Tue Sep 15 08:54:39 2020 by Edward Tyley using cetskelgen
7 // from cetlib version v3_08_00.
8 //
9 // Producer to find the distance of closest approach from a shower to
10 // a unambiguous cosmic ray
11 ////////////////////////////////////////////////////////////////////////
12 
13 #include "art/Framework/Core/EDProducer.h"
14 #include "art/Framework/Core/ModuleMacros.h"
15 #include "art/Framework/Principal/Event.h"
16 #include "art/Framework/Principal/Handle.h"
17 #include "art/Framework/Principal/Run.h"
18 #include "art/Framework/Principal/SubRun.h"
19 #include "canvas/Utilities/InputTag.h"
20 #include "fhiclcpp/ParameterSet.h"
22 #include "messagefacility/MessageLogger/MessageLogger.h"
23 
24 #include "canvas/Persistency/Common/FindManyP.h"
30 
31 #include <memory>
32 
33 #include "TF1.h"
34 #include "TGraph.h"
35 
36 namespace sbn {
37 class ShowerCosmicDistance : public art::EDProducer {
38  public:
39  explicit ShowerCosmicDistance(fhicl::ParameterSet const& p);
40  // The compiler-generated destructor is fine for non-base
41  // classes without bare pointers or other resource use.
42 
43  // Plugins should not be copied or assigned.
48 
49  // Required functions.
50  void produce(art::Event& e) override;
51 
52  private:
53  // FCL params
54  const art::InputTag fPandoraLabel;
55  const art::InputTag fShowerLabel;
56 
57  const float fMinShowerEnergy;
58 
59  const std::vector<art::Ptr<recob::PFParticle>> GetCosmicPFPs(const std::vector<art::Ptr<recob::PFParticle>>& pfps,
60  const art::FindManyP<larpandoraobj::PFParticleMetadata> fmPFPMeta) const;
61 
62  const float FindShowerResidual(const recob::Shower& shower,
63  const std::vector<art::Ptr<recob::PFParticle>>& cosmicPFPs,
64  const art::FindManyP<recob::SpacePoint>& fmPFPSP) const;
65 };
66 
67 ShowerCosmicDistance::ShowerCosmicDistance(fhicl::ParameterSet const& p)
68  : EDProducer { p }
69  , fPandoraLabel(p.get<art::InputTag>("PandoraLabel"))
70  , fShowerLabel(p.get<art::InputTag>("ShowerLabel"))
71  , fMinShowerEnergy(p.get<float>("MinShowerEnergy"))
72 {
73  produces<std::vector<float>>();
74  produces<art::Assns<recob::Shower, float>>();
75 }
76 
78 {
79  //Get the showers
80  auto const showerHandle = e.getValidHandle<std::vector<recob::Shower>>(fShowerLabel);
81  auto const pfpHandle = e.getValidHandle<std::vector<recob::PFParticle>>(fPandoraLabel);
82 
83  std::vector<art::Ptr<recob::Shower>> showers;
84  art::fill_ptr_vector(showers, showerHandle);
85 
86  std::vector<art::Ptr<recob::PFParticle>> pfps;
87  art::fill_ptr_vector(pfps, pfpHandle);
88 
89  const art::FindManyP<larpandoraobj::PFParticleMetadata> fmPFPMeta(pfpHandle, e, fPandoraLabel);
90  if (!fmPFPMeta.isValid()) {
91  throw cet::exception("ShowerCosmicDistance") << "PFP-Meta association is somehow not valid. Stopping";
92  return;
93  }
94  const art::FindManyP<recob::SpacePoint> fmPFPSP(pfpHandle, e, fPandoraLabel);
95  if (!fmPFPSP.isValid()) {
96  throw cet::exception("ShowerCosmicDistance") << "PFP-SP association is somehow not valid. Stopping";
97  return;
98  }
99 
100  const std::vector<art::Ptr<recob::PFParticle>> cosmicPFPs(GetCosmicPFPs(pfps, fmPFPMeta));
101 
102  std::unique_ptr<std::vector<float>> residualCol(std::make_unique<std::vector<float>>());
103  std::unique_ptr<art::Assns<recob::Shower, float>> residualAssns(std::make_unique<art::Assns<recob::Shower, float>>());
104 
105  for (auto const& shower : showers) {
106 
107  // To reduce the combinatorics, put a minumum energy cut on the showers we consider
108  if (shower->best_plane() < 0 || shower->Energy().at(shower->best_plane()) < fMinShowerEnergy)
109  continue;
110 
111  const float res(FindShowerResidual(*shower, cosmicPFPs, fmPFPSP));
112 
113  residualCol->push_back(res);
114  util::CreateAssn(*this, e, *residualCol, shower, *residualAssns);
115  }
116 
117  e.put(std::move(residualCol));
118  e.put(std::move(residualAssns));
119 }
120 
121 const std::vector<art::Ptr<recob::PFParticle>> ShowerCosmicDistance::GetCosmicPFPs(
122  const std::vector<art::Ptr<recob::PFParticle>>& pfps,
123  const art::FindManyP<larpandoraobj::PFParticleMetadata> fmPFPMeta) const
124 {
125  std::vector<art::Ptr<recob::PFParticle>> cosmicPFPs;
126  for (auto const& pfp : pfps) {
127 
128  if (!pfp->IsPrimary())
129  continue;
130 
131  auto const& pfpMetaVec(fmPFPMeta.at(pfp.key()));
132  if (pfpMetaVec.size() != 1)
133  throw cet::exception("ShowerCosmicDistance") << "Wrong metadata entries for PFP: " << pfpMetaVec.size() << ". Stopping";
134 
135  // Ignore anything that is not a clear cosmic
136  if (!pfpMetaVec.front()->GetPropertiesMap().count("IsClearCosmic"))
137  continue;
138 
139  // TODO: Should expand to check for T0 tags from CRT/Flash matching
140 
141  cosmicPFPs.push_back(pfp);
142  }
143  return cosmicPFPs;
144 }
145 
147  const std::vector<art::Ptr<recob::PFParticle>>& cosmicPFPs,
148  const art::FindManyP<recob::SpacePoint>& fmPFPSP) const
149 {
150  float res(std::numeric_limits<float>::max());
151  const TVector3 showerStart3(shower.ShowerStart());
152  const geo::Point_t showerStart(showerStart3.X(), showerStart3.Y(), showerStart3.Z());
153 
154  // Loop over the cosmic PFPs and find the closest
155  for (auto const& cosmicPFP : cosmicPFPs) {
156  auto const& pfpSPs(fmPFPSP.at(cosmicPFP.key()));
157  // Loop over all of the spacepoints in the PFP and find the closest
158  for (auto const& sp : pfpSPs) {
159  const float dist((showerStart - sp->position()).r());
160  res = std::min(res, dist);
161  }
162  }
163  return res;
164 }
165 }
166 
167 DEFINE_ART_MODULE(sbn::ShowerCosmicDistance)
pdgs p
Definition: selectors.fcl:22
const std::vector< art::Ptr< recob::PFParticle > > GetCosmicPFPs(const std::vector< art::Ptr< recob::PFParticle >> &pfps, const art::FindManyP< larpandoraobj::PFParticleMetadata > fmPFPMeta) const
process_name shower
Definition: cheaterreco.fcl:51
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
const float FindShowerResidual(const recob::Shower &shower, const std::vector< art::Ptr< recob::PFParticle >> &cosmicPFPs, const art::FindManyP< recob::SpacePoint > &fmPFPSP) const
Provides recob::Track data product.
ShowerCosmicDistance(fhicl::ParameterSet const &p)
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
void produce(art::Event &e) override
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
do i e
const TVector3 & ShowerStart() const
Definition: Shower.h:192
ShowerCosmicDistance & operator=(ShowerCosmicDistance const &)=delete
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
esac echo uname r