CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FFTJetVertexAdder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FFTJetProducers
4 // Class: FFTJetVertexAdder
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Thu Jun 21 19:19:40 CDT 2012
16 //
17 //
18 
19 #include <iostream>
20 #include "CLHEP/Random/RandGauss.h"
21 
22 // framework include files
31 
34 
37 
39 
40 #define init_param(type, varname) varname (ps.getParameter< type >( #varname ))
41 
42 //
43 // class declaration
44 //
46 {
47 public:
48  explicit FFTJetVertexAdder(const edm::ParameterSet&);
50 
51 protected:
52  // methods
53  void beginJob() override;
54  void produce(edm::Event&, const edm::EventSetup&) override;
55  void endJob() override;
56 
57 private:
61 
65 
66  const bool useBeamSpot;
67  const bool addExistingVertices;
68 
69  const double fixedX;
70  const double fixedY;
71  const double fixedZ;
72 
73  const double sigmaX;
74  const double sigmaY;
75  const double sigmaZ;
76 
77  const double nDof;
78  const double chi2;
79  const double errX;
80  const double errY;
81  const double errZ;
82 
83  const unsigned nVerticesToMake;
84 
85  CLHEP::RandGauss* rGauss_;
86 };
87 
88 //
89 // constructors and destructor
90 //
92  : init_param(edm::InputTag, beamSpotLabel),
93  init_param(edm::InputTag, existingVerticesLabel),
94  init_param(std::string, outputLabel),
95  init_param(bool, useBeamSpot),
96  init_param(bool, addExistingVertices),
97  init_param(double, fixedX),
98  init_param(double, fixedY),
99  init_param(double, fixedZ),
100  init_param(double, sigmaX),
101  init_param(double, sigmaY),
102  init_param(double, sigmaZ),
103  init_param(double, nDof),
104  init_param(double, chi2),
105  init_param(double, errX),
106  init_param(double, errY),
107  init_param(double, errZ),
108  init_param(unsigned, nVerticesToMake),
109  rGauss_(0)
110 {
111  produces<reco::VertexCollection>(outputLabel);
112 }
113 
114 
116 {
117  delete rGauss_;
118 }
119 
120 
121 // ------------ method called to produce the data ------------
123  edm::Event& iEvent, const edm::EventSetup& iSetup)
124 {
125  // get PFCandidates
126  std::auto_ptr<reco::VertexCollection> pOutput(new reco::VertexCollection);
127 
128  double xmean = fixedX;
129  double ymean = fixedY;
130  double zmean = fixedZ;
131 
132  double xwidth = sigmaX;
133  double ywidth = sigmaY;
134  double zwidth = sigmaZ;
135 
136  if (useBeamSpot)
137  {
138  edm::Handle<reco::BeamSpot> beamSpotHandle;
139  iEvent.getByLabel(beamSpotLabel, beamSpotHandle);
140  if (!beamSpotHandle.isValid())
141  throw cms::Exception("FFTJetBadConfig")
142  << "ERROR in FFTJetVertexAdder:"
143  " could not find beam spot information"
144  << std::endl;
145 
146  xmean = beamSpotHandle->x0();
147  ymean = beamSpotHandle->y0();
148  zmean = beamSpotHandle->z0();
149 
150  xwidth = beamSpotHandle->BeamWidthX();
151  ywidth = beamSpotHandle->BeamWidthY();
152  zwidth = beamSpotHandle->sigmaZ();
153  }
154 
156  for (unsigned i=0; i<3; ++i)
157  for (unsigned j=0; j<3; ++j)
158  err[i][j] = 0.0;
159  err[0][0] = errX*errX;
160  err[1][1] = errY*errY;
161  err[2][2] = errZ*errZ;
162 
163  for (unsigned iv=0; iv<nVerticesToMake; ++iv)
164  {
165  const double x0 = (*rGauss_)(xmean, xwidth);
166  const double y0 = (*rGauss_)(ymean, ywidth);
167  const double z0 = (*rGauss_)(zmean, zwidth);
168  const reco::Vertex::Point position(x0, y0, z0);
169  pOutput->push_back(reco::Vertex(position, err, chi2, nDof, 0));
170  }
171 
173  {
174  typedef reco::VertexCollection::const_iterator IV;
175 
177  iEvent.getByLabel(existingVerticesLabel, vertices);
178  if (!vertices.isValid())
179  throw cms::Exception("FFTJetBadConfig")
180  << "ERROR in FFTJetVertexAdder:"
181  " could not find existing collection of vertices"
182  << std::endl;
183 
184  const IV vertend(vertices->end());
185  for (IV iv=vertices->begin(); iv!=vertend; ++iv)
186  pOutput->push_back(*iv);
187  }
188 
189  iEvent.put(pOutput, outputLabel);
190 }
191 
192 
193 // ------------ method called once each job just before starting event loop
195 {
196  if (!rGauss_)
197  {
199  if ( !rng.isAvailable() )
200  throw cms::Exception("FFTJetBadConfig")
201  << "ERROR in FFTJetVertexAdder:"
202  " failed to initialize the random number generator"
203  << std::endl;
204  rGauss_ = new CLHEP::RandGauss(rng->getEngine());
205  }
206 }
207 
208 
209 // ------------ method called once each job just after ending the event loop
211 {
212 }
213 
214 
215 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
const std::string outputLabel
const bool addExistingVertices
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
#define init_param(type, varname)
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
const unsigned nVerticesToMake
const edm::InputTag beamSpotLabel
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
bool isAvailable() const
Definition: Service.h:46
int j
Definition: DBlmapReader.cc:9
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
const edm::InputTag existingVerticesLabel
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
void produce(edm::Event &, const edm::EventSetup &) override
void beginJob() override
FFTJetVertexAdder & operator=(const FFTJetVertexAdder &)
CLHEP::RandGauss * rGauss_
void endJob() override