12 #include "fhiclcpp/ParameterSet.h"
15 #include "TMathBase.h"
23 fConeAngle = pset.get<
double>(
"ConeAngle");
24 fCylinderRadius = pset.get<
double>(
"CylinderRadius");
25 fTrackVertexCut = pset.get<
double>(
"TrackVertexCut");
26 fCylinderCut = pset.get<
double>(
"CylinderCut");
27 fShowerConeCut = pset.get<
double>(
"ShowerConeCut");
29 fDebug = pset.get<
int>(
"Debug",0);
35 const std::vector<art::Ptr<recob::SpacePoint> >& spacePoints,
36 const art::FindManyP<recob::Hit>& fmht,
37 const art::FindManyP<recob::Track>& fmth,
38 const art::FindManyP<recob::SpacePoint>& fmspt,
39 const art::FindManyP<recob::Track>& fmtsp)
const {
62 std::map<int,std::unique_ptr<ReconTrack> > reconTracks;
63 for (
std::vector<art::Ptr<recob::Track> >::const_iterator trackIt =
tracks.begin(); trackIt !=
tracks.end(); ++trackIt) {
64 std::unique_ptr<ReconTrack>
track = std::make_unique<ReconTrack>(trackIt->key());
65 track->
SetVertex((*trackIt)->Vertex<TVector3>());
66 track->
SetEnd((*trackIt)->End<TVector3>());
67 track->
SetVertexDir((*trackIt)->VertexDirection<TVector3>());
70 track->
SetHits(fmht.at(trackIt->key()));
72 const std::vector<art::Ptr<recob::SpacePoint> > spsss = fmspt.at(trackIt->key());
77 reconTracks[trackIt->key()] = std::move(track);
84 double avCylinderSpacePoints = 0;
85 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
87 TVector3 point = trackIt->second->Vertex();
88 TVector3 direction = trackIt->second->Direction();
103 for (
std::vector<art::Ptr<recob::SpacePoint> >::const_iterator spacePointIt = spacePoints.begin(); spacePointIt != spacePoints.end(); ++spacePointIt) {
104 const std::vector<art::Ptr<recob::Track> > spTracks = fmtsp.at(spacePointIt->key());
105 if (find_if(spTracks.begin(), spTracks.end(), [&trackIt](
const art::Ptr<recob::Track>& t){
return (
int)t.key() == trackIt->first; }) != spTracks.end())
108 TVector3 pos = SpacePointPos(*spacePointIt);
109 TVector3 proj = ProjPoint(pos, direction, point);
110 if ((pos-proj).Mag() < fCylinderRadius)
111 trackIt->second->AddCylinderSpacePoint(spacePointIt->key());
117 avCylinderSpacePoints += trackIt->second->CylinderSpacePointRatio();
119 avCylinderSpacePoints /= (double)reconTracks.size();
122 std::cout << std::endl <<
"Cylinder space point ratios:" << std::endl;
123 for (std::map<
int,std::unique_ptr<ReconTrack> >::const_iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt)
124 std::cout <<
" Track " << trackIt->first <<
" has cylinder space point ratio " << trackIt->second->CylinderSpacePointRatio() <<
" (event average " << avCylinderSpacePoints <<
")" << std::endl;
129 std::cout << std::endl <<
"Identifying tracks:" << std::endl;
130 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt)
131 if (trackIt->second->CylinderSpacePointRatio() / avCylinderSpacePoints < fCylinderCut) {
133 std::cout <<
" Making track " << trackIt->first <<
" a track (Type I)" << std::endl;
134 trackIt->second->MakeTrack();
149 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
150 if (trackIt->second->IsTrack())
152 for (std::map<
int,std::unique_ptr<ReconTrack> >::const_iterator otherTrackIt = reconTracks.begin(); otherTrackIt != reconTracks.end(); ++otherTrackIt) {
153 if (trackIt->first == otherTrackIt->first or !otherTrackIt->second->IsTrack())
155 if ((trackIt->second->Vertex() - otherTrackIt->second->Vertex()).Mag() < fTrackVertexCut or
156 (trackIt->second->Vertex() - otherTrackIt->second->End()).Mag() < fTrackVertexCut or
157 (trackIt->second->End() - otherTrackIt->second->Vertex()).Mag() < fTrackVertexCut or
158 (trackIt->second->End() - otherTrackIt->second->End()).Mag() < fTrackVertexCut) {
160 std::cout <<
" Making track " << trackIt->first <<
" a track (Type II)" << std::endl;
161 trackIt->second->MakeTrack();
169 std::vector<art::Ptr<recob::SpacePoint> > showerSpacePoints;
170 for (
std::vector<art::Ptr<recob::SpacePoint> >::const_iterator spacePointIt = spacePoints.begin(); spacePointIt != spacePoints.end(); ++spacePointIt) {
171 bool showerSpacePoint =
true;
172 const std::vector<art::Ptr<recob::Track> > spacePointTracks = fmtsp.at(spacePointIt->key());
173 for (
std::vector<art::Ptr<recob::Track> >::const_iterator trackIt = spacePointTracks.begin(); trackIt != spacePointTracks.end(); ++trackIt)
174 if (reconTracks[trackIt->key()]->IsTrack())
175 showerSpacePoint =
false;
176 if (showerSpacePoint)
177 showerSpacePoints.push_back(*spacePointIt);
182 double avConeSize = 0;
183 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
184 for (
std::vector<art::Ptr<recob::SpacePoint> >::const_iterator spacePointIt = showerSpacePoints.begin(); spacePointIt != showerSpacePoints.end(); ++spacePointIt) {
185 bool associatedSpacePoint =
false;
186 const std::vector<art::Ptr<recob::Track> > spTracks = fmtsp.at(spacePointIt->key());
187 for (
std::vector<art::Ptr<recob::Track> >::const_iterator spTrackIt = spTracks.begin(); spTrackIt != spTracks.end(); ++spTrackIt)
188 if ((
int)spTrackIt->key() == trackIt->first)
189 associatedSpacePoint =
true;
190 if (associatedSpacePoint)
192 if ((SpacePointPos(*spacePointIt) - trackIt->second->Vertex()).Angle(trackIt->second->Direction()) < fConeAngle * TMath::Pi() / 180) {
193 trackIt->second->AddForwardSpacePoint(spacePointIt->key());
194 trackIt->second->AddForwardTrack(spTracks.at(0).key());
196 if ((SpacePointPos(*spacePointIt) - trackIt->second->Vertex()).Angle(-1*trackIt->second->Direction()) < fConeAngle * TMath::Pi() / 180) {
197 trackIt->second->AddBackwardSpacePoint(spacePointIt->key());
198 trackIt->second->AddBackwardTrack(spTracks.at(0).key());
201 avConeSize += trackIt->second->ConeSize();
203 avConeSize /= (double)reconTracks.size();
205 std::cout << std::endl <<
"Identifying showers:" << std::endl;
206 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
218 std::cout <<
" Track " << trackIt->first <<
" has space point cone size " << trackIt->second->ConeSize() <<
" and track cone size " << trackIt->second->TrackConeSize() << std::endl;
219 if (TMath::Abs(trackIt->second->ConeSize()) > 30
and TMath::Abs(trackIt->second->TrackConeSize()) > 3) {
220 trackIt->second->MakeShower();
222 std::cout <<
" Making track " << trackIt->first <<
" a shower (Type I)" << std::endl;
223 if (trackIt->second->ConeSize() < 0)
224 trackIt->second->FlipTrack();
229 std::cout << std::endl <<
" Shower cones:" << std::endl;
230 for (std::map<
int,std::unique_ptr<ReconTrack> >::const_iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
231 if (trackIt->second->IsShower()) {
233 std::cout <<
" Track " << trackIt->first << std::endl;
234 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator otherTrackIt = reconTracks.begin(); otherTrackIt != reconTracks.end(); ++otherTrackIt) {
235 if (trackIt->first == otherTrackIt->first or !otherTrackIt->second->IsUndetermined())
237 if ((otherTrackIt->second->Vertex()-trackIt->second->Vertex()).Angle(trackIt->second->Direction()) < fConeAngle * TMath::Pi() / 180 or
238 (otherTrackIt->second->End()-trackIt->second->Vertex()).Angle(trackIt->second->Direction()) < fConeAngle * TMath::Pi() / 180) {
239 std::cout <<
" " << otherTrackIt->first << std::endl;
240 otherTrackIt->second->MakeShower();
242 std::cout <<
" Making track " << otherTrackIt->first <<
" a shower (Type II)" << std::endl;
249 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
250 if (trackIt->second->IsUndetermined()) {
253 trackIt->second->MakeShower();
257 std::cout << std::endl <<
"Event " <<
event <<
" track shower separation:" << std::endl;
258 std::cout <<
"Shower initial tracks are:" << std::endl;
259 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt)
260 if (trackIt->second->IsShowerTrack())
261 std::cout <<
" " << trackIt->first << std::endl;
263 std::cout <<
"Track tracks are:" << std::endl;
264 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt)
265 if (trackIt->second->IsTrack())
266 std::cout <<
" " << trackIt->first << std::endl;
270 for (
std::vector<art::Ptr<recob::Hit> >::const_iterator hitIt = hits.begin(); hitIt != hits.end(); ++hitIt) {
271 bool showerHit =
true;
272 const std::vector<art::Ptr<recob::Track> > hitTracks = fmth.at(hitIt->key());
273 for (
std::vector<art::Ptr<recob::Track> >::const_iterator hitTrackIt = hitTracks.begin(); hitTrackIt != hitTracks.end(); ++hitTrackIt)
274 if (reconTracks[hitTrackIt->key()]->IsTrack())
277 showerHits.push_back(*hitIt);
287 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
289 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator otherTrackIt = reconTracks.begin(); otherTrackIt != reconTracks.end(); ++otherTrackIt) {
291 if (trackIt->first == otherTrackIt->first)
293 if ((otherTrackIt->second->Vertex() - trackIt->second->Vertex()).Angle(trackIt->second->VertexDirection()) < fConeAngle * TMath::Pi() / 180 or
294 (otherTrackIt->second->End() - trackIt->second->Vertex()).Angle(trackIt->second->VertexDirection()) < fConeAngle * TMath::Pi() / 180) {
295 trackIt->second->AddForwardTrack(otherTrackIt->first);
296 otherTrackIt->second->AddShowerTrack(trackIt->first);
298 if ((otherTrackIt->second->Vertex() - trackIt->second->Vertex()).Angle(-1*trackIt->second->VertexDirection()) < fConeAngle * TMath::Pi() / 180 or
299 (otherTrackIt->second->End() - trackIt->second->Vertex()).Angle(-1*trackIt->second->VertexDirection()) < fConeAngle * TMath::Pi() / 180)
300 trackIt->second->AddBackwardTrack(otherTrackIt->first);
307 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
309 if (!trackIt->second->ShowerTrackCandidate())
312 std::cout <<
"Track " << trackIt->first <<
" is a candidate, with shower cone tracks:" << std::endl;
313 const std::vector<int>& showerConeTracks = trackIt->second->ForwardConeTracks();
314 for (std::vector<int>::const_iterator showerConeTrackIt = showerConeTracks.begin(); showerConeTrackIt != showerConeTracks.end(); ++showerConeTrackIt)
315 std::cout <<
" " << *showerConeTrackIt << std::endl;
317 bool isBestCandidate =
true;
318 const std::vector<int>& showerTracks = trackIt->second->ShowerTracks();
319 for (std::vector<int>::const_iterator showerTrackIt = showerTracks.begin(); showerTrackIt != showerTracks.end(); ++showerTrackIt) {
320 if (!reconTracks[*showerTrackIt]->ShowerTrackCandidate())
322 if (std::find(showerConeTracks.begin(), showerConeTracks.end(), *showerTrackIt) == showerConeTracks.end())
324 if (reconTracks[*showerTrackIt]->IsShowerTrack())
326 if (trackIt->second->TrackConeSize() < reconTracks[*showerTrackIt]->TrackConeSize())
327 isBestCandidate =
false;
331 trackIt->second->MakeShowerTrack();
336 std::vector<int> showerTracks;
337 for (std::map<
int,std::unique_ptr<ReconTrack> >::iterator trackIt = reconTracks.begin(); trackIt != reconTracks.end(); ++trackIt) {
338 if (trackIt->second->IsShowerTrack()) {
339 showerTracks.push_back(trackIt->first);
340 const std::vector<int>& coneTracks = trackIt->second->ForwardConeTracks();
341 for (std::vector<int>::const_iterator coneTrackIt = coneTracks.begin(); coneTrackIt != coneTracks.end(); ++coneTrackIt)
342 reconTracks[*coneTrackIt]->MakeShowerCone();
353 double sumx=0., sumy=0., sumz=0., sumx2=0., sumy2=0., sumxy=0., sumxz=0., sumyz=0.;
354 for (std::vector<TVector3>::const_iterator pointIt = points.begin(); pointIt != points.end(); ++pointIt) {
356 sumx += pointIt->X();
357 sumy += pointIt->Y();
358 sumz += pointIt->Z();
359 sumx2 += pointIt->X() * pointIt->X();
360 sumy2 += pointIt->Y() * pointIt->Y();
361 sumxy += pointIt->X() * pointIt->Y();
362 sumxz += pointIt->X() * pointIt->Z();
363 sumyz += pointIt->Y() * pointIt->Z();
366 double dydx = (nhits * sumxy - sumx * sumy) / (nhits * sumx2 - sumx * sumx);
367 double yint = (sumy * sumx2 - sumx * sumxy) / (nhits * sumx2 - sumx * sumx);
368 double dzdx = (nhits * sumxz - sumx * sumz) / (nhits * sumx2 - sumx * sumx);
369 double zint = (sumz * sumx2 - sumx * sumxz) / (nhits * sumx2 - sumx * sumx);
370 TVector2 directionXY = TVector2(1,dydx).Unit(), directionXZ = TVector2(1,dzdx).Unit();
371 TVector3 direction = TVector3(1,dydx,dzdx).Unit();
372 TVector3 intercept = TVector3(0,yint,zint);
375 if (dir
and TMath::Abs(direction.Angle(*dir)) > TMath::Pi() / 2.)
384 std::vector<TVector3> points;
385 std::unique_ptr<TVector3>
dir;
387 for (
unsigned int traj = 0; traj < track->NumberTrajectoryPoints(); ++traj)
388 points.push_back(track->LocationAtPoint<TVector3>(traj));
389 dir = std::make_unique<TVector3>(track->VertexDirection<TVector3>());
391 return Gradient(points, dir);
397 std::vector<TVector3> points;
398 std::unique_ptr<TVector3>
dir;
400 for (
std::vector<art::Ptr<recob::SpacePoint> >::const_iterator spacePointIt = spacePoints.begin(); spacePointIt != spacePoints.end(); ++spacePointIt)
401 points.push_back(SpacePointPos(*spacePointIt));
403 return Gradient(points, dir);
408 return (point-origin).Dot(direction) * direction +
origin;
412 const double* xyz = spacePoint->XYZ();
413 return TVector3(xyz[0], xyz[1], xyz[2]);
418 TVector3 point = SpacePointPos(spacePoints.at(0));
419 TVector3 direction = Gradient(spacePoints);
421 std::vector<double> distances;
422 for (
std::vector<art::Ptr<recob::SpacePoint> >::const_iterator spacePointIt = spacePoints.begin(); spacePointIt != spacePoints.end(); ++spacePointIt) {
423 TVector3 pos = SpacePointPos(*spacePointIt);
424 TVector3 proj = ProjPoint(pos, direction, point);
425 distances.push_back((pos-proj).Mag());
428 double rms = TMath::RMS(distances.begin(), distances.end());
void SetDirection(TVector3 direction)
std::vector< int > InitialTrackLikeSegment(std::map< int, std::unique_ptr< ReconTrack > > &reconTracks) const
void SetEnd(TVector3 end)
ClusterModuleLabel join with tracks
void reconfigure(fhicl::ParameterSet const &pset)
Read in configurable parameters from provided parameter set.
void SetLength(double length)
TVector3 ProjPoint(const TVector3 &point, const TVector3 &direction, const TVector3 &origin=TVector3(0, 0, 0)) const
process_name use argoneut_mc_hitfinder track
void SetSpacePoints(std::vector< art::Ptr< recob::SpacePoint > > spacePoints)
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.
void SetVertex(TVector3 vertex)
double SpacePointsRMS(const std::vector< art::Ptr< recob::SpacePoint > > &spacePoints) const
TrackShowerSeparationAlg(fhicl::ParameterSet const &pset)
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
for($it=0;$it< $RaceTrack_number;$it++)
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
void SetVertexDir(TVector3 vertexDir)
TVector3 Gradient(const std::vector< TVector3 > &points, const std::unique_ptr< TVector3 > &dir) const
void SetHits(std::vector< art::Ptr< recob::Hit > > hits)
BEGIN_PROLOG could also be cout
constexpr Point origin()
Returns a origin position with a point of the specified type.