CMS 3D CMS Logo

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 public:
47  explicit FFTJetVertexAdder(const edm::ParameterSet&);
48  FFTJetVertexAdder() = delete;
49  FFTJetVertexAdder(const FFTJetVertexAdder&) = delete;
51  ~FFTJetVertexAdder() override;
52 
53 protected:
54  // methods
55  void beginStream(edm::StreamID) override;
56  void produce(edm::Event&, const edm::EventSetup&) override;
57 
58 private:
61 
64 
66 
67  const bool useBeamSpot;
68  const bool addExistingVertices;
69 
70  const double fixedX;
71  const double fixedY;
72  const double fixedZ;
73 
74  const double sigmaX;
75  const double sigmaY;
76  const double sigmaZ;
77 
78  const double nDof;
79  const double chi2;
80  const double errX;
81  const double errY;
82  const double errZ;
83 
84  const unsigned nVerticesToMake;
85 };
86 
87 //
88 // constructors and destructor
89 //
96  init_param(double, fixedX),
97  init_param(double, fixedY),
98  init_param(double, fixedZ),
99  init_param(double, sigmaX),
100  init_param(double, sigmaY),
101  init_param(double, sigmaZ),
102  init_param(double, nDof),
103  init_param(double, chi2),
104  init_param(double, errX),
105  init_param(double, errY),
106  init_param(double, errZ),
107  init_param(unsigned, nVerticesToMake) {
108  if (useBeamSpot)
109  beamSpotToken = consumes<reco::BeamSpot>(beamSpotLabel);
111  existingVerticesToken = consumes<reco::VertexCollection>(existingVerticesLabel);
112  produces<reco::VertexCollection>(outputLabel);
113 }
114 
116 
117 // ------------ method called to produce the data ------------
120  CLHEP::RandGauss rGauss(rng->getEngine(iEvent.streamID()));
121 
122  // get PFCandidates
123  auto pOutput = std::make_unique<reco::VertexCollection>();
124 
125  double xmean = fixedX;
126  double ymean = fixedY;
127  double zmean = fixedZ;
128 
129  double xwidth = sigmaX;
130  double ywidth = sigmaY;
131  double zwidth = sigmaZ;
132 
133  if (useBeamSpot) {
134  edm::Handle<reco::BeamSpot> beamSpotHandle;
135  iEvent.getByToken(beamSpotToken, beamSpotHandle);
136  if (!beamSpotHandle.isValid())
137  throw cms::Exception("FFTJetBadConfig") << "ERROR in FFTJetVertexAdder:"
138  " could not find beam spot information"
139  << std::endl;
140 
141  xmean = beamSpotHandle->x0();
142  ymean = beamSpotHandle->y0();
143  zmean = beamSpotHandle->z0();
144 
145  xwidth = beamSpotHandle->BeamWidthX();
146  ywidth = beamSpotHandle->BeamWidthY();
147  zwidth = beamSpotHandle->sigmaZ();
148  }
149 
151  for (unsigned i = 0; i < 3; ++i)
152  for (unsigned j = 0; j < 3; ++j)
153  err[i][j] = 0.0;
154  err[0][0] = errX * errX;
155  err[1][1] = errY * errY;
156  err[2][2] = errZ * errZ;
157 
158  for (unsigned iv = 0; iv < nVerticesToMake; ++iv) {
159  const double x0 = rGauss(xmean, xwidth);
160  const double y0 = rGauss(ymean, ywidth);
161  const double z0 = rGauss(zmean, zwidth);
162  const reco::Vertex::Point position(x0, y0, z0);
163  pOutput->push_back(reco::Vertex(position, err, chi2, nDof, 0));
164  }
165 
166  if (addExistingVertices) {
167  typedef reco::VertexCollection::const_iterator IV;
168 
171  if (!vertices.isValid())
172  throw cms::Exception("FFTJetBadConfig") << "ERROR in FFTJetVertexAdder:"
173  " could not find existing collection of vertices"
174  << std::endl;
175 
176  const IV vertend(vertices->end());
177  for (IV iv = vertices->begin(); iv != vertend; ++iv)
178  pOutput->push_back(*iv);
179  }
180 
181  iEvent.put(std::move(pOutput), outputLabel);
182 }
183 
184 // ------------ method called once each job just before starting event loop
187  if (!rng.isAvailable()) {
188  throw cms::Exception("FFTJetBadConfig") << "ERROR in FFTJetVertexAdder:"
189  " failed to initialize the random number generator"
190  << std::endl;
191  }
192 }
193 
194 //define this as a plug-in
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:82
const std::string outputLabel
int32_t *__restrict__ iv
const bool addExistingVertices
void beginStream(edm::StreamID) override
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
#define init_param(type, varname)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
edm::EDGetTokenT< reco::VertexCollection > existingVerticesToken
const unsigned nVerticesToMake
const edm::InputTag beamSpotLabel
double x0() const
x coordinate
Definition: BeamSpot.h:61
int iEvent
Definition: GenABIO.cc:224
FFTJetVertexAdder & operator=(const FFTJetVertexAdder &)=delete
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:84
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::InputTag existingVerticesLabel
double y0() const
y coordinate
Definition: BeamSpot.h:63
~FFTJetVertexAdder() override
void produce(edm::Event &, const edm::EventSetup &) override
double sigmaZ() const
sigma z
Definition: BeamSpot.h:76
bool isValid() const
Definition: HandleBase.h:70
double z0() const
z coordinate
Definition: BeamSpot.h:65
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:289
bool isAvailable() const
Definition: Service.h:40
FFTJetVertexAdder()=delete
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken
def move(src, dest)
Definition: eostools.py:511