LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
tca::MCParticleListUtils Class Reference

#include "TCTruth.h"

Public Member Functions

 MCParticleListUtils (TjStuff &my_tjs)
 
void MakeTruTrajPoint (unsigned int MCParticleListIndex, TrajPoint &tp)
 
ShowerStruct3D MakeCheatShower (unsigned int mcpIndex, Point3_t primVx, int &truParentPFP)
 
bool PrimaryElectronStart (Point3_t &start, Vector3_t &dir, float &energy)
 
int PrimaryElectronPFPID (const geo::TPCID &tpcid)
 
int PrimaryElectronTjID (CTP_t inCTP)
 
int MCParticleStartTjID (unsigned int MCParticleListIndex, CTP_t inCTP)
 
unsigned int GetMCPartListIndex (const TrajPoint &tp)
 
unsigned int GetMCPartListIndex (const Trajectory &tj, unsigned short &nTruHits)
 
unsigned int GetMCPartListIndex (const ShowerStruct &ss, unsigned short &nTruHits)
 

Public Attributes

TjStufftjs
 

Detailed Description

Definition at line 81 of file TCTruth.h.

Constructor & Destructor Documentation

tca::MCParticleListUtils::MCParticleListUtils ( TjStuff my_tjs)
inline

Definition at line 85 of file TCTruth.h.

85 : tjs(my_tjs) {}

Member Function Documentation

unsigned int tca::MCParticleListUtils::GetMCPartListIndex ( const TrajPoint tp)

Definition at line 1499 of file TCTruth.cxx.

References tca::TrajPoint::Chg, tca::TjStuff::fHits, tca::TrajPoint::Hits, tca::TjStuff::MCPartList, tca::TruthMatcher::tjs, and tca::TrajPoint::UseHit.

1500  {
1501  // Returns the MCParticle index that best matches the hits used in the Tp
1502  if(tjs.MCPartList.empty()) return UINT_MAX;
1503  if(tp.Chg <= 0) return UINT_MAX;
1504  std::vector<unsigned int> mcpIndex;
1505  std::vector<unsigned short> mcpCnt;
1506  for(unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
1507  if(!tp.UseHit[ii]) continue;
1508  unsigned int mcpi = tjs.fHits[tp.Hits[ii]].MCPartListIndex;
1509  if(mcpi == UINT_MAX) continue;
1510  unsigned short indx = 0;
1511  for(indx = 0; indx < mcpIndex.size(); ++indx) if(mcpi == mcpIndex[indx]) break;
1512  if(indx == mcpIndex.size()) {
1513  // not in the list so add it
1514  mcpIndex.push_back(mcpi);
1515  mcpCnt.push_back(1);
1516  } else {
1517  ++mcpCnt[indx];
1518  }
1519  } // ii
1520  if(mcpIndex.empty()) return UINT_MAX;
1521  if(mcpIndex.size() == 1) return mcpIndex[0];
1522  unsigned int indx = 0;
1523  unsigned short maxCnt = 0;
1524  for(unsigned short ii = 0; ii < mcpIndex.size(); ++ii) {
1525  if(mcpCnt[ii] > maxCnt) {
1526  maxCnt = mcpCnt[ii];
1527  indx = mcpIndex[ii];
1528  }
1529  } // ii
1530  return indx;
1531  } // GetMCPartListIndex
std::vector< TCHit > fHits
Definition: DataStructs.h:495
std::vector< simb::MCParticle * > MCPartList
Definition: DataStructs.h:520
unsigned int tca::MCParticleListUtils::GetMCPartListIndex ( const Trajectory tj,
unsigned short &  nTruHits 
)

Definition at line 1571 of file TCTruth.cxx.

References tca::TjStuff::fHits, tca::TjStuff::MCPartList, tca::Trajectory::Pts, and tca::TruthMatcher::tjs.

