void dtkMatrixTestCase::testViews(void)
{
    dtkUnderscore _;
    dtkDenseMatrix<double> m0(4,4);
    m0.fill(1);
    dtkDenseMatrix<double>::View m0_view=m0(_(1,2), _(2,3));
    m0_view.fill(42);

    for(qlonglong j=1; j<5; j++)
    {
        for(qlonglong i=1; i<5; i++)
        {
            if((i==1 || i==2) && (j==2 || j==3))
                QVERIFY(m0(i,j)==42);
            else
                QVERIFY(m0(i,j)==1);
        }
    }

    //test stride
    dtkDenseMatrix<double> m1(3,3);
    dtkDenseMatrix<double>::View m1_view=m1(_, _(1,2,3));

    m1.fill(1);
    m1_view.fill(42);

    for(qlonglong j=1; j<4; j++)
    {
        for(qlonglong i=1; i<4; i++)
        {
            if(j==1 || j==3)
                QVERIFY(m1(i,j)==42);
            else
                QVERIFY(m1(i,j)==1);
        }
    }

    dtkDenseMatrix<double> m2(11,11);
    dtkDenseMatrix<double>::View m2_view=m2(_(2,3), _(3,2,7));

    m2.fill(1);
    m2_view.fill(42);

    for(qlonglong j=1; j<12; j++)
    {
        for(qlonglong i=1; i<12; i++)
        {
            if((j==3 || j==5 || j==7) && ((i==2)||(i==3)))
                QVERIFY(m2(i,j)==42);
            else
                QVERIFY(m2(i,j)==1);
        }
    }
    //test column


}
Beispiel #2
0
void CVMath::setupMatrixM2()
{
	Line r1 = Points::getInstance().getR1();
	Line r2 = Points::getInstance().getR2();
	Line r3 = Points::getInstance().getR3();
	Line r4 = Points::getInstance().getR4();
	
	l0 << r1.x, r1.y, r1.z;
	m0 << r2.x, r2.y, r2.z;
	l1 << r3.x, r3.y, r3.z;
	m1 << r4.x, r4.y, r4.z;

	MatrixXd LT_M = MatrixXd(2, 3);
	LT_M << l0(0)*m0(0), l0(0)*m0(1) + l0(1)*m0(0), l0(1)*m0(1),
			l1(0)*m1(0), l1(0)*m1(1) + l1(1)*m1(0), l1(1)*m1(1);


	JacobiSVD<MatrixXd> svdA (LT_M, Eigen::ComputeFullV);

	VectorXd x = svdA.matrixV().col(2);

	MatrixXd KKT = MatrixXd(2, 2);
	KKT << x(0), x(1),
		x(1), x(2);

	MatrixXd HHT = MatrixXd(3, 3);
	HHT << x(0), x(1), 0,
		   x(1), x(2), 0,
		   0, 0, 0;

	MatrixXd aux = MatrixXd(2, 2); 
	aux = HHT.llt().matrixU();

	std::cout << x << std::endl;
	std::cout << aux << std::endl;
	
	Hp = MatrixXd(3, 3);
	
	//add 1 ao final para se tornar inversivel
	Hp << aux(0,0), aux(0,1), 0,
		0, aux(1, 1), 0,
		0, 0, 1;
	std::cout << Hp << std::endl;

	Hp_INV = MatrixXd(3, 3);
	Hp_INV = Hp.inverse().eval();
	std::cout << Hp_INV << std::endl;

}
Beispiel #3
0
/// Initialize Particle Gun parameters
StatusCode ConstPtParticleGun::initialize() {
  StatusCode sc = GaudiTool::initialize();
  if (!sc.isSuccess()) return sc;

  IRndmGenSvc* randSvc = svc<IRndmGenSvc>("RndmGenSvc", true);
  sc = m_flatGenerator.initialize(randSvc, Rndm::Flat(0., 1.));
  if (!sc.isSuccess()) return Error("Cannot initialize flat generator");

  // check momentum and angles
  if ((m_minEta > m_maxEta) || (m_minPhi > m_maxPhi)) return Error("Incorrect values for eta or phi!");

  m_deltaPhi = m_maxPhi - m_minPhi;
  m_deltaEta = m_maxEta - m_minEta;

  // setup particle information
  m_masses.clear();
  auto pd = Pythia8::ParticleData();

  info() << "Particle type chosen randomly from :";
  PIDs::iterator icode;
  for (icode = m_pdgCodes.begin(); icode != m_pdgCodes.end(); ++icode) {
    info() << " " << *icode;
    m_masses.push_back(pd.m0(*icode));
  }

  info() << endmsg;

  info() << "Eta range: " << m_minEta << "  <-> " << m_maxEta << endmsg;
  info() << "Phi range: " << m_minPhi / Gaudi::Units::rad << " rad <-> " << m_maxPhi / Gaudi::Units::rad << " rad"
         << endmsg;

  return sc;
}
Beispiel #4
0
int sc_main(int argc, char* argv[])
{
    sc_signal<bool> t_a0;
    sc_signal<bool> t_a1;
    sc_signal<bool> t_a2;
    sc_signal<bool> t_a3;
    sc_signal<bool> t_b0;
    sc_signal<bool> t_b1;
    sc_signal<bool> t_b2;
    sc_signal<bool> t_b3;
    sc_signal<bool> t_c0;
    sc_signal<bool> t_s0;
    sc_signal<bool> t_s1;
    sc_signal<bool> t_s2;
    sc_signal<bool> t_s3;
    sc_signal<bool> t_c4;
    ripple_adder r0("r0");
    r0.a0(t_a0);
    r0.a1(t_a1);
    r0.a2(t_a2);
    r0.a3(t_a3);
    r0.b0(t_b0);
    r0.b1(t_b1);
    r0.b2(t_b2);
    r0.b3(t_b3);
    r0.c0(t_c0);
    r0.s0(t_s0);
    r0.s1(t_s1);
    r0.s2(t_s2);
    r0.s3(t_s3);
    r0.c4(t_c4);
    ripple_adder_driver d0("d0");
    d0.d_a0(t_a0);
    d0.d_a1(t_a1);
    d0.d_a2(t_a2);
    d0.d_a3(t_a3);
    d0.d_b0(t_b0);
    d0.d_b1(t_b1);
    d0.d_b2(t_b2);
    d0.d_b3(t_b3);
    d0.d_c0(t_c0);
    ripple_adder_monitor m0("m0");
    m0.m_a0(t_a0);
    m0.m_a1(t_a1);
    m0.m_a2(t_a2);
    m0.m_a3(t_a3);
    m0.m_b0(t_b0);
    m0.m_b1(t_b1);
    m0.m_b2(t_b2);
    m0.m_b3(t_b3);
    m0.m_c0(t_c0);
    m0.m_s0(t_s0);
    m0.m_s1(t_s1);
    m0.m_s2(t_s2);
    m0.m_s3(t_s3);
    m0.m_c4(t_c4);
    // simulate for max 1000 ns
    sc_start(1, SC_SEC);
    return 0;
}
Beispiel #5
0
Foam::tmp<Foam::volScalarField>
Foam::kineticTheoryModels::granularPressureModels::Chao::
granularPressureCoeffPrime
(
    const phaseModel& phase1,
    const phaseModel& phase2,
    const volScalarField& Theta1,
    const volScalarField& Theta2,
    const volScalarField& g0,
    const volScalarField& g0prime,
    const dimensionedScalar& e
) const
{
    volScalarField m0
    (
        constant::mathematical::pi/6.0
       *(phase1.rho()*pow3(phase1.d()) + phase2.rho()*pow3(phase2.d()))
    );
    tmp<volScalarField> pCoeff
    (
        2.0*phase2*constant::mathematical::pi/(3.0*m0)*phase1.rho()
       *phase2.rho()*(1.0 + e)*pow3((phase1.d() + phase2.d())/2.0)
       *(Theta1 + Theta2 + 0.2*magSqr(phase1.U() - phase2.U()))
    );

    if (&phase1 == &phase2)
    {
        return pCoeff*(2.0*g0 + phase1*g0prime);

    }
    else
    {
        return pCoeff*(g0 + phase1*g0prime);
    }
}
Beispiel #6
0
BOOST_FIXTURE_TEST_CASE( math2d__transformations, Some2dPoints )
{
    move2 m0(r0,p0);
    move2 m1(r1,p1);
    BOOMST_CHECK_APPROX_EQUAL( p2 + p1, leftOrthogonal(p2) >> m1 );
    BOOMST_CHECK_APPROX_EQUAL( m0, inverse(inverse(m0)) );
    BOOMST_CHECK_APPROX_EQUAL( move2_id, compose(inverse(m0),m0) );
    BOOMST_CHECK_APPROX_EQUAL( p1, p1 >> m0 >> inverse(m0) );
    BOOMST_CHECK_APPROX_EQUAL( p0, zero2 >> m0 );
    BOOMST_CHECK_APPROX_EQUAL( p3, move2_id.map(p3) );
}
Beispiel #7
0
int main(){
	double a, b, m, n;	// スーパー楕円のパラメータ
	int N;				// 選択する点の数

	cin >> a >> b >> m >> n >> N;

	Simple_window win(Point(100, 100), 640, 480, "q12_13");

	const int sx = win.x_max() / 2;	// 原点
	const int sy = win.y_max() / 2;
	const int scale = 100;			// スケール
	int x, y;						// 座標
	double angle = 0;				// 角度(θ)

	Mark m0(Point(sx, sy), 'X');	// 中心点
	vector<Point> vp;

	vector<Color> vc;
	vc.push_back(Color::black);
	vc.push_back(Color::red);
	vc.push_back(Color::yellow);
	vc.push_back(Color::green);
	vc.push_back(Color::cyan);
	vc.push_back(Color::blue);
	vc.push_back(Color::magenta);
	vc.push_back(Color::white);

	Lines l[10000];					// ライン数の上限

	m = 1 / (m / 2);				// 2乗になるようにし、逆数をとる
	n = 1 / (n / 2);

	for(int i = 0; i < N; ++i){
		int rs = sin(angle) < 0 ? -1 : 1;	// sinの符号をとる
		int rc = cos(angle) < 0 ? -1 : 1;	// cosの符号をとる
		x = sx + a * scale * pow(abs(sin(angle)), m) * rs;	// 絶対値を累乗し、後で符号をかける
		y = sy - b * scale * pow(abs(cos(angle)), n) * rc;

		vp.push_back(Point(x, y));
		angle += 2 * M_PI / N;	// N角形の内角
	}

	for(int i = 0; i < vp.size(); ++i){
		for(int j = i + 1; j < vp.size(); ++j){
			l[i * j].add(vp[i], vp[j]);
			l[i * j].set_style(Line_style(Line_style::solid, 2));
			l[i * j].set_color(vc[(i * j) % 8]);
			win.attach(l[i * j]);
		}
	}

	win.attach(m0);
	win.wait_for_button();
}
   void testGetAcceptField()
      {
         UtlString v;

         HttpMessage m0(
            "SUBSCRIBE sip:[email protected] SIP/2.0\r\n"
            "From: <sip:[email protected]>;tag=1c1198308561\r\n"
            "To: <sip:[email protected];user=phone>\r\n"
            "Call-Id: [email protected]\r\n"
            "Cseq: 1 INVITE\r\n"
            "Via: SIP/2.0/UDP 10.139.4.84;branch=z9hG4bK-de2c934952294f774ee0acbc133e9b1d\r\n"
            "Via: SIP/2.0/UDP 10.139.33.244;branch=z9hG4bKac1198312375\r\n"
            "Content-Length: 0\r\n"
            "\r\n"
                                 );

         CPPUNIT_ASSERT(!m0.getAcceptField(v));

         HttpMessage m1(
            "SUBSCRIBE sip:[email protected] SIP/2.0\r\n"
            "From: <sip:[email protected]>;tag=1c1198308561\r\n"
            "To: <sip:[email protected];user=phone>\r\n"
            "Call-Id: [email protected]\r\n"
            "Cseq: 1 INVITE\r\n"
            "Via: SIP/2.0/UDP 10.139.4.84;branch=z9hG4bK-de2c934952294f774ee0acbc133e9b1d\r\n"
            "Via: SIP/2.0/UDP 10.139.33.244;branch=z9hG4bKac1198312375\r\n"
            "Accept: foo, bar\r\n"
            "Content-Length: 0\r\n"
            "\r\n"
                                 );

         CPPUNIT_ASSERT(m1.getAcceptField(v));
         ASSERT_STR_EQUAL("foo, bar", v.data());

         HttpMessage m2(
            "SUBSCRIBE sip:[email protected] SIP/2.0\r\n"
            "From: <sip:[email protected]>;tag=1c1198308561\r\n"
            "To: <sip:[email protected];user=phone>\r\n"
            "Call-Id: [email protected].244\r\n"
            "Cseq: 1 INVITE\r\n"
            "Via: SIP/2.0/UDP 10.139.4.84;branch=z9hG4bK-de2c934952294f774ee0acbc133e9b1d\r\n"
            "Via: SIP/2.0/UDP 10.139.33.244;branch=z9hG4bKac1198312375\r\n"
            "Accept: foo, bar\r\n"
            "Accept: baz\r\n"
            "Content-Length: 0\r\n"
            "\r\n"
                                 );

         CPPUNIT_ASSERT(m2.getAcceptField(v));
         ASSERT_STR_EQUAL("foo, bar,baz", v.data());
      }
