CMS 3D CMS Logo

NuclearTester.cc
Go to the documentation of this file.
3 
4 //----------------------------------------------------------------------
5 NuclearTester::NuclearTester(unsigned int max_hits, const MeasurementEstimator* est, const TrackerGeometry* track_geom)
6  : maxHits(max_hits), theEstimator(est), trackerGeom(track_geom) {
7  NuclearIndex = 0;
8 }
9 
10 //----------------------------------------------------------------------
12  // TODO : if energy of primary track is below a threshold don't use checkWithMultiplicity but only checkwith compatible_hits.front
13 
14  // 1. if momentum of the primary track is below 5 GeV and if the number of compatible hits >0
15  // assume that a nuclear interaction occured at the end of the track
16  if (allTM.front().first.updatedState().globalMomentum().mag() < 5.0 && compatible_hits.front() > 0) {
17  NuclearIndex = 1;
18  return true;
19  }
20 
21  // 2. else to use multiplicity we require at least 3 TM vectors to check if nuclear interactions occurs
22  if (nHitsChecked() < 3)
23  return false;
24 
25  // 2. check with multiplicity :
26  if (checkWithMultiplicity() == true)
27  return true;
28  else {
29  // 3. last case : uncompleted track with at least 1 compatible hits in the last layer
30  if (nHitsChecked() >= maxHits && compatible_hits.front() > 0) {
31  NuclearIndex = 1;
32  return true;
33  }
34  }
35 
36  return false;
37 }
38 //----------------------------------------------------------------------
40  //RQ: assume that the input vector of compatible hits has been filled from Outside to Inside the tracker !
41 
42  // find the first min nb of compatible TM :
43  std::vector<int>::iterator min_it = min_element(compatible_hits.begin(), compatible_hits.end());
44 
45  // if the outermost hit has no compatible TM, min_it has to be recalculated :
46  if (min_it == compatible_hits.begin() && *min_it != 0)
47  return false;
48  if (min_it == compatible_hits.begin() && *min_it == 0)
49  min_it = min_element(compatible_hits.begin() + 1, compatible_hits.end());
50 
51  // this first min cannot be the innermost TM :
52  if (min_it == compatible_hits.end() - 1)
53  return false;
54 
55  // if the previous nb of compatible TM is > min+2 and if the next compatible TM is min+-1 -> NUCLEAR
56  // example : Nhits = 5, 8, 2, 2, ...
57  if ((*(min_it - 1) - *min_it) > 2 && (*(min_it + 1) - *min_it) < 2) {
58  NuclearIndex = min_it - compatible_hits.begin();
59  return true;
60  }
61 
62  // case of : Nhits = 5, 8, 3, 2, 2, ...
63  if (min_it - 1 != compatible_hits.begin()) //because min_it must be at least at the third position
64  {
65  if (min_it - 1 != compatible_hits.begin() && (*(min_it - 1) - *min_it) < 2 && (*(min_it - 2) - *(min_it - 1)) > 2) {
66  NuclearIndex = min_it - 1 - compatible_hits.begin();
67  return true;
68  }
69  }
70 
71  return false;
72 }
73 
74 //----------------------------------------------------------------------
75 double NuclearTester::meanHitDistance(const std::vector<TrajectoryMeasurement>& vecTM) const {
76  std::vector<GlobalPoint> vgp = this->HitPositions(vecTM);
77  double mean_dist = 0;
78  int ncomb = 0;
79  if (vgp.size() < 2)
80  return 0;
81  for (std::vector<GlobalPoint>::iterator itp = vgp.begin(); itp != vgp.end() - 1; itp++) {
82  for (std::vector<GlobalPoint>::iterator itq = itp + 1; itq != vgp.end(); itq++) {
83  double dist = ((*itp) - (*itq)).mag();
84  // to calculate mean distance between particles and not hits (to not take into account twice stereo hits)
85  if (dist > 1E-12) {
86  mean_dist += dist;
87  ncomb++;
88  }
89  }
90  }
91  return mean_dist / ncomb;
92 }
93 //----------------------------------------------------------------------
94 std::vector<GlobalPoint> NuclearTester::HitPositions(const std::vector<TrajectoryMeasurement>& vecTM) const {
95  std::vector<GlobalPoint> gp;
96 
97  std::vector<TM>::const_iterator last = this->lastValidTM(vecTM);
98 
99  for (std::vector<TrajectoryMeasurement>::const_iterator itm = vecTM.begin(); itm != last; itm++) {
100  ConstRecHitPointer trh = itm->recHit();
101  if (trh->isValid())
102  gp.push_back(trackerGeom->idToDet(trh->geographicalId())->surface().toGlobal(trh->localPosition()));
103  }
104  return gp;
105 }
106 //----------------------------------------------------------------------
107 double NuclearTester::fwdEstimate(const std::vector<TrajectoryMeasurement>& vecTM) const {
108  if (vecTM.empty())
109  return 0;
110 
111  auto hit = vecTM.front().recHit().get();
112  if (hit->isValid())
113  return theEstimator->estimate(vecTM.front().forwardPredictedState(), *hit).second;
114  else
115  return -1;
116  /*
117  double meanEst=0;
118  int goodTM=0;
119  std::vector<TM>::const_iterator last;
120  //std::vector<TM>::const_iterator last = this->lastValidTM(vecTM);
121  if(vecTM.size() > 2) last = vecTM.begin()+2;
122  else last = vecTM.end();
123 
124  for(std::vector<TrajectoryMeasurement>::const_iterator itm = vecTM.begin(); itm!=last; itm++) {
125  meanEst += itm->estimate();
126  goodTM++;
127  }
128  return meanEst/goodTM;
129 */
130 }
131 //----------------------------------------------------------------------
132 std::vector<TrajectoryMeasurement>::const_iterator NuclearTester::lastValidTM(const std::vector<TM>& vecTM) const {
133  if (vecTM.empty())
134  return vecTM.end();
135  if (vecTM.front().recHit()->isValid())
136  return std::find_if(vecTM.begin(), vecTM.end(), [](auto const& meas) { return !meas.recHit()->isValid(); });
137  else
138  return vecTM.end();
139 }
140 //----------------------------------------------------------------------
TMPairVector allTM
Definition: NuclearTester.h:64
std::vector< int > compatible_hits
Definition: NuclearTester.h:65
std::vector< TM >::const_iterator lastValidTM(const std::vector< TM > &vecTM) const
bool checkWithMultiplicity()
const MeasurementEstimator * theEstimator
Definition: NuclearTester.h:70
bool isNuclearInteraction()
U second(std::pair< T, U > const &p)
std::vector< GlobalPoint > HitPositions(const std::vector< TrajectoryMeasurement > &vecTM) const
unsigned int nHitsChecked() const
Definition: NuclearTester.h:58
unsigned int maxHits
Definition: NuclearTester.h:69
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
const TrackerGeomDet * idToDet(DetId) const override
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
TrajectoryMeasurement::ConstRecHitPointer ConstRecHitPointer
Definition: NuclearTester.h:20
double meanHitDistance() const
Definition: NuclearTester.h:44
NuclearTester(unsigned int max_hits, const MeasurementEstimator *est, const TrackerGeometry *track_geom)
Definition: NuclearTester.cc:5
const TrackerGeometry * trackerGeom
Definition: NuclearTester.h:71
double fwdEstimate() const
Definition: NuclearTester.h:46