15 #include "TMathBase.h" 66 std::map<int, std::unique_ptr<ReconTrack>> reconTracks;
68 trackIt != tracks.end();
70 std::unique_ptr<ReconTrack>
track = std::make_unique<ReconTrack>(trackIt->key());
71 track->SetVertex((*trackIt)->Vertex<TVector3>());
72 track->SetEnd((*trackIt)->End<TVector3>());
73 track->SetVertexDir((*trackIt)->VertexDirection<TVector3>());
74 track->SetLength((*trackIt)->Length());
75 track->SetDirection(
Gradient(*trackIt));
76 track->SetHits(fmht.at(trackIt->key()));
77 track->SetSpacePoints(fmspt.at(trackIt->key()));
78 const std::vector<art::Ptr<recob::SpacePoint>> spsss = fmspt.at(trackIt->key());
79 reconTracks[trackIt->key()] = std::move(track);
83 double avCylinderSpacePoints = 0;
84 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator trackIt = reconTracks.begin();
85 trackIt != reconTracks.end();
88 TVector3 point = trackIt->second->Vertex();
89 TVector3 direction = trackIt->second->Direction();
94 spacePointIt != spacePoints.end();
96 const std::vector<art::Ptr<recob::Track>> spTracks = fmtsp.at(spacePointIt->key());
98 return (
int)t.key() == trackIt->first;
105 trackIt->second->AddCylinderSpacePoint(spacePointIt->key());
107 avCylinderSpacePoints += trackIt->second->CylinderSpacePointRatio();
109 avCylinderSpacePoints /= (double)reconTracks.size();
112 std::cout << std::endl <<
"Cylinder space point ratios:" << std::endl;
113 for (std::map<
int, std::unique_ptr<ReconTrack>>::
const_iterator trackIt = reconTracks.begin();
114 trackIt != reconTracks.end();
116 std::cout <<
" Track " << trackIt->first <<
" has cylinder space point ratio " 117 << trackIt->second->CylinderSpacePointRatio() <<
" (event average " 118 << avCylinderSpacePoints <<
")" << std::endl;
122 if (
fDebug > 0) std::cout << std::endl <<
"Identifying tracks:" << std::endl;
123 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator trackIt = reconTracks.begin();
124 trackIt != reconTracks.end();
126 if (trackIt->second->CylinderSpacePointRatio() / avCylinderSpacePoints <
fCylinderCut) {
128 std::cout <<
" Making track " << trackIt->first <<
" a track (Type I)" << std::endl;
129 trackIt->second->MakeTrack();
133 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator trackIt = reconTracks.begin();
134 trackIt != reconTracks.end();
136 if (trackIt->second->IsTrack())
continue;
137 for (std::map<
int, std::unique_ptr<ReconTrack>>::
const_iterator otherTrackIt =
139 otherTrackIt != reconTracks.end();
141 if (trackIt->first == otherTrackIt->first or !otherTrackIt->second->IsTrack())
continue;
142 if ((trackIt->second->Vertex() - otherTrackIt->second->Vertex()).Mag() <
fTrackVertexCut or
143 (trackIt->second->Vertex() - otherTrackIt->second->End()).Mag() <
fTrackVertexCut or
144 (trackIt->second->End() - otherTrackIt->second->Vertex()).Mag() <
fTrackVertexCut or
145 (trackIt->second->End() - otherTrackIt->second->End()).Mag() <
fTrackVertexCut) {
147 std::cout <<
" Making track " << trackIt->first <<
" a track (Type II)" << std::endl;
148 trackIt->second->MakeTrack();
156 std::vector<art::Ptr<recob::SpacePoint>> showerSpacePoints;
158 spacePointIt != spacePoints.end();
160 bool showerSpacePoint =
true;
161 const std::vector<art::Ptr<recob::Track>> spacePointTracks = fmtsp.at(spacePointIt->key());
163 trackIt != spacePointTracks.end();
165 if (reconTracks[trackIt->key()]->IsTrack()) showerSpacePoint =
false;
166 if (showerSpacePoint) showerSpacePoints.push_back(*spacePointIt);
171 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator trackIt = reconTracks.begin();
172 trackIt != reconTracks.end();
175 showerSpacePoints.begin();
176 spacePointIt != showerSpacePoints.end();
178 bool associatedSpacePoint =
false;
179 const std::vector<art::Ptr<recob::Track>> spTracks = fmtsp.at(spacePointIt->key());
181 spTrackIt != spTracks.end();
183 if ((
int)spTrackIt->key() == trackIt->first) associatedSpacePoint =
true;
184 if (associatedSpacePoint)
continue;
185 if ((
SpacePointPos(*spacePointIt) - trackIt->second->Vertex())
186 .Angle(trackIt->second->Direction()) <
fConeAngle * TMath::Pi() / 180) {
187 trackIt->second->AddForwardSpacePoint(spacePointIt->key());
188 trackIt->second->AddForwardTrack(spTracks.at(0).key());
190 if ((
SpacePointPos(*spacePointIt) - trackIt->second->Vertex())
191 .Angle(-1 * trackIt->second->Direction()) <
fConeAngle * TMath::Pi() / 180) {
192 trackIt->second->AddBackwardSpacePoint(spacePointIt->key());
193 trackIt->second->AddBackwardTrack(spTracks.at(0).key());
197 if (
fDebug > 0) std::cout << std::endl <<
"Identifying showers:" << std::endl;
198 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator trackIt = reconTracks.begin();
199 trackIt != reconTracks.end();
202 std::cout <<
" Track " << trackIt->first <<
" has space point cone size " 203 << trackIt->second->ConeSize() <<
" and track cone size " 204 << trackIt->second->TrackConeSize() << std::endl;
205 if (TMath::Abs(trackIt->second->ConeSize()) > 30 and
206 TMath::Abs(trackIt->second->TrackConeSize()) > 3) {
207 trackIt->second->MakeShower();
209 std::cout <<
" Making track " << trackIt->first <<
" a shower (Type I)" << std::endl;
210 if (trackIt->second->ConeSize() < 0) trackIt->second->FlipTrack();
215 std::cout << std::endl <<
" Shower cones:" << std::endl;
216 for (std::map<
int, std::unique_ptr<ReconTrack>>::
const_iterator trackIt = reconTracks.begin();
217 trackIt != reconTracks.end();
219 if (trackIt->second->IsShower()) {
220 if (
fDebug > 1) std::cout <<
" Track " << trackIt->first << std::endl;
221 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator otherTrackIt = reconTracks.begin();
222 otherTrackIt != reconTracks.end();
224 if (trackIt->first == otherTrackIt->first or !otherTrackIt->second->IsUndetermined())
226 if ((otherTrackIt->second->Vertex() - trackIt->second->Vertex())
227 .Angle(trackIt->second->Direction()) <
fConeAngle * TMath::Pi() / 180 or
228 (otherTrackIt->second->End() - trackIt->second->Vertex())
229 .Angle(trackIt->second->Direction()) <
fConeAngle * TMath::Pi() / 180) {
230 std::cout <<
" " << otherTrackIt->first << std::endl;
231 otherTrackIt->second->MakeShower();
233 std::cout <<
" Making track " << otherTrackIt->first <<
" a shower (Type II)" 241 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator trackIt = reconTracks.begin();
242 trackIt != reconTracks.end();
244 if (trackIt->second->IsUndetermined()) { trackIt->second->MakeShower(); }
247 std::cout << std::endl <<
"Event " <<
event <<
" track shower separation:" << std::endl;
248 std::cout <<
"Shower initial tracks are:" << std::endl;
249 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator trackIt = reconTracks.begin();
250 trackIt != reconTracks.end();
252 if (trackIt->second->IsShowerTrack()) std::cout <<
" " << trackIt->first << std::endl;
254 std::cout <<
"Track tracks are:" << std::endl;
255 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator trackIt = reconTracks.begin();
256 trackIt != reconTracks.end();
258 if (trackIt->second->IsTrack()) std::cout <<
" " << trackIt->first << std::endl;
264 bool showerHit =
true;
265 const std::vector<art::Ptr<recob::Track>> hitTracks = fmth.at(hitIt->key());
267 hitTrackIt != hitTracks.end();
269 if (reconTracks[hitTrackIt->key()]->IsTrack()) showerHit =
false;
270 if (showerHit) showerHits.push_back(*hitIt);
277 std::map<
int, std::unique_ptr<ReconTrack>>& reconTracks)
const 281 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator trackIt = reconTracks.begin();
282 trackIt != reconTracks.end();
285 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator otherTrackIt = reconTracks.begin();
286 otherTrackIt != reconTracks.end();
289 if (trackIt->first == otherTrackIt->first)
continue;
290 if ((otherTrackIt->second->Vertex() - trackIt->second->Vertex())
291 .Angle(trackIt->second->VertexDirection()) <
fConeAngle * TMath::Pi() / 180 or
292 (otherTrackIt->second->End() - trackIt->second->Vertex())
293 .Angle(trackIt->second->VertexDirection()) <
fConeAngle * TMath::Pi() / 180) {
294 trackIt->second->AddForwardTrack(otherTrackIt->first);
295 otherTrackIt->second->AddShowerTrack(trackIt->first);
297 if ((otherTrackIt->second->Vertex() - trackIt->second->Vertex())
298 .Angle(-1 * trackIt->second->VertexDirection()) <
fConeAngle * TMath::Pi() / 180 or
299 (otherTrackIt->second->End() - trackIt->second->Vertex())
300 .Angle(-1 * trackIt->second->VertexDirection()) <
fConeAngle * TMath::Pi() / 180)
301 trackIt->second->AddBackwardTrack(otherTrackIt->first);
306 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator trackIt = reconTracks.begin();
307 trackIt != reconTracks.end();
310 if (!trackIt->second->ShowerTrackCandidate())
continue;
312 std::cout <<
"Track " << trackIt->first
313 <<
" is a candidate, with shower cone tracks:" << std::endl;
314 const std::vector<int>& showerConeTracks = trackIt->second->ForwardConeTracks();
316 showerConeTrackIt != showerConeTracks.end();
318 std::cout <<
" " << *showerConeTrackIt << std::endl;
320 bool isBestCandidate =
true;
321 const std::vector<int>& showerTracks = trackIt->second->ShowerTracks();
323 showerTrackIt != showerTracks.end();
325 if (!reconTracks[*showerTrackIt]->ShowerTrackCandidate())
continue;
326 if (std::find(showerConeTracks.begin(), showerConeTracks.end(), *showerTrackIt) ==
327 showerConeTracks.end())
329 if (reconTracks[*showerTrackIt]->IsShowerTrack())
continue;
330 if (trackIt->second->TrackConeSize() < reconTracks[*showerTrackIt]->TrackConeSize())
331 isBestCandidate =
false;
334 if (isBestCandidate) trackIt->second->MakeShowerTrack();
338 std::vector<int> showerTracks;
339 for (std::map<
int, std::unique_ptr<ReconTrack>>::
iterator trackIt = reconTracks.begin();
340 trackIt != reconTracks.end();
342 if (trackIt->second->IsShowerTrack()) {
343 showerTracks.push_back(trackIt->first);
344 const std::vector<int>& coneTracks = trackIt->second->ForwardConeTracks();
346 coneTrackIt != coneTracks.end();
348 reconTracks[*coneTrackIt]->MakeShowerCone();
356 const std::unique_ptr<TVector3>&
dir)
const 360 double sumx = 0., sumy = 0., sumz = 0., sumx2 = 0., sumxy = 0., sumxz = 0.;
364 sumx += pointIt->X();
365 sumy += pointIt->Y();
366 sumz += pointIt->Z();
367 sumx2 += pointIt->X() * pointIt->X();
368 sumxy += pointIt->X() * pointIt->Y();
369 sumxz += pointIt->X() * pointIt->Z();
372 double dydx = (nhits * sumxy - sumx * sumy) / (nhits * sumx2 - sumx * sumx);
373 double yint = (sumy * sumx2 - sumx * sumxy) / (nhits * sumx2 - sumx * sumx);
374 double dzdx = (nhits * sumxz - sumx * sumz) / (nhits * sumx2 - sumx * sumx);
375 double zint = (sumz * sumx2 - sumx * sumxz) / (nhits * sumx2 - sumx * sumx);
376 TVector2 directionXY = TVector2(1, dydx).Unit(), directionXZ = TVector2(1, dzdx).Unit();
377 TVector3 direction = TVector3(1, dydx, dzdx).Unit();
378 TVector3 intercept = TVector3(0, yint, zint);
381 if (dir and TMath::Abs(direction.Angle(*dir)) > TMath::Pi() / 2.) direction *= -1;
389 std::vector<TVector3> points;
390 std::unique_ptr<TVector3>
dir;
403 std::vector<TVector3> points;
404 std::unique_ptr<TVector3>
dir;
407 spacePointIt != spacePoints.end();
415 const TVector3& direction,
416 const TVector3&
origin)
const 418 return (point - origin).Dot(direction) * direction +
origin;
424 const double* xyz = spacePoint->
XYZ();
425 return TVector3(xyz[0], xyz[1], xyz[2]);
433 TVector3 direction =
Gradient(spacePoints);
435 std::vector<double> distances;
437 spacePointIt != spacePoints.end();
441 distances.push_back((pos - proj).Mag());
444 double rms = TMath::RMS(distances.begin(), distances.end());
void reconfigure(fhicl::ParameterSet const &pset)
Read in configurable parameters from provided parameter set.
double SpacePointsRMS(const std::vector< art::Ptr< recob::SpacePoint >> &spacePoints) const
Point_t const & LocationAtPoint(size_t i) const
Access to track position at different points.
TVector3 ProjPoint(const TVector3 &point, const TVector3 &direction, const TVector3 &origin=TVector3(0, 0, 0)) const
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Vector_t VertexDirection() const
Access to track direction at different points.
for(Int_t i=0;i< nentries;i++)
std::vector< int > InitialTrackLikeSegment(std::map< int, std::unique_ptr< ReconTrack >> &reconTracks) const
TVector3 SpacePointPos(const art::Ptr< recob::SpacePoint > &spacePoint) const
Return 3D point of this space point.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
TrackShowerSeparationAlg(fhicl::ParameterSet const &pset)
T get(std::string const &key) const
const Double32_t * XYZ() const
TVector3 Gradient(const std::vector< TVector3 > &points, const std::unique_ptr< TVector3 > &dir) const
std::vector< art::Ptr< recob::Hit > > SelectShowerHits(int event, const std::vector< art::Ptr< recob::Hit >> &hits, const std::vector< art::Ptr< recob::Track >> &tracks, const std::vector< art::Ptr< recob::SpacePoint >> &spacePoints, const art::FindManyP< recob::Hit > &fmht, const art::FindManyP< recob::Track > &fmth, const art::FindManyP< recob::SpacePoint > &fmspt, const art::FindManyP< recob::Track > &fmtsp) const
constexpr Point origin()
Returns a origin position with a point of the specified type.
Event finding and building.