1572  {
1573  // Returns the index of the MCParticle that has the most number of matches
1574  // to the hits in this trajectory
1575 
1576  if(tjs.MCPartList.empty()) return UINT_MAX;
1577 
1578  // Check all hits associated with this Tj
1579  std::vector<unsigned int> pListCnt(tjs.MCPartList.size());
1580 
1581  for(auto& tp : tj.Pts) {
1582  for(unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
1583  if(!tp.UseHit[ii]) continue;
1584  unsigned int iht = tp.Hits[ii];
1585  // ignore unmatched hits
1586  if(tjs.fHits[iht].MCPartListIndex > tjs.MCPartList.size() - 1) continue;
1587  ++pListCnt[tjs.fHits[iht].MCPartListIndex];
1588  } // ii
1589  } // pt
1590 
1591  unsigned int pIndex = UINT_MAX;
1592  nTruHits = 0;
1593  for(unsigned short ii = 0; ii < pListCnt.size(); ++ii) {
1594  if(pListCnt[ii] > nTruHits) {
1595  nTruHits = pListCnt[ii];
1596  pIndex = ii;
1597  }
1598  } // ii
1599 
1600  return pIndex;
1601 
1602  } // GetMCPartListIndex
std::vector< TCHit > fHits
Definition: DataStructs.h:495
std::vector< simb::MCParticle * > MCPartList
Definition: DataStructs.h:520
unsigned int tca::MCParticleListUtils::GetMCPartListIndex ( const ShowerStruct ss,
unsigned short &  nTruHits 
)

Definition at line 1534 of file TCTruth.cxx.

References tca::TjStuff::allTraj, tca::TjStuff::fHits, tca::TjStuff::MCPartList, tca::Trajectory::Pts, tca::ShowerStruct::TjIDs, and tca::TruthMatcher::tjs.

1535  {
1536  // Returns the index of the MCParticle that has the most number of matches
1537  // to the hits in this shower
1538 
1539  if(tjs.MCPartList.empty()) return UINT_MAX;
1540  if(ss.TjIDs.empty()) return UINT_MAX;
1541 
1542  std::vector<unsigned int> pListCnt(tjs.MCPartList.size());
1543 
1544  for(auto& tjid : ss.TjIDs) {
1545  Trajectory& tj = tjs.allTraj[tjid - 1];
1546  for(auto& tp : tj.Pts) {
1547  for(unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
1548  if(!tp.UseHit[ii]) continue;
1549  unsigned int iht = tp.Hits[ii];
1550  // ignore unmatched hits
1551  if(tjs.fHits[iht].MCPartListIndex > tjs.MCPartList.size() - 1) continue;
1552  ++pListCnt[tjs.fHits[iht].MCPartListIndex];
1553  } // ii
1554  } // pt
1555  } // tjid
1556 
1557  unsigned int pIndex = UINT_MAX;
1558  nTruHits = 0;
1559  for(unsigned short ii = 0; ii < pListCnt.size(); ++ii) {
1560  if(pListCnt[ii] > nTruHits) {
1561  nTruHits = pListCnt[ii];
1562  pIndex = ii;
1563  }
1564  } // ii
1565 
1566  return pIndex;
1567 
1568  } // GetMCPartListIndex
Float_t ss
Definition: plot.C:23
std::vector< Trajectory > allTraj
vector of all trajectories in each plane
Definition: DataStructs.h:493
std::vector< TCHit > fHits
Definition: DataStructs.h:495
std::vector< simb::MCParticle * > MCPartList
Definition: DataStructs.h:520
ShowerStruct3D tca::MCParticleListUtils::MakeCheatShower ( unsigned int  mcpIndex,
Point3_t  primVx,
int &  truParentPFP 
)

Definition at line 1191 of file TCTruth.cxx.

References tca::TjStuff::allTraj, close(), tca::CreateSS(), tca::CreateSS3(), geo::CryostatID::Cryostat, tca::EncodeCTP(), evd::details::end(), sim::ParticleList::EveId(), tca::TjStuff::fHits, tca::GetAssns(), tca::kMat3D, tca::TjStuff::MCPartList, tca::TjStuff::NumPlanes, cheat::ParticleInventoryService::ParticleList(), tca::TjStuff::pfps, tca::PosSep(), ss, tca::StoreShower(), tca::TruthMatcher::tjs, geo::TPCID::TPC, tca::TjStuff::TPCID, tca::TjStuff::UnitsPerTick, tca::UpdateShower(), and tca::TjStuff::WirePitch.

