Public Member Functions | Private Member Functions | Private Attributes | List of all members
trk::TrackContainmentAlg Class Reference

#include <TrackContainmentAlg.hh>

Public Member Functions

 TrackContainmentAlg ()
 Default constructor. More...
 
void SetupOutputTree (TTree *)
 
void Configure (fhicl::ParameterSet const &)
 
void SetRunEvent (unsigned int const &, unsigned int const &)
 
void ProcessTracks (std::vector< std::vector< recob::Track > > const &, geo::GeometryCore const &)
 
std::vector< std::vector< int > > const & GetTrackContainmentValues ()
 
std::vector< std::vector< double > > const & GetTrackMinDistanceValues ()
 
std::vector< std::vector< anab::CosmicTag > > const & GetTrackCosmicTags ()
 
void setMakeCosmicTags (bool flag=true)
 
void setFillOutputTree (bool flag=true)
 

Private Member Functions

bool IsContained (recob::Track const &, geo::GeometryCore const &)
 
anab::CosmicTagID_t GetCosmicTagID (recob::Track const &, geo::GeometryCore const &)
 
double MinDistanceStartPt (recob::Track const &, recob::Track const &)
 
double MinDistanceEndPt (recob::Track const &, recob::Track const &)
 

Private Attributes

double fZBuffer
 
double fYBuffer
 
double fXBuffer
 
double fIsolation
 
bool fMakeCosmicTags
 
bool fDebug
 
bool fFillOutputTree
 
TTree * fTrackTree
 
TrackTree_t fTrackTreeObj
 
unsigned int fRun
 
unsigned int fEvent
 
unsigned int fCollection
 
unsigned int fTrkID
 
double fDistance
 
int fContainment
 
std::vector< std::vector< int > > fTrackContainmentLevel
 
std::vector< std::vector< std::pair< int, int > > > fTrackContainmentIndices
 
std::vector< std::vector< double > > fMinDistances
 
std::vector< std::vector< anab::CosmicTag > > fCosmicTags
 

Detailed Description

Definition at line 57 of file TrackContainmentAlg.hh.

Constructor & Destructor Documentation

trk::TrackContainmentAlg::TrackContainmentAlg ( )

Default constructor.

Definition at line 10 of file TrackContainmentAlg.cxx.

10 {}

Member Function Documentation

void trk::TrackContainmentAlg::Configure ( fhicl::ParameterSet const &  p)

Definition at line 24 of file TrackContainmentAlg.cxx.

25 {
26  fZBuffer = p.get<double>("ZBuffer");
27  fYBuffer = p.get<double>("YBuffer");
28  fXBuffer = p.get<double>("XBuffer");
29  fIsolation = p.get<double>("Isolation");
30 
31  fDebug = p.get<bool>("Debug",false);
32  fMakeCosmicTags = p.get<bool>("MakeCosmicTags",true);
33  fFillOutputTree = p.get<bool>("FillOutputTree",true);
34 }
p
Definition: test.py:223
anab::CosmicTagID_t trk::TrackContainmentAlg::GetCosmicTagID ( recob::Track const &  track,
geo::GeometryCore const &  geo 
)
private

Definition at line 54 of file TrackContainmentAlg.cxx.

55 {
56 
58 
59  if(track.Vertex().Z() < (0+fZBuffer) || track.Vertex().Z() > (geo.DetLength()-fZBuffer))
61  else if(track.Vertex().Y() < (-1*geo.DetHalfHeight()+fYBuffer) || track.Vertex().Y() > (geo.DetHalfHeight()-fYBuffer))
63  else if( (track.Vertex().X()>0 && track.Vertex().X() < (0+fXBuffer)) ||
64  (track.Vertex().X()<2*geo.DetHalfWidth() && track.Vertex().X() > (2*geo.DetHalfWidth()-fXBuffer)) )
66 
67  if( track.End().Z() < (0+fZBuffer) || track.End().Z() > (geo.DetLength()-fZBuffer) ){
76  }
77  else if( track.End().Y() < (-1*geo.DetHalfHeight()+fYBuffer) || track.End().Y() > (geo.DetHalfHeight()-fYBuffer) ){
86  }
87  else if( (track.End().X()>0 && track.End().X() < (0+fXBuffer)) ||
88  (track.End().X()<2*geo.DetHalfWidth() && track.End().X() > (2*geo.DetHalfWidth()-fXBuffer)) ){
97  }
98 
99  if(track.Vertex().X() < 0 || track.Vertex().X() > 2*geo.DetHalfWidth())
101  if(track.End().X() < 0 || track.End().X() > 2*geo.DetHalfWidth()){
104  else
106  }
107 
108  return id;
109 }
LArSoft geometry interface.
Definition: ChannelGeo.h:16
std::vector< std::vector<int> > const& trk::TrackContainmentAlg::GetTrackContainmentValues ( )
inline

