CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BeamHaloSource.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <time.h>
3 
7 
9 
12 
13 using namespace edm;
14 using namespace std;
15 
16 #include "HepMC/IO_HEPEVT.h"
17 #include "HepMC/HEPEVT_Wrapper.h"
18 // #include "HepMC/ConvertHEPEVT.h"
19 // #include "HepMC/CBhepevt.h"
20 #include "HepMC/WeightContainer.h"
21 
22 
23 #define KI_BHG_INIT ki_bhg_init_
24 extern "C" {
25  void KI_BHG_INIT(long& seed);
26 }
27 
28 #define BHSETPARAM bhsetparam_
29 extern "C" {
30  void BHSETPARAM(int* iparam, float* fparam, const char* cparam, int length);
31 }
32 
33 #define KI_BHG_FILL ki_bhg_fill_
34 extern "C" {
35  void KI_BHG_FILL(int& iret, float& weight);
36 }
37 
38 #define KI_BHG_STAT ki_bhg_stat_
39 extern "C" {
40  void KI_BHG_STAT(int &iret);
41 }
42 
43 
44 // HepMC::ConvertHEPEVT conv;
45 //include "HepMC/HEPEVT_Wrapper.h"
46 static HepMC::HEPEVT_Wrapper wrapper;
47 static HepMC::IO_HEPEVT conv;
48 
49 
51  int iret=0;
52  call_ki_bhg_stat(iret);
53 }
54 
55 
57  InputSourceDescription const& desc ) :
58  GeneratedInputSource(pset, desc), evt(0)
59 {
60 
61  int iparam[8];
62  float fparam[4];
63  std::string cparam;
64  // -- from bhgctrl.inc
65  iparam[0] = pset.getUntrackedParameter<int>("GENMOD");
66  iparam[1] = pset.getUntrackedParameter<int>("LHC_B1");
67  iparam[2] = pset.getUntrackedParameter<int>("LHC_B2");
68  iparam[3] = pset.getUntrackedParameter<int>("IW_MUO");
69  iparam[4] = pset.getUntrackedParameter<int>("IW_HAD");
70  iparam[5] = numberEventsInRun();
71  iparam[6] = pset.getUntrackedParameter<int>("OFFSET",0);
72  iparam[7] = pset.getUntrackedParameter<int>("shift_bx");
73 
74  fparam[0] = (float)pset.getUntrackedParameter<double>("EG_MIN");
75  fparam[1] = (float)pset.getUntrackedParameter<double>("EG_MAX");
76 
77  fparam[2] = (float)pset.getUntrackedParameter<double>("BXNS");
78  fparam[3] = (float)pset.getUntrackedParameter<double>("W0",1.0);
79 
80  cparam = pset.getUntrackedParameter<std::string>("G3FNAME","input.txt");
81  call_bh_set_parameters(iparam,fparam,cparam);
82 
83 
84 // -- Seed for randomnumbers
87  long seed = (long)(rng->mySeed());
88 
89 
90 // -- initialisation
91  call_ki_bhg_init(seed);
92 
93 
94  produces<HepMCProduct>();
95  cout << "BeamHaloSource: starting event generation ... " << endl;
96 
97 }
98 
99 
101 {
102 }
103 
105  // cout << "in produce " << endl;
106 
107  // auto_ptr<HepMCProduct> bare_product(new HepMCProduct());
108 
109  // cout << "apres autoptr " << endl;
110 
111  int iret=0;
112  float weight = 0;
113  call_ki_bhg_fill(iret, weight);
114 
115  if( iret < 0 ) return false;
116 
117  // cout << "apres fortran " << endl;
118 
119 
120  // HepMC::GenEvent* evt = conv.getGenEventfromHEPEVT();
121  // HepMC::GenEvent* evt = conv.read_next_event(); seems to be broken (?)
122  evt = new HepMC::GenEvent();
123 
124  for (int theindex = 1; theindex<=wrapper.number_entries(); theindex++) {
125  HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(wrapper.x(theindex),wrapper.y(theindex),wrapper.z(theindex),wrapper.t(theindex)));
126  HepMC::FourVector p(wrapper.px(theindex),wrapper.py(theindex),wrapper.pz(theindex),wrapper.e(theindex));
127  HepMC::GenParticle* Part =
128  new HepMC::GenParticle(p,wrapper.id(theindex),wrapper.status(theindex));
129  Vtx->add_particle_out(Part);
130  evt->add_vertex(Vtx);
131  }
132 
133  evt->set_event_number(event());
134 
135  HepMC::WeightContainer& weights = evt -> weights();
136  weights.push_back(weight);
137  // evt->print();
138  std::auto_ptr<HepMCProduct> CMProduct(new HepMCProduct());
139  if (evt) CMProduct->addHepMCData(evt );
140  e.put(CMProduct);
141 
142  return true;
143 }
144 
145 
146 
147 bool BeamHaloSource::call_bh_set_parameters(int* ival, float* fval, const std::string cval_string) {
148  BHSETPARAM(ival,fval,cval_string.c_str(),cval_string.length());
149  return true;
150 }
151 
153  KI_BHG_INIT(seed);
154  return true;
155 }
156 
157 bool BeamHaloSource::call_ki_bhg_fill(int& iret, float& weight) {
158  KI_BHG_FILL(iret,weight);
159  return true;
160 }
161 
163  KI_BHG_STAT(iret);
164  return true;
165 }
166 
167 
168 
169 
170 
T getUntrackedParameter(std::string const &, T const &) const
static HepMC::IO_HEPEVT conv
#define BHSETPARAM
CLHEP::HepRandomEngine * _BeamHalo_randomEngine
Definition: PYR.cc:3
bool call_ki_bhg_stat(int &iret)
#define KI_BHG_FILL
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
bool call_ki_bhg_fill(int &iret, float &weight)
bool call_bh_set_parameters(int *ival, float *fval, const std::string cval_string)
HepMC::GenEvent * evt
static HepMC::HEPEVT_Wrapper wrapper
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
virtual ~BeamHaloSource()
Destructor.
BeamHaloSource(const ParameterSet &, const InputSourceDescription &)
Constructor.
unsigned int numberEventsInRun() const
bool call_ki_bhg_init(long &seed)
virtual bool produce(Event &e)
#define KI_BHG_STAT
tuple cout
Definition: gather_cfg.py:121
#define KI_BHG_INIT
virtual uint32_t mySeed() const =0
Exists for backward compatibility.