CMS 3D CMS Logo

edm::MadGraphProducer Class Reference

#include <GeneratorInterface/MadGraphInterface/interface/MadGraphProducer.h>

Inheritance diagram for edm::MadGraphProducer:

edm::EDFilter edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 MadGraphProducer (const ParameterSet &)
 Constructor.
virtual ~MadGraphProducer ()
 Destructor.

Private Member Functions

virtual bool beginRun (Run &run, const EventSetup &es)
bool call_pygive (const std::string &iParm)
 Interface to the PYGIVE pythia routine, with add'l protections.
void clear ()
virtual bool endRun (Run &run, const EventSetup &es)
virtual bool filter (Event &e, const EventSetup &es)
void init ()

Private Attributes

unsigned int eventNumber_
HepMC::GenEvent * evt
unsigned int firstEvent_
CLHEP::HepRandomEngine * fRandomEngine
bool initialized_
unsigned int maxEventsToPrint_
 Events to print if verbosity.
double MEMAIN_etaclmax
unsigned int MEMAIN_iexcfile
double MEMAIN_qcut
bool minimalLH_
HepMC::PdfInfo * pdf_info
bool produceEventTreeFile_
ParameterSet pset_
bool pythiaHepMCVerbosity_
 HepMC verbosity flag.
unsigned int pythiaPylistVerbosity_
 Pythia PYLIST Verbosity flag.
TauolaInterface tauola_
bool useExternalGenerators_
bool useTauola_
bool useTauolaPolarization_


Detailed Description

Definition at line 33 of file MadGraphProducer.h.


Constructor & Destructor Documentation

MadGraphProducer::MadGraphProducer ( const ParameterSet pset  ) 

Constructor.

Definition at line 126 of file MadGraphProducer.cc.

References call_pygive(), MEMAIN::clfact, edm::errors::Configuration, MEMAIN::etaclmax, MEMAIN::etcjet, SOURCEPRS::externalLH, firstEvent_, fRandomEngine, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), i, MEMAIN::iexcfile, MEMAIN::ktsche, maxEventsToPrint_, MEMAIN::maxjets, memain_, MEMAIN_etaclmax, MEMAIN_iexcfile, MEMAIN_qcut, SOURCEPRS::minimalLH, minimalLH_, MEMAIN::minjets, pars, pdf_info, pythiaHepMCVerbosity_, pythiaPylistVerbosity_, MEMAIN::qcut, randomEngine, MEMAIN::rclmax, sourceprs_, and useExternalGenerators_.

