00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "GeneratorInterface/TopRexInterface/interface/ToprexProducer.h"
00015 #include "GeneratorInterface/TopRexInterface/interface/PYR.h"
00016 #include "GeneratorInterface/TopRexInterface/interface/FindJets.h"
00017 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00018 #include "FWCore/Framework/interface/Event.h"
00019 #include "FWCore/ServiceRegistry/interface/Service.h"
00020 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00021 #include "CLHEP/Random/JamesRandom.h"
00022 #include "CLHEP/Random/RandFlat.h"
00023
00024 #include <iostream>
00025 #include "time.h"
00026
00027 using namespace edm;
00028 using namespace std;
00029
00030
00031
00032 #include "HepMC/PythiaWrapper6_2.h"
00033 #include "HepMC/IO_HEPEVT.h"
00034 #include "GeneratorInterface/TopRexInterface/interface/ToprexWrapper.h"
00035
00036
00037
00038
00039 #include "GeneratorInterface/CommonInterface/interface/PythiaCMS.h"
00040 #include "GeneratorInterface/CommonInterface/interface/Txgive.h"
00041
00042
00043 HepMC::IO_HEPEVT conv2;
00044
00045
00046
00047
00048 static const unsigned long kNanoSecPerSec = 1000000000;
00049 static const unsigned long kAveEventPerSec = 200;
00050
00051 ToprexProducer::ToprexProducer( const ParameterSet & pset) :
00052 EDProducer(), evt(0),
00053 pythiaPylistVerbosity_ (pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0)),
00054 pythiaHepMCVerbosity_ (pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false)),
00055 maxEventsToPrint_ (pset.getUntrackedParameter<int>("maxEventsToPrint",1)),
00056 eventNumber_(0)
00057 {
00058
00059 cout << "ToprexProducer: initializing TopReX " << endl;
00060
00061
00062
00063 pythiaPylistVerbosity_ = pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0);
00064 cout << "Pythia PYLIST verbosity level = " << pythiaPylistVerbosity_ << endl;
00065
00066
00067 pythiaHepMCVerbosity_ = pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false);
00068 cout << "Pythia HepMC verbosity = " << pythiaHepMCVerbosity_ << endl;
00069
00070
00071 maxEventsToPrint_ = pset.getUntrackedParameter<int>("maxEventsToPrint",0);
00072 cout << "Number of events to be printed = " << maxEventsToPrint_ << endl;
00073
00075
00076 {
00077 ParameterSet pythia_params =
00078 pset.getParameter<ParameterSet>("PythiaParameters") ;
00079
00080
00081
00082 vector<string> setNames =
00083 pythia_params.getParameter<vector<string> >("parameterSets");
00084
00085
00086 for ( unsigned i=0; i<setNames.size(); ++i ) {
00087
00088 string mySet = setNames[i];
00089
00090
00091 vector<string> pars =
00092 pythia_params.getParameter<vector<string> >(mySet);
00093
00094 if (mySet != "CSAParameters"){
00095 cout << "----------------------------------------------" << endl;
00096 cout << "Read PYTHIA parameter set " << mySet << endl;
00097 cout << "----------------------------------------------" << endl;
00098
00099
00100 for( vector<string>::const_iterator
00101 itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
00102 static string sRandomValueSetting("MRPY(1)");
00103 if( 0 == itPar->compare(0,sRandomValueSetting.size(),sRandomValueSetting) ) {
00104 throw edm::Exception(edm::errors::Configuration,"PythiaError")
00105 <<" attempted to set random number using pythia command 'MRPY(1)' this is not allowed.\n Please use the RandomNumberGeneratorService to set the random number seed.";
00106 }
00107 if( ! call_pygive(*itPar) ) {
00108 throw edm::Exception(edm::errors::Configuration,"PythiaError")
00109 <<" pythia did not accept the following \""<<*itPar<<"\"";
00110 }
00111 }
00112 }else if(mySet == "CSAParameters"){
00113
00114
00115
00116 pars = pythia_params.getParameter<vector<string> >("CSAParameters");
00117
00118 cout << "----------------------------------------------" << endl;
00119 cout << "Reading CSA parameter settings. " << endl;
00120 cout << "----------------------------------------------" << endl;
00121
00122 call_txgive_init();
00123
00124
00125
00126 for (vector<string>::const_iterator
00127 itPar = pars.begin(); itPar != pars.end(); ++itPar) {
00128 call_txgive(*itPar);
00129
00130 }
00131
00132 }
00133 }
00134
00135 }
00136
00137
00138
00139 #include "GeneratorInterface/CommonInterface/interface/ExternalGenRead.inc"
00140
00141
00142
00143
00144 cout << "----------------------------------------------" << endl;
00145 cout << "Setting Pythia random number seed " << endl;
00146 cout << "----------------------------------------------" << endl;
00147 edm::Service<RandomNumberGenerator> rng;
00148 randomEngine = fRandomEngine = &(rng->getEngine());
00149 uint32_t seed = rng->mySeed();
00150 ostringstream sRandomSet;
00151 sRandomSet <<"MRPY(1)="<<seed;
00152 call_pygive(sRandomSet.str());
00153
00154
00155
00156 call_toprex( "USER", "p", "p", 14000. );
00157
00158 call_pyinit( "USER", "p", "p", 14000. );
00159
00160
00161 cout << endl;
00162
00163 produces<HepMCProduct>();
00164 cout << "ToprexProducer: starting event generation ... " << endl;
00165 }
00166
00167
00168 ToprexProducer::~ToprexProducer(){
00169 cout << "ToprexProducer: event generation done. " << endl;
00170 call_pystat(1);
00171
00172 clear();
00173 }
00174
00175 void ToprexProducer::clear() { }
00176
00177
00178 void ToprexProducer::produce(Event & e, const EventSetup& es) {
00179
00180 auto_ptr<HepMCProduct> bare_product(new HepMCProduct());
00181
00182
00183 call_pyevnt();
00184
00185
00186
00187 call_findjets();
00188 call_pyhepc( 1 );
00189
00190 HepMC::GenEvent* evt = conv2.read_next_event();
00191 evt->set_signal_process_id(pypars.msti[0]);
00192 evt->set_event_scale(pypars.pari[16]);
00193 ++eventNumber_;
00194 evt->set_event_number(eventNumber_);
00195
00196
00197
00198
00199
00200
00201
00202
00203 if(e.id().event() <= maxEventsToPrint_ &&
00204 (pythiaPylistVerbosity_ || pythiaHepMCVerbosity_)) {
00205
00206
00207 if(pythiaPylistVerbosity_) {
00208 call_pylist(pythiaPylistVerbosity_);
00209 }
00210
00211
00212 if(pythiaHepMCVerbosity_) {
00213 cout << "Event process = " << pypars.msti[0] << endl
00214 << "----------------------" << endl;
00215
00216 }
00217 }
00218
00219
00220
00221
00222
00223 if(evt) bare_product->addHepMCData(evt );
00224
00225 e.put(bare_product);
00226
00227 return;
00228 }
00229
00230 bool
00231 ToprexProducer::call_pygive(const std::string& iParm )
00232 {
00233 int numWarn = pydat1.mstu[26];
00234 int numErr = pydat1.mstu[22];
00235
00236 PYGIVE( iParm.c_str(), iParm.length() );
00237
00238 return pydat1.mstu[26] == numWarn && pydat1.mstu[22] == numErr;
00239 }
00240
00241
00242 bool
00243 ToprexProducer::call_txgive(const std::string& iParm )
00244 {
00245 TXGIVE( iParm.c_str(), iParm.length() );
00246 return 1;
00247 }
00248
00249 bool
00250 ToprexProducer::call_txgive_init()
00251 {
00252 TXGIVE_INIT();
00253 cout << " Setting CSA defaults. " << endl;
00254 return 1;
00255 }