FSPEventFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // GENIEEventFilter_module class:
4 // Algoritm to produce a filtered event file having events with user-defined
5 // GENIE stauscode==1 (not GEANT!) particles in MCTruth
6 //
7 // eldwan.brianne@desy.de
8 //
9 ////////////////////////////////////////////////////////////////////////
10 
11 //Framework Includes
20 #include "fhiclcpp/ParameterSet.h"
21 #include "canvas/Persistency/Common/FindOne.h"
22 #include "canvas/Persistency/Common/FindOneP.h"
23 #include "canvas/Persistency/Common/FindMany.h"
24 #include "canvas/Persistency/Common/FindManyP.h"
25 
26 //nusim Includes
30 
31 namespace gar{
32  namespace filt {
33 
34  class FSPEventFilter : public art::EDFilter {
35 
36  public:
37 
38  explicit FSPEventFilter(fhicl::ParameterSet const& );
39 
40  // Filters should not be copied or assigned.
41  FSPEventFilter(FSPEventFilter const &) = delete;
42  FSPEventFilter(FSPEventFilter &&) = delete;
43  FSPEventFilter & operator = (FSPEventFilter const &) = delete;
45 
46  bool filter(art::Event& evt);
47  void beginJob();
48 
49  private:
50 
52  std::vector<int> fPDG;
53 
54  bool isMatched(std::vector<int> const& a, std::vector<int> const& b) const;
55 
56  }; // class GENIEEventFilter
57 
58  //-------------------------------------------------
60  : EDFilter{pset}
61  {
62  fGeneratorLabel = pset.get< std::string >("GeneratorModuleLabel", "generator");
63  fPDG = pset.get< std::vector<int> >("PDG");
64  }
65 
66  //-------------------------------------------------
68  {
69 
70  }
71 
72  //-------------------------------------------------
74  {
75  auto mcthandlelist = evt.getHandle< std::vector<simb::MCTruth> >(fGeneratorLabel);
76  if (!mcthandlelist) {
77  throw cet::exception("FSPEventFilter") << " No simb::MCTruth branch."
78  << " Line " << __LINE__ << " in file " << __FILE__ << std::endl;
79  }
80 
81  art::Ptr<simb::MCTruth> mcp(mcthandlelist, 0);
82  std::vector<int> FSP;
83 
84  for(int i = 0; i < mcp->NParticles(); ++i){
85  simb::MCParticle part(mcp->GetParticle(i));
86 
87  if (part.StatusCode()== 1)
88  FSP.push_back(part.PdgCode());
89  }
90 
91  return isMatched(fPDG, FSP); // returns true if the user-defined fPDG exist(s) in the final state particles
92  }
93 
94  //------------------------------------------------
95  bool FSPEventFilter::isMatched(std::vector<int> const& a, std::vector<int> const& b) const
96  {
97  for (auto const a_int : a) {
98  for (auto const b_int : b) {
99  if (a_int == b_int) {
100  return true;
101  }
102  }
103  }
104  return false;
105  }
106 
107  } //namespace filt
108 } //namespace gar
109 
110 //--------------------------------------------------
111 namespace gar {
112  namespace filt {
114  } //namespace gar
115 } //namespace filt
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
FSPEventFilter & operator=(FSPEventFilter const &)=delete
bool isMatched(std::vector< int > const &a, std::vector< int > const &b) const
int NParticles() const
Definition: MCTruth.h:75
Particle class.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
const double a
bool filter(art::Event &evt)
const simb::MCParticle & GetParticle(int i) const
Definition: MCTruth.h:76
General GArSoft Utilities.
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
static bool * b
Definition: config.cpp:1043
FSPEventFilter(fhicl::ParameterSet const &)
TCEvent evt
Definition: DataStructs.cxx:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)