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
11 
12 // Framework includes
13 #include "fhiclcpp/ParameterSet.h"
16 
17 // LArSoft Includes
19 #include "nug4/ParticleNavigation/ParticleList.h"
22 
23 ///Geant4 interface
24 namespace simfilter {
25 
27  {
28  public:
29 
30  explicit FilterPrimaryPDG(fhicl::ParameterSet const &pset);
31 
32  private:
33  bool filter(art::Event&) override;
34 
36  std::vector<int> fPrimaryVec;
37  };
38 
39 } // namespace simfilter
40 
41 namespace simfilter {
42 
43  //-----------------------------------------------------------------------
44  // Constructor
46  : EDFilter{pset}, fPrimaryVec{pset.get<std::vector<int> >("PrimaryParticles")}
47  {}
48 
49  //-----------------------------------------------------------------------
51  {
52 
53  //get the list of particles from this event
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 
96 
97 } // namespace simfilter
bool filter(art::Event &) override
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
art framework interface to geometry description
FilterPrimaryPDG(fhicl::ParameterSet const &pset)
int PdgCode(Resonance_t res, int Q)
(resonance id, charge) -> PDG code
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
const sim::ParticleList & ParticleList() const
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
Tools and modules for checking out the basics of the Monte Carlo.
TCEvent evt
Definition: DataStructs.cxx:7
Framework includes.
static QCString * s
Definition: config.cpp:1042