#include <GeneratorInterface/AlpgenInterface/interface/AlpgenProducer.h>
Public Member Functions | |
AlpgenProducer (const ParameterSet &) | |
Constructor. | |
virtual | ~AlpgenProducer () |
Destructor. | |
Private Member Functions | |
void | beginRun (Run &r) |
bool | call_pygive (const std::string &iParm) |
Interface to the PYGIVE/TXGIVE pythia routine, with add'l protections. | |
bool | call_txgive (const std::string &iParm) |
void | clear () |
virtual void | produce (Event &e, const EventSetup &es) |
Private Attributes | |
bool | doubleParticle |
double | etamax |
double | etamin |
unsigned int | eventsRead_ |
HepMC::GenEvent * | evt |
std::string | fileName_ |
std::vector< std::string > | fileNames_ |
CLHEP::HepRandomEngine * | fRandomEngine |
CLHEP::RandFlat * | fRandomGenerator |
LHERunInfoProduct::Header | lheAlpgenUnwParHeader |
unsigned int | maxEventsToPrint_ |
Events to print if verbosity. | |
int | Nev_ |
int | particleID |
double | phimax |
double | phimin |
double | ptmax |
double | ptmin |
bool | pythiaHepMCVerbosity_ |
HepMC verbosity flag. | |
unsigned int | pythiaPylistVerbosity_ |
Pythia PYLIST Verbosity flag. |
Definition at line 36 of file AlpgenProducer.h.
AlpgenProducer::AlpgenProducer | ( | const ParameterSet & | pset | ) |
Constructor.
Definition at line 51 of file AlpgenProducer.cc.
References LHERunInfoProduct::Header::addLine(), call_pygive(), call_txgive(), edm::errors::Configuration, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), fileName_, fileNames_, fRandomEngine, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), lheAlpgenUnwParHeader, GenMuonPlsPt100GeV_cfg::maxEvents, maxEventsToPrint_, Nev_, pars, pythiaHepMCVerbosity_, pythiaPylistVerbosity_, and randomEngine.
00051 : 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 // JMM experimenting 00057 fileNames_ (pset.getUntrackedParameter<std::vector<std::string> >("fileNames")), 00058 eventsRead_(0), 00059 lheAlpgenUnwParHeader("AlpgenUnwParFile") 00060 // end JMM experimenting 00061 { 00062 00063 fileName_ = fileNames_[0]; 00064 // strip the file: 00065 if ( fileName_.find("file:") || fileName_.find("rfio:")){ 00066 fileName_.erase(0,5); 00067 } 00068 00069 // open the .unw file to store additional 00070 // informations in the AlpgenInfoProduct 00071 // unwfile = new ifstream((fileName_+".unw").c_str()); 00072 // get the number of input events from _unw.par files 00073 char buffer[256]; 00074 ifstream reader((fileName_+"_unw.par").c_str()); 00075 char sNev[80]; 00076 lheAlpgenUnwParHeader.addLine("\n"); 00077 while ( reader.getline (buffer,256) ) { 00078 istringstream is(buffer); 00079 lheAlpgenUnwParHeader.addLine(std::string(buffer) + "\n"); 00080 is >> sNev; 00081 Nev_ = atoi(sNev); 00082 } 00083 00084 // JMM experimenting 00085 #ifdef NEVER 00086 //check that N(asked events) <= N(input events) 00087 if(maxEvents()>Nev_) { 00088 cout << "ALPGEN warning: Number of events requested > Number of unweighted events." << endl; 00089 cout << " Execution will stop after processing the last unweighted event" << endl; 00090 } 00091 00092 if(maxEvents() != -1 && maxEvents() < Nev_) // stop at N(asked events) if N(asked events)<N(input events) 00093 Nev_ = maxEvents(); 00094 #endif 00095 // end JMM experimenting 00096 00097 // PYLIST Verbosity Level 00098 // Valid PYLIST arguments are: 1, 2, 3, 5, 7, 11, 12, 13 00099 pythiaPylistVerbosity_ = pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0); 00100 00101 // HepMC event verbosity Level 00102 pythiaHepMCVerbosity_ = pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false); 00103 00104 //Max number of events printed on verbosity level 00105 maxEventsToPrint_ = pset.getUntrackedParameter<int>("maxEventsToPrint",0); 00106 00107 // Set PYTHIA parameters in a single ParameterSet 00108 { 00109 ParameterSet pythia_params = 00110 pset.getParameter<ParameterSet>("PythiaParameters") ; 00111 00112 // Read the PYTHIA parameters for each set of parameters 00113 vector<string> pars = 00114 pythia_params.getParameter<vector<string> >("pythia"); 00115 00116 // Loop over all parameters and stop in case of mistake 00117 for( vector<string>::const_iterator 00118 itPar = pars.begin(); itPar != pars.end(); ++itPar ) { 00119 static string sRandomValueSetting("MRPY(1)"); 00120 if( 0 == itPar->compare(0,sRandomValueSetting.size(),sRandomValueSetting) ) { 00121 throw edm::Exception(edm::errors::Configuration,"PythiaError") 00122 <<" attempted to set random number seed."; 00123 } 00124 if( ! call_pygive(*itPar) ) { 00125 throw edm::Exception(edm::errors::Configuration,"PythiaError") 00126 <<" pythia did not accept the following \""<<*itPar<<"\""; 00127 } 00128 } 00129 } 00130 00131 // Read the Alpgen parameters 00132 00133 // read External Generator parameters 00134 { ParameterSet generator_params = 00135 pset.getParameter<ParameterSet>("GeneratorParameters") ; 00136 vector<string> pars = 00137 generator_params.getParameter<vector<string> >("generator"); 00138 for( vector<string>::const_iterator 00139 itPar = pars.begin(); itPar != pars.end(); ++itPar ) 00140 { 00141 call_txgive(*itPar); 00142 } 00143 // giving to txgive a string with the alpgen filename 00144 string tmpstring = "UNWFILE = " + fileName_; 00145 call_txgive(tmpstring); 00146 } 00147 00148 00149 //In the future, we will get the random number seed on each event and tell 00150 // pythia to use that new seed 00151 edm::Service<RandomNumberGenerator> rng; 00152 randomEngine = fRandomEngine = &(rng->getEngine()); 00153 uint32_t seed = rng->mySeed(); 00154 ostringstream sRandomSet; 00155 sRandomSet <<"MRPY(1)="<<seed; 00156 call_pygive(sRandomSet.str()); 00157 00158 // call_pretauola(-1); // TAUOLA initialization 00159 call_pyinit( "USER", "p", "p", 14000. ); 00160 00161 cout << endl; // Stetically add for the output 00162 //******** 00163 00164 produces<HepMCProduct>(); 00165 produces<LHEEventProduct>(); 00166 00167 // produces<AlpWgtFileInfoProduct, edm::InRun>(); 00168 produces<LHERunInfoProduct, edm::InRun>(); 00169 }
AlpgenProducer::~AlpgenProducer | ( | ) | [virtual] |
Destructor.
Definition at line 172 of file AlpgenProducer.cc.
References alpgen_end, and clear().
00172 { 00173 call_pystat(1); 00174 // call_pretauola(1); // output from TAUOLA 00175 alpgen_end(); 00176 clear(); 00177 }
Definition at line 183 of file AlpgenProducer.cc.
References LHERunInfoProduct::Header::addLine(), indexGen::comments, fileName_, lheAlpgenUnwParHeader, edm::Run::put(), lhef::CommonBlocks::readHEPRUP(), and edm::runInfo.
00183 { 00184 // get the LHE init information from Fortran code 00185 lhef::HEPRUP heprup; 00186 lhef::CommonBlocks::readHEPRUP(&heprup); 00187 auto_ptr<LHERunInfoProduct> runInfo(new LHERunInfoProduct(heprup)); 00188 00189 // information on weighted events 00190 LHERunInfoProduct::Header lheAlpgenWgtHeader("AlpgenWgtFile"); 00191 lheAlpgenWgtHeader.addLine("\n"); 00192 ifstream wgtascii((fileName_+".wgt").c_str()); 00193 char buffer[512]; 00194 while(wgtascii.getline(buffer,512)) { 00195 lheAlpgenWgtHeader.addLine(std::string(buffer) + "\n"); 00196 } 00197 00198 // comments on top 00199 LHERunInfoProduct::Header comments; 00200 comments.addLine("\n"); 00201 comments.addLine("\tExtracted by AlpgenInterface\n"); 00202 00203 // build the final Run info object 00204 runInfo->addHeader(comments); 00205 runInfo->addHeader(lheAlpgenUnwParHeader); 00206 runInfo->addHeader(lheAlpgenWgtHeader); 00207 r.put(runInfo); 00208 }
bool AlpgenProducer::call_pygive | ( | const std::string & | iParm | ) | [private] |
Interface to the PYGIVE/TXGIVE pythia routine, with add'l protections.
Definition at line 321 of file AlpgenProducer.cc.
References pydat1, and PYGIVE.
Referenced by AlpgenProducer().
00321 { 00322 00323 int numWarn = pydat1.mstu[26]; //# warnings 00324 int numErr = pydat1.mstu[22];// # errors 00325 00326 //call the fortran routine pygive with a fortran string 00327 PYGIVE( iParm.c_str(), iParm.length() ); 00328 // PYGIVE( iParm ); 00329 //if an error or warning happens it is problem 00330 return pydat1.mstu[26] == numWarn && pydat1.mstu[22] == numErr; 00331 }
bool AlpgenProducer::call_txgive | ( | const std::string & | iParm | ) | [private] |
Definition at line 334 of file AlpgenProducer.cc.
References TXGIVE.
Referenced by AlpgenProducer().
00335 { 00336 //call the fortran routine txgive with a fortran string 00337 TXGIVE( iParm.c_str(), iParm.length() ); 00338 return 1; 00339 }
void AlpgenProducer::produce | ( | Event & | e, | |
const EventSetup & | es | |||
) | [private, virtual] |
Implements edm::EDProducer.
Definition at line 210 of file AlpgenProducer.cc.
References lhef::HEPEUP::AQCDUP, lhef::HEPEUP::AQEDUP, call_pylist(), conv2, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), edm::EventID::event(), eventsRead_, evt, Exception, i, edm::Event::id(), maxEventsToPrint_, Nev_, lhef::HEPEUP::NUP, edm::Event::put(), pyint1, pypars, pythiaHepMCVerbosity_, pythiaPylistVerbosity_, lhef::CommonBlocks::readHEPEUP(), and lhef::HEPEUP::SPINUP.
00210 { 00211 00212 // exit if N(events asked) has been exceeded 00213 if(e.id().event()> Nev_) { 00214 throw cms::Exception("Generator") << "Can't produce event because _unw.par file is over."; 00215 } else { 00216 00217 auto_ptr<HepMCProduct> bare_product(new HepMCProduct()); 00218 00219 // // Additional information from unweighted file 00220 // auto_ptr<AlpgenInfoProduct> alp_product(new AlpgenInfoProduct()); 00221 00222 // Extract from .unw file the info for AlpgenInfoProduct 00223 00224 // char buffer[512]; 00225 // if(unwfile->getline(buffer,512)) { 00226 // alp_product->EventInfo(buffer); 00227 // } 00228 // if(unwfile->getline(buffer,512)) 00229 // alp_product->InPartonInfo(buffer); 00230 // if(unwfile->getline(buffer,512)) 00231 // alp_product->InPartonInfo(buffer); 00232 // for(int i_out = 0; i_out < alp_product->nTot()-2; i_out++) { 00233 // if(unwfile->getline(buffer,512)) 00234 // alp_product->OutPartonInfo(buffer); 00235 // } 00236 00237 call_pyevnt(); // generate one event with Pythia 00238 // call_pretauola(0); // tau-lepton decays with TAUOLA 00239 00240 // fill the parton level LHE event information 00241 lhef::HEPEUP hepeup; 00242 lhef::CommonBlocks::readHEPEUP(&hepeup); 00243 hepeup.AQEDUP = hepeup.AQCDUP = -1.0; // alphas are not saved by Alpgen 00244 for(int i = 0; i < hepeup.NUP; i++) 00245 hepeup.SPINUP[i] = -9; // Alpgen does not store spin information 00246 auto_ptr<LHEEventProduct> lheEvent(new LHEEventProduct(hepeup)); 00247 // Moved to later, first we have to make sure that the event generated by Pythia is OK. 00248 // e.put(lheEvent); 00249 00250 // The way this is implemented, call_pyevnt() will keep reading events from the .unw until 00251 // one of them is able to pass the matching veto. If it can't read a last event, it will 00252 // simply continue with whatever event was in memory. In this case, there are two possibilities: 00253 // A) The event passed the matching veto. There is meaningful information in HEPEUP. Continue. 00254 // (Will fail next Event with HEPEUP.NUP == 0. Harmless.) 00255 // B) The event didn't pass. HEPEUP.NUP == 0. This should never happen, and we should abort here. 00256 if(hepeup.NUP==0) { 00257 edm::LogInfo("Generator|TooLittleData") << "ALPGEN warning: last unweighted event reached.\n" 00258 << " (hepeup.NUP == 0)\n" 00259 << " The event number " << e.id().event() << " will not be written to disk."; 00260 throw cms::Exception("Generator") << "Can't produce event because _unw.par file is over."; 00261 } 00262 00263 call_pyhepc( 1 ); 00264 // HepMC::GenEvent* evt = conv2.getGenEventfromHEPEVT(); 00265 HepMC::GenEvent* evt = conv2.read_next_event(); 00266 00267 evt->set_signal_process_id(pypars.msti[0]); 00268 ++eventsRead_; 00269 evt->set_event_number(eventsRead_); 00270 00271 int id1 = pyint1.mint[14]; 00272 int id2 = pyint1.mint[15]; 00273 if ( id1 == 21 ) id1 = 0; 00274 if ( id2 == 21 ) id2 = 0; 00275 double x1 = pyint1.vint[40]; 00276 double x2 = pyint1.vint[41]; 00277 double Q = pyint1.vint[50]; 00278 double pdf1 = pyint1.vint[38]; 00279 pdf1 /= x1 ; 00280 double pdf2 = pyint1.vint[39]; 00281 pdf2 /= x2 ; 00282 evt->set_pdf_info( HepMC::PdfInfo(id1,id2,x1,x2,Q,pdf1,pdf2) ) ; 00283 00284 evt->weights().push_back( pyint1.vint[96] ); 00285 00286 //******** Verbosity ******** 00287 00288 if(e.id().event() <= maxEventsToPrint_ && 00289 (pythiaPylistVerbosity_ || pythiaHepMCVerbosity_)) { 00290 00291 // Prints PYLIST info 00292 if(pythiaPylistVerbosity_) { 00293 call_pylist(pythiaPylistVerbosity_); 00294 } 00295 00296 // Prints HepMC event 00297 if(pythiaHepMCVerbosity_) { 00298 cout << "Event process = " << pypars.msti[0] << endl 00299 << "----------------------" << endl; 00300 evt->print(); 00301 } 00302 } 00303 00304 if(evt) bare_product->addHepMCData(evt ); 00305 00306 // Last check to make sure there are no empty events. This DOES NOT 00307 // supersedes the AlpgenEmptyEventFilter, because this is a Producer, 00308 // not a source. So, it can only return, instead of returning false. 00309 // Should we take extra care here? 00310 00311 if(!(evt->particles_empty())) { 00312 e.put(lheEvent); 00313 e.put(bare_product); 00314 } 00315 00316 return; 00317 } 00318 }
bool edm::AlpgenProducer::doubleParticle [private] |
Definition at line 75 of file AlpgenProducer.h.
double edm::AlpgenProducer::etamax [private] |
Definition at line 77 of file AlpgenProducer.h.
double edm::AlpgenProducer::etamin [private] |
Definition at line 77 of file AlpgenProducer.h.
unsigned int edm::AlpgenProducer::eventsRead_ [private] |
HepMC::GenEvent* edm::AlpgenProducer::evt [private] |
std::string edm::AlpgenProducer::fileName_ [private] |
std::vector<std::string> edm::AlpgenProducer::fileNames_ [private] |
CLHEP::HepRandomEngine* edm::AlpgenProducer::fRandomEngine [private] |
CLHEP::RandFlat* edm::AlpgenProducer::fRandomGenerator [private] |
Definition at line 81 of file AlpgenProducer.h.
unsigned int edm::AlpgenProducer::maxEventsToPrint_ [private] |
Events to print if verbosity.
Definition at line 67 of file AlpgenProducer.h.
Referenced by AlpgenProducer(), and produce().
int edm::AlpgenProducer::Nev_ [private] |
int edm::AlpgenProducer::particleID [private] |
Definition at line 74 of file AlpgenProducer.h.
double edm::AlpgenProducer::phimax [private] |
Definition at line 78 of file AlpgenProducer.h.
double edm::AlpgenProducer::phimin [private] |
Definition at line 78 of file AlpgenProducer.h.
double edm::AlpgenProducer::ptmax [private] |
Definition at line 76 of file AlpgenProducer.h.
double edm::AlpgenProducer::ptmin [private] |
Definition at line 76 of file AlpgenProducer.h.
HepMC verbosity flag.
Definition at line 65 of file AlpgenProducer.h.
Referenced by AlpgenProducer(), and produce().
unsigned int edm::AlpgenProducer::pythiaPylistVerbosity_ [private] |
Pythia PYLIST Verbosity flag.
Definition at line 63 of file AlpgenProducer.h.
Referenced by AlpgenProducer(), and produce().