00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "GeneratorInterface/ComphepInterface/interface/ComphepSource.h"
00017 #include "GeneratorInterface/ComphepInterface/interface/ComphepWrapper.h"
00018 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00019 #include "FWCore/Framework/interface/Event.h"
00020 #include "FWCore/ServiceRegistry/interface/Service.h"
00021 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00022
00023 #include <iostream>
00024 #include "time.h"
00025
00026 using namespace edm;
00027 using namespace std;
00028
00029
00030
00031 #include "HepMC/PythiaWrapper6_2.h"
00032 #include "HepMC/IO_HEPEVT.h"
00033 #include "GeneratorInterface/ComphepInterface/interface/ComphepWrapper.h"
00034
00035
00036 #include "GeneratorInterface/CommonInterface/interface/PythiaCMS.h"
00037 #include "GeneratorInterface/CommonInterface/interface/Txgive.h"
00038
00039 HepMC::IO_HEPEVT conv;
00040
00041
00042
00043 #include "GeneratorInterface/ComphepInterface/interface/MCDBInterface.h"
00044
00045
00046
00047 static const unsigned long kNanoSecPerSec = 1000000000;
00048 static const unsigned long kAveEventPerSec = 200;
00049
00050 ComphepSource::ComphepSource( const ParameterSet & pset,
00051 InputSourceDescription const& desc ) :
00052 GeneratedInputSource(pset, desc), evt(0),
00053 pythiaPylistVerbosity_ (pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0)),
00054 pythiaHepMCVerbosity_ (pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false)),
00055 maxEventsToPrint_ (pset.getUntrackedParameter<int>("maxEventsToPrint",1)),
00056 getInputFromMCDB_ (pset.getUntrackedParameter<bool>("getInputFromMCDB",false)), MCDBArticleID_ (pset.getParameter<int>("MCDBArticleID")) {
00057
00058
00059
00060
00061
00062 if (getInputFromMCDB_) {
00063 CHFile_ = pset.getUntrackedParameter<string>("ComphepInputFile");
00064 mcdbGetInputFile(CHFile_, MCDBArticleID_);
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074 pythiaPylistVerbosity_ = pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0);
00075
00076
00077 pythiaHepMCVerbosity_ = pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false);
00078
00079
00080 maxEventsToPrint_ = pset.getUntrackedParameter<int>("maxEventsToPrint",0);
00081
00083
00084 {
00085 ParameterSet pythia_params =
00086 pset.getParameter<ParameterSet>("PythiaParameters") ;
00087
00088
00089
00090 vector<string> setNames =
00091 pythia_params.getParameter<vector<string> >("parameterSets");
00092
00093
00094 for ( unsigned i=0; i<setNames.size(); ++i ) {
00095
00096 string mySet = setNames[i];
00097
00098
00099 vector<string> pars =
00100 pythia_params.getParameter<vector<string> >(mySet);
00101
00102 if (mySet != "CSAParameters"){
00103
00104
00105 for( vector<string>::const_iterator
00106 itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
00107 static string sRandomValueSetting("MRPY(1)");
00108 if( 0 == itPar->compare(0,sRandomValueSetting.size(),sRandomValueSetting) ) {
00109 throw edm::Exception(edm::errors::Configuration,"PythiaError")
00110 <<" 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.";
00111 }
00112 if( ! call_pygive(*itPar) ) {
00113 throw edm::Exception(edm::errors::Configuration,"PythiaError")
00114 <<" pythia did not accept the following \""<<*itPar<<"\"";
00115 }
00116 }
00117 }else if(mySet == "CSAParameters"){
00118
00119
00120
00121 pars = pythia_params.getParameter<vector<string> >("CSAParameters");
00122
00123
00124 call_txgive_init();
00125
00126
00127
00128 for (vector<string>::const_iterator
00129 itPar = pars.begin(); itPar != pars.end(); ++itPar) {
00130 call_txgive(*itPar);
00131
00132 }
00133
00134 }
00135 }
00136
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146 edm::Service<RandomNumberGenerator> rng;
00147 uint32_t seed = rng->mySeed();
00148 ostringstream sRandomSet;
00149 sRandomSet <<"MRPY(1)="<<seed;
00150 call_pygive(sRandomSet.str());
00151
00152 call_pevmain();
00153
00154
00155
00156 cout << endl;
00157
00158
00159 produces<HepMCProduct>();
00160 }
00161
00162
00163 ComphepSource::~ComphepSource(){
00164 call_pystat(1);
00165
00166 clear();
00167 }
00168
00169 void ComphepSource::clear() {
00170
00171 }
00172
00173
00174 bool ComphepSource::produce(Event & e) {
00175
00176 auto_ptr<HepMCProduct> bare_product(new HepMCProduct());
00177
00178
00179
00180
00181 call_pyevnt();
00182
00183
00184 call_pyhepc( 1 );
00185
00186
00187 HepMC::GenEvent* evt = conv.read_next_event();
00188 evt->set_signal_process_id(pypars.msti[0]);
00189 evt->set_event_number(numberEventsInRun() - remainingEvents() - 1);
00190
00191
00192
00193
00194 if(event() <= maxEventsToPrint_ &&
00195 (pythiaPylistVerbosity_ || pythiaHepMCVerbosity_)) {
00196
00197
00198 if(pythiaPylistVerbosity_) {
00199 call_pylist(pythiaPylistVerbosity_);
00200 }
00201
00202
00203 if(pythiaHepMCVerbosity_) {
00204 cout << "Event process = " << pypars.msti[0] << endl
00205 << "----------------------" << endl;
00206 evt->print();
00207 }
00208 }
00209
00210
00211
00212
00213
00214 if(evt) bare_product->addHepMCData(evt );
00215
00216 e.put(bare_product);
00217
00218 return true;
00219 }
00220
00221 bool
00222 ComphepSource::call_pygive(const std::string& iParm )
00223 {
00224 int numWarn = pydat1.mstu[26];
00225 int numErr = pydat1.mstu[22];
00226
00227 PYGIVE( iParm.c_str(), iParm.length() );
00228
00229 return pydat1.mstu[26] == numWarn && pydat1.mstu[22] == numErr;
00230 }
00231
00232 bool
00233 ComphepSource::call_txgive(const std::string& iParm )
00234 {
00235
00236 TXGIVE( iParm.c_str(), iParm.length() );
00237 return 1;
00238 }
00239
00240 bool
00241 ComphepSource::call_txgive_init()
00242 {
00243 TXGIVE_INIT();
00244 return 1;
00245 }