LArSoft  v09_90_00
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 
65  // * MC truth information
66  art::Handle<std::vector<simb::MCTruth>> mctruthListHandle;
67  std::vector<art::Ptr<simb::MCTruth>> mclist;
69 
70  if (evt.getByLabel(fGenModuleLabel, mctruthListHandle))
71  art::fill_ptr_vector(mclist, mctruthListHandle);
72  evt.getByLabel(fLArG4ModuleLabel, mcpHandle);
73 
74  // std::cout << "FilterNoDirtNeutrinos: mclist.size() is " << mclist.size()<< std::endl ;
75 
76  std::set<art::Ptr<simb::MCTruth>> mctSetGENIE;
77  for (size_t i = 0; i < mctruthListHandle->size(); ++i) {
78  art::Ptr<simb::MCTruth> mct_ptr(mctruthListHandle, i);
79  if (mctSetGENIE.find(mct_ptr) == mctSetGENIE.end()) mctSetGENIE.insert(mct_ptr);
80  }
81 
82  // Get the MCTruths from associations to our particles
83  art::FindOneP<simb::MCTruth> assMCT(mcpHandle, evt, "largeant");
84 
85  double xmin;
86  double xmax;
87  double ymin;
88  double ymax;
89  double zmin;
90  double zmax;
91 
93  // Get cryostat (box) volume boundary.
94  xmin = geom->DetHalfWidth() - geom->CryostatHalfWidth();
95  xmax = geom->DetHalfWidth() + geom->CryostatHalfWidth();
96  ymin = -geom->CryostatHalfHeight();
97  ymax = geom->CryostatHalfHeight();
98  zmin = geom->DetLength() / 2. - geom->DetLength() / 2.;
99  zmax = geom->DetLength() / 2. + geom->DetLength() / 2.;
100  }
101  else {
102  // Get fiducial volume boundary.
103  xmin = 0.;
104  xmax = 2. * geom->DetHalfWidth();
105  ymin = -geom->DetHalfHeight();
106  ymax = geom->DetHalfHeight();
107  zmin = 0.;
108  zmax = geom->DetLength();
109  }
110 
111  // std::cout << "FilterNoDirtNeutrinos: mcpHandle->size() is " << mcpHandle->size()<< std::endl ;
112  // Now let's loop over G4 MCParticle list and track back MCTruth
113  bool inTPC(false);
114  for (size_t i = 0; i < mcpHandle->size() && !inTPC; ++i) {
115  const art::Ptr<simb::MCParticle> mcp_ptr(mcpHandle, i);
116  const art::Ptr<simb::MCTruth>& mct = assMCT.at(i);
117  if (mctSetGENIE.find(mct) == mctSetGENIE.end()) {
118  // This is non-genie
119  continue;
120  }
121  else {
122  // This is genie
123 
124  const simb::MCParticle* part(&mcpHandle->at(i));
125  // for c2: pdg and trackID no longer used
126  //int pdg = part->PdgCode();
127  //int trackID = part->TrackId();
128 
129  // std::cout << "FilterNoDirtNeutrinos: i is " << i << std::endl ;
130  // Now walk through trajectory and see if it enters the TPC
131  int n = part->NumberTrajectoryPoints();
132  for (int j = 0; j < n && !inTPC; ++j) {
133  // std::cout << "FilterNoDirtNeutrinos: Loop counter on NumTrajPt j is " << j << std::endl ;
134 
135  TVector3 pos = part->Position(j).Vect();
136  if (pos.X() >= xmin && pos.X() <= xmax && pos.Y() >= ymin && pos.Y() <= ymax &&
137  pos.Z() >= zmin && pos.Z() <= zmax) {
138  interactionDesired = true;
139  // std::cout << "FilterNoDirtNeutrinos: Genie daughter found in TPC. G4Particle " << i << " , TrackID/pdg " << trackID << "/ " << pdg << " is discovered." << std::endl ;
140  std::cout << "FilterNoDirtNeutrinos: Genie daughter found in TPC. G4Particle "
141  << std::endl;
142  inTPC = true;
143  }
144  } // trajectory loop
145  } // end Genie particle
146  } // loop on MCPHandle
147 
148  return interactionDesired;
149 
150  } // end FilterNoDirtNeutrinos()function
151 
152 } // namespace simfilter
153 
154 namespace simfilter {
155 
157 
158 } // namespace simfilter
Length_t DetHalfWidth(TPCID const &tpcid=tpc_zero) const
Returns the half width of the active volume of the specified TPC.
Length_t CryostatHalfWidth(CryostatID const &cid=cryostat_zero) const
Returns the half width of the cryostat (x direction)
Particle class.
Length_t CryostatHalfHeight(CryostatID const &cid=cryostat_zero) const
Returns the height of the cryostat (y direction)
Length_t DetLength(TPCID const &tpcid=tpc_zero) const
Returns the length of the active volume of the specified TPC.
TString part[npart]
Definition: Style.C:32
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
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]
Length_t DetHalfHeight(TPCID const &tpcid=tpc_zero) const
Returns the half height of the active volume of the specified TPC.
TCEvent evt
Definition: DataStructs.cxx:8
Framework includes.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
art framework interface to geometry description