1192  {
1193  // Make a 3D shower for an electron or photon MCParticle in the current TPC.
1194  // The shower ID is set to 0 if there is a failure. The ID of the most likely parent pfp is returned
1195  // as well - the one that is closest to the primary vertex position
1196  auto ss3 = CreateSS3(tjs, tjs.TPCID);
1197  truParentPFP = 0;
1198  // save the ID
1199  int goodID = ss3.ID;
1200  // set it to the failure state
1201  ss3.ID = 0;
1202  ss3.Cheat = true;
1203  if(mcpIndex > tjs.MCPartList.size() - 1) return ss3;
1204  auto& mcp = tjs.MCPartList[mcpIndex];
1205  int pdg = abs(mcp->PdgCode());
1206  if(!(pdg == 11 || pdg == 111)) return ss3;
1208  int eveID = mcp->TrackId();
1209  float showerEnergy = 1000 * mcp->E();
1210  float shMaxAlong = 7.0 * log(showerEnergy / 15);
1211  std::cout<<"MCS: showerEnergy "<<(int)showerEnergy<<" MeV. shMaxAlong "<<shMaxAlong<<" cm\n";
1212 
1213  // put the shower hits in two vectors. One for the InShower hits
1214  // and one for the shower parent
1215  std::vector<std::vector<unsigned int>> showerHits(tjs.NumPlanes);
1216  std::vector<std::vector<unsigned int>> parentHits(tjs.NumPlanes);
1217  unsigned short nsh = 0;
1218  unsigned short npar = 0;
1219  unsigned int cstat = tjs.TPCID.Cryostat;
1220  unsigned int tpc = tjs.TPCID.TPC;
1221  for(unsigned int iht = 0; iht < tjs.fHits.size(); ++iht) {
1222  auto& hit = tjs.fHits[iht];
1223  if(hit.MCPartListIndex > tjs.MCPartList.size()-1) continue;
1224  if(hit.ArtPtr->WireID().TPC != tpc) continue;
1225  if(hit.ArtPtr->WireID().Cryostat != cstat) continue;
1226  if(hit.Integral <= 0) continue;
1227  // require that it be used in a tj to ignore hits that are far
1228  // from the shower
1229  if(hit.InTraj <= 0) continue;
1230  auto& shmcp = tjs.MCPartList[hit.MCPartListIndex];
1231  // look for an electron
1232  if(abs(shmcp->PdgCode()) != 11) continue;
1233  // with eve ID = the primary electron being considered
1234  int eid = pi_serv->ParticleList().EveId(shmcp->TrackId());
1235  if(eid != eveID) continue;
1236  if(shmcp->TrackId() == eid) {
1237  // store the shower parent hit
1238  parentHits[hit.ArtPtr->WireID().Plane].push_back(iht);
1239  ++npar;
1240  } else {
1241  // store the InShower hit
1242  showerHits[hit.ArtPtr->WireID().Plane].push_back(iht);
1243  ++nsh;
1244  }
1245  } // iht
1246  // require more hits in the shower than in the parent
1247  if(npar > nsh) return ss3;
1248 /*
1249  for(unsigned short plane = 0; plane < tjs.NumPlanes; ++plane) {
1250  std::cout<<" plane "<<plane<<" shower hits "<<showerHits[plane].size();
1251  std::cout<<" parentHits "<<parentHits[plane].size()<<"\n";
1252  } // plane
1253 */
1254  // create 2D cheat showers in each plane
1255  std::vector<int> dummy_tjlist;
1256  for(unsigned short plane = 0; plane < tjs.NumPlanes; ++plane) {
1257  CTP_t inCTP = EncodeCTP(cstat, tpc, plane);
1258  auto ss = CreateSS(tjs, inCTP, dummy_tjlist);
1259  // fill the ShPts
1260  ss.ShPts.resize(showerHits[plane].size());
1261  for(unsigned short iht = 0; iht < showerHits[plane].size(); ++iht) {
1262  auto& hit = tjs.fHits[showerHits[plane][iht]];
1263  ss.ShPts[iht].HitIndex = showerHits[plane][iht];
1264  ss.ShPts[iht].TID = 0;
1265  ss.ShPts[iht].Chg = hit.Integral;
1266  ss.ShPts[iht].Pos[0] = hit.ArtPtr->WireID().Wire;
1267  ss.ShPts[iht].Pos[1] = hit.PeakTime * tjs.UnitsPerTick;
1268  } // iht
1269  ss.SS3ID = goodID;
1270  if(!UpdateShower("MCS", tjs, ss, true)) {
1271  std::cout<<"Failed to update 2S"<<ss.ID<<"\n";
1272  return ss3;
1273  } // UpdateShower failed
1274  // remove shower points that are far away
1275  std::vector<ShowerPoint> spts;
1276  for(auto& spt : ss.ShPts) {
1277  // don't make a tight cut right now. The shower parameterization isn't great
1278  double along = tjs.WirePitch * spt.RotPos[0];
1279  float tau = along / shMaxAlong;
1280 // auto& hit = tjs.fHits[spt.HitIndex];
1281 // if(ss.ID == 2) std::cout<<"chk "<<PrintHit(hit)<<" along "<<(int)along<<" tau "<<std::fixed<<std::setprecision(1)<<tau<<"\n";
1282  if(tau > -1 && tau < 2) {
1283  spts.push_back(spt);
1284  } else {
1285 // std::cout<<"Skip "<<PrintHit(hit)<<" along "<<(int)along<<"\n";
1286  }
1287  } // spt
1288  std::cout<<" 2S"<<ss.ID<<" shpts "<<ss.ShPts.size()<<" new "<<spts.size()<<"\n";
1289  ss.ShPts = spts;
1290  ss.NeedsUpdate = true;
1291  if(!UpdateShower("MCS", tjs, ss, true)) {
1292  std::cout<<"Failed to update 2S"<<ss.ID<<"\n";
1293  return ss3;
1294  } // UpdateShower failed
1295  if(!StoreShower("MCS", tjs, ss)) {
1296  std::cout<<"Failed to store 2S"<<ss.ID<<"\n";
1297  return ss3;
1298  } // UpdateShower failed
1299  ss3.CotIDs.push_back(ss.ID);
1300  } // plane
1301  ss3.ID = goodID;
1302  if(!UpdateShower("MCS", tjs, ss3, true)) {
1303  std::cout<<"SS3 Failed...\n";
1304  ss3.ID = 0;
1305  return ss3;
1306  }
1307  // success
1308 
1309  // now look for a parent pfp
1310  std::vector<std::pair<int, int>> pcnt;
1311  for(unsigned short plane = 0; plane < tjs.NumPlanes; ++plane) {
1312  for(auto iht : parentHits[plane]) {
1313  auto& hit = tjs.fHits[iht];
1314  if(hit.InTraj <= 0) continue;
1315  auto& tj = tjs.allTraj[hit.InTraj - 1];
1316  if(!tj.AlgMod[kMat3D]) continue;
1317  auto TInP = GetAssns(tjs, "T", tj.ID, "P");
1318  if(TInP.empty()) continue;
1319  auto& pfp = tjs.pfps[TInP[0] - 1];
1320  unsigned short indx = 0;
1321  for(indx = 0; indx < pcnt.size(); ++indx) if(pfp.ID == pcnt[indx].first) break;
1322  if(indx == pcnt.size()) {
1323  pcnt.push_back(std::make_pair(pfp.ID, 1));
1324  } else {
1325  ++pcnt[indx].second;
1326  }
1327  } // iht
1328  } // plane
1329  float close = 5;
1330  for(auto pcn : pcnt) {
1331  if(pcn.second < 6) continue;
1332  auto& pfp = tjs.pfps[pcn.first - 1];
1333  for(unsigned short end = 0; end < 2; ++end) {
1334  float sep = PosSep(pfp.XYZ[end], primVx);
1335  if(sep > close) continue;
1336  close = sep;
1337  truParentPFP = pfp.ID;
1338  }
1339  } // pcn
1340  std::cout<<"truParent P"<<truParentPFP<<" close "<<std::fixed<<std::setprecision(2)<<close<<"\n";
1341 
1342  return ss3;
1343  } // MakeCheatShower
std::vector< PFPStruct > pfps
Definition: DataStructs.h:505
Float_t ss
Definition: plot.C:23
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
int EveId(const int trackID) const
unsigned short NumPlanes
Definition: DataStructs.h:475
bool UpdateShower(std::string inFcnLabel, TjStuff &tjs, ShowerStruct &ss, bool prt)
Definition: TCShower.cxx:1104
std::vector< Trajectory > allTraj
vector of all trajectories in each plane
Definition: DataStructs.h:493
bool StoreShower(std::string inFcnLabel, TjStuff &tjs, ShowerStruct3D &ss3)
Definition: TCShower.cxx:4468
float UnitsPerTick
scale factor from Tick to WSE equivalent units
Definition: DataStructs.h:468
geo::TPCID TPCID
Definition: DataStructs.h:469
Detector simulation of raw signals on wires.
ShowerStruct3D CreateSS3(TjStuff &tjs, const geo::TPCID &tpcid)
Definition: TCShower.cxx:4553
unsigned int CTP_t
Definition: DataStructs.h:41
std::vector< TCHit > fHits
Definition: DataStructs.h:495
in close()
float WirePitch
Definition: DataStructs.h:482
double PosSep(const Point3_t &pos1, const Point3_t &pos2)
Definition: PFPUtils.cxx:1625
CTP_t EncodeCTP(unsigned int cryo, unsigned int tpc, unsigned int plane)
Definition: DataStructs.h:45
std::vector< simb::MCParticle * > MCPartList
Definition: DataStructs.h:520
ShowerStruct CreateSS(TjStuff &tjs, CTP_t inCTP, const std::vector< int > &tjl)
Definition: TCShower.cxx:4572
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:203
std::vector< int > GetAssns(const TjStuff &tjs, std::string type1Name, int id, std::string type2Name)
Definition: Utils.cxx:4079
void tca::MCParticleListUtils::MakeTruTrajPoint ( unsigned int  MCParticleListIndex,
TrajPoint tp 
)

