31 #include "Utilities/AssociationUtil.h" 46 tensorflow::Tensor
vector_to_tensor(std::vector<unsigned char>, std::vector<unsigned char>);
50 std::vector<std::pair<int, double>> &outputwithpdg, std::vector<float> &
result , std::vector<unsigned char> pmslc);
105 produces< std::vector<cvn::Result> >();
106 produces< art::Assns<cvn::Result, rb::Cluster> >();
107 produces< art::Assns<cvn::Result, rb::Prong> >();
108 produces< std::vector<rb::PID> >();
109 produces< art::Assns<rb::PID,rb::Prong> >();
135 const unsigned int vectorSize = pm.size();
138 tensorflow::Tensor tensor(tensorflow::DT_FLOAT, {1, vectorSize});
139 auto rel = tensor.tensor<
float,2>();
142 for(
unsigned int i = 0;
i < vectorSize; ++
i)
rel(0,
i) = pm[
i];
149 const unsigned int vectorSizeSlice = pmslice.size();
150 const unsigned int vectorSizeProng = pmprong.size();
151 const unsigned int vectorSizeTotal = vectorSizeSlice + vectorSizeProng;
154 tensorflow::Tensor tensor(tensorflow::DT_FLOAT, {1, vectorSizeTotal});
155 auto rel = tensor.tensor<
float,2>();
158 for(
unsigned int i = 0;
i < vectorSizeSlice; ++
i)
rel(0,
i) = pmslice[
i];
159 for(
unsigned int j = vectorSizeSlice;
j < vectorSizeTotal; ++
j)
rel(0,
j) = pmprong[
j-vectorSizeSlice];
170 std::unique_ptr< std::vector<cvn::Result> >
171 resultCol(
new std::vector<cvn::Result>);
172 std::unique_ptr< art::Assns<cvn::Result, rb::Cluster> >
174 std::unique_ptr< art::Assns<cvn::Result, rb::Prong> >
176 std::unique_ptr< std::vector<rb::PID> >
177 pidCol(
new std::vector<rb::PID>);
178 std::unique_ptr< art::Assns<rb::PID, rb::Prong> >
185 for(
unsigned int i = 0;
i < slicecol->size(); ++
i){
193 for(
size_t iClust = 0; iClust < slicelist.
size(); ++iClust) {
194 if(!fmPixelMap.isValid())
continue;
195 if(slicelist[iClust]->IsNoise())
continue;
199 const std::vector<art::Ptr<cvn::PixelMap> > pixelMapsSl = fmPixelMap.at(iClust);
200 if(pixelMapsSl.empty())
continue;
201 std::vector<unsigned char> pmslice = (*pixelMapsSl[0]).PixelMapToVector(
fUseGeV);
206 if( fmProng2D.isValid() ) {
208 std::vector<art::Ptr<rb::Prong>> prongs2D = fmProng2D.at(iClust);
210 if ( fmPixelMap2D.isValid() ) {
212 for(
unsigned int iProng = 0; iProng < prongs2D.size(); ++iProng ){
214 std::vector<std::pair<int, double>> outputwithpdg;
215 std::vector<float>
result;
216 if ( fmPixelMap2D.at(iProng).empty() )
continue;
223 resultvec[
i] = result[
i];
225 pidCol->emplace_back(outputwithpdg[
i].first, outputwithpdg[
i].
second);
227 prongs2D[iProng], *(assocpid.get()), UINT_MAX);
230 const float* resultoutput = resultvec;
231 resultCol->emplace_back(resultoutput, fNOutput2D);
233 slicelist[iClust], *(assocresultslice.get()), UINT_MAX);
235 prongs2D[iClust], *(assocresultprong.get()), UINT_MAX);
242 std::vector<art::Ptr<rb::Prong>> prongs3D;
243 if( fmProng3D.isValid() ) {
245 std::vector<art::Ptr<rb::Prong>> prongs3D = fmProng3D.at(iClust);
247 if ( fmPixelMap3D.isValid() ) {
248 for(
unsigned int iProng = 0; iProng < prongs3D.size(); ++iProng ){
250 std::vector<std::pair<int, double>> outputwithpdg;
251 std::vector<float>
result;
252 if ( fmPixelMap3D.at(iProng).empty() )
continue;
258 for(
unsigned int i = 0;
i < result.size();
i++){
259 resultvec[
i] = result[
i];
261 pidCol->emplace_back(outputwithpdg[
i].first, outputwithpdg[
i].
second);
263 prongs3D[iProng], *(assocpid.get()), UINT_MAX);
266 const float* resultoutput = resultvec;
267 resultCol->emplace_back(resultoutput, fNOutput3D);
269 slicelist[iClust], *(assocresultslice.get()), UINT_MAX);
271 prongs3D[iClust], *(assocresultprong.get()), UINT_MAX);
277 evt.
put(std::move(resultCol));
278 evt.
put(std::move(assocresultslice));
279 evt.
put(std::move(assocresultprong));
280 evt.
put(std::move(pidCol));
281 evt.
put(std::move(assocpid));
287 std::vector<std::pair<int, double>> &outputwithpdg, std::vector<float> &
result , std::vector<unsigned char> pmslc) {
289 std::vector<unsigned char> pmprong = (*pixelMaps[0]).PixelMapToVector(
fUseGeV);
291 tensorflow::Tensor tensorslc;
292 tensorflow::Tensor tensor;
298 auto tfoutput = TFResult[0].tensor<
float,2>();
301 for(
unsigned int i = 0;
i < NOutput;
i++){
313 result.push_back( (
float)tfoutput(0,
i) );
std::string fPixelMapInput
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.
tensorflow::TFHandler * GetModel2D(const art::Event &evt)
tensorflow::TFHandler * fTF3D
std::string EnvExpansion(const std::string &inString)
Function to expand environment variables.
std::string fProng3DLabel
void CalcResult(std::vector< art::Ptr< cvn::PixelMap > > pixelMaps, tensorflow::TFHandler *fTF, unsigned int NOutput, std::vector< std::pair< int, double >> &outputwithpdg, std::vector< float > &result, std::vector< unsigned char > pmslc)
tensorflow::TFHandler * GetModel3D(const art::Event &evt)
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
DEFINE_ART_MODULE(TestTMapFile)
tensorflow::TFHandler * fTF2D
tensorflow::Tensor vector_to_tensor(std::vector< unsigned char >)
std::vector< Tensor > Predict(std::vector< std::pair< std::string, Tensor >> inputs, std::vector< std::string > outputLabels)
ProductID put(std::unique_ptr< PROD > &&product)
void push_back(Ptr< U > const &p)
std::string fProng2DLabel
CVNNeutronProngTF(fhicl::ParameterSet const &pset)
std::vector< std::string > fPreselectionLabels
bool IsFiltered(const art::Event &evt, art::Ptr< T > x, const std::vector< std::string > &labels)
Is this Ptr marked "filtered out"?
std::string fGeneratorLabel
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
assert(nhit_max >=nhit_nbins)
std::string fProngModLabel
Wrapper for Tensorflow which handles construction and prediction.
void produce(art::Event &evt)
virtual ~CVNNeutronProngTF()
std::string fInputNameSlc