/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
HepMCtoG4 Class Reference

HepMCtoG4 - tool to convert GenEvents into G4Events. More...

#include <HepMCtoG4.h>

Inheritance diagram for HepMCtoG4:
Inheritance graph
[legend]
Collaboration diagram for HepMCtoG4:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 HepMCtoG4 (const std::string &type, const std::string &name, const IInterface *parent)
 HepMCtoG4 - tool to convert GenEvents into G4Events.
virtual ~HepMCtoG4 ()
virtual StatusCode initialize ()
virtual StatusCode finalize ()
virtual StatusCode convert (const HepMC::GenEvent &input, std::vector< G4PrimaryVertex * > &output)
 Do the conversion.

Static Public Member Functions

static const InterfaceID & interfaceID ()

Private Member Functions

G4PrimaryParticle * makeG4particle (const HepMC::GenParticle &part, const HepMC::GenEvent *event, const HepMC::GenVertex *vertex)

Private Attributes

bool m_zeroTime
 Property: ZeroTime.
IParticlePropertySvc * m_pps

Detailed Description

HepMCtoG4 - tool to convert GenEvents into G4Events.

bv@bnl.gov 2008/1/1.

Definition at line 18 of file HepMCtoG4.h.


Constructor & Destructor Documentation

HepMCtoG4::HepMCtoG4 ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

HepMCtoG4 - tool to convert GenEvents into G4Events.

bv@bnl.gov 2008/1/1. Note that how this works makes assumptions as to how the HepMC::Gen* classes are filled.

Definition at line 31 of file HepMCtoG4.cc.

    : GaudiTool(type,name,parent)
    , m_pps(0) // djaffe
{
    declareInterface<IHepMCtoG4>(this);
    
    declareProperty("ZeroTime",m_zeroTime = false,
                    "Set true and all times will be reset so the signal vertex is at t=0.");
}
HepMCtoG4::~HepMCtoG4 ( ) [virtual]

Definition at line 43 of file HepMCtoG4.cc.

{
}

Member Function Documentation

StatusCode HepMCtoG4::initialize ( ) [virtual]

Definition at line 48 of file HepMCtoG4.cc.

{
    m_pps = svc<IParticlePropertySvc>( "ParticlePropertySvc", true ) ; //djaffe
    return StatusCode::SUCCESS;
}
StatusCode HepMCtoG4::finalize ( ) [virtual]

Definition at line 54 of file HepMCtoG4.cc.

{
  return StatusCode::SUCCESS;
}
StatusCode HepMCtoG4::convert ( const HepMC::GenEvent input,
std::vector< G4PrimaryVertex * > &  output 
) [virtual]

Do the conversion.

Implements IHepMCtoG4.

Definition at line 116 of file HepMCtoG4.cc.

{

    // Catch HepMC::GenEvent weighting
    bool hasEventWeight = false;
    double eventWeight = 1.0;
    // If HepMC event weights container has only one value, apply to
    // all vertices as described in HepMC v2 documentation.
    if( input.weights().size() == 1 ){ 
        hasEventWeight = true; 
        eventWeight *= input.weights().front();
    }

    // Loop over vertices in the event
    HepMC::GenEvent::vertex_const_iterator
        iVtx = input.vertices_begin(),
        doneVtx = input.vertices_end();
    for (/*nop*/; doneVtx != iVtx; ++iVtx) {
            
        G4PrimaryVertex* g4vtx = new G4PrimaryVertex;
        bool first_time = true;
        
        // Catch HepMC::GenVertex weighting
        bool hasVertexWeight = false;
        double vertexWeight = 1.0;
        // If HepMC::GenVertex weights container has only one value,
        // apply to current vertex as described in HepMC v2
        // documentation.
        if( (*iVtx)->weights().size() == 1 ){ 
            hasVertexWeight = true;
            vertexWeight *= (*iVtx)->weights().front();
        }
        if( hasEventWeight || hasVertexWeight ){
            g4vtx->SetWeight( eventWeight*vertexWeight );
        }

        // Loop over particles in the vertex
        HepMC::GenVertex::particles_out_const_iterator 
            iPart = (*iVtx)->particles_out_const_begin(),
            donePart = (*iVtx)->particles_out_const_end();
        for (/*nop*/; donePart != iPart; ++iPart) {
                
            // Only keep particles that are important for tracking
            if ((*iPart)->status() != 1) continue;

            if (first_time) {
                first_time = false;
                HepMC::FourVector v = (*iPart)->production_vertex()->position();
                g4vtx->SetPosition(v.x(),v.y(),v.z());
                if (m_zeroTime) 
                    g4vtx->SetT0(0.0);
                else
                    g4vtx->SetT0(v.t());
                g4vtx->SetUserInformation(new G4DhPrimaryVertexInformation(&input,*iVtx));
            }
            g4vtx->SetPrimary(makeG4particle(*(*iPart),&input,*iVtx));
        }

        if (!g4vtx->GetNumberOfParticle()) {
            delete g4vtx;
            continue;
        }

        output.push_back(g4vtx);
    }
    return StatusCode::SUCCESS;
}
G4PrimaryParticle * HepMCtoG4::makeG4particle ( const HepMC::GenParticle part,
const HepMC::GenEvent event,
const HepMC::GenVertex vertex 
) [private]

