BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
GenModule Class Reference

#include <GenModule.h>

+ Inheritance diagram for GenModule:

Public Member Functions

 GenModule (const std::string &name, ISvcLocator *pSvcLocator)
 
virtual ~GenModule ()
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 
virtual StatusCode genInitialize ()
 
virtual StatusCode genuserInitialize ()
 
virtual StatusCode callGenerator ()
 
virtual StatusCode genFinalize ()
 
virtual StatusCode fillEvt (GenEvent *evt)
 

Protected Member Functions

void StripPartonsInit (void)
 
void StripPartons (GenEvent *evt)
 

Protected Attributes

bool m_fixedMode
 
double m_meanInteractions
 
int m_randomSeed
 
std::vector< int > m_AllPartons
 
std::vector< int > m_StripVector
 
bool m_StripPartonSwitch
 
CLHEP::HepRandomEngine * m_pRandomEngine
 
CLHEP::RandPoisson * m_pPoissonGenerator
 
HepPDT::ParticleDataTable * m_particleTable
 

Detailed Description

Definition at line 41 of file GenModule.h.

Constructor & Destructor Documentation

◆ GenModule()

GenModule::GenModule ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 38 of file GenModule.cxx.

39 : Algorithm(name, pSvcLocator),
42 //---------------------------------------------------------------------------
43{
44 declareProperty("FixedMode",m_fixedMode=true);
45 declareProperty("MeanInt",m_meanInteractions=1.0);
46 declareProperty("RandomSeed",m_randomSeed=1234567);
47 declareProperty("StripPartons",m_StripVector);
48 m_StripVector.push_back(0);
49
50}
CLHEP::RandPoisson * m_pPoissonGenerator
Definition: GenModule.h:68
std::vector< int > m_StripVector
Definition: GenModule.h:61
CLHEP::HepRandomEngine * m_pRandomEngine
Definition: GenModule.h:67
double m_meanInteractions
Definition: GenModule.h:58
int m_randomSeed
Definition: GenModule.h:59
bool m_fixedMode
Definition: GenModule.h:57

◆ ~GenModule()

GenModule::~GenModule ( )
virtual

Definition at line 53 of file GenModule.cxx.

53 {
54 // Delete random number objects if they were created
55
58
59}

Member Function Documentation

◆ callGenerator()

StatusCode GenModule::callGenerator ( )
virtual

Reimplemented in BesGenModule, and SingleParticleGun.

Definition at line 218 of file GenModule.cxx.

218 {
219 //---------------------------------------------------------------------------
220 return StatusCode::SUCCESS;
221}

Referenced by execute().

◆ execute()

StatusCode GenModule::execute ( )

Definition at line 125 of file GenModule.cxx.

