Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <iostream>
00008
00009 #include "Pythia6Gun.h"
00010
00011
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "FWCore/Utilities/interface/Exception.h"
00014
00015 #include "FWCore/Framework/interface/EDProducer.h"
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/EventSetup.h"
00018
00019 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00020
00021 using namespace edm;
00022 using namespace gen;
00023
00024
00025 Pythia6Gun::Pythia6Gun( const ParameterSet& pset ) :
00026 fPy6Service( new Pythia6Service(pset) ),
00027 fEvt(0)
00028
00029 {
00030
00031 ParameterSet pgun_params =
00032 pset.getParameter<ParameterSet>("PGunParameters");
00033
00034
00035
00036
00037
00038
00039 fMinPhi = pgun_params.getParameter<double>("MinPhi");
00040 fMaxPhi = pgun_params.getParameter<double>("MaxPhi");
00041
00042 fHepMCVerbosity = pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity", false ) ;
00043 fPylistVerbosity = pset.getUntrackedParameter<int>( "pythiaPylistVerbosity", 0 ) ;
00044 fMaxEventsToPrint = pset.getUntrackedParameter<int>( "maxEventsToPrint", 0 );
00045
00046
00047 if (!call_pygive("MSTU(12)=12345"))
00048 {
00049 throw edm::Exception(edm::errors::Configuration,"PythiaError")
00050 <<" pythia did not accept MSTU(12)=12345";
00051 }
00052
00053 produces<HepMCProduct>();
00054
00055 }
00056
00057 Pythia6Gun::~Pythia6Gun()
00058 {
00059 if ( fPy6Service ) delete fPy6Service;
00060
00061
00062
00063
00064 }
00065
00066
00067 void Pythia6Gun::beginJob()
00068 {
00069
00070 return ;
00071
00072 }
00073
00074 void Pythia6Gun::beginRun( Run const&, EventSetup const& es )
00075 {
00076 assert ( fPy6Service ) ;
00077
00078 Pythia6Service::InstanceWrapper guard(fPy6Service);
00079
00080 fPy6Service->setGeneralParams();
00081 fPy6Service->setCSAParams();
00082 fPy6Service->setSLHAParams();
00083
00084 call_pygive("MSTU(10)=1");
00085
00086 call_pyinit("NONE", "", "", 0.0);
00087
00088 std::cout << " FYI: MSTU(10)=1 is ENFORCED in Py6-PGuns, for technical reasons"
00089 << std::endl;
00090 return;
00091 }
00092
00093 void Pythia6Gun::endRun( Run const&, EventSetup const& es )
00094 {
00095
00096
00097
00098 call_pystat(1);
00099
00100 return;
00101 }
00102
00103 void Pythia6Gun::attachPy6DecaysToGenEvent()
00104 {
00105
00106 for ( int iprt=fPartIDs.size(); iprt<pyjets.n; iprt++ )
00107 {
00108 int parent = pyjets.k[2][iprt];
00109 if ( parent != 0 )
00110 {
00111
00112
00113 HepMC::GenParticle* parentPart = fEvt->barcode_to_particle( parent );
00114 parentPart->set_status( 2 );
00115
00116 HepMC::GenVertex* DecVtx = new HepMC::GenVertex(HepMC::FourVector(pyjets.v[0][iprt],
00117 pyjets.v[1][iprt],
00118 pyjets.v[2][iprt],
00119 pyjets.v[3][iprt]));
00120 DecVtx->add_particle_in( parentPart );
00121
00122
00123
00124 HepMC::FourVector pmom(pyjets.p[0][iprt],pyjets.p[1][iprt],
00125 pyjets.p[2][iprt],pyjets.p[3][iprt] );
00126
00127 int dstatus = 0;
00128 if ( pyjets.k[0][iprt] >= 1 && pyjets.k[0][iprt] <= 10 )
00129 {
00130 dstatus = 1;
00131 }
00132 else if ( pyjets.k[0][iprt] >= 11 && pyjets.k[0][iprt] <= 20 )
00133 {
00134 dstatus = 2;
00135 }
00136 else if ( pyjets.k[0][iprt] >= 21 && pyjets.k[0][iprt] <= 30 )
00137 {
00138 dstatus = 3;
00139 }
00140 else if ( pyjets.k[0][iprt] >= 31 && pyjets.k[0][iprt] <= 100 )
00141 {
00142 dstatus = pyjets.k[0][iprt];
00143 }
00144 HepMC::GenParticle* daughter =
00145 new HepMC::GenParticle(pmom,
00146 HepPID::translatePythiatoPDT( pyjets.k[1][iprt] ),
00147 dstatus);
00148 daughter->suggest_barcode( iprt+1 );
00149 DecVtx->add_particle_out( daughter );
00150
00151
00152 int iprt1;
00153 for ( iprt1=iprt+1; iprt1<pyjets.n; iprt1++ )
00154 {
00155 if ( pyjets.k[2][iprt1] != parent ) break;
00156
00157 HepMC::FourVector pmomN(pyjets.p[0][iprt1],pyjets.p[1][iprt1],
00158 pyjets.p[2][iprt1],pyjets.p[3][iprt1] );
00159
00160 dstatus = 0;
00161 if ( pyjets.k[0][iprt1] >= 1 && pyjets.k[0][iprt1] <= 10 )
00162 {
00163 dstatus = 1;
00164 }
00165 else if ( pyjets.k[0][iprt1] >= 11 && pyjets.k[0][iprt1] <= 20 )
00166 {
00167 dstatus = 2;
00168 }
00169 else if ( pyjets.k[0][iprt1] >= 21 && pyjets.k[0][iprt1] <= 30 )
00170 {
00171 dstatus = 3;
00172 }
00173 else if ( pyjets.k[0][iprt1] >= 31 && pyjets.k[0][iprt1] <= 100 )
00174 {
00175 dstatus = pyjets.k[0][iprt1];
00176 }
00177 HepMC::GenParticle* daughterN =
00178 new HepMC::GenParticle(pmomN,
00179 HepPID::translatePythiatoPDT( pyjets.k[1][iprt1] ),
00180 dstatus);
00181 daughterN->suggest_barcode( iprt1+1 );
00182 DecVtx->add_particle_out( daughterN );
00183 }
00184
00185 iprt = iprt1-1;
00186
00187
00188 fEvt->add_vertex( DecVtx );
00189
00190 }
00191 }
00192
00193 return;
00194
00195 }
00196
00197 void Pythia6Gun::produce( edm::Event& evt, const edm::EventSetup& )
00198 {
00199
00200 generateEvent() ;
00201
00202 fEvt->set_beam_particles(0,0);
00203 fEvt->set_event_number(evt.id().event()) ;
00204 fEvt->set_signal_process_id(pypars.msti[0]) ;
00205
00206 attachPy6DecaysToGenEvent();
00207
00208 int evtN = evt.id().event();
00209 if ( evtN <= fMaxEventsToPrint )
00210 {
00211 if ( fPylistVerbosity )
00212 {
00213 call_pylist(fPylistVerbosity);
00214 }
00215 if ( fHepMCVerbosity )
00216 {
00217 if ( fEvt ) fEvt->print();
00218 }
00219 }
00220
00221 loadEvent( evt );
00222 }
00223
00224 void Pythia6Gun::loadEvent( edm::Event& evt )
00225 {
00226
00227 std::auto_ptr<HepMCProduct> bare_product(new HepMCProduct());
00228
00229 if(fEvt) bare_product->addHepMCData( fEvt );
00230
00231 evt.put(bare_product);
00232
00233
00234 return;
00235
00236 }
00237
00238 HepMC::GenParticle* Pythia6Gun::addAntiParticle( int& ip, int& particleID,
00239 double& ee, double& eta, double& phi )
00240 {
00241
00242 if ( ip < 2 ) return 0;
00243
00244
00245 int py6PID = HepPID::translatePDTtoPythia( particleID );
00246
00247 int pythiaCode = pycomp_(py6PID);
00248
00249 int has_antipart = pydat2.kchg[3-1][pythiaCode-1];
00250 int particleID2 = has_antipart ? -1 * particleID : particleID;
00251 int py6PID2 = has_antipart ? -1 * py6PID : py6PID;
00252 double the = 2.*atan(exp(eta));
00253 phi = phi + M_PI;
00254 if (phi > 2.* M_PI) {phi = phi - 2.* M_PI;}
00255
00256
00257 pyjets.p[4][ip-1] = pyjets.p[4][ip-2];
00258
00259 py1ent_(ip, py6PID2, ee, the, phi);
00260
00261 double px = pyjets.p[0][ip-1];
00262 double py = pyjets.p[1][ip-1];
00263 double pz = pyjets.p[2][ip-1];
00264 HepMC::FourVector ap(px,py,pz,ee) ;
00265 HepMC::GenParticle* APart =
00266 new HepMC::GenParticle(ap,particleID2,1);
00267 APart->suggest_barcode( ip ) ;
00268
00269 return APart;
00270
00271 }