CMS 3D CMS Logo

Public Member Functions | Private Attributes | Static Private Attributes | Friends

gen::Pythia6Service Class Reference

#include <Pythia6Service.h>

Inheritance diagram for gen::Pythia6Service:
gen::FortranInstance gen::Pythia6ServiceWithCallback gen::Pythia6ServiceWithCallback

List of all members.

Public Member Functions

void closePYUPDA ()
void closeSLHA ()
virtual void enter ()
void openPYUPDA (const char *, bool write_file)
void openSLHA (const char *)
 Pythia6Service (edm::ParameterSet const &)
 Pythia6Service ()
void setCSAParams ()
void setGeneralParams ()
void setPYUPDAParams (bool afterPyinit)
void setSLHAFromHeader (const std::vector< std::string > &lines)
void setSLHAParams ()
 ~Pythia6Service ()

Private Attributes

bool fInitialising
std::vector< std::string > fParamCSA
std::vector< std::string > fParamGeneral
std::vector< std::string > fParamPYUPDA
std::vector< std::string > fParamSLHA
CLHEP::HepRandomEngine * fRandomEngine
int fUnitPYUPDA
int fUnitSLHA

Static Private Attributes

static Pythia6ServicefPythia6Owner = 0

Friends

double gen::pyr_ (int *)

Detailed Description

Definition at line 26 of file Pythia6Service.h.


Constructor & Destructor Documentation

Pythia6Service::Pythia6Service ( )

Definition at line 80 of file Pythia6Service.cc.

Pythia6Service::Pythia6Service ( edm::ParameterSet const &  ps)

Definition at line 85 of file Pythia6Service.cc.

References Exception, fParamCSA, fParamGeneral, fParamPYUPDA, fParamSLHA, fPythia6Owner, edm::ParameterSet::getParameter(), geometryCSVtoXML::line, and groupFilesInBlocks::lines.

  : fRandomEngine(&getEngineReference()), fUnitSLHA(24), fUnitPYUPDA(25)
{
   if (fPythia6Owner)
      throw cms::Exception("PythiaError") <<
            "Two Pythia6Service instances claiming Pythia6 ownership." <<
            std::endl;

   fPythia6Owner = this;

/*
   ParameterCollector collector(ps.getParameter<edm::ParameterSet>("PythiaParameters"));

   fParamGeneral.clear();
   fParamCSA.clear();
   fParamSLHA.clear();
   
   fParamGeneral = std::vector<std::string>(collector.begin(), collector.end());
   fParamCSA     = std::vector<std::string>(collector.begin("CSAParameters"), collector.end());
   fParamSLHA    = std::vector<std::string>(collector.begin("SLHAParameters"), collector.end());
*/
     

   // Set PYTHIA parameters in a single ParameterSet
   //
   edm::ParameterSet pythia_params = 
      ps.getParameter<edm::ParameterSet>("PythiaParameters") ;
      
   // read and sort Pythia6 cards
   //
   std::vector<std::string> setNames =
      pythia_params.getParameter<std::vector<std::string> >("parameterSets");
      
   // std::vector<std::string>  paramLines;
   fParamGeneral.clear();
   fParamCSA.clear();
   fParamSLHA.clear();
   fParamPYUPDA.clear();
   

   for(std::vector<std::string>::const_iterator iter = setNames.begin();
                                                iter != setNames.end(); ++iter) 
   {
      std::vector<std::string> lines =
         pythia_params.getParameter< std::vector<std::string> >(*iter);

      for(std::vector<std::string>::const_iterator line = lines.begin();
                                                   line != lines.end(); ++line ) 
      {
         if (line->substr(0, 7) == "MRPY(1)")
            throw cms::Exception("PythiaError") <<
            "Attempted to set random number"
            " using Pythia command 'MRPY(1)'."
            " Please use the"
            " RandomNumberGeneratorService." <<
            std::endl;

         if ( *iter == "CSAParameters" )
         {
            fParamCSA.push_back(*line);
         }
         else if ( *iter == "SLHAParameters" )
         {
            fParamSLHA.push_back(*line);
         }
         else if ( *iter == "PYUPDAParameters" )
         {
            fParamPYUPDA.push_back(*line);
         }
         else
         {
            fParamGeneral.push_back(*line);
         }
      }
   }
}
Pythia6Service::~Pythia6Service ( )

