CMS 3D CMS Logo

Public Member Functions | Private Attributes

SherpaHadronizer Class Reference

Inheritance diagram for SherpaHadronizer:
gen::BaseHadronizer

List of all members.

Public Member Functions

const char * classname () const
bool decay ()
bool declareSpecialSettings (const std::vector< std::string >)
bool declareStableParticles (const std::vector< int > &pdgIds)
void finalizeEvent ()
bool generatePartonsAndHadronize ()
bool initializeForInternalPartons ()
bool readSettings (int)
bool residualDecay ()
 SherpaHadronizer (const edm::ParameterSet &params)
void statistics ()
 ~SherpaHadronizer ()

Private Attributes

SHERPA::Sherpa Generator
unsigned int maxEventsToPrint
CLHEP::HepRandomEngine * randomEngine
std::string SherpaChecksum
double SherpaDefaultWeight
edm::ParameterSet SherpaParameterSet
std::string SherpaPath
std::string SherpaPathPiece
std::string SherpaProcess
std::string SherpaResultDir

Detailed Description

Definition at line 26 of file SherpaHadronizer.cc.


Constructor & Destructor Documentation

SherpaHadronizer::SherpaHadronizer ( const edm::ParameterSet params)

Definition at line 68 of file SherpaHadronizer.cc.

References dirstructure::argv, gather_cfg::cout, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), i, maxEventsToPrint, SherpaDefaultWeight, SherpaParameterSet, SherpaPath, SherpaPathPiece, SherpaProcess, and SherpaResultDir.

                                                                :
  BaseHadronizer(params),
  SherpaParameterSet(params.getParameter<edm::ParameterSet>("SherpaParameters"))
{
  if (!params.exists("SherpaProcess")) SherpaProcess="";
        else SherpaProcess=params.getParameter<std::string>("SherpaProcess");
  if (!params.exists("SherpaPath")) SherpaPath="";
    else SherpaPath=params.getParameter<std::string>("SherpaPath");
  if (!params.exists("SherpaPathPiece")) SherpaPathPiece="";
    else SherpaPathPiece=params.getParameter<std::string>("SherpaPathPiece");
  if (!params.exists("SherpaResultDir")) SherpaResultDir="Result";
    else SherpaResultDir=params.getParameter<std::string>("SherpaResultDir");
  if (!params.exists("SherpaDefaultWeight")) SherpaDefaultWeight=1.;
    else SherpaDefaultWeight=params.getParameter<double>("SherpaDefaultWeight");
  if (!params.exists("maxEventsToPrint")) maxEventsToPrint=0;
    else maxEventsToPrint=params.getParameter<int>("maxEventsToPrint");

        
  spf::SherpackFetcher Fetcher(params);
  int retval=Fetcher.Fetch();   
  if (retval != 0) {
        std::cout << "SherpaHadronizer: Preparation of Sherpack failed ... " << std::endl;
        std::cout << "SherpaHadronizer: Error code: " << retval << std::endl;
        std::terminate();  
          
  }       
  // The ids (names) of parameter sets to be read (Analysis,Run) to create Analysis.dat, Run.dat
  //They are given as a vstring.  
  std::vector<std::string> setNames = SherpaParameterSet.getParameter<std::vector<std::string> >("parameterSets");
  //Loop all set names...
  for ( unsigned i=0; i<setNames.size(); ++i ) {
    // ...and read the parameters for each set given in vstrings
    std::vector<std::string> pars = SherpaParameterSet.getParameter<std::vector<std::string> >(setNames[i]);
    std::cout << "Write Sherpa parameter set " << setNames[i] <<" to "<<setNames[i]<<".dat "<<std::endl;
    std::string datfile =  SherpaPath + "/" + setNames[i] +".dat";
    std::ofstream os(datfile.c_str());  
    // Loop over all strings and write the according *.dat
    for(std::vector<std::string>::const_iterator itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
      os<<(*itPar)<<std::endl;
    } 
  }

  //To be conform to the default Sherpa usage create a command line:
  //name of executable  (only for demonstration, could also be empty)
  std::string shRun  = "./Sherpa";
  //Path where the Sherpa libraries are stored
  std::string shPath = "PATH=" + SherpaPath;
  // new for Sherpa 1.3.0, suggested by authors
  std::string shPathPiece = "PATH_PIECE=" + SherpaPathPiece; 
  //Path where results are stored 
  std::string shRes  = "RESULT_DIRECTORY=" + SherpaResultDir; // from Sherpa 1.2.0 on
  //Name of the external random number class
  std::string shRng  = "EXTERNAL_RNG=CMS_SHERPA_RNG";
  
  //create the command line
  char* argv[5];
  argv[0]=(char*)shRun.c_str();
  argv[1]=(char*)shPath.c_str();
  argv[2]=(char*)shPathPiece.c_str();
  argv[3]=(char*)shRes.c_str();
  argv[4]=(char*)shRng.c_str();
  
  //initialize Sherpa with the command line
  Generator.InitializeTheRun(5,argv);
}
SherpaHadronizer::~SherpaHadronizer ( )

Definition at line 134 of file SherpaHadronizer.cc.

{
}

Member Function Documentation

const char* SherpaHadronizer::classname ( ) const [inline]

Definition at line 40 of file SherpaHadronizer.cc.

