Index: ICOSIM/CPP/trunk/source/simulation.cc
===================================================================
--- ICOSIM/CPP/trunk/source/simulation.cc	(revision 15)
+++ ICOSIM/CPP/trunk/source/simulation.cc	(revision 17)
@@ -78,4 +78,6 @@
     particlefile = inputfile + "initial.dat";
 
+    cout << "READ THE BUNCH OF PARTICLES FROM THE FILE: " << particlefile <<endl;
+    
     //if the name of the file is not 'initial.dat', uncomment the following two lines
 
@@ -663,5 +665,5 @@
       cout <<"********************************"<<endl;
         cout << "RunningFlag = " <<  RunningFlag << endl;
-	cout << "READ THE BUNCH OF PARTICLES FROM THE FILE: " <<inputfile <<endl;
+	
         readParticle(Apr, Zpr, inputfile);
 
@@ -676,5 +678,5 @@
       cout << "RunningFlag = " <<  RunningFlag << endl;
       cout << "GENERATION OF THE BUNCH OF PARTICLES." << endl;
-        genbunch(i0, nparti, partdistr, r1r2skin, nsigi * nsigi * emix, nsigi * nsigi * emiy, sigdpp, lat.reseau[i0]->BETX, lat.reseau[i0]->ALFX, lat.reseau[i0]->DX, lat.reseau[i0]->DPX, lat.reseau[i0]->BETY, lat.reseau[i0]->ALFY, lat.reseau[i0]->DY, lat.reseau[i0]->DPY, nsigi);
+        genbunch(i0, nparti, partdistr, r1r2skin, nsigi * nsigi * emix, nsigi * nsigi * emiy, sigdpp, lat.reseau[i0]->BETX, lat.reseau[i0]->ALFX, lat.reseau[i0]->DX, lat.reseau[i0]->DPX, lat.reseau[i0]->BETY, lat.reseau[i0]->ALFY, lat.reseau[i0]->DY, lat.reseau[i0]->DPY, nsigi, inputfile);
 
         //we set the id of the particles
@@ -742,5 +744,4 @@
       cout <<"********************************"<<endl;
 	cout << "RunningFlag = " <<  RunningFlag << endl;
-	cout << "READ THE BUNCH OF PARTICLES FROM THE FILE: " <<inputfile <<endl;
         readParticle(Apr, Zpr, inputfile);
     } else if (RunningFlag == 3) {
@@ -749,5 +750,5 @@
       cout << "RunningFlag = " <<  RunningFlag << endl;
       cout << "GENERATION OF THE BUNCH OF PARTICLES." << endl;
-        genbunch(i0, nparti, partdistr, r1r2skin, nsigi * nsigi * emix, nsigi * nsigi * emiy, sigdpp, lat.reseau[i0]->BETX, lat.reseau[i0]->ALFX, lat.reseau[i0]->DX, lat.reseau[i0]->DPX, lat.reseau[i0]->BETY, lat.reseau[i0]->ALFY, lat.reseau[i0]->DY, lat.reseau[i0]->DPY, nsigi);
+        genbunch(i0, nparti, partdistr, r1r2skin, nsigi * nsigi * emix, nsigi * nsigi * emiy, sigdpp, lat.reseau[i0]->BETX, lat.reseau[i0]->ALFX, lat.reseau[i0]->DX, lat.reseau[i0]->DPX, lat.reseau[i0]->BETY, lat.reseau[i0]->ALFY, lat.reseau[i0]->DY, lat.reseau[i0]->DPY, nsigi, inputfile);
     }
 
@@ -827,5 +828,5 @@
 
 
-    //We take the particles hitting collimators during the previous tracking (we take their coordinates at the beginning of the last turn before the hit), and do a more precise tracking
+    //We take the particles hitting collimators during the previous tracking (we take their coordinates at the beginning of the last turn before the hit), and do a  preciser tracking
     cout <<" "<<endl;
       cout <<"********************************"<<endl;
@@ -1101,4 +1102,5 @@
 
         for (int m(0); m < lat.nhitcolli.size(); ++m) {
+	    cout << "m = " << m << "nhitcollio[m] is: " << nhitcollio[m] << " lat.nhitcolli[m] is:  " << lat.nhitcolli[m] << endl; 
             nhitcollio[m] = nhitcollio[m] + lat.nhitcolli[m];
         }
@@ -1106,4 +1108,5 @@
         for (int m(0); m < lat.nhitspoiler.size(); ++m) {
             nhitspoilero[m] = nhitspoilero[m] + lat.nhitspoiler[m];
+	    
         }
 