Definition at line 1174 of file TCTruth.cxx.

References tca::TrajPoint::CTP, dir, tca::MakeBareTP(), tca::TjStuff::MCPartList, simb::MCParticle::Px(), simb::MCParticle::Py(), simb::MCParticle::Pz(), tca::SetMag(), tca::TruthMatcher::tjs, simb::MCParticle::Vx(), simb::MCParticle::Vy(), and simb::MCParticle::Vz().

1175  {
1176  // Creates a trajectory point at the start of the MCParticle with index MCParticleListIndex. The
1177  // projected length of the MCParticle in the plane coordinate system is stored in TruTp.Delta.
1178  // The calling function should specify the CTP in which this TP resides.
1179 
1180  if(MCParticleListIndex > tjs.MCPartList.size() - 1) return;
1181 
1182  const simb::MCParticle* mcp = tjs.MCPartList[MCParticleListIndex];
1183 
1184  Point3_t pos {{mcp->Vx(), mcp->Vy(), mcp->Vz()}};
1185  Vector3_t dir {{mcp->Px(), mcp->Py(), mcp->Pz()}};
1186  SetMag(dir, 1);
1187  tp = MakeBareTP(tjs, pos, dir, tp.CTP);
1188  } // MakeTruTrajPoint
double Py(const int i=0) const
Definition: MCParticle.h:235
std::array< double, 3 > Point3_t
Definition: DataStructs.h:35
double Px(const int i=0) const
Definition: MCParticle.h:234
TrajPoint MakeBareTP(TjStuff &tjs, Point3_t &pos, Vector3_t &dir, CTP_t inCTP)
Definition: Utils.cxx:3435
bool SetMag(Vector3_t &v1, double mag)
Definition: PFPUtils.cxx:1641
double Vx(const int i=0) const
Definition: MCParticle.h:225
TDirectory * dir
Definition: macro.C:5
double Pz(const int i=0) const
Definition: MCParticle.h:236
std::vector< simb::MCParticle * > MCPartList
Definition: DataStructs.h:520
double Vz(const int i=0) const
Definition: MCParticle.h:227
std::array< double, 3 > Vector3_t
Definition: DataStructs.h:36
double Vy(const int i=0) const
Definition: MCParticle.h:226
int tca::MCParticleListUtils::MCParticleStartTjID ( unsigned int  MCParticleListIndex,
CTP_t  inCTP 
)

