Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-14 07:53:14

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file Pythia6.cc
0027 /// \brief Implementation of the Pythia6 class
0028 
0029 // ----------------------------------------------------------------------------
0030 // According to TPythia6 class from Root:
0031 // (The TPythia6 class is an interface class to F77 routines in Pythia6                //
0032 // CERNLIB event generators, written by T.Sjostrand.)
0033 // http://root.cern/
0034 // see http://root.cern/root/License.html
0035 //
0036 // The complete Pythia6 documentation can be found at:
0037 // http://home.thep.lu.se/~torbjorn/pythiaaux/recent.html
0038 // ----------------------------------------------------------------------------
0039 
0040 // ******************************************************************************
0041 // ******************************************************************************
0042 // **                                                                          **
0043 // **                                                                          **
0044 // **              *......*                  Welcome to the Lund Monte Carlo!  **
0045 // **         *:::!!:::::::::::*                                               **
0046 // **      *::::::!!::::::::::::::*          PPP  Y   Y TTTTT H   H III   A    **
0047 // **    *::::::::!!::::::::::::::::*        P  P  Y Y    T   H   H  I   A A   **
0048 // **   *:::::::::!!:::::::::::::::::*       PPP    Y     T   HHHHH  I  AAAAA  **
0049 // **   *:::::::::!!:::::::::::::::::*       P      Y     T   H   H  I  A   A  **
0050 // **    *::::::::!!::::::::::::::::*!       P      Y     T   H   H III A   A  **
0051 // **      *::::::!!::::::::::::::* !!                                         **
0052 // **      !! *:::!!:::::::::::*    !!       This is PYTHIA version 6.418      **
0053 // **      !!     !* -><- *         !!       Last date of change:  9 Jun 2008  **
0054 // **      !!     !!                !!                                         **
0055 // **      !!     !!                !!       Now is  0 Jan 2000 at  0:00:00    **
0056 // **      !!                       !!                                         **
0057 // **      !!        lh             !!       Disclaimer: this program comes    **
0058 // **      !!                       !!       without any guarantees. Beware    **
0059 // **      !!                 hh    !!       of errors and use common sense    **
0060 // **      !!    ll                 !!       when interpreting results.        **
0061 // **      !!                       !!                                         **
0062 // **      !!                                Copyright T. Sjostrand (2008)     **
0063 // **                                                                          **
0064 // ** An archive of program versions and documentation is found on the web:    **
0065 // ** http://www.thep.lu.se/~torbjorn/Pythia.html                              **
0066 // **                                                                          **
0067 // ** When you cite this program, the official reference is to the 6.4 manual: **
0068 // ** T. Sjostrand, S. Mrenna and P. Skands, JHEP05 (2006) 026                 **
0069 // ** (LU TP 06-13, FERMILAB-PUB-06-052-CD-T) [hep-ph/0603175].                **
0070 // **                                                                          **
0071 // ** Also remember that the program, to a large extent, represents original   **
0072 // ** physics research. Other publications of special relevance to your        **
0073 // ** studies may therefore deserve separate mention.                          **
0074 // **                                                                          **
0075 // ** Main author: Torbjorn Sjostrand; Department of Theoretical Physics,      **
0076 // **   Lund University, Solvegatan 14A, S-223 62 Lund, Sweden;                **
0077 // **   phone: + 46 - 46 - 222 48 16; e-mail: torbjorn@thep.lu.se              **
0078 // ** Author: Stephen Mrenna; Computing Division, GDS Group,                   **
0079 // **   Fermi National Accelerator Laboratory, MS 234, Batavia, IL 60510, USA; **
0080 // **   phone: + 1 - 630 - 840 - 2556; e-mail: mrenna@fnal.gov                 **
0081 // ** Author: Peter Skands; Theoretical Physics Department,                    **
0082 // **   Fermi National Accelerator Laboratory, MS 106, Batavia, IL 60510, USA; **
0083 // **   and CERN/PH, CH-1211 Geneva, Switzerland;                              **
0084 // **   phone: + 41 - 22 - 767 24 59; e-mail: skands@fnal.gov                  **
0085 // **                                                                          **
0086 // **                                                                          **
0087 // ******************************************************************************
0088 
0089 #include "Pythia6.hh"
0090 
0091 #include <cstdlib>
0092 #include <cstring>
0093 #include <iostream>
0094 
0095 #ifndef WIN32
0096 #  define pycomp pycomp_
0097 #  define py1ent py1ent_
0098 #  define type_of_call
0099 #else
0100 #  define pycomp PYCOMP
0101 #  define py1ent PY1ENT
0102 #  define type_of_call _stdcall
0103 #endif
0104 
0105 // pythia6 functions
0106 extern "C"
0107 {
0108   int type_of_call pycomp(int* kf);
0109   void type_of_call py1ent(int&, int&, double&, double&, double&);
0110   void* pythia6_common_address(const char*);
0111 }
0112 
0113 // Direct declaration of pythia6 common blocks
0114 // extern "C" {
0115 //   extern Pyjets_t pyjets_;
0116 //   extern Pydat1_t pydat1_;
0117 //   extern Pydat3_t pydat3_;
0118 // }
0119 
0120 Pythia6* Pythia6::fgInstance = 0;
0121 
0122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0123 
0124 Pythia6* Pythia6::Instance()
0125 {
0126   /// Static access method
0127 
0128   if (!fgInstance) fgInstance = new Pythia6();
0129 
0130   return fgInstance;
0131 }
0132 
0133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0134 
0135 Pythia6::Pythia6() : fParticles(0), fPyjets(0), fPydat1(0), fPydat3(0)
0136 {
0137   /// Pythia6 constructor: creates a vector of Pythia6Particle in which it will
0138   /// store all particles. Note that there may be only one functional Pythia6
0139   /// object at a time, so it's not use to create more than one instance of it.
0140 
0141   // Protect against multiple objects.   All access should be via the
0142   // Instance member function.
0143   if (fgInstance) {
0144     std::cerr << "There's already an instance of Pythia6" << std::endl;
0145     exit(1);
0146   }
0147 
0148   fParticles = new ParticleVector();
0149 
0150   // Initialize common-blocks
0151   fPyjets = (Pyjets_t*)pythia6_common_address("PYJETS");
0152   fPydat1 = (Pydat1_t*)pythia6_common_address("PYDAT1");
0153   fPydat3 = (Pydat3_t*)pythia6_common_address("PYDAT3");
0154 
0155   // Alternative way to initialize common-blocks
0156   // usind direct declaration of pythia6 common blocks
0157   // fPyjets = &pyjets_;
0158   // fPydat1 = &pydat1_;
0159   // fPydat3 = &pydat3_;
0160 }
0161 
0162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0163 
0164 Pythia6::~Pythia6()
0165 {
0166   /// Destroy the object, delete and dispose all Pythia6Particles currently on
0167   /// list.
0168 
0169   if (fParticles) {
0170     ParticleVector::const_iterator it;
0171     for (it = fParticles->begin(); it != fParticles->end(); it++)
0172       delete *it;
0173     delete fParticles;
0174   }
0175 }
0176 
0177 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0178 
0179 int Pythia6::Pycomp(int kf)
0180 {
0181   /// Interface with fortran routine pycomp
0182 
0183   return pycomp(&kf);
0184 }
0185 
0186 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0187 
0188 void Pythia6::Py1ent(int ip, int kf, double pe, double theta, double phi)
0189 {
0190   /// Add one entry to the event record, i.e. either a parton or a
0191   /// particle.
0192   ///
0193   ///  IP:   normally line number for the parton/particle. There are two
0194   ///        exceptions:
0195   ///
0196   ///        If IP = 0: line number 1 is used and PYEXEC is called.
0197   ///        If IP < 0: line -IP is used, with status code K(-IP,2)=2
0198   ///                   rather than 1; thus a parton system may be built
0199   ///                   up by filling all but the last parton of the
0200   ///                   system with IP < 0.
0201   ///  KF:   parton/particle flavour code (PDG code)
0202   ///  PE:   parton/particle energy. If PE is smaller than the mass,
0203   ///        the parton/particle is taken to be at rest.
0204   ///  THETA:
0205   ///  PHI:  polar and azimuthal angle for the momentum vector of the
0206   ///        parton/particle.
0207 
0208   py1ent(ip, kf, pe, theta, phi);
0209 }
0210 
0211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0212 
0213 int Pythia6::ImportParticles(ParticleVector* particles, const char* option)
0214 {
0215   ///  Default primary creation method. It reads the /HEPEVT/ common block which
0216   ///  has been filled by the GenerateEvent method. If the event generator does
0217   ///  not use the HEPEVT common block, This routine has to be overloaded by
0218   ///  the subclasses.
0219   ///  The function loops on the generated particles and store them in
0220   ///  the TClonesArray pointed by the argument particles.
0221   ///  The default action is to store only the stable particles (ISTHEP = 1)
0222   ///  This can be demanded explicitly by setting the option = "Final"
0223   ///  If the option = "All", all the particles are stored.
0224 
0225   if (particles == 0) return 0;
0226 
0227   ParticleVector::const_iterator it;
0228   for (it = particles->begin(); it != particles->end(); it++)
0229     delete *it;
0230   particles->clear();
0231 
0232   int numpart = fPyjets->N;
0233   int nparts = 0;
0234   if (!strcmp(option, "") || !strcmp(option, "Final")) {
0235     for (int i = 0; i < numpart; i++) {
0236       if (fPyjets->K[0][i] == 1) {
0237         //
0238         //  Use the common block values for the TParticle constructor
0239         //
0240         particles->push_back(new Pythia6Particle(
0241           fPyjets->K[0][i], fPyjets->K[1][i], fPyjets->K[2][i], fPyjets->K[3][i], fPyjets->K[4][i],
0242           fPyjets->P[0][i], fPyjets->P[1][i], fPyjets->P[2][i], fPyjets->P[3][i], fPyjets->P[4][i],
0243           fPyjets->V[0][i], fPyjets->V[1][i], fPyjets->V[2][i], fPyjets->V[3][i],
0244           fPyjets->V[4][i]));
0245 
0246         //     if(gDebug) printf("%d %d %d! ",i,fPyjets->K[1][i],numpart);
0247         nparts++;
0248       }
0249     }
0250   }
0251   else if (!strcmp(option, "All")) {
0252     for (int i = 0; i < numpart; i++) {
0253       particles->push_back(new Pythia6Particle(
0254         fPyjets->K[0][i], fPyjets->K[1][i], fPyjets->K[2][i], fPyjets->K[3][i], fPyjets->K[4][i],
0255         fPyjets->P[0][i], fPyjets->P[1][i], fPyjets->P[2][i], fPyjets->P[3][i], fPyjets->P[4][i],
0256         fPyjets->V[0][i], fPyjets->V[1][i], fPyjets->V[2][i], fPyjets->V[3][i], fPyjets->V[4][i]));
0257     }
0258     nparts = numpart;
0259   }
0260 
0261   return nparts;
0262 }
0263 
0264 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......