55 for (
auto ide : ides) {
56 if (ide.energy > energy) {
75 for (
size_t it = 1; it < traj.
size(); ++it) {
85 return std::make_pair(
id, dist);
91 const float rangeCut,
const std::string &spLabel)
const{
110 vector<Ptr<SpacePoint>> spacePoints;
111 auto spacePointHandle = evt.
getHandle<vector<SpacePoint>>(spLabel);
112 if (spacePointHandle) {
120 map<int,unsigned int> neighbourMap;
124 neighbourMap[sp0->ID()] = 0;
128 if(sp0->ID() == sp1->ID())
continue;
131 const double *p0 = sp0->XYZ();
132 const double *p1 = sp1->XYZ();
135 const float dx = p1[0] - p0[0];
136 const float dy = p1[1] - p0[1];
137 const float dz = p1[2] - p0[2];
138 const float dist = sqrt(dx*dx + dy*dy + dz*dz);
141 ++neighbourMap[sp0->ID()];
151 vector<Ptr<SpacePoint>> allSpacePoints;
152 auto spacePointHandle = evt.
getHandle<vector<SpacePoint>>(spLabel);
153 if (spacePointHandle) {
161 std::vector<art::Ptr<recob::SpacePoint>> vec;
163 vec.push_back(
m.second);
170 std::vector<std::map<int,unsigned int>>
result;
172 for(
unsigned int m = 0;
m < rangeCuts.size(); ++
m){
173 result.push_back(map<int,unsigned int>());
177 for(
auto &
m : result){
181 if(sp0->ID() == sp1->ID())
continue;
183 const double *p0 = sp0->XYZ();
184 const double *p1 = sp1->XYZ();
186 const float dx = p1[0] - p0[0];
187 const float dy = p1[1] - p0[1];
188 const float dz = p1[2] - p0[2];
189 const float dist = sqrt(dx*dx + dy*dy + dz*dz);
191 for(
unsigned int r = 0;
r < rangeCuts.size(); ++
r){
192 if(dist < rangeCuts[
r]){
193 result[
r][sp0->ID()] = result[
r][sp0->ID()] + 1;
203 std::vector<art::Ptr<recob::SpacePoint>> allSpacePoints;
204 auto spacePointHandle = evt.
getHandle<std::vector<recob::SpacePoint>>(spLabel);
205 if (spacePointHandle) {
213 std::map<int,int> closestID;
214 std::map<int,float> closestDistance;
219 closestID[sp0->ID()] = 0;
220 closestDistance[sp0->ID()] = 99999;
222 if(sp0->ID() == sp1->ID())
continue;
224 const double *p0 = sp0->XYZ();
225 const double *p1 = sp1->XYZ();
227 const float dx = p1[0] - p0[0];
228 const float dy = p1[1] - p0[1];
229 const float dz = p1[2] - p0[2];
230 const float dist = sqrt(dx*dx + dy*dy + dz*dz);
231 if(dist < closestDistance[sp0->ID()]){
232 closestDistance[sp0->ID()] =
dist;
233 closestID[sp0->ID()] = sp1->ID();
243 std::vector<art::Ptr<recob::SpacePoint>> allSpacePoints;
244 auto spacePointHandle = evt.
getHandle<std::vector<recob::SpacePoint>>(spLabel);
245 if (spacePointHandle) {
254 vector<Ptr<SpacePoint>> vec;
256 vec.push_back(
m.second);
263 std::map<int,int> closestID;
264 std::map<int,int> secondID;
269 int thisSP = sp0->ID();
272 float closestDist = 99999;
273 float secondDist = 99999;
275 if(thisSP == sp1->ID())
continue;
277 const double *p0 = sp0->XYZ();
278 const double *p1 = sp1->XYZ();
280 const float dx = p1[0] - p0[0];
281 const float dy = p1[1] - p0[1];
282 const float dz = p1[2] - p0[2];
283 const float dist = sqrt(dx*dx + dy*dy + dz*dz);
284 if(dist < closestDist){
285 secondDist = closestDist;
290 else if(dist < secondDist){
295 closestID.insert(std::make_pair(thisSP,closest));
296 secondID.insert(std::make_pair(thisSP,second));
298 map<int,pair<int,int>> finalMap;
299 for(
unsigned int m = 0;
m < closestID.size(); ++
m){
300 finalMap[
m] = std::make_pair(closestID[
m],secondID[m]);
308 TVector3 basePos(baseNode.XYZ());
309 TVector3 neighbour1Pos(n1.XYZ());
310 TVector3 neighbour2Pos(n2.XYZ());
311 TVector3 baseToNeighbour1 = neighbour1Pos - basePos;
312 TVector3 baseToNeighbour2 = neighbour2Pos - basePos;
313 dotProduct = baseToNeighbour1.Dot(baseToNeighbour2);
314 angle = baseToNeighbour1.Angle(baseToNeighbour2);
323 map<unsigned int, float> ret;
325 for (
size_t spIdx = 0; spIdx < spacePoints.size(); ++spIdx) {
328 charge +=
hit->Integral();
330 ret[spacePoints[spIdx]->ID()] = charge;
340 vector<Ptr<SpacePoint>> spacePoints;
341 auto spacePointHandle = evt.
getHandle<vector<SpacePoint>>(spLabel);
342 if (!spacePointHandle) {
344 <<
"Could not find spacepoints with module label " 348 art::FindManyP<Hit> fmp(spacePointHandle, evt, spLabel);
349 vector<vector<Ptr<Hit>>> sp2Hit(spacePoints.size());
350 for (
size_t spIdx = 0; spIdx < sp2Hit.size(); ++spIdx) {
351 sp2Hit[spIdx] = fmp.at(spIdx);
361 map<unsigned int, float> ret;
365 const art::FindManyP<Hit> sp2Hit(allSP, evt, spLabel);
367 for (
size_t itSP = 0; itSP < allSP->size(); ++itSP) {
369 float chargeRMS = 0.0;
370 const vector<Ptr<Hit>> spHits = sp2Hit.at(itSP);
371 unsigned int nHits = spHits.size();
372 for (
auto const hit : spHits) {
373 chargeRMS +=
hit->RMS();
375 ret[sp.ID()] = chargeRMS /
static_cast<float>(nHits);
388 map<unsigned int, int> ret;
390 for (
size_t spIdx = 0; spIdx < spacePoints.size(); ++spIdx) {
392 std::map<unsigned int, float> trueParticles;
395 for (
auto ide : ides) {
396 int id = ide.trackID;
397 if (trueParticles.count(
id)) trueParticles[
id] += ide.energy;
398 else trueParticles[
id] = ide.energy;
401 ret[spacePoints[spIdx]->ID()] = std::max_element(trueParticles.begin(), trueParticles.end(), [](
const pair<unsigned int, float> &lhs,
402 const pair<unsigned int, float> &rhs) {
return lhs.second < rhs.second; })->first;
412 vector<Ptr<SpacePoint>> spacePoints;
413 auto spacePointHandle = evt.
getHandle<vector<SpacePoint>>(spLabel);
414 if (!spacePointHandle) {
417 <<
"Could not find spacepoints with module label " 421 art::FindManyP<Hit> fmp(spacePointHandle, evt, spLabel);
422 vector<vector<Ptr<Hit>>> sp2Hit(spacePoints.size());
423 for (
size_t spIdx = 0; spIdx < sp2Hit.size(); ++spIdx) {
424 sp2Hit[spIdx] = fmp.at(spIdx);
426 return GetTrueG4ID(clockData, spacePoints, sp2Hit);
436 map<unsigned int, int> ret;
438 for (
size_t spIdx = 0; spIdx < spacePoints.size(); ++spIdx) {
440 std::map<unsigned int, unsigned int> trueParticleHits;
443 for (
auto ide : ides) {
444 int id = ide.trackID;
445 if (trueParticleHits.count(
id)) trueParticleHits[
id] += 1;
446 else trueParticleHits[id] = 1;
449 ret[spacePoints[spIdx]->ID()] = std::max_element(trueParticleHits.begin(), trueParticleHits.end(), [](
const pair<unsigned int, unsigned> &lhs,
450 const pair<unsigned int, unsigned int> &rhs) {
return lhs.second < rhs.second; })->first;
460 vector<Ptr<SpacePoint>> spacePoints;
461 auto spacePointHandle = evt.
getHandle<vector<SpacePoint>>(spLabel);
462 if (!spacePointHandle) {
465 <<
"Could not find spacepoints with module label " 469 art::FindManyP<Hit> fmp(spacePointHandle, evt, spLabel);
470 vector<vector<Ptr<Hit>>> sp2Hit(spacePoints.size());
471 for (
size_t spIdx = 0; spIdx < sp2Hit.size(); ++spIdx) {
472 sp2Hit[spIdx] = fmp.at(spIdx);
482 std::map<unsigned int, int> idMap;
486 map<unsigned int,int> pdgMap;
491 for(
const pair<unsigned int, int>
m : idMap){
493 if(
m.second == 0) std::cout <<
"Getting particle with ID " <<
m.second <<
" for space point " <<
m.first <<
std::endl;
495 int trackID =
m.second;
496 if(useAbsoluteTrackID || trackID >= 0){
497 trackID =
abs(trackID);
502 pdgMap.insert(std::make_pair(
m.first,pdg));
518 map<unsigned int, vector<float>> ret;
519 for (
size_t spIdx = 0; spIdx < spacePoints.size(); ++spIdx) {
523 int offset = 3 *
hit->WireID().Plane;
525 if (feat[offset+2] != 0) {
526 std::ostringstream
err;
527 err <<
"2D features for plane " <<
hit->WireID().Plane <<
" have already been " 529 throw std::runtime_error(err.str());
531 feat[offset] =
hit->WireID().Wire;
532 feat[offset+1] =
hit->PeakTime();
533 feat[offset+2] =
hit->Integral();
535 ret[spacePoints[spIdx]->ID()] = feat;
546 vector<vector<float>> allViews;
547 allViews.push_back(pm.
fPEX);
548 allViews.push_back(pm.
fPEY);
549 allViews.push_back(pm.
fPEZ);
551 const unsigned int nWires = pm.
fNWire;
552 const unsigned int nTDCs = pm.
fNTdc;
554 vector<GCNGraph> outputGraphs;
556 for(
unsigned int v = 0; v < allViews.size(); ++v){
560 for(
unsigned int w = 0;
w < nWires; ++
w){
562 for(
unsigned int t = 0;
t < nTDCs; ++
t){
564 const unsigned int index =
w*nTDCs +
t;
565 const float charge = allViews[v][
index];
568 if(charge < chargeThreshold)
continue;
579 outputGraphs.push_back(newGraph);
587 map<unsigned int,unsigned int> neighbourMap;
592 neighbourMap[n1] = 0;
594 const unsigned int w1 =
static_cast<unsigned int>(node1.
GetPosition()[0]);
595 const unsigned int t1 =
static_cast<unsigned int>(node1.
GetPosition()[1]);
600 if(n1 == n2)
continue;
603 const unsigned int w2 =
static_cast<unsigned int>(node2.
GetPosition()[0]);
604 const unsigned int t2 =
static_cast<unsigned int>(node2.
GetPosition()[1]);
626 if(w2 <= w1 + npixel && w2 >= w1 - npixel){
627 if(t2 <= t1 + npixel && t2 >= t1 - npixel){
652 dirTruth->resize(spacePoints.size());
654 vector<pair<size_t, float>>
dist;
656 vector<int> closestTrajPoint(spacePoints.size(), -1);
660 size_t nMismatched(0), nNoHit(0), nGood(0);
662 for (
size_t spIdx = 0; spIdx < spacePoints.size(); ++spIdx) {
664 if (spIdx != (
size_t)spacePoints[spIdx]->ID()) {
666 << spIdx <<
" mismatched with spacepoint ID " 667 << spacePoints[spIdx]->ID();
686 bool firstHit =
true;
696 trueParticleID = trueID;
699 else if (trueParticleID != trueID) {
716 dist.push_back(std::make_pair(spIdx, closest.second));
717 trueIDs[spIdx] =
abs(trueParticleID);
718 closestTrajPoint[spIdx] = closest.first;
719 ret[spIdx] = closest.second;
756 for (
size_t spIdx = 0; spIdx < spacePoints.size(); ++spIdx) {
758 if (ret[spIdx] && dirTruth) {
761 for (
size_t it = 0; it < 3; ++it) {
762 dirTruth->at(spIdx).push_back(dir[it]);
768 std::cout <<
"There were " << nGood <<
" valid spacepoints, " << nNoHit
770 <<
" spacepoints with no associated hits or noise hits, and " << nMismatched
771 <<
" spacepoints produced from mismatched hits." <<
std::endl;
780 const std::set<unsigned int>& particles)
const {
783 map<unsigned int, unsigned int> ret;
784 for (
int p : particles) {
785 if (
p == 0)
continue;
802 set<int> allIDs = trackIDs;
807 for (
int id : trackIDs) {
809 while (p->
Mother() != 0) {
815 for (
int id : allIDs) {
static constexpr double g
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
std::vector< float > fPEY
Vector of Y PE measurements for pixels.
Handle< PROD > getHandle(SelectorBase const &) const
const simb::MCTrajectory & Trajectory() const
const simb::MCParticle * TrackIdToParticle_P(int id) const
static std::vector< ptruth > GetParticleTree(const cvn::GCNGraph *g)
double SqDist(const Line_t &line, const Point_t &pt) const
unsigned int fNWire
Number of wires, length of pixel map.
Representation of a simple 3D line segment Defines a finite 3D straight line by having the start and ...
GCNGraph, basic input for the GCN.
std::map< unsigned int, std::vector< float > > Get2DFeatures(std::vector< art::Ptr< recob::SpacePoint >> const &spacePoints, std::vector< std::vector< art::Ptr< recob::Hit >>> const &sp2Hit) const
Get 2D hit features for a given spacepoint.
std::map< unsigned int, float > GetSpacePointChargeMap(std::vector< art::Ptr< recob::SpacePoint >> const &spacePoints, std::vector< std::vector< art::Ptr< recob::Hit >>> const &sp2Hit) const
Use the association between space points and hits to return a charge.
void AddNode(std::vector< float > position, std::vector< float > features)
Add a new node.
std::vector< float > GetNodeGroundTruth(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::SpacePoint >> const &spacePoints, std::vector< std::vector< art::Ptr< recob::Hit >>> const &spToHit, float distCut, std::vector< std::vector< float >> *dirTruth=nullptr) const
Get ground truth for spacepoint deghosting graph network.
const std::vector< float > GetGroundTruth() const
Get the node truth.
std::pair< unsigned int, float > GetClosestApproach(const recob::SpacePoint sp, const simb::MCParticle p) const
Get closest trajectory point for true particle given reconstructed spacepoint.
std::string Process() const
Utility class for truth labels.
std::map< int, std::pair< int, int > > GetTwoNearestNeighbours(art::Event const &evt, const std::string &spLabel) const
Get the two nearest neighbours to use for calcuation of angles between them and the node in question...
std::map< unsigned int, unsigned int > GetParticleFlowMap(const std::set< unsigned int > &particles) const
Get hierarchy map from set of particles.
std::vector< float > fPEZ
Vector of Y PE measurements for pixels.
std::map< int, int > GetNearestNeighbours(art::Event const &evt, const std::string &spLabel) const
Get the nearest neighbour map for the spacepoints. Returns a map of <nose_spacepoint_id,nearest_neighbour_spacepoint_id>
simb::MCParticle TrackIdToParticle(int const id) const
std::string EndProcess() const
std::map< unsigned int, int > GetTruePDG(detinfo::DetectorClocksData const &clockData, art::Event const &evt, const std::string &spLabel, bool useAbsoluteTrackID, bool useHits) const
Get the true pdg code for each spacepoint.
std::map< int, unsigned int > GetAllNeighbours(art::Event const &evt, const float rangeCut, const std::string &spLabel) const
double P(const int i=0) const
std::vector< float > fPEX
Vector of X PE measurements for pixels.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
unsigned int GetSpacePointNeighbours(const recob::SpacePoint &sp, art::Event const &evt, const float rangeCut, const std::string &spLabel) const
Get the number of neighbours within rangeCut cm of this space point.
static int max(int a, int b)
const TLorentzVector & Position(const size_type) const
The accessor methods described above.
void GetAngleAndDotProduct(const recob::SpacePoint &baseNode, const recob::SpacePoint &n1, const recob::SpacePoint &n2, float &dotProduct, float &angle) const
Get the angle and the dot product between the vector from the base node to its neighbours.
void err(const char *fmt,...)
Detector simulation of raw signals on wires.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
double Vx(const int i=0) const
Declaration of signal hit object.
const GCNGraphNode & GetNode(const unsigned int index) const
Access nodes.
int GetTrackIDFromHit(detinfo::DetectorClocksData const &clockData, const recob::Hit &) const
Get primary true G4 ID for hit.
Contains all timing reference information for the detector.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
std::map< unsigned int, int > GetTrueG4IDFromHits(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::SpacePoint >> const &spacePoints, std::vector< std::vector< art::Ptr< recob::Hit >>> const &sp2Hit) const
Get the true G4 ID for each spacepoint using energy matching.
PixelMap, basic input to CVN neural net.
double Vz(const int i=0) const
std::vector< cvn::GCNGraph > ExtractGraphsFromPixelMap(const cvn::PixelMap &pm, const float chargeThreshold) const
Convert a pixel map into three 2D GCNGraph objects.
std::vector< std::map< int, unsigned int > > GetNeighboursForRadii(art::Event const &evt, const std::vector< float > &rangeCuts, const std::string &spLabel) const
Gets the number of nearest neigbours for each space point for a vector of cut values. Much more efficient that using the above functions multiple times.
Utilities for calculating feature values for the GCN.
const std::vector< float > GetPosition() const
Get the node position, features or ground truth.
2D representation of charge deposited in the TDC/wire plane
const unsigned int GetNumberOfNodes() const
Get the number of nodes.
unsigned int fNTdc
Number of tdcs, width of pixel map.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
second_as<> second
Type of time stored in seconds, in double precision.
std::map< unsigned int, float > GetSpacePointMeanHitRMSMap(art::Event const &evt, const std::string &spLabel) const
std::map< unsigned int, unsigned int > Get2DGraphNeighbourMap(const cvn::GCNGraph &g, const unsigned int npixel) const
Get the neighbours map <graph node, neighbours> for the three 2D graph in 2 box (npixel+1) around the...
const TLorentzVector & Momentum(const size_type) const
double Vy(const int i=0) const
geoalgo::GeoAlgo fGeoAlgo
QTextStream & endl(QTextStream &s)
std::map< unsigned int, int > GetTrueG4ID(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::SpacePoint >> const &spacePoints, std::vector< std::vector< art::Ptr< recob::Hit >>> const &sp2Hit) const
Get the true G4 ID for each spacepoint using energy matching.