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