All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FilterNoDirtNeutrinos_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file FilterNoDirtNeutrinos_module.cc
3 /// \brief Simple EDFilter to require neutrino interaction in TPC
4 ///
5 /// \author echurch@fnal.gov
6 ////////////////////////////////////////////////////////////////////////
7 
8 /// Framework includes
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Core/EDFilter.h"
11 
12 // Framework includes
13 #include "art/Framework/Principal/Event.h"
14 #include "fhiclcpp/ParameterSet.h"
15 #include "art/Framework/Principal/Handle.h"
16 #include "art/Framework/Services/Registry/ServiceHandle.h"
17 #include "canvas/Persistency/Common/Ptr.h"
18 #include "cetlib_except/exception.h"
19 #include "canvas/Persistency/Common/FindOneP.h"
20 
21 // LArSoft Includes
22 #include "nusimdata/SimulationBase/MCParticle.h"
23 #include "nusimdata/SimulationBase/MCTruth.h"
25 
26 // C++ Includes
27 #include <iostream>
28 #include <cstring>
29 
30 ///Geant4 interface
31 namespace simfilter {
32 
33  class FilterNoDirtNeutrinos : public art::EDFilter
34  {
35  public:
36 
37  explicit FilterNoDirtNeutrinos(fhicl::ParameterSet const &pset);
38 
39  private:
40  bool filter(art::Event&) override;
41 
42  std::string fLArG4ModuleLabel;
43  std::string fGenModuleLabel;
45 
46  };
47 
48 } // namespace simfilter
49 
50 namespace simfilter {
51 
52  //-----------------------------------------------------------------------
53  // Constructor
54  FilterNoDirtNeutrinos::FilterNoDirtNeutrinos(fhicl::ParameterSet const& pset) : EDFilter{pset},
55  fLArG4ModuleLabel (pset.get< std::string > ("LArG4ModuleLabel" , "NoLabel") )
56  , fGenModuleLabel (pset.get< std::string > ("GenModuleLabel" , "NoLabel") )
57  , fKeepCryostatNeutrinos (pset.get< bool > ("KeepCryostatNeutrinos", false) )
58  {
59  }
60 
61  //-----------------------------------------------------------------------
63  {
64  bool interactionDesired(false);
65  //get the list of particles from this event
66  art::ServiceHandle<geo::Geometry const> geom;
67 
68  // * MC truth information
69  art::Handle< std::vector<simb::MCTruth> > mctruthListHandle;
70  std::vector<art::Ptr<simb::MCTruth> > mclist;
71  art::Handle<std::vector<simb::MCParticle> > mcpHandle;
72 
73 
74 
75  if (evt.getByLabel(fGenModuleLabel,mctruthListHandle))
76  art::fill_ptr_vector(mclist, mctruthListHandle);
77  evt.getByLabel(fLArG4ModuleLabel,mcpHandle);
78 
79  // std::cout << "FilterNoDirtNeutrinos: mclist.size() is " << mclist.size()<< std::endl ;
80 
81  std::set<art::Ptr<simb::MCTruth> > mctSetGENIE;
82  for(size_t i=0; i<mctruthListHandle->size(); ++i)
83  {
84  art::Ptr<simb::MCTruth> mct_ptr(mctruthListHandle,i);
85  if( mctSetGENIE.find(mct_ptr) == mctSetGENIE.end() ) mctSetGENIE.insert(mct_ptr);
86  }
87 
88  // Get the MCTruths from associations to our particles
89  art::FindOneP<simb::MCTruth> assMCT(mcpHandle, evt, "largeant");
90 
91  double xmin;
92  double xmax;
93  double ymin;
94  double ymax;
95  double zmin;
96  double zmax;
97 
99  {
100  // Get cryostat (box) volume boundary.
101  xmin = geom->DetHalfWidth() - geom->CryostatHalfWidth();
102  xmax = geom->DetHalfWidth() + geom->CryostatHalfWidth();
103  ymin = -geom->CryostatHalfHeight();
104  ymax = geom->CryostatHalfHeight();
105  zmin = geom->DetLength()/2. - geom->DetLength()/2.;
106  zmax = geom->DetLength()/2. + geom->DetLength()/2.;
107  }
108  else
109  {
110  // Get fiducial volume boundary.
111  xmin = 0.;
112  xmax = 2.*geom->DetHalfWidth();
113  ymin = -geom->DetHalfHeight();
114  ymax = geom->DetHalfHeight();
115  zmin = 0.;
116  zmax = geom->DetLength();
117  }
118 
119  // std::cout << "FilterNoDirtNeutrinos: mcpHandle->size() is " << mcpHandle->size()<< std::endl ;
120  // Now let's loop over G4 MCParticle list and track back MCTruth
121  bool inTPC (false);
122  for(size_t i=0; i < mcpHandle->size() && !inTPC; ++i)
123  {
124  const art::Ptr<simb::MCParticle> mcp_ptr(mcpHandle,i);
125  const art::Ptr<simb::MCTruth> &mct = assMCT.at(i);
126  if( mctSetGENIE.find(mct) == mctSetGENIE.end() )
127  {
128  // This is non-genie
129  continue;
130  }
131  else
132  {
133  // This is genie
134 
135  const simb::MCParticle* part(&mcpHandle->at(i));
136  // for c2: pdg and trackID no longer used
137  //int pdg = part->PdgCode();
138  //int trackID = part->TrackId();
139 
140  // std::cout << "FilterNoDirtNeutrinos: i is " << i << std::endl ;
141  // Now walk through trajectory and see if it enters the TPC
142  int n = part->NumberTrajectoryPoints();
143  for(int j = 0; j < n && !inTPC; ++j)
144  {
145  // std::cout << "FilterNoDirtNeutrinos: Loop counter on NumTrajPt j is " << j << std::endl ;
146 
147  TVector3 pos = part->Position(j).Vect();
148  if(pos.X() >= xmin &&
149  pos.X() <= xmax &&
150  pos.Y() >= ymin &&
151  pos.Y() <= ymax &&
152  pos.Z() >= zmin &&
153  pos.Z() <= zmax)
154  {
155  interactionDesired = true;
156  // std::cout << "FilterNoDirtNeutrinos: Genie daughter found in TPC. G4Particle " << i << " , TrackID/pdg " << trackID << "/ " << pdg << " is discovered." << std::endl ;
157  std::cout << "FilterNoDirtNeutrinos: Genie daughter found in TPC. G4Particle " << std::endl ;
158  inTPC=true;
159  }
160  } // trajectory loop
161  } // end Genie particle
162  } // loop on MCPHandle
163 
164  return interactionDesired;
165 
166  } // end FilterNoDirtNeutrinos()function
167 
168 } // namespace simfilter
169 
170 namespace simfilter {
171 
172  DEFINE_ART_MODULE(FilterNoDirtNeutrinos)
173 
174 } // namespace simfilter
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
FilterNoDirtNeutrinos(fhicl::ParameterSet const &pset)
TCEvent evt
Definition: DataStructs.cxx:8
art framework interface to geometry description
BEGIN_PROLOG could also be cout