CosmicFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: CosmicFilter
3 // Plugin Type: filter (art v2_11_03)
4 // File: CosmicFilter_module.cc
5 //
6 // Generated at Fri Aug 24 06:12:20 2018 by Philip Rodrigues using cetskelgen
7 // from cetlib version v3_03_01.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 
23 
24 #include <memory>
25 
26 #include "TGeoManager.h"
27 #include "TLorentzVector.h"
28 #include "TVector3.h"
29 
30 
31 class CosmicFilter;
32 
33 
34 class CosmicFilter : public art::EDFilter {
35 public:
36  explicit CosmicFilter(fhicl::ParameterSet const & p);
37  // The compiler-generated destructor is fine for non-base
38  // classes without bare pointers or other resource use.
39 
40  // Plugins should not be copied or assigned.
41  CosmicFilter(CosmicFilter const &) = delete;
42  CosmicFilter(CosmicFilter &&) = delete;
43  CosmicFilter & operator = (CosmicFilter const &) = delete;
44  CosmicFilter & operator = (CosmicFilter &&) = delete;
45 
46  // Required functions.
47  bool filter(art::Event & e) override;
48 
49 private:
50 
51  // Declare member data here.
52 
53  // Project the particle in a straight line: does it intersect the
54  // volume with the given name?
55  bool intersectsVolume(const simb::MCParticle& particle, const char* volumeName) const;
56 
58 };
59 
60 
62  : EDFilter{p}
63 // Initialize member data here.
64 {
65  // Call appropriate produces<>() functions here.
66 }
67 
69 {
70  auto const& mctruths =
71  *e.getValidHandle<std::vector<simb::MCTruth>>(art::InputTag{"generator"});
72 
73  const simb::MCTruth& truth=mctruths.at(0);
74  const simb::MCParticle& cosmic_particle=truth.GetParticle(0);
75  return intersectsVolume(cosmic_particle, "volDetEnclosure_0");
76 }
77 
78 bool CosmicFilter::intersectsVolume(const simb::MCParticle& particle, const char* volumeName) const
79 {
80  TGeoManager* geoManager=geom->ROOTGeoManager();
81  geoManager->SetCurrentPoint(particle.Vx(), particle.Vy(), particle.Vz());
82  TVector3 unitMom=particle.Momentum().Vect().Unit();
83  geoManager->SetCurrentDirection(unitMom.X(), unitMom.Y(), unitMom.Z());
84  geoManager->FindNextBoundaryAndStep();
85 
86  while(!geoManager->IsOutside()){
87  geoManager->FindNextBoundaryAndStep();
88  if(TString(geoManager->GetPath()).Contains(volumeName)) return true;
89  }
90  return false;
91 }
92 
Particle class.
TGeoManager * ROOTGeoManager() const
Access to the ROOT geometry description manager.
art framework interface to geometry description
bool intersectsVolume(const simb::MCParticle &particle, const char *volumeName) const
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
double Vx(const int i=0) const
Definition: MCParticle.h:221
CosmicFilter(fhicl::ParameterSet const &p)
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
double Vz(const int i=0) const
Definition: MCParticle.h:223
CosmicFilter & operator=(CosmicFilter const &)=delete
Event generator information.
Definition: MCTruth.h:32
art::ServiceHandle< geo::Geometry > geom
bool filter(art::Event &e) override
double Vy(const int i=0) const
Definition: MCParticle.h:222