All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FilterPrimaryPDG_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file FilterPrimaryPDG_module.cc
3 /// \brief Simple EDFilter to require a particular pdg is present as a primary
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 "fhiclcpp/ParameterSet.h"
14 #include "art/Framework/Services/Registry/ServiceHandle.h"
15 #include "messagefacility/MessageLogger/MessageLogger.h"
16 
17 // LArSoft Includes
19 #include "nug4/ParticleNavigation/ParticleList.h"
22 
23 ///Geant4 interface
24 namespace simfilter {
25 
26  class FilterPrimaryPDG : public art::EDFilter
27  {
28  public:
29 
30  explicit FilterPrimaryPDG(fhicl::ParameterSet const &pset);
31 
32  private:
33  bool filter(art::Event&) override;
34 
35  std::string fG4ModuleLabel;
36  std::vector<int> fPrimaryVec;
37  };
38 
39 } // namespace simfilter
40 
41 namespace simfilter {
42 
43  //-----------------------------------------------------------------------
44  // Constructor
45  FilterPrimaryPDG::FilterPrimaryPDG(fhicl::ParameterSet const& pset)
46  : EDFilter{pset}, fPrimaryVec{pset.get<std::vector<int> >("PrimaryParticles")}
47  {}
48 
49  //-----------------------------------------------------------------------
50  bool FilterPrimaryPDG::filter(art::Event& evt)
51  {
52 
53  //get the list of particles from this event
54  art::ServiceHandle<cheat::ParticleInventoryService const> pi_serv;
55  art::ServiceHandle<geo::Geometry const> geom;
56 
57  // get the particles from the back tracker
58  const sim::ParticleList& Particles = pi_serv->ParticleList();
59  std::vector<const simb::MCParticle*> pvec;
60  pvec.reserve(Particles.size());
61  for (const auto& PartPair: Particles) {
62  pvec.push_back(PartPair.second);
63  // fPDGCodes->Fill(PartPair.second->PdgCode());
64  }
65 
66  bool pdgDesired(false);
67  for(unsigned int i = 0; i < pvec.size(); ++i)
68  {
69  for (int pdg : fPrimaryVec)
70  {
71  const std::string sprim("primary");
72  if(pvec[i]->PdgCode() == pdg)
73  {
74  Char_t tProcess[50];
75  for(unsigned int s = 0; s < pvec[i]->Process().length(); ++s)
76  *(tProcess+s) = pvec[i]->Process()[s];
77  std::string sProcess(tProcess);
78  if (!sProcess.compare(sprim))
79  {
80  mf::LogInfo("FilterPrimaryPDG") << " Found a primary " << pdg << " in event.";
81  pdgDesired = true;
82  }
83  }
84  }
85 
86  }
87 
88  return pdgDesired;
89  }
90 
91 } // namespace simfilter
92 
93 namespace simfilter {
94 
95  DEFINE_ART_MODULE(FilterPrimaryPDG)
96 
97 } // namespace simfilter
bool filter(art::Event &) override
var pdg
Definition: selectors.fcl:14
FilterPrimaryPDG(fhicl::ParameterSet const &pset)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
TCEvent evt
Definition: DataStructs.cxx:8
Tools and modules for checking out the basics of the Monte Carlo.
art framework interface to geometry description