All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FilterParticlesActiveVolume_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 #ifndef FILTER_FILTERPARTICLESACTIVEVOLUME_H
8 #define FILTER_FILTERPARTICLESACTIVEVOLUME_H
9 
10 /// Framework includes
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Core/EDFilter.h"
13 
14 // Framework includes
15 #include "art/Framework/Principal/Event.h"
16 #include "fhiclcpp/ParameterSet.h"
17 #include "art/Framework/Principal/Handle.h"
18 #include "art/Framework/Services/Registry/ServiceHandle.h"
19 #include "messagefacility/MessageLogger/MessageLogger.h"
20 #include "canvas/Persistency/Common/Ptr.h"
21 #include "canvas/Persistency/Common/PtrVector.h"
22 #include "cetlib_except/exception.h"
23 #include "canvas/Persistency/Common/FindManyP.h"
24 #include "canvas/Persistency/Common/FindOneP.h"
25 
26 // LArSoft Includes
27 #include "nug4/ParticleNavigation/ParticleList.h"
28 #include "nusimdata/SimulationBase/MCTruth.h"
31 
32 // C++ Includes
33 #include <iostream>
34 #include <cstring>
35 #include <sys/stat.h>
36 
37 namespace simb{
38  class MCTruth;
39 }
40 
41 namespace sim{
42  class ParticleList;
43 }
44 
45 ///Geant4 interface
46 namespace simfilter {
47 
48  class FilterParticlesActiveVolume : public art::EDFilter
49  {
50  // explicit EDFilter(ParameterSet const&)
51  public:
52 
53  explicit FilterParticlesActiveVolume(fhicl::ParameterSet const &pset);
55 
56  bool filter(art::Event&) ;
57  virtual void reconfigure(fhicl::ParameterSet const&) ;
58 
59  virtual void beginJob() ;
60  /*
61  virtual void endJob() ;
62  virtual bool beginRun(art::Run &) ;
63  virtual bool endRun(art::Run &) ;
64  virtual bool beginSubRun(art::SubRun &) ;
65  virtual bool endSubRun(art::SubRun &) ;
66  */
67  private:
68 
69  double fXmax;
70  double fXmin;
71  double fZmax;
72  double fZmin;
73  double fYmax;
74  double fYmin;
75  int finActive;
76  int filtpart;
77  };
78 
79 } // namespace simfilter
80 
81 namespace simfilter {
82 
83  //-----------------------------------------------------------------------
84  // Constructor
85  FilterParticlesActiveVolume::FilterParticlesActiveVolume(fhicl::ParameterSet const& pset) : EDFilter{pset}
86  {
87  this->reconfigure(pset);
88  }
89 
90  //-----------------------------------------------------------------------
91  // Destructor
93  {
94  }
95 
96  //-----------------------------------------------------------------------
98  {
99  art::ServiceHandle<geo::Geometry> geo;
100 
101  }
102 
103  //-----------------------------------------------------------------------
104  void FilterParticlesActiveVolume::reconfigure(fhicl::ParameterSet const& p)
105  {
106  finActive = p.get< int >("inActive");
107  if (finActive==0) {
108  fXmax = p.get< double >("Xmax");
109  fYmax = p.get< double >("Ymax");
110  fZmax = p.get< double >("Zmax");
111  fXmin = p.get< double >("Xmin");
112  fYmin = p.get< double >("Ymin");
113  fZmin = p.get< double >("Zmin");
114  }
115  if (finActive==1) {
116  fXmax=-999;
117  fYmax=-999;
118  fZmax=-999;
119  fXmin=-999;
120  fYmin=-999;
121  fZmin=-999;
122  }
123  filtpart = p.get< int >("filterpart");
124 
125  return;
126  }
127 
128  //-----------------------------------------------------------------------
130  {
131  bool interactionDesired(false);
132  //get the list of particles from this event
133  art::ServiceHandle<geo::Geometry> geom;
134 
135 
136  // * MC truth information
137 
138  //std::vector< art::Handle< std::vector<simb::MCTruth> > > allmclists;
139  //evt.getManyByType(allmclists);
140  auto allmclists = evt.getMany< std::vector<simb::MCTruth> >();
141 
142 
143  std::cout << fXmin << " " << fXmax << " " << fYmin << " " <<fYmax << " " << fZmin << " " << fZmax << std::endl;
144 
145  geo::CryostatGeo const& cryo0 = geom->Cryostat(0);
146  geo::CryostatGeo const& cryo1 = geom->Cryostat(1);
147 
148  geo::TPCGeo const& tpc00 = cryo0.TPC(0);
149  TVector3 xyzcenter00 = tpc00.GetActiveVolumeCenter();
150  std::cout << xyzcenter00[0] << " " << xyzcenter00[1] << " " << xyzcenter00[2] << std::endl;
151 
152  geo::TPCGeo const& tpc01 = cryo0.TPC(1);
153  TVector3 xyzcenter01 = tpc01.GetActiveVolumeCenter();
154  std::cout << xyzcenter01[0] << " " << xyzcenter01[1] << " " << xyzcenter01[2] << std::endl;
155 
156  geo::TPCGeo const& tpc10 = cryo1.TPC(0);
157  TVector3 xyzcenter10 = tpc10.GetActiveVolumeCenter();
158  std::cout << xyzcenter10[0] << " " << xyzcenter10[1] << " " << xyzcenter10[2] << std::endl;
159 
160  geo::TPCGeo const& tpc11 = cryo1.TPC(1);
161  TVector3 xyzcenter11 = tpc11.GetActiveVolumeCenter();
162  std::cout << xyzcenter11[0] << " " << xyzcenter11[1] << " " << xyzcenter11[2] << std::endl;
163 
164  double h00=tpc00.ActiveHalfHeight();
165  double h01=tpc01.ActiveHalfHeight();
166  double h10=tpc10.ActiveHalfHeight();
167  double h11=tpc11.ActiveHalfHeight();
168  double w00=tpc00.ActiveHalfWidth();
169  double w01=tpc01.ActiveHalfWidth();
170  double w10=tpc10.ActiveHalfWidth();
171  double w11=tpc11.ActiveHalfWidth();
172  double l00=tpc00.ActiveLength();
173  double l01=tpc01.ActiveLength();
174  double l10=tpc10.ActiveLength();
175  double l11=tpc11.ActiveLength();
176 
177  std::cout << h00 << " " << w00 << " " << l00 << std::endl;
178  std::cout << h01 << " " << w01 << " " << l01 << std::endl;
179  std::cout << h10 << " " << w10 << " " << l10 << std::endl;
180  std::cout << h11 << " " << w11 << " " << l11 << std::endl;
181 
182  for(size_t mcl = 0; mcl < allmclists.size(); ++mcl){
183  art::Handle< std::vector<simb::MCTruth> > mclistHandle = allmclists[mcl];
184  for(size_t m = 0; m < mclistHandle->size(); ++m){
185  art::Ptr<simb::MCTruth> mct(mclistHandle, m);
186  for(int ipart=0;ipart<mct->NParticles();ipart++){
187  int pdg=mct->GetParticle(ipart).PdgCode();
188  double xx=mct->GetParticle(ipart).Vx();
189  double yy=mct->GetParticle(ipart).Vy();
190  double zz=mct->GetParticle(ipart).Vz();
191 
192  if (finActive==1 && pdg==filtpart)
193  {
194  if (xx>(xyzcenter00[0]-w00) && xx<(xyzcenter00[0]+w00) && yy>(xyzcenter00[1]-h00) && yy<(xyzcenter00[1]+h00) && zz>(xyzcenter00[2]-l00/2) && zz<(xyzcenter00[2]+l00/2))
195  {
196  interactionDesired = true;
197  }
198  if (xx>(xyzcenter01[0]-w01) && xx<(xyzcenter01[0]+w01) && yy>(xyzcenter01[1]-h01) && yy<(xyzcenter01[1]+h01) && zz>(xyzcenter01[2]-l01/2) && zz<(xyzcenter01[2]+l01/2))
199  {
200  interactionDesired = true;
201  }
202  if (xx>(xyzcenter10[0]-w10) && xx<(xyzcenter10[0]+w10) && yy>(xyzcenter10[1]-h10) && yy<(xyzcenter10[1]+h10) && zz>(xyzcenter10[2]-l10/2) && zz<(xyzcenter10[2]+l10/2))
203  {
204  interactionDesired = true;
205  }
206  if (xx>(xyzcenter11[0]-w11) && xx<(xyzcenter11[0]+w11) && yy>(xyzcenter11[1]-h11) && yy<(xyzcenter11[1]+h11) && zz>(xyzcenter11[2]-l11/2) && zz<(xyzcenter11[2]+l11/2))
207  {
208  interactionDesired = true;
209  }
210 
211  if (finActive==0 && pdg==filtpart)
212  {
213  if (xx>fXmin && xx<fXmax && yy>fYmin && yy<fYmax && zz>fZmin && zz<fZmax)
214  {
215  interactionDesired = true;
216  }
217  }
218 
219  }
220  // std::cout << "FilterNoDirtParticles: i is " << i << std::endl ;
221  // Now walk through trajectory and see if it enters the TPC
222  // trajectory loop
223  // end Genie particle
224  }
225  }
226  }// loop on MCPHandle
227 
228  return interactionDesired;
229 
230  } // end FilterNoDirtParticles()function
231 
232 } // namespace simfilter
233 
234 namespace simfilter {
235 
236  DEFINE_ART_MODULE(FilterParticlesActiveVolume)
237 
238 } // namespace simfilter
239 
240 #endif // FILTER_FILTERNEUTRINOSACTIVEVOLUME_H
241 
FilterParticlesActiveVolume(fhicl::ParameterSet const &pset)
Point GetActiveVolumeCenter() const
Returns the center of the TPC active volume in world coordinates [cm].
Definition: TPCGeo.h:288
var pdg
Definition: selectors.fcl:14
double ActiveHalfHeight() const
Half height (associated with y coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:99
pdgs p
Definition: selectors.fcl:22
Geometry information for a single TPC.
Definition: TPCGeo.h:38
virtual void reconfigure(fhicl::ParameterSet const &)
for pfile in ack l reconfigure(.*) override"` do echo "checking $
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
double ActiveHalfWidth() const
Half width (associated with x coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:95
double ActiveLength() const
Length (associated with z coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:103
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc&#39;th TPC in the cryostat.
Definition: CryostatGeo.cxx:93
TCEvent evt
Definition: DataStructs.cxx:8
Tools and modules for checking out the basics of the Monte Carlo.
art framework interface to geometry description
BEGIN_PROLOG could also be cout