Beispiel #9
0
int test_ctr()
{
	int Error(0);

#if(GLM_HAS_INITIALIZER_LISTS)
	glm::mat4x2 m0(
		glm::vec2(0, 1), 
		glm::vec2(2, 3),
		glm::vec2(4, 5),
		glm::vec2(6, 7));

	glm::mat4x2 m1{0, 1, 2, 3, 4, 5, 6, 7};

	glm::mat4x2 m2{
		{0, 1},
		{2, 3},
		{4, 5},
		{6, 7}};

	for(glm::length_t i = 0; i < m0.length(); ++i)
		Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;

	for(glm::length_t i = 0; i < m1.length(); ++i)
		Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;

	std::vector<glm::mat4x2> v1{
		{0, 1, 2, 3, 4, 5, 6, 7},
		{0, 1, 2, 3, 4, 5, 6, 7}
	};

	std::vector<glm::mat4x2> v2{
		{
			{ 0, 1},
			{ 4, 5},
			{ 8, 9},
			{ 12, 13}
		},
		{
			{ 0, 1},
			{ 4, 5},
			{ 8, 9},
			{ 12, 13}
		}
	};

#endif//GLM_HAS_INITIALIZER_LISTS

	return Error;
}
Beispiel #10
0
int test_ctr()
{
	int Error(0);

#if(GLM_HAS_INITIALIZER_LISTS)
	glm::mat4x3 m0(
		glm::vec3(0, 1, 2), 
		glm::vec3(3, 4, 5),
		glm::vec3(6, 7, 8),
		glm::vec3(9, 10, 11));

	glm::mat4x3 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

	glm::mat4x3 m2{
		{0, 1, 2},
		{3, 4, 5},
		{6, 7, 8},
		{9, 10, 11}};

	for(glm::length_t i = 0; i < m0.length(); ++i)
		Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;

	for(glm::length_t i = 0; i < m1.length(); ++i)
		Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;

	std::vector<glm::mat4x3> v1{
		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
	};

	std::vector<glm::mat4x3> v2{
		{
			{ 0, 1, 2 },
			{ 4, 5, 6 },
			{ 8, 9, 10 },
			{ 12, 13, 14 }
		},
		{
			{ 0, 1, 2 },
			{ 4, 5, 6 },
			{ 8, 9, 10 },
			{ 12, 13, 14 }
		}
	};

#endif//GLM_HAS_INITIALIZER_LISTS

	return Error;
}
Beispiel #11
0
void memoryleak()
{
  typedef Eigen::Matrix<ScalarWithExceptions,Dynamic,1> VectorType;
  typedef Eigen::Matrix<ScalarWithExceptions,Dynamic,Dynamic> MatrixType;
  
  {
    int n = 50;
    VectorType v0(n), v1(n);
    MatrixType m0(n,n), m1(n,n), m2(n,n);
    v0.setOnes(); v1.setOnes();
    m0.setOnes(); m1.setOnes(); m2.setOnes();
    CHECK_MEMLEAK(v0 = m0 * m1 * v1);
    CHECK_MEMLEAK(m2 = m0 * m1 * m2);
    CHECK_MEMLEAK((v0+v1).dot(v0+v1));
  }
  VERIFY(ScalarWithExceptions::instances==0 && "global memory leak detected in " && EIGEN_MAKESTRING(OP)); \
}
Beispiel #12
0
int test_ctr()
{
    int Error(0);

#if(GLM_HAS_INITIALIZER_LISTS)
    glm::mat3x4 m0(
        glm::vec4(0, 1, 2, 3),
        glm::vec4(4, 5, 6, 7),
        glm::vec4(8, 9, 10, 11));

    glm::mat3x4 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

    glm::mat3x4 m2{
        {0, 1, 2, 3},
        {4, 5, 6, 7},
        {8, 9, 10, 11}};

    for(glm::length_t i = 0; i < m0.length(); ++i)
        Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;

    for(glm::length_t i = 0; i < m1.length(); ++i)
        Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;

    std::vector<glm::mat3x4> v1{
        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
    };

    std::vector<glm::mat3x4> v2{
        {
            { 0, 1, 2, 3},
            { 4, 5, 6, 7},
            { 8, 9, 10, 11}
        },
        {
            { 0, 1, 2, 3},
            { 4, 5, 6, 7},
            { 8, 9, 10, 11}
        }
    };

#endif//GLM_HAS_INITIALIZER_LISTS

    return Error;
}
Beispiel #13
0
// anisotropic version of the background field
SMetric3 BGM_MeshMetric(GEntity *ge,
                        double U, double V,
                        double X, double Y, double Z)
{

  // Metrics based on element size

  // Element size = min. between default lc and lc from point (if applicable),
  // constrained by lcMin and lcMax
  double lc = CTX::instance()->lc;
  if(CTX::instance()->mesh.lcFromPoints && ge->dim() < 2)
    lc = std::min(lc, LC_MVertex_PNTS(ge, U, V));
  lc = std::min(lc, ge->getMeshSize());
  lc = std::max(lc, CTX::instance()->mesh.lcMin);
  lc = std::min(lc, CTX::instance()->mesh.lcMax);
  if(lc <= 0.){
    Msg::Error("Wrong mesh element size lc = %g (lcmin = %g, lcmax = %g)",
               lc, CTX::instance()->mesh.lcMin, CTX::instance()->mesh.lcMax);
    lc = CTX::instance()->lc;
  }
  SMetric3 m0(1./(lc*lc));

  // Intersect with metrics from fields if applicable
  FieldManager *fields = ge->model()->getFields();
  SMetric3 m1 = m0;
  if(fields->getBackgroundField() > 0){
    Field *f = fields->get(fields->getBackgroundField());
    if(f) {
      SMetric3 l4;
      if (!f->isotropic()) (*f)(X, Y, Z, l4, ge);
      else {
        const double L = (*f)(X, Y, Z, ge);
        l4 = SMetric3(1/(L*L));
      }
      m1 = intersection(l4, m0);
    }
  }

  // Intersect with metrics from curvature if applicable
  SMetric3 m = (CTX::instance()->mesh.lcFromCurvature && ge->dim() < 3) ?
      intersection(m1, LC_MVertex_CURV_ANISO(ge, U, V)) : m1;

  return m;
}
Beispiel #14
0
/*-------------------------------------------------------------------------*/
void AzPrepText2::gen_X_seq(const AzIntArr &ia_tokno, int dic_sz, 
                       int pch_sz, int pch_step, int padding,  
                       bool do_allow_zero, bool do_skip_stopunk, 
                       /*---  output  ---*/
                       AzSmat *m_feat, 
                       AzIntArr *ia_pos) const /* patch position: may be NULL */
{
  const char *eyec = "AzPrepText2::gen_X_seq"; 
  AzX::throw_if_null(m_feat, eyec, "m_feat"); 
  AzX::no_support(do_skip_stopunk, eyec, "variable strides with Seq"); 
  int t_num; 
  const int *tokno = ia_tokno.point(&t_num); 
    
  int pch_num = DIVUP(t_num+padding*2-pch_sz, pch_step) + 1; 
  m_feat->reform(dic_sz*pch_sz, pch_num);   
  if (ia_pos != NULL) ia_pos->reset(); 

  int col = 0; 
  int tx0 = -padding; 
  for (int pch_no = 0; pch_no < pch_num; ++pch_no) {
    int tx1 = tx0 + pch_sz; 
    
    AzSmat m; 
    for (int tx = tx0; tx < tx1; ++tx) {
      AzSmat m0(dic_sz, 1); 
      if (tx >= 0 && tx < t_num && tokno[tx] >= 0) {
        AzIntArr ia_row; ia_row.put(tokno[tx]); 
        m0.col_u(0)->load(&ia_row, 1); 
      }
      if (tx == tx0) m.set(&m0); 
      else           m.rbind(&m0); 
    }
    if (do_allow_zero || !m.isZero()) {
      m_feat->col_u(col)->set(m.col(0)); 
      if (ia_pos != NULL) ia_pos->put(tx0); 
      ++col; 
    }

    if (tx1 >= t_num+padding) break; 
    tx0 += pch_step; 
  }
  m_feat->resize(col);   
}
int test_ctr()
{
	int Error(0);

#if GLM_HAS_INITIALIZER_LISTS
	glm::mat2x3 m0(
		glm::vec3(0, 1, 2),
		glm::vec3(3, 4, 5));
	
	glm::mat2x3 m1{0, 1, 2, 3, 4, 5};
	
	glm::mat2x3 m2{
		{0, 1, 2},
		{3, 4, 5}};
	
	for(glm::length_t i = 0; i < m0.length(); ++i)
		Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
	
	for(glm::length_t i = 0; i < m1.length(); ++i)
		Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
	
	std::vector<glm::mat2x3> v1{
		{0, 1, 2, 3, 4, 5},
		{0, 1, 2, 3, 4, 5}
	};
	
	std::vector<glm::mat2x3> v2{
		{
			{ 0, 1, 2},
			{ 4, 5, 6}
		},
		{
			{ 0, 1, 2},
			{ 4, 5, 6}
		}
	};
	
#endif//GLM_HAS_INITIALIZER_LISTS
	
	return Error;
}
Beispiel #16
0
void	mime_test()
{
	{
		mime_part m1( "text", "plain" );
		m1.add_content_type_param( "charset", "utf-8" );
		m1.add_header( "Content-Transfer-Encoding", "7bit" );
		m1.set_body( "body." );

		std::string data = m1.get();
		printf( "%s\ndone.\n", data.c_str() );
	}

	{
		mime_part mr( "multipart", "mixed" );
		mime_part m0( "multipart", "mixed" );
		mr.append_part( &m0 );

		mime_part m1( "text", "plain" );
		m1.add_content_type_param( "charset", "utf-8" );
		m1.add_header( "Content-Transfer-Encoding", "7bit" );
		m1.set_body( "body." );

		mime_part m2( "application", "x-msdownload" );
		m2.add_content_type_param( "name", "abcd.data" );
		m2.add_header( "Content-Transfer-Encoding", "base64" );
		m2.add_header( "Content-Disposition", "attachment" );
		m2.add_content_type_param( "filename", "abcd.data" );
		m2.set_body( "lalajsdflajdlfkjadlkfjaldkfjladjflakdjflakdjflakjdflajdsflajdlfkajdlfkjaldkfjalkdjflakdjsflkasdjflasd" );

		m0.append_part( &m1 );
		m0.append_part( &m2 );

		std::string data = mr.get();
		printf( "\n%s\ndone.\n", data.c_str() );
	}
}
Beispiel #17
0
/**
* Creates a tangent between two circles or arcs.
* Out of the 4 possible tangents, the one closest to
* the given coordinate is returned.
*
* @param coord Coordinate to define which tangent we want (typically a
*              mouse coordinate).
* @param circle1 1st circle or arc entity.
* @param circle2 2nd circle or arc entity.
*/
RS_Line* RS_Creation::createTangent2(const RS_Vector& coord,
                                     RS_Entity* circle1,
                                     RS_Entity* circle2) {
	RS_Line* ret = nullptr;
    RS_Vector circleCenter1;
    RS_Vector circleCenter2;
    double circleRadius1 = 0.0;
    double circleRadius2 = 0.0;

    // check given entities:
	if(! (circle1 && circle2))
		return nullptr;
	if( !(circle1->isArc() && circle2->isArc()))
		return nullptr;

	std::vector<RS_Line*> poss;
    //        for (int i=0; i<4; ++i) {
	//            poss[i] = nullptr;
    //        }
    RS_LineData d;
    if( circle1->rtti() == RS2::EntityEllipse) {
        std::swap(circle1,circle2);//move Ellipse to the second place
    }
    circleCenter1=circle1->getCenter();
    circleRadius1=circle1->getRadius();
    circleCenter2=circle2->getCenter();
    circleRadius2=circle2->getRadius();
    if(circle2->rtti() != RS2::EntityEllipse) {
        //no ellipse

        // create all possible tangents:

        double angle1 = circleCenter1.angleTo(circleCenter2);
        double dist1 = circleCenter1.distanceTo(circleCenter2);

        if (dist1>1.0e-6) {
            // outer tangents:
            double dist2 = circleRadius2 - circleRadius1;
            if (dist1>dist2) {
                double angle2 = asin(dist2/dist1);
				double angt1 = angle1 + angle2 + M_PI_2;
				double angt2 = angle1 - angle2 - M_PI_2;
				RS_Vector offs1 = RS_Vector::polar(circleRadius1, angt1);
				RS_Vector offs2 = RS_Vector::polar(circleRadius2, angt1);

				poss.push_back( new RS_Line{circleCenter1 + offs1,
													  circleCenter2 + offs2});


                offs1.setPolar(circleRadius1, angt2);
                offs2.setPolar(circleRadius2, angt2);

				poss.push_back( new RS_Line{circleCenter1 + offs1,
													  circleCenter2 + offs2});
            }

            // inner tangents:
            double dist3 = circleRadius2 + circleRadius1;
            if (dist1>dist3) {
                double angle3 = asin(dist3/dist1);
				double angt3 = angle1 + angle3 + M_PI_2;
				double angt4 = angle1 - angle3 - M_PI_2;
                RS_Vector offs1;
                RS_Vector offs2;

                offs1.setPolar(circleRadius1, angt3);
                offs2.setPolar(circleRadius2, angt3);

				poss.push_back( new RS_Line{circleCenter1 - offs1,
													  circleCenter2 + offs2});


                offs1.setPolar(circleRadius1, angt4);
                offs2.setPolar(circleRadius2, angt4);

				poss.push_back( new RS_Line{circleCenter1 - offs1,
													  circleCenter2 + offs2});
            }

        }
    }else{
        //circle2 is Ellipse
		std::unique_ptr<RS_Ellipse> e2((RS_Ellipse*)circle2->clone());
//        RS_Ellipse* e2=new RS_Ellipse(nullptr,RS_EllipseData(RS_Vector(4.,1.),RS_Vector(2.,0.),0.5,0.,0.,false));
//        RS_Ellipse  e3(nullptr,RS_EllipseData(RS_Vector(4.,1.),RS_Vector(2.,0.),0.5,0.,0.,false));
//        RS_Ellipse* circle1=new RS_Ellipse(nullptr,RS_EllipseData(RS_Vector(0.,0.),RS_Vector(1.,0.),1.,0.,0.,false));
        RS_Vector m0(circle1->getCenter());
//        std::cout<<"translation: "<<-m0<<std::endl;
        e2->move(-m0); //circle1 centered at origin

        double a,b;
        double a0(0.);
        if(circle1->rtti() != RS2::EntityEllipse){//circle1 is either arc or circle
            a=fabs(circle1->getRadius());
            b=a;
			if(fabs(a)<RS_TOLERANCE) return nullptr;
        }else{//circle1 is ellipse
            RS_Ellipse* e1=static_cast<RS_Ellipse*>(circle1);
            a0=e1->getAngle();
//            std::cout<<"rotation: "<<-a0<<std::endl;
            e2->rotate(-a0);//e1 major axis along x-axis
            a=e1->getMajorRadius();
            b=e1->getRatio()*a;
			if(fabs(a)<RS_TOLERANCE || fabs(b)<RS_TOLERANCE) return nullptr;
        }
        RS_Vector factor1(1./a,1./b);
//        std::cout<<"scaling: factor1="<<factor1<<std::endl;
        e2->scale(RS_Vector(0.,0.),factor1);//circle1 is a unit circle
        factor1.set(a,b);
        double a2(e2->getAngle());
//        std::cout<<"rotation: a2="<<-a2<<std::endl;
        e2->rotate(-a2); //ellipse2 with major axis in x-axis direction
        a=e2->getMajorP().x;
        b=a*e2->getRatio();
        RS_Vector v(e2->getCenter());
//        std::cout<<"Center: (x,y)="<<v<<std::endl;


        std::vector<double> m(0,0.);
        m.push_back(1./(a*a)); //ma000
        m.push_back(1./(b*b)); //ma000
        m.push_back(v.y*v.y-1.); //ma100
        m.push_back(v.x*v.y); //ma101
        m.push_back(v.x*v.x-1.); //ma111
        m.push_back(2.*a*b*v.y); //mb10
        m.push_back(2.*a*b*v.x); //mb11
        m.push_back(a*a*b*b); //mc1

		auto vs0=RS_Math::simultaneousQuadraticSolver(m); //to hold solutions
		if (vs0.getNumber()<1) return nullptr;
//        for(size_t i=0;i<vs0.getNumber();i++){
		for(RS_Vector vpec: vs0){
			RS_Vector vpe2(e2->getCenter()+
						   RS_Vector(vpec.y/e2->getRatio(),vpec.x*e2->getRatio()));
            vpec.x *= -1.;//direction vector of tangent
            RS_Vector vpe1(vpe2 - vpec*(RS_Vector::dotP(vpec,vpe2)/vpec.squared()));
//            std::cout<<"vpe1.squared()="<<vpe1.squared()<<std::endl;
			RS_Line *l=new RS_Line{vpe1, vpe2};
            l->rotate(a2);
            l->scale(factor1);
            l->rotate(a0);
            l->move(m0);
            poss.push_back(l);

        }
        //debugging

    }
    // find closest tangent:
	if(poss.size()<1) return nullptr;
    double minDist = RS_MAXDOUBLE;
    double dist;
    int idx = -1;
	for (size_t i=0; i<poss.size(); ++i) {
		if (poss[i]) {
            poss[i]->getNearestPointOnEntity(coord,false,&dist);
//        std::cout<<poss.size()<<": i="<<i<<" dist="<<dist<<"\n";
            if (dist<minDist) {
                minDist = dist;
                idx = i;
            }
        }
    }
//idx=static_cast<int>(poss.size()*(random()/(double(1.0)+RAND_MAX)));
    if (idx!=-1) {
        RS_LineData d = poss[idx]->getData();
		for(auto p: poss){
			if(p)
				delete p;
		}

		if (document && handleUndo) {
            document->startUndoCycle();
        }

		ret = new RS_Line{container, d};
		setEntity(ret);
    } else {
		ret = nullptr;
    }

    return ret;
}
Beispiel #18
0
// mcmc_helper(im,im_prev,buf,int(xwho),int(xwho2));
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
    // trw_bprop_helper2(model, psi_ij_rho, psi_i, rho, maxiter, n, m1, m2, b_i,...
    //                   dm1, dm2, dn, dpsi_i, dpsi_ij);
          
    int i=0;
    int nnodes     = mapdouble(mxGetField(prhs[i],0,"nnodes"))(0);
    int ncliques   = mapdouble(mxGetField(prhs[i],0,"ncliques"))(0);
    int nvals      = mapdouble(mxGetField(prhs[i],0,"nvals"))(0);
    MatrixXi pairs = mapdouble(mxGetField(prhs[i],0,"pairs")).cast<int>();
    pairs.array() -= 1;
    MatrixXi N1   = mapdouble(mxGetField(prhs[i],0,"N1")).cast<int>();
    N1.array() -= 1;
    MatrixXi N2   = mapdouble(mxGetField(prhs[i],0,"N2")).cast<int>();
    N2.array() -= 1;    
    i++;
        
    MatrixMd psi_ij  = mapdouble(prhs[i++]);
    MatrixMd psi_i   = mapdouble(prhs[i++]);
    double rho       = mapdouble(prhs[i++])(0);
    int maxiter      = mapdouble(prhs[i++])(0);
    MatrixMd n       = mapdouble(prhs[i++]);
    MatrixMd m1      = mapdouble(prhs[i++]);
    MatrixMd m2      = mapdouble(prhs[i++]);
    MatrixMd b_i     = mapdouble(prhs[i++]);
    MatrixMd mstor   = mapdouble(prhs[i++]);
    MatrixMd dm1     = mapdouble(prhs[i++]);
    MatrixMd dm2     = mapdouble(prhs[i++]);
    MatrixMd dn      = mapdouble(prhs[i++]);
    MatrixMd dpsi_i  = mapdouble(prhs[i++]);
    MatrixMd dpsi_ij = mapdouble(prhs[i++]);
    MatrixMd b_ij0   = mapdouble(prhs[i++]);
    MatrixMd db_ij0  = mapdouble(prhs[i++]);
    int dorec        = mapdouble(prhs[i++]).cast<int>()(0);
    
    int w  = mstor.rows()-1;
    
    MatrixXd S (nvals,nvals);
    MatrixXd m0(nvals,1);

    for(int c=0; c<ncliques; c++){
        int i = pairs(c, 0);
        int j = pairs(c, 1);
        for(int yi=0; yi<nvals; yi++){
            for(int yj=0; yj<nvals; yj++){
                int index = yi + yj*nvals;
                //b_ij0(index,c) = b_ij0(index,c)*psi_i(yi,i)*psi_i(yj,j)*n(yi,i)*n(yj,j)/m1(yi,c)/m2(yj,c);
                dpsi_i(yi, i) = dpsi_i(yi, i) + db_ij0(index, c)*b_ij0(index, c)/psi_i(yi, i);
                dpsi_i(yj, j) = dpsi_i(yj, j) + db_ij0(index, c)*b_ij0(index, c)/psi_i(yj, j);
                dn(yi, i)     = dn(yi, i)     + db_ij0(index, c)*b_ij0(index, c)/n(yi, i);
                dn(yj, j)     = dn(yj, j)     + db_ij0(index, c)*b_ij0(index, c)/n(yj, j);
                dm1(yi, c)    = dm1(yi, c)    - db_ij0(index, c)*b_ij0(index, c)/m1(yi, c);
                dm2(yj, c)    = dm2(yj, c)    - db_ij0(index, c)*b_ij0(index, c)/m2(yj, c);
            }
        }
    }

    for(int i=0; i<b_i.cols(); i++){
        for(int yi=0; yi<nvals; yi++){
            for(int k=0; k<N1.cols(); k++){
                int d = N1(i, k);
                if(d==-2) continue;
                //n(yi, i) *= m1(yi, d);
                dm1(yi,d) += rho * dn(yi,i)*n(yi,i)/m1(yi,d);
            }
            for(int k=0; k<N2.cols(); k++){
                int d = N2(i, k);
                if(d==-2) continue;
                //n(yi, i) *= m2(yi, d);
                dm2(yi,d) += rho * dn(yi,i)*n(yi,i)/m2(yi,d);
            }
        }
    }
    
    int reps;
    double conv;
    for(reps=0; reps<maxiter; reps++){
        
        for(int c0=2*ncliques-1; c0>=0; c0--){
            int c, mode;
            if(c0<ncliques){
                c    = c0;
                mode = 1;
            } else{
                c    = ncliques - 1 - (c0-ncliques);
                mode = 2;
            }
            int i = pairs(c,0);
            int j = pairs(c,1);

            if( mode==1 ){
                
                for(int yi=0; yi<nvals; yi++)
                    n(yi, i) = 1;
                for(int k=0; k<N1.cols(); k++){
                    int d = N1(i, k);
                    if(d==-2) continue;
                    for(int yi=0; yi<nvals; yi++)
                        n(yi, i) *= m1(yi, d);
                }
                for(int k=0; k<N2.cols(); k++){
                    int d = N2(i, k);
                    if(d==-2) continue;
                    for(int yi=0; yi<nvals; yi++)
                        n(yi, i) *= m2(yi, d);
                }
                // n.col(i) = n.col(i).array().pow(rho);
                if(rho==1){
                    //nothing
                } else if(rho==.5){
                    n.col(i) = n.col(i).array().sqrt();
                } else
                    n.col(i) = n.col(i).array().pow(rho);
                
                // compute m(y_j)
                for(int yj=0; yj<nvals; yj++){
                    m0(yj) = 0;
                    for(int yi=0; yi<nvals; yi++){
                        int index = yi + yj*nvals;
                        S(yi,yj)  = psi_ij(index, c)*psi_i(yi, i)*n(yi, i)/m1(yi, c);
                        m0(yj)   += S(yi,yj);
                    }
                }
            
                double k = S.sum();
                
                MatrixXd dm0 = dm2.col(c)/k; 
                dm0.array() -= (dm2.col(c).array()*m0.array()).sum()/(k*k);
                
                MatrixXd dn  = 0*n.col(i);
                
                //#pragma omp parallel for num_threads(2)
                for(int yj=0; yj<nvals; yj++){
                    for(int yi=0; yi<nvals; yi++){
                        int index = yi + yj*nvals;
                        dpsi_ij(index,c) += dm0(yj)*S(yi,yj)/psi_ij(index,c);
                        dpsi_i(yi,i)     += dm0(yj)*S(yi,yj)/psi_i(yi,i);
                        dn(yi)           += dm0(yj)*S(yi,yj)/n(yi,i);
                        dm1(yi,c)        -= dm0(yj)*S(yi,yj)/m1(yi,c);
                    }
                }
                
               for(int yi=0; yi<nvals; yi++){
                    for(int k=0; k<N1.cols(); k++){
                        int d = N1(i, k);
                        if(d==-2) continue;
                        dm1(yi,d) += rho*dn(yi)*n(yi,i)/m1(yi,d);
                    }
                    for(int k=0; k<N2.cols(); k++){
                        int d = N2(i, k);
                        if(d==-2) continue;
                        dm2(yi,d) += rho*dn(yi)*n(yi,i)/m2(yi,d);
                    }
               }
               dm2.col(c) *= 0.0;
               if( dorec )
                   for(int yj=nvals-1; yj>=0; yj--){ m2(yj,c)=mstor(w); w--;}
            } else{
                for( int yj=0; yj<nvals; yj++)
                    n(yj, j) = 1;
                for(int k=0; k<N1.cols(); k++){
                    int d = N1(j, k);
                    if(d==-2) continue;
                    for( int yj=0; yj<nvals; yj++)
                        n(yj, j) *= m1(yj, d);
                }
                for(int k=0; k<N2.cols(); k++){
                    int d = N2(j, k);
                    if(d==-2) continue;
                    for( int yj=0; yj<nvals; yj++)
                        n(yj, j) *= m2(yj, d);
                }
                
//                n.col(j) = n.col(j).array().pow(rho);
                if(rho==1){
                    //nothing
                } else if(rho==.5){
                    n.col(j) = n.col(j).array().sqrt();
                } else
                    n.col(j) = n.col(j).array().pow(rho);
                
                
                for(int yi=0; yi<nvals; yi++){
                    m0(yi) = 0;
                    for(int yj=0; yj<nvals; yj++){
                        int index = yi + yj*nvals;
                        S(yi,yj)  = psi_ij(index, c)*psi_i(yj, j)*n(yj, j)/m2(yj, c);
                        m0(yi)   += S(yi,yj);
                    }
                }
                double k = S.sum();

                MatrixXd dm0 = dm1.col(c)/k; 
                dm0.array() -= (dm1.col(c).array()*m0.array()).sum()/(k*k);
                MatrixXd dn  = 0*n.col(i);

                for(int yj=0; yj<nvals; yj++){
                    for(int yi=0; yi<nvals; yi++){
                        int index = yi + yj*nvals;
                        dpsi_ij(index,c) += dm0(yi)*S(yi,yj)/psi_ij(index,c);
                        dpsi_i(yj,j)     += dm0(yi)*S(yi,yj)/psi_i(yj,j);
                        dn(yj)           += dm0(yi)*S(yi,yj)/n(yj,j);
                        dm2(yj,c)        -= dm0(yi)*S(yi,yj)/m2(yj,c);
                    }
                }
                
                for(int yj=0; yj<nvals; yj++){
                    for(int k=0; k<N1.cols(); k++){
                        int d = N1(j, k);
                        if(d==-2) continue;
                        dm1(yj, d) += rho*dn(yj)*n(yj, j)/m1(yj, d);
                    }
                    for(int k=0; k<N2.cols(); k++){
                        int d = N2(j, k);
                        if(d==-2) continue;
                        dm2(yj, d) += rho*dn(yj)*n(yj, j)/m2(yj, d);
                    }
                }
                
               dm1.col(c) *= 0.0;
               if( dorec )
                   for(int yi=nvals-1; yi>=0; yi--){ m1(yi,c)=mstor(w); w--;}
            }
        }
    }
}
Beispiel #19
0
void isis_looper::myLoop(int nsel, int mode, bool silent)
{

  char plotName[300];
  sprintf(plotName,"test");
  
  if (nsel == 0)                	{sprintf(plotName,"tt");}
  else if (nsel == 1)   		{sprintf(plotName,"twdr");}
  else if (nsel == -1)   		{sprintf(plotName,"twds");}
  else if (nsel == 2)   		{sprintf(plotName,"zjets");}
  else if (nsel == 3)   		{sprintf(plotName,"di");}
  else if (nsel == 4)			{sprintf(plotName, "st");}
  else if (nsel == 5)   		{sprintf(plotName,"wjets");}
  else if (nsel == 6)   		{sprintf(plotName,"qcd_mu");}
  else if (nsel == 7)                	{sprintf(plotName,"others");}
  
  else if (nsel == 555)                	{sprintf(plotName,"mc");}
  
  else if (nsel == 666)                	{sprintf(plotName,"data");}
    
  else if (nsel == -10)                   {sprintf(plotName,"tt");}
  else if (nsel ==  10)                   {sprintf(plotName,"tt");}
  
  bool nosf = false;
  
  
  char newRootFile[300];
  double lumi = luminosity; 
  if (mode == 0 )        lumi = 4399; 
  else if ( mode == 1)   lumi = 1000; // to check 
  else if ( mode == 2)   lumi = 5103.58; // to check 
  sprintf(newRootFile,"results/an_%dpb_%d.root", (int)lumi, mode);
  
   if(nsel == -10){
  sprintf(newRootFile,"results/JERsysDown_an_%dpb_%d.root", (int)lumi, mode);
  }else if(nsel == 10 ){
   sprintf(newRootFile,"results/JERsysUp_an_%dpb_%d.root", (int)lumi, mode);
  }
 
  TFile f_var(newRootFile, "UPDATE");
  
  if(!silent){
    std::cout << "[Info:] results root file " << newRootFile << std::endl;
  }
  
  
  //////////
  char title[300];
  sprintf(title,"cuts_%s",plotName);
  TH1F* histo = new TH1F( title, " ", 10,  0, 10 );
  histo->Sumw2();
  
  sprintf(title,"met_high_%s",plotName);
  TH1F* histo_met_high = new TH1F( title, " ", 100,  0, 200 );
  histo_met_high->Sumw2();
  
  sprintf(title,"met_low_%s",plotName);
  TH1F* histo_met_low = new TH1F( title, " ", 100,  0, 200 );
  histo_met_low->Sumw2();
  
  sprintf(title,"promet_%s",plotName);
  TH1F* histo_promet = new TH1F( title, " ", 100,  0, 200 );
  histo_promet->Sumw2();
  
  sprintf(title,"met_cut_%s",plotName);
  TH1F* histo_met_cut = new TH1F( title, " ", 100,  0, 200 );
  histo_met_cut->Sumw2();
  
  sprintf(title,"met_bt_%s",plotName);
  TH1F* histo_met_bt = new TH1F( title, " ", 100,  0, 200 );
  histo_met_bt->Sumw2();
  
  sprintf(title,"mll_after_%s",plotName);
  TH1F* histo_mll_after = new TH1F( title, " ", 100,  0, 200 );
  histo_mll_after->Sumw2();
  
  sprintf(title,"njets_cut_%s",plotName);
  TH1F* histo_njets_cut = new TH1F( title, " ", 10,  -0.5, 9.5 );
  histo_njets_cut->Sumw2();
  
  sprintf(title,"njetsbt_cut_%s",plotName);
  TH1F* histo_njetsbt_cut = new TH1F( title, " ", 10,   -0.5, 9.5 );
  histo_njetsbt_cut->Sumw2();
  
  sprintf(title,"njetsbt_high_%s",plotName);
  TH1F* histo_njetsbt_high = new TH1F( title, " ", 10,   -0.5, 9.5 );
  histo_njetsbt_high->Sumw2();
  
  sprintf(title,"njetsbt_low_%s",plotName);
  TH1F* histo_njetsbt_low = new TH1F( title, " ", 10,   -0.5, 9.5 );
  histo_njetsbt_low->Sumw2();
  
  sprintf(title,"njets_high_%s",plotName);
  TH1F* histo_njets_high = new TH1F( title, " ", 10,   -0.5, 9.5 );
  histo_njets_high->Sumw2();
  
  sprintf(title,"njets_low_%s",plotName);
  TH1F* histo_njets_low = new TH1F( title, " ", 10,   -0.5, 9.5 );
  histo_njets_low->Sumw2();
  
  sprintf(title,"ptsys_high_%s",plotName);
  TH1F* histo_ptsys_high = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_high->Sumw2();
  
  sprintf(title,"ptsys_low_%s",plotName);
  TH1F* histo_ptsys_low = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_low->Sumw2();
  
  sprintf(title,"ht_high_%s",plotName);
  TH1F* histo_ht_high = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_high->Sumw2();
  
  sprintf(title,"ht_low_%s",plotName);
  TH1F* histo_ht_low = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_low->Sumw2();
  
  sprintf(title,"ht_cut_%s",plotName);
  TH1F* histo_ht_cut = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_cut->Sumw2();
  
  sprintf(title,"pt_max_%s",plotName);
  TH1F* histo_pt_max = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_max->Sumw2();
  
  sprintf(title,"pt_min_%s",plotName);
  TH1F* histo_pt_min = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_min->Sumw2();
  
  sprintf(title,"btagHE_%s",plotName);
  TH2F* histo_btagHE = new TH2F( title, " ", 300,  -200, 100, 100, -2, 7);
  histo_btagHE->Sumw2();
  
  sprintf(title,"btagHP_%s",plotName);
  TH2F* histo_btagHP = new TH2F( title, " ", 300,  -200, 100, 100, -2, 7);
  histo_btagHP->Sumw2();
  
  sprintf(title,"etalepton_%s",plotName);
  TH1F* histo_etalepton = new TH1F( title, " ", 101,  -3, 3);
  histo_etalepton->Sumw2();
  
  sprintf(title,"ht_bf_%s",plotName);
  TH1F* histo_ht_bf = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_bf->Sumw2();
  
  sprintf(title,"ptsys_bf_%s",plotName);
  TH1F* histo_ptsys_bf = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_bf->Sumw2();
  
  sprintf(title,"npu_%s",plotName);
  TH1F* histo_npu = new TH1F( title, " ", 30,   -0.5, 29.5 );
  histo_npu->Sumw2();
  
  
  /// Classic plotmaker plots
  sprintf(title,"met_%s",plotName);
  TH1F* histo_met = new TH1F( title, " ", 100,  0, 200 );
  histo_met->Sumw2();
  
  sprintf(title,"mll_%s",plotName);
  TH1F* histo_mll = new TH1F( title, " ", 100,  0, 200 );
  histo_mll->Sumw2();
  
  sprintf(title,"njets_%s",plotName);
  TH1F* histo_njets = new TH1F( title, " ", 10,  0, 10 );
  histo_njets->Sumw2();
  
  sprintf(title,"njetsbt_%s",plotName);
  TH1F* histo_njetsbt = new TH1F( title, " ", 10,  -0.5, 9.5 );
  histo_njetsbt->Sumw2();
  
  sprintf(title,"ptsys_%s",plotName);
  TH1F* histo_ptsys = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys->Sumw2();
  
  sprintf(title,"ht_%s",plotName);
  TH1F* histo_ht = new TH1F( title, " ", 300,  0, 600 );
  histo_ht->Sumw2();
  
  sprintf(title,"pt_leading_%s",plotName);
  TH1F* histo_pt_leading = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_leading->Sumw2();
  
  
  sprintf(title,"eta_leading_%s",plotName);
  TH1F* histo_eta_leading = new TH1F( title, " ", 101,  -3, 3);
  histo_eta_leading->Sumw2();
  
  sprintf(title,"nvertex_%s",plotName);
  TH1F* histo_nvertex = new TH1F( title, " ", 70,   -0.5, 69.5 );
  histo_nvertex->Sumw2();
 
  
  // 1 jet level
  /// Classic plotmaker plots
  sprintf(title,"met_1j_%s",plotName);
  TH1F* histo_met_1j = new TH1F( title, " ", 100,  0, 200 );
  histo_met_1j->Sumw2();
  
  sprintf(title,"mll_1j_%s",plotName);
  TH1F* histo_mll_1j = new TH1F( title, " ", 100,  0, 200 );
  histo_mll_1j->Sumw2();
  
  sprintf(title,"ptsys_1j_%s",plotName);
  TH1F* histo_ptsys_1j = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_1j->Sumw2();
  
  sprintf(title,"ht_1j_%s",plotName);
  TH1F* histo_ht_1j = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_1j->Sumw2();
  
  sprintf(title,"pt_leading_1j_%s",plotName);
  TH1F* histo_pt_leading_1j = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_leading_1j->Sumw2();
  
  sprintf(title,"nvertex_1j_%s",plotName);
  TH1F* histo_nvertex_1j = new TH1F( title, " ", 30,   -0.5, 29.5 );
  histo_nvertex_1j->Sumw2();
  
  // 1 jet level
  /// Classic plotmaker plots
  sprintf(title,"met_1j1t_%s",plotName);
  TH1F* histo_met_1j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_met_1j1t->Sumw2();
  
  sprintf(title,"mll_1j1t_%s",plotName);
  TH1F* histo_mll_1j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_mll_1j1t->Sumw2();
  
  sprintf(title,"ptsys_1j1t_%s",plotName);
  TH1F* histo_ptsys_1j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_1j1t->Sumw2();
  
  sprintf(title,"ht_1j1t_%s",plotName);
  TH1F* histo_ht_1j1t = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_1j1t->Sumw2();
  
  sprintf(title,"pt_leading_1j1t_%s",plotName);
  TH1F* histo_pt_leading_1j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_leading_1j1t->Sumw2();
  
  sprintf(title,"nvertex_1j1t_%s",plotName);
  TH1F* histo_nvertex_1j1t = new TH1F( title, " ", 30,   -0.5, 29.5 );
  histo_nvertex_1j1t->Sumw2();
  
  
  // 2j1t
  /// Classic plotmaker plots
  sprintf(title,"met_2j1t_%s",plotName);
  TH1F* histo_met_2j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_met_2j1t->Sumw2();
  
  sprintf(title,"mll_2j1t_%s",plotName);
  TH1F* histo_mll_2j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_mll_2j1t->Sumw2();
  
  sprintf(title,"ptsys_2j1t_%s",plotName);
  TH1F* histo_ptsys_2j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_2j1t->Sumw2();
  
  sprintf(title,"ht_2j1t_%s",plotName);
  TH1F* histo_ht_2j1t = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_2j1t->Sumw2();
  
  sprintf(title,"pt_leading_2j1t_%s",plotName);
  TH1F* histo_pt_leading_2j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_leading_2j1t->Sumw2();
  
  sprintf(title,"nvertex_2j1t_%s",plotName);
  TH1F* histo_nvertex_2j1t = new TH1F( title, " ", 30,   -0.5, 29.5 );
  histo_nvertex_2j1t->Sumw2();
  
  
  // 2j2t
  /// Classic plotmaker plots
  sprintf(title,"met_2j2t_%s",plotName);
  TH1F* histo_met_2j2t = new TH1F( title, " ", 100,  0, 200 );
  histo_met_2j2t->Sumw2();
  
  sprintf(title,"mll_2j2t_%s",plotName);
  TH1F* histo_mll_2j2t = new TH1F( title, " ", 100,  0, 200 );
  histo_mll_2j2t->Sumw2();
  
  sprintf(title,"ptsys_2j2t_%s",plotName);
  TH1F* histo_ptsys_2j2t = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_2j2t->Sumw2();
  
  sprintf(title,"ht_2j2t_%s",plotName);
  TH1F* histo_ht_2j2t = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_2j2t->Sumw2();
  
  sprintf(title,"pt_leading_2j2t_%s",plotName);
  TH1F* histo_pt_leading_2j2t = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_leading_2j2t->Sumw2();
  
  sprintf(title,"nvertex_2j2t_%s",plotName);
  TH1F* histo_nvertex_2j2t = new TH1F( title, " ", 30,   -0.5, 29.5 );
  histo_nvertex_2j2t->Sumw2();

  
  // all regions
  sprintf(title,"R_%s",plotName);
  TH1F* histo_R = new TH1F( title, " ", 40,  0, 40 );
  histo_R->Sumw2();
  
  
  // checking pu reweighting
  sprintf(title,"nvertex_final_%s",plotName);
  TH1F* histo_nvertex_final = new TH1F( title, " ", 70,   -0.5, 69.5 );
  histo_nvertex_final->Sumw2();
  
  sprintf(title,"nvertex_final_3D_%s",plotName);
  TH1F* histo_nvertex_final_3D = new TH1F( title, " ", 70,   -0.5, 69.5 );
  histo_nvertex_final_3D->Sumw2();
  
  sprintf(title,"nvertex_final_purw_%s",plotName);
  TH1F* histo_nvertex_final_purw = new TH1F( title, " ", 70,   -0.5, 69.5 );
  histo_nvertex_final_purw->Sumw2();
  


  sprintf(title,"nvertex_2lep_%s",plotName);
  TH1F* histo_nvertex_2lep = new TH1F( title, " ", 70,   -0.5, 69.5 );
  histo_nvertex_2lep->Sumw2();
//<<<<<<< isis_looper.C
  
  //_________________________________________________________________________________
  //added by Isis
  
  // -- Leading jet --- 
    sprintf(title,"eta_jet_%s",plotName);
  TH1F* histo_eta_jet = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet->Sumw2();
  
 
     sprintf(title,"eta_jet_110_%s",plotName);
  TH1F* histo_eta_jet_110 = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet_110->Sumw2();
  
      sprintf(title,"eta_jet_90_%s",plotName);
  TH1F* histo_eta_jet_90 = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet_90->Sumw2();
  
  
      sprintf(title,"eta_jet_70_%s",plotName);
  TH1F* histo_eta_jet_70 = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet_70->Sumw2();
  
  
      sprintf(title,"eta_jet_50_%s",plotName);
  TH1F* histo_eta_jet_50 = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet_50->Sumw2();
  
      sprintf(title,"eta_jet_30_%s",plotName);
  TH1F* histo_eta_jet_30 = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet_30->Sumw2();
 
 
   // -- Second Leading jet --- 
    sprintf(title,"eta_jet1_%s",plotName);
  TH1F* histo_eta_jet1 = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet1->Sumw2();
  
 
     sprintf(title,"eta_jet1_110_%s",plotName);
  TH1F* histo_eta_jet1_110 = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet1_110->Sumw2();
  
      sprintf(title,"eta_jet1_90_%s",plotName);
  TH1F* histo_eta_jet1_90 = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet1_90->Sumw2();
  
  
      sprintf(title,"eta_jet1_70_%s",plotName);
  TH1F* histo_eta_jet1_70 = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet1_70->Sumw2();
  
  
      sprintf(title,"eta_jet1_50_%s",plotName);
  TH1F* histo_eta_jet1_50 = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet1_50->Sumw2();
  
      sprintf(title,"eta_jet1_30_%s",plotName);
  TH1F* histo_eta_jet1_30 = new TH1F( title, " ", 50,-5, 5 );  //#bins - begin - end
  histo_eta_jet1_30->Sumw2();
  
  // ---- Z/gamma controlregion 
 
    sprintf(title,"mll_zgamma_%s",plotName);
  TH1F* histo_mll_zgamma = new TH1F( title, " ", 50,  0, 200 );
  histo_mll_zgamma->Sumw2();
  
  
    sprintf(title,"met_zgamma_%s",plotName);
  TH1F* histo_met_zgamma= new TH1F( title, " ", 50,  0, 200 );
  histo_met_zgamma->Sumw2();
  
//=======
//>>>>>>> 1.1.2.3



  

//__________________________________________________ END HISTO DEF _________________________________________________________


  if (fChain == 0) return;
  
  Long64_t nentries = fChain->GetEntriesFast();
  
  Long64_t nbytes = 0, nb = 0;
  for (Long64_t jentry=0; jentry<nentries;jentry++) {
    
    
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    
    
    if (lumi != lum && nsel != 666 && mode !=3){
      if (jentry == 0)std::cout << "[Warning:] This tree was made with a different luminosity (" << lum << ") than " << lumi << std::endl;
      //xlWeight*=(lumi/lum);
    }
    
  //  if(puweight > 5){ continue ;}
    
    if(ptLepton->size() != 2){
      std::cout << "[Warning:] Something is wrong, your Tree is not correctly filled" << std::endl;
      break;
    } else {
      histo->Fill(0.,xlWeight);
      histo_nvertex_2lep->Fill(nvertex,xlWeight);
      TLorentzVector lepton0(pxLepton->at(0),pyLepton->at(0), pzLepton->at(0), eLepton->at(0));
      TLorentzVector lepton1(pxLepton->at(1),pyLepton->at(1), pzLepton->at(1), eLepton->at(1)); 
      TLorentzVector pair = lepton0+lepton1;
      
      double phipairmet_t = 0;
      double pi_m = 3.1416/2;
      phipairmet_t = pi_m;
      
      TVector3 vmet(metPx, metPy, 0);
      
      double promet = metPt*sin(phipairmet_t);
      TVector3 m0(pxLepton->at(0),pyLepton->at(0), pzLepton->at(0));
      TVector3 m1(pxLepton->at(1),pyLepton->at(1), pzLepton->at(1)); 
      if (fabs(m0.DeltaPhi(vmet)) < phipairmet_t) phipairmet_t = fabs(m0.DeltaPhi(vmet));
      if (fabs(m1.DeltaPhi(vmet)) < phipairmet_t) phipairmet_t = fabs(m1.DeltaPhi(vmet));
      
      if (phipairmet_t == pi_m) promet = metPt;
      
      if (pair.M() > 20){
	histo->Fill(1, xlWeight);

	double SFval, SFerror;
	if ( nsel == 666 || nosf){
	  SFval = 1;
	  SFerror = 0;
	} else if (nsel == 0){
	  SFval = 0.95;
	  SFerror = 0.03;
	} else {
	  SFval = 0.97;
	  SFerror = 0.03;
	}
	
	
	int nJetsBT = 0;
	int nTightJetsBT = 0;
	int nJets = 0;
	bool bTagged = false;
	int iJetn[5]={-1, -1,-1,-1,-1};
	int iJet = -5;
	int iSF;
	double tempSF = SFval;
	
	int SFvalue = int(tempSF*100);
	
	for (unsigned int i =0; i < ptJet->size(); i ++){ 
	  TLorentzVector tempJet(pxJet->at(i),pyJet->at(i), pzJet->at(i), eJet->at(i));
	  if (ptJet->at(i) > 30 && TMath::Min(fabs(lepton0.DeltaR(tempJet)), fabs(lepton1.DeltaR(tempJet))) > 0.3) {
	    
	    iJetn[nJets] = i;
	    iJet = i;
	    nJets++;
	    
	    
	    if (btCSVBJet->at(i) > 0.679){
	      iSF = rand() % 100;
	      if (iSF < SFvalue ){
		bTagged = true;
		nJetsBT++;
		nTightJetsBT++;
	      } 
	    } 
	  } else if (btCSVBJet->at(i) > 0.679){
	    iSF = rand() % 100;
	    if (iSF < SFvalue ) nJetsBT++;
	  }  
	  
	}
	
	
        if(nJets){
	 TLorentzVector jet(pxJet->at(iJetn[0]),pyJet->at(iJetn[0]), pzJet->at(iJetn[0]), eJet->at(iJetn[0]));
	// TLorentzVector jet1(pxJet->at(iJetn[1]),pyJet->at(iJetn[1]), pzJet->at(iJetn[1]), eJet->at(iJetn[1])); //2e jet erbij nemen
	 histo_eta_jet->Fill(jet.Eta(),xlWeight);      
	 //histo_eta_jet1->Fill(jet1.Eta(),xlWeight);    // 2e jet in dezelfde plot steken , misschien beter om aparte plot te maken? 
	 
	 if( ptJet->at(iJet) > 110 ){
	   histo_eta_jet_110->Fill(jet.Eta(),xlWeight); 
	  // histo_eta_jet1_110->Fill(jet1.Eta(),xlWeight); 
	}
	 if (ptJet->at(iJet) > 90){
	   histo_eta_jet_90->Fill(jet.Eta(),xlWeight);
	 //  histo_eta_jet1_90->Fill(jet1.Eta(),xlWeight);  
	 }
	 if (ptJet->at(iJet) > 70){
	   histo_eta_jet_70->Fill(jet.Eta(),xlWeight);
	 //  histo_eta_jet1_70->Fill(jet1.Eta(),xlWeight);  
	 }
	 if(ptJet->at(iJet) > 50){
	  histo_eta_jet_50->Fill(jet.Eta(),xlWeight); 
	 // histo_eta_jet1_50->Fill(jet1.Eta(),xlWeight); 
	 }
	 if (ptJet->at(iJet) > 30){
	  histo_eta_jet_30->Fill(jet.Eta(),xlWeight);
	 // histo_eta_jet1_30->Fill(jet1.Eta(),xlWeight); 
	 }
	 
	
	}
	

	histo_pt_max->Fill(TMath::Max(lepton0.Pt(), lepton1.Pt()), xlWeight);
	histo_pt_min->Fill(TMath::Min(lepton0.Pt(), lepton1.Pt()), xlWeight);
	histo_njets->Fill(nJets,  xlWeight);
	histo_njetsbt->Fill(nJetsBT,  xlWeight);
	histo_mll->Fill(pair.M(),  xlWeight);
	histo_met->Fill(metPt,  xlWeight);
	histo_promet->Fill(promet, xlWeight);
	

	if (nvertex > 5){
	  histo_met_high->Fill(metPt,  xlWeight);
	  histo_njets_high->Fill(nJets,  xlWeight);
	  histo_njetsbt_high->Fill(nJetsBT,  xlWeight);
	} else {
	  histo_met_low->Fill(metPt,  xlWeight);
	  histo_njets_low->Fill(nJets,  xlWeight);
	  histo_njetsbt_low->Fill(nJetsBT,  xlWeight);  
	}
	
	if (nJets) histo_pt_leading->Fill(ptJet->at(0), xlWeight);
	
	if (nJets){
	  TLorentzVector jet_aux(pxJet->at(0),pyJet->at(0), pzJet->at(0), eJet->at(0));
	  histo_eta_leading->Fill(jet_aux.Eta(), xlWeight);
	}
	
	if (nJets == 1){
	  histo_etalepton->Fill(lepton0.Eta(), xlWeight);
	  TLorentzVector jet(pxJet->at(iJet),pyJet->at(iJet), pzJet->at(iJet), eJet->at(iJet));
	   
	  double ptSysPx1 = lepton0.Px() + lepton1.Px() + jet.Px() + metPx;
	  double ptSysPy1 = lepton0.Py() + lepton1.Py() + jet.Py() + metPy;
	  double ptSystem1 = sqrt(ptSysPx1*ptSysPx1 + ptSysPy1*ptSysPy1);
	  double ht1 = lepton0.Pt() + lepton1.Pt() + jet.Pt() + metPt; 
	  histo_ptsys_bf->Fill(ptSystem1, xlWeight);
	  histo_ht_bf->Fill(ht1, xlWeight);
	}
	bool invMass = false;
	if      (mode == 0) invMass = true;
	else if (mode == 1  && (pair.M() > invMax || pair.M() < invMin)) invMass = true;
	else if (mode == 2 && (pair.M() > invMax || pair.M() < invMin)) invMass = true;
	
	//____________________________
        //Z/gamma control region
        
	//if (pair.M() > 81 || pair.M() < 101)
	if(!invMass || (mode == 0 && (pair.M() > 81 || pair.M() < 101) )) 
	{	  
	         
		  histo_mll_zgamma->Fill(pair.M(),  xlWeight);
	          histo_met_zgamma->Fill(metPt,  xlWeight);
	          
	}	 

	//______________________________________


	if (invMass){
	  histo->Fill(2, xlWeight);
	  histo_mll_after->Fill(pair.M(),  xlWeight);
	  histo_met_cut->Fill(metPt,  xlWeight);
	  if (metPt >= metCut || mode ==0){
	   
	    histo->Fill(3, xlWeight);
	    histo_njets_cut->Fill(nJets, xlWeight);
	    if (nJets == 1){
	      histo->Fill(4, xlWeight);
	      histo_njetsbt_cut->Fill(nJetsBT, xlWeight);
	      TLorentzVector jet(pxJet->at(iJet),pyJet->at(iJet), pzJet->at(iJet), eJet->at(iJet));
		
	      double ptSysPx = lepton0.Px() + lepton1.Px() + jet.Px() + metPx;
	      double ptSysPy = lepton0.Py() + lepton1.Py() + jet.Py() + metPy;
	      double ptSystem = sqrt(ptSysPx*ptSysPx + ptSysPy*ptSysPy);
	      double ht = lepton0.Pt() + lepton1.Pt() + jet.Pt() + metPt; 
	      
	      histo_mll_1j->Fill(pair.M(),  xlWeight);
	      histo_met_1j->Fill(metPt,  xlWeight);
	      histo_ptsys_1j->Fill(ptSystem, xlWeight);
	      histo_ht_1j->Fill(ht, xlWeight);
	      histo_pt_leading_1j->Fill(jet.Pt(), xlWeight);
	      
	      
	      if (nJets == 1 && nTightJetsBT == 1 && bTagged && nJetsBT == 1){
		histo->Fill(5, xlWeight);
		
	      
	        histo_mll_1j1t->Fill(pair.M(),  xlWeight);
	        histo_met_1j1t->Fill(metPt,  xlWeight);
	        histo_ptsys_1j1t->Fill(ptSystem, xlWeight);
	        histo_ht_1j1t->Fill(ht, xlWeight);
	        histo_pt_leading_1j1t->Fill(jet.Pt(), xlWeight);
	      
		histo_ptsys->Fill(ptSystem, xlWeight);
		histo_ht->Fill(ht, xlWeight);
		
		histo_met_bt->Fill(metPt, xlWeight);
		
		histo_nvertex->Fill(nvertex, xlWeight);
		histo_npu->Fill(npu, xlWeight);
		
		if (nvertex > 5) {
		  histo_ptsys_high->Fill(ptSystem, xlWeight);
		  histo_ht_high->Fill(ht, xlWeight);
		} else {
		  histo_ptsys_low->Fill(ptSystem, xlWeight);
		  histo_ht_low->Fill(ht, xlWeight);
		  
		}
		
		if (ht > htMin || mode !=0){
		  histo->Fill(6, xlWeight);
		  histo_ht_cut->Fill(ht, xlWeight);
		  
		  //Example to access the pu reweighting!
		  histo_nvertex_final->Fill(nvertex, rawWeight);
		  histo_nvertex_final_3D->Fill(nvertex, rawWeight*puweight3D);
		  histo_nvertex_final_purw->Fill(nvertex, rawWeight*puweight);
		  
		}
	      }
	    }
	  }
	  
	  
	  //Filling of all region from here
	  if (metPt >= metCut || mode ==0){
	
	    if (nJets != 0){
	      
	      TLorentzVector jet(pxJet->at(iJet),pyJet->at(iJet), pzJet->at(iJet), eJet->at(iJet));
	      
	      double ptSysPx = lepton0.Px() + lepton1.Px() + jet.Px() + metPx;
	      double ptSysPy = lepton0.Py() + lepton1.Py() + jet.Py() + metPy;
	      double ptSystem = sqrt(ptSysPx*ptSysPx + ptSysPy*ptSysPy);
	      double ht = lepton0.Pt() + lepton1.Pt() + jet.Pt() + metPt; 
	      
	      if (nJets == 2 && nTightJetsBT == 1 && nJetsBT == 1) {
	        histo_mll_2j1t->Fill(pair.M(),  xlWeight);
	        histo_met_2j1t->Fill(metPt,  xlWeight);
	        histo_ptsys_2j1t->Fill(ptSystem, xlWeight);
	        histo_ht_2j1t->Fill(ht, xlWeight);
	        histo_pt_leading_2j1t->Fill(jet.Pt(), xlWeight);
	      } else if (nJets == 2 && nTightJetsBT == 2 && nJetsBT == 2)  {
	        histo_mll_2j2t->Fill(pair.M(),  xlWeight);
	        histo_met_2j2t->Fill(metPt,  xlWeight);
	        histo_ptsys_2j2t->Fill(ptSystem, xlWeight);
	        histo_ht_2j2t->Fill(ht, xlWeight);
	        histo_pt_leading_2j2t->Fill(jet.Pt(), xlWeight);
	      }
	      
	      
	   
		  
	      //All possible regions
	      if (nJets == 1 && nTightJetsBT == 1 && bTagged && nJetsBT == 1 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))histo_R->Fill(1, xlWeight); //signal
	      if (nJets == 1 && nTightJetsBT == 2)  histo_R->Fill(2, xlWeight);
	      if (nJets == 1 && nTightJetsBT > 0)  histo_R->Fill(3, xlWeight);
	      if (nJets == 1 && nTightJetsBT > 1)  histo_R->Fill(4, xlWeight);
	      if (nJets == 2 && nTightJetsBT == 0)  histo_R->Fill(5, xlWeight);
	      if (nJets == 2 && nTightJetsBT == 1)  histo_R->Fill(6, xlWeight); //CR1 no ht no ptsys
	      if (nJets == 2 && nTightJetsBT == 2)  histo_R->Fill(7, xlWeight); //CR2 no ht no ptsys
	      if (nJets == 2 && nTightJetsBT > 0)  histo_R->Fill(8, xlWeight);
	      if (nJets == 2 && nTightJetsBT > 1)  histo_R->Fill(9, xlWeight);
	      if (nJets > 1 && nTightJetsBT == 0)  histo_R->Fill(10, xlWeight);
	      if (nJets > 1 && nTightJetsBT == 1)  histo_R->Fill(11, xlWeight);
	      if (nJets > 1 && nTightJetsBT == 2)  histo_R->Fill(12, xlWeight);
	      if (nJets > 1 && nTightJetsBT !=0 )  histo_R->Fill(13, xlWeight);
	      if (nJets > 1 && nTightJetsBT > 1 )  histo_R->Fill(14, xlWeight);
	      if (nJets == 3 && nTightJetsBT ==3 )  histo_R->Fill(15, xlWeight);
	      if (nJets == 1 && nTightJetsBT ==1 && bTagged && nJetsBT == 1)  histo_R->Fill(16, xlWeight);
	      if (nJets == 2 && nTightJetsBT == 1 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(17, xlWeight); //CR 1 regular
	      if (nJets == 2 && nTightJetsBT == 2 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(18, xlWeight); //CR 2 regular
	      if (nJets == 2 && nTightJetsBT == 1 && nJetsBT == 1 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(19, xlWeight);
	      if (nJets == 2 && nTightJetsBT == 2 && nJetsBT == 2 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(20, xlWeight);
	      if (nJets == 2 && nJetsBT == 1 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(21, xlWeight); //CR 1 another way
	      if (nJets == 2 && nJetsBT == 2 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(22, xlWeight); //CR 2 another way
	      if (nJets == 2 && nTightJetsBT == 1 && nJetsBT == 1)  histo_R->Fill(23, xlWeight); //CR1 no ht no ptsys tighter
	      if (nJets == 2 && nTightJetsBT == 2 && nJetsBT == 2)  histo_R->Fill(24, xlWeight); //CR2 no ht no ptsys tighter
	      if (nJets == 2 && nJetsBT == 1)  histo_R->Fill(25, xlWeight); //CR1 no ht no ptsys another flavor
	      if (nJets == 2 && nJetsBT == 2)  histo_R->Fill(26, xlWeight); //CR2 no ht no ptsys another flavor
	      if (nJets == 1 && nTightJetsBT == 1 && bTagged && nJetsBT == 1 && (ht > htMin || mode !=0))histo_R->Fill(27, xlWeight); //signal no ptsys
	      if (nJets == 1 && nTightJetsBT == 1 && bTagged && nJetsBT == 1 && ptSystem <= ptsysCut)histo_R->Fill(28, xlWeight); //signal no ht
	      if (nJets == 2 && nTightJetsBT == 1 &&  (ht > htMin || mode !=0))  histo_R->Fill(29, xlWeight); //CR 1 
	      if (nJets == 2 && nTightJetsBT == 2 &&  (ht > htMin || mode !=0))  histo_R->Fill(30, xlWeight); //CR 2 
				
	      
	    } //jets in the event
	  } //all CR
	  
	} // mll
      } //mll pre
    } // 2 leptons
  }// event loop.
  
  
  
  if (!silent){ 
    cout << "------------------------------------------" << endl;
    cout << "[Results:] " << plotName <<  endl;
    cout << "------------------------------------------" << endl;  
    for (int i = 2; i < 9; i++){
      if (i == 2) cout << " leptons: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
      if (i == 3) cout << " inv. mass: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
      if (i == 4) cout << " met: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
      if (i == 5) cout << " jet: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
      if (i == 6) cout << " jet_bt: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
      if (i == 7) cout << " ht: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
    }
    cout << "------------------------------------------" << endl; 
    cout << "[eta values:]" << plotName << endl;
    cout << "------------------------------------------" << endl; 
    for (int j =1 ; j<7; j++){
      if(j == 1) {
         double amount = 0; 
	 //double amounterror = 0; 
      
         for(int k = 0; k< 50; k++) {   
	     amount = amount + histo_eta_jet_30->GetBinContent(k); 
	  //   amounterror = sqrt(amounterror^2 + (histo_eta_jet_30->GetBinError(k))^2);
           //cout << "pt higher then 30: " << histo_eta_jet_30->GetBinContent(k) << " +/- " << histo_eta_jet_30->GetBinError(k) << endl; 
         }
	 
	 cout << "pt higher then 30: " << amount <<  endl;
      
      }
        if(j == 2) {
         double amount = 0; 
	 //double amounterror = 0; 
      
         for(int k = 0; k< 50; k++) {   
	     amount = amount + histo_eta_jet_50->GetBinContent(k); 
	  //   amounterror = sqrt(amounterror^2 + (histo_eta_jet_30->GetBinError(k))^2);
           //cout << "pt higher then 50: " << histo_eta_jet_30->GetBinContent(k) << " +/- " << histo_eta_jet_30->GetBinError(k) << endl; 
         }
	 
	 cout << "pt higher then 50: " << amount <<  endl;
      
      }
      
            if(j == 3) {
         double amount = 0; 
	 //double amounterror = 0; 
      
         for(int k = 0; k< 50; k++) {   
	     amount = amount + histo_eta_jet_70->GetBinContent(k); 
	  //   amounterror = sqrt(amounterror^2 + (histo_eta_jet_30->GetBinError(k))^2);
           //cout << "pt higher then 30: " << histo_eta_jet_30->GetBinContent(k) << " +/- " << histo_eta_jet_30->GetBinError(k) << endl; 
         }
	 
	 cout << "pt higher then 70: " << amount <<  endl;
      
      }
            if(j == 4) {
         double amount = 0; 
	 //double amounterror = 0; 
      
         for(int k = 0; k< 50; k++) {   
	     amount = amount + histo_eta_jet_70->GetBinContent(k); 
	  //   amounterror = sqrt(amounterror^2 + (histo_eta_jet_30->GetBinError(k))^2);
           //cout << "pt higher then 30: " << histo_eta_jet_30->GetBinContent(k) << " +/- " << histo_eta_jet_30->GetBinError(k) << endl; 
         }
	 
	 cout << "pt higher then 70: " << amount <<  endl;
      
      }
            if(j == 5) {
         double amount = 0; 
	 //double amounterror = 0; 
      
         for(int k = 0; k< 50; k++) {   
	     amount = amount + histo_eta_jet_90->GetBinContent(k); 
	  //   amounterror = sqrt(amounterror^2 + (histo_eta_jet_30->GetBinError(k))^2);
           //cout << "pt higher then 30: " << histo_eta_jet_30->GetBinContent(k) << " +/- " << histo_eta_jet_30->GetBinError(k) << endl; 
         }
	 
	 cout << "pt higher then 90: " << amount <<  endl;
      
      }
            if(j == 6) {
         double amount = 0; 
	 //double amounterror = 0; 
      
         for(int k = 0; k< 50; k++) {   
	     amount = amount + histo_eta_jet_110->GetBinContent(k); 
	  //   amounterror = sqrt(amounterror^2 + (histo_eta_jet_30->GetBinError(k))^2);
           //cout << "pt higher then 30: " << histo_eta_jet_30->GetBinContent(k) << " +/- " << histo_eta_jet_30->GetBinError(k) << endl; 
         }
	 
	 cout << "pt higher then 110: " << amount <<  endl;
      
      }
    
    }
    
    
    
    
  }
  f_var.Write();
  f_var.Close();
}
Beispiel #20
0
float CIKJoint::getValueOverLimitation(bool deactivate)
{
	if (!active)
	{ // The case (!active)&&spherical&&topSpherical&&(!sphericalUp) should not return here!
		if (!spherical)
			return(-1.0f); // No limitation violation
		if (!topSpherical)
			return(-1.0f);
		if (sphericalUp)
			return(-1.0f);
	}
	if (spherical)
	{
		if (!topSpherical)
			return(-1.0f);
		if (range>179.9f*degToRad)
			return(-1.0f);
		if (sphericalUp)
		{ // Bottom-up
			if (!parent->active)
				return(-1.0f); // Was already deactivated
			C4Vector rotYm90(C3Vector(0.0f,-piValue/2.0f,0.0f));
			C4Vector tr0(C3Vector(parent->parent->tempParameter,parent->tempParameter,0.0f));
			C4Vector tr(C3Vector(parent->parent->tempParameter+parent->parent->probableDeltaValue,parent->tempParameter+parent->probableDeltaValue,0.0f));
			C4Vector sphericalTr(parent->parent->transformation.Q*rotYm90);
			tr0=sphericalTr*tr0;
			tr=sphericalTr*tr;
			C3X3Matrix m0(tr0.getMatrix());
			C3X3Matrix m(tr.getMatrix());
			C3Vector z0(m0(0,2),m0(1,2),m0(2,2));
			C3Vector z(m(0,2),m(1,2),m(2,2));
			C3Vector zVertical(0.0f,0.0f,1.0f);
			C4Vector zVerticalToZ0(zVertical,z0);
			C4Vector zVerticalToZ(zVertical,z);
			C4Vector angleAndAxis0(zVerticalToZ0.getAngleAndAxis());
			C4Vector angleAndAxis(zVerticalToZ.getAngleAndAxis());
			float p=angleAndAxis(0);
			float deltaV=p-angleAndAxis0(0);
			float tolerance=range*0.0001f;
			bool respected=true;
			if (p>range+tolerance)
			{
				p=range;
				respected=false;
			}
			if (!respected)
			{
				float retVal=fabs((p-angleAndAxis0(0)+deltaV)/deltaV);
				if (deactivate)
				{
					tr.setAngleAndAxis(p,C3Vector(angleAndAxis(1),angleAndAxis(2),angleAndAxis(3)));
					tr=sphericalTr.getInverse()*tr;
					C3Vector euler(tr.getEulerAngles());
					parent->tempParameter=euler(1);
					parent->active=false;
					parent->copyStateToAvatarKids();
					parent->parent->tempParameter=euler(0);
					parent->parent->active=false;
					parent->parent->copyStateToAvatarKids();
					parent->parent->parent->active=true;
					parent->parent->parent->copyStateToAvatarKids();
				}
				return(retVal);
			}
		}
		else
		{ // Top-down
			if (active)
				return(-1.0f); // Was already deactivated
			C4Vector rotY180(C3Vector(0.0f,piValue,0.0f));
			C4Vector rotXm90(C3Vector(-piValue/2.0f,0.0f,0.0f));
			C4Vector rotZ90(C3Vector(0.0f,0.0f,piValue/2.0f));
			C4Vector tr0(C3Vector(parent->tempParameter,parent->parent->tempParameter,0.0f));
			C4Vector tr(C3Vector(parent->tempParameter+parent->probableDeltaValue,parent->parent->tempParameter+parent->parent->probableDeltaValue,0.0f));
			C4Vector sphericalTr((rotZ90*rotXm90*transformation.Q*rotY180).getInverse());
			tr0=sphericalTr*tr0;
			tr=sphericalTr*tr;
			C3X3Matrix m0(tr0.getMatrix());
			C3X3Matrix m(tr.getMatrix());
			C3Vector z0(m0(0,2),m0(1,2),m0(2,2));
			C3Vector z(m(0,2),m(1,2),m(2,2));
			C3Vector zVertical(0.0f,0.0f,1.0f);
			C4Vector zVerticalToZ0(zVertical,z0);
			C4Vector zVerticalToZ(zVertical,z);
			C4Vector angleAndAxis0(zVerticalToZ0.getAngleAndAxis());
			C4Vector angleAndAxis(zVerticalToZ.getAngleAndAxis());
			float p=angleAndAxis(0);
			float deltaV=p-angleAndAxis0(0);
			float tolerance=range*0.0001f;
			bool respected=true;
			if (p>range+tolerance)
			{
				p=range;
				respected=false;
			}
			if (!respected)
			{
				float retVal=fabs((p-angleAndAxis0(0)+deltaV)/deltaV);
				if (deactivate)
				{
					tr.setAngleAndAxis(p,C3Vector(angleAndAxis(1),angleAndAxis(2),angleAndAxis(3)));
					tr=sphericalTr.getInverse()*tr;
					C3Vector euler(tr.getEulerAngles());
					active=true;
					copyStateToAvatarKids();
					parent->tempParameter=euler(0);
					parent->active=false;
					parent->copyStateToAvatarKids();
					parent->parent->tempParameter=euler(1);
					parent->parent->active=false;
					parent->parent->copyStateToAvatarKids();
				}
				return(retVal);
			}
		}
		return(-1.0f);
	}
	else
	{
		float p=tempParameter+probableDeltaValue;
		float tolerance=range*0.0001f;
		bool respected=true;
		if (revolute)
		{
			if ( (range<359.9f*degToRad)&&(!cyclic) )
			{
				if (p<minValue-tolerance)
				{
					p=minValue;
					respected=false;
				}
				else if (p>minValue+range+tolerance)
				{
					p=minValue+range;
					respected=false;
				}
			}
		}
		else
		{
			if (p<minValue-tolerance)
			{
				p=minValue;
				respected=false;
			}
			else if (p>minValue+range+tolerance)
			{
				p=minValue+range;
				respected=false;
			}
		}
		if (!respected)
		{
			float retVal=fabs((p-tempParameter+probableDeltaValue)/probableDeltaValue);
			if (deactivate)
			{
				tempParameter=p;
				active=false;
				copyStateToAvatarKids();
			}
			return(retVal);
		}
		return(-1.0f); // Respected
	}
}
Beispiel #21
0
void looper::myLoop(int nsel, int mode, bool silent)
{

  char plotName[300];
  sprintf(plotName,"test");
  
  if (nsel == 0)                	{sprintf(plotName,"tt");}
  else if (nsel == 1)   		{sprintf(plotName,"twdr");}
  else if (nsel == -1)   		{sprintf(plotName,"twds");}
  else if (nsel == 2)   		{sprintf(plotName,"zjets");}
  else if (nsel == 3)   		{sprintf(plotName,"di");}
  else if (nsel == 4)			{sprintf(plotName, "st");}
  else if (nsel == 5)   		{sprintf(plotName,"wjets");}
  else if (nsel == 6)   		{sprintf(plotName,"qcd_mu");}
  else if (nsel == 7)                	{sprintf(plotName,"others");}
  
  else if (nsel == 555)                	{sprintf(plotName,"mc");}
  
  else if (nsel == 666)                	{sprintf(plotName,"data");}
  
  bool nosf = false;
  
  char newRootFile[300];
  double lumi = luminosity; 
  if (mode == 0 )        lumi = 11966.617; 
  else if ( mode == 1)   lumi = 12067.294;
  else if ( mode == 2)   lumi = 12093.792;
  sprintf(newRootFile,"results/an_%dpb_%d.root", (int)lumi, mode);
 
  TFile f_var(newRootFile, "UPDATE");
  
  if(!silent){
    std::cout << "[Info:] results root file " << newRootFile << std::endl;
  }
  
  
  //////////
  char title[300];
  sprintf(title,"cuts_%s",plotName);
  TH1F* histo = new TH1F( title, " ", 10,  0, 10 );
  histo->Sumw2();
  
  sprintf(title,"met_high_%s",plotName);
  TH1F* histo_met_high = new TH1F( title, " ", 100,  0, 200 );
  histo_met_high->Sumw2();
  
  sprintf(title,"met_low_%s",plotName);
  TH1F* histo_met_low = new TH1F( title, " ", 100,  0, 200 );
  histo_met_low->Sumw2();
  
  sprintf(title,"promet_%s",plotName);
  TH1F* histo_promet = new TH1F( title, " ", 100,  0, 200 );
  histo_promet->Sumw2();
  
  sprintf(title,"met_cut_%s",plotName);
  TH1F* histo_met_cut = new TH1F( title, " ", 100,  0, 200 );
  histo_met_cut->Sumw2();
  
  sprintf(title,"met_bt_%s",plotName);
  TH1F* histo_met_bt = new TH1F( title, " ", 100,  0, 200 );
  histo_met_bt->Sumw2();
  
  sprintf(title,"mll_after_%s",plotName);
  TH1F* histo_mll_after = new TH1F( title, " ", 100,  0, 200 );
  histo_mll_after->Sumw2();
  
  sprintf(title,"njets_cut_%s",plotName);
  TH1F* histo_njets_cut = new TH1F( title, " ", 10,  -0.5, 9.5 );
  histo_njets_cut->Sumw2();
  
  sprintf(title,"njetsbt_cut_%s",plotName);
  TH1F* histo_njetsbt_cut = new TH1F( title, " ", 10,   -0.5, 9.5 );
  histo_njetsbt_cut->Sumw2();
  
  sprintf(title,"njetsbt_high_%s",plotName);
  TH1F* histo_njetsbt_high = new TH1F( title, " ", 10,   -0.5, 9.5 );
  histo_njetsbt_high->Sumw2();
  
  sprintf(title,"njetsbt_low_%s",plotName);
  TH1F* histo_njetsbt_low = new TH1F( title, " ", 10,   -0.5, 9.5 );
  histo_njetsbt_low->Sumw2();
  
  sprintf(title,"njets_high_%s",plotName);
  TH1F* histo_njets_high = new TH1F( title, " ", 10,   -0.5, 9.5 );
  histo_njets_high->Sumw2();
  
  sprintf(title,"njets_low_%s",plotName);
  TH1F* histo_njets_low = new TH1F( title, " ", 10,   -0.5, 9.5 );
  histo_njets_low->Sumw2();
  
  sprintf(title,"ptsys_high_%s",plotName);
  TH1F* histo_ptsys_high = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_high->Sumw2();
  
  sprintf(title,"ptsys_low_%s",plotName);
  TH1F* histo_ptsys_low = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_low->Sumw2();
  
  sprintf(title,"ht_high_%s",plotName);
  TH1F* histo_ht_high = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_high->Sumw2();
  
  sprintf(title,"ht_low_%s",plotName);
  TH1F* histo_ht_low = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_low->Sumw2();
  
  sprintf(title,"ht_cut_%s",plotName);
  TH1F* histo_ht_cut = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_cut->Sumw2();
  
  sprintf(title,"pt_max_%s",plotName);
  TH1F* histo_pt_max = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_max->Sumw2();
  
  sprintf(title,"pt_min_%s",plotName);
  TH1F* histo_pt_min = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_min->Sumw2();
  
  sprintf(title,"btagHE_%s",plotName);
  TH2F* histo_btagHE = new TH2F( title, " ", 300,  -200, 100, 100, -2, 7);
  histo_btagHE->Sumw2();
  
  sprintf(title,"btagHP_%s",plotName);
  TH2F* histo_btagHP = new TH2F( title, " ", 300,  -200, 100, 100, -2, 7);
  histo_btagHP->Sumw2();
  
  sprintf(title,"etalepton_%s",plotName);
  TH1F* histo_etalepton = new TH1F( title, " ", 101,  -3, 3);
  histo_etalepton->Sumw2();
  
  sprintf(title,"ht_bf_%s",plotName);
  TH1F* histo_ht_bf = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_bf->Sumw2();
  
  sprintf(title,"ptsys_bf_%s",plotName);
  TH1F* histo_ptsys_bf = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_bf->Sumw2();
  
  sprintf(title,"npu_%s",plotName);
  TH1F* histo_npu = new TH1F( title, " ", 30,   -0.5, 29.5 );
  histo_npu->Sumw2();
  
  
  /// Classic plotmaker plots
  sprintf(title,"met_%s",plotName);
  TH1F* histo_met = new TH1F( title, " ", 100,  0, 200 );
  histo_met->Sumw2();
  
  sprintf(title,"mll_%s",plotName);
  TH1F* histo_mll = new TH1F( title, " ", 100,  0, 200 );
  histo_mll->Sumw2();
  
  sprintf(title,"njets_%s",plotName);
  TH1F* histo_njets = new TH1F( title, " ", 10,  0, 10 );
  histo_njets->Sumw2();
  
  sprintf(title,"njetsbt_%s",plotName);
  TH1F* histo_njetsbt = new TH1F( title, " ", 10,  -0.5, 9.5 );
  histo_njetsbt->Sumw2();
  
  sprintf(title,"ptsys_%s",plotName);
  TH1F* histo_ptsys = new TH1F( title, " ", 200,  0, 200 );
  histo_ptsys->Sumw2();
  
  sprintf(title,"ht_%s",plotName);
  TH1F* histo_ht = new TH1F( title, " ", 300,  0, 600 );
  histo_ht->Sumw2();
  
  sprintf(title,"pt_leading_%s",plotName);
  TH1F* histo_pt_leading = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_leading->Sumw2();
  
  sprintf(title,"nvertex_%s",plotName);
  TH1F* histo_nvertex = new TH1F( title, " ", 70,   -0.5, 69.5 );
  histo_nvertex->Sumw2();
  
  sprintf(title,"nloosejets_%s",plotName);
  TH1F* histo_nloosejets = new TH1F( title, " ", 10,  -0.5, 9.5 );
  histo_nloosejets->Sumw2();
  
  sprintf(title,"nloosejets_bt_%s",plotName);
  TH1F* histo_nloosejets_bt = new TH1F( title, " ", 10,  -0.5, 9.5 );
  histo_nloosejets_bt->Sumw2();
 
  
  // 1 jet level
  /// Classic plotmaker plots
  sprintf(title,"met_1j_%s",plotName);
  TH1F* histo_met_1j = new TH1F( title, " ", 100,  0, 200 );
  histo_met_1j->Sumw2();
  
  sprintf(title,"mll_1j_%s",plotName);
  TH1F* histo_mll_1j = new TH1F( title, " ", 100,  0, 200 );
  histo_mll_1j->Sumw2();
  
  sprintf(title,"ptsys_1j_%s",plotName);
  TH1F* histo_ptsys_1j = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_1j->Sumw2();
  
  sprintf(title,"ht_1j_%s",plotName);
  TH1F* histo_ht_1j = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_1j->Sumw2();
  
  sprintf(title,"pt_leading_1j_%s",plotName);
  TH1F* histo_pt_leading_1j = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_leading_1j->Sumw2();
  
  sprintf(title,"nvertex_1j_%s",plotName);
  TH1F* histo_nvertex_1j = new TH1F( title, " ", 30,   -0.5, 29.5 );
  histo_nvertex_1j->Sumw2();
  
  // 1 jet level
  /// Classic plotmaker plots
  sprintf(title,"met_1j1t_%s",plotName);
  TH1F* histo_met_1j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_met_1j1t->Sumw2();
  
  sprintf(title,"mll_1j1t_%s",plotName);
  TH1F* histo_mll_1j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_mll_1j1t->Sumw2();
  
  sprintf(title,"ptsys_1j1t_%s",plotName);
  TH1F* histo_ptsys_1j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_ptsys_1j1t->Sumw2();
  
  sprintf(title,"ht_1j1t_%s",plotName);
  TH1F* histo_ht_1j1t = new TH1F( title, " ", 200,  0, 200 );
  histo_ht_1j1t->Sumw2();
  
  sprintf(title,"pt_leading_1j1t_%s",plotName);
  TH1F* histo_pt_leading_1j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_leading_1j1t->Sumw2();
  
  sprintf(title,"nvertex_1j1t_%s",plotName);
  TH1F* histo_nvertex_1j1t = new TH1F( title, " ", 30,   -0.5, 29.5 );
  histo_nvertex_1j1t->Sumw2();
  
  
  // 2j1t
  /// Classic plotmaker plots
  sprintf(title,"met_2j1t_%s",plotName);
  TH1F* histo_met_2j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_met_2j1t->Sumw2();
  
  sprintf(title,"mll_2j1t_%s",plotName);
  TH1F* histo_mll_2j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_mll_2j1t->Sumw2();
  
  sprintf(title,"ptsys_2j1t_%s",plotName);
  TH1F* histo_ptsys_2j1t = new TH1F( title, " ", 200,  0, 200 );
  histo_ptsys_2j1t->Sumw2();
  
  sprintf(title,"ht_2j1t_%s",plotName);
  TH1F* histo_ht_2j1t = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_2j1t->Sumw2();
  
  sprintf(title,"pt_leading_2j1t_%s",plotName);
  TH1F* histo_pt_leading_2j1t = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_leading_2j1t->Sumw2();
  
  sprintf(title,"nvertex_2j1t_%s",plotName);
  TH1F* histo_nvertex_2j1t = new TH1F( title, " ", 30,   -0.5, 29.5 );
  histo_nvertex_2j1t->Sumw2();
  
  
  // 2j2t
  /// Classic plotmaker plots
  sprintf(title,"met_2j2t_%s",plotName);
  TH1F* histo_met_2j2t = new TH1F( title, " ", 100,  0, 200 );
  histo_met_2j2t->Sumw2();
  
  sprintf(title,"mll_2j2t_%s",plotName);
  TH1F* histo_mll_2j2t = new TH1F( title, " ", 100,  0, 200 );
  histo_mll_2j2t->Sumw2();
  
  sprintf(title,"ptsys_2j2t_%s",plotName);
  TH1F* histo_ptsys_2j2t = new TH1F( title, " ", 300,  0, 600 );
  histo_ptsys_2j2t->Sumw2();
  
  sprintf(title,"ht_2j2t_%s",plotName);
  TH1F* histo_ht_2j2t = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_2j2t->Sumw2();
  
  sprintf(title,"pt_leading_2j2t_%s",plotName);
  TH1F* histo_pt_leading_2j2t = new TH1F( title, " ", 100,  0, 200 );
  histo_pt_leading_2j2t->Sumw2();
  
  sprintf(title,"nvertex_2j2t_%s",plotName);
  TH1F* histo_nvertex_2j2t = new TH1F( title, " ", 30,   -0.5, 29.5 );
  histo_nvertex_2j2t->Sumw2();

  
  // all regions
  sprintf(title,"R_%s",plotName);
  TH1F* histo_R = new TH1F( title, " ", 40,  0, 40 );
  histo_R->Sumw2();
  
  
  sprintf(title,"nvertex_2lep_%s",plotName);
  TH1F* histo_nvertex_2lep = new TH1F( title, " ", 70,   -0.5, 69.5 );
  histo_nvertex_2lep->Sumw2();


  // Test jets
  sprintf(title,"ht_2j1t_leading_%s",plotName);
  TH1F* histo_ht_2j1t_leading = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_2j1t_leading->Sumw2();
  
  sprintf(title,"ht_2j1t_all_%s",plotName);
  TH1F* histo_ht_2j1t_all = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_2j1t_all->Sumw2();
  
  sprintf(title,"ht_2j2t_leading_%s",plotName);
  TH1F* histo_ht_2j2t_leading = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_2j1t_leading->Sumw2();
  
  sprintf(title,"ht_2j2t_all_%s",plotName);
  TH1F* histo_ht_2j2t_all = new TH1F( title, " ", 300,  0, 600 );
  histo_ht_2j2t_all->Sumw2();
  
  sprintf(title,"ptsys_2j1t_leading_%s",plotName);
  TH1F* histo_ptsys_2j1t_leading = new TH1F( title, " ", 200,  0, 200 );
  histo_ptsys_2j1t_leading->Sumw2();
  
  sprintf(title,"ptsys_2j1t_all_%s",plotName);
  TH1F* histo_ptsys_2j1t_all = new TH1F( title, " ", 200,  0, 200 );
  histo_ptsys_2j1t_all->Sumw2();
  
  sprintf(title,"ptsys_2j2t_leading_%s",plotName);
  TH1F* histo_ptsys_2j2t_leading = new TH1F( title, " ", 200,  0, 200 );
  histo_ptsys_2j1t_leading->Sumw2();
  
  sprintf(title,"ptsys_2j2t_all_%s",plotName);
  TH1F* histo_ptsys_2j2t_all = new TH1F( title, " ", 200,  0, 200 );
  histo_ptsys_2j2t_all->Sumw2();



  if (fChain == 0) return;
  
  Long64_t nentries = fChain->GetEntriesFast();
  
  Long64_t nbytes = 0, nb = 0;
  for (Long64_t jentry=0; jentry<nentries;jentry++) {
    
    
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    
    
    if (lumi != lum && nsel != 666 && mode !=3){
      if (jentry == 0)std::cout << "[Warning:] This tree was made with a different luminosity (" << lum << ") than " << lumi << std::endl;
      //xlWeight*=(lumi/lum);
    }
    
    if(ptLepton->size() != 2){
      std::cout << "[Warning:] Something is wrong, your Tree is not correctly filled" << std::endl;
      break;
    } else {
      histo->Fill(0.,xlWeight);
      histo_nvertex_2lep->Fill(nvertex,xlWeight);
      TLorentzVector lepton0(pxLepton->at(0),pyLepton->at(0), pzLepton->at(0), eLepton->at(0));
      TLorentzVector lepton1(pxLepton->at(1),pyLepton->at(1), pzLepton->at(1), eLepton->at(1)); 
      TLorentzVector pair = lepton0+lepton1;
      
      //if (ptLepton->at(0) < 40 && ptLepton->at(1) < 40) continue;
       if(ptLepton->at(0) < 30 || ptLepton->at(1) < 30)continue;
      
      double phipairmet_t = 0;
      double pi_m = 3.1416/2;
      phipairmet_t = pi_m;
      
      TVector3 vmet(metPx, metPy, 0);
      
      double promet = metPt*sin(phipairmet_t);
      TVector3 m0(pxLepton->at(0),pyLepton->at(0), pzLepton->at(0));
      TVector3 m1(pxLepton->at(1),pyLepton->at(1), pzLepton->at(1)); 
      if (fabs(m0.DeltaPhi(vmet)) < phipairmet_t) phipairmet_t = fabs(m0.DeltaPhi(vmet));
      if (fabs(m1.DeltaPhi(vmet)) < phipairmet_t) phipairmet_t = fabs(m1.DeltaPhi(vmet));
      
      if (phipairmet_t == pi_m) promet = metPt;
      
      if (pair.M() > 20){
	histo->Fill(1, xlWeight);

	double SFval, SFerror;
	if ( nsel == 666 || nosf){
	  SFval = 1;
	  SFerror = 0;
	} else if (nsel == 0){
	  SFval = 0.95;
	  SFerror = 0.03;
	} else {
	  SFval = 0.97;
	  SFerror = 0.03;
	}
	
	
	int nJetsBT = 0;
	int nTightJetsBT = 0;
	int nJets = 0;
	bool bTagged = false;
	int iJet = -5;
	int iSF;
	double tempSF = SFval;
	int iLead = -5;
	
	int SFvalue = int(tempSF*100);
	int nloose = 0;
	int nloosebt = 0;
	
	for (unsigned int i =0; i < ptJet->size(); i ++){ 
	  TLorentzVector tempJet(pxJet->at(i),pyJet->at(i), pzJet->at(i), eJet->at(i));
	  if (ptJet->at(i) > 30 && fabs(tempJet.Eta()) < 2.5 && TMath::Min(fabs(lepton0.DeltaR(tempJet)), fabs(lepton1.DeltaR(tempJet))) > 0.3) {
	    nJets++;
	    iJet = i;
	    if (iLead == -5) iLead = iJet;
	    if (btCSVBJet->at(i) > 0.679){
	      iSF = rand() % 100;
	      if (iSF < SFvalue ){
		bTagged = true;
		nJetsBT++;
		nTightJetsBT++;
	      } 
	    } 
	  } else if (btCSVBJet->at(i) > 0.679 && fabs(tempJet.Eta()) < 2.5){
	    iSF = rand() % 100;
	    if (iSF < SFvalue ){ nJetsBT++; nloosebt++;}
	  }
	  
	  if (ptJet->at(i) <= 30 || fabs(tempJet.Eta()) >= 2.5) nloose++;
	}
	
	histo_nloosejets->Fill(nloose, xlWeight);
	histo_nloosejets_bt->Fill(nloosebt, xlWeight);

	histo_pt_max->Fill(TMath::Max(lepton0.Pt(), lepton1.Pt()), xlWeight);
	histo_pt_min->Fill(TMath::Min(lepton0.Pt(), lepton1.Pt()), xlWeight);
	histo_njets->Fill(nJets,  xlWeight);
	histo_njetsbt->Fill(nJetsBT,  xlWeight);
	histo_mll->Fill(pair.M(),  xlWeight);
	histo_met->Fill(metPt,  xlWeight);
	histo_promet->Fill(promet, xlWeight);
	
	if (nvertex > 5){
	  histo_met_high->Fill(metPt,  xlWeight);
	  histo_njets_high->Fill(nJets,  xlWeight);
	  histo_njetsbt_high->Fill(nJetsBT,  xlWeight);
	} else {
	  histo_met_low->Fill(metPt,  xlWeight);
	  histo_njets_low->Fill(nJets,  xlWeight);
	  histo_njetsbt_low->Fill(nJetsBT,  xlWeight);  
	}
	
	if (nJets) histo_pt_leading->Fill(ptJet->at(0), xlWeight);
	if (nJets == 1){
	  histo_etalepton->Fill(lepton0.Eta(), xlWeight);
	  TLorentzVector jet(pxJet->at(iJet),pyJet->at(iJet), pzJet->at(iJet), eJet->at(iJet));
	   
	  double ptSysPx1 = lepton0.Px() + lepton1.Px() + jet.Px() + metPx;
	  double ptSysPy1 = lepton0.Py() + lepton1.Py() + jet.Py() + metPy;
	  double ptSystem1 = sqrt(ptSysPx1*ptSysPx1 + ptSysPy1*ptSysPy1);
	  double ht1 = lepton0.Pt() + lepton1.Pt() + jet.Pt() + metPt; 
	  histo_ptsys_bf->Fill(ptSystem1, xlWeight);
	  histo_ht_bf->Fill(ht1, xlWeight);
	}
	bool invMass = false;
	if      (mode == 0) invMass = true;
	else if (mode == 1  && (pair.M() > invMax || pair.M() < invMin)) invMass = true;
	else if (mode == 2 && (pair.M() > invMax || pair.M() < invMin)) invMass = true;
	

	if (invMass){
	  histo->Fill(2, xlWeight);
	  histo_mll_after->Fill(pair.M(),  xlWeight);
	  histo_met_cut->Fill(metPt,  xlWeight);
	  if (metPt >= metCut || mode ==0){
	   
	    histo->Fill(3, xlWeight);
	    histo_njets_cut->Fill(nJets, xlWeight);
	    if (nJets == 1){
	      histo->Fill(4, xlWeight);
	      histo_njetsbt_cut->Fill(nJetsBT, xlWeight);
	      TLorentzVector jet(pxJet->at(iJet),pyJet->at(iJet), pzJet->at(iJet), eJet->at(iJet));
		
	      double ptSysPx = lepton0.Px() + lepton1.Px() + jet.Px() + metPx;
	      double ptSysPy = lepton0.Py() + lepton1.Py() + jet.Py() + metPy;
	      double ptSystem = sqrt(ptSysPx*ptSysPx + ptSysPy*ptSysPy);
	      double ht = lepton0.Pt() + lepton1.Pt() + jet.Pt() + metPt; 
	      
	      histo_mll_1j->Fill(pair.M(),  xlWeight);
	      histo_met_1j->Fill(metPt,  xlWeight);
	      histo_ptsys_1j->Fill(ptSystem, xlWeight);
	      histo_ht_1j->Fill(ht, xlWeight);
	      histo_pt_leading_1j->Fill(jet.Pt(), xlWeight);
	      
	      
	      if (nJets == 1 && nTightJetsBT == 1 && bTagged && nJetsBT == 1){
		histo->Fill(5, xlWeight);
		
	      
	        histo_mll_1j1t->Fill(pair.M(),  xlWeight);
	        histo_met_1j1t->Fill(metPt,  xlWeight);
	        histo_ptsys_1j1t->Fill(ptSystem, xlWeight);
	        histo_ht_1j1t->Fill(ht, xlWeight);
	        histo_pt_leading_1j1t->Fill(jet.Pt(), xlWeight);
	      
		histo_ptsys->Fill(ptSystem, xlWeight);
		histo_ht->Fill(ht, xlWeight);
		
		histo_met_bt->Fill(metPt, xlWeight);
		
		histo_nvertex->Fill(nvertex, xlWeight);
		histo_npu->Fill(npu, xlWeight);
		
		if (nvertex > 5) {
		  histo_ptsys_high->Fill(ptSystem, xlWeight);
		  histo_ht_high->Fill(ht, xlWeight);
		} else {
		  histo_ptsys_low->Fill(ptSystem, xlWeight);
		  histo_ht_low->Fill(ht, xlWeight);
		  
		}
		
		if (ht > htMin || mode !=0){
		  histo->Fill(6, xlWeight);
		  histo_ht_cut->Fill(ht, xlWeight);
		 
		  
		}
	      }
	    }
	  }
	  
	  
	  //Filling of all region from here
	  if (metPt >= metCut || mode ==0){
	
	    if (nJets != 0){
	      
	      TLorentzVector jet(pxJet->at(iJet),pyJet->at(iJet), pzJet->at(iJet), eJet->at(iJet));
	      
	      double ptSysPx = lepton0.Px() + lepton1.Px() + jet.Px() + metPx;
	      double ptSysPy = lepton0.Py() + lepton1.Py() + jet.Py() + metPy;
	      double ptSystem = sqrt(ptSysPx*ptSysPx + ptSysPy*ptSysPy);
	      double ht = lepton0.Pt() + lepton1.Pt() + jet.Pt() + metPt; 
	      
	      if (nJets == 2 && nTightJetsBT == 1 && nJetsBT == 1) {
	        histo_mll_2j1t->Fill(pair.M(),  xlWeight);
	        histo_met_2j1t->Fill(metPt,  xlWeight);
	        histo_ptsys_2j1t->Fill(ptSystem, xlWeight);
	        histo_ht_2j1t->Fill(ht, xlWeight);
	        histo_pt_leading_2j1t->Fill(jet.Pt(), xlWeight);
		TLorentzVector jet2(pxJet->at(iLead),pyJet->at(iLead), pzJet->at(iLead), eJet->at(iLead));
		double htled = lepton0.Pt() + lepton1.Pt() + jet2.Pt() + metPt; 
		histo_ht_2j1t_leading->Fill(htled, xlWeight);
		double htall = lepton0.Pt() + lepton1.Pt() + jet.Pt() + jet2.Pt() + metPt; 
		histo_ht_2j1t_all->Fill(htall, xlWeight);
		
		 
		double ptSysPxled = lepton0.Px() + lepton1.Px() + jet2.Px() + metPx;
		double ptSysPyled = lepton0.Py() + lepton1.Py() + jet2.Py() + metPy;
		double ptSystemled = sqrt(ptSysPxled*ptSysPxled + ptSysPyled*ptSysPyled);
	      	histo_ptsys_2j1t_leading->Fill(ptSystemled, xlWeight);
		
		double ptSysPxall = lepton0.Px() + lepton1.Px() + jet.Px() + jet2.Px() + metPx;
		double ptSysPyall = lepton0.Py() + lepton1.Py() + jet.Py() + jet2.Py() + metPy;
		double ptSystemall = sqrt(ptSysPxall*ptSysPxall + ptSysPyall*ptSysPyall);
	      	histo_ptsys_2j1t_all->Fill(ptSystemall, xlWeight);
		
		
		
		
		
		
	      } else if (nJets == 2 && nTightJetsBT == 2 && nJetsBT == 2)  {
	        histo_mll_2j2t->Fill(pair.M(),  xlWeight);
	        histo_met_2j2t->Fill(metPt,  xlWeight);
	        histo_ptsys_2j2t->Fill(ptSystem, xlWeight);
	        histo_ht_2j2t->Fill(ht, xlWeight);
	        histo_pt_leading_2j2t->Fill(jet.Pt(), xlWeight);
		TLorentzVector jet2(pxJet->at(iLead),pyJet->at(iLead), pzJet->at(iLead), eJet->at(iLead));
		double htled = lepton0.Pt() + lepton1.Pt() + jet2.Pt() + metPt; 
		histo_ht_2j2t_leading->Fill(htled, xlWeight);
		double htall = lepton0.Pt() + lepton1.Pt() + jet.Pt() + jet2.Pt() + metPt; 
		histo_ht_2j2t_all->Fill(htall, xlWeight);    
	
	
	
		double ptSysPxled = lepton0.Px() + lepton1.Px() + jet2.Px() + metPx;
		double ptSysPyled = lepton0.Py() + lepton1.Py() + jet2.Py() + metPy;
		double ptSystemled = sqrt(ptSysPxled*ptSysPxled + ptSysPyled*ptSysPyled);
	      	histo_ptsys_2j2t_leading->Fill(ptSystemled, xlWeight);
		
		double ptSysPxall = lepton0.Px() + lepton1.Px() + jet.Px() + jet2.Px() + metPx;
		double ptSysPyall = lepton0.Py() + lepton1.Py() + jet.Py() + jet2.Py() + metPy;
		double ptSystemall = sqrt(ptSysPxall*ptSysPxall + ptSysPyall*ptSysPyall);
	      	histo_ptsys_2j2t_all->Fill(ptSystemall, xlWeight);
		
		
		
		
		
		
	      }
	      
	      
	   
		  
	      //All possible regions
	      if (nJets == 1 && nTightJetsBT == 1 && bTagged && nJetsBT == 1 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))histo_R->Fill(1, xlWeight); //signal
	      if (nJets == 1 && nTightJetsBT == 2)  histo_R->Fill(2, xlWeight);
	      if (nJets == 1 && nTightJetsBT > 0)  histo_R->Fill(3, xlWeight);
	      if (nJets == 1 && nTightJetsBT > 1)  histo_R->Fill(4, xlWeight);
	      if (nJets == 2 && nTightJetsBT == 0)  histo_R->Fill(5, xlWeight);
	      if (nJets == 2 && nTightJetsBT == 1)  histo_R->Fill(6, xlWeight); //CR1 no ht no ptsys
	      if (nJets == 2 && nTightJetsBT == 2)  histo_R->Fill(7, xlWeight); //CR2 no ht no ptsys
	      if (nJets == 2 && nTightJetsBT > 0)  histo_R->Fill(8, xlWeight);
	      if (nJets == 2 && nTightJetsBT > 1)  histo_R->Fill(9, xlWeight);
	      if (nJets > 1 && nTightJetsBT == 0)  histo_R->Fill(10, xlWeight);
	      if (nJets > 1 && nTightJetsBT == 1)  histo_R->Fill(11, xlWeight);
	      if (nJets > 1 && nTightJetsBT == 2)  histo_R->Fill(12, xlWeight);
	      if (nJets > 1 && nTightJetsBT !=0 )  histo_R->Fill(13, xlWeight);
	      if (nJets > 1 && nTightJetsBT > 1 )  histo_R->Fill(14, xlWeight);
	      if (nJets == 3 && nTightJetsBT ==3 )  histo_R->Fill(15, xlWeight);
	      if (nJets == 1 && nTightJetsBT ==1 && bTagged && nJetsBT == 1)  histo_R->Fill(16, xlWeight);
	      if (nJets == 2 && nTightJetsBT == 1 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(17, xlWeight); //CR 1 regular
	      if (nJets == 2 && nTightJetsBT == 2 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(18, xlWeight); //CR 2 regular
	      if (nJets == 2 && nTightJetsBT == 1 && nJetsBT == 1 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(19, xlWeight);
	      if (nJets == 2 && nTightJetsBT == 2 && nJetsBT == 2 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(20, xlWeight);
	      if (nJets == 2 && nJetsBT == 1 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(21, xlWeight); //CR 1 another way
	      if (nJets == 2 && nJetsBT == 2 && ptSystem <= ptsysCut && (ht > htMin || mode !=0))  histo_R->Fill(22, xlWeight); //CR 2 another way
	      if (nJets == 2 && nTightJetsBT == 1 && nJetsBT == 1)  histo_R->Fill(23, xlWeight); //CR1 no ht no ptsys tighter
	      if (nJets == 2 && nTightJetsBT == 2 && nJetsBT == 2)  histo_R->Fill(24, xlWeight); //CR2 no ht no ptsys tighter
	      if (nJets == 2 && nJetsBT == 1)  histo_R->Fill(25, xlWeight); //CR1 no ht no ptsys another flavor
	      if (nJets == 2 && nJetsBT == 2)  histo_R->Fill(26, xlWeight); //CR2 no ht no ptsys another flavor
	      if (nJets == 1 && nTightJetsBT == 1 && bTagged && nJetsBT == 1 && (ht > htMin || mode !=0))histo_R->Fill(27, xlWeight); //signal no ptsys
	      if (nJets == 1 && nTightJetsBT == 1 && bTagged && nJetsBT == 1 && ptSystem <= ptsysCut)histo_R->Fill(28, xlWeight); //signal no ht
	      if (nJets == 2 && nTightJetsBT == 1 &&  (ht > htMin || mode !=0))  histo_R->Fill(29, xlWeight); //CR 1 
	      if (nJets == 2 && nTightJetsBT == 2 &&  (ht > htMin || mode !=0))  histo_R->Fill(30, xlWeight); //CR 2 
				
	      
	    } //jets in the event
	  } //all CR
	  
	} // mll
      } //mll pre
    } // 2 leptons
  }// event loop.
  
  
  
  if (!silent){ 
    cout << "------------------------------------------" << endl;
    cout << "[Results:] " << plotName <<  endl;
    cout << "------------------------------------------" << endl;  
    for (int i = 2; i < 9; i++){
      if (i == 2) cout << " leptons: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
      if (i == 3) cout << " inv. mass: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
      if (i == 4) cout << " met: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
      if (i == 5) cout << " jet: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
      if (i == 6) cout << " jet_bt: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
      if (i == 7) cout << " ht: " <<  histo->GetBinContent(i) << " +/-  " <<  histo->GetBinError(i)  << endl;
    }
    cout << "------------------------------------------" << endl; 
  }
  f_var.Write();
  f_var.Close();
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
    // trw_bprop_helper2(model, psi_ij_rho, psi_i, rho, maxiter, n, m1, m2, b_i,...
    //                   dm1, dm2, dn, dpsi_i, dpsi_ij);

    int i=0;
    int nnodes     = mapdouble(mxGetField(prhs[i],0,"nnodes"))(0);
    int ncliques   = mapdouble(mxGetField(prhs[i],0,"ncliques"))(0);
    int nvals      = mapdouble(mxGetField(prhs[i],0,"nvals"))(0);
    MatrixXi pairs = mapdouble(mxGetField(prhs[i],0,"pairs")).cast<int>();
    pairs.array() -= 1;
    MatrixXi N1   = mapdouble(mxGetField(prhs[i],0,"N1")).cast<int>();
    N1.array() -= 1;
    MatrixXi N2   = mapdouble(mxGetField(prhs[i],0,"N2")).cast<int>();
    N2.array() -= 1;
    MatrixXi tree2clique  = mapdouble(mxGetField(prhs[i],0,"tree2clique")).cast<int>();
    tree2clique.array() -= 1;
    MatrixXi treeschedule = mapdouble(mxGetField(prhs[i],0,"treeschedule")).cast<int>();
    treeschedule.array() -= 1;
    i++;

    MatrixMd psi_ij  = mapdouble(prhs[i++]);
    MatrixMd psi_i   = mapdouble(prhs[i++]);
    double rho       = mapdouble(prhs[i++])(0);
    int maxiter      = mapdouble(prhs[i++])(0);
    MatrixMd n       = mapdouble(prhs[i++]);
    MatrixMd m1      = mapdouble(prhs[i++]);
    MatrixMd m2      = mapdouble(prhs[i++]);
    MatrixMd b_i     = mapdouble(prhs[i++]);
    MatrixMd mstor   = mapdouble(prhs[i++]);
    MatrixMd dm1     = mapdouble(prhs[i++]);
    MatrixMd dm2     = mapdouble(prhs[i++]);
    MatrixMd dn      = mapdouble(prhs[i++]);
    MatrixMd dpsi_i  = mapdouble(prhs[i++]);
    MatrixMd dpsi_ij = mapdouble(prhs[i++]);
    MatrixMd b_ij0   = mapdouble(prhs[i++]);
    MatrixMd db_ij0  = mapdouble(prhs[i++]);
    int dorec        = mapdouble(prhs[i++]).cast<int>()(0);

    MatrixMi w      = mapint32(prhs[i++]);

    #pragma omp parallel for num_threads(NTHREAD)
    for(int c=0; c<ncliques; c++) {
        int i = pairs(c, 0);
        int j = pairs(c, 1);
        for(int yi=0; yi<nvals; yi++) {
            for(int yj=0; yj<nvals; yj++) {
                int index = yi + yj*nvals;
                //b_ij0(index,c) = b_ij0(index,c)*psi_i(yi,i)*psi_i(yj,j)*n(yi,i)*n(yj,j)/m1(yi,c)/m2(yj,c);
                dpsi_i(yi, i) = dpsi_i(yi, i) + db_ij0(index, c)*b_ij0(index, c)/psi_i(yi, i);
                dpsi_i(yj, j) = dpsi_i(yj, j) + db_ij0(index, c)*b_ij0(index, c)/psi_i(yj, j);
                dn(yi, i)     = dn(yi, i)     + db_ij0(index, c)*b_ij0(index, c)/n(yi, i);
                dn(yj, j)     = dn(yj, j)     + db_ij0(index, c)*b_ij0(index, c)/n(yj, j);
                dm1(yi, c)    = dm1(yi, c)    - db_ij0(index, c)*b_ij0(index, c)/m1(yi, c);
                dm2(yj, c)    = dm2(yj, c)    - db_ij0(index, c)*b_ij0(index, c)/m2(yj, c);
            }
        }
    }

    #pragma omp parallel for num_threads(NTHREAD)
    for(int i=0; i<b_i.cols(); i++) {
        for(int yi=0; yi<nvals; yi++) {
            for(int k=0; k<N1.cols(); k++) {
                int d = N1(i, k);
                if(d==-2) continue;
                //n(yi, i) *= m1(yi, d);
                dm1(yi,d) += rho * dn(yi,i)*n(yi,i)/m1(yi,d);
            }
            for(int k=0; k<N2.cols(); k++) {
                int d = N2(i, k);
                if(d==-2) continue;
                //n(yi, i) *= m2(yi, d);
                dm2(yi,d) += rho * dn(yi,i)*n(yi,i)/m2(yi,d);
            }
        }
    }

    //tree_ncliques = sum(double(model.tree2clique>0),1);
    //ntree = length(tree_ncliques);
    int ntree = tree2clique.cols();
    MatrixXi tree_ncliques = MatrixXi::Zero(ntree,1);
    for(int tree=0; tree<tree2clique.cols(); tree++)
        for(i=0; i<tree2clique.rows(); i++)
            if(tree2clique(i,tree) != -1)
                tree_ncliques(tree)++;

    int reps;
    double conv;
    for(reps=0; reps<maxiter; reps++) {
        // must re-order blocks
        //for(int block=0; block<treeschedule.cols(); block++){
        for(int block=treeschedule.cols()-1; block>=0; block--) {
            // need not re-order trees, but why not...
            // helps if someone specifies not parallel trees
            // for(int treenum=treeschedule.rows()-1; treenum>=0; treenum--){
            #pragma omp parallel for schedule(dynamic) num_threads(NTHREAD)
            for(int treenum=0; treenum<treeschedule.rows(); treenum++) {
                MatrixXd S (nvals,nvals);
                MatrixXd m0(nvals,1);

                int tree = treeschedule(treenum,block);
                if(tree==-1)
                    continue;
                int ncliques = tree_ncliques(tree);

                for(int c0=2*ncliques-1; c0>=0; c0--) {
                    int c, mode;
                    if(c0<ncliques) {
                        c    = tree2clique(c0,tree);
                        mode = 1;
                    } else {
                        c    = tree2clique(ncliques - 1 - (c0-ncliques),tree);
                        mode = 2;
                    }

                    //cout << "BW c " << c << " mode " << mode << endl;

                    int i = pairs(c,0);
                    int j = pairs(c,1);

                    if( mode==1 ) {

                        for(int yi=0; yi<nvals; yi++)
                            n(yi, i) = 1;
                        for(int k=0; k<N1.cols(); k++) {
                            int d = N1(i, k);
                            if(d==-2) continue;
                            for(int yi=0; yi<nvals; yi++)
                                n(yi, i) *= m1(yi, d);
                        }
                        for(int k=0; k<N2.cols(); k++) {
                            int d = N2(i, k);
                            if(d==-2) continue;
                            for(int yi=0; yi<nvals; yi++)
                                n(yi, i) *= m2(yi, d);
                        }
                        // n.col(i) = n.col(i).array().pow(rho);
                        if(rho==1) {
                            //nothing
                        } else if(rho==.5) {
                            n.col(i) = n.col(i).array().sqrt();
                        } else
                            n.col(i) = n.col(i).array().pow(rho);

                        // compute m(y_j)
                        for(int yj=0; yj<nvals; yj++) {
                            m0(yj) = 0;
                            for(int yi=0; yi<nvals; yi++) {
                                int index = yi + yj*nvals;
                                S(yi,yj)  = psi_ij(index, c)*psi_i(yi, i)*n(yi, i)/m1(yi, c);
                                m0(yj)   += S(yi,yj);
                            }
                        }

                        double k = S.sum();

                        MatrixXd dm0 = dm2.col(c)/k;
                        dm0.array() -= (dm2.col(c).array()*m0.array()).sum()/(k*k);

                        MatrixXd dn  = 0*n.col(i);

                        for(int yj=0; yj<nvals; yj++) {
                            for(int yi=0; yi<nvals; yi++) {
                                int index = yi + yj*nvals;
                                dpsi_ij(index,c) += dm0(yj)*S(yi,yj)/psi_ij(index,c);
                                dpsi_i(yi,i)     += dm0(yj)*S(yi,yj)/psi_i(yi,i);
                                dn(yi)           += dm0(yj)*S(yi,yj)/n(yi,i);
                                dm1(yi,c)        -= dm0(yj)*S(yi,yj)/m1(yi,c);
                            }
                        }

                        for(int yi=0; yi<nvals; yi++) {
                            for(int k=0; k<N1.cols(); k++) {
                                int d = N1(i, k);
                                if(d==-2) continue;
                                dm1(yi,d) += rho*dn(yi)*n(yi,i)/m1(yi,d);
                            }
                            for(int k=0; k<N2.cols(); k++) {
                                int d = N2(i, k);
                                if(d==-2) continue;
                                dm2(yi,d) += rho*dn(yi)*n(yi,i)/m2(yi,d);
                            }
                        }
                        dm2.col(c) *= 0.0;
                        if( dorec )
                            for(int yj=nvals-1; yj>=0; yj--) {
                                w(tree)=w(tree)-1;
                                m2(yj,c)=mstor(w(tree),tree);
                            }
                    } else if( mode==2 ) {
                        for( int yj=0; yj<nvals; yj++)
                            n(yj, j) = 1;
                        for(int k=0; k<N1.cols(); k++) {
                            int d = N1(j, k);
                            if(d==-2) continue;
                            for( int yj=0; yj<nvals; yj++)
                                n(yj, j) *= m1(yj, d);
                        }
                        for(int k=0; k<N2.cols(); k++) {
                            int d = N2(j, k);
                            if(d==-2) continue;
                            for( int yj=0; yj<nvals; yj++)
                                n(yj, j) *= m2(yj, d);
                        }

//                n.col(j) = n.col(j).array().pow(rho);
                        if(rho==1) {
                            //nothing
                        } else if(rho==.5) {
                            n.col(j) = n.col(j).array().sqrt();
                        } else
                            n.col(j) = n.col(j).array().pow(rho);


                        for(int yi=0; yi<nvals; yi++) {
                            m0(yi) = 0;
                            for(int yj=0; yj<nvals; yj++) {
                                int index = yi + yj*nvals;
                                S(yi,yj)  = psi_ij(index, c)*psi_i(yj, j)*n(yj, j)/m2(yj, c);
                                m0(yi)   += S(yi,yj);
                            }
                        }
                        double k = S.sum();

                        MatrixXd dm0 = dm1.col(c)/k;
                        dm0.array() -= (dm1.col(c).array()*m0.array()).sum()/(k*k);
                        MatrixXd dn  = 0*n.col(i);

                        for(int yj=0; yj<nvals; yj++) {
                            for(int yi=0; yi<nvals; yi++) {
                                int index = yi + yj*nvals;
                                dpsi_ij(index,c) += dm0(yi)*S(yi,yj)/psi_ij(index,c);
                                dpsi_i(yj,j)     += dm0(yi)*S(yi,yj)/psi_i(yj,j);
                                dn(yj)           += dm0(yi)*S(yi,yj)/n(yj,j);
                                dm2(yj,c)        -= dm0(yi)*S(yi,yj)/m2(yj,c);
                            }
                        }

                        for(int yj=0; yj<nvals; yj++) {
                            for(int k=0; k<N1.cols(); k++) {
                                int d = N1(j, k);
                                if(d==-2) continue;
                                dm1(yj, d) += rho*dn(yj)*n(yj, j)/m1(yj, d);
                            }
                            for(int k=0; k<N2.cols(); k++) {
                                int d = N2(j, k);
                                if(d==-2) continue;
                                dm2(yj, d) += rho*dn(yj)*n(yj, j)/m2(yj, d);
                            }
                        }

                        dm1.col(c) *= 0.0;
                        if( dorec )
                            for(int yi=nvals-1; yi>=0; yi--) {
                                w(tree)=w(tree)-1;
                                m1(yi,c)=mstor(w(tree),tree);
                            }
                    }
                }
            }
        }
    }
}
Beispiel #23
0
void mPrime(uint32_t state[64]){ 
uint32_t output[16] = {0};
uint32_t temp_9_call[16];
uint32_t temp_10_rnge[(15 - 0) + 1];
extract_bs_range(temp_10_rnge, state, 0, 15);
m0(temp_9_call, temp_10_rnge, output);
state[0] = temp_9_call[0];
state[1] = temp_9_call[1];
state[2] = temp_9_call[2];
state[3] = temp_9_call[3];
state[4] = temp_9_call[4];
state[5] = temp_9_call[5];
state[6] = temp_9_call[6];
state[7] = temp_9_call[7];
state[8] = temp_9_call[8];
state[9] = temp_9_call[9];
state[10] = temp_9_call[10];
state[11] = temp_9_call[11];
state[12] = temp_9_call[12];
state[13] = temp_9_call[13];
state[14] = temp_9_call[14];
state[15] = temp_9_call[15];
uint32_t temp_11_call[16];
uint32_t temp_12_rnge[(31 - 16) + 1];
extract_bs_range(temp_12_rnge, state, 16, 31);
m1(temp_11_call, temp_12_rnge, output);
state[16] = temp_11_call[0];
state[17] = temp_11_call[1];
state[18] = temp_11_call[2];
state[19] = temp_11_call[3];
state[20] = temp_11_call[4];
state[21] = temp_11_call[5];
state[22] = temp_11_call[6];
state[23] = temp_11_call[7];
state[24] = temp_11_call[8];
state[25] = temp_11_call[9];
state[26] = temp_11_call[10];
state[27] = temp_11_call[11];
state[28] = temp_11_call[12];
state[29] = temp_11_call[13];
state[30] = temp_11_call[14];
state[31] = temp_11_call[15];
uint32_t temp_13_call[16];
uint32_t temp_14_rnge[(47 - 32) + 1];
extract_bs_range(temp_14_rnge, state, 32, 47);
m1(temp_13_call, temp_14_rnge, output);
state[32] = temp_13_call[0];
state[33] = temp_13_call[1];
state[34] = temp_13_call[2];
state[35] = temp_13_call[3];
state[36] = temp_13_call[4];
state[37] = temp_13_call[5];
state[38] = temp_13_call[6];
state[39] = temp_13_call[7];
state[40] = temp_13_call[8];
state[41] = temp_13_call[9];
state[42] = temp_13_call[10];
state[43] = temp_13_call[11];
state[44] = temp_13_call[12];
state[45] = temp_13_call[13];
state[46] = temp_13_call[14];
state[47] = temp_13_call[15];
uint32_t temp_15_call[16];
uint32_t temp_16_rnge[(63 - 48) + 1];
extract_bs_range(temp_16_rnge, state, 48, 63);
m0(temp_15_call, temp_16_rnge, output);
state[48] = temp_15_call[0];
state[49] = temp_15_call[1];
state[50] = temp_15_call[2];
state[51] = temp_15_call[3];
state[52] = temp_15_call[4];
state[53] = temp_15_call[5];
state[54] = temp_15_call[6];
state[55] = temp_15_call[7];
state[56] = temp_15_call[8];
state[57] = temp_15_call[9];
state[58] = temp_15_call[10];
state[59] = temp_15_call[11];
state[60] = temp_15_call[12];
state[61] = temp_15_call[13];
state[62] = temp_15_call[14];
state[63] = temp_15_call[15];
}
void motion_update::particle_motion(robot_control control, pose& particle)
{
	// Get euler angles from quaternion for control odometry in period t-1
	tf::Quaternion q0(control.odometry[0].orientation.x,
					  control.odometry[0].orientation.y,
					  control.odometry[0].orientation.z,
					  control.odometry[0].orientation.w);
	tf::Matrix3x3 m0(q0);
	double roll0, pitch0, yaw0;
	m0.getRPY(roll0, pitch0, yaw0);

	// Get euler angles from quaternion for control odometry in period t
	tf::Quaternion q1(control.odometry[1].orientation.x,
					  control.odometry[1].orientation.y,
					  control.odometry[1].orientation.z,
					  control.odometry[1].orientation.w);
	tf::Matrix3x3 m1(q1);
	double roll1, pitch1, yaw1;
	m1.getRPY(roll1, pitch1, yaw1);

//	std::cout << "yaw1: " << yaw1 << std::endl;

	// Recover relative motion parameters from control
	float delta_rot1 = float (atan2f(control.odometry[1].position.y - control.odometry[0].position.y,
							         control.odometry[1].position.x - control.odometry[0].position.x) -
			 	 	 	 	  float (yaw0));
	float delta_trans = float (sqrtf(powf(control.odometry[0].position.x - control.odometry[1].position.x, 2) +
			 	 	 	 	 	 	 powf(control.odometry[0].position.y - control.odometry[1].position.y, 2)));
	float delta_rot2 = float (yaw1 - yaw0 - delta_rot1);

	// Construct random distributions class
	normal_distribution_approximation norm_dist_approx(dist_params);

	// Perturb the motion parameters by noise in robot motion
	float rot1_sq = (motion_update_params.alpha1 * powf(delta_rot1, 2)) +
			        (motion_update_params.alpha2 * powf(delta_trans, 2));
	float trans_sq = (motion_update_params.alpha3 * powf(delta_trans, 2)) +
					 (motion_update_params.alpha4 * powf(delta_rot1, 2)) +
					 (motion_update_params.alpha4 * powf(delta_rot2, 2));
	float rot2_sq = (motion_update_params.alpha1 * powf(delta_rot2, 2)) +
 	   	   	   	   	(motion_update_params.alpha2 * powf(delta_trans, 2));

	// Noise
	float sample_rot1 = norm_dist_approx.sample_distribution(rot1_sq);
	float sample_trans = norm_dist_approx.sample_distribution(trans_sq);
	float sample_rot2 = norm_dist_approx.sample_distribution(rot2_sq);

	// Perturbed motion parameters
	float delta_rot1_perturbed = delta_rot1 - sample_rot1;
	float delta_trans_perturbed = delta_trans - sample_trans;
	float delta_rot2_perturbed = delta_rot2 - sample_rot2;

//	std::cout << "d_rot1: " << delta_rot1 << " | "
//			  << "d_rot1_pur: " << delta_rot1_perturbed << " | "
//			  << "d_trans: " << delta_trans << " | "
//			  << "d_trans_pur: " << delta_trans_perturbed << " | "
//			  << "d_rot2: " << delta_rot2 << " | "
//			  << "d_rot2_pur: " << delta_rot2_perturbed
//			  << std::endl;

	// Get euler angles from quaternion for initial_pose of particle
	tf::Quaternion q_ini(particle.orientation.x,
			particle.orientation.y,
			particle.orientation.z,
			particle.orientation.w);
	tf::Matrix3x3 m_ini(q_ini);
	double roll_ini, pitch_ini, yaw_ini;
	m_ini.getRPY(roll_ini, pitch_ini, yaw_ini);

//	std::cout << "yaw_ini: " << yaw_ini << std::endl;

	// Update the current pose x_t of the particle using the sample motion parameters
	particle.position.x = particle.position.x + delta_trans_perturbed * cosf((float)yaw_ini + delta_rot1_perturbed);
	particle.position.y = particle.position.y + delta_trans_perturbed * sinf((float)yaw_ini + delta_rot1_perturbed);
	float theta = (float)yaw_ini + delta_rot1_perturbed + delta_rot2_perturbed;

	// Convert back angle to quaternion
	particle.orientation.x = tf::createQuaternionFromYaw(theta).getX();
	particle.orientation.y = tf::createQuaternionFromYaw(theta).getY();
	particle.orientation.z = tf::createQuaternionFromYaw(theta).getZ();
	particle.orientation.w = tf::createQuaternionFromYaw(theta).getW();
}
Beispiel #25
0
void dgMatrix::CalcPitchYawRoll (dgVector& euler0, dgVector& euler1) const
{
	const dgMatrix& matrix = *this;
	dgAssert (dgAbsf (((matrix[0] * matrix[1]) % matrix[2]) - dgFloat32 (1.0f)) < dgFloat32 (1.0e-4f));

	// Assuming the angles are in radians.
	if (matrix[0][2] > dgFloat32 (0.99995f)) {
		dgFloat32 picth0 = dgFloat32 (0.0f);
		dgFloat32 yaw0 = dgFloat32 (-3.141592f * 0.5f);
		dgFloat32 roll0 = - dgAtan2(matrix[2][1], matrix[1][1]);
		euler0[0] = picth0;
		euler0[1] = yaw0;
		euler0[2] = roll0;

		euler1[0] = picth0;
		euler1[1] = yaw0;
		euler1[2] = roll0;

	} else if (matrix[0][2] < dgFloat32 (-0.99995f)) {
		dgFloat32 picth0 = dgFloat32 (0.0f);
		dgFloat32 yaw0 = dgFloat32 (3.141592f * 0.5f);
		dgFloat32 roll0 = dgAtan2(matrix[2][1], matrix[1][1]);
		euler0[0] = picth0;
		euler0[1] = yaw0;
		euler0[2] = roll0;

		euler1[0] = picth0;
		euler1[1] = yaw0;
		euler1[2] = roll0;
	} else {
		dgFloat32 yaw0 = -dgAsin ( matrix[0][2]);
		dgFloat32 yaw1 = dgFloat32 (3.141592f) - yaw0;
		dgFloat32 sign0 = dgSign(dgCos (yaw0));
		dgFloat32 sign1 = dgSign(dgCos (yaw1));

		dgFloat32 picth0 = dgAtan2(matrix[1][2] * sign0, matrix[2][2] * sign0);
		dgFloat32 picth1 = dgAtan2(matrix[1][2] * sign1, matrix[2][2] * sign1);

		dgFloat32 roll0 = dgAtan2(matrix[0][1] * sign0, matrix[0][0] * sign0);
		dgFloat32 roll1 = dgAtan2(matrix[0][1] * sign1, matrix[0][0] * sign1);

		if (yaw1 > dgFloat32 (3.141592f)) {
			yaw1 -= dgFloat32 (2.0f * 3.141592f);
		}

		euler0[0] = picth0;
		euler0[1] = yaw0;
		euler0[2] = roll0;

		euler1[0] = picth1;
		euler1[1] = yaw1;
		euler1[2] = roll1;
	}
	euler0[3] = dgFloat32(0.0f);
	euler1[3] = dgFloat32(0.0f);

#ifdef _DEBUG
	dgMatrix m0 (dgPitchMatrix (euler0[0]) * dgYawMatrix(euler0[1]) * dgRollMatrix(euler0[2]));
	dgMatrix m1 (dgPitchMatrix (euler1[0]) * dgYawMatrix(euler1[1]) * dgRollMatrix(euler1[2]));
	for (int i = 0; i < 3; i ++) {
		for (int j = 0; j < 3; j ++) {
			dgFloat32 error = dgAbsf (m0[i][j] - matrix[i][j]);
			dgAssert (error < 5.0e-2f);
			error = dgAbsf (m1[i][j] - matrix[i][j]);
			dgAssert (error < 5.0e-2f);
		}
	}
#endif
}
Beispiel #26
0
int main(int argc, char** argv)
{
    std::vector<std::string> args;
    for (int i=1;i<argc;++i)
    {
        args.push_back(argv[i]);
    }
    bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();

    mapnik::Map m0(100,100);
    mapnik::Map m2(200,100);

    // mapnik::datasource
    mapnik::datasource_cache::instance().register_datasources("plugins/input/shape.input");
    mapnik::parameters p;
    p["type"]="shape";
    p["file"]="demo/data/boundaries";
    p["encoding"]="latin1";
    auto ds0 = mapnik::datasource_cache::instance().create(p);

    auto ds1 = ds0; // shared ptr copy
    BOOST_TEST(ds1 == ds0);
    BOOST_TEST(*ds1 == *ds0);
    ds1 = mapnik::datasource_cache::instance().create(p); // new with the same parameters
    BOOST_TEST(ds1 != ds0);
    BOOST_TEST(*ds1 == *ds0);
    auto ds2 = std::move(ds1);
    BOOST_TEST(ds2 != ds0);
    BOOST_TEST(*ds2 == *ds0);

    // mapnik::layer
    mapnik::layer l0("test-layer");
    l0.set_datasource(ds0);

    mapnik::layer l1 = l0; // copy assignment
    BOOST_TEST(l1 == l0);
    mapnik::layer l2(l0); // copy ctor
    BOOST_TEST(l2 == l0);
    mapnik::layer l3(mapnik::layer("test-layer")); // move ctor
    l3.set_datasource(ds2);

    BOOST_TEST(l3 == l0);
    mapnik::layer l4 = std::move(l3);
    BOOST_TEST(l4 == l0); // move assignment

    m0.add_layer(l4);
    m0.set_background(mapnik::color("skyblue"));
    m2.set_background(mapnik::color("skyblue"));

    auto m1 = m0; //copy

    BOOST_TEST(m0 == m1);
    BOOST_TEST(m0 != m2);

    m2 = m1; // copy
    BOOST_TEST(m2 == m1);
    m2 = std::move(m1);
    BOOST_TEST(m2 == m0);
    BOOST_TEST(m1 != m0);

    BOOST_TEST(m0 == m2);

    if (!::boost::detail::test_errors())
    {
        if (quiet) std::clog << "\x1b[1;32m.\x1b[0m";
        else std::clog << "C++ copy/move/assignment tests: \x1b[1;32m✓ \x1b[0m\n";
        ::boost::detail::report_errors_remind().called_report_errors_function = true;
    }
    else
    {
        return ::boost::report_errors();
    }
}
Beispiel #27
0
void user_main( void * args ) 
{

  LOG(INFO) << "Test -2";
  bool x0 = false;
  {
    {
      // must run on this node
      auto f0 = [&x0]{ BOOST_CHECK_EQUAL( x0, true ); };
      Grappa::Message< decltype(f0) > m0( 0, f0 );
      //auto m1 = Grappa::message( 0, [&]{ x1 = true; } );
      m0.enqueue();
      x0 = true;
    }
    Grappa::flush( 0 );
    Grappa::impl::poll( );
  }

  LOG(INFO) << "Test -1";
  x0 = false;
  {
    // must run on this node
    auto m0 = Grappa::message( 0, [&x0]{ BOOST_CHECK_EQUAL( x0, true ); } );
    m0.enqueue();
    x0 = true;
  }
  Grappa::flush( 0 );
  Grappa::impl::poll( );
  
  LOG(INFO) << "Test 0";
  x0 = false;
  {
    // must run on this node
    auto m0 = Grappa::send_message( 0, [&x0]{ BOOST_CHECK_EQUAL( x0, true ); } );
    
    // //auto l0 = [&x0]{ BOOST_CHECK_EQUAL( x0, true ); };
    // // Grappa::SendMessage< decltype(l0) > m0( 0, l0 );
    
    // auto l0a = [&x0](void * useless, size_t nothing){ BOOST_CHECK_EQUAL( x0, true ); };
    // int foo[10];
    // auto m0 = Grappa::send_message( 0, l0a, foo, sizeof(foo) );
    
    x0 = true;
  }
  Grappa::flush( 0 );
  Grappa::impl::poll( );
  

  LOG(INFO) << "Test 1";
  {
    bool x1 = false;
    {
      // must run on this node
      auto f1 = [&x1]{ x1 = true; };
      Grappa::Message< decltype(f1) > m1( 0, f1 );
      //auto m1 = Grappa::message( 0, [&]{ x1 = true; } );
      m1.enqueue();
    }
    Grappa::flush( 0 );
    Grappa::impl::poll();
    BOOST_CHECK_EQUAL( x1, true );
  }
  
  LOG(INFO) << "Test 2";
  {
    // must run on this node
    Grappa::Message< Check > m2( 0, Check() );
    //auto m2 = Grappa::message( 0, Check() );
    m2->x = true;
    m2.enqueue();
    Grappa::flush( 0 );
    Grappa::impl::poll();
  }

  LOG(INFO) << "Test 4";
  {
    bool x4 = false;
    {
      //auto m4 = Grappa::send_message( 0, [&]{ x4 = true; } );
      // must run on this node
      auto f4 = [&]{ x4 = true; };
      auto m4 = Grappa::send_message( 0, f4 );
    }
    Grappa::flush( 0 );
    Grappa::impl::poll();
    BOOST_CHECK_EQUAL( x4, true );
  }

  LOG(INFO) << "Test 5";
  {
    bool x5 = false;
    // must run on this node
    auto f5 = [&x5] (void * payload, size_t payload_size) { 
      bool * b = reinterpret_cast< bool * >( payload );
      BOOST_CHECK_EQUAL( *b, x5 );
    };

    {
      //Grappa::SendPayloadMessage< decltype(f5) > m5( 0, f5, &x5, sizeof(x5) );
      auto m5 = Grappa::send_message( 0, f5, &x5, sizeof(x5) );
    }
    Grappa::flush( 0 );
    Grappa::impl::poll();

    {
      x5 = true;
      auto m5a = Grappa::send_message( 0, f5, &x5, sizeof(x5) );
    }
    Grappa::flush( 0 );
    Grappa::impl::poll();
  }

  LOG(INFO) << "Test 6";
  {
    Grappa::ConditionVariable cv;
    Grappa::ConditionVariable * cvp = &cv;

    auto m6 = Grappa::send_heap_message( 1, [cvp] { 
        BOOST_CHECK_EQUAL( Grappa::mycore(), 1 );
        auto m6a = Grappa::send_heap_message( 0, [cvp] {
            BOOST_CHECK_EQUAL( Grappa::mycore(), 0 );
            Grappa::signal( cvp );
          } );
        Grappa::flush( 0 );
        Grappa::impl::poll();
      } );
    Grappa::flush( 1 );
    Grappa::impl::poll();
    Grappa::wait( cvp );
    LOG(INFO) << "Test 6 done";
  }

  //Grappa_merge_and_dump_stats();
}
Beispiel #28
0
/*
 * clip
 *
 * Takes two 3-arrays by reference. clip will change these values to be ones that
 * are clipped within the viewport, hither, and yon planes. Returns 0 if the line
 * is clipped entirely, 1 otherwise.
 * */
int clip(float p1[3], float p2[3], direction d) {
    Matrix normal(3,1);
    Matrix m0(1,3,p1);
    Matrix v(1,3);
    float v_entries[] = { p2[0] - p1[0],
			  p2[1] - p1[1],
			  p2[2] - p1[2] };
    v << v_entries;
    float normal_entries[3] = { 0, 0, 0 };
    float D;

    // Set normal vector, D, and check if the entire line is clipped
    switch ( d ) {
    case TOP:
    {
	if ( p1[1] > Wb - VIEWPORT_MARGIN && p2[1] > Wb - VIEWPORT_MARGIN ) {
	    return 0;
	}
	normal_entries[1] = 1;
	D = Wb - VIEWPORT_MARGIN;
    }
	break;
    case BOTTOM:
    {
	if ( p1[1] < VIEWPORT_MARGIN && p2[1] < VIEWPORT_MARGIN ) {
	    return 0;
	}
	normal_entries[1] = 1;
	D = VIEWPORT_MARGIN;
    }
	break;
    case LEFT:
    {
	if ( p1[0] < VIEWPORT_MARGIN && p2[0] < VIEWPORT_MARGIN ) {
	    return 0;
	}
	normal_entries[0] = 1;
	D = VIEWPORT_MARGIN;
    }
	break;
    case RIGHT:
    {
	if ( p1[0] > Wr - VIEWPORT_MARGIN && p2[0] > Wr - VIEWPORT_MARGIN ) {
	    return 0;
	}
	normal_entries[0] = 1;
	D = Wr - VIEWPORT_MARGIN;
    }
	break;
    case HITHER:
    {
	if ( p1[2] < 0 && p2[2] < 0 ) {
	    return 0;
	}
	normal_entries[2] = 1;
	D = 0;
    }
        break;
    case YON:
    {
	if ( p1[2] > 1 && p2[2] > 1) {
	    return 0;
	}
	normal_entries[2] = 1;
	D = 1;
    }
	break;
    }
    normal << normal_entries;
    
    // Check if there is nothing to be clipped. If so, return.
    float normalDotV = (v*normal)(0,0);
    if ( normalDotV == 0.0f ) return 1;

    // Get the clipped point
    float t = (D - (m0*normal)(0,0))/normalDotV;
    Matrix clippedPointVector = v*t + m0;
    float clippedPoint[3] = { clippedPointVector(0,0),
			      clippedPointVector(0,1),
			      clippedPointVector(0,2) };
 
    // We assume that at least part of the line is visible here.
    switch ( d ) {
    case TOP:
    {
	if ( p1[1] > Wb - VIEWPORT_MARGIN ) {
	    std::copy(clippedPoint, clippedPoint+3, p1);
	} else if ( p2[1] > Wb - VIEWPORT_MARGIN ) {
	    std::copy(clippedPoint, clippedPoint+3, p2);
	}
    }
	break;
    case BOTTOM:
    {
	if ( p1[1] < VIEWPORT_MARGIN ) {
	    std::copy(clippedPoint, clippedPoint+3, p1);
	} else if ( p2[1] < VIEWPORT_MARGIN ) {
	    std::copy(clippedPoint, clippedPoint+3, p2);
	}
    }
	break;
    case LEFT:
    {
	if ( p1[0] < VIEWPORT_MARGIN ) {
	    std::copy(clippedPoint, clippedPoint+3, p1);
	} else if ( p2[0] < VIEWPORT_MARGIN ) {
	    std::copy(clippedPoint, clippedPoint+3, p2);
	}
    }
	break;
    case RIGHT:
    {
	if ( p1[0] > Wr - VIEWPORT_MARGIN ) {
	    std::copy(clippedPoint, clippedPoint+3, p1);
	} else if ( p2[0] > Wr - VIEWPORT_MARGIN) {
	    std::copy(clippedPoint, clippedPoint+3, p2);
	}
    }
	break;
    case HITHER:
    {
	if ( p1[2] < 0 ) {
	    std::copy(clippedPoint, clippedPoint+3, p1);
	} else if ( p2[2] < 0 ) {
	    std::copy(clippedPoint, clippedPoint+3, p2);
	}

    }
	break;
    case YON:
    {
	if ( p1[2] > 1 ) {
	    std::copy(clippedPoint, clippedPoint+3, p1);
	} else if ( p2[2] > 1 ) {
	    std::copy(clippedPoint, clippedPoint+3, p2);
	}

    }
	break;
    }

    return 1;
}
Beispiel #29
0
int test_ctr()
{
	int Error(0);

#if GLM_HAS_TRIVIAL_QUERIES
	//Error += std::is_trivially_default_constructible<glm::mat4>::value ? 0 : 1;
	//Error += std::is_trivially_copy_assignable<glm::mat4>::value ? 0 : 1;
	Error += std::is_trivially_copyable<glm::mat4>::value ? 0 : 1;
	//Error += std::is_copy_constructible<glm::mat4>::value ? 0 : 1;
	//Error += std::has_trivial_copy_constructor<glm::mat4>::value ? 0 : 1;
#endif

#if(GLM_HAS_INITIALIZER_LISTS)
	glm::mat4 m0(
		glm::vec4(0, 1, 2, 3), 
		glm::vec4(4, 5, 6, 7),
		glm::vec4(8, 9, 10, 11),
		glm::vec4(12, 13, 14, 15));

	assert(sizeof(m0) == 4 * 4 * 4);

	glm::vec4 V{0, 1, 2, 3};

	glm::mat4 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};

	glm::mat4 m2{
		{0, 1, 2, 3},
		{4, 5, 6, 7},
		{8, 9, 10, 11},
		{12, 13, 14, 15}};

	for(glm::length_t i = 0; i < m0.length(); ++i)
		Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;

	for(glm::length_t i = 0; i < m1.length(); ++i)
		Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;

	std::vector<glm::mat4> m3{
		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};

	std::vector<glm::mat4> v1{
		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};

	std::vector<glm::mat4> v2{
		{
			{ 0, 1, 2, 3 },
			{ 4, 5, 6, 7 },
			{ 8, 9, 10, 11 },
			{ 12, 13, 14, 15 }
		},
		{
			{ 0, 1, 2, 3 },
			{ 4, 5, 6, 7 },
			{ 8, 9, 10, 11 },
			{ 12, 13, 14, 15 }
		}};

#endif//GLM_HAS_INITIALIZER_LISTS

	return Error;
}
Beispiel #30
0
//dVector dMatrix::GetEulerAngles (dEulerAngleOrder order) const
void dMatrix::GetEulerAngles (dVector & euler0, dVector & euler1, dEulerAngleOrder order) const
{
   int a0 = (order >> 8) & 3;
   int a1 = (order >> 4) & 3;
   int a2 = (order >> 0) & 3;
   const dMatrix & matrix = *this;
   // Assuming the angles are in radians.
   if (matrix[a0][a2] > 0.99995f)
   {
      dFloat picth0 = 0.0f;
      dFloat yaw0 = -3.141592f * 0.5f;
      dFloat roll0 = - dAtan2 (matrix[a2][a1], matrix[a1][a1]);
      euler0[a0] = picth0;
      euler0[a1] = yaw0;
      euler0[a2] = roll0;
      euler1[a0] = picth0;
      euler1[a1] = yaw0;
      euler1[a2] = roll0;
   }
   else
      if (matrix[a0][a2] < -0.99995f)
      {
         dFloat picth0 = 0.0f;
         dFloat yaw0 = 3.141592f * 0.5f;
         dFloat roll0 = dAtan2 (matrix[a2][a1], matrix[a1][a1]);
         euler0[a0] = picth0;
         euler0[a1] = yaw0;
         euler0[a2] = roll0;
         euler1[a0] = picth0;
         euler1[a1] = yaw0;
         euler1[a2] = roll0;
      }
      else
      {
         //euler[a0] = -dAtan2(-matrix[a1][a2], matrix[a2][a2]);
         //euler[a1] = -dAsin ( matrix[a0][a2]);
         //euler[a2] = -dAtan2(-matrix[a0][a1], matrix[a0][a0]);
         dFloat yaw0 = -dAsin ( matrix[a0][a2]);
         dFloat yaw1 = 3.141592f - yaw0;
         dFloat sign0 = dSign (dCos (yaw0));
         dFloat sign1 = dSign (dCos (yaw1));
         dFloat picth0 = dAtan2 (matrix[a1][a2] * sign0, matrix[a2][a2] * sign0);
         dFloat picth1 = dAtan2 (matrix[a1][a2] * sign1, matrix[a2][a2] * sign1);
         dFloat roll0 = dAtan2 (matrix[a0][a1] * sign0, matrix[a0][a0] * sign0);
         dFloat roll1 = dAtan2 (matrix[a0][a1] * sign1, matrix[a0][a0] * sign1);
         if (yaw1 > 3.141592f)
            yaw1 -= 2.0f * 3.141592f;
         euler0[a0] = picth0;
         euler0[a1] = yaw0;
         euler0[a2] = roll0;
         euler1[a0] = picth1;
         euler1[a1] = yaw1;
         euler1[a2] = roll1;
      }
   euler0[3] = dFloat (0.0f);
   euler1[3] = dFloat (0.0f);
#ifdef _DEBUG
   if (order == m_pitchYawRoll)
   {
      dMatrix m0 (dPitchMatrix (euler0[0]) * dYawMatrix (euler0[1]) * dRollMatrix (euler0[2]));
      dMatrix m1 (dPitchMatrix (euler1[0]) * dYawMatrix (euler1[1]) * dRollMatrix (euler1[2]));
      for (int i = 0; i < 3; i ++)
      {
         for (int j = 0; j < 3; j ++)
         {
            dFloat error = dAbs (m0[i][j] - matrix[i][j]);
            dAssert (error < 5.0e-2f);
            error = dAbs (m1[i][j] - matrix[i][j]);
            dAssert (error < 5.0e-2f);
         }
      }
   }
#endif
}