9#include <trg/klm/modules/klmtrigger/KLMTriggerModule.h>
12#include "trg/klm/modules/klmtrigger/KLMAxis.h"
14#include "trg/klm/modules/klmtrigger/klmtrgLayerCounter.h"
15#include <trg/klm/modules/klmtrigger/klmtrgLinearFit.h>
17#include <trg/klm/modules/klmtrigger/IO_csv.h>
20#include <klm/bklm/geometry/GeometryPar.h>
22#include <framework/datastore/StoreArray.h>
23#include <framework/datastore/StoreObjPtr.h>
26#include <framework/dataobjects/EventMetaData.h>
29#include <klm/dataobjects/KLMDigit.h>
32#include <trg/klm/dataobjects/KLMTrgSummary.h>
33#include <trg/klm/dataobjects/KLMTrgFittedTrack.h>
40#include <trg/klm/dbobjects/KLMTriggerParameters.h>
41#include <framework/database/DBObjPtr.h>
44#include <unordered_map>
66using namespace Belle2::KLM_TRG_definitions;
71const std::string m_klmtrackCollectionName =
"TRGKLMTracks";
72const std::string m_klmhitCollectionName =
"TRGKLMHits";
90vector<string> split(
const string& str,
const string& delim)
92 vector<string> tokens;
93 size_t prev = 0, pos = 0;
95 pos = str.find(delim, prev);
96 if (pos == string::npos) pos = str.length();
97 string token = str.substr(prev, pos - prev);
98 if (!token.empty()) tokens.push_back(token);
99 prev = pos + delim.length();
100 }
while (pos < str.length() && prev < str.length());
104std::vector<int> layer_string_list_to_integer_range(
const std::string& instr)
106 std::vector<int> ret;
107 auto str_spl = split(instr,
":");
109 int start = std::stoi(str_spl[0]);
110 int stop = std::stoi(str_spl[1]);
111 for (
int i = start; i < stop ; ++i) {
117std::vector<int> layer_string_list_to_integer_list(
const std::string& instr)
119 std::vector<int> ret;
120 auto str_spl = split(instr,
",");
122 for (
const auto& e : str_spl) {
123 ret.push_back(std::stoi(e));
128std::vector<int> layer_string_list_to_integer(
const std::string& instr)
130 if (instr.find(
":") != string::npos) {
131 return layer_string_list_to_integer_range(instr);
133 if (instr.find(
",") != string::npos) {
134 return layer_string_list_to_integer_list(instr);
136 std::vector<int> ret;
139KLMTriggerModule::KLMTriggerModule() :
Module()
141 setDescription(
"KLM trigger simulation");
142 setPropertyFlags(c_ParallelProcessingCertified);
144 addParam(
"y_cutoff", y_cutoff,
"", 500);
145 addParam(
"intercept_cutoff", m_intercept_cutoff,
"", 500);
146 addParam(
"CSV_Dump_Path", m_dump_Path,
"", m_dump_Path);
182 get_IO_csv_handle().do_dump =
true;
191 B2DEBUG(100,
"KLMTrigger: Experiment " << evtMetaData->getExperiment() <<
", run " << evtMetaData->getRun());
193 B2FATAL(
"KLM trigger parameters are not available.");
198 for (
auto e : m_layerUsed) {
199 B2DEBUG(20,
"KLMTrigger: layer " << e <<
" used.");
201 }
catch (
const std::exception& e) {
202 B2FATAL(
"Something went wrong when parsing the 'm_whichLayers' string"
204 <<
LogVar(
"exception", e.what()));
207 m_klmtrg_layer_counter = std::make_shared< Belle2::klmtrgLayerCounter>();
208 m_klm_trig_linear_fit = std::make_shared< Belle2::klmtrgLinearFit>();
209 m_klm_trig_linear_fit->set_y_cutoff(y_cutoff);
210 m_klm_trig_linear_fit->set_intercept_cutoff(m_intercept_cutoff);
215 for (
auto e : m_layerUsed) {
216 m_klmtrg_layer_counter->add_layersUsed(e);
233 m_klm_trig_linear_fit->add_geometry(e);
239 }
catch (
const std::exception& er) {
260template <
typename T1,
typename T2>
261auto push_linear_fit_to_KLMTrgFittedTrack(T1&& linear_fited, T2& KLMTrgFittedTrack_)
263 for (
const auto& e : linear_fited) {
265 auto FittedTrack = KLMTrgFittedTrack_.appendNew();
266 FittedTrack->setSlopeXY(e.slopeXY) ;
267 FittedTrack->setInterceptXY(e.interceptXY);
268 FittedTrack->setIpXY(e.ipXY) ;
269 FittedTrack->setPlane(e.plane);
270 FittedTrack->setChisqXY(e.chisqXY);
271 FittedTrack->setSubdetector(e.subdetector);
272 FittedTrack->setSection(e.section);
273 FittedTrack->setSector(e.sector);
274 FittedTrack->setNhits(e.Nhits);
275 FittedTrack->setTrack_id(e.track_id);
284template <
typename T1,
typename T2,
typename T3>
285auto push_KLMSummary(T1&& m_klmtrg_layer_counter, T2&& m_klm_trig_linear_fit, T3&
KLMTrgSummary)
369 get_IO_csv_handle().event_nr = m_event_nr;
371 auto hits = nt::algorithms::fill_vector(klmDigits.
getEntries(),
373 const auto& digit = klmDigits[Index];
376 dummy.event_nr = m_event_nr;
377 dummy.subdetector = digit->getSubdetector();
378 dummy.section = digit->getSection();
379 dummy.sector = digit->getSector() - 1;
380 dummy.plane = digit->getPlane();
381 dummy.layer = digit->getLayer();
382 dummy.strip = digit->getStrip();
387 m_klmtrg_layer_counter->run(hits);
388 m_klm_trig_linear_fit->run(hits);
391 push_linear_fit_to_KLMTrgFittedTrack(m_klm_trig_linear_fit->get_result(), KLMTrgFittedTrack_);
393 push_KLMSummary(m_klmtrg_layer_counter, m_klm_trig_linear_fit,
KLMTrgSummary);
395 }
catch (
const std::exception& er) {
@ c_ForwardSection
Forward.
@ c_BackwardSection
Backward.
Class for accessing objects in the database.
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
@ c_ForwardSection
Forward.
@ c_BackwardSection
Backward.
Store KLM TRG track information as a ROOT object.
virtual void initialize() override
Initialize the Module.
virtual void event() override
This method is the core of the module.
virtual void endRun() override
This method is called if the current run ends.
std::string m_dump_Path
Name of the file for debugging output.
virtual void beginRun() override
Called when entering a new run.
DBObject containing parameters used in KLMTrigger module.
int32_t getNLayers() const
Get the number of layers used in the trigger logic.
std::string getWhichLayers() const
Get the pattern of layers used in the trigger logic.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
bool isValid() const
Check whether the array was registered.
int getEntries() const
Get the number of objects in the array.
Type-safe access to single objects in the data store.
Class to store variables with their name which were sent to the logging service.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.