Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CaloWaveformProcessing.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CaloWaveformProcessing.cc
2 #include "CaloWaveformFitting.h"
3 
5 
6 #include <phool/onnxlib.h>
7 
8 #include <algorithm> // for max
9 #include <cassert>
10 #include <cstdlib> // for getenv
11 #include <iostream>
12 #include <memory> // for allocator_traits<>::value_type
13 #include <string>
14 
15 Ort::Session *onnxmodule;
16 
18 {
19  delete m_Fitter;
20 }
21 
23 {
24  char *calibrationsroot = getenv("CALIBRATIONROOT");
25  assert(calibrationsroot);
27  {
28  std::string calibrations_repo_template = std::string(calibrationsroot) + "/WaveformProcessing/templates/" + m_template_input_file;
29  url_template = CDBInterface::instance()->getUrl(m_template_name, calibrations_repo_template);
33 
34  if (_bdosoftwarezerosuppression == true)
35  {
37  }
38  }
40  {
41  std::string calibrations_repo_model = std::string(calibrationsroot) + "/WaveformProcessing/models/" + m_model_name;
42  url_onnx = CDBInterface::instance()->getUrl(m_model_name, calibrations_repo_model);
44  }
45 }
46 
47 std::vector<std::vector<float>> CaloWaveformProcessing::process_waveform(std::vector<std::vector<float>> waveformvector)
48 {
49  int size1 = waveformvector.size();
50  std::vector<std::vector<float>> fitresults;
52  {
53  for (int i = 0; i < size1; i++)
54  {
55  waveformvector.at(i).push_back(i);
56  }
57  fitresults = m_Fitter->calo_processing_templatefit(waveformvector);
58  }
60  {
61  fitresults = CaloWaveformProcessing::calo_processing_ONNX(waveformvector);
62  }
64  {
65  fitresults = m_Fitter->calo_processing_fast(waveformvector);
66  }
67  return fitresults;
68 }
69 
70 std::vector<std::vector<float>> CaloWaveformProcessing::calo_processing_ONNX(std::vector<std::vector<float>> chnlvector)
71 {
72  std::vector<std::vector<float>> fit_values;
73  int nchnls = chnlvector.size();
74  for (int m = 0; m < nchnls; m++)
75  {
76  std::vector<float> v = chnlvector.at(m);
77  int nsamples = v.size() - 1;
78  std::vector<float> vtmp;
79  vtmp.reserve(nsamples);
80  for (int k = 0; k < nsamples; k++)
81  {
82  vtmp.push_back(v.at(k) / 1000.0);
83  }
84  std::vector<float> val = onnxInference(onnxmodule, vtmp, 1, 31, 3);
85  int nvals = val.size();
86  for (int i = 0; i < nvals; i++)
87  {
88  if (i == 0 || i == 2)
89  {
90  val.at(i) = val.at(i) * 1000;
91  }
92  }
93  fit_values.push_back(val);
94  val.clear();
95  }
96  return fit_values;
97 }
98 
100 {
101  if (m_Fitter)
102  {
103  return m_Fitter->get_nthreads();
104  }
105  return _nthreads;
106 }
108 {
109  _nthreads = nthreads;
110  if (m_Fitter)
111  {
112  m_Fitter->set_nthreads(nthreads);
113  }
114  return;
115 }