00126                                                              :
00127  EDFilter(), evt(0),
00128  pythiaPylistVerbosity_ (pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0)),
00129  pythiaHepMCVerbosity_ (pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false)),
00130  maxEventsToPrint_ (pset.getUntrackedParameter<int>("maxEventsToPrint",0)),
00131  firstEvent_(pset.getUntrackedParameter<unsigned int>("firstEvent", 0)),
00132  MEMAIN_etaclmax(pset.getUntrackedParameter<double>("MEMAIN_etaclmax",0.)),
00133  MEMAIN_qcut(pset.getUntrackedParameter<double>("MEMAIN_qcut",0.)),
00134  MEMAIN_iexcfile(pset.getUntrackedParameter<unsigned int>("MEMAIN_iexcfile",0)),
00135  produceEventTreeFile_ (pset.getUntrackedParameter<bool>("produceEventTreeFile",false)),
00136  minimalLH_(pset.getUntrackedParameter<bool>("minimalLH",false)),
00137  initialized_(false),
00138  eventNumber_(firstEvent_),
00139  pset_(pset),
00140  useExternalGenerators_(false),
00141  useTauola_(false),
00142  useTauolaPolarization_(false)
00143 {
00144   edm::LogInfo("Generator|MadGraph")<<" initializing MadGraphProducer";
00145   pdf_info = new HepMC::PdfInfo();
00146 
00147   // check whether using minimal LH
00148   sourceprs_.minimalLH = minimalLH_; // pass to ME2pythia through common block
00149   sourceprs_.externalLH = true;
00150   if(minimalLH_) edm::LogInfo("Generator|MadGraph")<<" ----- Using minimal Les Houches Accord functionality - ignoring MadGraph specifics.";
00151   
00152   // first set to default values, mostly zeros
00153   memain_.etcjet=0.;
00154   memain_.rclmax=0.;
00155   memain_.etaclmax=0.;
00156   memain_.qcut=0.;
00157   memain_.clfact=0.;
00158   memain_.maxjets=0;
00159   memain_.minjets=0;
00160   memain_.iexcfile=0;
00161   memain_.ktsche=0;
00162   // then set (some) values from cards
00163   memain_.iexcfile=MEMAIN_iexcfile;
00164   memain_.etaclmax=MEMAIN_etaclmax;
00165   memain_.qcut=MEMAIN_qcut;
00166   // print out
00167   edm::LogInfo("Generator|MadGraph")<<"MEMAIN before ME2pythia initialization - etcjet ="<<memain_.etcjet<<" rclmax ="<<memain_.rclmax<<" etaclmax ="<<memain_.etaclmax<<" qcut ="<<memain_.qcut<<" clfact ="<<memain_.clfact<<" maxjets ="<<memain_.maxjets<<" minjets ="<<memain_.minjets<<" iexcfile ="<<memain_.iexcfile<<" ktsche ="<<memain_.ktsche;
00168 
00169   edm::LogInfo("Generator|MadGraph")<<"MadGraphProducer: initializing Pythia.";
00170   // PYLIST Verbosity Level
00171   // Valid PYLIST arguments are: 1, 2, 3, 5, 7, 11, 12, 13
00172   edm::LogInfo("Generator|MadGraph")<<"Pythia PYLIST verbosity level = " << pythiaPylistVerbosity_;
00173   // HepMC event verbosity Level
00174   edm::LogInfo("Generator|MadGraph")<<"Pythia HepMC verbosity = " << pythiaHepMCVerbosity_;
00175   //Max number of events printed on verbosity level 
00176   edm::LogInfo("Generator|MadGraph")<<"Number of events to be printed = " << maxEventsToPrint_;
00177   // max nr of events and first event
00178 //edm::LogInfo("Generator|MadGraph")<<"firstEvent / maxEvents = "<<firstEvent_<<" / "<< maxEvents();
00179   edm::LogInfo("Generator|MadGraph")<<"firstEvent / maxEvents = "<<firstEvent_<<" / 999999999";
00180 
00181   // Set PYTHIA parameters in a single ParameterSet
00182   ParameterSet pythia_params = pset.getParameter<ParameterSet>("PythiaParameters") ;
00183   
00184   // The parameter sets to be read (default, min bias, user ...) in the proper order.
00185   std::vector<std::string> setNames = pythia_params.getParameter<std::vector<std::string> >("parameterSets");
00186   
00187   // Loop over the sets
00188   for ( unsigned i=0; i<setNames.size(); ++i ) {
00189     std::string mySet = setNames[i];
00190     
00191     // Read the PYTHIA parameters for each set of parameters
00192     std::vector<std::string> pars = 
00193       pythia_params.getParameter<std::vector<std::string> >(mySet);
00194     
00195     edm::LogInfo("Generator|MadGraph")<<"----------------------------------------------";
00196     edm::LogInfo("Generator|MadGraph")<<"Read PYTHIA parameter set " << mySet;
00197     edm::LogInfo("Generator|MadGraph")<<"----------------------------------------------";
00198     
00199     // Loop over all parameters and stop in case of mistake
00200     for( std::vector<std::string>::const_iterator  
00201            itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
00202       static std::string sRandomValueSetting("MRPY(1)");
00203       if( 0 == itPar->compare(0,sRandomValueSetting.size(),sRandomValueSetting) ) {
00204         throw edm::Exception(edm::errors::Configuration,"PythiaError")
00205           <<" 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.";
00206       }
00207       if( ! call_pygive(*itPar) ) {
00208         throw edm::Exception(edm::errors::Configuration,"PythiaError") 
00209           <<" pythia did not accept the following \""<<*itPar<<"\"";
00210       }
00211     }
00212   }
00213 
00214   // TAUOLA, etc.
00215   //
00216   useExternalGenerators_ = pset.getUntrackedParameter<bool>("UseExternalGenerators",false);
00217   
00218   //Setting random numer seed
00219   edm::LogInfo("Generator|MadGraph")<<"----------------------------------------------";
00220   edm::LogInfo("Generator|MadGraph")<<"Setting Pythia random number seed";
00221   edm::LogInfo("Generator|MadGraph")<<"----------------------------------------------";
00222   edm::Service<RandomNumberGenerator> rng;
00223   randomEngine = fRandomEngine = &(rng->getEngine());
00224   uint32_t seed = rng->mySeed();
00225   std::ostringstream sRandomSet;
00226   sRandomSet <<"MRPY(1)="<<seed;
00227   call_pygive(sRandomSet.str());
00228   produces<HepMCProduct>();
00229   edm::LogInfo("Generator|MadGraph")<<"starting event generation ...";
00230 }

