From ea983b7f96e40d4f2cb16617024f3922d7fa8e0c Mon Sep 17 00:00:00 2001
From: matta <matta@npt>
Date: Wed, 6 Feb 2013 12:29:07 +0000
Subject: [PATCH] * Finnishing Sharc geometry:  - Placement of Box detector Ok
 for Pad and Single layer case  - Restauring original colour of the PCB

---
 Inputs/DetectorConfiguration/Sharc.detector | 18 +++----
 NPSimulation/include/Sharc.hh               | 45 +++++++++++-------
 NPSimulation/src/Sharc.cc                   | 52 +++++++++++----------
 3 files changed, 65 insertions(+), 50 deletions(-)

diff --git a/Inputs/DetectorConfiguration/Sharc.detector b/Inputs/DetectorConfiguration/Sharc.detector
index 74afb1bee..45043e097 100644
--- a/Inputs/DetectorConfiguration/Sharc.detector
+++ b/Inputs/DetectorConfiguration/Sharc.detector
@@ -14,22 +14,22 @@ Target
 Sharc
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   %Upstream CD
-  %SharcQQQ
+  SharcQQQ
     Z= -100
     R= 0
     Phi= 0
     ThicknessDector= 100
-  %SharcQQQ
+  SharcQQQ
     Z= -100
     R= 0
     Phi= 90
     ThicknessDector= 100
-  %SharcQQQ
+  SharcQQQ
     Z= -100
     R= 0
     Phi= 180
     ThicknessDector= 100
-  %SharcQQQ
+  SharcQQQ
     Z= -100
     R= 0
     Phi= 270
@@ -48,7 +48,7 @@ Sharc
     ThicknessPAD4= 0
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %Down Stream Box
- % SharcBOX
+  SharcBOX
     Z= 40
     ThicknessDector1= 100
     ThicknessDector2= 100
@@ -60,22 +60,22 @@ Sharc
     ThicknessPAD4= 1000
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   %Downstream CD
-  %SharcQQQ
+  SharcQQQ
     Z= 100
     R= 0
     Phi= 0
     ThicknessDector= 100
-  %SharcQQQ
+  SharcQQQ
     Z= 100
     R= 0
     Phi= 90
     ThicknessDector= 100
-  %SharcQQQ
+  SharcQQQ
     Z= 100
     R= 0
     Phi= 180
     ThicknessDector= 100
-  %SharcQQQ
+  SharcQQQ
     Z= 100
     R= 0
     Phi= 270
diff --git a/NPSimulation/include/Sharc.hh b/NPSimulation/include/Sharc.hh
index 7d71daa82..b63908b0c 100644
--- a/NPSimulation/include/Sharc.hh
+++ b/NPSimulation/include/Sharc.hh
@@ -58,9 +58,9 @@ namespace SHARC
   const G4double BOX_PCB_Border_ShortSide = 2*mm;
   
   // Single stage box case (DSSD only)
-  const G4double BOX_PCB_Slot1_Width = BOX_PCB_Thickness;
-  const G4double BOX_PCB_Slot1_Border = 4*mm;
-  const G4double BOX_PCB_Slot1_Deepness = BOX_PCB_Border_ShortSide;
+  const G4double BOX_PCB_Slot_Width1 = BOX_PCB_Thickness;
+  const G4double BOX_PCB_Slot_Border1 = 4*mm;
+  const G4double BOX_PCB_Slot_Deepness1 = BOX_PCB_Border_ShortSide;
   
   // BOX Wafer
   const G4double BOX_Wafer_Width  = 52.20*mm;
@@ -71,16 +71,16 @@ namespace SHARC
   const G4int    BOX_Wafer_Back_NumberOfStrip = 16 ;
   
   // Compute
