CMS 3D CMS Logo

Public Member Functions | Public Attributes | Private Attributes

PrimaryVertexProducer Class Reference

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

Inheritance diagram for PrimaryVertexProducer:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

edm::ParameterSet config () const
 PrimaryVertexProducer (const edm::ParameterSet &)
virtual void produce (edm::Event &, const edm::EventSetup &)
 ~PrimaryVertexProducer ()

Public Attributes

edm::InputTag beamSpotLabel
edm::InputTag trackLabel

Private Attributes

bool fVerbose
PrimaryVertexProducerAlgorithm theAlgo
edm::ParameterSet theConfig

Detailed Description

Description: steers tracker primary vertex reconstruction and storage

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

Definition at line 40 of file PrimaryVertexProducer.h.


Constructor & Destructor Documentation

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

Definition at line 31 of file PrimaryVertexProducer.cc.

References beamSpotLabel, fVerbose, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), and trackLabel.

  : theAlgo(conf), theConfig(conf)
{
  edm::LogInfo("PVDebugInfo") 
    << "Initializing PV producer " << "\n";
  fVerbose=conf.getUntrackedParameter<bool>("verbose", false);
  trackLabel = conf.getParameter<edm::InputTag>("TrackLabel");
  beamSpotLabel = conf.getParameter<edm::InputTag>("beamSpotLabel");
 
  produces<reco::VertexCollection>();

}
PrimaryVertexProducer::~PrimaryVertexProducer ( )

Definition at line 45 of file PrimaryVertexProducer.cc.

{}

Member Function Documentation

edm::ParameterSet PrimaryVertexProducer::config ( void  ) const [inline]

Definition at line 48 of file PrimaryVertexProducer.h.

References theConfig.

{ return theConfig; }
void PrimaryVertexProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 53 of file PrimaryVertexProducer.cc.

References beamSpotLabel, gather_cfg::cout, fVerbose, edm::EventSetup::get(), edm::Event::getByLabel(), edm::Event::put(), query::result, theAlgo, trackLabel, v, and PrimaryVertexProducerAlgorithm::vertices().

{
  using namespace edm;

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

  // get the BeamSpot, it will alwys be needed, even when not used as a constraint
  reco::BeamSpot vertexBeamSpot;
  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
  iEvent.getByLabel(beamSpotLabel,recoBeamSpotHandle);
  if (recoBeamSpotHandle.isValid()){
    vertexBeamSpot = *recoBeamSpotHandle;
  }else{
    edm::LogError("UnusableBeamSpot") << "No beam spot available from EventSetup";
  }



  // 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);


  // interface RECO tracks to vertex reconstruction
  edm::ESHandle<TransientTrackBuilder> theB;
  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
  std::vector<reco::TransientTrack> t_tks = (*theB).build(tks, vertexBeamSpot);
  if(fVerbose) {std::cout << "RecoVertex/PrimaryVertexProducer"
                     << "Found: " << t_tks.size() << " reconstructed tracks" << "\n";
  }


  // call vertex reconstruction
  std::vector<TransientVertex> t_vts = theAlgo.vertices(t_tks, vertexBeamSpot);
  if(fVerbose){
    std::cout <<"RecoVertex/PrimaryVertexProducer: "
              << " found " << t_vts.size() << " reconstructed vertices" << "\n";
  }
   
  // convert transient vertices returned by the theAlgo to (reco) vertices
  for (std::vector<TransientVertex>::const_iterator iv = t_vts.begin();
       iv != t_vts.end(); iv++) {
    reco::Vertex v = *iv;
    vColl.push_back(v);
  }

  if (vColl.empty()) {
    GlobalError bse(vertexBeamSpot.rotatedCovariance3D());
    if ( (bse.cxx() <= 0.) || 
        (bse.cyy() <= 0.) ||
        (bse.czz() <= 0.) ) {
      AlgebraicSymMatrix33 we;
      we(0,0)=10000; we(1,1)=10000; we(2,2)=10000;
      vColl.push_back(reco::Vertex(vertexBeamSpot.position(), we,0.,0.,0));
      if(fVerbose){
        std::cout <<"RecoVertex/PrimaryVertexProducer: "
                  << "Beamspot with invalid errors "<<bse.matrix()<<std::endl;
        std::cout << "Will put Vertex derived from dummy-fake BeamSpot into Event.\n";
      }
    } else {
      vColl.push_back(reco::Vertex(vertexBeamSpot.position(), 
                                 vertexBeamSpot.rotatedCovariance3D(),0.,0.,0));
      if(fVerbose){
        std::cout <<"RecoVertex/PrimaryVertexProducer: "
                  << " will put Vertex derived from BeamSpot into Event.\n";
      }
    }
  }

  if(fVerbose){
    int ivtx=0;
    for(reco::VertexCollection::const_iterator v=vColl.begin(); 
        v!=vColl.end(); ++v){
      std::cout << "recvtx "<< ivtx++ 
                << "#trk " << std::setw(3) << v->tracksSize()
                << " chi2 " << std::setw(4) << v->chi2() 
                << " ndof " << std::setw(3) << v->ndof() 
                << " x "  << std::setw(6) << v->position().x() 
                << " dx " << std::setw(6) << v->xError()
                << " y "  << std::setw(6) << v->position().y() 
                << " dy " << std::setw(6) << v->yError()
                << " z "  << std::setw(6) << v->position().z() 
                << " dz " << std::setw(6) << v->zError()
                << std::endl;
    }
  }

  
  *result = vColl;
  //  iEvent.put(result, "PrimaryVertex");
  iEvent.put(result);
  
}

Member Data Documentation

Definition at line 50 of file PrimaryVertexProducer.h.

Referenced by PrimaryVertexProducer(), and produce().

Definition at line 58 of file PrimaryVertexProducer.h.

Referenced by PrimaryVertexProducer(), and produce().

Definition at line 55 of file PrimaryVertexProducer.h.

Referenced by produce().

Definition at line 57 of file PrimaryVertexProducer.h.

Referenced by config().

Definition at line 49 of file PrimaryVertexProducer.h.

Referenced by PrimaryVertexProducer(), and produce().