LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
FilterStoppingMuon_module.cc
Go to the documentation of this file.
1 
14 #include "fhiclcpp/ParameterSet.h"
15 
16 // LArSoft Includes
19 
20 // C++ Includes
21 #include <iostream>
22 
23 namespace {
24 
25  struct bounds {
26  double minBound;
27  double maxBound;
28  };
29 
30  inline bool within(bounds const& bnds, double const value)
31  {
32  return bnds.minBound < value and value < bnds.maxBound;
33  }
34 
35  class FilterStoppingMuon : public art::SharedFilter {
36  public:
37  explicit FilterStoppingMuon(fhicl::ParameterSet const& pset, art::ProcessingFrame const&);
38 
39  private:
40  void beginRun(art::Run&, art::ProcessingFrame const&) override;
41  bool filter(art::Event&, art::ProcessingFrame const&) override;
42  std::string const fLArG4ModuleLabel;
43  bounds fXBounds{};
44  bounds fYBounds{};
45  bounds fZBounds{};
46  };
47 
48  //-----------------------------------------------------------------------
49  // Constructor
50  FilterStoppingMuon::FilterStoppingMuon(fhicl::ParameterSet const& pset,
51  art::ProcessingFrame const&)
52  : SharedFilter{pset}, fLArG4ModuleLabel{pset.get<std::string>("LArG4ModuleLabel", "largeant")}
53  {
54  async<art::InEvent>();
55  }
56 
57  void FilterStoppingMuon::beginRun(art::Run&, art::ProcessingFrame const& frame)
58  {
59  // Detector geometries are allowed to change on run boundaries.
60  auto const geom = frame.serviceHandle<geo::Geometry const>();
61  fXBounds = {0., 2. * geom->DetHalfWidth()};
62  fYBounds = {-geom->DetHalfHeight(), geom->DetHalfHeight()};
63  fZBounds = {0., geom->DetLength()};
64  }
65 
66  //-----------------------------------------------------------------------
67  bool FilterStoppingMuon::filter(art::Event& evt, art::ProcessingFrame const&)
68  {
69  // get the particles produced by largeant
70  auto const& mcps = *evt.getValidHandle<std::vector<simb::MCParticle>>(fLArG4ModuleLabel);
71 
72  for (auto const& part : mcps) {
73  // skip anything that isn't a muon
74  if (std::abs(part.PdgCode()) != 13) { continue; }
75 
76  // make sure the end position is inside the TPC
77  if (within(fXBounds, part.EndX()) and within(fYBounds, part.EndY()) and
78  within(fZBounds, part.EndZ())) {
79  // we found a stopping muon -> return true (keep this event)
80  // N.B. Printing this out during multi-threaded execution may
81  // result in mangled printouts. If that is a problem, then
82  // these printouts should be made only if a 'debug' mode is
83  // specified, in which case 'serialize()' would be called
84  // instead of 'async'.
85  std::cout << "************* IN TPC *******************" << std::endl;
86  return true;
87  }
88 
89  } // for all mcparticles
90 
91  return false;
92 
93  } // end FilterStoppingMuon()function
94 
95 }
96 
97 DEFINE_ART_MODULE(FilterStoppingMuon)
Length_t DetHalfWidth(TPCID const &tpcid=tpc_zero) const
Returns the half width of the active volume of the specified TPC.
constexpr auto abs(T v)
Returns the absolute value of the argument.
Particle class.
Definition: Run.h:37
Framework includes.
TString part[npart]
Definition: Style.C:32
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
ServiceHandle< T > serviceHandle() const
T get(std::string const &key) const
Definition: ParameterSet.h:314
The geometry of one entire detector, as served by art.
Definition: Geometry.h:181
double value
Definition: spectrum.C:18
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
TCEvent evt
Definition: DataStructs.cxx:8
art framework interface to geometry description