From 92253df24d41ffa69f17ffc650a7834f6ef11d4e Mon Sep 17 00:00:00 2001
From: adrien-matta <a.matta@surrey.ac.uk>
Date: Tue, 16 Dec 2014 09:54:08 +0000
Subject: [PATCH] * Updating S1 to follow new logic

---
 NPSimulation/AnnularS1/AnnularS1.cc    | 355 ++++++++++++-------------
 NPSimulation/AnnularS1/AnnularS1.hh    |  17 +-
 NPSimulation/Paris/Paris.hh            |  10 +-
 NPSimulation/include/SiliconScorers.hh |  18 +-
 NPSimulation/src/SiliconScorers.cc     |  19 +-
 5 files changed, 212 insertions(+), 207 deletions(-)

diff --git a/NPSimulation/AnnularS1/AnnularS1.cc b/NPSimulation/AnnularS1/AnnularS1.cc
index 47ede5eee..120205e10 100644
--- a/NPSimulation/AnnularS1/AnnularS1.cc
+++ b/NPSimulation/AnnularS1/AnnularS1.cc
@@ -25,11 +25,9 @@
 #include <string>
 #include <cmath>
 
-// G4 Geometry headers
+// Geant4 
 #include "G4Box.hh"
 #include "G4Tubs.hh"
-
-// G4 various headers
 #include "G4Material.hh"
 #include "G4VisAttributes.hh"
 #include "G4Colour.hh"
@@ -39,12 +37,10 @@
 #include "G4PVDivision.hh"
 #include "G4ExtrudedSolid.hh"
 #include "G4SubtractionSolid.hh"
-// G4 sensitive
 #include "G4SDManager.hh"
 #include "G4MultiFunctionalDetector.hh"
 
 // NPTool headers
-#include "ObsoleteGeneralScorers.hh"
 #include "MaterialManager.hh"
 #include "AnnularS1.hh"
 #include "SiliconScorers.hh"
