CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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::readSettings( int )
00184 {
00185 
00186    Pythia6Service::InstanceWrapper guard(pythia6Service_);
00187 
00188    pythia6Service_->setGeneralParams();
00189 
00190    return true;
00191 
00192 }
00193 
00194 bool ExhumeHadronizer::initializeForInternalPartons()
00195 {
00196    Pythia6Service::InstanceWrapper guard(pythia6Service_);
00197 
00198    // pythia6Service_->setGeneralParams();
00199  
00200    //Exhume Initialization
00201    edm::ParameterSet processPSet = myPSet_.getParameter<edm::ParameterSet>("ExhumeProcess");
00202    std::string processType = processPSet.getParameter<std::string>("ProcessType");
00203    int sigID = -1;
00204    if(processType == "Higgs"){
00205       exhumeProcess_ = new Exhume::Higgs(myPSet_);
00206       int higgsDecay = processPSet.getParameter<int>("HiggsDecay");
00207       (static_cast<Exhume::Higgs*>(exhumeProcess_))->SetHiggsDecay(higgsDecay);
00208       sigID = 100 + higgsDecay;
00209    } else if(processType == "QQ"){      
00210       exhumeProcess_ = new Exhume::QQ(myPSet_);
00211       int quarkType = processPSet.getParameter<int>("QuarkType");
00212       double thetaMin = processPSet.getParameter<double>("ThetaMin");
00213       ((Exhume::QQ*)exhumeProcess_)->SetQuarkType(quarkType);
00214       (static_cast<Exhume::QQ*>(exhumeProcess_))->SetThetaMin(thetaMin);
00215       sigID = 200 + quarkType;
00216    } else if(processType == "GG"){
00217       exhumeProcess_ = new Exhume::GG(myPSet_);
00218       double thetaMin = processPSet.getParameter<double>("ThetaMin");
00219       (static_cast<Exhume::GG*>(exhumeProcess_))->SetThetaMin(thetaMin);
00220       sigID = 300;
00221    } else if(processType == "DiPhoton"){
00222       exhumeProcess_ = new Exhume::DiPhoton(myPSet_);
00223       double thetaMin = processPSet.getParameter<double>("ThetaMin");
00224       (static_cast<Exhume::DiPhoton*>(exhumeProcess_))->SetThetaMin(thetaMin);
00225       sigID = 400;
00226    } else{
00227       sigID = -1;
00228       throw edm::Exception(edm::errors::Configuration,"ExhumeError") <<" No valid Exhume Process";
00229    }
00230     
00231    pypars.msti[0] = sigID;
00232    //exhumeEvent_ = new Exhume::Event(*exhumeProcess_,&getEngineReference());
00233    exhumeEvent_ = new Exhume::Event(*exhumeProcess_,randomEngine_);
00234 
00235    double massRangeLow = processPSet.getParameter<double>("MassRangeLow");
00236    double massRangeHigh = processPSet.getParameter<double>("MassRangeHigh");
00237    exhumeEvent_->SetMassRange(massRangeLow,massRangeHigh);
00238    exhumeEvent_->SetParameterSpace();
00239 
00240    return true;
00241 }
00242 
00243 bool ExhumeHadronizer::declareStableParticles(const std::vector<int>& _pdg )
00244 {
00245    std::vector<int> pdg = _pdg;
00246    //return pythia6Hadronizer_->declareStableParticles(pdg);
00247 
00248    for ( size_t i=0; i < pdg.size(); i++ )
00249    {
00250       int pyCode = pycomp( pdg[i] );
00251       std::ostringstream pyCard ;
00252       pyCard << "MDCY(" << pyCode << ",1)=0";
00253       std::cout << pyCard.str() << std::endl;
00254       call_pygive( pyCard.str() );
00255    }
00256    
00257    return true;
00258 
00259 }
00260 
00261 bool ExhumeHadronizer::declareSpecialSettings( const std::vector<std::string>& )
00262 {
00263    return true;
00264 }
00265 
00266 void ExhumeHadronizer::statistics()
00267 {
00268   std::ostringstream footer_str;
00269 
00270   double cs = exhumeEvent_->CrossSectionCalculation();
00271   double eff = exhumeEvent_->GetEfficiency();
00272   std::string name = exhumeProcess_->GetName();
00273 
00274   footer_str << "\n" <<"   You have just been ExHuMEd." << "\n" << "\n";
00275   footer_str << "   The cross section for process " << name
00276              << " is " << cs << " fb" << "\n" << "\n";
00277   footer_str << "   The efficiency of event generation was " << eff << "%" << "\n" << "\n";
00278 
00279   edm::LogInfo("") << footer_str.str();
00280 
00281   if ( !runInfo().internalXSec() )
00282   {
00283      runInfo().setInternalXSec( cs );
00284   }
00285 
00286   return;
00287 }
00288 
00289 const char* ExhumeHadronizer::classname() const
00290 {
00291    return "gen::ExhumeHadronizer";
00292 }
00293 
00294 } // namespace gen