{ return "SherpaHadronizer"; }
bool SherpaHadronizer::decay ( )

Definition at line 220 of file SherpaHadronizer.cc.

{
        return true;
}
bool SherpaHadronizer::declareSpecialSettings ( const std::vector< std::string >  ) [inline]

Definition at line 34 of file SherpaHadronizer.cc.

{ return true; }
bool SherpaHadronizer::declareStableParticles ( const std::vector< int > &  pdgIds)

Definition at line 156 of file SherpaHadronizer.cc.

{
#if 0
  for(std::vector<int>::const_iterator iter = pdgIds.begin();
      iter != pdgIds.end(); ++iter)
    if (!markStable(*iter))
      return false;
  
  return true;
#else
  return false;
#endif
}
void SherpaHadronizer::finalizeEvent ( )

Definition at line 230 of file SherpaHadronizer.cc.

References gen::BaseHadronizer::event(), lhef::getStatus(), and maxEventsToPrint.

{
#if 0
        for(HepMC::GenEvent::particle_iterator iter = event->particles_begin();
            iter != event->particles_end(); iter++)
                (*iter)->set_status(getStatus(*iter));
#endif
        //******** Verbosity *******
        if (maxEventsToPrint > 0) {
                maxEventsToPrint--;
                event()->print();               
        }
}
bool SherpaHadronizer::generatePartonsAndHadronize ( )

Definition at line 187 of file SherpaHadronizer.cc.

References relval_steps::gen(), gen::BaseHadronizer::resetEvent(), SherpaDefaultWeight, and CommonMethods::weight().

{
  //get the next event and check if it produced
  if (Generator.GenerateOneEvent()) { 
    //convert it to HepMC2
    SHERPA::Input_Output_Handler* ioh = Generator.GetIOHandler();
    SHERPA::HepMC2_Interface* hm2i = ioh->GetHepMC2Interface();
    //get the event weight from blobs
    ATOOLS::Blob_List* blobs = Generator.GetEventHandler()-> GetBlobs();
    ATOOLS::Blob* sp(blobs->FindFirst(ATOOLS::btp::Signal_Process));
    double weight((*sp)["Weight"]->Get<double>());
    double ef((*sp)["Enhance"]->Get<double>());
    // in case of unweighted events sherpa puts the max weight as event weight. 
    // this is not optimal, we want 1 for unweighted events, so we check 
    // whether we are producing unweighted events ("EVENT_GENERATION_MODE" == "1")
    if ( ATOOLS::ToType<int>( ATOOLS::rpa->gen.Variable("EVENT_GENERATION_MODE") ) == 1 ) {
      if (ef > 0.) {
        weight = SherpaDefaultWeight/ef;
      } else {
        weight = -1234.;
      }
    }
    //create and empty event and then hand it to SherpaIOHandler to fill it
    HepMC::GenEvent* evt = new HepMC::GenEvent();
    hm2i->Sherpa2HepMC(blobs, *evt, weight);
    resetEvent(evt);         
    return true;
  }
  else {
    return false;
  }  
}
bool SherpaHadronizer::initializeForInternalPartons ( )

Definition at line 138 of file SherpaHadronizer.cc.

{
  
  //initialize Sherpa
  Generator.InitializeTheEventHandler();
  
  return true;
}
bool SherpaHadronizer::readSettings ( int  ) [inline]

Definition at line 31 of file SherpaHadronizer.cc.

{ return true; }
bool SherpaHadronizer::residualDecay ( )

Definition at line 225 of file SherpaHadronizer.cc.

{
        return true;
}
void SherpaHadronizer::statistics ( )

Definition at line 171 of file SherpaHadronizer.cc.

References gen::BaseHadronizer::runInfo(), and GenRunInfoProduct::setInternalXSec().

{
  //calculate statistics
  Generator.SummarizeRun(); 

  //get the xsec from EventHandler
  SHERPA::Event_Handler* theEventHandler = Generator.GetEventHandler();
  double xsec_val = theEventHandler->TotalXS();
  double xsec_err = theEventHandler->TotalErr();
  
  //set the internal cross section in pb in GenRunInfoProduct 
  runInfo().setInternalXSec(GenRunInfoProduct::XSec(xsec_val,xsec_err));

}

Member Data Documentation

SHERPA::Sherpa SherpaHadronizer::Generator [private]

Definition at line 53 of file SherpaHadronizer.cc.

unsigned int SherpaHadronizer::maxEventsToPrint [private]

Definition at line 51 of file SherpaHadronizer.cc.

Referenced by finalizeEvent(), and SherpaHadronizer().

CLHEP::HepRandomEngine* SherpaHadronizer::randomEngine [private]

Definition at line 54 of file SherpaHadronizer.cc.

std::string SherpaHadronizer::SherpaChecksum [private]

Definition at line 45 of file SherpaHadronizer.cc.

Definition at line 49 of file SherpaHadronizer.cc.

Referenced by generatePartonsAndHadronize(), and SherpaHadronizer().

Definition at line 50 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaPath [private]

Definition at line 46 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaPathPiece [private]

Definition at line 47 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaProcess [private]

Definition at line 44 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().

std::string SherpaHadronizer::SherpaResultDir [private]

Definition at line 48 of file SherpaHadronizer.cc.

Referenced by SherpaHadronizer().