7 #include "G4SystemOfUnits.hh"
9 #include "Randomize.hh"
16 _primaryVec = std::vector<G4PrimaryParticle*>(particles->size());
39 for (
size_t i = 0; i < particles->size(); i++) {
42 MCParticle* mcp = (MCParticle*) (*particles)[i];
48 <<
" gen status: " << mcp->getGeneratorStatus() <<
LOG::endl
49 <<
" sim status: " << mcp->getSimulatorStatus() <<
LOG::endl
50 <<
" energy: " << mcp->getEnergy() <<
LOG::endl
51 <<
" time: " << mcp->getTime() <<
LOG::endl
52 <<
" daughters: " << mcp->getDaughters().size() <<
LOG::endl
53 <<
" vertex: ( " << mcp->getVertex()[0] <<
", " << mcp->getVertex()[1] <<
", " << mcp->getVertex()[2] <<
" )" <<
LOG::endl
54 <<
" p: ( " << mcp->getMomentum()[0] <<
", " << mcp->getMomentum()[1] <<
", " << mcp->getMomentum()[2] <<
" )" <<
LOG::endl
55 <<
" charge: " << mcp->getCharge() <<
LOG::endl
56 <<
" mass: " << mcp->getMass() <<
LOG::endl
57 <<
" daughters: " << mcp->getDaughters().size() <<
LOG::endl
58 <<
" parents: " << mcp->getParents().size() <<
LOG::endl
63 if (mcp->getParents().size() == 0) {
74 log() <<
LOG::debug <<
"created vertex for MCParticle " << i <<
" at " << vertex->GetPosition() <<
LOG::done;
85 const std::set<G4PrimaryParticle*> primaries =
createPrimary(0, mcp);
92 if (primaries.size() > 0) {
99 for (std::set<G4PrimaryParticle*>::const_iterator it = primaries.begin(); it != primaries.end(); it++) {
121 vertex->SetPrimary(*it);
127 event->AddPrimaryVertex(vertex);
146 for (std::vector<G4PrimaryParticle*>::iterator it =
_primaryVec.begin();
149 G4PrimaryParticle* primary = (*it);
152 <<
" PDG: " << primary->GetPDGcode() <<
LOG::endl
153 <<
" mass: " << primary->GetMass() <<
LOG::endl
154 <<
" charge: " << primary->GetCharge() <<
LOG::endl
155 <<
" momentum: " << primary->GetMomentum() <<
LOG::endl
156 <<
" proper time: " << primary->GetProperTime() <<
LOG::endl
157 <<
" has dau: " << (primary->GetDaughter() != 0) <<
LOG::endl;
158 if (primary->GetDaughter() != 0) {
159 std::vector<int> dauIndices;
160 G4PrimaryParticle* daughter = primary->GetDaughter();
162 dauIndices.push_back(
indexOf(daughter));
163 daughter = daughter->GetNext();
181 G4Exception(
"",
"", FatalException,
"MCParticle is null.");
185 std::set<G4PrimaryParticle*> primaries;
187 G4PrimaryParticle* primary = 0;
190 if (
_primaryMap.count(mcp) == 0 && (mcp->getGeneratorStatus() == 1 || mcp->getGeneratorStatus() == 2)) {
197 primary =
new G4PrimaryParticle();
198 primary->SetPDGcode(mcp->getPDG());
199 primary->SetCharge(mcp->getCharge());
200 primary->SetMass(mcp->getMass() * GeV);
201 const double* p = mcp->getMomentum();
202 primary->SetMomentum(p[0] * GeV, p[1] * GeV, p[2] * GeV);
205 if (mcp->getDaughters().size() > 0) {
208 << mcp->getDaughters().size() <<
" daughters " <<
LOG::done;
211 MCParticle* dp = mcp->getDaughters()[0];
212 double properTime = fabs((dp->getTime() - mcp->getTime()) * mcp->getMass()) / mcp->getEnergy();
213 primary->SetProperTime(properTime * ns);
230 parent->SetDaughter(primary);
241 primaries.insert(primary);
247 <<
" PDG: " << primary->GetPDGcode() <<
LOG::endl
248 <<
" mass: " << primary->GetMass() <<
LOG::endl
249 <<
" charge: " << primary->GetCharge() <<
LOG::endl
250 <<
" momentum: " << primary->GetMomentum() <<
LOG::endl
251 <<
" proper time: " << primary->GetProperTime() <<
LOG::endl
252 <<
" has dau: " << (primary->GetDaughter() != 0) <<
LOG::endl
265 for (
int i = 0; i < mcp->getDaughters().size(); i++) {
269 std::set<G4PrimaryParticle*> daughters =
createPrimary(primary, mcp->getDaughters()[i]);
274 if (daughters.size() > 0) {
275 primaries.insert(daughters.begin(), daughters.end());
287 G4PrimaryVertex* vertex = 0;
289 if (mcp->getGeneratorStatus() == 1 || mcp->getGeneratorStatus() == 2) {
296 const double* particleVertex = mcp->getVertex();
297 G4ThreeVector particlePosition(particleVertex[0], particleVertex[1], particleVertex[2]);
300 G4double particleTime = mcp->getTime();
303 vertex =
new G4PrimaryVertex(particlePosition, particleTime);
307 <<
" position: " << vertex->GetPosition() <<
LOG::endl
308 <<
" time: " << particleTime <<
LOG::endl
327 const G4double gamma = sqrt(1 + sqr(tan(alpha)));
328 const G4double betagamma = tan(alpha);
330 if (particles != 0) {
332 int nMCP = particles->getNumberOfElements();
334 for (
int i = 0; i < nMCP; ++i) {
336 IMPL::MCParticleImpl* mcp =
dynamic_cast<IMPL::MCParticleImpl*
>(particles->getElementAt(i));
338 const double* p = mcp->getMomentum();
343 const G4double m = mcp->getMass();
348 pPrime[0] = betagamma * sqrt(sqr(p[0]) + sqr(p[1]) + sqr(p[2]) + sqr(m)) + gamma * p[0];
355 mcp->setMomentum(pPrime);
364 z = G4RandGauss::shoot(0, rms/mm);
371 for (std::set<G4PrimaryParticle*>::iterator it = primaries.begin(); it != primaries.end(); it++) {
372 G4PrimaryParticle* dau = (*it)->GetDaughter();
374 if (dau == particle) {
377 dau = dau->GetNext();
static EventSourceManager * instance()
ostream & getOutputStream() const
int indexOf(MCParticle *particle)
std::vector< G4PrimaryParticle * > _primaryVec
void applyLorentzTransformation(LCCollection *mcparticles, const G4double angle)
void generateEvent(LCCollectionVec *mcparticles, G4Event *event)
PrimaryParticleMap _primaryMap
G4double smearZPosition(const G4double rms)
void setMCParticleCollection(LCCollectionVec *mcpVec)
LCCollectionVec * _inputVec
std::set< G4PrimaryParticle * > createPrimary(G4PrimaryParticle *parent, MCParticle *mcp)
G4PrimaryVertex * createVertex(MCParticle *mcp)
bool isDaughter(G4PrimaryParticle *particle, const std::set< G4PrimaryParticle * > &primaries)