Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSAnalysis.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSAnalysis.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSAnalysis.hh	(revision 11)
@@ -0,0 +1,32 @@
+#ifndef MEMPHYS_Analysis_h
+#define MEMPHYS_Analysis_h
+
+// Inheritance :
+#include <MEMPHYS/MEMPHYSIAnalysis.hh>
+
+namespace AIDA {
+ class IAnalysisFactory;
+ class ITree;
+}
+
+#define CAST(aObject,aClass) (aClass*)(aObject)->cast(#aClass)
+
+
+class MEMPHYSAnalysis  : public virtual MEMPHYSIAnalysis {
+  public: //MEMPHYSIAnalysis
+    virtual void closeTree();         
+  public:        
+    MEMPHYSAnalysis(AIDA::IAnalysisFactory&,bool aBatch = true);
+    virtual ~MEMPHYSAnalysis();
+
+    //Get tree pointer
+    AIDA::ITree* tree() const {return fTree;}
+
+  private:
+    AIDA::IAnalysisFactory& fAIDA;
+    bool fBatch;
+    AIDA::ITree* fTree;
+};
+
+
+#endif
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSCast.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSCast.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSCast.hh	(revision 11)
@@ -0,0 +1,7 @@
+#ifndef MEMPHYS_Cast_h
+#define MEMPHYS_Cast_h
+
+#define CAST(aObject,aClass) (aClass*)(aObject)->cast(#aClass)
+
+
+#endif
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSDetectorConstruction.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSDetectorConstruction.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSDetectorConstruction.hh	(revision 11)
@@ -0,0 +1,246 @@
+#ifndef MEMPHYSDetectorConstruction_H
+#define MEMPHYSDetectorConstruction_H 1
+
+//Geant4
+#include "G4Transform3D.hh"
+#include "G4VUserDetectorConstruction.hh"
+#include "G4LogicalVolume.hh"
+#include "G4VPhysicalVolume.hh"
+#include "G4OpticalSurface.hh"
+#include "globals.hh"
+
+//std
+#include <fstream>
+#include <map>
+#include <hash_map.h>
+
+enum cyl_location {endcap1,wall,endcap2}; //JEC FIXME Not in Global
+
+class G4Box;
+class G4Tubs;
+class G4Material;
+class G4LogicalVolume;
+class G4AssemblyVolume;
+class G4VPhysicalVolume;
+
+class MEMPHYSAnalysis; 
+class MEMPHYSDetectorMessenger;
+class MEMPHYSWCSD;
+
+//JEC FIXME does it runs on over plateform?
+namespace __gnu_cxx {
+  template<> struct hash< std::string >
+  {
+    size_t operator()( const std::string& x ) const {
+      return hash< const char* >()( x.c_str() );
+    }
+  };
+}
+
+//JEC 18/11/05 introduce AIDA
+namespace AIDA {
+  class ITuple;
+}
+class MEMPHYSAnalysis; 
+
+class MEMPHYSDetectorConstruction : public G4VUserDetectorConstruction {
+ public:
+
+  MEMPHYSDetectorConstruction(MEMPHYSAnalysis&);
+  virtual ~MEMPHYSDetectorConstruction();
+  
+  G4VPhysicalVolume* Construct();
+
+  // Related to the WC geometry
+  void Set20inchPMTGeometry(); //JEC is obsolete according to M.F but code is still valid(?)
+  void Set8inchPMTGeometry();
+  void SetRockGeometry();
+  void UpdateGeometry();
+
+  G4double GetWaterTubeLength()   {return WCLength;}
+  G4double GetWaterTubePosition() {return WCPosition;}
+  G4double GetPMTSize()           {return WCPMTRadius;}
+  G4double GetRockThickness()     {return RockThickness;}
+  //JEC FIXME not used G4int    GetMyConfiguration()   {return myConfiguration;}
+
+  // Related to the WC tube IDs
+  static G4int GetTubeID(std::string tubeTag){return tubeLocationMap[tubeTag];}
+  static G4Transform3D GetTubeTransform(int tubeNo){return tubeIDMap[tubeNo];}
+
+private:
+
+  // The Construction routines
+  G4LogicalVolume*   ConstructWC();
+  void               ConstructRock(G4LogicalVolume* logicExpHall, G4bool RockIsVisible);
+  void               ConstructMaterials();
+
+  // Code for traversing the geometry and assigning tubeIDs.
+  // First make a typedef for the pointer to the member fcn.  The
+  // syntax is too wacked out to be using all over.
+
+  typedef void (MEMPHYSDetectorConstruction::*DescriptionFcnPtr) (G4VPhysicalVolume*, 
+								  int, int, const G4Transform3D&);
+
+  // Now Funcs for traversing the geometry
+  void TraverseReplicas(G4VPhysicalVolume*, int, const G4Transform3D&, DescriptionFcnPtr);
+
+  void DescribeAndDescendGeometry(G4VPhysicalVolume*, int, int, const G4Transform3D&, DescriptionFcnPtr);
+
+  // Functions that the traversal routines call or we use to manipulate the
+  // data we accumulate.
+  void DumpGeometryTableToFile(); //JEC FIXME deprecated use FillGeometryTuple
+  void FillGeometryTuple();
+
+  void PrintGeometryTree(G4VPhysicalVolume*, int, int, const G4Transform3D&);
+  void DescribeAndRegisterPMT(G4VPhysicalVolume*, int, int, const G4Transform3D&);
+  void GetWCGeom(G4VPhysicalVolume*, int, int, const G4Transform3D&);
+
+
+  //JEC FIXME is it necessary to maintain fAnalysis?
+  MEMPHYSAnalysis&  fAnalysis;            //the Analysis JEC 18/11/05
+  AIDA::ITuple*     geomTuple;            //the Geometry tuple
+
+  // Sensitive Detectors. We declare the pointers here because we need
+  // to check their state if we change the geometry.
+  MEMPHYSWCSD*  aWCPMT;
+
+  //Water, Blacksheet surface
+  G4OpticalSurface * OpWaterBSSurface;
+
+  //Glass, Cathode surface in PMTs
+  G4OpticalSurface * OpGlassCathodeSurface;
+
+
+  // The messenger we use to change the geometry.
+  MEMPHYSDetectorMessenger* messenger;
+
+
+  //---Volume lengths
+
+  // These are shared between the different member functions 
+  // constructWC
+
+  G4int RockChoice;
+
+  G4double WCLength;
+  G4double RockLength;
+
+  G4double WCPosition;
+  G4double RockPosition;
+
+  // WC geometry parameters
+
+  G4double WCPMTRadius;
+  G4double WCDiameter;
+  G4double WCRadius;
+  G4double WCBarrelPMTBlackSheetDist;
+  G4double WCCapPMTBlackSheetDist;
+  G4double WCCapLength;
+  G4double WCBackODLength;
+  G4double WCFrontODLength;
+  G4double WCBarrelLength;
+  G4double WCBarrelRingRadius;
+  G4double WCBarrelPMTRadius;
+  G4int    WCBarrelRingNPhi;
+  G4double WCBarrelRingdPhi;
+  G4int    WCBarrelNRings;
+  G4double WCBarrelCellLength;
+  G4int    WCCapNCell;
+  G4double WCCapCellSize;
+  G4double WCCapSquareSide;
+  G4double WCCapSquareDiag;
+  G4double WCCapEdgeWidth;
+  G4double WCCapEdgeLimit;
+  G4double WCPMTGlassThickness;
+  G4double WCBlackSheetThickness;
+
+  // Variables related to the geometry
+
+  //  std::ofstream geoFile;   // File for text output
+  G4int totalNumPMTs;      // The number of PMTs for this configuration     
+  G4double WCCylInfo[2];    // Info for the geometry tree: radius & length
+  G4double WCPMTSize;       // Info for the geometry tree: pmt size
+  G4ThreeVector WCOffset;   // Info for the geometry tree: WC center offset
+
+  // Tube map information
+  static std::map<int, G4Transform3D> tubeIDMap;
+  static std::map<int, cyl_location> tubeCylLocation;
+  //JEC FIXME: why it works wo using std::hash_map and std::hash?
+  static hash_map<std::string, int, hash<std::string> >  tubeLocationMap;
+
+  // Variable related to the rock
+  G4double RockThickness;
+  G4double RockUpstreamLength_z;
+  G4double RockDownstreamLength_z;
+ 
+  G4double RockMotherVolLength_x;
+  G4double RockMotherVolLength_y;
+  G4double RockMotherVolLength_z;
+
+  G4double RockUpstreamHallRadius;
+
+  G4double RockCentralHallLength_x;
+  G4double RockCentralHallLength_y;
+  G4double RockCentralHallLength_z;
+
+  G4double RockUpHallouterRadiusTube;
+  G4double RockUpHallinnerRadiusTube;
+  G4double RockUpHallhightTube;
+  G4double RockUpHallstartAngleTube;
+  G4double RockUpHallspanningAngleTube;
+ 
+  G4double RockDownHallLength_x;
+  G4double RockDownHallLength_y;
+  G4double RockDownHallLength_z;
+
+  G4double RockUpHallTubePosition_y;
+  G4double RockUpHallTubePosition_z;
+
+  G4double RockTmpBox1Length_x;
+  G4double RockTmpBox1Length_y;
+  G4double RockTmpBox1Length_z;
+
+  G4double RockCeilingLength_x;
+  G4double RockCeilingLength_y;
+  G4double RockCeilingLength_z;
+
+
+  G4ThreeVector RockMotherPosition;
+  G4ThreeVector RockCentralHallPosition;
+  G4ThreeVector RockDownHallPosition;
+  G4ThreeVector RockCenterHallrelativeMomPosition;
+  G4ThreeVector RockCeilingPosition;
+
+  G4double RockCentralHallPosition_y;
+  G4double RockCentralHallPosition_z;
+  G4double RockMotherPosition_y;
+  G4double RockMotherPosition_z;
+  G4double RockDownHallPosition_y;
+  G4double RockDownHallPosition_z;
+
+  G4ThreeVector RockUpHallTubePosition;
+  G4ThreeVector RockTmpBox1relativeUpHallTubePosition;
+  G4ThreeVector RockUpHallTuberelativeCentralHallPosition;
+  G4ThreeVector RockDownHallrelativeCentralHallPosition;
+  G4ThreeVector RockDownrelativeMomPosition;
+  G4ThreeVector RockUpHallrelativeCeilingPosition;
+
+  G4double RockUpHallShift;
+
+
+  G4double GapRockUpstreamlAr;                 //JEC FIXME 
+  G4double GapRockDownstreamMRDScint;          //JEC FIXME
+  G4double lArDLength;                         //JEC FIXME
+
+  // Variables related to configuration
+
+  //JEC FIXME not used G4int myConfiguration;   // Detector Config Parameter
+ 
+  // Rock related variable
+  G4double RockUpstreamPosition; // RockUpstream z-position from WC center
+  G4double RockDownstreamPosition; // RockDownstream z-position from WC center
+  
+};
+
+#endif
+
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSDetectorMessenger.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSDetectorMessenger.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSDetectorMessenger.hh	(revision 11)
@@ -0,0 +1,34 @@
+#ifndef MEMPHYSDetectorMessenger_h
+#define MEMPHYSDetectorMessenger_h 1
+
+class MEMPHYSDetectorConstruction;
+class G4UIdirectory;
+class G4UIcmdWithAString;
+
+#include "G4UImessenger.hh"
+#include "globals.hh"
+#include "G4ios.hh"
+#include "G4UImessenger.hh"
+#include "G4UIdirectory.hh"
+#include "G4UIcmdWithADouble.hh"
+
+class MEMPHYSDetectorMessenger: public G4UImessenger {
+ public:
+  MEMPHYSDetectorMessenger(MEMPHYSDetectorConstruction* mpga);
+  virtual ~MEMPHYSDetectorMessenger();
+  
+ public:
+  void         SetNewValue(G4UIcommand* command, G4String newValues);
+ 
+ private:
+  MEMPHYSDetectorConstruction* MEMPHYSDetector;
+
+ private: //commands
+  
+  G4UIdirectory*      MEMPHYSDir;
+  G4UIcmdWithAString* PMTConfig;
+};
+
+#endif
+
+
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSEventAction.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSEventAction.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSEventAction.hh	(revision 11)
@@ -0,0 +1,61 @@
+#ifndef MEMPHYSEventAction_h
+#define MEMPHYSEventAction_h 1
+
+//Geant4
+#include "G4UserEventAction.hh"
+#include "G4ThreeVector.hh"
+#include "G4Types.hh"
+#include "G4ios.hh"
+
+//MEMPHYS
+#include "MEMPHYS/MEMPHYSDetectorConstruction.hh"
+#include "MEMPHYS/MEMPHYSWCHit.hh"
+#include "MEMPHYS/MEMPHYSWCDigi.hh"
+
+
+class G4Event;
+
+//JEC 10/11/05 introduce AIDA
+namespace AIDA {
+  class ITuple;
+}
+
+
+class MEMPHYSAnalysis; 
+class MEMPHYSRunAction;
+class MEMPHYSPrimaryGeneratorAction;
+
+class MEMPHYSEventAction : public G4UserEventAction {
+  
+ public:
+  MEMPHYSEventAction(MEMPHYSAnalysis&,
+		     MEMPHYSRunAction*, 
+		     MEMPHYSDetectorConstruction*,
+		     MEMPHYSPrimaryGeneratorAction*);
+  virtual ~MEMPHYSEventAction();
+  
+ public:
+  void BeginOfEventAction(const G4Event*);
+  void EndOfEventAction(const G4Event*);
+  
+  MEMPHYSRunAction* GetRunAction(){return runAction;}
+  
+ private:
+  G4int MEMPHYSEventFindStartingVolume(G4ThreeVector vtx);
+  G4int MEMPHYSEventFindStoppingVolume(G4String stopVolumeName);
+  
+ private:
+  //JEC FIXME is it necessary to maintain fAnalysis?
+  MEMPHYSAnalysis&               fAnalysis;            //the Analysis
+  MEMPHYSRunAction*              runAction;            //the Run
+  MEMPHYSPrimaryGeneratorAction* generatorAction;      //the Generator 
+  MEMPHYSDetectorConstruction*   detectorConstructor;  //the Detector
+
+  AIDA::ITuple*                  eventTuple;           //the Event tuple
+
+};
+
+
+#endif
+
+    
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSIAnalysis.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSIAnalysis.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSIAnalysis.hh	(revision 11)
@@ -0,0 +1,13 @@
+#ifndef MEMPHYS_IAnalysis_h
+#define MEMPHYS_IAnalysis_h
+
+
+class MEMPHYSIAnalysis  {
+public:        
+  virtual ~MEMPHYSIAnalysis() {}
+public:        
+  virtual void closeTree() = 0;
+};
+
+
+#endif
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSPhysicsList.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSPhysicsList.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSPhysicsList.hh	(revision 11)
@@ -0,0 +1,60 @@
+#ifndef MEMPHYSPhysicsList_h
+#define MEMPHYSPhysicsList_h 1
+
+//Geant4
+#include "G4VUserPhysicsList.hh"
+#include "globals.hh"
+
+//MEMPHYS
+#include "MEMPHYS/MEMPHYSPhysicsMessenger.hh"
+
+class MEMPHYSPhysicsList: public G4VUserPhysicsList {
+  public:
+    MEMPHYSPhysicsList();
+    virtual ~MEMPHYSPhysicsList();
+
+  //=================================
+  // Added by JLR 2005-07-05
+  //=================================
+  // This method sets the model for 
+  // hadronic secondary interactions
+  void SetSecondaryHad(G4String hadval);
+
+  private:
+    MEMPHYSPhysicsMessenger* PhysicsMessenger;
+
+    G4String SecondaryHadModel;
+
+    G4bool gheishahad;
+    G4bool bertinihad;
+    G4bool binaryhad;
+
+  protected:
+    // Construct particle and physics process
+    void ConstructParticle();
+    void ConstructProcess();
+    void SetCuts();
+
+  protected:
+    // these methods Construct particles 
+    void ConstructBosons();
+    void ConstructLeptons();
+    void ConstructMesons();
+    void ConstructBaryons();
+
+  protected:
+    // these methods Construct physics processes and register them
+    void ConstructGeneral();
+    void ConstructEM();
+    void ConstructOp();
+    void ConstructHad();
+};
+
+#endif
+
+
+
+
+
+
+
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSPhysicsMessenger.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSPhysicsMessenger.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSPhysicsMessenger.hh	(revision 11)
@@ -0,0 +1,28 @@
+#ifndef MEMPHYSPhysicsMessenger_h
+#define MEMPHYSPhysicsMessenger_h 1
+
+#include "globals.hh"
+#include "G4UImessenger.hh"
+
+class MEMPHYSPhysicsList;
+class G4UIdirectory;
+class G4UIcommand;
+class G4UIcmdWithAString;
+
+class MEMPHYSPhysicsMessenger: public G4UImessenger
+{
+public:
+  MEMPHYSPhysicsMessenger(MEMPHYSPhysicsList*);
+  virtual ~MEMPHYSPhysicsMessenger();
+
+  void SetNewValue(G4UIcommand* command, G4String newValue);
+
+private:
+  MEMPHYSPhysicsList* MEMPHYSPhysics;
+
+  G4UIdirectory*      MEMPHYSDir;
+  G4UIcmdWithAString* hadmodelCmd;
+
+};
+
+#endif
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSPrimaryGeneratorAction.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSPrimaryGeneratorAction.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSPrimaryGeneratorAction.hh	(revision 11)
@@ -0,0 +1,101 @@
+#ifndef MEMPHYSPrimaryGeneratorAction_h
+#define MEMPHYSPrimaryGeneratorAction_h
+
+#include "G4VUserPrimaryGeneratorAction.hh"
+#include "G4ThreeVector.hh"
+#include "globals.hh"
+
+#include <fstream>
+
+class G4ParticleGun;
+class G4Event;
+
+class MEMPHYSDetectorConstruction;
+class MEMPHYSPrimaryGeneratorMessenger;
+
+class MEMPHYSPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction {
+ public:
+  MEMPHYSPrimaryGeneratorAction(MEMPHYSDetectorConstruction*);
+  virtual ~MEMPHYSPrimaryGeneratorAction();
+  
+public:
+  void GeneratePrimaries(G4Event* anEvent);
+
+  // Normal gun setting calls these functions to fill jhfNtuple and Root tree
+  void SetVtx(G4ThreeVector i)     { vtx = i; };
+  void SetBeamEnergy(G4double i)   { beamenergy = i; };
+  void SetBeamDir(G4ThreeVector i) { beamdir = i; };
+  void SetBeamPDG(G4int i)         { beampdg = i; };
+
+  // These go with jhfNtuple
+  G4int GetVecRecNumber(){return vecRecNumber;}
+  G4int GetMode() {return mode;};
+  G4int GetVtxVol() {return vtxvol;};
+  G4ThreeVector GetVtx() {return vtx;}
+  G4int GetNpar() {return npar;};
+  G4int GetBeamPDG() {return beampdg;};
+  G4double GetBeamEnergy() {return beamenergy;};
+  G4ThreeVector GetBeamDir() {return beamdir;};
+  G4int GetTargetPDG() {return targetpdg;};
+  G4double GetTargetEnergy() {return targetenergy;};
+  G4ThreeVector GetTargetDir() {return targetdir;};
+
+  // older ...
+  G4double GetNuEnergy() {return nuEnergy;};
+  G4double GetEnergy() {return energy;};
+  G4double GetXPos() {return xPos;};
+  G4double GetYPos() {return yPos;};
+  G4double GetZPos() {return zPos;};
+  G4double GetXDir() {return xDir;};
+  G4double GetYDir() {return yDir;};
+  G4double GetZDir() {return zDir;};
+
+private:
+  MEMPHYSDetectorConstruction*      myDetector;
+  G4ParticleGun*                   particleGun;
+  MEMPHYSPrimaryGeneratorMessenger* messenger;
+
+  // Variables set by the messenger
+  G4bool   useMulineEvt;
+  G4bool   useNormalEvt;
+  std::fstream inputFile;
+  G4String vectorFileName;
+  G4bool   GenerateVertexInRock;
+
+  // These go with jhfNtuple
+  G4int mode;
+  G4int vtxvol;
+  G4ThreeVector vtx;
+  G4int npar;
+  G4int beampdg, targetpdg;
+  G4ThreeVector beamdir, targetdir;
+  G4double beamenergy, targetenergy;
+  G4int vecRecNumber;
+
+  G4double nuEnergy;
+  G4double energy;
+  G4double xPos, yPos, zPos;
+  G4double xDir, yDir, zDir;
+
+  G4int    _counterRock; 
+  G4int    _counterCublic; 
+public:
+
+   void SetMulineEvtGenerator(G4bool choice) { useMulineEvt = choice; }
+   G4bool IsUsingMulineEvtGenerator() { return useMulineEvt; }
+
+   void SetNormalEvtGenerator(G4bool choice) { useNormalEvt = choice; }
+   G4bool IsUsingNormalEvtGenerator()  { return useNormalEvt; }
+
+  void OpenVectorFile(G4String fileName) {
+    if ( inputFile.is_open() ) inputFile.close();
+    vectorFileName = fileName;
+    inputFile.open(vectorFileName, std::fstream::in);
+  }
+  G4bool IsGeneratingVertexInRock() { return GenerateVertexInRock; }
+  void SetGenerateVertexInRock(G4bool choice) { GenerateVertexInRock = choice; }
+};
+
+#endif
+
+
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSPrimaryGeneratorMessenger.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSPrimaryGeneratorMessenger.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSPrimaryGeneratorMessenger.hh	(revision 11)
@@ -0,0 +1,33 @@
+#ifndef MEMPHYSPrimaryGeneratorMessenger_h
+#define MEMPHYSPrimaryGeneratorMessenger_h 1
+
+class G4UIdirectory;
+class G4UIcmdWithAString;
+class MEMPHYSPrimaryGeneratorAction;
+
+
+#include "G4UImessenger.hh"
+#include "globals.hh"
+
+class MEMPHYSPrimaryGeneratorMessenger: public G4UImessenger {
+ public:
+  MEMPHYSPrimaryGeneratorMessenger(MEMPHYSPrimaryGeneratorAction* mpga);
+  virtual ~MEMPHYSPrimaryGeneratorMessenger();
+  
+ public:
+  void     SetNewValue(G4UIcommand* command, G4String newValues);
+  G4String GetCurrentValue(G4UIcommand* command);
+  
+ private:
+  MEMPHYSPrimaryGeneratorAction* myAction;
+  
+ private: //commands
+  G4UIdirectory*      mydetDirectory;
+  G4UIcmdWithAString* genCmd;
+  G4UIcmdWithAString* fileNameCmd;
+  
+};
+
+#endif
+
+
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSRunAction.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSRunAction.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSRunAction.hh	(revision 11)
@@ -0,0 +1,37 @@
+#ifndef MEMPHYSRunAction_h
+#define MEMPHYSRunAction_h 1
+
+//Geant4
+#include "G4UserRunAction.hh"
+#include "globals.hh"
+#include "G4String.hh"
+
+class G4Run;
+class MEMPHYSRunActionMessenger;
+
+class MEMPHYSRunAction : public G4UserRunAction {
+public:
+  MEMPHYSRunAction();
+  virtual ~MEMPHYSRunAction();
+
+public:
+  void BeginOfRunAction(const G4Run*);
+  void EndOfRunAction(const G4Run*);
+
+  int  GetNumberOfEventsGenerated() { return numberOfEventsGenerated;}
+  void incrementEventsGenerated() { numberOfEventsGenerated++;}
+  void incrementWaterTubeHits()   { numberOfTimesWaterTubeHit++;}  
+  void incrementCatcherHits()     { numberOfTimesCatcherHit++;}
+  void incrementRockHits()        { numberOfTimesRockHit++;}
+
+private:
+
+  int numberOfEventsGenerated;
+  int numberOfTimesWaterTubeHit;
+  int numberOfTimesCatcherHit;
+  int numberOfTimesRockHit;
+
+  MEMPHYSRunActionMessenger* messenger;
+};
+
+#endif
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSRunActionMessenger.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSRunActionMessenger.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSRunActionMessenger.hh	(revision 11)
@@ -0,0 +1,28 @@
+#ifndef MEMPHYSRunActionMessenger_h
+#define MEMPHYSRunActionMessenger_h 1
+
+class MEMPHYSRunAction;
+class G4UIdirectory;
+class G4UIcmdWithAString;
+
+#include "G4UImessenger.hh"
+#include "globals.hh"
+
+class MEMPHYSRunActionMessenger: public G4UImessenger {
+ public:
+  MEMPHYSRunActionMessenger(MEMPHYSRunAction* mpga);
+  virtual ~MEMPHYSRunActionMessenger();
+  
+ public:
+  void     SetNewValue(G4UIcommand* command, G4String newValues);
+  
+ private:
+  MEMPHYSRunAction* MEMPHYSRun;
+  
+ private: //commands
+  G4UIdirectory*      MEMPHYSIODir;
+};
+
+#endif
+
+
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSStackingAction.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSStackingAction.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSStackingAction.hh	(revision 11)
@@ -0,0 +1,22 @@
+#ifndef MEMPHYSStackingAction_H
+#define MEMPHYSStackingAction_H 1
+
+#include "globals.hh"
+#include "G4UserStackingAction.hh"
+
+class G4Track;
+
+class MEMPHYSStackingAction : public G4UserStackingAction {
+
+  public:
+    MEMPHYSStackingAction();
+    virtual ~MEMPHYSStackingAction();
+
+  public:
+    virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track* aTrack);
+    virtual void NewStage();
+    virtual void PrepareNewEvent();
+};
+
+#endif
+
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSTrackInformation.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSTrackInformation.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSTrackInformation.hh	(revision 11)
@@ -0,0 +1,47 @@
+#ifndef MEMPHYSTrackInformation_h
+#define MEMPHYSTrackInformation_h 1
+
+
+#include "globals.hh"
+#include "G4Track.hh"
+#include "G4Allocator.hh"
+#include "G4VUserTrackInformation.hh"
+
+// Maximilien Fechner, december 2004
+// Information class for flagging the secondaries
+// I'm interested in (namely gammas from pi0s and secondaries
+// from muon decay
+class MEMPHYSTrackInformation : public G4VUserTrackInformation {
+private:
+  G4bool saveit; 
+
+public:
+  MEMPHYSTrackInformation() : saveit(true) {}
+  MEMPHYSTrackInformation(const MEMPHYSTrackInformation* aninfo) 
+  { saveit = aninfo->saveit;}
+  virtual ~MEMPHYSTrackInformation() {}
+  MEMPHYSTrackInformation(const G4Track* );
+  
+  inline void *operator new(size_t);
+  inline void operator delete(void *aTrackInfo);
+  inline int operator ==(const MEMPHYSTrackInformation& right) const
+  {return (this==&right);}
+
+  void Print() const;
+
+};
+
+extern G4Allocator<MEMPHYSTrackInformation> aMEMPHYSTrackInfoAllocator;
+
+inline void* MEMPHYSTrackInformation::operator new(size_t) { 
+  void* aTrackInfo;
+  aTrackInfo = (void*)aMEMPHYSTrackInfoAllocator.MallocSingle();
+  return aTrackInfo;
+}
+
+inline void MEMPHYSTrackInformation::operator delete(void *aTrackInfo){ 
+  aMEMPHYSTrackInfoAllocator.FreeSingle((MEMPHYSTrackInformation*)aTrackInfo);
+}
+
+
+#endif
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSTrackingAction.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSTrackingAction.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSTrackingAction.hh	(revision 11)
@@ -0,0 +1,33 @@
+#ifndef MEMPHYSTrackingAction_h
+#define MEMPHYSTrackingAction_h
+
+//Geant4
+#include "G4UserTrackingAction.hh"
+#include "globals.hh"
+
+#include <set>
+
+
+class G4Track;
+
+class MEMPHYSTrackingAction : public G4UserTrackingAction {
+ public:
+   MEMPHYSTrackingAction();
+  virtual ~MEMPHYSTrackingAction();
+
+  void PreUserTrackingAction (const G4Track* aTrack);
+  void PostUserTrackingAction(const G4Track* aTrack);
+
+private:
+  std::set<G4String> ProcessList;
+  std::set<G4int> ParticleList;
+  
+  //JEC 15/11/05 add these parameters (may be later on a messenger)
+  G4float percentageOfCherenkovPhotonsToDraw;
+  G4float thresholdTobeSaved;
+};
+
+
+#endif
+
+
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSTrajectory.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSTrajectory.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSTrajectory.hh	(revision 11)
@@ -0,0 +1,126 @@
+//JEC FIXME: what a forward declaration like that!!!   class MEMPHYSTrajectory;
+#ifndef MEMPHYSTrajectory_h
+#define MEMPHYSTrajectory_h 1
+
+//Geant4 
+#include "G4VTrajectory.hh"
+#include "G4Allocator.hh"
+#include "G4ios.hh"
+#include "globals.hh"
+#include "G4ParticleDefinition.hh"
+#include "G4TrajectoryPoint.hh"
+#include "G4Track.hh"
+#include "G4Step.hh"
+
+//std
+#include <stdlib.h>
+#include <vector>
+
+
+class G4Polyline;
+
+typedef std::vector<G4VTrajectoryPoint*>  TrajectoryPointContainer;
+
+class MEMPHYSTrajectory : public G4VTrajectory {
+
+ public:
+
+  
+  // Constructor/Destrcutor
+   MEMPHYSTrajectory();
+   MEMPHYSTrajectory(const G4Track* aTrack);
+   MEMPHYSTrajectory(MEMPHYSTrajectory &);
+
+   virtual ~MEMPHYSTrajectory();
+
+  // Operators
+  inline void* operator new(size_t);
+  inline void  operator delete(void*);
+  inline int operator == (const MEMPHYSTrajectory& right) const
+  {return (this==&right);} 
+
+  //inherited methods 
+  virtual G4int GetTrackID() const { return fTrackID; }
+  virtual G4int GetParentID() const { return fParentID; }
+  virtual G4String GetParticleName() const { return ParticleName; }
+  virtual G4double GetCharge() const { return PDGCharge; }
+  virtual G4int GetPDGEncoding() const { return PDGEncoding; }
+  virtual G4ThreeVector GetInitialMomentum() const { return initialMomentum; }
+  virtual int GetPointEntries() const { return positionRecord->size(); }
+  virtual G4VTrajectoryPoint* GetPoint(G4int i) const 
+  { return (*positionRecord)[i]; }
+  //JEC FIXME what to do with these Show/Draw routines...
+  virtual void ShowTrajectory(std::ostream& os=G4cout) const;
+  virtual void DrawTrajectory(G4int i_mode=0) const;
+  virtual const std::map<G4String,G4AttDef>* GetAttDefs() const;
+  virtual std::vector<G4AttValue>* CreateAttValues() const;
+
+
+  //Other Get/Set
+  G4ParticleDefinition* GetParticleDefinition();
+
+  inline G4String GetCreatorProcessName() const { return creatorProcess; }
+  inline G4double GetGlobalTime() const { return globalTime; }
+
+  inline G4bool GetSaveFlag() const { return SaveIt; }
+  inline void SetSaveFlag(G4bool value) { SaveIt = value; }
+
+  inline G4ThreeVector GetStoppingPoint() const { return stoppingPoint; }
+  inline void SetStoppingPoint(G4ThreeVector& currentPosition) 
+  { stoppingPoint = currentPosition;}
+
+  inline G4VPhysicalVolume* GetStoppingVolume() const { return stoppingVolume;}
+  inline void SetStoppingVolume(G4VPhysicalVolume* currentVolume)
+  { stoppingVolume = currentVolume;}
+
+
+  // Other member functions
+  virtual void AppendStep(const G4Step* aStep);
+  virtual void MergeTrajectory(G4VTrajectory* secondTrajectory);
+
+
+
+ private:
+
+  TrajectoryPointContainer* positionRecord;
+  G4int                     fTrackID;
+  G4int                     fParentID;
+  G4int                     PDGEncoding;
+  G4double                  PDGCharge;
+  G4String                  ParticleName;
+  G4ThreeVector             initialMomentum;
+
+  G4ThreeVector             stoppingPoint;
+  G4VPhysicalVolume         *stoppingVolume;
+
+  G4bool                    SaveIt;
+  G4String                  creatorProcess;
+  G4double                  globalTime;
+};
+
+/***            TEMP  : M FECHNER ***********
+** modification by Chris Walter that works for geant4 >= 4.6.2p01
+** does not compile with 4.6.1
+#if defined G4TRACKING_ALLOC_EXPORT
+  extern G4DLLEXPORT G4Allocator<MEMPHYSTrajectory> myTrajectoryAllocator;
+#else
+  extern G4DLLIMPORT G4Allocator<MEMPHYSTrajectory> myTrajectoryAllocator;
+#endif
+*/
+
+extern G4Allocator<MEMPHYSTrajectory> myTrajectoryAllocator;
+
+inline void* MEMPHYSTrajectory::operator new(size_t)
+{
+  void* aTrajectory;
+  aTrajectory = (void*)myTrajectoryAllocator.MallocSingle();
+  return aTrajectory;
+}
+
+inline void MEMPHYSTrajectory::operator delete(void* aTrajectory)
+{
+  myTrajectoryAllocator.FreeSingle((MEMPHYSTrajectory*)aTrajectory);
+}
+
+#endif
+
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSWCDigi.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSWCDigi.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSWCDigi.hh	(revision 11)
@@ -0,0 +1,67 @@
+#ifndef MEMPHYSWCDigi_h
+#define MEMPHYSWCDigi_h 1
+
+#include "G4VDigi.hh"
+#include "G4TDigiCollection.hh"
+#include "G4Allocator.hh"
+#include "G4ThreeVector.hh"
+
+class MEMPHYSWCDigi : public G4VDigi {
+
+public:
+  
+  MEMPHYSWCDigi();
+  virtual ~MEMPHYSWCDigi();
+  MEMPHYSWCDigi(const MEMPHYSWCDigi&);
+  const MEMPHYSWCDigi& operator=(const MEMPHYSWCDigi&);
+  int operator==(const MEMPHYSWCDigi&) const;
+  
+  inline void* operator new(size_t);
+  inline void  operator delete(void*);
+  
+  void Draw(); //JEC FIXME what do we do with this?
+  void Print();
+
+private:
+  
+  G4int   tubeID;
+  G4float pe;   
+  G4float time; 
+  
+public:
+  
+  inline void SetTubeID(G4int tube) {tubeID = tube;};
+  inline void SetPe(G4float Q)      {pe     = Q;};
+  inline void SetTime(G4float T)    {time   = T;};
+  
+  inline G4int   GetTubeID() {return tubeID;};
+  inline G4float GetPe()     {return pe;};
+  inline G4float GetTime()   {return time;};
+  
+};
+
+//-----------------------------------------------------------------------
+
+typedef G4TDigiCollection<MEMPHYSWCDigi> MEMPHYSWCDigitsCollection;
+extern G4Allocator<MEMPHYSWCDigi> MEMPHYSWCDigiAllocator;
+
+inline void* MEMPHYSWCDigi::operator new(size_t) {
+  void* aDigi;
+  aDigi = (void*) MEMPHYSWCDigiAllocator.MallocSingle();
+  return aDigi;
+}
+
+inline void MEMPHYSWCDigi::operator delete(void* aDigi) {
+  MEMPHYSWCDigiAllocator.FreeSingle((MEMPHYSWCDigi*) aDigi);
+}
+
+#endif
+
+
+
+
+
+
+
+
+
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSWCDigitizer.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSWCDigitizer.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSWCDigitizer.hh	(revision 11)
@@ -0,0 +1,75 @@
+#ifndef MEMPHYSWCDigitizer_h
+#define MEMPHYSWCDigitizer_h 1
+
+//Geant4
+#include "G4VDigitizerModule.hh"
+#include "globals.hh"
+#include "Randomize.hh"
+
+//MEMPHYS
+#include "MEMPHYS/MEMPHYSWCDigi.hh"
+
+
+class MEMPHYSWCDigitizer : public G4VDigitizerModule {
+public:
+  
+  MEMPHYSWCDigitizer(G4String name);
+  virtual ~MEMPHYSWCDigitizer();
+  
+  void SetPMTSize(G4float inputSize) {PMTSize = inputSize;}
+  void Digitize();
+  
+private:
+  static void Threshold(double& pe,int& iflag){
+    double x = pe+0.1; iflag=0;
+    double thr; double RDUMMY,err;
+    if ( x<1.1) {
+      thr = std::min(1.0,
+	     -0.06374+x*(
+	        3.748+x*(
+	       -63.23+x*(
+		452.0+x*(
+	      -1449.0+x*(
+	       2513.0+x*(
+	       -2529.+x*(
+               1472.0+x*(
+               -452.2+x*(
+                51.34+x*2.370))))))))));
+    } else {
+      thr = 1.0;
+    }
+    RDUMMY = G4UniformRand();
+    if (thr < RDUMMY) {
+      pe = 0.0;
+      iflag = 1;
+    } else {
+      err = G4RandGauss::shoot(0.0,0.03);
+      pe = pe+err;
+    }
+  }//Threshold
+
+  static const double offset; // hit time offset
+  static const double pmtgate; // ns
+  static const double eventgateup; // ns
+  static const double eventgatedown; // ns
+  static const double LongTime; // ns
+  static const int GlobalThreshold; //number of hit PMTs within an <=200ns sliding window that decides the global trigger t0
+
+  G4int triggerhisto[20000]; // for finding t0
+  G4float RealOffset;  // t0 = offset corrected for trigger start
+  G4float MinTime;  // very first hit time
+
+  MEMPHYSWCDigitsCollection*  DigitsCollection;
+  
+  G4float PMTSize;
+};
+
+#endif
+
+
+
+
+
+
+
+
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSWCHit.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSWCHit.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSWCHit.hh	(revision 11)
@@ -0,0 +1,91 @@
+#ifndef MEMPHYSWCHit_h
+#define MEMPHYSWCHit_h 1
+
+//Geant4
+#include "G4VHit.hh"
+#include "G4THitsCollection.hh"
+#include "G4Allocator.hh"
+#include "G4ThreeVector.hh"
+#include "G4LogicalVolume.hh"
+#include "G4ios.hh"
+
+//std
+#include <algorithm> // for sort, find, count_if
+#include <functional> //for less_equal, bind2nd,...
+
+class MEMPHYSWCHit : public G4VHit {
+ public:
+  
+  MEMPHYSWCHit();
+  virtual ~MEMPHYSWCHit();
+  G4int operator==(const MEMPHYSWCHit&) const;
+  
+  inline void* operator new(size_t);
+  inline void  operator delete(void*);
+  
+  void Draw(); //JEC FIXME what do we do with this?
+  void Print();
+  
+ public:
+  
+  void SetTubeID       (G4int tube)                 { tubeID = tube; };
+  void SetTrackID      (G4int track)                { trackID = track; };
+  void SetEdep         (G4double de)                { edep = de; };
+  void SetPos          (G4ThreeVector xyz)          { pos = xyz; };
+  void SetRot          (G4RotationMatrix rotMatrix) { rot = rotMatrix; };
+  void SetLogicalVolume(G4LogicalVolume* logV)      { pLogV = logV;}
+
+  // This is temporarily used for the drawing scale
+  void SetMaxPe(G4int number = 0)  {maxPe   = number;};
+
+  void AddPe(G4float hitTime);  
+
+  G4int         GetTubeID()     { return tubeID; };
+  G4int         GetTrackID()    { return trackID; };
+  G4ThreeVector GetPos()        { return pos; };
+  G4int         GetTotalPe()    { return totalPe;};
+  G4float       GetTime(int i)  { return time[i];};
+  
+  void SortHitTimes() {   sort(time.begin(),time.end()); }
+  G4int GetPeInGate(double pmtgate,double evgate);
+
+
+ private:
+
+  //JEC 17/11/05 put the Copy Ctor and the Assignation Operator private
+  MEMPHYSWCHit(const MEMPHYSWCHit&);
+  const MEMPHYSWCHit& operator=(const MEMPHYSWCHit&);
+  
+  G4int            tubeID;
+  G4int            trackID;
+  G4double         edep;
+  G4ThreeVector    pos;
+  G4RotationMatrix rot;
+  G4LogicalVolume* pLogV;
+
+  // This is temporarily used for the drawing scale
+  // Since its static *every* WChit sees the same value for this.
+  static G4int     maxPe;
+
+  G4int                 totalPe;
+  std::vector<G4float>  time;
+  G4int                 totalPeInGate;
+};
+
+//----------------------------------------------------------------
+
+typedef G4THitsCollection<MEMPHYSWCHit> MEMPHYSWCHitsCollection;
+
+extern G4Allocator<MEMPHYSWCHit> MEMPHYSWCHitAllocator;
+
+inline void* MEMPHYSWCHit::operator new(size_t) {
+  void *aHit;
+  aHit = (void *) MEMPHYSWCHitAllocator.MallocSingle();
+  return aHit;
+}
+
+inline void MEMPHYSWCHit::operator delete(void *aHit) {
+  MEMPHYSWCHitAllocator.FreeSingle((MEMPHYSWCHit*) aHit);
+}
+
+#endif
Index: /MEMPHYS/v0/MEMPHYS/MEMPHYSWCSD.hh
===================================================================
--- /MEMPHYS/v0/MEMPHYS/MEMPHYSWCSD.hh	(revision 11)
+++ /MEMPHYS/v0/MEMPHYS/MEMPHYSWCSD.hh	(revision 11)
@@ -0,0 +1,31 @@
+#ifndef MEMPHYSWCSD_h
+#define MEMPHYSWCSD_h 1
+
+//Geant4
+#include "G4VSensitiveDetector.hh"
+
+//MEMPHYS
+#include "MEMPHYS/MEMPHYSWCHit.hh"
+
+class G4Step;
+class G4HCofThisEvent;
+
+class MEMPHYSWCSD : public G4VSensitiveDetector {
+ public:
+  MEMPHYSWCSD(G4String);
+  virtual ~MEMPHYSWCSD();
+  
+  void   Initialize(G4HCofThisEvent*);
+  G4bool ProcessHits(G4Step*, G4TouchableHistory*);
+  void   EndOfEvent(G4HCofThisEvent*);
+  
+ private:
+
+  MEMPHYSWCHitsCollection* hitsCollection;
+  std::map<int,int> PMTHitMap;   // Whether a PMT was hit already
+  G4int HCID; //JEC 16/11/05 
+
+};
+
+#endif
+
Index: /MEMPHYS/v0/applications/MEMPHYS_batch.cxx
===================================================================
--- /MEMPHYS/v0/applications/MEMPHYS_batch.cxx	(revision 11)
+++ /MEMPHYS/v0/applications/MEMPHYS_batch.cxx	(revision 11)
@@ -0,0 +1,106 @@
+// Geant4:
+#include "G4ios.hh"
+#include "G4RunManager.hh"
+#include "G4UImanager.hh"
+
+//MEMPHYS:
+#include "MEMPHYS/MEMPHYSAnalysis.hh"
+#include "MEMPHYS/MEMPHYSDetectorConstruction.hh"
+#include "MEMPHYS/MEMPHYSPhysicsList.hh"
+#include "MEMPHYS/MEMPHYSPhysicsMessenger.hh"
+#include "MEMPHYS/MEMPHYSPrimaryGeneratorAction.hh"
+#include "MEMPHYS/MEMPHYSEventAction.hh"
+#include "MEMPHYS/MEMPHYSRunAction.hh"
+#include "MEMPHYS/MEMPHYSStackingAction.hh"
+#include "MEMPHYS/MEMPHYSTrackingAction.hh"
+
+
+//JEC AIDA :
+#include <AIDA/IAnalysisFactory.h>
+
+// std::
+#include <iostream>
+
+//JEC Lib :
+#include <Lib/System.h>
+
+/////////////////////////////////////////////////////////////////
+int main(
+	 int //aArgc 
+	 , char** //aArgv
+	 )
+{
+  //AIDA Analysis factory
+  AIDA::IAnalysisFactory* aida = AIDA_createAnalysisFactory();
+  if(!aida) {
+    std::cout << "MEMPHYS_batch :"
+              << " AIDA not found." << std::endl;
+    return 0;
+  }
+  //Book all the histo, tuple 
+  MEMPHYSAnalysis* analysis = new MEMPHYSAnalysis(*aida);
+
+
+  // Construct the default run manager
+  G4RunManager* runManager = new G4RunManager;
+
+  // UserInitialization classes (mandatory)
+
+
+
+  //JEC 18/11/05 give the "analysis" to fill geometry ITuple
+  MEMPHYSDetectorConstruction* MEMPHYSdetector = 
+    new MEMPHYSDetectorConstruction(*analysis); 
+
+  runManager->SetUserInitialization(MEMPHYSdetector);
+
+  runManager->SetUserInitialization(new MEMPHYSPhysicsList);
+
+  G4UImanager* UI = G4UImanager::GetUIpointer();
+  if (UI) {
+    std::string file = 
+      Lib::System::getenv("MEMPHYSROOT")+"/scripts/Geant4/jobOptions.mac"; //JEC FIXME this comes from JHF
+    UI->ApplyCommand("/control/execute "+file);  
+  }
+
+
+
+  // Set user action classes
+  MEMPHYSPrimaryGeneratorAction* myGeneratorAction = new MEMPHYSPrimaryGeneratorAction(MEMPHYSdetector);
+  runManager->SetUserAction(myGeneratorAction);
+
+  MEMPHYSRunAction* myRunAction = new MEMPHYSRunAction();
+
+  runManager->SetUserAction(myRunAction);
+
+
+  runManager->SetUserAction(new MEMPHYSEventAction(*analysis,
+						   myRunAction, 
+						   MEMPHYSdetector,
+						   myGeneratorAction));
+  runManager->SetUserAction(new MEMPHYSTrackingAction);
+
+  runManager->SetUserAction(new MEMPHYSStackingAction);
+
+
+  // Initialize G4 kernel
+  runManager->Initialize();
+
+  if (UI) {
+    std::string file = 
+      Lib::System::getenv("MEMPHYSROOT")+"/scripts/Geant4/init.g4m"; //JEC FIXME this comes from JHF
+    UI->ApplyCommand("/control/execute "+file);  
+  }
+
+  runManager->BeamOn(1); //what does this means here?
+
+
+  //JEC interactive session  delete visManager;
+
+  delete runManager;
+  delete analysis;
+  delete aida;
+  return 0;
+}
+
+
Index: /MEMPHYS/v0/applications/MEMPHYS_session.cxx
===================================================================
--- /MEMPHYS/v0/applications/MEMPHYS_session.cxx	(revision 11)
+++ /MEMPHYS/v0/applications/MEMPHYS_session.cxx	(revision 11)
@@ -0,0 +1,150 @@
+
+// Geant4:
+#include "G4ios.hh"
+#include "G4RunManager.hh"
+#include "G4UImanager.hh"
+
+//AIDA :
+#include <AIDA/IAnalysisFactory.h>
+
+// std::
+#include <iostream>
+
+// Lib :
+#include <Lib/Interfaces/ISession.h>
+#include <Lib/Manager.h>
+#include <Lib/System.h>
+//#include <Lib/Debug.h>
+
+// G4Lab :
+#include <G4Lab/UIOnX.h>
+#include <G4Lab/TrackingAction.h>
+
+//MEMPHYS:
+#include "MEMPHYS/MEMPHYSAnalysis.hh"
+#include "MEMPHYS/MEMPHYSDetectorConstruction.hh"
+#include "MEMPHYS/MEMPHYSPhysicsList.hh"
+#include "MEMPHYS/MEMPHYSPhysicsMessenger.hh"
+#include "MEMPHYS/MEMPHYSPrimaryGeneratorAction.hh"
+#include "MEMPHYS/MEMPHYSEventAction.hh"
+#include "MEMPHYS/MEMPHYSRunAction.hh"
+#include "MEMPHYS/MEMPHYSStackingAction.hh"
+#include "MEMPHYS/MEMPHYSTrackingAction.hh"
+
+
+
+// Create a manager to access the MEMPHYSAnalysis from the callbacks :
+
+class MEMPHYSAnalysisManager 
+  :public virtual IManager
+  ,public MEMPHYSAnalysis  {
+ public: //IManager
+  virtual const std::string& name() const { return fName;}
+  virtual void* cast(const std::string& aTo) const {
+    if(aTo=="MEMPHYSAnalysisManager") {
+      return (MEMPHYSAnalysisManager*)this;
+    } else if(aTo=="MEMPHYSIAnalysis") {
+      return (MEMPHYSIAnalysis*)this;
+    } else if(aTo=="MEMPHYSAnalysis") {
+      return (MEMPHYSAnalysis*)this;
+    } else if(aTo=="IManager") {
+      return (IManager*)this;
+    } else {
+      return 0;
+    }
+  }
+ public:
+  MEMPHYSAnalysisManager(AIDA::IAnalysisFactory& aAIDA,bool aBatch)
+    :MEMPHYSAnalysis(aAIDA,aBatch),fName("MEMPHYSAnalysisManager") {}
+  virtual ~MEMPHYSAnalysisManager(){}
+ private:
+  std::string fName;
+};
+
+
+//////////////////////////////////////////////////////////////////////////////
+int main(
+	 int aArgc
+	 ,char** aArgv
+	 ) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  //Lib::Debug::checkByClass(true);
+
+  G4RunManager* runManager = new G4RunManager;
+
+  // Need to pass the G4RunManager at UIOnX creation
+  std::string gui = "$MEMPHYSROOT/scripts/OnX/MEMPHYS_session.onx";
+  G4Lab::UIOnX* session = new G4Lab::UIOnX(runManager,gui,aArgc,aArgv);
+
+  MEMPHYSAnalysisManager* analysisManager = 0;
+
+  // Declare actions that needs some UI or analysis facilities :
+  ISession* onxSession = session->session();
+  if(onxSession) {
+    // Get theg AIDA Lab implementation :
+    AIDA::IAnalysisFactory* aida = 
+      Lib_findManager(*onxSession,"AnalysisFactory",AIDA::IAnalysisFactory);
+    if(!aida) {
+      std::cout << "MEMPHYS_session :"
+                << " AnalysisFactory not found." << std::endl;
+    } else {
+      analysisManager = new MEMPHYSAnalysisManager(*aida,false);
+      onxSession->addManager(analysisManager);
+    }
+  }
+
+  G4UImanager* UI = G4UImanager::GetUIpointer();
+  if (UI) {
+    std::string file = 
+      Lib::System::getenv("MEMPHYSROOT")+"/scripts/Geant4/jobOptions.mac";
+    UI->ApplyCommand("/control/execute "+file);  
+  }
+
+  
+  //JEC 18/11/05 give the "analysis" to fill geometry ITuple
+  MEMPHYSDetectorConstruction* MEMPHYSdetector = 
+    new MEMPHYSDetectorConstruction(*analysisManager); 
+
+  runManager->SetUserInitialization(MEMPHYSdetector);
+
+  runManager->SetUserInitialization(new MEMPHYSPhysicsList);
+
+  // Set user action classes
+  MEMPHYSPrimaryGeneratorAction* myGeneratorAction = new MEMPHYSPrimaryGeneratorAction(MEMPHYSdetector);
+  runManager->SetUserAction(myGeneratorAction);
+
+  MEMPHYSRunAction* myRunAction = new MEMPHYSRunAction();
+
+  runManager->SetUserAction(myRunAction);
+
+
+  runManager->SetUserAction(new MEMPHYSEventAction(*analysisManager,
+						   myRunAction, 
+						   MEMPHYSdetector,
+						   myGeneratorAction));
+  runManager->SetUserAction(new MEMPHYSTrackingAction);
+
+  runManager->SetUserAction(new MEMPHYSStackingAction);
+
+
+  // Initialize G4 kernel
+  runManager->Initialize();
+
+  if (UI) {
+    std::string file = 
+      Lib::System::getenv("MEMPHYSROOT")+"/scripts/Geant4/init.g4m";
+    UI->ApplyCommand("/control/execute "+file);  
+  }
+
+  // Main UI loop :
+  session->SessionStart();
+
+  delete session; //It will delete the analysisManager.
+
+  delete runManager;
+
+  return 0;
+}
+
Index: /MEMPHYS/v0/cmt/requirements
===================================================================
--- /MEMPHYS/v0/cmt/requirements	(revision 11)
+++ /MEMPHYS/v0/cmt/requirements	(revision 11)
@@ -0,0 +1,98 @@
+package MEMPHYS
+version v0
+
+branches run
+
+#//////////////////////////////////////////////////
+#/// Uses needed to build this package ////////////
+#//////////////////////////////////////////////////
+
+use G4Lab v7r*
+
+
+#//////////////////////////////////////////////////
+#/// Over Geant4 kernel and AIDA interfaces only //
+#//////////////////////////////////////////////////
+
+build_strategy no_prototypes
+include_path none
+
+include_dirs $(MEMPHYSROOT)
+
+# Over Geant4 and AIDA only :
+library MEMPHYSCore ${G4Lab_libopts} -s=../source *.cxx
+
+#JEC 17/11/05 add the G4readout_incs to manage G4DigiManager
+macro MEMPHYSCore_cppflags "${G4Lab_Geant4_incs} ${G4readout_incs} ${G4particles_incs} ${G4processes_incs}"
+macro MEMPHYSCore_shlibflags "${G4Lab_Geant4_linkopts} ${LibCore_linkopts} ${dld_linkopts} ${cxxstd_linkopts}"
+macro MEMPHYSCore_linkopts "-L${MEMPHYSROOT}/$(Platform_bin) -lMEMPHYSCore" WIN32 "${MEMPHYSROOT}\$(Platform_bin)\MEMPHYSCore.lib"
+
+#//////////////////////////////////////////////////
+#/// DLD callbacks ////////////////////////////////
+#//////////////////////////////////////////////////
+
+library MEMPHYS -import=OpenInventor -s=../source/Callbacks Callbacks.cxx InventorCallbacks.cxx
+macro MEMPHYS_cppflags "${G4Lab_Geant4_incs}"
+macro MEMPHYS_shlibflags "${LibCore_linkopts} ${HEPVisPlotter_linkopts} ${HEPVisDetector_linkopts} ${HEPVisGeometry_linkopts} ${HEPVisUtils_linkopts} ${freetype_linkopts} ${jpeg_linkopts} ${dvi2bitmap_linkopts} ${OpenInventor_linkopts} ${OpenGL_linkopts} ${Xext_linkopts} ${X11_linkopts} ${dld_linkopts} ${cxxstd_linkopts}"
+
+#//////////////////////////////////////////////////
+#/// Application "a la Geant4 examples" ///////////
+#//////////////////////////////////////////////////
+
+# Over Geant4 and AIDA only :
+application MEMPHYS_batch -import=expat ../applications/MEMPHYS_batch.cxx use_linkopts='"${MEMPHYSCore_linkopts} ${G4physics_lists_hadronic_linkopts} ${G4Lab_Geant4_linkopts} ${LabAnalysisFactory_linkopts} ${LibCore_linkopts} ${math_linkopts} ${dld_linkopts}"'
+macro MEMPHYS_batch_cppflags "${MEMPHYSCore_cppflags} ${G4physics_lists_hadronic_incs}"
+
+# Over G4Lab :
+application MEMPHYS_session -import=expat ../applications/MEMPHYS_session.cxx use_linkopts='"${MEMPHYSCore_linkopts} ${G4physics_lists_hadronic_linkopts}  ${G4LabUIOnX_linkopts} ${G4LabCore_linkopts} ${G4Lab_Geant4_linkopts} ${G4LabHDUMMY_linkopts} ${HEPVisPlotter_linkopts} ${HEPVisDetector_linkopts} ${HEPVisGeometry_linkopts} ${HEPVisUtils_linkopts} ${freetype_linkopts} ${jpeg_linkopts} ${dvi2bitmap_linkopts} ${OpenInventor_linkopts} ${OnXCore_linkopts} ${LibXML_linkopts} ${expat_linkopts} ${LibZip_linkopts} ${zlib_linkopts} ${LibCore_linkopts} ${dld_linkopts} ${cxxstd_linkopts} ${Windows_linkopts} ${OpenGL_linkopts} ${Xext_linkopts} ${X11_linkopts} "' 
+macro MEMPHYS_session_cppflags "${G4Lab_Geant4_incs} ${MEMPHYS_batch_cppflags}"
+
+
+#JEC 18/11/05 not yet implemented: what's that Guy?
+# Over AIDA / Lab :
+#macro aida_config_libs "`aida-config --libs`" WIN32 "${LabAnalysisFactory_linkopts} ${LibCore_linkopts} ${math_linkopts} ${dld_linkopts}"
+#application MEMPHYS_analysis ../applications/MEMPHYS_analysis.cxx use_linkopts='"$(aida_config_libs)"'
+
+
+#//////////////////////////////////////////////////
+#//////////////////////////////////////////////////
+#//////////////////////////////////////////////////
+
+private
+macro build_library_links "true" WIN32 ""
+macro remove_library_links "true" WIN32 ""
+
+# WIN32 : /GR to enable RTTI and dynamic cast.
+# WIN32 : /GX to enable exception handling (for STL).
+macro_append cppflags "" WIN32 " /GX /GR" 
+
+# DEBUG :
+#macro_append cflags  " -g" WIN32 " /ZI /Od"
+#macro_append cppflags  " -g" WIN32 " /ZI /Od"
+#macro_append cpplinkflags  " -g" WIN32 " /DEBUG"
+
+# OPTIMIZE :
+macro_append cflags  " -O" WIN32 " /O2"
+macro_append cppflags  " -O" WIN32 " /O2"
+macro_append cpplinkflags  " -O" WIN32 ""
+
+# SunOS : For std::map, std::list templates :
+macro ar "$(ar)"  SunOS "CC -xar -o"
+public
+
+#//////////////////////////////////////////////////
+#// Run time //////////////////////////////////////
+#//////////////////////////////////////////////////
+
+use Lab v11r*
+
+path_remove LD_LIBRARY_PATH "${MEMPHYSROOT}/$(Platform_bin)" WIN32 "" Darwin ""
+path_append LD_LIBRARY_PATH "${MEMPHYSROOT}/$(Platform_bin)" WIN32 "" Darwin ""
+
+path_remove DYLD_LIBRARY_PATH "" Darwin "${MEMPHYSROOT}/$(Platform_bin)" WIN32 ""
+path_append DYLD_LIBRARY_PATH "" Darwin "${MEMPHYSROOT}/$(Platform_bin)" WIN32 ""
+
+path_remove PATH "" WIN32 "${MEMPHYSROOT}\$(Platform_bin)"
+path_append PATH "" WIN32 "${MEMPHYSROOT}\$(Platform_bin)"
+
+