MadGraphProducer::~MadGraphProducer (  )  [virtual]

Destructor.

Definition at line 233 of file MadGraphProducer.cc.

References clear(), and pdf_info.

00233                                    {
00234   edm::LogInfo("Generator|MadGraph")<<"event generation done.";
00235   delete pdf_info;
00236   clear();
00237   //  rm -f MGinput.dat;
00238 }


Member Function Documentation

bool MadGraphProducer::beginRun ( Run run,
const EventSetup es 
) [private, virtual]

Reimplemented from edm::EDFilter.

Definition at line 303 of file MadGraphProducer.cc.

References edmNew::copy(), file, lhef::CommonBlocks::fillHEPRUP(), mergeAndRegister_online::fname, edm::DataViewImpl::getByLabel(), mgopen_(), minimalLH_, NULL, out, and remove().

00304 {
00305   edm::Handle<LHERunInfoProduct> product;
00306   run.getByLabel("source", product);
00307   lhef::CommonBlocks::fillHEPRUP(&product->heprup());
00308 
00309   if (!minimalLH_) {
00310     const char *fname = std::tmpnam(NULL);
00311     std::ofstream file(fname, std::fstream::out | std::fstream::trunc);
00312     std::copy(product->begin(), product->init(),
00313               std::ostream_iterator<std::string>(file));
00314     file.close();
00315     mgopen_(fname, std::strlen(fname));
00316     std::remove(fname);
00317   }
00318 
00319   return true;
00320 }

bool MadGraphProducer::call_pygive ( const std::string &  iParm  )  [private]

Interface to the PYGIVE pythia routine, with add'l protections.

Definition at line 402 of file MadGraphProducer.cc.

References pydat1, and PYGIVE.

Referenced by MadGraphProducer().

00402                                                           {
00403   int numWarn = pydat1.mstu[26]; //# warnings
00404   int numErr = pydat1.mstu[22];// # errors
00405   //call the fortran routine pygive with a fortran string
00406   PYGIVE( iParm.c_str(), iParm.length() );
00407   //  PYGIVE( iParm );
00408   //if an error or warning happens it is problem
00409   return pydat1.mstu[26] == numWarn && pydat1.mstu[22] == numErr;
00410 }

void MadGraphProducer::clear ( void   )  [private]

Definition at line 240 of file MadGraphProducer.cc.

Referenced by ~MadGraphProducer().

00240                              {
00241 }

bool MadGraphProducer::endRun ( Run run,
const EventSetup es 
) [private, virtual]

Reimplemented from edm::EDFilter.

Definition at line 322 of file MadGraphProducer.cc.

References initialized_, mgclos_(), edm::TauolaInterface::print(), tauola_, and useTauola_.

00323 {
00324   call_pystat(1);
00325   if ( useTauola_ ) {
00326     tauola_.print();
00327     //call_pretauola(1); // print TAUOLA decay statistics output
00328   }
00329 
00330   mgclos_();
00331   initialized_ = false;
00332   return true;
00333 }

bool MadGraphProducer::filter ( Event e,
const EventSetup es 
) [private, virtual]

Implements edm::EDFilter.

Definition at line 335 of file MadGraphProducer.cc.

References call_pylist(), conv, edm::EventID::event(), eventNumber_, eventtree_(), evt, lhef::CommonBlocks::fillHEPEUP(), edm::Event::getByLabel(), hepeup_, edm::Event::id(), init(), initialized_, maxEventsToPrint_, HEPEUP_::nup, pdf_info, edm::TauolaInterface::processEvent(), produceEventTreeFile_, edm::Event::put(), pypars, pythiaHepMCVerbosity_, pythiaPylistVerbosity_, sourceprs_, tauola_, useTauola_, and SOURCEPRS::validLH.