Definition at line 1454 of file TCTruth.cxx.

References geo::CryostatID::Cryostat, tca::DecodeCTP(), tca::TjStuff::fHits, tca::TjStuff::MCPartList, geo::PlaneID::Plane, tca::TruthMatcher::tjs, tmp, and geo::TPCID::TPC.

1455  {
1456  // Finds the trajectory that has hits matched to the MC Particle and is the closest to the
1457  // MCParticle start vertex
1458 
1459  if(mcpIndex > tjs.MCPartList.size() - 1) return 0;
1460 
1461  geo::PlaneID planeID = DecodeCTP(inCTP);
1462 
1463  // tj ID and occurrence count
1464  std::vector<std::array<int, 2>> t_cnt;
1465  for(auto hit : tjs.fHits) {
1466  if(hit.InTraj <= 0) continue;
1467  if(hit.MCPartListIndex != mcpIndex) continue;
1468  if(hit.ArtPtr->WireID().TPC != planeID.TPC) continue;
1469  if(hit.ArtPtr->WireID().Plane != planeID.Plane) continue;
1470  if(hit.ArtPtr->WireID().Cryostat != planeID.Cryostat) continue;
1471  unsigned short indx = 0;
1472  for(indx = 0; indx < t_cnt.size(); ++indx) if(t_cnt[indx][0] == hit.InTraj) break;
1473  if(indx == t_cnt.size()) {
1474  // didn't find the traj ID in t_cnt so add it
1475  std::array<int, 2> tmp;
1476  tmp[0] = hit.InTraj;
1477  tmp[1] = 1;
1478  t_cnt.push_back(tmp);
1479  } else {
1480  // count occurrences of this tj ID
1481  ++t_cnt[indx][1];
1482  }
1483  } // hit
1484 
1485  if(t_cnt.empty()) return 0;
1486  unsigned short occMax = 0;
1487  unsigned short occIndx = 0;
1488  for(unsigned short ii = 0; ii < t_cnt.size(); ++ii) {
1489  auto& tcnt = t_cnt[ii];
1490  if(tcnt[1] < occMax) continue;
1491  occMax = tcnt[1];
1492  occIndx = ii;
1493  } // tcnt
1494  return t_cnt[occIndx][0];
1495 
1496  } // MCParticleStartTj
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
Float_t tmp
Definition: plot.C:37
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:258
Detector simulation of raw signals on wires.
std::vector< TCHit > fHits
Definition: DataStructs.h:495
geo::PlaneID DecodeCTP(CTP_t CTP)
Definition: DataStructs.cxx:89
std::vector< simb::MCParticle * > MCPartList
Definition: DataStructs.h:520
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:203
int tca::MCParticleListUtils::PrimaryElectronPFPID ( const geo::TPCID tpcid)

