Message: Is it safe to copy a G4VUserPhysicsList ? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question Is it safe to copy a G4VUserPhysicsList ? 

Forum: Physics List
Date: Dec 17, 11:09
From: Iurii Sorokin <Iurii Sorokin>

Is it safe to make a copy of some Reference Physics List using the G4VModularPhysicsList copy constructor, and pass the copy to the G4RunManager? The question is illustrated with the following code:

    // Create a reference physics list:
    G4PhysListFactory factory;
    G4VModularPhysicsList* phys_list = factory.GetReferencePhysList("QGSP_BIC_EMZ");

    // Make a copy.
    // 
    // The problem here is that the dynamic type of 'phys_list' is 'QGSP_BIC',
    // whereas I call the copy-constructor of G4VModularPhysicsList. So 'phys_list' 
    // will be sliced, and the dynamic type of the copy will be 
    // G4VModularPhysicsList. Also, in fact, the copy constructor of 
    // G4VModularPhysicsList is protected, but suppose for a moment, that I can
    // call it. I will explain it below. 
    G4VModularPhysicsList* phys_list_copy = new G4VModularPhysicsList( *phys_list ); 

    // Pass the copy to G4RunManager:
    G4RunManager run_manager;
    run_manager.SetUserInitialization( phys_list_copy );

Is the code above safe? I mean, was GEANT4 designed with an idea that a physics list can be copied like that?

Now, regarding calling the protected copy constructor. In fact I need to create MyPhysicsList class, that is based on "QGSP_BIC_EMZ", but with some modifications. Important is that MyPhysicsList must be default-constructable, and must not require calling any additional initializers. I came up with the following code:

class MyPhysicsList : public G4VModularPhysicsList
{
    MyPhysicsList()
    : G4VModularPhysicsList( *factory.GetReferencePhysList("QGSP_BIC_EMZ") )
    {
        ReplacePhysics( ... );
        RegisterPhysics( ... );
        ...
    }
};

Here I can call the protected G4VModularPhysicsList copy constructor.

I'm using GEANT4 version 10.5.0

Thanks in advance!

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: Is it safe to copy a G4VUserPhysicsList ?   (Iurii Sorokin - Dec 17, 11:15)
(_ None: Re: Is it safe to copy a G4VUserPhysicsList ?   (Iurii Sorokin - Dec 18, 06:45)
(_ Idea: Re: Is it safe to copy a G4VUserPhysicsList ?   (Vladimir Ivanchenko - Dec 18, 07:37)
(_ None: Re: Is it safe to copy a G4VUserPhysicsList ?   (Iurii Sorokin - Dec 18, 07:46)
 Add Message Add Message
to: "Is it safe to copy a G4VUserPhysicsList ?"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]