9#include <trg/klm/modules/klmtrigger/KLMTriggerModule.h>
12#include "trg/klm/modules/klmtrigger/KLMAxis.h"
14#include "trg/klm/modules/klmtrigger/KLM_Trig.h"
15#include <trg/klm/modules/klmtrigger/klm_trig_linear_fit.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>
31#include <trg/klm/dataobjects/KLMTriggerHit.h>
32#include <trg/klm/dataobjects/KLMTriggerTrack.h>
33#include <trg/klm/dataobjects/KLMTrgSummary.h>
34#include <trg/klm/dataobjects/KLMTrgFittedTrack.h>
41#include <trg/klm/dbobjects/KLMTriggerParameters.h>
42#include <framework/database/DBObjPtr.h>
45#include <unordered_map>
67using namespace Belle2::KLM_TRG_definitions;
72const std::string m_klmtrackCollectionName =
"TRGKLMTracks";
73const std::string m_klmhitCollectionName =
"TRGKLMHits";
91vector<string> split(
const string& str,
const string& delim)
93 vector<string> tokens;
94 size_t prev = 0, pos = 0;
96 pos = str.find(delim, prev);
97 if (pos == string::npos) pos = str.length();
98 string token = str.substr(prev, pos - prev);
99 if (!token.empty()) tokens.push_back(token);
100 prev = pos + delim.length();
101 }
while (pos < str.length() && prev < str.length());
105std::vector<int> layer_string_list_to_integer_range(
const std::string& instr)
107 std::vector<int> ret;
108 auto str_spl = split(instr,
":");
110 int start = std::stoi(str_spl[0]);
111 int stop = std::stoi(str_spl[1]);
112 for (
int i = start; i < stop ; ++i) {
118std::vector<int> layer_string_list_to_integer_list(
const std::string& instr)
120 std::vector<int> ret;
121 auto str_spl = split(instr,
",");
123 for (
const auto& e : str_spl) {
124 ret.push_back(std::stoi(e));
129std::vector<int> layer_string_list_to_integer(
const std::string& instr)
131 if (instr.find(
":") != string::npos) {
132 return layer_string_list_to_integer_range(instr);
134 if (instr.find(
",") != string::npos) {
135 return layer_string_list_to_integer_list(instr);
137 std::vector<int> ret;
140KLMTriggerModule::KLMTriggerModule() :
Module()
142 setDescription(
"KLM trigger simulation");
143 setPropertyFlags(c_ParallelProcessingCertified);
147 addParam(
"y_cutoff", y_cutoff,
"", 500);
148 addParam(
"intercept_cutoff", m_intercept_cutoff,
"", 500);
150 std::string dump_Path;
151 addParam(
"CSV_Dump_Path", dump_Path,
"", dump_Path);
153 if (!dump_Path.empty()) {
154 get_IO_csv_handle().dump_path = dump_Path;
155 get_IO_csv_handle().do_dump =
true;
212 B2DEBUG(100,
"KLMTrigger: Experiment " << evtMetaData->getExperiment() <<
", run " << evtMetaData->getRun());
214 B2FATAL(
"KLM trigger parameters are not available.");
219 for (
auto e : m_layerUsed) {
220 B2DEBUG(20,
"KLMTrigger: layer " << e <<
" used.");
222 }
catch (
const std::exception& e) {
223 B2FATAL(
"Something went wrong when parsing the 'm_whichLayers' string"
225 <<
LogVar(
"exception", e.what()));
228 m_klmtrg_layer_counter = std::make_shared< Belle2::klmtrg_layer_counter_t>();
229 m_klm_trig_linear_fit = std::make_shared< Belle2::klm_trig_linear_fit_t>();
230 m_klm_trig_linear_fit->set_y_cutoff(y_cutoff);
231 m_klm_trig_linear_fit->set_intercept_cutoff(m_intercept_cutoff);
236 for (
auto e : m_layerUsed) {
237 m_klmtrg_layer_counter->add_layersUsed(e);
254 m_klm_trig_linear_fit->add_geometry(e);
260 }
catch (
const std::exception& er) {
281template <
typename T1,
typename T2>
282auto push_linear_fit_to_KLMTrgFittedTrack(T1&& linear_fited, T2& KLMTrgFittedTrack_)
284 for (
const auto& e : linear_fited) {
286 auto FittedTrack = KLMTrgFittedTrack_.appendNew();
287 FittedTrack->setSlopeXY(e.slopeXY) ;
288 FittedTrack->setInterceptXY(e.interceptXY);
289 FittedTrack->setIpXY(e.ipXY) ;
290 FittedTrack->setPlane(e.plane);
291 FittedTrack->setChisqXY(e.chisqXY);
292 FittedTrack->setSubdetector(e.subdetector);
293 FittedTrack->setSection(e.section);
294 FittedTrack->setSector(e.sector);
295 FittedTrack->setNhits(e.Nhits);
296 FittedTrack->setTrack_id(e.track_id);
319 get_IO_csv_handle().event_nr = m_event_nr;
321 auto hits = nt::algorithms::fill_vector(klmDigits.
getEntries(),
323 const auto& digit = klmDigits[Index];
326 dummy.event_nr = m_event_nr;
327 dummy.subdetector = digit->getSubdetector();
328 dummy.section = digit->getSection();
329 dummy.sector = digit->getSector();
330 dummy.plane = digit->getPlane();
331 dummy.layer = digit->getLayer();
332 dummy.strip = digit->getStrip();
337 m_klmtrg_layer_counter->run(hits);
338 m_klm_trig_linear_fit->run(hits);
341 push_linear_fit_to_KLMTrgFittedTrack(m_klm_trig_linear_fit->get_result(), KLMTrgFittedTrack_);
410 }
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.
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 wether the array was registered.
int getEntries() const
Get the number of objects in the array.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
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.