12 #include "cetlib_except/exception.h" 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];
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));
62 throw cet::exception(__FUNCTION__) <<
"LOGIC ERROR: mother/ancestor track ID is invalid!";
71 mother_part = part_v[mother_index];
76 ancestor_part = part_v[ancestor_index];
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);
107 if (edep_index < 0)
continue;
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()
unsigned int MotherTrackID(const unsigned int part_index) const
const std::vector< sim::MCEdep > & GetEdepArrayAt(size_t edep_index) const
Returns a vector of MCEdep object at the given index.
int AncestorPdgCode() const
TLorentzVector _start_vtx
const MCStep & End() const
Class def header for mcstep data container.
unsigned int MotherTrackID() const
TLorentzVector _start_mom
unsigned int AncestorTrackID(const unsigned int part_index)
int TrackToEdepIndex(unsigned int track_id) const
Converts a track ID to MCEdep array index. Returns -1 if no corresponding array found ...
T get(std::string const &key) const
Class def header for mctrack data container.
const MCStep & AncestorStart() const
Definition of data types for geometry description.
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
MCTrackRecoAlg(fhicl::ParameterSet const &pset)
Default constructor with fhicl parameters.
const MCStep & MotherStart() const
int MotherPdgCode() const
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
std::set< int > _pdg_list
PDG code list for which particle's trajectory within the detector is saved.
const std::string & Process() const
const std::string & MotherProcess() const
const unsigned int kINVALID_UINT
const MCStep & Start() const
std::unique_ptr< std::vector< sim::MCTrack > > Reconstruct(MCRecoPart &part_v, MCRecoEdep &edep_v)
unsigned int TrackID() const
unsigned int TrackToParticleIndex(const unsigned int track_id) const
const MCStep & AncestorEnd() const
cet::coded_exception< error, detail::translate > exception