CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PrimaryVertexProducer.cc
Go to the documentation of this file.
2 
8 
11 
16 
17 //using namespace reco;
18 
19 //
20 // constants, enums and typedefs
21 //
22 
23 //
24 // static data member definitions
25 //
26 
27 //
28 // constructors and destructor
29 //
31  : theAlgo(conf), theConfig(conf)
32 {
33  edm::LogInfo("PVDebugInfo")
34  << "Initializing PV producer " << "\n";
35  fVerbose=conf.getUntrackedParameter<bool>("verbose", false);
36  trackLabel = conf.getParameter<edm::InputTag>("TrackLabel");
37  beamSpotLabel = conf.getParameter<edm::InputTag>("beamSpotLabel");
38 
39  produces<reco::VertexCollection>();
40 
41 }
42 
43 
45 
46 //
47 // member functions
48 //
49 
50 // ------------ method called to produce the data ------------
51 void
53 {
54  using namespace edm;
55 
56  std::auto_ptr<reco::VertexCollection> result(new reco::VertexCollection);
58 
59  // get the BeamSpot, it will alwys be needed, even when not used as a constraint
60  reco::BeamSpot vertexBeamSpot;
61  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
62  iEvent.getByLabel(beamSpotLabel,recoBeamSpotHandle);
63  if (recoBeamSpotHandle.isValid()){
64  vertexBeamSpot = *recoBeamSpotHandle;
65  }else{
66  edm::LogError("UnusableBeamSpot") << "No beam spot available from EventSetup";
67  }
68 
69 
70 
71  // get RECO tracks from the event
72  // `tks` can be used as a ptr to a reco::TrackCollection
74  iEvent.getByLabel(trackLabel, tks);
75 
76 
77  // interface RECO tracks to vertex reconstruction
79  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
80  std::vector<reco::TransientTrack> t_tks = (*theB).build(tks, vertexBeamSpot);
81  if(fVerbose) {std::cout << "RecoVertex/PrimaryVertexProducer"
82  << "Found: " << t_tks.size() << " reconstructed tracks" << "\n";
83  }
84 
85 
86  // call vertex reconstruction
87  std::vector<TransientVertex> t_vts = theAlgo.vertices(t_tks, vertexBeamSpot);
88  if(fVerbose){
89  std::cout <<"RecoVertex/PrimaryVertexProducer: "
90  << " found " << t_vts.size() << " reconstructed vertices" << "\n";
91  }
92 
93  // convert transient vertices returned by the theAlgo to (reco) vertices
94  for (std::vector<TransientVertex>::const_iterator iv = t_vts.begin();
95  iv != t_vts.end(); iv++) {
96  reco::Vertex v = *iv;
97  vColl.push_back(v);
98  }
99 
100  if (vColl.empty()) {
101  GlobalError bse(vertexBeamSpot.rotatedCovariance3D());
102  if ( (bse.cxx() <= 0.) ||
103  (bse.cyy() <= 0.) ||
104  (bse.czz() <= 0.) ) {
106  we(0,0)=10000; we(1,1)=10000; we(2,2)=10000;
107  vColl.push_back(reco::Vertex(vertexBeamSpot.position(), we,0.,0.,0));
108  if(fVerbose){
109  std::cout <<"RecoVertex/PrimaryVertexProducer: "
110  << "Beamspot with invalid errors "<<bse.matrix()<<std::endl;
111  std::cout << "Will put Vertex derived from dummy-fake BeamSpot into Event.\n";
112  }
113  } else {
114  vColl.push_back(reco::Vertex(vertexBeamSpot.position(),
115  vertexBeamSpot.rotatedCovariance3D(),0.,0.,0));
116  if(fVerbose){
117  std::cout <<"RecoVertex/PrimaryVertexProducer: "
118  << " will put Vertex derived from BeamSpot into Event.\n";
119  }
120  }
121  }
122 
123  if(fVerbose){
124  int ivtx=0;
125  for(reco::VertexCollection::const_iterator v=vColl.begin();
126  v!=vColl.end(); ++v){
127  std::cout << "recvtx "<< ivtx++
128  << "#trk " << std::setw(3) << v->tracksSize()
129  << " chi2 " << std::setw(4) << v->chi2()
130  << " ndof " << std::setw(3) << v->ndof()
131  << " x " << std::setw(6) << v->position().x()
132  << " dx " << std::setw(6) << v->xError()
133  << " y " << std::setw(6) << v->position().y()
134  << " dy " << std::setw(6) << v->yError()
135  << " z " << std::setw(6) << v->position().z()
136  << " dz " << std::setw(6) << v->zError()
137  << std::endl;
138  }
139  }
140 
141 
142  *result = vColl;
143  // iEvent.put(result, "PrimaryVertex");
144  iEvent.put(result);
145 
146 }
147 
148 
149 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
virtual std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &tracks) const
int iEvent
Definition: GenABIO.cc:243
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
tuple result
Definition: query.py:137
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
tuple conf
Definition: dbtoconf.py:185
virtual void produce(edm::Event &, const edm::EventSetup &)
const T & get() const
Definition: EventSetup.h:55
PrimaryVertexProducerAlgorithm theAlgo
PrimaryVertexProducer(const edm::ParameterSet &)
tuple cout
Definition: gather_cfg.py:41
mathSSE::Vec4< T > v