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")
8  else if (operationModeString == "BeamSpotSigma")
10  else if (operationModeString == "VerticesFixed")
12  else if (operationModeString == "VerticesSigma")
14  else
15  throw cms::Exception("Configuration") << "Unknown operation mode string: " << operationModeString;
16 
18  m_maxNVertices = 1;
20  token_vertex = iC.consumes<reco::VertexCollection>(regPSet.getParameter<edm::InputTag>("vertexCollection"));
21  m_maxNVertices = regPSet.getParameter<int>("maxNVertices");
22  }
23 
24  // mode-dependent z-halflength of tracking regions
25  m_zErrorBeamSpot = regPSet.getParameter<double>("zErrorBeamSpot");
27  m_nSigmaZVertex = regPSet.getParameter<double>("nSigmaZVertex");
29  m_zErrorVertex = regPSet.getParameter<double>("zErrorVertex");
30  m_nSigmaZBeamSpot = -1.;
32  m_nSigmaZBeamSpot = regPSet.getParameter<double>("nSigmaZBeamSpot");
33  if (m_nSigmaZBeamSpot < 0.)
34  throw cms::Exception("Configuration") << "nSigmaZBeamSpot must be positive for BeamSpotSigma mode!";
35  }
36 }
37 
39  const std::string& defaultBeamSpot,
40  const std::string& defaultVertex,
41  int defaultMaxVertices) {
42  desc.add<std::string>("operationMode", "BeamSpotFixed");
43  desc.add<edm::InputTag>("beamSpot", defaultBeamSpot);
44  desc.add<edm::InputTag>("vertexCollection", defaultVertex);
45  desc.add<int>("maxNVertices", defaultMaxVertices);
46 
47  desc.add<double>("nSigmaZBeamSpot", 4.);
48  desc.add<double>("zErrorBeamSpot", 24.2);
49  desc.add<double>("nSigmaZVertex", 3.);
50  desc.add<double>("zErrorVertex", 0.2);
51 }
52 
54  Origins ret;
55 
56  // always need the beam spot (as a fall back strategy for vertex modes)
58  iEvent.getByToken(token_beamSpot, bs);
59  if (!bs.isValid())
60  return ret;
61 
62  // this is a default origin for all modes
63  GlobalPoint default_origin(bs->x0(), bs->y0(), bs->z0());
64 
65  // fill the origins and halfLengths depending on the mode
67  ret.emplace_back(
68  default_origin,
72  iEvent.getByToken(token_vertex, vertices);
73  int n_vert = 0;
74  for (const auto& v : *vertices) {
75  if (v.isFake() || !v.isValid())
76  continue;
77 
78  ret.emplace_back(
79  GlobalPoint(v.x(), v.y(), v.z()),
81  ++n_vert;
82  if (m_maxNVertices >= 0 && n_vert >= m_maxNVertices) {
83  break;
84  }
85  }
86  // no-vertex fall-back case:
87  if (ret.empty()) {
88  ret.emplace_back(default_origin, (m_nSigmaZBeamSpot > 0.) ? m_nSigmaZBeamSpot * bs->z0Error() : m_zErrorBeamSpot);
89  }
90  }
91 
92  return ret;
93 }
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:65
VertexBeamspotOrigins(const edm::ParameterSet &regPSet, edm::ConsumesCollector &&iC)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
ret
prodAgent to be discontinued
edm::EDGetTokenT< reco::BeamSpot > token_beamSpot
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
std::vector< std::pair< GlobalPoint, float > > Origins
int iEvent
Definition: GenABIO.cc:224
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:70
double z0Error() const
error on z
Definition: BeamSpot.h:90
edm::EDGetTokenT< reco::VertexCollection > token_vertex
double sigmaZ() const
sigma z
Definition: BeamSpot.h:76
double y0() const
y coordinate
Definition: BeamSpot.h:63
double x0() const
x coordinate
Definition: BeamSpot.h:61