Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
protoduneana
protoduneana
Utilities
ProtoDUNETruthBeamFilter_module.cc
Go to the documentation of this file.
1
////////////////////////////////////////////////////////////////////////
2
//
3
// Filter to selects events with a given beam particle.
4
// Owen Goodwin
5
// owen.goodwin@postgrad.manchester.ac.uk
6
//
7
////////////////////////////////////////////////////////////////////////
8
9
// Framework includes
10
#include "
art/Framework/Core/EDFilter.h
"
11
#include "
art/Framework/Principal/Event.h
"
12
#include "
art/Framework/Principal/Handle.h
"
13
#include "
art/Framework/Services/Registry/ServiceHandle.h
"
14
#include "art_root_io/TFileService.h"
15
#include "
art/Framework/Core/ModuleMacros.h
"
16
#include "
messagefacility/MessageLogger/MessageLogger.h
"
17
#include "
fhiclcpp/ParameterSet.h
"
18
#include "
nusimdata/SimulationBase/MCParticle.h
"
19
#include "
nusimdata/SimulationBase/MCTruth.h
"
20
21
22
23
24
// ROOT includes
25
#include "TTree.h"
26
#include "TFile.h"
27
#include "TString.h"
28
#include "TH1.h"
29
#include "TH2.h"
30
// C++ Includes
31
#include <fstream>
32
#include <string>
33
#include <sstream>
34
#include <cmath>
35
#include <algorithm>
36
#include <iostream>
37
#include <vector>
38
39
40
41
namespace
protoana
{
42
class
ProtoDUNETruthBeamFilter;
43
}
44
45
class
protoana::ProtoDUNETruthBeamFilter
:
public
art::EDFilter
{
46
public
:
47
48
explicit
ProtoDUNETruthBeamFilter
(
fhicl::ParameterSet
const
& pset);
49
virtual
~ProtoDUNETruthBeamFilter
();
50
51
void
beginJob
();
52
bool
filter
(
art::Event
&
evt
);
53
void
reconfigure
(
fhicl::ParameterSet
const
& pset);
54
void
endJob
();
55
56
private
:
57
58
bool
fDebug
;
/// Controls the verbosity
59
60
std::vector<int>
fPDG
;
/// List of particle PDGs we want to keep
61
62
63
64
TH1D*
fSelectedEvents
;
65
TH1D*
fTotalEvents
;
66
67
68
69
};
70
71
//-----------------------------------------------------------------------
72
protoana::ProtoDUNETruthBeamFilter::ProtoDUNETruthBeamFilter
(
fhicl::ParameterSet
const
& pset)
73
:
EDFilter
(pset)
74
{
75
this->
reconfigure
(pset);
76
77
}
78
79
//-----------------------------------------------------------------------
80
protoana::ProtoDUNETruthBeamFilter::~ProtoDUNETruthBeamFilter
(){}
81
82
//-----------------------------------------------------------------------
83
void
protoana::ProtoDUNETruthBeamFilter::beginJob
() {
84
85
art::ServiceHandle<art::TFileService>
tfs;
86
fSelectedEvents
= tfs->make<TH1D>(
"fSelectedEvents"
,
"Number of Selected Events"
, 3, 0, 3);
//counts the number of selected events
87
fTotalEvents
= tfs->make<TH1D>(
"fTotalEvents"
,
"Total Events"
, 3, 0, 3);
//counts the initial number of events in the unfiltered root input file
88
89
}
90
91
//-----------------------------------------------------------------------
92
void
protoana::ProtoDUNETruthBeamFilter::reconfigure
(
fhicl::ParameterSet
const
& pset){
93
94
95
fPDG
= pset.
get
< std::vector<int> >(
"PDG"
);
96
fDebug
= pset.
get
<
bool
>(
"IsVerbose"
);
97
98
}
99
100
//-----------------------------------------------------------------------
101
bool
protoana::ProtoDUNETruthBeamFilter::filter
(
art::Event
&
evt
){
102
103
104
105
if
(
fDebug
) std::cout <<
"Reading Event"
<<
std::endl
;
106
107
108
bool
found
=
false
;
109
// Access truth info
110
std::vector< art::Ptr<simb::MCTruth> > mclist;
111
auto
mctruthhandle = evt.
getHandle
< std::vector<simb::MCTruth> >(
"generator"
);
112
if
(mctruthhandle){
113
art::fill_ptr_vector
(mclist,mctruthhandle);
114
}
115
else
{
116
mf::LogError
(
"protoana::ProtoDUNETruthBeamParticle::analyze"
) <<
"Requested protoDUNE beam generator information does not exist!"
;
117
return
found
;
118
}
119
fTotalEvents
->Fill(1);
//count total events
120
121
art::Ptr<simb::MCTruth>
mctruth;
122
mctruth = mclist[0];
123
124
125
for
(
int
i = 0; i < mctruth->
NParticles
(); ++i){
126
const
simb::MCParticle
& part(mctruth->
GetParticle
(i));
127
128
bool
isgoodparticle = (part.Process() ==
"primary"
&& mctruth->
Origin
()==4);
//primary particle and beam origin
129
if
(!isgoodparticle)
continue
;
130
// Select partciles with the chosen pdg
131
for
(
unsigned
int
j = 0; j <
fPDG
.size(); j++){
132
if
(part.PdgCode() ==
fPDG
[j]){
133
found =
true
;
134
if
(
fDebug
) std::cout <<
"this is a selected event with PDG "
<< part.
PdgCode
() <<
std::endl
;
135
fSelectedEvents
->Fill(1);
//count selected events
136
break
;
137
}
138
}
139
140
}
141
142
return
found
;
143
144
}
145
146
147
void
protoana::ProtoDUNETruthBeamFilter::endJob
() {}
148
149
DEFINE_ART_MODULE
(
protoana::ProtoDUNETruthBeamFilter
)
150
art::ServiceHandle< art::TFileService >
simb::MCParticle::PdgCode
int PdgCode() const
Definition:
MCParticle.h:212
art::EDFilter
Definition:
EDFilter.h:16
protoana::ProtoDUNETruthBeamFilter
Definition:
ProtoDUNETruthBeamFilter_module.cc:45
Handle.h
art::DataViewImpl::getHandle
Handle< PROD > getHandle(SelectorBase const &) const
Definition:
DataViewImpl.h:382
simb::MCTruth::Origin
simb::Origin_t Origin() const
Definition:
MCTruth.h:74
simb::MCParticle
Definition:
MCParticle.h:24
simb::MCTruth::NParticles
int NParticles() const
Definition:
MCTruth.h:75
mf::LogError
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Definition:
MessageLogger.h:211
MCParticle.h
Particle class.
protoana::ProtoDUNETruthBeamFilter::reconfigure
void reconfigure(fhicl::ParameterSet const &pset)
Definition:
ProtoDUNETruthBeamFilter_module.cc:92
MessageLogger.h
ParameterSet.h
ServiceHandle.h
DEFINE_ART_MODULE
#define DEFINE_ART_MODULE(klass)
Definition:
ModuleMacros.h:67
EDFilter.h
protoana
Definition:
ProtoDUNEDataUtils.h:19
protoana::ProtoDUNETruthBeamFilter::beginJob
void beginJob()
Definition:
ProtoDUNETruthBeamFilter_module.cc:83
fhicl::ParameterSet::get
T get(std::string const &key) const
Definition:
ParameterSet.h:271
protoana::ProtoDUNETruthBeamFilter::fDebug
bool fDebug
Definition:
ProtoDUNETruthBeamFilter_module.cc:58
protoana::ProtoDUNETruthBeamFilter::~ProtoDUNETruthBeamFilter
virtual ~ProtoDUNETruthBeamFilter()
Definition:
ProtoDUNETruthBeamFilter_module.cc:80
protoana::ProtoDUNETruthBeamFilter::fTotalEvents
TH1D * fTotalEvents
Definition:
ProtoDUNETruthBeamFilter_module.cc:65
ModuleMacros.h
simb::MCTruth::GetParticle
const simb::MCParticle & GetParticle(int i) const
Definition:
MCTruth.h:76
art::Event
Definition:
Event.h:22
protoana::ProtoDUNETruthBeamFilter::filter
bool filter(art::Event &evt)
Definition:
ProtoDUNETruthBeamFilter_module.cc:101
protoana::ProtoDUNETruthBeamFilter::fSelectedEvents
TH1D * fSelectedEvents
List of particle PDGs we want to keep.
Definition:
ProtoDUNETruthBeamFilter_module.cc:64
protoana::ProtoDUNETruthBeamFilter::endJob
void endJob()
Definition:
ProtoDUNETruthBeamFilter_module.cc:147
ValidateOpDetReco.found
bool found
Definition:
ValidateOpDetReco.py:358
art::EDFilter::EDFilter
EDFilter(fhicl::ParameterSet const &pset)
Definition:
EDFilter.h:21
MCTruth.h
tca::evt
TCEvent evt
Definition:
DataStructs.cxx:7
Event.h
art::fill_ptr_vector
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition:
Ptr.h:297
protoana::ProtoDUNETruthBeamFilter::fPDG
std::vector< int > fPDG
Controls the verbosity.
Definition:
ProtoDUNETruthBeamFilter_module.cc:60
art::Ptr< simb::MCTruth >
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
fhicl::ParameterSet
Definition:
ParameterSet.h:36
protoana::ProtoDUNETruthBeamFilter::ProtoDUNETruthBeamFilter
ProtoDUNETruthBeamFilter(fhicl::ParameterSet const &pset)
Definition:
ProtoDUNETruthBeamFilter_module.cc:72
Generated by
1.8.11