示例#1
0
void test_conversion_no_expect(std::string unitString1, std::string unitString2)
{
  ASSERT_NO_THROW(Unit unit1(unitString1.c_str()));
  ASSERT_NO_THROW(Unit unit2(unitString2.c_str()));
  
  Unit unit1(unitString1.c_str());
  Unit unit2(unitString2.c_str());
  UCFn *cf = (UCFn*) NULL;

  ASSERT_NO_THROW(cf = unit1.Conversion_to(&unit2));

  clean_up_UCFn(&cf);
  ASSERT_EQ((UCFn*) NULL, cf);
}
/*===========================================================================*/
void StochasticUniformGridRenderer::Engine::draw( kvs::ObjectBase* object, kvs::Camera* camera, kvs::Light* light )
{
    kvs::Texture::Binder unit0( m_volume_texture, 0 );
    kvs::Texture::Binder unit1( m_exit_texture, 1 );
    kvs::Texture::Binder unit2( m_entry_texture, 2 );
    kvs::Texture::Binder unit3( m_transfer_function_texture, 3 );
    kvs::Texture::Binder unit4( randomTexture(), 4 );
    kvs::ProgramObject::Binder unit( m_ray_casting_shader );

    if ( isEnabledShading() ) kvs::OpenGL::Enable( GL_LIGHTING );
    else kvs::OpenGL::Disable( GL_LIGHTING );

    const float f = camera->back();
    const float n = camera->front();
    const float to_zw1 = ( f * n ) / ( f - n );
    const float to_zw2 = 0.5f * ( ( f + n ) / ( f - n ) ) + 0.5f;
    const float to_ze1 = 0.5f + 0.5f * ( ( f + n ) / ( f - n ) );
    const float to_ze2 = ( f - n ) / ( f * n );
    const kvs::Vector3f light_position = kvs::WorldCoordinate( light->position() ).toObjectCoordinate( object ).position();
    const kvs::Vector3f camera_position = kvs::WorldCoordinate( camera->position() ).toObjectCoordinate( object ).position();
    m_ray_casting_shader.setUniform( "to_zw1", to_zw1 );
    m_ray_casting_shader.setUniform( "to_zw2", to_zw2 );
    m_ray_casting_shader.setUniform( "to_ze1", to_ze1 );
    m_ray_casting_shader.setUniform( "to_ze2", to_ze2 );
    m_ray_casting_shader.setUniform( "light_position", light_position );
    m_ray_casting_shader.setUniform( "camera_position", camera_position );

    const size_t size = randomTextureSize();
    const int count = repetitionCount() * ::RandomNumber();
    const float offset_x = static_cast<float>( ( count ) % size );
    const float offset_y = static_cast<float>( ( count / size ) % size );
    const kvs::Vec2 random_offset( offset_x, offset_y );
    m_ray_casting_shader.setUniform( "random_offset", random_offset );
    this->draw_quad();
}
示例#3
0
int main()

