Class Reference for E1039 Core & Analysis Software
UtilTrack.cc
Go to the documentation of this file.
1 #include <cassert>
2 #include <geom_svc/GeomSvc.h>
3 #include <ktracker/SRecEvent.h>
6 #include "UtilTrigger.h"
7 #include "UtilTrack.h"
8 using namespace std;
9 
11 
13 
17 SQTrack* UtilTrack::FindTrackByID(const SQTrackVector* vec, const int id_trk, const bool do_assert)
18 {
19  for (SQTrackVector::ConstIter it = vec->begin(); it != vec->end(); it++) {
20  SQTrack* trk = *it;
21  if (trk->get_track_id() == id_trk) {
22  if (do_assert) assert(trk);
23  return trk;
24  }
25  }
26  return 0;
27 }
28 
30 
36 SQHitVector* UtilTrack::FindHitsOfTrack(const SQHitVector* vec_in, const int id_trk)
37 {
38  SQHitVector* vec = vec_in->Clone();
39  vec->clear();
40  for (SQHitVector::ConstIter it = vec_in->begin(); it != vec_in->end(); it++) {
41  SQHit* hit = *it;
42  if (hit->get_track_id() == id_trk) vec->push_back(hit);
43  }
44  return vec;
45 }
46 
48 
56 SQHitVector* UtilTrack::FindDetectorHitsOfTrack(const SQHitVector* vec_in, const int id_trk, const std::string det_name)
57 {
58  SQHitVector* vec = vec_in->Clone();
59  vec->clear();
60  for (SQHitVector::ConstIter it = vec_in->begin(); it != vec_in->end(); it++) {
61  SQHit* hit = *it;
62  if (hit->get_track_id() != id_trk) continue;
63  string name = GeomSvc::instance()->getDetectorName( hit->get_detector_id() );
64  if (name.substr(0, det_name.size()) != det_name) continue;
65  vec->push_back(hit);
66  }
67  return vec;
68 }
69 
71 SQHitVector* UtilTrack::FindDetectorHitsOfTrack(const SQHitVector* vec_in, const int id_trk, const char* det_name)
72 {
73  return FindDetectorHitsOfTrack(vec_in, id_trk, (const string)det_name);
74 }
75 
77 
83 SQHitVector* UtilTrack::FindHodoHitsOfTrack(const SQHitVector* vec_in, const int id_trk)
84 {
85  return FindDetectorHitsOfTrack(vec_in, id_trk, "H");
86 }
87 
89 
99 std::vector<int> UtilTrack::FindMatchedRoads(SRecTrack* trk, const double margin)
100 {
101  return FindMatchedRoads(trk->get_pos_st1(), trk->get_mom_st1(), trk->get_pos_st3(), trk->get_mom_st3(), margin);
102 }
103 
105 std::vector<int> UtilTrack::FindMatchedRoads(const TVector3 pos1, const TLorentzVector mom1, const TVector3 pos3, const TLorentzVector mom3, const double margin)
106 {
107  GeomSvc* geom = GeomSvc::instance();
108  double y_st1 = pos1.Y();
109  double y_st3 = pos3.Y();
110  int top_bot = y_st3>0 ? +1 : -1;
111  if (verbosity > 0) cout << "UtilTrack::FindMatchedRoads(): y_st1=" << y_st1 << " y_st3=" << y_st3 << " top_bot=" << top_bot << endl;
112 
113  vector<int> list_ele_id[5]; // 0=unused, 1=st1, 2=st2,,,
114  for (int st = 1; st <= 4; st++) {
115  string det_name = (string)"H" + (char)('0'+st) + (top_bot>0 ? 'T' : 'B');
116  int det_id = geom->getDetectorID(det_name);
117  Plane* det = geom->getPlanePtr(det_id);
118  double x_det = det->xc + det->deltaX;
119  //double y_det = det->yc + det->deltaY;
120  double z_det = det->zc + det->deltaZ;
121  int n_ele = det->nElements;
122  double space = det->spacing;
123  double width = det->cellWidth;
124  if (verbosity > 2) cout << " st" << st << ":";
125  if (verbosity > 3) cout << " x_det=" << x_det << " n_ele=" << n_ele << " space=" << space << " width=" << width;
126 
127  const TVector3* pos = (st == 1 ? &pos1 : &pos3);
128  const TLorentzVector* mom = (st == 1 ? &mom1 : &mom3);
129  double x_trk = pos->X() + (z_det - pos->Z()) * mom->X() / mom->Z();
130  double y_trk = pos->Y() + (z_det - pos->Z()) * mom->Y() / mom->Z();
131  //double x_trk, y_trk;
132  //trk->getExpPositionFast(z_det, x_trk, y_trk);
133  int ele_cent = (int)((n_ele+1)/2.0 + (x_trk-x_det)/space + 0.5);
134  if (verbosity > 2) cout << " x_trk=" << x_trk << " y_trk=" << y_trk;
135 
137  for (int i_ele = ele_cent - 1; i_ele <= ele_cent + 1; i_ele++) {
138  if (i_ele <= 0 || i_ele > n_ele) continue;
139  double x_ele = x_det + space * (i_ele - (n_ele+1)/2.0);
140  if (verbosity > 2) cout << " [ele=" << i_ele << " x=" << x_ele;
141  if (verbosity > 3) cout << " edge=" << (width/2-fabs(x_trk-x_ele));
142  if (verbosity > 2) cout << "]";
143  if (fabs(x_trk - x_ele) < width/2 + margin) list_ele_id[st].push_back(i_ele);
144  }
145  if (verbosity > 2) cout << endl;
146  }
147  vector<int> list_road_id;
148  for (auto it1 = list_ele_id[1].begin(); it1 != list_ele_id[1].end(); it1++) {
149  for (auto it2 = list_ele_id[2].begin(); it2 != list_ele_id[2].end(); it2++) {
150  for (auto it3 = list_ele_id[3].begin(); it3 != list_ele_id[3].end(); it3++) {
151  for (auto it4 = list_ele_id[4].begin(); it4 != list_ele_id[4].end(); it4++) {
152  if (verbosity > 0) cout << " road " << *it1 << " " << *it2 << " " << *it3 << " " << *it4;
153  if (verbosity > 1) cout << " " << UtilTrigger::Hodo2Road(*it1, *it2, *it3, *it4, top_bot);
154  if (verbosity > 0) cout << endl;
155  list_road_id.push_back(UtilTrigger::Hodo2Road(*it1, *it2, *it3, *it4, top_bot));
156  }}}}
157  return list_road_id;
158 }
User interface class about the geometry of detector planes.
Definition: GeomSvc.h:164
int getDetectorID(const std::string &detectorName) const
Get the plane position.
Definition: GeomSvc.h:219
static GeomSvc * instance()
singlton instance
Definition: GeomSvc.cxx:212
Plane * getPlanePtr(int detectorID)
Definition: GeomSvc.h:233
std::string getDetectorName(const int &detectorID) const
Definition: GeomSvc.h:223
Definition: GeomSvc.h:37
int nElements
Definition: GeomSvc.h:69
double spacing
Definition: GeomSvc.h:70
double deltaZ
Definition: GeomSvc.h:96
double zc
Definition: GeomSvc.h:107
double cellWidth
Definition: GeomSvc.h:71
double xc
Definition: GeomSvc.h:105
double deltaX
Definition: GeomSvc.h:94
An SQ interface class to hold a list of SQHit objects.
Definition: SQHitVector.h:32
virtual SQHitVector * Clone() const =0
std::vector< SQHit * >::const_iterator ConstIter
Definition: SQHitVector.h:37
virtual ConstIter end() const =0
virtual ConstIter begin() const =0
virtual void push_back(const SQHit *hit)=0
virtual void clear()=0
An SQ interface class to hold one detector hit.
Definition: SQHit.h:20
virtual short get_detector_id() const
Return the detector ID of this hit.
Definition: SQHit.h:42
virtual int get_track_id() const
Return the track ID associated with this hit. Probably the value is not properly set at present.
Definition: SQHit.h:66
An SQ interface class to hold a list of SQTrack objects.
Definition: SQTrackVector.h:19
virtual ConstIter begin() const =0
virtual ConstIter end() const =0
std::vector< SQTrack * >::const_iterator ConstIter
Definition: SQTrackVector.h:22
An SQ interface class to hold one true or reconstructed track.
Definition: SQTrack.h:8
virtual int get_track_id() const =0
Return the track ID, which is unique per event(?).
virtual TVector3 get_pos_st3() const
Return the track position at Station 3.
Definition: SRecEvent.h:72
virtual TLorentzVector get_mom_st3() const
Return the track momentum at Station 3.
Definition: SRecEvent.h:81
virtual TVector3 get_pos_st1() const
Return the track position at Station 1.
Definition: SRecEvent.h:69
virtual TLorentzVector get_mom_st1() const
Return the track momentum at Station 1.
Definition: SRecEvent.h:78
SQHitVector * FindDetectorHitsOfTrack(const SQHitVector *vec_in, const int id_trk, const std::string det_name)
Find track-associated hits whose detector name starts with 'det_name'.
Definition: UtilTrack.cc:56
std::vector< int > FindMatchedRoads(SRecTrack *trk, const double margin=0)
Find all roads that match to the given track within the hodo paddle width plus the given margin.
Definition: UtilTrack.cc:99
int verbosity
Definition: UtilTrack.cc:10
SQHitVector * FindHodoHitsOfTrack(const SQHitVector *vec_in, const int id_trk)
Find all hodoscope hits hits associated with the given track.
Definition: UtilTrack.cc:83
SQHitVector * FindHitsOfTrack(const SQHitVector *vec_in, const int id_trk)
Find all hits associated with the given track.
Definition: UtilTrack.cc:36
SQTrack * FindTrackByID(const SQTrackVector *vec, const int id_trk, const bool do_assert=false)
Find a track by track ID in the given track list.
Definition: UtilTrack.cc:17
int Hodo2Road(const int h1, const int h2, const int h3, const int h4, const int tb)
Convert a set of hodo IDs to a roadset ID.
Definition: UtilTrigger.cc:13