CMS 3D CMS Logo

GenericTripletGenerator.cc
Go to the documentation of this file.
4 
5 
8 #include <map>
9 
10 
12  theSeedingLayerToken(iC.consumes<SeedingLayerSetsHits>(conf.getParameter<edm::InputTag>("LayerSrc"))) {
13  edm::LogInfo("CtfSpecialSeedGenerator|GenericTripletGenerator") << "Constructing GenericTripletGenerator";
14 }
15 
16 
18  const edm::Event& e,
19  const edm::EventSetup& es){
20  hitTriplets.clear();
21  hitTriplets.reserve(0);
23  e.getByToken(theSeedingLayerToken, hlayers);
24  const SeedingLayerSetsHits& layers = *hlayers;
25  if(layers.numberOfLayersInSet() != 3)
26  throw cms::Exception("CtfSpecialSeedGenerator") << "You are using " << layers.numberOfLayersInSet() <<" layers in set instead of 3 ";
27  std::map<float, OrderedHitTriplet> radius_triplet_map;
29  auto innerHits = region.hits(es, ls[0]);
30  //std::cout << "innerHits.size()=" << innerHits.size() << std::endl;
31  auto middleHits = region.hits(es, ls[1]);
32  //std::cout << "middleHits.size()=" << middleHits.size() << std::endl;
33  auto outerHits = region.hits(es, ls[2]);
34  //std::cout << "outerHits.size()=" << outerHits.size() << std::endl;
35  //std::cout << "trying " << innerHits.size()*middleHits.size()*outerHits.size() << " combinations "<<std::endl;
36  for (auto iOuterHit = outerHits.begin(); iOuterHit != outerHits.end(); iOuterHit++){
37  for (auto iMiddleHit = middleHits.begin(); iMiddleHit != middleHits.end(); iMiddleHit++){
38  for (auto iInnerHit = innerHits.begin(); iInnerHit != innerHits.end(); iInnerHit++){
39  //GlobalPoint innerpos = ls[0].hitBuilder()->build(&(**iInnerHit))->globalPosition();
40  //GlobalPoint middlepos = ls[1].hitBuilder()->build(&(**iMiddleHit))->globalPosition();
41  //GlobalPoint outerpos = ls[2].hitBuilder()->build(&(**iOuterHit))->globalPosition();
42  //FastCircle circle(innerpos,
43  // middlepos,
44  // outerpos);
45  //do a first check on the radius of curvature to reduce the combinatorics
46  OrderedHitTriplet oht(&(**iInnerHit),&(**iMiddleHit),&(**iOuterHit));
47  std::pair<bool,float> val_radius = qualityFilter(oht,radius_triplet_map,ls);
48  if (val_radius.first){
49  //if (circle.rho() > 200 || circle.rho() == 0) { //0 radius means straight line
50  //hitTriplets.push_back(OrderedHitTriplet(*iInnerHit,
51  // *iMiddleHit,
52  // *iOuterHit));
53  hitTriplets.push_back(oht);
54  radius_triplet_map.insert(std::make_pair(val_radius.second,oht));
55  }
56  }
57  }
58  }
59  }
60  //std::cout << "ending with " << hitTriplets.size() << " triplets" << std::endl;
61  return hitTriplets;
62 }
63 
65  const std::map<float, OrderedHitTriplet>& map,
67  //first check the radius
68  GlobalPoint innerpos = oht.inner()->globalPosition();
69  GlobalPoint middlepos = oht.middle()->globalPosition();
70  GlobalPoint outerpos = oht.outer()->globalPosition();
71  std::vector<const TrackingRecHit*> ohttrh;
72  ohttrh.push_back(&(*(oht.inner()))); ohttrh.push_back(&(*(oht.middle()))); ohttrh.push_back(&(*(oht.outer())));
73  std::vector<const TrackingRecHit*>::const_iterator ioht;
74  //now chech that the change in phi is reasonable. the limiting angular distance is the one in case
75  //one of the two points is a tangent point.
76  float limit_phi_distance1 = sqrt((middlepos.x()-outerpos.x())*(middlepos.x()-outerpos.x()) +
77  (middlepos.y()-outerpos.y())*(middlepos.y()-outerpos.y()))/middlepos.mag();//actually this is the tangent of the limiting angle
78  float limit_phi_distance2 = sqrt((middlepos.x()-innerpos.x())*(middlepos.x()-innerpos.x()) +
79  (middlepos.y()-innerpos.y())*(middlepos.y()-innerpos.y()))/innerpos.mag();
80  //if (fabs(tan(outerpos.phi()-middlepos.phi()))>limit_phi_distance1 ||
81  // fabs(tan(innerpos.phi()-middlepos.phi()))>limit_phi_distance2) {
82  if (fabs(outerpos.phi()-middlepos.phi())>fabs(atan(limit_phi_distance1)) ||
83  fabs(innerpos.phi()-middlepos.phi())>fabs(atan(limit_phi_distance2)) ) {
84  //std::cout << "rejected because phi" << std::endl;
85  return std::make_pair(false, 0.);
86  }
87  //should we add a control on the r-z plane too?
88  /*
89  //now check that there is no big change in the r-z projection
90  float dz1 = outerpos.z()-middlepos.z();
91  float dr1 = sqrt(outerpos.x()*outerpos.x()+outerpos.y()*outerpos.y())-
92  sqrt(middlepos.x()*middlepos.x()+middlepos.y()*middlepos.y());
93  float dz2 = middlepos.z()-innerpos.z();
94  float dr2 = sqrt(middlepos.x()*middlepos.x()+middlepos.y()*middlepos.y())-
95  sqrt(innerpos.x()*innerpos.x()+innerpos.y()*innerpos.y());
96  float tan1 = dz1/dr1;
97  float tan2 = dz2/dr2;
98  //how much should we allow? should we make it configurable?
99  if (fabs(tan1-tan2)/tan1>0.5){
100  //std::cout << "rejected because z" << std::endl;
101  return std::make_pair(false, 0.);
102  }
103  */
104  //now check the radius is not too small
105  FastCircle circle(innerpos, middlepos, outerpos);
106  if (circle.rho() < 200 && circle.rho() != 0) return std::make_pair(false, circle.rho()); //to small radius
107  //now check if at least 2 hits are shared with an existing triplet
108  //look for similar radii in the map
109  std::map<float, OrderedHitTriplet>::const_iterator lower_bound = map.lower_bound((1-0.01)*circle.rho());
110  std::map<float, OrderedHitTriplet>::const_iterator upper_bound = map.upper_bound((1+0.01)*circle.rho());
111  std::map<float, OrderedHitTriplet>::const_iterator iter;
112  for (iter = lower_bound; iter != upper_bound && iter->first <= upper_bound->first; iter++){
113  int shared=0;
114  std::vector<const TrackingRecHit*> curtrh;
115  curtrh.push_back(&*(iter->second.inner()));curtrh.push_back(&*(iter->second.middle()));curtrh.push_back(&*(iter->second.outer()));
116  std::vector<const TrackingRecHit*>::const_iterator curiter;
117  for (curiter = curtrh.begin(); curiter != curtrh.end(); curiter++){
118  for (ioht = ohttrh.begin(); ioht != ohttrh.end(); ioht++){
119  if ((*ioht)->geographicalId()==(*curiter)->geographicalId() &&
120  ((*ioht)->localPosition()-(*curiter)->localPosition()).mag()<1e-5) shared++;
121  }
122  }
123  if (shared>1) return std::make_pair(false, circle.rho());
124  }
125 
126  return std::make_pair(true,circle.rho());
127 }
SeedingHitSet::ConstRecHitPointer SeedingHit
unsigned short numberOfLayersInSet() const
Get number of layers in each SeedingLayerSets.
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
MiddleRecHit middle() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
double rho() const
Definition: FastCircle.h:54
edm::EDGetTokenT< SeedingLayerSetsHits > theSeedingLayerToken
InnerRecHit inner() const
BaseTrackerRecHit const * ConstRecHitPointer
Definition: SeedingHitSet.h:11
T mag() const
Definition: PV3DBase.h:67
const OrderedSeedingHits & run(const TrackingRegion &region, const edm::Event &ev, const edm::EventSetup &es) override
T sqrt(T t)
Definition: SSEVec.h:18
std::pair< bool, float > qualityFilter(const OrderedHitTriplet &oht, const std::map< float, OrderedHitTriplet > &map, const SeedingLayerSetsHits::SeedingLayerSet &ls) const
def ls(path, rec=False)
Definition: eostools.py:348
virtual Hits hits(const edm::EventSetup &es, const SeedingLayerSetsHits::SeedingLayer &layer) const =0
get hits from layer compatible with region constraints
HLT enums.
GenericTripletGenerator(const edm::ParameterSet &conf, edm::ConsumesCollector &iC)
OuterRecHit outer() const
T x() const
Definition: PV3DBase.h:62