@@ -61,6 +57,7 @@ using namespace ANNULARS1;
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 AnnularS1::AnnularS1(){
   m_Event = new TS1Data();
+  m_LogicalDetector = 0 ;
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -73,168 +70,161 @@ void AnnularS1::AddModule(G4double PosZ){
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
-void AnnularS1::VolumeMaker(G4int             DetecNumber,
-    G4ThreeVector     position,
-    G4RotationMatrix* rotation,
-    G4LogicalVolume*  world)
-{
-  G4Material* Silicon = MaterialManager::getInstance()->GetMaterialFromLibrary("Si");
-  G4Material* Vacuum = MaterialManager::getInstance()->GetMaterialFromLibrary("Vacuum");
-  ////////////////////////////////////////////////////////////////
-  ////////////// Starting Volume Definition //////////////////////
-  ////////////////////////////////////////////////////////////////
-  // Name of the module
-  G4String Name = "AnnularS1";
-
-  // Building the PCB
-  // The PCB is a simple extruded volume from 8reference point
-  vector<G4TwoVector> polygon;
-  for(unsigned int i = 0 ; i < 8 ; i++){
-    G4TwoVector Point(PCBPointsX[i],PCBPointsY[i]);
-    polygon.push_back(Point);
+G4LogicalVolume* AnnularS1::ConstructVolume(){
+
+  if(!m_LogicalDetector){
+    G4Material* Silicon = MaterialManager::getInstance()->GetMaterialFromLibrary("Si");
+    G4Material* Vacuum = MaterialManager::getInstance()->GetMaterialFromLibrary("Vacuum");
+    ////////////////////////////////////////////////////////////////
+    ////////////// Starting Volume Definition //////////////////////
+    ////////////////////////////////////////////////////////////////
+    // Name of the module
+    G4String Name = "AnnularS1";
+
+    // Building the PCB
+    // The PCB is a simple extruded volume from 8reference point
+    vector<G4TwoVector> polygon;
+    for(unsigned int i = 0 ; i < 8 ; i++){
+      G4TwoVector Point(PCBPointsX[i],PCBPointsY[i]);
+      polygon.push_back(Point);
+    }
+
+    // Mast volume containing all the detector
+    G4ExtrudedSolid* solidAnnularS1 = new G4ExtrudedSolid(Name,
+        polygon,
+        PCBThickness*0.5,
+        G4TwoVector(0,0),1,
+        G4TwoVector(0,0),1);
+
+    // Definition of the volume containing the sensitive detector
+    m_LogicalDetector = new G4LogicalVolume(solidAnnularS1, Vacuum, Name, 0, 0, 0);
+    m_LogicalDetector->SetVisAttributes(G4VisAttributes::Invisible);
+
+    // PCB Base
+    G4ExtrudedSolid* solidPCBBase = new G4ExtrudedSolid("PCBBase",
+        polygon,
+        PCBThickness*0.5,
+        G4TwoVector(0,0),1,
+        G4TwoVector(0,0),1);   
+
+    // Wafer Shape to be substracted to the PCB
+    G4Tubs* solidWaferShapeBase = new G4Tubs("WaferShape", 
+        0,
+        WaferOutterRadius,
+        PCBThickness,
+        0*deg, 
+        360*deg); 
+
+    // A no rotation matrix is always handy ;)
+    G4RotationMatrix* norotation = new  G4RotationMatrix(); 
+    // Rotation of the box that make the Si cut                       
+    G4RotationMatrix* cutrotation = new  G4RotationMatrix(G4ThreeVector(0,0,1),45*deg);                        
+    G4ThreeVector cutposition1(80*mm+WaferRCut,0,0); cutposition1.setPhi(45*deg);
+    G4Transform3D transform1(*cutrotation,cutposition1);
+
+    G4Box* solidCutout = new G4Box("cuttout",80*mm,80*mm,80*mm); 
+
+    G4SubtractionSolid* solidWaferShape1 = new G4SubtractionSolid("WaferShape1",
+        solidWaferShapeBase,
+        solidCutout,
+        transform1);
+
+
+    G4ThreeVector cutposition2(-80*mm-WaferRCut,0,0); cutposition2.setPhi(-135*deg);
+    G4Transform3D transform2(*cutrotation,cutposition2);
+    G4SubtractionSolid* solidWaferShape = new G4SubtractionSolid("WaferShape",
+        solidWaferShape1,
+        solidCutout,
+        transform2);
+
+
+    // PCB final
+    G4SubtractionSolid* solidPCB = new G4SubtractionSolid("AnnularS1_PCB1",
+        solidPCBBase,
+        solidWaferShape);
+
+    G4LogicalVolume* logicPCB = new G4LogicalVolume(solidPCB, Vacuum, "AnnularS1_PCB", 0, 0, 0);
+
+    new G4PVPlacement(G4Transform3D(*norotation, G4ThreeVector()),
+        logicPCB,
+        "AnnularS1_PCB",
+        m_LogicalDetector,
+        false,
+        0);
+
+    G4VisAttributes* PCBVisAtt = new G4VisAttributes(G4Colour(0.2, 0.5, 0.2)) ;
+    logicPCB->SetVisAttributes(PCBVisAtt);
+
+
+    // Wafer itself
+    G4Tubs* solidWaferBase = new G4Tubs("Wafer", 
+        WaferInnerRadius,
+        WaferOutterRadius,
+        WaferThickness,
+        0*deg, 
+        360*deg); 
+
+    G4SubtractionSolid* solidWafer1 = new G4SubtractionSolid("Wafer1",
+        solidWaferBase,
+        solidCutout,
+        transform1);
+
+    G4SubtractionSolid* solidWafer = new G4SubtractionSolid("Wafer",
+        solidWafer1,
+        solidCutout,
+        transform2);
+
+    G4LogicalVolume* logicWafer = new G4LogicalVolume(solidWafer, Silicon, "AnnularS1_Wafer", 0, 0, 0);
+    new G4PVPlacement(G4Transform3D(*norotation, G4ThreeVector()),
+        logicWafer,
+        "AnnularS1_Wafer",
+        m_LogicalDetector,
+        false,
+        0);
+
+    G4VisAttributes* SiVisAtt = new G4VisAttributes(G4Colour(0.3, 0.3, 0.3)) ;
+    logicWafer->SetVisAttributes(SiVisAtt); 
+
+    // Active Wafer
+    G4Tubs* solidActiveWaferBase = new G4Tubs("ActiveWafer", 
+        ActiveWaferInnerRadius,
+        ActiveWaferOutterRadius,
+        WaferThickness,
+        0*deg, 
+        360*deg); 
+
+
+    G4ThreeVector activecutposition1(80*mm+ActiveWaferRCut,0,0); activecutposition1.setPhi(45*deg);
+    G4Transform3D activetransform1(*cutrotation,activecutposition1);
+
+    G4SubtractionSolid* solidActiveWafer1 = new G4SubtractionSolid("ActiveWafer1",
+        solidActiveWaferBase,
+        solidCutout,
+        activetransform1);
+
+    G4ThreeVector activecutposition2(-80*mm-ActiveWaferRCut,0,0); activecutposition2.setPhi(-135*deg);
+    G4Transform3D activetransform2(*cutrotation,activecutposition2);
+
+    G4SubtractionSolid* solidActiveWafer = new G4SubtractionSolid("ActiveWafer",
+        solidActiveWafer1,
+        solidCutout,
+        activetransform2);
+
+    G4LogicalVolume* logicActiveWafer = new G4LogicalVolume(solidActiveWafer, Silicon, "AnnularS1_ActiveWafer", 0, 0, 0);
+    new G4PVPlacement(G4Transform3D(*norotation, G4ThreeVector()),
+        logicActiveWafer,
+        "AnnularS1_ActiveWafer",
+        logicWafer,
+        false,
+        0);
+
+    logicActiveWafer->SetVisAttributes(SiVisAtt);
+
+    // Set Silicon strip sensible
+    logicActiveWafer->SetSensitiveDetector(m_Scorer);
   }
+  return m_LogicalDetector;
 
-  // Mast volume containing all the detector
-  G4ExtrudedSolid* solidAnnularS1 = new G4ExtrudedSolid(Name,
-      polygon,
-      PCBThickness*0.5,
-      G4TwoVector(0,0),1,
-      G4TwoVector(0,0),1);
-
-  // Definition of the volume containing the sensitive detector
-  G4LogicalVolume* logicAnnularS1 = new G4LogicalVolume(solidAnnularS1, Vacuum, Name, 0, 0, 0);
-
-  new G4PVPlacement(G4Transform3D(*rotation, position),
-      logicAnnularS1,
-      Name,
-      world,
-      false,
-      DetecNumber);
-
-  logicAnnularS1->SetVisAttributes(G4VisAttributes::Invisible);
-
-  // PCB Base
-  G4ExtrudedSolid* solidPCBBase = new G4ExtrudedSolid("PCBBase",
-      polygon,
-      PCBThickness*0.5,
-      G4TwoVector(0,0),1,
-      G4TwoVector(0,0),1);   
-
-  // Wafer Shape to be substracted to the PCB
-  G4Tubs* solidWaferShapeBase = new G4Tubs("WaferShape", 
-      0,
-      WaferOutterRadius,
-      PCBThickness,
-      0*deg, 
-      360*deg); 
-
-  // A no rotation matrix is always handy ;)
-  G4RotationMatrix* norotation = new  G4RotationMatrix(); 
-  // Rotation of the box that make the Si cut                       
-  G4RotationMatrix* cutrotation = new  G4RotationMatrix(G4ThreeVector(0,0,1),45*deg);                        
-  G4ThreeVector cutposition1(80*mm+WaferRCut,0,0); cutposition1.setPhi(45*deg);
-  G4Transform3D transform1(*cutrotation,cutposition1);
-
-  G4Box* solidCutout = new G4Box("cuttout",80*mm,80*mm,80*mm); 
-
-  G4SubtractionSolid* solidWaferShape1 = new G4SubtractionSolid("WaferShape1",
-      solidWaferShapeBase,
-      solidCutout,
-      transform1);
-
-
-  G4ThreeVector cutposition2(-80*mm-WaferRCut,0,0); cutposition2.setPhi(-135*deg);
-  G4Transform3D transform2(*cutrotation,cutposition2);
-  G4SubtractionSolid* solidWaferShape = new G4SubtractionSolid("WaferShape",
-      solidWaferShape1,
-      solidCutout,
-      transform2);
-
-
-  // PCB final
-  G4SubtractionSolid* solidPCB = new G4SubtractionSolid("AnnularS1_PCB1",
-      solidPCBBase,
-      solidWaferShape);
-
-  G4LogicalVolume* logicPCB = new G4LogicalVolume(solidPCB, Vacuum, "AnnularS1_PCB", 0, 0, 0);
-
-  new G4PVPlacement(G4Transform3D(*norotation, G4ThreeVector()),
-      logicPCB,
-      "AnnularS1_PCB",
-      logicAnnularS1,
-      false,
-      DetecNumber);
-
-  G4VisAttributes* PCBVisAtt = new G4VisAttributes(G4Colour(0.2, 0.5, 0.2)) ;
-  logicPCB->SetVisAttributes(PCBVisAtt);
-
-
-  // Wafer itself
-  G4Tubs* solidWaferBase = new G4Tubs("Wafer", 
-      WaferInnerRadius,
-      WaferOutterRadius,
-      WaferThickness,
-      0*deg, 
-      360*deg); 
-
-  G4SubtractionSolid* solidWafer1 = new G4SubtractionSolid("Wafer1",
-      solidWaferBase,
-      solidCutout,
-      transform1);
-
-  G4SubtractionSolid* solidWafer = new G4SubtractionSolid("Wafer",
-      solidWafer1,
-      solidCutout,
-      transform2);
-
-  G4LogicalVolume* logicWafer = new G4LogicalVolume(solidWafer, Silicon, "AnnularS1_Wafer", 0, 0, 0);
-  new G4PVPlacement(G4Transform3D(*norotation, G4ThreeVector()),
-      logicWafer,
-      "AnnularS1_Wafer",
-      logicAnnularS1,
-      false,
-      DetecNumber);
-
-  G4VisAttributes* SiVisAtt = new G4VisAttributes(G4Colour(0.3, 0.3, 0.3)) ;
-  logicWafer->SetVisAttributes(SiVisAtt); 
-
-  // Active Wafer
-  G4Tubs* solidActiveWaferBase = new G4Tubs("ActiveWafer", 
-      ActiveWaferInnerRadius,
-      ActiveWaferOutterRadius,
-      WaferThickness,
-      0*deg, 
-      360*deg); 
-
-
-  G4ThreeVector activecutposition1(80*mm+ActiveWaferRCut,0,0); activecutposition1.setPhi(45*deg);
-  G4Transform3D activetransform1(*cutrotation,activecutposition1);
-
-  G4SubtractionSolid* solidActiveWafer1 = new G4SubtractionSolid("ActiveWafer1",
-      solidActiveWaferBase,
-      solidCutout,
-      activetransform1);
-
-  G4ThreeVector activecutposition2(-80*mm-ActiveWaferRCut,0,0); activecutposition2.setPhi(-135*deg);
-  G4Transform3D activetransform2(*cutrotation,activecutposition2);
- 
-  G4SubtractionSolid* solidActiveWafer = new G4SubtractionSolid("ActiveWafer",
-      solidActiveWafer1,
-      solidCutout,
-      activetransform2);
-
-  G4LogicalVolume* logicActiveWafer = new G4LogicalVolume(solidActiveWafer, Silicon, "AnnularS1_ActiveWafer", 0, 0, 0);
-  new G4PVPlacement(G4Transform3D(*norotation, G4ThreeVector()),
-      logicActiveWafer,
-      "AnnularS1_ActiveWafer",
-      logicWafer,
-      false,
-      DetecNumber);
-
-  logicActiveWafer->SetVisAttributes(SiVisAtt);
-
-  // Set Silicon strip sensible
-  logicActiveWafer->SetSensitiveDetector(m_Scorer);
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -242,6 +232,7 @@ void AnnularS1::VolumeMaker(G4int             DetecNumber,
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 // Virtual Method of VDetector class
 
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 // Read stream at Configfile to pick-up parameters of detector (Position,...)
 // Called in DetecorConstruction::ReadDetextorConfiguration Method
 void AnnularS1::ReadConfiguration(string Path){
@@ -304,6 +295,7 @@ void AnnularS1::ReadConfiguration(string Path){
   }
 }
 
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 // Construct detector and inialise sensitive part.
 // Called After DetecorConstruction::AddDetector Method
 void AnnularS1::ConstructDetector(G4LogicalVolume* world){
@@ -321,13 +313,18 @@ void AnnularS1::ConstructDetector(G4LogicalVolume* world){
     rotation = new G4RotationMatrix();
     if (position.z() < 0) rotation->rotateX(180*deg);
 
-    // Build geometry and declare scorers
-    VolumeMaker(i + 1, position, rotation, world);
+    new G4PVPlacement(G4Transform3D(*rotation, position),
+        ConstructVolume(),
+        "AnnularS1",
+        world,
+        false,
+        i+1);
   }
 
   delete rotation ;
 }
 
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 // Connect the GaspardTrackingData class to the output TTree
 // of the simulation
 void AnnularS1::InitializeRootOutput(){
@@ -337,6 +334,7 @@ void AnnularS1::InitializeRootOutput(){
   pTree->SetBranchAddress("AnnularS1",&m_Event);
 }
 
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 // Read sensitive part and fill the Root tree.
 // Called at in the EventAction::EndOfEventAvtion
 void AnnularS1::ReadSensitive(const G4Event* event){
@@ -345,16 +343,16 @@ void AnnularS1::ReadSensitive(const G4Event* event){
 
   G4THitsMap<G4double*>* SiliconHitMap;
   std::map<G4int, G4double**>::iterator Silicon_itr;
-  
+
   G4int SiliconCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("AnnularS1_Scorer/AnnularS1_Scorer");
   SiliconHitMap = (G4THitsMap<G4double*>*)(event->GetHCofThisEvent()->GetHC(SiliconCollectionID));
-  
+
   // Loop on the Silicon map
   for (Silicon_itr = SiliconHitMap->GetMap()->begin() ; Silicon_itr != SiliconHitMap->GetMap()->end() ; Silicon_itr++){
     G4double* Info = *(Silicon_itr->second);
-   
+
     double Energy = Info[0];
-    
+
     if(Energy>EnergyThreshold){
       double Time       = Info[1];
       int DetNbr        = (int) Info[7];
@@ -365,41 +363,42 @@ void AnnularS1::ReadSensitive(const G4Event* event){
       m_Event->SetS1ThetaEDetectorNbr(DetNbr);
       m_Event->SetS1ThetaEStripNbr(StripTheta+StripQuadrant*NbrRingStrips);
       m_Event->SetS1ThetaEEnergy(RandGauss::shoot(Energy, ResoEnergy));
-      
+
       m_Event->SetS1ThetaTDetectorNbr(DetNbr);
       m_Event->SetS1ThetaTStripNbr(StripTheta+StripQuadrant*NbrRingStrips);
       m_Event->SetS1ThetaTTime(RandGauss::shoot(Time, ResoTime));
-      
+
       m_Event->SetS1PhiEDetectorNbr(DetNbr);
       m_Event->SetS1PhiEStripNbr(StripPhi);
       m_Event->SetS1PhiEEnergy(RandGauss::shoot(Energy, ResoEnergy));
       m_Event->SetS1PhiTDetectorNbr(DetNbr);
       m_Event->SetS1PhiTStripNbr(StripPhi);
       m_Event->SetS1PhiTTime(RandGauss::shoot(Time, ResoTime));
-      
+
       // Interraction Coordinates
       ms_InterCoord->SetDetectedPositionX(Info[2]) ;
       ms_InterCoord->SetDetectedPositionY(Info[3]) ;
       ms_InterCoord->SetDetectedPositionZ(Info[4]) ;
       ms_InterCoord->SetDetectedAngleTheta(Info[5]/deg) ;
       ms_InterCoord->SetDetectedAnglePhi(Info[6]/deg) ;
-      
+
     }
   }
   // clear map for next event
   SiliconHitMap->clear();
 }
 
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 // Initilize the Scorer use to read out the sensitive volume 
-void AnnularS1::InitializeScorers()
-{
- bool already_exist = false;  
+void AnnularS1::InitializeScorers(){
+  bool already_exist = false;  
   // Associate Scorer
   m_Scorer = CheckScorer("AnnularS1_Scorer",already_exist);
   if(already_exist) return;
 
   G4VPrimitiveScorer* AnnularScorer =
     new  SILICONSCORERS::PS_Silicon_Annular("AnnularS1_Scorer",
+        2,
         ActiveWaferInnerRadius,
         ActiveWaferOutterRadius,
         -22.5*deg,
diff --git a/NPSimulation/AnnularS1/AnnularS1.hh b/NPSimulation/AnnularS1/AnnularS1.hh
index 5b7fb1aac..b21f2f55f 100644
--- a/NPSimulation/AnnularS1/AnnularS1.hh
+++ b/NPSimulation/AnnularS1/AnnularS1.hh
@@ -33,12 +33,11 @@ using namespace CLHEP;
 // NPTool - ROOT headers
 #include "TS1Data.h"
 
-// Geant4Header
+// Geant4
 #include "G4MultiFunctionalDetector.hh"
+#include "G4LogicalVolume.hh"
 
-
-class AnnularS1 : public VDetector
-{
+class AnnularS1 : public VDetector{
    ////////////////////////////////////////////////////
    /////// Default Constructor and Destructor /////////
    ////////////////////////////////////////////////////
@@ -53,13 +52,11 @@ public:
    // By Position Method
    void AddModule(G4double PosZ);
 
-   // Effectively construct Volume
-   // Avoid to have two time same code for Angle and Point definition
-   void VolumeMaker(G4int             DetecNumber,
-                    G4ThreeVector     pos,
-                    G4RotationMatrix* rot,
-                    G4LogicalVolume*  world);
+   // Produce the logical volume of the detector
+   G4LogicalVolume* ConstructVolume();
 
+private:
+  G4LogicalVolume* m_LogicalDetector;
 
    ////////////////////////////////////////////////////
    ////  Inherite from GaspardTrackerModule class /////
diff --git a/NPSimulation/Paris/Paris.hh b/NPSimulation/Paris/Paris.hh
index b885e1063..77c7d6b33 100644
--- a/NPSimulation/Paris/Paris.hh
+++ b/NPSimulation/Paris/Paris.hh
@@ -1,20 +1,20 @@
 #ifndef Paris_h
 #define Paris_h 1
 /*****************************************************************************
- * Copyright (C) 2009-2013   this file is part of the NPTool Project         *
+ * Copyright (C) 2009-2014   this file is part of the NPTool Project         *
  *                                                                           *
  * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
  * For the list of contributors see $NPTOOL/Licence/Contributors             *
  *****************************************************************************/
 
 /*****************************************************************************
- * Original Author: Adrien MATTA  contact address: a.matta@surrey.ac.uk      *
+ * Original Author: M. Labiche  contact address: marc.labiche@stfc.ac.uk     *
  *                                                                           *
- * Creation Date  : November 2012                                            *
- * Last update    :                                                          *
+ * Creation Date  : December 2009                                            *
+ * Last update    : December 2014                                            *
  *---------------------------------------------------------------------------*
  * Decription:                                                               *
- *  This class describe the Paris Silicon detector                           *
+ *  This class describe the Paris scintillator array                         *
  *                                                                           *
  *---------------------------------------------------------------------------*
  * Comment:                                                                  *
diff --git a/NPSimulation/include/SiliconScorers.hh b/NPSimulation/include/SiliconScorers.hh
index af9e75869..5e2c849fd 100644
--- a/NPSimulation/include/SiliconScorers.hh
+++ b/NPSimulation/include/SiliconScorers.hh
@@ -36,7 +36,7 @@ namespace SILICONSCORERS {
   class PS_Silicon_Rectangle : public G4VPrimitiveScorer{
     
   public: // with description
-    PS_Silicon_Rectangle(G4String name, G4double StripPlaneLength, G4double StripPlaneWidth, G4int NumberOfStripLength,G4int NumberOfStripWidth,G4int depth=0);
+    PS_Silicon_Rectangle(G4String name, G4int Level, G4double StripPlaneLength, G4double StripPlaneWidth, G4int NumberOfStripLength,G4int NumberOfStripWidth,G4int depth=0);
      ~PS_Silicon_Rectangle();
     
   protected: // with description
@@ -56,7 +56,9 @@ namespace SILICONSCORERS {
     G4int    m_NumberOfStripWidth;
     G4double m_StripPitchLength;
     G4double m_StripPitchWidth;
-    
+    // Level at which to find the copy number linked to the detector number
+    G4int    m_Level;
+
   private: // inherited from G4VPrimitiveScorer
     G4int HCID;
     G4THitsMap<G4double*>* EvtMap;
@@ -74,7 +76,7 @@ namespace SILICONSCORERS {
   class PS_Silicon_Annular : public G4VPrimitiveScorer{
     
   public: // with description
-    PS_Silicon_Annular(G4String name, G4double StripPlaneInnerRadius, G4double StripPlaneOuterRadius, G4double PhiStart,G4double PhiStop, G4int NumberOfStripRing,G4int NumberOfStripSector=1, G4int NumberOfQuadrant=1,G4int depth=0);
+    PS_Silicon_Annular(G4String name,G4int Level, G4double StripPlaneInnerRadius, G4double StripPlaneOuterRadius, G4double PhiStart,G4double PhiStop, G4int NumberOfStripRing,G4int NumberOfStripSector=1, G4int NumberOfQuadrant=1,G4int depth=0);
     ~PS_Silicon_Annular();
     
   protected: // with description
@@ -98,7 +100,9 @@ namespace SILICONSCORERS {
     G4double m_StripPitchRing;
     G4double m_StripPitchSector;
     G4double m_StripPitchQuadrant; 
-    
+    // Level at which to find the copy number linked to the detector number
+    G4int    m_Level;
+
   private: // inherited from G4VPrimitiveScorer
     G4int HCID;
     G4THitsMap<G4double*>* EvtMap;
@@ -117,7 +121,7 @@ namespace SILICONSCORERS {
   class PS_Silicon_Resistive : public G4VPrimitiveScorer{
     
   public: // with description
-    PS_Silicon_Resistive(G4String name,
+    PS_Silicon_Resistive(G4String name, G4int Level,
                          G4double StripPlaneLength, G4double StripPlaneWidth,
                          G4int NumberOfStripWidth,G4int depth=0);
     
@@ -138,7 +142,9 @@ namespace SILICONSCORERS {
     G4double m_StripPlaneWidth;
     G4int    m_NumberOfStripWidth;
     G4double m_StripPitchWidth;
-    
+    // Level at which to find the copy number linked to the detector number
+    G4int    m_Level;
+   
   private: // inherited from G4VPrimitiveScorer
     G4int HCID;
     G4THitsMap<G4double*>* EvtMap;
diff --git a/NPSimulation/src/SiliconScorers.cc b/NPSimulation/src/SiliconScorers.cc
index 504861f0c..d23e61dbd 100644
--- a/NPSimulation/src/SiliconScorers.cc
+++ b/NPSimulation/src/SiliconScorers.cc
@@ -24,7 +24,7 @@
 using namespace SILICONSCORERS ;
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
-PS_Silicon_Rectangle::PS_Silicon_Rectangle(G4String name, G4double StripPlaneLength, G4double StripPlaneWidth, G4int NumberOfStripLength,G4int NumberOfStripWidth,G4int depth)
+PS_Silicon_Rectangle::PS_Silicon_Rectangle(G4String name,G4int Level, G4double StripPlaneLength, G4double StripPlaneWidth, G4int NumberOfStripLength,G4int NumberOfStripWidth,G4int depth)
 :G4VPrimitiveScorer(name, depth),HCID(-1){
   m_StripPlaneLength = StripPlaneLength;
   m_StripPlaneWidth = StripPlaneWidth;
@@ -32,7 +32,8 @@ PS_Silicon_Rectangle::PS_Silicon_Rectangle(G4String name, G4double StripPlaneLen
   m_NumberOfStripWidth = NumberOfStripWidth;
   m_StripPitchLength = m_StripPlaneLength / m_NumberOfStripLength;
   m_StripPitchWidth = m_StripPlaneWidth / m_NumberOfStripWidth;
-  
+  m_Level = Level;
+
   m_Position = G4ThreeVector(-1000,-1000,-1000);
   m_DetectorNumber = -1;
   m_StripLengthNumber = -1;
@@ -52,7 +53,7 @@ G4bool PS_Silicon_Rectangle::ProcessHits(G4Step* aStep, G4TouchableHistory*){
   Infos[0] = aStep->GetTotalEnergyDeposit();
   Infos[1] = aStep->GetPreStepPoint()->GetGlobalTime();
   
-  m_DetectorNumber = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(1);
+  m_DetectorNumber = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_Level);
   m_Position  = aStep->GetPreStepPoint()->GetPosition();
   
   // Interaction coordinates (used to fill the InteractionCoordinates branch)
@@ -127,7 +128,7 @@ void PS_Silicon_Rectangle::PrintAll(){
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
-PS_Silicon_Annular::PS_Silicon_Annular(G4String name, G4double StripPlaneInnerRadius, G4double StripPlaneOuterRadius, G4double PhiStart,G4double PhiStop, G4int NumberOfStripRing,G4int NumberOfStripSector,G4int NumberOfQuadrant,G4int depth)
+PS_Silicon_Annular::PS_Silicon_Annular(G4String name,G4int Level, G4double StripPlaneInnerRadius, G4double StripPlaneOuterRadius, G4double PhiStart,G4double PhiStop, G4int NumberOfStripRing,G4int NumberOfStripSector,G4int NumberOfQuadrant,G4int depth)
 :G4VPrimitiveScorer(name, depth),HCID(-1){
   
   m_StripPlaneInnerRadius = StripPlaneInnerRadius;
@@ -140,6 +141,7 @@ PS_Silicon_Annular::PS_Silicon_Annular(G4String name, G4double StripPlaneInnerRa
   m_StripPitchRing =  (m_StripPlaneOuterRadius-m_StripPlaneInnerRadius)/m_NumberOfStripRing;
   m_StripPitchSector = (m_PhiStop-m_PhiStart)/m_NumberOfStripSector;
   m_StripPitchQuadrant = (m_PhiStop-m_PhiStart)/m_NumberOfStripQuadrant;  
+  m_Level = Level;
 
   m_Position = G4ThreeVector(-1000,-1000,-1000);
   m_uz = G4ThreeVector(0,0,1);
@@ -161,7 +163,7 @@ G4bool PS_Silicon_Annular::ProcessHits(G4Step* aStep, G4TouchableHistory*){
   
   Infos[1] = aStep->GetPreStepPoint()->GetGlobalTime();
   
-  m_DetectorNumber = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(1);
+  m_DetectorNumber = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_Level);
   m_Position = aStep->GetPreStepPoint()->GetPosition();
  
   // Interaction coordinates (used to fill the InteractionCoordinates branch)
@@ -238,13 +240,14 @@ void PS_Silicon_Annular::PrintAll(){
   G4cout << " Number of entries " << EvtMap->entries() << G4endl     ;
 }
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
-PS_Silicon_Resistive::PS_Silicon_Resistive(G4String name, G4double StripPlaneLength, G4double StripPlaneWidth, G4int NumberOfStripWidth,G4int depth)
+PS_Silicon_Resistive::PS_Silicon_Resistive(G4String name,G4int Level, G4double StripPlaneLength, G4double StripPlaneWidth, G4int NumberOfStripWidth,G4int depth)
 :G4VPrimitiveScorer(name, depth),HCID(-1){
   m_StripPlaneLength = StripPlaneLength;
   m_StripPlaneWidth = StripPlaneWidth;
   m_NumberOfStripWidth = NumberOfStripWidth;
   m_StripPitchWidth = m_StripPlaneWidth / m_NumberOfStripWidth;
-  
+  m_Level = Level;
+
   m_Position = G4ThreeVector(-1000,-1000,-1000);
   m_DetectorNumber = -1;
   m_StripWidthNumber = -1;
@@ -263,7 +266,7 @@ G4bool PS_Silicon_Resistive::ProcessHits(G4Step* aStep, G4TouchableHistory*){
   
   EnergyAndTime[2] = aStep->GetPreStepPoint()->GetGlobalTime();
   
-  m_DetectorNumber = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(1);
+  m_DetectorNumber = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_Level);
   m_Position  = aStep->GetPreStepPoint()->GetPosition();
   
   // Interaction coordinates (used to fill the InteractionCoordinates branch)
-- 
GitLab