Index: /esaf_lal/branches/camille/packages/g4libs.gmk
===================================================================
--- /esaf_lal/branches/camille/packages/g4libs.gmk	(revision 183)
+++ /esaf_lal/branches/camille/packages/g4libs.gmk	(revision 184)
@@ -1,8 +1,29 @@
 #this config file includes Geant4 libs
+
+ifneq ($(shell which geant4-config 2>/dev/null),)
+    G4LIBS := $(shell geant4-config --libs)
+    G4INCLUDES := $(shell geant4-config --cflags)
+    USE_G4 = 1
+    export USE_G4 G4LIBS G4INCLUDES
+else
 ifdef G4INSTALL
-GEANT_LIBDIR := $(G4INSTALL)/lib/Linux-g++
-G4LIBS   := -L${GEANT_LIBDIR} $(shell cat ${GEANT_LIBDIR}/libname.map | ${GEANT_LIBDIR}/liblist -m ${GEANT_LIBDIR})
-G4LIBS   += -L${CLHEP_LIB_DIR} -l${CLHEP_LIB} 
-#-L/usr/lib -lxerces-c-3.1
-export G4LIBS
+    GEANT_LIBDIR := $(G4INSTALL)/lib/Linux-g++
+    G4LIBS   := -L${GEANT_LIBDIR} $(shell cat ${GEANT_LIBDIR}/libname.map | ${GEANT_LIBDIR}/liblist -m ${GEANT_LIBDIR})
+    G4LIBS   += -L${CLHEP_LIB_DIR} -l${CLHEP_LIB} 
+
+    G4INCLUDES += -I$(G4INSTALL)/include
+    G4INCLUDES += -I$(CLHEP_INCLUDE_DIR)
+
+    USE_G4 = 1
+
+ifdef VGM_INSTALL
+    VGMINCLUDES := -I$(VGM_INSTALL)/packages/VGM/include
+    VGMINCLUDES += -I$(VGM_INSTALL)/packages/BaseVGM/include
+    VGMINCLUDES += -I$(VGM_INSTALL)/packages/Geant4GM/include
+    VGMINCLUDES += -I$(VGM_INSTALL)/packages/RootGM/include
+    export VGMINCLUDES
 endif
+
+    export USE_G4 G4LIBS G4INCLUDES 
+endif
+endif
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/GNUmakefile
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/GNUmakefile	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/GNUmakefile	(revision 184)
@@ -17,5 +17,4 @@
 
 include $(ESAFINSTALL)/packages/config.gmk
-#include $(G4INSTALL)/config/G4VIS_USE.gmk
 
 # Include paths needed for rootcint dictionary generation
@@ -24,6 +23,5 @@
 INCLUDES += -I$(ESAFPACKAGES)/common/root/include
 INCLUDES += -I$(ESAFPACKAGES)/simulation/tools/include
-INCLUDES += -I$(G4INSTALL)/include
-INCLUDES += -I$(CLHEP_INCLUDE_DIR)
+INCLUDES += $(G4INCLUDES)
 
 # headers and settings needed for the local library compilation
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/include/FresnelSurface.h
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/include/FresnelSurface.h	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/include/FresnelSurface.h	(revision 184)
@@ -21,5 +21,5 @@
 
     void setSmoothedEdges(double rad);
-    double PointOnSurf(double x) { AbstractMethod(); return kInfinity; }
+    double PointOnSurf(double x);
     double DistanceToSurf(const G4ThreeVector& p, const G4ThreeVector& v){ AbstractMethod(); return kInfinity; }
     double DistanceToSurf(const G4ThreeVector& p, const G4ThreeVector& v, FSIntersectedSegment*){ AbstractMethod(); return kInfinity; }
@@ -47,4 +47,5 @@
     int     GetNTeeth()     { return theToothN-1; }
     std::vector<SSurface*>& GetTeeth() { return fSurfaces; }
+    
 protected:
     #ifdef USE_ROOT
@@ -53,4 +54,5 @@
     void FillArray(int n, double* rho, double* z);
     void FillArray(const std::vector<SSurface*>& surf);
+    int FindTooth( double rho );
 
     /// Surfaces
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/include/SSurface.h
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/include/SSurface.h	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/include/SSurface.h	(revision 184)
@@ -9,4 +9,5 @@
 
 #include <geomdefs.hh>
+#include <assert.h>
 #include <G4ThreeVector.hh>
 class G4PhysicalVolume;
@@ -58,5 +59,5 @@
 
     // plug for temporarily unimplemented methods
-    void AbstractMethod() { fprintf(stderr, "Error, calling the unimplemented method"); exit(1); }
+    void AbstractMethod() { fprintf(stderr, "Error, calling the unimplemented method. The method was not supposed to be used."); assert(false); }
 protected:
     double fR1;
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/include/ShapeOfLens.h
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/include/ShapeOfLens.h	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/include/ShapeOfLens.h	(revision 184)
@@ -63,7 +63,7 @@
 
     void DescribeYourselfTo(G4VGraphicsScene& scene) const;
-/*    G4Polyhedron* CreatePolyhedron() const;
+    G4Polyhedron* CreatePolyhedron() const;
     G4Polyhedron* GetPolyhedron () const;
-    G4NURBS*      CreateNURBS() const;*/
+    G4NURBS*      CreateNURBS() const;
 
     void GetCylinderLimits(double& r, double& z1, double& z2) { r=fR; z1=fZ1; z2=fZ2; }
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/src/FresnelSurface.cc
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/src/FresnelSurface.cc	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/src/FresnelSurface.cc	(revision 184)
@@ -46,4 +46,16 @@
     }
     fSurfacesIns.clear();
+}
+
+//__________________________________________________________________________________
+int FresnelSurface::FindTooth( double rho ) { 
+    return BinarySearch(theToothEdges, rho, 0, theToothN); 
+} 
+
+//__________________________________________________________________________________
+double FresnelSurface::PointOnSurf(double rho) { 
+    int n_tooth = FindTooth( rho );
+    if( n_tooth<0 ) return kInfinity;
+    return fSurfacesIns[ n_tooth*2 ]->PointOnSurf( rho );   
 }
 
