CMS 3D CMS Logo

ToprexSource.cc

Go to the documentation of this file.
00001 /*
00002  *  $Date: 2008/04/10 13:00:08 $
00003  *  $Revision: 1.5 $
00004  *  
00005  *  Filip Moorgat & Hector Naves 
00006  *  26/10/05
00007  * 
00008  *  Patrick Janot : added the PYTHIA card reading
00009  *
00010  *  Serge Slabospitsky : added TopRex interface
00011  */
00012 
00013 
00014 #include "GeneratorInterface/TopRexInterface/interface/ToprexSource.h"
00015 #include "GeneratorInterface/TopRexInterface/interface/PYR.h"
00016 #include "GeneratorInterface/CommonInterface/interface/FindJets.h"
00017 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00018 #include "FWCore/Framework/interface/Event.h"
00019 #include "FWCore/ServiceRegistry/interface/Service.h"
00020 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00021 
00022 #include <iostream>
00023 #include "time.h"
00024 
00025 using namespace edm;
00026 using namespace std;
00027 
00028 // Generator modifications
00029 // ***********************
00030 #include "HepMC/PythiaWrapper6_2.h"
00031 #include "HepMC/IO_HEPEVT.h"
00032 #include "GeneratorInterface/TopRexInterface/interface/ToprexWrapper.h"
00033 //#include "GeneratorInterface/CommonInterface/interface/PretauolaWrapper.h"
00034 //#include "CLHEP/HepMC/CBhepevt.h"
00035 
00036 
00037 #include "GeneratorInterface/CommonInterface/interface/PythiaCMS.h"
00038 #include "GeneratorInterface/CommonInterface/interface/Txgive.h"
00039 
00040 
00041 HepMC::IO_HEPEVT conv;
00042 // ***********************
00043 
00044 
00045 //used for defaults
00046   static const unsigned long kNanoSecPerSec = 1000000000;
00047   static const unsigned long kAveEventPerSec = 200;
00048 
00049 ToprexSource::ToprexSource( const ParameterSet & pset, 
00050                             InputSourceDescription const& desc ) :
00051   GeneratedInputSource(pset, desc), evt(0), 
00052   pythiaPylistVerbosity_ (pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0)),
00053   pythiaHepMCVerbosity_ (pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false)),
00054   maxEventsToPrint_ (pset.getUntrackedParameter<int>("maxEventsToPrint",1))
00055   
00056 {
00057   
00058   cout << "ToprexSource: initializing TopReX " << endl;
00059   
00060  
00061   
00062   // PYLIST Verbosity Level
00063   // Valid PYLIST arguments are: 1, 2, 3, 5, 7, 11, 12, 13
00064   pythiaPylistVerbosity_ = pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0);
00065   cout << "Pythia PYLIST verbosity level = " << pythiaPylistVerbosity_ << endl;
00066   
00067   // HepMC event verbosity Level
00068   pythiaHepMCVerbosity_ = pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false);
00069   cout << "Pythia HepMC verbosity = " << pythiaHepMCVerbosity_ << endl; 
00070 
00071   //Max number of events printed on verbosity level 
00072   maxEventsToPrint_ = pset.getUntrackedParameter<int>("maxEventsToPrint",0);
00073   cout << "Number of events to be printed = " << maxEventsToPrint_ << endl;
00074 
00076   // Set PYTHIA parameters in a single ParameterSet
00077   {
00078   ParameterSet pythia_params = 
00079     pset.getParameter<ParameterSet>("PythiaParameters") ;
00080   
00081   // The parameter sets to be read (default, min bias, user ...) in the
00082   // proper order.
00083   vector<string> setNames = 
00084     pythia_params.getParameter<vector<string> >("parameterSets");
00085   
00086   // Loop over the sets
00087   for ( unsigned i=0; i<setNames.size(); ++i ) {
00088     
00089     string mySet = setNames[i];
00090     
00091     // Read the PYTHIA parameters for each set of parameters
00092     vector<string> pars = 
00093       pythia_params.getParameter<vector<string> >(mySet);
00094     
00095     if (mySet != "CSAParameters"){
00096     cout << "----------------------------------------------" << endl;
00097     cout << "Read PYTHIA parameter set " << mySet << endl;
00098     cout << "----------------------------------------------" << endl;
00099     
00100     // Loop over all parameters and stop in case of mistake
00101     for( vector<string>::const_iterator  
00102            itPar = pars.begin(); itPar != pars.end(); ++itPar ) {
00103       static string sRandomValueSetting("MRPY(1)");
00104       if( 0 == itPar->compare(0,sRandomValueSetting.size(),sRandomValueSetting) ) {
00105         throw edm::Exception(edm::errors::Configuration,"PythiaError")
00106           <<" 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.";
00107       }
00108       if( ! call_pygive(*itPar) ) {
00109         throw edm::Exception(edm::errors::Configuration,"PythiaError") 
00110           <<" pythia did not accept the following \""<<*itPar<<"\"";
00111       }
00112     }
00113     }else if(mySet == "CSAParameters"){   
00114 
00115    // Read CSA parameter
00116   
00117    pars = pythia_params.getParameter<vector<string> >("CSAParameters");
00118 
00119    cout << "----------------------------------------------" << endl; 
00120    cout << "Reading CSA parameter settings. " << endl;
00121    cout << "----------------------------------------------" << endl;                                                                           
00122 
00123     call_txgive_init();
00124   
00125   
00126    // Loop over all parameters and stop in case of a mistake
00127     for (vector<string>::const_iterator 
00128             itPar = pars.begin(); itPar != pars.end(); ++itPar) {
00129       call_txgive(*itPar); 
00130      
00131          } 
00132   
00133   }
00134   }
00135 
00136 }
00137 
00138 
00139 // Read the TopReX parameters
00140 
00141 
00142   //In the future, we will get the random number seed on each event and tell 
00143   // pythia to use that new seed
00144     cout << "----------------------------------------------" << endl;
00145     cout << "Setting Pythia random number seed " << endl;
00146     cout << "----------------------------------------------" << endl;
00147   edm::Service<RandomNumberGenerator> rng;
00148   randomEngine = fRandomEngine = &(rng->getEngine());
00149   uint32_t seed = rng->mySeed();
00150   ostringstream sRandomSet;
00151   sRandomSet <<"MRPY(1)="<<seed;
00152   call_pygive(sRandomSet.str());
00153 
00154  // srs insertion
00155   //  cout << "TopReX start called OK" << endl;
00156   call_toprex( "USER", "p", "p", 14000. );
00157   // cout << "TopReX was called OK" << endl;
00158   call_pyinit( "USER", "p", "p", 14000. );
00159   //
00160   //     call_pretauola(-1);     // TAUOLA initialization
00161   cout << endl; // Stetically add for the output
00162 
00163   produces<HepMCProduct>();
00164   cout << "ToprexSource: starting event generation ... " << endl;
00165 }
00166 
00167 
00168 ToprexSource::~ToprexSource(){
00169   cout << "ToprexSource: event generation done. " << endl;
00170   call_pystat(1);
00171   //    call_pretauola(1);  // output from TAUOLA 
00172   clear(); 
00173 }
00174 
00175 void ToprexSource::clear() { }
00176 
00177 
00178 bool ToprexSource::produce(Event & e) {
00179 
00180     auto_ptr<HepMCProduct> bare_product(new HepMCProduct());  
00181      //
00182 
00183     call_pyevnt();      // generate one event with Pythia
00184 
00185     //        call_pretauola(0);       // tau-lepton decays with TAUOLA 
00186 
00187     call_findjets();      // find jets 
00188     call_pyhepc( 1 );
00189     
00190     HepMC::GenEvent* evt = conv.read_next_event();
00191     evt->set_signal_process_id(pypars.msti[0]);
00192     evt->set_event_scale(pypars.pari[16]);
00193     evt->set_event_number(numberEventsInRun() - remainingEvents() - 1);
00194 
00195     //    Nest (*evt);
00196 
00197 
00198 
00199 
00200     //******** Verbosity ********
00201     
00202     if(event() <= maxEventsToPrint_ &&
00203        (pythiaPylistVerbosity_ || pythiaHepMCVerbosity_)) {
00204 
00205       // Prints PYLIST info
00206       if(pythiaPylistVerbosity_) {
00207         call_pylist(pythiaPylistVerbosity_);
00208       }
00209       
00210       // Prints HepMC event
00211       if(pythiaHepMCVerbosity_) {
00212         cout << "Event process = " << pypars.msti[0] << endl 
00213         << "----------------------" << endl;
00214         //      evt->print();
00215       }
00216     }
00217     
00218     
00219     //evt = reader_->fillCurrentEventData(); 
00220     //********                                      
00221 
00222     if(evt)  bare_product->addHepMCData(evt );
00223 
00224     e.put(bare_product);
00225 
00226     return true;
00227 }
00228 
00229 bool 
00230 ToprexSource::call_pygive(const std::string& iParm ) 
00231 {
00232    int numWarn = pydat1.mstu[26]; //# warnings
00233    int numErr = pydat1.mstu[22];// # errors
00234 //call the fortran routine pygive with a fortran string
00235   PYGIVE( iParm.c_str(), iParm.length() );  
00236 //if an error or warning happens it is problem
00237    return pydat1.mstu[26] == numWarn && pydat1.mstu[22] == numErr;   
00238 }
00239 
00240 //------------
00241 bool 
00242 ToprexSource::call_txgive(const std::string& iParm ) 
00243    {
00244    TXGIVE( iParm.c_str(), iParm.length() );  
00245         return 1;  
00246    }
00247 
00248 bool
00249 ToprexSource::call_txgive_init() 
00250 {
00251    TXGIVE_INIT();
00252    cout << "  Setting CSA defaults.   "   << endl;
00253    return 1;
00254 }

Generated on Tue Jun 9 17:37:10 2009 for CMSSW by  doxygen 1.5.4