Definition at line 162 of file Pythia6Service.cc.

References fParamCSA, fParamGeneral, fParamPYUPDA, fParamSLHA, and fPythia6Owner.

{
   if (fPythia6Owner == this)
      fPythia6Owner = 0;

   fParamGeneral.clear();
   fParamCSA.clear();
   fParamSLHA.clear();
   fParamPYUPDA.clear();
}

Member Function Documentation

void Pythia6Service::closePYUPDA ( )

Definition at line 283 of file Pythia6Service.cc.

References fiocls_(), and fUnitPYUPDA.

{

   fiocls_(&fUnitPYUPDA);
   
   return;

}
void Pythia6Service::closeSLHA ( )
void Pythia6Service::enter ( ) [virtual]

Reimplemented from gen::FortranInstance.

Definition at line 173 of file Pythia6Service.cc.

References gen::call_pygive(), and fPythia6Owner.

{
   FortranInstance::enter();

   if (!fPythia6Owner) {
     edm::LogInfo("Generator|Pythia6Interface") <<
          "gen::Pythia6Service is going to initialise Pythia, as no other "
          "instace has done so yet, and Pythia service routines have been "
          "requested by a dummy instance." << std::endl;

     call_pygive("MSTU(12)=12345");
     call_pyinit("NONE", "", "", 0.0);

     fPythia6Owner = this;
   }
}
void Pythia6Service::openPYUPDA ( const char *  file,
bool  write_file 
)

Definition at line 256 of file Pythia6Service.cc.

References call_pyupda(), gather_cfg::cout, fioopn_(), fioopnw_(), and fUnitPYUPDA.

Referenced by setPYUPDAParams().

{

        if (write_file) {
          std::cout<<"=== WRITING PYUPDA FILE "<<file<<" ==="<<std::endl;
          fioopnw_( &fUnitPYUPDA, file, strlen(file) );
          // Write Pythia particle table to this card file.
          call_pyupda(1, fUnitPYUPDA);
        } else {
          std::cout<<"=== READING PYUPDA FILE "<<file<<" ==="<<std::endl;
          fioopn_( &fUnitPYUPDA, file, strlen(file) );
          // Update Pythia particle table with this card file.
          call_pyupda(3, fUnitPYUPDA);
        }
        
        return;

}
void Pythia6Service::openSLHA ( const char *  file)

Definition at line 240 of file Pythia6Service.cc.

References gen::call_pygive(), fioopn_(), and fUnitSLHA.

Referenced by setSLHAFromHeader(), and setSLHAParams().

{

        std::ostringstream pyCard1 ;
        pyCard1 << "IMSS(21)=" << fUnitSLHA;
        call_pygive( pyCard1.str() );
        std::ostringstream pyCard2 ;
        pyCard2 << "IMSS(22)=" << fUnitSLHA;
        call_pygive( pyCard2.str() );

        fioopn_( &fUnitSLHA, file, strlen(file) );
        
        return;

}
void Pythia6Service::setCSAParams ( )

Definition at line 206 of file Pythia6Service.cc.

References fParamCSA, i, reco_skim_cfg_mod::maxSize, SETCSAPARBUFSIZE, gen::txgive_(), and gen::txgive_init_().

Referenced by gen::Pythia6Gun::beginRun(), gen::Cascade2Hadronizer::initializeForInternalPartons(), gen::Cascade2Hadronizer::readSettings(), gen::PyquenHadronizer::readSettings(), and gen::Pythia6Hadronizer::readSettings().

