Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
filter::TruthFilter Class Reference

A class for filtering Truth hits and truth interactions. More...

Inheritance diagram for filter::TruthFilter:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 TruthFilter (fhicl::ParameterSet const &pset)
 
virtual ~TruthFilter ()
 
void produce (art::Event &evt)
 
void beginJob ()
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< Tconsumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< Tconsumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TconsumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< TmayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< TmayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TmayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Private Attributes

std::string fGenModuleLabel
 
std::string fInputModuleLabel
 
int fRejectHadron
 
int fRejectLepton
 
int fNCOnly
 
int fCCOnly
 
int fNuOnly
 
int fNuBarOnly
 
int fNuE
 
int fNuMu
 
int fNuTau
 
bool fDoRejectInteractions
 

Static Private Attributes

static bool fNotYetWarned =true
 

Detailed Description

A class for filtering Truth hits and truth interactions.

Definition at line 30 of file TruthFilter_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

filter::TruthFilter::TruthFilter ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 66 of file TruthFilter_module.cc.

References fCCOnly, fDoRejectInteractions, fNCOnly, fNuBarOnly, fNuE, fNuMu, fNuOnly, fNuTau, fRejectHadron, fRejectLepton, and getGoodRuns4SAM::n.

66  :
67  fGenModuleLabel (pset.get< std::string >("GenModuleLabel")),
68  fInputModuleLabel (pset.get< std::string >("InputModuleLabel")),
69  fRejectHadron (pset.get< int >("RejectLepton")),
70  fRejectLepton (pset.get< int >("RejectHadron")),
71  fNCOnly (pset.get< int >("NCOnly")),
72  fCCOnly (pset.get< int >("CCOnly")),
73  fNuOnly (pset.get< int >("NuOnly")),
74  fNuBarOnly (pset.get< int >("NuBarOnly")),
75  fNuE (pset.get< int >("NuE")),
76  fNuMu (pset.get< int >("NuMu")),
77  fNuTau (pset.get< int >("NuTau")),
79  {
80  /*
81  assert_jobc(fNuE>=-1&&fNuE<=1,
82  "Choices for NuE are -1 (reject), 0 (no decision),+1 (require)\n");
83  assert_jobc(fNuMu>=-1&&fNuMu<=1,
84  "Choices for NuMu are -1 (reject), 0 (no decision),+1 (require)\n");
85  assert_jobc(fNuTau>=-1&&fNuTau<=1,
86  "Choices for NuTau are -1 (reject), 0 (no decision),+1 (require)\n");
87  */
88 
89  int n=TMath::Abs(fNuE)+TMath::Abs(fNuMu)+TMath::Abs(fNuTau);
92 
93  // assert_jobc(!(fRejectLepton&&fRejectHadron),"Cannot filter both Lepton and Hadron\n");
94 
95  produces< std::vector<sim::FilterFlags> >();
96  }
enum BeamMode string
virtual filter::TruthFilter::~TruthFilter ( )
inlinevirtual

Definition at line 34 of file TruthFilter_module.cc.

References beginJob(), evt, and produce().

34 {};

Member Function Documentation

void filter::TruthFilter::beginJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 99 of file TruthFilter_module.cc.

Referenced by ~TruthFilter().

100  {
101  }
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 146 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

