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 
64 
67 
69 
70  const bool useBeamSpot;
71  const bool addExistingVertices;
72 
73  const double fixedX;
74  const double fixedY;
75  const double fixedZ;
76 
77  const double sigmaX;
78  const double sigmaY;
79  const double sigmaZ;
80 
81  const double nDof;
82  const double chi2;
83  const double errX;
84  const double errY;
85  const double errZ;
86 
87  const unsigned nVerticesToMake;
88 };
89 
90 //
91 // constructors and destructor
92 //
95  init_param(edm::InputTag, existingVerticesLabel),
96  init_param(std::string, outputLabel),
97  init_param(bool, useBeamSpot),
98  init_param(bool, addExistingVertices),
99  init_param(double, fixedX),
100  init_param(double, fixedY),
101  init_param(double, fixedZ),
102  init_param(double, sigmaX),
103  init_param(double, sigmaY),
104  init_param(double, sigmaZ),
105  init_param(double, nDof),
106  init_param(double, chi2),
107  init_param(double, errX),
108  init_param(double, errY),
109  init_param(double, errZ),
110  init_param(unsigned, nVerticesToMake)
111 {
112  if (useBeamSpot)
113  beamSpotToken = consumes<reco::BeamSpot>(beamSpotLabel);
115  existingVerticesToken = consumes<reco::VertexCollection>(existingVerticesLabel);
116  produces<reco::VertexCollection>(outputLabel);
117 }
118 
119 
121 {
122 }
123 
124 
125 // ------------ method called to produce the data ------------
127  edm::Event& iEvent, const edm::EventSetup& iSetup)
128 {
130  CLHEP::RandGauss rGauss(rng->getEngine(iEvent.streamID()));
131 
132  // get PFCandidates
133  std::auto_ptr<reco::VertexCollection> pOutput(new reco::VertexCollection);
134 
135  double xmean = fixedX;
136  double ymean = fixedY;
137  double zmean = fixedZ;
138 
139  double xwidth = sigmaX;
140  double ywidth = sigmaY;
141  double zwidth = sigmaZ;
142 
143  if (useBeamSpot)
144  {
145  edm::Handle<reco::BeamSpot> beamSpotHandle;
146  iEvent.getByToken(beamSpotToken, beamSpotHandle);
147  if (!beamSpotHandle.isValid())
148  throw cms::Exception("FFTJetBadConfig")
149  << "ERROR in FFTJetVertexAdder:"
150  " could not find beam spot information"
151  << std::endl;
152 
153  xmean = beamSpotHandle->x0();
154  ymean = beamSpotHandle->y0();
155  zmean = beamSpotHandle->z0();
156 
157  xwidth = beamSpotHandle->BeamWidthX();
158  ywidth = beamSpotHandle->BeamWidthY();
159  zwidth = beamSpotHandle->sigmaZ();
160  }
161 
163  for (unsigned i=0; i<3; ++i)
164  for (unsigned j=0; j<3; ++j)
165  err[i][j] = 0.0;
166  err[0][0] = errX*errX;
167  err[1][1] = errY*errY;
168  err[2][2] = errZ*errZ;
169 
170  for (unsigned iv=0; iv<nVerticesToMake; ++iv)
171  {
172  const double x0 = rGauss(xmean, xwidth);
173  const double y0 = rGauss(ymean, ywidth);
174  const double z0 = rGauss(zmean, zwidth);
175  const reco::Vertex::Point position(x0, y0, z0);
176  pOutput->push_back(reco::Vertex(position, err, chi2, nDof, 0));
177  }
178 
180  {
181  typedef reco::VertexCollection::const_iterator IV;
182 
184  iEvent.getByToken(existingVerticesToken, vertices);
185  if (!vertices.isValid())
186  throw cms::Exception("FFTJetBadConfig")
187  << "ERROR in FFTJetVertexAdder:"
188  " could not find existing collection of vertices"
189  << std::endl;
190 
191  const IV vertend(vertices->end());
192  for (IV iv=vertices->begin(); iv!=vertend; ++iv)
193  pOutput->push_back(*iv);
194  }
195 
196  iEvent.put(pOutput, outputLabel);
197 }
198 
199 
200 // ------------ method called once each job just before starting event loop
202 {
204  if ( !rng.isAvailable() ) {
205  throw cms::Exception("FFTJetBadConfig")
206  << "ERROR in FFTJetVertexAdder:"
207  " failed to initialize the random number generator"
208  << std::endl;
209  }
210 }
211 
212 
213 // ------------ method called once each job just after ending the event loop
215 {
216 }
217 
218 
219 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
const std::string outputLabel
const bool addExistingVertices
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#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)
edm::EDGetTokenT< reco::VertexCollection > existingVerticesToken
const unsigned nVerticesToMake
const edm::InputTag beamSpotLabel
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
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
bool isValid() const
Definition: HandleBase.h:75
void produce(edm::Event &, const edm::EventSetup &) override
void beginJob() override
FFTJetVertexAdder & operator=(const FFTJetVertexAdder &)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &) const =0
Use this engine in event methods.
static int position[264][3]
Definition: ReadPGInfo.cc:509
StreamID streamID() const
Definition: Event.h:79
void endJob() override
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken