CMS 3D CMS Logo

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