{
#define SETCSAPARBUFSIZE 514
   char buf[SETCSAPARBUFSIZE];
   
   txgive_init_();
   for(std::vector<std::string>::const_iterator iter = fParamCSA.begin();
                                                iter != fParamCSA.end(); ++iter)
   {
      // Null pad the string should not be needed because it uses
      // read, which will look for \n, but just in case...
      for (size_t i = 0; i < SETCSAPARBUFSIZE; ++i)
        buf[i] = ' ';
      // Skip empty parameters.
      if (iter->length() <= 0)
        continue;
      // Limit the size of the string to something which fits the buffer.
      size_t maxSize = iter->length() > (SETCSAPARBUFSIZE-2) ? (SETCSAPARBUFSIZE-2) : iter->length();
      strncpy(buf, iter->c_str(), maxSize);
      // Add extra \n if missing, otherwise "read" continues reading. 
      if (buf[maxSize-1] != '\n')
      {
         buf[maxSize] = '\n';
         // Null terminate in case the string is passed back to C.
         // Not sure that is actually needed.
         buf[maxSize + 1] = 0;
      }
      txgive_(buf, iter->length() );
   }   
   
   return ;
#undef SETCSAPARBUFSIZE
}
void Pythia6Service::setGeneralParams ( )

Definition at line 190 of file Pythia6Service.cc.

References gen::call_pygive(), and fParamGeneral.

Referenced by ParticleReplacerParticleGun::beginJob(), gen::Pythia6Gun::beginRun(), gen::Cascade2Hadronizer::initializeForInternalPartons(), gen::Cascade2Hadronizer::readSettings(), gen::PyquenHadronizer::readSettings(), gen::Pythia6Hadronizer::readSettings(), gen::HydjetHadronizer::readSettings(), and gen::ExhumeHadronizer::readSettings().

{
   // now pass general config cards 
   //
   for(std::vector<std::string>::const_iterator iter = fParamGeneral.begin();
                                                iter != fParamGeneral.end(); ++iter)
   {
      if (!call_pygive(*iter))
         throw cms::Exception("PythiaError")
         << "Pythia did not accept \""
         << *iter << "\"." << std::endl;
   }
   
   return ;
}
void Pythia6Service::setPYUPDAParams ( bool  afterPyinit)

Definition at line 333 of file Pythia6Service.cc.

References end, python::connectstrParser::f1, mergeVDriftHistosByStation::file, fParamPYUPDA, edm::FileInPath::fullPath(), openPYUPDA(), dqm_diff::start, and groupFilesInBlocks::temp.

Referenced by gen::Pythia6Hadronizer::initializeForExternalPartons(), gen::Cascade2Hadronizer::initializeForInternalPartons(), and gen::Pythia6Hadronizer::initializeForInternalPartons().

{
   std::string shortfile;
   bool write_file = false;
   bool usePostPyinit = false;

   //   std::cout<<"=== CALLING setPYUPDAParams === "<<afterPyinit<<" "<<fParamPYUPDA.size()<<std::endl;

   // This assumes that PYUPDAFILE only appears once ...

   for (std::vector<std::string>::const_iterator iter = fParamPYUPDA.begin();
                                                 iter != fParamPYUPDA.end(); iter++ )
   {
     //     std::cout<<"PYUPDA check "<<*iter<<std::endl;
        if( iter->find( "PYUPDAFILE", 0 ) != std::string::npos ) {
          std::string::size_type start = iter->find_first_of( "=" ) + 1;
          std::string::size_type end = iter->length() - 1;
          std::string::size_type temp = iter->find_first_of( "'", start );
          if( temp != std::string::npos ) {
            start = temp + 1;
            end = iter->find_last_of( "'" ) - 1;
          } 
          start = iter->find_first_not_of( " ", start );
          end = iter->find_last_not_of( " ", end );
          //std::cout << " start, end = " << start << " " << end << std::endl;          
          shortfile = iter->substr( start, end - start + 1 );
        } else if ( iter->find( "PYUPDAWRITE", 0 ) != std::string::npos ) {
          write_file = true;
        } else if ( iter->find( "PYUPDApostPYINIT", 0 ) != std::string::npos ) {
          usePostPyinit = true;
        }
   }
   
   if (!shortfile.empty()) {
     std::string file;
     if (write_file) {
       file = shortfile;
     } else {
       // If reading, get full path to file and require it to exist.
       FileInPath f1( shortfile );
       file = f1.fullPath();
     }

     if (afterPyinit == usePostPyinit || (write_file && afterPyinit)) {
       openPYUPDA( file.c_str(), write_file );
     }
   }

   return;
}
void Pythia6Service::setSLHAFromHeader ( const std::vector< std::string > &  lines)