@@ -180,5 +192,5 @@
       }
     #endif
-    int n_tooth = BinarySearch(theToothEdges,rho,0,theToothN);
+    int n_tooth = FindTooth( rho );
     if( n_tooth<0 ) {
         printf("Warning. Tooth not found. Shouldn't happen (rho=%g of [%g, %g]).",
@@ -255,5 +267,5 @@
     }// approach to the limiting surface
 
-    int theCurrentToothIndex=BinarySearch(theToothEdges, perp, 0, theToothN);
+    int theCurrentToothIndex=FindTooth( perp );
     if ( theCurrentToothIndex<0 ) return kInfinity;
     vector<SSurface*>::const_iterator it=fSurfaces.begin()+theCurrentToothIndex*2;
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/src/ShapeOfLens.cc
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/src/ShapeOfLens.cc	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/G4fresnellens/src/ShapeOfLens.cc	(revision 184)
@@ -463,7 +463,8 @@
                                    GetTrack()->GetTrackID();
             printf("Event %i, %s\n", id, GetName().data());
-            printf("pos(%.10g,%.10g,%.10g)\n", p.x(), p.y(), p.z());
             double rho=p.perp();
-            printf("dz1 %g, dz2 %g\n", p.z()-fUpSurface->PointOnSurf(rho),p.z()-fDownSurface->PointOnSurf(rho));
+            printf("pos (%.10g,%.10g,%.10g), rho=%.10g\n", p.x(), p.y(), p.z(), rho);
+            double z1=fUpSurface->PointOnSurf(rho), z2=fDownSurface->PointOnSurf(rho);
+            printf("dz1 %g, dz2 %g: z1, z2 (%g, %g)\n", p.z()-z1,p.z()-z2, z1, z2);
             return norm;
         }
@@ -518,4 +519,20 @@
     top_volume->DescribeYourselfTo(scene);
 }
