9 #ifndef ANAB_MVAREADER_H 10 #define ANAB_MVAREADER_H 22 template <
class T,
size_t N>
32 std::unique_ptr<FVectorReader> ptr(
new FVectorReader(evt, tag, success));
33 if (success) {
return ptr; }
34 else {
return nullptr; }
56 std::array<float, N> vout;
57 for (
size_t i = 0; i < N; ++i) vout[i] = (*
fVectors)[key][i];
86 o <<
"FVectorReader:" << std::endl << *(a.
fDescription) << std::endl;
96 std::vector< FeatureVector<N> >
const *
fVectors;
103 template <
class T,
size_t N>
113 std::unique_ptr<MVAReader> ptr(
new MVAReader(evt, tag, success));
114 if (success) {
return ptr; }
115 else {
return nullptr; }
144 std::vector<float>
const & weights)
const 151 std::function<
float (T
const &)> fweight)
const 169 template <
class T,
size_t N>
173 if (!N) {
throw cet::exception(
"FVectorReader") <<
"Vector size should be > 0." << std::endl; }
175 auto descriptionHandle = evt.
getValidHandle< std::vector< anab::FVecDescription<N> > >(tag);
179 for (
auto const & dscr : *descriptionHandle)
181 if (dscr.outputInstance() == outputInstanceName)
186 if (!
fDescription) {
throw cet::exception(
"FVectorReader") <<
"Vectors description not found for " << outputInstanceName << std::endl; }
197 throw cet::exception(
"FVectorReader") <<
"Feature vectors and data products sizes inconsistent: " <<
fVectors->size() <<
"!=" <<
fDataHandle->size() << std::endl;
202 template <
class T,
size_t N>
208 if (!N) { std::cout <<
"FVectorReader: Vector size should be > 0." << std::endl;
return; }
211 if (!evt.
getByLabel( tag, descriptionHandle )) {
return; }
215 for (
auto const & dscr : *descriptionHandle)
217 if (dscr.outputInstance() == outputInstanceName)
222 if (!
fDescription) { std::cout <<
"FVectorReader: Vectors description not found for " << outputInstanceName << std::endl;
return; }
228 std::cout <<
"FVectorReader: Associated data product handle failed: " << *(
fDataHandle.
whyFailed()) << std::endl;
return;
233 std::cout <<
"FVectorReader: Feature vectors and data products sizes inconsistent: " <<
fVectors->size() <<
"!=" <<
fDataHandle->size() << std::endl;
return;
240 #endif //ANAB_MVAREADER
const art::Handle< std::vector< T > > & dataHandle() const
Access the data product handle.
art::Handle< std::vector< T > > fDataHandle
std::array< float, N > getVector(size_t key) const
Get copy of the feature vector at index "key".
static std::unique_ptr< FVectorReader > create(const art::Event &evt, const art::InputTag &tag)
std::array< float, N > getOutput(std::vector< art::Ptr< T > > const &items, std::function< float(T const &)> fweight) const
int getIndex(const std::string &name) const
Index of column with given name, or -1 if name not found.
const std::string & outputName(size_t index) const
Meaning/name of the index'th column in the collection of MVA output vectors.
std::vector< FeatureVector< N > > const & vectors() const
Access the vector of the feature vectors.
T const & item(size_t key) const
Access data product at index "key".
std::string getProductName(std::type_info const &ti) const
FVecDescription< N > const * fDescription
std::array< float, N > getOutput(art::Ptr< T > const &item) const
Get copy of the MVA output vector idicated with art::Ptr::key().
std::vector< FeatureVector< N > > const * fVectors
MVAReader(const art::Event &evt, const art::InputTag &tag)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< T > const & items() const
std::array< float, N > getVector(art::Ptr< T > const &item) const
Get copy of the feature vector idicated with art::Ptr::key().
Helper functions for MVAReader and MVAWriter wrappers.
const std::string & columnName(size_t index) const
Meaning/name of the index'th column in the collection of feature vectors.
std::vector< FeatureVector< N > > const & outputs() const
Access the vector of the feature vectors.
size_t size() const
Get the number of contained items (no. of data product objects equal to no. of feature vectors)...
size_t length() const
Get the length of a single feature vector.
FVectorReader(const art::Event &evt, const art::InputTag &tag)
Helper functions for MVAReader/Writer and FVecReader/Writer wrappers.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
std::shared_ptr< art::Exception const > whyFailed() const
friend std::ostream & operator<<(std::ostream &o, FVectorReader const &a)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
std::array< float, N > getOutput(std::vector< art::Ptr< T > > const &items) const
Get MVA results accumulated over the vector of items (eg. over hits associated to a cluster)...
std::array< float, N > getOutput(size_t key) const
Get copy of the MVA output vector at index "key".
std::array< float, N > getOutput(std::vector< art::Ptr< T > > const &items, std::vector< float > const &weights) const
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
cet::coded_exception< error, detail::translate > exception
MVAReader(const art::Event &evt, const art::InputTag &tag, bool &success)
Not-throwing constructor.
const std::string & dataTag() const
Get the input tag (string representation) of data product used to calculate feature vectors...