LDMX Software
PatternLUTMaker.cxx
1// Analyzer file which writes a LUT text file from input cluster text file (made
2// in ClusterTripletMaker) containing only those cluster combination entries
3// which occur with a frequency above the lut_threshold parameter
4
6
7namespace tools {
8
9PatternLUTMaker::PatternLUTMaker(const std::string& name,
10 framework::Process& process)
11 : Analyzer(name, process) {}
12
13void PatternLUTMaker::configure(framework::config::Parameters& ps) {
14 input_file_ = ps.get<std::string>("input_file");
15 output_file_ = ps.get<std::string>("output_file");
16 lut_threshold_ = ps.get<double>("lut_threshold");
17 verbose_ = ps.get<int>("verbosity");
18
19 // The LUT threshold is the minimum percentage of times that a track
20 // must appear in a pool of events to be written to the LUT.
21 // Example --- horizontal tracks whose pad 1-2 and pad 2-3 delta values
22 // are both 0 make up ~80% of tracks out of 10.000 events,
23 // while a track with deltas (+22,-22), meaning pad 1 cluster in
24 // e.g. bar 4, pad 2 cluster in bar 26, and pad 3 cluster in bar 4
25 // only appears once in 10.000 events (0.01%). The straight
26 // tracks are written to the LUT and the single "anomaly" is not.
27 // Primary motivation here is for use in the case of an unknown TS
28 // misalignment.
29
30 ldmx_log(info) << "In PatternLUTMaker: configure done!" << std::endl;
31 ldmx_log(info) << "Got parameters: \nInput file: " << input_file_
32 << "\nOutput file: " << output_file_
33 << "\nLUT threshold: " << lut_threshold_
34 << "\nVerbosity: " << verbose_;
35
36 return;
37}
38
39void PatternLUTMaker::onProcessStart() {
40 infile_.open(input_file_);
41 outfile_.open(output_file_);
42
43 if (total_lines_ > 0) return;
44 int ev;
45 float p1, p2, p3;
46 while (infile_ >> ev >> p1 >> p2 >> p3) {
47 float p12 = p2 - p1; //for each cluster combination, calculate vertical propagation
48 float p23 = p3 - p2; //between pads 1 and 2 (p12) and between pads 2 and 3 (p23);
49 groups_[{p12, p23}].push_back({ev, p1, p2, p3}); //and group by these values
50 total_lines_++; //(the "propagation patterns").
51 }
52 return;
53}
54
55void PatternLUTMaker::analyze(const framework::Event& event) {
56}
57
58void PatternLUTMaker::onProcessEnd() {
59 ldmx_log(info) << "total_lines = " << total_lines_;
60 ldmx_log(info) << "groups = " << groups_.size();
61 int combs = 0; //combs will be the total number of patterns written to the LUT
62 int tracks = 0; //and tracks the number of tracks contained within those pattern groups
63
64 if (verbose_) {
65 ldmx_log(info) << "Total number of cluster combinations: " << total_lines_ << "\n"
66 << "Number of different propagation patterns: " << groups_.size()
67 << "\n" << "LUT Threshold: " << lut_threshold_ * 100 << "%\n";
68 }
69
70 for (auto& g : groups_) {
71 int count = g.second.size();
72 double frac = static_cast<double>(count) / total_lines_;
73
74 if (verbose_) {
75 ldmx_log(debug) << "(" << g.first.first << "," << g.first.second << ") appears "
76 << count << " times, (" << frac * 100 << " %)" << "\n";
77 }
78
79 if (frac > lut_threshold_) { // write to outfile_ (LUT file) if over threshold
80 combs++;
81 for (auto& line : g.second) {
82 tracks++;
83 outfile_ << line.p1_ << " " << line.p2_ << " " << line.p3_ << "\n";
84 }
85 }
86
87 }
88
89 if (verbose_) {
90 ldmx_log(info) << "\nLUT textfile written." << "\n" << combs
91 << " combinations (" << tracks << " tracks) written to LUT.\n";
92 }
93 return;
94}
95} // namespace tools
96
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
Writes LUT based on frequency of track propagation patterns for LUT-based TS tracking.
Implements an event buffer system for storing event data.
Definition Event.h:42
Class which represents the process under execution.
Definition Process.h:37
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78