BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
Eepipi/Eepipi-00-00-06/src/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/GenVertex.h"
19#include "HepMC/GenParticle.h"
20
21#include "GaudiKernel/MsgStream.h"
22#include "GaudiKernel/ISvcLocator.h"
23#include "GaudiKernel/AlgFactory.h"
24#include "GaudiKernel/DataSvc.h"
25#include "GaudiKernel/SmartDataPtr.h"
26
27#include "GeneratorObject/McGenEvent.h"
28#include "CLHEP/Vector/LorentzVector.h"
29#include "cfortran/cfortran.h"
30
31#include <stdlib.h>
32#include <time.h>
33
34 typedef 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-
41 } MOMSET_DEF;
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//common/cosee/setcos
55typedef struct {
56 double setcos;
57} COSEE_DEF;
58#define COSEE COMMON_BLOCK(COSEE_DEF, cosee)
60
61//common/MCTRUTH/mccheck
62typedef struct {
65#define MCTRUTH COMMON_BLOCK(MCTRUTH_DEF, mctruth)
67
68//--//Unify Eepipi random engine with Bes random servive
69extern "C" {
70 extern float flat_();
71}
72
73float flat_(){
74 float rr;
75 double rd=EepipiRandom::random();
76// std::cout<<"EepipiRandom::random()="<<rd<<endl;
77 rr=(float)rd;
78 return (float)EepipiRandom::random();
79 // return rr;
80}
81extern "C" {
82 extern void intxs_();
83}
84
85
86PROTOCCALLSFSUB1(GEVENT,gevent,INT)
87#define GEVENT(NEVENTS) CCALLSFSUB1(GEVENT,gevent,INT,NEVENTS)
88
89
90Eepipi::Eepipi(const string& name, ISvcLocator* pSvcLocator):Algorithm( name, pSvcLocator )
91{
92 declareProperty("Ecms", m_Ecms = 3.65); // Ecm = sqrt(s) [GeV]
93// declareProperty("cosee", m_cosee = 0.99); // set costheta for e+ e- in final state
94 declareProperty("WriteMC", m_mctruth = 0); //write out the MC truth of final state to "pdata1.dat"
95}
96
97StatusCode Eepipi::initialize(){
98
99 MsgStream log(messageService(), name());
100
101 log << MSG::INFO << "Eepipi initialize" << endreq;
102
103 //set Bes unified random engine
104 static const bool CREATEIFNOTTHERE(true);
105 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
106 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
107 {
108 log << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
109 return RndmStatus;
110 }
111 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine("Eepipi");
112 std::cout<<"==============================="<<engine<<endl;
114 // *****************
115 MCTRUTH.mccheck=m_mctruth;
116 BEAMENERGY.ecms=m_Ecms;
117 COSEE.setcos=m_cosee;
118 // std::cout<<"m_Ires= "<<m_Ires<<endl;
119
120 getMaxEvent();
121 std::cout<<"m_evtMax = "<<m_evtMax<<std::endl;
122 intxs_();
123 GEVENT(m_evtMax);
124
125 return StatusCode::SUCCESS;
126}
127
128static int evtgen=1;
129StatusCode Eepipi::execute()
130{
131 MsgStream log(messageService(), name());
132
133
134 int npart = 0;
135 int pid1,pid2,pid3,pid4,pst1,pst2;
136 pid1 = 11;
137 pid2 =-11;
138 pid3 = 211;
139 pid4 =-211;
140 pst1 = 1;
141 pst2 = 1;
142
143
144
145 // Fill event information
146 GenEvent* evt = new GenEvent(1,1);
147
148 GenVertex* prod_vtx = new GenVertex();
149// prod_vtx->add_particle_out( p );
150 evt->add_vertex( prod_vtx );
151
152 // incoming beam e- HepLorentzVector(px,py,pz,energy) required!
153 GenParticle* p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p1[1][evtgen], MOMSET.p1[2][evtgen],
154 MOMSET.p1[3][evtgen], MOMSET.p1[0][evtgen]),
155 11, 3);
156 p->suggest_barcode( ++npart );
157 prod_vtx->add_particle_in(p);
158
159// std::cout<<"incoming beam e+"<<endl;
160 // incoming beam e+, e+ moving along the z-direction
161 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q1[1][evtgen], MOMSET.q1[2][evtgen],
162 MOMSET.q1[3][evtgen], MOMSET.q1[4][evtgen]),
163 -11, 3);
164
165 p->suggest_barcode( ++npart );
166 prod_vtx->add_particle_in(p);
167
168 // scattered lepton +
169 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p2[1][evtgen], MOMSET.p2[2][evtgen],
170 MOMSET.p2[3][evtgen], MOMSET.p2[0][evtgen]),
171 pid1,pst1);
172 p->suggest_barcode( ++npart );
173 prod_vtx->add_particle_out(p);
174
175 // scattered lepton -
176 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q2[1][evtgen], MOMSET.q2[2][evtgen],
177 MOMSET.q2[3][evtgen], MOMSET.q2[0][evtgen]),
178 pid2, pst2);
179 p->suggest_barcode( ++npart );
180 prod_vtx->add_particle_out(p);
181
182 // outgoing pi+
183 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p3[1][evtgen], MOMSET.p3[2][evtgen],
184 MOMSET.p3[3][evtgen], MOMSET.p3[0][evtgen]),
185 pid3,pst1);
186 p->suggest_barcode( ++npart );
187 prod_vtx->add_particle_out(p);
188
189 //outgoing pi-
190 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q3[1][evtgen], MOMSET.q3[2][evtgen],
191 MOMSET.q3[3][evtgen], MOMSET.q3[0][evtgen]),
192 pid4, pst2);
193 p->suggest_barcode( ++npart );
194 prod_vtx->add_particle_out(p);
195
196
197
198 evtgen++;
199
200 if( log.level() < MSG::INFO )
201 {
202 evt->print();
203 }
204
205 // Check if the McCollection already exists
206 SmartDataPtr<McGenEventCol> anMcCol(eventSvc(), "/Event/Gen");
207 if (anMcCol!=0)
208 {
209 // Add event to existing collection
210 MsgStream log(messageService(), name());
211 log << MSG::INFO << "Add McGenEvent to existing collection" << endreq;
212 McGenEvent* mcEvent = new McGenEvent(evt);
213 anMcCol->push_back(mcEvent);
214 }
215 else
216 {
217 // Create Collection and add to the transient store
218 McGenEventCol *mcColl = new McGenEventCol;
219 McGenEvent* mcEvent = new McGenEvent(evt);
220 mcColl->push_back(mcEvent);
221 StatusCode sc = eventSvc()->registerObject("/Event/Gen",mcColl);
222 if (sc != StatusCode::SUCCESS)
223 {
224 log << MSG::ERROR << "Could not register McGenEvent" << endreq;
225 delete mcColl;
226 delete evt;
227 delete mcEvent;
228 return StatusCode::FAILURE;
229 }
230 else
231 {
232 // log << MSG::INFO << "McGenEventCol created and " << npart <<" particles stored in McGenEvent" << endreq;
233 }
234 }
235
236 return StatusCode::SUCCESS;
237}
238
239StatusCode Eepipi::finalize()
240{
241 MsgStream log(messageService(), name());
242 char delcmd[300];
243 strcpy(delcmd,"cat ");
244 strcat(delcmd,"fresult.dat");
245 system(delcmd);
246
247 std::cout<< "Eepipi finalized" << endl;
248 return StatusCode::SUCCESS;
249}
250
252 IProperty* appPropMgr=0;
253 StatusCode status =
254 serviceLocator()->getService("ApplicationMgr", IProperty::interfaceID(),
255 reinterpret_cast<IInterface*&>( appPropMgr ));
256 if( status.isFailure() ) return status;
257
258 IntegerProperty evtMax("EvtMax",0);
259 status = appPropMgr->getProperty( &evtMax );
260 if (status.isFailure()) return status;
261
262 m_evtMax = evtMax.value();
263 return status;
264}
265
#define MOMSET
Definition: Babayaga.cxx:45
#define BEAMENERGY
Definition: Babayaga.cxx:65
#define GEVENT(NEVENTS)
void intxs_()
#define COMMON_BLOCK_DEF(DEFINITION, NAME)
#define PROTOCCALLSFSUB1(UN, LN, T1)
static void setRandomEngine(CLHEP::HepRandomEngine *randomEngine)
static double random()
Eepipi(const string &name, ISvcLocator *pSvcLocator)
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)=0
Interface to the CLHEP engine.