00001
00002
00003
00004
00005 #include "BesGenModule/BesGenModule.h"
00006 #include "GeneratorModule/GeneratorName.h"
00007
00008
00009 #include "GaudiKernel/MsgStream.h"
00010 #include "GaudiKernel/DataSvc.h"
00011 #include "GaudiKernel/SmartDataPtr.h"
00012
00013
00014
00015
00016
00017
00018 #include "GeneratorObject/McGenEvent.h"
00019 #include "McTruth/DecayMode.h"
00020
00021
00022 #include "HepMC/GenEvent.h"
00023
00024
00025
00026 #include "HepMC/IO_HEPEVT.h"
00027
00028 #include "HepMC/HEPEVT_Wrapper.h"
00029 #include "McTruth/McEvent.h"
00030
00031
00032 #include "GeneratorObject/McGenEvent.h"
00033 #include "GeneratorUtil/StringParse.h"
00034 #include <stdlib.h>
00035 #include <vector>
00036 #include <iostream>
00037 #include <string>
00038
00039 #include "GaudiKernel/ISvcLocator.h"
00040 #include "GaudiKernel/Bootstrap.h"
00041 #include "GaudiKernel/IDataProviderSvc.h"
00042 #include "BesKernel/IBesRndmGenSvc.h"
00043
00044
00045
00046 #include "CLHEP/Random/RandFlat.h"
00047
00048 std::string BesGenModule::besMcGen_stream="PHOTOS_INIT";
00049
00050
00051
00052
00053 extern "C" {
00054 void mainini_(int *,const char *);
00055
00056 void mainexe_(int*,int* mvec);
00057 void mainfin_(int*);
00058 void runi_seed_(int*);
00059 }
00060
00061
00062
00063 using HepMC::IO_HEPEVT;
00064 using HepMC::HEPEVT_Wrapper;
00065
00066
00067
00068
00069
00070
00071
00072
00073 BesGenModule::BesGenModule(const std::string& name,
00074 ISvcLocator* pSvcLocator): GenModule(name,pSvcLocator)
00075 {
00076
00077 besMcGen_stream = "PHOTOS_INIT";
00078
00079
00080 declareProperty("Runcards", runname = "run.cards");
00081 declareProperty("Ratio", Nr = 1);
00082
00083 }
00084
00085 BesGenModule::~BesGenModule()
00086 {}
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 StatusCode BesGenModule::genInitialize() {
00105
00106
00107 MsgStream log(messageService(), name());
00108 log << MSG::INFO << " BES PHOTOS INITIALISING. \n" << endreq;
00109
00110
00111
00112 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, true);
00113 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
00114 {
00115 log << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
00116 return RndmStatus;
00117 }
00118
00119 BesGenModule::besMcGen_stream = "PHOTOS_INIT";
00120
00121 BesGenModule::besMcGen_stream = "PHOTOS111";
00122
00123 m_events = 0;
00124 n=0;
00125 cardname = runname.c_str();
00126
00127
00128 mainini_(&n,cardname);
00129
00130 int theseed;
00131 runi_seed_(&theseed);
00132 p_BesRndmGenSvc->setGenseed(theseed+1);
00133
00134 HepMC::HEPEVT_Wrapper::set_sizeof_int(4);
00135 HepMC::HEPEVT_Wrapper::set_sizeof_real(4);
00136 HepMC::HEPEVT_Wrapper::set_max_number_entries(2000);
00137
00138
00139 return StatusCode::SUCCESS;
00140 }
00141
00142
00143 StatusCode BesGenModule::callGenerator() {
00144
00145 MsgStream log(messageService(), name());
00146 log << MSG::INFO << " BesGenModule generating. \n" << endreq;
00147
00148 StatusCode status = StatusCode::SUCCESS;
00149 int iq;
00150
00151
00152
00153
00154 mainexe_(&Nr,mvec);
00155
00156
00157
00158
00159
00160
00161
00162 McEvent* aMcEvent = new McEvent;
00163 StatusCode sc = eventSvc()->registerObject("/Event/MC",aMcEvent);
00164
00165
00166 SmartDataPtr<DecayMode> anMcCol(eventSvc(), "/Event/MC/DecayMode");
00167 if (anMcCol!=0) {
00168
00169 }
00170 else {
00171
00172 DecayMode *decayMode = new DecayMode;
00173 decayMode->putData(mvec, 10);
00174 StatusCode sc = eventSvc()->registerObject("/Event/MC/DecayMode",decayMode);
00175 }
00176
00177
00178 SmartDataPtr<DecayMode> aMcCol(eventSvc(), "/Event/MC/DecayMode");
00179 if (aMcCol!=0) {
00180
00181 }
00182
00183
00184
00185
00186
00187
00188 ++m_events;
00189
00190
00191
00192 log << MSG::INFO << " BESGenModule generating done. \n" << endreq;
00193 return status;
00194
00195 }
00196
00197
00198 StatusCode BesGenModule::genFinalize() {
00199
00200 MsgStream log(messageService(), name());
00201 mainfin_(&n);
00202 log << MSG:: INFO << " BESGenModule Ending... \n" << endreq;
00203 return StatusCode::SUCCESS;
00204 }
00205
00206 StatusCode BesGenModule::fillEvt(GenEvent* evt) {
00207
00208 MsgStream log(messageService(), name());
00209 log << MSG:: INFO << " BESGenModule Filling... \n" << endreq;
00210
00211 evt->set_event_number(m_events);
00212 HepMC::IO_HEPEVT hepio;
00213 hepio.fill_next_event(evt);
00214
00215
00216
00217
00218 return StatusCode::SUCCESS;
00219 }
00220
00221