-  const G4double BOX_LeftOver =  BOX_PCB_Length - BOX_PCB_Border_ShortSide - BOX_Wafer_Length - BOX_PCB_Slot1_Border - BOX_PCB_Slot1_Width ;
-  const G4double BOX_Exposed_Length1 = BOX_Wafer_Length + BOX_PCB_Slot1_Border ;
+  const G4double BOX_LeftOver1 =  BOX_PCB_Length - BOX_PCB_Border_ShortSide - BOX_Wafer_Length - BOX_PCB_Slot_Border1 - BOX_PCB_Slot_Width1 ;
+  const G4double BOX_Exposed_Length1 = BOX_Wafer_Length + BOX_PCB_Slot_Border1 ;
   
   const G4double BOX_CenterOffset1 = - 0.5 * BOX_PCB_Length+BOX_PCB_Border_ShortSide+0.5*BOX_Exposed_Length1;
-  const G4double BOX_DetectorSpacing = 0.5*BOX_Exposed_Length1+0.5*BOX_PCB_Slot1_Width;
+  const G4double BOX_DetectorSpacing1 = 0.5*BOX_Exposed_Length1+0.5*BOX_PCB_Slot_Width1;
   
-  const G4double BOX_Wafer_Width_Offset = -0.5*BOX_PCB_Width + BOX_PCB_Border_LongSide + 0.5*BOX_Wafer_Width;
-  const G4double BOX_Wafer_Length_Offset = -0.5*BOX_PCB_Length + BOX_PCB_Border_ShortSide + 0.5*BOX_Wafer_Length;
+  const G4double BOX_Wafer_Width_Offset1 = -0.5*BOX_PCB_Width + BOX_PCB_Border_LongSide + 0.5*BOX_Wafer_Width;
+  const G4double BOX_Wafer_Length_Offset1 = -0.5*BOX_PCB_Length + BOX_PCB_Border_ShortSide + 0.5*BOX_Wafer_Length;
   
-  const G4double BOX_PCB_Slot1_Position = 0.5*BOX_PCB_Length-BOX_LeftOver - 0.5*BOX_PCB_Slot1_Width;
+  const G4double BOX_PCB_Slot_Position1 = 0.5*BOX_PCB_Length-BOX_LeftOver1 - 0.5*BOX_PCB_Slot_Width1;
 
   // PAD //
   // PAD PCB
@@ -96,13 +96,25 @@ namespace SHARC
   const G4double PAD_Wafer_DeadLayer_Thickness = 0.1*um;
   
   // Compute
-  const G4double PAD_Wafer_Width_Offset = PAD_PCB_Width/2. - PAD_PCB_Border_LongSide - PAD_Wafer_Width/2.;
-  const G4double PAD_Wafer_Length_Offset = PAD_PCB_Length/2. - PAD_PCB_Border_ShortSide - PAD_Wafer_Length/2.;
-  // Double stage box case (DSSD+PAD)
-  const G4double BOX_PCB_Slot2_Width = BOX_PCB_Thickness+PAD_PCB_Thickness;
-  const G4double BOX_PCB_Slot2_Border = 2.7*mm;
-  const G4double BOX_PCB_Slot2_Deepness = BOX_PCB_Border_ShortSide;
-  const G4double BOX_PCB_Slot2_Position =(BOX_Wafer_Length/2.-BOX_Wafer_Length_Offset) + BOX_PCB_Slot2_Border + BOX_PCB_Slot2_Width/2.;
+  const G4double PAD_Wafer_Width_Offset = -0.5*PAD_PCB_Width + PAD_PCB_Border_LongSide + 0.5*PAD_Wafer_Width;
+  const G4double PAD_Wafer_Length_Offset = -0.5*PAD_PCB_Length + PAD_PCB_Border_ShortSide + 0.5*PAD_Wafer_Length;
+
+  
+  // Double stage box case (DSSD+PAD) (the wafer is the same but the slot is different to accomodate the additional PAD)
+  const G4double BOX_PCB_Slot_Width2 = BOX_PCB_Thickness + PAD_PCB_Thickness ;
+  const G4double BOX_PCB_Slot_Border2 = 2.7*mm;
+  const G4double BOX_PCB_Slot_Deepness2 = BOX_PCB_Border_ShortSide;
+  
+  const G4double BOX_LeftOver2 =  BOX_PCB_Length - BOX_PCB_Border_ShortSide - BOX_Wafer_Length - BOX_PCB_Slot_Border2 - BOX_PCB_Slot_Width2;
+  const G4double BOX_Exposed_Length2 = BOX_Wafer_Length + BOX_PCB_Slot_Border2 ;
+  
+  const G4double BOX_CenterOffset2 = - 0.5*BOX_PCB_Length+BOX_PCB_Border_ShortSide + 0.5*BOX_Exposed_Length2;
+  const G4double BOX_DetectorSpacing2 = 0.5*BOX_Exposed_Length2 + 0.5*BOX_PCB_Thickness;
+
+  const G4double BOX_Wafer_Width_Offset2 = - 0.5*BOX_PCB_Width + BOX_PCB_Border_LongSide + 0.5*BOX_Wafer_Width;
+  const G4double BOX_Wafer_Length_Offset2 = - 0.5*BOX_PCB_Length + BOX_PCB_Border_ShortSide + 0.5*BOX_Wafer_Length;
+  
+  const G4double BOX_PCB_Slot_Position2 = 0.5*BOX_PCB_Length-BOX_LeftOver2 - 0.5*BOX_PCB_Slot_Width2;
   
   // QQQ //
   // QQQ PCB
