CMS 3D CMS Logo

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