CMS 3D CMS Logo

GenericTripletGenerator.cc

Go to the documentation of this file.
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         //conf_(conf),
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         //edm::ParameterSet leyerPSet = conf_.getParameter<edm::ParameterSet>("LayerPSet");
00019         //SeedingLayerSetsBuilder lsBuilder(leyerPSet);
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                 //std::cout << "innerHits.size()=" << innerHits.size() << std::endl;
00040                 std::vector<SeedingHit> middleHits = region.hits(e, es, &ls[1]);
00041                 //std::cout << "middleHits.size()=" << middleHits.size() << std::endl;
00042                 std::vector<SeedingHit> outerHits  = region.hits(e, es, &ls[2]);
00043                 //std::cout << "outerHits.size()=" << outerHits.size() << std::endl;
00044                 //std::cout << "trying " << innerHits.size()*middleHits.size()*outerHits.size() << " combinations "<<std::endl;
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                                         //GlobalPoint innerpos  = ls[0].hitBuilder()->build(&(**iInnerHit))->globalPosition();
00052                                         //GlobalPoint middlepos = ls[1].hitBuilder()->build(&(**iMiddleHit))->globalPosition();
00053                                         //GlobalPoint outerpos  = ls[2].hitBuilder()->build(&(**iOuterHit))->globalPosition();
00054                                         //FastCircle circle(innerpos,
00055                                         //                middlepos,
00056                                         //                  outerpos);
00057                                         //do a first check on the radius of curvature to reduce the combinatorics       
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                                         //if (circle.rho() > 200 || circle.rho() == 0) { //0 radius means straight line
00062                                                 //hitTriplets.push_back(OrderedHitTriplet(*iInnerHit,
00063                                                 //                                      *iMiddleHit,
00064                                                 //                                      *iOuterHit));
00065                                                 hitTriplets.push_back(oht);
00066                                                 radius_triplet_map.insert(std::make_pair(val_radius.second,oht));
00067                                         }
00068                                 }
00069                         }
00070                 }
00071         }
00072         //std::cout << "ending with " << hitTriplets.size() << " triplets" << std::endl;
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         //first check the radius
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         //now chech that the change in phi is reasonable. the limiting angular distance is the one in case 
00087         //one of the two points is a tangent point.
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();//actually this is the tangent of the limiting angle          
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         //if (fabs(tan(outerpos.phi()-middlepos.phi()))>limit_phi_distance1 || 
00093         //    fabs(tan(innerpos.phi()-middlepos.phi()))>limit_phi_distance2) {
00094         if (fabs(outerpos.phi()-middlepos.phi())>fabs(atan(limit_phi_distance1)) ||
00095             fabs(innerpos.phi()-middlepos.phi())>fabs(atan(limit_phi_distance2)) ) {    
00096                 //std::cout << "rejected because phi" << std::endl;
00097                 return std::make_pair(false, 0.);
00098         }
00099         //should we add a control on the r-z plane too?
00100         /*
00101         //now check that there is no big change in the r-z projection
00102         float dz1 = outerpos.z()-middlepos.z();
00103         float dr1 = sqrt(outerpos.x()*outerpos.x()+outerpos.y()*outerpos.y())-
00104                     sqrt(middlepos.x()*middlepos.x()+middlepos.y()*middlepos.y());              
00105         float dz2 = middlepos.z()-innerpos.z(); 
00106         float dr2 = sqrt(middlepos.x()*middlepos.x()+middlepos.y()*middlepos.y())-
00107                     sqrt(innerpos.x()*innerpos.x()+innerpos.y()*innerpos.y());
00108         float tan1 = dz1/dr1;
00109         float tan2 = dz2/dr2;
00110         //how much should we allow? should we make it configurable?
00111         if (fabs(tan1-tan2)/tan1>0.5){
00112                 //std::cout << "rejected because z" << std::endl;
00113                 return std::make_pair(false, 0.);       
00114         }
00115         */
00116         //now check the radius is not too small
00117         FastCircle circle(innerpos, middlepos, outerpos);
00118         if (circle.rho() < 200 && circle.rho() != 0) return std::make_pair(false, circle.rho()); //to small radius      
00119         //now check if at least 2 hits are shared with an existing triplet
00120         //look for similar radii in the map
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 }

Generated on Tue Jun 9 17:45:45 2009 for CMSSW by  doxygen 1.5.4