|
| 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) |
0 commit comments