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 
8 
12 
15 
16 using namespace edm;
17 using namespace std;
18 
19 #include "HepMC/IO_HEPEVT.h"
20 #include "HepMC/HEPEVT_Wrapper.h"
21 // #include "HepMC/ConvertHEPEVT.h"
22 // #include "HepMC/CBhepevt.h"
23 #include "HepMC/WeightContainer.h"
24 
25 
26 #define KI_BHG_INIT ki_bhg_init_
27 extern "C" {
28  void KI_BHG_INIT(long& seed);
29 }
30 
31 #define BHSETPARAM bhsetparam_
32 extern "C" {
33  void BHSETPARAM(int* iparam, float* fparam, const char* cparam, int length);
34 }
35 
36 #define KI_BHG_FILL ki_bhg_fill_
37 extern "C" {
38  void KI_BHG_FILL(int& iret, float& weight);
39 }
40 
41 #define KI_BHG_STAT ki_bhg_stat_
42 extern "C" {
43  void KI_BHG_STAT(int &iret);
44 }
45 
46 
47 // HepMC::ConvertHEPEVT conv;
48 //include "HepMC/HEPEVT_Wrapper.h"
49 static HepMC::HEPEVT_Wrapper wrapper;
50 static HepMC::IO_HEPEVT conv;
51 
52 
54  int iret=0;
55  call_ki_bhg_stat(iret);
56 }
57 
58 
60  evt(0),
61  isInitialized_(false)
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  produces<HepMCProduct>();
87  produces<GenEventInfoProduct>();
88  produces<GenRunInfoProduct, InRun>();
89 
90  cout << "BeamHaloProducer: starting event generation ... " << endl;
91 }
92 
93 
95 {
96 }
97 
98 void BeamHaloProducer::setRandomEngine(CLHEP::HepRandomEngine* v) {
100 }
101 
103 {
104  if(!isInitialized_) {
105  isInitialized_ = true;
106  RandomEngineSentry<BeamHaloProducer> randomEngineSentry(this, lumi.index());
107 
108  // -- initialisation
109  long seed = 1; // This seed is not actually used
110  call_ki_bhg_init(seed);
111  }
112 }
113 
115 
116  RandomEngineSentry<BeamHaloProducer> randomEngineSentry(this, e.streamID());
117 
118  // cout << "in produce " << endl;
119 
120  // auto_ptr<HepMCProduct> bare_product(new HepMCProduct());
121 
122  // cout << "apres autoptr " << endl;
123 
124  int iret=0;
125  float weight = 0;
126  call_ki_bhg_fill(iret, weight);
127 
128 // Throw an exception if call_ki_bhg_fill(...) fails. Use the EventCorruption
129 // exception since it maps onto SkipEvent which is what we want to do here.
130 
131  if( iret < 0 )
133  << "BeamHaloProducer: function call_ki_bhg_fill returned " << iret << endl;
134 
135  // cout << "apres fortran " << endl;
136 
137 
138  // HepMC::GenEvent* evt = conv.getGenEventfromHEPEVT();
139  // HepMC::GenEvent* evt = conv.read_next_event(); seems to be broken (?)
140  evt = new HepMC::GenEvent();
141 
142  for (int theindex = 1; theindex<=wrapper.number_entries(); theindex++) {
143  HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(wrapper.x(theindex),wrapper.y(theindex),wrapper.z(theindex),wrapper.t(theindex)));
144  HepMC::FourVector p(wrapper.px(theindex),wrapper.py(theindex),wrapper.pz(theindex),wrapper.e(theindex));
145  HepMC::GenParticle* Part =
146  new HepMC::GenParticle(p,wrapper.id(theindex),wrapper.status(theindex));
147  Vtx->add_particle_out(Part);
148  evt->add_vertex(Vtx);
149  }
150 
151  evt->set_event_number(e.id().event());
152 
153  HepMC::WeightContainer& weights = evt -> weights();
154  weights.push_back(weight);
155  // evt->print();
156  std::auto_ptr<HepMCProduct> CMProduct(new HepMCProduct());
157  if (evt) CMProduct->addHepMCData(evt);
158  e.put(CMProduct);
159 
160  auto_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(evt));
161  e.put(genEventInfo);
162 }
163 
165 {
166  // just create an empty product
167  // to keep the EventContent definitions happy
168  // later on we might put the info into the run info that this is a PGun
169  auto_ptr<GenRunInfoProduct> genRunInfo( new GenRunInfoProduct() );
170  run.put( genRunInfo );
171 }
172 
173 bool BeamHaloProducer::call_bh_set_parameters(int* ival, float* fval, const std::string cval_string) {
174  BHSETPARAM(ival,fval,cval_string.c_str(),cval_string.length());
175  return true;
176 }
177 
179  KI_BHG_INIT(seed);
180  return true;
181 }
182 
184  KI_BHG_FILL(iret,weight);
185  return true;
186 }
187 
189  KI_BHG_STAT(iret);
190  return true;
191 }
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
LuminosityBlockIndex index() const
static HepMC::IO_HEPEVT conv
void setRandomEngine(CLHEP::HepRandomEngine *v)
tuple lumi
Definition: fjr2json.py:35
#define BHSETPARAM
virtual void beginLuminosityBlock(LuminosityBlock const &, EventSetup const &) override
virtual ~BeamHaloProducer()
Destructor.
virtual void produce(Event &e, const EventSetup &es) override
#define KI_BHG_FILL
HepMC::GenEvent * evt
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
CLHEP::HepRandomEngine * _BeamHalo_randomEngine
Definition: PYR.cc:3
virtual void endRunProduce(Run &r, const EventSetup &es) override
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)
bool call_ki_bhg_stat(int &iret)
edm::EventID id() const
Definition: EventBase.h:56
#define KI_BHG_STAT
StreamID streamID() const
Definition: Event.h:72
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:107
volatile std::atomic< bool > shutdown_flag false
int weight
Definition: histoStyle.py:50
#define KI_BHG_INIT
Definition: Run.h:41
static HepMC::HEPEVT_Wrapper wrapper