CMS 3D CMS Logo

ComphepSource.cc

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

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