agile is hosted by Hepforge, IPPP Durham

Ariadne.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include "AGILe/Ariadne/Ariadne.hh"
00003 #include "AGILe/Ariadne/AriadneWrapper62.hh"
00004 #include "AGILe/Utils.hh"
00005 #include "AGILe/HepMCTools.hh"
00006 
00007 #include "HepMC/HEPEVT_Wrapper.h"
00008 
00009 namespace AGILe {
00010 
00011   // Author: Andy Buckley/ S.Todorova
00012 
00013 
00015   Ariadne::Ariadne() {
00017     FC_PYJETS.n = 0; //< Ensure dummyness of the next call
00018     call_pyhepc(1);
00019     //HepMC::HEPEVT_Wrapper::set_max_number_entries(4000);
00020     //HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00021     HepMC::HEPEVT_Wrapper::set_max_number_entries(FC_PYDAT1.mstu[8-1]);
00022     //HepMC::HEPEVT_Wrapper::set_max_number_entries(10000);
00023     HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00024 
00025     // Start counting events at 1.
00026     _nevt = 1;
00027 
00028     // Initialize Pythia PYDATA block data as external
00029     FC_INITPYDATA();
00030 
00031     // Write the full shower structure
00032     setParam("MSTP(125)", 2);
00033 
00034     // Tell Pythia not to write multiple copies of particles in event record.
00035     setParam("MSTP(128)", 2);
00036 
00037     // Set up particle names map
00039     _particleNames[ELECTRON]    = "e-";
00040     _particleNames[POSITRON]    = "e+";
00041     _particleNames[PROTON]      = "p+";
00042     _particleNames[ANTIPROTON]  = "pbar-";
00043     _particleNames[NEUTRON]     = "n0";
00044     _particleNames[ANTINEUTRON] = "nbar0";
00045     _particleNames[PHOTON]      = "gamma";
00046     _particleNames[MUON]        = "mu-";
00047     _particleNames[ANTIMUON]    = "mu+";
00048     // TAU, ANTITAU
00049     _particleNames[NU_E]        = "nu_e";
00050     _particleNames[NU_EBAR]     = "nu_ebar";
00051     _particleNames[NU_MU]       = "nu_mu";
00052     _particleNames[NU_MUBAR]    = "nu_mubar";
00053     _particleNames[NU_TAU]      = "nu_tau";
00054     _particleNames[NU_TAUBAR]   = "nu_taubar";
00055     _particleNames[PIPLUS]      = "pi+";
00056     _particleNames[PIMINUS]     = "pi-";
00057     // PIZERO
00058     // PHOTOELECTRON, PHOTOPOSITRON,
00059     // PHOTOMUON,     PHOTOANTIMUON,
00060     // PHOTOTAU,      PHOTOANTITAU,
00067   }
00068 
00069 
00070   void Ariadne::setGenSpecificInitialState(PdgCode p1, double e1, PdgCode p2, double e2) {
00071     getLog() << Log::INFO << "Setting initial state..." << endl;
00072     // For Pythia, we have to hold on to this state until initialize() is called.
00073     _particleName1 = _particleNames[p1];
00074     _particleName2 = _particleNames[p2];
00076     _e1 = e1;
00077     _e2 = e2;
00078   }
00079 
00080 
00082   void Ariadne::initialize() {
00083     Generator::initialize();
00084     // call ariadne tune
00085     call_artune("4.12");
00086     //for (int i=20; i<25; i++) std::cout <<"para("<<i+1<<"):"<<FC_ARDAT1.para[i]<<std::endl;
00087 
00088     // Call pythia initialization with stored parameters as set by setGenSpecificInitialState()
00089     if (FC_PYPARS.mstp[142] != 1) {
00090       if (fuzzyEquals(_e1, _e2)) {
00091         call_pyinit("CMS", _particleName1.c_str(), _particleName2.c_str(), _e1+_e2);
00092       } else {
00093         stringstream p13cmd, p23cmd;
00094         p13cmd << "P(1,3) = " << _e1;
00095         p23cmd << "P(2,3) = " << -_e2;
00096         call_pygive("P(1,1) = 0.0");
00097         call_pygive("P(1,2) = 0.0");
00098         call_pygive(p13cmd.str().c_str());
00099         call_pygive("P(2,1) = 0.0");
00100         call_pygive("P(2,2) = 0.0");
00101         call_pygive(p23cmd.str().c_str());
00102         call_pyinit("3MOM", _particleName1.c_str(), _particleName2.c_str(), 0.0);
00103       }
00104     } else {
00105       // User process, parameters taken from LHAPDF initialisation file.
00106       call_pyinit("USER"," "," ", 0.0);
00107     }
00108 
00109     call_arinit("pythia");
00110 
00111     _initialized = true;
00112 
00113     // std::cout <<"check setup:"<<std::endl;
00114     // std::cout <<"PARA(1)  "<<FC_ARDAT1.para[0]<<std::endl;
00115     // std::cout <<"PARA(3)  "<<FC_ARDAT1.para[2]<<std::endl;
00116     // std::cout <<"PARJ(41)  "<<FC_PYDAT1.parj[40]<<std::endl;
00117     // std::cout <<"PARJ(42)  "<<FC_PYDAT1.parj[41]<<std::endl;
00118 
00119   }
00120 
00121   // Set a parameter with a string value
00122   bool Ariadne::setParam(const string& name, const string& value) {
00123     Generator::setParam(name, value);
00124     if (name.substr(0,4)=="PARA" || name.substr(0,4)=="para" ) {
00125       size_t il = 0; size_t ir = 0;
00126       while (il<name.size() && name.substr(il,1)!="(") il++;
00127       while (ir<name.size() && name.substr(ir,1)!=")") ir++;
00128       if (il>3 && ir>il ) {
00129         const string&  num= name.substr(il+1,ir-il-1);
00130         int ip = std::atoi(num.c_str());
00131         float val = std::atof(value.c_str());
00132         //std::cout <<"old value:"<<FC_ARDAT1.para[ip-1]<<std::endl;
00133         FC_ARDAT1.para[ip-1] = val;
00134         //std::cout <<"new value:"<<FC_ARDAT1.para[ip-1]<<std::endl;
00135         call_ariset(ip,val);
00136         //std::cout <<"ARIADNE: PARA"<<"("<<ip<<") set to "<<value<<std::endl;
00137       }
00138     } else {
00139       const string pygive_input(toUpper(name) + "=" + value);
00140       call_pygive(pygive_input.c_str());
00141     }
00142     return SUCCESS;
00143   }
00144 
00145   // Run the generator for one event
00146   void Ariadne::makeEvent(HepMC::GenEvent& evt) {
00147     Generator::makeEvent(evt);
00149     // Generate one event.
00150     call_pyevnt();
00151     // run Ariadne
00152     call_arexec();
00153     // Generate one event with new UE and shower.
00154     //call_pyevnw();
00155     // Convert common PYJETS into common HEPEVT.
00156     call_pyhepc(1);
00157     // Increment an event counter (Pythia does not count for itself).
00158     _nevt++;
00159     // fill the event using HepMC
00160     fillEvent(evt);
00161     evt.set_event_number(_nevt);
00162   }
00163 
00164 
00165   // Fill a HepMC event
00166   void Ariadne::fillEvent(HepMC::GenEvent& evt) {
00167     _hepevt.fill_next_event(&evt);
00168     fixHepMCUnitsFromGeVmm(evt);
00169     #ifdef HEPMC_HAS_CROSS_SECTION
00170     HepMC::GenCrossSection xsec;
00171     const double xsecval = getCrossSection();
00172     const double xsecerr = getCrossSection() / std::sqrt(FC_PYPARS.msti[4]);
00173     getLog() << Log::DEBUG << "Writing cross-section = " << xsecval << " +- " << xsecerr << endl;
00174     xsec.set_cross_section(xsecval, xsecerr);
00175     evt.set_cross_section(xsec);
00176     #endif
00177   }
00178 
00179 
00180   string Ariadne::getPDFSet(PdgCode pid) {
00181     switch(pid) {
00182     case PROTON:
00183     case ANTIPROTON:
00184       if (FC_PYPARS.mstp[51] == 1) {
00185         return "PYINTERNAL";
00186       } else if(FC_PYPARS.mstp[51] == 2) {
00187         return "PYLHAPDF";
00188       }
00189       break;
00190 
00191     case ELECTRON:
00192     case POSITRON:
00193       if (FC_PYPARS.mstp[55] == 1) {
00194         return "PYINTERNAL";
00195       } else if(FC_PYPARS.mstp[55] == 2) {
00196         return "PYLHAPDF";
00197       }
00198       break;
00199     default:
00200       break;
00201     }
00202     throw runtime_error("Unknown particle for PDF Set");
00203   }
00204 
00205 
00206   int Ariadne::getPDFMember(PdgCode pid) {
00207     switch(pid) {
00208     case PROTON:
00209     case ANTIPROTON:
00210       return FC_PYPARS.mstp[50];
00211       break;
00212     case ELECTRON:
00213     case POSITRON:
00214       return FC_PYPARS.mstp[54];
00215       break;
00216     default:
00217       break;
00218     }
00219     throw runtime_error("Unknown particle for PDF Set");
00220   }
00221 
00222 
00223   string Ariadne::getPDFScheme(PdgCode pid) const {
00224     switch(pid){
00225     case PROTON:
00226     case ANTIPROTON:
00227       if (FC_PYPARS.mstp[51]==1) {
00228         return "PYINTERNAL";
00229       } else if(FC_PYPARS.mstp[51]==2) {
00230         return "LHAPDF";
00231       }
00232       break;
00233     case ELECTRON:
00234     case POSITRON:
00235       if (FC_PYPARS.mstp[55]==1) {
00236         return "PYINTERNAL";
00237       } else if(FC_PYPARS.mstp[55]==2) {
00238         return "LHAPDF";
00239       }
00240       break;
00241     default:
00242       break;
00243     }
00244     throw runtime_error("Unknown particle for PDF Set");
00245   }
00246 
00247 
00248   const double Ariadne::getCrossSection(){
00249     // _crossSection = FC_PYINT5.xsec[2][0] * 1e09;
00250     _crossSection = FC_PYPARS.pari[0] * 1e09;
00251     return _crossSection;
00252   }
00253 
00254   const string Ariadne::getVersion(){
00255     stringstream s;
00256     s << FC_PYPARS.mstp[180] << "." << FC_PYPARS.mstp[181];
00257     return s.str();
00258   }
00259 
00260   // Tidy up after ourselves
00261   void Ariadne::finalize() {
00262     getLog() << Log::INFO << "Finalising..." << endl;
00263     // Print out stats from run
00264     call_pystat(1);
00265   }
00266 
00267 
00268 }
00269 
00270 
00271 extern "C" {
00272   AGILe::Generator* create() { return new AGILe::Ariadne(); }
00273   void destroy(AGILe::Generator* gen) { delete gen; }
00274 }
Generated on Tue Mar 6 10:39:38 2012 for AGILe - A Generator Interface Library (+ executable) by  doxygen 1.6.3