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.
Loading...
Searching...
No Matches
PreselectAndCategorize.cxx
Go to the documentation of this file.
1/*
2 * @file PreselectAndCategorize.cxx
3 * @author Tom Eichlersmith
4 * @date Dec 2024
5 * @author Sarah Gaiser
6 * @date Apr 2025
7 */
8
10
11
13 auto pSmearingFile = parameters.getString("pSmearingFile");
14 auto beamPosCfg = parameters.getString("beamPosCfg");
15 auto v0ProjectionFitsCfg = parameters.getString("v0ProjectionFitsCfg");
16 auto trackBiasCfg = parameters.getString("trackBiasCfg");
17
18 calTimeOffset_ = parameters.getDouble("calTimeOffset");
19 isData_ = parameters.getInteger("isData") != 0;
20 isSignal_ = parameters.getInteger("isSignal") != 0;
21}
22
24 _ah = std::make_shared<AnaHelpers>();
25
26 //init Reading Tree
27 bus_.board_input<EventHeader>(tree, "EventHeader");
28 bus_.board_input<std::vector<Vertex*>>(tree, vtxColl_);
29 if(not isData_ and not mcColl_.empty())
30 bus_.board_input<std::vector<MCParticle*>>(tree, mcColl_);
31
32 /* pre-selection on vertices */
33 vertex_cf_.add("ele_track_chi2ndf", 100, 0.0, 20.0);
34 vertex_cf_.add("pos_track_chi2ndf", 100, 0.0, 20.0);
35 vertex_cf_.add("vertex_chi2", 100,0.0,50.0);
36 vertex_cf_.init();
37
38 /* event selection after vertex selection */
39 event_cf_.add("at_least_one_vertex", 10, 0.0, 10.0);
40 event_cf_.add("no_extra_vertices", 10, 0.0, 10.0);
41 event_cf_.init();
42
43 n_vertices_h_ = std::make_unique<TH2F>(
44 "n_vertices_h",
45 "N Vertices in Event (readout and preselected)",
46 10,-0.5,9.5,
47 10,-0.5,9.5
48 );
49}
50
51void PreselectAndCategorize::setFile(TFile* out_file) {
52 Processor::setFile(out_file);
53
54 // create output TTree in output file
55 output_tree_ = std::make_unique<TTree>("preselection",
56 "Preselected and Categorized Vertices",
57 99, out_file);
58 bus_.board_output<double>(output_tree_.get(), "weight");
59 bus_.board_output<Vertex>(output_tree_.get(), "vertex");
60 bus_.board_output<Particle>(output_tree_.get(), "ele");
61 bus_.board_output<Particle>(output_tree_.get(), "pos");
62 bus_.board_output<double>(output_tree_.get(), "psum");
63
64 for (const auto& name : {"eleL1", "eleL2", "posL1", "posL2"}) {
65 bus_.board_output<bool>(output_tree_.get(), name);
66 }
67
68 if (not v0proj_fits_.empty()) {
69 for (const auto& name : {"vtx_proj_sig", "vtx_proj_x", "vtx_proj_x_sig",
70 "vtx_proj_y", "vtx_proj_y_sig"}) {
71 bus_.board_output<double>(output_tree_.get(), name);
72 }
73 }
74}
75
77 const auto& eh{bus_.get<EventHeader>("EventHeader")};
78 int run_number = eh.getRunNumber();
79
80 event_cf_.begin_event();
81
82 const auto& vtxs{bus_.get<std::vector<Vertex*>>(vtxColl_)};
83
84 std::vector<std::tuple<Vertex,Particle,Particle>> preselected_vtx;
85 for (Vertex* vtx : vtxs) {
86 // access the indiviual Vertex, electron, and positron
87 // and add corrections to them before applying pre-selection
88 int i_ele{-1}, i_pos{-1};
89 for (int ipart = 0; ipart < vtx->getParticles().GetEntries(); ++ipart) {
90 int pdg_id = ((Particle*)vtx->getParticles().At(ipart))->getPDG();
91 if (pdg_id == 11) {
92 i_ele = ipart;
93 } else if (pdg_id == -11) {
94 i_pos = ipart;
95 }
96 }
97 if (i_ele < 0 or i_pos < 0) {
98 throw std::runtime_error("Vertex formed without either an electron or positron!");
99 }
100
101 Particle ele = *dynamic_cast<Particle*>(vtx->getParticles().At(i_ele));
102 Particle pos = *dynamic_cast<Particle*>(vtx->getParticles().At(i_pos));
103
104 // for both particles, get cluster, update, re-set cluster
105 CalCluster ele_clu = ele.getCluster();
106 CalCluster pos_clu = pos.getCluster();
107
108 ele_clu.setTime(ele_clu.getTime() - calTimeOffset_);
109 pos_clu.setTime(pos_clu.getTime() - calTimeOffset_);
110
111 ele.setCluster(&ele_clu);
112 pos.setCluster(&pos_clu);
113
114 Track ele_trk = ele.getTrack();
115 Track pos_trk = pos.getTrack();
116
117 // put tracks back into their particles
118 // with their new data
119 ele.setTrack(&ele_trk);
120 pos.setTrack(&pos_trk);
121
122 vertex_cf_.begin_event();
123 vertex_cf_.apply("ele_track_chi2ndf", ele.getTrack().getChi2Ndf() <= 20.0);
124 vertex_cf_.apply("pos_track_chi2ndf", pos.getTrack().getChi2Ndf() <= 20.0);
125 vertex_cf_.apply("vertex_chi2", vtx->getChi2() <= 20.0);
126
127 vertex_cf_.fill_nm1("ele_track_chi2ndf", ele.getTrack().getChi2Ndf());
128 vertex_cf_.fill_nm1("pos_track_chi2ndf", pos.getTrack().getChi2Ndf());
129 vertex_cf_.fill_nm1("vertex_chi2", vtx->getChi2());
130
131 if (vertex_cf_.keep()) {
132 preselected_vtx.emplace_back(*vtx, ele, pos);
133 }
134 }
135
136 n_vertices_h_->Fill(vtxs.size(), preselected_vtx.size());
137 event_cf_.apply("at_least_one_vertex", preselected_vtx.size() > 0);
138 event_cf_.apply("no_extra_vertices", preselected_vtx.size() < 2);
139 if (not event_cf_.keep()) {
140 return true;
141 }
142
143 // correct number of vertices (i.e. only one)
144 // unpack the vector of vertices into the single elements
145 auto [ vtx, ele, pos ] = preselected_vtx.at(0);
146
147 // earliest layer hit categories
148 bool eleL1{false}, eleL2{false}, posL1{false}, posL2{false};
149 Track ele_trk{ele.getTrack()}, pos_trk{pos.getTrack()};
150 _ah->InnermostLayerCheck(&ele_trk, eleL1, eleL2);
151 _ah->InnermostLayerCheck(&pos_trk, posL1, posL2);
152 bus_.set("eleL1", eleL1);
153 bus_.set("eleL2", eleL2);
154 bus_.set("posL1", posL1);
155 bus_.set("posL2", posL2);
156
157 TVector3 ele_mom(
158 ele_trk.getMomentum()[0],
159 ele_trk.getMomentum()[1],
160 ele_trk.getMomentum()[2]
161 );
162 TVector3 pos_mom(
163 pos_trk.getMomentum()[0],
164 pos_trk.getMomentum()[1],
165 pos_trk.getMomentum()[2]
166 );
167 bus_.set("psum", ele_mom.Mag() + pos_mom.Mag());
168
169 bus_.set("weight", 1.);
170 bus_.set("vertex", vtx);
171 bus_.set("ele", ele);
172 bus_.set("pos", pos);
173
174 output_tree_->Fill();
175 return true;
176}
177
179 outF_->cd();
180 output_tree_->Write();
181 n_vertices_h_->Write();
182 vertex_cf_.save();
183 event_cf_.save();
184}
185
#define DECLARE_PROCESSOR(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Definition Processor.h:139
void setTime(const double time)
Definition CalCluster.h:80
double getTime() const
Definition CalCluster.h:83
Definition IEvent.h:7
description
Track getTrack() const
Definition Particle.h:48
CalCluster getCluster() const
Definition Particle.h:62
void setTrack(Track *track)
Definition Particle.h:42
void setCluster(CalCluster *cluster)
Definition Particle.h:56
virtual void configure(const ParameterSet &parameters)
Callback for the Processor to configure itself from the given set of parameters.
virtual void finalize()
Callback for the Processor to take any necessary action when the processing of events finishes,...
virtual void initialize(TTree *tree)
Callback for the Processor to take any necessary action when the processing of events starts,...
std::string mcColl_
description
std::unique_ptr< TH2F > n_vertices_h_
virtual void setFile(TFile *out_file)
Set output TFile for AnaProcessors.
std::shared_ptr< AnaHelpers > _ah
description
std::unique_ptr< TTree > output_tree_
TFile * outF_
Definition Processor.h:125
virtual bool process()
Process the histograms and generate analysis output.
Definition Processor.h:95
virtual void setFile(TFile *outFile)
Set output TFile for AnaProcessors.
Definition Processor.h:88
Definition Track.h:32
double getChi2Ndf() const
Definition Track.h:128
std::vector< double > getMomentum()
Definition Track.h:287