CMS 3D CMS Logo

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