+    
+//__________________________________________________________________________________
+G4Polyhedron* ShapeOfLens::CreatePolyhedron() const {
+  return top_volume->CreatePolyhedron();
+}
+
+//__________________________________________________________________________________
+G4Polyhedron* ShapeOfLens::GetPolyhedron () const {
+  return top_volume->GetPolyhedron();
+}
+
+//__________________________________________________________________________________
+G4NURBS*      ShapeOfLens::CreateNURBS() const {
+  return top_volume->CreateNURBS();
+}
+
 //__________________________________________________________________________________
 G4ThreeVector ShapeOfLens::GetPointOnSurface() const{
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/GNUmakefile
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/GNUmakefile	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/GNUmakefile	(revision 184)
@@ -1,6 +1,4 @@
 
-ifdef G4INSTALL
 SUBDIRS = optics G4fresnellens
-endif
 
 .PHONY: clean cleandict obj lib tags doc all
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/GNUmakefile
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/GNUmakefile	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/GNUmakefile	(revision 184)
@@ -35,10 +35,10 @@
 INCLUDES += -I$(G4INSTALL)/include
 INCLUDES += -I$(CLHEP_INCLUDE_DIR)
-ifdef VGM_INSTALL
-INCLUDES += -I$(VGM_INSTALL)/packages/VGM/include
-INCLUDES += -I$(VGM_INSTALL)/packages/BaseVGM/include
-INCLUDES += -I$(VGM_INSTALL)/packages/Geant4GM/include
-INCLUDES += -I$(VGM_INSTALL)/packages/RootGM/include
+INCLUDES += $(G4INCLUDES)
+ifdef VGMINCLUDES
+    INCLUDES += $(VGMINCLUDES)
 endif
+#
+#
 # headers and settings needed for the local library compilation
 CXXFLAGS += $(INCLUDES) $(CPPFLAGS)
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/include/OptPrimaryGeneratorAction.hh
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/include/OptPrimaryGeneratorAction.hh	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/include/OptPrimaryGeneratorAction.hh	(revision 184)
@@ -23,4 +23,5 @@
         void Init();
         void FillCircle(G4Event*);
+        void FillSphere(G4Event*);
         void OnePoint(G4Event* anEvent);
         void GenerateEnergy();
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/include/OptSteppingAction.hh
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/include/OptSteppingAction.hh	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/include/OptSteppingAction.hh	(revision 184)
@@ -26,4 +26,5 @@
     G4OpBoundaryProcessStatus   theStatus;
     int                         fStatus;
+    int                         fStatusKilled;
     OptUserStackingAction*      fStacking;
 
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/include/OptUserStackingAction.hh
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/include/OptUserStackingAction.hh	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/include/OptUserStackingAction.hh	(revision 184)
@@ -21,4 +21,7 @@
 class G4TrackInformation;
 class ListPhotonsOnPupil;
+
+class TGraph2D;
+
 class OptUserStackingAction : public G4UserStackingAction, public G4UserTrackingAction, public G4UserEventAction, public EsafMsgSource, public VirtualTelParm  {
 public:
@@ -35,4 +38,5 @@
     void PrepareNewEvent();
     void SetPupil(PhotonsOnPupil*);
+ 
     void SetNmax(int m) { fNmax=m; }
     void Progress(int, const char*);
@@ -44,11 +48,13 @@
     void SetTrackHistory(int hist){fTrackHistory=hist;}
     OptSteppingAction* stepping;
-
+    
+    G4Track* NewPhoton(Photon*,int,int n=0);
+    void     Reset();
 private:
 
     bool GoToElectronics(Photon*);
-    void     Reset();
+    
     EVector  NewInteractionPoint(const Photon *p, double DZ) const;
-    G4Track* NewPhoton(Photon*,int,int n=0);
+    
     void CheckTrace(int id,const G4ThreeVector& pos,const G4ThreeVector& mom,double lambda,double time);
 
@@ -64,5 +70,7 @@
     double   fTimeFirstPhoton;
     double   fTimeLastPhoton;
-
+    
+    int     fNReflElec;
+    
     int     fNTracked;
     int     fNG4Tracked;
@@ -70,11 +78,17 @@
     int     fNTotal;
     int     fNG4focalplane;
+    int     fNiris;
     int     fNfocalplane;
     int     fNlost;
     int     fNoptics;
+		int     fNwalls;
+		int     fNearth;
     int     fProgress;
     int     fTrackHistory;
     int     forigin;
     bool    ftus;
+    
+    TGraph2D* f_before;
+    TGraph2D* f_after;
     ListPhotonsOnPupil* fPhOnPupil;
 };
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/G4Detector.cc
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/G4Detector.cc	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/G4Detector.cc	(revision 184)
@@ -12,8 +12,9 @@
 #include "OpticsFactory.hh"
 #include "Pupil.hh"
-
+#include "ParentPhoton.hh"
+#include "Photon.hh"
 
 #include <TMath.h>
-
+#include <TFile.h>
 using namespace sou;
 
@@ -101,8 +102,46 @@
 
     // wrapper to track the photons onto the real pupil
+    
+//     TFile f("output/event.root","RECREATE");
+    
     Pupil pupil( photons, GetGeometry());
+/*		
+		TTree* t = new TTree("t","tt");
+		Photon* photon =0;
+		ParentPhoton* pp =0;*/
 
+// 		TVector3 vpos(0.,0.,0.);
+// 		TVector3 vdir(0.,0.,0.);
+// 		
+// 		t->Branch("position","TVector3",&vpos);
+// 		t->Branch("direction","TVector3",&vdir);
+// 		t->Branch("wl",&wl,"w/D");
+// 		t->Branch("flag",&fl,"flag/I");
+
+// 		t->Branch("photon","ParentPhoton",&pp);
     if(pupil.GetNphotons()==0) Msg(EsafMsg::Warning)  << "NO PHOTONS ON PUPIL !!!"<< MsgDispatch;
-    else Msg(EsafMsg::Info)  << "PHOTONS ON PUPIL: "<<pupil.GetNphotons()<< MsgDispatch;
+    else {Msg(EsafMsg::Info)  << "PHOTONS ON PUPIL: "<<pupil.GetNphotons()<< MsgDispatch;
+// 			photon = pupil.GetPhoton();
+// 			pp=photon->parent;
+// 			printf("www  %g\n",pp->W());
+// 			int id=0;
+// 			
+// 		  while(id<pupil.GetNphotons()){
+// 				photon->id = id;
+// 				t->Fill();
+// 				
+// 				photon = pupil.GetPhoton();
+// 				if(photon){
+// 					pp=photon->parent;
+// 					printf("www  %g\n",pp->W());
+// 					
+// 				}
+// 				id++;
+// 	//			photon->Dump();
+// 			
+// 			}
+// 			f.Write();
+// 			f.Close();
+		}
 
     // transport photons from pupil to pmts
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/G4EusoGeometryShape.cc
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/G4EusoGeometryShape.cc	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/G4EusoGeometryShape.cc	(revision 184)
@@ -64,5 +64,5 @@
     expHall_x = expHall_y = 2000.*mm;
     expHall_z = 4000.*mm;
-    fit=true;
+    fit = Conf()->GetBool("G4EusoGeometryShape.UseFitTransmittivity");
     CYTOP=0;
     PMMA=0;
@@ -258,15 +258,7 @@
     ShapeOfLens* lens1_solid = new ShapeOfLens("FresnelLens_1", (thin*0.5+0.5)*mm, (r_wall+1.)*mm, upsurf1, downsurf1);
 
-//     downsurf1->draw(lens_file, 0, surf1, "S1", "RECREATE");
-//     upsurf1->draw(lens_file, 0, surf1, "S2", "UPDATE");
     G4IntersectionSolid* intersec1 = new G4IntersectionSolid("box*FresnelLens_1", box, lens1_solid);
     G4LogicalVolume* lens1_log = new G4LogicalVolume(intersec1,!strcmp(mat,"CYTOP")?CYTOP:PMMA, "FresnelLens_1",0,0,0);
     
-//     lens1_solid->GetCylinderLimits(c_rad, c_z1, c_z2);
-//     c_dz=(fabs(c_z2)+fabs(c_z1));
-//     G4Tubs* lens1_mother_solid=new G4Tubs("lens1_mother",0., c_rad+10.*mm, c_dz+10.*mm, 0.*deg, 360.*deg);
-//     G4LogicalVolume* lens1_mother_log = new G4LogicalVolume(lens1_mother_solid, Vacuum, "FresnelLens_1_mother",0,0,0);
-//     G4VPhysicalVolume* lens1_mother_phys = new G4PVPlacement(0, G4ThreeVector(0.,0.,surf1), lens1_mother_log, "FresnelLens_1_mother", expHall_log,false,0);
-
     #ifndef DISABLE_1_LENSphys
     G4VPhysicalVolume* lens1_phys = new G4PVPlacement(0, G4ThreeVector(0.,0.,surf1), lens1_log, "FresnelLens_1", expHall_log,false,0);
@@ -313,14 +305,5 @@
     G4LogicalVolume* lens2_log = new G4LogicalVolume(intersec2,!strcmp(mat,"CYTOP")?CYTOP:PMMA, "FresnelLens_2",0,0,0);
 
-//     downsurf2->draw(lens_file, 0, surf1, "S4", "UPDATE");
-//     upsurf2->draw(lens_file, 0, surf1, "S5", "UPDATE");
-
-//     lens2_solid->GetCylinderLimits(c_rad, c_z1, c_z2);
-//     c_dz=(fabs(c_z2)+fabs(c_z1));
-//     G4Tubs* lens2_mother_solid=new G4Tubs("lens2_mother",0., c_rad+10.*mm, c_dz+10.*mm, 0.*deg, 360.*deg);
-//     G4LogicalVolume* lens2_mother_log = new G4LogicalVolume(lens2_mother_solid, Vacuum, "FresnelLens_2_mother",0,0,0);
-//     G4VPhysicalVolume* lens2_mother_phys = new G4PVPlacement(0, G4ThreeVector(0.,0.,surf1), lens2_mother_log, "FresnelLens_2_mother", expHall_log,false,0);
-
-    double diffr_rad=rsurf5; //FIXME
+    double diffr_rad=rsurf5; //FIXME: diffractive surface is shorter than surf5
     double diffr_dz=1.e-8;
     G4VSolid* euso_diffractor;
@@ -332,6 +315,4 @@
         ParametricSurface* upsurf_diffr = new SphericSurface(Rc2*mm,Rc2*mm+diffr_dz,rsurf5*mm);
         ParametricSurface* downsurf_diffr = new SphericSurface(Rc2*mm,Rc2*mm-diffr_dz,rsurf5*mm);
-//         downsurf_diffr->draw(lens_file, 0, surf1+thin+diffr_dz+fGeomTolerance, "D1", "UPDATE");
-//         upsurf_diffr->draw(lens_file, 0, surf1+thin+diffr_dz+fGeomTolerance, "D2", "UPDATE");
         euso_diffractor=new ShapeOfLens("euso_diffractor_par", diffr_dz, diffr_rad, upsurf_diffr, downsurf_diffr);
 	
@@ -375,6 +356,4 @@
      ShapeOfLens* lens3_solid = new ShapeOfLens("FresnelLens_3",(thin*0.5+0.5)*mm, (r_wall+1.)*mm, upsurf3, downsurf3);
      G4IntersectionSolid* intersec3 = new G4IntersectionSolid("box*FresnelLens_3", box, lens3_solid);
-//      downsurf3->draw(lens_file, 0, surf1, "S6", "UPDATE");
-//      upsurf3->draw(lens_file, 0, surf1, "S7", "UPDATE");
 
      G4LogicalVolume* lens3_log = new G4LogicalVolume(intersec3,!strcmp(mat,"CYTOP")?CYTOP:PMMA, "FresnelLens_3",0,0,0);
@@ -395,5 +374,4 @@
     double fs_dz=10.*mm;
     double fs_pos= ((fOpticalSystemParam->FS_OFFSET-surf2)*0.5+surf2)*mm;//surf1+c_dz+15.*mm+fs_dz;
-   // printf("fpos************************ %g",fs_pos);
     double fs_rad=fOpticalSystemParam->r_fs*mm;
 
@@ -418,5 +396,5 @@
 
         /*G4VPhysicalVolume* iris_phys = */
-        new G4PVPlacement(0,G4ThreeVector(0,0,iris_dz+iris_thickness),iris_log,"irisr",expHall_log,false,0);
+        new G4PVPlacement(0,G4ThreeVector(0,0,iris_dz+iris_thickness),iris_log,"iris",expHall_log,false,0);
     }
     else Msg(EsafMsg::Warning) << "IRIS is turned off." << MsgDispatch;
