TG4RunConfiguration problem

From: Dmitry Naumov <naumovd_at_fi.infn.it>
Date: Tue, 25 Jul 2006 12:45:36 +0400


Dear VMC team,

I migrated to new version of Geant4 VMC (1.9), Geant4 (8.1), root (5.12.00) and encounter a run-time problem of the code which was working with previous versions. I have the following message:

naumov_at_naumov-laptop(12:31)> ./bin/i686/G4Sim -b --events=1 NUCLON running in batch mode
*** glibc detected *** double free or corruption (out): 0x095ec208 *** Abort

I find that the crash happens when I call a ctor of TG4RunConfiguration: TG4RunConfiguration* runConfiguration=new TG4RunConfiguration();

what is strange to me that I could run smoothly my macros (run_g4.C) where I also call TG4RunConfiguration. In the log file http://root.cern.ch/root/vmc/geant4_vmc_versions.txt I see that indeed some new support was added to TG4RunConfiguration while I did not find what is wrong with my piece of code. Please have a look into my main program which I link against G4, VMC, ROOT etc libraries to get the executable. Thank you, best regards, Dmitry

#include "MCApplication.h"
#include "SimuManager.h"
#include "DetectorFactory.h"
#include "VirtualDetector.h"
#include "PrimaryGenerator.h"
#include "NRunConfiguration.h"

#include <TGeant4.h>
#include <TG4RunConfiguration.h>
#include <TApplication.h>
#include <PrimaryGenerator.h>
#include <TVirtualMC.h>
#include <TROOT.h>
#include <TInterpreter.h>
#include <TString.h>

#include <iostream>
#include <exception>
using namespace std;
static string transp = "g4";
static string ofile  = "nuclon";
static string plist  = "g4vmc";
static Int_t fEvMax  = 1;
static Int_t seed    = 12345000;
static Int_t run     = 1234;
static Float_t Emin  = 1.0;
static Float_t Emax  = 1000;

static Float_t Thetamin = 0;
static Float_t Thetamax = 180;
static Int_t  activate_header = 1;
static Int_t  activate_target = 1;
static Int_t  activate_container = 1;
static Int_t  activate_tracks = 0;
static Int_t  activate_neutrals = 0;
static Int_t  make_shrink = 0;

//_____________________________________________________________________________
TGeant4 *CreateG4(){
    //
    // 
    //

    TG4RunConfiguration* runConfiguration=NULL;

    if (TString(plist).Contains("g4vmc")) {

         runConfiguration = new TG4RunConfiguration();
        TG4PhysicsListOptions options;
        options.SetHadronPhysics(true);
        runConfiguration->SetPhysicsListOptions(options);

}

    else if (TString(plist).Contains("proper")) {

        runConfiguration = new NRunConfiguration();
}

    else

        Error("Unknown Physics List",plist.c_str());

    // TGeant4
    TGeant4 *geant4 = new TGeant4("TGeant4", "The Geant4 Monte Carlo", runConfiguration);

    geant4->ProcessGeantMacro("macros/g4config.in");     cout << "Geant4 has been created." << endl;     return geant4;
}

