Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
srcs
larevt
larevt
Filters
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
12
#include "art/Framework/Core/EDFilter.h"
13
#include "art/Framework/Core/ModuleMacros.h"
14
#include "art/Framework/Principal/Event.h"
15
#include "fhiclcpp/ParameterSet.h"
16
#include "art/Framework/Principal/Handle.h"
17
#include "canvas/Persistency/Common/Ptr.h"
18
#include "art/Framework/Services/Registry/ServiceHandle.h"
19
#include "art_root_io/TFileService.h"
20
21
//Larsoft Includes
22
#include "nusimdata/SimulationBase/MCParticle.h"
23
#include "nusimdata/SimulationBase/MCTruth.h"
24
25
// ROOT includes
26
#include "TH1.h"
27
28
namespace
filt
{
29
30
class
FinalStateParticleFilter
:
public
art::EDFilter {
31
32
public
:
33
34
explicit
FinalStateParticleFilter
(fhicl::ParameterSet
const
& );
35
36
bool
filter
(art::Event&
evt
);
37
void
beginJob
();
38
39
40
private
:
41
42
std::string
fGenieModuleLabel
;
43
std::vector<int>
fPDG
;
44
std::vector<int>
fStatusCode
;
45
TH1D*
fSelectedEvents
;
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
//-------------------------------------------------
57
FinalStateParticleFilter::FinalStateParticleFilter
(fhicl::ParameterSet
const
& pset)
58
: EDFilter{pset}
59
{
60
fGenieModuleLabel = pset.get< std::string >(
"GenieModuleLabel"
);
61
fPDG
= pset.get< std::vector<int> >(
"PDG"
);
62
}
63
64
//-------------------------------------------------
65
void
FinalStateParticleFilter::beginJob
()
66
{
67
art::ServiceHandle<art::TFileService const>
tfs
;
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
//-------------------------------------------------
73
bool
FinalStateParticleFilter::filter
(art::Event &
evt
)
74
{
75
76
//const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
77
78
art::Handle< std::vector<simb::MCTruth> > mclist;
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
128
DEFINE_ART_MODULE(FinalStateParticleFilter)
129
130
}
//namespace filt
filt::FinalStateParticleFilter::beginJob
void beginJob()
Definition:
FinalStateParticleFilter_module.cc:65
filt::FinalStateParticleFilter::fTotalEvents
TH1D * fTotalEvents
Definition:
FinalStateParticleFilter_module.cc:46
filt::FinalStateParticleFilter::fGenieModuleLabel
std::string fGenieModuleLabel
Definition:
FinalStateParticleFilter_module.cc:42
evgen::fPDG
createEngine fPDG
Definition:
GaisserParam_module.cc:170
a
process_name gaushit a
Definition:
decode_signalprocess_icarus.fcl:37
filt::FinalStateParticleFilter::filter
bool filter(art::Event &evt)
Definition:
FinalStateParticleFilter_module.cc:73
filt::FinalStateParticleFilter
Definition:
FinalStateParticleFilter_module.cc:30
filt::FinalStateParticleFilter::FinalStateParticleFilter
FinalStateParticleFilter(fhicl::ParameterSet const &)
Definition:
FinalStateParticleFilter_module.cc:57
filt::FinalStateParticleFilter::fSelectedEvents
TH1D * fSelectedEvents
Definition:
FinalStateParticleFilter_module.cc:45
filt
then filt
Definition:
make_xml_premcc1.0.sh:159
filt::FinalStateParticleFilter::isSubset
bool isSubset(std::vector< int > const &a, std::vector< int > const &b) const
Definition:
FinalStateParticleFilter_module.cc:105
tfs
art::ServiceHandle< art::TFileService > tfs
Definition:
NuVertexChargeTree_module.cc:254
tca::evt
TCEvent evt
Definition:
DataStructs.cxx:8
cout
BEGIN_PROLOG could also be cout
Definition:
messageservice.fcl:10
filt::FinalStateParticleFilter::fPDG
std::vector< int > fPDG
Definition:
FinalStateParticleFilter_module.cc:43
filt::FinalStateParticleFilter::fStatusCode
std::vector< int > fStatusCode
Definition:
FinalStateParticleFilter_module.cc:44
Generated by
1.8.5