@@ -466,11 +444,5 @@
             TGraph* ph = new TGraph(fmatname);
             TF1* f=new TF1("ri","1./(x+[0])*[1]+1./(x*x+[2])*[3]+[4]",200.,600.);
-            //printf("mp2 fit\n");
             ph->Fit(f,"QNO","",250.,500.);//NOS
-            //TFile ff("fit.root","RECREATE");
-            //ph->Draw("A*");
-            //ph->Write("fit");
-            //ff.Close();
-            //printf("mp2 fit\n");
             mp->setRealRI(f,250.,500.);
             mp->setTrans(Form("%s/pmma_transmittivity.dat",lens_dir));
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/G4TusGeometry.cc
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/G4TusGeometry.cc	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/G4TusGeometry.cc	(revision 184)
@@ -24,6 +24,6 @@
 #include <G4Polyhedra.hh>
 
-#include <Geant4GM/volumes/Factory.h>
-#include <RootGM/volumes/Factory.h>
+//#include <Geant4GM/volumes/Factory.h>
+//#include <RootGM/volumes/Factory.h>
 
 
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OpEUSODiffraction.cc
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OpEUSODiffraction.cc	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OpEUSODiffraction.cc	(revision 184)
@@ -8,4 +8,5 @@
 #include <G4TransportationManager.hh>
 #include <G4Navigator.hh>
+#include <G4Version.hh>
 
 #include <TGraph.h>