Definition at line 1374 of file TCTruth.cxx.

References tca::TjStuff::allTraj, close(), geo::CryostatID::Cryostat, tca::EncodeCTP(), sim::ParticleList::EveId(), tca::FarEnd(), tca::TjStuff::fHits, tca::GetAssns(), tca::kMat3D, tca::kUsedHits, tca::TjStuff::MCPartList, tca::TjStuff::NumPlanes, part, cheat::ParticleInventoryService::ParticleList(), tca::TjStuff::pfps, tca::PosSep2(), tca::PutTrajHitsInVector(), tca::SetIntersection(), tca::TruthMatcher::tjs, and geo::TPCID::TPC.

1375  {
1376  // Returns the ID of a pfp that has hits whose eve ID is a primary electron
1377  // and is the closest (< 5 WSE units) to the primary electron start
1378  if(tjs.MCPartList.empty()) return 0;
1380  TruthMatcher tm{tjs};
1381  for(unsigned int part = 0; part < tjs.MCPartList.size(); ++part) {
1382  auto& mcp = tjs.MCPartList[part];
1383  // require electron
1384  if(abs(mcp->PdgCode()) != 11) continue;
1385  int eveID = pi_serv->ParticleList().EveId(mcp->TrackId());
1386  if(mcp->TrackId() != eveID) continue;
1387  Point3_t start = {{mcp->Vx(), mcp->Vy(), mcp->Vz()}};
1388  auto const* SCE = lar::providerFrom<spacecharge::SpaceChargeService>();
1389  geo::Vector_t posOffsets = SCE->GetPosOffsets({start[0], start[1], start[2]});
1390  posOffsets.SetX(-posOffsets.X());
1391  start[0] += posOffsets.X();
1392  start[1] += posOffsets.Y();
1393  start[2] += posOffsets.Z();
1394  // make a list of pfps that use tjs that use these hits
1395  std::vector<int> pfplist;
1396  for(unsigned short plane = 0; plane < tjs.NumPlanes; ++plane) {
1397  CTP_t inCTP = EncodeCTP(tpcid.Cryostat, tpcid.TPC, plane);
1398  std::vector<unsigned int> mcphits = tm.PutMCPHitsInVector(part, inCTP);
1399  if(mcphits.empty()) continue;
1400  for(auto iht : mcphits) {
1401  auto& hit = tjs.fHits[iht];
1402  if(hit.InTraj <= 0) continue;
1403  // require that the tj is 3D-matched
1404  auto& tj = tjs.allTraj[hit.InTraj - 1];
1405  if(!tj.AlgMod[kMat3D]) continue;
1406  // find the number of hits that are in mcphits
1407  auto tjhits = PutTrajHitsInVector(tj, kUsedHits);
1408  auto shared = SetIntersection(tjhits, mcphits);
1409  if(shared.size() < 10) continue;
1410  // find out what pfp it is used in.
1411  auto TInP = GetAssns(tjs, "T", tj.ID, "P");
1412  if(TInP.size() != 1) continue;
1413  int pid = TInP[0];
1414  if(std::find(pfplist.begin(), pfplist.end(), pid) == pfplist.end()) pfplist.push_back(pid);
1415  } // iht
1416  } // plane
1417  if(pfplist.empty()) return 0;
1418  // Use the one that is closest to the true start position, not the
1419  // one that has the most matching hits. Electrons are likely to be
1420  // poorly reconstructed
1421  int pfpid = 0;
1422  float close = 1E6;
1423  for(auto pid : pfplist) {
1424  auto& pfp = tjs.pfps[pid - 1];
1425  unsigned short nearEnd = 1 - FarEnd(tjs, pfp, start);
1426  float sep = PosSep2(pfp.XYZ[nearEnd], start);
1427  if(sep > close) continue;
1428  close = sep;
1429  pfpid = pid;
1430  }
1431  return pfpid;
1432  } // part
1433  return 0;
1434  } // PrimaryElectronPFPID
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:167
std::array< double, 3 > Point3_t
Definition: DataStructs.h:35
std::vector< unsigned int > PutTrajHitsInVector(Trajectory const &tj, HitStatus_t hitRequest)
Definition: Utils.cxx:2283
std::vector< PFPStruct > pfps
Definition: DataStructs.h:505
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
int EveId(const int trackID) const
unsigned short NumPlanes
Definition: DataStructs.h:475
std::vector< T > SetIntersection(const std::vector< T > &set1, const std::vector< T > &set2)
Definition: Utils.h:214
unsigned short FarEnd(const TjStuff &tjs, const PFPStruct &pfp, const Point3_t &pos)
Definition: PFPUtils.cxx:2936
TString part[npart]
Definition: Style.C:32
std::vector< Trajectory > allTraj
vector of all trajectories in each plane
Definition: DataStructs.h:493
double PosSep2(const Point3_t &pos1, const Point3_t &pos2)
Definition: PFPUtils.cxx:1631
Detector simulation of raw signals on wires.
unsigned int CTP_t
Definition: DataStructs.h:41
std::vector< TCHit > fHits
Definition: DataStructs.h:495
in close()
CTP_t EncodeCTP(unsigned int cryo, unsigned int tpc, unsigned int plane)
Definition: DataStructs.h:45
std::vector< simb::MCParticle * > MCPartList
Definition: DataStructs.h:520
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:203
std::vector< int > GetAssns(const TjStuff &tjs, std::string type1Name, int id, std::string type2Name)
Definition: Utils.cxx:4079
bool tca::MCParticleListUtils::PrimaryElectronStart ( Point3_t start,
Vector3_t dir,
float &  energy 
)

