33 auto result = std::make_unique<std::vector<sim::MCTrack>>();
37 for(
size_t i=0; i<part_v.size(); ++i) {
38 auto const& mini_part = part_v[i];
39 if( part_v._pdg_list.find(mini_part._pdgcode) == part_v._pdg_list.end() )
continue;
43 std::vector<double>
dEdx;
44 std::vector<std::vector<double> > dQdx;
47 mini_track.
Origin ( mini_part._origin );
48 mini_track.
PdgCode ( mini_part._pdgcode );
49 mini_track.
TrackID ( mini_part._track_id );
50 mini_track.
Process ( mini_part._process );
51 mini_track.
Start ( MCStep( mini_part._start_vtx, mini_part._start_mom ) );
52 mini_track.
End ( MCStep( mini_part._end_vtx, mini_part._end_mom ) );
54 unsigned int mother_track = part_v.MotherTrackID(i);
55 unsigned int ancestor_track = part_v.AncestorTrackID(i);
59 throw cet::exception(__FUNCTION__) <<
"LOGIC ERROR: mother/ancestor track ID is invalid!";
61 MCMiniPart mother_part;
62 MCMiniPart ancestor_part;
64 unsigned int mother_index = part_v.TrackToParticleIndex(mother_track);
65 unsigned int ancestor_index = part_v.TrackToParticleIndex(ancestor_track);
67 if(mother_index !=
kINVALID_UINT) mother_part = part_v[mother_index];
68 else mother_part._track_id = mother_track;
70 if(ancestor_index !=
kINVALID_UINT) ancestor_part = part_v[ancestor_index];
71 else ancestor_part._track_id = ancestor_track;
76 mini_track.
MotherStart ( MCStep( mother_part._start_vtx, mother_part._start_mom ) );
77 mini_track.
MotherEnd ( MCStep( mother_part._end_vtx, mother_part._end_mom ) );
82 mini_track.
AncestorStart ( MCStep( ancestor_part._start_vtx, ancestor_part._start_mom ) );
83 mini_track.
AncestorEnd ( MCStep( ancestor_part._end_vtx, ancestor_part._end_mom ) );
88 for(
auto const& vtx_mom : mini_part._det_path){
89 mini_track.push_back(MCStep(vtx_mom.first,vtx_mom.second));
95 if(mini_track.size() == 0){
96 mctracks.push_back(mini_track);
100 auto const& edep_index = edep_v.TrackToEdepIndex(mini_part._track_id);
101 if(edep_index < 0 )
continue;
102 auto const& edeps = edep_v.GetEdepArrayAt(edep_index);
106 for(
auto const& step_trk : mini_track){
108 if(
int(&step_trk - &mini_track[0])+1 ==
int(mini_track.size()) ){
112 auto const& nxt_step_trk = mini_track.at(
int(&step_trk - &mini_track[0])+1);
117 double dist = sqrt(
pow(step_trk.X() - nxt_step_trk.X(),2) +
118 pow(step_trk.Y() - nxt_step_trk.Y(),2) +
119 pow(step_trk.Z() - nxt_step_trk.Z(),2));
130 double a = 0,
b = 0,
c = 0,
d = 0;
131 a = nxt_step_trk.X() - step_trk.X();
132 b = nxt_step_trk.Y() - step_trk.Y();
133 c = nxt_step_trk.Z() - step_trk.Z();
134 d = -1*(a*step_trk.X() +
b*step_trk.Y() +
c*step_trk.Z());
148 TVector3
B(nxt_step_trk.Position().X() - step_trk.Position().X(),
149 nxt_step_trk.Position().Y() - step_trk.Position().Y(),
150 nxt_step_trk.Position().Z() - step_trk.Position().Z());
154 double step_dedx = 0;
155 std::vector<double> step_dqdx;
159 for(
auto const& edep : edeps){
161 TVector3 x_0(edep.pos._x, edep.pos._y, edep.pos._z);
163 TVector3
A(step_trk.Position().X() - x_0.X(),
164 step_trk.Position().Y() - x_0.Y(),
165 step_trk.Position().Z() - x_0.Z());
171 LineDist = sqrt(
A.Mag2() - 2*
pow(
A*
B,2)/
B.Mag2() +
pow(
A*
B,2)/
B.Mag2());
179 if( (a*edep.pos._x +
b*edep.pos._y +
c*edep.pos._z +
d)/sqrt(
pow(a,2) +
pow(
b,2) +
pow(
c,2)) <= dist + 0.03 &&
180 (a*edep.pos._x +
b*edep.pos._y +
c*edep.pos._z +
d)/sqrt(
pow(a,2) +
pow(
b,2) +
pow(
c,2)) >= 0 - 0.03 &&
187 for(
auto const& pid_energy : edep.deps){
188 engy += pid_energy.energy;
197 auto const pid = edep.pid;
198 auto q_i = pindex.find(
pid);
199 if(q_i != pindex.end())
200 step_dqdx[
pid.Plane] += (
double)(edep.deps[pindex[
pid]].charge);
209 step_dqdx[0] /=
dist;
210 step_dqdx[1] /=
dist;
211 step_dqdx[2] /=
dist;
221 dEdx.push_back(step_dedx);
222 dQdx[0].push_back(step_dqdx[0]);
223 dQdx[1].push_back(step_dqdx[1]);
224 dQdx[2].push_back(step_dqdx[2]);
231 mini_track.dEdx(dEdx);
232 mini_track.dQdx(dQdx);
235 mctracks.push_back(mini_track);
243 for(
auto const&
prof : mctracks) {
247 << Form(
" Track particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
252 << Form(
" Mother particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
253 prof.MotherPdgCode(),
prof.MotherTrackID(),
254 prof.MotherStart().X(),
prof.MotherStart().Y(),
prof.MotherStart().Z(),
prof.MotherStart().T(),
255 prof.MotherStart().Px(),
prof.MotherStart().Py(),
prof.MotherStart().Pz(),
prof.MotherStart().E())
257 << Form(
" Ancestor particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
258 prof.AncestorPdgCode(),
prof.AncestorTrackID(),
259 prof.AncestorStart().X(),
prof.AncestorStart().Y(),
prof.AncestorStart().Z(),
prof.AncestorStart().T(),
260 prof.AncestorStart().Px(),
prof.AncestorStart().Py(),
prof.AncestorStart().Pz(),
prof.AncestorStart().E())
262 << Form(
" ... with %zu trajectory points!",
prof.size())
267 << Form(
" Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
271 << Form(
" End @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
273 (*
prof.rbegin()).Px(), (*
prof.rbegin()).Py(), (*
prof.rbegin()).Pz(), (*
prof.rbegin()).
E())
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
double dEdx(float dqdx, float Efield)
const MCStep & AncestorStart() const
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
QTextStream & endl(QTextStream &s)