CMS 3D CMS Logo

ComphepProducer.cc

Go to the documentation of this file.
00001 /*
00002  *  $Date: 2008/04/09 14:25:40 $
00003  *  $Revision: 1.1 $
00004  *  
00005  *  Filip Moorgat & Hector Naves 
00006  *  26/10/05
00007  * 
00008  *  Patrick Janot : added the PYTHIA card reading
00009  *
00010  *  Serge SLabospitsky : added Comphep reading tools 
00011  *
00012  *  Hector Naves : added MCDB Interface (25/10/06)
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 // Generator modifications
00032 // ***********************
00033 #include "HepMC/PythiaWrapper6_2.h"
00034 #include "HepMC/IO_HEPEVT.h"
00035 #include "GeneratorInterface/ComphepInterface/interface/ComphepWrapper.h"
00036 //#include "GeneratorInterface/CommonInterface/interface/PretauolaWrapper.h"
00037 
00038 #include "GeneratorInterface/CommonInterface/interface/PythiaCMS.h"
00039 #include "GeneratorInterface/CommonInterface/interface/Txgive.h"
00040 
00041 HepMC::IO_HEPEVT conv2;
00042 // ***********************
00043 
00044 // MCDB Interface
00045 #include "GeneratorInterface/ComphepInterface/interface/MCDBInterface.h"
00046 
00047 //used for defaults
00048   static const unsigned long kNanoSecPerSec = 1000000000;
00049   static const unsigned long kAveEventPerSec = 200;
00050 
00051 // Added 12 March '08 by JMM as part of forcing Pythia to use
00052 // the random number engines from the random service.  The
00053 // remaining question is how to make sure this version of PYR
00054 // is used instead of the one embedded in Pythia.
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   // Interface with the LCG MCDB
00079   //
00080   if (getInputFromMCDB_) {
00081     CHFile_ = pset.getUntrackedParameter<string>("ComphepInputFile");
00082     mcdbGetInputFile(CHFile_, MCDBArticleID_);
00083   }
00084   //  
00085   //******
00086 
00087 
00088   
00089   
00090   // PYLIST Verbosity Level
00091   // Valid PYLIST arguments are: 1, 2, 3, 5, 7, 11, 12, 13
00092   pythiaPylistVerbosity_ = pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0);
00093   
00094   // HepMC event verbosity Level
00095   pythiaHepMCVerbosity_ = pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false);
00096 
00097   //Max number of events printed on verbosity level 
00098   maxEventsToPrint_ = pset.getUntrackedParameter<int>("maxEventsToPrint",0);
00099   
00101   // Set PYTHIA parameters in a single ParameterSet
00102   {
00103   ParameterSet pythia_params = 
00104     pset.getParameter<ParameterSet>("PythiaParameters") ;
00105   
00106   // The parameter sets to be read (default, min bias, user ...) in the
00107   // proper order.
00108   vector<string> setNames = 
00109     pythia_params.getParameter<vector<string> >("parameterSets");
00110   
00111   // Loop over the sets
00112   for ( unsigned i=0; i<setNames.size(); ++i ) {
00113     
00114     string mySet = setNames[i];
00115     
00116     // Read the PYTHIA parameters for each set of parameters
00117     vector<string> pars = 
00118       pythia_params.getParameter<vector<string> >(mySet);
00119     
00120     if (mySet != "CSAParameters"){
00121     
00122     // Loop over all parameters and stop in case of mistake
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    // Read CSA parameter
00138   
00139    pars = pythia_params.getParameter<vector<string> >("CSAParameters");
00140 
00141 
00142     call_txgive_init();
00143   
00144   
00145    // Loop over all parameters and stop in case of a mistake
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  // Read the Comphep parameter
00159 #include "GeneratorInterface/CommonInterface/interface/ExternalGenRead.inc"
00160 
00161 
00162 
00163   //In the future, we will get the random number seed on each event and tell 
00164   // pythia to use that new seed
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   //  call_pretauola(-1);     // TAUOLA initialization
00176 
00177   cout << endl; // Statically add for the output
00178   //********                                      
00179   
00180   produces<HepMCProduct>();
00181 }
00182 
00183 
00184 ComphepProducer::~ComphepProducer(){
00185   call_pystat(1);
00186   //  call_pretauola(1);  // output from TAUOLA 
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();      // generate one event with Pythia
00203     //    call_pretauola(0);  // tau-lepton decays with TAUOLA 
00204 
00205     call_pyhepc( 1 );
00206     
00207     //    HepMC::GenEvent* evt = conv2.getGenEventfromHEPEVT();
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     //******** Verbosity ********
00215     
00216     if(e.id().event() <= maxEventsToPrint_ &&
00217        (pythiaPylistVerbosity_ || pythiaHepMCVerbosity_)) {
00218 
00219       // Prints PYLIST info
00220       if(pythiaPylistVerbosity_) {
00221         call_pylist(pythiaPylistVerbosity_);
00222       }
00223       
00224       // Prints HepMC event
00225       if(pythiaHepMCVerbosity_) {
00226         cout << "Event process = " << pypars.msti[0] << endl 
00227         << "----------------------" << endl;
00228         evt->print();
00229       }
00230     }
00231     
00232     
00233     //evt = reader_->fillCurrentEventData(); 
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]; //# warnings
00245   int numErr = pydat1.mstu[22];// # errors
00246 //call the fortran routine pygive with a fortran string
00247   PYGIVE( iParm.c_str(), iParm.length() );  
00248 //if an error or warning happens it is problem
00249   return pydat1.mstu[26] == numWarn && pydat1.mstu[22] == numErr;   
00250 }
00251 //------------
00252 bool 
00253 ComphepProducer::call_txgive(const std::string& iParm ) 
00254    {
00255     //call the fortran routine txgive with a fortran string
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 }

Generated on Tue Jun 9 17:36:53 2009 for CMSSW by  doxygen 1.5.4