--- trieste/pamVMC/run_g4_testTRK.C	2009/03/24 14:03:55	1.2
+++ trieste/pamVMC/run_g4_testTRK.C	2009/03/24 14:18:54	1.3
@@ -2,7 +2,13 @@
 // $Id: run_g4.C,v 1.0 2007/06/01 
 //
 // Macro for running G4PAM_VMC with Geant4. 
-void run_g4_testTRK(const TString& configMacro = "g4Config.C") {
+void run_g4_testTRK(TString outfilename="/gpfs/wizard/flight/analysis/cecilia/trieste/pamVMC/pamtest",
+		    UInt_t seed = 0, const TString& configMacro = "g4Config.C") {
+
+    if (seed == 0) { // set random seed
+      TRandom3 *r = new TRandom3(0);
+      seed = r->GetSeed();
+    }
 
     // Load basic libraries
     gROOT->LoadMacro("./macro/basiclibs.C");
@@ -26,7 +32,7 @@
     
     // MC application
     PamVMCApplication* appl 
-      = new PamVMCApplication("PAMG4_VMC", "PAMELA GEANT4 VMC application");
+      = new PamVMCApplication("PAMG4_VMC", "PAMELA GEANT4 VMC application", outfilename.Data(), seed);
     
 
     //appl->GetPrimaryGenerator()->SetNofPrimaries(1);  
@@ -37,11 +43,20 @@
     //optPhoton();  
 	appl->SetVerboseLevel(2);
     // Initialize MC
-    appl->InitMC(configMacro);
+    appl->InitMC(configMacro, outfilename.Data(), seed);
 
     // Cecilia: set seed for random generator  
-    TRandom3 *rndgen = new TRandom3(123);
+    TRandom3 *rndgen = new TRandom3(seed);
     ((TGeant4*)gMC)->SetRandom(rndgen);
+    // Write seed in a txt file
+    TString seedfname = outfilename;
+    seedfname.Append("Seed.txt");
+    cout<<" FILENAME "<<seedfname.Data()<<endl;
+    FILE *seedfile = fopen(seedfname.Data(),"w");
+    fprintf(seedfile,"%d\n",rndgen->GetSeed() );
+    fclose(seedfile);
+  
+    cout<<"SEED "<<rndgen->GetSeed()<<endl;
 
 
     // Customise Geant4 setting after initialization:
@@ -60,13 +75,13 @@
     
     ((TGeant4*)gMC)->ProcessGeantMacro("g4config2.in");
     // Visualization settings
-    ((TGeant4*)gMC)->ProcessGeantMacro("g4vis.in");
+    //((TGeant4*)gMC)->ProcessGeantMacro("g4vis.in");
  
    ((TGeant4*)gMC)->SetMaxNStep(50000);
    //appl->GetPrimaryGenerator()->SetParticle(1000060120);
     appl->GetPrimaryGenerator()->SetParticle(kElectron);
     //appl->GetPrimaryGenerator()->SetDirection(0.,0.);
-    appl->GetPrimaryGenerator()->SetKinEnergy(10.);
+    //appl->GetPrimaryGenerator()->SetKinEnergy(10.);
      //appl->GetPrimaryGenerator()->SetRigidity(1.0); //GV 
     //appl->GetPrimaryGenerator()->SetPosition(1.,1.,130.);
 
@@ -80,14 +95,9 @@
       // endritabrata
 
       // cecilia
-      //appl->GetPrimaryGenerator()->GenPosition(-22.4,22.4, -18.5, 18.5, 110.0,110.0);
-      // appl->GetPrimaryGenerator()->GenPosition(-8.,8., -6., 6., 110.0,110.0);
-      appl->GetPrimaryGenerator()->GenSphPhiThe();
-      //appl->GetPrimaryGenerator()->GenDirection(0.,0.1, 0.,2*TMath::Pi()); // 5 gradi
-      // appl->GetPrimaryGenerator()->GenSpe(7.,20.,-2.75);
-      //  appl->GetPrimaryGenerator()->Print();
-      // if (i==9) ((TGeant4*)gMC)->ProcessGeantMacro("g4vis.in"); 
-      appl->GetPrimaryGenerator()->Print();
+       appl->GetPrimaryGenerator()->GenSphPhiThe(-25,25., -25.,25., 108.0,108.0);
+       appl->GetPrimaryGenerator()->GenSpe(5.,30.,-3.3); 
+
       appl->RunMC(1);
 
     }