LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
12
#include "
art/Framework/Core/EDFilter.h
"
13
#include "
art/Framework/Core/ModuleMacros.h
"
14
#include "
art/Framework/Principal/Event.h
"
15
#include "
art/Framework/Principal/Handle.h
"
16
#include "
art/Framework/Services/Registry/ServiceHandle.h
"
17
#include "art_root_io/TFileService.h"
18
#include "
canvas/Persistency/Common/Ptr.h
"
19
#include "
fhiclcpp/ParameterSet.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
explicit
FinalStateParticleFilter
(
fhicl::ParameterSet
const
&);
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
;
42
TH1D*
fSelectedEvents
;
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
//-------------------------------------------------
54
FinalStateParticleFilter::FinalStateParticleFilter
(
fhicl::ParameterSet
const
& pset)
55
:
EDFilter
{pset}
56
{
57
fGenieModuleLabel
= pset.get<std::string>(
"GenieModuleLabel"
);
58
fPDG
= pset.get<std::vector<int>>(
"PDG"
);
59
}
60
61
//-------------------------------------------------
62
void
FinalStateParticleFilter::beginJob
()
63
{
64
art::ServiceHandle<art::TFileService const>
tfs;
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
//-------------------------------------------------
79
bool
FinalStateParticleFilter::filter
(
art::Event
&
evt
)
80
{
81
82
//const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
83
84
art::Handle<std::vector<simb::MCTruth>
> mclist;
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) {
94
simb::MCParticle
part
(mc->
GetParticle
(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
134
DEFINE_ART_MODULE
(
FinalStateParticleFilter
)
135
136
}
//namespace filt
art::ServiceHandle< art::TFileService const >
filt::FinalStateParticleFilter::beginJob
void beginJob()
Definition:
FinalStateParticleFilter_module.cc:62
art::EDFilter
Definition:
EDFilter.h:16
filt
Definition:
FinalStateParticleFilter_module.cc:28
filt::FinalStateParticleFilter::fTotalEvents
TH1D * fTotalEvents
Definition:
FinalStateParticleFilter_module.cc:43
simb::MCParticle
Definition:
MCParticle.h:24
art::Handle
Definition:
fwd.h:19
simb::MCTruth::NParticles
int NParticles() const
Definition:
MCTruth.h:75
filt::FinalStateParticleFilter::fGenieModuleLabel
std::string fGenieModuleLabel
Definition:
FinalStateParticleFilter_module.cc:39
MCParticle.h
Particle class.
Handle.h
ParameterSet.h
ServiceHandle.h
part
TString part[npart]
Definition:
Style.C:32
filt::FinalStateParticleFilter::filter
bool filter(art::Event &evt)
Definition:
FinalStateParticleFilter_module.cc:79
DEFINE_ART_MODULE
#define DEFINE_ART_MODULE(klass)
Definition:
ModuleMacros.h:65
EDFilter.h
filt::FinalStateParticleFilter
Definition:
FinalStateParticleFilter_module.cc:30
Event.h
Ptr.h
filt::FinalStateParticleFilter::FinalStateParticleFilter
FinalStateParticleFilter(fhicl::ParameterSet const &)
Definition:
FinalStateParticleFilter_module.cc:54
ModuleMacros.h
simb::MCTruth::GetParticle
const simb::MCParticle & GetParticle(int i) const
Definition:
MCTruth.h:76
art::Event
Definition:
Event.h:26
art::ProductRetriever::getByLabel
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition:
ProductRetriever.h:444
filt::FinalStateParticleFilter::fSelectedEvents
TH1D * fSelectedEvents
Definition:
FinalStateParticleFilter_module.cc:42
art::EDFilter::EDFilter
EDFilter(fhicl::ParameterSet const &pset)
Definition:
EDFilter.cc:6
MCTruth.h
filt::FinalStateParticleFilter::isSubset
bool isSubset(std::vector< int > const &a, std::vector< int > const &b) const
Definition:
FinalStateParticleFilter_module.cc:112
tca::evt
TCEvent evt
Definition:
DataStructs.cxx:8
art::Ptr< simb::MCTruth >
filt::FinalStateParticleFilter::fPDG
std::vector< int > fPDG
Definition:
FinalStateParticleFilter_module.cc:40
fhicl::ParameterSet
Definition:
ParameterSet.h:36
filt::FinalStateParticleFilter::fStatusCode
std::vector< int > fStatusCode
Definition:
FinalStateParticleFilter_module.cc:41
larevt
v09_10_03
source
larevt
Filters
FinalStateParticleFilter_module.cc
Generated on Thu May 2 2024 20:59:39 for LArSoft by
1.8.11