CMS 3D CMS Logo

Classes | Public Member Functions | Public Attributes | Private Attributes

PrimaryVertexProducerAlgorithm Class Reference

#include <RecoVertex/PrimaryVertexProducerAlgorithm/src/PrimaryVertexProducerAlgorithm.cc>

Inheritance diagram for PrimaryVertexProducerAlgorithm:
VertexReconstructor

List of all members.

Classes

struct  algo

Public Member Functions

virtual
PrimaryVertexProducerAlgorithm
clone () const
edm::ParameterSet config () const
 PrimaryVertexProducerAlgorithm (const edm::ParameterSet &)
virtual std::vector
< TransientVertex
vertices (const std::vector< reco::TransientTrack > &tracks, const reco::BeamSpot &beamSpot, const std::string &label="") const
virtual std::vector
< TransientVertex
vertices (const std::vector< reco::TransientTrack > &tracks) const
 ~PrimaryVertexProducerAlgorithm ()

Public Attributes

edm::InputTag beamSpotLabel
edm::InputTag trackLabel

Private Attributes

std::vector< algoalgorithms
bool fVerbose
edm::ParameterSet theConfig
TrackClusterizerInZtheTrackClusterizer
TrackFilterForPVFindingBasetheTrackFilter

Detailed Description

Description: allow redoing the primary vertex reconstruction from a list of tracks, considered obsolete

Implementation: <Notes on="" implementation>="">

Definition at line 59 of file PrimaryVertexProducerAlgorithm.h.


Constructor & Destructor Documentation

PrimaryVertexProducerAlgorithm::PrimaryVertexProducerAlgorithm ( const edm::ParameterSet conf) [explicit]

Definition at line 20 of file PrimaryVertexProducerAlgorithm.cc.

References algorithm(), algorithms, beamSpotLabel, edm::ParameterSet::exists(), PrimaryVertexProducerAlgorithm::algo::fitter, fVerbose, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), PrimaryVertexProducerAlgorithm::algo::label, PrimaryVertexProducerAlgorithm::algo::minNdof, AlCaHLTBitMon_QueryRunRegistry::string, theTrackClusterizer, theTrackFilter, trackLabel, PrimaryVertexProducerAlgorithm::algo::useBeamConstraint, and PrimaryVertexProducerAlgorithm::algo::vertexSelector.

