CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/GeneratorInterface/ExhumeInterface/src/ExhumeHadronizer.cc

Go to the documentation of this file.
00001 #include "GeneratorInterface/ExhumeInterface/interface/ExhumeHadronizer.h"
00002 
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 
00006 #include "GeneratorInterface/Core/interface/FortranCallback.h"
00007 #include "GeneratorInterface/Core/interface/RNDMEngineAccess.h"
00008 #include "GeneratorInterface/Pythia6Interface/interface/Pythia6Service.h"
00009 
00010 #include "HepPID/ParticleIDTranslations.hh"
00011 
00012 #include "HepMC/GenEvent.h"
00013 #include "HepMC/PdfInfo.h"
00014 #include "HepMC/HEPEVT_Wrapper.h"
00015 #include "HepMC/IO_HEPEVT.h"
00016 
00017 //ExHuME headers
00018 #include "GeneratorInterface/ExhumeInterface/interface/Event.h"
00019 #include "GeneratorInterface/ExhumeInterface/interface/QQ.h"
00020 #include "GeneratorInterface/ExhumeInterface/interface/GG.h"
00021 #include "GeneratorInterface/ExhumeInterface/interface/Higgs.h"
00022 #include "GeneratorInterface/ExhumeInterface/interface/DiPhoton.h"
00023 
00024 #include <string>
00025 #include <sstream>
00026 
00027 HepMC::IO_HEPEVT conv;
00028 
00029 namespace gen
00030 {
00031 extern "C" {
00032 extern struct {
00033    int mstu[200];
00034    double paru[200];
00035    int mstj[200];
00036    double parj[200];
00037 } pydat1_;
00038 #define pydat1 pydat1_
00039 
00040 extern struct {
00041    int mstp[200];
00042    double parp[200];
00043    int msti[200];
00044    double pari[200];
00045 } pypars_;
00046 #define pypars pypars_
00047 
00048 extern struct {
00049    int mint[400];
00050    double vint[400];
00051 } pyint1_;
00052 #define pyint1 pyint1_
00053 }
00054 
00055 extern "C" {
00056    void pylist_(int*);
00057    int  pycomp_(int&);
00058    void pygive_(const char*, int);
00059 }
00060 #define pylist pylist_
00061 #define pycomp pycomp_
00062 #define pygive pygive_
00063 
00064 inline void call_pylist( int mode ){ pylist( &mode ); } 
00065 inline bool call_pygive(const std::string &line)
00066 {
00067    int numWarn = pydat1.mstu[26];    // # warnings
00068    int numErr = pydat1.mstu[22];     // # errors
00069 
00070    pygive(line.c_str(), line.length());
00071 
00072    return (pydat1.mstu[26] == numWarn)&&(pydat1.mstu[22] == numErr);
00073 } 
00074  
00075 ExhumeHadronizer::ExhumeHadronizer(edm::ParameterSet const& pset)
00076    : BaseHadronizer(pset),
00077      pythia6Service_(new Pythia6Service(pset)),
00078      randomEngine_(&getEngineReference()),
00079      comEnergy_(pset.getParameter<double>("comEnergy")),
00080      myPSet_(pset),
00081      hepMCVerbosity_(pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false)),
00082      maxEventsToPrint_(pset.getUntrackedParameter<int>("maxEventsToPrint", 0)),
00083      pythiaListVerbosity_(pset.getUntrackedParameter<int>("pythiaPylistVerbosity", 0))
00084 { 
00085 
00086    convertToPDG_ = false;
00087    if ( pset.exists( "doPDGConvert" ) )
00088    {
00089       convertToPDG_ = pset.getParameter<bool>("doPDGConvert");
00090    }
00091    
00092    //pythia6Hadronizer_ = new Pythia6Hadronizer(pset);  
00093 }
00094 
00095 ExhumeHadronizer::~ExhumeHadronizer(){
00096    //delete pythia6Hadronizer_;
00097    delete pythia6Service_;
00098    delete exhumeEvent_;
00099    delete exhumeProcess_;
00100 }
00101 
00102 void ExhumeHadronizer::finalizeEvent()
00103 {
00104    //pythia6Hadronizer_->finalizeEvent();
00105 
00106    event()->set_signal_process_id( pypars.msti[0] );
00107    event()->set_event_scale( pypars.pari[16] );
00108 
00109    HepMC::PdfInfo pdf;
00110    pdf.set_id1( pyint1.mint[14] == 21 ? 0 : pyint1.mint[14] );
00111    pdf.set_id2( pyint1.mint[15] == 21 ? 0 : pyint1.mint[15] );
00112    pdf.set_x1( pyint1.vint[40] );
00113    pdf.set_x2( pyint1.vint[41] );
00114    pdf.set_pdf1( pyint1.vint[38] / pyint1.vint[40] );
00115    pdf.set_pdf2( pyint1.vint[39] / pyint1.vint[41] );
00116    pdf.set_scalePDF( pyint1.vint[50] );
00117 
00118    event()->set_pdf_info( pdf ) ;
00119 
00120    event()->weights().push_back( pyint1.vint[96] );
00121 
00122    // convert particle IDs Py6->PDG, if requested
00123    if(convertToPDG_) {
00124       for ( HepMC::GenEvent::particle_iterator part = event()->particles_begin(); 
00125                                                part != event()->particles_end(); ++part) {
00126          (*part)->set_pdg_id(HepPID::translatePythiatoPDT((*part)->pdg_id()));
00127       }
00128    }
00129 
00130    // service printouts, if requested
00131    //
00132    if (maxEventsToPrint_ > 0) 
00133    {
00134       --maxEventsToPrint_;
00135       if (pythiaListVerbosity_) call_pylist(pythiaListVerbosity_);
00136       if (hepMCVerbosity_) 
00137       {
00138          std::cout << "Event process = " << pypars.msti[0] << std::endl 
00139               << "----------------------" << std::endl;
00140          event()->print();
00141       }
00142    }
00143 
00144    return;
00145 }
00146 
00147 bool ExhumeHadronizer::generatePartonsAndHadronize()
00148 {
00149    Pythia6Service::InstanceWrapper guard(pythia6Service_);
00150 
00151    FortranCallback::getInstance()->resetIterationsPerEvent();
00152    
00153    // generate event
00154    
00155    exhumeEvent_->Generate();
00156    exhumeProcess_->Hadronise();
00157 
00158    event().reset( conv.read_next_event() );
00159    
00160    return true;
00161 }
00162 
00163 bool ExhumeHadronizer::hadronize()
00164 {
00165    return false;
00166 }
00167 
00168 bool ExhumeHadronizer::decay()
00169 {
00170    return true;
00171 }
00172 
00173 bool ExhumeHadronizer::residualDecay()
00174 {
00175    return true;
00176 }
00177 
00178 bool ExhumeHadronizer::initializeForExternalPartons()
00179 {
00180    return false;
00181 }
00182 
00183 bool ExhumeHadronizer::initializeForInternalPartons()
00184 {
00185    Pythia6Service::InstanceWrapper guard(pythia6Service_);
00186 
00187    pythia6Service_->setGeneralParams();
00188  
00189    //Exhume Initialization
00190    edm::ParameterSet processPSet = myPSet_.getParameter<edm::ParameterSet>("ExhumeProcess");
00191    std::string processType = processPSet.getParameter<std::string>("ProcessType");
00192    int sigID = -1;
00193    if(processType == "Higgs"){
00194       exhumeProcess_ = new Exhume::Higgs(myPSet_);
00195       int higgsDecay = processPSet.getParameter<int>("HiggsDecay");
00196       (static_cast<Exhume::Higgs*>(exhumeProcess_))->SetHiggsDecay(higgsDecay);
00197       sigID = 100 + higgsDecay;
00198    } else if(processType == "QQ"){      
00199       exhumeProcess_ = new Exhume::QQ(myPSet_);
00200       int quarkType = processPSet.getParameter<int>("QuarkType");
00201       double thetaMin = processPSet.getParameter<double>("ThetaMin");
00202       ((Exhume::QQ*)exhumeProcess_)->SetQuarkType(quarkType);
00203       (static_cast<Exhume::QQ*>(exhumeProcess_))->SetThetaMin(thetaMin);
00204       sigID = 200 + quarkType;
00205    } else if(processType == "GG"){
00206       exhumeProcess_ = new Exhume::GG(myPSet_);
00207       double thetaMin = processPSet.getParameter<double>("ThetaMin");
00208       (static_cast<Exhume::GG*>(exhumeProcess_))->SetThetaMin(thetaMin);
00209       sigID = 300;
00210    } else if(processType == "DiPhoton"){
00211       exhumeProcess_ = new Exhume::DiPhoton(myPSet_);
00212       double thetaMin = processPSet.getParameter<double>("ThetaMin");
00213       (static_cast<Exhume::DiPhoton*>(exhumeProcess_))->SetThetaMin(thetaMin);
00214       sigID = 400;
00215    } else{
00216       sigID = -1;
00217       throw edm::Exception(edm::errors::Configuration,"ExhumeError") <<" No valid Exhume Process";
00218    }
00219     
00220    pypars.msti[0] = sigID;
00221    //exhumeEvent_ = new Exhume::Event(*exhumeProcess_,&getEngineReference());
00222    exhumeEvent_ = new Exhume::Event(*exhumeProcess_,randomEngine_);
00223 
00224    double massRangeLow = processPSet.getParameter<double>("MassRangeLow");
00225    double massRangeHigh = processPSet.getParameter<double>("MassRangeHigh");
00226    exhumeEvent_->SetMassRange(massRangeLow,massRangeHigh);
00227    exhumeEvent_->SetParameterSpace();
00228 
00229    return true;
00230 }
00231 
00232 bool ExhumeHadronizer::declareStableParticles( std::vector<int> pdg )
00233 {
00234    //return pythia6Hadronizer_->declareStableParticles(pdg);
00235 
00236    for ( size_t i=0; i < pdg.size(); i++ )
00237    {
00238       int pyCode = pycomp( pdg[i] );
00239       std::ostringstream pyCard ;
00240       pyCard << "MDCY(" << pyCode << ",1)=0";
00241       std::cout << pyCard.str() << std::endl;
00242       call_pygive( pyCard.str() );
00243    }
00244    
00245    return true;
00246 
00247 }
00248 
00249 bool ExhumeHadronizer::declareSpecialSettings( const std::vector<std::string> )
00250 {
00251    return true;
00252 }
00253 
00254 void ExhumeHadronizer::statistics()
00255 {
00256   std::ostringstream footer_str;
00257 
00258   double cs = exhumeEvent_->CrossSectionCalculation();
00259   double eff = exhumeEvent_->GetEfficiency();
00260   std::string name = exhumeProcess_->GetName();
00261 
00262   footer_str << "\n" <<"   You have just been ExHuMEd." << "\n" << "\n";
00263   footer_str << "   The cross section for process " << name
00264              << " is " << cs << " fb" << "\n" << "\n";
00265   footer_str << "   The efficiency of event generation was " << eff << "%" << "\n" << "\n";
00266 
00267   edm::LogInfo("") << footer_str.str();
00268 
00269   if ( !runInfo().internalXSec() )
00270   {
00271      runInfo().setInternalXSec( cs );
00272   }
00273 
00274   return;
00275 }
00276 
00277 const char* ExhumeHadronizer::classname() const
00278 {
00279    return "gen::ExhumeHadronizer";
00280 }
00281 
00282 } // namespace gen