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
11 
12 // Framework includes
14 #include "fhiclcpp/ParameterSet.h"
18 #include "cetlib_except/exception.h"
19 #include "canvas/Persistency/Common/FindOneP.h"
20 
21 // LArSoft Includes
25 
26 // C++ Includes
27 #include <iostream>
28 #include <cstring>
29 
30 ///Geant4 interface
31 namespace simfilter {
32 
34  {
35  public:
36 
37  explicit FilterNoDirtNeutrinos(fhicl::ParameterSet const &pset);
38 
39  private:
40  bool filter(art::Event&) override;
41 
45 
46  };
47 
48 } // namespace simfilter
49 
50 namespace simfilter {
51 
52  //-----------------------------------------------------------------------
53  // Constructor
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
67 
68  // * MC truth information
69  art::Handle< std::vector<simb::MCTruth> > mctruthListHandle;
70  std::vector<art::Ptr<simb::MCTruth> > mclist;
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 
173 
174 } // namespace simfilter
geo::Length_t CryostatHalfHeight(geo::CryostatID const &cid) const
Returns the height of the cryostat (y direction)
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
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::void_t< T > n
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
FilterNoDirtNeutrinos(fhicl::ParameterSet const &pset)
geo::Length_t CryostatHalfWidth(geo::CryostatID const &cid) const
Returns the half width of the cryostat (x direction)
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
TCEvent evt
Definition: DataStructs.cxx:7
Framework includes.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
QTextStream & endl(QTextStream &s)