CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RoadSearchCloudMakerAlgorithm.cc
Go to the documentation of this file.
1 //
2 // Package: RecoTracker/RoadSearchCloudMaker
3 // Class: RoadSearchCloudMakerAlgorithm
4 //
5 // Description:
6 // Road categories determined by outer Seed RecHit
7 // RPhi: outer Seed RecHit in the Barrel
8 // ZPhi: outer Seed RecHit in the Disks
9 // use inner and outer Seed RecHit and BeamSpot to calculate extrapolation
10 // RPhi: phi = phi0 + asin(k r)
11 // ZPhi: phi = phi0 + C z
12 // Loop over RoadSet, access Rings of Road
13 // get average radius of Ring
14 // use extrapolation to calculate phi_ref at average Ring radius
15 // determine window in phi for DetId lookup in the Ring
16 // phi_ref ± phi_window
17 // PARAMETER: phi_window = pi/24
18 // loop over DetId's in phi window in Ring
19 // two cases (problem of phi = 0/2pi):
20 // lower window border < upper window border
21 // upper window border < lower window border
22 // Loop over RecHits of DetId
23 // check compatibility of RecHit with extrapolation (delta phi cut)
24 // single layer sensor treatment
25 // RPhi:
26 // stereo and barrel single layer sensor
27 // calculate delta-phi
28 // disk single layer sensor (r coordinate not well defined)
29 // calculate delta phi between global positions of maximal strip extension and reference
30 // ZPhi:
31 // stereo sensor
32 // calculate delta-phi
33 // barrel single layer sensor (z coordinate not well defined)
34 // calculate delta phi between global positions of maximal strip extension and reference
35 // disk single layer sensor (tilted strips relative to local coordinate system of sensor
36 // calculate delta phi between global positions of maximal strip extension and reference
37 // Check delta phi cut
38 // cut value can be calculated based on extrapolation and Seed (pT dependent delta phi cut)
39 // currently: constant delta phi cut (PARAMETER)
40 // fill RecHit into Cloud
41 // do not fill more than 32 RecHits per DetID into cloud (PARAMETER)
42 // first stage of Cloud cleaning cuts:
43 // number of layers with hits in cloud (PARAMETER)
44 // number of layers with no hits in cloud (PARAMETER)
45 // number of consecutive layers with no hits in cloud (PARAMETER)
46 //
47 // Original Author: Oliver Gutsche, gutsche@fnal.gov
48 // Created: Sat Jan 14 22:00:00 UTC 2006
49 //
50 // $Author: gpetrucc $
51 // $Date: 2008/10/31 16:02:33 $
52 // $Revision: 1.56 $
53 //
54 
55 #include <vector>
56 #include <iostream>
57 #include <cmath>
58 
60 
62 
67 
81 
88 
91 
93 
95 
98 
99 using namespace std;
100 
101 double RoadSearchCloudMakerAlgorithm::epsilon = 0.000000001;
102 
105  recHitVectorClass.use_rphiRecHits(conf_.getParameter<bool>("UseRphiRecHits"));
106  recHitVectorClass.use_stereoRecHits(conf_.getParameter<bool>("UseStereoRecHits"));
107 
108 
109  theRPhiRoadSize = conf_.getParameter<double>("RPhiRoadSize");
110  theZPhiRoadSize = conf_.getParameter<double>("ZPhiRoadSize");
111  UsePixels = conf_.getParameter<bool>("UsePixelsinRS");
112  NoFieldCosmic = conf_.getParameter<bool>("StraightLineNoBeamSpotCloud");
113  theMinimumHalfRoad = conf_.getParameter<double>("MinimumHalfRoad");
114 
115  maxDetHitsInCloudPerDetId = conf_.getParameter<unsigned int>("MaxDetHitsInCloudPerDetId");
116  minFractionOfUsedLayersPerCloud = conf_.getParameter<double>("MinimalFractionOfUsedLayersPerCloud");
117  maxFractionOfMissedLayersPerCloud = conf_.getParameter<double>("MaximalFractionOfMissedLayersPerCloud");
118  maxFractionOfConsecutiveMissedLayersPerCloud = conf_.getParameter<double>("MaximalFractionOfConsecutiveMissedLayersPerCloud");
119  increaseMaxNumberOfConsecutiveMissedLayersPerCloud = conf_.getParameter<unsigned int>("IncreaseMaxNumberOfConsecutiveMissedLayersPerCloud");
120  increaseMaxNumberOfMissedLayersPerCloud = conf_.getParameter<unsigned int>("IncreaseMaxNumberOfMissedLayersPerCloud");
121 
122  doCleaning_ = conf.getParameter<bool>("DoCloudCleaning");
123  mergingFraction_ = conf.getParameter<double>("MergingFraction");
124  maxRecHitsInCloud_ = (unsigned int)conf.getParameter<int>("MaxRecHitsInCloud");
125  scalefactorRoadSeedWindow_ = conf.getParameter<double>("scalefactorRoadSeedWindow");
126 
127  roadsLabel_ = conf.getParameter<std::string>("RoadsLabel");
128 
129 }
130 
132 
133 }
134 
136  // map phi to [0,2pi]
137  double result = phi;
138  if ( result < -1.0*Geom::twoPi()) result = result + Geom::twoPi();
139  if ( result < 0) result = Geom::twoPi() + result;
140  if ( result > Geom::twoPi()) result = result - Geom::twoPi();
141  return result;
142 }
143 
145  // map phi to [-pi,pi]
146  double result = phi;
147  if ( result < 1.0*Geom::pi() ) result = result + Geom::twoPi();
148  if ( result >= Geom::pi()) result = result - Geom::twoPi();
149  return result;
150 }
151 
153  const SiStripRecHit2DCollection* rphiRecHits,
154  const SiStripRecHit2DCollection* stereoRecHits,
155  const SiStripMatchedRecHit2DCollection* matchedRecHits,
156  const SiPixelRecHitCollection *pixRecHits,
157  const edm::EventSetup& es,
159 {
160  // intermediate arrays for storing clouds for cleaning
161  const int nphibin = 24;
162  const int netabin = 24;
163  RoadSearchCloudCollection CloudArray[nphibin][netabin];
164 
165  // get roads
167  es.get<RoadMapRecord>().get(roadsLabel_, roads);
168 
169  // get RoadSearchSeed collection
170  const RoadSearchSeedCollection* inputSeeds = input.product();
171 
172  // set collections for general hit access method
173  recHitVectorClass.setCollections(rphiRecHits,stereoRecHits,matchedRecHits,pixRecHits);
175 
176  // get tracker geometry
178  es.get<TrackerDigiGeometryRecord>().get(tracker);
179 
180  // get hit matcher
181  SiStripRecHitMatcher* theHitMatcher = new SiStripRecHitMatcher(3.0);
182 
183  edm::LogInfo("RoadSearch") << "Found " << inputSeeds->size() << " input seeds.";
184  // loop over seeds
185  for ( RoadSearchSeedCollection::const_iterator seed = inputSeeds->begin(); seed != inputSeeds->end(); ++seed) {
186 
187  const Roads::RoadSeed *roadSeed = seed->getSeed();
188 
189  if ( roadSeed == 0 ) {
190  edm::LogWarning("RoadSearch") << "RoadSeed could not be resolved from RoadSearchSeed hits, discard seed!";
191  } else {
192 
193  Roads::type roadType = roads->getRoadType(roadSeed);
194  if (NoFieldCosmic) roadType = Roads::RPhi;
195 
196  // fixme: from here on, calculate with 1st and 3rd seed hit (inner and outer of initial circle)
197  // fixme: adapt to new seed structure
198 
199  // get global positions of the hits, calculate before Road lookup to be used
200  const TrackingRecHit* innerSeedRingHit = (*(seed->begin()));
201  const TrackingRecHit* outerSeedRingHit = (*(seed->end() - 1));
202 
203  GlobalPoint innerSeedHitGlobalPosition = tracker->idToDet(innerSeedRingHit->geographicalId())->surface().toGlobal(innerSeedRingHit->localPosition());
204  GlobalPoint outerSeedHitGlobalPosition = tracker->idToDet(outerSeedRingHit->geographicalId())->surface().toGlobal(outerSeedRingHit->localPosition());
205 
206  LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " inner hit (x/y/z): "
207  << innerSeedHitGlobalPosition.x() << " / "
208  << innerSeedHitGlobalPosition.y() << " / "
209  << innerSeedHitGlobalPosition.z();
210  LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " outer hit (x/y/z): "
211  << outerSeedHitGlobalPosition.x() << " / "
212  << outerSeedHitGlobalPosition.y() << " / "
213  << outerSeedHitGlobalPosition.z();
214 
215  LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " inner hit (r/phi): "
216  << innerSeedHitGlobalPosition.perp() << " / "
217  << innerSeedHitGlobalPosition.phi();
218  LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " outer hit (r/phi): "
219  << outerSeedHitGlobalPosition.perp() << " / "
220  << outerSeedHitGlobalPosition.phi();
221 
222 
223  // extrapolation parameters, phio: [0,2pi]
224  double d0 = 0.0;
225  double phi0 = -99.;
226  double k0 = -99999999.99;
227 
228  double phi1 = -99.;
229  double k1 = -99999999.99;
230  // get bins of eta and phi of outer seed hit;
231 
232  double outer_phi = map_phi(outerSeedHitGlobalPosition.phi());
233  double outer_eta = outerSeedHitGlobalPosition.eta();
234 
235  int phibin = (int)(nphibin*(outer_phi/(2*Geom::pi())));
236  int etabin = (int)(netabin*(outer_eta+3.0)/6.0);
237 
238  // calculate phi0 and k0 dependent on RoadType
239  if ( roadType == Roads::RPhi ) {
240  double dr = outerSeedHitGlobalPosition.perp() - innerSeedHitGlobalPosition.perp();
241  const double dr_min = 1; // cm
242  if ( dr < dr_min ) {
243  edm::LogWarning("RoadSearch") << "RPhi road: seed Hits distance smaller than 1 cm, do not consider this seed.";
244  } else {
245  // calculate r-phi extrapolation: phi = phi0 + asin(k0 r)
246  double det = innerSeedHitGlobalPosition.x() * outerSeedHitGlobalPosition.y() - innerSeedHitGlobalPosition.y() * outerSeedHitGlobalPosition.x();
247  if ( det == 0 ) {
248  edm::LogWarning("RoadSearch") << "RPhi road: 'det' == 0, do not consider this seed.";
249  } else {
250  double x0=0.0; double y0=0.0;
251  double innerx=innerSeedHitGlobalPosition.x();
252  double innery=innerSeedHitGlobalPosition.y();
253  double outerx=outerSeedHitGlobalPosition.x();
254  double outery=outerSeedHitGlobalPosition.y();
255 
256  if (NoFieldCosmic){
257  phi0=atan2(outery-innery,outerx-innerx);
258  double alpha=atan2(innery,innerx);
259  double d1=sqrt(innerx*innerx+innery*innery);
260  d0=d1*sin(alpha-phi0); x0=-d0*sin(phi0); y0=d0*cos(phi0); k0=0.0;
261  }else{
262  makecircle(innerx,innery,outerx,outery,x0,y0);
263  phi0 = phi0h;
264  k0 = omegah;
265  }
266  LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " trajectory parameters: d0 = "<< d0 << " phi0 = " << phi0;
267  }
268  }
269  } else {
270  double dz = outerSeedHitGlobalPosition.z() - innerSeedHitGlobalPosition.z();
271  const double dz_min = 1.e-6; // cm;
272  if ( std::abs(dz) < dz_min ) {
273  edm::LogWarning("RoadSearch") << "ZPhi road: seed Hits are less than .01 microns away in z, do not consider this seed.";
274  } else {
275  // calculate z-phi extrapolation: phi = phi0 + k0 z
276  k0 = map_phi2(outerSeedHitGlobalPosition.phi() - innerSeedHitGlobalPosition.phi()) / dz;
277  phi0 = map_phi(innerSeedHitGlobalPosition.phi() - k0 * innerSeedHitGlobalPosition.z());
278 
279  // get approx pt for use in correcting matched hits
280  makecircle(innerSeedHitGlobalPosition.x(),innerSeedHitGlobalPosition.y(),
281  outerSeedHitGlobalPosition.x(),outerSeedHitGlobalPosition.y(),
282  0.0,0.0); // x0,y0 = 0.0 for now
283  phi1 = phi0h;
284  k1 = omegah;
285  }
286  }
287 
288  // continue if valid extrapolation parameters have been found
289  if ( (phi0 != -99.) && (k0 != -99999999.99) ) {
290  const Roads::RoadSet *roadSet = seed->getSet();
291 
292  // create cloud
293  RoadSearchCloud cloud;
294 
295  bool firstHitFound = false;
296  unsigned int layerCounter = 0;
297  unsigned int usedLayers = 0;
298  unsigned int missedLayers = 0;
299  unsigned int consecutiveMissedLayers = 0;
300 
301  unsigned int totalLayers = roadSet->size();
302 
303  // caluclate minNumberOfUsedLayersPerCloud, maxNumberOfMissedLayersPerCloud and maxNumberOfConsecutiveMissedLayersPerCloud
304  // by rounding to integer minFractionOfUsedLayersPerCloud. maxFractionOfMissedLayersPerCloud and maxFractionOfConsecutiveMissedLayersPerCloud
305  unsigned int minNumberOfUsedLayersPerCloud = static_cast<unsigned int>(totalLayers * minFractionOfUsedLayersPerCloud + 0.5);
306  if (minNumberOfUsedLayersPerCloud < 3) minNumberOfUsedLayersPerCloud = 3;
307  unsigned int maxNumberOfMissedLayersPerCloud = static_cast<unsigned int>(totalLayers * maxFractionOfMissedLayersPerCloud + 0.5);
308  unsigned int maxNumberOfConsecutiveMissedLayersPerCloud = static_cast<unsigned int>(totalLayers * maxFractionOfConsecutiveMissedLayersPerCloud + 0.5);
309 
310  // increase consecutive layer cuts between 0.9 and 1.5
311  if (std::abs(outer_eta) > 0.9 && std::abs(outer_eta) < 1.5) {
312  maxNumberOfConsecutiveMissedLayersPerCloud += increaseMaxNumberOfConsecutiveMissedLayersPerCloud;
313  maxNumberOfMissedLayersPerCloud += increaseMaxNumberOfMissedLayersPerCloud;
314  }
315 
316  for ( Roads::RoadSet::const_iterator roadSetVector = roadSet->begin();
317  roadSetVector != roadSet->end();
318  ++roadSetVector ) {
319 
320  ++layerCounter;
321  unsigned int usedHitsInThisLayer = 0;
322  bool intersectsLayer = false;
323 
324  for ( std::vector<const Ring*>::const_iterator ring = roadSetVector->begin(); ring != roadSetVector->end(); ++ring ) {
325 
326  // calculate phi-range for lookup of DetId's in Rings of RoadSet
327  // calculate phi at radius of Ring using extrapolation, Ring radius average of Ring.rmin() and Ring.rmax()
328  double ringRadius = (*ring)->getrmin() + ((*ring)->getrmax()-(*ring)->getrmin())/2;
329  double ringZ = (*ring)->getzmin() + ((*ring)->getzmax()-(*ring)->getzmin())/2;
330  double ringPhi = 0.0;
331  if ( roadType == Roads::RPhi ) {
332  ringPhi = phiFromExtrapolation(d0,phi0,k0,ringRadius,roadType);
333  } else {
334  ringPhi = phiFromExtrapolation(d0,phi0,k0,ringZ,roadType);
335  }
336  if (ringPhi == -99) continue;
337  intersectsLayer = true;
338 
339  LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " testing ring at R = " << ringRadius
340  << " Z = " << ringZ << " ringPhi = " << ringPhi;
341 
342  int nDetIds = (*ring)->getNumDetIds();
343  double theHalfRoad = theMinimumHalfRoad*(2.0*Geom::pi())/((double)nDetIds);
344  // calculate range in phi around ringPhi
345  double upperPhiRangeBorder = map_phi2(ringPhi + theHalfRoad);
346  double lowerPhiRangeBorder = map_phi2(ringPhi - theHalfRoad);
347 
348  if ( lowerPhiRangeBorder <= upperPhiRangeBorder ) {
349 
350  for ( Ring::const_iterator detid = (*ring)->lower_bound(lowerPhiRangeBorder); detid != (*ring)->upper_bound(upperPhiRangeBorder); ++detid) {
351  usedHitsInThisLayer += FillRecHitsIntoCloudGeneral(detid->second,d0,phi0,k0,phi1,k1,roadType,ringPhi,
352  tracker.product(),theHitMatcher,cloud);
353  }
354 
355  } else {
356  for ( Ring::const_iterator detid = (*ring)->lower_bound(lowerPhiRangeBorder); detid != (*ring)->end(); ++detid) {
357  usedHitsInThisLayer += FillRecHitsIntoCloudGeneral(detid->second,d0,phi0,k0,phi1,k1,roadType,ringPhi,
358  tracker.product(),theHitMatcher,cloud);
359  }
360 
361  for ( Ring::const_iterator detid = (*ring)->begin(); detid != (*ring)->upper_bound(upperPhiRangeBorder); ++detid) {
362  usedHitsInThisLayer += FillRecHitsIntoCloudGeneral(detid->second,d0,phi0,k0,phi1,k1,roadType,ringPhi,
363  tracker.product(),theHitMatcher,cloud);
364  }
365  }
366  LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " now has " << usedHitsInThisLayer << " hits in ring at R = " << ringRadius
367  << " Z = " << ringZ << " ringPhi = " << ringPhi;
368  }
369 
370  if ( !firstHitFound ) {
371  if ( usedHitsInThisLayer > 0 ) {
372 
373  firstHitFound = true;
374 
375  // reset totalLayers according to first layer with hit
376  totalLayers = roadSet->size() - layerCounter + 1;
377 
378  // re-caluclate minNumberOfUsedLayersPerCloud, maxNumberOfMissedLayersPerCloud and maxNumberOfConsecutiveMissedLayersPerCloud
379  // by rounding to integer minFractionOfUsedLayersPerCloud. maxFractionOfMissedLayersPerCloud and maxFractionOfConsecutiveMissedLayersPerCloud
380  minNumberOfUsedLayersPerCloud = static_cast<unsigned int>(totalLayers * minFractionOfUsedLayersPerCloud + 0.5);
381  if (minNumberOfUsedLayersPerCloud < 3) minNumberOfUsedLayersPerCloud = 3;
382  maxNumberOfMissedLayersPerCloud = static_cast<unsigned int>(totalLayers * maxFractionOfMissedLayersPerCloud + 0.5);
383  maxNumberOfConsecutiveMissedLayersPerCloud = static_cast<unsigned int>(totalLayers * maxFractionOfConsecutiveMissedLayersPerCloud + 0.5);
384 
385  // increase consecutive layer cuts between 0.9 and 1.5
386  if (std::abs(outer_eta) > 0.9 && std::abs(outer_eta) < 1.5) {
387  maxNumberOfConsecutiveMissedLayersPerCloud += increaseMaxNumberOfConsecutiveMissedLayersPerCloud;
388  maxNumberOfMissedLayersPerCloud += increaseMaxNumberOfMissedLayersPerCloud;
389  }
390 
391  ++usedLayers;
392  consecutiveMissedLayers = 0;
393 
394  }
395  } else {
396  if (intersectsLayer){
397  if ( usedHitsInThisLayer > 0 ) {
398  ++usedLayers;
399  consecutiveMissedLayers = 0;
400  } else {
401  ++ missedLayers;
402  ++consecutiveMissedLayers;
403  }
404  }
405  LogDebug("RoadSearch") << "Seed # "<<seed-inputSeeds->begin() << " Layer info: "
406  << " totalLayers: " << totalLayers
407  << " usedLayers: " << usedLayers
408  << " missedLayers: " << missedLayers
409  << " consecutiveMissedLayers: " << consecutiveMissedLayers;
410 
411  // break condition, hole larger than maxNumberOfConsecutiveMissedLayersPerCloud
412  if ( consecutiveMissedLayers > maxNumberOfConsecutiveMissedLayersPerCloud ) {
413  LogDebug("RoadSearch") << "BREAK: seed # "<<seed-inputSeeds->begin()
414  << " More than " << maxNumberOfConsecutiveMissedLayersPerCloud << " missed consecutive layers!";
415  break;
416  }
417 
418  // break condition, already missed too many layers
419  if ( missedLayers > maxNumberOfMissedLayersPerCloud ) {
420  LogDebug("RoadSearch") << "BREAK: seed # "<<seed-inputSeeds->begin()
421  << " More than " << maxNumberOfMissedLayersPerCloud << " missed layers!";
422  break;
423  }
424 
425  // break condition, cannot satisfy minimal number of used layers
426  if ( totalLayers-missedLayers < minNumberOfUsedLayersPerCloud ) {
427  LogDebug("RoadSearch") << "BREAK: seed # "<<seed-inputSeeds->begin()
428  << " Cannot satisfy at least " << minNumberOfUsedLayersPerCloud << " used layers!";
429  break;
430  }
431  }
432 
433  }
434 
435  if ( consecutiveMissedLayers <= maxNumberOfConsecutiveMissedLayersPerCloud ) {
436  if ( usedLayers >= minNumberOfUsedLayersPerCloud ) {
437  if ( missedLayers <= maxNumberOfMissedLayersPerCloud ) {
438 
439  CloudArray[phibin][etabin].push_back(cloud);
440 
441  if ( roadType == Roads::RPhi ){
442  LogDebug("RoadSearch") << "This r-phi seed # "<<seed-inputSeeds->begin()
443  <<" yields a cloud with " <<cloud.size() <<" hits on " << usedLayers << " layers out of " << totalLayers;
444  } else {
445  LogDebug("RoadSearch") << "This z-phi seed # "<<seed-inputSeeds->begin()
446  <<" yields a cloud with " <<cloud.size() <<" hits on " << usedLayers << " layers out of " << totalLayers;
447  }
448  } else {
449  LogDebug("RoadSearch") << "Missed layers: " << missedLayers << " More than " << maxNumberOfMissedLayersPerCloud << " missed layers!";
450  if ( roadType == Roads::RPhi ){
451  LogDebug("RoadSearch") << "This r-phi seed # "<<seed-inputSeeds->begin() <<" yields no clouds";
452  } else {
453  LogDebug("RoadSearch") << "This z-phi seed # "<<seed-inputSeeds->begin() <<" yields no clouds";
454  }
455  }
456  }
457  else {
458  LogDebug("RoadSearch") << "Seed # "<<seed-inputSeeds->begin() <<" fails: used layers = " << usedLayers << " < " << minNumberOfUsedLayersPerCloud;
459  }
460  }
461  else {
462  LogDebug("RoadSearch") << "Seed # "<<seed-inputSeeds->begin() <<" fails: consecutive missed layers = " << consecutiveMissedLayers << " > " << maxNumberOfConsecutiveMissedLayersPerCloud;
463  }
464  }
465  }
466  }
467 
468  // Loop for initial cleaning
469  for (int iphi=0; iphi<nphibin; ++iphi){
470  for (int ieta=0; ieta<netabin; ++ieta){
471  if (!CloudArray[iphi][ieta].empty()) {
472  if (doCleaning_){
473  RoadSearchCloudCollection temp = Clean(&CloudArray[iphi][ieta]);
474  for ( RoadSearchCloudCollection::const_iterator ic = temp.begin(); ic!=temp.end(); ++ic)
475  output.push_back(*ic);
476  }
477  else
478  for ( RoadSearchCloudCollection::const_iterator ic = CloudArray[iphi][ieta].begin();
479  ic!=CloudArray[iphi][ieta].end(); ++ic)
480  output.push_back(*ic);
481  }
482  }
483  }
484 
485  delete theHitMatcher;
486  edm::LogInfo("RoadSearch") << "Found " << output.size() << " clouds.";
487  for ( RoadSearchCloudCollection::const_iterator ic = output.begin(); ic!=output.end(); ++ic)
488  edm::LogInfo("RoadSearch") << " Cloud " << ic-output.begin()<< " has " << ic->size() << " hits.";
489 
490 }
491 
492 unsigned int RoadSearchCloudMakerAlgorithm::FillRecHitsIntoCloudGeneral(DetId id, double d0, double phi0, double k0, double phi1, double k1,
493  Roads::type roadType, double ringPhi,
494  const TrackerGeometry *tracker, const SiStripRecHitMatcher* theHitMatcher,
495  RoadSearchCloud &cloud) {
496 
497  unsigned int usedRecHits = 0;
498 
499  bool double_ring_layer = !isSingleLayer(id);
500 
501  std::vector<TrackingRecHit*> recHitVector = recHitVectorClass.getHitVector(&id);
502 
503  for ( std::vector<TrackingRecHit*>::const_iterator recHitIterator = recHitVector.begin(); recHitIterator != recHitVector.end(); ++recHitIterator) {
504 
505  if ( (unsigned int)id.subdetId() == StripSubdetector::TIB
506  || (unsigned int)id.subdetId() == StripSubdetector::TOB
507  || (unsigned int)id.subdetId() == StripSubdetector::TID
508  || (unsigned int)id.subdetId() == StripSubdetector::TEC ) {
509 
510  const SiStripRecHit2D *recHit = (SiStripRecHit2D*)(*recHitIterator);
511  DetId hitId = recHit->geographicalId();
512 
513  GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
514  //LogDebug("RoadSearch") << " Testing hit at (x/y/z): " << ghit.x() << " / " << ghit.y() << " / " << ghit.z();
515  LogDebug("RoadSearch") << " Testing hit at (x/y/z): "
516  << tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition()).x() << " / "
517  << tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition()).y() << " / "
518  << tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition()).z();
519 
520  if ( roadType == Roads::RPhi ) {
521  if (double_ring_layer && isSingleLayer(hitId)) {
522  //
523  // This is where the barrel stereoRecHits end up for Roads::RPhi
524  //
525 
526  // Adjust matched hit for track angle
527 
528  const GluedGeomDet *theGluedDet = dynamic_cast<const GluedGeomDet*>(tracker->idToDet(hitId));
529 
530  SiStripMatchedRecHit2D* theCorrectedHit = CorrectMatchedHit(*recHitIterator,theGluedDet,
531  tracker, theHitMatcher,
532  k0, phi0);
533  if (theCorrectedHit != 0){
534 
535  GlobalPoint ghit = tracker->idToDet(theCorrectedHit->geographicalId())->surface().toGlobal(theCorrectedHit->localPosition());
536  double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
537  double hitphi = map_phi(ghit.phi());
538  double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
539 
540  float dp = (hitphi-phi);
541  float dx = hitRadius*tan(dp);
542 
543  LogDebug("RoadSearch") << " Hit phi = " << hitphi << " expected phi = " << phi
544  <<" dx = " << dx << " for dxMax = " << phiMax(roadType,phi0,k0);
545 
546  // switch cut to dx instead of dphi
547  if ( std::abs(dx) < phiMax(roadType,phi0,k0) ) {
548  if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
549  cloud.addHit(recHit);
550  ++usedRecHits;
551  }
552  }
553  delete theCorrectedHit;
554  }
555  } else { // Single layer hits here
556  if ( isBarrelSensor(hitId) ) {
557  //
558  // This is where the barrel rphiRecHits end up for Roads::RPhi
559  //
560  GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
561  double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
562  double hitphi = map_phi(ghit.phi());
563  double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
564 
565  float dp = (hitphi-phi);
566  float dx = hitRadius*tan(dp);
567  LogDebug("RoadSearch") << " Hit phi = " << hitphi << " expected phi = " << phi
568  <<" dx = " << dx << " for dxMax = " << phiMax(roadType,phi0,k0);
569  // switch cut to dx instead of dphi
570  if ( std::abs(dx) < phiMax(roadType,phi0,k0) ) {
571  if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
572  cloud.addHit(recHit);
573  ++usedRecHits;
574  }
575  }
576  }
577  else {
578 
579  LocalPoint hit = recHit->localPosition();
580  const StripTopology *topology = dynamic_cast<const StripTopology*>(&(tracker->idToDetUnit(hitId)->topology()));
581  double stripAngle = topology->stripAngle(topology->strip(hit));
582  double stripLength = topology->localStripLength(hit);
583 
584  LocalPoint innerHitLocal(hit.x()+stripLength/2*std::sin(stripAngle),hit.y()-stripLength/2*std::cos(stripAngle),0);
585  LocalPoint outerHitLocal(hit.x()-stripLength/2*std::sin(stripAngle),hit.y()+stripLength/2*std::cos(stripAngle),0);
586 
587  double innerRadius = tracker->idToDetUnit(hitId)->surface().toGlobal(innerHitLocal).perp();
588  double outerRadius = tracker->idToDetUnit(hitId)->surface().toGlobal(outerHitLocal).perp();
589  double innerExtrapolatedPhi = phiFromExtrapolation(d0,phi0,k0,innerRadius,roadType);
590  double outerExtrapolatedPhi = phiFromExtrapolation(d0,phi0,k0,outerRadius,roadType);
591 
592  GlobalPoint innerHitGlobal =tracker->idToDetUnit(hitId)->surface().toGlobal(innerHitLocal);
593  GlobalPoint outerHitGlobal =tracker->idToDetUnit(hitId)->surface().toGlobal(outerHitLocal);
594 
595  GlobalPoint innerRoadGlobal(GlobalPoint::Cylindrical(innerRadius,innerExtrapolatedPhi,
596  tracker->idToDetUnit(hitId)->surface().toGlobal(hit).z()));
597  GlobalPoint outerRoadGlobal(GlobalPoint::Cylindrical(outerRadius,outerExtrapolatedPhi,
598  tracker->idToDetUnit(hitId)->surface().toGlobal(hit).z()));
599 
600  LocalPoint innerRoadLocal = tracker->idToDetUnit(hitId)->surface().toLocal(innerRoadGlobal);
601  LocalPoint outerRoadLocal = tracker->idToDetUnit(hitId)->surface().toLocal(outerRoadGlobal);
602 
603  double dxinter = CheckXYIntersection(innerHitLocal, outerHitLocal,
604  innerRoadLocal, outerRoadLocal);
605 
606  LogDebug("RoadSearch") << " Hit phi inner = " << innerHitGlobal.phi() << " and outer = " << outerHitGlobal.phi()
607  << " expected inner phi = " << innerExtrapolatedPhi
608  << " and outer phi = " << outerExtrapolatedPhi
609  <<" dx = " << dxinter << " for dxMax = " << phiMax(roadType,phi0,k0);
610 
611  if ( fabs(dxinter) < phiMax(roadType,phi0,k0)) {
612  //
613  // This is where the disk rphiRecHits end up for Roads::ZPhi
614  //
615  if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
616  cloud.addHit(recHit);
617  ++usedRecHits;
618  }
619  }
620  //else
621  //std::cout<< " ===>>> HIT FAILS !!! " << std::endl;
622  }
623  }
624  } else {
625  //
626  // roadType == Roads::ZPhi
627  //
628  if (double_ring_layer && isSingleLayer(hitId)) {
629 
630  // Adjust matched hit for track angle
631 
632  //const SiStripMatchedRecHit2D *theRH = dynamic_cast<SiStripMatchedRecHit2D*>(*recHitIterator);
633  const GluedGeomDet *theGluedDet = dynamic_cast<const GluedGeomDet*>(tracker->idToDet(hitId));
634 
635  SiStripMatchedRecHit2D* theCorrectedHit = CorrectMatchedHit(*recHitIterator,theGluedDet,
636  tracker, theHitMatcher,
637  k1, phi1);
638  if (theCorrectedHit != 0){
639 
640  GlobalPoint ghit = tracker->idToDet(theCorrectedHit->geographicalId())->surface().toGlobal(theCorrectedHit->localPosition());
641  double hitphi = map_phi(ghit.phi());
642  double hitZ = ghit.z();
643  double phi = phiFromExtrapolation(d0,phi0,k0,hitZ,roadType);
644 
645  float dp = hitphi-phi;
646  float dx = hitZ*tan(dp);
647 
648  //
649  // This is where the disk stereoRecHits end up for Roads::ZPhi
650  //
651  if ( std::abs(dx) < phiMax(roadType,phi0,k1)) {
652  if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
653  cloud.addHit(recHit);
654  ++usedRecHits;
655  }
656  }
657  delete theCorrectedHit;
658  }
659  } else { // Single layer hits here
660  if ( isBarrelSensor(hitId) ) {
661  //
662  // This is where the barrel (???) rphiRecHits end up for Roads::ZPhi
663  //
664  LocalPoint hit = recHit->localPosition();
665  const StripTopology *topology = dynamic_cast<const StripTopology*>(&(tracker->idToDetUnit(hitId)->topology()));
666  double stripAngle = topology->stripAngle(topology->strip(hit));
667  double stripLength = topology->localStripLength(hit);
668 
669  //if (stripAngle!=0) std::cout<<"HEY, WE FOUND A HIT ON A STEREO MODULE!!!" << std::endl;
670  // new method
671  LocalPoint innerHitLocal(hit.x()+stripLength/2*std::sin(stripAngle),hit.y()-stripLength/2*std::cos(stripAngle),0);
672  LocalPoint outerHitLocal(hit.x()-stripLength/2*std::sin(stripAngle),hit.y()+stripLength/2*std::cos(stripAngle),0);
673  double innerHitPhi = map_phi(tracker->idToDetUnit(hitId)->surface().toGlobal(innerHitLocal).phi());
674  double outerHitPhi = map_phi(tracker->idToDetUnit(hitId)->surface().toGlobal(outerHitLocal).phi());
675  double innerHitZ = tracker->idToDetUnit(hitId)->surface().toGlobal(innerHitLocal).z();
676  double outerHitZ = tracker->idToDetUnit(hitId)->surface().toGlobal(outerHitLocal).z();
677  double innerExtrapolatedPhi = phiFromExtrapolation(d0,phi0,k0,innerHitZ,roadType);
678  double outerExtrapolatedPhi = phiFromExtrapolation(d0,phi0,k0,outerHitZ,roadType);
679 
680  double midPointZ = 0.5*(innerHitZ+outerHitZ);
681 
682  double dPhiInter = CheckZPhiIntersection(innerHitPhi, innerHitZ, outerHitPhi, outerHitZ,
683  innerExtrapolatedPhi, innerHitZ,
684  outerExtrapolatedPhi, outerHitZ);
685 
686  double dX = midPointZ*tan(dPhiInter);
687 
688  if (std::abs(dX) < 1.5*phiMax(roadType,phi0,k1)) {
689  if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
690  cloud.addHit(recHit);
691  ++usedRecHits;
692  }
693  }
694 
695  } else {
696 
697  //
698  // This is where the disk rphiRecHits end up for Roads::ZPhi
699  //
700  LocalPoint hit = recHit->localPosition();
701  const StripTopology *topology = dynamic_cast<const StripTopology*>(&(tracker->idToDetUnit(hitId)->topology()));
702  double stripAngle = topology->stripAngle(topology->strip(hit));
703  double stripLength = topology->localStripLength(hit);
704  // new method
705  double hitZ = tracker->idToDetUnit(hitId)->surface().toGlobal(hit).z();
706  double extrapolatedPhi = phiFromExtrapolation(d0,phi0,k0,hitZ,roadType);
707 
708  LocalPoint innerHitLocal(hit.x()+stripLength/2*std::sin(stripAngle),hit.y()-stripLength/2*std::cos(stripAngle),0);
709  LocalPoint outerHitLocal(hit.x()-stripLength/2*std::sin(stripAngle),hit.y()+stripLength/2*std::cos(stripAngle),0);
710 
711  double innerHitPhi = map_phi(tracker->idToDetUnit(hitId)->surface().toGlobal(innerHitLocal).phi());
712  double outerHitPhi = map_phi(tracker->idToDetUnit(hitId)->surface().toGlobal(outerHitLocal).phi());
713  //double innerZ = tracker->idToDetUnit(hitId)->surface().toGlobal(innerHitLocal).z();
714  //double outerZ = tracker->idToDetUnit(hitId)->surface().toGlobal(outerHitLocal).z();
715  //if (innerZ != outerZ) std::cout<<"HEY!!! innerZ = " << innerZ << " != outerZ = " << outerZ << std::endl;
716 
717  double deltaPhi = ZPhiDeltaPhi(innerHitPhi,outerHitPhi,extrapolatedPhi);
718  double deltaX = hitZ*tan(deltaPhi);
719  if (std::abs(deltaX) < phiMax(roadType,phi0,k1)){
720  if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
721  cloud.addHit(recHit);
722  ++usedRecHits;
723  }
724  }
725  }
726  }
727  }
728  } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelBarrel
729  || (unsigned int)id.subdetId() == PixelSubdetector::PixelEndcap) {
730  if ( UsePixels ) {
731 
732  const SiPixelRecHit *recHit = (SiPixelRecHit*)(*recHitIterator);
733 
734  if ( roadType == Roads::RPhi ) {
735 
736  if ( isBarrelSensor(id) ) {
737  // Barrel Pixel, RoadType RPHI
738 
739  GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
740  double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
741  double hitphi = map_phi(ghit.phi());
742  double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
743 
744  float dp = hitphi-phi;
745  float dx = hitRadius*tan(dp);
746 
747  // switch cut to dx instead of dphi
748  if ( std::abs(dx) < phiMax(roadType,phi0,k0) ) {
749  cloud.addHit(recHit);
750  ++usedRecHits;
751  }
752  } else {
753 
754  // Forward Pixel,roadtype RPHI
755 
756  // Get Local Hit Position of the Pixel Hit
757  LocalPoint hit = recHit->localPosition();
758 
759  // Get Phi of hit position
760  double hitphi = map_phi(tracker->idToDetUnit(id)->surface().toGlobal(hit).phi());
761 
762  // Get Global Hit position
763  GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
764 
765  // Get Hit Radis
766  double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
767 
768  // Get Phi from extrapolation
769  double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
770 
771  if ( std::abs(hitphi-phi) < phiMax(roadType,phi0,k0) ) {
772  cloud.addHit(recHit);
773  ++usedRecHits;
774  }
775  }
776  } else {
777 
778  GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
779  double phi = phiFromExtrapolation(d0,phi0,k0,ghit.z(),roadType);
780  double hitphi = map_phi(ghit.phi());
781  double dphi = map_phi2(hitphi-phi);
782  float dx = ghit.z()*tan(dphi);
783 
784  if ( std::abs(dx) < 0.25 ) {
785  cloud.addHit(recHit);
786  ++usedRecHits;
787  }
788  }
789  }
790  } else {
791  edm::LogError("RoadSearch") << "recHitVector from general hit access function contains unknown detector id: " << (unsigned int)id.subdetId() << " rawId: " << id.rawId();
792  }
793 
794  } //for loop over all recHits
795 
796 
797  return usedRecHits;
798 }
799 
801  double d0, double phi0, double k0, Roads::type roadType, double ringPhi,
802  const TrackerGeometry *tracker, RoadSearchCloud &cloud) {
803 
804 
805  unsigned int usedRecHits = 0;
806 
807  // Get Geometry
808  //const PixelTopology *topology = dynamic_cast<const PixelTopology*>(&(tracker->idToDetUnit(id)->topology()));
809 
810 
811  // retrieve vector<SiPixelRecHit> for id
812  // loop over SiPixelRecHit
813  // check if compatible with cloud, fill into cloud
814 
815  SiPixelRecHitCollection::const_iterator recHitMatch = inputRecHits->find(id);
816  if (recHitMatch == inputRecHits->end()) return usedRecHits;
817 
818  const SiPixelRecHitCollection::DetSet recHitRange = *recHitMatch;
819 
820  for ( SiPixelRecHitCollection::DetSet::const_iterator recHitIterator = recHitRange.begin();
821  recHitIterator != recHitRange.end(); ++recHitIterator) {
822 
823  const SiPixelRecHit * recHit = &(*recHitIterator);
824 
825  if ( roadType == Roads::RPhi ) {
826 
827  if ( isBarrelSensor(id) ) {
828  // Barrel Pixel, RoadType RPHI
829 
830  GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
831  double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
832  double hitphi = map_phi(ghit.phi());
833  double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
834 
835  if ( std::abs(hitphi-phi) < phiMax(roadType,phi0,k0) ) {
836  cloud.addHit(recHit);
837  ++usedRecHits;
838  }
839  }
840  else {
841 
842  // Forward Pixel,roadtype RPHI
843 
844  // Get Local Hit Position of the Pixel Hit
845  LocalPoint hit = recHit->localPosition();
846 
847  // Get Phi of hit position
848  double hitphi = map_phi(tracker->idToDetUnit(id)->surface().toGlobal(hit).phi());
849 
850  // Get Global Hit position
851  GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
852 
853  // Get Hit Radis
854  double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
855 
856  // Get Phi from extrapolation
857  double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
858 
859  if ( std::abs(hitphi-phi) < phiMax(roadType,phi0,k0) ) {
860  cloud.addHit(recHit);
861  ++usedRecHits;
862  }
863  }
864  }
865 
866  else {
867 
868  GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
869 
870  double phi = phiFromExtrapolation(d0,phi0,k0,ghit.z(),roadType);
871  if ( (phi - phiMax(roadType,phi0,k0)) < ringPhi && (phi + phiMax(roadType,phi0,k0))>ringPhi ) {
872  cloud.addHit(recHit);
873  ++usedRecHits;
874  }
875  }
876 
877  }
878 
879  return usedRecHits;
880 }
881 
883 
884  if ( (unsigned int)id.subdetId() == StripSubdetector::TIB ) {
885  TIBDetId tibid(id.rawId());
886  if ( !tibid.glued() ) {
887  return true;
888  }
889  } else if ( (unsigned int)id.subdetId() == StripSubdetector::TOB ) {
890  TOBDetId tobid(id.rawId());
891  if ( !tobid.glued() ) {
892  return true;
893  }
894  } else if ( (unsigned int)id.subdetId() == StripSubdetector::TID ) {
895  TIDDetId tidid(id.rawId());
896  if ( !tidid.glued() ) {
897  return true;
898  }
899  } else if ( (unsigned int)id.subdetId() == StripSubdetector::TEC ) {
900  TECDetId tecid(id.rawId());
901  if ( !tecid.glued() ) {
902  return true;
903  }
904  } else {
905  return false;
906  }
907 
908  return false;
909 }
910 
912 
913  if ( (unsigned int)id.subdetId() == StripSubdetector::TIB ) {
914  return true;
915  } else if ( (unsigned int)id.subdetId() == StripSubdetector::TOB ) {
916  return true;
917  } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelBarrel ) {
918  return true;
919  } else {
920  return false;
921  }
922 
923 }
924 
925 double RoadSearchCloudMakerAlgorithm::phiFromExtrapolation(double d0, double phi0, double k0, double ringRadius, Roads::type roadType) {
926 
927  double ringPhi = -99.;
928  if ( roadType == Roads::RPhi ) {
929  double omega=k0, rl=ringRadius;
930  double sp0=sin(phi0); double cp0=cos(phi0);
931  if (fabs(omega)>0.000005){
932  double xc=-sp0*(d0+1.0/omega);
933  double yc=cp0*(d0+1.0/omega);
934  double rh=fabs(1.0/omega);
935  double bbb=fabs(d0+1.0/omega);
936  double sss=0.5*(rl+rh+bbb);
937  double ddd=sqrt((sss-bbb)*(sss-rh)/(sss*(sss-rl)));
938  double phil1=2.0*atan(ddd);
939  double phit=phi0+phil1; if (omega<0.0)phit=phi0-phil1;
940  double xh=xc+sin(phit)/omega;
941  double yh=yc-cos(phit)/omega;
942  double phih=atan2(yh,xh);
943  ringPhi = map_phi(phih);
944  }
945  else {
946  double cee = rl*rl - d0*d0 -0.25*omega*omega - omega*d0;
947  if (cee<0.0){return ringPhi;}
948  double l = sqrt(cee);
949  double xh=-sp0*d0+l*cp0-0.5*l*l*omega*sp0;
950  double yh= cp0*d0+l*sp0+0.5*l*l*omega*cp0;
951  double phih=atan2(yh,xh);
952  ringPhi = map_phi(phih);
953  }
954  }
955  else {
956  ringPhi = map_phi(phi0 + k0 * ringRadius);
957  }
958 
959  return ringPhi;
960 }
961 
963  double phi0, double k0) {
964 
965  double dphi;
966  if ( roadType == Roads::RPhi ) {
967  // switch cut to dx instead of dphi
968  // Still call this dphi, but will now be dx
969  dphi = theRPhiRoadSize + 0.15*82.0*fabs(k0);
970  }
971  else if ( roadType == Roads::ZPhi ) {
972  dphi = theZPhiRoadSize + 0.4*82.0*fabs(k0);
973  }
974  else {
975  edm::LogWarning("RoadSearch") << "Bad roadType: "<< roadType;
976  dphi = theZPhiRoadSize;
977  }
978  return dphi;
979 
980 }
981 
982 void RoadSearchCloudMakerAlgorithm::makecircle(double x1, double y1,
983  double x2,double y2, double x3, double y3){
984  double x1t=x1-x3; double y1t=y1-y3; double r1s=x1t*x1t+y1t*y1t;
985  double x2t=x2-x3; double y2t=y2-y3; double r2s=x2t*x2t+y2t*y2t;
986  double rho=x1t*y2t-x2t*y1t;
987  double xc, yc, rc, fac;
990  fac=sqrt(x1t*x1t+y1t*y1t);
991  xc=x2+y1t*rc/fac;
992  yc=y2-x1t*rc/fac;
993  }else{
994  fac=0.5/rho;
995  xc=fac*(r1s*y2t-r2s*y1t);
996  yc=fac*(r2s*x1t-r1s*x2t);
997  rc=sqrt(xc*xc+yc*yc); xc+=x3; yc+=y3;
998  }
999  double s3=0.0;
1000  double f1=x1*yc-y1*xc; double f2=x2*yc-y2*xc;
1001  double f3=x3*yc-y3*xc;
1002  if ((f1<0.0)&&(f2<0.0)&&(f3<=0.0))s3=1.0;
1003  if ((f1>0.0)&&(f2>0.0)&&(f3>=0.0))s3=-1.0;
1004  d0h=-s3*(sqrt(xc*xc+yc*yc)-rc);
1005  phi0h=atan2(yc,xc)+s3*Geom::halfPi();
1006  omegah=-s3/rc;
1007 }
1008 
1010  LocalPoint& inner2, LocalPoint& outer2){
1011 
1012  double deltaX = -999.;
1013  // just get the x coord of intersection of two line segments
1014  // check if intersection lies inside segments
1015  double det12 = inner1.x()*outer1.y() - inner1.y()*outer1.x();
1016  double det34 = inner2.x()*outer2.y() - inner2.y()*outer2.x();
1017 
1018  double xinter = (det12*(inner2.x()-outer2.x()) - det34*(inner1.x()-outer1.x()))/
1019  ((inner1.x()-outer1.x())*(inner2.y()-outer2.y()) -
1020  (inner2.x()-outer2.x())*(inner1.y()-outer1.y()));
1021 
1022  bool inter = true;
1023  if (inner1.x() < outer1.x()){
1024  if ((xinter<inner1.x()) || (xinter>outer1.x())) inter = false;
1025  }
1026  else{
1027  if ((xinter>inner1.x()) || (xinter<outer1.x())) inter = false;
1028  }
1029 
1030  if (inner2.x() < outer2.x()){
1031  if ((xinter<inner2.x()) || (xinter>outer2.x())) inter = false;
1032  }
1033  else{
1034  if ((xinter>inner2.x()) || (xinter<outer2.x())) inter = false;
1035  }
1036 
1037  if (inter){
1038  deltaX = 0;
1039  }
1040  else{
1041  deltaX = min(fabs(inner1.x()-inner2.x()),fabs(outer1.x()-outer2.x()));
1042  }
1043  return deltaX;
1044 
1045 }
1046 
1047 double RoadSearchCloudMakerAlgorithm::CheckZPhiIntersection(double iPhi1, double iZ1, double oPhi1, double oZ1,
1048  double iPhi2, double iZ2, double oPhi2, double oZ2){
1049 
1050  // Have to make sure all are in the same hemisphere
1051  if ((iPhi1 > Geom::pi() || oPhi1 > Geom::pi() || iPhi2 > Geom::pi() || oPhi2 > Geom::pi()) &&
1052  (iPhi1 < Geom::pi() || oPhi1 < Geom::pi() || iPhi2 < Geom::pi() || oPhi2 < Geom::pi())){
1053  iPhi1 = map_phi2(iPhi1); oPhi1 = map_phi2(oPhi1);
1054  iPhi2 = map_phi2(iPhi2); oPhi2 = map_phi2(oPhi2);
1055  }
1056 
1057  double deltaPhi = -999.;
1058  // just get the x coord of intersection of two line segments
1059  // check if intersection lies inside segments
1060  double det12 = iZ1*oPhi1 - iPhi1*oZ1;
1061  double det34 = iZ2*oPhi2 - iPhi2*oZ2;
1062 
1063  double xinter = (det12*(iZ2-oZ2) - det34*(iZ1-oZ1))/
1064  ((iZ1-oZ1)*(iPhi2-oPhi2) -
1065  (iZ2-oZ2)*(iPhi1-oPhi1));
1066 
1067  bool inter = true;
1068  if (iZ1 < oZ1){
1069  if ((xinter<iZ1) || (xinter>oZ1)) inter = false;
1070  }
1071  else{
1072  if ((xinter>iZ1) || (xinter<oZ1)) inter = false;
1073  }
1074 
1075  if (iZ2 < oZ2){
1076  if ((xinter<iZ2) || (xinter>oZ2)) inter = false;
1077  }
1078  else{
1079  if ((xinter>iZ2) || (xinter<oZ2)) inter = false;
1080  }
1081 
1082  if (inter){
1083  deltaPhi = 0;
1084  }
1085  else{
1086  deltaPhi = min(fabs(iPhi2-iPhi1),fabs(oPhi2-oPhi1));
1087  }
1088  return deltaPhi;
1089 
1090 }
1091 
1092 
1093 double RoadSearchCloudMakerAlgorithm::ZPhiDeltaPhi(double hitPhi1, double hitPhi2, double predictedPhi){
1094 
1095  double deltaPhi = -999.;
1096 
1097  double dPhiHits = map_phi2(hitPhi1-hitPhi2);
1098  double dPhi1 = map_phi2(hitPhi1-predictedPhi);
1099  double dPhi2 = map_phi2(hitPhi2-predictedPhi);
1100 
1101  if (dPhiHits >= 0){ // hitPhi1 >= hitPhi2
1102  if ( (dPhi1>=0.0) && (dPhi2 <= 0.0))
1103  deltaPhi = 0.0;
1104  else{
1105  if (std::abs(dPhi1)<std::abs(dPhi2))
1106  deltaPhi = dPhi1;
1107  else
1108  deltaPhi = dPhi2;
1109  }
1110  }
1111  else { // hitPhi1 < hitPhi2
1112  if ( (dPhi1<=0.0) && (dPhi2 >= 0.0))
1113  deltaPhi = 0.0;
1114  else{
1115  if (std::abs(dPhi1)<std::abs(dPhi2))
1116  deltaPhi = dPhi1;
1117  else
1118  deltaPhi = dPhi2;
1119  }
1120  }
1121 
1122  return deltaPhi;
1123 
1124 }
1125 
1127 
1129 
1130  //
1131  // no raw clouds - nothing to try merging
1132  //
1133 
1134  if ( inputCollection->empty() ){
1135  LogDebug("RoadSearch") << "Found " << output.size() << " clean clouds.";
1136  return output;
1137  }
1138 
1139  //
1140  // 1 raw cloud - nothing to try merging, but one cloud to duplicate
1141  //
1142 
1143  if ( 1==inputCollection->size() ){
1144  output = *inputCollection;
1145 // RoadSearchCloud *temp = inputCollection->begin()->clone();
1146 // output.push_back(*temp);
1147 // delete temp;
1148  LogDebug("RoadSearch") << "Found " << output.size() << " clean clouds.";
1149  return output;
1150  }
1151 
1152  //
1153  // got > 1 raw cloud - something to try merging
1154  //
1155  std::vector<bool> already_gone(inputCollection->size());
1156  for (unsigned int i=0; i<inputCollection->size(); ++i) {
1157  already_gone[i] = false;
1158  }
1159 
1160  int raw_cloud_ctr=0;
1161  // loop over clouds
1162  for ( RoadSearchCloudCollection::const_iterator raw_cloud = inputCollection->begin(); raw_cloud != inputCollection->end(); ++raw_cloud) {
1163  ++raw_cloud_ctr;
1164 
1165  if (already_gone[raw_cloud_ctr-1])continue;
1166 
1167  // produce output cloud where other clouds are merged in
1168  // create temp pointer for clone which will be deleted afterwards
1169 // RoadSearchCloud *temp_lone_cloud = raw_cloud->clone();
1170 // RoadSearchCloud lone_cloud = *temp_lone_cloud;
1171  RoadSearchCloud lone_cloud = *raw_cloud;
1172 
1173  int second_cloud_ctr=raw_cloud_ctr;
1174  for ( RoadSearchCloudCollection::const_iterator second_cloud = raw_cloud+1; second_cloud != inputCollection->end(); ++second_cloud) {
1175  second_cloud_ctr++;
1176 
1177  std::vector<const TrackingRecHit*> unshared_hits;
1178 
1179  if ( already_gone[second_cloud_ctr-1] )continue;
1180 
1181  for ( RoadSearchCloud::RecHitVector::const_iterator second_cloud_hit = second_cloud->begin_hits();
1182  second_cloud_hit != second_cloud->end_hits();
1183  ++ second_cloud_hit ) {
1184  bool is_shared = false;
1185  for ( RoadSearchCloud::RecHitVector::const_iterator lone_cloud_hit = lone_cloud.begin_hits();
1186  lone_cloud_hit != lone_cloud.end_hits();
1187  ++ lone_cloud_hit ) {
1188 
1189  if ((*lone_cloud_hit)->geographicalId() == (*second_cloud_hit)->geographicalId())
1190  if ((*lone_cloud_hit)->localPosition().x() == (*second_cloud_hit)->localPosition().x())
1191  if ((*lone_cloud_hit)->localPosition().y() == (*second_cloud_hit)->localPosition().y())
1192  {is_shared=true; break;}
1193  }
1194  if (!is_shared) unshared_hits.push_back(*second_cloud_hit);
1195 
1196  if ( ((float(unshared_hits.size())/float(lone_cloud.size())) >
1197  ((float(second_cloud->size())/float(lone_cloud.size()))-mergingFraction_)) &&
1198  ((float(unshared_hits.size())/float(second_cloud->size())) > (1-mergingFraction_))){
1199  // You'll never merge these clouds..... Could quit now!
1200  break;
1201  }
1202 
1203  if (lone_cloud.size()+unshared_hits.size() > maxRecHitsInCloud_) {
1204  break;
1205  }
1206 
1207  }
1208 
1209  double f_lone_shared=double(second_cloud->size()-unshared_hits.size())/double(lone_cloud.size());
1210  double f_second_shared=double(second_cloud->size()-unshared_hits.size())/double(second_cloud->size());
1211 
1212  if ( ( (static_cast<unsigned int>(f_lone_shared*1E9) > static_cast<unsigned int>(mergingFraction_*1E9))||(static_cast<unsigned int>(f_second_shared*1E9) > static_cast<unsigned int>(mergingFraction_*1E9)) )
1213  && (lone_cloud.size()+unshared_hits.size() <= maxRecHitsInCloud_) ){
1214 
1215  LogDebug("RoadSearch") << " Merge CloudA: " << raw_cloud_ctr << " with CloudB: " << second_cloud_ctr
1216  << " Shared fractions are " << f_lone_shared << " and " << f_second_shared;
1217 
1218  //
1219  // got a cloud to merge
1220  //
1221  for (unsigned int k=0; k<unshared_hits.size(); ++k) {
1222  lone_cloud.addHit(unshared_hits[k]);
1223  }
1224 
1225  already_gone[second_cloud_ctr-1]=true;
1226 
1227  }//end got a cloud to merge
1228 
1229  }//interate over all second clouds
1230 
1231  output.push_back(lone_cloud);
1232 
1233  }//iterate over all raw clouds
1234 
1235  LogDebug("RoadSearch") << "Found " << output.size() << " clean clouds.";
1236 
1237  return output;
1238 }
1239 
1241  const GluedGeomDet* gluedDet,
1242  const TrackerGeometry *tracker,
1243  const SiStripRecHitMatcher* theHitMatcher,
1244  double k0, double phi0) {
1245 
1246  const SiStripMatchedRecHit2D *theRH = dynamic_cast<const SiStripMatchedRecHit2D*>(originalHit);
1247  if (theRH == 0) {
1248  std::cout<<" Could not cast original hit" << std::endl;
1249  }
1250  if (theRH != 0){
1251  const GeomDet *recHitGeomDet = tracker->idToDet(theRH->geographicalId());
1252  const GluedGeomDet *theGluedDet = dynamic_cast<const GluedGeomDet*>(recHitGeomDet);
1253 
1254  const GeomDetUnit* theMonoDet = theGluedDet->monoDet();
1255  const SiStripRecHit2D* theMonoHit = theRH->monoHit();
1256  GlobalPoint monoRHpos = (theMonoDet->surface()).toGlobal(theMonoHit->localPosition());
1257 
1258  GlobalPoint gcenterofstrip=(theMonoDet->surface()).toGlobal(theMonoHit->localPosition());
1259 
1260  float gtrackangle_xy = map_phi2(phi0 + 2.0*asin(0.5*gcenterofstrip.perp()*k0));
1261  float rzangle = atan2(gcenterofstrip.perp(),gcenterofstrip.z());
1262 
1263  GlobalVector gtrackangle2(cos(gtrackangle_xy)*sin(rzangle),
1264  sin(gtrackangle_xy)*sin(rzangle),
1265  cos(rzangle));
1266  LocalVector trackdirection2=((tracker->idToDet(theRH->geographicalId()))->surface()).toLocal(gtrackangle2);
1267  GlobalVector gdir = theMonoDet->surface().toGlobal(trackdirection2);
1268 
1269  SiStripMatchedRecHit2D* theCorrectedHit = theHitMatcher->match(theRH,theGluedDet,trackdirection2);
1270  if (theCorrectedHit!=0) return theCorrectedHit;
1271  }
1272 
1273  return 0;
1274 }
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:78
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
float alpha
Definition: AMPTWrapper.h:95
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
T perp() const
Definition: PV3DBase.h:66
const int netabin
void setCollections(const SiStripRecHit2DCollection *rphiRecHits, const SiStripRecHit2DCollection *stereoRecHits, const SiStripMatchedRecHit2DCollection *matchedRecHits, const SiPixelRecHitCollection *pixelRecHits)
Definition: DetHitAccess.cc:42
virtual float stripAngle(float strip) const =0
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
unsigned int size() const
tuple d0
Definition: debug_cff.py:3
SiStripMatchedRecHit2D * CorrectMatchedHit(const TrackingRecHit *originalRH, const GluedGeomDet *gluedDet, const TrackerGeometry *tracker, const SiStripRecHitMatcher *theHitMatcher, double k0, double phi0)
double deltaPhi(float phi1, float phi2)
Definition: VectorUtil.h:30
SiStripMatchedRecHit2D * match(const SiStripRecHit2D *monoRH, const SiStripRecHit2D *stereoRH, const GluedGeomDet *gluedDet, LocalVector trackdirection) const
void use_rphiRecHits(bool input)
Definition: DetHitAccess.h:45
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Definition: DDAxes.h:10
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
double phiMax(Roads::type roadType, double phi0, double k0)
T y() const
Definition: PV3DBase.h:57
#define abs(x)
Definition: mlp_lapack.h:159
RecHitVector::const_iterator begin_hits() const
#define min(a, b)
Definition: mlp_lapack.h:161
RoadSearchCloudCollection Clean(RoadSearchCloudCollection *rawColl)
std::vector< RoadSearchSeed > RoadSearchSeedCollection
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
const_iterator find(id_type i) const
tuple d1
Definition: debug_cff.py:7
double double double z
virtual LocalPoint localPosition() const
void run(edm::Handle< RoadSearchSeedCollection > input, const SiStripRecHit2DCollection *rphiRecHits, const SiStripRecHit2DCollection *stereoRecHits, const SiStripMatchedRecHit2DCollection *matchedRecHits, const SiPixelRecHitCollection *pixRecHits, const edm::EventSetup &es, RoadSearchCloudCollection &output)
Runs the algorithm.
virtual float strip(const LocalPoint &) const =0
double CheckZPhiIntersection(double iPhi1, double iZ1, double oPhi1, double oZ1, double iPhi2, double iZ2, double oPhi2, double oZ2)
std::vector< std::vector< const Ring * > > RoadSet
Definition: Roads.h:39
void makecircle(double x1_cs, double y1_cs, double x2_cs, double y2_cs, double x3_cs, double y3_cs)
virtual const Topology & topology() const =0
double CheckXYIntersection(LocalPoint &ip1, LocalPoint &op1, LocalPoint &ip2, LocalPoint &op2)
double phiFromExtrapolation(double d0, double phi0, double k0, double ringRadius, Roads::type roadType)
void addHit(const TrackingRecHit *input)
T sqrt(T t)
Definition: SSEVec.h:28
LocalPoint toLocal(const GlobalPoint &gp) const
T z() const
Definition: PV3DBase.h:58
tuple result
Definition: query.py:137
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
double ZPhiDeltaPhi(double phi1, double phi2, double phiExpect)
const_iterator end() const
std::vector< TrackingRecHit * > getHitVector(const DetId *detid)
Definition: DetHitAccess.cc:55
double halfPi()
Definition: Pi.h:33
virtual const GeomDet * idToDet(DetId) const
tuple conf
Definition: dbtoconf.py:185
tuple input
Definition: collect_tpl.py:10
std::pair< std::vector< const Ring * >, std::vector< const Ring * > > RoadSeed
Definition: Roads.h:38
int k[5][pyjets_maxn]
void use_stereoRecHits(bool input)
Definition: DetHitAccess.h:46
RoadSearchCloudMakerAlgorithm(const edm::ParameterSet &conf)
Definition: DetId.h:20
virtual uint32_t glued() const
Definition: SiStripDetId.h:142
RecHitVector::const_iterator end_hits() const
type
Definition: Roads.h:45
void setMode(accessMode input)
Definition: DetHitAccess.h:44
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
unsigned int FillRecHitsIntoCloudGeneral(DetId id, double d0, double phi0, double k0, double phi1, double k1, Roads::type roadType, double ringPhi, const TrackerGeometry *tracker, const SiStripRecHitMatcher *theHitMatcher, RoadSearchCloud &cloud)
T const * product() const
Definition: Handle.h:74
T eta() const
Definition: PV3DBase.h:70
virtual const GeomDetUnit * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
#define begin
Definition: vmac.h:31
iterator end()
Definition: DetSetNew.h:59
unsigned int FillPixRecHitsIntoCloud(DetId id, const SiPixelRecHitCollection *inputRecHits, double d0, double phi0, double k0, Roads::type roadType, double ringPhi, const TrackerGeometry *tracker, RoadSearchCloud &cloud)
double pi()
Definition: Pi.h:31
virtual float localStripLength(const LocalPoint &aLP) const =0
double twoPi()
Definition: Pi.h:32
DetIdMap::const_iterator const_iterator
Definition: Ring.h:37
tuple cout
Definition: gather_cfg.py:41
DetId geographicalId() const
Definition: DDAxes.h:10
const SiStripRecHit2D * monoHit() const
T x() const
Definition: PV3DBase.h:56
virtual LocalPoint localPosition() const =0
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
std::vector< RoadSearchCloud > RoadSearchCloudCollection
Our base class.
Definition: SiPixelRecHit.h:27
Definition: DDAxes.h:10
iterator begin()
Definition: DetSetNew.h:56