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);
145 addParam(
"y_cutoff", y_cutoff,
"", 500);
146 addParam(
"intercept_cutoff", m_intercept_cutoff,
"", 500);
147 addParam(
"CSV_Dump_Path", m_dump_Path,
"", m_dump_Path);
196 get_IO_csv_handle().do_dump =
true;
205 B2DEBUG(100,
"KLMTrigger: Experiment " << evtMetaData->getExperiment() <<
", run " << evtMetaData->getRun());
207 B2FATAL(
"KLM trigger parameters are not available.");
212 for (
auto e : m_layerUsed) {
213 B2DEBUG(20,
"KLMTrigger: layer " << e <<
" used.");
215 }
catch (
const std::exception& e) {
216 B2FATAL(
"Something went wrong when parsing the 'm_whichLayers' string"
218 <<
LogVar(
"exception", e.what()));
221 m_klmtrg_layer_counter = std::make_shared< Belle2::klmtrg_layer_counter_t>();
222 m_klm_trig_linear_fit = std::make_shared< Belle2::klm_trig_linear_fit_t>();
223 m_klm_trig_linear_fit->set_y_cutoff(y_cutoff);
224 m_klm_trig_linear_fit->set_intercept_cutoff(m_intercept_cutoff);
229 for (
auto e : m_layerUsed) {
230 m_klmtrg_layer_counter->add_layersUsed(e);
247 m_klm_trig_linear_fit->add_geometry(e);
253 }
catch (
const std::exception& er) {
274template <
typename T1,
typename T2>
275auto push_linear_fit_to_KLMTrgFittedTrack(T1&& linear_fited, T2& KLMTrgFittedTrack_)
277 for (
const auto& e : linear_fited) {
279 auto FittedTrack = KLMTrgFittedTrack_.appendNew();
280 FittedTrack->setSlopeXY(e.slopeXY) ;
281 FittedTrack->setInterceptXY(e.interceptXY);
282 FittedTrack->setIpXY(e.ipXY) ;
283 FittedTrack->setPlane(e.plane);
284 FittedTrack->setChisqXY(e.chisqXY);
285 FittedTrack->setSubdetector(e.subdetector);
286 FittedTrack->setSection(e.section);
287 FittedTrack->setSector(e.sector);
288 FittedTrack->setNhits(e.Nhits);
289 FittedTrack->setTrack_id(e.track_id);
312 get_IO_csv_handle().event_nr = m_event_nr;
314 auto hits = nt::algorithms::fill_vector(klmDigits.
getEntries(),
316 const auto& digit = klmDigits[Index];
319 dummy.event_nr = m_event_nr;
320 dummy.subdetector = digit->getSubdetector();
321 dummy.section = digit->getSection();
322 dummy.sector = digit->getSector();
323 dummy.plane = digit->getPlane();
324 dummy.layer = digit->getLayer();
325 dummy.strip = digit->getStrip();
330 m_klmtrg_layer_counter->run(hits);
331 m_klm_trig_linear_fit->run(hits);
334 push_linear_fit_to_KLMTrgFittedTrack(m_klm_trig_linear_fit->get_result(), KLMTrgFittedTrack_);
403 }
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 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.