CMS 3D CMS Logo

edm::MadGraphSource Class Reference

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

Inheritance diagram for edm::MadGraphSource:

edm::ExternalInputSource edm::ConfigurableInputSource edm::InputSource edm::ProductRegistryHelper

List of all members.

Public Member Functions

void endRun (Run &r)
 MadGraphSource (const ParameterSet &, const InputSourceDescription &)
 Constructor.
virtual ~MadGraphSource ()
 Destructor.

Private Member Functions

bool call_pygive (const std::string &iParm)
 Interface to the PYGIVE pythia routine, with add'l protections.
void clear ()
virtual bool produce (Event &e)

Private Attributes

HepMC::GenEvent * evt
unsigned int firstEvent_
bool getInputFromMCDB_
 Get input file from LCG MCDB.
unsigned int lhe_event_counter_
unsigned int maxEventsToPrint_
 Events to print if verbosity.
int MCDBArticleID_
 Sets the MCDB Article ID (0 if none).
double MEMAIN_etaclmax
unsigned int MEMAIN_iexcfile
int MEMAIN_maxjets
double MEMAIN_qcut
std::string MGfile_
 Name of file which contains the unweighted MadGraph events.
bool minimalLH_
HepMC::PdfInfo * pdf_info
bool produceEventTreeFile_
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 32 of file MadGraphSource.h.


Constructor & Destructor Documentation

MadGraphSource::MadGraphSource ( const ParameterSet pset,
const InputSourceDescription desc 
)

Constructor.

Definition at line 109 of file MadGraphSource.cc.

References call_pygive(), cards, MEMAIN::clfact, edm::errors::Configuration, GenMuonPlsPt100GeV_cfg::cout, edm::TauolaInterface::disablePolarizationEffects(), edm::TauolaInterface::enablePolarizationEffects(), lat::endl(), MEMAIN::etaclmax, MEMAIN::etcjet, file, firstEvent_, getInputFromMCDB_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), i, MEMAIN::iexcfile, in, edm::TauolaInterface::initialize(), MEMAIN::ktsche, edm::InputSource::maxEvents(), maxEventsToPrint_, MEMAIN::maxjets, MCDBArticleID_, mcdbGetInputFile(), memain_, MEMAIN_etaclmax, MEMAIN_iexcfile, MEMAIN_maxjets, MEMAIN_qcut, MGfile_, mgopen_(), SOURCEPRS::minimalLH, minimalLH_, MEMAIN::minjets, indexGen::ofile, pars, pdf_info, pythiaHepMCVerbosity_, pythiaPylistVerbosity_, MEMAIN::qcut, randomEngine, MEMAIN::rclmax, sourceprs_, tauola_, TXGIVE, useExternalGenerators_, useTauola_, and useTauolaPolarization_.

