11 #include <unordered_map>
14 #include "SQLamarr/HepMC2DataLoader.h"
15 #include "SQLamarr/PVFinder.h"
16 #include "SQLamarr/db_functions.h"
17 #include "SQLamarr/MCParticleSelector.h"
18 #include "SQLamarr/PVReconstruction.h"
19 #include "SQLamarr/Plugin.h"
20 #include "SQLamarr/GenerativePlugin.h"
21 #include "SQLamarr/GlobalPRNG.h"
22 #include "SQLamarr/TemporaryTable.h"
23 #include "SQLamarr/BlockLib/LbParticleId.h"
24 #include "SQLamarr/CleanEventStore.h"
35 std::vector<std::string> globVector(
const std::string& pattern);
38 int main(
int argc,
char* argv[])
40 std::string path{
"../temporary_data/HepMC2-ascii/DSt_Pi.hepmc2/evt0.mc2"};
43 std::vector<std::string> file_paths = globVector(path);
63 size_t runNumber = 456;
65 for (std::string& file_path: file_paths)
67 loader.load(file_path, runNumber, evtNumber++);
78 "../temporary_data/PrimaryVertex/PrimaryVertexSmearing.db",
79 "PVSmearing",
"2016_pp_MagUp")
84 "../temporary_data/models/lhcb.trk.2016MU.so",
92 log10(norm2(p.px, p.py, p.pz)) AS mc_log10_p,
95 pseudorapidity(p.px, p.py, p.pz) AS mc_eta,
96 azimuthal(p.px, p.py, p.pz) AS mc_phi,
97 abs(p.pid) == 11 AS mc_is_e,
98 abs(p.pid) == 13 AS mc_is_mu,
100 abs(p.pid) == 211 OR abs(p.pid) == 321 OR abs(p.pid) == 2212
102 propagation_charge(p.pid) AS mc_charge
103 FROM MCParticles AS p
104 INNER JOIN MCVertices AS ov ON p.production_vertex = ov.mcvertex_id
108 propagation_charge(p.pid) <> 0.
110 "tmp_acceptance_out", {
"acceptance"}, {
"mcparticle_id"}
113 acceptance_model.execute();
117 "../temporary_data/models/lhcb.trk.2016MU.so",
125 log10(norm2(p.px, p.py, p.pz)) AS mc_log10_p,
128 pseudorapidity(p.px, p.py, p.pz) AS mc_eta,
129 azimuthal(p.px, p.py, p.pz) AS mc_phi,
130 abs(p.pid) == 11 AS mc_is_e,
131 abs(p.pid) == 13 AS mc_is_mu,
133 abs(p.pid) == 211 OR abs(p.pid) == 321 OR abs(p.pid) == 2212
135 propagation_charge(p.pid) AS mc_charge
136 FROM MCParticles AS p
137 INNER JOIN MCVertices AS ov ON p.production_vertex = ov.mcvertex_id
141 propagation_charge(p.pid) <> 0.
143 "tmp_efficiency_out",
144 {
"not_recoed",
"long",
"upstream",
"downstream"},
148 efficiency_model.execute();
154 "mc_x",
"mc_y",
"mc_z",
"mc_log10_p",
"mc_tx",
"mc_ty",
"mc_eta",
"mc_phi",
"mc_is_e",
"mc_is_mu",
"mc_is_h",
"mc_charge",
155 "not_recoed",
"long",
"upstream",
"downstream"
159 p.mcparticle_id AS mcparticle_id,
163 log10(norm2(p.px, p.py, p.pz)) AS mc_log10_p,
166 pseudorapidity(p.px, p.py, p.pz) AS mc_eta,
167 azimuthal(p.px, p.py, p.pz) AS mc_phi,
168 abs(p.pid) == 11 AS mc_is_e,
169 abs(p.pid) == 13 AS mc_is_mu,
171 abs(p.pid) == 211 OR abs(p.pid) == 321 OR abs(p.pid) == 2212
173 propagation_charge(p.pid) AS mc_charge,
175 out.not_recoed AS not_recoed,
177 out.upstream AS upstream,
178 out.downstream AS downstream
179 FROM MCParticles AS p
180 INNER JOIN MCVertices AS ov ON p.production_vertex = ov.mcvertex_id
181 INNER JOIN tmp_efficiency_out AS out ON out.mcparticle_id == p.mcparticle_id
185 propagation_charge(p.pid) <> 0.
195 "tmp_particles_recoed_as", {
"mcparticle_id",
"track_type"},
198 random_category(not_recoed, 0, 0, long, upstream) AS track_type
199 FROM tmp_efficiency_out AS eff
200 INNER JOIN tmp_acceptance_out AS acc
201 ON eff.mcparticle_id = acc.mcparticle_id
202 WHERE random_category(1 - acc.acceptance, acc.acceptance) == 1
207 assign_track_cat.execute();
210 "tmp_closest_to_beam", {
"mcparticle_id",
"x",
"y",
"z"},
214 z_closest_to_beam(ov.x, ov.y, ov.z, p.px/p.pz, p.py/p.pz) AS z,
220 FROM MCParticles AS p
221 INNER JOIN MCVertices AS ov
222 ON p.production_vertex = ov.mcvertex_id
226 x0 + (z - z0)*tx AS x,
227 y0 + (z - z0)*ty AS y,
233 propagate_to_ctb.execute();
237 "../temporary_data/models/lhcb.trk.2016MU.so",
247 log10(norm2(p.px, p.py, p.pz)) AS mc_log10_p,
248 abs(p.pid) == 11 AS mc_is_e,
249 abs(p.pid) == 13 AS mc_is_mu,
250 (abs(p.pid) = 211 OR abs(p.pid) = 321 OR abs(p.pid) = 2212) AS is_h,
251 (recguess.track_type == 3) AS is_long,
252 (recguess.track_type == 4) AS is_upstream,
253 (recguess.track_type == 5) AS is_downstream
254 FROM MCParticles AS p
255 INNER JOIN MCVertices AS ov ON p.production_vertex = ov.mcvertex_id
256 INNER JOIN tmp_particles_recoed_as AS recguess
257 ON p.mcparticle_id = recguess.mcparticle_id
258 INNER JOIN tmp_closest_to_beam AS ctb
259 ON p.mcparticle_id = ctb.mcparticle_id
261 recguess.track_type BETWEEN 3 AND 5;
263 "tmp_resolution_out",
264 {
"dx",
"dy",
"dz",
"dtx",
"dty",
"dp",
265 "chi2PerDoF",
"nDoF_f",
"ghostProb"},
270 resolution_model.execute();
274 "../temporary_data/models/lhcb.trk.2016MU.so",
284 log10(norm2(p.px, p.py, p.pz)) AS mc_log10_p,
285 tmpres.chi2PerDoF AS chi2PerDoF,
286 tmpres.nDoF_f AS nDoF_f,
287 tmpres.ghostProb AS ghostProb,
288 abs(p.pid) == 11 AS mc_is_e,
289 abs(p.pid) == 13 AS mc_is_mu,
290 (abs(p.pid) = 211 OR abs(p.pid) = 321 OR abs(p.pid) = 2212) AS is_h,
291 (recguess.track_type == 3) AS is_long,
292 (recguess.track_type == 4) AS is_upstream,
293 (recguess.track_type == 5) AS is_downstream
294 FROM MCParticles AS p
295 INNER JOIN MCVertices AS ov ON p.production_vertex = ov.mcvertex_id
296 INNER JOIN tmp_particles_recoed_as AS recguess
297 ON p.mcparticle_id = recguess.mcparticle_id
298 INNER JOIN tmp_resolution_out AS tmpres
299 ON p.mcparticle_id = tmpres.mcparticle_id
300 INNER JOIN tmp_closest_to_beam AS ctb
301 ON p.mcparticle_id = ctb.mcparticle_id
303 recguess.track_type >= 3 AND recguess.track_type <= 5
305 "tmp_covariance_out",
307 "log_cov_ClosestToBeam_0_0",
308 "log_cov_ClosestToBeam_1_1",
309 "log_cov_ClosestToBeam_2_2",
310 "log_cov_ClosestToBeam_3_3",
311 "log_cov_ClosestToBeam_4_4",
312 "corr_ClosestToBeam_0_1",
313 "corr_ClosestToBeam_0_2",
314 "corr_ClosestToBeam_1_2",
315 "corr_ClosestToBeam_0_3",
316 "corr_ClosestToBeam_1_3",
317 "corr_ClosestToBeam_2_3",
318 "corr_ClosestToBeam_0_4",
319 "corr_ClosestToBeam_1_4",
320 "corr_ClosestToBeam_2_4",
321 "corr_ClosestToBeam_3_4"
327 covariance_model.execute();
331 {
"cov00",
"cov01",
"cov02",
"cov03",
"cov04",
332 "cov11",
"cov12",
"cov13",
"cov14",
333 "cov22",
"cov23",
"cov24",
340 sqrt(exp(log_cov_ClosestToBeam_0_0)) AS sig0,
341 sqrt(exp(log_cov_ClosestToBeam_1_1)) AS sig1,
342 sqrt(exp(log_cov_ClosestToBeam_2_2)) AS sig2,
343 sqrt(exp(log_cov_ClosestToBeam_3_3)) AS sig3,
344 sqrt(exp(log_cov_ClosestToBeam_4_4)) AS sig4,
345 corr_ClosestToBeam_0_1 AS cor01,
346 corr_ClosestToBeam_0_2 AS cor02,
347 corr_ClosestToBeam_1_2 AS cor12,
348 corr_ClosestToBeam_0_3 AS cor03,
349 corr_ClosestToBeam_1_3 AS cor13,
350 corr_ClosestToBeam_2_3 AS cor23,
351 corr_ClosestToBeam_0_4 AS cor04,
352 corr_ClosestToBeam_1_4 AS cor14,
353 corr_ClosestToBeam_2_4 AS cor24,
354 corr_ClosestToBeam_3_4 AS cor34
355 FROM tmp_covariance_out
376 covariance.execute();
378 const std::string pidlib =
"../temporary_data/models/lhcb.pid.2016MU-sim.so";
379 const std::string particle_table =
"MCParticles";
380 const std::string track_table =
"tmp_particles_recoed_as";
382 std::vector<std::unique_ptr<SQLamarr::GenerativePlugin>> pid_algos;
384 particle_table, track_table, 211));
386 particle_table, track_table, 321));
388 particle_table, track_table, 2212));
390 particle_table, track_table, 13));
391 for (
auto& pid_algo: pid_algos)
398 "SELECT * FROM tmp_pid_pi",
399 "SELECT * FROM tmp_pid_k",
400 "SELECT * FROM tmp_pid_mu",
401 "SELECT * FROM tmp_pid_p"
405 concat_pid.execute();
412 std::cout <<
SQLamarr::dump_table(db,
"SELECT COUNT(*) as n_files FROM DataSources") << std::endl;
415 std::cout <<
"GenVertices\n" <<
SQLamarr::dump_table(db,
"SELECT * FROM GenVertices LIMIT 10") << std::endl;
416 std::cout <<
"GenParticles\n" <<
SQLamarr::dump_table(db,
"SELECT * FROM GenParticles") << std::endl;
420 "SELECT * FROM MCParticles") << std::endl;
467 std::vector<std::string> globVector(
const std::string& pattern)
469 std::vector<std::string> files;
472 glob(pattern.c_str(),GLOB_TILDE,NULL,&glob_result);
474 for(
unsigned int i = 0; i < glob_result.gl_pathc; ++i)
475 files.push_back(
string(glob_result.gl_pathv[i]));
477 globfree(&glob_result);
static SmearingParametrization load_parametrization(const std::string file_path, const std::string table_name, const std::string condition)
Instanciate a SmearingParametrization object from an SQLite file.
static PRNG * get_or_create(const sqlite3_context *db, uint64_t seed=no_seed)
Return a pointer to an initialized generator.
A database connection handler easying sharing the DB between C++ and Python.
std::unique_ptr< GenerativePlugin > make(SQLite3DB &db, const std::string &library, const std::string &function_name, const std::string &output_table, const std::string &particle_table, const std::string &track_table, const int abspid)
Initialize a GenerativePlugin specialized for PID pipelines.
std::vector< std::string > get_column_names(bool include_indices=true, bool include_outputs=true)
Provide a vector of the names of the columns of the output table.
SQLite3DB make_database(std::string filename, int flags=SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI, std::string init=std::string())
Initialize the database.
std::string dump_table(SQLite3DB &db, const std::string &query)
Dump the result of a query to a string.