9#include "trg/cdc/modules/neurotrigger/CDCTriggerNeuroIDHistModule.h"
10#include <framework/datastore/StoreArray.h>
11#include <mdst/dataobjects/MCParticle.h>
12#include <tracking/dataobjects/RecoTrack.h>
13#include <trg/cdc/dataobjects/CDCTriggerSegmentHit.h>
14#include <trg/cdc/dataobjects/CDCTriggerTrack.h>
15#include <framework/datastore/StoreObjPtr.h>
16#include <framework/dataobjects/EventMetaData.h>
17#include <framework/core/ModuleParam.templateDetails.h>
19#include <cdc/geometry/CDCGeometryPar.h>
20#include <framework/gearbox/Unit.h>
26#include "boost/iostreams/filter/gzip.hpp"
27#include "boost/iostreams/filtering_streambuf.hpp"
28#include "boost/iostreams/filtering_stream.hpp"
29#include "boost/multi_array.hpp"
30#define BOOST_MULTI_ARRAY_NO_GENERATORS
45 addParam(
"hitCollectionName", m_hitCollectionName,
46 "Name of the input StoreArray of CDCTriggerSegmentHits.",
49 "Name of the StoreArray holding the 2D input tracks.",
50 std::string(
"TRGCDC2DFinderTracks"));
52 "If true, use RecoTracks as targets instead of MCParticles.",
55 "Name of the MCParticle/RecoTrack collection used as target values.",
56 std::string(
"MCParticles"));
58 "Name of the config file, where all the parameters and the IDHist configuration is written.",
61 "Name of the config file, where all the parameters and the IDHist configuration is read in from.",
64 "amount of events used for creating the IDHist. If it is 0, "
65 "all Events are used.",
83 B2ERROR(
"Configuration file is missing! Make sure to give the configuration file as a parameter. \
84 An example file neuroconfig_example.conf has been saved.");
88 for (
unsigned iMLP = 0; iMLP <
m_NeuroTrigger.nSectors(); ++iMLP) {
97 for (
int iSL = 0; iSL < 9; ++iSL) {
101 layerId += (iSL > 0 ? 6 : 7);
119 B2ERROR(
"No networks defined, please make sure to have a proper configuration file! Example file will be created here: ./neurotrigger_default.conf");
130 for (
int itrack = 0; itrack <
m_tracks.getEntries(); ++itrack) {
135 if (targetvector[4] == 0) {
140 float thetaTarget = targetvector[2];
141 float zTarget = targetvector[3];
148 float phi0 =
m_tracks[itrack]->getPhi0();
149 float invpt =
m_tracks[itrack]->getKappa(1.5);
150 float theta = atan2(1.,
m_tracks[itrack]->getCotTheta());
151 std::vector<int> sectors =
m_NeuroTrigger.selectMLPsTrain(phi0, invpt, theta);
152 if (sectors.size() == 0)
continue;
154 std::vector<float> targetRaw = {};
156 targetRaw.push_back(zTarget);
158 targetRaw.push_back(thetaTarget);
159 for (
unsigned i = 0; i < sectors.size(); ++i) {
160 int isector = sectors[i];
161 std::vector<float> target =
m_NeuroTrigger[isector].scaleTarget(targetRaw);
163 bool outOfRange =
false;
164 for (
unsigned itarget = 0; itarget < target.size(); ++itarget) {
165 if (fabs(target[itarget]) > 1.) {
167 target[itarget] /= fabs(target[itarget]);
206 B2INFO(
"Training sample preparation for NeuroTrigger finished, stopping event loop.");
209 eventMetaData->setEndOfData();
222 B2WARNING(
"ID ranges are already set in the config file, they will be updated now!");
224 B2ERROR(
"The ID ranges in the config file are already locked and cannot be updated!");
236 std::vector<NNTParam<float>> expertline;
237 expertline.push_back(
float(isector));
238 expertline.back().lock();
239 for (
auto x : hset.relID) {
240 expertline.push_back(x);
241 expertline.back().lock();
Struct for training data of a single MLP for the neuro trigger.
bool m_trainOnRecoTracks
Switch between MCParticles or RecoTracks as targets.
NeuroTriggerParameters m_neuroParameters
Parameters for the NeuroTrigger.
NeuroTrigger m_NeuroTrigger
Instance of the NeuroTrigger.
std::string m_targetCollectionName
Name of the MCParticles/RecoTracks collection used as target values.
std::string m_inputCollectionName
name of the event time StoreObjPtr
StoreArray< CDCTriggerTrack > m_tracks
List of input tracks.
std::vector< CDCTriggerMLPData > m_trainSets_prepare
dataset for all idhist prepare data
int m_nPrepare
Number of samples to prepare input ranges.
std::string m_writeconfigFileName
name for the output configuration file which holds all the parameters and the idhist tables for each ...
std::string m_configFileName
name for the input configuration file which holds all the parameters and the idhist tables for each e...
Combination of several CDCHits to a track segment hit for the trigger.
The Class for CDC Geometry Parameters.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
A Class to store the Monte Carlo particle information.
void setDescription(const std::string &description)
Sets the description of the module.
This is the Reconstruction Event-Data Model Track.
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
Accessor to arrays stored in the data store.
Type-safe access to single objects in the data store.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
virtual void initialize() override
Initialize the module.
virtual void event() override
Called once for each event.
virtual void terminate() override
Do the training for all sectors.
CDCTriggerNeuroIDHistModule()
Constructor, for setting module description and parameters.
Abstract base class for different kinds of events.