Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cvneventtf::CVNEventTF Class Reference
Inheritance diagram for cvneventtf::CVNEventTF:
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

 CVNEventTF (fhicl::ParameterSet const &pset)
 
virtual ~CVNEventTF ()
 
void produce (art::Event &evt)
 
bool IsRHC (const art::Event &evt)
 
tensorflow::Tensor vector_to_tensor (std::vector< unsigned char >)
 
tensorflow::TFHandlerGetModel (const art::Event &evt)
 
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
 

Protected Attributes

std::string fSliceLabel
 
std::string fPixelMapInput
 
std::string fGeneratorLabel
 
std::string fNuMILabel
 
bool fObeyPreselection
 
std::vector< std::stringfPreselectionLabels
 
bool fUseGeV
 
std::string fLibPath
 
std::string fModelFHCName
 
std::string fModelRHCName
 
unsigned int fNOutput
 
std::string fInputName
 
std::string fOutputName
 
unsigned int fCPUlimit
 
bool fUseOppositeHornCurrentNetwork
 
tensorflow::TFHandlerfTFFHC
 
tensorflow::TFHandlerfTFRHC
 

Detailed Description

Definition at line 39 of file CVNEventTF_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

cvneventtf::CVNEventTF::CVNEventTF ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 71 of file CVNEventTF_module.cc.

References util::EnvExpansion(), and fLibPath.

71  :
72  fSliceLabel (pset.get<std::string>("SliceLabel")),
73  fPixelMapInput(pset.get<std::string>("PixelMapInput")),
74  fGeneratorLabel (pset.get<std::string>("GeneratorLabel")),
75  fNuMILabel (pset.get<std::string>("NuMILabel")),
76  fObeyPreselection (pset.get<bool> ("ObeyPreselection" )),
77  fPreselectionLabels(pset.get<std::vector<std::string>> ("PreselectionLabels")),
78  fUseGeV (pset.get<bool> ("UseGeV")),
79  fLibPath (pset.get<std::string>("LibPath")),
80  fModelFHCName (pset.get<std::string>("ModelFHCName")),
81  fModelRHCName (pset.get<std::string>("ModelRHCName")),
82  fNOutput (pset.get<unsigned int>("NOutput")),
83  fInputName (pset.get<std::string>("InputName")),
84  fOutputName (pset.get<std::string>("OutputName")),
85  fCPUlimit (pset.get<unsigned int>("CPUlimit")),
86  fUseOppositeHornCurrentNetwork(pset.get<bool>("UseOppositeHornCurrentNetwork")),
87  fTFFHC(0),
88  fTFRHC(0)
89  {
91  produces< std::vector<cvn::Result> >();
92  produces< art::Assns<cvn::Result,rb::Cluster> >();
93  }
std::string EnvExpansion(const std::string &inString)
Function to expand environment variables.
Definition: EnvExpand.cxx:8
tensorflow::TFHandler * fTFFHC
std::vector< std::string > fPreselectionLabels
tensorflow::TFHandler * fTFRHC
enum BeamMode string
cvneventtf::CVNEventTF::~CVNEventTF ( )
virtual

Definition at line 95 of file CVNEventTF_module.cc.

References fTFFHC, and fTFRHC.

96  {
97  if(fTFFHC) delete fTFFHC;
98  if(fTFRHC) delete fTFRHC;
99  }
tensorflow::TFHandler * fTFFHC
tensorflow::TFHandler * fTFRHC

Member Function Documentation

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
tensorflow::TFHandler * cvneventtf::CVNEventTF::GetModel ( const art::Event evt)

Definition at line 122 of file CVNEventTF_module.cc.

References fCPUlimit, fLibPath, fModelFHCName, fModelRHCName, fTFFHC, fTFRHC, and IsRHC().

Referenced by produce().

123  {
124 
125  if (IsRHC(evt)) {
126  if (!fTFRHC)
128  return fTFRHC;
129  }
130  else {
131  if (!fTFFHC)
133  return fTFFHC;
134  }
135  }
bool IsRHC(const art::Event &evt)
tensorflow::TFHandler * fTFFHC
tensorflow::TFHandler * fTFRHC
Wrapper for Tensorflow which handles construction and prediction.
Definition: TFHandler.h:19
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  }
bool cvneventtf::CVNEventTF::IsRHC ( const art::Event evt)

Definition at line 101 of file CVNEventTF_module.cc.

References art::Handle< T >::failedToGet(), fGeneratorLabel, fNuMILabel, fUseOppositeHornCurrentNetwork, art::DataViewImpl::getByLabel(), art::Event::isRealData(), and sumdata::SpillData::isRHC.

Referenced by GetModel().

102  {
104  if (!evt.isRealData())
105  evt.getByLabel(fGeneratorLabel, spillPot);
106  else
107  evt.getByLabel(fNuMILabel, spillPot);
108 
109  if (spillPot.failedToGet())
110  {
111  mf::LogError("CVNEventTF") <<
112  "Spill Data not found, aborting without horn current information";
113  abort();
114  }
115 
116  if(fUseOppositeHornCurrentNetwork) return !spillPot->isRHC;
117 
118  // NB - the logic here will cause 0HC to use the FHC network
119  return spillPot->isRHC;
120  }
bool isRHC
is the beam in antineutrino mode, aka RHC
Definition: SpillData.h:28
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool isRealData() const
Definition: Event.h:83
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
bool failedToGet() const
Definition: Handle.h:196
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 cvneventtf::CVNEventTF::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 151 of file CVNEventTF_module.cc.

References util::CreateAssn(), DEFINE_ART_MODULE(), fInputName, check_time_usage::float, fNOutput, fObeyPreselection, fOutputName, fPixelMapInput, fPreselectionLabels, fSliceLabel, fUseGeV, art::DataViewImpl::getByLabel(), GetModel(), MECModelEnuComparisons::i, rb::IsFiltered(), output, tensorflow::TFHandler::Predict(), art::PtrVector< T >::push_back(), art::Event::put(), fillBadChanDBTables::result, art::PtrVector< T >::size(), and vector_to_tensor().

152  {
153 
154  tensorflow::TFHandler* fTF = GetModel(evt);
155  //Containers for things we're gonna produce
156  std::unique_ptr< std::vector<cvn::Result> >
157  resultCol(new std::vector<cvn::Result>);
158  std::unique_ptr< art::Assns<cvn::Result, rb::Cluster> >
159  assocresult(new art::Assns<cvn::Result, rb::Cluster>);
160 
161  // Get slices
163  evt.getByLabel(fSliceLabel, slicecol);
164  art::PtrVector<rb::Cluster> slicelist;
165  for(unsigned int i = 0; i < slicecol->size(); ++i){
166  slicelist.push_back(art::Ptr<rb::Cluster>(slicecol, i));
167  }
168 
169  // Get pixel maps
170  art::FindManyP<cvn::PixelMap> fmPixelMap(slicecol, evt, fPixelMapInput);
171 
172  //loop over slices
173  for(size_t iClust = 0; iClust < slicelist.size(); ++iClust) {
174  if(!fmPixelMap.isValid()) continue;
175  if(slicelist[iClust]->IsNoise()) continue;
176  if(fObeyPreselection && rb::IsFiltered(evt, slicecol, iClust, fPreselectionLabels)) continue;
177 
178  const std::vector<art::Ptr<cvn::PixelMap> > pixelMaps = fmPixelMap.at(iClust);
179  if(pixelMaps.empty()) continue;
180 
181  std::vector<unsigned char> pmslice = (*pixelMaps[0]).PixelMapToVector(fUseGeV);
182 
183  tensorflow::Tensor tensor = vector_to_tensor(pmslice);
184 
185  std::vector<tensorflow::Tensor> result = fTF->Predict({{fInputName,tensor}},
186  {fOutputName});
187  auto tfoutput = result[0].tensor<float,2>();
188 
189  float resultvec[fNOutput];
190 
191  for(unsigned int i = 0; i<fNOutput; i++){
192  resultvec[i] = (float)tfoutput(0,i);
193  }
194  const float* output = resultvec;
195 
196  resultCol->emplace_back(output, fNOutput);
197 
198  util::CreateAssn(*this, evt, *(resultCol.get()),
199  slicelist[iClust], *(assocresult.get()), UINT_MAX);
200 
201  } // slices
202 
203  evt.put(std::move(resultCol));
204  evt.put(std::move(assocresult));
205 
206  } // produce
ofstream output
static bool CreateAssn(art::EDProducer const &prod, art::Event &evt, std::vector< T > &a, art::Ptr< U > b, art::Assns< T, U > &assn, size_t indx=UINT_MAX, std::string const &instance=std::string())
Create a 1 to 1 association between a new product and one already in the event.
std::vector< Tensor > Predict(std::vector< std::pair< std::string, Tensor >> inputs, std::vector< std::string > outputLabels)
Definition: TFHandler.cxx:64
tensorflow::Tensor vector_to_tensor(std::vector< unsigned char >)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
bool IsFiltered(const art::Event &evt, art::Ptr< T > x, const std::vector< std::string > &labels)
Is this Ptr marked "filtered out"?
Definition: FilterList.h:96
size_type size() const
Definition: PtrVector.h:308
tensorflow::TFHandler * GetModel(const art::Event &evt)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::vector< std::string > fPreselectionLabels
Wrapper for Tensorflow which handles construction and prediction.
Definition: TFHandler.h:19
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

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

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited
tensorflow::Tensor cvneventtf::CVNEventTF::vector_to_tensor ( std::vector< unsigned char >  pm)

