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