Referenced by clone().

  :theConfig(conf)
{

  fVerbose   = conf.getUntrackedParameter<bool>("verbose", false);
  trackLabel = conf.getParameter<edm::InputTag>("TrackLabel");
  beamSpotLabel = conf.getParameter<edm::InputTag>("beamSpotLabel");


  // select and configure the track selection
  std::string trackSelectionAlgorithm=conf.getParameter<edm::ParameterSet>("TkFilterParameters").getParameter<std::string>("algorithm");
  if(trackSelectionAlgorithm=="filter"){
    theTrackFilter= new TrackFilterForPVFinding( conf.getParameter<edm::ParameterSet>("TkFilterParameters") );
  }else if (trackSelectionAlgorithm=="filterWithThreshold"){
    theTrackFilter= new HITrackFilterForPVFinding(conf.getParameter<edm::ParameterSet>("TkFilterParameters"));
  }else{
    throw VertexException("PrimaryVertexProducerAlgorithm: unknown track selection algorithm: " + trackSelectionAlgorithm);  
  }


  // select and configure the track clusterizer
  std::string clusteringAlgorithm=conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<std::string>("algorithm");
  if (clusteringAlgorithm=="gap"){
    theTrackClusterizer = new GapClusterizerInZ(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkGapClusParameters"));
  }else if(clusteringAlgorithm=="DA"){
    theTrackClusterizer = new DAClusterizerInZ(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
  }
  // provide the vectorized version of the clusterizer, if supported by the build
#ifdef __GXX_EXPERIMENTAL_CXX0X__
   else if(clusteringAlgorithm == "DA_vect") {
    theTrackClusterizer = new DAClusterizerInZ_vect(conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
  }
#endif


  else{
    throw VertexException("PrimaryVertexProducerAlgorithm: unknown clustering algorithm: " + clusteringAlgorithm);  
  }


  // select and configure the vertex fitters
  if (conf.exists("vertexCollections")){
    std::vector<edm::ParameterSet> vertexCollections =conf.getParameter< std::vector<edm::ParameterSet> >("vertexCollections");

    for( std::vector< edm::ParameterSet >::const_iterator algoconf = vertexCollections.begin(); algoconf != vertexCollections.end(); algoconf++){
      
      algo algorithm;
      std::string fitterAlgorithm = algoconf->getParameter<std::string>("algorithm");
      if (fitterAlgorithm=="KalmanVertexFitter") {
        algorithm.fitter= new KalmanVertexFitter();
      } else if( fitterAlgorithm=="AdaptiveVertexFitter") {
        algorithm.fitter= new AdaptiveVertexFitter();
      } else {
        throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + fitterAlgorithm);  
      }
      algorithm.label = algoconf->getParameter<std::string>("label");
      algorithm.minNdof = algoconf->getParameter<double>("minNdof");
      algorithm.useBeamConstraint=algoconf->getParameter<bool>("useBeamConstraint");
      algorithm.vertexSelector=new VertexCompatibleWithBeam(VertexDistanceXY(), algoconf->getParameter<double>("maxDistanceToBeam"));
      algorithms.push_back(algorithm);
      
    }
  }else{
    edm::LogWarning("MisConfiguration")<<"this module's configuration has changed, please update to have a vertexCollections=cms.VPSet parameter.";

    algo algorithm;
    std::string fitterAlgorithm = conf.getParameter<std::string>("algorithm");
    if (fitterAlgorithm=="KalmanVertexFitter") {
      algorithm.fitter= new KalmanVertexFitter();
    } else if( fitterAlgorithm=="AdaptiveVertexFitter") {
      algorithm.fitter= new AdaptiveVertexFitter();
    } else {
      throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + fitterAlgorithm);  
    }
    algorithm.label = "";
    algorithm.minNdof = conf.getParameter<double>("minNdof");
    algorithm.useBeamConstraint=conf.getParameter<bool>("useBeamConstraint");
    
    algorithm.vertexSelector=new VertexCompatibleWithBeam(VertexDistanceXY(), conf.getParameter<edm::ParameterSet>("PVSelParameters").getParameter<double>("maxDistanceToBeam"));

    algorithms.push_back(algorithm);
  }
 
}
PrimaryVertexProducerAlgorithm::~PrimaryVertexProducerAlgorithm ( )

Definition at line 106 of file PrimaryVertexProducerAlgorithm.cc.

References algorithm(), algorithms, theTrackClusterizer, and theTrackFilter.

{
  if (theTrackFilter) delete theTrackFilter;
  if (theTrackClusterizer) delete theTrackClusterizer;
  for( std::vector <algo>::const_iterator algorithm=algorithms.begin(); algorithm!=algorithms.end(); algorithm++){
    if (algorithm->fitter) delete algorithm->fitter;
    if (algorithm->vertexSelector) delete algorithm->vertexSelector;
  }
}

Member Function Documentation

virtual PrimaryVertexProducerAlgorithm* PrimaryVertexProducerAlgorithm::clone ( void  ) const [inline, virtual]

Clone method

Implements VertexReconstructor.

Definition at line 76 of file PrimaryVertexProducerAlgorithm.h.

References PrimaryVertexProducerAlgorithm().

                                                         {
    return new PrimaryVertexProducerAlgorithm(*this);
  }
edm::ParameterSet PrimaryVertexProducerAlgorithm::config ( void  ) const [inline]

Definition at line 82 of file PrimaryVertexProducerAlgorithm.h.

References theConfig.

{ return theConfig; }
std::vector< TransientVertex > PrimaryVertexProducerAlgorithm::vertices ( const std::vector< reco::TransientTrack > &  ) const [virtual]

Reconstruct vertices

Implements VertexReconstructor.

Definition at line 126 of file PrimaryVertexProducerAlgorithm.cc.

{

   throw VertexException("PrimaryVertexProducerAlgorithm: cannot make a Primary Vertex without a beam spot" );

   return std::vector<TransientVertex>();
}
std::vector< TransientVertex > PrimaryVertexProducerAlgorithm::vertices ( const std::vector< reco::TransientTrack > &  tracks,
const reco::BeamSpot beamSpot,
const std::string &  label = "" 
) const [virtual]

Definition at line 136 of file PrimaryVertexProducerAlgorithm.cc.

References algorithm(), algorithms, TrackClusterizerInZ::clusterize(), gather_cfg::cout, GlobalErrorBase< T, ErrorWeightType >::cxx(), GlobalErrorBase< T, ErrorWeightType >::cyy(), GlobalErrorBase< T, ErrorWeightType >::czz(), TransientVertex::degreesOfFreedom(), VertexState::error(), fVerbose, TransientVertex::isValid(), GlobalErrorBase< T, ErrorWeightType >::matrix(), TransientVertex::position(), TrackFilterForPVFindingBase::select(), python::multivaluedict::sort(), theTrackClusterizer, theTrackFilter, v, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

{





  bool validBS = true;
  VertexState beamVertexState(beamSpot);
  if ( (beamVertexState.error().cxx() <= 0.) || 
       (beamVertexState.error().cyy() <= 0.) ||
       (beamVertexState.error().czz() <= 0.) ) {
    validBS = false;
    edm::LogError("UnusableBeamSpot") << "Beamspot with invalid errors "<<beamVertexState.error().matrix();
  }


//   // get RECO tracks from the event
//   // `tks` can be used as a ptr to a reco::TrackCollection
//   edm::Handle<reco::TrackCollection> tks;
//   iEvent.getByLabel(trackLabel, tks);


  // select tracks
  std::vector<reco::TransientTrack> seltks = theTrackFilter->select( t_tks );


  // clusterize tracks in Z
  std::vector< std::vector<reco::TransientTrack> > clusters =  theTrackClusterizer->clusterize(seltks);
  if (fVerbose){std::cout <<  " clustering returned  "<< clusters.size() << " clusters  from " << seltks.size() << " selected tracks" <<std::endl;}


  // vertex fits
  for( std::vector <algo>::const_iterator algorithm=algorithms.begin(); algorithm!=algorithms.end(); algorithm++){
    if (  ! (algorithm->label == label) )continue;

  //std::auto_ptr<reco::VertexCollection> result(new reco::VertexCollection);
  // reco::VertexCollection vColl;
  

    std::vector<TransientVertex> pvs;
    for (std::vector< std::vector<reco::TransientTrack> >::const_iterator iclus
           = clusters.begin(); iclus != clusters.end(); iclus++) {


      TransientVertex v; 
      if( algorithm->useBeamConstraint && validBS &&((*iclus).size()>1) ){
        
        v = algorithm->fitter->vertex(*iclus, beamSpot);
        
      }else if( !(algorithm->useBeamConstraint) && ((*iclus).size()>1) ) {
      
        v = algorithm->fitter->vertex(*iclus); 
        
      }// else: no fit ==> v.isValid()=False


      if (fVerbose){
        if (v.isValid()) std::cout << "x,y,z=" << v.position().x() <<" " << v.position().y() << " " <<  v.position().z() << std::endl;
        else std::cout <<"Invalid fitted vertex\n";
      }

      if (v.isValid() 
            && (v.degreesOfFreedom()>=algorithm->minNdof) 
          && (!validBS || (*(algorithm->vertexSelector))(v,beamVertexState))
          ) pvs.push_back(v);
    }// end of cluster loop

    if(fVerbose){
      std::cout << "PrimaryVertexProducerAlgorithm::vertices  candidates =" << pvs.size() << std::endl;
    }



    

    // sort vertices by pt**2  vertex (aka signal vertex tagging)
    if(pvs.size()>1){
      sort(pvs.begin(), pvs.end(), VertexHigherPtSquared());
    }

    return pvs;
  }
  
  std::vector<TransientVertex> dummy;
  return dummy;//avoid compiler warning, should never be here
}

Member Data Documentation

Definition at line 84 of file PrimaryVertexProducerAlgorithm.h.

Referenced by PrimaryVertexProducerAlgorithm().

Definition at line 102 of file PrimaryVertexProducerAlgorithm.h.

Referenced by PrimaryVertexProducerAlgorithm(), and vertices().

Definition at line 101 of file PrimaryVertexProducerAlgorithm.h.

Referenced by config().

Definition at line 83 of file PrimaryVertexProducerAlgorithm.h.

Referenced by PrimaryVertexProducerAlgorithm().