@@ -93,5 +94,9 @@
     }
     if ( Rindex ) {
-        Rindex1 = Rindex->GetProperty(thePhotonMomentum);
+		#if G4VERSION_NUMBER<950
+            Rindex1 = Rindex->GetProperty(thePhotonMomentum);//g9.4
+		#else
+        	Rindex1 = Rindex->Value(thePhotonMomentum); //g9.5
+		#endif
     } else {
         theStatus = edNoINDEX;
@@ -108,5 +113,9 @@
 
     if ( Rindex ) {
-        Rindex2 = Rindex->GetProperty(thePhotonMomentum);
+		#if G4VERSION_NUMBER<950
+        	Rindex2 = Rindex->GetProperty(thePhotonMomentum);//g9.4
+		#else
+            Rindex2 = Rindex->Value(thePhotonMomentum);//g9.5
+		#endif
     } else {
         theStatus = edNoINDEX;
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptPhysicsList.cc
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptPhysicsList.cc	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptPhysicsList.cc	(revision 184)
@@ -115,6 +115,6 @@
 {
   AddTransportation();
-   ConstructGeneral();
-   ConstructEM();
+//    ConstructGeneral();
+  ConstructEM();
   ConstructOp();
 }
@@ -136,8 +136,8 @@
     if (theDecayProcess->IsApplicable(*particle)) {
         pmanager->AddDiscreteProcess(theDecayProcess);
-//      pmanager ->AddProcess(theDecayProcess);
-//       // set ordering for PostStepDoIt and AtRestDoIt
-//       pmanager ->SetProcessOrdering(theDecayProcess, idxPostStep);
-//       pmanager ->SetProcessOrdering(theDecayProcess, idxAtRest);
+     pmanager ->AddProcess(theDecayProcess);
+      // set ordering for PostStepDoIt and AtRestDoIt
+      pmanager ->SetProcessOrdering(theDecayProcess, idxPostStep);
+      pmanager ->SetProcessOrdering(theDecayProcess, idxAtRest);
     }
   }
@@ -234,8 +234,8 @@
   if ( use_diffraction ) theEUSODiffractionProcess = new OpEUSODiffraction();
   else Msg(EsafMsg::Warning) << "Diffraction is turned off." << MsgDispatch;
-    theCerenkovProcess           -> SetVerboseLevel(0);
-    theAbsorptionProcess         -> SetVerboseLevel(0);
-    theRayleighScatteringProcess -> SetVerboseLevel(0);
-    theBoundaryProcess           -> SetVerboseLevel(0);
+//   theCerenkovProcess           -> SetVerboseLevel(0);
+//   theAbsorptionProcess         -> SetVerboseLevel(0);
+//   theRayleighScatteringProcess -> SetVerboseLevel(0);
+//   theBoundaryProcess           -> SetVerboseLevel(0);
 //  theCerenkovProcess->DumpPhysicsTable();
 //  theScintillationProcess->DumpPhysicsTable();
@@ -243,12 +243,7 @@
 //  theRayleighScatteringProcess->DumpPhysicsTable();
 
- // theCerenkovProcess->SetMaxNumPhotonsPerStep(300);
-  theCerenkovProcess->SetTrackSecondariesFirst(true);
-/*
-  theScintillationProcess->SetScintillationYieldFactor(1.);
-  theScintillationProcess->SetTrackSecondariesFirst(true);*/
-
-//   G4EmSaturation* emSaturation = G4LossTableManager::Instance()->EmSaturation();
-//   theScintillationProcess->AddSaturation(emSaturation);
+ //theCerenkovProcess->SetMaxNumPhotonsPerStep(300);
+//    theCerenkovProcess->SetTrackSecondariesFirst(true);
+
 
   G4OpticalSurfaceModel themodel = unified;
@@ -265,9 +260,5 @@
       pmanager->SetProcessOrdering(theCerenkovProcess,idxPostStep);
     }
-//     if (theScintillationProcess->IsApplicable(*particle)) {
-//       pmanager->AddProcess(theScintillationProcess);
-//       pmanager->SetProcessOrderingToLast(theScintillationProcess, idxAtRest);
-//       pmanager->SetProcessOrderingToLast(theScintillationProcess, idxPostStep);
-//     }
+
     if (particleName == "opticalphoton") {
       G4cout << " AddDiscreteProcess to OpticalPhoton " << G4endl;
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptPrimaryGeneratorAction.cc
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptPrimaryGeneratorAction.cc	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptPrimaryGeneratorAction.cc	(revision 184)
@@ -79,4 +79,6 @@
     else if(!FillPosition.compare ("Point"))
         OnePoint(anEvent);
+    else if(!FillPosition.compare ("Sphere"))
+        FillSphere(anEvent);
 
 }
@@ -142,3 +144,13 @@
 
 
+//-----------------------------------------------------------------------------------------
+void OptPrimaryGeneratorAction::FillSphere(G4Event* anEvent){
+    TVector3 p;
+    double phi = gRandom->Uniform(0.,TwoPi());
+    double th = gRandom->Uniform(Pi()-asin(1325./3143.57795946),Pi());
+    p.SetMagThetaPhi(3143.57795946,th,phi);
+    p.SetZ(p.Z()+3143.57795946+78.);
+    particleGun->SetParticlePosition(G4ThreeVector(p.X(),p.Y(),p.Z()));
+    particleGun->GeneratePrimaryVertex(anEvent);
+}
 
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptSteppingAction.cc
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptSteppingAction.cc	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptSteppingAction.cc	(revision 184)
@@ -53,5 +53,6 @@
     kWalls                    = 5,
     kEarth                    = 6,
-    kG4FocalSurface           = 7
+    kIris                     = 7,
+    kG4FocalSurface           = 8
 };
 
@@ -59,15 +60,17 @@
 {
     //theStatus = Undefined;
+    //double fGeomTolerance=G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
+
     fBoundary = NULL;
     fProcessManager = NULL;
     fProcessVector = NULL;
     fStatus = 0;
+    fStatusKilled = 0;
     fStacking = stack;
     ConfigFileParser* conf = Config::Get()->GetCF("G4","G4Detector");
     string det=conf->GetStr("G4Detector.DetectorType");
-    //double fGeomTolerance=G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
     if (det.find("Tus")!=string::npos){
-	fTus=true;
-        cover=0; 
+      fTus=true;
+      cover=0; 
     }
     else {
@@ -87,4 +90,5 @@
     }
     SetSender("OptSteppingAction");
+	
 
 }
