Process the event and put new data products into it.
48 {
50
52 ldmx::EcalGeometry::CONDITIONS_OBJECT_NAME);
53
54
55 const auto ecal_rec_hits =
event.getCollection<
ldmx::EcalHit>(
56 rec_coll_name_, ecal_rec_hits_passname_);
57 auto nhits = std::count_if(
58 ecal_rec_hits.begin(), ecal_rec_hits.end(),
59 [](
const ldmx::EcalHit& hit) { return hit.getEnergy() > 0; });
60
61
62 ldmx_log(debug) <<
"nhits = " << nhits <<
" MAX_NUM_HITS = " <<
MAX_NUM_HITS;
64 std::array<double, 3> etraj = {-999., -999., -999.};
65 std::array<double, 3> enorm = {-999., -999., -999.};
66
68
69 if (!recoil_from_tracking_ &&
70 event.
exists(ecal_sp_coll_name_, ecal_sp_hits_passname_)) {
72 ecal_sp_coll_name_, ecal_sp_hits_passname_);
73 double electron_pz_max = -1.0;
74 for (auto const& hit : ecal_sp_hits) {
75
76 if (hit.getPdgID() != 11) continue;
77 double electron_z = hit.getPosition()[2];
78
79 if (electron_z <= 239.0 || electron_z >= 240.0) continue;
80 double electron_pz = hit.getMomentum()[2];
81
82 if (electron_pz > electron_pz_max) {
83 electron_pz_max = electron_pz;
84 electron_hit = &hit;
85 }
86 }
87
88 if (electron_hit) {
89
90 ldmx_log(debug) << "Electron Found in the Ecal SP!";
93 ldmx_log(debug) << "ECAL SP pos_=(" << pos[0] << "," << pos[1] << ","
94 << pos[2] << ")";
95 ldmx_log(debug) << "ECAL SP mom=(" << mom[0] << "," << mom[1] << ","
96 << mom[2] << ")";
97 etraj = {pos[0], pos[1], pos[2]};
98 double pz = mom[2];
99 if (pz != 0) {
100
101 enorm = {mom[0] / pz, mom[1] / pz, 1.0};
102 }
103 }
104 } else if (recoil_from_tracking_) {
105
106 auto recoil_tracks{
event.getCollection<
ldmx::Track>(track_collection_,
107 track_pass_name_)};
108 ldmx::TrackStateType ts_at_ecal = ldmx::AtECAL;
109 auto recoil_track_states_ecal =
111 if (!recoil_track_states_ecal.empty()) {
112 std::array<double, 3> pos = {recoil_track_states_ecal[0],
113 recoil_track_states_ecal[1],
114 recoil_track_states_ecal[2]};
115 std::array<double, 3> mom = {(recoil_track_states_ecal[3]),
116 (recoil_track_states_ecal[4]),
117 (recoil_track_states_ecal[5])};
118 ldmx_log(debug) << "Electron track pos_=(" << pos[0] << "," << pos[1]
119 << "," << pos[2] << ")";
120 ldmx_log(debug) << "Electron track mom=(" << mom[0] << "," << mom[1]
121 << "," << mom[2] << ")";
122 etraj = pos;
123 double pz = mom[2];
124 if (pz != 0) {
125 enorm = {mom[0] / pz, mom[1] / pz, 1.0};
126 }
127 } else {
128 ldmx_log(info) << " No recoil track at ECAL";
129 }
130 } else {
131 ldmx_log(fatal) << " No electron hit at scoring plane or no tracking";
132 }
133
134 if (etraj[0] == -999.) {
135
136 result.setDiscValue(-99);
137 result.setVetoResult(false);
138 } else {
139
140 makeInputs(ecal_geometry, ecal_rec_hits, etraj, enorm);
141
142 auto logits = rt_->run(INPUT_NAMES, data_)[0];
143
144
145 auto prob = std::exp((
logSoftmax(logits)[1]));
146 result.setDiscValue(prob);
147
148 double logit_diff = logits[1] - logits[0];
149 ldmx_log(debug) << "ParticleNet logit difference = " << logit_diff;
151 }
152 } else {
153 result.setDiscValue(-99);
154 result.setVetoResult(false);
155 }
156
157 ldmx_log(debug) << "ParticleNet disc value = " << result.getDisc();
158
159
162 } else {
164 }
165
167}
std::vector< float > trackProp(const ldmx::Tracks &tracks, ldmx::TrackStateType ts_type, const std::string &ts_title)
Return a vector of parameters for a propagated recoil track.
std::vector< float > logSoftmax(const std::vector< float > &logits)
Transform logits to a probability.
void makeInputs(const ldmx::EcalGeometry &geom, const std::vector< ldmx::EcalHit > &ecalRecHits, std::array< double, 3 > etraj, std::array< double, 3 > enorm)
Make inputs to the DNN from ECAL RecHits.
const T & getCondition(const std::string &condition_name)
Access a conditions object for the current event.
void setStorageHint(framework::StorageControl::Hint hint)
Mark the current event as having the given storage control hint from this module_.
bool exists(const std::string &name, const std::string &passName, bool unique=true) const
Check for the existence of an object or collection with the given name and pass name in the event.
Stores reconstructed hit information from the ECAL.
bool passesVeto() const
Checks if the event passes the Ecal veto.
Represents a simulated tracker hit in the simulation.
std::vector< float > getPosition() const
Get the XYZ position of the hit [mm].
std::vector< double > getMomentum() const
Get the XYZ momentum of the particle at the position at which the hit took place [MeV].
Implementation of a track object.
constexpr StorageControl::Hint HINT_SHOULD_DROP
storage control hint alias for backwards compatibility
constexpr StorageControl::Hint HINT_SHOULD_KEEP
storage control hint alias for backwards compatibility