Definition at line 1346 of file TCTruth.cxx.

References sim::ParticleList::EveId(), tca::TjStuff::MCPartList, part, cheat::ParticleInventoryService::ParticleList(), tca::SetMag(), and tca::TruthMatcher::tjs.

1347  {
1348  // returns the SCE corrected start position of a primary electron
1349  if(tjs.MCPartList.empty()) return false;
1351  for(unsigned int part = 0; part < tjs.MCPartList.size(); ++part) {
1352  auto& mcp = tjs.MCPartList[part];
1353  // require electron
1354  if(abs(mcp->PdgCode()) != 11) continue;
1355  int eveID = pi_serv->ParticleList().EveId(mcp->TrackId());
1356  if(mcp->TrackId() != eveID) continue;
1357  start = {{mcp->Vx(), mcp->Vy(), mcp->Vz()}};
1358  auto const* SCE = lar::providerFrom<spacecharge::SpaceChargeService>();
1359  geo::Vector_t posOffsets = SCE->GetPosOffsets({start[0], start[1], start[2]});
1360  posOffsets.SetX(-posOffsets.X());
1361  start[0] += posOffsets.X();
1362  start[1] += posOffsets.Y();
1363  start[2] += posOffsets.Z();
1364  dir = {{mcp->Px(), mcp->Py(), mcp->Pz()}};
1365  SetMag(dir, 1);
1366  energy = 1000 * (mcp->E() - mcp->Mass());
1367  return true;
1368  } // part
1369  return false;
1370  } // PrimaryElectronStart
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:167
int EveId(const int trackID) const
TString part[npart]
Definition: Style.C:32
double energy
Definition: plottest35.C:25
bool SetMag(Vector3_t &v1, double mag)
Definition: PFPUtils.cxx:1641
TDirectory * dir
Definition: macro.C:5
std::vector< simb::MCParticle * > MCPartList
Definition: DataStructs.h:520
int tca::MCParticleListUtils::PrimaryElectronTjID ( CTP_t  inCTP)