@@ -92,158 +96,139 @@
 OptSteppingAction::~OptSteppingAction()
 {
-
+	
 }
 
 void OptSteppingAction::UserSteppingAction(const G4Step * theStep)
 {
-    G4VPhysicalVolume* prevol=theStep->GetPreStepPoint()->GetPhysicalVolume();
-    G4VPhysicalVolume* postvol=theStep->GetPostStepPoint()->GetPhysicalVolume();
-    G4String PreStepVolume,PostStepVolume;
-    if(prevol){
-        PreStepVolume = prevol->GetName();
-    }
-    if(postvol){
-        PostStepVolume = postvol->GetName();
-    }
-    
-    G4StepPoint *PostStep = 0;
-    G4StepPoint *PreStep = 0;
-    G4ThreeVector pre_pos, pre_dir;
-    G4ThreeVector post_pos, post_dir;
-    
-    PreStep = theStep->GetPreStepPoint();
-    pre_pos = PreStep->GetPosition();
-    pre_dir = PreStep->GetMomentumDirection();
-    PostStep = theStep->GetPostStepPoint();
-    post_pos =  PostStep->GetPosition();
-    post_dir =  PostStep->GetMomentumDirection();
-
-    
-    fStepCounter++;
-    if ( fStepCounter>fMaxIterations ){
-        theStep->GetTrack()->SetTrackStatus(fStopAndKill);
-        MsgForm(EsafMsg::Warning,"This photon exceeded the maximum number of iterations (%i), killed.",fMaxIterations);
-    }
+  G4VPhysicalVolume* prevol=theStep->GetPreStepPoint()->GetPhysicalVolume();
+  G4VPhysicalVolume* postvol=theStep->GetPostStepPoint()->GetPhysicalVolume();
+  G4String PreStepVolume,PostStepVolume;
+  if(prevol){
+    PreStepVolume = prevol->GetName();
+  }
+  if(postvol){
+    PostStepVolume = postvol->GetName();
+  }
+    
+  G4StepPoint *PostStep = 0;
+  G4StepPoint *PreStep = 0;
+  G4ThreeVector pre_pos, pre_dir;
+  G4ThreeVector post_pos, post_dir;
+  
+  PreStep = theStep->GetPreStepPoint();
+  pre_pos = PreStep->GetPosition();
+  pre_dir = PreStep->GetMomentumDirection();
+  PostStep = theStep->GetPostStepPoint();
+  post_pos =  PostStep->GetPosition();
+  post_dir =  PostStep->GetMomentumDirection();
+
+    
+  fStepCounter++;
+  if ( fStepCounter>fMaxIterations ){
+    theStep->GetTrack()->SetTrackStatus(fStopAndKill);
+    MsgForm(EsafMsg::Warning,"This photon exceeded the maximum number of iterations (%i), killed.",fMaxIterations);
+    fStatus=-3;
+    fStatusKilled++;
+  }
 
     //find the boundary process only once
-    if( !fBoundary ){
-        fProcessManager = theStep->GetTrack()->GetDefinition()->GetProcessManager();
-        G4int nprocesses = fProcessManager->GetProcessListLength();
-        fProcessVector = fProcessManager->GetProcessList();
-
-        for(int i=0;i<nprocesses;i++){
-            if( (*fProcessVector)[i]->GetProcessName()=="OpBoundary" ){
-                fBoundary = (G4OpBoundaryProcess*)(*fProcessVector)[i];
-                break;
-            }
-        }
-    }
-
-    theStatus = Undefined;
-    if(fBoundary)theStatus = fBoundary->GetStatus();
-
-    double rho = post_pos.perp();
-    if(!fTus && (fabs(post_pos.y())>=r_cut || rho>=r_wall)){
-	if(cover->Inside (pre_pos)==kInside ){
-	    theStep->GetTrack()->SetTrackStatus(fStopAndKill);
-	    fStatus=-4;
-	    double dist = cover->DistanceToOut (pre_pos, pre_dir);
-	    // intersection with virtual wall
-	    
-	    if(dist!=kInfinity ){
-	      //printf("dist %g\n",dist);
-		pre_pos+=pre_dir.unit()*dist;
-		PostStep->SetPosition(pre_pos);
-		PostStep->SetMomentumDirection(pre_dir);
-		post_pos=pre_pos;
-		post_dir=pre_dir;
-		double t = PostStep->GetLocalTime();
-		t+=dist/c_light;
-		PostStep->SetLocalTime(t);
-	    }
-	}
- 	else if(cover->Inside (pre_pos)==kSurface){
-	    
-	    //double newdist= cover->DistanceToIn (pre_pos, pre_dir);
-	    //if(newdist==kInfinity ){
-	      PostStep->SetPosition(pre_pos);
-	      //printf("dist %g\n",newdist);
-	    //}
-//  	    if(newdist!=kInfinity ){
-// 		pre_pos-=pre_dir.unit()*newdist;
-		//pre_pos.z()=0.;
-// 		PostStep->SetPosition(pre_pos);
-// 		PostStep->SetMomentumDirection(pre_dir);
-// 		post_pos=pre_pos;
-// 		post_dir=pre_dir;
-// 		double t = PostStep->GetLocalTime();
-// 		t-=newdist/c_light;
-// 		PostStep->SetLocalTime(t);
-// 		
-// 	    
-// 	    
-// 	    
-// 	    }
-// 	    
-// 	
- 	}
- 	else PostStep->SetPosition(pre_pos);
-	
-    }
-
-  
-    if ( PostStep && fStatus!=-4 && PostStep->GetStepStatus()==fPostStepDoItProc &&
-         theStep->GetTrack()->GetTrackStatus()==fStopAndKill ) fStatus=-3;
-
-    if(postvol){
+  if( !fBoundary ){
+    fProcessManager = theStep->GetTrack()->GetDefinition()->GetProcessManager();
+    G4int nprocesses = fProcessManager->GetProcessListLength();
+    fProcessVector = fProcessManager->GetProcessList();
+
+    for(int i=0;i<nprocesses;i++){
+      if( (*fProcessVector)[i]->GetProcessName()=="OpBoundary" ){
+        fBoundary = (G4OpBoundaryProcess*)(*fProcessVector)[i];
+        break;
+      }
+    }
+  }
+
+  theStatus = Undefined;
+  if(fBoundary)theStatus = fBoundary->GetStatus();
+
+  double rho = post_pos.perp();
+  if(!fTus && (fabs(post_pos.y())>=r_cut || rho>=r_wall)){
+    if(cover->Inside (pre_pos)==kInside ){
+      theStep->GetTrack()->SetTrackStatus(fStopAndKill);
+      fStatus=-4;
+      double dist = cover->DistanceToOut (pre_pos, pre_dir);
+      // intersection with virtual wall
       
-        if ( PostStepVolume.contains("FresnelLens") || PreStepVolume.contains("FresnelLens")||
-            PreStepVolume.contains("mirror_phys") ||PostStepVolume.contains("mirror_phys") ){
-            if(fStatus==0) fStatus++;
-        }
-
-        if(PostStepVolume=="absorber"){
-	    
-            theStep->GetTrack()->SetTrackStatus(fStopAndKill);
-            fStatus=(fStatus>0?-2:-1);
-	    if(fStatus==-1||fStatus==-2)PostStep->SetPosition(pre_pos);
-        }
-    }
+      if(dist!=kInfinity ){
+				pre_pos+=pre_dir.unit()*dist;
+				PostStep->SetPosition(pre_pos);
+				PostStep->SetMomentumDirection(pre_dir);
+				post_pos=pre_pos;
+				post_dir=pre_dir;
+				double t = PostStep->GetLocalTime();
+				t+=dist/c_light;
+				PostStep->SetLocalTime(t);
+			}
+    }
+    else if(cover->Inside (pre_pos)==kSurface)
+      PostStep->SetPosition(pre_pos);
+    else PostStep->SetPosition(pre_pos);
+    
+  }
+  
+  if ( PostStep && fStatus!=-4 && PostStep->GetStepStatus()==fPostStepDoItProc &&
+    theStep->GetTrack()->GetTrackStatus()==fStopAndKill ) fStatus=-3;
+
+  if(postvol){
+      
+    if ( PostStepVolume.contains("FresnelLens") || PreStepVolume.contains("FresnelLens")||
+      PreStepVolume.contains("mirror_phys") ||PostStepVolume.contains("mirror_phys") ){
+      if(fStatus==0) fStatus++;
+    }
+
+    if(PostStepVolume=="absorber"){
+  
+      theStep->GetTrack()->SetTrackStatus(fStopAndKill);
+      fStatus=(fStatus>0?-2:-1);
+      if(fStatus==-1||fStatus==-2)PostStep->SetPosition(pre_pos);
+    }
+    
+    if(PostStepVolume=="iris"){
+      fStatus=-5;
+    }
+  }
 
    
-    if ( theStatus==Absorption || theStatus==Detection ){
-        fStatus=-3;
-	
-    }
-    G4TrackStatus TrackStatus = theStep->GetTrack()->GetTrackStatus();
-
-    if(TrackStatus==fStopAndKill){
-        fStepCounter=0;
-        int history;
-        if ( post_pos.z()<0 && post_dir.z()<0  ){
-            history=kEarth;
-            double dist = cover->DistanceToOut (pre_pos, pre_dir);
-        // intersection with virtual wall
-            
-            if(dist!=kInfinity && dist!=0){
-
-                pre_pos+=pre_dir.unit()*dist;
-                PostStep->SetPosition(pre_pos);
-                PostStep->SetMomentumDirection(pre_dir);
-                post_pos=pre_pos;
-                post_dir=pre_dir;
-                double t = PostStep->GetLocalTime();
-                t+=dist/c_light;
-                PostStep->SetLocalTime(t);
-            }
-	 
-	 }
-         else if ( fStatus==-2 ) history=kG4FocalSurface;
-         else if ( fStatus==-3) history=kOptics;
-         else if ( fStatus==-4) history=kWalls;
-         else history=keUndefined;
-
-         fStacking->SetTrackHistory(history);
-         fStatus=0;
-    }
+  if ( theStatus==Absorption || theStatus==Detection ){
+    fStatus=-3;
+
+  }
+  G4TrackStatus TrackStatus = theStep->GetTrack()->GetTrackStatus();
+
+  if(TrackStatus==fStopAndKill){
+    fStepCounter=0;
+    int history;
+  
+    if ( post_pos.z()<=0 && post_dir.z()<0 && !fTus){
+      history=kEarth;
+      double dist = cover->DistanceToOut (pre_pos, pre_dir);
+  // intersection with virtual wall
+      if(dist!=kInfinity && dist!=0){
+        pre_pos+=pre_dir.unit()*dist;
+        PostStep->SetPosition(pre_pos);
+        PostStep->SetMomentumDirection(pre_dir);
+        post_pos=pre_pos;
+        post_dir=pre_dir;
+        double t = PostStep->GetLocalTime();
+        t+=dist/c_light;
+        PostStep->SetLocalTime(t);
+      }
+
+    }
+    else if ( fStatus==-2 ) history=kG4FocalSurface;
+    else if ( fStatus==-3) history=kOptics;
+    else if ( fStatus==-4) history=kWalls;
+    else if ( fStatus==-5) history=kIris;
+    else history=keUndefined;
+
+    fStacking->SetTrackHistory(history);
+    fStatus=0;
+  }
 }