{
    Entry test(20, 20, 0);
    Entry test2(21, 21, 1);
    Entry test3(23, 45, 1);
    Entry test4(23, 45, 1);
    Unit unit1(5, 2, 2, 0);

    unit1.storeEntry(0, test);
    unit1.storeEntry(0, test2);
    unit1.storeEntry(2, test3);
    unit1.storeEntry(5, test4);
    unit1.storeEntry(6, test4);
    cout << unit1 << endl;

    unit1.clearData();

    unit1.storeEntryData();

    Unit unit2(3, 2, 2, 0);
    unit2.storeEntry(0, test);
    unit2.storeEntry(1, test2);

    unit2.storeEntryData();
    //unit1.storeEntryData();
    cout << unit2 << endl;


}
示例#4
0
TEST_F(UnitConversion, NewtonMeterToInvalidFootPound)
{
  testReq.add_requirement("2743423356");
  Unit unit1("N*m");

  std::cerr << "The purpose of this test is to throw to an exception. Error messages are expected." << std::endl;
  ASSERT_THROW(unit1.Convert_to(1.0, "lbfft"), Unit::CONVERSION_ERROR);
}
double TWEDMSet(MSet *arg1, MSet *arg2, Instant* tMax, Word &map)
{
  bool debugme= true;
  ArgVectorPointer funargs = qp->Argument(map.addr);
  int n= arg1->GetNoComponents(),m= arg2->GetNoComponents();
  vector< vector<double> > DTW(n, vector<double>(m, 10000));
  USetRef unit1(false), unit2(false);
  Word mapRes;
  int cost=0;

  DTW[0][0]= 0;

  for (int i = 1 ; i< n; ++i)
  {
    arg1->Get(i, unit1);
    USet utmp1(false);
    unit1.GetUnit(arg1->data, utmp1);
    (*funargs)[0] = SetWord(&(utmp1.constValue));
    for (int j = 1; j< m; ++j)
    {
      arg2->Get(j, unit2);
      USet utmp2(false);
      unit2.GetUnit(arg2->data, utmp2);
      (*funargs)[1] = SetWord(&(utmp2.constValue));

      if( ((unit1.timeInterval.start > unit2.timeInterval.start) &&
          (unit1.timeInterval.start - unit2.timeInterval.start < *tMax)) ||
          ((unit2.timeInterval.start >= unit1.timeInterval.start) &&
          (unit2.timeInterval.start - unit1.timeInterval.start < *tMax)))
      {
         qp->Request(map.addr, mapRes);
         CcBool* mr= static_cast<CcBool*>(mapRes.addr);
         cost =(mr->IsDefined() && mr->GetBoolval())? 0: 1;
      }
      else
        cost= 10000;
      DTW[i][j] = Min(Min(
            // insertion
            DTW[i-1][j] + 1 ,
            // deletion
            DTW[i][j-1] + 1),
            // match
            DTW[i-1][j-1] + cost) ;
      if(debugme)
      {
        cerr<<"\n Cost = "<< cost;
        cerr<<"\n DTW[i-1][j] + 1 = "<< DTW[i-1][j] + 1;
        cerr<<"\n DTW[i][j-1] + 1 = "<< DTW[i][j-1] + 1;
        cerr<<"\n DTW[i-1][j-1] + cost = "<< DTW[i-1][j-1] + cost;
        cerr<<"\n DTW[i][j] = "<< DTW[i][j];
      }
    }
  }
  return DTW[n-1][m-1];
}
示例#6
0
void test_conversion_no_throw(std::string unitString1, std::string unitString2, double expected_offset, double expected_scale, double tolerance = TOL)
{
  ASSERT_NO_THROW(Unit unit1(unitString1.c_str()));
  ASSERT_NO_THROW(Unit unit2(unitString2.c_str()));
  
  Unit unit1(unitString1.c_str());
  Unit unit2(unitString2.c_str());
  UCFn *cf = (UCFn*) NULL;

  ASSERT_NO_THROW(cf = unit1.Conversion_to(&unit2));

  EXPECT_NEAR(expected_offset, cf->C[0], tolerance );
  EXPECT_NEAR(expected_scale,  cf->C[1], tolerance );

  clean_up_UCFn(&cf);
  ASSERT_EQ((UCFn*) NULL, cf);

  units_requirements(false);

}
TEST(AreaUnitTest, Can_Create_Via_Assign) {
    // Arrange
    AreaUnit unit1(1, "kg");
    AreaUnit unit2(1000, "t");

    // Act
    unit2 = unit1;

    // Assert
    EXPECT_EQ(unit1, unit2);
}
示例#8
0
void test_conversion_throw(std::string unitString1, std::string unitString2)
{
  ASSERT_NO_THROW(Unit unit1(unitString1.c_str()));
  ASSERT_NO_THROW(Unit unit2(unitString2.c_str()));
  
  Unit unit1(unitString1.c_str());
  Unit unit2(unitString2.c_str());
  UCFn* cf = (UCFn*) NULL;

  std::cerr << "The purpose of this test is to throw to an exception. Error messages are expected." << std::endl;

  ASSERT_THROW(cf = unit1.Conversion_to(&unit2), Unit::CONVERSION_ERROR);

  if(cf!= (UCFn*) NULL)
  {
    clean_up_UCFn(&cf);
  }
  ASSERT_EQ((UCFn*) NULL, cf);

  units_requirements(true);
}
void SceneHandler::addUnit(Behaviours* behaviour, GameState::Enum state)
{
	if (state != GameState::SCENARIO)
	{
		std::shared_ptr<Unit> unit(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), state));
		m_unitObjects.push_back(unit);
	}
	else
	{
		m_leader = new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), state);
		
		std::shared_ptr<Unit> unit1(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM));
		unit1->m_fixRotation = 30;
		m_team.push_back(unit1);
		std::shared_ptr<Unit> unit2(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM));
		unit2->m_fixRotation = 60;
		m_team.push_back(unit2);
		std::shared_ptr<Unit> unit3(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM));
		unit3->m_fixRotation = 90;
		m_team.push_back(unit3);
		std::shared_ptr<Unit> unit4(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM));
		unit4->m_fixRotation = 120;
		m_team.push_back(unit4);
		std::shared_ptr<Unit> unit5(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM));
		unit5->m_fixRotation = 150;
		m_team.push_back(unit5);
		std::shared_ptr<Unit> unit6(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM));
		unit6->m_fixRotation = 180;
		m_team.push_back(unit6);
		std::shared_ptr<Unit> unit7(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM));
		unit7->m_fixRotation = 210;
		m_team.push_back(unit7);

		std::shared_ptr<Unit> enemie1(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE1));
		m_unitObjects.push_back(enemie1);
		std::shared_ptr<Unit> enemie2(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE2));
		m_unitObjects.push_back(enemie2);
		std::shared_ptr<Unit> enemie3(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE3));
		m_unitObjects.push_back(enemie3);
		std::shared_ptr<Unit> enemie4(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE4));
		m_unitObjects.push_back(enemie4);
		std::shared_ptr<Unit> enemie5(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE5));
		m_unitObjects.push_back(enemie5);
		std::shared_ptr<Unit> enemie6(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE6));
		m_unitObjects.push_back(enemie6);
		std::shared_ptr<Unit> enemie7(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE7));
		m_unitObjects.push_back(enemie7);
		std::shared_ptr<Unit> enemie8(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE8));
		m_unitObjects.push_back(enemie8);
	}
}
/*===========================================================================*/
void StochasticUniformGridRenderer::Engine::setup( kvs::ObjectBase* object, kvs::Camera* camera, kvs::Light* light )
{
    m_random_index = m_ray_casting_shader.attributeLocation("random_index");

    if ( m_transfer_function_changed )
    {
        m_transfer_function_texture.release();
        this->create_transfer_function_texture();
    }

    const kvs::Mat4 PM = kvs::OpenGL::ProjectionMatrix() * kvs::OpenGL::ModelViewMatrix();
    const kvs::Mat4 PM_inverse = PM.inverted();
    m_ray_casting_shader.bind();
    m_ray_casting_shader.setUniform( "ModelViewProjectionMatrix", PM );
    m_ray_casting_shader.setUniform( "ModelViewProjectionMatrixInverse", PM_inverse );
    m_ray_casting_shader.setUniform( "random_texture_size_inv", 1.0f / randomTextureSize() );
    m_ray_casting_shader.setUniform( "volume_data", 0 );
    m_ray_casting_shader.setUniform( "exit_points", 1 );
    m_ray_casting_shader.setUniform( "entry_points", 2 );
    m_ray_casting_shader.setUniform( "transfer_function_data", 3 );
    m_ray_casting_shader.setUniform( "random_texture", 4 );
    m_ray_casting_shader.unbind();

    kvs::ProgramObject::Binder unit0( m_bounding_cube_shader );
    kvs::FrameBufferObject::Binder unit1( m_entry_exit_framebuffer );
    m_bounding_cube_shader.setUniform( "ModelViewProjectionMatrix", PM );

    kvs::OpenGL::Enable( GL_CULL_FACE );
    kvs::OpenGL::Disable( GL_LIGHTING );

    // Draw the back face of the bounding cube for the entry points.
    kvs::OpenGL::SetDrawBuffer( GL_COLOR_ATTACHMENT0_EXT );
    kvs::OpenGL::Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    kvs::OpenGL::SetCullFace( GL_FRONT );
    this->draw_bounding_cube_buffer();

    // Draw the front face of the bounding cube for the entry points.
    kvs::OpenGL::SetDrawBuffer( GL_COLOR_ATTACHMENT1_EXT );
    kvs::OpenGL::Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    kvs::OpenGL::SetCullFace( GL_BACK );
    this->draw_bounding_cube_buffer();

    kvs::OpenGL::Disable( GL_CULL_FACE );
}
示例#11
0
void QMatrixReconstruction(NoiseCovariance& N, string outfilename){
	cout << endl << "Now reconstructing Q from basis vectors..." << endl;
	//vector< vector< vector<double> > > reconstructed(kParaBins*kPerpBins, vector< vector<double> >(xBins*yBins*fBins, vector<double>(xBins*yBins*fBins,0)));
	vector< vector<double> > reconstructed(kParaBins*kPerpBins, vector<double>(fBins, 0));
	for (int k1 = 0; k1 < fBins; k1++){
		cout << " " << floor(100.0 * k1/fBins) << "% done.\r" << std::flush;
		for (int i1 = 0; i1 < 1; i1++){
			for (int j1 = 0; j1 < 1; j1++){
/* 				for (int i2 = 0; i2 < xBins; i2++){
					for (int j2 = 0; j2 < yBins; j2++){
						for (int k2 = 0; k2 < fBins; k2++){ */
				for (int i2 = 0; i2 < 1; i2++){
					for (int j2 = 0; j2 < 1; j2++){
						for (int k2 = 0; k2 < 1; k2++){
							CVector unit1(s);
							CVector unit2(s);
							int here1 = i1*yBins*fBins + j1*fBins + k1;
							int here2 = i2*yBins*fBins + j2*fBins + k2;
							unit1.real[here1] = 1.0;	
							unit2.real[here2] = 1.0;
							CVector P = bandPowerSpectrum(unit1, unit2, N, true);
							for (int n = 0; n < kParaBins*kPerpBins; n++) reconstructed[n][here1]/*[here2]*/ = 2*P.real[n];
						}
					}
				}
			}
		}
	}
	cout << "Done.                  " << endl;	
	
	ofstream outfile;
	//outfile.precision(30);
	outfile.open(outfilename.c_str(), ios::trunc);	
	for (int n = 0; n < kParaBins*kPerpBins; n++){
		for (int i = 0; i < fBins; i++){
			//for (int j = 0; j < xBins*yBins*fBins; j++){
				outfile << reconstructed[n][i]/*[j]*/ << " ";
			//}
			//outfile << endl;
		}
		outfile << endl << endl;
	}
	outfile.close();
}
示例#12
0
void doThings(lua_State* L)
{
    // load the function.
    load(L, "functions.lua");
    // load the Unit Wrapper.
    loadWrapper(L);

    ApplyDamageFunction damageFunction("applyDamage");

    Unit unit1(12, 30);
    Unit unit2(7, 40);
    
    std::cout << "Health of unit1 and unit2 before unit1 deals damage to unit2 : [Unit1 : " << unit1.health << "] [Unit2 : " << unit2.health << "]" << std::endl;
    damageFunction.applyDamage(L, unit1, unit2);
    std::cout << "Health of unit1 and unit2 after unit1 deals damage to unit2 : [Unit1 : " << unit1.health << "] [Unit2 : " << unit2.health << "]" << std::endl;
    damageFunction.applyDamage(L, unit2, unit1);
    std::cout << "Health of unit1 and unit2 after unit2 deals damage to unit1 : [Unit1 : " << unit1.health << "] [Unit2 : " << unit2.health << "]" << std::endl;
    
}
示例#13
0
int main (void){
    banner();
    unit1();
    unit2();
    bye();
}
示例#14
0
void EvtB2MuMuMuNuAmp::CalcAmp(EvtParticle *parent, 
                               EvtAmp& amp,
			       EvtbTosllMSFF   *formFactorsms){ 
                            
    
  // Check the charge conservation in the reaction 
  int charge[4];
  charge[0] = (EvtPDL::chg3(parent->getDaug(0)->getId()))/3;
  charge[1] = (EvtPDL::chg3(parent->getDaug(1)->getId()))/3;
  charge[2] = (EvtPDL::chg3(parent->getDaug(2)->getId()))/3;
  charge[3] = (EvtPDL::chg3(parent->getDaug(3)->getId()))/3;
  if(abs(charge[0]+charge[1]+charge[2]+charge[3])!=1){
     EvtGenReport(EVTGEN_ERROR,"EvtGen") 
            << "\n\n The function EvtB2MuMuMuNuAmp::CalcAmp(...)"
            << "\n Error in the daughters charge definition!"
            << "\n charge1 = " << charge[0] 
            << "\t KF code1 = " << EvtPDL::getLundKC(parent->getDaug(0)->getId())
            << "\n charge2 = " << charge[1]
            << "\t KF code2 = " << EvtPDL::getLundKC(parent->getDaug(1)->getId())
            << "\n charge3 = " << charge[2]
            << "\t KF code3 = " << EvtPDL::getLundKC(parent->getDaug(2)->getId())
            << "\n charge4 = " << charge[3]
            << "\t KF code4 = " << EvtPDL::getLundKC(parent->getDaug(3)->getId())
            << "\n number of daughters = " << parent->getNDaug()
            << std::endl;
     ::abort();
  }
  
  
  // Daughter's positions in the matrix element
  int il1, il2, il3, il4;  //   Mu^+(k_1), Mu^-(k_2), \bar Nu_{Mu}(k_3) and Mu^-(k_4)
                           //or Mu^-(k_1), Mu^+(k_2),      Nu_{Mu}(k_3) and Mu^+(k_4)
                           //   This is the "canonical set" for current matrix element.
                           
  il1 = -101; //initialization of the daughter's positions 
  il2 = -102;
  il3 = -103; 
  il4 = -104;                        
  
  // Daughter's positions for the decay 
  //                   B^-(p) -> Mu^+(k_1) Mu^-(k_2) \bar Nu_{Mu}(k_3) Mu^-(k_4).
  if(charge[0]+charge[1]+charge[2]+charge[3] == -1){
     int ll;
     int min_charge, min_charge_il;
     min_charge    = charge[0];
     min_charge_il = 0;
     for(ll = 1; ll < 4; ll++){
        if(min_charge > charge[ll]){ 
               min_charge = charge[ll];
               min_charge_il = ll;
        }              
     }
     il2 = min_charge_il;                        // this is Mu^-(k_2)  
     if(il2 > 2){
       EvtGenReport(EVTGEN_ERROR,"EvtGen") 
            << "\n\n The function EvtB2MuMuMuNuAmp::CalcAmp(...)"
            << "\n Error in the particles distribution!"
            << "\n il2 = "          << il2
            << "\n min_charge = "   << min_charge
            << "\n total charge = -1 = " << (charge[0]+charge[1]+charge[2]+charge[3])
            << std::endl;
       ::abort();
     }       
     for(ll = il2 + 1; ll < 4; ll++){
        if(charge[ll] == -1) il4 = ll;           // this is  Mu^-(k_4)
        }          
     for(ll = 0; ll < 4; ll++){
        if(charge[ll] == +1) il1 = ll;           // this is  Mu^+(k_1)
        }           
     for(ll = 0; ll < 4; ll++){
        if(charge[ll] == 0) il3 = ll;            // this is  \bar Nu_{Mu}(k_3)
        }               
  }

  // Daughter's positions for the decay 
  //                   B^+(p) -> Mu^-(k_1) Mu^+(k_2) Nu_{Mu}(k_3) Mu^+(k_4).
  if(charge[0]+charge[1]+charge[2]+charge[3] == 1){
     int ll;
     int max_charge, max_charge_il;
     max_charge    = charge[0];
     max_charge_il = 0;
     for(ll = 1; ll < 4; ll++){
        if(max_charge < charge[ll]){ 
               max_charge = charge[ll];
               max_charge_il = ll;
        }              
     }
     il2 = max_charge_il;                        // this is Mu^+(k_2)  
     if(il2 > 2){
       EvtGenReport(EVTGEN_ERROR,"EvtGen") 
            << "\n\n The function EvtB2MuMuMuNuAmp::CalcAmp(...)"
            << "\n Error in the particles distribution!"
            << "\n il2 = "          << il2
            << "\n max_charge = "   << max_charge
            << "\n total charge = +1 = " << (charge[0]+charge[1]+charge[2]+charge[3])
            << std::endl;
       ::abort();
     }       
     for(ll = il2 + 1; ll < 4; ll++){
        if(charge[ll] == 1) il4 = ll;            // this is  Mu^+(k_4)
        }          
     for(ll = 0; ll < 4; ll++){
        if(charge[ll] == -1) il1 = ll;           // this is  Mu^-(k_1)
        }           
     for(ll = 0; ll < 4; ll++){
        if(charge[ll] == 0) il3 = ll;            // this is  Nu_{Mu}(k_3)
        }               
  }

  
  if((il1 < 0)||(il2 < 0)|| (il3 < 0) || (il4 < 0)){
     EvtGenReport(EVTGEN_ERROR,"EvtGen") 
            << "\n\n The function EvtB2MuMuMuNuAmp::CalcAmp(...)"
            << "\n ilX < 0 !!!"
            << "\n il1 = " << il1
            << "\t il2 = " << il2
            << "\t il3 = " << il3
            << "\t il4 = " << il4
            << std::endl;
     ::abort();     
  }
  
  // Output for program work check.
  // Need to comment in the final version!
//  EvtGenReport(EVTGEN_ERROR,"EvtGen") 
//            << "\n il1 = " << il1
//            << "\t il2 = " << il2
//            << "\t il3 = " << il3
//            << "\t il4 = " << il4
//            << std::endl;
   //END of the daughter's positions initialization           
            
  
  // Kinematics initialization          
  
  EvtComplex unit1(1.0,0.0); // real unit
  EvtComplex uniti(0.0,1.0); // imaginary unit  

  double M1 = parent->mass();                // B-meson mass, GeV
  double ml = parent->getDaug(il1)->mass();  // mass of muon, GeV
  
  // Id and 4-momentums of the particles
  
  EvtId idparent = parent->getId(); // B-meson Id
  
  EvtVector4R p;                    // B-meson 4-momentum
  p.set(0.0,0.0,0.0,0.0);
  
  
  EvtId id_L1, id_L2, id_L3, id_L4; // leptonic Id
  
  EvtVector4R k_1;  // 4-momentum of mu^+ in the    B^- rest frame; (il1)
  EvtVector4R k_2;  // 4-momentum of mu^- in the    B^- rest frame; (il2) 
  EvtVector4R k_3;  // 4-momentum of \bar nu in the B^- rest frame; (il3)
  EvtVector4R k_4;  // 4-momentum of mu^- in the    B^- rest frame; (il4)

  k_1.set(0.0,0.0,0.0,0.0);
  k_2.set(0.0,0.0,0.0,0.0);
  k_3.set(0.0,0.0,0.0,0.0);
  k_4.set(0.0,0.0,0.0,0.0);

  EvtVector4R q_fierst;     // q = k_1 + k_2 4-momentum in the B-rest frame
  EvtVector4R k_fierst;     // k = k_3 + k_4 4-momentum in the B-rest frame
  double q2_fierst;         // Mandelstam variable s=q^2
  double k2_fierst;         // Mandelstam variable t=k^2

  EvtVector4R q_second;     // q = k_1 + k_4 4-momentum in the B-rest frame
  EvtVector4R k_second;     // k = k_3 + k_2 4-momentum in the B-rest frame
  double q2_second;         // Mandelstam variable s=q^2
  double k2_second;         // Mandelstam variable t=k^2

  p = parent->getP4Restframe();     // B-meson 4-momentum in the B-rest frame

  k_1 = parent->getDaug(il1)->getP4();
  k_2 = parent->getDaug(il2)->getP4();
  k_3 = parent->getDaug(il3)->getP4();
  k_4 = parent->getDaug(il4)->getP4();
  
  q_fierst = k_1 + k_2;
  k_fierst = k_3 + k_4;
  q2_fierst = q_fierst.mass2();
  k2_fierst = k_fierst.mass2(); 
  
  q_second = k_1 + k_4;
  k_second = k_3 + k_2; 
  q2_second = q_second.mass2();
  k2_second = k_second.mass2(); 
  
  
  // For "B^-" - and "B^+" - mesons amplitudeы separately calculations 
  static EvtIdSet bmesons("B-","B_c-");
  static EvtIdSet bbarmesons("B+","B_c+");
  
//  // Information for test of 4-momentum.
//  // Need to comment in the final version!
//  EvtGenReport(EVTGEN_ERROR,"EvtGen") 
//            << "\n 4-momentum initialization  test"
//            << "\n k_1 = " << k_1
//            << "\n k_2 = " << k_2
//            << "\n k_3 = " << k_3
//            << "\n k_4 = " << k_4
//            << "\n q_fierst = " << q_fierst
//            << "\n q_second = " << q_second
//            << "\n k_fierst = " << k_fierst
//            << "\n k_second = " << k_second
//            << std::endl; 

  
  //
  // I. VMD Contribution
  //
  
  double M2[4];   //intermediate vector mesons mass for VMD contribution
  // M2[0] = EvtPDL::getMass(EvtPDL::getId(std::string("rho0")));  // Rho^0
  // M2[1] = EvtPDL::getMass(EvtPDL::getId(std::string("omega"))); // Omega^0
  // M2[2] = M2[0];  // GeV Rho^0
  // M2[3] = M2[1];  // GeV Omega^0
  M2[0] = 0.77526; // GeV Rho^0
  M2[1] = 0.78265; // GeV Omega^0
  M2[2] = M2[0];  // GeV Rho^0
  M2[3] = M2[1];  // GeV Omega^0
  
  double Width2[4]; //intermediate vector mesons width for VMD contribution
  // Width2[0] = EvtPDL::getWidth(EvtPDL::getId(std::string("rho0")));  // Rho^0
  // Width2[1] = EvtPDL::getWidth(EvtPDL::getId(std::string("omega"))); // Omega^0
  // Width2[2] = Width2[0];  // GeV Rho^0
  // Width2[3] = Width2[1];  // GeV Omega^0
  Width2[0] = 0.1491;   // GeV Rho^0
  Width2[1] = 0.00849;  // GeV Omega^0
  Width2[2] = Width2[0];  // GeV Rho^0
  Width2[3] = Width2[1];  // GeV Omega^0
  
  double fV2[4]; //intermediate vector mesons leptonic constant for VMD contribution
                 // see D.Melikhov, N.Nikitin. PRD70, 114028 (2004)
  fV2[0] = 5.04; // GeV Rho^0    
  fV2[1] = 17.1; // GeV Omega^0
  fV2[2] = 5.04; // GeV Rho^0    
  fV2[3] = 17.1; // GeV Omega^0
  
  // For taking the form factors values
  
  // B -> V intermediate vector mesons
  // transition form-factors for VMD contribution
  // 0 -- Rho^0 for k2_fierst
  // 1 -- Omega^0 for k2_fierst
  // 2 -- Rho^0 for k2_second
  // 3 -- Omega^0 for k2_second
  double a1[4],a2[4],a3[4],a0[4],v[4],t1[4],t2[4],t3[4];  
                                         
  
  EvtId B_meson_for_FF     = EvtPDL::getId(std::string("B0"));
  EvtId rho_meson_for_FF   = EvtPDL::getId(std::string("rho0"));
  EvtId omega_meson_for_FF = EvtPDL::getId(std::string("omega"));
  
  formFactorsms->getVectorFF(B_meson_for_FF, rho_meson_for_FF, k2_fierst,
                             a1[0],a2[0],a0[0],v[0],t1[0],t2[0],t3[0]);
                             
  formFactorsms->getVectorFF(B_meson_for_FF, omega_meson_for_FF, k2_fierst,
                             a1[1],a2[1],a0[1],v[1],t1[1],t2[1],t3[1]);
                             
  formFactorsms->getVectorFF(B_meson_for_FF, rho_meson_for_FF, k2_second,
                             a1[2],a2[2],a0[2],v[2],t1[2],t2[2],t3[2]);
                             
  formFactorsms->getVectorFF(B_meson_for_FF, omega_meson_for_FF, k2_second,
                             a1[3],a2[3],a0[3],v[3],t1[3],t2[3],t3[3]);
                                
   int aa;
   for(aa = 0; aa < 4; aa++){
          a3[aa] = ((M1 + M2[aa])*a1[aa] - (M1 - M2[aa])*a2[aa])/(2.0*M2[aa]);
       }                         
  
//  // Information for test of VMD contribution.
//  // Need to comment in the final version!
//  EvtGenReport(EVTGEN_ERROR,"EvtGen") 
//            << "\n VMD Contribution test"
//            << "\n M(Bu) = " << M1 << " GeV;"
//            << "\n M(Rho) = " << M2[0] << " GeV;"
//            << "\t M(Omega) = " << M2[1] << " GeV;"
//            << "\t Gamma(Rho) = " << Width2[0] << " Gev;"
//            << "\t Gamma(Omega) = " << Width2[1] << " Gev."
//            << "\n\n a1[0] = " << a1[0]
//            << "\t  a2[0] = " << a2[0]
//            << "\t  a0[0] = " << a0[0]
//            << "\t  a3[0] = " << a3[0]
//            << "\t   v[0] = " <<  v[0]
//            << "\n\n a1[1] = " << a1[1]
//            << "\t  a2[1] = " << a2[1]
//            << "\t  a0[1] = " << a0[1]
//            << "\t  a3[1] = " << a3[1]
//            << "\t   v[1] = " <<  v[1]
//            << "\n\n a1[2] = " << a1[2]
//            << "\t  a2[2] = " << a2[2]
//            << "\t  a0[2] = " << a0[2]
//            << "\t  a3[2] = " << a3[2]
//            << "\t   v[2] = " <<  v[2]
//            << "\n\n a1[3] = " << a1[3]
//            << "\t  a2[3] = " << a2[3]
//            << "\t  a0[3] = " << a0[3]
//            << "\t  a3[3] = " << a3[3]
//            << "\t   v[3] = " <<  v[3]
//            << std::endl; 
  
  
  
  // Tensor structures for VMD contribution
  EvtTensor4C Tvmd_fierst, Tvmd_second; 
  
  
  //
  // II. Electromagnetic foton emission from B-meson contribution 
  //                     (EM contribution)  
  //
  
  // EM form factors
  // 0 -- u-quark emission for q2_fierst
  // 1 -- b-quark emission for q2_fierst
  // 2 -- u-quark emission for q2_second
  // 3 -- b-quark emission for q2_second
  double v_em[4];
  double MBstar = 5.325; // GeV
  
  v_em[0] = 4.0*MBstar*FF_B2BstarGamma_fromU(q2_fierst)/(3.0*(M1 + MBstar));
  v_em[1] = 2.0*MBstar*FF_B2BstarGamma_fromB(q2_fierst)/(3.0*(M1 + MBstar));
  v_em[2] = 4.0*MBstar*FF_B2BstarGamma_fromU(q2_second)/(3.0*(M1 + MBstar));
  v_em[3] = 2.0*MBstar*FF_B2BstarGamma_fromB(q2_second)/(3.0*(M1 + MBstar));
  
  // Tensor structures for EM contribution
  EvtTensor4C Tem_fierst, Tem_second; 
  
  
  //
  // ***
  //
  
  
  
  // Leptonic currents 
  //   L1 = (\bar mu \gamma^{\mu} (1 - \gamma^5) nu) 
  //                             or (\bar nu \gamma^{\mu} (1 - \gamma^5) mu)
  //   L2 = (\bar mu \gamma^{\nu} mu)
  EvtVector4C L1_fierst, L2_fierst;
  EvtVector4C L1_second, L2_second;

  
  int i1, i2, i3, i4;  // leptonic spin structures counters
  int leptonicspin[4]; // array for the saving of the leptonic spin configuration



  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  // +                Contribution for B- decay               +
  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  if (bmesons.contains(idparent)){
  
  Tvmd_fierst = 0.0*EvtTensor4C::g();  
  for(aa = 0; aa < 2; aa++){
      EvtComplex coeff_vmd;
      
      double Re_vmd, Im_vmd, znam_vmd;
      Re_vmd = q2_fierst - M2[aa]*M2[aa];
      Im_vmd = Width2[aa]*M2[aa];
      znam_vmd = fV2[aa]*(Re_vmd*Re_vmd + Im_vmd*Im_vmd);
      coeff_vmd = unit1*Re_vmd/znam_vmd - uniti*Im_vmd/znam_vmd;
      
      double vaa, a2aa, a3aa;
      vaa  = 2.0*v[aa]/(M1 + M2[aa]);
      a2aa = a2[aa]/(M1 + M2[aa]);
      a3aa = 2.0*M2[aa]*(a3[aa] - a0[aa])/k2_fierst;
           
      Tvmd_fierst = Tvmd_fierst 
        +coeff_vmd*(0.0*EvtTensor4C::g()
        -(unit1*vaa*dual(EvtGenFunctions::directProd(p,q_fierst)))
        -uniti*a1[aa]*(M1 + M2[aa])*EvtTensor4C::g()
        +uniti*a2aa*EvtGenFunctions::directProd((p + q_fierst),p)
        +uniti*a3aa*EvtGenFunctions::directProd((p - q_fierst),p));
      }
 
  Tvmd_second = 0.0*EvtTensor4C::g();
  for(aa = 2; aa < 4; aa++){
      EvtComplex coeff_vmd;
      
      double Re_vmd, Im_vmd, znam_vmd;
      Re_vmd = q2_second - M2[aa]*M2[aa];
      Im_vmd = Width2[aa]*M2[aa];
      znam_vmd = fV2[aa]*(Re_vmd*Re_vmd + Im_vmd*Im_vmd);
      coeff_vmd = unit1*Re_vmd/znam_vmd - uniti*Im_vmd/znam_vmd;
      
      double vaa, a2aa, a3aa;
      vaa  = 2.0*v[aa]/(M1 + M2[aa]);
      a2aa = a2[aa]/(M1 + M2[aa]);
      a3aa = 2.0*M2[aa]*(a3[aa] - a0[aa])/k2_second;
      
      Tvmd_second = Tvmd_second  
        +coeff_vmd*(0.0*EvtTensor4C::g()
        -unit1*vaa*dual(EvtGenFunctions::directProd(p,q_second))
        -uniti*a1[aa]*(M1 + M2[aa])*EvtTensor4C::g()
        +uniti*a2aa*EvtGenFunctions::directProd((p + q_second),p)
        +uniti*a3aa*EvtGenFunctions::directProd((p - q_second),p));
      }
      
  Tem_fierst = 0.0*EvtTensor4C::g(); 
  for(aa = 0; aa < 2; aa++){
      double fBstar = 0.2; // GeV
      double coeff;
      coeff = fBstar/(q2_fierst*(k2_fierst - MBstar*MBstar));
      Tem_fierst = Tem_fierst - coeff*v_em[aa]*dual(EvtGenFunctions::directProd(p,k_fierst)); 
     }  
     
  Tem_second = 0.0*EvtTensor4C::g(); 
  for(aa = 2; aa < 4; aa++){
      double fBstar = 0.2; // GeV
      double coeff;
      coeff = fBstar/(q2_fierst*(k2_fierst - MBstar*MBstar));
      Tem_second = Tem_second - coeff*v_em[aa]*dual(EvtGenFunctions::directProd(p,k_second)); 
     }     
      
  // Amplitude calculation
  for(i2=0;i2<2;i2++){
    leptonicspin[0] = i2;
    for(i1=0;i1<2;i1++){
      leptonicspin[1] = i1;
      for(i4=0;i4<2;i4++){
        leptonicspin[2] = i4;
        i3 = 0;                  // neutrino spin structure!
        leptonicspin[3] = i3;
        
        //(\bar mu(k_4) \gamma^{\mu} (1 - \gamma^5) nu(- k_3))
        L1_fierst = EvtLeptonVACurrent(parent->getDaug(il4)->spParent(i4),
                                       parent->getDaug(il3)->spParentNeutrino());
        
        
        //(\bar mu(k_2) \gamma^{\mu} mu(- k_1))
        L2_fierst = EvtLeptonVCurrent(parent->getDaug(il2)->spParent(i2),
                                       parent->getDaug(il1)->spParent(i1));
        
        
        //(\bar mu(k_2) \gamma^{\mu} (1 - \gamma^5) nu(- k_3))
        L1_second = EvtLeptonVACurrent(parent->getDaug(il2)->spParent(i2),
                                       parent->getDaug(il3)->spParentNeutrino());
        
        
        //(\bar mu(k_4) \gamma^{\mu} mu(- k_1))
        L2_second = EvtLeptonVCurrent(parent->getDaug(il4)->spParent(i4),
                                       parent->getDaug(il1)->spParent(i1));
         
        // VMD                               
        EvtVector4C Evmd_fierst, Evmd_second;
        Evmd_fierst=Tvmd_fierst.cont2(L2_fierst);
        Evmd_second=Tvmd_second.cont2(L2_second);
        
        // EM
        EvtVector4C Eem_fierst, Eem_second;
        Eem_fierst=Tem_fierst.cont2(L1_fierst);
        Eem_second=Tem_second.cont2(L1_second);
           
        // Bremsstrahlung   
        EvtComplex Ebrst_fierst, Ebrst_second;
        double fB = 0.20; // GeV leptonic constant of B^{\pm} mesons
        Ebrst_fierst = uniti*fB*L2_fierst*L1_fierst/q2_fierst;
        Ebrst_second = uniti*fB*L2_second*L1_second/q2_second;
        
        amp.vertex(leptonicspin, L1_fierst*Evmd_fierst + L2_fierst*Eem_fierst + Ebrst_fierst 
                               - L1_second*Evmd_second - L2_second*Eem_second - Ebrst_second);
                               
         if(q2_fierst < 4.0*ml*ml)
            {
               amp.vertex(leptonicspin, unit1*0.0);
            }                      
          if(q2_second < 4.0*ml*ml)
            {
               amp.vertex(leptonicspin, unit1*0.0);
            }  
           if(k2_fierst < ml*ml)
            {
               amp.vertex(leptonicspin, unit1*0.0);
            }                      
          if(k2_second < ml*ml)
            {
               amp.vertex(leptonicspin, unit1*0.0);
            }                                                                    
          
        }  // End of the operator "for(i4=0;i4<2;i4++)"
      }    // End of the operator "for(i1=0;i1<2;i1++)"
    }      // End of the operator "for(i2=0;i2<2;i2++)"
      
   }  // End of the operator: "if (bmesons.contains(idparent))"

   
   else { // Start of the operator "else N1" 
  // ++++++++++++++++++++++++++++++++++++++++++++++++++
  // +           Contribution for B+ decay            +
  // ++++++++++++++++++++++++++++++++++++++++++++++++++
  if (bbarmesons.contains(idparent)){
  
  Tvmd_fierst = 0.0*EvtTensor4C::g();  
  for(aa = 0; aa < 2; aa++){
      EvtComplex coeff_vmd;
      
      double Re_vmd, Im_vmd, znam_vmd;
      Re_vmd = q2_fierst - M2[aa]*M2[aa];
      Im_vmd = Width2[aa]*M2[aa];
      znam_vmd = fV2[aa]*(Re_vmd*Re_vmd + Im_vmd*Im_vmd);
      coeff_vmd = unit1*Re_vmd/znam_vmd - uniti*Im_vmd/znam_vmd;
      
      double vaa, a2aa, a3aa;
      vaa  = 2.0*v[aa]/(M1 + M2[aa]);
      a2aa = a2[aa]/(M1 + M2[aa]);
      a3aa = 2.0*M2[aa]*(a3[aa] - a0[aa])/k2_fierst;
            
      Tvmd_fierst = Tvmd_fierst 
        +coeff_vmd*(0.0*EvtTensor4C::g()
        +unit1*vaa*dual(EvtGenFunctions::directProd(p,q_fierst))
        -uniti*a1[aa]*(M1 + M2[aa])*EvtTensor4C::g()
        +uniti*a2aa*EvtGenFunctions::directProd((p + q_fierst),p)
        +uniti*a3aa*EvtGenFunctions::directProd((p - q_fierst),p));
      }
 
  Tvmd_second = 0.0*EvtTensor4C::g();
  for(aa = 2; aa < 4; aa++){
      EvtComplex coeff_vmd;
      
      double Re_vmd, Im_vmd, znam_vmd;
      Re_vmd = q2_second - M2[aa]*M2[aa];
      Im_vmd = Width2[aa]*M2[aa];
      znam_vmd = fV2[aa]*(Re_vmd*Re_vmd + Im_vmd*Im_vmd);
      coeff_vmd = unit1*Re_vmd/znam_vmd - uniti*Im_vmd/znam_vmd;
      
      double vaa, a2aa, a3aa;
      vaa  = 2.0*v[aa]/(M1 + M2[aa]);
      a2aa = a2[aa]/(M1 + M2[aa]);
      a3aa = 2.0*M2[aa]*(a3[aa] - a0[aa])/k2_second;
   
      Tvmd_second = Tvmd_second  
        +coeff_vmd*(0.0*EvtTensor4C::g()
        +unit1*vaa*dual(EvtGenFunctions::directProd(p,q_second))
        -uniti*a1[aa]*(M1 + M2[aa])*EvtTensor4C::g()
        +uniti*a2aa*EvtGenFunctions::directProd((p + q_second),p)
        +uniti*a3aa*EvtGenFunctions::directProd((p - q_second),p));
      }
      
  Tem_fierst = 0.0*EvtTensor4C::g(); 
  for(aa = 0; aa < 2; aa++){
      double fBstar = 0.0 - 0.2; // GeV
      double coeff;
      coeff = fBstar/(q2_fierst*(k2_fierst - MBstar*MBstar));
      Tem_fierst = Tem_fierst + coeff*v_em[aa]*dual(EvtGenFunctions::directProd(p,k_fierst)); 
     }  
     
  Tem_second = 0.0*EvtTensor4C::g(); 
  for(aa = 2; aa < 4; aa++){
      double fBstar = 0.0 - 0.2; // GeV
      double coeff;
      coeff = fBstar/(q2_fierst*(k2_fierst - MBstar*MBstar));
      Tem_second = Tem_second + coeff*v_em[aa]*dual(EvtGenFunctions::directProd(p,k_second)); 
     }        
      
  // Amplitude calculation
  for(i2=0;i2<2;i2++){
    leptonicspin[0] = i2;
    for(i1=0;i1<2;i1++){
      leptonicspin[1] = i1;
      for(i4=0;i4<2;i4++){
        leptonicspin[2] = i4;
        i3 = 0;                  // neutrino spin structure!
        leptonicspin[3] = i3;
        
        //(\bar nu(k_3) \gamma^{\mu} (1 - \gamma^5) mu(- k_4))
        L1_fierst = EvtLeptonVACurrent(parent->getDaug(il3)->spParentNeutrino(),
                                       parent->getDaug(il4)->spParent(i4));
        
        
        //(\bar mu(k_1) \gamma^{\mu} mu(- k_2))
        L2_fierst = EvtLeptonVCurrent(parent->getDaug(il1)->spParent(i1),
                                       parent->getDaug(il2)->spParent(i2));
        
        
        //(\bar nu(k_3) \gamma^{\mu} (1 - \gamma^5) mu(- k_2))
        L1_second = EvtLeptonVACurrent(parent->getDaug(il3)->spParentNeutrino(),
                                       parent->getDaug(il2)->spParent(i2));
        
        
        //(\bar mu(k_1) \gamma^{\mu} mu(- k_4))
        L2_second = EvtLeptonVCurrent(parent->getDaug(il1)->spParent(i1),
                                       parent->getDaug(il4)->spParent(i4));
         
        // VMD        
        EvtVector4C Evmd_fierst, Evmd_second;
        Evmd_fierst=Tvmd_fierst.cont2(L2_fierst);
        Evmd_second=Tvmd_second.cont2(L2_second);
        
        // EM
        EvtVector4C Eem_fierst, Eem_second;
        Eem_fierst=Tem_fierst.cont2(L1_fierst);
        Eem_second=Tem_second.cont2(L1_second);
           
        // Bremsstrahlung                                                               
        EvtComplex Ebrst_fierst, Ebrst_second;
        double fB = 0.20; // GeV leptonic constant of B^{\pm} mesons
        Ebrst_fierst = uniti*fB*L2_fierst*L1_fierst/q2_fierst;
        Ebrst_second = uniti*fB*L2_second*L1_second/q2_second;
        
        
        amp.vertex(leptonicspin, L1_fierst*Evmd_fierst + L2_fierst*Eem_fierst + Ebrst_fierst 
                               - L1_second*Evmd_second - L2_second*Eem_second - Ebrst_second);
                               
         if(q2_fierst < 4.0*ml*ml)
            {
               amp.vertex(leptonicspin, unit1*0.0);
            }                      
          if(q2_second < 4.0*ml*ml)
            {
               amp.vertex(leptonicspin, unit1*0.0);
            }  
           if(k2_fierst < ml*ml)
            {
               amp.vertex(leptonicspin, unit1*0.0);
            }                      
          if(k2_second < ml*ml)
            {
               amp.vertex(leptonicspin, unit1*0.0);
            }                          
          
        }  // End of the operator "for(i4=0;i4<2;i4++)"
      }    // End of the operator "for(i1=0;i1<2;i1++)"
    }      // End of the operator "for(i2=0;i2<2;i2++)"
      
   }  // End of the operator: "if (bbarmesons.contains(idparent))"
   
   else{ // Start of the operator "else N2"
         EvtGenReport(EVTGEN_ERROR,"EvtGen") 
             << "\n\n The function EvtB2MuMuMuNuAmp::CalcAmp(...)"
             << "\n Wrong B-meson number"
             << "\n B-meson KF code = " << EvtPDL::getLundKC(parent->getId())
             << std::endl;
         ::abort();    
   }  // End of the operator "else N2" 

   }  // End of the operator "else N1" 
}