Definition at line 65 of file HepMCtoG4.cc.

{
    HepMC::FourVector p = part.momentum();

    G4PrimaryParticle* g4part = 0;
    
    double m, cm ;
    if (part.pdg_id() == 20022 /*opticalphoton*/) {
        g4part = new G4PrimaryParticle(G4OpticalPhoton::Definition(),
                                       p.px(),p.py(),p.pz());
        m = 0. ;
    }
    else {
        g4part = new G4PrimaryParticle(part.pdg_id(),p.px(),p.py(),p.pz());
        m = cm = sqrt(fabs( p.t()*p.t() - (p.x()*p.x() + p.y()*p.y() + p.z()*p.z()) ));

        ParticleProperty*  ppp = m_pps->findByStdHepID( part.pdg_id() );
        if ( ppp  ) {
            m = ppp->mass();
            double r = 0.;
            if ( m > 0 ) { r = std::abs(cm-m)/m; } 
            if ( r > 0.001 || std::abs(cm-m) > 0.01*MeV ) {
                warning() << "calculated mass = " << cm
                          << " differs from IParticlePropertySvc mass " << m
                          << " for pdg_id " << part.pdg_id()
                          << ". Using IParticlePropertySvc mass. " << endreq;
            }
        }
        else {
            if ( p.t() < 0.01*MeV && std::abs(part.pdg_id()) > 1000000000 ) {
                debug() << "As expected, there is no IParticlePropertySvc mass for pdg_id "
                        << part.pdg_id() << " which is a zero-energy, recoil nucleus created by GenDecay. Use calculated mass " << m 
                        << " from particle energy " << p.t() << " momentum " << sqrt(p.x()*p.x() + p.y()*p.y() + p.z()*p.z())
                        << endreq;
            }
            else {
                warning() << "cannot find IParticlePropertySvc mass for pdg_id "
                          << part.pdg_id() << " and status " << part.status() << " . Using calculated mass " << m 
                          << " from particle energy " << p.t() << " momentum " << sqrt(p.x()*p.x() + p.y()*p.y() + p.z()*p.z())
                          << endreq;
            }
        }
    }
    g4part->SetMass(m);
    HepMC::ThreeVector pol = part.polarization().normal3d();
    g4part->SetPolarization(pol.x(),pol.y(),pol.z());

    g4part->SetUserInformation(new G4DhPrimaryParticleInformation(event,vertex,&part));
    return g4part;        
}
const InterfaceID & IHepMCtoG4::interfaceID ( ) [static, inherited]

Definition at line 8 of file IHepMCtoG4.cc.

{ 
    return IID_IHepMCtoG4; 
}

Member Data Documentation

bool HepMCtoG4::m_zeroTime [private]

Property: ZeroTime.

Set true and all times will be reset so the signal vertex is at t=0. NOTE: default is false.

Definition at line 37 of file HepMCtoG4.h.

IParticlePropertySvc* HepMCtoG4::m_pps [private]

Definition at line 39 of file HepMCtoG4.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:05:42 for G4DataHelpers by doxygen 1.7.4