CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BeamHaloProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <ctime>
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 #define KI_BHG_INIT ki_bhg_init_
26 extern "C" {
27 void KI_BHG_INIT(long& seed);
28 }
29 
30 #define BHSETPARAM bhsetparam_
31 extern "C" {
32 void BHSETPARAM(int* iparam, float* fparam, const char* cparam, int length);
33 }
34 
35 #define KI_BHG_FILL ki_bhg_fill_
36 extern "C" {
37 void KI_BHG_FILL(int& iret, float& weight);
38 }
39 
40 #define KI_BHG_STAT ki_bhg_stat_
41 extern "C" {
42 void KI_BHG_STAT(int& iret);
43 }
44 
45 // HepMC::ConvertHEPEVT conv;
46 //include "HepMC/HEPEVT_Wrapper.h"
47 static HepMC::HEPEVT_Wrapper wrapper;
48 static HepMC::IO_HEPEVT conv;
49 
51  int iret = 0;
52  call_ki_bhg_stat(iret);
53 }
54 
55 BeamHaloProducer::BeamHaloProducer(const ParameterSet& pset) : evt(nullptr), isInitialized_(false) {
56  int iparam[8];
57  float fparam[4];
58  std::string cparam;
59  // -- from bhgctrl.inc
60  iparam[0] = pset.getUntrackedParameter<int>("GENMOD");
61  iparam[1] = pset.getUntrackedParameter<int>("LHC_B1");
62  iparam[2] = pset.getUntrackedParameter<int>("LHC_B2");
63  iparam[3] = pset.getUntrackedParameter<int>("IW_MUO");
64  iparam[4] = pset.getUntrackedParameter<int>("IW_HAD");
65  iparam[5] = 9999999;
66  iparam[6] = pset.getUntrackedParameter<int>("OFFSET", 0);
67  iparam[7] = pset.getUntrackedParameter<int>("shift_bx");
68 
69  fparam[0] = (float)pset.getUntrackedParameter<double>("EG_MIN");
70  fparam[1] = (float)pset.getUntrackedParameter<double>("EG_MAX");
71 
72  fparam[2] = (float)pset.getUntrackedParameter<double>("BXNS");
73  fparam[3] = (float)pset.getUntrackedParameter<double>("W0", 1.0);
74 
75  cparam = pset.getUntrackedParameter<std::string>("G3FNAME", "input.txt");
76  call_bh_set_parameters(iparam, fparam, cparam);
77 
78  produces<HepMCProduct>("unsmeared");
79  produces<GenEventInfoProduct>();
80  produces<GenRunInfoProduct, Transition::EndRun>();
81 
82  usesResource("BeamHaloProducer");
83 
84  cout << "BeamHaloProducer: starting event generation ... " << endl;
85 }
86 
88 
89 void BeamHaloProducer::setRandomEngine(CLHEP::HepRandomEngine* v) { _BeamHalo_randomEngine = v; }
90 
92  if (!isInitialized_) {
93  isInitialized_ = true;
94  RandomEngineSentry<BeamHaloProducer> randomEngineSentry(this, lumi.index());
95 
96  // -- initialisation
97  long seed = 1; // This seed is not actually used
98  call_ki_bhg_init(seed);
99  }
100 }
101 
103  RandomEngineSentry<BeamHaloProducer> randomEngineSentry(this, e.streamID());
104 
105  // cout << "in produce " << endl;
106 
107  // unique_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  // Throw an exception if call_ki_bhg_fill(...) fails. Use the EventCorruption
116  // exception since it maps onto SkipEvent which is what we want to do here.
117 
118  if (iret < 0)
120  << "BeamHaloProducer: function call_ki_bhg_fill returned " << iret << endl;
121 
122  // cout << "apres fortran " << endl;
123 
124  // HepMC::GenEvent* evt = conv.getGenEventfromHEPEVT();
125  // HepMC::GenEvent* evt = conv.read_next_event(); seems to be broken (?)
126  evt = new HepMC::GenEvent();
127 
128  for (int theindex = 1; theindex <= wrapper.number_entries(); theindex++) {
129  HepMC::GenVertex* Vtx = new HepMC::GenVertex(
130  HepMC::FourVector(wrapper.x(theindex), wrapper.y(theindex), wrapper.z(theindex), wrapper.t(theindex)));
131  HepMC::FourVector p(wrapper.px(theindex), wrapper.py(theindex), wrapper.pz(theindex), wrapper.e(theindex));
132  HepMC::GenParticle* Part = new HepMC::GenParticle(p, wrapper.id(theindex), wrapper.status(theindex));
133  Vtx->add_particle_out(Part);
134  evt->add_vertex(Vtx);
135  }
136 
137  evt->set_event_number(e.id().event());
138 
139  HepMC::WeightContainer& weights = evt->weights();
140  weights.push_back(weight);
141  // evt->print();
142  std::unique_ptr<HepMCProduct> CMProduct(new HepMCProduct());
143  if (evt)
144  CMProduct->addHepMCData(evt);
145  e.put(std::move(CMProduct), "unsmeared");
146 
147  unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(evt));
148  e.put(std::move(genEventInfo));
149 }
150 
152  // just create an empty product
153  // to keep the EventContent definitions happy
154  // later on we might put the info into the run info that this is a PGun
155  unique_ptr<GenRunInfoProduct> genRunInfo(new GenRunInfoProduct());
156  run.put(std::move(genRunInfo));
157 }
158 
159 bool BeamHaloProducer::call_bh_set_parameters(int* ival, float* fval, const std::string cval_string) {
160  BHSETPARAM(ival, fval, cval_string.c_str(), cval_string.length());
161  return true;
162 }
163 
165  KI_BHG_INIT(seed);
166  return true;
167 }
168 
170  KI_BHG_FILL(iret, weight);
171  return true;
172 }
173 
175  KI_BHG_STAT(iret);
176  return true;
177 }
~BeamHaloProducer() override
Destructor.
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
LuminosityBlockIndex index() const
static HepMC::IO_HEPEVT conv
void setRandomEngine(CLHEP::HepRandomEngine *v)
#define BHSETPARAM
void beginLuminosityBlock(LuminosityBlock const &, EventSetup const &) override
void produce(Event &e, const EventSetup &es) override
#define KI_BHG_FILL
HepMC::GenEvent * evt
CLHEP::HepRandomEngine * _BeamHalo_randomEngine
Definition: PYR.cc:3
def move
Definition: eostools.py:511
void endRunProduce(Run &r, const EventSetup &es) override
list lumi
Definition: dqmdumpme.py:53
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)
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:109
bool call_ki_bhg_stat(int &iret)
edm::EventID id() const
Definition: EventBase.h:59
#define KI_BHG_STAT
StreamID streamID() const
Definition: Event.h:98
bool call_ki_bhg_init(long &seed)
tuple cout
Definition: gather_cfg.py:144
int weight
Definition: histoStyle.py:51
#define KI_BHG_INIT
Definition: Run.h:45
static HepMC::HEPEVT_Wrapper wrapper