CMS 3D CMS Logo

VertexBeamspotOrigins.cc
Go to the documentation of this file.
2 
4  // operation mode
5  std::string operationModeString = regPSet.getParameter<std::string>("operationMode");
6  if (operationModeString == "BeamSpotFixed") m_operationMode = OperationMode::BEAM_SPOT_FIXED;
7  else if (operationModeString == "BeamSpotSigma") m_operationMode = OperationMode::BEAM_SPOT_SIGMA;
8  else if (operationModeString == "VerticesFixed") m_operationMode = OperationMode::VERTICES_FIXED;
9  else if (operationModeString == "VerticesSigma") m_operationMode = OperationMode::VERTICES_SIGMA;
10  else throw cms::Exception("Configuration") <<"Unknown operation mode string: "<<operationModeString;
11 
13  m_maxNVertices = 1;
15  token_vertex = iC.consumes<reco::VertexCollection>(regPSet.getParameter<edm::InputTag>("vertexCollection"));
16  m_maxNVertices = regPSet.getParameter<int>("maxNVertices");
17  }
18 
19  // mode-dependent z-halflength of tracking regions
20  m_zErrorBeamSpot = regPSet.getParameter<double>("zErrorBeamSpot");
21  if (m_operationMode == OperationMode::VERTICES_SIGMA) m_nSigmaZVertex = regPSet.getParameter<double>("nSigmaZVertex");
22  if (m_operationMode == OperationMode::VERTICES_FIXED) m_zErrorVertex = regPSet.getParameter<double>("zErrorVertex");
23  m_nSigmaZBeamSpot = -1.;
25  m_nSigmaZBeamSpot = regPSet.getParameter<double>("nSigmaZBeamSpot");
26  if (m_nSigmaZBeamSpot < 0.)
27  throw cms::Exception("Configuration") << "nSigmaZBeamSpot must be positive for BeamSpotSigma mode!";
28  }
29 }
30 
32  const std::string& defaultVertex, int defaultMaxVertices) {
33  desc.add<std::string>("operationMode", "BeamSpotFixed");
34  desc.add<edm::InputTag>("beamSpot", defaultBeamSpot);
35  desc.add<edm::InputTag>("vertexCollection", defaultVertex);
36  desc.add<int>("maxNVertices", defaultMaxVertices);
37 
38  desc.add<double>("nSigmaZBeamSpot", 4.);
39  desc.add<double>("zErrorBeamSpot", 24.2);
40  desc.add<double>("nSigmaZVertex", 3.);
41  desc.add<double>("zErrorVertex", 0.2);
42 }
43 
45  Origins ret;
46 
47  // always need the beam spot (as a fall back strategy for vertex modes)
49  iEvent.getByToken( token_beamSpot, bs );
50  if( !bs.isValid() ) return ret;
51 
52  // this is a default origin for all modes
53  GlobalPoint default_origin( bs->x0(), bs->y0(), bs->z0() );
54 
55  // fill the origins and halfLengths depending on the mode
57  ret.emplace_back(default_origin,
61  iEvent.getByToken( token_vertex, vertices );
62  int n_vert = 0;
63  for(const auto& v: *vertices) {
64  if(v.isFake() || !v.isValid()) continue;
65 
66  ret.emplace_back( GlobalPoint( v.x(), v.y(), v.z() ),
68  ++n_vert;
69  if(m_maxNVertices >= 0 && n_vert >= m_maxNVertices) {
70  break;
71  }
72  }
73  // no-vertex fall-back case:
74  if(ret.empty()) {
75  ret.emplace_back( default_origin,
77  }
78  }
79 
80  return ret;
81 }
Origins origins(const edm::Event &iEvent) const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
double z0() const
z coordinate
Definition: BeamSpot.h:68
VertexBeamspotOrigins(const edm::ParameterSet &regPSet, edm::ConsumesCollector &&iC)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::EDGetTokenT< reco::BeamSpot > token_beamSpot
std::vector< std::pair< GlobalPoint, float > > Origins
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
static void fillDescriptions(edm::ParameterSetDescription &desc, const std::string &defaultBeamSpot="offlineBeamSpot", const std::string &defaultVertex="firstStepPrimaryVertices", int defaultMaxVertices=-1)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
int iEvent
Definition: GenABIO.cc:224
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
double z0Error() const
error on z
Definition: BeamSpot.h:94
edm::EDGetTokenT< reco::VertexCollection > token_vertex
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
double y0() const
y coordinate
Definition: BeamSpot.h:66
double x0() const
x coordinate
Definition: BeamSpot.h:64