hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
smearing-tool.cxx
Go to the documentation of this file.
1#include "TrackSmearingTool.h"
2#include "TrackerHit.h"
3#include "Track.h"
4
5#include "TTree.h"
6#include "TFile.h"
7
8#include <functional>
9
10void usage() {
11 std::cout << R"(
12 Run the smearing tool over known momentum values for testing.
13
14 smearing-tool {smearing_file.root} {output.root}
15
16 The output.root file will contain a TTree of the input data
17 and the resulting smeared momentum.
18)" << std::flush;
19}
20
21void smearing_test(
22 TDirectoryFile* output_d,
23 const std::string& smearing_file,
24 const std::string& name,
25 std::function<double()> unsmeared_sampler,
26 int trials = 100,
27 int min_nhits = 8,
28 int max_nhits = 12
29) {
30 TrackSmearingTool tst{smearing_file};
31 TrackerHit empty_hit;
33
34 track.setTrackParameters(
35 0. /* d0 */,
36 0. /* phi0 */,
37 1. /* omega */,
38 1. /* tan_lambda - choosing positive (top) */,
39 0. /* z0 */
40 );
41 for (int i{0}; i < min_nhits-1; i++) track.addHit(&empty_hit);
42
43 bool top = true;
44 int nhits = min_nhits;
45 double unsmeared_momentum = 1.;
46 double smeared_momentum = 1.;
47
48 output_d->cd();
49 TTree data{name.c_str(), name.c_str()};
50 data.Branch("top", &top);
51 data.Branch("nhits", &nhits);
52 data.Branch("unsmeared_momentum", &unsmeared_momentum);
53 data.Branch("smeared_momentum", &smeared_momentum);
54
55 for (nhits = min_nhits; nhits < max_nhits+1; nhits++) {
56 track.addHit(&empty_hit);
57 for (int _i{0}; _i < trials; _i++) {
58 unsmeared_momentum = unsmeared_sampler();
59 track.setMomentum(0. /*px*/, 0. /*py*/, unsmeared_momentum /*pz*/);
60 tst.updateWithSmearP(track);
61 smeared_momentum = track.getP();
62 data.Fill();
63 }
64 }
65 data.Write();
66}
67
69 return 1.0;
70}
72double normal_momentum() {
73 static std::normal_distribution<double> dist(1.0, 0.05);
74 static std::mt19937 gen;
75 return dist(gen);
76}
77
78int main(int nargs, char* argv[]) try {
79 /*
80 std::cout << nargs << " : ";
81 for (int i{0}; i < nargs; i++) std::cout << argv[i] << " ";
82 std::cout << std::endl;
83 */
84 if (nargs < 2) {
85 usage();
86 return 1;
87 } else if (nargs < 3) {
88 usage();
89 std::cout << "\n ERROR: Need two files for testing." << std::endl;
90 }
91 std::string smearing_file{argv[1]}, output_file{argv[2]};
92 TFile output{argv[2], "RECREATE"};
93
95 &output,
96 smearing_file,
97 "fixed",
99 );
100
102 &output,
103 smearing_file,
104 "gaussian",
106 10000 /* num trials */
107 );
108
109 output.Write();
110 output.Close();
111} catch (const std::runtime_error& rte) {
112 std::cerr << rte.what() << std::endl;
113 return 127;
114}
Class used to encapsulate track information.
Class used to encapsulate tracker hit information.
Definition Track.h:32
double fixed_momentum_sampler()
void usage()
double normal_momentum()
int main(int nargs, char *argv[])
void smearing_test(TDirectoryFile *output_d, const std::string &smearing_file, const std::string &name, std::function< double()> unsmeared_sampler, int trials=100, int min_nhits=8, int max_nhits=12)