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
00054 Service<RandomNumberGenerator> rng;
00055 hijRandomEngine = &(rng->getEngine());
00056
00057 }
00058
00059
00060
00061 HijingHadronizer::~HijingHadronizer()
00062 {
00063
00064 }
00065
00066
00067 void HijingHadronizer::add_heavy_ion_rec(HepMC::GenEvent *evt)
00068 {
00069
00070 HepMC::HeavyIon* hi = new HepMC::HeavyIon(
00071 himain1.jatt,
00072 himain1.np,
00073 himain1.nt,
00074 himain1.n0+himain1.n01+himain1.n10+himain1.n11,
00075 0,
00076 0,
00077 himain1.n01,
00078 himain1.n10,
00079 himain1.n11,
00080
00081 hiparnt.hint1[18],
00082 phi0_,
00083 0,
00084
00085 hiparnt.hint1[11]
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
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
00103
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,
00109 y,
00110 himain2.patt[2][index],
00111 himain2.patt[3][index]),
00112 himain2.katt[0][index],
00113 himain2.katt[3][index]
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
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
00138 if(rotate_) rotateEvtPlane();
00139
00140
00141
00142 float f_bmin = bmin_;
00143 float f_bmax = bmax_;
00144 HIJING(frame_.data(), f_bmin, f_bmax, strlen(frame_.data()));
00145
00146
00147 HepMC::GenEvent *evt = new HepMC::GenEvent();
00148 get_particles(evt);
00149
00150
00151
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;
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
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;
00213
00214 }
00215 prod_vertex->add_particle_out(part);
00216 }
00217 }
00218
00219
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
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
00241
00242 if(0){
00243 std::string dumstr = "";
00244 call_pygive(dumstr);
00245 }
00246
00247
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( 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