00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "Bhwide/Bhwide.h"
00013 #include "Bhwide/BhwideRandom.h"
00014
00015
00016 #include "HepMC/GenEvent.h"
00017 #include "HepMC/GenVertex.h"
00018 #include "HepMC/GenParticle.h"
00019 #include "CLHEP/Vector/LorentzVector.h"
00020
00021 #include "GaudiKernel/MsgStream.h"
00022 #include "GaudiKernel/ISvcLocator.h"
00023 #include "GaudiKernel/AlgFactory.h"
00024 #include "GaudiKernel/DataSvc.h"
00025 #include "GaudiKernel/SmartDataPtr.h"
00026
00027 #include "GeneratorObject/McGenEvent.h"
00028 #include "BesKernel/IBesRndmGenSvc.h"
00029
00030 #include "cfortran/cfortran.h"
00031
00032 #include <stdlib.h>
00033
00034 using namespace std;
00035
00036
00037
00038 typedef struct {
00039 double p1[4];
00040 double q1[4];
00041 double p2[4];
00042 double q2[4];
00043 double phot[4][100];
00044 int nphot; } MOMSET_DEF;
00045
00046 #define MOMSET COMMON_BLOCK(MOMSET_DEF, momset)
00047 COMMON_BLOCK_DEF(MOMSET_DEF,MOMSET);
00048
00049
00050
00051
00052 PROTOCCALLSFSUB1(GLIMIT,glimit,INT)
00053 #define GLIMIT(LENMX) CCALLSFSUB1(GLIMIT,glimit,INT,LENMX)
00054
00055 PROTOCCALLSFSUB1(DUMPS,dumps,INT)
00056 #define DUMPS(NOUT) CCALLSFSUB1(DUMPS,dumps,INT,NOUT)
00057
00058 PROTOCCALLSFSUB3(BHWIDE,bhwide,INT,DOUBLEV,INTV)
00059 #define BHWIDE(MODE,XPAR,NPAR) CCALLSFSUB3(BHWIDE,bhwide,INT,DOUBLEV,INTV,MODE,XPAR,NPAR)
00060
00061 PROTOCCALLSFSUB3(MARINI, marini, INT, INT, INT)
00062 #define MARINI(IJKLIN, NTOTIN, NTOT2N) CCALLSFSUB3(MARINI, marini, INT, INT, INT, IJKLIN, NTOTIN, NTOT2N)
00063
00064 extern "C" {
00065 extern double ranmarr_();
00066 extern void marran_(float* rvec, int* nma);
00067 extern void ecuran_(double* rvec, int* nma);
00068 extern void carran_(double* rvec, int* nma);
00069 }
00070
00071 double ranmarr_()
00072 {
00073 return BhwideRandom::random();
00074 }
00075
00076 void marran_(float* rvec, int* nma)
00077 {
00078 int nmax = *nma;
00079 assert(nmax<100);
00080 double rvecd[100];
00081 BhwideRandom::FlatArray(rvecd, nmax);
00082 for(int i=0; i<nmax; i++) rvec[i]=rvecd[i];
00083 }
00084
00085 void carran_(double* rvec, int* nma)
00086 {
00087 int nmax = *nma;
00088 assert(nmax<100);
00089 double rvecd[100];
00090 BhwideRandom::FlatArray(rvecd, nmax);
00091 for(int i=0; i<nmax; i++) rvec[i]=rvecd[i];
00092 }
00093
00094 void ecuran_(double* rvec, int* nma)
00095 {
00096 int nmax = *nma;
00097 assert(nmax<100);
00098 double rvecd[100];
00099 BhwideRandom::FlatArray(rvecd, nmax);
00100 for(int i=0; i<nmax; i++) rvec[i]=rvecd[i];
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110 Bhwide::Bhwide(const string& name, ISvcLocator* pSvcLocator):Algorithm( name, pSvcLocator )
00111 {
00112 declareProperty("CMEnergy", m_cmEnergy = 3.097);
00113 declareProperty("EleMinThetaAngle", m_ThMine = 22);
00114 declareProperty("EleMaxThetaAngle", m_ThMaxe = 158);
00115 declareProperty("PosMinThetaAngle", m_ThMinp = 22);
00116 declareProperty("PosMaxThetaAngle", m_ThMaxp = 158);
00117 declareProperty("EleMinEnergy", m_EnMine = 0.01);
00118 declareProperty("PosMinEnergy", m_EnMinp = 0.01);
00119 declareProperty("Acollinearity", m_Acolli = 10);
00120 declareProperty("SoftPhotonCut", m_infraredCut = 1E-5);
00121 declareProperty("VacuumPolarization", m_keyPia = 3);
00122 declareProperty("KeyMod", m_keyMod = 2);
00123 declareProperty("KeyLib", m_keyLib = 2);
00124 declareProperty("EWC", m_keyEwc = 1);
00125 m_initSeed.clear();
00126
00127
00128 }
00129
00130 StatusCode Bhwide::initialize(){
00131
00132 MsgStream log(messageService(), name());
00133
00134 log << MSG::INFO << "Bhwide initialize" << endreq;
00135
00136 static const bool CREATEIFNOTTHERE(true);
00137 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
00138 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
00139 {
00140 log << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
00141 return RndmStatus;
00142 }
00143 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine("Bhwide");
00144 engine->showStatus();
00145 BhwideRandom::setRandomEngine(engine);
00146
00147 GLIMIT(50000);
00148
00152 double WTMAX = 3.0;
00153 double AMAZ = 91.1882;
00154 double GAMMZ = 2.4952;
00155 double SINW2 = 0.22225;
00156 double AMTOP = 174.3;
00157 double AMHIG = 115.0;
00159 int KeyWgt = 0;
00161 int KeyRnd = 1;
00162 int KeyCha = 0;
00163 int KeyZof = 0;
00164 int KeyOpt = 1000*KeyZof +100*KeyCha +10*KeyWgt + KeyRnd;
00165
00166 int KeyEWC = m_keyEwc;
00167
00168 int KeyLib = m_keyLib;
00169
00170 int KeyMod = m_keyMod;
00171 int KeyPia = m_keyPia;
00172 int KeyRad = 1000*KeyEWC + 100*KeyLib + 10*KeyMod + KeyPia;
00173
00175 npar[0]= KeyOpt;
00176 npar[1]= KeyRad;
00177
00178 xpar[0] = m_cmEnergy;
00179 xpar[1] = m_ThMinp;
00180 xpar[2] = m_ThMaxp;
00181 xpar[3] = m_ThMine;
00182 xpar[4] = m_ThMaxe;
00183 xpar[5] = m_EnMinp;
00184 xpar[6] = m_EnMine;
00185 xpar[7] = m_Acolli;
00186 xpar[8] = m_infraredCut;
00187 xpar[9] = WTMAX;
00188 xpar[10] = AMAZ;
00189 xpar[11] = GAMMZ;
00190 xpar[12] = SINW2;
00191 xpar[13] = AMTOP;
00192 xpar[14] = AMHIG;
00193
00194
00195
00196 BHWIDE(-1,xpar,npar);
00197
00198 return StatusCode::SUCCESS;
00199 }
00200
00201 StatusCode Bhwide::execute()
00202 {
00203 MsgStream log(messageService(), name());
00204 log << MSG::INFO << "Bhwide executing" << endreq;
00205
00206
00207 BHWIDE( 0,xpar,npar);
00208
00209 if( log.level() < MSG::INFO )
00210 {
00211 DUMPS(6);
00212
00213
00214 }
00215
00216 int npart = 0;
00217
00218
00219 GenEvent* evt = new GenEvent(1,1);
00220
00221 GenVertex* prod_vtx = new GenVertex();
00222
00223 evt->add_vertex( prod_vtx );
00224
00225
00226 GenParticle* p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p1[0], MOMSET.p1[1],
00227 MOMSET.p1[2], MOMSET.p1[3]),
00228 -11, 3);
00229 p->suggest_barcode( ++npart );
00230 prod_vtx->add_particle_in(p);
00231
00232
00233 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q1[0], MOMSET.q1[1], MOMSET.q1[2], MOMSET.q1[3]),
00234 11, 3);
00235 p->suggest_barcode( ++npart );
00236 prod_vtx->add_particle_in(p);
00237
00238
00239 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p2[0], MOMSET.p2[1],
00240 MOMSET.p2[2], MOMSET.p2[3]),
00241 -11, 1);
00242 p->suggest_barcode( ++npart );
00243 prod_vtx->add_particle_out(p);
00244
00245
00246 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q2[0], MOMSET.q2[1], MOMSET.q2[2], MOMSET.q2[3]),
00247 11, 1);
00248 p->suggest_barcode( ++npart );
00249 prod_vtx->add_particle_out(p);
00250
00251 int iphot=0;
00252 for (iphot=0; iphot<MOMSET.nphot; iphot++)
00253 {
00254
00255 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.phot[0][iphot], MOMSET.phot[1][iphot],
00256 MOMSET.phot[2][iphot], MOMSET.phot[3][iphot]),
00257 22, 1);
00258 p->suggest_barcode( ++npart );
00259 prod_vtx->add_particle_out(p);
00260 }
00261
00262 if( log.level() < MSG::INFO )
00263 {
00264 evt->print();
00265 }
00266
00267
00268 SmartDataPtr<McGenEventCol> anMcCol(eventSvc(), "/Event/Gen");
00269 if (anMcCol!=0)
00270 {
00271
00272 MsgStream log(messageService(), name());
00273 log << MSG::INFO << "Add McGenEvent to existing collection" << endreq;
00274 McGenEvent* mcEvent = new McGenEvent(evt);
00275 anMcCol->push_back(mcEvent);
00276 }
00277 else
00278 {
00279
00280 McGenEventCol *mcColl = new McGenEventCol;
00281 McGenEvent* mcEvent = new McGenEvent(evt);
00282 mcColl->push_back(mcEvent);
00283 StatusCode sc = eventSvc()->registerObject("/Event/Gen",mcColl);
00284 if (sc != StatusCode::SUCCESS)
00285 {
00286 log << MSG::ERROR << "Could not register McGenEvent" << endreq;
00287 delete mcColl;
00288 delete evt;
00289 delete mcEvent;
00290 return StatusCode::FAILURE;
00291 }
00292 else
00293 {
00294 log << MSG::INFO << "McGenEventCol created and " << npart <<" particles stored in McGenEvent" << endreq;
00295 }
00296 }
00297
00298 return StatusCode::SUCCESS;
00299 }
00300
00301 StatusCode Bhwide::finalize()
00302 {
00303 MsgStream log(messageService(), name());
00304
00305 BHWIDE( 2,xpar,npar);
00306
00307 log << MSG::INFO << "Bhwide finalized" << endreq;
00308
00309 return StatusCode::SUCCESS;
00310 }