00110    : ExternalInputSource (pset, desc, false), evt(0),
00111      pythiaPylistVerbosity_ (pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0)),
00112      pythiaHepMCVerbosity_ (pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false)),
00113      maxEventsToPrint_ (pset.getUntrackedParameter<int>("maxEventsToPrint",0)),
00114      MGfile_ (fileNames()[0]),
00115      getInputFromMCDB_ (pset.getUntrackedParameter<bool>("getInputFromMCDB",false)),
00116      MCDBArticleID_ (pset.getParameter<int>("MCDBArticleID")),
00117      firstEvent_(pset.getUntrackedParameter<unsigned int>("firstEvent", 0)),
00118      lhe_event_counter_(0),MEMAIN_etaclmax(pset.getUntrackedParameter<double>("MEMAIN_etaclmax",0.)),
00119      MEMAIN_qcut(pset.getUntrackedParameter<double>("MEMAIN_qcut",0.)),
00120      MEMAIN_iexcfile(pset.getUntrackedParameter<unsigned int>("MEMAIN_iexcfile",0)), 
00121      MEMAIN_maxjets(pset.getUntrackedParameter<int>("MEMAIN_maxjets",-1)), 
00122      produceEventTreeFile_ (pset.getUntrackedParameter<bool>("produceEventTreeFile",false)), 
00123      minimalLH_(pset.getUntrackedParameter<bool>("minimalLH",false)),
00124   useExternalGenerators_(false),
00125   useTauola_(false),
00126   useTauolaPolarization_(false)
00127 {
00128 
00129   edm::LogInfo("Generator|MadGraph")<<" initializing MadGraphSource";
00130   pdf_info = new HepMC::PdfInfo();
00131 
00132   std::ifstream file;
00133   std::ofstream ofile;
00134 
00135   // Interface with the LCG MCDB
00136   if (getInputFromMCDB_)  mcdbGetInputFile(MGfile_, MCDBArticleID_);
00137 
00138   // strip the input file name
00139   if ( MGfile_.find("file:") || MGfile_.find("rfio:")){
00140     MGfile_.erase(0,5);
00141   }   
00142  //
00143   file.open(MGfile_.c_str(),std::ios::in);  
00144   if(!file){
00145     edm::LogError("GeneratorError|OpenMadGraphFileError")<< "Error: Cannot open MadGraph input file";
00146     throw edm::Exception(edm::errors::Configuration,"OpenMadGraphFileError")
00147       <<" Cannot open MadGraph input file, check file name and path.";
00148   }else{
00149     edm::LogInfo("Generator|MadGraph")<<"Opened MadGraph file successfully!";
00150     file.close();
00151   }
00152   
00153   edm::LogInfo("Generator|MadGraph")<< "MadGraph input file is " << MGfile_;
00154   
00155   mgopen_(MGfile_.c_str(), MGfile_.size());
00156 
00157 //  //Write to file name and first event to be read in to a file which the MadGraph subroutine will read in
00158 //  ofile.open("MGinput.dat",std::ios::out);
00159 //  ofile<<MGfile_;
00160 //  ofile<<"\n";
00161 //  ofile.close();
00162 
00163   // check whether using minimal LH
00164   sourceprs_.minimalLH = minimalLH_; // pass to ME2pythia through common block
00165   if(minimalLH_) edm::LogInfo("Generator|MadGraph")<<" ----- Using minimal Les Houches Accord functionality - ignoring MadGraph specifics.";
00166   
00167   // first set to default values, mostly zeros
00168   memain_.etcjet=0.;
00169   memain_.rclmax=0.;
00170   memain_.etaclmax=0.;
00171   memain_.qcut=0.;
00172   memain_.clfact=0.;
00173   memain_.maxjets=0;
00174   memain_.minjets=0;
00175   memain_.iexcfile=0;
00176   memain_.ktsche=0;
00177   // then set (some) values from cards
00178   memain_.iexcfile=MEMAIN_iexcfile;
00179   memain_.etaclmax=MEMAIN_etaclmax;
00180   memain_.qcut=MEMAIN_qcut;
00181   // print out
00182   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;
00183 
00184   edm::LogInfo("Generator|MadGraph")<<"MadGraphSource: initializing Pythia.";
00185   // PYLIST Verbosity Level
00186   // Valid PYLIST arguments are: 1, 2, 3, 5, 7, 11, 12, 13
00187   edm::LogInfo("Generator|MadGraph")<<"Pythia PYLIST verbosity level = " << pythiaPylistVerbosity_;
00188   // HepMC event verbosity Level
00189   edm::LogInfo("Generator|MadGraph")<<"Pythia HepMC verbosity = " << pythiaHepMCVerbosity_;
00190   //Max number of events printed on verbosity level 
00191   edm::LogInfo("Generator|MadGraph")<<"Number of events to be printed = " << maxEventsToPrint_;
00192   // max nr of events and first event
00193   edm::LogInfo("Generator|MadGraph")<<"firstEvent / maxEvents = "<<firstEvent_<<" / "<< maxEvents();
00194 
00195   // Set PYTHIA parameters in a single ParameterSet
00196   ParameterSet pythia_params = pset.getParameter<ParameterSet>("PythiaParameters") ;
00197   
00198   // The parameter sets to be read (default, min bias, user ...) in the proper order.
00199   std::vector<std::string> setNames = pythia_params.getParameter<std::vector<std::string> >("parameterSets");
00200   
00201   // Loop over the sets
00202   for ( unsigned i=0; i<setNames.size(); ++i ) {
00203     std::string mySet = setNames[i];
00204     
00205     // Read the PYTHIA parameters for each set of parameters
00206     std::vector<std::string> pars = 
00207       pythia_params.getParameter<std::vector<std::string> >(mySet);
00208     
00209     edm::LogInfo("Generator|MadGraph")<<"----------------------------------------------";
00210     edm::LogInfo("Generator|MadGraph")<<"Read PYTHIA parameter set " << mySet;
00211     edm::LogInfo("Generator|MadGraph")<<"----------------------------------------------";
00212     
00213     // Loop over all parameters and stop in case of mistake
00214     for( std::vector<std::string>::const_iterator  
00215            itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
00216       static std::string sRandomValueSetting("MRPY(1)");
00217       if( 0 == itPar->compare(0,sRandomValueSetting.size(),sRandomValueSetting) ) {
00218         throw edm::Exception(edm::errors::Configuration,"PythiaError")
00219           <<" 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.";
00220       }
00221       if( ! call_pygive(*itPar) ) {
00222         throw edm::Exception(edm::errors::Configuration,"PythiaError") 
00223           <<" pythia did not accept the following \""<<*itPar<<"\"";
00224       }
00225     }
00226   }
00227   
00228   //Setting random numer seed
00229   edm::LogInfo("Generator|MadGraph")<<"----------------------------------------------";
00230   edm::LogInfo("Generator|MadGraph")<<"Setting Pythia random number seed";
00231   edm::LogInfo("Generator|MadGraph")<<"----------------------------------------------";
00232   edm::Service<RandomNumberGenerator> rng;
00233   randomEngine = &(rng->getEngine());
00234   uint32_t seed = rng->mySeed();
00235   std::ostringstream sRandomSet;
00236   sRandomSet <<"MRPY(1)="<<seed;
00237   call_pygive(sRandomSet.str());
00238   // Call pythia initialisation with user defined upinit subroutine
00239   call_pyinit( "USER", "", "", 0.);
00240 
00241   // enforce highest multiplicity if MEMAIN_maxjets is larger than 0 (it is -1 if not set in the CMSSW configuration)
00242   if( (MEMAIN_maxjets>0) && (MEMAIN_maxjets > memain_.maxjets)){
00243     edm::LogWarning("Generator|MadGraph")<<"Enforcing highest multiplicity through CMSSW configuration to be maxjets="<<MEMAIN_maxjets<<" instead of the one calculated from the ME2pythia which is maxjets="<<memain_.maxjets;
00244     memain_.maxjets=MEMAIN_maxjets;
00245   }
00246 
00247 
00248   // TAUOLA, etc.
00249   //
00250   useExternalGenerators_ = pset.getUntrackedParameter<bool>("UseExternalGenerators",false);
00251 //  useTauola_ = pset.getUntrackedParameter<bool>("UseTauola", false);
00252 //  useTauolaPolarization_ = pset.getUntrackedParameter<bool>("UseTauolaPolarization", false);
00253 
00254   if ( useExternalGenerators_ ) {
00255  // read External Generator parameters
00256     ParameterSet ext_gen_params =
00257        pset.getParameter<ParameterSet>("ExternalGenerators") ;
00258     vector<string> extGenNames =
00259        ext_gen_params.getParameter< vector<string> >("parameterSets");
00260     for (unsigned int ip=0; ip<extGenNames.size(); ++ip )
00261     {
00262       string curSet = extGenNames[ip];
00263       ParameterSet gen_par_set =
00264          ext_gen_params.getUntrackedParameter< ParameterSet >(curSet);
00265 /*
00266      cout << "----------------------------------------------" << endl;
00267      cout << "Read External Generator parameter set "  << endl;
00268      cout << "----------------------------------------------" << endl;
00269 */
00270      if ( curSet == "Tauola" )
00271      {
00272         useTauola_ = true;
00273         if ( useTauola_ ) {
00274            cout << "--> use TAUOLA" << endl;
00275         } 
00276         useTauolaPolarization_ = gen_par_set.getParameter<bool>("UseTauolaPolarization");
00277         if ( useTauolaPolarization_ ) 
00278         {
00279            cout << "(Polarization effects enabled)" << endl;
00280            tauola_.enablePolarizationEffects();
00281         } 
00282         else 
00283         {
00284            cout << "(Polarization effects disabled)" << endl;
00285            tauola_.disablePolarizationEffects();
00286         }
00287         vector<string> cards = gen_par_set.getParameter< vector<string> >("InputCards");
00288         cout << "----------------------------------------------" << endl;
00289         cout << "Initializing Tauola" << endl;
00290         for( vector<string>::const_iterator
00291                 itPar = cards.begin(); itPar != cards.end(); ++itPar )
00292         {
00293            // call_txgive(*itPar);
00294            TXGIVE( (*itPar).c_str(), (*itPar).length() );
00295            cout << "     " <<  (*itPar).c_str() << endl;
00296         }
00297         tauola_.initialize();
00298         //call_pretauola(-1); // initialize TAUOLA package for tau decays
00299      }
00300     }
00301     // cout << "----------------------------------------------" << endl;
00302   }
00303 
00304 
00305   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;
00306 
00307   produces<HepMCProduct>();
00308   edm::LogInfo("Generator|MadGraph")<<"starting event generation ...";
00309 }

MadGraphSource::~MadGraphSource (  )  [virtual]

Destructor.

Definition at line 312 of file MadGraphSource.cc.

References clear(), mgclos_(), and pdf_info.

00312                                {
00313   edm::LogInfo("Generator|MadGraph")<<"event generation done.";
00314   delete pdf_info;
00315   clear();
00316   mgclos_();
00317   //  rm -f MGinput.dat;
00318 }


Member Function Documentation

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

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

Definition at line 409 of file MadGraphSource.cc.

References pydat1, and PYGIVE.

Referenced by MadGraphSource().

00409                                                         {
00410   int numWarn = pydat1.mstu[26]; //# warnings
00411   int numErr = pydat1.mstu[22];// # errors
00412   //call the fortran routine pygive with a fortran string
00413   PYGIVE( iParm.c_str(), iParm.length() );
00414   //  PYGIVE( iParm );
00415   //if an error or warning happens it is problem
00416   return pydat1.mstu[26] == numWarn && pydat1.mstu[22] == numErr;
00417 }

void MadGraphSource::clear ( void   )  [private]

Definition at line 320 of file MadGraphSource.cc.

Referenced by ~MadGraphSource().

00320                            {
00321 }

void MadGraphSource::endRun ( Run r  )  [virtual]

Reimplemented from edm::ConfigurableInputSource.

