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