CMS 3D CMS Logo

NuclearInteractionFinder.cc
Go to the documentation of this file.
4 
6 
9 
12 
14  const TrackerGeometry* iTrackerGeom,
15  const Propagator* iPropagator,
16  const MeasurementEstimator* iEstimator,
17  const MeasurementTracker* iMeasurementTracker,
18  const GeometricSearchTracker* iGeomSearchTracker,
19  const NavigationSchool* iNavigationSchool)
20  : maxHits(iConfig.maxHits),
23  thePropagator = iPropagator;
24  theEstimator = iEstimator;
25  theMeasurementTracker = iMeasurementTracker;
26  theGeomSearchTracker = iGeomSearchTracker;
27  theNavigationSchool = iNavigationSchool;
28 
29  LogDebug("NuclearSeedGenerator") << "New NuclearInteractionFinder instance with parameters : \n"
30  << "maxHits : " << maxHits << "\n"
31  << "rescaleErrorFactor : " << rescaleErrorFactor << "\n"
32  << "checkCompletedTrack : " << checkCompletedTrack << "\n";
33 
34  nuclTester = std::make_unique<NuclearTester>(maxHits, theEstimator, iTrackerGeom);
35 
36  currentSeed = std::make_unique<SeedFromNuclearInteraction>(thePropagator, iTrackerGeom, iConfig.ptMin);
37 
38  thePrimaryHelix = std::make_unique<TangentHelix>();
39 }
40 
41 //----------------------------------------------------------------------
43  if (traj.empty() || !traj.isValid())
44  return false;
45 
46  LogDebug("NuclearSeedGenerator") << "Analyzis of a new trajectory with a number of valid hits = " << traj.foundHits();
47 
48  std::vector<TrajectoryMeasurement> measurements = traj.measurements();
49 
50  // initialization
51  nuclTester->reset(measurements.size());
52  allSeeds.clear();
53 
54  LayerMeasurements layerMeasurements(*theMeasurementTracker, event);
55 
56  if (traj.direction() == alongMomentum) {
57  std::reverse(measurements.begin(), measurements.end());
58  }
59 
60  std::vector<TrajectoryMeasurement>::const_iterator it_meas = measurements.begin();
61 
62  std::vector<double> ncompatibleHits;
63  bool NIfound = false;
64 
65  // Loop on all the RecHits.
66  while (!NIfound) {
67  if (it_meas == measurements.end())
68  break;
69 
70  // check only the maxHits outermost hits of the primary track
71  if (nuclTester->nHitsChecked() > maxHits)
72  break;
73 
74  nuclTester->push_back(*it_meas, findCompatibleMeasurements(*it_meas, rescaleErrorFactor, layerMeasurements));
75 
76  LogDebug("NuclearSeedGenerator") << "Number of compatible meas:" << (nuclTester->back()).size() << "\n"
77  << "Mean distance between hits :" << nuclTester->meanHitDistance() << "\n"
78  << "Forward estimate :" << nuclTester->fwdEstimate() << "\n";
79 
80  // don't check tracks which reach the end of the tracker if checkCompletedTrack==false
81  if (checkCompletedTrack == false && (nuclTester->compatibleHits()).front() == 0)
82  break;
83 
84  if (nuclTester->isNuclearInteraction())
85  NIfound = true;
86 
87  ++it_meas;
88  }
89 
90  if (NIfound) {
91  LogDebug("NuclearSeedGenerator") << "NUCLEAR INTERACTION FOUND at index : " << nuclTester->nuclearIndex() << "\n";
92 
93  // Get correct parametrization of the helix of the primary track at the interaction point (to be used by improveCurrentSeed)
94  definePrimaryHelix(measurements.begin() + nuclTester->nuclearIndex() - 1);
95 
96  this->fillSeeds(nuclTester->goodTMPair());
97 
98  return true;
99  }
100 
101  return false;
102 }
103 //----------------------------------------------------------------------
104 void NuclearInteractionFinder::definePrimaryHelix(std::vector<TrajectoryMeasurement>::const_iterator it_meas) {
105  // This method uses the 3 last TM after the interaction point to calculate the helix parameters
106 
107  GlobalPoint pt[3];
108  for (int i = 0; i < 3; i++) {
109  pt[i] = (it_meas->updatedState()).globalParameters().position();
110  it_meas++;
111  }
112  thePrimaryHelix = std::make_unique<TangentHelix>(pt[0], pt[1], pt[2]);
113 }
114 //----------------------------------------------------------------------
115 std::vector<TrajectoryMeasurement> NuclearInteractionFinder::findCompatibleMeasurements(
116  const TM& lastMeas, double rescale, const LayerMeasurements& layerMeasurements) const {
117  const TSOS& currentState = lastMeas.updatedState();
118  LogDebug("NuclearSeedGenerator") << "currentState :" << currentState << "\n";
119 
120  TSOS newState = rescaleError(rescale, currentState);
121  return findMeasurementsFromTSOS(newState, lastMeas.recHit()->geographicalId(), layerMeasurements);
122 }
123 //----------------------------------------------------------------------
124 std::vector<TrajectoryMeasurement> NuclearInteractionFinder::findMeasurementsFromTSOS(
125  const TSOS& currentState, DetId detid, const LayerMeasurements& layerMeasurements) const {
126  using namespace std;
127  int invalidHits = 0;
128  vector<TM> result;
129  const DetLayer* lastLayer = theGeomSearchTracker->detLayer(detid);
130  vector<const DetLayer*> nl;
131 
132  if (lastLayer) {
133  nl = theNavigationSchool->nextLayers(*lastLayer, *currentState.freeState(), alongMomentum);
134  } else {
135  edm::LogError("NuclearInteractionFinder") << "In findCompatibleMeasurements : lastLayer not accessible";
136  return result;
137  }
138 
139  if (nl.empty()) {
140  LogDebug("NuclearSeedGenerator") << "In findCompatibleMeasurements : no compatible layer found";
141  return result;
142  }
143 
144  for (vector<const DetLayer*>::iterator il = nl.begin(); il != nl.end(); il++) {
145  vector<TM> tmp = layerMeasurements.measurements((**il), currentState, *thePropagator, *theEstimator);
146  if (!tmp.empty()) {
147  if (result.empty())
148  result = tmp;
149  else {
150  // keep one dummy TM at the end, skip the others
151  result.insert(result.end() - invalidHits, tmp.begin(), tmp.end());
152  }
153  invalidHits++;
154  }
155  }
156 
157  // sort the final result, keep dummy measurements at the end
158  if (result.size() > 1) {
159  sort(result.begin(), result.end() - invalidHits, TrajMeasLessEstim());
160  }
161  return result;
162 }
163 
164 //----------------------------------------------------------------------
166  const std::pair<TrajectoryMeasurement, std::vector<TrajectoryMeasurement> >& tmPairs) {
167  // This method returns the seeds calculated by the class SeedsFromNuclearInteraction
168 
169  const TM& innerTM = tmPairs.first;
170  const std::vector<TM>& outerTMs = tmPairs.second;
171 
172  // Loop on all outer TM
173  for (std::vector<TM>::const_iterator outtm = outerTMs.begin(); outtm != outerTMs.end(); outtm++) {
174  if ((innerTM.recHit())->isValid() && (outtm->recHit())->isValid()) {
175  currentSeed->setMeasurements(innerTM.updatedState(), innerTM.recHit(), outtm->recHit());
176  allSeeds.push_back(*currentSeed);
177  } else
178  LogDebug("NuclearSeedGenerator") << "The initial hits for seeding are invalid"
179  << "\n";
180  }
181  return;
182 }
183 //----------------------------------------------------------------------
184 std::unique_ptr<TrajectorySeedCollection> NuclearInteractionFinder::getPersistentSeeds() {
185  auto output = std::make_unique<TrajectorySeedCollection>();
186  for (std::vector<SeedFromNuclearInteraction>::const_iterator it_seed = allSeeds.begin(); it_seed != allSeeds.end();
187  it_seed++) {
188  if (it_seed->isValid()) {
189  output->push_back(it_seed->TrajSeed());
190  } else
191  LogDebug("NuclearSeedGenerator") << "The seed is invalid"
192  << "\n";
193  }
194  return output;
195 }
196 //----------------------------------------------------------------------
198  std::vector<SeedFromNuclearInteraction> newSeedCollection;
199 
200  LayerMeasurements layerMeasurements(*theMeasurementTracker, event);
201 
202  // loop on all actual seeds
203  for (std::vector<SeedFromNuclearInteraction>::const_iterator it_seed = allSeeds.begin(); it_seed != allSeeds.end();
204  it_seed++) {
205  if (!it_seed->isValid())
206  continue;
207 
208  // find compatible TM in an outer layer
209  std::vector<TM> thirdTMs =
210  findMeasurementsFromTSOS(it_seed->updatedTSOS(), it_seed->outerHitDetId(), layerMeasurements);
211 
212  // loop on those new TMs
213  for (std::vector<TM>::const_iterator tm = thirdTMs.begin(); tm != thirdTMs.end(); tm++) {
214  if (!tm->recHit()->isValid())
215  continue;
216 
217  // create new seeds collection using the circle equation
218  currentSeed->setMeasurements(*thePrimaryHelix, it_seed->initialTSOS(), it_seed->outerHit(), tm->recHit());
219  newSeedCollection.push_back(*currentSeed);
220  }
221  }
222  allSeeds.clear();
223  allSeeds = newSeedCollection;
224 }
225 //----------------------------------------------------------------------
227  AlgebraicSymMatrix55 m(state.localError().matrix());
229  LocalTrajectoryParameters ltp = state.localParameters();
230 
231  // we assume that the error on q/p is equal to 20% of q/p * rescale
232  mr(0, 0) = (ltp.signedInverseMomentum() * 0.2 * rescale) * (ltp.signedInverseMomentum() * 0.2 * rescale);
233 
234  // the error on dx/z and dy/dz is fixed to 10% (* rescale)
235  mr(1, 1) = 1E-2 * rescale * rescale;
236  mr(2, 2) = 1E-2 * rescale * rescale;
237 
238  // the error on the local x and y positions are not modified.
239  mr(3, 3) = m(3, 3);
240  mr(4, 4) = m(4, 4);
241 
242  return TSOS(ltp, mr, state.surface(), &(state.globalParameters().magneticField()), state.surfaceSide());
243 }
size
Write out results.
std::unique_ptr< TangentHelix > thePrimaryHelix
bool isValid() const
Definition: Trajectory.h:257
std::unique_ptr< TrajectorySeedCollection > getPersistentSeeds()
Fill &#39;output&#39; with persistent nuclear seeds.
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
float signedInverseMomentum() const
Signed inverse momentum q/p (zero for neutrals).
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
bool run(const Trajectory &traj, const MeasurementTrackerEvent &event)
Run the Finder.
void improveSeeds(const MeasurementTrackerEvent &event)
Improve the seeds with a third RecHit.
std::unique_ptr< SeedFromNuclearInteraction > currentSeed
Log< level::Error, false > LogError
int foundHits() const
Definition: Trajectory.h:206
std::unique_ptr< NuclearTester > nuclTester
DataContainer const & measurements() const
Definition: Trajectory.h:178
PropagationDirection const & direction() const
Definition: Trajectory.cc:133
const MeasurementTracker * theMeasurementTracker
std::vector< const DetLayer * > nextLayers(const DetLayer &detLayer, Args &&... args) const
const NavigationSchool * theNavigationSchool
const MeasurementEstimator * theEstimator
std::vector< SeedFromNuclearInteraction > allSeeds
std::vector< TrajectoryMeasurement > findMeasurementsFromTSOS(const TSOS &currentState, DetId detid, const LayerMeasurements &layerMeasurements) const
Definition: DetId.h:17
std::vector< TrajectoryMeasurement > findCompatibleMeasurements(const TM &lastMeas, double rescaleFactor, const LayerMeasurements &layerMeasurements) const
Find compatible TM of a TM with error rescaled by rescaleFactor.
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
TrajectoryStateOnSurface const & updatedState() const
const GeometricSearchTracker * theGeomSearchTracker
TrajectoryStateOnSurface TSOS
void fillSeeds(const std::pair< TrajectoryMeasurement, std::vector< TrajectoryMeasurement > > &tmPairs)
get the seeds at the interaction point
Definition: Config.py:1
FreeTrajectoryState const * freeState(bool withErrors=true) const
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
NuclearInteractionFinder(const Config &iConfig, const TrackerGeometry *theTrckerGeom, const Propagator *thePropagator, const MeasurementEstimator *theEstimator, const MeasurementTracker *theMeasurementTracker, const GeometricSearchTracker *theGeomSearchTracker, const NavigationSchool *theNavigationSchool)
TrajectoryStateOnSurface rescaleError(float rescale, const TSOS &state) const
tmp
align.sh
Definition: createJobs.py:716
void definePrimaryHelix(std::vector< TrajectoryMeasurement >::const_iterator it_meas)
Calculate the parameters of the circle representing the primary track at the interaction point...
Definition: event.py:1
ConstRecHitPointer const & recHit() const
#define LogDebug(id)