@@ -1871,12 +1874,12 @@
 
 
-void Simulation::genbunch(const int& i0, const int& npart, const string& partdistr, const double& r1r2skin, const double& emx, const double& emy, const double& sigdpp, const double& bx, const double& ax, const double& dx, const double& dpx, const double& by, const double& ay, const double& dy, const double& dpy, const double& nsigi)
+void Simulation::genbunch(const int& i0, const int& npart, const string& partdistr, const double& r1r2skin, const double& emx, const double& emy, const double& sigdpp, const double& bx, const double& ax, const double& dx, const double& dpx, const double& by, const double& ay, const double& dy, const double& dpy, const double& nsigi, const string& inputfile)
 {
 
   //save bunch distribution
   
-  //string path1;
-  //path1 = outputpath + "initial.dat";
-  ofstream sortie("initial.dat");
+  string outfile;
+  outfile = inputfile + "initial.dat";
+  ofstream sortie(outfile.c_str());
   
   if (sortie.fail()) {
@@ -1999,5 +2002,5 @@
         sortie << endl;
 
-        sortie << "Number of particles that have hit another element during a preceding turn (asumhits):";
+        sortie << "(Total) Number of particles that have hit another element during the preceding turns (asumhits):";
 
         for (int i(0); i < asumhits.size(); ++i) {
@@ -2007,5 +2010,5 @@
         sortie << endl;
 
-        sortie << "Number of particles that have hit the collimators, for each collimator (nhitcolli):";
+        sortie << "(Total) Number of particles that have hit the collimators, for each collimator (nhitcolli):";
 
         for (int i(0); i < nhitcollio.size(); ++i) {
@@ -2102,5 +2105,5 @@
 
         for (int i(0); i < plosslocal.size(); ++i) {
-            outplot1 << setw(10) <<  plosslocal[i]*PlossPb / NLostTotal << setw(10) << zlosslocal[i] / 1000 << endl;
+            outplot1<< setw(10) <<  plosslocal[i]*PlossPb / NLostTotal << setw(10) << zlosslocal[i] / 1000 << endl;
         }
 
@@ -2190,4 +2193,5 @@
     vector <int> newnhitcolli, ipsnew;
 
+    cout << " size of nhitcollio.size():  "<<nhitcollio.size()<<endl;
     for (int i(0); i < nhitcollio.size(); ++i) {
         if (removedCollimators[i] == 0) {
@@ -2209,5 +2213,6 @@
 
         for (int i(0); i < newnhitcolli.size(); ++i) {
-            outplot3 << setw(10) << i + 1 << setw(10) <<  newnhitcolli[i]*PlossPb / NLostTotal << setw(10) << ipsnew[i] << setw(20) << lat.reseau[ipsnew[i]]->NAME << endl;
+	  cout << newnhitcolli[i]*PlossPb / NLostTotal << endl;
+            outplot3 << setw(10) << i + 1 << setw(20) <<  newnhitcolli[i]*PlossPb / NLostTotal << setw(10) << ipsnew[i] << setw(20) << lat.reseau[ipsnew[i]]->NAME << endl;
         }
         outplot3.close();
@@ -2262,5 +2267,5 @@
 
         for (int i(0); i < asumrem.size(); ++i) {
-            outplot4 << setw(10) << i << setw(10) <<  asumrem[i] << setw(10) << asumhitcolli[i] << setw(10) << asumhits[i] << endl;
+            outplot4 << setw(10) << i << setw(10) <<  asumrem[i] << setw(10) << asumhitcolli[i] << setw(10) << asumhits[i] << setw(10) << (asumrem[i]+asumhitcolli[i]+asumhits[i])<<endl;
         }
         outplot4.close();
@@ -2273,4 +2278,8 @@
     //Writing PlotRunSummary1.p
 
+    //flag to switch to generate GUNPLOT script or not, default is false
+    bool gnuplotflag = true;
+    if(gnuplotflag)
+    {
     ofstream PlotRun1;
     string plotrunname1;
@@ -2288,5 +2297,5 @@
         PlotRun1 << "set key default" << endl;
         PlotRun1 << "set xrange [-1:]" << endl;
-        PlotRun1 << "set ylabel \"P\'(W/m)\"" << endl;
+        PlotRun1 << "set ylabel \"P\' (W/m)\"" << endl;
         PlotRun1 << "set xlabel \"Distance from starting point (km)\"" << endl;
         PlotRun1 << "set title \"Loss map\"" << endl << endl;
@@ -2352,4 +2361,6 @@
     }
 
+    }
+    
 }
 
