BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BabayagaNLO.cxx
Go to the documentation of this file.
1// #include "HepMC/HEPEVT_Wrapper.h"
2#include "HepMC/IO_HEPEVT.h"
3// #include "HepMC/IO_Ascii.h"
4#include "HepMC/GenEvent.h"
5
6#include "GaudiKernel/ISvcLocator.h"
7#include "GaudiKernel/MsgStream.h"
8#include "GaudiKernel/SmartDataPtr.h"
9
10#include "BabayagaNLO.h"
11#include "BabayagaNLORandom.h"
12#include "BesRndmGenSvc/IBesRndmGenSvc.h"
13#include "CLHEP/Vector/LorentzVector.h"
14#include "GeneratorObject/McGenEvent.h"
15
16#include "boost/filesystem.hpp"
17
18#define fs boost::filesystem
19using namespace HepMC;
20
21#ifdef DECLARE_COMPONENT
23#endif
24
25extern "C" {
26
27extern void bossinterface_( int* xpari, double* xpard );
28extern void init_babayaga_();
29extern void generate_event_( bool& use_unweighted );
30extern void print_statistics_();
31extern void set_ecms_spread_( double& ecms, double& bspread );
32
33// common/momentainitial/pin1,pin2
34extern struct {
35 double pin1[4];
36 double pin2[4];
38
39// common/event_mom/p1,p2,qph
40extern struct {
41 double p1[4], p2[4], qph[4][40];
43
44// common/weights/use_weighted,sdif
45extern struct {
46 double sdif;
49
50// common/babayagainitint/in_conf_spin,nphmax,naccepted,nwhenmax,nover,istopsearch,nneg,ng
51extern struct {
56
57// common/vpcnskf/nskfilepath
58extern struct {
59 char nskfilepath[400];
61}
62
63BabayagaNLO::BabayagaNLO( const std::string& name, ISvcLocator* pSvcLocator )
64 : Algorithm( name, pSvcLocator ) {
65 // enum int_pars
66 //{kChannel,kVerbose,kNsearch,kAlphaRun,kPhMode,kModelVP,kPrecision,kUseWeighted,kDarkMode};
67 // enum dbl_pars
68 //{kEcm,kEspread,kCutTh0,kCutTh1,kCutAColl,kCutEmin,kCutInvMass0,kCutInvMass1,kDarkMass,kDarkWidth,kDarkVec,kDarkAx,kMaxSdif,kScaleVPerr};
69
70 declareProperty( "Channel", m_ch = 0 ); // 0=ee, 1=mumu, 2 = gg
71 declareProperty( "Verbose", m_iverbose = 0 );
72 declareProperty( "Nsearch", m_nsearch = 4000000 ); // event used for maximum search
73 declareProperty( "RunningAlpha", m_arun = 0 ); // alpha running
74 declareProperty( "VPparam", m_iteubn = 0 ); // 0= Jegerlehner, 1 = Teubner, 2 = Novosibirsk
75 declareProperty( "PhotonNumber",
76 m_photmode = -1 ); // maximum number of photon (-1 = unlimited (40))
77 declareProperty( "Precision", m_precision = 0 ); // 0=best, 1=alpha2, 2=born
78
79 declareProperty( "CMSEnergy", m_ecmsinput = 3.686 );
80 declareProperty( "BeamEnergySpread", m_beamspread = 0.0013 );
81
82 declareProperty( "ThetaMin", m_thmin = 10 ); //| Range of charged particles (ee,mumu)
83 declareProperty( "ThetaMax", m_thmax = 170 ); //| or one photon pair (gg)
84 declareProperty( "AcollMax", m_zmax = 180.0 ); // Maximum acollinearity
85 declareProperty( "Emin",
86 m_emin = 0.001 ); // minimum energy of charged tracks/most energetic photons
87 declareProperty( "MinInvMass",
88 m_Minv_min = 0.0 ); //| Range of invariant mass to be generated
89 declareProperty( "MaxInvMass",
90 m_Minv_max = -1.0 ); //| charged (ee,mumu) or at least one photon pair (gg)
91
92 declareProperty( "MaximumVal", m_sdif_max = 1.e-18 ); // starting value for maximum search
93 declareProperty( "ScaleVPerr", m_scale_vperr = 0.0 ); // add hadronic vp error scaled by this
94 // value ( vp_hadr = vp_hadr +
95 // scale*d_hvp, default: no addition)
96
97 declareProperty( "UseWeightedEv", m_weighted = 0 ); // enable generation of weighted events
98 // (default: unweighted)
99
100 declareProperty( "DarkMode", m_darkmode = 0 ); // use dark photon (A') model
101 declareProperty( "DarkMass", m_DarkMass = 0.4 ); // A' mass
102 declareProperty( "DarkWidth", m_DarkWidth = -1.0 ); // A' width (default: point-like)
103 declareProperty( "DarkVectorCoupling", m_DarkVec = 1.e-3 ); //| A'
104 declareProperty( "DarkAxialCoupling", m_DarkAxial = 0 ); //| couplings
105
106 std::string path = "./";
107 if ( getenv( "BABAYAGANLOROOT" ) != NULL )
108 {
109 path = getenv( "BABAYAGANLOROOT" );
110 path += "/share/";
111 }
112 path.append( "vpol_novosibirsk.dat" );
113 declareProperty( "NskFilePath", m_nsk_filepath = path ); // path to nsk VP input file
114}
115
117 MsgStream log( msgSvc(), name() );
118 log << MSG::DEBUG << "BabayagaNLO in initialize()" << endmsg;
119
120 // set Bes unified random engine
121 static const bool CREATEIFNOTTHERE( true );
122 StatusCode RndmStatus = service( "BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE );
123 if ( !RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc )
124 {
125 log << MSG::ERROR << " Could not initialize Random Number Service" << endmsg;
126 return RndmStatus;
127 }
128 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine( "BabayagaNLO" );
130
131 // start initialize
132 int xpari[10];
133 double xpard[14];
134
135 xpari[kChannel] = m_ch;
136 xpari[kVerbose] = m_iverbose;
137 xpari[kNsearch] = m_nsearch;
138 xpari[kAlphaRun] = m_arun;
139 xpari[kPhMode] = m_photmode;
140 xpari[kModelVP] = m_iteubn;
141 xpari[kPrecision] = m_precision;
142 xpari[kUseWeighted] = m_weighted;
143 xpari[kDarkMode] = m_darkmode;
144
145 xpard[kEcm] = m_ecmsinput;
146 xpard[kEspread] = m_beamspread;
147 xpard[kCutTh0] = m_thmin;
148 xpard[kCutTh1] = m_thmax;
149 xpard[kCutAColl] = m_zmax;
150 xpard[kCutEmin] = m_emin;
151 xpard[kCutInvMass0] = m_Minv_min;
152 xpard[kCutInvMass1] = m_Minv_max;
153 xpard[kDarkMass] = m_DarkMass;
154 xpard[kDarkWidth] = m_DarkWidth;
155 xpard[kDarkVec] = m_DarkVec;
156 xpard[kDarkAx] = m_DarkAxial;
157 xpard[kMaxSdif] = m_sdif_max;
158 xpard[kScaleVPerr] = m_scale_vperr;
159
160 using namespace boost::filesystem;
161 path p_nskfile( m_nsk_filepath.data() );
162 if ( !exists( p_nskfile ) && m_arun > 0 && m_iteubn == 2 )
163 {
164 log << MSG::FATAL << "Cannot find Novosibirsk VP file (" << p_nskfile.native()
165 << ")!\n Is the environment variable BABAYAGANLOROOT set?" << endmsg;
166 return StatusCode::FAILURE;
167 }
168
169 m_nsk_filepath = p_nskfile.native();
170 strcpy( vpcnskf_.nskfilepath, m_nsk_filepath.data() );
171
172 bossinterface_( xpari, xpard );
173
175
176 log << MSG::DEBUG << "Finish BabayagaNLO initialize()" << endmsg;
177 return StatusCode::SUCCESS;
178}
179
181 MsgStream log( msgSvc(), name() );
182 log << MSG::DEBUG << "BabayagaNLO in execute()" << endmsg;
183
184 // Fill event information
185 GenEvent* evt = new GenEvent( 1, 1 );
186 GenVertex* prod_vtx = new GenVertex();
187 evt->add_vertex( prod_vtx );
188
189 log << MSG::DEBUG << "check point 1" << endmsg;
190 bool unw = !( m_weighted );
191
192 log << MSG::DEBUG << "check point 2" << endmsg;
193 generate_event_( unw );
194
195 log << MSG::DEBUG << "check point 3" << endmsg;
196 int finalpidm, finalpidp;
197 if ( m_ch == 0 )
198 {
199 finalpidm = 11;
200 finalpidp = -11;
201 }
202 else if ( m_ch == 1 )
203 {
204 finalpidm = 13;
205 finalpidp = -13;
206 }
207 else if ( m_ch == 2 )
208 {
209 finalpidm = 22;
210 finalpidp = 22;
211 }
212 else
213 {
214 finalpidm = 11;
215 finalpidp = -11;
216 }
217
218 double* p1 = momentainitial_.pin1;
219 double* p2 = momentainitial_.pin2;
220 double* p3 = event_mom_.p1;
221 double* p4 = event_mom_.p2;
222
223 // incoming particle -
224 GenParticle* p =
225 new GenParticle( CLHEP::HepLorentzVector( p1[1], p1[2], -p1[3], p1[0] ), 11, 3 );
226 p->suggest_barcode( 1 );
227 prod_vtx->add_particle_in( p );
228
229 // incoming particle +
230 p = new GenParticle( CLHEP::HepLorentzVector( p2[1], p2[2], -p2[3], p2[0] ), -11, 3 );
231 p->suggest_barcode( 2 );
232 prod_vtx->add_particle_in( p );
233
234 log << MSG::DEBUG << "check point 4" << endmsg;
235 // outgoing particle -
236 p = new GenParticle( CLHEP::HepLorentzVector( p3[1], p3[2], -p3[3], p3[0] ), finalpidm, 1 );
237 p->suggest_barcode( 3 );
238 prod_vtx->add_particle_out( p );
239
240 // outgoing particle +
241 p = new GenParticle( CLHEP::HepLorentzVector( p4[1], p4[2], -p4[3], p4[0] ), finalpidp, 1 );
242 p->suggest_barcode( 4 );
243 prod_vtx->add_particle_out( p );
244
245 log << MSG::DEBUG << "check point 5" << endmsg;
246 // photons
247 int id_cntr = 5;
248 for ( int i = 0; i < babayagainitint_.ng; i++ )
249 {
250 double px = event_mom_.qph[1][i];
251 double py = event_mom_.qph[2][i];
252 double pz = -1. * event_mom_.qph[3][i];
253 double eph = event_mom_.qph[0][i];
254 p = new GenParticle( CLHEP::HepLorentzVector( px, py, pz, eph ), 22, 1 );
255 p->suggest_barcode( id_cntr );
256 prod_vtx->add_particle_out( p );
257 id_cntr++;
258 }
259
260 log << MSG::DEBUG << "check point 6" << endmsg;
261 if ( !unw )
262 { // Add dummy particle with diffential cross section as mass
263 p = new GenParticle( CLHEP::HepLorentzVector( 0, 0, 0, weights_.sdif ), 99, 1 );
264 p->suggest_barcode( id_cntr );
265 prod_vtx->add_particle_out( p );
266 id_cntr++;
267 }
268
269 if ( log.level() <= MSG::DEBUG ) { evt->print(); }
270
271 // Check if the McCollection already exists
272 SmartDataPtr<McGenEventCol> anMcCol( eventSvc(), "/Event/Gen" );
273 if ( anMcCol != 0 )
274 {
275 // Add event to existing collection
276 log << MSG::WARNING << "add event" << endmsg;
277 MsgStream log( msgSvc(), name() );
278 log << MSG::INFO << "Add McGenEvent to existing collection" << endmsg;
279 McGenEvent* mcEvent = new McGenEvent( evt );
280 anMcCol->push_back( mcEvent );
281 }
282 else
283 {
284 // Create Collection and add to the transient store
285 log << MSG::WARNING << "create collection" << endmsg;
286 McGenEventCol* mcColl = new McGenEventCol;
287 McGenEvent* mcEvent = new McGenEvent( evt );
288 mcColl->push_back( mcEvent );
289 StatusCode sc = eventSvc()->registerObject( "/Event/Gen", mcColl );
290 if ( sc != StatusCode::SUCCESS )
291 {
292 log << MSG::ERROR << "Could not register McGenEvent" << endmsg;
293 delete mcColl;
294 delete evt;
295 delete mcEvent;
296 return StatusCode::FAILURE;
297 }
298 else { log << MSG::INFO << "McGenEventCol created!" << endmsg; }
299 }
300
301 log << MSG::DEBUG << "before execute() return" << endmsg;
302 return StatusCode::SUCCESS;
303}
304
306 MsgStream log( msgSvc(), name() );
307 log << MSG::INFO << "BabayagaNLO in finalize()" << endmsg;
308
310 return StatusCode::SUCCESS;
311}
int ng
int in_conf_spin
struct @214337157042007332045025275370201147311033014270 momentainitial_
void init_babayaga_()
double pin1[4]
struct @366033172356361027275342303204275345125072327175 vpcnskf_
int nover
void set_ecms_spread_(double &ecms, double &bspread)
double sdif
double pin2[4]
bool use_unweighted
long naccepted
struct @213124374032053315171040157000161342011375010356 babayagainitint_
double qph[4][40]
void print_statistics_()
double p2[4]
double p1[4]
int nwhenmax
void generate_event_(bool &use_unweighted)
struct @133277167203374344147262151032122303311146055065 event_mom_
char nskfilepath[400]
int istopsearch
int nphmax
void bossinterface_(int *xpari, double *xpard)
int nneg
struct @062176164373272207324360012110235007047111322315 weights_
DECLARE_COMPONENT(BesBdkRc)
ObjectVector< McGenEvent > McGenEventCol
IMessageSvc * msgSvc()
static void setRandomEngine(CLHEP::HepRandomEngine *randomEngine)
StatusCode finalize()
BabayagaNLO(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode execute()
StatusCode initialize()
const double ecms
Definition inclkstar.cxx:26