CMS 3D CMS Logo

SurveyPxbDicer.cc
Go to the documentation of this file.
3 
4 //#include <stdexcept>
5 #include <vector>
6 #include <cmath>
7 #include <string>
8 #include <sstream>
9 #include <functional>
10 #include <algorithm>
11 #include <fstream>
13 #include "Math/SMatrix.h"
14 #include "Math/SVector.h"
15 #include "CLHEP/Random/RandGauss.h"
16 #include "CLHEP/Random/Random.h"
18 
19 #include <iostream>
20 
21 SurveyPxbDicer::SurveyPxbDicer(const std::vector<edm::ParameterSet> &pars, unsigned int seed) {
22  CLHEP::HepRandom::setTheSeed(seed);
23  mean_a0 = getParByName("a0", "mean", pars);
24  sigma_a0 = getParByName("a0", "sigma", pars);
25  mean_a1 = getParByName("a1", "mean", pars);
26  sigma_a1 = getParByName("a1", "sigma", pars);
27  mean_scale = getParByName("scale", "mean", pars);
28  sigma_scale = getParByName("scale", "sigma", pars);
29  mean_phi = getParByName("phi", "mean", pars);
30  sigma_phi = getParByName("phi", "sigma", pars);
31  mean_x = getParByName("x", "mean", pars);
32  sigma_x = getParByName("x", "sigma", pars);
33  mean_y = getParByName("y", "mean", pars);
34  sigma_y = getParByName("y", "sigma", pars);
35 }
36 
37 std::string SurveyPxbDicer::doDice(const fidpoint_t &fidpointvec, const idPair_t &id, const bool rotate) {
38  // Dice the local parameters
40  const value_t a1 = ranGauss(mean_a1, sigma_a1);
43  const value_t a2 = scale * cos(phi);
44  const value_t a3 = scale * sin(phi);
45  const coord_t p0 = transform(fidpointvec[0], a0, a1, a2, a3);
46  const coord_t p1 = transform(fidpointvec[1], a0, a1, a2, a3);
47  const coord_t p2 = transform(fidpointvec[2], a0, a1, a2, a3);
48  const coord_t p3 = transform(fidpointvec[3], a0, a1, a2, a3);
49  const value_t sign = rotate ? -1 : 1;
50  std::ostringstream oss;
51  oss << id.first << " " << sign * ranGauss(p0.x(), sigma_x) << " " << -sign * ranGauss(p0.y(), sigma_y) << " "
52  << sign * ranGauss(p1.x(), sigma_x) << " " << -sign * ranGauss(p1.y(), sigma_y) << " " << id.second << " "
53  << sign * ranGauss(p2.x(), sigma_x) << " " << -sign * ranGauss(p2.y(), sigma_y) << " "
54  << sign * ranGauss(p3.x(), sigma_x) << " " << -sign * ranGauss(p3.y(), sigma_y) << " " << sigma_x << " "
55  << sigma_y << " " << rotate << " # MC-truth:"
56  << " a0-a3: " << a0 << " " << a1 << " " << a2 << " " << a3 << " S: " << scale << " phi: " << phi
57  << " x0: " << fidpointvec[0].x() << " " << fidpointvec[0].y() << " x1: " << fidpointvec[1].x() << " "
58  << fidpointvec[1].y() << " x2: " << fidpointvec[2].x() << " " << fidpointvec[2].y()
59  << " x3: " << fidpointvec[3].x() << " " << fidpointvec[3].y() << std::endl;
60  return oss.str();
61 }
62 
63 void SurveyPxbDicer::doDice(const fidpoint_t &fidpointvec,
64  const idPair_t &id,
65  std::ofstream &outfile,
66  const bool rotate) {
67  outfile << doDice(fidpointvec, id, rotate);
68 }
69 
71  const coord_t &x, const value_t &a0, const value_t &a1, const value_t &a2, const value_t &a3) {
72  return coord_t(a0 + a2 * x.x() + a3 * x.y(), a1 - a3 * x.x() + a2 * x.y());
73 }
74 
76  const std::string &par,
77  const std::vector<edm::ParameterSet> &pars) {
78  std::vector<edm::ParameterSet>::const_iterator it;
79  it = std::find_if(pars.begin(), pars.end(), [&name](auto const &c) { return findParByName()(name, c); });
80  if (it == pars.end()) {
81  throw std::runtime_error("Parameter not found in SurveyPxbDicer::getParByName");
82  }
83  return (*it).getParameter<value_t>(par);
84 }
SurveyPxbDicer::mean_a0
value_t mean_a0
Definition: SurveyPxbDicer.h:45
SurveyPxbDicer::mean_x
value_t mean_x
Definition: SurveyPxbDicer.h:51
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
SurveyPxbImage.h
SurveyPxbDicer::sigma_phi
value_t sigma_phi
Definition: SurveyPxbDicer.h:50
Validation_hcalonly_cfi.sign
sign
Definition: Validation_hcalonly_cfi.py:32
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
SurveyPxbDicer::SurveyPxbDicer
SurveyPxbDicer()
Definition: SurveyPxbDicer.h:31
Point3DBase.h
DDAxes::x
SurveyPxbDicer::fidpoint_t
std::vector< coord_t > fidpoint_t
Definition: SurveyPxbDicer.h:25
SurveyPxbDicer::transform
coord_t transform(const coord_t &x, const value_t &a0, const value_t &a1, const value_t &a2, const value_t &a3)
Definition: SurveyPxbDicer.cc:70
SurveyPxbDicer::idPair_t
std::pair< id_t, id_t > idPair_t
Definition: SurveyPxbDicer.h:28
svgfig.rotate
def rotate(angle, cx=0, cy=0)
Definition: svgfig.py:705
SurveyPxbDicer::doDice
std::string doDice(const fidpoint_t &fidpointvec, const idPair_t &id, const bool rotate=false)
Definition: SurveyPxbDicer.cc:37
testProducerWithPsetDescEmpty_cfi.a2
a2
Definition: testProducerWithPsetDescEmpty_cfi.py:35
SurveyPxbDicer::mean_a1
value_t mean_a1
Definition: SurveyPxbDicer.h:48
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
SurveyPxbDicer::sigma_y
value_t sigma_y
Definition: SurveyPxbDicer.h:52
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
vertices_cff.x
x
Definition: vertices_cff.py:29
p2
double p2[4]
Definition: TauolaWrapper.h:90
SurveyPxbDicer::sigma_x
value_t sigma_x
Definition: SurveyPxbDicer.h:51
SurveyPxbDicer::mean_scale
value_t mean_scale
Definition: SurveyPxbDicer.h:49
Point3DBase
Definition: Point3DBase.h:10
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SurveyPxbDicer::coord_t
SurveyPxbImage::coord_t coord_t
Definition: SurveyPxbDicer.h:23
SurveyPxbDicer::sigma_a1
value_t sigma_a1
Definition: SurveyPxbDicer.h:48
Scenarios_cff.scale
scale
Definition: Scenarios_cff.py:2186
SurveyPxbDicer::ranGauss
value_t ranGauss(value_t mean, value_t sigma)
Definition: SurveyPxbDicer.h:45
SurveyPxbDicer::mean_phi
value_t mean_phi
Definition: SurveyPxbDicer.h:50
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
p1
double p1[4]
Definition: TauolaWrapper.h:89
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
DDAxes::phi
SurveyPxbDicer.h
SurveyPxbDicer::findParByName
Function object for searching for a parameter in the VPSet.
Definition: SurveyPxbDicer.h:69
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
p3
double p3[4]
Definition: TauolaWrapper.h:91
timingPdfMaker.outfile
outfile
Definition: timingPdfMaker.py:351
ParameterSet.h
SurveyPxbDicer::sigma_a0
value_t sigma_a0
Definition: SurveyPxbDicer.h:45
SurveyPxbDicer::sigma_scale
value_t sigma_scale
Definition: SurveyPxbDicer.h:49
a0
static constexpr float a0
Definition: L1EGammaCrystalsEmulatorProducer.cc:81
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
SurveyPxbDicer::mean_y
value_t mean_y
Definition: SurveyPxbDicer.h:52
SurveyPxbDicer::getParByName
value_t getParByName(const std::string &name, const std::string &par, const std::vector< edm::ParameterSet > &pars)
Definition: SurveyPxbDicer.cc:75
SurveyPxbDicer::value_t
double value_t
Definition: SurveyPxbDicer.h:24