Definition at line 323 of file MadGraphSource.cc.

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

00323                                    {
00324  
00325   call_pystat(1);
00326   if ( useTauola_ ) {
00327     tauola_.print();
00328     //call_pretauola(1); // print TAUOLA decay statistics output
00329   }
00330 
00331 }

bool MadGraphSource::produce ( Event e  )  [private, virtual]

Implements edm::ConfigurableInputSource.

Definition at line 334 of file MadGraphSource.cc.

References call_pylist(), conv, edm::ConfigurableInputSource::event(), eventtree_(), evt, firstEvent_, hepeup_, lhe_event_counter_, maxEventsToPrint_, edm::ConfigurableInputSource::numberEventsInRun(), HEPEUP_::nup, pdf_info, edm::TauolaInterface::processEvent(), produceEventTreeFile_, edm::Event::put(), pypars, pythiaHepMCVerbosity_, pythiaPylistVerbosity_, edm::InputSource::remainingEvents(), tauola_, and useTauola_.

00334                                       {
00335   std::auto_ptr<HepMCProduct> bare_product(new HepMCProduct());  
00336 
00337   // skip LHE events - read firstEvent_ times <event>...</event> from the LHE file without returning from produce()
00338   for(;lhe_event_counter_<firstEvent_; ++lhe_event_counter_){
00339     call_pyevnt();      // generate one event with Pythia
00340     call_pyhepc( 1 );
00341     edm::LogWarning("Generator|MadGraph")<<"skipping LHE event "<<lhe_event_counter_;
00342     if(hepeup_.nup==0)
00343     {
00344     edm::LogInfo("Generator|MadGraph")<<
00345     "The interface signalled end of Les Houches file. Apparently, firstEvent setting is greater than the number of LHE events. Finishing event processing here.";
00346     return false; // finish event processing if variable nup from common block HEPEUP set to 0 in ME2Pythia.f
00347     }
00348   }
00349     
00350   call_pyevnt();      // generate one event with Pythia
00351 
00352   if(hepeup_.nup==0){
00353     edm::LogInfo("Generator|MadGraph")<<"The interface signalled end of Les Houches file. Finishing event processing here.";
00354     return false; // finish event processing if variable nup from common block HEPEUP set to 0 in ME2Pythia.f
00355   }
00356 
00357     if ( useTauola_ ) {
00358       tauola_.processEvent();
00359       //call_pretauola(0); // generate tau decays with TAUOLA
00360     }
00361 
00362   call_pyhepc( 1 );
00363 
00364   if(produceEventTreeFile_) eventtree_(); // write out an event tree file
00365 
00366   HepMC::IO_HEPEVT conv;
00367   HepMC::GenEvent* evt = conv.read_next_event();
00368   evt->set_signal_process_id(pypars.msti[0]);
00369   evt->set_event_number(numberEventsInRun() - remainingEvents() - 1);
00370 
00371   // store PDF information
00372   int id_1 = pypars.msti[14];
00373   int id_2 = pypars.msti[15];
00374   if (id_1 == 21) id_1 = 0;
00375   if (id_2 == 21) id_2 = 0;
00376   pdf_info->set_id1(id_1);
00377   pdf_info->set_id2(id_2);
00378   pdf_info->set_x1(pypars.pari[32]);
00379   pdf_info->set_x2(pypars.pari[33]);
00380   pdf_info->set_scalePDF(pypars.pari[20]);
00381   pdf_info->set_pdf1(pypars.pari[28]);
00382   pdf_info->set_pdf2(pypars.pari[29]);
00383   evt->set_pdf_info( *pdf_info);
00384 
00385 
00386   if(event() <= maxEventsToPrint_ && (pythiaPylistVerbosity_ || pythiaHepMCVerbosity_)) {
00387     // Prints PYLIST info
00388     if(pythiaPylistVerbosity_) {
00389       call_pylist(pythiaPylistVerbosity_);
00390     }
00391     // Prints HepMC event
00392     if(pythiaHepMCVerbosity_) {
00393       edm::LogInfo("Generator|MadGraph")<<"Event process = " << pypars.msti[0];
00394       evt->print();
00395     }
00396   }
00397 
00398 /*
00399   if(hepeup_.nup==0){
00400     edm::LogInfo("Generator|MadGraph")<<"The interface signalled end of Les Houches file. Finishing event processing here.";
00401     return false; // finish event processing if variable nup from common block HEPEUP set to 0 in ME2Pythia.f
00402   }
00403 */
00404   if(evt)  bare_product->addHepMCData(evt );
00405   e.put(bare_product);
00406   return true;
00407 }