@@ -122,7 +134,6 @@ namespace SHARC
 }
 
 using namespace SHARC ;
-
 class Sharc : public VDetector
 {
   ////////////////////////////////////////////////////
diff --git a/NPSimulation/src/Sharc.cc b/NPSimulation/src/Sharc.cc
index 03eaca7e3..f42e734b4 100644
--- a/NPSimulation/src/Sharc.cc
+++ b/NPSimulation/src/Sharc.cc
@@ -355,19 +355,22 @@ void Sharc::ConstructBOXDetector(G4LogicalVolume* world){
       G4double BOX_PCB_Slot_Deepness;
       G4double BOX_PCB_Slot_Border;
       G4double BOX_PCB_Slot_Position;
+      G4double BOX_DetectorSpacing;
       
-      if(m_ThicknessPAD[i][j]>0){
-        BOX_PCB_Slot_Width = BOX_PCB_Slot2_Width;
-        BOX_PCB_Slot_Deepness = BOX_PCB_Slot2_Deepness;
-        BOX_PCB_Slot_Border = BOX_PCB_Slot2_Border;
-        BOX_PCB_Slot_Position = BOX_PCB_Slot2_Position;
+      if(m_ThicknessPAD[i][j]>0){ //PAD Case
+        BOX_PCB_Slot_Width = BOX_PCB_Slot_Width2;
+        BOX_PCB_Slot_Deepness = BOX_PCB_Slot_Deepness2;
+        BOX_PCB_Slot_Border = BOX_PCB_Slot_Border2;
+        BOX_PCB_Slot_Position = BOX_PCB_Slot_Position2;
+        BOX_DetectorSpacing =  BOX_DetectorSpacing2;
       }
       
-      else{
-        BOX_PCB_Slot_Width = BOX_PCB_Slot1_Width;
-        BOX_PCB_Slot_Deepness = BOX_PCB_Slot1_Deepness;
-        BOX_PCB_Slot_Border = BOX_PCB_Slot1_Border;
-        BOX_PCB_Slot_Position = BOX_PCB_Slot1_Position;
+      else{ // No Pad Case
+        BOX_PCB_Slot_Width = BOX_PCB_Slot_Width1;
+        BOX_PCB_Slot_Deepness = BOX_PCB_Slot_Deepness1;
+        BOX_PCB_Slot_Border = BOX_PCB_Slot_Border1;
+        BOX_PCB_Slot_Position = BOX_PCB_Slot_Position1;
+        BOX_DetectorSpacing = BOX_DetectorSpacing1 ;
       }
       
       G4Box*  SlotShape = new G4Box("SlotShape",
@@ -376,7 +379,7 @@ void Sharc::ConstructBOXDetector(G4LogicalVolume* world){
                                     BOX_PCB_Slot_Deepness);
       
       G4ThreeVector Box_Wafer_Offset =
-      G4ThreeVector(BOX_Wafer_Length_Offset, BOX_Wafer_Width_Offset,0 );
+      G4ThreeVector(BOX_Wafer_Length_Offset1, BOX_Wafer_Width_Offset1,0 );
       
       G4SubtractionSolid* PCB1 = new G4SubtractionSolid("PCB", PCBFull, SlotShape,new G4RotationMatrix,G4ThreeVector(BOX_PCB_Slot_Position, 0,0.5*BOX_PCB_Thickness));
       
@@ -389,8 +392,7 @@ void Sharc::ConstructBOXDetector(G4LogicalVolume* world){
       // Sub Volume PCB
       G4LogicalVolume* logicPCB =
       new G4LogicalVolume(PCB,m_MaterialPCB,"logicPCB", 0, 0, 0);
-      //logicPCB->SetVisAttributes(PCBVisAtt);
-      logicPCB->SetVisAttributes(new G4VisAttributes(G4Colour(j/4., (4-j)/4., 0.5)) );
+      logicPCB->SetVisAttributes(PCBVisAtt);
       
       // Sub Volume Wafer
       G4LogicalVolume* logicWafer =
@@ -457,33 +459,35 @@ void Sharc::ConstructBOXDetector(G4LogicalVolume* world){
                           logicPADPCB,"PAD_PCB",logicPADDetector,false,i*4+j+1);
         
         new G4PVPlacement(new G4RotationMatrix(0,0,0),
-                          PAD_Wafer_Offset,
+                          PAD_Wafer_Offset-G4ThreeVector(0,0,0.5*PAD_PCB_Thickness-0.5*m_ThicknessPAD[i][j]),
                           logicPADWafer,"PAD_Wafer",logicPADDetector,false,i*4+j+1);
       }
       
       ///////////////////////////////////////////////////////////////////////////////////
       // Place the detector in the world
       // Position of the center of the PCB
-      G4ThreeVector DetectorPosition =
-      G4ThreeVector(-BOX_CenterOffset1,-Box_Wafer_Offset.y(),0);
+      
+      G4ThreeVector DetectorPosition;
+      
+      if(m_ThicknessPAD[i][j]>0){ //PAD Case
+       DetectorPosition = G4ThreeVector(-BOX_CenterOffset2,-Box_Wafer_Offset.y(),0);
+      }
+      
+      else{ // No Pad Case
+        DetectorPosition = G4ThreeVector(-BOX_CenterOffset1,-Box_Wafer_Offset.y(),0);
+      }
 
       // Distance of the PCB to the target
       G4ThreeVector DetectorSpacing =
         -G4ThreeVector(0, 0,BOX_DetectorSpacing);
 
-      // If a PAD is present, DSSD is not in the center of the Slot:
-      G4ThreeVector PAD_OFFSET=-G4ThreeVector(0.5*PAD_PCB_Thickness,0,0);
-      if(m_ThicknessPAD[i][j]>0) DetectorPosition+=PAD_OFFSET;
       
       DetectorPosition+=DetectorSpacing;
       
-      G4ThreeVector PADDetectorPosition =
-      -PAD_Wafer_Offset+0.5*G4ThreeVector(BOX_PCB_Slot_Border + 0.5*BOX_PCB_Slot_Width -(BOX_PCB_Border_ShortSide - BOX_PCB_Slot_Deepness),0,-BOX_PCB_Thickness-PAD_PCB_Thickness+(BOX_PCB_Slot_Width-BOX_PCB_Thickness));
-      
+      G4ThreeVector PADDetectorPosition = DetectorPosition ;
       G4ThreeVector PADDetectorSpacing =
-      -G4ThreeVector(0, 0,0.5*(PAD_Wafer_Length+(PAD_PCB_Border_ShortSide- BOX_PCB_Slot_Deepness)+BOX_PCB_Slot_Border+BOX_PCB_Slot_Width));
+      -G4ThreeVector(0, 0,0.5*BOX_PCB_Thickness+0.5*PAD_PCB_Thickness);
       
-      if(m_ThicknessPAD[i][j]>0) PADDetectorPosition+=PAD_OFFSET;
       
       PADDetectorPosition+=PADDetectorSpacing;
       
-- 
GitLab