Definition at line 72 of file TrackContainmentAlg.hh.

73  { return fTrackContainmentLevel; }
std::vector< std::vector< int > > fTrackContainmentLevel
std::vector< std::vector< anab::CosmicTag > > const & trk::TrackContainmentAlg::GetTrackCosmicTags ( )

Definition at line 323 of file TrackContainmentAlg.cxx.

324 {
325  if(fMakeCosmicTags)
326  return fCosmicTags;
327  else
328  throw cet::exception("TrackContainmentAlg::GetTrackCosmicTags")
329  << "Cosmic tags not created. Set MakeCosmicTags to true in fcl paramters.";
330 }
std::vector< std::vector< anab::CosmicTag > > fCosmicTags
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::vector< std::vector<double> > const& trk::TrackContainmentAlg::GetTrackMinDistanceValues ( )
inline

Definition at line 74 of file TrackContainmentAlg.hh.

75  { return fMinDistances; }
std::vector< std::vector< double > > fMinDistances
bool trk::TrackContainmentAlg::IsContained ( recob::Track const &  track,
geo::GeometryCore const &  geo 
)
private

Definition at line 36 of file TrackContainmentAlg.cxx.

37 {
38  if( track.Vertex().Z() < (0+fZBuffer) || track.Vertex().Z() > (geo.DetLength()-fZBuffer) )
39  return false;
40  if( track.End().Z() < (0+fZBuffer) || track.End().Z() > (geo.DetLength()-fZBuffer) )
41  return false;
42  if( track.Vertex().Y() < (-1*geo.DetHalfHeight()+fYBuffer) || track.Vertex().Y() > (geo.DetHalfHeight()-fYBuffer) )
43  return false;
44  if( track.End().Y() < (-1*geo.DetHalfHeight()+fYBuffer) || track.End().Y() > (geo.DetHalfHeight()-fYBuffer) )
45  return false;
46  if( track.Vertex().X() < (0+fXBuffer) || track.Vertex().X() > (2*geo.DetHalfWidth()-fXBuffer) )
47  return false;
48  if( track.End().X() < (0+fXBuffer) || track.End().X() > (2*geo.DetHalfWidth()-fXBuffer) )
49  return false;
50 
51  return true;
52 }
LArSoft geometry interface.
Definition: ChannelGeo.h:16
double trk::TrackContainmentAlg::MinDistanceEndPt ( recob::Track const &  t_probe,
recob::Track const &  t_ref 
)
private

Definition at line 127 of file TrackContainmentAlg.cxx.

128 {
129  double min_distance = 9e12;
130  double tmp;
131  for(size_t i_p=0; i_p<t_ref.NumberTrajectoryPoints(); ++i_p){
132  tmp =
133  (t_probe.End().X()-t_ref.LocationAtPoint(i_p).X())*(t_probe.End().X()-t_ref.LocationAtPoint(i_p).X()) +
134  (t_probe.End().Y()-t_ref.LocationAtPoint(i_p).Y())*(t_probe.End().Y()-t_ref.LocationAtPoint(i_p).Y()) +
135  (t_probe.End().Z()-t_ref.LocationAtPoint(i_p).Z())*(t_probe.End().Z()-t_ref.LocationAtPoint(i_p).Z());
136  if(tmp<min_distance)
137  min_distance=tmp;
138  }
139  return std::sqrt(min_distance);
140 }
string tmp
Definition: languages.py:63
double trk::TrackContainmentAlg::MinDistanceStartPt ( recob::Track const &  t_probe,
recob::Track const &  t_ref 
)
private

Definition at line 111 of file TrackContainmentAlg.cxx.

112 {
113  double min_distance = 9e12;
114  double tmp;
115  for(size_t i_p=0; i_p<t_ref.NumberTrajectoryPoints(); ++i_p){
116  tmp =
117  (t_probe.Vertex().X()-t_ref.LocationAtPoint(i_p).X())*(t_probe.Vertex().X()-t_ref.LocationAtPoint(i_p).X()) +
118  (t_probe.Vertex().Y()-t_ref.LocationAtPoint(i_p).Y())*(t_probe.Vertex().Y()-t_ref.LocationAtPoint(i_p).Y()) +
119  (t_probe.Vertex().Z()-t_ref.LocationAtPoint(i_p).Z())*(t_probe.Vertex().Z()-t_ref.LocationAtPoint(i_p).Z());
120  //std::cout << "\t\t\ttmp=" << tmp << std::endl;
121  if(tmp<min_distance)
122  min_distance=tmp;
123  }
124  return std::sqrt(min_distance);
125 }
string tmp
Definition: languages.py:63
void trk::TrackContainmentAlg::ProcessTracks ( std::vector< std::vector< recob::Track > > const &  tracksVec,
geo::GeometryCore const &  geo 
)

