3 #include "fhiclcpp/ParameterSet.h"
13 fTrackTree = tfs_tree_trk;
14 fTrackTree->SetObject(fTrackTree->GetName(),
"Track Tree");
15 fTrackTree->Branch(
"run",&fRun);
16 fTrackTree->Branch(
"event",&fEvent);
17 fTrackTree->Branch(
"trk",&fTrackTreeObj,fTrackTreeObj.Leaflist().c_str());
18 fTrackTree->Branch(
"trk_col",&fCollection);
19 fTrackTree->Branch(
"trk_id",&fTrkID);
20 fTrackTree->Branch(
"trk_mindist",&fDistance);
21 fTrackTree->Branch(
"trk_containment",&fContainment);
26 fZBuffer = p.get<
double>(
"ZBuffer");
27 fYBuffer = p.get<
double>(
"YBuffer");
28 fXBuffer = p.get<
double>(
"XBuffer");
29 fIsolation = p.get<
double>(
"Isolation");
31 fDebug = p.get<
bool>(
"Debug",
false);
32 fMakeCosmicTags = p.get<
bool>(
"MakeCosmicTags",
true);
33 fFillOutputTree = p.get<
bool>(
"FillOutputTree",
true);
40 if( track.
End().Z() < (0+fZBuffer) || track.
End().Z() > (geo.
DetLength()-fZBuffer) )
48 if( track.
End().X() < (0+fXBuffer) || track.
End().X() > (2*geo.
DetHalfWidth()-fXBuffer) )
63 else if( (track.
Vertex().X()>0 && track.
Vertex().X() < (0+fXBuffer)) ||
67 if( track.
End().Z() < (0+fZBuffer) || track.
End().Z() > (geo.
DetLength()-fZBuffer) ){
87 else if( (track.
End().X()>0 && track.
End().X() < (0+fXBuffer)) ||
113 double min_distance = 9e12;
124 return std::sqrt(min_distance);
129 double min_distance = 9e12;
139 return std::sqrt(min_distance);
157 <<
"\t x:(" << 0+fXBuffer <<
"," << 2*geo.
DetHalfWidth()-fXBuffer <<
")" << std::endl;
161 int containment_level=0;
162 bool track_linked =
false;
163 std::size_t n_tracks=0;
165 fTrackContainmentLevel.clear();
166 fTrackContainmentLevel.resize(tracksVec.size());
167 fMinDistances.clear();
168 fMinDistances.resize(tracksVec.size());
170 fTrackContainmentIndices.clear();
171 fTrackContainmentIndices.push_back(
std::vector< std::pair<int,int> >() );
174 fCosmicTags.resize(tracksVec.size());
178 for(
size_t i_tc=0; i_tc<tracksVec.size(); ++i_tc){
179 fTrackContainmentLevel[i_tc].resize(tracksVec[i_tc].
size(),-1);
180 fMinDistances[i_tc].resize(tracksVec[i_tc].
size(),9e12);
182 n_tracks += tracksVec[i_tc].size();
183 for(
size_t i_t=0; i_t<tracksVec[i_tc].size(); ++i_t){
185 if(!IsContained(tracksVec[i_tc][i_t],geo)){
186 if(!track_linked) track_linked=
true;
187 fTrackContainmentLevel[i_tc][i_t] = 0;
188 fTrackContainmentIndices.back().emplace_back(i_tc,i_t);
190 std::cout <<
"\tTrack (" << i_tc <<
"," << i_t <<
")"
191 <<
" " << containment_level << std::endl;
207 fTrackContainmentIndices.push_back(
std::vector< std::pair<int,int> >() );
209 for(
size_t i_tc=0; i_tc<tracksVec.size(); ++i_tc){
210 for(
size_t i_t=0; i_t<tracksVec[i_tc].size(); ++i_t){
211 if(fTrackContainmentLevel[i_tc][i_t]>=0)
215 for(
auto const& i_tr : fTrackContainmentIndices[containment_level-1]){
224 if(MinDistanceStartPt(tracksVec[i_tc][i_t],tracksVec[i_tr.first][i_tr.second])<fMinDistances[i_tc][i_t])
225 fMinDistances[i_tc][i_t] = MinDistanceStartPt(tracksVec[i_tc][i_t],tracksVec[i_tr.first][i_tr.second]);
226 if(MinDistanceEndPt(tracksVec[i_tc][i_t],tracksVec[i_tr.first][i_tr.second])<fMinDistances[i_tc][i_t])
227 fMinDistances[i_tc][i_t] = MinDistanceEndPt(tracksVec[i_tc][i_t],tracksVec[i_tr.first][i_tr.second]);
229 if(MinDistanceStartPt(tracksVec[i_tc][i_t],tracksVec[i_tr.first][i_tr.second])<fIsolation ||
230 MinDistanceEndPt(tracksVec[i_tc][i_t],tracksVec[i_tr.first][i_tr.second])<fIsolation){
231 if(!track_linked) track_linked=
true;
232 fTrackContainmentLevel[i_tc][i_t] = containment_level;
233 fTrackContainmentIndices.back().emplace_back(i_tc,i_t);
236 std::cout <<
"\tTrackPair (" << i_tc <<
"," << i_t <<
") and (" << i_tr.first <<
"," << i_tr.second <<
")"
237 <<
" " << containment_level << std::endl;
252 std::cout <<
"All done! Now let's make the tree and tags!" << std::endl;
255 for(
size_t i_tc=0; i_tc<tracksVec.size(); ++i_tc){
256 for(
size_t i_t=0; i_t<tracksVec[i_tc].size(); ++i_t){
261 fDistance = fMinDistances[i_tc][i_t];
264 fContainment = fTrackContainmentLevel[i_tc][i_t];
275 if(fTrackContainmentLevel[i_tc][i_t]>=0){
276 score = 1./(1.+(float)fTrackContainmentLevel[i_tc][i_t]);
277 if(fTrackContainmentLevel[i_tc][i_t]==0)
278 id = GetCosmicTagID(tracksVec[i_tc][i_t],geo);
283 fCosmicTags[i_tc][i_t] =
284 anab::CosmicTag(std::vector<float>{(float)tracksVec[i_tc][i_t].Vertex().X(),
285 (float)tracksVec[i_tc][i_t].Vertex().Y(),
286 (float)tracksVec[i_tc][i_t].Vertex().Z()},
287 std::vector<float>{(float)tracksVec[i_tc][i_t].End().X(),
288 (float)tracksVec[i_tc][i_t].End().Y(),
289 (float)tracksVec[i_tc][i_t].End().Z()},
295 if(fTrackContainmentLevel[i_tc][i_t]<0 && fDebug){
296 std::cout <<
"Track (" << i_tc <<
"," << i_t <<
")"
297 <<
" " << fTrackContainmentLevel[i_tc][i_t]
298 <<
" " << fMinDistances[i_tc][i_t] << std::endl;
300 << tracksVec[i_tc][i_t].Vertex().X() <<
","
301 << tracksVec[i_tc][i_t].Vertex().Y() <<
","
302 << tracksVec[i_tc][i_t].Vertex().Z() <<
")" << std::endl;
303 std::cout <<
"\tNearest wire ..." << std::endl;
304 for(
size_t i_p=0; i_p<geo.
Nplanes(); ++i_p)
305 std::cout <<
"\t\tPlane " << i_p <<
" " << geo.
NearestWireID(tracksVec[i_tc][i_t].Vertex(),i_p).Wire << std::endl;
307 << tracksVec[i_tc][i_t].End().X() <<
","
308 << tracksVec[i_tc][i_t].End().Y() <<
","
309 << tracksVec[i_tc][i_t].End().Z() <<
")" << std::endl;
310 std::cout <<
"\tNearest wire ..." << std::endl;
311 for(
size_t i_p=0; i_p<geo.
Nplanes(); ++i_p)
312 std::cout <<
"\t\tPlane " << i_p <<
" " << geo.
NearestWireID(tracksVec[i_tc][i_t].End(),i_p).Wire << std::endl;
313 std::cout <<
"\tLength=" << tracksVec[i_tc][i_t].Length() << std::endl;
314 std::cout <<
"\tSimple_length=" << (tracksVec[i_tc][i_t].End()-tracksVec[i_tc][i_t].Vertex()).R() << std::endl;
328 throw cet::exception(
"TrackContainmentAlg::GetTrackCosmicTags")
329 <<
"Cosmic tags not created. Set MakeCosmicTags to true in fcl paramters.";
double MinDistanceStartPt(recob::Track const &, recob::Track const &)
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
enum anab::cosmic_tag_id CosmicTagID_t
Point_t const & LocationAtPoint(size_t i) const
void SetupOutputTree(TTree *)
BEGIN_PROLOG or score(default)}sbnd_crttrackmatchingalg_crID
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
std::size_t size(FixedBins< T, C > const &) noexcept
anab::CosmicTagID_t GetCosmicTagID(recob::Track const &, geo::GeometryCore const &)
process_name use argoneut_mc_hitfinder track
void ProcessTracks(std::vector< std::vector< recob::Track > > const &, geo::GeometryCore const &)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Access the description of detector geometry.
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
struct trk::TrackTree TrackTree_t
Point_t const & Vertex() const
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
void Configure(fhicl::ParameterSet const &)
void SetRunEvent(unsigned int const &, unsigned int const &)
Description of geometry of one entire detector.
double MinDistanceEndPt(recob::Track const &, recob::Track const &)
std::vector< std::vector< anab::CosmicTag > > const & GetTrackCosmicTags()
TrackContainmentAlg()
Default constructor.
Point_t const & End() const
geo::WireID NearestWireID(geo::Point_t const &point, geo::PlaneID const &planeid) const
Returns the ID of wire closest to position in the specified TPC.
BEGIN_PROLOG could also be cout
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
bool IsContained(recob::Track const &, geo::GeometryCore const &)