00336 {
00337   edm::Handle<LHEEventProduct> product;
00338   e.getByLabel("source", product);
00339   lhef::CommonBlocks::fillHEPEUP(&product->hepeup());
00340   sourceprs_.validLH = true;
00341   if (!initialized_)
00342     init();
00343 
00344   std::auto_ptr<HepMCProduct> bare_product(new HepMCProduct());  
00345 
00346   call_pyevnt();      // generate one event with Pythia
00347 
00348   if (hepeup_.nup == 0 || pypars.msti[0] == 1) {
00349     // the event got rejected by the matching and we have to filter
00350     edm::LogInfo("Generator|MadGraph") << "Event was skipped.";
00351     e.put(bare_product); // put an empty product, CMSSW filter will take care
00352     return false;
00353   }
00354 
00355   if ( useTauola_ ) {
00356     tauola_.processEvent();
00357     //call_pretauola(0); // generate tau decays with TAUOLA
00358   }
00359 
00360   call_pyhepc( 1 );
00361 
00362   if(produceEventTreeFile_) eventtree_(); // write out an event tree file
00363 
00364   HepMC::IO_HEPEVT conv;
00365   HepMC::GenEvent* evt = conv.read_next_event();
00366   evt->set_signal_process_id(pypars.msti[0]);
00367   evt->set_event_number(eventNumber_);
00368   ++eventNumber_;
00369 
00370   // store PDF information
00371   int id_1 = pypars.msti[14];
00372   int id_2 = pypars.msti[15];
00373   if (id_1 == 21) id_1 = 0;
00374   if (id_2 == 21) id_2 = 0;
00375   pdf_info->set_id1(id_1);
00376   pdf_info->set_id2(id_2);
00377   pdf_info->set_x1(pypars.pari[32]);
00378   pdf_info->set_x2(pypars.pari[33]);
00379   pdf_info->set_scalePDF(pypars.pari[20]);
00380   pdf_info->set_pdf1(pypars.pari[28]);
00381   pdf_info->set_pdf2(pypars.pari[29]);
00382   evt->set_pdf_info( *pdf_info);
00383 
00384   if(e.id().event() <= maxEventsToPrint_ && (pythiaPylistVerbosity_ || pythiaHepMCVerbosity_)) {
00385     // Prints PYLIST info
00386     if(pythiaPylistVerbosity_) {
00387       call_pylist(pythiaPylistVerbosity_);
00388     }
00389     // Prints HepMC event
00390     if(pythiaHepMCVerbosity_) {
00391       edm::LogInfo("Generator|MadGraph")<<"Event process = " << pypars.msti[0];
00392       evt->print();
00393     }
00394   }
00395 
00396   bare_product->addHepMCData(evt );
00397   e.put(bare_product);
00398 
00399   return true;
00400 }

void MadGraphProducer::init ( void   )  [private]

Definition at line 243 of file MadGraphProducer.cc.

References cards, MEMAIN::clfact, GenMuonPlsPt100GeV_cfg::cout, edm::TauolaInterface::disablePolarizationEffects(), edm::TauolaInterface::enablePolarizationEffects(), lat::endl(), MEMAIN::etaclmax, MEMAIN::etcjet, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), MEMAIN::iexcfile, edm::TauolaInterface::initialize(), initialized_, MEMAIN::ktsche, MEMAIN::maxjets, memain_, MEMAIN::minjets, pset_, MEMAIN::qcut, MEMAIN::rclmax, tauola_, TXGIVE, useExternalGenerators_, useTauola_, and useTauolaPolarization_.

Referenced by filter().

00243                             {
00244   initialized_ = true;
00245 
00246   // Call pythia initialisation with user defined upinit subroutine
00247   call_pyinit( "USER", "", "", 0.);
00248 
00249   if ( useExternalGenerators_ ) {
00250     // read External Generator parameters
00251     ParameterSet ext_gen_params =
00252        pset_.getParameter<ParameterSet>("ExternalGenerators") ;
00253     vector<string> extGenNames =
00254        ext_gen_params.getParameter< vector<string> >("parameterSets");
00255     for (unsigned int ip=0; ip<extGenNames.size(); ++ip )
00256     {
00257       string curSet = extGenNames[ip];
00258       ParameterSet gen_par_set =
00259          ext_gen_params.getUntrackedParameter< ParameterSet >(curSet);
00260 /*
00261      cout << "----------------------------------------------" << endl;
00262      cout << "Read External Generator parameter set "  << endl;
00263      cout << "----------------------------------------------" << endl;
00264 */
00265      if ( curSet == "Tauola" )
00266      {
00267         useTauola_ = true;
00268         if ( useTauola_ ) {
00269            cout << "--> use TAUOLA" << endl;
00270         } 
00271         useTauolaPolarization_ = gen_par_set.getParameter<bool>("UseTauolaPolarization");
00272         if ( useTauolaPolarization_ ) 
00273         {
00274            cout << "(Polarization effects enabled)" << endl;
00275            tauola_.enablePolarizationEffects();
00276         } 
00277         else 
00278         {
00279            cout << "(Polarization effects disabled)" << endl;
00280            tauola_.disablePolarizationEffects();
00281         }
00282         vector<string> cards = gen_par_set.getParameter< vector<string> >("InputCards");
00283         cout << "----------------------------------------------" << endl;
00284         cout << "Initializing Tauola" << endl;
00285         for( vector<string>::const_iterator
00286                 itPar = cards.begin(); itPar != cards.end(); ++itPar )
00287         {
00288            // call_txgive(*itPar);
00289            TXGIVE( (*itPar).c_str(), (*itPar).length() );
00290            cout << "     " <<  (*itPar).c_str() << endl;
00291         }
00292         tauola_.initialize();
00293         //call_pretauola(-1); // initialize TAUOLA package for tau decays
00294      }
00295     }
00296     // cout << "----------------------------------------------" << endl;
00297   }
00298 
00299 
00300   edm::LogInfo("Generator|MadGraph")<<"MEMAIN after ME2pythia initialization - etcjet ="<<memain_.etcjet<<" rclmax ="<<memain_.rclmax<<" etaclmax ="<<memain_.etaclmax<<" qcut ="<<memain_.qcut<<" clfact ="<<memain_.clfact<<" maxjets ="<<memain_.maxjets<<" minjets ="<<memain_.minjets<<" iexcfile ="<<memain_.iexcfile<<" ktsche ="<<memain_.ktsche;
00301 }