//______________________________________________________________________________
void ParseCmdLine(Int_t* argc, char** argv ) {
    //
    // Parse the commandline and set the corresponding variables
    //
   
    for(Int_t i=1; i < *argc; i++) {
        if ( strlen(argv[i]) >= 2 &&
                (argv[i][0] == '-') &&
                (argv[i][0] != '-')) {
            Warning("ParseCmdLine","G4 usage:");
        Warning("ParseCmdLine","");
            Warning("ParseCmdLine","G4 [-b --events=<n> --seed=<n> 
--ofile=<fname> ");
           
        }
    else if (strncmp(argv[i],"-b=",3)==0) {
            // Number of events
        gROOT->SetBatch();
        }
    else if (strncmp(argv[i],"--t=",4)==0) {
            // Number of events
            string s = argv[i]+4;
            size_t pos = s.find('=');
        transp = s.substr(pos+1);
        }   
    else if (strncmp(argv[i],"--events=",9)==0) {
            // Number of events
            sscanf(argv[i]+9,"%d",&fEvMax);
        }
    else if (strncmp(argv[i],"--seed=",7)==0) {
            // Set random seed
        sscanf(argv[i]+7,"%d",&seed);

}
else if (strncmp(argv[i],"--emin=",7)==0) { // Set min energy sscanf(argv[i]+7,"%f",&Emin);
}
else if (strncmp(argv[i],"--emax=",7)==0) { // Set rmax energy sscanf(argv[i]+7,"%f",&Emax);
}
else if (strncmp(argv[i],"--tmin=",7)==0) { // Set min energy sscanf(argv[i]+7,"%f",&Thetamin);
}
else if (strncmp(argv[i],"--tmax=",7)==0) { // Set rmax energy sscanf(argv[i]+7,"%f",&Thetamax);

}

    else if (strncmp(argv[i],"--run=",6)==0) {
            // Set random seed
        sscanf(argv[i]+6,"%d",&run);

}

    else if (strncmp(argv[i],"--shrink=",9)==0) {
            // make shrink-file
        sscanf(argv[i]+9,"%d",&make_shrink);

}

    else if (strncmp(argv[i],"--do-target=",11)==0) {
            // enable/disable target simulation
            sscanf(argv[i]+11,"%d",&activate_target);

}

    else if (strncmp(argv[i],"--do-container=",14)==0) {
            // enable/disable target simulation
            sscanf(argv[i]+14,"%d",&activate_container);

}

    else if (strncmp(argv[i],"--do-tracks=",11)==0) {
            // enable/disable target simulation
            sscanf(argv[i]+11,"%d",&activate_tracks);

}

    else if (strncmp(argv[i],"--do-neutrals=",13)==0) {
            // enable/disable target simulation
            sscanf(argv[i]+13,"%d",&activate_neutrals);

}

    else if (strncmp(argv[i],"--ofile=",7)==0) {
            // Set output file
            string s = argv[i]+7;
            size_t pos = s.find('=');
        ofile = s.substr(pos+1);           

}

    else if (strncmp(argv[i],"--plist=",7)==0) {
            // Set output file
            string s = argv[i]+7;
            size_t pos = s.find('=');
        plist = s.substr(pos+1);           

}
}

}
//_____________________________________________________________________________
void Run() {
    //
    // simulation path
    //

    MCApplication *appl = new MCApplication("nuclon", "The NUCLON MC application");

    if (fEvMax>0) appl->SetNevents(fEvMax);

    appl->SetSeed(seed);
    appl->SetOutputFileName(ofile);
    appl->SetRun(run);

    Double_t mp = 0.938271998;
    if (appl->GetPrimaryGenerator())
appl->GetPrimaryGenerator()->SetEnergyMin(Emin+mp);

    if (appl->GetPrimaryGenerator())
appl->GetPrimaryGenerator()->SetEnergyMax(Emax+mp);

    if (appl->GetPrimaryGenerator())
appl->GetPrimaryGenerator()->SetThetaMin(Thetamin);

    if (appl->GetPrimaryGenerator())
appl->GetPrimaryGenerator()->SetThetaMax(Thetamax);

    appl->ActivateHeader(activate_header);
    appl->ActivateTarget(activate_target);
    appl->ActivateContainer(activate_container);
    appl->ActivateTracks(activate_tracks);
    appl->ActivateNeutrals(activate_neutrals);

    appl->GetPrimaryGenerator()->SetNofPrimaries(1);
    appl->SetPrintModulo(1);

    appl->SetVerboseLevel(0);
    appl->MakeShrinkFile(make_shrink);

    DetectorFactory::Get()->SetDetector("Detector6");     TGeant4 *geant4 = CreateG4();

    appl->InitMC("macros/dummy.C");
    appl->RunMC(fEvMax);

    geant4->ProcessGeantCommand("/random/saveThisRun run.rndm");     delete geant4;
    delete appl;
}

//_____________________________________________________________________________
int main(int argc, char **argv)
{

    try {

         ParseCmdLine(&argc, argv);
         TApplication theApp("App", &argc, argv);
         if ( gROOT->IsBatch()) {
              cout << "NUCLON running in batch mode\n";
              Run();   
              return 0;
         }
     else {
          Run();
              theApp.Run(0);
              cout << "NUCLON END\n";
              return 0;
     }

}

    catch (exception &e) {

        cerr << "NUCLON ERROR: " << e.what() << endl;
}

} Received on Tue Jul 25 2006 - 10:45:41 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:55:09 MET