CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SeedFromGenericPairOrTriplet.cc
Go to the documentation of this file.
10 
12  const TrackerGeometry* geom,
13  const TransientTrackingRecHitBuilder* builder,
14  const Propagator* propagatorAlong,
15  const Propagator* propagatorOpposite,
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  const TrackingRecHit* innerHit = hits[0]->hit();
64  const TrackingRecHit* middleHit = hits[1]->hit();
65  const TrackingRecHit* outerHit = hits[2]->hit();
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 0;
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 = 0;
97  GlobalPoint* secondPoint = 0;
98  GlobalPoint* thirdPoint = 0;
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 TrackingRecHit*> 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, iSetup);
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 0;
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  const TrackingRecHit* innerHit = hits[0]->hit();
156  const TrackingRecHit* outerHit = hits[1]->hit();
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 = 0;
168  GlobalPoint* secondPoint = 0;
169  int momentumSign = 1;
170  //const TrackingRecHit* firstHit = 0;
171  //const TrackingRecHit* secondHit = 0;
172  std::vector<const TrackingRecHit*> 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 TrackingRecHit*>& 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
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));
244  KFUpdator updator;
245  TrajectoryStateOnSurface startingState = updator.update(initialState,*transHit);
246 
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 0;
254  }
255  TrajectoryStateOnSurface seedTSOS = updator.update(propTSOS, *transHit2);
256  if (!seedTSOS.isValid()){
257  LogDebug("SeedFromGenericPairOrTriplet") << "first update failed";
258  return 0;
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  std::vector<const TrackingRecHit*>::const_iterator ihits;
267  for (ihits = trHits.begin(); ihits != trHits.end(); ihits++){
268  seed_hits.push_back((*ihits)->clone());
269  }
270  TrajectorySeed* seed = new TrajectorySeed(PTraj,seed_hits,dir);
271  return seed;
272 }
273 /*
274 CurvilinearTrajectoryError SeedFromGenericPairOrTriplet::initialError(const TrackingRecHit* rechit) {
275  TransientTrackingRecHit::RecHitPointer transHit = theBuilder->build(rechit);
276  //AlgebraicSymMatrix C(5,1);
277  AlgebraicSymMatrix55 C = AlgebraicMatrixID();
278  //C*=0.1;
279  if (theSetMomentum){
280  C(0,0)=1/theP;
281  C(3,3)=transHit->globalPositionError().cxx();
282  C(4,4)=transHit->globalPositionError().czz();
283 
284  //C[0][0]=1/theP;
285  //C[3][3]=transHit->globalPositionError().cxx();
286  //C[4][4]=transHit->globalPositionError().czz();
287  } else {
288  float zErr = transHit->globalPositionError().czz();
289  float transverseErr = transHit->globalPositionError().cxx(); // assume equal cxx cyy
290  C(3,3) = transverseErr;
291  C(4,4) = zErr;
292  //C[3][3] = transverseErr;
293  //C[4][4] = zErr;
294  }
295 
296  return CurvilinearTrajectoryError(C);
297 }
298 */
300  //if we are setting the momentum with the PSet we look for aligned hits
301  if (theSetMomentum){
302  if (hits.size()==3){
303  std::vector<GlobalPoint> gPoints;
304  unsigned int nHits = hits.size();
305  for (unsigned int iHit = 0; iHit < nHits; ++iHit) gPoints.push_back(hits[iHit]->globalPosition());
306  unsigned int subid=(*hits[0]).geographicalId().subdetId();
307  if(subid == StripSubdetector::TEC || subid == StripSubdetector::TID){
308  LogDebug("SeedFromGenericPairOrTriplet")
309  << "In the endcaps we cannot decide if hits are aligned with only phi and z";
310  return true;
311  }
312  FastCircle circle(gPoints[0],
313  gPoints[1],
314  gPoints[2]);
315  if (circle.rho() < 500 && circle.rho() != 0) {
316  LogDebug("SeedFromGenericPairOrTriplet") <<
317  "Seed qualityFilter rejected because rho = " << circle.rho();
318  return false;
319  }
320 
321  }
322  }
323  return true;
324 }
325 
327  if (!theSetMomentum){
328  if (momentum.perp() < theP) return false;
329  }
330  return true;
331 }
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:78
FTS stateAtVertex() const
Definition: FastHelix.cc:7
T perp() const
Definition: PV3DBase.h:71
void update(const LocalTrajectoryParameters &p, const Surface &aSurface, const MagneticField *field, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
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:47
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
T y() const
Definition: PV3DBase.h:62
PropagationDirection
TrackCharge charge() const
double charge(const std::vector< uint8_t > &Ampls)
double rho() const
Definition: FastCircle.h:54
Geom::Theta< T > theta() const
Definition: PV3DBase.h:74
U second(std::pair< T, U > const &p)
void push_back(D *&d)
Definition: OwnVector.h:273
T mag() const
Definition: PV3DBase.h:66
const TransientTrackingRecHitBuilder * theBuilder
string unit
Definition: csvLumiCalc.py:46
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
T z() const
Definition: PV3DBase.h:63
TrajectorySeed * seedFromTriplet(const SeedingHitSet &hits, const PropagationDirection &dir, const NavigationDirection &seedDir, const edm::EventSetup &iSetup, int charge=-1) const
bool first
Definition: L1TdeRCT.cc:94
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
virtual const GeomDet * idToDet(DetId) const
GlobalVector momentum() const
TrajectorySeed * buildSeed(const GlobalVector &momentum, int charge, std::vector< const TrackingRecHit * > &trHits, const PropagationDirection &dir) const
virtual TrajectoryStateOnSurface propagate(const FreeTrajectoryState &, const Surface &) const
Definition: Propagator.cc:12
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
const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
unsigned int size() const
Definition: SeedingHitSet.h:31
DetId geographicalId() const
dbl *** dir
Definition: mlp_gen.cc:35
T x() const
Definition: PV3DBase.h:61
virtual LocalPoint localPosition() const =0