FinalStateParticleFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
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 //
9 ////////////////////////////////////////////////////////////////////////
10 
11 //Framework Includes
15 #include "fhiclcpp/ParameterSet.h"
19 #include "art_root_io/TFileService.h"
20 
21 //Larsoft Includes
24 
25 // ROOT includes
26 #include "TH1.h"
27 
28 namespace filt {
29 
31 
32  public:
33 
35 
36  bool filter(art::Event& evt);
37  void beginJob();
38 
39 
40  private:
41 
43  std::vector<int> fPDG;
44  std::vector<int> fStatusCode;
46  TH1D* fTotalEvents;
47 
48  bool isSubset(std::vector<int> const& a, std::vector<int> const& b) const;
49 
50  }; // class FinalStateParticleFilter
51 
52 }
53 
54 namespace filt{
55 
56  //-------------------------------------------------
58  : EDFilter{pset}
59  {
60  fGenieModuleLabel = pset.get< std::string >("GenieModuleLabel");
61  fPDG = pset.get< std::vector<int> >("PDG");
62  }
63 
64  //-------------------------------------------------
66  {
68  fSelectedEvents = tfs->make<TH1D>("fSelectedEvents", "Number of Selected Events", 3, 0, 3); //counts the number of selected events
69  fTotalEvents = tfs->make<TH1D>("fTotalEvents", "Total Events", 3, 0, 3); //counts the initial number of events in the unfiltered root input file
70  }
71 
72  //-------------------------------------------------
74  {
75 
76  //const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
77 
79  evt.getByLabel(fGenieModuleLabel,mclist);
80  art::Ptr<simb::MCTruth> mc(mclist,0);
81 
82  fTotalEvents->Fill(1);
83 
84  std::vector<int> finalstateparticles;
85 
86  //get a vector of final state particles
87  for(int i = 0; i < mc->NParticles(); ++i){
88  simb::MCParticle part(mc->GetParticle(i));
89  if(part.StatusCode()== 1)
90  finalstateparticles.push_back(part.PdgCode());
91  }
92 
93  if(isSubset(fPDG, finalstateparticles)){
94  fSelectedEvents->Fill(1);
95  std::cout << "this is a selected event" << std::endl;
96  }
97 
98  return isSubset(fPDG, finalstateparticles); // returns true if the user-defined fPDG exist(s) in the final state particles
99 
100  } // bool
101  //} // namespace
102 
103 //------------------------------------------------
104 
105 bool FinalStateParticleFilter::isSubset(std::vector<int> const& a, std::vector<int> const& b) const
106 {
107  for (auto const a_int : a) {
108  bool found = false;
109  for (auto const b_int : b) {
110  if (a_int == b_int){
111  found = true;
112  break;
113  }
114  }
115 
116  if (!found){
117  return false;
118  }
119  }
120  return true;
121 }
122 }
123 
124 //--------------------------------------------------
125 
126 namespace filt {
127 
129 
130 } //namespace filt
std::string string
Definition: nybbler.cc:12
int NParticles() const
Definition: MCTruth.h:75
Particle class.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
const double a
FinalStateParticleFilter(fhicl::ParameterSet const &)
const simb::MCParticle & GetParticle(int i) const
Definition: MCTruth.h:76
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
static bool * b
Definition: config.cpp:1043
bool isSubset(std::vector< int > const &a, std::vector< int > const &b) const
TCEvent evt
Definition: DataStructs.cxx:7
QTextStream & endl(QTextStream &s)