58 std::map<int,std::unique_ptr<ReconTrack> > reconTracks;
60 std::unique_ptr<ReconTrack>
track = std::make_unique<ReconTrack>(trackIt->key());
61 track->SetVertex((*trackIt)->Vertex<TVector3>());
62 track->SetEnd((*trackIt)->End<TVector3>());
63 track->SetVertexDir((*trackIt)->VertexDirection<TVector3>());
64 track->SetLength((*trackIt)->Length());
65 track->SetDirection(
Gradient(*trackIt));
66 track->SetHits(fmht.at(trackIt->key()));
67 track->SetSpacePoints(fmspt.at(trackIt->key()));
68 const std::vector<art::Ptr<recob::SpacePoint> > spsss = fmspt.at(trackIt->key());
73 reconTracks[trackIt->key()] = std::move(track);
80 double avCylinderSpacePoints = 0;
81 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
83 TVector3 point = trackIt->second->Vertex();
84 TVector3 direction = trackIt->second->Direction();
100 const std::vector<art::Ptr<recob::Track> > spTracks = fmtsp.at(spacePointIt->key());
101 if (find_if(spTracks.begin(), spTracks.end(), [&trackIt](
const art::Ptr<recob::Track>& t){
return (
int)t.key() == trackIt->first; }) != spTracks.end())
107 trackIt->second->AddCylinderSpacePoint(spacePointIt->key());
113 avCylinderSpacePoints += trackIt->second->CylinderSpacePointRatio();
115 avCylinderSpacePoints /= (double)reconTracks.size();
118 std::cout << std::endl <<
"Cylinder space point ratios:" << std::endl;
119 for (std::map<
int,std::unique_ptr<ReconTrack> >::
const_iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt)
120 std::cout <<
" Track " << trackIt->first <<
" has cylinder space point ratio " << trackIt->second->CylinderSpacePointRatio() <<
" (event average " << avCylinderSpacePoints <<
")" << std::endl;
125 std::cout << std::endl <<
"Identifying tracks:" << std::endl;
126 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt)
127 if (trackIt->second->CylinderSpacePointRatio() / avCylinderSpacePoints <
fCylinderCut) {
129 std::cout <<
" Making track " << trackIt->first <<
" a track (Type I)" << std::endl;
130 trackIt->second->MakeTrack();
145 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
146 if (trackIt->second->IsTrack())
148 for (std::map<
int,std::unique_ptr<ReconTrack> >::
const_iterator otherTrackIt = reconTracks.begin(); otherTrackIt != reconTracks.end(); ++otherTrackIt) {
149 if (trackIt->first == otherTrackIt->first or !otherTrackIt->second->IsTrack())
151 if ((trackIt->second->Vertex() - otherTrackIt->second->Vertex()).Mag() <
fTrackVertexCut or
152 (trackIt->second->Vertex() - otherTrackIt->second->End()).Mag() <
fTrackVertexCut or
153 (trackIt->second->End() - otherTrackIt->second->Vertex()).Mag() <
fTrackVertexCut or
154 (trackIt->second->End() - otherTrackIt->second->End()).Mag() <
fTrackVertexCut) {
156 std::cout <<
" Making track " << trackIt->first <<
" a track (Type II)" << std::endl;
157 trackIt->second->MakeTrack();
165 std::vector<art::Ptr<recob::SpacePoint> > showerSpacePoints;
167 bool showerSpacePoint =
true;
168 const std::vector<art::Ptr<recob::Track> > spacePointTracks = fmtsp.at(spacePointIt->key());
170 if (reconTracks[trackIt->key()]->IsTrack())
171 showerSpacePoint =
false;
172 if (showerSpacePoint)
173 showerSpacePoints.push_back(*spacePointIt);
178 double avConeSize = 0;
179 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
181 bool associatedSpacePoint =
false;
182 const std::vector<art::Ptr<recob::Track> > spTracks = fmtsp.at(spacePointIt->key());
184 if ((
int)spTrackIt->key() == trackIt->first)
185 associatedSpacePoint =
true;
186 if (associatedSpacePoint)
188 if ((
SpacePointPos(*spacePointIt) - trackIt->second->Vertex()).Angle(trackIt->second->Direction()) <
fConeAngle * TMath::Pi() / 180) {
189 trackIt->second->AddForwardSpacePoint(spacePointIt->key());
190 trackIt->second->AddForwardTrack(spTracks.at(0).key());
192 if ((
SpacePointPos(*spacePointIt) - trackIt->second->Vertex()).Angle(-1*trackIt->second->Direction()) <
fConeAngle * TMath::Pi() / 180) {
193 trackIt->second->AddBackwardSpacePoint(spacePointIt->key());
194 trackIt->second->AddBackwardTrack(spTracks.at(0).key());
197 avConeSize += trackIt->second->ConeSize();
199 avConeSize /= (double)reconTracks.size();
201 std::cout << std::endl <<
"Identifying showers:" << std::endl;
202 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
214 std::cout <<
" Track " << trackIt->first <<
" has space point cone size " << trackIt->second->ConeSize() <<
" and track cone size " << trackIt->second->TrackConeSize() << std::endl;
215 if (TMath::Abs(trackIt->second->ConeSize()) > 30 and TMath::Abs(trackIt->second->TrackConeSize()) > 3) {
216 trackIt->second->MakeShower();
218 std::cout <<
" Making track " << trackIt->first <<
" a shower (Type I)" << std::endl;
219 if (trackIt->second->ConeSize() < 0)
220 trackIt->second->FlipTrack();
225 std::cout << std::endl <<
" Shower cones:" << std::endl;
226 for (std::map<
int,std::unique_ptr<ReconTrack> >::
const_iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
227 if (trackIt->second->IsShower()) {
229 std::cout <<
" Track " << trackIt->first << std::endl;
230 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator otherTrackIt = reconTracks.begin(); otherTrackIt != reconTracks.end(); ++otherTrackIt) {
231 if (trackIt->first == otherTrackIt->first or !otherTrackIt->second->IsUndetermined())
233 if ((otherTrackIt->second->Vertex()-trackIt->second->Vertex()).Angle(trackIt->second->Direction()) <
fConeAngle * TMath::Pi() / 180 or
234 (otherTrackIt->second->End()-trackIt->second->Vertex()).Angle(trackIt->second->Direction()) <
fConeAngle * TMath::Pi() / 180) {
235 std::cout <<
" " << otherTrackIt->first << std::endl;
236 otherTrackIt->second->MakeShower();
238 std::cout <<
" Making track " << otherTrackIt->first <<
" a shower (Type II)" << std::endl;
245 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
246 if (trackIt->second->IsUndetermined()) {
249 trackIt->second->MakeShower();
253 std::cout << std::endl <<
"Event " <<
event <<
" track shower separation:" << std::endl;
254 std::cout <<
"Shower initial tracks are:" << std::endl;
255 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt)
256 if (trackIt->second->IsShowerTrack())
257 std::cout <<
" " << trackIt->first << std::endl;
259 std::cout <<
"Track tracks are:" << std::endl;
260 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt)
261 if (trackIt->second->IsTrack())
262 std::cout <<
" " << trackIt->first << std::endl;
267 bool showerHit =
true;
268 const std::vector<art::Ptr<recob::Track> > hitTracks = fmth.at(hitIt->key());
270 if (reconTracks[hitTrackIt->key()]->IsTrack())
273 showerHits.push_back(*hitIt);
283 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
285 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator otherTrackIt = reconTracks.begin(); otherTrackIt != reconTracks.end(); ++otherTrackIt) {
287 if (trackIt->first == otherTrackIt->first)
289 if ((otherTrackIt->second->Vertex() - trackIt->second->Vertex()).Angle(trackIt->second->VertexDirection()) <
fConeAngle * TMath::Pi() / 180 or
290 (otherTrackIt->second->End() - trackIt->second->Vertex()).Angle(trackIt->second->VertexDirection()) <
fConeAngle * TMath::Pi() / 180) {
291 trackIt->second->AddForwardTrack(otherTrackIt->first);
292 otherTrackIt->second->AddShowerTrack(trackIt->first);
294 if ((otherTrackIt->second->Vertex() - trackIt->second->Vertex()).Angle(-1*trackIt->second->VertexDirection()) <
fConeAngle * TMath::Pi() / 180 or
295 (otherTrackIt->second->End() - trackIt->second->Vertex()).Angle(-1*trackIt->second->VertexDirection()) <
fConeAngle * TMath::Pi() / 180)
296 trackIt->second->AddBackwardTrack(otherTrackIt->first);
303 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
305 if (!trackIt->second->ShowerTrackCandidate())
308 std::cout <<
"Track " << trackIt->first <<
" is a candidate, with shower cone tracks:" << std::endl;
309 const std::vector<int>& showerConeTracks = trackIt->second->ForwardConeTracks();
311 std::cout <<
" " << *showerConeTrackIt << std::endl;
313 bool isBestCandidate =
true;
314 const std::vector<int>& showerTracks = trackIt->second->ShowerTracks();
316 if (!reconTracks[*showerTrackIt]->ShowerTrackCandidate())
318 if (std::find(showerConeTracks.begin(), showerConeTracks.end(), *showerTrackIt) == showerConeTracks.end())
320 if (reconTracks[*showerTrackIt]->IsShowerTrack())
322 if (trackIt->second->TrackConeSize() < reconTracks[*showerTrackIt]->TrackConeSize())
323 isBestCandidate =
false;
327 trackIt->second->MakeShowerTrack();
332 std::vector<int> showerTracks;
333 for (std::map<
int,std::unique_ptr<ReconTrack> >::
iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
334 if (trackIt->second->IsShowerTrack()) {
335 showerTracks.push_back(trackIt->first);
336 const std::vector<int>& coneTracks = trackIt->second->ForwardConeTracks();
338 reconTracks[*coneTrackIt]->MakeShowerCone();
349 double sumx=0., sumy=0., sumz=0., sumx2=0., sumy2=0., sumxy=0., sumxz=0., sumyz=0.;
352 sumx += pointIt->X();
353 sumy += pointIt->Y();
354 sumz += pointIt->Z();
355 sumx2 += pointIt->X() * pointIt->X();
356 sumy2 += pointIt->Y() * pointIt->Y();
357 sumxy += pointIt->X() * pointIt->Y();
358 sumxz += pointIt->X() * pointIt->Z();
359 sumyz += pointIt->Y() * pointIt->Z();
362 double dydx = (nhits * sumxy - sumx * sumy) / (nhits * sumx2 - sumx * sumx);
363 double yint = (sumy * sumx2 - sumx * sumxy) / (nhits * sumx2 - sumx * sumx);
364 double dzdx = (nhits * sumxz - sumx * sumz) / (nhits * sumx2 - sumx * sumx);
365 double zint = (sumz * sumx2 - sumx * sumxz) / (nhits * sumx2 - sumx * sumx);
366 TVector2 directionXY = TVector2(1,dydx).Unit(), directionXZ = TVector2(1,dzdx).Unit();
367 TVector3 direction = TVector3(1,dydx,dzdx).Unit();
368 TVector3 intercept = TVector3(0,yint,zint);
371 if (dir and TMath::Abs(direction.Angle(*dir)) > TMath::Pi() / 2.)
380 std::vector<TVector3> points;
381 std::unique_ptr<TVector3>
dir;
393 std::vector<TVector3> points;
394 std::unique_ptr<TVector3>
dir;
404 return (point-origin).Dot(direction) * direction +
origin;
408 const double* xyz = spacePoint->
XYZ();
409 return TVector3(xyz[0], xyz[1], xyz[2]);
415 TVector3 direction =
Gradient(spacePoints);
417 std::vector<double> distances;
421 distances.push_back((pos-proj).Mag());
424 double rms = TMath::RMS(distances.begin(), distances.end());
TVector3 ProjPoint(const TVector3 &point, const TVector3 &direction, const TVector3 &origin=TVector3(0, 0, 0))
TVector3 SpacePointPos(const art::Ptr< recob::SpacePoint > &spacePoint)
Return 3D point of this space point.
void reconfigure(fhicl::ParameterSet const &pset)
Read in configurable parameters from provided parameter set.
Point_t const & LocationAtPoint(size_t i) const
Access to track position at different points.
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
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)
Vector_t VertexDirection() const
Access to track direction at different points.
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
TVector3 Gradient(const std::vector< TVector3 > &points, const std::unique_ptr< TVector3 > &dir)
const Double32_t * XYZ() const
double SpacePointsRMS(const std::vector< art::Ptr< recob::SpacePoint > > &spacePoints)
std::vector< int > InitialTrackLikeSegment(std::map< int, std::unique_ptr< ReconTrack > > &reconTracks)
constexpr Point origin()
Returns a origin position with a point of the specified type.
Event finding and building.