TEST(BaseLib, Functional) { auto num_const = InstanceCounter<A>::getNumberOfConstructions(); auto num_move = InstanceCounter<A>::getNumberOfMoves(); auto num_copy = InstanceCounter<A>::getNumberOfCopies(); auto num_inst = InstanceCounter<A>::getNumberOfInstances(); // Base line: measure how many copies and moves // std::function<>(std::bind(...)) needs. A a_base(0.0); // move the object to std::bind() InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); std::function<void(A)> fct_mult( std::bind(&A::multiply, std::move(a_base), std::placeholders::_1)); auto const num_copy_base_move = InstanceCounter<A>::getNumberOfCopies() - num_copy; auto const num_move_base_move = InstanceCounter<A>::getNumberOfMoves() - num_move; // call std::function using pass-by-value A a_base2(0.0); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); fct_mult(a_base2); auto const num_copy_base_pass = InstanceCounter<A>::getNumberOfCopies() - num_copy; auto const num_move_base_pass = InstanceCounter<A>::getNumberOfMoves() - num_move; // end base line // self test InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); A a1(3.0); A a2(a1); EXPECT_INSTANCES(A, num_const+1, num_move, num_copy+1, num_inst+2); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); auto f1_get = BaseLib::easyBind(&A::getValue, a1); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(3.0, f1_get()); // check that really a reference is returned { auto f2_getRef = BaseLib::easyBind(&A::getValueRef, a2); auto& value_ref = f2_getRef(); EXPECT_EQ(3.0, value_ref); value_ref = 4.0; EXPECT_EQ(4.0, a2.getValue()); } EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); // test binding to pointers { A* ap = &a1; auto fp_get = BaseLib::easyBind(&A::getValue, ap); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(3.0, fp_get()); A const* apc = &a1; auto fpc_get = BaseLib::easyBind(&A::getValue, apc); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(3.0, fpc_get()); } EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); // check that referenced objects are not copied { A& a3 = a2; auto f3_get = BaseLib::easyBind(&A::getValue, a3); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(4.0, f3_get()); } { A const& a3 = a2; auto f3_get = BaseLib::easyBind(&A::getValue, a3); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(4.0, f3_get()); } EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); // temporaries must be moved { auto ftemp_get = BaseLib::easyBind(&A::getValue, A(5.0)); EXPECT_INSTANCES(A, num_const + 1, num_move + num_move_base_move, num_copy + num_copy_base_move, num_inst + 1); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); EXPECT_EQ(5.0, ftemp_get()); } // ftemp_get destroyed EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst-1); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); // testing explicit move { A a_move(5.0); EXPECT_INSTANCES(A, num_const+1, num_move, num_copy, num_inst+1); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); auto ftemp_get = BaseLib::easyBind(&A::getValue, std::move(a_move)); EXPECT_INSTANCES(A, num_const, num_move + num_move_base_move, num_copy + num_copy_base_move, num_inst+1); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); EXPECT_EQ(5.0, ftemp_get()); } // ftemp_get destroyed and a_move EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst-2); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); // test binding a callable object { auto f1_op = BaseLib::easyBind(a1); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(21.0, f1_op(7.0)); } EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); // test binding a lambda { double value = 2.0; auto f_op = BaseLib::easyBind([&value](const double x) { value *= x; return value; }); EXPECT_EQ(6.0, f_op(3.0)); EXPECT_EQ(6.0, value); } // check that parameters passed by reference are not copied { auto f1_add = BaseLib::easyBind(&A::add, a1); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); f1_add(a2); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(7.0, f1_get()); } // check that parameters passed by value are copied { auto f1_mult = BaseLib::easyBind(&A::multiply, a1); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); f1_mult(a2); EXPECT_INSTANCES(A, num_const, num_move + num_move_base_pass, num_copy + num_copy_base_pass, num_inst); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); EXPECT_EQ(28.0, f1_get()); EXPECT_EQ(4.0, a2.getValue()); } }
int main() { cout << "以下实验是规定了Document的值,测试时可以自行改变其值与测试内容" << endl; char b1[5] = { 'i', '9', '5', ',', 's' }; Line a1 (b1, b1 + 5); char b2[7] = { ' ', 'c', 'r', 'l', ' ','c','o' }; Line a2(b2,b2+7); char b3[6] = { '8','w', ' ', 'l', '*', 'l'}; Line a3(b3, b3 + 6); list<Line>answer; answer.push_back(a1); answer.push_back(a2); answer.push_back(a3); Document my_doc(answer); Document tmp = my_doc; cout << "原来文件为:" << endl; print(tmp); cout << endl; cout << "文件的字符数为:" << number(tmp) << endl; cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl; cout << "其中字母序列(第二种算法):" << number2(tmp)<<endl; const string pre= "i7"; cout << "查找单词为:" << pre<<endl; Text_iterator p = find_text(tmp, pre); if (p==tmp.end() ) { cout << "不存在该单词" << endl; } else { cout << "存在该单词" << endl; int length = pre.length(); string now = "wa56 ker"; cout << "替换为:" << now << endl; cout << "替换后的文件为:" << endl; p.change(length, now); print(tmp); cout << endl; cout << "文件的字符数为:" << number(tmp) << endl; cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl; cout << "其中字母序列(第二种算法):" << number2(tmp) << endl; } tmp = my_doc; string pres = "crl"; cout << "查找单词为:" << pres << endl; Text_iterator s = find_text(tmp, pres); if (s == tmp.end()) { cout << "不存在该单词" << endl; } else { cout << "存在该单词" << endl; int length = pres.length(); string now = "wa56 er"; cout << "替换为:" << now << endl; cout << "替换后的文件为:" << endl; s.change(length, now); print(tmp); cout << endl; cout << "文件的字符数为:" << number(tmp) << endl; cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl; cout << "其中字母序列(第二种算法):" << number2(tmp) << endl; } getchar(); getchar(); getchar(); }
virtual void run() const { for (std::size_t i=1; i <= d0; i++) a0(i) = a1(i); }
//////////////////////////////////////////////////////////////////////////////// // Overload registration //////////////////////////////////////////////////////////////////////////////// NT2_REGISTER_DISPATCH ( tag::minus_, tag::cpu_, (A0) , ((simd_<arithmetic_<A0>,tag::altivec_>)) ((simd_<arithmetic_<A0>,tag::altivec_>)) ); //////////////////////////////////////////////////////////////////////////////// // Overloads implementation //////////////////////////////////////////////////////////////////////////////// namespace nt2 { namespace ext { template<class Dummy> struct call< tag::minus_ ( tag::simd_<tag::arithmetic_,tag::altivec_> , tag::simd_<tag::arithmetic_,tag::altivec_> ) , tag::cpu_, Dummy > : callable { template<class Sig> struct result; template<class This,class A> struct result<This(A,A)> : meta::strip<A> {}; NT2_FUNCTOR_CALL(2) { A0 that = { vec_sub(a0(),a1()) }; return that; } }; } } #endif
int BeamContact2Dp::update(void) // this function updates variables for an incremental step n to n+1 { double tensileStrength; Vector a1(BC2D_NUM_DIM); Vector b1(BC2D_NUM_DIM); Vector a1_n(BC2D_NUM_DIM); Vector b1_n(BC2D_NUM_DIM); Vector disp_a(3); Vector disp_b(3); Vector disp_L(BC2D_NUM_DIM); double rot_a; double rot_b; Vector x_c(BC2D_NUM_DIM); // update slave node coordinates mDcrd_s = mIcrd_s + theNodes[2]->getTrialDisp(); // update nodal coordinates disp_a = theNodes[0]->getTrialDisp(); disp_b = theNodes[1]->getTrialDisp(); for (int i = 0; i < 2; i++) { mDcrd_a(i) = mIcrd_a(i) + disp_a(i); mDcrd_b(i) = mIcrd_b(i) + disp_b(i); } // compute incremental rotation from step n to step n+1 rot_a = disp_a(2) - mDisp_a_n(2); rot_b = disp_b(2) - mDisp_b_n(2); // get tangent vectors from last converged step a1_n = Geta1(); b1_n = Getb1(); // linear update of tangent vectors a1 = a1_n + rot_a*mEyeS*a1_n; b1 = b1_n + rot_b*mEyeS*b1_n; // update centerline projection coordinate x_c = mDcrd_a*mShape(0) + a1*mLength*mShape(1) + mDcrd_b*mShape(2) + b1*mLength*mShape(3); // update penetration function mGap = (mNormal^(mDcrd_s - x_c)) - mRadius; if (mGap < 0.0 && in_bounds) { inContact = true; } else { mGap = 0.0; inContact = false; } // update normal contact force if (was_inContact) { mLambda = mPenalty*mGap; } else { mLambda = 0.0; } // get tensile strength from contact material tensileStrength = theMaterial->getTensileStrength(); // determine trial strain vector based on contact state if (inContact) { Vector strain(3); double slip; Vector c1n1(2); Vector c2n1(2); // tangent at the centerline projection in step n+1 c1n1 = mDshape(0)*mDcrd_a + mDshape(1)*mLength*ma_1 + mDshape(2)*mDcrd_b + mDshape(3)*mLength*mb_1; // update vector c2 for step n+1 c2n1 = (mDcrd_s - x_c)/((mDcrd_s - x_c).Norm()); // update vector c2 for step n+1 c2n1(0) = -c1n1(1); c2n1(1) = c1n1(0); // compute the slip slip = mg_xi^(mDcrd_s - x_c - mrho*c2n1); // set the strain vector strain(0) = mGap; strain(1) = slip; strain(2) = -mLambda; theMaterial->setTrialStrain(strain); } else { Vector strain(3); // set the strain vector strain(0) = mGap; strain(1) = 0.0; strain(2) = -mLambda; theMaterial->setTrialStrain(strain); } return 0; }
int main(void) { a1(); return acount + tcount; }
void TubeGenerator::generateCarbonTube(int n1, int n2, int k, float transition, float bondLength, std::vector<Molecule::Atom>& atoms, std::vector<Molecule::Link>& links) { if (n1 < n2) std::swap(n1, n2); atoms.clear(); links.clear(); gameplay::Vector2 a1(1.7320508f, 0.0f); gameplay::Vector2 a2(-0.8660254f, 1.5f); gameplay::Vector2 R = (a1 * static_cast<float>(n1) + a2 * static_cast<float>(n2))* bondLength; gameplay::Vector2 L(-R.y, R.x); L.normalize(); L.scale(k * bondLength); int ymin = -1; int ymax = static_cast<int>(ceilf(std::max(L.y, R.y) / bondLength)) + 1; int xmin = static_cast<int>(floorf(L.x / bondLength / a1.x)) - 1; int xmax = static_cast<int>(ceilf(R.x / bondLength / a1.x - a2.x * ymax)) + 1; std::map<std::tuple<int, int, int>, int> clippedAtoms; float Rlen = R.length(); float Llen = L.length(); float eps = 0.0001f; for (int y = ymin; y <= ymax; y++) for (int x = xmin; x <= xmax; x++) { // process hexagon atoms gameplay::Vector2 hexagonCenter(x * bondLength * a1.x + a2.x * y * bondLength, y * bondLength * a2.y); // process only two hexagon's atoms // these are unique to hexagon // the rest will be processed by other hexagons // each atom then can be uniquely defined by hexagon coordinates (x, y) and one index (0-1) for (int i = 0; i < 2; i++) { float phi = MATH_PI / 6.0f + MATH_PI / 3.0f * i; gameplay::Vector2 atomPosition(cosf(phi), sinf(phi)); atomPosition = hexagonCenter + atomPosition * bondLength; // clip atoms by square defined by R and L vectors float u = gameplay::Vector2::dot(atomPosition, R) / Rlen; float v = gameplay::Vector2::dot(atomPosition, L) / Llen; if (u >= -eps && v >= -eps && u < Rlen - eps && v < Llen - eps) { clippedAtoms.insert(std::make_pair(std::make_tuple(x, y, i), static_cast<int>(atoms.size()))); atoms.push_back({ 1, 0.0f, gameplay::Vector3(u, v, 0.0f) }); //atoms.push_back({ 1, 0.0f, gameplay::Vector3(atomPosition.x, atomPosition.y, 0.0f) }); } } } std::vector<std::tuple<int, int, int>> unboundAtoms; // check links for (auto it = clippedAtoms.begin(), end_it = clippedAtoms.end(); it != end_it; it++) { int x = std::get<0>((*it).first); int y = std::get<1>((*it).first); if (std::get<2>((*it).first) == 0) { auto next = clippedAtoms.find(std::make_tuple(x, y, 1)); if (next != clippedAtoms.end()) links.push_back({ (*it).second, (*next).second, 1 }); else unboundAtoms.push_back((*it).first); next = clippedAtoms.find(std::make_tuple(x, y - 1, 1)); if (next != clippedAtoms.end()) links.push_back({ (*it).second, (*next).second, 1 }); else unboundAtoms.push_back((*it).first); next = clippedAtoms.find(std::make_tuple(x + 1, y, 1)); if (next != clippedAtoms.end()) links.push_back({ (*it).second, (*next).second, 1 }); else unboundAtoms.push_back((*it).first); } } // bend graphene if (transition > 0.0f) { for (auto it = atoms.begin(), end_it = atoms.end(); it != end_it; it++) { float radius = R.length() / MATH_PIX2 / transition; float phi = (*it).pos.x / radius; (*it).pos.x = radius * sinf(phi); (*it).pos.z = radius * cosf(phi); } } // add new links //for (auto it = unboundAtoms.begin(), end_it = unboundAtoms.end(); it != end_it; it++) //{ // auto first = clippedAtoms.find(std::make_tuple(x, y, 0)); // if (first != clippedAtoms.end()) // { // auto next = clippedAtoms.find(std::make_tuple(x, y, 1)); // if (next == clippedAtoms.end()) // { // for (int x1 = xmax; x1 > x; x1--) // { // auto last = clippedAtoms.find(std::make_tuple(x1, y, 1)); // if (last != clippedAtoms.end()) // { // links.push_back({ (*first).second, (*last).second, 1 }); // break; // } // } // } // next = clippedAtoms.find(std::make_tuple(x, y - 1, 1)); // if (next == clippedAtoms.end()) // { // for (int x1 = xmin; x1 < x; x1++ ) // { // auto last = clippedAtoms.find(std::make_tuple(x1, y - 1, 1)); // if (last != clippedAtoms.end()) // { // links.push_back({ (*first).second, (*last).second, 1 }); // break; // } // } // } // next = clippedAtoms.find(std::make_tuple(x + 1, y, 1)); // if (next == clippedAtoms.end()) // { // for (int x1 = xmin; x1 < x; x1++) // { // auto last = clippedAtoms.find(std::make_tuple(x1, y, 1)); // if (last != clippedAtoms.end()) // { // links.push_back({ (*first).second, (*last).second, 1 }); // break; // } // } // } // } //} }
void TestBandDiv(tmv::DivType dt) { const int N = 10; std::vector<tmv::BandMatrixView<T> > b; std::vector<tmv::BandMatrixView<std::complex<T> > > cb; MakeBandList(b,cb); tmv::Matrix<T> a1(N,N); for (int i=0; i<N; ++i) for (int j=0; j<N; ++j) a1(i,j) = T(3+i-2*j); a1.diag().addToAll(T(10)*N); a1 /= T(10); tmv::Matrix<std::complex<T> > ca1 = a1 * std::complex<T>(3,-4); tmv::Vector<T> v1(N); tmv::Vector<T> v2(N-1); for (int i=0; i<N; ++i) v1(i) = T(16-3*i); for (int i=0; i<N-1; ++i) v2(i) = T(-6+i); tmv::Vector<std::complex<T> > cv1(N); tmv::Vector<std::complex<T> > cv2(N-1); for (int i=0; i<N; ++i) cv1(i) = std::complex<T>(16-3*i,i+4); for (int i=0; i<N-1; ++i) cv2(i) = std::complex<T>(2*i-3,-6+i); tmv::Matrix<T> a3 = a1.colRange(0,N/2); tmv::Matrix<std::complex<T> > ca3 = ca1.colRange(0,N/2); tmv::Matrix<T> a4 = a1.rowRange(0,N/2); tmv::Matrix<std::complex<T> > ca4 = ca1.rowRange(0,N/2); tmv::Matrix<T> a5 = a1.colRange(0,0); tmv::Matrix<std::complex<T> > ca5 = ca1.colRange(0,0); tmv::Matrix<T> a6 = a1.rowRange(0,0); tmv::Matrix<std::complex<T> > ca6 = ca1.rowRange(0,0); tmv::Matrix<T> a7 = a1; tmv::Matrix<std::complex<T> > ca7 = ca1; a7.diag().addToAll(T(10)*N); ca7.diag().addToAll(T(10)*N); for(size_t i=START;i<b.size();i++) { if (showstartdone) std::cout<<"Start loop: i = "<<i<<"\nbi = "<<tmv::TMV_Text(b[i])<< " "<<b[i]<<std::endl; tmv::BandMatrixView<T> bi = b[i]; tmv::BandMatrixView<std::complex<T> > cbi = cb[i]; if (dt == tmv::LU && !bi.isSquare()) continue; bi.saveDiv(); cbi.saveDiv(); tmv::Matrix<T> m(bi); m.saveDiv(); bi.divideUsing(dt); bi.setDiv(); m.divideUsing(dt); m.setDiv(); std::ostream* divout = showdiv ? &std::cout : 0; Assert(bi.checkDecomp(divout),"CheckDecomp"); T eps = m.rowsize()*EPS*Norm(m)*Norm(m.inverse()); if (bi.colsize() == N) { tmv::Vector<T> x1 = v1/bi; tmv::Vector<T> x2 = v1/m; if (showacc) { std::cout<<"v/b: Norm(x1-x2) = "<<Norm(x1-x2)<< " "<<eps*Norm(x1)<<std::endl; } Assert(Norm(x1-x2) < eps*Norm(x1),"Band v/b"); } if (bi.rowsize() == N) { tmv::Vector<T> x1 = v1%bi; tmv::Vector<T> x2 = v1%m; if (showacc) { std::cout<<"v%b: Norm(x1-x2) = "<<Norm(x1-x2)<< " "<<eps*Norm(x1)<<std::endl; } Assert(Norm(x1-x2) < eps*Norm(x1),"Band v%b"); } tmv::Matrix<T,tmv::ColMajor> binv = bi.inverse(); tmv::Matrix<T,tmv::ColMajor> minv = m.inverse(); if (showacc) { std::cout<<"minv = "<<minv<<std::endl; std::cout<<"binv = "<<binv<<std::endl; std::cout<<"Norm(minv-binv) = "<<Norm(minv-binv)<< " "<<eps*Norm(binv)<<std::endl; } Assert(Norm(binv-minv) < eps*Norm(binv),"Band Inverse"); if (m.isSquare()) { if (showacc) { std::cout<<"Det(b) = "<<Det(bi)<< ", Det(m) = "<<Det(m)<<std::endl; std::cout<<"abs(bdet-mdet) = "<<std::abs(Det(bi)-Det(m)); std::cout<<" EPS*abs(mdet) = "<< eps*std::abs(Det(m))<<std::endl; std::cout<<"abs(abs(bdet)-abs(mdet)) = "<< std::abs(std::abs(Det(bi))-std::abs(Det(m))); std::cout<<" EPS*abs(mdet) = "<< eps*std::abs(Det(m))<<std::endl; } Assert(std::abs(Det(m)-Det(bi)) < eps*std::abs(Det(m)+Norm(m)), "Band Det"); T msign, bsign; Assert(std::abs(m.logDet(&msign)-bi.logDet(&bsign)) < N*eps, "Band LogDet"); Assert(std::abs(msign-bsign) < N*eps,"Band LogDet - sign"); } cbi.divideUsing(dt); cbi.setDiv(); Assert(cbi.checkDecomp(divout),"CheckDecomp"); tmv::Matrix<std::complex<T> > cm(cbi); cm.saveDiv(); cm.divideUsing(dt); cm.setDiv(); T ceps = EPS*Norm(cm)*Norm(cm.inverse()); if (cm.isSquare()) { if (showacc) { std::cout<<"Det(cbi) = "<<Det(cbi)<<", Det(cm) = "<< Det(cm)<<std::endl; std::cout<<"abs(cbidet-cmdet) = "<<std::abs(Det(cbi)-Det(cm)); std::cout<<" cbidet/cmdet = "<<Det(cbi)/Det(cm); std::cout<<" EPS*abs(cmdet) = "<< ceps*std::abs(Det(cm))<<std::endl; std::cout<<"abs(abs(bdet)-abs(mdet)) = "<< std::abs(std::abs(Det(bi))-std::abs(Det(m))); std::cout<<" EPS*abs(mdet) = "<< ceps*std::abs(Det(m))<<std::endl; } Assert(std::abs(Det(cbi)-Det(cm)) < ceps*std::abs(Det(cm)+Norm(cm)), "Band CDet"); std::complex<T> cmsign, cbsign; Assert(std::abs(cm.logDet(&cmsign)-cbi.logDet(&cbsign)) < N*eps, "Band CLogDet"); Assert(std::abs(cmsign-cbsign) < N*eps,"Band CLogDet - sign"); } tmv::Vector<std::complex<T> > cv(v1 * std::complex<T>(1,1)); cv(1) += std::complex<T>(-1,5); cv(2) -= std::complex<T>(-1,5); if (m.colsize() == N) { // test real / complex tmv::Vector<std::complex<T> > y1 = v1/cbi; tmv::Vector<std::complex<T> > y2 = v1/cm; if (showacc) { std::cout<<"v/cb: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<ceps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < ceps*Norm(y1),"Band v/cb"); // test complex / real y1 = cv/bi; y2 = cv/m; if (showacc) { std::cout<<"cv/b: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<eps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < eps*Norm(y1),"Band cv/b"); // test complex / complex y1 = cv/cbi; y2 = cv/cm; if (showacc) { std::cout<<"cv/cb: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<ceps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < ceps*Norm(y1),"Band cv/cb"); } if (bi.rowsize() == N) { tmv::Vector<std::complex<T> > y1 = v1%cbi; tmv::Vector<std::complex<T> > y2 = v1%cm; if (showacc) { std::cout<<"v%cb: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<ceps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < ceps*Norm(y1),"Band v%cb"); y1 = cv%bi; y2 = cv%m; if (showacc) { std::cout<<"cv%b: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<eps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < eps*Norm(y1),"Band cv%b"); y1 = cv%cbi; y2 = cv%cm; if (showacc) { std::cout<<"cv%cb: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<ceps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < ceps*Norm(y1),"Band cv%cb"); } } TestBandDiv_A<T>(dt); TestBandDiv_B1<T>(dt); TestBandDiv_B2<T>(dt); TestBandDiv_C1<T>(dt); if (dt == tmv::LU) TestBandDiv_C2<T>(dt); TestBandDiv_D1<T>(dt); if (dt == tmv::LU) TestBandDiv_D2<T>(dt); std::cout<<"BandMatrix<"<<tmv::TMV_Text(T())<<"> Division using "; std::cout<<tmv::TMV_Text(dt)<<" passed all tests\n"; }
float F(int k){ return(sqrt(pow(a1(k),2)+pow(b1(k),2)));}
void fitKmm_loQ(Int_t bin) { gSystem->Load("libRooFit"); gROOT->SetStyle("Plain"); gStyle->SetOptStat(1111); TFile * file = TFile::Open("/Disk/ecdf-nfs-ppe/lhcb/gcowan/B2Kll/data/fromAlex/BuKmm.root"); TTree * DecayTree = dynamic_cast<TTree*>(file->Get("DecayTree")); TString binStr; binStr+=bin; Double_t minQ(0.), maxQ(0.); switch(bin) { case 0: minQ = TMath::Sqrt(1.1e6); maxQ = TMath::Sqrt(2.e6); break; case 1: minQ = TMath::Sqrt(2.e6); maxQ = TMath::Sqrt(3.e6); break; case 2: minQ = TMath::Sqrt(3.e6); maxQ = TMath::Sqrt(4.e6); break; case 3: minQ = TMath::Sqrt(4.e6); maxQ = TMath::Sqrt(5.e6); break; case 4: minQ = TMath::Sqrt(5.e6); maxQ = TMath::Sqrt(6.e6); break; default: return; } TString cutStr("Psi_M> "); cutStr += minQ; cutStr += " && Psi_M< "; cutStr += maxQ; //B_M RooRealVar B_M("B_M","; m(Kmumu) (MeV/c^{2}); Candidates / 12 MeV/c^{2}",5150,6000); RooRealVar Psi_M("Psi_M","; m(mumu) (MeV/c^{2}); Candidates / 45 MeV/c^{2}",500,5000); RooDataSet * data = new RooDataSet("data", "dataset with B_REFITTED_M", DecayTree, RooArgSet(B_M,Psi_M)); RooDataSet * data1 = dynamic_cast<RooDataSet*>(data->reduce(cutStr)); // from J/Psi region // 1 #sigma_{Lo} 1.59171e+01 9.61516e-02 1.80663e-03 6.11760e-02 // 2 M_{B} 5.28397e+03 3.00802e-02 1.66677e-03 3.66768e-01 // 3 a1 1.57752e+00 1.64484e-02 2.65338e-03 -7.53912e-01 // 4 a2 -2.64268e+00 2.11254e-02 2.51938e-03 4.90950e-01 // 5 frac 6.78672e-01 1.29969e-02 7.03329e-03 3.65422e-01 // 6 n1 4.79832e+00 2.84430e-01 2.61785e-02 -4.03463e-02 // 7 n2 1.08224e+00 2.68180e-02 5.47500e-03 -9.00362e-01 // 8 nbkg 5.56890e+03 1.31433e+02 7.62084e-03 -8.36640e-01 // 9 nsig 6.56230e+05 8.17224e+02 4.15943e-03 6.95832e-01 // 10 p0 -6.44379e-02 2.13769e-03 2.57927e-02 4.41139e-01 // 11 ratio 1.60407e+00 9.46569e-03 3.93086e-03 -7.72555e-01 // B DCB // start, range to from. plus names and titles. RooRealVar sigmean("M_{B}","B mass",5281.0,5250.0,5300.0,"MeV/c^{2}"); RooRealVar sigsigma("#sigma_{Lo}","B sigma",15.9,0.0,30.0,"MeV/c^{2}"); RooRealVar a1("a1","a1", 1.57752e+00); RooRealVar n1("n1","n1", 4.79832e+00); RooRealVar a2("a2","a2",-2.64268e+00); RooRealVar n2("n2","n2", 1.08224e+00); RooRealVar ratio("ratio","Ratio of widths",1.60407e+00); RooProduct sigsigma2("#sigma_{B}2","B sigma2",RooArgSet(sigsigma,ratio)); RooRealVar frac("frac","fraction of events in each gaussian",6.78672e-01); RooCBShape BSig_RF( "Bsig_RF", "Signal CB B RF Mass", B_M, sigmean, sigsigma, a1, n1 ); RooCBShape BSig_RF2( "Bsig_RF2", "Signal CB B RF Mass", B_M, sigmean, sigsigma2, a2, n2 ); RooAddPdf B0Sig("B0signal","signal pdf",RooArgList(BSig_RF,BSig_RF2),RooArgList(frac)); RooRealVar p0("p0","",-6.44379e-02,-0.1,0.1); RooExponential comb_bkg("comb_bkg","",B_M,p0); // Number of signal & background events RooRealVar nsig("nsig","#signal events",150,-1000,50000,"Events"); RooRealVar nbkg("nbkg","#signal events",150,-1000,50000,"Events"); RooAddPdf full_RF_PDF("full_RF_PDF","RF PDF of everything",RooArgList(B0Sig,comb_bkg), RooArgList(nsig,nbkg)); //# Do the fit on REFITTED Mass full_RF_PDF.fitTo(*data1,RooFit::Extended()); TCanvas * can = new TCanvas("can","Mass fits Data",800,600); B_M_RF_Plot = B_M.frame(100); B_M_RF_Plot->SetTitle(""); B_M_RF_Plot->GetYaxis()->SetTitle("Candidates / 8.5 MeV/c^{2}"); B_M_RF_Plot->GetXaxis()->SetTitle("m(K#mu#mu) (MeV/c^{2})"); data1->plotOn(B_M_RF_Plot); full_RF_PDF.plotOn(B_M_RF_Plot); full_RF_PDF.plotOn(B_M_RF_Plot, RooFit::Components("comb_bkg"), RooFit::LineStyle(kDashed),RooFit::LineColor(kMagenta)); full_RF_PDF.plotOn(B_M_RF_Plot, RooFit::Components("B0signal"), RooFit::LineStyle(kDashed)); B_M_RF_Plot->Draw(); can->SaveAs("plots/Kmm_loQ_"+binStr+".pdf"); can->SetLogy(); B_M_RF_Plot->SetMinimum(1.e-1); B_M_RF_Plot->SetMaximum(5.e+2); B_M_RF_Plot->Draw(); can->SaveAs("plots/Kmm_loQ_"+binStr+"_log.pdf"); //// Try splot stuff //// First set all parameters to constant except for yields sigmean.setConstant(); sigsigma.setConstant(); p0.setConstant(); RooStats::SPlot * sData = new RooStats::SPlot("sData","An SPlot",*data1, &full_RF_PDF, RooArgList(nsig,nbkg)); sData->GetSDataSet()->write("/Home/dcraik/Kll/tuples/Kmm_loQ_"+binStr+"_sWeights.txt"); }
void C3DPlotCanvas::SelectByRect() { int hl_size = highlight_state->GetHighlightSize(); std::vector<bool>& hs = highlight_state->GetHighlight(); std::vector<int>& nh = highlight_state->GetNewlyHighlighted(); std::vector<int>& nuh = highlight_state->GetNewlyUnhighlighted(); int total_newly_selected = 0; int total_newly_unselected = 0; double world11[3], world12[3], world22[3], world21[3]; double world113[3], world123[3], world223[3], world213[3]; int pixel11[2], pixel12[2], pixel22[2], pixel21[2]; int small_x = (select_start.x < select_end.x)? select_start.x:select_end.x; int large_x = (select_start.x > select_end.x)? select_start.x:select_end.x; int small_y = (select_start.y < select_end.y)? select_start.y:select_end.y; int large_y = (select_start.y > select_end.y)? select_start.y:select_end.y; pixel11[0] = small_x; pixel12[0] = small_x; pixel21[0] = large_x; pixel22[0] = large_x; pixel11[1] = small_y; pixel21[1] = small_y; pixel12[1] = large_y; pixel22[1] = large_y; ball->apply_transform(); unproject_pixel(pixel11, world11, 0.0); unproject_pixel(pixel12, world12, 0.0); unproject_pixel(pixel22, world22, 0.0); unproject_pixel(pixel21, world21, 0.0); unproject_pixel(pixel11, world113, 1.0); unproject_pixel(pixel12, world123, 1.0); unproject_pixel(pixel22, world223, 1.0); unproject_pixel(pixel21, world213, 1.0); ball->unapply_transform(); SPlane* plane; int i; bool *inside = new bool[num_obs*4]; for(i=0; i<num_obs*4; i++) inside[i] = false; double *world1, *world2, *world3, *world4; for (int k=0; k<4; k++) { switch(k) { case 0: world1 = world11; world2 = world12; world3 = world113; world4 = world123; break; case 1: world1 = world12; world2 = world22; world3 = world123; world4 = world223; break; case 2: world1 = world22; world2 = world21; world3 = world223; world4 = world213; break; case 3: world1 = world21; world2 = world11; world3 = world213; world4 = world113; break; default: break; } plane = new SPlane(world1, world2, world3); Vec3f a1(world1[0], world1[1], world1[2]); Vec3f a2(world2[0], world2[1], world2[2]); Vec3f a3(world3[0], world3[1], world3[2]); Vec3f a4(world4[0], world4[1], world4[2]); Vec3f l1 = a3 - a1; Vec3f l2 = a4 - a2; int xt = var_info[0].time; int yt = var_info[1].time; int zt = var_info[2].time; for (i=0; i<num_obs; i++) { Vec3f cor(scaled_d[0][xt][i], scaled_d[1][yt][i], scaled_d[2][zt][i]); if (plane->isPositive(cor)) inside[k*num_obs+i] = true; } delete plane; } delete [] inside; for (i=0; i<num_obs; i++) { bool contains = (inside[i] && inside[num_obs+i] && inside[2*num_obs+i] && inside[3*num_obs+i]); if (contains) { if (!hs[i]) nh[total_newly_selected++] = i; } else { if (hs[i]) nuh[total_newly_unselected++] = i; } } if (total_newly_selected == 0 && total_newly_unselected == 0) return; if (total_newly_selected == 0 && total_newly_unselected == highlight_state->GetTotalHighlighted()) { highlight_state->SetEventType(HighlightState::unhighlight_all); highlight_state->notifyObservers(); } else { highlight_state->SetEventType(HighlightState::delta); highlight_state->SetTotalNewlyHighlighted(total_newly_selected); highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); highlight_state->notifyObservers(); } }
template <class T> const T& AbstractRing<T>::Divide(const Element &a, const Element &b) const { // make copy of a in case MultiplicativeInverse() overwrites it Element a1(a); return Multiply(a1, MultiplicativeInverse(b)); }
template <class T> const T& AbstractGroup<T>::Subtract(const Element &a, const Element &b) const { // make copy of a in case Inverse() overwrites it Element a1(a); return Add(a1, Inverse(b)); }
int main() { B b; A a1(b); A a2 = b; }
//Returns true if the triangle is visible bool DepthBuffer::testTriangle2x2(const vec4f& v0,const vec4f& v1,const vec4f& v2){ VecS32 colOffset(0, 1, 0, 1); VecS32 rowOffset(0, 0, 1, 1); vec2i vertex[3]; vertex[0] = vec2i(int32(v0.x),int32(v0.y)); vertex[1] = vec2i(int32(v1.x),int32(v1.y)); vertex[2] = vec2i(int32(v2.x),int32(v2.y)); // Reject the triangle if any of its verts is behind the nearclip plane if(v0.w == 0.0f || v1.w == 0.0f || v2.w == 0.0f) return true; float minZ = std::min(v0.z,std::min(v1.z,v2.z)); VecF32 fixedDepth(minZ); // Fab(x, y) = Ax + By + C = 0 // Fab(x, y) = (ya - yb)x + (xb - xa)y + (xa * yb - xb * ya) = 0 // Compute A = (ya - yb) for the 3 line segments that make up each triangle auto A0 = vertex[1].y - vertex[2].y; auto A1 = vertex[2].y - vertex[0].y; auto A2 = vertex[0].y - vertex[1].y; // Compute B = (xb - xa) for the 3 line segments that make up each triangle auto B0 = vertex[2].x - vertex[1].x; auto B1 = vertex[0].x - vertex[2].x; auto B2 = vertex[1].x - vertex[0].x; // Compute C = (xa * yb - xb * ya) for the 3 line segments that make up each triangle auto C0 = vertex[1].x * vertex[2].y - vertex[2].x * vertex[1].y; auto C1 = vertex[2].x * vertex[0].y - vertex[0].x * vertex[2].y; auto C2 = vertex[0].x * vertex[1].y - vertex[1].x * vertex[0].y; // Use bounding box traversal strategy to determine which pixels to rasterize auto minx = std::max(std::min(std::min(vertex[0].x,vertex[1].x),vertex[2].x),0) & (~1); auto maxx = std::min(std::max(std::max(vertex[0].x,vertex[1].x),vertex[2].x),size_.x-2); auto miny = std::max(std::min(std::min(vertex[0].y,vertex[1].y),vertex[2].y),0) & (~1); auto maxy = std::min(std::max(std::max(vertex[0].y,vertex[1].y),vertex[2].y),size_.y-2); VecS32 a0(A0); VecS32 a1(A1); VecS32 a2(A2); VecS32 b0(B0); VecS32 b1(B1); VecS32 b2(B2); VecS32 col = VecS32(minx) + colOffset; VecS32 row = VecS32(miny) + rowOffset; auto rowIdx = miny*size_.x + 2 * minx; VecS32 w0_row = a0 * col + b0 * row + VecS32(C0); VecS32 w1_row = a1 * col + b1 * row + VecS32(C1); VecS32 w2_row = a2 * col + b2 * row + VecS32(C2); //Multiply each weight by two(rasterize 2x2 quad at once). a0 = shiftl<1>(a0); a1 = shiftl<1>(a1); a2 = shiftl<1>(a2); b0 = shiftl<1>(b0); b1 = shiftl<1>(b1); b2 = shiftl<1>(b2); for(int32 y = miny;y<=maxy;y+=2,rowIdx += 2 * size_.x){ auto w0 = w0_row; auto w1 = w1_row; auto w2 = w2_row; auto idx = rowIdx; for(int32 x = minx;x<=maxx;x+=2,idx+=4){ auto mask = w0|w1|w2; auto masks = _mm_movemask_ps(bits2float(mask).simd); if(masks != 0xF){ VecF32 previousDepth = VecF32::load(data_+idx); auto cmpMask = ((~masks)&0xF)& _mm_movemask_ps(cmple(fixedDepth,previousDepth).simd); if(cmpMask){ return true; } } w0+=a0; w1+=a1; w2+=a2; } w0_row += b0; w1_row += b1; w2_row += b2; } return false; }
float fi(int k){ return(atan(b1(k)/a1(k)));}
int main () try { auto usb = usb_open(); std::shared_ptr<libusb_device_handle> dh = usb_device_get (usb.get(), 0x1130, 0x660c); usb_attach_interface a1 (dh, 0); usb_attach_interface a2 (dh, 1); usb_error::check (libusb_set_configuration (dh.get (), 1)); usb_claim_interface i1 (dh, 0); usb_claim_interface i2 (dh, 1); // init { struct dev_info { uint16_t dev_type; uint8_t cal[2][2]; // OpenBSD repeatedly issues the devtype command until this != 0x53 // Maybe this is necessary if the device has just been plugged in // and has not settled yet? uint8_t footer; } dinfo; msg256 dinfo_raw = read_data (dh, cmd_devtype); std::copy (std::begin(dinfo_raw), std::end(dinfo_raw), reinterpret_cast<unsigned char*> (&dinfo)); //int val; switch (dinfo.dev_type) { case dev_type_temper1: send_cmd (dh, cmd_reset0); /*val = (dinfo.cal[0][0] - 0x14) * 100; val += dinfo.cal[0][1] * 10; std::cerr << "calibration: " << val << std::endl;*/ break; default: throw std::runtime_error ("unknwon device type"); } } // read { msg256 d = read_data (dh, cmd_getdata_inner); // raw values /* std::ostringstream h; h << std::hex << "0x" << int (d[0]) << " 0x" << int (d[1]); std::cout << h.str () << std::endl; std::cout << ((d[0] << 8) + (d[1] & 0xff)) << std::endl; */ // from OpenBSD //std::cout << d[0] * 100 + (d[1] >> 4) * 25 / 4 << std::endl; // easy way std::cout << float (d[0]) + float (d[1])/256 << '\n'; } return EXIT_SUCCESS; } catch (std::exception& e) { std::cerr << "exception: " << e.what () << std::endl; return EXIT_FAILURE; }
void test() { cout << " zDate Class Demo \n\n"; // default constructor, Jan 1 0000 zDate a; cout << a << endl; // Various versions of the constructors zDate x(zDate::oct,20,1962); cout << x << endl; // constructor with a julian zDate z( 2450000L ); cout << z << endl; // make a date with system date (tests copy constructor) zDate s(zDate::Today()); cout << s << endl; // init with the day of year zDate y(33, 1996); cout << y << endl; // init from current system time time_t secs_now = time(NULL); zDate n(localtime(&secs_now)); cout << n << endl; // using date addition and subtraction zDate adder = x + 10; cout << adder << endl; adder = adder - 25; cout << adder << endl; //using subtraction of two date objects zDate a1(zDate::Today()); zDate a2 = a1 + 14; cout << (a1 - a2) << endl; cout << (a2 += 10) << endl; a1++; cout << "Tommorrow= " << a1 << endl; a1 = zDate(zDate::jul, 14, 1991); cout << "a1 (7-14-91) < a2 (" << a2 << ")? ==> " << ((a1 < a2) ? "TRUE" : "FALSE") << endl; cout << "a1 (7-14-91) > a2 ("<< a2 << ")? ==> " << ((a1 > a2) ? "TRUE" : "FALSE") << endl; cout << "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1 < zDate(zDate::aug, 1, 1991)) ? "TRUE" : "FALSE") << endl; cout << "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1 > zDate(zDate::aug, 1, 1991)) ? "TRUE" : "FALSE") << endl; cout << "a1 (7-14-91) == 7-14-91 ? ==> " << ((a1==zDate(zDate::jul, 14, 1991)) ? "TRUE" : "FALSE") << endl; zDate a3 = a1; cout << "a1 (" << a1 << ") == a3 (" << a3 << ") ? ==> " << ((a1==a3) ? "TRUE" : "FALSE") << endl; zDate a4 = a1; ++a4; cout << "a1 ("<< a1 <<") == a4 (" << a4 << ") ? ==> " << ((a1==a4) ? "TRUE" : "FALSE") << endl; zDate a5(zDate::Today()); cout << "Today is: " << a5 << endl; a4 = zDate::Today(); cout << "Today (a4) is: " << a4 << endl; cout << "Today + 4 is: " << (a4 += 4) << endl; a4 = zDate::Today(); cout << "Today - 4 is: " << (a4 -= 4) << endl; cout << "=========== Leap Year Test ===========\n"; a1 = zDate(zDate::jan, 15, 1992); cout << a1 << "\t" << ((a1.IsLeapYear()) ? "Leap" : "non-Leap"); cout << "\t" << "day of year: " << a1.DayOfYear() << endl; a1 = zDate(zDate::feb, 16, 1993); cout << a1 << "\t" << ((a1.IsLeapYear()) ? "Leap" : "non-Leap"); cout << "\t" << "day of year: " << a1.DayOfYear() << endl; zDate v4(zDate::Today()); cout << "---------- Add Stuff -----------\n"; cout << "Start => " << v4 << endl; cout << "Add 4 Weeks => " << v4.AddWeeks(4) << endl; cout << "Sub 52 Weeks => " << v4.AddWeeks(-52) << endl; cout << "Add 2 Years => " << v4.AddYears(2) << endl; cout << flush; cout << "---------- Misc Stuff -----------\n"; cout << "The date aboves' day of the month is => " << v4.Day() << endl; cout << "There are " << v4.DaysInMonth() << " days in this month.\n"; cout << "This day happens to be " << v4.DayOfWeek() << " day of week" << endl; cout << "on the " << v4.WeekOfYear() << " week of the year," << endl; cout << "on the " << v4.WeekOfMonth() << " week of the month, " << endl; cout << "which is the "<< (int)v4.Month() << "nth month in the year.\n"; cout << "The year alone is " << v4.Year() << endl; cout << "And this is the " << v4.DayOfYear() << " day of year" << endl; cout << "of a year with " << v4.DaysInYear() << " days in it" << endl; cout << "which makes exatcly " << v4.WeeksInYear() << " weeks" << endl; zDate birthday(zDate::jul, 16, 1973); cout << "The age test: i was born on " << birthday << " which makes me " << v4.Age(birthday) << " years old" << endl; zDate D2(zDate::jul, 4, 1776); int I1 = 4; cout << "Before: I1 = " << I1 << ", D2 = " << D2 << endl; cout << "---------- Postfix '++' test -----------\n"; cout << "Test : I1++ = " << I1++ << ", D2++ = " << D2++ << endl; cout << "After: I1 = " << I1 << ", D2 = " << D2 << endl; cout << "---------- Prefix '++' test -----------\n"; cout << "Test : ++I1 = " << ++I1 << ", ++D2 = " << ++D2 << endl; cout << "After: I1 = " << I1 << ", D2 = " << D2 << endl; cout << "---------- Postfix '--' test -----------\n"; cout << "Test : I1-- = " << I1-- << ", D2-- = " << D2-- << endl; cout << "After: I1 = " << I1 << ", D2 = " << D2 << endl; cout << "---------- Prefix '--' test -----------\n"; cout << "Test : --I1 = " << --I1 << ", --D2 = " << --D2 << endl; cout << "After: I1 = " << I1 << ", D2 = " << D2 << endl; cout << "Last day of this year is dayno " << zDate(zDate::dec, 31, 1996).DayOfYear() << endl; cout << "Last day of prev year is dayno " << zDate(zDate::dec, 31, 1995).DayOfYear() << endl; cout << "Today the moon is " << zDate::Today().MoonPhase() << endl; zDate today = zDate::Today(); cout << "DST for " << today.Year() << " starts on " << today.BeginDST() << " and ends on " << today.EndDST() << endl; cout << "Today, " << today << ", DST is " << (today.IsDST() ? "" : "not") << "in effect" << endl; zDate date1(zDate::aug, 31, 1996); cout << "Adding 6 months to " << date1 << " results in " << date1.AddMonths(6) << endl; zDate date2(zDate::mar, 31, 1996); cout << "Subtracting 1 month from " << date2 << " results in " << date2.AddMonths(-1) << endl; zDate date3(zDate::jul, 4, 1776); cout << "Adding 2400 months to " << date3 << " results in " << date3.AddMonths(2400) << endl; cout << "Today's day number is " << zDate::Today().DayNumber() << endl; zDate date4(zDate::feb, 29, 1996); cout << date4 << " subtract two years = " << date4.AddYears(-2) << endl; cout << "In 1996, DST began on " << zDate::BeginDST(1996) << endl; zDate date5(zDate::sep, 26, 1996); cout << "Moon phase on " << date5 << " was " << date5.MoonPhase() << endl; zDate date6(zDate::oct, 3, 1996); cout << date6 << " + 55 days is " << (date6 + 55) << endl; zDate date7(zDate::oct, 4, 1996); cout << date7 << " + 217 days is "; date7 += 217; cout << date7 << endl; date7 = zDate(zDate::oct, 4, 1996); cout << "Same date - (-217) days is "; date7 -= -217; cout << date7 << endl; cout << "For 1996, Easter is on " << zDate::Easter(1996) << endl; }
void test() { // This function tests C++0x 5.16 // p1 (contextually convert to bool) int i1 = ToBool() ? 0 : 1; // p2 (one or both void, and throwing) i1 ? throw 0 : throw 1; i1 ? test() : throw 1; i1 ? throw 0 : test(); i1 ? test() : test(); i1 = i1 ? throw 0 : 0; i1 = i1 ? 0 : throw 0; i1 = i1 ? (throw 0) : 0; i1 = i1 ? 0 : (throw 0); i1 ? 0 : test(); // expected-error {{right operand to ? is void, but left operand is of type 'int'}} i1 ? test() : 0; // expected-error {{left operand to ? is void, but right operand is of type 'int'}} (i1 ? throw 0 : i1) = 0; // expected-error {{expression is not assignable}} (i1 ? i1 : throw 0) = 0; // expected-error {{expression is not assignable}} // p3 (one or both class type, convert to each other) // b1 (lvalues) Base base; Derived derived; Convertible conv; Base &bar1 = i1 ? base : derived; Base &bar2 = i1 ? derived : base; Base &bar3 = i1 ? base : conv; Base &bar4 = i1 ? conv : base; // these are ambiguous BadBase bb; BadDerived bd; (void)(i1 ? bb : bd); // expected-error {{conditional expression is ambiguous; 'BadBase' can be converted to 'BadDerived' and vice versa}} (void)(i1 ? bd : bb); // expected-error {{conditional expression is ambiguous}} // curiously enough (and a defect?), these are not // for rvalues, hierarchy takes precedence over other conversions (void)(i1 ? BadBase() : BadDerived()); (void)(i1 ? BadDerived() : BadBase()); // b2.1 (hierarchy stuff) extern const Base constret(); extern const Derived constder(); // should use const overload A a1((i1 ? constret() : Base()).trick()); A a2((i1 ? Base() : constret()).trick()); A a3((i1 ? constret() : Derived()).trick()); A a4((i1 ? Derived() : constret()).trick()); // should use non-const overload i1 = (i1 ? Base() : Base()).trick(); i1 = (i1 ? Base() : Base()).trick(); i1 = (i1 ? Base() : Derived()).trick(); i1 = (i1 ? Derived() : Base()).trick(); // should fail: const lost (void)(i1 ? Base() : constder()); // expected-error {{incompatible operand types ('Base' and 'const Derived')}} (void)(i1 ? constder() : Base()); // expected-error {{incompatible operand types ('const Derived' and 'Base')}} Priv priv; Fin fin; (void)(i1 ? Base() : Priv()); // expected-error{{private base class}} (void)(i1 ? Priv() : Base()); // expected-error{{private base class}} (void)(i1 ? Base() : Fin()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? Fin() : Base()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? base : priv); // expected-error {{private base class}} (void)(i1 ? priv : base); // expected-error {{private base class}} (void)(i1 ? base : fin); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? fin : base); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}} // b2.2 (non-hierarchy) i1 = i1 ? I() : i1; i1 = i1 ? i1 : I(); I i2(i1 ? I() : J()); I i3(i1 ? J() : I()); // "the type [it] woud have if E2 were converted to an rvalue" vfn pfn = i1 ? F() : test; pfn = i1 ? test : F(); (void)(i1 ? A() : B()); // expected-error {{conversion from 'B' to 'A' is ambiguous}} (void)(i1 ? B() : A()); // expected-error {{conversion from 'B' to 'A' is ambiguous}} (void)(i1 ? 1 : Ambig()); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}} (void)(i1 ? Ambig() : 1); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}} // By the way, this isn't an lvalue: &(i1 ? i1 : i2); // expected-error {{cannot take the address of an rvalue}} // p4 (lvalue, same type) Fields flds; int &ir1 = i1 ? flds.i1 : flds.i2; (i1 ? flds.b1 : flds.i2) = 0; (i1 ? flds.i1 : flds.b2) = 0; (i1 ? flds.b1 : flds.b2) = 0; // p5 (conversion to built-in types) // GCC 4.3 fails these double d1 = i1 ? I() : K(); pfn = i1 ? F() : G(); DFnPtr pfm; pfm = i1 ? DFnPtr() : &Base::fn1; pfm = i1 ? &Base::fn1 : DFnPtr(); // p6 (final conversions) i1 = i1 ? i1 : ir1; int *pi1 = i1 ? &i1 : 0; pi1 = i1 ? 0 : &i1; i1 = i1 ? i1 : EVal; i1 = i1 ? EVal : i1; d1 = i1 ? 'c' : 4.0; d1 = i1 ? 4.0 : 'c'; Base *pb = i1 ? (Base*)0 : (Derived*)0; pb = i1 ? (Derived*)0 : (Base*)0; pfm = i1 ? &Base::fn1 : &Derived::fn2; pfm = i1 ? &Derived::fn2 : &Base::fn1; pfm = i1 ? &Derived::fn2 : 0; pfm = i1 ? 0 : &Derived::fn2; const int (MixedFieldsDerived::*mp1) = i1 ? &MixedFields::ci : &MixedFieldsDerived::i; const volatile int (MixedFields::*mp2) = i1 ? &MixedFields::ci : &MixedFields::cvi; (void)(i1 ? &MixedFields::ci : &MixedFields::vi); // Conversion of primitives does not result in an lvalue. &(i1 ? i1 : d1); // expected-error {{cannot take the address of an rvalue}} (void)&(i1 ? flds.b1 : flds.i1); // expected-error {{address of bit-field requested}} (void)&(i1 ? flds.i1 : flds.b1); // expected-error {{address of bit-field requested}} unsigned long test0 = 5; test0 = test0 ? (long) test0 : test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}} test0 = test0 ? (int) test0 : test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? (short) test0 : test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}} test0 = test0 ? test0 : (long) test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}} test0 = test0 ? test0 : (int) test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? test0 : (short) test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}} test0 = test0 ? test0 : (long) 10; test0 = test0 ? test0 : (int) 10; test0 = test0 ? test0 : (short) 10; test0 = test0 ? (long) 10 : test0; test0 = test0 ? (int) 10 : test0; test0 = test0 ? (short) 10 : test0; int test1; test0 = test0 ? EVal : test0; test1 = test0 ? EVal : (int) test0; test0 = test0 ? EVal : test1; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? test1 : EVal; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test1 = test0 ? EVal : (int) test0; test1 = test0 ? (int) test0 : EVal; // Note the thing that this does not test: since DR446, various situations // *must* create a separate temporary copy of class objects. This can only // be properly tested at runtime, though. const Abstract &a = true ? static_cast<const Abstract&>(Derived1()) : Derived2(); // expected-error {{allocating an object of abstract class type 'const Abstract'}} true ? static_cast<const Abstract&>(Derived1()) : throw 3; // expected-error {{allocating an object of abstract class type 'const Abstract'}} }
std::tuple<bool, vector, float, vector, vector> shape::distance(shape const& shape) const { vector direction(shape.centroid() - centroid()); vector a1(vertices_[support(direction)]); vector a2(shape.vertices()[shape.support(-direction)]); vector a(a1 - a2); vector b1(vertices_[support(-direction)]); vector b2(shape.vertices()[shape.support(direction)]); vector b(b1 - b2); vector c1, c2, c; direction = segment(b, a).closest(vector()); for(int unsigned iterations(0); iterations < 10; ++iterations) { direction = -direction.normalize(); if(!direction) return std::make_tuple(false, vector(), 0.0f, vector(), vector()); c1 = vertices_[support(direction)]; c2 = shape.vertices()[shape.support(-direction)]; c = c1 - c2; if(a.cross(b) * b.cross(c) > 0.0f && a.cross(b) * c.cross(a) > 0.0f) return std::make_tuple(false, vector(), 0.0f, vector(), vector()); float const projection(c.dot(direction)); if(projection - a.dot(direction) < std::sqrt(std::numeric_limits<float>::epsilon())) { std::tuple<vector, vector> const closest_points(get_closest_points(a1, a2, a, b1, b2, b)); return std::make_tuple(true, direction, -projection, std::get<0>(closest_points), std::get<1>(closest_points)); } vector const point1(segment(a, c).closest(vector())); vector const point2(segment(c, b).closest(vector())); float const point1_length(point1.length()); float const point2_length(point2.length()); if(point1_length <= std::numeric_limits<float>::epsilon()) { std::tuple<vector, vector> const closest_points(get_closest_points(a1, a2, a, c1, c2, c)); return std::make_tuple(true, direction, point1_length, std::get<0>(closest_points), std::get<1>(closest_points)); } else if(point2_length <= std::numeric_limits<float>::epsilon()) { std::tuple<vector, vector> const closest_points(get_closest_points(c1, c2, c, b1, b2, b)); return std::make_tuple(true, direction, point2_length, std::get<0>(closest_points), std::get<1>(closest_points)); } if(point1_length < point2_length) { b1 = c1; b2 = c2; b = c; direction = point1; } else { a1 = c1; a2 = c2; a = c; direction = point2; } } std::tuple<vector, vector> const closest_points(get_closest_points(a1, a2, a, b1, b2, b)); return std::make_tuple(true, direction, -c.dot(direction), std::get<0>(closest_points), std::get<1>(closest_points)); }
void TunnelLevel::setup(){ INFO("Generating Test Level..."); readFile(); initalizeGrid(); createRenders(); createLevel(); INFO("Removal String so less of make"); waterSurfaceManager = WaterSurfaceManagerPtr(new WaterSurfaceManager()); addGameObject(waterSurfaceManager); CameraPtr cam3(new Camera(glm::vec3(30, 45, 0), glm::vec3(30, 15, 6), glm::vec3(0, 1, 0))); cam3->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); addCamera("CinematicCamera", cam3); setMainCamera("CinematicCamera"); setCullingCamera("CinematicCamera"); INFO("Setting up the cameras for the Test Level..."); CameraPtr cam1(new Camera(glm::vec3(32.0f, 12.0f, -24.0f), glm::vec3(4, 4, -10), glm::vec3(0, 1, 0))); cam1->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); addCamera("Camera1", cam1); setMainCamera("Camera1"); setCullingCamera("Camera1"); CameraPtr cam2(new Camera(glm::vec3(0, 1, 0), glm::vec3(-6, -3, 6), glm::vec3(0, 1, 0))); cam2->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); l1 = LightPtr(new Light(glm::vec3(1), 30.0f, glm::vec3(32, 30, -20))); l1->setPosition(l1->getDirection()); Uniform3DGridPtr<int> typeGrid = getTypeGrid(); gridCenter = glm::vec3((typeGrid->getMaxX() - typeGrid->getMinX())/2.0f, (typeGrid->getMaxY() - typeGrid->getMinY())/2.0f, (typeGrid->getMinZ() - typeGrid->getMaxZ())/2.0f); l1->setViewMatrix(glm::lookAt( l1->getPosition(), gridCenter, glm::vec3(0, 1, 0))); l1->setProjectionMatrix(glm::ortho<float>(-30,30,-30,30,-70,70)); addLight("Sun", l1); cinematicPlayer = CinematicPlayerPtr(new CinematicPlayer(cam3)); cinematicPlayer->setup(); addGameObject("cinematicPlayer", cinematicPlayer); INFO("Setting up the player for the Test Level..."); player = PlayerPtr(new Player(cam1, 2)); player->setup(); addGameObject("player" , player); CollisionManager::addCollisionObjectToList(player); debugPlayer = DebugPlayerPtr(new DebugPlayer(cam2)); debugPlayer->setup(); addGameObject("debugPlayer" , debugPlayer); addCamera("DebugCamera", cam2); INFO("Creating Switch for the Test Level..."); SwitchPtr s1(new Switch(glm::vec3(0.9f, 0.1f, 0.1f), glm::vec3(33.7f, 11.0f, -27.0f), glm::vec3(0,0,1), -20.0f, 1)); s1->setup(); addGameObject("s1", s1); CollisionManager::addCollisionObjectToGrid(s1); std::list<SolidCubePtr> solidCubes; // INFO("Creating Active Terrain for the Test Level..."); for(int i = 11; i < 36; i+=2) { for(int j = -27; j < -20; j+=2) { SolidCubePtr at1(new SolidCube(glm::vec3(29, i, j))); at1->setup(); RenderEngine::getRenderGrid()->removeObject(at1->getObject()); solidCubes.push_back(at1); } } ActiveTerrainPtr a1(new ActiveTerrain(s1, glm::vec3(), glm::vec3(), 50.0f)); a1->setup(); a1->setCubes(solidCubes); addGameObject("a1", a1); sky = ObjectPtr(new Object( LoadManager::getMesh("sphere.obj"), MaterialManager::getMaterial("None"))); sky->applyTexture(LoadManager::getTexture("Sky")); sky->enableTexture(); sky->scale(glm::vec3(-50.0f,-50.0f,-50.0f)); sky->translate(Director::getScene()->getCamera()->getEye()); RenderEngine::getRenderElement("textured")->addObject(sky); ExclamationPtr exclamation = ExclamationPtr(new Exclamation(glm::vec3(60, 5, -23))); exclamation->setup(); addGameObject("exclamation", exclamation); PTR_CAST(SolidCube, (*grid)(7, 20, 11))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(7, 20, 12))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(7, 20, 11))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); PTR_CAST(SolidCube, (*grid)(7, 20, 12))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); shearRegion(8, 10, 21, 21, 11, 12, 1, 0, 0.0f); shearRegion(11, 13, 20, 20, 11, 12, 1, 0, 0.5f); PTR_CAST(SolidCube, (*grid)(16, 12, 0))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(17, 12, 0))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(16, 12, 0))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); PTR_CAST(SolidCube, (*grid)(17, 12, 0))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); shearRegion(16, 17, 13, 13, 1, 4, 0, 1, 0.0f); shearRegion(16, 17, 12, 12, 5, 8, 0, 1, 0.5f); PTR_CAST(SolidCube, (*grid)(16, 12, 23))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(17, 12, 23))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(16, 12, 23))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); PTR_CAST(SolidCube, (*grid)(17, 12, 23))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); shearRegion(16, 17, 13, 13, 19, 22, 0, -1, 0.0f); shearRegion(16, 17, 12, 12, 15, 18, 0, -1, 0.5f); PTR_CAST(SolidCube, (*grid)(26, 12, 15))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(26, 12, 8))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(26, 12, 15))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); PTR_CAST(SolidCube, (*grid)(26, 12, 8))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); }
/************************************************************************* Tests EVD problem *************************************************************************/ static void testevdproblem(const ap::real_1d_array& d, const ap::real_1d_array& e, int n, double& valerr, double& vecerr, bool& wnsorted, int& failc) { ap::real_1d_array lambda; ap::real_1d_array lambdaref; ap::real_2d_array z; ap::real_2d_array zref; ap::real_2d_array a1; ap::real_2d_array a2; ap::real_2d_array ar; bool wsucc; int i; int j; int k; int m; int i1; int i2; double v; double a; double b; lambdaref.setbounds(0, n-1); zref.setbounds(0, n-1, 0, n-1); a1.setbounds(0, n-1, 0, n-1); a2.setbounds(0, n-1, 0, n-1); // // Reference EVD // if( !refevd(d, e, n, lambdaref, zref) ) { failc = failc+1; return; } // // Test different combinations // for(i1 = 0; i1 <= n-1; i1++) { for(i2 = i1; i2 <= n-1; i2++) { // // Select A, B // if( i1>0 ) { a = 0.5*(lambdaref(i1)+lambdaref(i1-1)); } else { a = lambdaref(0)-1; } if( i2<n-1 ) { b = 0.5*(lambdaref(i2)+lambdaref(i2+1)); } else { b = lambdaref(n-1)+1; } // // Test interval, no vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } if( !smatrixtdevdr(lambda, e, n, 0, a, b, m, z) ) { failc = failc+1; return; } if( m!=i2-i1+1 ) { failc = failc+1; return; } for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } // // Test indexes, no vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } if( !smatrixtdevdi(lambda, e, n, 0, i1, i2, z) ) { failc = failc+1; return; } m = i2-i1+1; for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } // // Test interval, transform vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } a1.setbounds(0, n-1, 0, n-1); a2.setbounds(0, n-1, 0, n-1); for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a1(i,j) = 2*ap::randomreal()-1; a2(i,j) = a1(i,j); } } if( !smatrixtdevdr(lambda, e, n, 1, a, b, m, a1) ) { failc = failc+1; return; } if( m!=i2-i1+1 ) { failc = failc+1; return; } for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } ar.setbounds(0, n-1, 0, m-1); for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(a2.getrow(i, 0, n-1), zref.getcolumn(i1+j, 0, n-1)); ar(i,j) = v; } } for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(a1.getcolumn(j, 0, n-1), ar.getcolumn(j, 0, n-1)); if( v<0 ) { ap::vmul(ar.getcolumn(j, 0, n-1), -1); } } for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { vecerr = ap::maxreal(vecerr, fabs(a1(i,j)-ar(i,j))); } } // // Test indexes, transform vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } a1.setbounds(0, n-1, 0, n-1); a2.setbounds(0, n-1, 0, n-1); for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a1(i,j) = 2*ap::randomreal()-1; a2(i,j) = a1(i,j); } } if( !smatrixtdevdi(lambda, e, n, 1, i1, i2, a1) ) { failc = failc+1; return; } m = i2-i1+1; for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } ar.setbounds(0, n-1, 0, m-1); for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(a2.getrow(i, 0, n-1), zref.getcolumn(i1+j, 0, n-1)); ar(i,j) = v; } } for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(a1.getcolumn(j, 0, n-1), ar.getcolumn(j, 0, n-1)); if( v<0 ) { ap::vmul(ar.getcolumn(j, 0, n-1), -1); } } for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { vecerr = ap::maxreal(vecerr, fabs(a1(i,j)-ar(i,j))); } } // // Test interval, do not transform vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } z.setbounds(0, 0, 0, 0); if( !smatrixtdevdr(lambda, e, n, 2, a, b, m, z) ) { failc = failc+1; return; } if( m!=i2-i1+1 ) { failc = failc+1; return; } for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(z.getcolumn(j, 0, n-1), zref.getcolumn(i1+j, 0, n-1)); if( v<0 ) { ap::vmul(z.getcolumn(j, 0, n-1), -1); } } for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { vecerr = ap::maxreal(vecerr, fabs(z(i,j)-zref(i,i1+j))); } } // // Test interval, do not transform vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } z.setbounds(0, 0, 0, 0); if( !smatrixtdevdi(lambda, e, n, 2, i1, i2, z) ) { failc = failc+1; return; } m = i2-i1+1; for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(z.getcolumn(j, 0, n-1), zref.getcolumn(i1+j, 0, n-1)); if( v<0 ) { ap::vmul(z.getcolumn(j, 0, n-1), -1); } } for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { vecerr = ap::maxreal(vecerr, fabs(z(i,j)-zref(i,i1+j))); } } } } }
void fit_and_weights_norm(){ gROOT->ProcessLine(".x ~/cern/scripts/lhcbStyle.C"); //lhcbStyle(); gStyle->SetLabelSize(0.05,"x"); gStyle->SetLabelSize(0.05,"y"); gStyle->SetTitleSize(0.05,"x"); gStyle->SetPaperSize(20,26); gStyle->SetPadTopMargin(0.0); gStyle->SetPadRightMargin(0.05); // increase for colz plots gStyle->SetPadBottomMargin(0.0); gStyle->SetPadLeftMargin(0.14); gStyle->SetTitleH(0.01); // const std::string filename("/afs/cern.ch/work/a/apmorris/private/cern/ntuples/new_tuples/normalisation_samples/Lb2JpsipK_2011_2012_signal_withbdt_cut_05.root"); const std::string treename = "withbdt"; const std::string out_file_mass("~/cern/plots/fitting/Lb2JpsipK_2011_2012_mass_fit_after_bdtg3_05.png"); // TFile* file = TFile::Open( filename.c_str() ); if( !file ) std::cout << "file " << filename << " does not exist" << std::endl; TTree* tree = (TTree*)file->Get( treename.c_str() ); if( !tree ) std::cout << "tree " << treename << " does not exist" << std::endl; // -- signal, mass shape RooRealVar Lambda_b0_DTF_MASS_constr1("Lambda_b0_DTF_MASS_constr1","m(#chi_{c}pK^{-})", 5550., 5700., "MeV/c^{2}"); RooRealVar Jpsi_M("Jpsi_M","m(#mu#mu)", 3000., 3200., "MeV/c^{2}"); //RooRealVar chi_c_M("chi_c_M","m(J/#psi#gamma)", 3400., 3700., "MeV/c^{2}"); RooRealVar mean("mean","mean", 5630., 5610., 5650.); RooRealVar sigma1("sigma1","sigma1", 10., 1., 100.); RooRealVar sigma2("sigma2","sigma2", 30.0, 5.0, 300.0); RooRealVar alpha1("alpha1","alpha1", 1.0, 0.5, 5.0); RooRealVar n1("n1","n1", 1.8, 0.2, 15.0); RooRealVar alpha2("alpha2","alpha2", -0.5, -5.5, 0.0); RooRealVar n2("n2","n2", 0.7, 0.2, 10.0); //RooRealVar bkgcat_chic("bkgcat_chic","bkgcat_chic", 0, 100); RooRealVar bdtg3("bdtg3", "bdtg3", -1.0, 1.0); // RooRealVar frac2("frac2","frac2", 0.3, 0., 1.); Lambda_b0_DTF_MASS_constr1.setBins(75); RooGaussian gauss1("gauss1","gauss1", Lambda_b0_DTF_MASS_constr1, mean, sigma1); RooGaussian gauss2("gauss2","gauss2", Lambda_b0_DTF_MASS_constr1, mean, sigma2); RooCBShape cb1("cb1","cb1", Lambda_b0_DTF_MASS_constr1, mean, sigma1, alpha1, n1); RooCBShape cb2("cb2","cb2", Lambda_b0_DTF_MASS_constr1, mean, sigma2, alpha2, n2); RooAddPdf sig("sig", "sig", RooArgList(cb1, cb2), RooArgList( frac2 )); RooRealVar cbRatio("cbRatio","cb Ratio", 0.8, 0.1, 1.0); RooRealVar sigYield("sigYield","sig Yield", 4e2, 1e1, 1e4); RooRealVar bgYield("bgYield","bg Yield", 1e2, 1e0, 5e5); //put in values from fit_MC here <<--- DON'T FORGET TO CHANGE THESE IF THE FIT CHANGES!!! /* EXT PARAMETER INTERNAL INTERNAL NO. NAME VALUE ERROR STEP SIZE VALUE 1 alpha1 1.74154e+00 3.36750e-02 1.24897e-04 -4.64754e-01 2 alpha2 -2.02379e+00 6.38694e-02 1.18078e-04 2.87434e+00 3 cbRatio 3.81630e-01 2.53217e-02 1.04396e-03 -3.83487e-01 4 mean 5.61983e+03 1.06900e-02 5.57074e-05 -9.73350e-02 5 n1 3.61886e+00 1.29299e-01 2.50836e-04 -5.68053e-01 6 n2 3.28978e+00 1.59452e-01 3.00100e-04 -3.78398e-01 7 sigma1 7.37006e+00 1.49989e-01 2.60360e-05 -1.05787e+00 8 sigma2 4.90330e+00 4.88847e-02 5.78092e-06 -1.44570e+00 */ alpha1.setVal( 1.74154e+00 ); alpha2.setVal( -2.02379e+00 ); n1.setVal( 3.61886e+00 ); n2.setVal( 3.28978e+00 ); frac2.setVal( 3.81630e-01 ); sigma1.setVal( 7.37006e+00 ); sigma2.setVal( 4.90330e+00 ); alpha1.setConstant( true ); alpha2.setConstant( true ); frac2.setConstant( true ); n1.setConstant( true ); n2.setConstant( true ); sigma1.setConstant( true ); sigma2.setConstant( true ); // -- bg, mass shape RooRealVar a1("a1","a1", -0.1, -0.5, 0.5); RooChebychev comb("comb","comb", Lambda_b0_DTF_MASS_constr1, a1); RooRealVar mean3("mean3","mean3", 5560., 5500., 5600.); RooRealVar sigma3("sigma3","sigma3", 5., 1., 10.); RooRealVar frac3("frac3","frac", 0.2, 0.0, 0.3); RooGaussian gauss3("gauss3","gauss3", Lambda_b0_DTF_MASS_constr1, mean3, sigma3); RooAddPdf bg("bg","bg", RooArgList(gauss3, comb), RooArgList(frac3)); // -- add signal & bg RooAddPdf pdf("pdf", "pdf", RooArgList(sig, comb), RooArgList( sigYield, bgYield)); RooArgSet obs; obs.add(Lambda_b0_DTF_MASS_constr1); obs.add(Jpsi_M); //obs.add(chi_c_M); //obs.add(proton_ProbNNp); //obs.add(proton_ProbNNk); //obs.add(kaon_ProbNNp); //obs.add(kaon_ProbNNk); RooDataSet ds("ds","ds", obs, RooFit::Import(*tree)); RooPlot* plot = Lambda_b0_DTF_MASS_constr1.frame(); RooFitResult * result = pdf.fitTo( ds, RooFit::Extended() ); ds.plotOn( plot ); pdf.plotOn( plot ); RooPlot* plotPullMass = Lambda_b0_DTF_MASS_constr1.frame(); plotPullMass->addPlotable( plot->pullHist() ); //plotPullMass->SetMinimum(); //plotPullMass->SetMaximum(); TCanvas* c = new TCanvas(); TPad* pad1 = new TPad("pad1","pad1", 0, 0.3, 1, 1.0); pad1->SetBottomMargin(0.0); pad1->SetTopMargin(0.01); pad1->Draw(); c->cd(); TPad* pad2 = new TPad("pad2","pad2", 0, 0., 1, 0.3); pad2->SetBottomMargin(0.0); pad2->SetTopMargin(0.0); pad2->Draw(); pdf.plotOn( plot, RooFit::Components( sig ), RooFit::LineColor( kTeal ), RooFit::LineStyle(kDashed) ); pdf.plotOn( plot, RooFit::Components( comb ), RooFit::LineColor( kOrange ), RooFit::LineStyle(kDashed) ); pdf.plotOn( plot, RooFit::Components( gauss3 ), RooFit::LineColor( kViolet ), RooFit::LineStyle(kDashed) ); pad1->cd(); plot->Draw(); pad2->cd(); plotPullMass->Draw("AP"); c->SaveAs(out_file_mass.c_str()); /* RooStats::SPlot* sData = new RooStats::SPlot("sData","An SPlot", ds, &pdf, RooArgList(sigYield, bgYield) ); RooDataSet * dataw_z = new RooDataSet(ds.GetName(),ds.GetTitle(),&ds,*(ds.get()),0,"sigYield_sw") ; TTree *tree_data = (TTree*)dataw_z->tree(); TFile * newfile = TFile::Open("/afs/cern.ch/work/a/apmorris/private/cern/ntuples/new_tuples/weighted_data.root","RECREATE"); tree_data->Write(); newfile->Close(); */ /* TCanvas* d = new TCanvas(); RooPlot* w_chi_c_Mp = chi_c_Mp.frame(); dataw_z->plotOn(w_chi_c_Mp, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ; w_chi_c_Mp->Draw(); d->SaveAs("m_chicp_sweighted.png"); TCanvas* e = new TCanvas(); RooPlot* w_mass_pK = mass_pK.frame(); dataw_z->plotOn(w_mass_pK, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ; w_mass_pK->Draw(); e->SaveAs("m_pK_sweighted.png"); */ /* TCanvas* f = new TCanvas(); RooPlot* w_Jpsi_M = Jpsi_M.frame(); dataw_z->plotOn(w_Jpsi_M, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ; w_Jpsi_M->Draw(); f->SaveAs("~/cern/plots/m_Jpsi_sweighted.png"); TCanvas* g = new TCanvas(); RooPlot* w_chi_c_M = chi_c_M.frame(); dataw_z->plotOn(w_chi_c_M, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ; w_chi_c_M->Draw(); g->SaveAs("~/cern/plots/m_Chic_sweighted.png"); */ }
//------------------------------------------------------------------------------ Real CalculatedPoint::SetEpoch(const Real ep) { A1Mjd a1(ep); GetMJ2000State(a1); return lastStateTime.Get(); }
double BeamContact2Dp::Project(double xi) // this function computes the centerline projection for the current step { double xi_p; double H1; double H2; double H3; double H4; double dH1; double dH2; double dH3; double dH4; double R; double DR; double dxi; Vector a1(BC2D_NUM_DIM); Vector b1(BC2D_NUM_DIM); Vector x_c_p(BC2D_NUM_DIM); Vector t_c(BC2D_NUM_DIM); Vector ddx_c(BC2D_NUM_DIM); // initialize to previous projection location xi_p = xi; // update end point tangents UpdateEndFrames(); // set tangent vectors a1 = Geta1(); b1 = Getb1(); // Hermitian basis functions and first derivatives H1 = 1.0 - 3.0*xi_p*xi_p + 2.0*xi_p*xi_p*xi_p; H2 = xi_p - 2.0*xi_p*xi_p + xi_p*xi_p*xi_p; H3 = 3.0*xi_p*xi_p - 2*xi_p*xi_p*xi_p; H4 = -xi_p*xi_p + xi_p*xi_p*xi_p; dH1 = -6.0*xi_p + 6.0*xi_p*xi_p; dH2 = 1.0 - 4.0*xi_p + 3.0*xi_p*xi_p; dH3 = 6.0*xi_p - 6.0*xi_p*xi_p; dH4 = -2.0*xi_p + 3.0*xi_p*xi_p; // compute current projection coordinate and tangent x_c_p = mDcrd_a*H1 + a1*mLength*H2 + mDcrd_b*H3 + b1*mLength*H4; t_c = mDcrd_a*dH1 + a1*mLength*dH2 + mDcrd_b*dH3 + b1*mLength*dH4; // compute initial value of residual R = (mDcrd_s - x_c_p)^t_c; // iterate to determine new value of xi int Gapcount = 0; while (fabs(R/mLength) > 1.0e-10 && Gapcount < 50) { // compute current curvature vector ddx_c = Get_dxc_xixi(xi_p); // increment projection location DR = ((mDcrd_s - x_c_p)^ddx_c) - (t_c^t_c); dxi = -R/DR; xi_p = xi_p + dxi; // Hermitian basis functions and first derivatives H1 = 1.0 - 3.0*xi_p*xi_p + 2.0*xi_p*xi_p*xi_p; H2 = xi_p - 2.0*xi_p*xi_p + xi_p*xi_p*xi_p; H3 = 3.0*xi_p*xi_p - 2*xi_p*xi_p*xi_p; H4 = -xi_p*xi_p + xi_p*xi_p*xi_p; dH1 = -6.0*xi_p + 6.0*xi_p*xi_p; dH2 = 1.0 - 4.0*xi_p + 3.0*xi_p*xi_p; dH3 = 6.0*xi_p - 6.0*xi_p*xi_p; dH4 = -2.0*xi_p + 3.0*xi_p*xi_p; // update projection coordinate and tangent x_c_p = mDcrd_a*H1 + a1*mLength*H2 + mDcrd_b*H3 + b1*mLength*H4; t_c = mDcrd_a*dH1 + a1*mLength*dH2 + mDcrd_b*dH3 + b1*mLength*dH4; // compute residual R = (mDcrd_s - x_c_p)^t_c; Gapcount += 1; } // update normal vector for current projection mNormal = (mDcrd_s - x_c_p)/((mDcrd_s - x_c_p).Norm()); // update Hermitian basis functions and derivatives mShape(0) = H1; mShape(1) = H2; mShape(2) = H3; mShape(3) = H4; mDshape(0) = dH1; mDshape(1) = dH2; mDshape(2) = dH3; mDshape(3) = dH4; return xi_p; }
void TestSymBandDiv_B2(tmv::DivType dt, PosDefCode pdc) { const int N = 10; std::vector<tmv::SymBandMatrixView<T> > sb; std::vector<tmv::SymBandMatrixView<std::complex<T> > > csb; MakeSymBandList(sb,csb,pdc); tmv::Matrix<T> a1(N,N); for (int i=0; i<N; ++i) for (int j=0; j<N; ++j) a1(i,j) = T(1-3*i+j); a1.diag().addToAll(T(10)*N); a1 /= T(10); tmv::Matrix<std::complex<T> > ca1 = a1 * std::complex<T>(3,-4); a1.diag().addToAll(T(10)*N); ca1.diag().addToAll(T(10)*N); tmv::MatrixView<T> a1v = a1.view(); tmv::MatrixView<std::complex<T> > ca1v = ca1.view(); #if (XTEST & 2) tmv::Matrix<T> a3 = a1.colRange(0,N/2); tmv::Matrix<std::complex<T> > ca3 = ca1.colRange(0,N/2); tmv::Matrix<T> a4 = a1.rowRange(0,N/2); tmv::Matrix<std::complex<T> > ca4 = ca1.rowRange(0,N/2); tmv::Matrix<T> a5(2*N,N); a5.rowRange(0,N) = a1; a5.rowRange(N,2*N) = a1; tmv::Matrix<std::complex<T> > ca5(2*N,N); ca5.rowRange(0,N) = ca1; ca5.rowRange(N,2*N) = ca1; tmv::Matrix<T> a6 = a5.transpose(); tmv::Matrix<std::complex<T> > ca6 = ca5.transpose(); tmv::MatrixView<T> a3v = a3.view(); tmv::MatrixView<T> a4v = a4.view(); tmv::MatrixView<T> a5v = a5.view(); tmv::MatrixView<T> a6v = a6.view(); tmv::MatrixView<std::complex<T> > ca3v = ca3.view(); tmv::MatrixView<std::complex<T> > ca4v = ca4.view(); tmv::MatrixView<std::complex<T> > ca5v = ca5.view(); tmv::MatrixView<std::complex<T> > ca6v = ca6.view(); #endif for(size_t i=START;i<sb.size();i++) { if (showstartdone) std::cout<<"Start loop: i = "<<i<<", si = "<<tmv::TMV_Text(sb[i])<< " "<<sb[i]<<std::endl; tmv::SymBandMatrixView<T> si = sb[i]; tmv::SymBandMatrixView<std::complex<T> > csi = csb[i]; si.saveDiv(); csi.saveDiv(); TestMatrixDivArith1(dt,a1v,si,ca1v,csi,"SymBand/SquareMatrix"); if (dt == tmv::LU) continue; #if (XTEST & 2) TestMatrixDivArith1(dt,a3v,si,ca3v,csi,"SymBand/NonSquareMatrix"); TestMatrixDivArith1(dt,a4v,si,ca4v,csi,"SymBand/NonSquareMatrix"); TestMatrixDivArith1(dt,a5v,si,ca5v,csi,"SymBand/NonSquareMatrix"); TestMatrixDivArith1(dt,a6v,si,ca6v,csi,"SymBand/NonSquareMatrix"); #endif } }
float f2(float x,float y,float z) { return (f(x)-a1(x)*z-a2(x)*y) / a0(x); }
//Rasterize 4 pixels at once void DepthBuffer::rasterizeTile2x2(int32 x,int32 y,uint32 pass) { auto tileIndex = x + y*tileCount_.x; auto count = tileTriangleCount_[tileIndex]; tileTriangleCount_[tileIndex] = 0; auto faces = triangleBins_ + x*kMaxTrianglesPerTile + y*tileCount_.x*kMaxTrianglesPerTile; vec2i tilePos(x*tileSize_.x,y*tileSize_.y); vec2i tileEnd(tilePos + tileSize_); #ifdef ARPHEG_ARCH_X86 enum { kNumLanes = 4 }; //Flush denormals to zero _mm_setcsr( _mm_getcsr() | 0x8040 ); VecS32 colOffset(0, 1, 0, 1); VecS32 rowOffset(0, 0, 1, 1); //Process the 4 binned triangles at a time VecS32 vertexX[3]; VecS32 vertexY[3]; VecF32 vertexZ[4]; VecS32 tileMinXSimd(tilePos.x); VecS32 tileMaxXSimd(tilePos.x+tileSize_.x-2); VecS32 tileMinYSimd(tilePos.y); VecS32 tileMaxYSimd(tilePos.y+tileSize_.y-2); for(uint32 i = 0;i<count;i += kNumLanes){ uint32 numSimdTris = std::min(uint32(kNumLanes),count-i); auto f = faces+i; for(uint32 ii = 0;ii< numSimdTris;++ii){ vertexX[0].lane[ii] = f[ii].v[0].x; vertexY[0].lane[ii] = f[ii].v[0].y; vertexX[1].lane[ii] = f[ii].v[1].x; vertexY[1].lane[ii] = f[ii].v[1].y; vertexX[2].lane[ii] = f[ii].v[2].x; vertexY[2].lane[ii] = f[ii].v[2].y; vertexZ[ii] = VecF32(f[ii].z[0],f[ii].z[1],f[ii].z[2],0.0f); } // Fab(x, y) = Ax + By + C = 0 // Fab(x, y) = (ya - yb)x + (xb - xa)y + (xa * yb - xb * ya) = 0 // Compute A = (ya - yb) for the 3 line segments that make up each triangle VecS32 A0 = vertexY[1] - vertexY[2]; VecS32 A1 = vertexY[2] - vertexY[0]; VecS32 A2 = vertexY[0] - vertexY[1]; // Compute B = (xb - xa) for the 3 line segments that make up each triangle VecS32 B0 = vertexX[2] - vertexX[1]; VecS32 B1 = vertexX[0] - vertexX[2]; VecS32 B2 = vertexX[1] - vertexX[0]; // Compute C = (xa * yb - xb * ya) for the 3 line segments that make up each triangle VecS32 C0 = vertexX[1] * vertexY[2] - vertexX[2] * vertexY[1]; VecS32 C1 = vertexX[2] * vertexY[0] - vertexX[0] * vertexY[2]; VecS32 C2 = vertexX[0] * vertexY[1] - vertexX[1] * vertexY[0]; // Use bounding box traversal strategy to determine which pixels to rasterize VecS32 minX = vmax(vmin(vmin(vertexX[0], vertexX[1]), vertexX[2]), tileMinXSimd) & VecS32(~1); VecS32 maxX = vmin(vmax(vmax(vertexX[0], vertexX[1]), vertexX[2]), tileMaxXSimd); VecS32 minY = vmax(vmin(vmin(vertexY[0], vertexY[1]), vertexY[2]), tileMinYSimd) & VecS32(~1); VecS32 maxY = vmin(vmax(vmax(vertexY[0], vertexY[1]), vertexY[2]), tileMaxYSimd); //Rasterize each triangle individually for(uint32 lane = 0;lane < numSimdTris;++lane){ //Rasterize in 2x2 quads. VecF32 zz[3]; zz[0] = VecF32(vertexZ[lane].lane[0]); zz[1] = VecF32(vertexZ[lane].lane[1]); zz[2] = VecF32(vertexZ[lane].lane[2]); VecS32 a0(A0.lane[lane]); VecS32 a1(A1.lane[lane]); VecS32 a2(A2.lane[lane]); VecS32 b0(B0.lane[lane]); VecS32 b1(B1.lane[lane]); VecS32 b2(B2.lane[lane]); int32 minx = minX.lane[lane]; int32 maxx = maxX.lane[lane]; int32 miny = minY.lane[lane]; int32 maxy = maxY.lane[lane]; VecS32 col = VecS32(minx) + colOffset; VecS32 row = VecS32(miny) + rowOffset; auto rowIdx = miny*size_.x + 2 * minx; VecS32 w0_row = a0 * col + b0 * row + VecS32(C0.lane[lane]); VecS32 w1_row = a1 * col + b1 * row + VecS32(C1.lane[lane]); VecS32 w2_row = a2 * col + b2 * row + VecS32(C2.lane[lane]); //Multiply each weight by two(rasterize 2x2 quad at once). a0 = shiftl<1>(a0); a1 = shiftl<1>(a1); a2 = shiftl<1>(a2); b0 = shiftl<1>(b0); b1 = shiftl<1>(b1); b2 = shiftl<1>(b2); VecF32 zInc = itof(a1)*zz[1] + itof(a2)*zz[2]; for(int32 y = miny;y<=maxy;y+=2,rowIdx += 2 * size_.x){ auto w0 = w0_row; auto w1 = w1_row; auto w2 = w2_row; VecF32 depth = zz[0] + itof(w1)*zz[1] + itof(w2)*zz[2]; auto idx = rowIdx; for(int32 x = minx;x<=maxx;x+=2,idx+=4){ auto mask = w0|w1|w2; VecF32 previousDepth = VecF32::load(data_+idx); VecF32 mergedDepth = vmin(depth,previousDepth); previousDepth = select(mergedDepth,previousDepth,mask); previousDepth.store(data_+idx); w0+=a0; w1+=a1; w2+=a2; depth+=zInc; } w0_row += b0; w1_row += b1; w2_row += b2; } } } #endif }
int a2(int n) { return n * a1(n-1); }
void Algorithm::FFT(QVector< std::complex<double> > &a, bool invert) { //qDebug()<<a; int n=a.length(); if(n==1) { return; } int i; QVector< std::complex<double> >a0(n/2),a1(n/2); for(i=0;i<n;i+=2) { a0[i/2]=a[i]; a1[i/2]=a[i+1]; } FFT(a0,invert); FFT(a1,invert); static double pi_2;//=M_PI *2; double ang=(pi_2/n)*(invert?-1:1); std::complex<double> w(1),wn(cos(ang),sin(ang)); for(i=0;i<n/2;i++) { a[i]=a0[i]+w*a1[i]; a[i+ n/2 ]=a0[i]-w*a1[i]; if(invert) { a[i]/=2; a[i+ n/2 ]/=2; } w*=wn; } /*/ int i,j=0; int n=a.length(); //double pi_2=M_PI *2; double ang; std::complex<double> w,wn; QVector< std::complex<double> > _a(n); for(i=0;i<n;i++) { a_[j]=a[i]; j=j+n/2; } n/=2; for(;n>1;n/=2) { ang=(M_PI/n)*(invert?-1:1); qDebug()<<"length"<<n; w=1,wn={cos(ang),sin(ang)}; i=0; j=0; while(1) { _a[i]=a[i]+w*a[i+n/2]; _a[i+n]=a[i]-w*a[i+n/2]; i++,j++; if(j==n/2) { w*=wn; j=0; i+=n/2; } qDebug()<<i<<j; if(i>=a.length()) { break; } a=_a; } } /*/ }