8#ifndef CDCTRIGGERMLPDATA_H
9#define CDCTRIGGERMLPDATA_H
11#include <framework/logging/Logger.h>
15#include "boost/iostreams/filter/gzip.hpp"
16#include "boost/iostreams/filtering_streambuf.hpp"
17#include "boost/iostreams/filtering_stream.hpp"
18#include "boost/multi_array.hpp"
19#define BOOST_MULTI_ARRAY_NO_GENERATORS
35 if (line.size() == 19) {
37 for (
unsigned i = 1; i <= 19; i++) {
40 }
else {B2ERROR(
"ERROR! wrong lengthof relID vector!");}
42 void operator= (std::vector<float> line)
44 if (line.size() == 19) {
46 for (
unsigned i = 1; i <= 19; i++) {
49 }
else {B2ERROR(
"ERROR! wrong length of relID vector!");}
53 HeaderSet(
unsigned expert, std::vector<float> relevantID)
55 if (relevantID.size() == 18) {
56 for (
unsigned i = 0; i < 18; ++i) {relID[i] = relevantID[i];}
57 }
else {B2ERROR(
"ERROR! wrong length of relID vector!");}
60 friend std::ostream& operator << (std::ostream& out,
const HeaderSet& hset)
62 out << hset.exPert <<
'\t';
63 for (
unsigned i = 0; i < 18; ++i) { out << hset.relID[i] <<
'\t';}
66 friend std::istream& operator >> (std::istream& in,
HeaderSet& hset)
72 std::getline(in, helpline,
'\n');
73 if (helpline.length() < 2) {
return in;}
74 std::stringstream ss(helpline);
75 std::getline(ss, help,
'\t');
77 hset.exPert = std::stoul(help);
78 for (
unsigned i = 0; i < 18; ++i) {
80 std::getline(ss, help,
'\t');
81 hset.relID[i] = std::stof(help);
91 template <const
unsigned inLen, const
unsigned outLen>
109 std::string headline;
112 headline =
"Experiment\tRun\tSubrun\tEvent\tTrack\tnTracks\tExpert\tiNodes\toNodes\t";
113 for (
unsigned i = 0; i < inLen / 3; ++i) {
114 headline +=
"SL" + std::to_string(i) +
"-relID\t";
115 headline +=
"SL" + std::to_string(i) +
"-driftT\t";
116 headline +=
"SL" + std::to_string(i) +
"-alpha\t";
118 headline +=
"RecoZ\tRecoTheta\tScaleZ\tRawZ\tScaleTheta\tRawTheta\t2DPhi\t3DTheta\t2DinvPt\n";
121 NeuroSet(
float xin[inLen],
float xout[outLen],
int xexp,
int xrun,
int xsubrun,
int xevt,
int xtrack,
unsigned xexpert,
122 int xntracks,
int xnnrawz,
int xnnrawtheta,
float xnnscalez,
float xnnscaletheta,
float xinphi,
float xintheta,
float xininvpt)
124 for (
unsigned i = 0; i < inLen; ++i) {
127 for (
unsigned i = 0; i < outLen; ++i) {
138 nnscalez = xnnscalez;
139 nnscaletheta = xnnscaletheta;
141 nnrawtheta = xnnrawtheta;
145 headline =
"Experiment\tRun\tSubrun\tEvent\tTrack\tnTracks\tExpert\tiNodes\toNodes\t";
146 for (
unsigned i = 0; i < inLen / 3; ++i) {
147 headline +=
"SL" + std::to_string(i) +
"-relID\t";
148 headline +=
"SL" + std::to_string(i) +
"-driftT\t";
149 headline +=
"SL" + std::to_string(i) +
"-alpha\t";
151 headline +=
"RecoZ\tRecoTheta\tScaleZ\tRawZ\tScaleTheta\tRawTheta\t2DPhi\t3DTheta\t2DinvPt\n";
154 friend std::ostream& operator << (std::ostream& out,
const NeuroSet& dset)
156 out << dset.exp <<
'\t' << dset.run <<
'\t' << dset.subrun <<
'\t' << dset.evt <<
'\t' << dset.track <<
'\t' << dset.ntracks <<
'\t'
157 << dset.expert <<
'\t'
158 << inLen <<
'\t' << outLen <<
'\t';
159 for (
auto indata : dset.input) {out << indata <<
'\t';}
160 for (
auto outdata : dset.target) {out << outdata <<
'\t';}
161 out << dset.nnscalez <<
'\t' << dset.nnrawz <<
'\t' << dset.nnscaletheta <<
'\t' << dset.nnrawtheta <<
'\t' << dset.inphi <<
'\t' <<
162 dset.intheta <<
'\t' << dset.ininvpt <<
'\t';
165 friend std::istream& operator >> (std::istream& in,
NeuroSet& dset)
169 std::getline(in, help,
'\t');
170 if (help.length() < 2) {
return in;}
171 dset.exp = std::stoi(help);
173 std::getline(in, help,
'\t');
174 dset.run = std::stoi(help);
176 std::getline(in, help,
'\t');
177 dset.subrun = std::stoi(help);
179 std::getline(in, help,
'\t');
180 dset.evt = std::stoi(help);
182 std::getline(in, help,
'\t');
183 dset.track = std::stoi(help);
185 std::getline(in, help,
'\t');
186 dset.ntracks = std::stoi(help);
188 std::getline(in, help,
'\t');
189 dset.expert = std::stoul(help);
191 std::string insize =
"";
192 std::string outsize =
"";
193 std::getline(in, insize,
'\t');
194 if (std::stoul(insize) != inLen) {
195 B2ERROR(
"Input and output format of neurotrigger training data does not match!");
197 std::getline(in, outsize,
'\t');
198 if (std::stoul(outsize) != outLen) {
199 B2ERROR(
"Input and output format of neurotrigger training data does not match!");
201 for (
unsigned i = 0; i < inLen; ++i) {
203 std::getline(in, help,
'\t');
205 dset.input[i] = std::stof(help);
206 }
catch (
const std::out_of_range& oor) {
207 B2WARNING(
"out of range error: " << help <<
" is not in float range!");
211 for (
unsigned i = 0; i < outLen; ++i) {
213 std::getline(in, help,
'\t');
215 dset.target[i] = std::stof(help);
216 }
catch (
const std::out_of_range& oor) {
217 B2WARNING(
"out of range error: " << help <<
" is not in float range!");
222 std::getline(in, help,
'\t');
223 dset.nnscalez = std::stof(help);
225 std::getline(in, help,
'\t');
226 dset.nnrawz = std::stoi(help);
228 std::getline(in, help,
'\t');
229 dset.nnscaletheta = std::stof(help);
231 std::getline(in, help,
'\t');
232 dset.nnrawtheta = std::stoi(help);
234 std::getline(in, help,
'\t');
235 dset.inphi = std::stof(help);
237 std::getline(in, help,
'\t');
238 dset.intheta = std::stof(help);
240 std::getline(in, help,
'\t');
241 dset.ininvpt = std::stof(help);
255 std::vector<unsigned short> counters;
256 counters.assign(nWires, 0);
262 void addHit(
unsigned iSL,
int iTS);
265 template<
unsigned inLen,
unsigned outLen>
266 void addSample(
const NeuroSet<inLen, outLen>& dsample)
268 std::vector<float> in(dsample.input, dsample.input +
sizeof dsample.input /
sizeof dsample.input[0]);
270 std::vector<float> out(dsample.target, dsample.target +
sizeof dsample.target /
sizeof dsample.target[0]);
273 m_runList.push_back(dsample.run);
274 m_subRunList.push_back(dsample.subrun);
276 m_trackList.push_back(dsample.track);
281 void addSample(
const std::vector<float>& input,
const std::vector<float>& target,
const int& expnumber,
const int& runnumber,
282 const int& subrunnumber,
const int& eventnumber,
const int& tracknumber)
287 m_runList.push_back(runnumber);
288 m_subRunList.push_back(subrunnumber);
290 m_trackList.push_back(tracknumber);
305 const std::vector<int>& getevtList()
const {
return getEvtList(); }
306 const std::vector<int>& getEvtList()
const {
return m_evtList; }
307 const std::vector<int>& getExpList()
const {
return m_expList; }
308 const std::vector<int>& getRunList()
const {
return m_runList; }
309 const std::vector<int>& getSubRunList()
const {
return m_subRunList; }
310 const std::vector<int>& getTrackList()
const {
return m_trackList; }
311 const int& getevtnum(
unsigned i)
const {
return m_evtList[i]; }
324 std::vector<int> m_runList;
325 std::vector<int> m_subRunList;
328 std::vector<int> m_trackList;
Struct for training data of a single MLP for the neuro trigger.
std::vector< std::vector< float > > m_inputSamples
list of input vectors for network training.
std::vector< int > m_evtList
List for debug purposes to store the event number for every entry of input/target vector.
const std::vector< float > & getInput(unsigned i) const
get input vector of sample i
const std::vector< float > & getTarget(unsigned i) const
get target value of sample i
short getTrackCounter() const
get track counter
std::vector< std::vector< float > > m_targetSamples
list of target values for network training.
ClassDef(CDCTriggerMLPData, 3)
Needed to make the ROOT object storable.
short m_trackCounter
number of tracks used for the hit counter.
void addHit(unsigned iSL, int iTS)
increase counter for super layer and track segment number in super layer.
std::vector< std::vector< unsigned short > > m_hitCounters
hit counter of active track segment IDs, used to determine the relevant id range for an MLP.
void countTrack()
increase track counter
unsigned short getHitCounter(unsigned iSL, int iTS) const
get hit counter for super layer and track segment number is super layer.
unsigned nSamples() const
get number of samples (same for input and target)
void addSample(const std::vector< float > &input, const std::vector< float > &target, const int &expnumber, const int &runnumber, const int &subrunnumber, const int &eventnumber, const int &tracknumber)
add a pair of input and target
void addCounters(unsigned nWires)
add hit counters for a layer with nWires
CDCTriggerMLPData()
default constructor.
~CDCTriggerMLPData()
destructor, empty because we don't allocate memory anywhere.
std::vector< int > m_expList
Vectors for experiment, run, event and tracknumber.
Abstract base class for different kinds of events.
Struct to keep one set of training data for either training, validation or testing.