CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/GeneratorInterface/ExhumeInterface/plugins/ExhumeProducer.cc

Go to the documentation of this file.
00001 #include "ExhumeProducer.h"
00002 #include "PYR.h"
00003 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00004 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
00005 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
00006 
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "FWCore/Framework/interface/Run.h"
00010 #include "FWCore/Framework/interface/MakerMacros.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00014 #include "Utilities/General/interface/FileInPath.h"
00015 
00016 #include "CLHEP/Random/RandomEngine.h"
00017 #include "CLHEP/Random/RandFlat.h"
00018 
00019 //ExHuME headers
00020 #include "GeneratorInterface/ExhumeInterface/interface/Event.h"
00021 #include "GeneratorInterface/ExhumeInterface/interface/QQ.h"
00022 #include "GeneratorInterface/ExhumeInterface/interface/GG.h"
00023 #include "GeneratorInterface/ExhumeInterface/interface/Higgs.h"
00024 
00025 #include <iostream>
00026 #include "time.h"
00027 
00028 using namespace edm;
00029 using namespace std;
00030 
00031 
00032 // Generator modifications
00033 // ***********************
00034 //#include "HepMC/include/PythiaWrapper6_2.h"
00035 //#include "HepMC/ConvertHEPEVT.h"
00036 //#include "HepMC/CBhepevt.h"
00037 #include "HepMC/IO_HEPEVT.h"
00038 
00039 #define pylist pylist_
00040 extern "C" {
00041         void pylist(int*);
00042 }
00043 inline void call_pylist( int mode ){ pylist( &mode ); }
00044 
00045 /*
00046 #define my_pythia_init my_pythia_init_
00047 extern "C" {
00048         void my_pythia_init();
00049 }
00050 #define pydata pydata_
00051 extern "C" {
00052     void pydata(void);
00053 }
00054 */
00055 extern struct {
00056         int mstp[200];
00057         double parp[200];
00058         int msti[200];
00059         double pari[200];
00060 } pypars_;
00061 #define pypars pypars_
00062 
00063 //HepMC::ConvertHEPEVT conv;
00064 HepMC::IO_HEPEVT conv;
00065 
00066 // ***********************
00067 
00068 
00069 //used for defaults
00070   static const unsigned long kNanoSecPerSec = 1000000000;
00071   static const unsigned long kAveEventPerSec = 200;
00072 
00073 ExhumeProducer::ExhumeProducer( const ParameterSet & pset) :
00074   EDProducer(),
00075   evt(0), 
00076   pythiaPylistVerbosity_ (pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0)),
00077   pythiaHepMCVerbosity_ (pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false)),
00078   maxEventsToPrint_ (pset.getUntrackedParameter<int>("maxEventsToPrint",1)),
00079   comEnergy_(pset.getParameter<double>("comEnergy")),
00080   extCrossSect_(pset.getUntrackedParameter<double>("crossSection", -1.)),
00081   extFilterEff_(pset.getUntrackedParameter<double>("filterEfficiency", -1.)),
00082   eventNumber_(0)
00083 {
00084   std::ostringstream header_str;
00085 
00086   header_str << "ExhumeProducer: initializing Exhume/Pythia.\n";
00087   
00088   // PYLIST Verbosity Level
00089   // Valid PYLIST arguments are: 1, 2, 3, 5, 7, 11, 12, 13
00090   pythiaPylistVerbosity_ = pset.getUntrackedParameter<int>("pythiaPylistVerbosity",0);
00091   header_str << "Pythia PYLIST verbosity level = " << pythiaPylistVerbosity_ << "\n";
00092   
00093   // HepMC event verbosity Level
00094   pythiaHepMCVerbosity_ = pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false);
00095   header_str << "Pythia HepMC verbosity = " << pythiaHepMCVerbosity_ << "\n"; 
00096 
00097   //Max number of events printed on verbosity level 
00098   maxEventsToPrint_ = pset.getUntrackedParameter<int>("maxEventsToPrint",0);
00099   header_str << "Number of events to be printed = " << maxEventsToPrint_ << "\n";
00100 
00101   //Exhume Initialization
00102   ParameterSet process_pset = pset.getParameter<ParameterSet>("ExhumeProcess") ;
00103   string processType = process_pset.getParameter<string>("ProcessType");
00104   if(processType == "Higgs"){
00105         exhumeProcess_ = new Exhume::Higgs(pset);
00106         int higgsDecay = process_pset.getParameter<int>("HiggsDecay");
00107         ((Exhume::Higgs*)exhumeProcess_)->SetHiggsDecay(higgsDecay);
00108         sigID_ = 100 + higgsDecay;
00109   } else if(processType == "QQ"){       
00110         exhumeProcess_ = new Exhume::QQ(pset);
00111         int quarkType = process_pset.getParameter<int>("QuarkType");
00112         double thetaMin = process_pset.getParameter<double>("ThetaMin");
00113         ((Exhume::QQ*)exhumeProcess_)->SetQuarkType(quarkType);
00114         ((Exhume::QQ*)exhumeProcess_)->SetThetaMin(thetaMin);
00115         sigID_ = 200 + quarkType;
00116   } else if(processType == "GG"){
00117         exhumeProcess_ = new Exhume::GG(pset);
00118         double thetaMin = process_pset.getParameter<double>("ThetaMin");
00119         ((Exhume::GG*)exhumeProcess_)->SetThetaMin(thetaMin);
00120         sigID_ = 300;
00121   } else{
00122         sigID_ = -1;
00123         throw edm::Exception(edm::errors::Configuration,"ExhumeError") <<" No valid Exhume Process";
00124   }
00125 
00126   edm::Service<RandomNumberGenerator> rng;
00127   //uint32_t seed = rng->mySeed();
00128   fRandomEngine = &(rng->getEngine());
00129   randomEngine = fRandomEngine;
00130   fRandomGenerator = new CLHEP::RandFlat(fRandomEngine) ;
00131   //exhumeEvent_ = new Exhume::Event(*exhumeProcess_,seed);
00132   exhumeEvent_ = new Exhume::Event(*exhumeProcess_,randomEngine);
00133 
00134   double massRangeLow = process_pset.getParameter<double>("MassRangeLow");
00135   double massRangeHigh = process_pset.getParameter<double>("MassRangeHigh");
00136   exhumeEvent_->SetMassRange(massRangeLow,massRangeHigh);
00137   exhumeEvent_->SetParameterSpace();
00138 
00139   header_str << "\n"; // Stetically add for the output
00140   //********                                      
00141   
00142   produces<HepMCProduct>();
00143   produces<GenEventInfoProduct>();
00144   produces<GenRunInfoProduct, edm::InRun>();
00145 
00146   header_str << "ExhumeProducer: starting event generation ...\n";
00147 
00148   edm::LogInfo("") << header_str.str();
00149 }
00150 
00151 
00152 ExhumeProducer::~ExhumeProducer(){
00153   std::ostringstream footer_str;
00154   footer_str << "ExhumeProducer: event generation done.\n";
00155 
00156   edm::LogInfo("") << footer_str.str();
00157 
00158   clear();
00159 }
00160 
00161 void ExhumeProducer::clear() {
00162   delete exhumeEvent_;
00163   delete exhumeProcess_;
00164 }
00165 
00166 void ExhumeProducer::endRun(Run & run) {
00167   std::ostringstream footer_str;
00168 
00169   double cs = exhumeEvent_->CrossSectionCalculation();
00170   double eff = exhumeEvent_->GetEfficiency();
00171   string name = exhumeProcess_->GetName();
00172 
00173   footer_str << "\n" <<"   You have just been ExHuMEd." << "\n" << "\n";
00174   footer_str << "   The cross section for process " << name
00175             << " is " << cs << " fb" << "\n" << "\n";
00176   footer_str << "   The efficiency of event generation was " << eff << "%" << "\n" << "\n";
00177 
00178   edm::LogInfo("") << footer_str.str();
00179 
00180   auto_ptr<GenRunInfoProduct> genRunInfoProd (new GenRunInfoProduct());
00181   genRunInfoProd->setInternalXSec(cs);
00182   genRunInfoProd->setFilterEfficiency(extFilterEff_);
00183   genRunInfoProd->setExternalXSecLO(extCrossSect_);
00184   genRunInfoProd->setExternalXSecNLO(-1.);   
00185 
00186   run.put(genRunInfoProd);
00187 }
00188 
00189 void ExhumeProducer::produce(Event & event, const EventSetup& setup) {
00190 
00191   auto_ptr<HepMCProduct> bare_product(new HepMCProduct());  
00192   edm::LogInfo("") << "ExhumeProducer: Generating event ...\n";
00193 
00194   exhumeEvent_->Generate();
00195   exhumeProcess_->Hadronise();
00196 
00197   HepMC::GenEvent* genEvt = conv.read_next_event();
00198   genEvt->set_signal_process_id(sigID_);        
00199   genEvt->set_event_scale(pypars.pari[16]);
00200 // JMM change
00201 //  genEvt->set_event_number(numberEventsInRun() - remainingEvents() - 1);
00202   ++eventNumber_;
00203   genEvt->set_event_number(eventNumber_);
00204     
00205   //******** Verbosity ********
00206     
00207 //  if(event() <= maxEventsToPrint_ &&
00208   if(event.id().event() <= maxEventsToPrint_ &&
00209      (pythiaPylistVerbosity_ || pythiaHepMCVerbosity_)) {
00210 
00211     // Prints PYLIST info
00212     if(pythiaPylistVerbosity_) {
00213        call_pylist(pythiaPylistVerbosity_);
00214     }
00215       
00216     // Prints HepMC event
00217     if(pythiaHepMCVerbosity_) {
00218        edm::LogInfo("") << "Event process = " << exhumeProcess_->GetName() << "\n" 
00219                         << "----------------------" << "\n";
00220        genEvt->print();
00221     }
00222   }
00223     
00224   if(genEvt)  bare_product->addHepMCData(genEvt);
00225   event.put(bare_product);
00226  
00227   std::auto_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(genEvt));
00228   event.put(genEventInfo);
00229 }
00230 
00231 DEFINE_FWK_MODULE(ExhumeProducer);