00001 #include "RecoTracker/SpecialSeedGenerators/interface/GenericTripletGenerator.h"
00002 #include "RecoTracker/TkSeedGenerator/interface/FastCircle.h"
00003 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
00004
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include <map>
00007 using namespace ctfseeding;
00008
00009
00010 GenericTripletGenerator::GenericTripletGenerator(const edm::ParameterSet& conf):
00011
00012 theLsb(conf.getParameter<edm::ParameterSet>("LayerPSet")){
00013 edm::LogInfo("CtfSpecialSeedGenerator|GenericTripletGenerator") << "Constructing GenericTripletGenerator";
00014 }
00015
00016
00017 SeedingLayerSets GenericTripletGenerator::init(const edm::EventSetup& es){
00018
00019
00020 SeedingLayerSets lss = theLsb.layers(es);
00021 return lss;
00022 }
00023
00024
00025 const OrderedSeedingHits& GenericTripletGenerator::run(const TrackingRegion& region,
00026 const edm::Event& e,
00027 const edm::EventSetup& es){
00028 hitTriplets.clear();
00029 hitTriplets.reserve(0);
00030 SeedingLayerSets lss = init(es);
00031 SeedingLayerSets::const_iterator iLss;
00032 std::map<float, OrderedHitTriplet> radius_triplet_map;
00033 for (iLss = lss.begin(); iLss != lss.end(); iLss++){
00034 SeedingLayers ls = *iLss;
00035 if (ls.size() != 3){
00036 throw cms::Exception("CtfSpecialSeedGenerator") << "You are using " << ls.size() <<" layers in set instead of 3 ";
00037 }
00038 std::vector<SeedingHit> innerHits = region.hits(e, es, &ls[0]);
00039
00040 std::vector<SeedingHit> middleHits = region.hits(e, es, &ls[1]);
00041
00042 std::vector<SeedingHit> outerHits = region.hits(e, es, &ls[2]);
00043
00044
00045 std::vector<SeedingHit>::const_iterator iOuterHit;
00046 for (iOuterHit = outerHits.begin(); iOuterHit != outerHits.end(); iOuterHit++){
00047 std::vector<SeedingHit>::const_iterator iMiddleHit;
00048 for (iMiddleHit = middleHits.begin(); iMiddleHit != middleHits.end(); iMiddleHit++){
00049 std::vector<SeedingHit>::const_iterator iInnerHit;
00050 for (iInnerHit = innerHits.begin(); iInnerHit != innerHits.end(); iInnerHit++){
00051
00052
00053
00054
00055
00056
00057
00058 OrderedHitTriplet oht(*iInnerHit,*iMiddleHit,*iOuterHit);
00059 std::pair<bool,float> val_radius = qualityFilter(oht,radius_triplet_map,ls);
00060 if (val_radius.first){
00061
00062
00063
00064
00065 hitTriplets.push_back(oht);
00066 radius_triplet_map.insert(std::make_pair(val_radius.second,oht));
00067 }
00068 }
00069 }
00070 }
00071 }
00072
00073 return hitTriplets;
00074 }
00075
00076 std::pair<bool,float> GenericTripletGenerator::qualityFilter(const OrderedHitTriplet& oht,
00077 const std::map<float, OrderedHitTriplet>& map,
00078 const SeedingLayers& ls) const{
00079
00080 GlobalPoint innerpos = ls[0].hitBuilder()->build(&(*(oht.inner())))->globalPosition();
00081 GlobalPoint middlepos = ls[1].hitBuilder()->build(&(*(oht.middle())))->globalPosition();
00082 GlobalPoint outerpos = ls[2].hitBuilder()->build(&(*(oht.outer())))->globalPosition();
00083 std::vector<const TrackingRecHit*> ohttrh;
00084 ohttrh.push_back(&(*(oht.inner()))); ohttrh.push_back(&(*(oht.middle()))); ohttrh.push_back(&(*(oht.outer())));
00085 std::vector<const TrackingRecHit*>::const_iterator ioht;
00086
00087
00088 float limit_phi_distance1 = sqrt((middlepos.x()-outerpos.x())*(middlepos.x()-outerpos.x()) +
00089 (middlepos.y()-outerpos.y())*(middlepos.y()-outerpos.y()))/middlepos.mag();
00090 float limit_phi_distance2 = sqrt((middlepos.x()-innerpos.x())*(middlepos.x()-innerpos.x()) +
00091 (middlepos.y()-innerpos.y())*(middlepos.y()-innerpos.y()))/innerpos.mag();
00092
00093
00094 if (fabs(outerpos.phi()-middlepos.phi())>fabs(atan(limit_phi_distance1)) ||
00095 fabs(innerpos.phi()-middlepos.phi())>fabs(atan(limit_phi_distance2)) ) {
00096
00097 return std::make_pair(false, 0.);
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 FastCircle circle(innerpos, middlepos, outerpos);
00118 if (circle.rho() < 200 && circle.rho() != 0) return std::make_pair(false, circle.rho());
00119
00120
00121 std::map<float, OrderedHitTriplet>::const_iterator lower_bound = map.lower_bound((1-0.01)*circle.rho());
00122 std::map<float, OrderedHitTriplet>::const_iterator upper_bound = map.upper_bound((1+0.01)*circle.rho());
00123 std::map<float, OrderedHitTriplet>::const_iterator iter;
00124 for (iter = lower_bound; iter != upper_bound && iter->first <= upper_bound->first; iter++){
00125 int shared=0;
00126 std::vector<const TrackingRecHit*> curtrh;
00127 curtrh.push_back(&*(iter->second.inner()));curtrh.push_back(&*(iter->second.middle()));curtrh.push_back(&*(iter->second.outer()));
00128 std::vector<const TrackingRecHit*>::const_iterator curiter;
00129 for (curiter = curtrh.begin(); curiter != curtrh.end(); curiter++){
00130 for (ioht = ohttrh.begin(); ioht != ohttrh.end(); ioht++){
00131 if ((*ioht)->geographicalId()==(*curiter)->geographicalId() &&
00132 ((*ioht)->localPosition()-(*curiter)->localPosition()).mag()<1e-5) shared++;
00133 }
00134 }
00135 if (shared>1) return std::make_pair(false, circle.rho());
00136 }
00137
00138 return std::make_pair(true,circle.rho());
00139 }