Go to the documentation of this file.00001
00002 #include "RecoVertex/PrimaryVertexProducer/interface/PrimaryVertexProducerAlgorithm.h"
00003
00004 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00005 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009
00010 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00011 #include "RecoVertex/VertexPrimitives/interface/TransientVertex.h"
00012 #include "RecoVertex/VertexTools/interface/VertexDistanceXY.h"
00013
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00016 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00017 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00018
00019
00020 PrimaryVertexProducerAlgorithm::PrimaryVertexProducerAlgorithm(const edm::ParameterSet& conf)
00021 :theConfig(conf)
00022 {
00023
00024 fVerbose = conf.getUntrackedParameter<bool>("verbose", false);
00025 trackLabel = conf.getParameter<edm::InputTag>("TrackLabel");
00026 beamSpotLabel = conf.getParameter<edm::InputTag>("beamSpotLabel");
00027
00028
00029
00030 std::string trackSelectionAlgorithm=conf.getParameter<edm::ParameterSet>("TkFilterParameters").getParameter<std::string>("algorithm");
00031 if(trackSelectionAlgorithm=="filter"){
00032 theTrackFilter= new TrackFilterForPVFinding( conf.getParameter<edm::ParameterSet>("TkFilterParameters") );
00033 }else if (trackSelectionAlgorithm=="filterWithThreshold"){
00034 theTrackFilter= new HITrackFilterForPVFinding(conf.getParameter<edm::ParameterSet>("TkFilterParameters"));
00035 }else{
00036 throw VertexException("PrimaryVertexProducerAlgorithm: unknown track selection algorithm: " + trackSelectionAlgorithm);
00037 }
00038
00039
00040
00041 std::string clusteringAlgorithm=conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<std::string>("algorithm");
00042 if (clusteringAlgorithm=="gap"){
00043 theTrackClusterizer = new GapClusterizerInZ(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkGapClusParameters"));
00044 }else if(clusteringAlgorithm=="DA"){
00045 theTrackClusterizer = new DAClusterizerInZ(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
00046 }
00047
00048 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00049 else if(clusteringAlgorithm == "DA_vect") {
00050 theTrackClusterizer = new DAClusterizerInZ_vect(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
00051 }
00052 #endif
00053
00054
00055 else{
00056 throw VertexException("PrimaryVertexProducerAlgorithm: unknown clustering algorithm: " + clusteringAlgorithm);
00057 }
00058
00059
00060
00061 if (conf.exists("vertexCollections")){
00062 std::vector<edm::ParameterSet> vertexCollections =conf.getParameter< std::vector<edm::ParameterSet> >("vertexCollections");
00063
00064 for( std::vector< edm::ParameterSet >::const_iterator algoconf = vertexCollections.begin(); algoconf != vertexCollections.end(); algoconf++){
00065
00066 algo algorithm;
00067 std::string fitterAlgorithm = algoconf->getParameter<std::string>("algorithm");
00068 if (fitterAlgorithm=="KalmanVertexFitter") {
00069 algorithm.fitter= new KalmanVertexFitter();
00070 } else if( fitterAlgorithm=="AdaptiveVertexFitter") {
00071 algorithm.fitter= new AdaptiveVertexFitter();
00072 } else {
00073 throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + fitterAlgorithm);
00074 }
00075 algorithm.label = algoconf->getParameter<std::string>("label");
00076 algorithm.minNdof = algoconf->getParameter<double>("minNdof");
00077 algorithm.useBeamConstraint=algoconf->getParameter<bool>("useBeamConstraint");
00078 algorithm.vertexSelector=new VertexCompatibleWithBeam(VertexDistanceXY(), algoconf->getParameter<double>("maxDistanceToBeam"));
00079 algorithms.push_back(algorithm);
00080
00081 }
00082 }else{
00083 edm::LogWarning("MisConfiguration")<<"this module's configuration has changed, please update to have a vertexCollections=cms.VPSet parameter.";
00084
00085 algo algorithm;
00086 std::string fitterAlgorithm = conf.getParameter<std::string>("algorithm");
00087 if (fitterAlgorithm=="KalmanVertexFitter") {
00088 algorithm.fitter= new KalmanVertexFitter();
00089 } else if( fitterAlgorithm=="AdaptiveVertexFitter") {
00090 algorithm.fitter= new AdaptiveVertexFitter();
00091 } else {
00092 throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + fitterAlgorithm);
00093 }
00094 algorithm.label = "";
00095 algorithm.minNdof = conf.getParameter<double>("minNdof");
00096 algorithm.useBeamConstraint=conf.getParameter<bool>("useBeamConstraint");
00097
00098 algorithm.vertexSelector=new VertexCompatibleWithBeam(VertexDistanceXY(), conf.getParameter<edm::ParameterSet>("PVSelParameters").getParameter<double>("maxDistanceToBeam"));
00099
00100 algorithms.push_back(algorithm);
00101 }
00102
00103 }
00104
00105
00106 PrimaryVertexProducerAlgorithm::~PrimaryVertexProducerAlgorithm()
00107 {
00108 if (theTrackFilter) delete theTrackFilter;
00109 if (theTrackClusterizer) delete theTrackClusterizer;
00110 for( std::vector <algo>::const_iterator algorithm=algorithms.begin(); algorithm!=algorithms.end(); algorithm++){
00111 if (algorithm->fitter) delete algorithm->fitter;
00112 if (algorithm->vertexSelector) delete algorithm->vertexSelector;
00113 }
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 std::vector<TransientVertex>
00126 PrimaryVertexProducerAlgorithm::vertices(const std::vector<reco::TransientTrack> & tracks) const
00127 {
00128
00129 throw VertexException("PrimaryVertexProducerAlgorithm: cannot make a Primary Vertex without a beam spot" );
00130
00131 return std::vector<TransientVertex>();
00132 }
00133
00134
00135 std::vector<TransientVertex>
00136 PrimaryVertexProducerAlgorithm::vertices(const std::vector<reco::TransientTrack> & t_tks,
00137 const reco::BeamSpot & beamSpot,
00138 const std::string& label
00139 ) const
00140 {
00141
00142
00143
00144
00145
00146 bool validBS = true;
00147 VertexState beamVertexState(beamSpot);
00148 if ( (beamVertexState.error().cxx() <= 0.) ||
00149 (beamVertexState.error().cyy() <= 0.) ||
00150 (beamVertexState.error().czz() <= 0.) ) {
00151 validBS = false;
00152 edm::LogError("UnusableBeamSpot") << "Beamspot with invalid errors "<<beamVertexState.error().matrix();
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 std::vector<reco::TransientTrack> seltks = theTrackFilter->select( t_tks );
00164
00165
00166
00167 std::vector< std::vector<reco::TransientTrack> > clusters = theTrackClusterizer->clusterize(seltks);
00168 if (fVerbose){std::cout << " clustering returned "<< clusters.size() << " clusters from " << seltks.size() << " selected tracks" <<std::endl;}
00169
00170
00171
00172 for( std::vector <algo>::const_iterator algorithm=algorithms.begin(); algorithm!=algorithms.end(); algorithm++){
00173 if ( ! (algorithm->label == label) )continue;
00174
00175
00176
00177
00178
00179 std::vector<TransientVertex> pvs;
00180 for (std::vector< std::vector<reco::TransientTrack> >::const_iterator iclus
00181 = clusters.begin(); iclus != clusters.end(); iclus++) {
00182
00183
00184 TransientVertex v;
00185 if( algorithm->useBeamConstraint && validBS &&((*iclus).size()>1) ){
00186
00187 v = algorithm->fitter->vertex(*iclus, beamSpot);
00188
00189 }else if( !(algorithm->useBeamConstraint) && ((*iclus).size()>1) ) {
00190
00191 v = algorithm->fitter->vertex(*iclus);
00192
00193 }
00194
00195
00196 if (fVerbose){
00197 if (v.isValid()) std::cout << "x,y,z=" << v.position().x() <<" " << v.position().y() << " " << v.position().z() << std::endl;
00198 else std::cout <<"Invalid fitted vertex\n";
00199 }
00200
00201 if (v.isValid()
00202 && (v.degreesOfFreedom()>=algorithm->minNdof)
00203 && (!validBS || (*(algorithm->vertexSelector))(v,beamVertexState))
00204 ) pvs.push_back(v);
00205 }
00206
00207 if(fVerbose){
00208 std::cout << "PrimaryVertexProducerAlgorithm::vertices candidates =" << pvs.size() << std::endl;
00209 }
00210
00211
00212
00213
00214
00215
00216 if(pvs.size()>1){
00217 sort(pvs.begin(), pvs.end(), VertexHigherPtSquared());
00218 }
00219
00220 return pvs;
00221 }
00222
00223 std::vector<TransientVertex> dummy;
00224 return dummy;
00225 }
00226
00227
00228
00229
00230
00231