00001
00002
00003
00004
00005
00006 #include "GeneratorInterface/Pythia8Interface/interface/Pythia8Source.h"
00007 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00008 #include "SimDataFormats/HepMCProduct/interface/GenInfoProduct.h"
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "FWCore/Framework/interface/Run.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00013 #include "CLHEP/Random/JamesRandom.h"
00014 #include "CLHEP/Random/RandFlat.h"
00015
00016 #include <iostream>
00017 #include "time.h"
00018
00019 #include "Basics.h"
00020
00021 using namespace edm;
00022 using namespace std;
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 static const unsigned long kNanoSecPerSec = 1000000000;
00037 static const unsigned long kAveEventPerSec = 200;
00038
00039 Pythia8Source::Pythia8Source( const ParameterSet & pset,
00040 InputSourceDescription const& desc ) :
00041 GeneratedInputSource(pset, desc),
00042 pythiaPylistVerbosity_ (pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0)),
00043 pythiaHepMCVerbosity_ (pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false)),
00044 maxEventsToPrint_ (pset.getUntrackedParameter<int>("maxEventsToPrint",1)),
00045 comenergy(pset.getUntrackedParameter<double>("comEnergy",14000.))
00046
00047 {
00048
00049 cout << "Pythia8Source: initializing Pythia. " << endl;
00050
00051
00052
00053
00054 pythiaPylistVerbosity_ = pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0);
00055 cout << "Pythia PYLIST verbosity level = " << pythiaPylistVerbosity_ << endl;
00056
00057
00058 pythiaHepMCVerbosity_ = pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false);
00059 cout << "Pythia HepMC verbosity = " << pythiaHepMCVerbosity_ << endl;
00060
00061
00062 maxEventsToPrint_ = pset.getUntrackedParameter<int>("maxEventsToPrint",0);
00063 cout << "Number of events to be printed = " << maxEventsToPrint_ << endl;
00064
00065
00066
00067
00068 cout << "----------------------------------------------" << endl;
00069 cout << "Setting Pythia8 random number seed " << endl;
00070 cout << "----------------------------------------------" << endl;
00071 edm::Service<RandomNumberGenerator> rng;
00072 uint32_t seed = rng->mySeed();
00073 Pythia8::Rndm::init(seed);
00074
00075
00076 pythia = new Pythia8::Pythia;
00077 pythia8event = &(pythia->event);
00078
00079
00080 ParameterSet pythia_params =
00081 pset.getParameter<ParameterSet>("PythiaParameters") ;
00082
00083
00084
00085 vector<string> setNames =
00086 pythia_params.getParameter<vector<string> >("parameterSets");
00087
00088
00089 for ( unsigned i=0; i<setNames.size(); ++i ) {
00090
00091 string mySet = setNames[i];
00092
00093
00094 vector<string> pars =
00095 pythia_params.getParameter<vector<string> >(mySet);
00096
00097 if (mySet != "CSAParameters") {
00098 cout << "----------------------------------------------" << endl;
00099 cout << "Read PYTHIA parameter set " << mySet << endl;
00100 cout << "----------------------------------------------" << endl;
00101
00102
00103 for( vector<string>::const_iterator
00104 itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
00105
00106 if ( ! pythia->readString(*itPar) ) {
00107 throw edm::Exception(edm::errors::Configuration,"PythiaError")
00108 <<" pythia8 did not accept the following \""<<*itPar<<"\"";
00109 }
00110
00111 }
00112
00113 } else {
00114 cout << " mySet == CSAParameters, not valid for Pythia8 " << endl;
00115 exit(1);
00116 }
00117
00118 }
00119
00120 pythia->init( 2212, 2212, comenergy);
00121
00122 pythia->settings.listChanged();
00123
00124 ToHepMC = new HepMC::I_Pythia8;
00125
00126
00127 cout << endl;
00128
00129
00130 produces<HepMCProduct>();
00131 produces<GenInfoProduct, edm::InRun>();
00132
00133 cout << "Pythia8Source: starting event generation ... " << endl;
00134
00135 }
00136
00137
00138 Pythia8Source::~Pythia8Source(){
00139 cout << "PythiaSource: event generation done. " << endl;
00140 pythia->statistics();
00141 delete pythia;
00142 delete ToHepMC;
00143 clear();
00144 }
00145
00146 void Pythia8Source::clear() {
00147
00148 }
00149
00150
00151 void Pythia8Source::endRun(Run & r) {
00152
00153 double cs = pythia->info.sigmaGen();
00154 auto_ptr<GenInfoProduct> giprod (new GenInfoProduct());
00155 giprod->set_cross_section(cs);
00156
00157
00158 r.put(giprod);
00159
00160 }
00161
00162
00163 bool Pythia8Source::produce(Event & e) {
00164
00165 auto_ptr<HepMCProduct> bare_product(new HepMCProduct());
00166
00167
00168
00169
00170 if (!pythia->next()) return false;
00171
00172 HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
00173 ToHepMC->fill_next_event( *pythia8event, hepmcevt );
00174
00175
00176
00177 hepmcevt->set_signal_process_id(pythia->info.code());
00178
00179 hepmcevt->set_event_scale(pythia->info.pTHat());
00180 hepmcevt->set_event_number(numberEventsInRun() - remainingEvents() - 1);
00181
00182 int id1 = pythia->info.id1();
00183 int id2 = pythia->info.id2();
00184 if ( id1 == 21 ) id1 = 0;
00185 if ( id2 == 21 ) id2 = 0;
00186 double x1 = pythia->info.x1();
00187 double x2 = pythia->info.x2();
00188 double Q = pythia->info.QRen();
00189 double pdf1 = pythia->info.pdf1()/pythia->info.x1();
00190 double pdf2 = pythia->info.pdf2()/pythia->info.x2();
00191 hepmcevt->set_pdf_info( HepMC::PdfInfo(id1,id2,x1,x2,Q,pdf1,pdf2) ) ;
00192
00193 hepmcevt->weights().push_back( pythia->info.weight() );
00194
00195
00196
00197 if(event() <= maxEventsToPrint_ &&
00198 (pythiaPylistVerbosity_ || pythiaHepMCVerbosity_) ) {
00199
00200
00201 if(pythiaPylistVerbosity_) {
00202
00203 pythia->info.list();
00204 pythia->event.list();
00205 }
00206
00207
00208 if(pythiaHepMCVerbosity_) {
00209
00210 cout << "Event process = " << pythia->info.code() << endl
00211 << "----------------------" << endl;
00212 hepmcevt->print();
00213 }
00214 }
00215
00216
00217 if(hepmcevt) bare_product->addHepMCData(hepmcevt);
00218
00219 e.put(bare_product);
00220
00221 return true;
00222 }
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 bool
00239 Pythia8Source::call_txgive(const std::string& iParm ) {
00240
00241
00242
00243
00244 return 1;
00245 }
00246
00247 bool
00248 Pythia8Source::call_txgive_init() {
00249
00250
00251
00252
00253 return 1;
00254 }