Index: /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptUserStackingAction.cc
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptUserStackingAction.cc	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/OptUserStackingAction.cc	(revision 184)
@@ -37,5 +37,6 @@
     kWalls                    = 5,
     kEarth                    = 6,
-    kG4FocalSurface           = 7
+    kIris                     = 7,
+    kG4FocalSurface           = 8
 };
 
@@ -71,5 +72,5 @@
     if (det.find("Tus")!=string::npos)ftus=true;
     else ftus=false;
-
+		
     SetSender("OptStackingAction");
 }
@@ -79,4 +80,11 @@
     // fFiller is deleted by Geant:
    // delete info;
+   MsgForm(EsafMsg::Info,"fNTracked = %i.",fNTracked );
+	 MsgForm(EsafMsg::Info,"walls = %i.",fNwalls );
+	 MsgForm(EsafMsg::Info,"optics = %i.",fNoptics );
+	 MsgForm(EsafMsg::Info,"focal plane = %i.",fNfocalplane );
+	 MsgForm(EsafMsg::Info,"earth = %i.",fNearth );
+   MsgForm(EsafMsg::Info,"iris = %i.",fNiris );
+	 MsgForm(EsafMsg::Info,"lost = %i.",fNlost );
 }
 
@@ -120,5 +128,4 @@
         fPhotonDef = particleTable->FindParticle("opticalphoton");
     }
-
     EVector& phdir=ph->dir;
     if(ftus)phdir*=-1.;
@@ -127,5 +134,4 @@
                                                     G4ThreeVector(phdir[X],phdir[Y],phdir[Z]),
                                                     energy);
-
     EVector& phpos=ph->pos;
     /// system of ESAF is copied from CLHEP, so no change is needed
@@ -146,5 +152,5 @@
 
     if(refl)return ph_tr;
