CMS 3D CMS Logo

SeedFromGenericPairOrTriplet.cc
Go to the documentation of this file.
10 
12  const TrackerGeometry* geom,
13  const TransientTrackingRecHitBuilder* builder,
16  const std::vector<int>& charges,
17  bool momFromPSet,
18  double errorRescaling)
19  : theMagfield(mf),
20  theTracker(geom),
21  theBuilder(builder),
22  thePropagatorAlong(propagatorAlong),
23  thePropagatorOpposite(propagatorOpposite),
24  theSetMomentum(momFromPSet),
25  theCharges(charges),
26  theErrorRescaling(errorRescaling) {}
27 
28 std::vector<TrajectorySeed*> SeedFromGenericPairOrTriplet::seed(const SeedingHitSet& hits,
30  const NavigationDirection& seedDir,
31  const edm::EventSetup& iSetup) {
32  std::vector<TrajectorySeed*> seeds;
33  if (hits.size() == 3) {
34  if (!theSetMomentum) {
35  TrajectorySeed* seed = seedFromTriplet(hits, dir, seedDir, iSetup);
36  if (seed)
37  seeds.push_back(seed);
38  } else {
39  for (std::vector<int>::const_iterator iCh = theCharges.begin(); iCh != theCharges.end(); iCh++) {
40  TrajectorySeed* seed = seedFromTriplet(hits, dir, seedDir, iSetup, *iCh);
41  if (seed)
42  seeds.push_back(seed);
43  }
44  }
45 
46  } else if (hits.size() == 2) {
47  if (!theSetMomentum) {
48  TrajectorySeed* seed = seedFromPair(hits, dir, seedDir);
49  if (seed)
50  seeds.push_back(seed);
51  } else {
52  for (std::vector<int>::const_iterator iCh = theCharges.begin(); iCh != theCharges.end(); iCh++) {
53  TrajectorySeed* seed = seedFromPair(hits, dir, seedDir, *iCh);
54  if (seed)
55  seeds.push_back(seed);
56  }
57  }
58  } else {
59  throw cms::Exception("CombinatorialSeedGeneratorForCosmics")
60  << " Wrong number of hits in Set: " << hits.size() << ", should be 2 or 3 ";
61  }
62  return seeds;
63 }
64 
67  const NavigationDirection& seedDir,
68  const edm::EventSetup& iSetup,
69  int charge) const {
70  if (hits.size() != 3) {
71  throw cms::Exception("CombinatorialSeedGeneratorForCosmics")
72  << "call to SeedFromGenericPairOrTriplet::seedFromTriplet with " << hits.size() << " hits ";
73  }
74 
75  auto innerHit = hits[0];
76  auto middleHit = hits[1];
77  auto outerHit = hits[2];
78  GlobalPoint inner = theTracker->idToDet(innerHit->geographicalId())->surface().toGlobal(innerHit->localPosition());
79  GlobalPoint middle = theTracker->idToDet(middleHit->geographicalId())->surface().toGlobal(middleHit->localPosition());
80  GlobalPoint outer = theTracker->idToDet(outerHit->geographicalId())->surface().toGlobal(outerHit->localPosition());
81  if (theSetMomentum) {
82  LogDebug("SeedFromGenericPairOrTriplet")
83  << "Using the following hits: outer(r, phi, theta) " << outerHit->geographicalId().subdetId() << " ("
84  << outer.perp() << ", " << outer.phi() << "," << outer.theta() << ") "
85  << middleHit->geographicalId().subdetId() << " middle (" << middle.perp() << ", " << middle.phi() << ","
86  << middle.theta() << ") " << innerHit->geographicalId().subdetId() << " inner (" << inner.perp() << ", "
87  << inner.phi() << "," << inner.theta() << ") "
88  << " (x, y, z) outer (" << inner.x() << ", " << inner.y() << ", " << inner.z() << ") middle ("
89  << middle.x() << ", " << middle.y() << ", " << middle.z() << ")";
90  if (!qualityFilter(hits))
91  return nullptr;
92  bool sdir = (seedDir == outsideIn);
93  SeedingHitSet newSet(sdir ? hits[1] : hits[0], sdir ? hits[2] : hits[1]);
94  TrajectorySeed* seed = seedFromPair(newSet, dir, seedDir, charge);
95  return seed;
96  }
97  GlobalPoint* firstPoint = nullptr;
98  GlobalPoint* secondPoint = nullptr;
99  GlobalPoint* thirdPoint = nullptr;
100  int momentumSign = 1;
101  //const TrackingRecHit* firstHit = 0;
102  //const TrackingRecHit* secondHit = 0;
103  //choose the prop dir and hit order accordingly to where the seed is made
104  std::vector<const BaseTrackerRecHit*> trHits;
105  if (seedDir == outsideIn) {
106  LogDebug("SeedFromGenericPairOrTriplet") << "Seed from outsideIn alongMomentum OR insideOut oppositeToMomentum";
107  firstPoint = &outer;
108  secondPoint = &middle;
109  thirdPoint = &inner;
110  trHits.push_back(outerHit);
111  trHits.push_back(middleHit);
112  //firstHit = outerHit;
113  //secondHit = middleHit;
114  } else {
115  LogDebug("SeedFromGenericPairOrTriplet") << "Seed from outsideIn oppositeToMomentum OR insideOut alongMomentum";
116  firstPoint = &inner;
117  secondPoint = &middle;
118  thirdPoint = &outer;
119  trHits.push_back(innerHit);
120  trHits.push_back(middleHit);
121  //firstHit = innerHit;
122  //secondHit = middleHit;
123  }
124  if (dir == oppositeToMomentum)
125  momentumSign = -1;
126  FastHelix helix(*thirdPoint, *secondPoint, *firstPoint, theMagfield->nominalValue(), theMagfield);
127  FreeTrajectoryState originalStartingState = helix.stateAtVertex();
128  LogDebug("SeedFromGenericPairOrTriplet") << "originalStartingState " << originalStartingState;
129  /*GlobalTrajectoryParameters originalPar = originalStartingState.parameters();
130  GlobalTrajectoryParameters newPar = GlobalTrajectoryParameters(originalPar.position(),
131  momentumSign*originalPar.momentum(),
132  originalPar.charge(),
133  &originalPar.magneticField());
134  */
135 
136  /*FastCircle helix(*thirdPoint, *secondPoint, *firstPoint);
137  GlobalTrajectoryParameters newPar = GlobalTrajectoryParameters(*secondPoint,
138  momentumSign*originalPar.momentum(),
139  originalPar.charge(),
140  &originalPar.magneticField());*/
141  //FreeTrajectoryState* startingState = new FreeTrajectoryState(newPar, initialError(trHits[0]));//trHits[1]));
142  if (!qualityFilter(momentumSign * originalStartingState.momentum()))
143  return nullptr;
144  //TrajectorySeed* seed = buildSeed(startingState, trHits, dir);
146  buildSeed(momentumSign * originalStartingState.momentum(), originalStartingState.charge(), trHits, dir);
147  return seed;
148 }
149 
151  const PropagationDirection& dir,
152  const NavigationDirection& seedDir,
153  int charge) const {
154  if (hits.size() != 2) {
155  throw cms::Exception("CombinatorialSeedGeneratorForCosmics")
156  << "call to SeedFromGenericPairOrTriplet::seedFromPair with " << hits.size() << " hits ";
157  }
158  auto innerHit = hits[0];
159  auto outerHit = hits[1];
160  GlobalPoint inner = theTracker->idToDet(innerHit->geographicalId())->surface().toGlobal(innerHit->localPosition());
161  GlobalPoint outer = theTracker->idToDet(outerHit->geographicalId())->surface().toGlobal(outerHit->localPosition());
162  LogDebug("SeedFromGenericPairOrTriplet")
163  << "Using the following hits: outer(r, phi, theta) (" << outer.perp() << ", " << outer.phi() << ","
164  << outer.theta() << ") inner (" << inner.perp() << ", " << inner.phi() << "," << inner.theta() << ")";
165  GlobalPoint* firstPoint = nullptr;
166  GlobalPoint* secondPoint = nullptr;
167  int momentumSign = 1;
168  //const TrackingRecHit* firstHit = 0;
169  //const TrackingRecHit* secondHit = 0;
170  std::vector<const BaseTrackerRecHit*> trHits;
171  //choose the prop dir and hit order accordingly to where the seed is made
172  if (seedDir == outsideIn) {
173  LogDebug("SeedFromGenericPairOrTriplet") << "Seed from outsideIn alongMomentum OR insideOut oppositeToMomentum";
174  firstPoint = &outer;
175  secondPoint = &inner;
176  //firstHit = outerHit;
177  //secondHit = innerHit;
178  trHits.push_back(outerHit);
179  trHits.push_back(innerHit);
180  } else {
181  LogDebug("SeedFromGenericPairOrTriplet") << "Seed from outsideIn oppositeToMomentum OR insideOut alongMomentum";
182  firstPoint = &inner;
183  secondPoint = &outer;
184  momentumSign = -1;
185  //firstHit = innerHit;
186  //secondHit = outerHit;
187  trHits.push_back(innerHit);
188  trHits.push_back(outerHit);
189  }
190  if (dir == oppositeToMomentum)
191  momentumSign = -1;
192  GlobalVector momentum = momentumSign * theP * (*secondPoint - *firstPoint).unit();
193  /*GlobalTrajectoryParameters gtp(*firstPoint,
194  momentum,
195  charge,
196  &(*theMagfield));*/
197  //FreeTrajectoryState* startingState = new FreeTrajectoryState(gtp,initialError(trHits[0]));//trHits[1]));
198  //if (!qualityFilter(startingState, hits)) return 0;
199  //TrajectorySeed* seed = buildSeed(startingState, firstHit, dir);
200  //TrajectorySeed* seed = buildSeed(startingState, trHits, dir);
201  TrajectorySeed* seed = buildSeed(momentum, charge, trHits, dir);
202  return seed;
203 }
204 
206  int charge,
207  //const TrackingRecHit* firsthit,
208  std::vector<const BaseTrackerRecHit*>& trHits,
209  const PropagationDirection& dir) const {
211  if (dir == oppositeToMomentum)
213 
214  //debug
215  GlobalPoint first = theTracker->idToDet(trHits[0]->geographicalId())->surface().toGlobal(trHits[0]->localPosition());
216  GlobalPoint second = theTracker->idToDet(trHits[1]->geographicalId())->surface().toGlobal(trHits[1]->localPosition());
217  LogDebug("SeedFromGenericPairOrTriplet")
218  << "Using the following hits: first(r, phi, theta) (" << first.perp() << ", " << first.phi() << ","
219  << first.theta() << ") second (" << second.perp() << ", " << second.phi() << "," << second.theta() << ")";
220  //build an initial trajectory state with big errors,
221  //then update it with the first hit
222  auto transHit = trHits[0];
223  LocalVector lmom = transHit->surface()->toLocal(momentum);
224  LocalTrajectoryParameters ltp(charge / momentum.mag(),
225  lmom.x() / lmom.z(),
226  lmom.y() / lmom.z(),
227  transHit->localPosition().x(),
228  transHit->localPosition().y(),
229  lmom.z() > 0. ? 1. : -1.);
230 
231  LocalTrajectoryError lte(100.,
232  100.,
233  (1. + (lmom.x() / lmom.z()) * (lmom.x() / lmom.z())),
234  (1. + (lmom.y() / lmom.z()) * (lmom.y() / lmom.z())),
235  1. / momentum.mag());
236 
237  TrajectoryStateOnSurface initialState(ltp, lte, *transHit->surface(), &(*theMagfield));
239  TrajectoryStateOnSurface startingState = updator.update(initialState, *transHit);
240 
241  auto transHit2 = trHits[1];
242 
243  //TrajectoryStateOnSurface seedTSOS(*startingState, *plane);
244  const TrajectoryStateOnSurface propTSOS = propagator->propagate(startingState, *(transHit2->surface()));
245  if (!propTSOS.isValid()) {
246  LogDebug("SeedFromGenericPairOrTriplet") << "first propagation failed";
247  return nullptr;
248  }
249  TrajectoryStateOnSurface seedTSOS = updator.update(propTSOS, *transHit2);
250  if (!seedTSOS.isValid()) {
251  LogDebug("SeedFromGenericPairOrTriplet") << "first update failed";
252  return nullptr;
253  }
254  LogDebug("SeedFromGenericPairOrTriplet") << "starting TSOS " << seedTSOS;
256  PTrajectoryStateOnDet PTraj =
257  trajectoryStateTransform::persistentState(seedTSOS, trHits[1]->geographicalId().rawId());
259  //build the transientTrackingRecHit for the starting hit, then call the method clone to rematch if needed
260  for (auto ihits = trHits.begin(); ihits != trHits.end(); ihits++) {
261  seed_hits.push_back((*ihits)->clone());
262  }
263  TrajectorySeed* seed = new TrajectorySeed(PTraj, seed_hits, dir);
264  return seed;
265 }
266 /*
267 CurvilinearTrajectoryError SeedFromGenericPairOrTriplet::initialError(const TrackingRecHit* rechit) {
268  SeedingHitSet::RecHitPointer transHit = theBuilder->build(rechit);
269  //AlgebraicSymMatrix C(5,1);
270  AlgebraicSymMatrix55 C = AlgebraicMatrixID();
271  //C*=0.1;
272  if (theSetMomentum){
273  C(0,0)=1/theP;
274  C(3,3)=transHit->globalPositionError().cxx();
275  C(4,4)=transHit->globalPositionError().czz();
276 
277  //C[0][0]=1/theP;
278  //C[3][3]=transHit->globalPositionError().cxx();
279  //C[4][4]=transHit->globalPositionError().czz();
280  } else {
281  float zErr = transHit->globalPositionError().czz();
282  float transverseErr = transHit->globalPositionError().cxx(); // assume equal cxx cyy
283  C(3,3) = transverseErr;
284  C(4,4) = zErr;
285  //C[3][3] = transverseErr;
286  //C[4][4] = zErr;
287  }
288 
289  return CurvilinearTrajectoryError(C);
290 }
291 */
293  //if we are setting the momentum with the PSet we look for aligned hits
294  if (theSetMomentum) {
295  if (hits.size() == 3) {
296  std::vector<GlobalPoint> gPoints;
297  unsigned int nHits = hits.size();
298  for (unsigned int iHit = 0; iHit < nHits; ++iHit)
299  gPoints.push_back(hits[iHit]->globalPosition());
300  unsigned int subid = (*hits[0]).geographicalId().subdetId();
301  if (subid == StripSubdetector::TEC || subid == StripSubdetector::TID) {
302  LogDebug("SeedFromGenericPairOrTriplet")
303  << "In the endcaps we cannot decide if hits are aligned with only phi and z";
304  return true;
305  }
306  FastCircle circle(gPoints[0], gPoints[1], gPoints[2]);
307  if (circle.rho() < 500 && circle.rho() != 0) {
308  LogDebug("SeedFromGenericPairOrTriplet") << "Seed qualityFilter rejected because rho = " << circle.rho();
309  return false;
310  }
311  }
312  }
313  return true;
314 }
315 
317  if (!theSetMomentum) {
318  if (momentum.perp() < theP)
319  return false;
320  }
321  return true;
322 }
Vector3DBase
Definition: Vector3DBase.h:8
SeedFromGenericPairOrTriplet::theP
float theP
Definition: SeedFromGenericPairOrTriplet.h:76
TrackerGeometry::idToDet
const TrackerGeomDet * idToDet(DetId) const override
Definition: TrackerGeometry.cc:193
TrajectoryStateOnSurface.h
CosmicGenFilterHelix_cfi.charges
charges
only generated particles of these IDs are considered
Definition: CosmicGenFilterHelix_cfi.py:6
SeedFromGenericPairOrTriplet::seedFromTriplet
TrajectorySeed * seedFromTriplet(const SeedingHitSet &hits, const PropagationDirection &dir, const NavigationDirection &seedDir, const edm::EventSetup &iSetup, int charge=-1) const
Definition: SeedFromGenericPairOrTriplet.cc:65
MessageLogger.h
FastHelix.h
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
SeedingHitSet
Definition: SeedingHitSet.h:6
SeedFromGenericPairOrTriplet::buildSeed
TrajectorySeed * buildSeed(const GlobalVector &momentum, int charge, std::vector< const BaseTrackerRecHit * > &trHits, const PropagationDirection &dir) const
Definition: SeedFromGenericPairOrTriplet.cc:205
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
FastHelix
Definition: FastHelix.h:26
PV3DBase::theta
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
trajectoryStateTransform::persistentState
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
Definition: TrajectoryStateTransform.cc:14
oppositeToMomentum
Definition: PropagationDirection.h:4
SeedFromGenericPairOrTriplet::seed
std::vector< TrajectorySeed * > seed(const SeedingHitSet &hits, const PropagationDirection &dir, const NavigationDirection &seedDir, const edm::EventSetup &iSetup)
Definition: SeedFromGenericPairOrTriplet.cc:28
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
TransientTrackingRecHit.h
SeedFromGenericPairOrTriplet::SeedFromGenericPairOrTriplet
SeedFromGenericPairOrTriplet(const MagneticField *mf, const TrackerGeometry *geom, const TransientTrackingRecHitBuilder *builder, const Propagator *propagatorAlong, const Propagator *propagatorOpposite, const std::vector< int > &charges, bool momFromPSet, double errorRescaling)
Definition: SeedFromGenericPairOrTriplet.cc:11
SeedFromGenericPairOrTriplet::theMagfield
const MagneticField * theMagfield
Definition: SeedFromGenericPairOrTriplet.h:70
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
LocalTrajectoryParameters
Definition: LocalTrajectoryParameters.h:25
Propagator
Definition: Propagator.h:44
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
FastCircle::rho
double rho() const
Definition: FastCircle.h:47
TrackCandidateProducer_cfi.propagator
propagator
Definition: TrackCandidateProducer_cfi.py:17
nHits
const caConstants::TupleMultiplicity *__restrict__ const HitsOnGPU *__restrict__ double *__restrict__ float *__restrict__ double *__restrict__ uint32_t nHits
Definition: BrokenLineFitOnGPU.h:27
SurfaceOrientation::inner
Definition: Surface.h:19
SeedFromGenericPairOrTriplet::theTracker
const TrackerGeometry * theTracker
Definition: SeedFromGenericPairOrTriplet.h:71
Surface::toGlobal
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
HLTSiStripMonitoring_cff.errorRescaling
errorRescaling
Definition: HLTSiStripMonitoring_cff.py:192
MagneticField::nominalValue
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:49
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
Point3DBase< float, GlobalTag >
SeedFromGenericPairOrTriplet::thePropagatorOpposite
const Propagator * thePropagatorOpposite
Definition: SeedFromGenericPairOrTriplet.h:74
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
SeedFromGenericPairOrTriplet.h
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
LocalTrajectoryError
Definition: LocalTrajectoryError.h:20
HLT_FULL_cff.updator
updator
Definition: HLT_FULL_cff.py:123
GeomDet::toGlobal
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
KFUpdator.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
HLT_FULL_cff.propagatorOpposite
propagatorOpposite
Definition: HLT_FULL_cff.py:116
SeedFromGenericPairOrTriplet::thePropagatorAlong
const Propagator * thePropagatorAlong
Definition: SeedFromGenericPairOrTriplet.h:73
SeedFromGenericPairOrTriplet::seedFromPair
TrajectorySeed * seedFromPair(const SeedingHitSet &hits, const PropagationDirection &dir, const NavigationDirection &seedDir, int charge=-1) const
Definition: SeedFromGenericPairOrTriplet.cc:150
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
edm::EventSetup
Definition: EventSetup.h:58
SeedFromGenericPairOrTriplet::theErrorRescaling
double theErrorRescaling
Definition: SeedFromGenericPairOrTriplet.h:79
FastCircle
Definition: FastCircle.h:33
unit
Basic3DVector unit() const
Definition: Basic3DVectorLD.h:162
TrajectoryStateOnSurface::rescaleError
void rescaleError(double factor)
Definition: TrajectoryStateOnSurface.h:82
PV3DBase::mag
T mag() const
Definition: PV3DBase.h:64
HLT_FULL_cff.propagatorAlong
propagatorAlong
Definition: HLT_FULL_cff.py:118
GeomDet.h
DetachedQuadStep_cff.seeds
seeds
Definition: DetachedQuadStep_cff.py:195
NavigationDirection
NavigationDirection
Definition: NavigationDirection.h:4
StripSubdetector::TEC
static constexpr auto TEC
Definition: StripSubdetector.h:19
SeedFromGenericPairOrTriplet::qualityFilter
bool qualityFilter(const SeedingHitSet &hits) const
Definition: SeedFromGenericPairOrTriplet.cc:292
outsideIn
Definition: NavigationDirection.h:4
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
Exception
Definition: hltDiff.cc:245
PropagationDirection
PropagationDirection
Definition: PropagationDirection.h:4
TrajectorySeed
Definition: TrajectorySeed.h:18
edm::OwnVector::push_back
void push_back(D *&d)
Definition: OwnVector.h:326
PTrajectoryStateOnDet
Definition: PTrajectoryStateOnDet.h:10
SurfaceOrientation::outer
Definition: Surface.h:19
MagneticField
Definition: MagneticField.h:19
TransientTrackingRecHitBuilder
Definition: TransientTrackingRecHitBuilder.h:6
GlobalPoint.h
StripSubdetector.h
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
SeedFromGenericPairOrTriplet::theSetMomentum
bool theSetMomentum
Definition: SeedFromGenericPairOrTriplet.h:77
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
KFUpdator
Definition: KFUpdator.h:32
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
SeedFromGenericPairOrTriplet::theCharges
std::vector< int > theCharges
Definition: SeedFromGenericPairOrTriplet.h:78
edm::OwnVector< TrackingRecHit >
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
TrackerGeometry
Definition: TrackerGeometry.h:14