21 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
"Passed " << tracks.
size() <<
" tracks for tagging cosmics.";
33 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
"...tagged " << n <<
" cosmic-like tracks.";
39 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
" - tag tracks out of 1 drift window;";
42 auto const* geom = lar::providerFrom<geo::Geometry>();
44 for (
auto & t : tracks.
tracks())
53 bool node_out_of_drift_min =
false;
54 bool node_out_of_drift_max =
false;
55 for (
size_t nidx = 0; nidx < trk.
Nodes().size(); ++nidx)
57 auto const & node = *(trk.
Nodes()[nidx]);
58 auto const & tpcGeo = geom->TPC(node.TPC(), node.Cryo());
60 int driftDir = abs(tpcGeo.DetectDriftDirection());
61 p = node.Point3D()[driftDir-1];
64 case 1: min = tpcGeo.MinX(); max = tpcGeo.MaxX();
break;
65 case 2: min = tpcGeo.MinY(); max = tpcGeo.MaxY();
break;
66 case 3: min = tpcGeo.MinZ(); max = tpcGeo.MaxZ();
break;
67 default:
throw cet::exception(
"PMAlgCosmicTagger") <<
"Drift direction unknown: " << driftDir << std::endl;
77 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
" - Tagged " << n <<
" tracks out of 1 drift window.";
88 auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
91 for(
auto & t : tracks.
tracks()){
97 if(t.Track()->GetT0() != 0.0){
98 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
" - track with T0 = " << t.Track()->GetT0();
110 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
" - Tagged " << n <<
" non-beam T0 tracks.";
119 auto const* geom = lar::providerFrom<geo::Geometry>();
125 for(
auto & t : tracks.
tracks()){
131 auto const & node0 = *(t.Track()->Nodes()[0]);
132 auto const & node1 = *(t.Track()->Nodes()[t.Track()->Nodes().size()-1]);
135 TVector3 vtx = (node0.Point3D()[hIdx] > node1.Point3D()[hIdx]) ? node0.Point3D() : node1.Point3D();
136 TVector3
end = (node0.Point3D()[hIdx] <= node1.Point3D()[hIdx]) ? node0.Point3D() : node1.Point3D();
145 if(top && frontBack){
153 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
" - Tagged " << n <<
" tracks crossing from top to front/back." << std::endl;
166 auto const* geom = lar::providerFrom<geo::Geometry>();
171 for(
auto & t : tracks.
tracks()){
177 auto const & node0 = *(t.Track()->Nodes()[0]);
178 auto const & node1 = *(t.Track()->Nodes()[t.Track()->Nodes().size()-1]);
181 TVector3 vtx = (node0.Point3D()[hIdx] > node1.Point3D()[hIdx]) ? node0.Point3D() : node1.Point3D();
182 TVector3
end = (node0.Point3D()[hIdx] <= node1.Point3D()[hIdx]) ? node0.Point3D() : node1.Point3D();
189 bool foundTrack =
false;
190 for(
auto const &
tt : tracks.
tracks()){
192 if((&
tt) == (&t))
continue;
195 TVector3 trkVtx = (
tt.Track()->Nodes()[0])->
Point3D();
196 TVector3 trkEnd = (
tt.Track()->Nodes()[
tt.Track()->Nodes().size()-1])->
Point3D();
218 std::vector<float> nSigmaPerView;
221 for(
auto const view : geom->Views()){
224 std::map<size_t,std::vector<double>> dedx;
225 t.Track()->GetRawdEdxSequence(dedx,view);
227 std::vector<double> trk_dedx;
229 for(
int h = t.Track()->NextHit(-1,view); h != -1; h = t.Track()->NextHit(h,view)){
231 if(h > t.Track()->PrevHit(t.Track()->size(),view))
break;
233 if(dedx[h][5] / dedx[h][6] <= 0 || dedx[h][5] / dedx[h][6] > 1e6)
continue;
234 trk_dedx.push_back(dedx[h][5] / dedx[h][6]);
237 if(trk_dedx.size() == 0){
238 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
"View " << view <<
" has no hits." << std::endl;
243 double mean = sum /
static_cast<double>(trk_dedx.size());
246 accum += (d -
mean) * (d - mean);
248 double stdev = sqrt(accum / static_cast<double>(trk_dedx.size()-1));
250 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
" View " << view <<
" has average dedx " << mean <<
" +/- " << stdev <<
" and final dedx " << trk_dedx[trk_dedx.size()-1] << std::endl;
252 nSigmaPerView.push_back(fabs((trk_dedx[trk_dedx.size()-1]-
mean)/stdev));
255 bool notStopper =
true;
256 short unsigned int n2Sigma = 0;
257 short unsigned int n3Sigma = 0;
258 for(
auto const nSigma : nSigmaPerView){
259 if(nSigma >= 2.0) ++n2Sigma;
260 if(nSigma >= 3.0) ++n3Sigma;
263 if(n3Sigma > 0) notStopper =
false;
264 if(n2Sigma == nSigmaPerView.size()) notStopper =
false;
275 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
" - Tagged " << n <<
" tracks stopping in the detector after starting at the top." << std::endl;
284 auto const* geom = lar::providerFrom<geo::Geometry>();
285 TVector3
dir = geom->TPC(0,0).HeightDir();
289 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
" - Tagged " << n <<
" tracks crossing the full detector height";
297 auto const* geom = lar::providerFrom<geo::Geometry>();
298 TVector3
dir = geom->TPC(0,0).WidthDir();
302 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
" - Tagged " << n <<
" tracks crossing the full detector width";
310 auto const* geom = lar::providerFrom<geo::Geometry>();
311 TVector3
dir = geom->TPC(0,0).LengthDir();
315 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
" - Tagged " << n <<
" tracks crossing the full detector length";
323 mf::LogWarning(
"pma::PMAlgCosmicTagger") <<
" - Could not recognise direction, not attempting to perform fullCrossingTagger.";
341 for(
auto & t : tracks.
tracks()){
347 auto const & node0 = *(t.Track()->Nodes()[0]);
348 auto const & node1 = *(t.Track()->Nodes()[t.Track()->Nodes().size()-1]);
351 double trkDim = fabs(node0.Point3D()[direction]-node1.Point3D()[direction]);
356 t.Track()->SetTagFlag(dirTag);
357 mf::LogInfo(
"pma::PMAlgCosmicTagger") <<
" -- track tagged in direction " << direction <<
" with " << trkDim <<
" (c.f. " << detDim <<
")";
372 bool front = (fabs(pos[dirIndx] -
fDimensionsMin[dirIndx]) < tolerance);
373 bool back = (fabs(pos[dirIndx] -
fDimensionsMax[dirIndx]) < tolerance);
375 return front || back;
388 auto const* geom = lar::providerFrom<geo::Geometry>();
391 for (
geo::TPCID const& tID: geom->IterateTPCIDs()) {
403 double center[3] = {0.};
407 if( center[0] - tpcDim[0] < minX ) minX = center[0] - tpcDim[0];
408 if( center[0] + tpcDim[0] > maxX ) maxX = center[0] + tpcDim[0];
409 if( center[1] - tpcDim[1] < minY ) minY = center[1] - tpcDim[1];
410 if( center[1] + tpcDim[1] > maxY ) maxY = center[1] + tpcDim[1];
411 if( center[2] - tpcDim[2] < minZ ) minZ = center[2] - tpcDim[2];
412 if( center[2] + tpcDim[2] > maxZ ) maxZ = center[2] + tpcDim[2];
428 if(dir.X() > 0.99)
return 0;
429 if(dir.Y() > 0.99)
return 1;
430 if(dir.Z() > 0.99)
return 2;
void tag(pma::TrkCandidateColl &tracks)
bool fTagOutOfDriftTracks
void SetTagFlag(ETag value)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
size_t tagApparentStopper(pma::TrkCandidateColl &tracks)
size_t nonBeamT0Tag(pma::TrkCandidateColl &tracks)
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
Geometry information for a single TPC.
std::vector< pma::Node3D * > const & Nodes(void) const
double fTopFrontBackMargin
bool fTagFullLengthTracks
std::vector< TrkCandidate > const & tracks(void) const
std::vector< double > fDimensionsMin
size_t fullHeightCrossing(pma::TrkCandidateColl &tracks)
double Length() const
Length is associated with z coordinate [cm].
bool isFrontBackVertex(const TVector3 &pos, double tolerance, short int dirIndx) const
bool fTagFullHeightTracks
size_t outOfDriftWindow(pma::TrkCandidateColl &tracks)
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
size_t tagTopFrontBack(pma::TrkCandidateColl &tracks)
short int ConvertDirToInt(const TVector3 &dir) const
double fFullCrossingMargin
std::vector< double > fDimensionsMax
The data type to uniquely identify a TPC.
double HalfHeight() const
Height is associated with y coordinate [cm].
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Implementation of the Projection Matching Algorithm.
double DriftDistance() const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
size_t fullWidthCrossing(pma::TrkCandidateColl &tracks)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
bool isTopVertex(const TVector3 &pos, double tolerance, short int dirIndx) const
void LocalToWorld(const double *tpc, double *world) const
Transform point from local TPC frame to world frame.
double fApparentStopperMargin
art framework interface to geometry description
double HalfWidth() const
Width is associated with x coordinate [cm].
constexpr Point origin()
Returns a origin position with a point of the specified type.
cet::coded_exception< error, detail::translate > exception
size_t fullCrossingTagger(pma::TrkCandidateColl &tracks, int direction)
Encapsulate the construction of a single detector plane.
size_t fullLengthCrossing(pma::TrkCandidateColl &tracks)