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