LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
FilterNoDirtNeutrinos_module.cc
Go to the documentation of this file.
1 
11 
12 // Framework includes
18 #include "cetlib_except/exception.h"
19 #include "fhiclcpp/ParameterSet.h"
20 
21 // LArSoft Includes
25 
26 // C++ Includes
27 #include <cstring>
28 #include <iostream>
29 
31 namespace simfilter {
32 
34  public:
35  explicit FilterNoDirtNeutrinos(fhicl::ParameterSet const& pset);
36 
37  private:
38  bool filter(art::Event&) override;
39 
40  std::string fLArG4ModuleLabel;
41  std::string fGenModuleLabel;
43  };
44 
45 } // namespace simfilter
46 
47 namespace simfilter {
48 
49  //-----------------------------------------------------------------------
50  // Constructor
52  : EDFilter{pset}
53  , fLArG4ModuleLabel(pset.get<std::string>("LArG4ModuleLabel", "NoLabel"))
54  , fGenModuleLabel(pset.get<std::string>("GenModuleLabel", "NoLabel"))
55  , fKeepCryostatNeutrinos(pset.get<bool>("KeepCryostatNeutrinos", false))
56  {}
57 
58  //-----------------------------------------------------------------------
60  {
61  bool interactionDesired(false);
62  //get the list of particles from this event
64  auto const& [cryostat, tpc] = std::make_tuple(geom->Cryostat(), geom->TPC());
65 
66  // * MC truth information
67  art::Handle<std::vector<simb::MCTruth>> mctruthListHandle;
68  std::vector<art::Ptr<simb::MCTruth>> mclist;
70 
71  if (evt.getByLabel(fGenModuleLabel, mctruthListHandle))
72  art::fill_ptr_vector(mclist, mctruthListHandle);
73  evt.getByLabel(fLArG4ModuleLabel, mcpHandle);
74 
75  std::set<art::Ptr<simb::MCTruth>> mctSetGENIE;
76  for (size_t i = 0; i < mctruthListHandle->size(); ++i) {
77  art::Ptr<simb::MCTruth> mct_ptr(mctruthListHandle, i);
78  if (mctSetGENIE.find(mct_ptr) == mctSetGENIE.end()) mctSetGENIE.insert(mct_ptr);
79  }
80 
81  // Get the MCTruths from associations to our particles
82  art::FindOneP<simb::MCTruth> assMCT(mcpHandle, evt, "largeant");
83 
84  double xmin;
85  double xmax;
86  double ymin;
87  double ymax;
88  double zmin;
89  double zmax;
90 
92  // Get cryostat (box) volume boundary.
93  xmin = tpc.HalfWidth() - cryostat.HalfWidth();
94  xmax = tpc.HalfWidth() + cryostat.HalfWidth();
95  ymin = -cryostat.HalfHeight();
96  ymax = cryostat.HalfHeight();
97  zmin = tpc.Length() / 2. - tpc.Length() / 2.;
98  zmax = tpc.Length() / 2. + tpc.Length() / 2.;
99  }
100  else {
101  // Get fiducial volume boundary.
102  xmin = 0.;
103  xmax = 2. * tpc.HalfWidth();
104  ymin = -tpc.HalfHeight();
105  ymax = tpc.HalfHeight();
106  zmin = 0.;
107  zmax = tpc.Length();
108  }
109 
110  // Now let's loop over G4 MCParticle list and track back MCTruth
111  bool inTPC(false);
112  for (size_t i = 0; i < mcpHandle->size() && !inTPC; ++i) {
113  const art::Ptr<simb::MCParticle> mcp_ptr(mcpHandle, i);
114  const art::Ptr<simb::MCTruth>& mct = assMCT.at(i);
115  if (mctSetGENIE.find(mct) == mctSetGENIE.end()) {
116  // This is non-genie
117  continue;
118  }
119  else {
120  // This is genie
121 
122  const simb::MCParticle* part(&mcpHandle->at(i));
123 
124  // Now walk through trajectory and see if it enters the TPC
125  int n = part->NumberTrajectoryPoints();
126  for (int j = 0; j < n && !inTPC; ++j) {
127 
128  TVector3 pos = part->Position(j).Vect();
129  if (pos.X() >= xmin && pos.X() <= xmax && pos.Y() >= ymin && pos.Y() <= ymax &&
130  pos.Z() >= zmin && pos.Z() <= zmax) {
131  interactionDesired = true;
132  std::cout << "FilterNoDirtNeutrinos: Genie daughter found in TPC. G4Particle "
133  << std::endl;
134  inTPC = true;
135  }
136  } // trajectory loop
137  } // end Genie particle
138  } // loop on MCPHandle
139 
140  return interactionDesired;
141 
142  } // end FilterNoDirtNeutrinos()function
143 
144 } // namespace simfilter
145 
Particle class.
TString part[npart]
Definition: Style.C:32
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
CryostatGeo const & Cryostat(CryostatID const &cryoid=details::cryostat_zero) const
Returns the specified cryostat.
FilterNoDirtNeutrinos(fhicl::ParameterSet const &pset)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.cc:6
Char_t n[5]
TCEvent evt
Definition: DataStructs.cxx:8
Framework includes.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
TPCGeo const & TPC(TPCID const &tpcid=details::tpc_zero) const
Returns the specified TPC.
Definition: GeometryCore.h:448
art framework interface to geometry description