28 auto result = std::make_unique<std::vector<sim::MCTrack>>();
29 auto& mctracks = *result;
32 for(
size_t i=0; i<part_v.size(); ++i) {
33 auto const& mini_part = part_v[i];
34 if( part_v._pdg_list.find(mini_part._pdgcode) == part_v._pdg_list.end() )
continue;
38 std::vector<double> dEdx;
39 std::vector<std::vector<double> > dQdx;
42 mini_track.
Origin ( mini_part._origin );
43 mini_track.
PdgCode ( mini_part._pdgcode );
44 mini_track.
TrackID ( mini_part._track_id );
45 mini_track.
Process ( mini_part._process );
46 mini_track.
Start ( MCStep( mini_part._start_vtx, mini_part._start_mom ) );
47 mini_track.
End ( MCStep( mini_part._end_vtx, mini_part._end_mom ) );
49 unsigned int mother_track = part_v.MotherTrackID(i);
50 unsigned int ancestor_track = part_v.AncestorTrackID(i);
54 throw cet::exception(__FUNCTION__) <<
"LOGIC ERROR: mother/ancestor track ID is invalid!";
56 MCMiniPart mother_part;
57 MCMiniPart ancestor_part;
59 unsigned int mother_index = part_v.TrackToParticleIndex(mother_track);
60 unsigned int ancestor_index = part_v.TrackToParticleIndex(ancestor_track);
62 if(mother_index !=
kINVALID_UINT) mother_part = part_v[mother_index];
63 else mother_part._track_id = mother_track;
65 if(ancestor_index !=
kINVALID_UINT) ancestor_part = part_v[ancestor_index];
66 else ancestor_part._track_id = ancestor_track;
71 mini_track.
MotherStart ( MCStep( mother_part._start_vtx, mother_part._start_mom ) );
72 mini_track.
MotherEnd ( MCStep( mother_part._end_vtx, mother_part._end_mom ) );
77 mini_track.
AncestorStart ( MCStep( ancestor_part._start_vtx, ancestor_part._start_mom ) );
78 mini_track.
AncestorEnd ( MCStep( ancestor_part._end_vtx, ancestor_part._end_mom ) );
83 for(
auto const& vtx_mom : mini_part._det_path){
84 mini_track.push_back(MCStep(vtx_mom.first,vtx_mom.second));
90 if(mini_track.size() == 0){
91 mctracks.push_back(mini_track);
95 auto const& edep_index = edep_v.TrackToEdepIndex(mini_part._track_id);
96 if(edep_index < 0 )
continue;
97 auto const& edeps = edep_v.GetEdepArrayAt(edep_index);
101 for(
auto const& step_trk : mini_track){
103 if(
int(&step_trk - &mini_track[0])+1 ==
int(mini_track.size()) ){
107 auto const& nxt_step_trk = mini_track.at(
int(&step_trk - &mini_track[0])+1);
112 double dist = sqrt(pow(step_trk.X() - nxt_step_trk.X(),2) +
113 pow(step_trk.Y() - nxt_step_trk.Y(),2) +
114 pow(step_trk.Z() - nxt_step_trk.Z(),2));
125 double a = 0, b = 0, c = 0,
d = 0;
126 a = nxt_step_trk.X() - step_trk.X();
127 b = nxt_step_trk.Y() - step_trk.Y();
128 c = nxt_step_trk.Z() - step_trk.Z();
129 d = -1*(a*step_trk.X() + b*step_trk.Y() + c*step_trk.Z());
143 TVector3
B(nxt_step_trk.Position().X() - step_trk.Position().X(),
144 nxt_step_trk.Position().Y() - step_trk.Position().Y(),
145 nxt_step_trk.Position().Z() - step_trk.Position().Z());
149 double step_dedx = 0;
150 std::vector<double> step_dqdx;
154 for(
auto const&
edep : edeps){
158 TVector3 A(step_trk.Position().X() - x_0.X(),
159 step_trk.Position().Y() - x_0.Y(),
160 step_trk.Position().Z() - x_0.Z());
166 LineDist = sqrt(A.Mag2() - 2*pow(A*
B,2)/
B.Mag2() + pow(A*
B,2)/
B.Mag2());
174 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 &&
175 (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 &&
182 for(
auto const& pid_energy :
edep.deps){
183 engy += pid_energy.energy;
193 auto q_i = pindex.find(
pid);
194 if(q_i != pindex.end())
195 step_dqdx[
pid.Plane] += (
double)(
edep.deps[pindex[
pid]].charge);
204 step_dqdx[0] /= dist;
205 step_dqdx[1] /= dist;
206 step_dqdx[2] /= dist;
216 dEdx.push_back(step_dedx);
217 dQdx[0].push_back(step_dqdx[0]);
218 dQdx[1].push_back(step_dqdx[1]);
219 dQdx[2].push_back(step_dqdx[2]);
226 mini_track.dEdx(dEdx);
227 mini_track.dQdx(dQdx);
230 mctracks.push_back(mini_track);
238 for(
auto const& prof : mctracks) {
242 << Form(
" Track particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
243 prof.PdgCode(),prof.TrackID(),
244 prof.Start().X(),prof.Start().Y(),prof.Start().Z(),prof.Start().T(),
245 prof.Start().Px(),prof.Start().Py(),prof.Start().Pz(),prof.Start().E())
247 << Form(
" Mother particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
248 prof.MotherPdgCode(),prof.MotherTrackID(),
249 prof.MotherStart().X(),prof.MotherStart().Y(),prof.MotherStart().Z(),prof.MotherStart().T(),
250 prof.MotherStart().Px(),prof.MotherStart().Py(),prof.MotherStart().Pz(),prof.MotherStart().E())
252 << Form(
" Ancestor particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
253 prof.AncestorPdgCode(),prof.AncestorTrackID(),
254 prof.AncestorStart().X(),prof.AncestorStart().Y(),prof.AncestorStart().Z(),prof.AncestorStart().T(),
255 prof.AncestorStart().Px(),prof.AncestorStart().Py(),prof.AncestorStart().Pz(),prof.AncestorStart().E())
257 << Form(
" ... with %zu trajectory points!",prof.size())
262 << Form(
" Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
263 prof[0].
X(), prof[0].
Y(), prof[0].
Z(), prof[0].T(),
264 prof[0].Px(), prof[0].Py(), prof[0].Pz(), prof[0].
E())
266 << Form(
" End @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
267 (*prof.rbegin()).
X(), (*prof.rbegin()).
Y(), (*prof.rbegin()).
Z(), (*prof.rbegin()).T(),
268 (*prof.rbegin()).Px(), (*prof.rbegin()).Py(), (*prof.rbegin()).Pz(), (*prof.rbegin()).
E())
273 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
const MCStep & MotherStart() const
int MotherPdgCode() const
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