-    if ( fEv ) {
+    if (fEv) {
         EDetectorPhotonAdder a(ph,0,kTRUE);
         fEv->Fill(a);
@@ -177,5 +183,6 @@
         double theConvConst=hbarc*twopi/eV;
         ph->wl=theConvConst/energy*nm;
-        ParentPhoton *p = new ParentPhoton(fNG4Tracked,x, y, dir.theta(),           dir.phi(),theConvConst/energy,time,(ParentPhotonType)2);
+        ParentPhoton *p = new ParentPhoton(fNG4Tracked,x, y, dir.theta(), 
+                                           dir.phi(),theConvConst/energy,time,(ParentPhotonType)2);
         ph->parent=p;
         track->SetUserInformation(new G4TrackInformation(ph,0,1));
@@ -247,14 +254,14 @@
 //______________________________________________________________________________
 void OptUserStackingAction::SetPupil(PhotonsOnPupil* p){
-
+    printf("**********Set event\n");
+    Reset();
+    fEv = EEvent::GetCurrent();
     if(!p) return;
 
-    Reset();
+    
     fPupil=p;
 
     fNTotal=fPupil->GetNphotons();
-    fEv = EEvent::GetCurrent();
-    fTimeFirstPhoton = fHuge;
-    fTimeLastPhoton = -fHuge;
+    
 }
 
@@ -262,11 +269,20 @@
 void OptUserStackingAction::Reset(){
 
-    fNG4focalplane=0;
-    fNfocalplane=0;
-    fNlost=0;
-    fNTracked=0;
-    fNG4Tracked=0;
-    fProgress=0;
-    forigin=0;
+    fNG4focalplane = 0;
+    fNfocalplane = 0;
+    fNlost = 0;
+		fNearth = 0;
+		fNoptics = 0;
+		fNwalls = 0;
+    fNTracked = 0;
+    fNiris = 0;
+    fNG4Tracked = 0;
+    fProgress = 0;
+    forigin = 0;
+    
+    fNTotal = 0;
+    
+    fEv = 0;
+    
     fTimeFirstPhoton = fHuge;
     fTimeLastPhoton = -fHuge;
@@ -290,32 +306,45 @@
         Photon* ph = (Photon*)this->UpdateCurrentPhoton((G4Track*)fTrackPost);
 
-
-        if ( this->GoToElectronics(ph) ){
-
-            return;
+        if ( this->GoToElectronics(ph) ){          
+          return;
         }
-
+        
         switch ( ph->history ) {
-            case kFocalPlane:
-                fNfocalplane++;
-                break;
-            case kG4FocalSurface :
-                fNG4focalplane++;
-                break;
-            case kOptics:
-                fNoptics++;
-                break;
-            default:
-                fNlost++;
+          case kFocalPlane:
+            fNfocalplane++;
+            break;
+          case kG4FocalSurface :
+            fNG4focalplane++;
+            break;
+          case kOptics:
+            fNoptics++;
+            break;
+          case kWalls:
+            fNwalls++;
+            break;
+          case kEarth:
+            fNearth++;
+            break;
+          case kIris:
+            fNiris++;
+            break;
+          default:
+            fNlost++;
+            printf("%i history *** x,y,z (%g %g %g)\n",ph->history, ph->pos[X],ph->pos[Y],ph->pos[Z]); 
         }
-
+        
         if( fEv  ) {
-            EDetectorPhotonAdder a(ph,0,kFALSE);
-            fEv->Fill(a);
-        }
-    }
+//           bool is_new = kFALSE;
+//           if(!fNTotal)is_new = kTRUE;
+//           EDetectorPhotonAdder a(ph,0,is_new);
+//           fEv->Fill(a);
+        } 
+        
+    }
+    
+    
     if (fNTotal){
-        fNTracked++;
-        this->Progress(100.*fNTracked/fNTotal,"Photons");
+      fNTracked++;
+      this->Progress(100.*fNTracked/fNTotal,"Photons");
     }
 }
@@ -342,5 +371,5 @@
     }
     EVector intPoint;
-    ph->history=kFocalPlane;
+//     ph->history=kFocalPlane;
 
     if(ftus){
@@ -350,5 +379,6 @@
     else fIdealFocalSurface->HitPosition(ph);
 
-
+    if(ph->hitIfs)ph->history=kFocalPlane;
+      
     double DZ= fFocalPlane->Bottom()-ph->pos[Z];
     // calculate impact point on the focal plane
@@ -356,7 +386,10 @@
     ph->time+=(ph->pos - intPoint).Mag()/Clight();
     ph->pos=intPoint;
-    Photon* newp=fFocalPlane->Transport(ph);
+//     printf("1new!\n");
+    
+    Photon* newp = fFocalPlane->Transport(ph);
+//     printf("0new!\n");
     if ( !newp ) return false;
-
+//     printf("new!\n");
     stackManager->PushOneTrack( this->NewPhoton(newp,newp->id,1) );
     return true;
@@ -370,5 +403,5 @@
     if (  (curn+1)>=n ) {
         if ( fEv ) {
-                TArrayI photonHistory(8);
+                TArrayI photonHistory(9);
                 photonHistory.AddAt(fNlost, 0);
                 photonHistory.AddAt(fNG4focalplane, kG4FocalSurface);
Index: /esaf_lal/branches/camille/packages/simulation/detector/GNUmakefile
===================================================================
--- /esaf_lal/branches/camille/packages/simulation/detector/GNUmakefile	(revision 183)
+++ /esaf_lal/branches/camille/packages/simulation/detector/GNUmakefile	(revision 184)
@@ -1,4 +1,4 @@
 # Dummy MakeFile
-# $Id: GNUmakefile 2856 2010-12-23 19:37:08Z biktem $
+# $Id: GNUmakefile 3032 2013-07-03 11:52:38Z biktem $
 # D. De Marco created Jan, 23 2002
 #
@@ -9,8 +9,7 @@
 
 include $(ESAFINSTALL)/packages/config.gmk
-#include $(G4INSTALL)/config/binmake.gmk
 SUBDIRS = electronics optics tools
 
-ifdef G4INSTALL
+ifdef USE_G4
 SUBDIRS += G4Detector
 endif