Definition at line 384 of file Pythia6Service.cc.

References Association::block, gather_cfg::blocks, call_pyslha(), mergeVDriftHistosByStation::file, alignmentValidation::fname, getHLTprescales::index, geometryCSVtoXML::line, NULL, openSLHA(), dbtoconf::out, pos, gen::pydat1_, python::multivaluedict::remove(), split, mathSSE::sqrt(), estimatePileup_makeJSON::trunc, and relativeConstraints::value.

Referenced by gen::Pythia6Hadronizer::initializeForExternalPartons().

{

        std::set<std::string> blocks;
        unsigned int model = 0, subModel = 0;

        const char *fname = std::tmpnam(NULL);
        std::ofstream file(fname, std::fstream::out | std::fstream::trunc);
        std::string block;
        for(std::vector<std::string>::const_iterator iter = lines.begin();
            iter != lines.end(); ++iter) {
                file << *iter;

                std::string line = *iter;
                std::transform(line.begin(), line.end(),
                               line.begin(), (int(*)(int))std::toupper);
                std::string::size_type pos = line.find('#');
                if (pos != std::string::npos)
                        line.resize(pos);

                if (line.empty())
                        continue;

                if (!boost::algorithm::is_space()(line[0])) {
                        std::vector<std::string> tokens;
                        boost::split(tokens, line,
                                     boost::algorithm::is_space(),
                                     boost::token_compress_on);
                        if (!tokens.size())
                                continue;
                        block.clear();
                        if (tokens.size() < 2)
                                continue;
                        if (tokens[0] == "BLOCK") {
                                block = tokens[1];
                                blocks.insert(block);
                                continue;
                        }

                        if (tokens[0] == "DECAY") {
                                block = "DECAY";
                                blocks.insert(block);
                        }
                } else if (block == "MODSEL") {
                        std::istringstream ss(line);
                        ss >> model >> subModel;
                } else if (block == "SMINPUTS") {
                        std::istringstream ss(line);
                        int index;
                        double value;
                        ss >> index >> value;
                        switch(index) {
                            case 1:
                                pydat1_.paru[103 - 1] = 1.0 / value;
                                break;
                            case 2:
                                pydat1_.paru[105 - 1] = value;
                                break;
                            case 4:
                                pydat2_.pmas[0][23 - 1] = value;
                                break;
                            case 6:
                                pydat2_.pmas[0][6 - 1] = value;
                                break;
                            case 7:
                                pydat2_.pmas[0][15 - 1] = value;
                                break;
                        }
                }
        }
        file.close();

        if (blocks.count("SMINPUTS"))
                pydat1_.paru[102 - 1] = 0.5 - std::sqrt(0.25 -
                        pydat1_.paru[0] * M_SQRT1_2 *
                        pydat1_.paru[103 - 1] / pydat1_.paru[105 - 1] /
                        (pydat2_.pmas[0][23 - 1] * pydat2_.pmas[0][23 - 1]));

/*
        int unit = 24;
        fioopn_(&unit, fname, std::strlen(fname));
        std::remove(fname);

        call_pygive("IMSS(21)=24");
        call_pygive("IMSS(22)=24");
*/
        
        openSLHA( fname ) ;
        std::remove( fname );
        
        if (model ||
            blocks.count("HIGMIX") ||
            blocks.count("SBOTMIX") ||
            blocks.count("STOPMIX") ||
            blocks.count("STAUMIX") ||
            blocks.count("AMIX") ||
            blocks.count("NMIX") ||
            blocks.count("UMIX") ||
            blocks.count("VMIX"))
                call_pyslha(1);
        if (model ||
            blocks.count("QNUMBERS") ||
            blocks.count("PARTICLE") ||
            blocks.count("MINPAR") ||
            blocks.count("EXTPAR") ||
            blocks.count("SMINPUTS") ||
            blocks.count("SMINPUTS"))
                call_pyslha(0);
        if (blocks.count("MASS"))
                call_pyslha(5, 0);
        if (blocks.count("DECAY"))
                call_pyslha(2);

      return ;

}
void Pythia6Service::setSLHAParams ( )