125 {
126 //---------------------------------------------------------------------------
127
128 int numToGenerate;
129 StatusCode status;
130
131 MsgStream log(messageService(), name());
132
133 log << MSG::DEBUG << "GenModule::execute()" << endreq;
134
135 // Decide how many interactions to generate
136 if(m_fixedMode) {
137 numToGenerate = (int) m_meanInteractions;
138 }
139 else {
140 numToGenerate = m_pPoissonGenerator->fire();
141 }
142
143 // Generate as many interactions as requested
144 for(int i=0; i<numToGenerate; i++) {
145
146 // Call the code that generates an event
147 status = this->callGenerator();
148
149 // Create the MC event and send the GeneratorEvent stored in it to fillEvt
150 GenEvent* evt = new GenEvent(1,1);
151 status = this->fillEvt(evt);
152
153 // Strip out the requested partons here.
155
156 // Check if the McCollection already exists
157 SmartDataPtr<McGenEventCol> anMcCol(eventSvc(), "/Event/Gen");
158 if (anMcCol!=0) {
159 // Add event to existing collection
160 MsgStream log(messageService(), name());
161 log << MSG::INFO << "Add McGenEvent to existing collection" << endreq;
162 McGenEvent* mcEvent = new McGenEvent(evt);
163 anMcCol->push_back(mcEvent);
164 }
165 else {
166 // Create Collection and add to the transient store
167 McGenEventCol *mcColl = new McGenEventCol;
168 McGenEvent* mcEvent = new McGenEvent(evt);
169 mcColl->push_back(mcEvent);
170
171 StatusCode sc = eventSvc()->registerObject("/Event/Gen",mcColl);
172
173 if (sc != StatusCode::SUCCESS) {
174 MsgStream log(messageService(), name());
175 log << MSG::ERROR << "Could not register McGenEvent" << endreq;
176 delete mcColl;
177 delete evt;
178 delete mcEvent;
179 return StatusCode::FAILURE;
180 }
181 else {
182// std::cout << " McGenEventCol made and stored" << std::endl;
183 }
184
185 }
186 }
187
188 // now call the incident service and set the signal.
189 IIncidentSvc *incSvc;
190 service("IncidentSvc",incSvc);
191 incSvc->fireIncident( Incident( name(), "McGenEvent Generated") );
192
193 return status;
194}
ObjectVector< McGenEvent > McGenEventCol
Definition: McGenEvent.h:39
void StripPartons(GenEvent *evt)
Definition: GenModule.cxx:274
bool m_StripPartonSwitch
Definition: GenModule.h:62
virtual StatusCode callGenerator()
Definition: GenModule.cxx:218
virtual StatusCode fillEvt(GenEvent *evt)
Definition: GenModule.cxx:230

◆ fillEvt()

StatusCode GenModule::fillEvt ( GenEvent *  evt)
virtual

Reimplemented in BesGenModule, and SingleParticleGun.

Definition at line 230 of file GenModule.cxx.

230 {
231 //---------------------------------------------------------------------------
232 return StatusCode::SUCCESS;
233}

Referenced by execute().

◆ finalize()

StatusCode GenModule::finalize ( )

Definition at line 197 of file GenModule.cxx.

197 {
198 //---------------------------------------------------------------------------
199
200 StatusCode status = this->genFinalize();
201
202 return status;
203}
virtual StatusCode genFinalize()
Definition: GenModule.cxx:224

◆ genFinalize()

StatusCode GenModule::genFinalize ( )
virtual

Reimplemented in BesGenModule, and SingleParticleGun.

Definition at line 224 of file GenModule.cxx.

224 {
225 //---------------------------------------------------------------------------
226 return StatusCode::SUCCESS;
227}

Referenced by finalize().

◆ genInitialize()

StatusCode GenModule::genInitialize ( )
virtual

Reimplemented in BesGenModule, and SingleParticleGun.

Definition at line 206 of file GenModule.cxx.

206 {
207 //---------------------------------------------------------------------------
208 return StatusCode::SUCCESS;
209}

Referenced by initialize().

◆ genuserInitialize()

StatusCode GenModule::genuserInitialize ( )
virtual

Definition at line 212 of file GenModule.cxx.

212 {
213 //---------------------------------------------------------------------------
214 return StatusCode::SUCCESS;
215}

Referenced by initialize().

◆ initialize()

StatusCode GenModule::initialize ( )

Definition at line 63 of file GenModule.cxx.

