CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/GeneratorInterface/HijingInterface/src/HijingHadronizer.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <cmath>
00003 
00004 #include "boost/lexical_cast.hpp"
00005 
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "FWCore/Framework/interface/Run.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/ServiceRegistry/interface/Service.h"
00011 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00012 #include "FWCore/Utilities/interface/EDMException.h"
00013 #include "GeneratorInterface/Core/interface/RNDMEngineAccess.h"
00014 
00015 #include "GeneratorInterface/HijingInterface/interface/HijingHadronizer.h"
00016 #include "GeneratorInterface/HijingInterface/interface/HijingPythiaWrapper.h"
00017 #include "GeneratorInterface/HijingInterface/interface/HijingWrapper.h"
00018 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00019 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
00020 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
00021 
00022 #include "HepMC/GenEvent.h"
00023 #include "HepMC/HeavyIon.h"
00024 #include "HepMC/SimpleVector.h"
00025 #include "CLHEP/Random/RandomEngine.h"
00026 
00027 static const double pi = 3.14159265358979;
00028 
00029 using namespace edm;
00030 using namespace std;
00031 using namespace gen;
00032 
00033 CLHEP::HepRandomEngine* hijRandomEngine;
00034 
00035 extern "C"
00036 {
00037   double gen::hijran_(int *idummy)
00038   {
00039     return hijRandomEngine->flat(); 
00040   }
00041 }
00042 
00043 HijingHadronizer::HijingHadronizer(const ParameterSet &pset) :
00044     BaseHadronizer(pset),
00045     evt(0), 
00046     pset_(pset),
00047     bmax_(pset.getParameter<double>("bMax")),
00048     bmin_(pset.getParameter<double>("bMin")),
00049     efrm_(pset.getParameter<double>("comEnergy")),
00050     frame_(pset.getParameter<string>("frame")),
00051     proj_(pset.getParameter<string>("proj")),
00052     targ_(pset.getParameter<string>("targ")),
00053     iap_(pset.getParameter<int>("iap")),
00054     izp_(pset.getParameter<int>("izp")),
00055     iat_(pset.getParameter<int>("iat")),
00056     izt_(pset.getParameter<int>("izt")),
00057     phi0_(0.),
00058     sinphi0_(0.),
00059     cosphi0_(1.),
00060     rotate_(pset.getParameter<bool>("rotateEventPlane"))
00061 {
00062   // Default constructor
00063   Service<RandomNumberGenerator> rng;
00064   hijRandomEngine = &(rng->getEngine());
00065 
00066 }
00067 
00068 
00069 //_____________________________________________________________________
00070 HijingHadronizer::~HijingHadronizer()
00071 {
00072   // destructor
00073 }
00074 
00075 //_____________________________________________________________________
00076 void HijingHadronizer::add_heavy_ion_rec(HepMC::GenEvent *evt)
00077 {
00078   // heavy ion record in the final CMSSW Event
00079   HepMC::HeavyIon* hi = new HepMC::HeavyIon(
00080     himain1.jatt,                               // Ncoll_hard/N of SubEvents
00081     himain1.np,                               // Npart_proj
00082     himain1.nt,                               // Npart_targ
00083     himain1.n0+himain1.n01+himain1.n10+himain1.n11, // Ncoll
00084     0,                                   // spectator_neutrons
00085     0,                                   // spectator_protons
00086     himain1.n01,                          // N_Nwounded_collisions
00087     himain1.n10,                          // Nwounded_N_collisions
00088     himain1.n11,                          // Nwounded_Nwounded_collisions
00089     //gsfs Changed from 19 to 18 (Fortran counts from 1 , not 0) 
00090     hiparnt.hint1[18],                   // impact_parameter in [fm]
00091     phi0_,                               // event_plane_angle
00092     0,                                   // eccentricity
00093     //gsfs Changed from 12 to 11 (Fortran counts from 1 , not 0) 
00094     hiparnt.hint1[11]                    // sigma_inel_NN
00095   );
00096   evt->set_heavy_ion(*hi);
00097   delete hi;
00098 }
00099 
00100 //___________________________________________________________________     
00101 HepMC::GenParticle* HijingHadronizer::build_hijing(int index, int barcode)
00102 {
00103    // Build particle object corresponding to index in hijing
00104                                                                                                                                                          
00105    double x0 = himain2.patt[0][index];
00106    double y0 = himain2.patt[1][index];
00107 
00108    double x = x0*cosphi0_-y0*sinphi0_;
00109    double y = y0*cosphi0_+x0*sinphi0_;
00110 
00111    HepMC::GenParticle* p = new HepMC::GenParticle(
00112                                                   HepMC::FourVector(x,  // px                                                                            
00113                                                                     y,  // py                                                                            
00114                                                                     himain2.patt[2][index],  // pz                                                         
00115                                                                     himain2.patt[3][index]), // E                                                          
00116                                                   himain2.katt[0][index],// id                                                                             
00117                                                   himain2.katt[3][index] // status                                                          
00118                                                   );
00119    p->suggest_barcode(barcode);
00120 
00121    return p;
00122 }
00123 
00124 //___________________________________________________________________     
00125 HepMC::GenVertex* HijingHadronizer::build_hijing_vertex(int i,int id)
00126 {
00127    // build verteces for the hijing stored events                        
00128    HepMC::GenVertex* vertex = new HepMC::GenVertex(HepMC::FourVector(0,0,0,0),id);
00129    return vertex;
00130 }
00131 
00132 bool HijingHadronizer::generatePartonsAndHadronize()
00133 {
00134    // generate single event
00135    if(rotate_) rotateEvtPlane();
00136 
00137    // generate a HIJING event
00138    HIJING(frame_.data(), bmin_, bmax_, strlen(frame_.data()));
00139 
00140    // event information
00141    HepMC::GenEvent *evt = new HepMC::GenEvent();
00142    get_particles(evt); 
00143 
00144    //   evt->set_signal_process_id(pypars.msti[0]);      // type of the process
00145    //   evt->set_event_scale(pypars.pari[16]);           // Q^2
00146    add_heavy_ion_rec(evt);
00147 
00148    event().reset(evt);
00149 
00150 
00151    return true;
00152 }
00153 
00154 //_____________________________________________________________________  
00155 bool HijingHadronizer::get_particles(HepMC::GenEvent *evt )
00156 {
00157       HepMC::GenVertex*  vertice;
00158 
00159       vector<HepMC::GenParticle*> particles;
00160       vector<int>                 mother_ids;
00161       vector<HepMC::GenVertex*>   prods;
00162 
00163       vertice = new HepMC::GenVertex(HepMC::FourVector(0,0,0,0),0);
00164       evt->add_vertex(vertice);
00165       if(!evt->signal_process_vertex()) evt->set_signal_process_vertex(vertice);
00166 
00167       const unsigned int knumpart = himain1.natt;
00168       for (unsigned int ipart = 0; ipart<knumpart; ipart++) {
00169 
00170          int mid = himain2.katt[2][ipart];
00171          particles.push_back(build_hijing(ipart,ipart+1));
00172          prods.push_back(build_hijing_vertex(ipart,0));
00173          mother_ids.push_back(mid);
00174          LogDebug("DecayChain")<<"Mother index : "<<mid;
00175       }
00176       
00177       LogDebug("Hijing")<<"Number of particles in vector "<<particles.size();
00178 
00179       for (unsigned int ipart = 0; ipart<particles.size(); ipart++) {
00180          HepMC::GenParticle* part = particles[ipart];
00181 
00182          int mid = mother_ids[ipart];
00183          LogDebug("DecayChain")<<"Particle "<<ipart;
00184          LogDebug("DecayChain")<<"Mother's ID "<<mid;
00185          LogDebug("DecayChain")<<"Particle's PDG ID "<<part->pdg_id();
00186 
00187          if(mid <= 0){
00188             vertice->add_particle_out(part);
00189             continue;
00190          }
00191 
00192          if(mid > 0){
00193             HepMC::GenParticle* mother = particles[mid];
00194             LogDebug("DecayChain")<<"Mother's PDG ID "<<mother->pdg_id();
00195 
00196             HepMC::GenVertex* prod_vertex = mother->end_vertex();
00197             if(!prod_vertex){
00198                prod_vertex = prods[ipart];
00199                prod_vertex->add_particle_in(mother);
00200                evt->add_vertex(prod_vertex);
00201                prods[ipart]=0; // mark to protect deletion                                                                                                   
00202 
00203             }
00204             prod_vertex->add_particle_out(part);
00205          }
00206       }
00207 
00208       // cleanup vertices not assigned to evt                                                                                                            
00209       for (unsigned int i = 0; i<prods.size(); i++) {
00210          if(prods[i]) delete prods[i];
00211       }
00212 
00213    return true;
00214 }
00215 
00216 //_____________________________________________________________________
00217 bool HijingHadronizer::call_hijset(double efrm, std::string frame, std::string proj, std::string targ, int iap, int izp, int iat, int izt)
00218 {
00219   // initialize hydjet  
00220    HIJSET(efrm,frame.data(),proj.data(),targ.data(),iap,izp,iat,izt,strlen(frame.data()),strlen(proj.data()),strlen(targ.data()));
00221    return true;
00222 }
00223 
00224 //______________________________________________________________
00225 bool HijingHadronizer::initializeForInternalPartons(){
00226 
00227   //initialize pythia5
00228 
00229   if(0){
00230     std::string dumstr = "";
00231     call_pygive(dumstr);
00232   }
00233 
00234    // initialize hijing
00235    LogInfo("HIJINGinAction") << "##### Calling HIJSET(" << efrm_ << "," <<frame_<<","<<proj_<<","<<targ_<<","<<iap_<<","<<izp_<<","<<iat_<<","<<izt_<<") ####";
00236    call_hijset(efrm_,frame_,proj_,targ_,iap_,izp_,iat_,izt_);
00237 
00238    return true;
00239 
00240 }
00241 
00242 bool HijingHadronizer::declareStableParticles( std::vector<int> pdg )
00243 {
00244    return true;
00245 }
00246 
00247 //________________________________________________________________                                                                    
00248 void HijingHadronizer::rotateEvtPlane(){
00249 
00250    phi0_ = 2.*pi*gen::hijran_(0) - pi;
00251    sinphi0_ = sin(phi0_);
00252    cosphi0_ = cos(phi0_);
00253 }
00254 
00255 //________________________________________________________________ 
00256 bool HijingHadronizer::hadronize()
00257 {
00258    return false;
00259 }
00260 
00261 bool HijingHadronizer::decay()
00262 {
00263    return true;
00264 }
00265    
00266 bool HijingHadronizer::residualDecay()
00267 {  
00268    return true;
00269 }
00270 
00271 void HijingHadronizer::finalizeEvent(){
00272     return;
00273 }
00274 
00275 void HijingHadronizer::statistics(){
00276     return;
00277 }
00278 
00279 const char* HijingHadronizer::classname() const
00280 {  
00281    return "gen::HijingHadronizer";
00282 }
00283