36 auto result = std::make_unique<std::vector<sim::MCTrack>>();
37 auto& mctracks = *result;
40 for (
size_t i = 0; i < part_v.size(); ++i) {
41 auto const& mini_part = part_v[i];
42 if (part_v._pdg_list.find(mini_part._pdgcode) == part_v._pdg_list.end())
continue;
46 std::vector<double>
dEdx;
47 std::vector<std::vector<double>> dQdx;
50 mini_track.
Origin(mini_part._origin);
51 mini_track.
PdgCode(mini_part._pdgcode);
52 mini_track.
TrackID(mini_part._track_id);
53 mini_track.
Process(mini_part._process);
54 mini_track.
Start(MCStep(mini_part._start_vtx, mini_part._start_mom));
55 mini_track.
End(MCStep(mini_part._end_vtx, mini_part._end_mom));
57 unsigned int mother_track = part_v.MotherTrackID(i);
58 unsigned int ancestor_track = part_v.AncestorTrackID(i);
62 throw cet::exception(__FUNCTION__) <<
"LOGIC ERROR: mother/ancestor track ID is invalid!";
64 MCMiniPart mother_part;
65 MCMiniPart ancestor_part;
67 unsigned int mother_index = part_v.TrackToParticleIndex(mother_track);
68 unsigned int ancestor_index = part_v.TrackToParticleIndex(ancestor_track);
71 mother_part = part_v[mother_index];
73 mother_part._track_id = mother_track;
76 ancestor_part = part_v[ancestor_index];
78 ancestor_part._track_id = ancestor_track;
83 mini_track.
MotherStart(MCStep(mother_part._start_vtx, mother_part._start_mom));
84 mini_track.
MotherEnd(MCStep(mother_part._end_vtx, mother_part._end_mom));
89 mini_track.
AncestorStart(MCStep(ancestor_part._start_vtx, ancestor_part._start_mom));
90 mini_track.
AncestorEnd(MCStep(ancestor_part._end_vtx, ancestor_part._end_mom));
94 for (
auto const& vtx_mom : mini_part._det_path) {
95 mini_track.push_back(MCStep(vtx_mom.first, vtx_mom.second));
101 if (mini_track.size() == 0) {
102 mctracks.push_back(mini_track);
106 auto const& edep_index = edep_v.TrackToEdepIndex(mini_part._track_id);
107 if (edep_index < 0)
continue;
108 auto const& edeps = edep_v.GetEdepArrayAt(edep_index);
112 for (
auto const& step_trk : mini_track) {
114 if (
int(&step_trk - &mini_track[0]) + 1 ==
115 int(mini_track.size())) {
119 auto const& nxt_step_trk = mini_track.at(
int(&step_trk - &mini_track[0]) + 1);
125 sqrt(pow(step_trk.X() - nxt_step_trk.X(), 2) + pow(step_trk.Y() - nxt_step_trk.Y(), 2) +
126 pow(step_trk.Z() - nxt_step_trk.Z(), 2));
137 double a = 0, b = 0, c = 0,
d = 0;
138 a = nxt_step_trk.X() - step_trk.X();
139 b = nxt_step_trk.Y() - step_trk.Y();
140 c = nxt_step_trk.Z() - step_trk.Z();
141 d = -1 * (a * step_trk.X() + b * step_trk.Y() + c * step_trk.Z());
155 TVector3 B(nxt_step_trk.Position().X() - step_trk.Position().X(),
156 nxt_step_trk.Position().Y() - step_trk.Position().Y(),
157 nxt_step_trk.Position().Z() - step_trk.Position().Z());
160 double step_dedx = 0;
161 std::vector<double> step_dqdx;
165 for (
auto const&
edep : edeps) {
169 TVector3 A(step_trk.Position().X() - x_0.X(),
170 step_trk.Position().Y() - x_0.Y(),
171 step_trk.Position().Z() - x_0.Z());
177 LineDist = sqrt(A.Mag2() - 2 * pow(A * B, 2) / B.Mag2() + pow(A * B, 2) / B.Mag2());
187 if ((a *
edep.pos._x + b *
edep.pos._y + c *
edep.pos._z +
d) /
188 sqrt(pow(a, 2) + pow(b, 2) + pow(c, 2)) <=
191 sqrt(pow(a, 2) + pow(b, 2) + pow(c, 2)) >=
199 for (
auto const& pid_energy :
edep.deps) {
200 engy += pid_energy.energy;
204 if (npid != 0) { engy /= npid; }
211 auto q_i = pindex.find(
pid);
212 if (q_i != pindex.end())
213 step_dqdx[
pid.Plane] += (
double)(
edep.deps[pindex[
pid]].charge);
222 step_dqdx[0] /=
dist;
223 step_dqdx[1] /=
dist;
224 step_dqdx[2] /=
dist;
234 dEdx.push_back(step_dedx);
235 dQdx[0].push_back(step_dqdx[0]);
236 dQdx[1].push_back(step_dqdx[1]);
237 dQdx[2].push_back(step_dqdx[2]);
241 mini_track.dEdx(dEdx);
242 mini_track.dQdx(dQdx);
244 mctracks.push_back(mini_track);
249 for (
auto const& prof : mctracks) {
253 << Form(
" Track particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum " 266 << Form(
" Mother particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum " 268 prof.MotherPdgCode(),
269 prof.MotherTrackID(),
270 prof.MotherStart().X(),
271 prof.MotherStart().Y(),
272 prof.MotherStart().Z(),
273 prof.MotherStart().T(),
274 prof.MotherStart().Px(),
275 prof.MotherStart().Py(),
276 prof.MotherStart().Pz(),
277 prof.MotherStart().E())
279 << Form(
" Ancestor particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum " 281 prof.AncestorPdgCode(),
282 prof.AncestorTrackID(),
283 prof.AncestorStart().X(),
284 prof.AncestorStart().Y(),
285 prof.AncestorStart().Z(),
286 prof.AncestorStart().T(),
287 prof.AncestorStart().Px(),
288 prof.AncestorStart().Py(),
289 prof.AncestorStart().Pz(),
290 prof.AncestorStart().E())
292 << Form(
" ... with %zu trajectory points!", prof.size()) << std::endl;
295 std::cout << Form(
" Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
305 << Form(
" End @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
306 (*prof.rbegin()).
X(),
307 (*prof.rbegin()).
Y(),
308 (*prof.rbegin()).
Z(),
309 (*prof.rbegin()).T(),
310 (*prof.rbegin()).Px(),
311 (*prof.rbegin()).Py(),
312 (*prof.rbegin()).Pz(),
313 (*prof.rbegin()).
E())
318 std::cout << std::endl << std::endl;
simb::Origin_t Origin() const
const std::string & AncestorProcess() const
const MCStep & MotherEnd() const
unsigned int AncestorTrackID() const
std::map< geo::PlaneID, size_t > createPlaneIndexMap()
int AncestorPdgCode() const
const MCStep & End() const
unsigned int MotherTrackID() const
const MCStep & AncestorStart() const
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
const MCStep & MotherStart() const
int MotherPdgCode() const
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
const std::string & Process() const
const std::string & MotherProcess() const
const unsigned int kINVALID_UINT
const MCStep & Start() const
unsigned int TrackID() const
const MCStep & AncestorEnd() const
cet::coded_exception< error, detail::translate > exception