test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Py8InterfaceBase.cc
Go to the documentation of this file.
2 
5 
6 // EvtGen plugin
7 //
8 //#include "Pythia8Plugins/EvtGen.h"
9 
10 using namespace Pythia8;
11 
12 namespace gen {
13 
14 Py8InterfaceBase::Py8InterfaceBase( edm::ParameterSet const& ps ) :
15 BaseHadronizer(ps),
16 useEvtGen(false), evtgenDecays(0)
17 {
18  fParameters = ps;
19 
20  pythiaPylistVerbosity = ps.getUntrackedParameter<int>("pythiaPylistVerbosity", 0);
21  pythiaHepMCVerbosity = ps.getUntrackedParameter<bool>("pythiaHepMCVerbosity", false);
22  pythiaHepMCVerbosityParticles = ps.getUntrackedParameter<bool>("pythiaHepMCVerbosityParticles", false);
23  maxEventsToPrint = ps.getUntrackedParameter<int>("maxEventsToPrint", 0);
24 
25  if(pythiaHepMCVerbosityParticles)
26  ascii_io = new HepMC::IO_AsciiParticles("cout", std::ios::out);
27 
28  if ( ps.exists("useEvtGenPlugin") ) {
29 
30  useEvtGen = true;
31 
32  string evtgenpath(getenv("EVTGENDATA"));
33  evtgenDecFile = evtgenpath + string("/DECAY_2010.DEC");
34  evtgenPdlFile = evtgenpath + string("/evt.pdl");
35 
36  if ( ps.exists( "evtgenDecFile" ) )
37  evtgenDecFile = ps.getParameter<string>("evtgenDecFile");
38 
39  if ( ps.exists( "evtgenPdlFile" ) )
40  evtgenPdlFile = ps.getParameter<string>("evtgenPdlFile");
41 
42  if ( ps.exists( "evtgenUserFile" ) )
43  evtgenUserFiles = ps.getParameter< std::vector<std::string> >("evtgenUserFile");
44 
45  }
46 
47 }
48 
50 {
51 
52  fMasterGen.reset(new Pythia);
53  fDecayer.reset(new Pythia);
54 
55  //add settings for resonance decay filter
56  fMasterGen->settings.addFlag("ResonanceDecayFilter:filter",false);
57  fMasterGen->settings.addFlag("ResonanceDecayFilter:exclusive",false);
58  fMasterGen->settings.addFlag("ResonanceDecayFilter:eMuAsEquivalent",false);
59  fMasterGen->settings.addFlag("ResonanceDecayFilter:eMuTauAsEquivalent",false);
60  fMasterGen->settings.addFlag("ResonanceDecayFilter:allNuAsEquivalent",false);
61  fMasterGen->settings.addMVec("ResonanceDecayFilter:mothers",std::vector<int>(),false,false,0,0);
62  fMasterGen->settings.addMVec("ResonanceDecayFilter:daughters",std::vector<int>(),false,false,0,0);
63 
64  fMasterGen->setRndmEnginePtr( &p8RndmEngine_ );
65  fDecayer->setRndmEnginePtr( &p8RndmEngine_ );
66 
67  fMasterGen->readString("Next:numberShowEvent = 0");
68  fDecayer->readString("Next:numberShowEvent = 0");
69 
70  edm::ParameterSet currentParameters;
71  if (randomIndex()>=0) {
72  std::vector<edm::ParameterSet> randomizedParameters = fParameters.getParameter<std::vector<edm::ParameterSet> >("RandomizedParameters");
73  currentParameters = randomizedParameters[randomIndex()];
74  }
75  else {
76  currentParameters = fParameters;
77  }
78 
79  ParameterCollector pCollector = currentParameters.getParameter<edm::ParameterSet>("PythiaParameters");
80 
81  for ( ParameterCollector::const_iterator line = pCollector.begin();
82  line != pCollector.end(); ++line )
83  {
84  if (line->find("Random:") != std::string::npos)
85  throw cms::Exception("PythiaError") << "Attempted to set random number "
86  "using Pythia commands. Please use " "the RandomNumberGeneratorService."
87  << std::endl;
88 
89  if (!fMasterGen->readString(*line)) throw cms::Exception("PythiaError")
90  << "Pythia 8 did not accept \""
91  << *line << "\"." << std::endl;
92 
93  if (line->find("ParticleDecays:") != std::string::npos) {
94 
95  if (!fDecayer->readString(*line)) throw cms::Exception("PythiaError")
96  << "Pythia 8 Decayer did not accept \""
97  << *line << "\"." << std::endl;
98  }
99 
100  }
101 
102  slhafile_.clear();
103 
104  if( currentParameters.exists( "SLHAFileForPythia8" ) ) {
105  std::string slhafilenameshort = currentParameters.getParameter<std::string>("SLHAFileForPythia8");
106  edm::FileInPath f1( slhafilenameshort );
107 
108  fMasterGen->settings.mode("SLHA:readFrom", 2);
109  fMasterGen->settings.word("SLHA:file", f1.fullPath());
110  }
111  else if( currentParameters.exists( "SLHATableForPythia8" ) ) {
112  std::string slhatable = currentParameters.getParameter<std::string>("SLHATableForPythia8");
113 
114  char tempslhaname[] = "pythia8SLHAtableXXXXXX";
115  int fd = mkstemp(tempslhaname);
116  write(fd,slhatable.c_str(),slhatable.size());
117  close(fd);
118 
119  slhafile_ = tempslhaname;
120 
121  fMasterGen->settings.mode("SLHA:readFrom", 2);
122  fMasterGen->settings.word("SLHA:file", slhafile_);
123  }
124 
125  return true;
126 
127 }
128 
129 bool Py8InterfaceBase::declareStableParticles( const std::vector<int>& pdgIds )
130 {
131 
132  for ( size_t i=0; i<pdgIds.size(); i++ )
133  {
134  // FIXME: need to double check if PID's are the same in Py6 & Py8,
135  // because the HepPDT translation tool is actually for **Py6**
136  //
137  // well, actually it looks like Py8 operates in PDT id's rather than Py6's
138  //
139 // int PyID = HepPID::translatePDTtoPythia( pdgIds[i] );
140  int PyID = pdgIds[i];
141  std::ostringstream pyCard ;
142  pyCard << PyID <<":mayDecay=false";
143 
144  if ( fMasterGen->particleData.isParticle( PyID ) ) {
145  fMasterGen->readString( pyCard.str() );
146  } else {
147 
148  edm::LogWarning("DataNotUnderstood") << "Pythia8 does not "
149  << "recognize particle id = "
150  << PyID << std::endl;
151  }
152  // alternative:
153  // set the 2nd input argument warn=false
154  // - this way Py8 will NOT print warnings about unknown particle code(s)
155  // fMasterPtr->readString( pyCard.str(), false )
156  }
157 
158  return true;
159 
160 }
161 
162 bool Py8InterfaceBase:: declareSpecialSettings( const std::vector<std::string>& settings ){
163  for ( unsigned int iss=0; iss<settings.size(); iss++ ){
164  if ( settings[iss].find("QED-brem-off") != std::string::npos ){
165  fMasterGen->readString( "TimeShower:QEDshowerByL=off" );
166  }
167  else{
168  size_t fnd1 = settings[iss].find("Pythia8:");
169  if ( fnd1 != std::string::npos ){
170  std::string value = settings[iss].substr (fnd1+8);
171  fDecayer->readString(value);
172  }
173  }
174  }
175  return true;
176 }
177 
178 
180 {
181 
182  fMasterGen->stat();
183  return;
184 
185 }
186 
187 }
bool declareSpecialSettings(const std::vector< std::string > &)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::auto_ptr< Pythia8::Pythia > fMasterGen
HepMC::IO_AsciiParticles * ascii_io
bool exists(std::string const &parameterName) const
checks if a parameter exists
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< std::string > evtgenUserFiles
def gen
run2 Cosmic #### Run 256259 @ 0T 2015C### Run 272133 @ 3.8T 2016B###
P8RndmEngine p8RndmEngine_
tuple fd
Definition: ztee.py:136
unsigned int pythiaPylistVerbosity
bool declareStableParticles(const std::vector< int > &)
unsigned int maxEventsToPrint
std::auto_ptr< Pythia8::Pythia > fDecayer
int randomIndex() const
const_iterator end() const
const_iterator begin() const
volatile std::atomic< bool > shutdown_flag false
edm::ParameterSet fParameters