CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/RecoVertex/AdaptiveVertexFinder/src/TrackVertexArbitratration.cc

Go to the documentation of this file.
00001 #include "RecoVertex/AdaptiveVertexFinder/interface/TrackVertexArbitratration.h"
00002 #include "DataFormats/GeometryVector/interface/VectorUtil.h"
00003 using namespace reco;
00004 
00005 TrackVertexArbitration::TrackVertexArbitration(const edm::ParameterSet &params) :
00006         primaryVertexCollection   (params.getParameter<edm::InputTag>("primaryVertices")),
00007         secondaryVertexCollection (params.getParameter<edm::InputTag>("secondaryVertices")),
00008         trackCollection           (params.getParameter<edm::InputTag>("tracks")),
00009         beamSpotCollection        (params.getParameter<edm::InputTag>("beamSpot")),
00010         dRCut                     (params.getParameter<double>("dRCut")),
00011         distCut                   (params.getParameter<double>("distCut")),
00012         sigCut                    (params.getParameter<double>("sigCut")),
00013         dLenFraction              (params.getParameter<double>("dLenFraction"))
00014 {
00015         
00016 }
00017 
00018 bool TrackVertexArbitration::trackFilterArbitrator(const reco::TrackRef &track) const
00019 {
00020         if (track->hitPattern().trackerLayersWithMeasurement() < 4)
00021                 return false;
00022         if (track->pt() < 0.4 )
00023                 return false;
00024         if (track->hitPattern().numberOfValidPixelHits() < 1)
00025                 return false;
00026 
00027         return true;
00028 }
00029 
00030 
00031 
00032 
00033 
00034 reco::VertexCollection  TrackVertexArbitration::trackVertexArbitrator(
00035          edm::Handle<BeamSpot> &beamSpot, 
00036          const reco::Vertex &pv,
00037          edm::ESHandle<TransientTrackBuilder> &trackBuilder,
00038          const edm::RefVector< TrackCollection > & selectedTracks,
00039          reco::VertexCollection & secondaryVertices)
00040 {
00041         using namespace reco;
00042 
00043              //std::cout << "PV: " << pv.position() << std::endl;
00044         VertexDistance3D dist;
00045 
00046   double sigmacut = 3.0;
00047   double Tini     = 256.;
00048   double ratio    = 0.25;
00049 
00050   AdaptiveVertexFitter theAdaptiveFitter(
00051                                             GeometricAnnealing(sigmacut, Tini, ratio),
00052                                             DefaultLinearizationPointFinder(),
00053                                             KalmanVertexUpdator<5>(),
00054                                             KalmanVertexTrackCompatibilityEstimator<5>(),
00055                                             KalmanVertexSmoother() );
00056 
00057 
00058 
00059         reco::VertexCollection recoVertices;
00060 
00061        VertexDistance3D vdist;
00062 
00063 for(std::vector<reco::Vertex>::const_iterator sv = secondaryVertices.begin();
00064             sv != secondaryVertices.end(); ++sv) {
00065 /*          recoVertices->push_back(*sv);
00066         
00067 
00068        for(std::vector<reco::Vertex>::iterator sv = recoVertices->begin();
00069             sv != recoVertices->end(); ++sv) {
00070 */
00071             GlobalPoint ppv(pv.position().x(),pv.position().y(),pv.position().z());
00072             GlobalPoint ssv(sv->position().x(),sv->position().y(),sv->position().z());
00073             GlobalVector flightDir = ssv-ppv;
00074 //            std::cout << "Vertex : " << sv-secondaryVertices->begin() << " " << sv->position() << std::endl;
00075             Measurement1D dlen= vdist.distance(pv,*sv);
00076             std::vector<reco::TransientTrack>  selTracks;
00077        for(unsigned int itrack = 0; itrack < selectedTracks.size(); itrack++){
00078                 TrackRef ref = (selectedTracks)[itrack];
00079 
00080         //for(TrackCollection::const_iterator track = tracks->begin();
00081           //  track != tracks->end(); ++track) {
00082 
00083             //    TrackRef ref(tracks, track - tracks->begin());
00084                 if (!trackFilterArbitrator(ref))                         continue;
00085 
00086                 TransientTrack tt = trackBuilder->build(ref);
00087                 tt.setBeamSpot(*beamSpot);
00088                 float w = sv->trackWeight(ref);
00089                 std::pair<bool,Measurement1D> ipv = IPTools::absoluteImpactParameter3D(tt,pv);
00090                 std::pair<bool,Measurement1D> itpv = IPTools::absoluteTransverseImpactParameter(tt,pv);
00091                 std::pair<bool,Measurement1D> isv = IPTools::absoluteImpactParameter3D(tt,*sv);
00092                 float dR = Geom::deltaR(flightDir,tt.track()); //.eta(), flightDir.phi(), tt.track().eta(), tt.track().phi());
00093 
00094                 if( w > 0 || ( isv.second.significance() < sigCut && isv.second.value() < distCut && isv.second.value() < dlen.value()*dLenFraction ) )
00095                 {
00096 
00097                   if(( isv.second.value() < ipv.second.value()  ) && isv.second.value() < distCut && isv.second.value() < dlen.value()*dLenFraction 
00098                   && dR < dRCut  ) 
00099                   {
00100 #ifdef VTXDEBUG
00101                      if(w > 0.5) std::cout << " = ";
00102                     else std::cout << " + ";
00103 #endif 
00104                      selTracks.push_back(tt);
00105                   } else
00106                   {
00107 #ifdef VTXDEBUG
00108                      if(w > 0.5 && isv.second.value() > ipv.second.value() ) std::cout << " - ";
00109                   else std::cout << "   ";
00110 #endif
00111                      //add also the tracks used in previous fitting that are still closer to Sv than Pv 
00112                      if(w > 0.5 && isv.second.value() <= ipv.second.value() && dR < dRCut) {  
00113                        selTracks.push_back(tt);
00114 #ifdef VTXDEBUG
00115                        std::cout << " = ";
00116 #endif
00117                      }
00118                      if(w > 0.5 && isv.second.value() <= ipv.second.value() && dR >= dRCut) {
00119 #ifdef VTXDEBUG
00120                        std::cout << " - ";
00121 #endif
00122 
00123                      }
00124 
00125                     
00126                   }
00127 #ifdef VTXDEBUG
00128 
00129                   std::cout << "t : " << itrack << " ref " << ref.key() << " w: " << w 
00130                   << " svip: " << isv.second.significance() << " " << isv.second.value()  
00131                   << " pvip: " << ipv.second.significance() << " " << ipv.second.value()  << " res " << tt.track().residualX(0)   << "," << tt.track().residualY(0) 
00132                   << " tpvip: " << itpv.second.significance() << " " << itpv.second.value()  << " dr: "   << dR << std::endl;
00133 #endif
00134  
00135                 }
00136                else
00137                  {
00138 #ifdef VTXDEBUG
00139 
00140                   std::cout << " . t : " << itrack << " ref " << ref.key()<<  " w: " << w 
00141                   << " svip: " << isv.second.significance() << " " << isv.second.value()  
00142                   << " pvip: " << ipv.second.significance() << " " << ipv.second.value()  << " dr: "   << dR << std::endl;
00143 #endif
00144 
00145                  }
00146            }      
00147 
00148            if(selTracks.size() >= 2)
00149               { 
00150                  TransientVertex singleFitVertex;
00151                  singleFitVertex = theAdaptiveFitter.vertex(selTracks,ssv);
00152                 if(singleFitVertex.isValid())  { recoVertices.push_back(reco::Vertex(singleFitVertex));
00153 
00154 #ifdef VTXDEBUG
00155                 const reco::Vertex & extVertex = recoVertices.back();
00156                       GlobalVector vtxDir = GlobalVector(extVertex.p4().X(),extVertex.p4().Y(),extVertex.p4().Z());
00157 
00158 
00159                 std::cout << " pointing : " << Geom::deltaR(extVertex.position() - pv.position(), vtxDir) << std::endl;
00160 #endif
00161                 }
00162               } 
00163         }
00164         return recoVertices;
00165 }
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174