Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup generator interface as in 4306 #4360

Merged
merged 1 commit into from Jun 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions IOMC/EventVertexGenerators/src/FlatEvtVtxGenerator.cc
Expand Up @@ -45,15 +45,16 @@ FlatEvtVtxGenerator::~FlatEvtVtxGenerator()

//Hep3Vector * FlatEvtVtxGenerator::newVertex() {
HepMC::FourVector* FlatEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) {
double aX,aY,aZ;
double aX,aY,aZ,aT;
aX = CLHEP::RandFlat::shoot(engine, fMinX, fMaxX);
aY = CLHEP::RandFlat::shoot(engine, fMinY, fMaxY);
aZ = CLHEP::RandFlat::shoot(engine, fMinZ, fMaxZ);
aT = CLHEP::RandFlat::shoot(engine, fMinZ, fMaxZ);

//if (fVertex == 0) fVertex = new CLHEP::Hep3Vector;
//fVertex->set(aX,aY,aZ);
if ( fVertex == 0 ) fVertex = new HepMC::FourVector() ;
fVertex->set(aX,aY,aZ,fTimeOffset);
fVertex->set(aX,aY,aZ,aT+fTimeOffset);

return fVertex;
}
Expand Down
5 changes: 3 additions & 2 deletions IOMC/EventVertexGenerators/src/GaussEvtVtxGenerator.cc
Expand Up @@ -46,14 +46,15 @@ GaussEvtVtxGenerator::~GaussEvtVtxGenerator()

//Hep3Vector* GaussEvtVtxGenerator::newVertex() {
HepMC::FourVector* GaussEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) {
double X,Y,Z;
double X,Y,Z,T;
X = CLHEP::RandGaussQ::shoot(engine, fMeanX, fSigmaX);
Y = CLHEP::RandGaussQ::shoot(engine, fMeanY, fSigmaY);
Z = CLHEP::RandGaussQ::shoot(engine, fMeanZ, fSigmaZ);
T = CLHEP::RandGaussQ::shoot(engine, fTimeOffset, fSigmaZ);

//if (fVertex == 0) fVertex = new CLHEP::Hep3Vector;
if ( fVertex == 0 ) fVertex = new HepMC::FourVector() ;
fVertex->set( X, Y, Z, fTimeOffset ) ;
fVertex->set( X, Y, Z, T);

return fVertex;
}
Expand Down
37 changes: 9 additions & 28 deletions SimG4Core/Generators/src/Generator.cc
Expand Up @@ -88,32 +88,30 @@ Generator::Generator(const ParameterSet & p) :
Generator::~Generator()
{}

void Generator::HepMC2G4(const HepMC::GenEvent * evt_orig, G4Event * g4evt)
void Generator::HepMC2G4(const HepMC::GenEvent * evt, G4Event * g4evt)
{

if ( *(evt_orig->vertices_begin()) == 0 ) {
if ( *(evt->vertices_begin()) == 0 ) {
throw SimG4Exception("SimG4CoreGenerator: Corrupted Event - GenEvent with no vertex");
}

HepMC::GenEvent* evt = new HepMC::GenEvent(*evt_orig);

if (evt->weights().size() > 0) {

weight_ = evt->weights()[0] ;
for (unsigned int iw=1; iw<evt->weights().size(); ++iw) {

// terminate if the versot of weights contains a zero-weight
// terminate if the vector of weights contains a zero-weight
if ( evt->weights()[iw] <= 0 ) break;
weight_ *= evt->weights()[iw] ;
}
}

if (vtx_ != 0) delete vtx_;
if (vtx_ != 0) { delete vtx_; }
vtx_ = new math::XYZTLorentzVector((*(evt->vertices_begin()))->position().x(),
(*(evt->vertices_begin()))->position().y(),
(*(evt->vertices_begin()))->position().z(),
(*(evt->vertices_begin()))->position().t());

if(verbose > 0) {
evt->print();
LogDebug("SimG4CoreGenerator") << "Primary Vertex = ("
Expand Down Expand Up @@ -178,7 +176,7 @@ void Generator::HepMC2G4(const HepMC::GenEvent * evt_orig, G4Event * g4evt)
double t1 = (*vitr)->position().t()*mm/c_light;

G4PrimaryVertex* g4vtx = new G4PrimaryVertex(x1, y1, z1, t1);

for (pitr= (*vitr)->particles_begin(HepMC::children);
pitr != (*vitr)->particles_end(HepMC::children); ++pitr){

Expand Down Expand Up @@ -323,7 +321,6 @@ void Generator::HepMC2G4(const HepMC::GenEvent * evt_orig, G4Event * g4evt)
}
}
if(toBeAdded){

G4int pdgcode= (*pitr)-> pdg_id();
G4PrimaryParticle* g4prim=
new G4PrimaryParticle(pdgcode, px*GeV, py*GeV, pz*GeV);
Expand Down Expand Up @@ -352,18 +349,6 @@ void Generator::HepMC2G4(const HepMC::GenEvent * evt_orig, G4Event * g4evt)
}
if ( verbose > 1 ) g4prim->Print();
g4vtx->SetPrimary(g4prim);

// impose also proper time for status=1 and available end_vertex
// VI: this is impossible, so commented out
/*
if ( 1 == status && decay_length > 0.0) {
double proper_time = decay_length/(p.Beta()*p.Gamma()*c_light);
if ( verbose > 1 ) LogDebug("SimG4CoreGenerator")
<<"Setting proper time for beta="<<p.Beta()<<" gamma="
<<p.Gamma()<<" Proper time=" <<proper_time/ns<<" ns" ;
g4prim->SetProperTime(proper_time);
}
*/
}
}

Expand All @@ -379,23 +364,18 @@ void Generator::HepMC2G4(const HepMC::GenEvent * evt_orig, G4Event * g4evt)
if ( verbose > 1 ) g4vtx->Print();
g4evt->AddPrimaryVertex(g4vtx);
}

delete evt;
}

void Generator::particleAssignDaughters( G4PrimaryParticle* g4p,
HepMC::GenParticle* vp,
double decaylength)
{
// V.I.: not needed anymore
//if (!(vp->end_vertex())) return;

if ( verbose > 1 )
if ( verbose > 1 ) {
LogDebug("SimG4CoreGenerator")
<< "Special case of long decay length \n"
<< "Assign daughters with to mother with decaylength="
<< decaylength/cm << " cm";

}
math::XYZTLorentzVector p(vp->momentum().px(), vp->momentum().py(),
vp->momentum().pz(), vp->momentum().e());

Expand Down Expand Up @@ -459,6 +439,7 @@ void Generator::particleAssignDaughters( G4PrimaryParticle* g4p,

(*vpdec)->set_status(1000+(*vpdec)->status());
g4p->SetDaughter(g4daught);

if ( verbose > 1 ) g4daught->Print();
}
}
Expand Down