BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EeToeeV/src/EeToeeV/Eepipi.cxx
Go to the documentation of this file.
1//*****************************************************************************
2//
3// Eepipi.cxx
4//
5// Algorithm runs e+e- ->e+e- rho0, rho0->pi+pi- precess
6//
7// July 2016-4-29 Rong-Gang Ping to create package for BES3
8// The original fortran code is generated with FDC, consult Prof. Wang Jianxiong
9//*****************************************************************************
10
11// Header for this module:-
12#include "../Eepipi/Eepipi.h"
13#include "../Eepipi/EepipiRandom.h"
14#include "BesKernel/IBesRndmGenSvc.h"
15
16// Framework Related Headers:-
17#include "HepMC/GenEvent.h"
18#include "HepMC/GenParticle.h"
19#include "HepMC/GenVertex.h"
20
21#include "GaudiKernel/AlgFactory.h"
22#include "GaudiKernel/DataSvc.h"
23#include "GaudiKernel/ISvcLocator.h"
24#include "GaudiKernel/MsgStream.h"
25#include "GaudiKernel/SmartDataPtr.h"
26
27#include "CLHEP/Vector/LorentzVector.h"
28#include "GeneratorObject/McGenEvent.h"
29#include "cfortran/cfortran.h"
30
31#include <stdlib.h>
32#include <time.h>
33
34typedef struct {
35 double q1[4][160001]; // e+ beam
36 double p1[4][160001]; // e- beam
37 double q2[4][160001]; // e-
38 double p2[4][160001]; // e+
39 double q3[4][160001]; // pi+
40 double p3[4][160001]; // pi-
42// MOMSET_DEF MOMSET;
43#define MOMSET COMMON_BLOCK( MOMSET_DEF, momset )
45
46// common/beamEnergy/ebeam
47typedef struct {
48 double ecms;
50#define BEAMENERGY COMMON_BLOCK( BEAMENERGY_DEF, beamenergy )
52// BEAMENERGY_DEF,BEAMENERGY
53
54//--//Unify Eepipi random engine with Bes random servive
55extern "C" {
56extern float flat_();
57}
58
59float flat_() {
60 float rr;
61 double rd = EepipiRandom::random();
62 // std::cout<<"EepipiRandom::random()="<<rd<<endl;
63 rr = (float)rd;
64 return (float)EepipiRandom::random();
65 // return rr;
66}
67extern "C" {
68extern void intxs_();
69}
70
71PROTOCCALLSFSUB1( GEVENT, gevent, INT )
72#define GEVENT( NEVENTS ) CCALLSFSUB1( GEVENT, gevent, INT, NEVENTS )
73
74Eepipi::Eepipi( const string& name, ISvcLocator* pSvcLocator )
75 : Algorithm( name, pSvcLocator ) {
76 declareProperty( "Ecms", m_Ecms = 3.65 ); // Ecm = sqrt(s) [GeV]
77}
78
79StatusCode Eepipi::initialize() {
80
81 MsgStream log( msgSvc(), name() );
82
83 log << MSG::INFO << "Eepipi initialize" << endmsg;
84
85 // set Bes unified random engine
86 static const bool CREATEIFNOTTHERE( true );
87 StatusCode RndmStatus = service( "BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE );
88 if ( !RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc )
89 {
90 log << MSG::ERROR << " Could not initialize Random Number Service" << endmsg;
91 return RndmStatus;
92 }
93 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine( "Eepipi" );
94 std::cout << "===============================" << engine << endl;
96 // *****************
97
98 BEAMENERGY.ecms = m_Ecms;
99 // std::cout<<"m_Ires= "<<m_Ires<<endl;
100
101 getMaxEvent();
102 std::cout << "m_evtMax = " << m_evtMax << std::endl;
103 intxs_();
104 GEVENT( m_evtMax );
105
106 return StatusCode::SUCCESS;
107}
108
109static int evtgen = 1;
110StatusCode Eepipi::execute() {
111 MsgStream log( msgSvc(), name() );
112
113 int npart = 0;
114 int pid1, pid2, pid3, pid4, pst1, pst2;
115 pid1 = 11;
116 pid2 = -11;
117 pid3 = 211;
118 pid4 = -211;
119 pst1 = 1;
120 pst2 = 1;
121
122 // Fill event information
123 GenEvent* evt = new GenEvent( 1, 1 );
124
125 GenVertex* prod_vtx = new GenVertex();
126 // prod_vtx->add_particle_out( p );
127 evt->add_vertex( prod_vtx );
128
129 // incoming beam e- HepLorentzVector(px,py,pz,energy) required!
130 GenParticle* p =
131 new GenParticle( CLHEP::HepLorentzVector( MOMSET.p1[1][evtgen], MOMSET.p1[2][evtgen],
132 MOMSET.p1[3][evtgen], MOMSET.p1[0][evtgen] ),
133 11, 3 );
134 p->suggest_barcode( ++npart );
135 prod_vtx->add_particle_in( p );
136
137 // std::cout<<"incoming beam e+"<<endl;
138 // incoming beam e+, e+ moving along the z-direction
139 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q1[1][evtgen], MOMSET.q1[2][evtgen],
140 MOMSET.q1[3][evtgen], MOMSET.q1[4][evtgen] ),
141 -11, 3 );
142
143 p->suggest_barcode( ++npart );
144 prod_vtx->add_particle_in( p );
145
146 // scattered lepton +
147 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p2[1][evtgen], MOMSET.p2[2][evtgen],
148 MOMSET.p2[3][evtgen], MOMSET.p2[0][evtgen] ),
149 pid1, pst1 );
150 p->suggest_barcode( ++npart );
151 prod_vtx->add_particle_out( p );
152
153 // scattered lepton -
154 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q2[1][evtgen], MOMSET.q2[2][evtgen],
155 MOMSET.q2[3][evtgen], MOMSET.q2[0][evtgen] ),
156 pid2, pst2 );
157 p->suggest_barcode( ++npart );
158 prod_vtx->add_particle_out( p );
159
160 // outgoing pi+
161 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p3[1][evtgen], MOMSET.p3[2][evtgen],
162 MOMSET.p3[3][evtgen], MOMSET.p3[0][evtgen] ),
163 pid3, pst1 );
164 p->suggest_barcode( ++npart );
165 prod_vtx->add_particle_out( p );
166
167 // outgoing pi-
168 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q3[1][evtgen], MOMSET.q3[2][evtgen],
169 MOMSET.q3[3][evtgen], MOMSET.q3[0][evtgen] ),
170 pid4, pst2 );
171 p->suggest_barcode( ++npart );
172 prod_vtx->add_particle_out( p );
173
174 evtgen++;
175
176 if ( log.level() < MSG::INFO ) { evt->print(); }
177
178 // Check if the McCollection already exists
179 SmartDataPtr<McGenEventCol> anMcCol( eventSvc(), "/Event/Gen" );
180 if ( anMcCol != 0 )
181 {
182 // Add event to existing collection
183 MsgStream log( msgSvc(), name() );
184 log << MSG::INFO << "Add McGenEvent to existing collection" << endmsg;
185 McGenEvent* mcEvent = new McGenEvent( evt );
186 anMcCol->push_back( mcEvent );
187 }
188 else
189 {
190 // Create Collection and add to the transient store
191 McGenEventCol* mcColl = new McGenEventCol;
192 McGenEvent* mcEvent = new McGenEvent( evt );
193 mcColl->push_back( mcEvent );
194 StatusCode sc = eventSvc()->registerObject( "/Event/Gen", mcColl );
195 if ( sc != StatusCode::SUCCESS )
196 {
197 log << MSG::ERROR << "Could not register McGenEvent" << endmsg;
198 delete mcColl;
199 delete evt;
200 delete mcEvent;
201 return StatusCode::FAILURE;
202 }
203 else
204 {
205 // log << MSG::INFO << "McGenEventCol created and " << npart <<" particles stored in
206 // McGenEvent" << endmsg;
207 }
208 }
209
210 return StatusCode::SUCCESS;
211}
212
213StatusCode Eepipi::finalize() {
214 MsgStream log( msgSvc(), name() );
215 char delcmd[300];
216 strcpy( delcmd, "cat " );
217 strcat( delcmd, "fresult.dat" );
218 system( delcmd );
219
220 std::cout << "Eepipi finalized" << endl;
221 return StatusCode::SUCCESS;
222}
223
224StatusCode Eepipi::getMaxEvent() {
225 IProperty* appPropMgr = 0;
226 StatusCode status =
227 serviceLocator()->getService( "ApplicationMgr", IProperty::interfaceID(),
228 reinterpret_cast<IInterface*&>( appPropMgr ) );
229 if ( status.isFailure() ) return status;
230
231 IntegerProperty evtMax( "EvtMax", 0 );
232 status = appPropMgr->getProperty( &evtMax );
233 if ( status.isFailure() ) return status;
234
235 m_evtMax = evtMax.value();
236 return status;
237}
double p2[4]
double p1[4]
#define MOMSET
Definition Babayaga.cxx:43
#define BEAMENERGY
Definition Babayaga.cxx:63
void intxs_()
COMMON_BLOCK_DEF(MOMSET_DEF, MOMSET)
#define GEVENT(NEVENTS)
void intxs_()
ObjectVector< McGenEvent > McGenEventCol
IMessageSvc * msgSvc()
static void setRandomEngine(CLHEP::HepRandomEngine *randomEngine)
static double random()
Eepipi(const string &name, ISvcLocator *pSvcLocator)
StatusCode initialize()
StatusCode execute()
StatusCode finalize()
StatusCode getMaxEvent()
const double ecms
Definition inclkstar.cxx:26
PROTOCCALLSFSUB1(RLXDRESETF, rlxdresetf, INTV)