CMS 3D CMS Logo

BeamHaloSource.cc

Go to the documentation of this file.
00001 
00002 #include "GeneratorInterface/BeamHaloGenerator/interface/BeamHaloSource.h"
00003 
00004 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/ServiceRegistry/interface/Service.h"
00007 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00008 
00009 #include <iostream>
00010 #include "time.h"
00011 
00012 using namespace edm;
00013 using namespace std;
00014 
00015 #include "HepMC/IO_HEPEVT.h"
00016 #include "HepMC/HEPEVT_Wrapper.h"
00017 // #include "HepMC/ConvertHEPEVT.h"
00018 // #include "HepMC/CBhepevt.h"
00019 #include "HepMC/WeightContainer.h"
00020 
00021 
00022 #define KI_BHG_INIT ki_bhg_init_
00023 extern "C" {
00024   void KI_BHG_INIT(long& seed);
00025 }
00026 
00027 #define BHSETPARAM bhsetparam_
00028 extern "C" {
00029   void BHSETPARAM(int* iparam, float* fparam, const char* cparam, int length);
00030 }
00031 
00032 #define KI_BHG_FILL ki_bhg_fill_
00033 extern "C" {
00034     void KI_BHG_FILL(int& iret, float& weight);
00035 }
00036 
00037 #define KI_BHG_STAT ki_bhg_stat_
00038 extern "C" {
00039     void KI_BHG_STAT(int &iret);
00040 }
00041 
00042 
00043 // HepMC::ConvertHEPEVT conv;
00044 //include "HepMC/HEPEVT_Wrapper.h"
00045 HepMC::HEPEVT_Wrapper wrapper;
00046 HepMC::IO_HEPEVT conv;
00047 
00048 
00049 BeamHaloSource::~BeamHaloSource() {
00050         int iret=0;
00051         call_ki_bhg_stat(iret);
00052 }
00053 
00054 
00055 BeamHaloSource::BeamHaloSource( const ParameterSet & pset,
00056                             InputSourceDescription const& desc ) :
00057         GeneratedInputSource(pset, desc), evt(0)
00058 {
00059 
00060    int iparam[6];
00061    float fparam[3];
00062    std::string cparam;
00063  // -- from bhgctrl.inc
00064    iparam[0]  = pset.getUntrackedParameter<int>("GENMOD");
00065    iparam[1]  = pset.getUntrackedParameter<int>("LHC_B1");
00066    iparam[2]  = pset.getUntrackedParameter<int>("LHC_B2");
00067    iparam[3]  = pset.getUntrackedParameter<int>("IW_MUO");
00068    iparam[4]  = pset.getUntrackedParameter<int>("IW_HAD");
00069    iparam[5]  = numberEventsInRun();
00070    iparam[6]  = pset.getUntrackedParameter<int>("OFFSET",0);
00071    iparam[7]  = pset.getUntrackedParameter<int>("shift_bx");
00072    
00073    fparam[0]  = (float)pset.getUntrackedParameter<double>("EG_MIN");
00074    fparam[1]  = (float)pset.getUntrackedParameter<double>("EG_MAX");
00075 
00076    fparam[2] = (float)pset.getUntrackedParameter<double>("BXNS");
00077    fparam[3]  = (float)pset.getUntrackedParameter<double>("W0",1.0);
00078 
00079    cparam     = pset.getUntrackedParameter<std::string>("G3FNAME","input.txt");
00080    call_bh_set_parameters(iparam,fparam,cparam);
00081 
00082 
00083 // -- Seed for randomnumbers
00084     Service<RandomNumberGenerator> rng;
00085     long seed = (long)(rng->mySeed());
00086 
00087 
00088 // -- initialisation
00089    call_ki_bhg_init(seed);
00090 
00091 
00092   produces<HepMCProduct>();
00093   cout << "BeamHaloSource: starting event generation ... " << endl;
00094 
00095 }
00096 
00097 
00098 void BeamHaloSource::clear()
00099 {
00100 }
00101 
00102 bool BeamHaloSource::produce(Event & e) {
00103         // cout << "in produce " << endl;
00104 
00105   //            auto_ptr<HepMCProduct> bare_product(new HepMCProduct());
00106 
00107         // cout << "apres autoptr " << endl;
00108 
00109         int iret=0;
00110         float weight = 0;
00111         call_ki_bhg_fill(iret, weight);
00112 
00113         if( iret < 0 ) return false;
00114 
00115         // cout << "apres fortran " << endl;
00116 
00117 
00118         // HepMC::GenEvent* evt = conv.getGenEventfromHEPEVT();
00119         //      HepMC::GenEvent* evt = conv.read_next_event();  seems to be broken (?)
00120   evt = new HepMC::GenEvent();
00121 
00122   for (int theindex = 1; theindex<=wrapper.number_entries(); theindex++) {
00123   HepMC::GenVertex* Vtx = new  HepMC::GenVertex(HepMC::FourVector(wrapper.x(theindex),wrapper.y(theindex),wrapper.z(theindex),wrapper.t(theindex)));
00124   HepMC::FourVector p(wrapper.px(theindex),wrapper.py(theindex),wrapper.pz(theindex),wrapper.e(theindex));
00125   HepMC::GenParticle* Part = 
00126     new HepMC::GenParticle(p,wrapper.id(theindex),wrapper.status(theindex));
00127   Vtx->add_particle_out(Part); 
00128   evt->add_vertex(Vtx);
00129   }
00130 
00131   evt->set_event_number(event());
00132 
00133         HepMC::WeightContainer& weights = evt -> weights();
00134         weights.push_back(weight);
00135         //      evt->print();
00136   std::auto_ptr<HepMCProduct> CMProduct(new HepMCProduct());
00137   if (evt) CMProduct->addHepMCData(evt );
00138   e.put(CMProduct);
00139     
00140     return true;
00141 }
00142 
00143 
00144 
00145 bool BeamHaloSource::call_bh_set_parameters(int* ival, float* fval, const std::string cval_string) {
00146   BHSETPARAM(ival,fval,cval_string.c_str(),cval_string.length());
00147         return true;
00148 }
00149 
00150 bool BeamHaloSource::call_ki_bhg_init(long& seed) {
00151         KI_BHG_INIT(seed);
00152         return true;
00153 }
00154 
00155 bool BeamHaloSource::call_ki_bhg_fill(int& iret, float& weight) {
00156         KI_BHG_FILL(iret,weight);
00157         return true;
00158 }
00159 
00160 bool BeamHaloSource::call_ki_bhg_stat(int& iret) {
00161         KI_BHG_STAT(iret);
00162         return true;
00163 }
00164 
00165 
00166 
00167 
00168 

Generated on Tue Jun 9 17:36:53 2009 for CMSSW by  doxygen 1.5.4