LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
FinalStateParticleFilter_module.cc
Go to the documentation of this file.
1 //
3 // FinalStateParticleFilter class:
4 // Algoritm to produce a filtered event file having
5 // events with user-defined final state particles
6 //
7 // saima@ksu.edu
8 //
10 
11 //Framework Includes
17 #include "art_root_io/TFileService.h"
19 #include "fhiclcpp/ParameterSet.h"
20 
21 //Larsoft Includes
24 
25 // ROOT includes
26 #include "TH1.h"
27 
28 namespace filt {
29 
31 
32  public:
34 
35  bool filter(art::Event& evt);
36  void beginJob();
37 
38  private:
39  std::string fGenieModuleLabel;
40  std::vector<int> fPDG;
41  std::vector<int> fStatusCode;
43  TH1D* fTotalEvents;
44 
45  bool isSubset(std::vector<int> const& a, std::vector<int> const& b) const;
46 
47  }; // class FinalStateParticleFilter
48 
49 }
50 
51 namespace filt {
52 
53  //-------------------------------------------------
55  : EDFilter{pset}
56  {
57  fGenieModuleLabel = pset.get<std::string>("GenieModuleLabel");
58  fPDG = pset.get<std::vector<int>>("PDG");
59  }
60 
61  //-------------------------------------------------
63  {
65  fSelectedEvents = tfs->make<TH1D>("fSelectedEvents",
66  "Number of Selected Events",
67  3,
68  0,
69  3); //counts the number of selected events
70  fTotalEvents =
71  tfs->make<TH1D>("fTotalEvents",
72  "Total Events",
73  3,
74  0,
75  3); //counts the initial number of events in the unfiltered root input file
76  }
77 
78  //-------------------------------------------------
80  {
81 
82  //const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
83 
85  evt.getByLabel(fGenieModuleLabel, mclist);
86  art::Ptr<simb::MCTruth> mc(mclist, 0);
87 
88  fTotalEvents->Fill(1);
89 
90  std::vector<int> finalstateparticles;
91 
92  //get a vector of final state particles
93  for (int i = 0; i < mc->NParticles(); ++i) {
95  if (part.StatusCode() == 1) finalstateparticles.push_back(part.PdgCode());
96  }
97 
98  if (isSubset(fPDG, finalstateparticles)) {
99  fSelectedEvents->Fill(1);
100  std::cout << "this is a selected event" << std::endl;
101  }
102 
103  return isSubset(
104  fPDG,
105  finalstateparticles); // returns true if the user-defined fPDG exist(s) in the final state particles
106 
107  } // bool
108  //} // namespace
109 
110  //------------------------------------------------
111 
112  bool FinalStateParticleFilter::isSubset(std::vector<int> const& a,
113  std::vector<int> const& b) const
114  {
115  for (auto const a_int : a) {
116  bool found = false;
117  for (auto const b_int : b) {
118  if (a_int == b_int) {
119  found = true;
120  break;
121  }
122  }
123 
124  if (!found) { return false; }
125  }
126  return true;
127  }
128 }
129 
130 //--------------------------------------------------
131 
132 namespace filt {
133 
135 
136 } //namespace filt
int NParticles() const
Definition: MCTruth.h:75
Particle class.
TString part[npart]
Definition: Style.C:32
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
FinalStateParticleFilter(fhicl::ParameterSet const &)
const simb::MCParticle & GetParticle(int i) const
Definition: MCTruth.h:76
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.cc:6
bool isSubset(std::vector< int > const &a, std::vector< int > const &b) const
TCEvent evt
Definition: DataStructs.cxx:8