Member Data Documentation

unsigned int edm::MadGraphProducer::eventNumber_ [private]

Definition at line 65 of file MadGraphProducer.h.

Referenced by filter().

HepMC::GenEvent* edm::MadGraphProducer::evt [private]

Definition at line 48 of file MadGraphProducer.h.

Referenced by filter().

unsigned int edm::MadGraphProducer::firstEvent_ [private]

Definition at line 56 of file MadGraphProducer.h.

Referenced by MadGraphProducer().

CLHEP::HepRandomEngine* edm::MadGraphProducer::fRandomEngine [private]

Definition at line 66 of file MadGraphProducer.h.

Referenced by MadGraphProducer().

bool edm::MadGraphProducer::initialized_ [private]

Definition at line 64 of file MadGraphProducer.h.

Referenced by endRun(), filter(), and init().

unsigned int edm::MadGraphProducer::maxEventsToPrint_ [private]

Events to print if verbosity.

Definition at line 55 of file MadGraphProducer.h.

Referenced by filter(), and MadGraphProducer().

double edm::MadGraphProducer::MEMAIN_etaclmax [private]

Definition at line 58 of file MadGraphProducer.h.

Referenced by MadGraphProducer().

unsigned int edm::MadGraphProducer::MEMAIN_iexcfile [private]

Definition at line 60 of file MadGraphProducer.h.

Referenced by MadGraphProducer().

double edm::MadGraphProducer::MEMAIN_qcut [private]

Definition at line 59 of file MadGraphProducer.h.

Referenced by MadGraphProducer().

bool edm::MadGraphProducer::minimalLH_ [private]

Definition at line 63 of file MadGraphProducer.h.

Referenced by beginRun(), and MadGraphProducer().

HepMC::PdfInfo* edm::MadGraphProducer::pdf_info [private]

Definition at line 49 of file MadGraphProducer.h.

Referenced by filter(), MadGraphProducer(), and ~MadGraphProducer().

bool edm::MadGraphProducer::produceEventTreeFile_ [private]

Definition at line 61 of file MadGraphProducer.h.

Referenced by filter().

ParameterSet edm::MadGraphProducer::pset_ [private]

Definition at line 67 of file MadGraphProducer.h.

Referenced by init().

bool edm::MadGraphProducer::pythiaHepMCVerbosity_ [private]

HepMC verbosity flag.

Definition at line 53 of file MadGraphProducer.h.

Referenced by filter(), and MadGraphProducer().

unsigned int edm::MadGraphProducer::pythiaPylistVerbosity_ [private]

Pythia PYLIST Verbosity flag.

Definition at line 51 of file MadGraphProducer.h.

Referenced by filter(), and MadGraphProducer().

TauolaInterface edm::MadGraphProducer::tauola_ [private]

Definition at line 73 of file MadGraphProducer.h.

Referenced by endRun(), filter(), and init().

bool edm::MadGraphProducer::useExternalGenerators_ [private]

Definition at line 70 of file MadGraphProducer.h.

Referenced by init(), and MadGraphProducer().

bool edm::MadGraphProducer::useTauola_ [private]

Definition at line 71 of file MadGraphProducer.h.

Referenced by endRun(), filter(), and init().

bool edm::MadGraphProducer::useTauolaPolarization_ [private]

Definition at line 72 of file MadGraphProducer.h.

Referenced by init().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:41:47 2009 for CMSSW by  doxygen 1.5.4