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];
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 ) );
59 throw cet::exception(__FUNCTION__) <<
"LOGIC ERROR: mother/ancestor track ID is invalid!";
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;
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);
101 if(edep_index < 0 )
continue;
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()
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
double dEdx(float dqdx, float Efield)
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
Code to link reconstructed objects back to the MC truth information.
Definition of data types for geometry description.
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
QTextStream & endl(QTextStream &s)