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
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
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
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.
std::string string
Definition: nybbler.cc:12
Particle class.
art framework interface to geometry description
Definition: Run.h:17
T abs(T value)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
ServiceHandle< T > serviceHandle() const
T get(std::string const &key) const
Definition: ParameterSet.h:271
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
The geometry of one entire detector, as served by art.
Definition: Geometry.h:196
BoundingBox bounds(int x, int y, int w, int h)
Definition: main.cpp:37
static unsigned filter(unsigned char *out, const unsigned char *in, unsigned w, unsigned h, const LodePNG_InfoColor *info)
Definition: lodepng.cpp:3576
TCEvent evt
Definition: DataStructs.cxx:7
QTextStream & endl(QTextStream &s)