122 bus_.clear_outputs();
124 const auto& tsbank{
bus_.get<
TSData>(
"TSBank")};
131 bool single2 = tsbank.isSingle2Trigger() == 1;
132 bool single3 = tsbank.isSingle3Trigger() == 1;
133 bool single_trigger = single2 || single3;
134 event_cf_.apply(
"single_trigger", single_trigger);
135 event_cf_.fill_nm1(
"single_trigger", single_trigger ? 1 : 0);
141 const auto& allClusters{
bus_.get<std::vector<CalCluster*>>(
"RecoEcalClusters")};
142 int n_clusters =
static_cast<int>(allClusters.size());
143 double event_max_clu_E = -9999.;
144 for (
const auto* cl : allClusters) {
145 if (cl->getEnergy() > event_max_clu_E) event_max_clu_E = cl->getEnergy();
154 auto nearest_energetic = [&](
const std::vector<double>& ecal,
155 double& out_dr,
double& out_E,
double& out_t) {
156 out_dr = 9999.0; out_E = -9999.0; out_t = -9999.0;
157 for (
const auto* cl : allClusters) {
159 auto cp = cl->getPosition();
160 double dr = std::sqrt((cp[0] - ecal[0]) * (cp[0] - ecal[0]) +
161 (cp[1] - ecal[1]) * (cp[1] - ecal[1]));
162 if (dr < out_dr) { out_dr = dr; out_E = cl->getEnergy(); out_t = cl->getTime() -
calTimeOffset_; }
167 bus_.set(
"weight", 1.);
168 bus_.set(
"run", eh.getRunNumber());
169 bus_.set(
"event", eh.getEventNumber());
170 bus_.set(
"single2", single2);
171 bus_.set(
"single3", single3);
173 bus_.set(
"ele_truth_p", TVector3(0., 0., 0.));
174 bus_.set(
"pos_truth_p", TVector3(0., 0., 0.));
175 bus_.set(
"ele_truth_E", -9999.);
176 bus_.set(
"pos_truth_E", -9999.);
177 bus_.set(
"true_vertex_invM", -9999.);
178 bus_.set(
"true_vertex_psum", -9999.);
179 bus_.set(
"true_decay_len", -9999.);
180 bus_.set(
"true_betagamma", -9999.);
182 bus_.set(
"ele_track_p", TVector3(0., 0., 0.));
183 bus_.set(
"pos_track_p", TVector3(0., 0., 0.));
184 for (
const auto& name : {
"ele_ecal_x",
"ele_ecal_y",
"ele_ecal_z",
185 "pos_ecal_x",
"pos_ecal_y",
"pos_ecal_z",
186 "ele_clu_E",
"ele_clu_x",
"ele_clu_y",
"ele_clu_time",
187 "pos_clu_E",
"pos_clu_x",
"pos_clu_y",
"pos_clu_time",
188 "pos_nearest_clu_dr",
"pos_nearest_clu_E",
"pos_nearest_clu_time"}) {
189 bus_.set<
double>(name, -9999.);
191 bus_.set(
"ele_clu_nhits", -1);
192 bus_.set(
"pos_clu_nhits", -1);
194 bool truth_epem_found =
false, has_v0 =
false;
195 bool ele_fiducial =
false, pos_fiducial =
false, both_tracks_fiducial =
false;
196 bool ele_has_cluster =
false, pos_has_cluster =
false;
198 bool pos_matched_cluster =
false;
199 double pos_clu_E_dbg = -9999.;
200 double pos_nearest_dr_dbg = -9999.;
202 bool ele_dr_matched =
false, pos_dr_matched =
false;
203 double ele_nearest_dr_dbg = -9999., ele_dr_E_dbg = -9999.;
204 double pos_dr_E_dbg = -9999.;
207 const std::vector<MCParticle*>* mcParticles =
nullptr;
209 mcParticles = &
bus_.get<std::vector<MCParticle*>>(
mcColl_);
211 ROOT::Math::PxPyPzEVector trueEleP, truePosP;
212 bool foundEle =
false, foundPos =
false;
214 std::vector<double> lP = ptr->getMomentum();
217 }
else if (ptr->getPDG() == 11 && ptr->getMomPDG() ==
signalMomPDG_) {
218 trueEleP = ROOT::Math::PxPyPzEVector(lP.at(0), lP.at(1), lP.at(2), ptr->getEnergy());
220 }
else if (ptr->getPDG() == -11 && ptr->getMomPDG() ==
signalMomPDG_) {
221 truePosP = ROOT::Math::PxPyPzEVector(lP.at(0), lP.at(1), lP.at(2), ptr->getEnergy());
225 truth_epem_found = foundEle && foundPos;
228 bus_.set(
"ele_truth_p", TVector3(trueEleP.Px(), trueEleP.Py(), trueEleP.Pz()));
229 bus_.set(
"ele_truth_E", trueEleP.E());
232 bus_.set(
"pos_truth_p", TVector3(truePosP.Px(), truePosP.Py(), truePosP.Pz()));
233 bus_.set(
"pos_truth_E", truePosP.E());
235 if (foundEle && foundPos) {
236 bus_.set(
"true_vertex_invM", (trueEleP + truePosP).M());
237 bus_.set(
"true_vertex_psum", trueEleP.P() + truePosP.P());
241 std::vector<double> vtxPos = mother->getVertexPosition();
242 std::vector<double> endPos = mother->getEndPoint();
243 double dx = endPos[0] - vtxPos[0];
244 double dy = endPos[1] - vtxPos[1];
245 double dz = endPos[2] - vtxPos[2];
246 bus_.set(
"true_decay_len", std::sqrt(dx * dx + dy * dy + dz * dz));
248 std::vector<double> mMom = mother->getMomentum();
249 double mp = std::sqrt(mMom[0] * mMom[0] + mMom[1] * mMom[1] + mMom[2] * mMom[2]);
250 if (mother->getMass() > 0)
bus_.set(
"true_betagamma", mp / mother->getMass());
254 event_cf_.fill_nm1(
"truth_epem_found", truth_epem_found ? 1 : 0);
257 const auto& vtxs{
bus_.get<std::vector<Vertex*>>(
vtxColl_)};
263 int chosen_i_ele{-1}, chosen_i_pos{-1};
265 double best_pos_dr = 1e9;
266 bool any_pos_matched =
false, any_ele_matched =
false;
267 bool first_pos_matched =
false, first_ele_matched =
false, first_v0_seen =
false;
268 for (
Vertex* vtx : vtxs) {
269 int i_ele{-1}, i_pos{-1};
270 for (
int ipart = 0; ipart < vtx->getParticles().GetEntries(); ++ipart) {
271 int pdg_id = ((
Particle*)vtx->getParticles().At(ipart))->getPDG();
274 else if (pdg_id == -11)
277 if (i_ele < 0 || i_pos < 0)
continue;
283 auto pEcal = p->getTrack().getPositionAtEcal();
284 double pdr, pE, pt, edr, eE, et;
285 nearest_energetic(pEcal, pdr, pE, pt);
286 nearest_energetic(eEcal, edr, eE, et);
289 any_pos_matched = any_pos_matched || pmatch;
290 any_ele_matched = any_ele_matched || ematch;
291 if (not first_v0_seen) {
292 first_v0_seen =
true;
293 first_pos_matched = pmatch;
294 first_ele_matched = ematch;
296 if (pdr < best_pos_dr) {
299 chosen_i_ele = i_ele;
300 chosen_i_pos = i_pos;
303 has_v0 = (chosen !=
nullptr);
309 bool trk_pos_matched =
false, trk_ele_matched =
false;
310 bool has_orphan_cluster =
false;
311 double orphan_clu_x = -9999., orphan_clu_y = -9999., orphan_clu_E = -9999.;
313 const auto& tracks{
bus_.get<std::vector<Track*>>(
trkColl_)};
314 for (
Track* trk : tracks) {
315 auto tEcal = trk->getPositionAtEcal();
316 if (tEcal.size() < 2)
continue;
318 nearest_energetic(tEcal, dr, E, t);
320 if (trk->getCharge() > 0) trk_pos_matched =
true;
321 else if (trk->getCharge() < 0) trk_ele_matched =
true;
327 for (
const auto* cl : allClusters) {
329 auto cp = cl->getPosition();
330 double min_trk_dr = 9999.;
331 for (
Track* trk : tracks) {
332 auto tE = trk->getPositionAtEcal();
333 if (tE.size() < 2)
continue;
334 double dr = std::sqrt((tE[0] - cp[0]) * (tE[0] - cp[0]) +
335 (tE[1] - cp[1]) * (tE[1] - cp[1]));
336 if (dr < min_trk_dr) min_trk_dr = dr;
339 has_orphan_cluster =
true;
340 if (cl->getEnergy() > orphan_clu_E) {
341 orphan_clu_E = cl->getEnergy();
342 orphan_clu_x = cp[0];
343 orphan_clu_y = cp[1];
350 bool pos_acceptance_loss = event_has_cluster && not trk_pos_matched;
352 bus_.set(
"trk_pos_matched", trk_pos_matched);
353 bus_.set(
"trk_ele_matched", trk_ele_matched);
354 bus_.set(
"n_v0", n_v0);
355 bus_.set(
"pos_acceptance_loss", pos_acceptance_loss);
356 bus_.set(
"has_orphan_cluster", has_orphan_cluster);
357 bus_.set<
double>(
"orphan_clu_x", orphan_clu_x);
358 bus_.set<
double>(
"orphan_clu_y", orphan_clu_y);
359 bus_.set<
double>(
"orphan_clu_E", orphan_clu_E);
369 bus_.set(
"ele_track_p", ele_p);
370 bus_.set(
"pos_track_p", pos_p);
374 bus_.set<
double>(
"ele_ecal_x", eleEcal[0]);
375 bus_.set<
double>(
"ele_ecal_y", eleEcal[1]);
376 bus_.set<
double>(
"ele_ecal_z", eleEcal[2]);
377 bus_.set<
double>(
"pos_ecal_x", posEcal[0]);
378 bus_.set<
double>(
"pos_ecal_y", posEcal[1]);
379 bus_.set<
double>(
"pos_ecal_z", posEcal[2]);
382 auto fiducial_at = [&](
const std::vector<double>& xyz) ->
bool {
383 float p[3] = {(float)xyz[0], (
float)xyz[1], (float)xyz[2]};
386 return _ah->IsECalFiducial(&c);
388 ele_fiducial = fiducial_at(eleEcal);
389 pos_fiducial = fiducial_at(posEcal);
390 both_tracks_fiducial = ele_fiducial && pos_fiducial;
399 if (ele_has_cluster) {
406 if (pos_has_cluster) {
415 double pos_dr, pos_dr_E, pos_dr_t;
416 double ele_dr, ele_dr_E, ele_dr_t;
417 nearest_energetic(posEcal, pos_dr, pos_dr_E, pos_dr_t);
418 nearest_energetic(eleEcal, ele_dr, ele_dr_E, ele_dr_t);
419 bus_.set<
double>(
"pos_nearest_clu_dr", pos_dr);
420 bus_.set<
double>(
"pos_nearest_clu_E", pos_dr_E);
421 bus_.set<
double>(
"pos_nearest_clu_time", pos_dr_t);
422 pos_dr_matched = (pos_dr <
drMatch_);
423 ele_dr_matched = (ele_dr <
drMatch_);
424 pos_nearest_dr_dbg = pos_dr;
425 pos_dr_E_dbg = pos_dr_E;
426 ele_nearest_dr_dbg = ele_dr;
427 ele_dr_E_dbg = ele_dr_E;
430 bus_.set(
"truth_epem_found", truth_epem_found);
431 bus_.set(
"has_v0", has_v0);
432 bus_.set(
"ele_fiducial", ele_fiducial);
433 bus_.set(
"pos_fiducial", pos_fiducial);
434 bus_.set(
"both_tracks_fiducial", both_tracks_fiducial);
435 bus_.set(
"ele_has_cluster", ele_has_cluster);
436 bus_.set(
"pos_has_cluster", pos_has_cluster);
439 event_cf_.fill_nm1(
"has_v0", has_v0 ? 1 : 0);
440 event_cf_.apply(
"both_tracks_fiducial", both_tracks_fiducial);
441 event_cf_.fill_nm1(
"both_tracks_fiducial", both_tracks_fiducial ? 1 : 0);
442 event_cf_.apply(
"pos_has_cluster", pos_has_cluster);
443 event_cf_.fill_nm1(
"pos_has_cluster", pos_has_cluster ? 1 : 0);
458 printf(
"[cluseff] run %d evt %d | nClu=%2d || nV0=%d hasV0=%d "
459 "|| v0: pos=%d ele=%d || trk: pos=%d ele=%d%s\n",
460 eh.getRunNumber(), eh.getEventNumber(), n_clusters,
461 n_v0, has_v0 ? 1 : 0,
462 any_pos_matched ? 1 : 0, any_ele_matched ? 1 : 0,
463 trk_pos_matched ? 1 : 0, trk_ele_matched ? 1 : 0,
464 (trk_pos_matched && not any_pos_matched) ?
" <-- e+ track but no v0!" :
"");