def generate_process_files(self):
        """Generate the .h and .cc files containing the matrix elements"""

        # Create the files
        filename = os.path.join(self.path, '%s.h' % self.process_class)
        
        self.write_process_h_file(writers.CPPWriter(filename))

        filename = os.path.join(self.path, '%s.cc' % self.process_class)

        self.write_process_cc_file(writers.CPPWriter(filename))

        logger.info('Created files %(process)s.h and %(process)s.cc in %(dir)s' % \
                    {'process': self.process_class, 'dir': self.path})
    def test_write_cplusplus_error(self):
        """Test that a non-string gives an error"""

        fsock = StringIO.StringIO()

        non_strings = [1.2, ["hej"]]

        writer = writers.CPPWriter(os.devnull)
        for nonstring in non_strings:
            self.assertRaises(AssertionError, writer.write_line, nonstring)
Exemple #3
0
    def test_write_cplusplus_special_syntax(self):
        """ """
        
        line = """mapFinalStates[{5,-5,-13,11,-12,14}] =
{
{ &CPPProcess::matrix_gg_ttx_bbxmupemvexvm,
 false,
 {std::make_pair(21,21)},
 256,
 256
 }
,
{ &CPPProcess::matrix_uux_ttx_bbxmupemvexvm,
 true,
 {std::make_pair(2,-2),std::make_pair(4,-4),std::make_pair(1,-1),std::make_pair(3,-3)},
 256,
 36
 }
};"""
        
        goal_string = """mapFinalStates[{5, -5, -13, 11, -12, 14}] = 
{
  {
    &CPPProcess::matrix_gg_ttx_bbxmupemvexvm, 
    false, 
    {
      std::make_pair(21, 21)
    }, 
    256, 
    256
  }
  , 
  {
    &CPPProcess::matrix_uux_ttx_bbxmupemvexvm, 
    true, 
    {
      std::make_pair(2, -2), std::make_pair(4, -4), std::make_pair(1, -1),
          std::make_pair(3, -3)
    }, 
    256, 
    36
  }
}; """
        writer = writers.CPPWriter(self.give_pos('cpp_test')).\
                 writelines(line.split('\n'))

        # Check that the output stays the same
        self.assertFileContains('cpp_test',
                                 goal_string)   
Exemple #4
0
    def test_write_cplusplus_line(self):
        """Test writing a cplusplus line"""

        fsock = StringIO.StringIO()

        lines = """#ifndef Pythia8_SigmaEW_H
#define Pythia8_SigmaEW_H

#include "PythiaComplex.h"
#include "SigmaProcess.h"

namespace Pythia8 {

 
/*==========================================================================

A derived class for q g -> q gamma (q = u, d, s, c, b).
Use massless approximation also for Q since no alternative.*/

class Sigma2qg2qgamma : public Sigma2Process {

public:

  // Constructor.
  Sigma2qg2qgamma() {   }

  // Calculate flavour-independent parts of cross section.
  virtual void sigmaKin();

  // Evaluate d(sigmaHat)/d(tHat). 
  virtual double sigmaHat();

  // Select flavour, colour and anticolour.
  virtual void setIdColAcol();

  // Info on the subprocess.
  virtual string name(  )   const {
      return "q g -> q gamma(udscb) test test test test test asasd as asd a dada djkl;sdf lkja sdfjkla;sdf l;kja+sdfkldf";}
  virtual int    code()   const {return 201e-3+2.E3+.01e+2+1E+3;}
  virtual string inFlux() const {return "qg";}

private:

  // Values stored for later use.
  double mNew, m2New, sigUS, sigma0; // Just qg

};

    // Select identity, colour and anticolour.

void Sigma2ff2fftgmZ::setIdColAcol() {

  // Trivial flavours: out = in.
  setId( id1, id2,    id1,id2);

  // Colour flow topologies. Swap when antiquarks.
  if (abs(id1)<9 && abs(id2)<9  &&  id1*id2>2/3.) 
                         setColAcol(1,0,2,0,1,0,2,0);
  else if (abs(id1)<9 &&abs(id2)< 9)
                         setColAcol(1,0,0,2,1,0,0,2); 
  else                   setColAcol(0,0,0,0,0,0,0,0);

  if ( (abs(id1)!=9&&id1<0)||(abs(id1 )==10 &&    id2 < 0) ) 
    swapColAcol( ) ;

  template< double > > hej;

}    """.split("\n")

        goal_string = """#ifndef Pythia8_SigmaEW_H
#define Pythia8_SigmaEW_H

#include "PythiaComplex.h"
#include "SigmaProcess.h"

namespace Pythia8 
{


//==========================================================================
// 
// A derived class for q g -> q gamma (q = u, d, s, c, b).
// Use massless approximation also for Q since no alternative.

class Sigma2qg2qgamma : public Sigma2Process 
{

  public:

    // Constructor.
    Sigma2qg2qgamma() {}

    // Calculate flavour-independent parts of cross section.
    virtual void sigmaKin(); 

    // Evaluate d(sigmaHat)/d(tHat).
    virtual double sigmaHat(); 

    // Select flavour, colour and anticolour.
    virtual void setIdColAcol(); 

    // Info on the subprocess.
    virtual string name() const 
    {
      return "q g -> q gamma(udscb) test test test test test asasd as asd a dada djkl;sdf lkja sdfjkla;sdf l;kja+sdfkldf"; 
    }
    virtual int code() const {return 201e-3 + 2.e3 + .01e+2 + 1e+3;}
    virtual string inFlux() const {return "qg";}

  private:

    // Values stored for later use.
    double mNew, m2New, sigUS, sigma0;  // Just qg

}; 

// Select identity, colour and anticolour.

void Sigma2ff2fftgmZ::setIdColAcol() 
{

  // Trivial flavours: out = in.
  setId(id1, id2, id1, id2); 

  // Colour flow topologies. Swap when antiquarks.
  if (abs(id1) < 9 && abs(id2) < 9 && id1 * id2 > 2/3.)
    setColAcol(1, 0, 2, 0, 1, 0, 2, 0); 
  else if (abs(id1) < 9 && abs(id2) < 9)
    setColAcol(1, 0, 0, 2, 1, 0, 0, 2); 
  else
    setColAcol(0, 0, 0, 0, 0, 0, 0, 0); 

  if ((abs(id1) != 9 && id1 < 0) || (abs(id1) == 10 && id2 < 0))
    swapColAcol(); 

  template<double> > hej; 

}
"""

        writer = writers.CPPWriter(self.give_pos('cpp_test')).\
                 writelines(lines)

        # Check that the output stays the same
        self.assertFileContains('cpp_test',
                                 goal_string)