Definition at line 1437 of file TCTruth.cxx.

References sim::ParticleList::EveId(), tca::TjStuff::MCPartList, part, cheat::ParticleInventoryService::ParticleList(), and tca::TruthMatcher::tjs.

1438  {
1439  // returns the ID of a tj in inCTP that is closest to the start of a primary electron
1440  if(tjs.MCPartList.empty()) return 0;
1442  for(unsigned int part = 0; part < tjs.MCPartList.size(); ++part) {
1443  auto& mcp = tjs.MCPartList[part];
1444  // require electron
1445  if(abs(mcp->PdgCode()) != 11) continue;
1446  int eveID = pi_serv->ParticleList().EveId(mcp->TrackId());
1447  if(mcp->TrackId() != eveID) continue;
1448  return MCParticleStartTjID(part, inCTP);
1449  } // part
1450  return 0;
1451  } // PrimaryElectronTjID
int EveId(const int trackID) const
int MCParticleStartTjID(unsigned int MCParticleListIndex, CTP_t inCTP)
Definition: TCTruth.cxx:1454
TString part[npart]
Definition: Style.C:32
std::vector< simb::MCParticle * > MCPartList
Definition: DataStructs.h:520

Member Data Documentation

TjStuff& tca::MCParticleListUtils::tjs

Definition at line 86 of file TCTruth.h.


The documentation for this class was generated from the following files: