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

 CVNCosmicTF (fhicl::ParameterSet const &pset)
 
virtual ~CVNCosmicTF ()
 
void produce (art::Event &evt)
 
void pixelmap_to_tensor (cvn::PixelMap const *pip, tensorflow::Tensor *tensorX, tensorflow::Tensor *tensorY)
 
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 bool sortPixelTime (const cvn::PixelMap *a, const cvn::PixelMap *b)
 
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 fPixelMapInput
 
float fCosmicCut
 
bool useFIFO
 
tensorflow::TFHandlerfTF
 
tensorflow::TFFifoHandlerfTFF
 
const art::ProductToken< std::vector< cvn::PixelMap > > fPixelMapToken
 

Detailed Description

Definition at line 32 of file CVNCosmicTF_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

cvntf::CVNCosmicTF::CVNCosmicTF ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 57 of file CVNCosmicTF_module.cc.

References util::EnvExpansion(), fTF, fTFF, fhicl::ParameterSet::get(), string, and useFIFO.

57  :
58  fPixelMapInput(pset.get<std::string>("PixelMapInput")),
59  fCosmicCut(pset.get<float>("CosmicCut")),
60  fTF(0),
61  fTFF(0),
62  fPixelMapToken(consumes<std::vector<cvn::PixelMap>>(fPixelMapInput))
63  {
64  fhicl::ParameterSet const handlerConfig = pset.get<fhicl::ParameterSet>("TFHandler");
65  std::string const handlerMethod = handlerConfig.get<std::string>("Method");
66  if (handlerMethod == "direct") {
67  fTF = new tensorflow::TFHandler(util::EnvExpansion(handlerConfig.get<std::string>("ModelPath")));
68  useFIFO = false;
69  }
70  else if (handlerMethod == "fifo") {
71  fTFF = new tensorflow::TFFifoHandler(handlerConfig);
72  useFIFO = true;
73  }
74  else {
75  mf::LogError("CVNCosmicTF") << "Unrecognized TensorFlowHandler method: " << handlerMethod;
76  abort();
77  }
78 
79  produces<std::vector<cvntf::CVNCosmicFiltList> >();
80 
81  }
const art::ProductToken< std::vector< cvn::PixelMap > > fPixelMapToken
std::string EnvExpansion(const std::string &inString)
Function to expand environment variables.
Definition: EnvExpand.cxx:8
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Wrapper which handles communication with a TF script via FIFO pipes.
Definition: TFFifoHandler.h:20
T get(std::string const &key) const
Definition: ParameterSet.h:231
tensorflow::TFFifoHandler * fTFF
tensorflow::TFHandler * fTF
Wrapper for Tensorflow which handles construction and prediction.
Definition: TFHandler.h:19
ProductToken< T > consumes(InputTag const &)
enum BeamMode string
cvntf::CVNCosmicTF::~CVNCosmicTF ( )
virtual

Definition at line 83 of file CVNCosmicTF_module.cc.

84  {
85  //if(fTF) delete fTF;
86  }

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
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 cvntf::CVNCosmicTF::pixelmap_to_tensor ( cvn::PixelMap const *  pip,
tensorflow::Tensor *  tensorX,
tensorflow::Tensor *  tensorY 
)

Definition at line 88 of file CVNCosmicTF_module.cc.

References check_time_usage::float, cvn::PixelMap::fPEX, cvn::PixelMap::fPEY, allTimeWatchdog::index, cvn::PixelMap::NCell(), and cvn::PixelMap::NPlanePerView().

Referenced by produce().

89  {
90  // Initialize the tensors
91  auto relX = tensorX->tensor<float,4>();
92  auto relY = tensorY->tensor<float,4>();
93 
94  int index = 0;
95 
96  // Loop over each element
97  for(unsigned int iPlane = 0; iPlane < pip->NPlanePerView(); ++iPlane){
98  for(unsigned int iCell = 0; iCell < pip->NCell(); ++iCell){
99  relX(0, iCell, iPlane, 0) = (pip->fPEX[index]>0 ? 1 : 0);
100  relY(0, iCell, iPlane, 0) = (pip->fPEY[index]>0 ? 1 : 0);
101  ++index; //unsigned int index = plane * fNCell + cell % fNCell;
102  }
103  }
104 
105  }
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
void cvntf::CVNCosmicTF::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 107 of file CVNCosmicTF_module.cc.

References cvntf::CVNCosmicFiltList::AddElement(), cvntf::CVNCosmicFilt::cosmicVal, DEFINE_ART_MODULE(), fCosmicCut, check_time_usage::float, fPixelMapToken, fTF, fTFF, art::DataViewImpl::getByToken(), MECModelEnuComparisons::i, ncells, cvntf::CVNCosmicFilt::ncVal, cvntf::CVNCosmicFilt::nHits, nplanes, cvntf::CVNCosmicFilt::nueVal, cvntf::CVNCosmicFilt::numuVal, cvntf::CVNCosmicFilt::nutauVal, cvntf::CVNCosmicFilt::passSel, pixelmap_to_tensor(), tensorflow::TFFifoHandler::Predict(), tensorflow::TFHandler::Predict(), art::Event::put(), fillBadChanDBTables::result, sortPixelTime(), cvntf::CVNCosmicFilt::timeWinMax, cvntf::CVNCosmicFilt::timeWinMin, and useFIFO.

108  {
109 
111  evt.getByToken(fPixelMapToken, pixelcol);
112  //art::PtrVector<cvn::PixelMap> pixellist;
113  std::vector<cvn::PixelMap const*> pixellist;
114 
115  auto cvnfiltlistcol = std::make_unique<std::vector<cvntf::CVNCosmicFiltList>>();
116 
117 
118  // Check for empty set of pixel maps
119  if (pixelcol->size() == 0) {
120  // If there are no pixel maps, add an empty set of filters to the event
121  evt.put(std::move(cvnfiltlistcol));
122  mf::LogWarning("CVNCosmicTF") << "No pixelmaps, storing an empty list of CosmicFilter results.";
123  return;
124  }
125 
126 
127  cvntf::CVNCosmicFiltList cosfiltlist;
128 
129  for (cvn::PixelMap const& pm: *pixelcol) {
130  pixellist.push_back(&pm);
131  }
132 
133  std::sort(pixellist.begin(), pixellist.end(), sortPixelTime);
134 
135 
136 
137 
138  //
139  // Evaluate the pixel maps and get the results back.
140  //
141  std::vector<std::vector<double> > tfoutput;
142 
143  if (useFIFO) {
144  tfoutput = fTFF->Predict(pixellist);
145  }
146  else {
147  for(size_t iP = 0; iP < pixellist.size(); ++iP) {
148  auto pip = pixellist[iP];
149 
150  // Fill the pixel map array for this slice
151  //std::vector<unsigned char> pm = pip->PixelMapToVector(false);
152 
153  const int ncells = pip->NCell();
154  const int nplanes = pip->NPlanePerView();
155  // Convert to format expected by the network
156  tensorflow::Tensor tensorX(tensorflow::DT_FLOAT, {1, ncells, nplanes, 1});
157  tensorflow::Tensor tensorY(tensorflow::DT_FLOAT, {1, ncells, nplanes, 1});
158  pixelmap_to_tensor(pip, &tensorX, &tensorY);
159 
160  std::vector<tensorflow::Tensor> result = fTF->Predict({{"xview",tensorX},{"yview",tensorY}},
161  {"output_out"});
162 
163  auto tfresult = result[0].tensor<float,2>();
164  std::vector<double> tfvals(5, 0);
165  for (int i = 0; i < 5; i++)
166  tfvals[i] = tfresult(0,i);
167 
168  tfoutput.push_back(tfvals);
169  }
170  }
171 
172 
173 
174  //
175  // loop over pixel maps again to save results
176  //
177 
178  for(size_t iP = 0; iP < pixellist.size(); ++iP) {
179  auto pip = pixellist[iP];
180 
181 
182  // Fill the cosmic filter info
183  cvntf::CVNCosmicFilt cosfilt;
184  cosfilt.timeWinMin = pip->MinTime();
185  cosfilt.timeWinMax = pip->MaxTime();
186  cosfilt.nHits = pip->fOccupiedPixels;
187  cosfilt.numuVal = tfoutput[iP][0];
188  cosfilt.nueVal = tfoutput[iP][1];
189  cosfilt.nutauVal = tfoutput[iP][2];
190  cosfilt.ncVal = tfoutput[iP][3];
191  cosfilt.cosmicVal = tfoutput[iP][4];
192  cosfilt.passSel = false;
193 
194 
195  // Apply cuts
196  if (cosfilt.cosmicVal < fCosmicCut) cosfilt.passSel = true;
197 
198 
199  // Save this CosFilt object
200  cosfiltlist.AddElement(cosfilt);
201  } // pixel maps
202 
203 
204  cvnfiltlistcol->push_back(cosfiltlist);
205 
206  evt.put(std::move(cvnfiltlistcol));
207 
208  } // produce
const art::ProductToken< std::vector< cvn::PixelMap > > fPixelMapToken
std::vector< std::vector< double > > Predict(const std::vector< cvn::PixelMap const * > pixellist) const
float ncVal
Cosmic CVN nc score for each time slice.
float cosmicVal
Cosmic CVN cosmic score for each time slice.
float nutauVal
Cosmic CVN nutau score for each time slice.
std::vector< Tensor > Predict(std::vector< std::pair< std::string, Tensor >> inputs, std::vector< std::string > outputLabels)
Definition: TFHandler.cxx:64
void AddElement(CVNCosmicFilt cf)
float nueVal
Cosmic CVN nue score for each time slice.
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
tensorflow::TFFifoHandler * fTFF
int nplanes
Definition: geom.C:145
PixelMap, basic input to CVN neural net.
Definition: PixelMap.h:23
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
int ncells
Definition: geom.C:124
float numuVal
Cosmic CVN numu score for each time slice.
tensorflow::TFHandler * fTF
bool getByToken(ProductToken< PROD > const &token, Handle< PROD > &result) const
Definition: DataViewImpl.h:387
static bool sortPixelTime(const cvn::PixelMap *a, const cvn::PixelMap *b)
void pixelmap_to_tensor(cvn::PixelMap const *pip, tensorflow::Tensor *tensorX, tensorflow::Tensor *tensorY)
unsigned int nHits
number of hits in time window
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

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

static bool cvntf::CVNCosmicTF::sortPixelTime ( const cvn::PixelMap a,
const cvn::PixelMap b 
)
inlinestatic

Definition at line 43 of file CVNCosmicTF_module.cc.

References cvn::PixelMap::MinTime().

Referenced by produce().

43 { return a->MinTime() < b->MinTime();}
float MinTime() const
Definition: PixelMap.h:46
void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Member Data Documentation

float cvntf::CVNCosmicTF::fCosmicCut
protected

Definition at line 47 of file CVNCosmicTF_module.cc.

Referenced by produce().

std::string cvntf::CVNCosmicTF::fPixelMapInput
protected

Definition at line 46 of file CVNCosmicTF_module.cc.

const art::ProductToken<std::vector<cvn::PixelMap> > cvntf::CVNCosmicTF::fPixelMapToken
protected

Definition at line 52 of file CVNCosmicTF_module.cc.

Referenced by produce().

tensorflow::TFHandler* cvntf::CVNCosmicTF::fTF
protected

Definition at line 50 of file CVNCosmicTF_module.cc.

Referenced by CVNCosmicTF(), and produce().

tensorflow::TFFifoHandler* cvntf::CVNCosmicTF::fTFF
protected

Definition at line 51 of file CVNCosmicTF_module.cc.

Referenced by CVNCosmicTF(), and produce().

bool cvntf::CVNCosmicTF::useFIFO
protected

Definition at line 48 of file CVNCosmicTF_module.cc.

Referenced by CVNCosmicTF(), and produce().


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