147 {
148  if (!moduleContext_)
149  return ProductToken<T>::invalid();
150 
151  consumables_[BT].emplace_back(ConsumableType::Product,
152  TypeID{typeid(T)},
153  it.label(),
154  it.instance(),
155  it.process());
156  return ProductToken<T>{it};
157 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 161 of file Consumer.h.

References T.

162 {
163  if (!moduleContext_)
164  return;
165 
166  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
167 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 171 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

172 {
173  if (!moduleContext_)
174  return ViewToken<T>::invalid();
175 
176  consumables_[BT].emplace_back(ConsumableType::ViewElement,
177  TypeID{typeid(T)},
178  it.label(),
179  it.instance(),
180  it.process());
181  return ViewToken<T>{it};
182 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited
CurrentProcessingContext const* art::EDProducer::currentContext ( ) const
protectedinherited
seed_t art::EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

Referenced by skim::NueSkimmer::CopyMichelSlice(), and skim::NueSkimmer::CopyMichelTrack().

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 189 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

190 {
191  if (!moduleContext_)
192  return ProductToken<T>::invalid();
193 
194  consumables_[BT].emplace_back(ConsumableType::Product,
195  TypeID{typeid(T)},
196  it.label(),
197  it.instance(),
198  it.process());
199  return ProductToken<T>{it};
200 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 204 of file Consumer.h.

References T.

205 {
206  if (!moduleContext_)
207  return;
208 
209  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
210 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 214 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

215 {
216  if (!moduleContext_)
217  return ViewToken<T>::invalid();
218 
219  consumables_[BT].emplace_back(ConsumableType::ViewElement,
220  TypeID{typeid(T)},
221  it.label(),
222  it.instance(),
223  it.process());
224  return ViewToken<T>{it};
225 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID(), and string.

41  {
42  return true;
43  }
static cet::exempt_ptr<Consumer> art::Consumer::non_module_context ( )
staticinherited
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
void filter::TruthFilter::produce ( art::Event evt)
virtual

get the neutrino information from the truth object

Implements art::EDProducer.

Definition at line 104 of file TruthFilter_module.cc.

References simb::MCNeutrino::CCNC(), DEFINE_ART_MODULE(), sim::ParticleNavigator::EveId(), fCCOnly, fDoRejectInteractions, fGenModuleLabel, sim::FLSHitList::fHits, fInputModuleLabel, fNCOnly, fNuBarOnly, fNuE, fNuMu, fNuOnly, fNuTau, fRejectHadron, sim::FilterFlags::fRejectHits, sim::FilterFlags::fRejectInter, fRejectLepton, art::DataViewImpl::getByLabel(), MECModelEnuComparisons::i, if(), genie::pdg::IsLepton(), calib::j, simb::kBeamNeutrino, simb::kCC, simb::kNC, simb::kSuperNovaNeutrino, simb::MCNeutrino::Nu(), simb::MCTruth::Origin(), sim::ParticleNavigator::Particle(), cheat::BackTracker::ParticleNavigator(), simb::MCParticle::PdgCode(), and art::Event::put().

Referenced by ~TruthFilter().

105  {
106  std::unique_ptr<std::vector<sim::FilterFlags> > fflags(new std::vector<sim::FilterFlags>);
107  std::unique_ptr<std::vector<sim::FLSHitList> > fhitlist(new std::vector<sim::FLSHitList>);
108 
111 
112  evt.getByLabel(fInputModuleLabel, hitlist);
113  evt.getByLabel(fGenModuleLabel, truthlist);
114 
115  // want to define entire vector (on entry per interaction), to maintain
116  // 1-to-1 correspondence with FLSHitList vector, etc.
117 
118  int NKeep=0; // keep track of kept interactions
119 
120  // loop over interactions
121  for (size_t i = 0; i < truthlist->size(); ++i) {
122 
123  sim::FilterFlags flag;
124 
125  //get the truth information from the list of truths
126  //taking the first event if there are two
127  simb::MCTruth truth = (*truthlist)[0];
128 
129  //first, see if we can skip entire interaction
131  && (truth.Origin() == simb::kBeamNeutrino ||
132  truth.Origin() == simb::kSuperNovaNeutrino)) {
133  ///get the neutrino information from the truth object
134  const simb::MCNeutrino* nu = &(truthlist->at(i).GetNeutrino());
135 
136  if ((fNCOnly && nu->CCNC()==simb::kCC) ||
137  (fCCOnly && nu->CCNC()==simb::kNC)) flag.fRejectInter=true;
138 
139  if ((fNuOnly && nu->Nu().PdgCode() < 0) ||
140  (fNuBarOnly && nu->Nu().PdgCode() > 0)) flag.fRejectInter=true;
141 
142  if ((fNuE == 1 && TMath::Abs(nu->Nu().PdgCode()) != 12) ||
143  (fNuE == -1 && TMath::Abs(nu->Nu().PdgCode()) == 12))
144  flag.fRejectInter=true;
145 
146  if ((fNuMu == 1 && TMath::Abs(nu->Nu().PdgCode()) != 14) ||
147  (fNuMu == -1 && TMath::Abs(nu->Nu().PdgCode()) == 14))
148  flag.fRejectInter=true;
149 
150  if ((fNuTau == 1 && TMath::Abs(nu->Nu().PdgCode()) != 16) ||
151  (fNuTau == -1 && TMath::Abs(nu->Nu().PdgCode()) == 16))
152  flag.fRejectInter=true;
153 
154  // skip looping over hits if this whole interaction is rejected
155  if (flag.fRejectInter) continue;
156  }
157 
158 
159  ++NKeep;//keep track of number of interactions not rejected
160 
162  const sim::ParticleNavigator& pnav = bt->ParticleNavigator();
163 
164  sim::FLSHitList filteredHitList;
165  // now loop over hits in this interaction
166  for (unsigned int j=0; j< hitlist->at(i).fHits.size(); ++j) {
167 
168  int trk=hitlist->at(i).fHits[j].GetTrackID();
169 
170  // find ultimate parent track
171  int motherTrk = pnav.EveId(trk);
172 
173  const unsigned int evePDG=TMath::Abs( pnav.Particle(motherTrk)->PdgCode() );
174 
175  bool IsLepton = (evePDG == 11) || (evePDG == 13) || (evePDG == 15);
176 
177  if ((fRejectHadron && !IsLepton) || (fRejectLepton && IsLepton))
178  flag.fRejectHits.insert(j);
179  else
180  filteredHitList.fHits.push_back(hitlist->at(i).fHits[j]);
181 
182  }// for input hit j
183 
184  fflags->push_back(flag);
185  fhitlist->push_back(filteredHitList);
186 
187  }//for interaction i
188 
189  evt.put(std::move(fflags));
190  evt.put(std::move(fhitlist));
191 
192  return;
193 
194  }
int PdgCode() const
Definition: MCParticle.h:211
int CCNC() const
Definition: MCNeutrino.h:148
std::vector< sim::FLSHit > fHits
Definition: FLSHitList.h:21
const sim::ParticleNavigator & ParticleNavigator() const
Get a reference to the ParticleNavigator.
Definition: BackTracker.h:744
const simb::MCParticle & Nu() const
Definition: MCNeutrino.h:146
simb::Origin_t Origin() const
Definition: MCTruth.h:73
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
Track finder for cosmic rays.
if(dump)
const double j
Definition: BetheBloch.cxx:29
std::set< int > fRejectHits
Definition: FilterFlags.h:20
A vector of FLSHit from single neutrino interaction.
Definition: FLSHitList.h:13
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Supernova neutrinos.
Definition: MCTruth.h:25
Event generator information.
Definition: MCTruth.h:32
Event generator information.
Definition: MCNeutrino.h:18
bool IsLepton(int pdgc)
Definition: PDGUtils.cxx:84
Beam neutrinos.
Definition: MCTruth.h:23
mapped_type Particle(const size_type) const
int EveId(const int trackID) const
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Referenced by art::RootOutput::endJob().

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Member Data Documentation

int filter::TruthFilter::fCCOnly
private

Definition at line 46 of file TruthFilter_module.cc.

Referenced by produce(), and TruthFilter().

bool filter::TruthFilter::fDoRejectInteractions
private

Definition at line 54 of file TruthFilter_module.cc.

Referenced by produce(), and TruthFilter().

std::string filter::TruthFilter::fGenModuleLabel
private

Definition at line 41 of file TruthFilter_module.cc.

Referenced by produce().

std::string filter::TruthFilter::fInputModuleLabel
private

Definition at line 42 of file TruthFilter_module.cc.

Referenced by produce().

int filter::TruthFilter::fNCOnly
private

Definition at line 45 of file TruthFilter_module.cc.

Referenced by produce(), and TruthFilter().

bool filter::TruthFilter::fNotYetWarned =true
staticprivate

Definition at line 55 of file TruthFilter_module.cc.

int filter::TruthFilter::fNuBarOnly
private

Definition at line 48 of file TruthFilter_module.cc.

Referenced by produce(), and TruthFilter().

int filter::TruthFilter::fNuE
private

Definition at line 50 of file TruthFilter_module.cc.

Referenced by produce(), and TruthFilter().

int filter::TruthFilter::fNuMu
private

Definition at line 51 of file TruthFilter_module.cc.

Referenced by produce(), and TruthFilter().

int filter::TruthFilter::fNuOnly
private

Definition at line 47 of file TruthFilter_module.cc.

Referenced by produce(), and TruthFilter().

int filter::TruthFilter::fNuTau
private

Definition at line 52 of file TruthFilter_module.cc.

Referenced by produce(), and TruthFilter().

int filter::TruthFilter::fRejectHadron
private

Definition at line 43 of file TruthFilter_module.cc.

Referenced by produce(), and TruthFilter().

int filter::TruthFilter::fRejectLepton
private

Definition at line 44 of file TruthFilter_module.cc.

Referenced by produce(), and TruthFilter().


The documentation for this class was generated from the following file: