SQLamarr
The stand-alone ultra-fast simulation option for the LHCb experiment
LbParticleId.cpp
1 #include "SQLamarr/BlockLib/LbParticleId.h"
2 
3 namespace SQLamarr
4 {
5  namespace BlockLib
6  {
7  namespace LbParticleId
8  {
9  //========================================================================
10  // make
11  //========================================================================
12  std::unique_ptr<GenerativePlugin> make(
13  SQLite3DB& db,
14  const std::string& library,
15  const std::string& function_name,
16  const std::string& output_table,
17  const std::string& particle_table,
18  const std::string& track_table,
19  const int abspid
20  )
21  {
22  const char q[] = R"(
23  SELECT
24  p.mcparticle_id AS mcparticle_id,
25  norm2(p.px, p.py, p.pz) AS p,
26  pseudorapidity(p.px, p.py, p.pz) AS eta,
27  random_normal() * 10 + 100 as nTracks,
28  propagation_charge(p.pid) AS track_charge,
29  0 AS isMuon
30  FROM %s AS p
31  INNER JOIN %s AS recguess
32  ON p.mcparticle_id = recguess.mcparticle_id
33  WHERE
34  recguess.track_type == 3
35  AND
36  abs(p.pid) == %d;
37  )";
38 
39  char buffer[1024];
40  sprintf(buffer, q, particle_table.c_str(), track_table.c_str(), abspid);
41 
42  return std::unique_ptr<GenerativePlugin>(
43  new GenerativePlugin (db,
44  library,
45  function_name,
46  buffer,
47  output_table,
48  get_column_names(false, true),
49  64,
50  get_column_names(true, false)
51  )
52  );
53  }
54 
55 
56  //========================================================================
57  // get_column_names
58  //========================================================================
59  std::vector<std::string> get_column_names (
60  bool include_indices,
61  bool include_outputs
62  )
63  {
64  std::vector<std::string> ret;
65 
66  std::vector<std::string> indices { "mc_particleid" };
67  std::vector<std::string> outputs {
68  // Rich
69  "RichDLLe", "RichDLLmu", "RichDLLK", "RichDLLp",
70  // Muon
71  "MuonMuLL", "MuonBkgLL",
72  // Global PID
73  "PIDe", "PIDK", "PIDp", "ProbNNe", "ProbNNpi", "ProbNNk", "ProbNNp",
74  // Global PID
75  "PIDmu", "ProbNNmu"
76  };
77 
78  if (include_indices)
79  ret.insert(ret.end(), indices.begin(), indices.end());
80 
81  if (include_outputs)
82  ret.insert(ret.end(), outputs.begin(), outputs.end());
83 
84  return ret;
85  }
86  }
87  }
88 }
Interface to dynamically linked generative parametrizations.
A database connection handler easying sharing the DB between C++ and Python.
Definition: db_functions.py:24
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.