All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FilterStoppingMuon_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file FilterStoppingMuon_module.cc
3 /// \brief Simple EDFilter to require muon to stop in the TPC
4 ///
5 /// \author dcaratelli@nevis.columbia.edu
6 ////////////////////////////////////////////////////////////////////////
7 
8 /// Framework includes
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Core/SharedFilter.h"
11 #include "art/Framework/Principal/Event.h"
12 #include "art/Framework/Principal/Handle.h"
13 #include "art/Framework/Services/Registry/ServiceHandle.h"
14 #include "fhiclcpp/ParameterSet.h"
15 
16 // LArSoft Includes
18 #include "nusimdata/SimulationBase/MCParticle.h"
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
31  within(bounds const& bnds, double const value)
32  {
33  return bnds.minBound < value and value < bnds.maxBound;
34  }
35 
36  class FilterStoppingMuon : public art::SharedFilter {
37  public:
38  explicit FilterStoppingMuon(fhicl::ParameterSet const& pset,
39  art::ProcessingFrame const&);
40 
41  private:
42  void beginRun(art::Run&, art::ProcessingFrame const&) override;
43  bool filter(art::Event&, art::ProcessingFrame const&) override;
44  std::string const fLArG4ModuleLabel;
45  bounds fXBounds{};
46  bounds fYBounds{};
47  bounds fZBounds{};
48  };
49 
50  //-----------------------------------------------------------------------
51  // Constructor
52  FilterStoppingMuon::FilterStoppingMuon(fhicl::ParameterSet const& pset,
53  art::ProcessingFrame const&)
54  : SharedFilter{pset}
55  , fLArG4ModuleLabel{pset.get<std::string>("LArG4ModuleLabel", "largeant")}
56  {
57  async<art::InEvent>();
58  }
59 
60  void
61  FilterStoppingMuon::beginRun(art::Run&, art::ProcessingFrame const& frame)
62  {
63  // Detector geometries are allowed to change on run boundaries.
64  auto const geom = frame.serviceHandle<geo::Geometry const>();
65  fXBounds = {0., 2. * geom->DetHalfWidth()};
66  fYBounds = {-geom->DetHalfHeight(), geom->DetHalfHeight()};
67  fZBounds = {0., geom->DetLength()};
68  }
69 
70  //-----------------------------------------------------------------------
71  bool
72  FilterStoppingMuon::filter(art::Event& evt, art::ProcessingFrame const&)
73  {
74  // get the particles produced by largeant
75  auto const& mcps =
76  *evt.getValidHandle<std::vector<simb::MCParticle>>(fLArG4ModuleLabel);
77 
78  for (auto const& part : mcps) {
79  // skip anything that isn't a muon
80  if (std::abs(part.PdgCode()) != 13) {
81  continue;
82  }
83 
84  // make sure the end position is inside the TPC
85  if (within(fXBounds, part.EndX()) and within(fYBounds, part.EndY()) and
86  within(fZBounds, part.EndZ())) {
87  // we found a stopping muon -> return true (keep this event)
88  // N.B. Printing this out during multi-threaded execution may
89  // result in mangled printouts. If that is a problem, then
90  // these printouts should be made only if a 'debug' mode is
91  // specified, in which case 'serialize()' would be called
92  // instead of 'async'.
93  std::cout << "************* IN TPC *******************" << std::endl;
94  return true;
95  }
96 
97  } // for all mcparticles
98 
99  return false;
100 
101  } // end FilterStoppingMuon()function
102 
103 }
104 
105 DEFINE_ART_MODULE(FilterStoppingMuon)
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
T abs(T value)
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
The geometry of one entire detector, as served by art.
Definition: Geometry.h:181
physics filters filter
temporary value
TCEvent evt
Definition: DataStructs.cxx:8
art framework interface to geometry description
BEGIN_PROLOG could also be cout