63 {
64 //---------------------------------------------------------------------------
65
66 // Inform the user what the mode and conditions are:
67 MsgStream log(messageService(), name());
68
69 // Initialize StripPartons variables
70 if (m_StripVector[0] > 0) {
72 } else {
73 m_StripPartonSwitch = false;
74 m_StripVector.clear();
75 }
76
77
78 // Get the Particle Properties Service
79 IPartPropSvc* p_PartPropSvc;
80 //static const bool CREATEIFNOTTHERE(true);
81 //StatusCode PartPropStatus = service("PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
82 StatusCode PartPropStatus = service("PartPropSvc", p_PartPropSvc);
83 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
84 log << MSG::ERROR << " Could not initialize Particle Properties Service" << endreq;
85 return PartPropStatus;
86 }
87
88 m_particleTable = p_PartPropSvc->PDT();
89
90 m_pRandomEngine = new CLHEP::Ranlux64Engine(m_randomSeed);
91
92 if(m_fixedMode) {
93 if(m_meanInteractions == 1.0) {
94 log << MSG::INFO << "Standard Initialization: Single Interaction Mode "
95 << endreq;
96 }
97 else {
98 log << MSG::INFO << "Fixed Number of Interactions per Event is: "
99 << m_meanInteractions << endreq;
100 }
101 }
102 else {
103 m_pPoissonGenerator = new CLHEP::RandPoisson(*m_pRandomEngine,
105
106 log << MSG::INFO <<
107 "Poisson Distribution of Interactions per Event with Mean: "
108 << m_meanInteractions << endreq;
109 }
110 // Initialize the generator itself
111 StatusCode status = this->genInitialize();
112 if (status.isFailure()) {
113 log << MSG::ERROR << "Could not initialize Generator properly" << endreq;
114 return status;
115 }
116 StatusCode status1 = this->genuserInitialize();
117 if (status1.isFailure()) {
118 log << MSG::ERROR << "Could not initialize user part properly" << endreq;
119 return status1;
120 }
121 return status;
122}
virtual StatusCode genuserInitialize()
Definition: GenModule.cxx:212
void StripPartonsInit(void)
Definition: GenModule.cxx:236
virtual StatusCode genInitialize()
Definition: GenModule.cxx:206
HepPDT::ParticleDataTable * m_particleTable
Definition: GenModule.h:73

◆ StripPartons()

void GenModule::StripPartons ( GenEvent *  evt)
protected

Definition at line 274 of file GenModule.cxx.

275{
276 // for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin();
277 // p != evt->particles_end(); ++p )
278 // {
279 // // std::cout << " PDG, BAR " << (*p)->pdg_id() << " " << (*p)->barcode() << std::endl;
280 // if ( std::find(m_StripVector.begin(),
281 // m_StripVector.end(),
282 // (*p)->pdg_id()) != m_StripVector.end() )
283 // {
284 // // std::cout << " REMOVING " << (*p)->pdg_id() << " " << (*p)->barcode() << std::endl;
285 // HepMC::GenVertex* pvtx = (*p)->production_vertex();
286 // HepMC::GenVertex* evtx = (*p)->end_vertex();
287 // if (pvtx) pvtx->remove_particle(*p);
288 // if (evtx) evtx->remove_particle(*p);
289 // delete *p;
290 // }
291
292 // }
293
294 // Loop on all vertices of the event and remove the particle from the vertex
295 for ( HepMC::GenEvent::vertex_iterator vtx = evt->vertices_begin();
296 vtx != evt->vertices_end(); ++vtx ) {
297 // Loop on all children particles and remove the ones that should be stripped out
298 for ( HepMC::GenVertex::particle_iterator p = (*vtx)-> particles_begin(HepMC::children);
299 p != (*vtx)->particles_end(HepMC::children);
300 ++p ){
301 if ( std::find(m_StripVector.begin(),
302 m_StripVector.end(),
303 (*p)->pdg_id()) != m_StripVector.end() ) {
304 if ( (*p)->end_vertex() ) (*p)->end_vertex()->remove_particle(*p);
305 if ( (*p)->production_vertex() ) (*p)->production_vertex()->remove_particle(*p);
306 delete *p;
307 }
308 }
309 // Loop on all parents particles and remove the ones that should be stripped out
310 for ( HepMC::GenVertex::particle_iterator p = (*vtx)-> particles_begin(HepMC::parents);
311 p != (*vtx)->particles_end(HepMC::parents);
312 ++p ) {
313 if ( std::find(m_StripVector.begin(),
314 m_StripVector.end(),
315 (*p)->pdg_id()) != m_StripVector.end() ) {
316 if ( (*p)->end_vertex() ) (*p)->end_vertex()->remove_particle(*p);
317 if ( (*p)->production_vertex() ) (*p)->production_vertex()->remove_particle(*p);
318 delete *p;
319 }
320 }
321 }
322}

