24 inTag =
"TargetScoringPlaneHits";
25 if (writeTruth_ && event.
exists(inTag)) {
26 const std::vector<ldmx::SimTrackerHit> hits =
29 for (
const auto& hit : hits) {
31 if (xyz[2] > 0 && xyz[2] < 1) {
32 if (hit.getTrackID() == 1) h = hit;
33 if (hit.getPdgID() == 11 && (hit.getEnergy() > hMaxEle.getEnergy()))
39 if (h.getPdgID() == 0)
41 std::string coll =
"Truth";
42 n.setVar(coll +
"_e", prec(h.getEnergy()));
43 n.setVar(coll +
"_x", prec(h.getPosition()[0]));
44 n.setVar(coll +
"_y", prec(h.getPosition()[1]));
45 n.setVar(coll +
"_px", prec(h.getMomentum()[0]));
46 n.setVar(coll +
"_py", prec(h.getMomentum()[1]));
47 n.setVar(coll +
"_pz", prec(h.getMomentum()[2]));
48 n.setVar(coll +
"_pdgId", h.getPdgID());
50 inTag =
"EcalScoringPlaneHits";
51 if (writeTruth_ && event.
exists(inTag)) {
52 const std::vector<ldmx::SimTrackerHit> hits =
55 for (
const auto& hit : hits) {
57 if (xyz[2] > 239.99 && xyz[2] < 240.01) {
58 if (hit.getTrackID() == 1) h = hit;
59 if (hit.getPdgID() == 11 && (hit.getEnergy() > hMaxEle.getEnergy()))
65 if (h.getPdgID() == 0)
67 std::string coll =
"TruthEcal";
68 n.setVar(coll +
"_e", prec(h.getEnergy()));
69 n.setVar(coll +
"_x", prec(h.getPosition()[0]));
70 n.setVar(coll +
"_y", prec(h.getPosition()[1]));
71 n.setVar(coll +
"_px", prec(h.getMomentum()[0]));
72 n.setVar(coll +
"_py", prec(h.getMomentum()[1]));
73 n.setVar(coll +
"_pz", prec(h.getMomentum()[2]));
74 n.setVar(coll +
"_pdgId", h.getPdgID());
77 inTag =
"ecalTrigSums";
78 if (writeEcalSums_ && event.
exists(inTag)) {
81 vector<float> energyAfterLayer;
82 for (
const auto& sum : sums) {
83 if (!(sum.energy() > 0))
continue;
84 if (sum.layer() >= energyAfterLayer.size())
85 energyAfterLayer.resize(sum.layer() + 1);
86 for (
int i = 0; i <= sum.layer(); i++) {
87 energyAfterLayer[i] += sum.energy();
90 n.setVar(
"Ecal_e_afterLayer", energyAfterLayer);
91 n.setVar(
"Ecal_e_nLayer",
int(energyAfterLayer.size()));
93 inTag =
"hcalTrigQuadsBackLayerSums";
94 if (writeHcalSums_ && event.
exists(inTag)) {
96 vector<float> energyAfterLayer;
97 for (
const auto& sum : sums) {
98 if (!(sum.hwEnergy() > 0))
continue;
99 if (sum.layer() >= energyAfterLayer.size())
100 energyAfterLayer.resize(sum.layer() + 1);
101 for (
int i = 0; i <= sum.layer(); i++) {
102 energyAfterLayer[i] += sum.hwEnergy();
105 n.setVar(
"Hcal_e_afterLayer", energyAfterLayer);
106 n.setVar(
"Hcal_e_nLayer",
int(energyAfterLayer.size()));
109 inTag =
"trigElectrons";
110 if (writeEle_ && event.
exists(inTag)) {
111 const auto eles =
event.getCollection<
TrigParticle>(inTag);
112 const int nEle = eles.size();
117 vector<float> v_e(nEle);
118 vector<float> v_eC(nEle);
119 vector<float> v_zC(nEle);
120 vector<float> v_px(nEle);
121 vector<float> v_py(nEle);
122 vector<float> v_pz(nEle);
123 vector<float> v_dx(nEle);
124 vector<float> v_dy(nEle);
125 vector<float> v_x(nEle);
126 vector<float> v_y(nEle);
127 vector<int> v_tp(nEle);
128 vector<int> v_depth(nEle);
129 for (
unsigned int i = 0; i < nEle; i++) {
130 if (eles[i].energy() > maxEVal) {
131 maxEVal = eles[i].energy();
134 if (eles[i].pt() > maxPtVal) {
135 maxPtVal = eles[i].pt();
138 v_e[i] = prec(eles[i].energy());
139 v_eC[i] = prec(eles[i].getClusEnergy());
140 v_zC[i] = prec(eles[i].endz());
141 v_px[i] = prec(eles[i].px());
142 v_py[i] = prec(eles[i].py());
143 v_pz[i] = prec(eles[i].pz());
144 v_dx[i] = prec(eles[i].endx() - eles[i].vx());
145 v_dy[i] = prec(eles[i].endy() - eles[i].vy());
146 v_x[i] = prec(eles[i].vx());
147 v_y[i] = prec(eles[i].vy());
148 v_tp[i] = prec(eles[i].getClusTP());
149 v_depth[i] = prec(eles[i].getClusDepth());
151 std::string coll =
"Electron";
152 n.setVar(
"n" + coll, nEle);
153 n.setVar(
"maxE", maxE);
154 n.setVar(
"maxPt", maxPt);
155 n.setVar(coll +
"_e", v_e);
156 n.setVar(coll +
"_eClus", v_eC);
157 n.setVar(coll +
"_zClus", v_zC);
158 n.setVar(coll +
"_px", v_px);
159 n.setVar(coll +
"_py", v_py);
160 n.setVar(coll +
"_pz", v_pz);
161 n.setVar(coll +
"_dx", v_dx);
162 n.setVar(coll +
"_dy", v_dy);
163 n.setVar(coll +
"_x", v_x);
164 n.setVar(coll +
"_y", v_y);
165 n.setVar(coll +
"_tp", v_tp);
166 n.setVar(coll +
"_depth", v_depth);
170void NtupleWriter::onProcessStart() {
172 outFile_ =
new TFile(outPath_.c_str(),
"recreate");
173 outFile_->SetCompressionSettings(209);
180 std::string coll =
"Electron";
181 n.addVar<
int>(tag_,
"n" + coll);
182 n.addVar<
int>(tag_,
"maxE");
183 n.addVar<
int>(tag_,
"maxPt");
184 n.addVar<vector<float> >(tag_, coll +
"_e");
185 n.addVar<vector<float> >(tag_, coll +
"_eClus");
186 n.addVar<vector<float> >(tag_, coll +
"_zClus");
187 n.addVar<vector<float> >(tag_, coll +
"_px");
188 n.addVar<vector<float> >(tag_, coll +
"_py");
189 n.addVar<vector<float> >(tag_, coll +
"_pz");
190 n.addVar<vector<float> >(tag_, coll +
"_dx");
191 n.addVar<vector<float> >(tag_, coll +
"_dy");
192 n.addVar<vector<float> >(tag_, coll +
"_x");
193 n.addVar<vector<float> >(tag_, coll +
"_y");
194 n.addVar<vector<int> >(tag_, coll +
"_tp");
195 n.addVar<vector<int> >(tag_, coll +
"_depth");
198 n.addVar<
float>(tag_,
"Truth_x");
199 n.addVar<
float>(tag_,
"Truth_y");
200 n.addVar<
float>(tag_,
"Truth_px");
201 n.addVar<
float>(tag_,
"Truth_py");
202 n.addVar<
float>(tag_,
"Truth_pz");
203 n.addVar<
float>(tag_,
"Truth_e");
204 n.addVar<
int>(tag_,
"Truth_pdgId");
205 n.addVar<
float>(tag_,
"TruthEcal_x");
206 n.addVar<
float>(tag_,
"TruthEcal_y");
207 n.addVar<
float>(tag_,
"TruthEcal_px");
208 n.addVar<
float>(tag_,
"TruthEcal_py");
209 n.addVar<
float>(tag_,
"TruthEcal_pz");
210 n.addVar<
float>(tag_,
"TruthEcal_e");
211 n.addVar<
int>(tag_,
"TruthEcal_pdgId");
213 if (writeEcalSums_) {
214 n.addVar<vector<float> >(tag_,
"Ecal_e_afterLayer");
215 n.addVar<
int>(tag_,
"Ecal_e_nLayer");
217 if (writeHcalSums_) {
218 n.addVar<vector<float> >(tag_,
"Hcal_e_afterLayer");
219 n.addVar<
int>(tag_,
"Hcal_e_nLayer");
Class for particles reconstructed by the trigger system.