Definition at line 292 of file Pythia6Service.cc.

References end, python::connectstrParser::f1, mergeVDriftHistosByStation::file, fParamSLHA, edm::FileInPath::fullPath(), openSLHA(), dqm_diff::start, and groupFilesInBlocks::temp.

Referenced by gen::Pythia6Gun::beginRun(), gen::Cascade2Hadronizer::initializeForInternalPartons(), gen::Cascade2Hadronizer::readSettings(), and gen::Pythia6Hadronizer::readSettings().

{
   for (std::vector<std::string>::const_iterator iter = fParamSLHA.begin();
                                                 iter != fParamSLHA.end(); iter++ )
   {

        if( iter->find( "SLHAFILE", 0 ) == std::string::npos ) continue;
        std::string::size_type start = iter->find_first_of( "=" ) + 1;
        std::string::size_type end = iter->length() - 1;
        std::string::size_type temp = iter->find_first_of( "'", start );
        if( temp != std::string::npos ) {
                        start = temp + 1;
                        end = iter->find_last_of( "'" ) - 1;
        } 
        start = iter->find_first_not_of( " ", start );
        end = iter->find_last_not_of( " ", end );
        //std::cout << " start, end = " << start << " " << end << std::endl;            
        std::string shortfile = iter->substr( start, end - start + 1 );
        FileInPath f1( shortfile );
        std::string file = f1.fullPath();

/*
        //
        // override what might have be given via the external config
        //
        std::ostringstream pyCard ;
        pyCard << "IMSS(21)=" << fUnitSLHA;
        call_pygive( pyCard.str() );
        pyCard << "IMSS(22)=" << fUnitSLHA;
        call_pygive( pyCard.str() );

        fioopn_( &fUnitSLHA, file.c_str(), file.length() );
*/

        openSLHA( file.c_str() );

   }
   
   return;
}

Friends And Related Function Documentation

double gen::pyr_ ( int *  ) [friend]

Member Data Documentation

Definition at line 51 of file Pythia6Service.h.

std::vector<std::string> gen::Pythia6Service::fParamCSA [private]

Definition at line 56 of file Pythia6Service.h.

Referenced by Pythia6Service(), setCSAParams(), and ~Pythia6Service().

std::vector<std::string> gen::Pythia6Service::fParamGeneral [private]

Definition at line 55 of file Pythia6Service.h.

Referenced by Pythia6Service(), setGeneralParams(), and ~Pythia6Service().

std::vector<std::string> gen::Pythia6Service::fParamPYUPDA [private]

Definition at line 58 of file Pythia6Service.h.

Referenced by Pythia6Service(), setPYUPDAParams(), and ~Pythia6Service().

std::vector<std::string> gen::Pythia6Service::fParamSLHA [private]

Definition at line 57 of file Pythia6Service.h.

Referenced by Pythia6Service(), setSLHAParams(), and ~Pythia6Service().

Definition at line 62 of file Pythia6Service.h.

Referenced by enter(), Pythia6Service(), and ~Pythia6Service().

CLHEP::HepRandomEngine* gen::Pythia6Service::fRandomEngine [private]

Definition at line 53 of file Pythia6Service.h.

Referenced by gen::pyr_().

Definition at line 60 of file Pythia6Service.h.

Referenced by closePYUPDA(), and openPYUPDA().

Definition at line 59 of file Pythia6Service.h.

Referenced by closeSLHA(), and openSLHA().