15 #include "TMathBase.h" 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;
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>());
68 track->SetLength((*trackIt)->Length());
69 track->SetDirection(
Gradient(*trackIt));
70 track->SetHits(fmht.at(trackIt->key()));
71 track->SetSpacePoints(fmspt.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();
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())
109 TVector3 proj =
ProjPoint(pos, direction, point);
111 trackIt->second->AddCylinderSpacePoint(spacePointIt->key());
117 avCylinderSpacePoints += trackIt->second->CylinderSpacePointRatio();
119 avCylinderSpacePoints /= (double)reconTracks.size();
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;
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;
171 bool showerSpacePoint =
true;
172 const std::vector<art::Ptr<recob::Track> > spacePointTracks = fmtsp.at(spacePointIt->key());
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) {
185 bool associatedSpacePoint =
false;
186 const std::vector<art::Ptr<recob::Track> > spTracks = fmtsp.at(spacePointIt->key());
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;
271 bool showerHit =
true;
272 const std::vector<art::Ptr<recob::Track> > hitTracks = fmth.at(hitIt->key());
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();
315 std::cout <<
" " << *showerConeTrackIt <<
std::endl;
317 bool isBestCandidate =
true;
318 const std::vector<int>& showerTracks = trackIt->second->ShowerTracks();
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();
342 reconTracks[*coneTrackIt]->MakeShowerCone();
353 double sumx=0., sumy=0., sumz=0., sumx2=0., sumy2=0., sumxy=0., sumxz=0., sumyz=0.;
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;
397 std::vector<TVector3> points;
398 std::unique_ptr<TVector3>
dir;
408 return (point-origin).Dot(direction) * direction +
origin;
412 const double* xyz = spacePoint->
XYZ();
413 return TVector3(xyz[0], xyz[1], xyz[2]);
421 std::vector<double> distances;
424 TVector3 proj =
ProjPoint(pos, direction, point);
425 distances.push_back((pos-proj).Mag());
428 double rms = TMath::RMS(distances.begin(), distances.end());
std::vector< int > InitialTrackLikeSegment(std::map< int, std::unique_ptr< ReconTrack > > &reconTracks) const
void reconfigure(fhicl::ParameterSet const &pset)
Read in configurable parameters from provided parameter set.
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Point_t const & LocationAtPoint(size_t i) const
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
TVector3 SpacePointPos(const art::Ptr< recob::SpacePoint > &spacePoint) const
Return 3D point of this space point.
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
T get(std::string const &key) const
for(std::string line;std::getline(inFile, line);)
const Double32_t * XYZ() const
TVector3 Gradient(const std::vector< TVector3 > &points, const std::unique_ptr< TVector3 > &dir) const
constexpr Point origin()
Returns a origin position with a point of the specified type.
QTextStream & endl(QTextStream &s)
Event finding and building.