CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
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 }
value_t mean_scale
Function object for searching for a parameter in the VPSet.
const edm::EventSetup & c
const TString p2
Definition: fwPaths.cc:13
double sign(double x)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T y() const
Definition: PV3DBase.h:60
value_t sigma_scale
coord_t transform(const coord_t &x, const value_t &a0, const value_t &a1, const value_t &a2, const value_t &a3)
U second(std::pair< T, U > const &p)
std::string doDice(const fidpoint_t &fidpointvec, const idPair_t &id, const bool rotate=false)
std::pair< id_t, id_t > idPair_t
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
value_t ranGauss(value_t mean, value_t sigma)
const TString p1
Definition: fwPaths.cc:12
uint16_t const *__restrict__ x
Definition: gpuClustering.h:39
static constexpr float a0
std::vector< coord_t > fidpoint_t
SurveyPxbImage::coord_t coord_t
def rotate
Definition: svgfig.py:705
value_t getParByName(const std::string &name, const std::string &par, const std::vector< edm::ParameterSet > &pars)
T x() const
Definition: PV3DBase.h:59