Skip to content

Commit 1c60d7c

Browse files
committed
filter module to select events according to the lepton type after the GENIE interactions
1 parent 08eadde commit 1c60d7c

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
art_make(
3+
MODULE_LIBRARIES larcorealg_Geometry
4+
nusimdata_SimulationBase
5+
${ART_FRAMEWORK_CORE}
6+
${ART_FRAMEWORK_PRINCIPAL}
7+
art_Persistency_Common
8+
art_Persistency_Provenance
9+
art_Utilities
10+
canvas
11+
${MF_MESSAGELOGGER}
12+
${FHICLCPP}
13+
cetlib cetlib_except
14+
${ROOT_BASIC_LIB_LIST}
15+
)
16+
17+
# install_headers()
18+
install_fhicl()
19+
install_source()
20+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
* @file FilterGENIELeptonType.cc
3+
* @brief A simple filter to select events with specified lepton types (+/-11, +/-12, +/-13, +/-14, etc.) from GENIE
4+
* @author Yun-Tse Tsai (yuntse@slac.stanford.edu)
5+
* @date October 14, 2018
6+
*
7+
*/
8+
9+
10+
// LArSoft libraries
11+
#include "nusimdata/SimulationBase/MCTruth.h"
12+
13+
14+
// framework libraries
15+
#include "art/Framework/Core/EDFilter.h"
16+
#include "art/Framework/Core/ModuleMacros.h"
17+
#include "art/Framework/Principal/Event.h"
18+
#include "art/Framework/Principal/Handle.h" // art::ValidHandle<>
19+
#include "art/Persistency/Common/PtrMaker.h"
20+
#include "canvas/Persistency/Common/Ptr.h"
21+
#include "canvas/Utilities/InputTag.h"
22+
#include "messagefacility/MessageLogger/MessageLogger.h"
23+
#include "fhiclcpp/types/Atom.h"
24+
#include "fhiclcpp/types/Sequence.h"
25+
#include "fhiclcpp/types/Table.h"
26+
27+
// C++ libraries
28+
#include <vector>
29+
#include <set>
30+
#include <algorithm> // std::copy()
31+
#include <iterator> // std::inserter()
32+
33+
34+
namespace {
35+
36+
template <typename T>
37+
std::set<T> vectorToSet(std::vector<T> const& v) {
38+
std::set<T> s;
39+
std::copy(v.begin(), v.end(), std::inserter(s, s.begin()));
40+
return s;
41+
} // vectorToSet()
42+
43+
} // local namespace
44+
45+
46+
namespace bdm {
47+
48+
class FilterGENIELeptonType : public art::EDFilter
49+
{
50+
public:
51+
52+
/// Algorithm configuration
53+
struct Config {
54+
55+
using Name = fhicl::Name;
56+
using Comment = fhicl::Comment;
57+
58+
fhicl::Atom< art::InputTag > MCTruthLabel{
59+
Name("MCTruthLabel"),
60+
Comment("the producer of the MCTruth used in the filter.")
61+
};
62+
63+
fhicl::Sequence< int > LeptonPdgCode{
64+
Name("LeptonPdgCode"),
65+
Comment("the lepton pdgcodes for the events to be kept.")
66+
};
67+
68+
}; // Config
69+
70+
using Parameters = art::EDFilter::Table<Config>;
71+
72+
explicit FilterGENIELeptonType( Parameters const& config );
73+
74+
virtual bool filter(art::Event&) override;
75+
76+
private:
77+
78+
art::InputTag fMCTruthLabel;
79+
std::set< int > fKeptLeptons;
80+
};
81+
82+
} // namespace bdm
83+
84+
// -------------------------------------------------------------------------
85+
// --- FilterGENIELeptonType
86+
// ---
87+
bdm::FilterGENIELeptonType::FilterGENIELeptonType( Parameters const& config )
88+
: fMCTruthLabel( config().MCTruthLabel() )
89+
, fKeptLeptons( ::vectorToSet(config().LeptonPdgCode()) )
90+
{
91+
consumes< std::vector< simb::MCTruth > >( fMCTruthLabel );
92+
}
93+
94+
bool bdm::FilterGENIELeptonType::filter( art::Event& evt )
95+
{
96+
97+
auto MCTruthHandle = evt.getValidHandle< std::vector< simb::MCTruth > >( fMCTruthLabel );
98+
auto const& MCTruthObjs = *MCTruthHandle;
99+
100+
bool isDesired = false;
101+
102+
for (auto const& MCTruthObj: MCTruthObjs) {
103+
auto const& lepton = MCTruthObj.GetNeutrino().Lepton();
104+
auto const leptonPdgCode = lepton.PdgCode();
105+
106+
isDesired = fKeptLeptons.count( leptonPdgCode ) > 0;
107+
if ( isDesired ) break;
108+
109+
}
110+
return isDesired;
111+
}
112+
113+
//------------------------------------------------------------------------------
114+
DEFINE_ART_MODULE(bdm::FilterGENIELeptonType)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
BEGIN_PROLOG
2+
3+
################################################################################
4+
standard_select_ncinteractions: {
5+
6+
MCTruthLabel: GenieGen
7+
LeptonPdgCode: [ -12, 12, -14, 14 ]
8+
9+
} # standard_select_final_state
10+
11+
12+
################################################################################
13+
14+
END_PROLOG

0 commit comments

Comments
 (0)