CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/GeneratorInterface/AMPTInterface/src/AMPTHadronizer.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/AMPTInterface/interface/AMPTHadronizer.h"
00016 #include "GeneratorInterface/AMPTInterface/interface/AMPTWrapper.h"
00017 
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* _amptRandomEngine;
00034 
00035 extern "C"
00036 {
00037   float gen::ranart_(int *idummy)
00038   {
00039     if(0) idummy = idummy; 
00040     float rannum = _amptRandomEngine->flat();
00041     return rannum;
00042   }
00043 }
00044 
00045 extern "C"
00046 {
00047   float gen::ran1_(int *idummy)
00048   {
00049     if(0) idummy = idummy;
00050     return _amptRandomEngine->flat();
00051   }
00052 }
00053 
00054 AMPTHadronizer::AMPTHadronizer(const ParameterSet &pset) :
00055     BaseHadronizer(pset),
00056     evt(0), 
00057     pset_(pset),
00058     bmax_(pset.getParameter<double>("bMax")),
00059     bmin_(pset.getParameter<double>("bMin")),
00060     efrm_(pset.getParameter<double>("comEnergy")),
00061     frame_(pset.getParameter<string>("frame")),
00062     proj_(pset.getParameter<string>("proj")),
00063     targ_(pset.getParameter<string>("targ")),
00064     iap_(pset.getParameter<int>("iap")),
00065     izp_(pset.getParameter<int>("izp")),
00066     iat_(pset.getParameter<int>("iat")),
00067     izt_(pset.getParameter<int>("izt")),
00068     amptmode_(pset.getParameter<int>("amptmode")),
00069     ntmax_(pset.getParameter<int>("ntmax")),
00070     dt_(pset.getParameter<double>("dt")),
00071     stringFragA_(pset.getParameter<double>("stringFragA")),
00072     stringFragB_(pset.getParameter<double>("stringFragB")),
00073     popcornmode_(pset.getParameter<bool>("popcornmode")),
00074     popcornpar_(pset.getParameter<double>("popcornpar")),
00075     shadowingmode_(pset.getParameter<bool>("shadowingmode")),
00076     quenchingmode_(pset.getParameter<bool>("quenchingmode")),
00077     quenchingpar_(pset.getParameter<double>("quenchingpar")),
00078     pthard_(pset.getParameter<double>("pthard")),
00079     mu_(pset.getParameter<double>("mu")),
00080     izpc_(pset.getParameter<int>("izpc")),
00081     alpha_(pset.getParameter<double>("alpha")),
00082     dpcoal_(pset.getParameter<double>("dpcoal")),
00083     drcoal_(pset.getParameter<double>("drcoal")),
00084     ks0decay_(pset.getParameter<bool>("ks0decay")),
00085     phidecay_(pset.getParameter<bool>("phidecay")),
00086     deuteronmode_(pset.getParameter<int>("deuteronmode")),          
00087     deuteronfactor_(pset.getParameter<int>("deuteronfactor")),
00088     deuteronxsec_(pset.getParameter<int>("deuteronxsec")),
00089     minijetpt_(pset.getParameter<double>("minijetpt")),
00090     maxmiss_(pset.getParameter<int>("maxmiss")),
00091     doInitialAndFinalRadiation_(pset.getParameter<int>("doInitialAndFinalRadiation")),
00092     ktkick_(pset.getParameter<int>("ktkick")),
00093     diquarkembedding_(pset.getParameter<int>("diquarkembedding")),
00094     diquarkpx_(pset.getParameter<double>("diquarkpx")),
00095     diquarkpy_(pset.getParameter<double>("diquarkpy")),
00096     diquarkx_(pset.getParameter<double>("diquarkx")),
00097     diquarky_(pset.getParameter<double>("diquarky")),
00098     phi0_(0.),
00099     sinphi0_(0.),
00100     cosphi0_(1.),
00101     rotate_(pset.getParameter<bool>("rotateEventPlane"))
00102 {
00103   // Default constructor
00104   edm::Service<RandomNumberGenerator> rng;
00105   _amptRandomEngine = &(rng->getEngine());
00106 }
00107 
00108 
00109 //_____________________________________________________________________
00110 AMPTHadronizer::~AMPTHadronizer()
00111 {
00112 }
00113 
00114 //_____________________________________________________________________
00115 void AMPTHadronizer::add_heavy_ion_rec(HepMC::GenEvent *evt)
00116 {
00117   // heavy ion record in the final CMSSW Event
00118   HepMC::HeavyIon* hi = new HepMC::HeavyIon(
00119     hmain1.jatt,                               // Ncoll_hard/N of SubEvents
00120     hmain1.np,                               // Npart_proj
00121     hmain1.nt,                               // Npart_targ
00122     hmain1.n0+hmain1.n01+hmain1.n10+hmain1.n11,  // Ncoll
00123     0,                                   // spectator_neutrons
00124     0,                                   // spectator_protons
00125     hmain1.n01,                          // N_Nwounded_collisions
00126     hmain1.n10,                          // Nwounded_N_collisions
00127     hmain1.n11,                          // Nwounded_Nwounded_collisions
00128     hparnt.hint1[18],                   // impact_parameter in [fm]
00129     phi0_,                              // event_plane_angle
00130     0,                                   // eccentricity
00131     hparnt.hint1[11]                    // sigma_inel_NN
00132   );
00133   evt->set_heavy_ion(*hi);
00134   delete hi;
00135 }
00136 
00137 //___________________________________________________________________     
00138 HepMC::GenParticle* AMPTHadronizer::build_ampt(int index, int barcode)
00139 {
00140    // Build particle object corresponding to index in ampt
00141 
00142    float px0 = hbt.plast[index][0];
00143    float py0 = hbt.plast[index][1];
00144    float pz0 = hbt.plast[index][2];
00145    float m = hbt.plast[index][3];
00146 
00147    float px = px0*cosphi0_-py0*sinphi0_;
00148    float py = py0*cosphi0_+px0*sinphi0_;
00149    float pz = pz0;
00150    float e = sqrt(px*px+py*py+pz*pz+m*m); 
00151    int status = 1;
00152 
00153    HepMC::GenParticle* p = new HepMC::GenParticle(
00154                                                   HepMC::FourVector(px,                                                                            
00155                                                                     py,                                                                            
00156                                                                     pz,                                                         
00157                                                                     e),                                                           
00158                                                   INVFLV(hbt.lblast[index]),// id                                                                             
00159                                                   status // status                                                          
00160                                                   );
00161 
00162    p->suggest_barcode(barcode);
00163    return p;
00164 }
00165 
00166 //___________________________________________________________________     
00167 HepMC::GenVertex* AMPTHadronizer::build_ampt_vertex(int i,int id)
00168 {
00169    // build verteces for the ampt stored events                        
00170    HepMC::GenVertex* vertex = new HepMC::GenVertex(HepMC::FourVector(0,0,0,0),id);
00171    return vertex;
00172 }
00173 //_____________________________________________________________________  
00174 bool AMPTHadronizer::generatePartonsAndHadronize()
00175 {
00176    // generate single event
00177    if(rotate_) rotateEvtPlane();
00178 
00179    // generate a AMPT event
00180    AMPT(frame_.data(), bmin_, bmax_, strlen(frame_.data()));
00181 
00182    // event information
00183    HepMC::GenEvent *evt = new HepMC::GenEvent();
00184    get_particles(evt); 
00185 
00186    add_heavy_ion_rec(evt);
00187 
00188    event().reset(evt);
00189 
00190 
00191    return true;
00192 }
00193 
00194 //_____________________________________________________________________  
00195 bool AMPTHadronizer::get_particles(HepMC::GenEvent *evt )
00196 {
00197       HepMC::GenVertex*  vertice;
00198 
00199       vector<HepMC::GenParticle*> particles;
00200       vector<int>                 mother_ids;
00201       vector<HepMC::GenVertex*>   prods;
00202 
00203       vertice = new HepMC::GenVertex(HepMC::FourVector(0,0,0,0),0);
00204       evt->add_vertex(vertice);
00205       if(!evt->signal_process_vertex()) evt->set_signal_process_vertex(vertice);
00206 
00207       const unsigned int knumpart = hbt.nlast;
00208       for (unsigned int ipart = 0; ipart<knumpart; ipart++) {
00209          int mid = 0;
00210          particles.push_back(build_ampt(ipart,ipart+1));
00211          prods.push_back(build_ampt_vertex(ipart,0));
00212          mother_ids.push_back(mid);
00213          LogDebug("DecayChain")<<"Mother index : "<<mid;
00214       }
00215       
00216       LogDebug("AMPT")<<"Number of particles in vector "<<particles.size();
00217 
00218       for (unsigned int ipart = 0; ipart<particles.size(); ipart++) {
00219          HepMC::GenParticle* part = particles[ipart];
00220 
00221          int mid = mother_ids[ipart];
00222          LogDebug("DecayChain")<<"Particle "<<ipart;
00223          LogDebug("DecayChain")<<"Mother's ID "<<mid;
00224          LogDebug("DecayChain")<<"Particle's PDG ID "<<part->pdg_id();
00225 
00226          if(mid <= 0){
00227             vertice->add_particle_out(part);
00228             continue;
00229          }
00230 
00231          if(mid > 0){
00232             HepMC::GenParticle* mother = particles[mid];
00233             LogDebug("DecayChain")<<"Mother's PDG ID "<<mother->pdg_id();
00234 
00235             HepMC::GenVertex* prod_vertex = mother->end_vertex();
00236             if(!prod_vertex){
00237                prod_vertex = prods[ipart];
00238                prod_vertex->add_particle_in(mother);
00239                evt->add_vertex(prod_vertex);
00240                prods[ipart]=0; // mark to protect deletion                                                                                                   
00241 
00242             }
00243             prod_vertex->add_particle_out(part);
00244          }
00245       }
00246 
00247       // cleanup vertices not assigned to evt                                                                                                            
00248       for (unsigned int i = 0; i<prods.size(); i++) {
00249          if(prods[i]) delete prods[i];
00250       }
00251 
00252    return true;
00253 }
00254 
00255 //_____________________________________________________________________
00256 bool AMPTHadronizer::call_amptset(double efrm, std::string frame, std::string proj, std::string targ, int iap, int izp, int iat, int izt)
00257 {
00258   // initialize hydjet  
00259    AMPTSET(efrm,frame.data(),proj.data(),targ.data(),iap,izp,iat,izt,strlen(frame.data()),strlen(proj.data()),strlen(targ.data()));
00260         return true;
00261 }
00262 //______________________________________________________________________
00263 bool AMPTHadronizer::ampt_init(const ParameterSet &pset)
00264 {
00265     anim.isoft=amptmode_;
00266     input2.ntmax=ntmax_;
00267     input1.dt=dt_;
00268     ludat1.parj[40]=stringFragA_;
00269     ludat1.parj[41]=stringFragB_;
00270     popcorn.ipop=popcornmode_;
00271     ludat1.parj[4]=popcornpar_;
00272     hparnt.ihpr2[5]=shadowingmode_;
00273     hparnt.ihpr2[3]=quenchingmode_;
00274     hparnt.hipr1[13]=quenchingpar_;
00275     hparnt.hipr1[7]=pthard_;
00276     para2.xmu=mu_;
00277     anim.izpc=izpc_;
00278     para2.alpha=alpha_;
00279     coal.dpcoal=dpcoal_;
00280     coal.drcoal=drcoal_;
00281     resdcy.iksdcy=ks0decay_;
00282     phidcy.iphidcy=phidecay_;
00283     para8.idpert=deuteronmode_;
00284     para8.npertd=deuteronfactor_;
00285     para8.idxsec=deuteronxsec_;
00286     phidcy.pttrig=minijetpt_;
00287     phidcy.maxmiss=maxmiss_;
00288     hparnt.ihpr2[1]=doInitialAndFinalRadiation_;
00289     hparnt.ihpr2[4]=ktkick_;
00290     embed.iembed=diquarkembedding_;
00291     embed.pxqembd=diquarkpx_;
00292     embed.pyqembd=diquarkpy_;
00293     embed.xembd=diquarkx_;
00294     embed.yembd=diquarky_;
00295 
00296     return true;
00297 }
00298 
00299 //_____________________________________________________________________
00300 bool AMPTHadronizer::initializeForInternalPartons(){
00301 
00302    // ampt running options
00303    ampt_init(pset_);
00304 
00305    // initialize ampt
00306    LogInfo("AMPTinAction") << "##### Calling AMPTSET(" << efrm_ << "," <<frame_<<","<<proj_<<","<<targ_<<","<<iap_<<","<<izp_<<","<<iat_<<","<<izt_<<") ####";
00307 
00308    call_amptset(efrm_,frame_,proj_,targ_,iap_,izp_,iat_,izt_);
00309 
00310    return true;
00311 }
00312 
00313 bool AMPTHadronizer::declareStableParticles( std::vector<int> pdg )
00314 {
00315    return true;
00316 }
00317 
00318 //________________________________________________________________                                                                    
00319 void AMPTHadronizer::rotateEvtPlane(){
00320    int zero = 0;
00321    double test = (double)gen::ranart_(&zero);
00322    phi0_ = 2.*pi*test - pi;
00323    sinphi0_ = sin(phi0_);
00324    cosphi0_ = cos(phi0_);
00325 }
00326 
00327 //________________________________________________________________ 
00328 bool AMPTHadronizer::hadronize()
00329 {
00330    return false;
00331 }
00332 
00333 bool AMPTHadronizer::decay()
00334 {
00335    return true;
00336 }
00337    
00338 bool AMPTHadronizer::residualDecay()
00339 {  
00340    return true;
00341 }
00342 
00343 void AMPTHadronizer::finalizeEvent(){
00344     return;
00345 }
00346 
00347 void AMPTHadronizer::statistics(){
00348     return;
00349 }
00350 
00351 const char* AMPTHadronizer::classname() const
00352 {  
00353    return "gen::AMPTHadronizer";
00354 }
00355