All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FilterCryostatNus_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file FilterCryostatNus_module.cc
3 /// \brief EDFilter to require projected generator trajectories in volumes
4 /// within a particular time window.
5 ///
6 /// \author Matthew.Bass@physics.ox.ac.uk
7 ////////////////////////////////////////////////////////////////////////
8 
9 /// Framework includes
10 #include "art/Framework/Core/EDFilter.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 
13 // Framework includes
14 #include "art/Framework/Principal/Event.h"
15 #include "art/Framework/Principal/Handle.h"
16 #include "canvas/Utilities/Exception.h"
17 #include "fhiclcpp/ParameterSet.h"
18 
19 // LArSoft Includes
23 #include "nusimdata/SimulationBase/MCTruth.h"
24 
25 // C++ Includes
26 #include <cmath> // std::abs()
27 
28 namespace simfilter {
29 
30  class FilterCryostatNus : public art::EDFilter {
31  public:
32  explicit FilterCryostatNus(fhicl::ParameterSet const& pset);
33 
34  private:
35  bool filter(art::Event&) override;
36  bool fKeepNusInCryostat; // true: keep cryostat nuint; false: filter them
37  };
38 
39 } // namespace simfilter
40 
41 namespace simfilter {
42 
43  FilterCryostatNus::FilterCryostatNus(fhicl::ParameterSet const& pset)
44  : EDFilter{pset}
45  , fKeepNusInCryostat{pset.get<bool>("KeepNusInCryostat", false)}
46  {}
47 
48  bool
50  {
51  // get the list of particles from this event
52  auto const& geom = *(lar::providerFrom<geo::Geometry>());
53 
54  //std::vector<art::Handle<std::vector<simb::MCTruth>>> allmclists;
55  //evt.getManyByType(allmclists);
56  auto allmclists = evt.getMany<std::vector<simb::MCTruth>>();
57 
58  bool inCryostatNu = false;
59  for (auto const& mclistHandle : allmclists) {
60  for (simb::MCTruth const& mct : *mclistHandle) {
61 
62  // get nu, does it end in cyrostat?
63  for (int ipart = 0; ipart < mct.NParticles(); ipart++) {
64  auto const& part = mct.GetParticle(ipart);
65  auto const absPDGID = std::abs(part.PdgCode());
66  if (absPDGID == 12 || absPDGID == 14 || absPDGID == 16) {
67  const TLorentzVector& end4 = part.EndPosition();
68  if (geom.PositionToCryostatPtr({end4.X(), end4.Y(), end4.Z()}) !=
69  nullptr) {
70  inCryostatNu = true;
71  }
72  } // if neutrino
73  } // for particles
74 
75  } // end loop over mctruth col
76 
77  } // end loop over all mctruth lists
78 
79  return fKeepNusInCryostat ^ (!inCryostatNu);
80  }
81 
82 } // namespace simfilter
83 
84 DEFINE_ART_MODULE(simfilter::FilterCryostatNus)
Utilities related to art service access.
Access the description of detector geometry.
T abs(T value)
FilterCryostatNus(fhicl::ParameterSet const &pset)
bool filter(art::Event &) override
TCEvent evt
Definition: DataStructs.cxx:8
art framework interface to geometry description