test
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>("unsmeared");
87  produces<GenEventInfoProduct>();
88  produces<GenRunInfoProduct, InRun>();
89 
90  usesResource("BeamHaloProducer");
91 
92  cout << "BeamHaloProducer: starting event generation ... " << endl;
93 }
94 
95 
97 {
98 }
99 
100 void BeamHaloProducer::setRandomEngine(CLHEP::HepRandomEngine* v) {
102 }
103 
105 {
106  if(!isInitialized_) {
107  isInitialized_ = true;
108  RandomEngineSentry<BeamHaloProducer> randomEngineSentry(this, lumi.index());
109 
110  // -- initialisation
111  long seed = 1; // This seed is not actually used
112  call_ki_bhg_init(seed);
113  }
114 }
115 
117 
118  RandomEngineSentry<BeamHaloProducer> randomEngineSentry(this, e.streamID());
119 
120  // cout << "in produce " << endl;
121 
122  // auto_ptr<HepMCProduct> bare_product(new HepMCProduct());
123 
124  // cout << "apres autoptr " << endl;
125 
126  int iret=0;
127  float weight = 0;
128  call_ki_bhg_fill(iret, weight);
129 
130 // Throw an exception if call_ki_bhg_fill(...) fails. Use the EventCorruption
131 // exception since it maps onto SkipEvent which is what we want to do here.
132 
133  if( iret < 0 )
135  << "BeamHaloProducer: function call_ki_bhg_fill returned " << iret << endl;
136 
137  // cout << "apres fortran " << endl;
138 
139 
140  // HepMC::GenEvent* evt = conv.getGenEventfromHEPEVT();
141  // HepMC::GenEvent* evt = conv.read_next_event(); seems to be broken (?)
142  evt = new HepMC::GenEvent();
143 
144  for (int theindex = 1; theindex<=wrapper.number_entries(); theindex++) {
145  HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(wrapper.x(theindex),wrapper.y(theindex),wrapper.z(theindex),wrapper.t(theindex)));
146  HepMC::FourVector p(wrapper.px(theindex),wrapper.py(theindex),wrapper.pz(theindex),wrapper.e(theindex));
147  HepMC::GenParticle* Part =
148  new HepMC::GenParticle(p,wrapper.id(theindex),wrapper.status(theindex));
149  Vtx->add_particle_out(Part);
150  evt->add_vertex(Vtx);
151  }
152 
153  evt->set_event_number(e.id().event());
154 
155  HepMC::WeightContainer& weights = evt -> weights();
156  weights.push_back(weight);
157  // evt->print();
158  std::auto_ptr<HepMCProduct> CMProduct(new HepMCProduct());
159  if (evt) CMProduct->addHepMCData(evt);
160  e.put(CMProduct, "unsmeared");
161 
162  auto_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(evt));
163  e.put(genEventInfo);
164 }
165 
167 {
168  // just create an empty product
169  // to keep the EventContent definitions happy
170  // later on we might put the info into the run info that this is a PGun
171  auto_ptr<GenRunInfoProduct> genRunInfo( new GenRunInfoProduct() );
172  run.put( genRunInfo );
173 }
174 
175 bool BeamHaloProducer::call_bh_set_parameters(int* ival, float* fval, const std::string cval_string) {
176  BHSETPARAM(ival,fval,cval_string.c_str(),cval_string.length());
177  return true;
178 }
179 
181  KI_BHG_INIT(seed);
182  return true;
183 }
184 
186  KI_BHG_FILL(iret,weight);
187  return true;
188 }
189 
191  KI_BHG_STAT(iret);
192  return true;
193 }
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:121
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:59
#define KI_BHG_STAT
StreamID streamID() const
Definition: Event.h:80
bool call_ki_bhg_init(long &seed)
tuple cout
Definition: gather_cfg.py:145
void put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Run.h:112
volatile std::atomic< bool > shutdown_flag false
int weight
Definition: histoStyle.py:50
#define KI_BHG_INIT
Definition: Run.h:43
static HepMC::HEPEVT_Wrapper wrapper