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
44 addParam(
"hitCollectionName", m_hitCollectionName,
45 "Name of the input StoreArray of CDCTriggerSegmentHits.",
48 "Name of the StoreArray holding the 2D input tracks.",
49 std::string(
"TRGCDC2DFinderTracks"));
51 "If true, use RecoTracks as targets instead of MCParticles.",
54 "Name of the MCParticle/RecoTrack collection used as target values.",
55 std::string(
"MCParticles"));
57 "Name of the config file, where all the parameters and the IDHist configuration is written.",
60 "Name of the config file, where all the parameters and the IDHist configuration is read in from.",
63 "amount of events used for creating the IDHist. If it is 0, "
64 "all Events are used.",
82 B2ERROR(
"Configuration file is missing! Make sure to give the configuration file as a parameter. \
83 An example file neuroconfig_example.conf has been saved.");
87 for (
unsigned iMLP = 0; iMLP <
m_NeuroTrigger.nSectors(); ++iMLP) {
96 for (
int iSL = 0; iSL < 9; ++iSL) {
100 layerId += (iSL > 0 ? 6 : 7);
118 B2ERROR(
"No networks defined, please make sure to have a proper configuration file! Example file will be created here: ./neurotrigger_default.conf");
129 for (
int itrack = 0; itrack <
m_tracks.getEntries(); ++itrack) {
134 if (targetvector[4] == 0) {
139 float thetaTarget = targetvector[2];
140 float zTarget = targetvector[3];
147 float phi0 =
m_tracks[itrack]->getPhi0();
148 float invpt =
m_tracks[itrack]->getKappa(1.5);
149 float theta = atan2(1.,
m_tracks[itrack]->getCotTheta());
150 std::vector<int> sectors =
m_NeuroTrigger.selectMLPsTrain(phi0, invpt, theta);
151 if (sectors.size() == 0)
continue;
153 std::vector<float> targetRaw = {};
155 targetRaw.push_back(zTarget);
157 targetRaw.push_back(thetaTarget);
158 for (
unsigned i = 0; i < sectors.size(); ++i) {
159 int isector = sectors[i];
160 std::vector<float> target =
m_NeuroTrigger[isector].scaleTarget(targetRaw);
162 bool outOfRange =
false;
163 for (
unsigned itarget = 0; itarget < target.size(); ++itarget) {
164 if (fabs(target[itarget]) > 1.) {
166 target[itarget] /= fabs(target[itarget]);
205 B2INFO(
"Training sample preparation for NeuroTrigger finished, stopping event loop.");
208 eventMetaData->setEndOfData();
221 B2WARNING(
"ID ranges are already set in the config file, they will be updated now!");
223 B2ERROR(
"The ID ranges in the config file are already locked and cannot be updated!");
235 std::vector<NNTParam<float>> expertline;
236 expertline.push_back(
float(isector));
237 expertline.back().lock();
238 for (
auto x : hset.relID) {
239 expertline.push_back(x);
240 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.