Definition at line 137 of file CVNEventTF_module.cc.

References check_time_usage::float, MECModelEnuComparisons::i, and shutoffs::rel.

Referenced by produce().

138  {
139  const unsigned int vectorSize = pm.size();
140 
141  // Initialize the tensors
142  tensorflow::Tensor tensor(tensorflow::DT_FLOAT, {1, vectorSize});
143  auto rel = tensor.tensor<float,2>();
144 
145  // Loop over each element
146  for(unsigned int i = 0; i < vectorSize; ++i) rel(0, i) = pm[i];
147 
148  return tensor;
149  }
string rel
Definition: shutoffs.py:11

Member Data Documentation

unsigned int cvneventtf::CVNEventTF::fCPUlimit
protected

Definition at line 63 of file CVNEventTF_module.cc.

Referenced by GetModel().

std::string cvneventtf::CVNEventTF::fGeneratorLabel
protected

Definition at line 52 of file CVNEventTF_module.cc.

Referenced by IsRHC().

std::string cvneventtf::CVNEventTF::fInputName
protected

Definition at line 61 of file CVNEventTF_module.cc.

Referenced by produce().

std::string cvneventtf::CVNEventTF::fLibPath
protected

Definition at line 57 of file CVNEventTF_module.cc.

Referenced by CVNEventTF(), and GetModel().

std::string cvneventtf::CVNEventTF::fModelFHCName
protected

Definition at line 58 of file CVNEventTF_module.cc.

Referenced by GetModel().

std::string cvneventtf::CVNEventTF::fModelRHCName
protected

Definition at line 59 of file CVNEventTF_module.cc.

Referenced by GetModel().

unsigned int cvneventtf::CVNEventTF::fNOutput
protected

Definition at line 60 of file CVNEventTF_module.cc.

Referenced by produce().

std::string cvneventtf::CVNEventTF::fNuMILabel
protected

Definition at line 53 of file CVNEventTF_module.cc.

Referenced by IsRHC().

bool cvneventtf::CVNEventTF::fObeyPreselection
protected

Definition at line 54 of file CVNEventTF_module.cc.

Referenced by produce().

std::string cvneventtf::CVNEventTF::fOutputName
protected

Definition at line 62 of file CVNEventTF_module.cc.

Referenced by produce().

std::string cvneventtf::CVNEventTF::fPixelMapInput
protected

Definition at line 51 of file CVNEventTF_module.cc.

Referenced by produce().

std::vector<std::string> cvneventtf::CVNEventTF::fPreselectionLabels
protected

Definition at line 55 of file CVNEventTF_module.cc.

Referenced by produce().

std::string cvneventtf::CVNEventTF::fSliceLabel
protected

Definition at line 50 of file CVNEventTF_module.cc.

Referenced by produce().

tensorflow::TFHandler* cvneventtf::CVNEventTF::fTFFHC
protected

Definition at line 65 of file CVNEventTF_module.cc.

Referenced by GetModel(), and ~CVNEventTF().

tensorflow::TFHandler* cvneventtf::CVNEventTF::fTFRHC
protected

Definition at line 66 of file CVNEventTF_module.cc.

Referenced by GetModel(), and ~CVNEventTF().

bool cvneventtf::CVNEventTF::fUseGeV
protected

Definition at line 56 of file CVNEventTF_module.cc.

Referenced by produce().

bool cvneventtf::CVNEventTF::fUseOppositeHornCurrentNetwork
protected

Definition at line 64 of file CVNEventTF_module.cc.

Referenced by IsRHC().


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