Referenced by execute().

◆ StripPartonsInit()

void GenModule::StripPartonsInit ( void  )
protected

Definition at line 236 of file GenModule.cxx.

237{
238 MsgStream log(messageService(), name());
239
240 for (int i = 1; i < 9; ++i) { m_AllPartons.push_back(i); m_AllPartons.push_back(-i); } // Quarks
241 m_AllPartons.push_back(21); // gluon
242
243 m_StripPartonSwitch = true;
244 m_StripVector.erase(m_StripVector.begin(), m_StripVector.begin()+1);
245 // When the user specifies only the StripPartonSwitch or gives a Particle Code
246 // which is NOT a parton then strip ALL partons
247 if (m_StripVector.size() == 0) {
248 log << MSG::INFO << " !!!! NO SPECIFIC PARTON FOR STRIPOUT WAS REQUESTED => STRIPOUT ALL "
249 << endreq;
251 } else {
252 bool value_ok = true;
253 std::vector<int>::const_iterator i = m_StripVector.begin();
254 do {
255 if ( std::find(m_AllPartons.begin(),
256 m_AllPartons.end(),
257 *i) == m_AllPartons.end() ) value_ok = false;
258 ++i;
259 } while (i != m_StripVector.end() && value_ok);
260 if (!value_ok) {
261 log << MSG::INFO << " !!!! ILEGAL PDG-ID FOR STRIPOUT WAS REQUESTED => STRIPOUT ALL "
262 << endreq;
264 }
265 }
266 log << MSG::INFO << " THE FOLLOWING PARTON(S) WILL BE STRIPED OUT ";
267 for (std::vector<int>::const_iterator ip = m_StripVector.begin(); ip != m_StripVector.end(); ++ip)
268 log << *ip << " ";
269 log << endreq;
270
271}
std::vector< int > m_AllPartons
Definition: GenModule.h:60

Referenced by initialize().

Member Data Documentation

◆ m_AllPartons

std::vector<int> GenModule::m_AllPartons
protected

Definition at line 60 of file GenModule.h.

Referenced by StripPartonsInit().

◆ m_fixedMode

bool GenModule::m_fixedMode
protected

Definition at line 57 of file GenModule.h.

Referenced by execute(), GenModule(), and initialize().

◆ m_meanInteractions

double GenModule::m_meanInteractions
protected

Definition at line 58 of file GenModule.h.

Referenced by execute(), GenModule(), and initialize().

◆ m_particleTable

HepPDT::ParticleDataTable* GenModule::m_particleTable
protected

Definition at line 73 of file GenModule.h.

Referenced by SingleParticleGun::genInitialize(), and initialize().

◆ m_pPoissonGenerator

CLHEP::RandPoisson* GenModule::m_pPoissonGenerator
protected

Definition at line 68 of file GenModule.h.

Referenced by execute(), initialize(), and ~GenModule().

◆ m_pRandomEngine

CLHEP::HepRandomEngine* GenModule::m_pRandomEngine
protected

Definition at line 67 of file GenModule.h.

Referenced by initialize(), and ~GenModule().

◆ m_randomSeed

int GenModule::m_randomSeed
protected

Definition at line 59 of file GenModule.h.

Referenced by GenModule(), and initialize().

◆ m_StripPartonSwitch

bool GenModule::m_StripPartonSwitch
protected

Definition at line 62 of file GenModule.h.

Referenced by execute(), initialize(), and StripPartonsInit().

◆ m_StripVector

std::vector<int> GenModule::m_StripVector
protected

Definition at line 61 of file GenModule.h.

Referenced by GenModule(), initialize(), StripPartons(), and StripPartonsInit().


The documentation for this class was generated from the following files: