CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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 
00034 HijingHadronizer::HijingHadronizer(const ParameterSet &pset) :
00035     BaseHadronizer(pset),
00036     evt(0), 
00037     pset_(pset),
00038     bmax_(pset.getParameter<double>("bMax")),
00039     bmin_(pset.getParameter<double>("bMin")),
00040     efrm_(pset.getParameter<double>("comEnergy")),
00041     frame_(pset.getParameter<string>("frame")),
00042     proj_(pset.getParameter<string>("proj")),
00043     targ_(pset.getParameter<string>("targ")),
00044     iap_(pset.getParameter<int>("iap")),
00045     izp_(pset.getParameter<int>("izp")),
00046     iat_(pset.getParameter<int>("iat")),
00047     izt_(pset.getParameter<int>("izt")),
00048     phi0_(0.),
00049     sinphi0_(0.),
00050     cosphi0_(1.),
00051     rotate_(pset.getParameter<bool>("rotateEventPlane"))
00052 {
00053   // Default constructor
00054   Service<RandomNumberGenerator> rng;
00055   hijRandomEngine = &(rng->getEngine());
00056 
00057 }
00058 
00059 
00060 //_____________________________________________________________________
00061 HijingHadronizer::~HijingHadronizer()
00062 {
00063   // destructor
00064 }
00065 
00066 //_____________________________________________________________________
00067 void HijingHadronizer::add_heavy_ion_rec(HepMC::GenEvent *evt)
00068 {
00069   // heavy ion record in the final CMSSW Event
00070   HepMC::HeavyIon* hi = new HepMC::HeavyIon(
00071     himain1.jatt,                               // Ncoll_hard/N of SubEvents
00072     himain1.np,                               // Npart_proj
00073     himain1.nt,                               // Npart_targ
00074     himain1.n0+himain1.n01+himain1.n10+himain1.n11, // Ncoll
00075     0,                                   // spectator_neutrons
00076     0,                                   // spectator_protons
00077     himain1.n01,                          // N_Nwounded_collisions
00078     himain1.n10,                          // Nwounded_N_collisions
00079     himain1.n11,                          // Nwounded_Nwounded_collisions
00080     //gsfs Changed from 19 to 18 (Fortran counts from 1 , not 0) 
00081     hiparnt.hint1[18],                   // impact_parameter in [fm]
00082     phi0_,                               // event_plane_angle
00083     0,                                   // eccentricity
00084     //gsfs Changed from 12 to 11 (Fortran counts from 1 , not 0) 
00085     hiparnt.hint1[11]                    // sigma_inel_NN
00086   );
00087   evt->set_heavy_ion(*hi);
00088   delete hi;
00089 }
00090 
00091 //___________________________________________________________________     
00092 HepMC::GenParticle* HijingHadronizer::build_hijing(int index, int barcode)
00093 {
00094    // Build particle object corresponding to index in hijing
00095                                                                                                                                                          
00096    double x0 = himain2.patt[0][index];
00097    double y0 = himain2.patt[1][index];
00098 
00099    double x = x0*cosphi0_-y0*sinphi0_;
00100    double y = y0*cosphi0_+x0*sinphi0_;
00101 
00102    // Hijing gives V0's status=4, they need to have status=1 to be decayed in geant
00103    // also change status=11 to status=2
00104    if(himain2.katt[3][index]<=10 && himain2.katt[3][index]>0) himain2.katt[3][index]=1;
00105    if(himain2.katt[3][index]<=20 && himain2.katt[3][index]>10) himain2.katt[3][index]=2;
00106 
00107    HepMC::GenParticle* p = new HepMC::GenParticle(
00108                                                   HepMC::FourVector(x,  // px                                                                            
00109                                                                     y,  // py                                                                            
00110                                                                     himain2.patt[2][index],  // pz                                                         
00111                                                                     himain2.patt[3][index]), // E                                                          
00112                                                   himain2.katt[0][index],// id                                                                             
00113                                                   himain2.katt[3][index] // status                                                          
00114                                                   );
00115    p->suggest_barcode(barcode);
00116    
00117    return p;
00118 }
00119 
00120 //___________________________________________________________________     
00121 HepMC::GenVertex* HijingHadronizer::build_hijing_vertex(int i,int id)
00122 {
00123   // build verteces for the hijing stored events                        
00124    double x0=himain2.vatt[0][i];
00125    double y0=himain2.vatt[1][i];
00126    double x = x0*cosphi0_-y0*sinphi0_;
00127    double y = y0*cosphi0_+x0*sinphi0_;
00128    double z=himain2.vatt[2][i];
00129    double t=himain2.vatt[3][i];
00130 
00131    HepMC::GenVertex* vertex = new HepMC::GenVertex(HepMC::FourVector(x,y,z,t),id);
00132    return vertex;
00133 }
00134 
00135 bool HijingHadronizer::generatePartonsAndHadronize()
00136 {
00137    // generate single event
00138    if(rotate_) rotateEvtPlane();
00139 
00140    // generate a HIJING event
00141    
00142    float f_bmin = bmin_;
00143    float f_bmax = bmax_;
00144    HIJING(frame_.data(), f_bmin, f_bmax, strlen(frame_.data()));
00145 
00146    // event information
00147    HepMC::GenEvent *evt = new HepMC::GenEvent();
00148    get_particles(evt); 
00149 
00150    //   evt->set_signal_process_id(pypars.msti[0]);      // type of the process
00151    //   evt->set_event_scale(pypars.pari[16]);           // Q^2
00152    add_heavy_ion_rec(evt);
00153 
00154    event().reset(evt);
00155 
00156    return true;
00157 }
00158 
00159 //_____________________________________________________________________  
00160 bool HijingHadronizer::get_particles(HepMC::GenEvent *evt )
00161 {
00162       HepMC::GenVertex*  vertice;
00163 
00164       vector<HepMC::GenParticle*> particles;
00165       vector<int>                 mother_ids;
00166       vector<HepMC::GenVertex*>   prods;
00167 
00168       vertice = new HepMC::GenVertex(HepMC::FourVector(0,0,0,0),0);
00169       evt->add_vertex(vertice);
00170       if(!evt->signal_process_vertex()) evt->set_signal_process_vertex(vertice);
00171 
00172       const unsigned int knumpart = himain1.natt;
00173 
00174       for (unsigned int ipart = 0; ipart<knumpart; ipart++) {
00175         
00176         int mid = himain2.katt[2][ipart] - 1;  // careful of fortan to c++ array index
00177 
00178         particles.push_back(build_hijing(ipart,ipart+1));
00179         prods.push_back(build_hijing_vertex(ipart,0));
00180         mother_ids.push_back(mid);
00181         LogDebug("DecayChain")<<"Mother index : "<<mid;
00182       } 
00183       
00184       LogDebug("Hijing")<<"Number of particles in vector "<<particles.size();
00185 
00186       for (unsigned int ipart = 0; ipart<particles.size(); ipart++) {
00187          HepMC::GenParticle* part = particles[ipart];
00188 
00189          int mid = mother_ids[ipart];
00190          LogDebug("DecayChain")<<"Particle "<<ipart;
00191          LogDebug("DecayChain")<<"Mother's ID "<<mid;
00192          LogDebug("DecayChain")<<"Particle's PDG ID "<<part->pdg_id();
00193          
00194          // remove zero pT particles from list, protection for fastJet against pt=0 jets
00195          if(part->status()==1&&sqrt(part->momentum().px()*part->momentum().px()+part->momentum().py()*part->momentum().py())==0) 
00196            continue;
00197          
00198          if(mid <= 0){
00199            vertice->add_particle_out(part);
00200             continue;
00201          }
00202 
00203          if(mid > 0){
00204             HepMC::GenParticle* mother = particles[mid];
00205             LogDebug("DecayChain")<<"Mother's PDG ID "<<mother->pdg_id();
00206             HepMC::GenVertex* prod_vertex = mother->end_vertex();
00207             if(!prod_vertex){
00208                prod_vertex = prods[ipart];
00209                prod_vertex->add_particle_in(mother);
00210                
00211                evt->add_vertex(prod_vertex);
00212                prods[ipart]=0; // mark to protect deletion                                                                                                   
00213                
00214             }
00215             prod_vertex->add_particle_out(part);
00216          }
00217       }
00218 
00219       // cleanup vertices not assigned to evt                                                                                                            
00220       for (unsigned int i = 0; i<prods.size(); i++) {
00221          if(prods[i]) delete prods[i];
00222       }
00223 
00224    return true;
00225 }
00226 
00227 //_____________________________________________________________________
00228 bool HijingHadronizer::call_hijset(double efrm, std::string frame, std::string proj, std::string targ, int iap, int izp, int iat, int izt)
00229 {
00230 
00231    float ef = efrm;
00232   // initialize hydjet  
00233    HIJSET(ef,frame.data(),proj.data(),targ.data(),iap,izp,iat,izt,strlen(frame.data()),strlen(proj.data()),strlen(targ.data()));
00234    return true;
00235 }
00236 
00237 //______________________________________________________________
00238 bool HijingHadronizer::initializeForInternalPartons(){
00239 
00240   //initialize pythia5
00241 
00242   if(0){
00243     std::string dumstr = "";
00244     call_pygive(dumstr);
00245   }
00246 
00247    // initialize hijing
00248    LogInfo("HIJINGinAction") << "##### Calling HIJSET(" << efrm_ << "," <<frame_<<","<<proj_<<","<<targ_<<","<<iap_<<","<<izp_<<","<<iat_<<","<<izt_<<") ####";
00249    call_hijset(efrm_,frame_,proj_,targ_,iap_,izp_,iat_,izt_);
00250 
00251    return true;
00252 
00253 }
00254 
00255 bool HijingHadronizer::declareStableParticles( const std::vector<int>& pdg )
00256 {
00257    return true;
00258 }
00259 
00260 //________________________________________________________________                                                                    
00261 void HijingHadronizer::rotateEvtPlane(){
00262 
00263    phi0_ = 2.*pi*gen::hijran_(0) - pi;
00264    sinphi0_ = sin(phi0_);
00265    cosphi0_ = cos(phi0_);
00266 }
00267 
00268 //________________________________________________________________ 
00269 bool HijingHadronizer::hadronize()
00270 {
00271    return false;
00272 }
00273 
00274 bool HijingHadronizer::decay()
00275 {
00276    return true;
00277 }
00278    
00279 bool HijingHadronizer::residualDecay()
00280 {  
00281    return true;
00282 }
00283 
00284 void HijingHadronizer::finalizeEvent(){
00285     return;
00286 }
00287 
00288 void HijingHadronizer::statistics(){
00289     return;
00290 }
00291 
00292 const char* HijingHadronizer::classname() const
00293 {  
00294    return "gen::HijingHadronizer";
00295 }
00296