9#include <trg/klm/modules/klmtrigger/KLMTriggerModule.h>
10#include <trg/klm/modules/klmtrigger/KLMAxis.h>
11#include <trg/klm/modules/klmtrigger/klmtrgLayerCounter.h>
12#include <trg/klm/modules/klmtrigger/klmtrgLinearFit.h>
13#include <trg/klm/modules/klmtrigger/IO_csv.h>
14#include <trg/klm/dataobjects/KLMTrgSummary.h>
15#include <trg/klm/dataobjects/KLMTrgFittedTrack.h>
16#include <trg/klm/dbobjects/KLMTriggerParameters.h>
19#include <klm/bklm/geometry/GeometryPar.h>
20#include <klm/dataobjects/KLMDigit.h>
23#include <framework/datastore/StoreArray.h>
24#include <framework/datastore/StoreObjPtr.h>
25#include <framework/dataobjects/EventMetaData.h>
26#include <framework/database/DBObjPtr.h>
32using namespace Belle2::KLM_TRG_definitions;
49vector<string> split(
const string& str,
const string& delim)
51 vector<string> tokens;
52 size_t prev = 0, pos = 0;
54 pos = str.find(delim, prev);
55 if (pos == string::npos) pos = str.length();
56 string token = str.substr(prev, pos - prev);
57 if (!token.empty()) tokens.push_back(token);
58 prev = pos + delim.length();
59 }
while (pos < str.length() && prev < str.length());
63std::vector<int> layer_string_list_to_integer_range(
const std::string& instr)
66 auto str_spl = split(instr,
":");
68 int start = std::stoi(str_spl[0]);
69 int stop = std::stoi(str_spl[1]);
70 for (
int i = start; i < stop ; ++i) {
76std::vector<int> layer_string_list_to_integer_list(
const std::string& instr)
79 auto str_spl = split(instr,
",");
81 for (
const auto& e : str_spl) {
82 ret.push_back(std::stoi(e));
87std::vector<int> layer_string_list_to_integer(
const std::string& instr)
89 if (instr.find(
":") != string::npos) {
90 return layer_string_list_to_integer_range(instr);
92 if (instr.find(
",") != string::npos) {
93 return layer_string_list_to_integer_list(instr);
98KLMTriggerModule::KLMTriggerModule() :
Module()
100 setDescription(
"KLM trigger simulation");
101 setPropertyFlags(c_ParallelProcessingCertified);
103 addParam(
"y_cutoff", y_cutoff,
"", 500);
104 addParam(
"intercept_cutoff", m_intercept_cutoff,
"", 500);
105 addParam(
"CSV_Dump_Path", m_dump_Path,
"", m_dump_Path);
125 get_IO_csv_handle().do_dump =
true;
134 B2DEBUG(100,
"KLMTrigger: Experiment " << evtMetaData->getExperiment() <<
", run " << evtMetaData->getRun());
136 B2FATAL(
"KLM trigger parameters are not available.");
141 for (
auto e : m_layerUsed) {
142 B2DEBUG(20,
"KLMTrigger: layer " << e <<
" used.");
144 }
catch (
const std::exception& e) {
145 B2FATAL(
"Something went wrong when parsing the 'm_whichLayers' string"
147 <<
LogVar(
"exception", e.what()));
150 m_klmtrg_layer_counter = std::make_shared< Belle2::klmtrgLayerCounter>();
151 m_klm_trig_linear_fit = std::make_shared< Belle2::klmtrgLinearFit>();
152 m_klm_trig_linear_fit->set_y_cutoff(y_cutoff);
153 m_klm_trig_linear_fit->set_intercept_cutoff(m_intercept_cutoff);
158 for (
auto e : m_layerUsed) {
159 m_klmtrg_layer_counter->add_layersUsed(e);
162 Belle2::KLM_TRG_definitions::KLM_geo_fit_t e{};
174 m_klm_trig_linear_fit->add_geometry(e);
178 }
catch (
const std::exception& er) {
189template <
typename T1,
typename T2>
190auto push_linear_fit_to_KLMTrgFittedTrack(T1&& linear_fited, T2& KLMTrgFittedTrack_)
192 for (
const auto& e : linear_fited) {
194 auto FittedTrack = KLMTrgFittedTrack_.appendNew();
195 FittedTrack->setSlopeXY(e.slopeXY) ;
196 FittedTrack->setInterceptXY(e.interceptXY);
197 FittedTrack->setIpXY(e.ipXY) ;
198 FittedTrack->setPlane(e.plane);
199 FittedTrack->setChisqXY(e.chisqXY);
200 FittedTrack->setSubdetector(e.subdetector);
201 FittedTrack->setSection(e.section);
202 FittedTrack->setSector(e.sector);
203 FittedTrack->setNhits(e.Nhits);
204 FittedTrack->setTrack_id(e.track_id);
210template <
typename T1,
typename T2,
typename T3>
211auto push_KLMSummary(T1&& m_klmtrg_layer_counter, T2&& m_klm_trig_linear_fit, T3&
KLMTrgSummary)
286 get_IO_csv_handle().event_nr = m_event_nr;
287 Belle2::KLM_TRG_definitions::KLM_Digit_compact_t dummy {};
288 auto hits = nt::algorithms::fill_vector(klmDigits.
getEntries(),
290 const auto& digit = klmDigits[Index];
292 dummy.event_nr = m_event_nr;
293 dummy.subdetector = digit->getSubdetector();
294 dummy.section = digit->getSection();
295 dummy.sector = digit->getSector() - 1;
296 dummy.plane = digit->getPlane();
297 dummy.layer = digit->getLayer();
298 dummy.strip = digit->getStrip();
303 m_klmtrg_layer_counter->run(hits);
304 m_klm_trig_linear_fit->run(hits);
306 push_linear_fit_to_KLMTrgFittedTrack(m_klm_trig_linear_fit->get_result(), KLMTrgFittedTrack_);
308 push_KLMSummary(m_klmtrg_layer_counter, m_klm_trig_linear_fit,
KLMTrgSummary);
310 }
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.