Definition at line 148 of file TrackContainmentAlg.cxx.

150 {
151 
152  if(fDebug){
153  std::cout << "Geometry:" << std::endl;
154  std::cout << "\t" << geo.DetHalfWidth() << " " << geo.DetHalfHeight() << " " << geo.DetLength() << std::endl;
155  std::cout << "\t z:(" << fZBuffer << "," << geo.DetLength()-fZBuffer << ")"
156  << "\t y:(" << -1.*geo.DetHalfHeight()+fYBuffer << "," << geo.DetHalfHeight()-fYBuffer << ")"
157  << "\t x:(" << 0+fXBuffer << "," << 2*geo.DetHalfWidth()-fXBuffer << ")" << std::endl;
158  }
159 
160 
161  int containment_level=0;
162  bool track_linked = false;
163  std::size_t n_tracks=0;
164 
165  fTrackContainmentLevel.clear();
166  fTrackContainmentLevel.resize(tracksVec.size());
167  fMinDistances.clear();
168  fMinDistances.resize(tracksVec.size());
169 
170  fTrackContainmentIndices.clear();
171  fTrackContainmentIndices.push_back( std::vector< std::pair<int,int> >() );
172 
173  fCosmicTags.clear();
174  fCosmicTags.resize(tracksVec.size());
175 
176  //first, loop through tracks and see what's not contained
177 
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);
181  fCosmicTags[i_tc].resize(tracksVec[i_tc].size(),anab::CosmicTag(-1));
182  n_tracks += tracksVec[i_tc].size();
183  for(size_t i_t=0; i_t<tracksVec[i_tc].size(); ++i_t){
184 
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);
189  if(fDebug){
190  std::cout << "\tTrack (" << i_tc << "," << i_t << ")"
191  << " " << containment_level << std::endl;
192  }
193 
194  }//end if contained
195  }//end loop over tracks
196 
197  }//end loop over track collections
198 
199 
200 
201  //now, while we are still linking tracks, loop over all tracks and note anything
202  //close to an uncontained (or linked) track
203  while(track_linked){
204 
205  track_linked=false;
206  ++containment_level;
207  fTrackContainmentIndices.push_back( std::vector< std::pair<int,int> >() );
208 
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)
212  continue;
213  else
214  {
215  for(auto const& i_tr : fTrackContainmentIndices[containment_level-1]){
216 
217  /*
218  if(fDebug){
219  std::cout << "\t\t" << MinDistanceStartPt(tracksVec[i_tc][i_t],tracksVec[i_tr.first][i_tr.second]) << std::endl;
220  std::cout << "\t\t" << MinDistanceEndPt(tracksVec[i_tc][i_t],tracksVec[i_tr.first][i_tr.second]) << std::endl;
221  }
222  */
223 
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]);
228 
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);
234 
235  if(fDebug){
236  std::cout << "\tTrackPair (" << i_tc << "," << i_t << ") and (" << i_tr.first << "," << i_tr.second << ")"
237  << " " << containment_level << std::endl;
238  }
239 
240  }//end if track not isolated
241 
242  }//end loop over existing uncontained/linked tracks
243 
244  }//end if track not already linked
245 
246  }//end loops over tracks
247  }//end loop over track collections
248  }//end while linking tracks
249 
250 
251  if(fDebug)
252  std::cout << "All done! Now let's make the tree and tags!" << std::endl;
253 
254  //now we're going to will the tree and create tags if requested
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){
257 
258  //fill ROOT Tree
259  if(fFillOutputTree){
260  fTrackTreeObj = TrackTree_t(tracksVec[i_tc][i_t]);
261  fDistance = fMinDistances[i_tc][i_t];
262  fCollection = i_tc;
263  fTrkID = i_t;
265  fTrackTree->Fill();
266  }
267 
268  if(fMakeCosmicTags){
269 
270  //default (if track looks contained and isolated)
271  float score=0;
273 
274  //overwrite if track is not contained or not isolated
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);
279  else
281  }
282 
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()},
290  score,id);
291  }//end cosmic tag making
292 
293 
294  //some debug work
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;
299  std::cout << "\tS_(X,Y,Z) = ("
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;
306  std::cout << "\tE_(X,Y,Z) = ("
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;
315  }//end debug statements if track contained
316 
317  }//end loops over tracks
318  }//end loop over track collections
319 
320 }//end ProcessTracks
std::vector< std::vector< int > > fTrackContainmentLevel
double MinDistanceStartPt(recob::Track const &, recob::Track const &)
struct vector vector
std::vector< std::vector< double > > fMinDistances
anab::CosmicTagID_t GetCosmicTagID(recob::Track const &, geo::GeometryCore const &)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
std::vector< std::vector< std::pair< int, int > > > fTrackContainmentIndices
struct trk::TrackTree TrackTree_t
double MinDistanceEndPt(recob::Track const &, recob::Track const &)
std::vector< std::vector< anab::CosmicTag > > fCosmicTags
void End(void)
Definition: gXSecComp.cxx:210
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
LArSoft geometry interface.
Definition: ChannelGeo.h:16
bool IsContained(recob::Track const &, geo::GeometryCore const &)
QTextStream & endl(QTextStream &s)
void trk::TrackContainmentAlg::setFillOutputTree ( bool  flag = true)
inline

