test
CMS 3D CMS Logo

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