Member Data Documentation

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

Definition at line 47 of file MadGraphSource.h.

Referenced by produce().

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

Definition at line 61 of file MadGraphSource.h.

Referenced by MadGraphSource(), and produce().

bool edm::MadGraphSource::getInputFromMCDB_ [private]

Get input file from LCG MCDB.

Definition at line 58 of file MadGraphSource.h.

Referenced by MadGraphSource().

unsigned int edm::MadGraphSource::lhe_event_counter_ [private]

Definition at line 62 of file MadGraphSource.h.

Referenced by produce().

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

Events to print if verbosity.

Definition at line 54 of file MadGraphSource.h.

Referenced by MadGraphSource(), and produce().

int edm::MadGraphSource::MCDBArticleID_ [private]

Sets the MCDB Article ID (0 if none).

Definition at line 60 of file MadGraphSource.h.

Referenced by MadGraphSource().

double edm::MadGraphSource::MEMAIN_etaclmax [private]

Definition at line 64 of file MadGraphSource.h.

Referenced by MadGraphSource().

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

Definition at line 66 of file MadGraphSource.h.

Referenced by MadGraphSource().

int edm::MadGraphSource::MEMAIN_maxjets [private]

Definition at line 67 of file MadGraphSource.h.

Referenced by MadGraphSource().

double edm::MadGraphSource::MEMAIN_qcut [private]

Definition at line 65 of file MadGraphSource.h.

Referenced by MadGraphSource().

std::string edm::MadGraphSource::MGfile_ [private]

Name of file which contains the unweighted MadGraph events.

Definition at line 56 of file MadGraphSource.h.

Referenced by MadGraphSource().

bool edm::MadGraphSource::minimalLH_ [private]

Definition at line 70 of file MadGraphSource.h.

Referenced by MadGraphSource().

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

Definition at line 48 of file MadGraphSource.h.

Referenced by MadGraphSource(), produce(), and ~MadGraphSource().

bool edm::MadGraphSource::produceEventTreeFile_ [private]

Definition at line 68 of file MadGraphSource.h.

Referenced by produce().

bool edm::MadGraphSource::pythiaHepMCVerbosity_ [private]

HepMC verbosity flag.

Definition at line 52 of file MadGraphSource.h.

Referenced by MadGraphSource(), and produce().

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

Pythia PYLIST Verbosity flag.

Definition at line 50 of file MadGraphSource.h.

Referenced by MadGraphSource(), and produce().

TauolaInterface edm::MadGraphSource::tauola_ [private]

Definition at line 76 of file MadGraphSource.h.

Referenced by endRun(), MadGraphSource(), and produce().

bool edm::MadGraphSource::useExternalGenerators_ [private]

Definition at line 73 of file MadGraphSource.h.

Referenced by MadGraphSource().

bool edm::MadGraphSource::useTauola_ [private]

Definition at line 74 of file MadGraphSource.h.

Referenced by endRun(), MadGraphSource(), and produce().

bool edm::MadGraphSource::useTauolaPolarization_ [private]

Definition at line 75 of file MadGraphSource.h.

Referenced by MadGraphSource().


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