Definition at line 79 of file TrackContainmentAlg.hh.

void trk::TrackContainmentAlg::setMakeCosmicTags ( bool  flag = true)
inline

Definition at line 78 of file TrackContainmentAlg.hh.

void trk::TrackContainmentAlg::SetRunEvent ( unsigned int const &  run,
unsigned int const &  event 
)

Definition at line 142 of file TrackContainmentAlg.cxx.

void trk::TrackContainmentAlg::SetupOutputTree ( TTree *  tfs_tree_trk)

Definition at line 12 of file TrackContainmentAlg.cxx.

12  {
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);
22 }
std::string Leaflist()

Member Data Documentation

unsigned int trk::TrackContainmentAlg::fCollection
private

Definition at line 96 of file TrackContainmentAlg.hh.

int trk::TrackContainmentAlg::fContainment
private

Definition at line 99 of file TrackContainmentAlg.hh.

std::vector< std::vector<anab::CosmicTag> > trk::TrackContainmentAlg::fCosmicTags
private

Definition at line 104 of file TrackContainmentAlg.hh.

bool trk::TrackContainmentAlg::fDebug
private

Definition at line 89 of file TrackContainmentAlg.hh.

double trk::TrackContainmentAlg::fDistance
private

Definition at line 98 of file TrackContainmentAlg.hh.

unsigned int trk::TrackContainmentAlg::fEvent
private

Definition at line 95 of file TrackContainmentAlg.hh.

bool trk::TrackContainmentAlg::fFillOutputTree
private

Definition at line 90 of file TrackContainmentAlg.hh.

double trk::TrackContainmentAlg::fIsolation
private

Definition at line 87 of file TrackContainmentAlg.hh.

bool trk::TrackContainmentAlg::fMakeCosmicTags
private

Definition at line 88 of file TrackContainmentAlg.hh.

std::vector< std::vector<double> > trk::TrackContainmentAlg::fMinDistances
private

Definition at line 103 of file TrackContainmentAlg.hh.

unsigned int trk::TrackContainmentAlg::fRun
private

Definition at line 94 of file TrackContainmentAlg.hh.

std::vector< std::vector< std::pair<int,int> > > trk::TrackContainmentAlg::fTrackContainmentIndices
private

Definition at line 102 of file TrackContainmentAlg.hh.

std::vector< std::vector<int> > trk::TrackContainmentAlg::fTrackContainmentLevel
private

Definition at line 101 of file TrackContainmentAlg.hh.

TTree* trk::TrackContainmentAlg::fTrackTree
private

Definition at line 92 of file TrackContainmentAlg.hh.

TrackTree_t trk::TrackContainmentAlg::fTrackTreeObj
private

Definition at line 93 of file TrackContainmentAlg.hh.

unsigned int trk::TrackContainmentAlg::fTrkID
private

Definition at line 97 of file TrackContainmentAlg.hh.

double trk::TrackContainmentAlg::fXBuffer
private

Definition at line 86 of file TrackContainmentAlg.hh.

double trk::TrackContainmentAlg::fYBuffer
private

Definition at line 85 of file TrackContainmentAlg.hh.

double trk::TrackContainmentAlg::fZBuffer
private

Definition at line 84 of file TrackContainmentAlg.hh.


The documentation for this class was generated from the following files: