CMS 3D CMS Logo

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.addFlag("ResonanceDecayFilter:udscAsEquivalent",false);
62  fMasterGen->settings.addFlag("ResonanceDecayFilter:udscbAsEquivalent",false);
63  fMasterGen->settings.addFlag("ResonanceDecayFilter:wzAsEquivalent",false);
64  fMasterGen->settings.addMVec("ResonanceDecayFilter:mothers",std::vector<int>(),false,false,0,0);
65  fMasterGen->settings.addMVec("ResonanceDecayFilter:daughters",std::vector<int>(),false,false,0,0);
66 
67  //add settings for PT filter
68  fMasterGen->settings.addFlag("PTFilter:filter",false);
69  fMasterGen->settings.addMode("PTFilter:quarkToFilter", 5 ,true,true,3, 6);
70  fMasterGen->settings.addParm("PTFilter:scaleToFilter", 0.4,true,true,0.0, 10.);
71  fMasterGen->settings.addParm("PTFilter:quarkRapidity",10.0,true,true,0.0, 10.);
72  fMasterGen->settings.addParm("PTFilter:quarkPt", -.1,true,true,-.1,100.);
73 
74  //add settings for powheg resonance scale calculation
75  fMasterGen->settings.addFlag("POWHEGres:calcScales",false);
76  fMasterGen->settings.addFlag("POWHEG:bb4l",false);
77  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:onlyDistance1",false);
78  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:veto",false);
79  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:dryRun",false);
80  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:vetoAtPL",false);
81  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:vetoQED",false);
82  fMasterGen->settings.addFlag("POWHEG:bb4l:PartonLevel:veto",false);
83  fMasterGen->settings.addFlag("POWHEG:bb4l:PartonLevel:excludeFSRConflicting",false);
84  fMasterGen->settings.addFlag("POWHEG:bb4l:DEBUG",false);
85  fMasterGen->settings.addFlag("POWHEG:bb4l:ScaleResonance:veto",false);
86  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:vetoDipoleFrame",false);
87  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:pTpythiaVeto",false);
88  fMasterGen->settings.addParm("POWHEG:bb4l:pTminVeto",10.0,true,true,0.0, 10.);
89 
90  fMasterGen->setRndmEnginePtr( &p8RndmEngine_ );
91  fDecayer->setRndmEnginePtr( &p8RndmEngine_ );
92 
93  fMasterGen->readString("Next:numberShowEvent = 0");
94  fDecayer->readString("Next:numberShowEvent = 0");
95 
96  edm::ParameterSet currentParameters;
97  if (randomIndex()>=0) {
98  std::vector<edm::ParameterSet> randomizedParameters = fParameters.getParameter<std::vector<edm::ParameterSet> >("RandomizedParameters");
99  currentParameters = randomizedParameters[randomIndex()];
100  }
101  else {
102  currentParameters = fParameters;
103  }
104 
105  ParameterCollector pCollector = currentParameters.getParameter<edm::ParameterSet>("PythiaParameters");
106 
107  for ( ParameterCollector::const_iterator line = pCollector.begin();
108  line != pCollector.end(); ++line )
109  {
110  if (line->find("Random:") != std::string::npos)
111  throw cms::Exception("PythiaError") << "Attempted to set random number "
112  "using Pythia commands. Please use " "the RandomNumberGeneratorService."
113  << std::endl;
114 
115  if (!fMasterGen->readString(*line)) throw cms::Exception("PythiaError")
116  << "Pythia 8 did not accept \""
117  << *line << "\"." << std::endl;
118 
119  if (line->find("ParticleDecays:") != std::string::npos) {
120 
121  if (!fDecayer->readString(*line)) throw cms::Exception("PythiaError")
122  << "Pythia 8 Decayer did not accept \""
123  << *line << "\"." << std::endl;
124  }
125 
126  }
127 
128  slhafile_.clear();
129 
130  if( currentParameters.exists( "SLHAFileForPythia8" ) ) {
131  std::string slhafilenameshort = currentParameters.getParameter<std::string>("SLHAFileForPythia8");
132  edm::FileInPath f1( slhafilenameshort );
133 
134  fMasterGen->settings.mode("SLHA:readFrom", 2);
135  fMasterGen->settings.word("SLHA:file", f1.fullPath());
136  }
137  else if( currentParameters.exists( "SLHATableForPythia8" ) ) {
138  std::string slhatable = currentParameters.getParameter<std::string>("SLHATableForPythia8");
139 
140  char tempslhaname[] = "pythia8SLHAtableXXXXXX";
141  int fd = mkstemp(tempslhaname);
142  write(fd,slhatable.c_str(),slhatable.size());
143  close(fd);
144 
145  slhafile_ = tempslhaname;
146 
147  fMasterGen->settings.mode("SLHA:readFrom", 2);
148  fMasterGen->settings.word("SLHA:file", slhafile_);
149  }
150 
151  return true;
152 
153 }
154 
155 bool Py8InterfaceBase::declareStableParticles( const std::vector<int>& pdgIds )
156 {
157 
158  for ( size_t i=0; i<pdgIds.size(); i++ )
159  {
160  // FIXME: need to double check if PID's are the same in Py6 & Py8,
161  // because the HepPDT translation tool is actually for **Py6**
162  //
163  // well, actually it looks like Py8 operates in PDT id's rather than Py6's
164  //
165 // int PyID = HepPID::translatePDTtoPythia( pdgIds[i] );
166  int PyID = pdgIds[i];
167  std::ostringstream pyCard ;
168  pyCard << PyID <<":mayDecay=false";
169 
170  if ( fMasterGen->particleData.isParticle( PyID ) ) {
171  fMasterGen->readString( pyCard.str() );
172  } else {
173 
174  edm::LogWarning("DataNotUnderstood") << "Pythia8 does not "
175  << "recognize particle id = "
176  << PyID << std::endl;
177  }
178  // alternative:
179  // set the 2nd input argument warn=false
180  // - this way Py8 will NOT print warnings about unknown particle code(s)
181  // fMasterPtr->readString( pyCard.str(), false )
182  }
183 
184  return true;
185 
186 }
187 
188 bool Py8InterfaceBase:: declareSpecialSettings( const std::vector<std::string>& settings ){
189  for ( unsigned int iss=0; iss<settings.size(); iss++ ){
190  if ( settings[iss].find("QED-brem-off") != std::string::npos ){
191  fMasterGen->readString( "TimeShower:QEDshowerByL=off" );
192  }
193  else{
194  size_t fnd1 = settings[iss].find("Pythia8:");
195  if ( fnd1 != std::string::npos ){
196  std::string value = settings[iss].substr (fnd1+8);
197  fDecayer->readString(value);
198  }
199  }
200  }
201  return true;
202 }
203 
204 
206 {
207 
208  fMasterGen->stat();
209  return;
210 
211 }
212 
213 }
bool declareSpecialSettings(const std::vector< std::string > &)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
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:20
std::vector< std::string > evtgenUserFiles
P8RndmEngine p8RndmEngine_
unsigned int pythiaPylistVerbosity
Definition: value.py:1
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
def write(self, setup)
edm::ParameterSet fParameters