From a0bdc34c5668f7c574e6a33fd1c1bc7832eb6d33 Mon Sep 17 00:00:00 2001
From: Nicolas de Sereville <deserevi@ipno.in2p3.fr>
Date: Tue, 9 Dec 2014 13:12:04 +0100
Subject: [PATCH] + Fix minor compilation bugs in NPL for new version of Paris 
  detector

+ ongoing work for adapting GaspardTrackerAnnular to the new
  scorer scheme
---
 .../DetectorConfiguration/gaspHyde.detector   |  20 +-
 NPLib/Paris/TParisPhysics.cxx                 |   1 +
 NPLib/VDetector/DetectorManager.cxx           |   4 +-
 NPSimulation/GASPARD/GaspardTrackerAnnular.cc | 192 +++++++++++++++++-
 NPSimulation/GASPARD/GaspardTrackerAnnular.hh |   3 +
 5 files changed, 199 insertions(+), 21 deletions(-)

diff --git a/Inputs/DetectorConfiguration/gaspHyde.detector b/Inputs/DetectorConfiguration/gaspHyde.detector
index 3a33e3f52..18ca64d39 100644
--- a/Inputs/DetectorConfiguration/gaspHyde.detector
+++ b/Inputs/DetectorConfiguration/gaspHyde.detector
@@ -28,7 +28,7 @@ Target
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
 GaspardTracker
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1 Annular Back
-%GPDAnnular
+GPDAnnular
         Z=      -156.5
         RMIN=   16
         RMAX=	52
@@ -37,7 +37,7 @@ GaspardTracker
         THIRDSTAGE= 1
         VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1 Annular Front
-%GPDAnnular
+GPDAnnular
         Z=      156.5
         RMIN=	16
         RMAX=	52
@@ -206,7 +206,7 @@ GaspardTracker
         THIRDSTAGE= 1
         VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1 Barrel
-GPDSquare
+%GPDSquare
         X1_Y1=          142.516	 49.00  -49.00
         X128_Y1=        142.516  49.00   49.00
         X1_Y128=        142.516 -49.00  -49.00
@@ -216,7 +216,7 @@ GPDSquare
         THIRDSTAGE= 1
         VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2
-GPDSquare
+%GPDSquare
         X1_Y1=           66.125	135.422  -49.00
         X128_Y1=         66.125 135.422   49.00
         X1_Y128=        135.422  66.126  -49.00
@@ -226,7 +226,7 @@ GPDSquare
         THIRDSTAGE= 1
         VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%3
-GPDSquare
+%GPDSquare
         X1_Y1=          -49.00	142.516  -49.00
         X128_Y1=        -49.00  142.516   49.00
         X1_Y128=         49.00  142.516  -49.00
@@ -236,7 +236,7 @@ GPDSquare
         THIRDSTAGE= 1
         VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%4
-GPDSquare
+%GPDSquare
         X1_Y1=         -135.422	 66.125  -49.00
         X128_Y1=       -135.422  66.125   49.00
         X1_Y128=        -66.126 135.422  -49.00
@@ -246,7 +246,7 @@ GPDSquare
         THIRDSTAGE= 1
         VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
-GPDSquare
+%GPDSquare
         X1_Y1=          -142.516 -49.00  -49.00
         X128_Y1=        -142.516 -49.00   49.00
         X1_Y128=        -142.516  49.00  -49.00
@@ -256,7 +256,7 @@ GPDSquare
         THIRDSTAGE= 1
         VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%6
-GPDSquare
+%GPDSquare
         X1_Y1=           -66.125 -135.422  -49.00
         X128_Y1=         -66.125 -135.422   49.00
         X1_Y128=        -135.422  -66.126  -49.00
@@ -266,7 +266,7 @@ GPDSquare
         THIRDSTAGE= 1
         VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%7
-GPDSquare
+%GPDSquare
         X1_Y1=           49.00 -142.516  -49.00
         X128_Y1=         49.00 -142.516   49.00
         X1_Y128=        -49.00 -142.516  -49.00
@@ -276,7 +276,7 @@ GPDSquare
         THIRDSTAGE= 1
         VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%8
-GPDSquare
+%GPDSquare
         X1_Y1=          135.422	 -66.125  -49.00
         X128_Y1=        135.422  -66.125   49.00
         X1_Y128=         66.126 -135.422  -49.00
diff --git a/NPLib/Paris/TParisPhysics.cxx b/NPLib/Paris/TParisPhysics.cxx
index 78625989f..9b6c90184 100644
--- a/NPLib/Paris/TParisPhysics.cxx
+++ b/NPLib/Paris/TParisPhysics.cxx
@@ -32,6 +32,7 @@
 #include <fstream>
 #include <cstdlib>
 #include <limits>
+#include <cmath>
 
 // Root
 #include "TChain.h"
diff --git a/NPLib/VDetector/DetectorManager.cxx b/NPLib/VDetector/DetectorManager.cxx
index f6c99e03e..8127a9891 100644
--- a/NPLib/VDetector/DetectorManager.cxx
+++ b/NPLib/VDetector/DetectorManager.cxx
@@ -31,7 +31,7 @@
 #include "../DetectorList.inc"
 #include "GaspardTracker.h"
 #include "Hyde2Tracker.h"
-#include "Paris.h"
+#include "TParisPhysics.h"
 #include "Shield.h"
 #include "Fatima.h"
 #include "TAnnularS1Physics.h"
@@ -398,7 +398,7 @@ void DetectorManager::ReadConfigurationFile(string Path)   {
       cout << "//////// Paris ////////" << endl << endl;
 
       // Instantiate the new array as a VDetector Object
-      VDetector* myDetector = new Paris();
+      VDetector* myDetector = new TParisPhysics();
       // Read Position of Telescope
       ConfigFile.close();
       myDetector->ReadConfiguration(Path);
diff --git a/NPSimulation/GASPARD/GaspardTrackerAnnular.cc b/NPSimulation/GASPARD/GaspardTrackerAnnular.cc
index d0a32c047..3aa1a3790 100644
--- a/NPSimulation/GASPARD/GaspardTrackerAnnular.cc
+++ b/NPSimulation/GASPARD/GaspardTrackerAnnular.cc
@@ -50,6 +50,7 @@
 #include "GaspardTrackerAnnular.hh"
 #include "ObsoleteGeneralScorers.hh"
 #include "GaspardScorers.hh"
+#include "SiliconScorers.hh"
 #include "TGaspardTrackerData.h"
 #include "RootOutput.h"
 #include "VDetector.hh"
@@ -423,6 +424,137 @@ void GaspardTrackerAnnular::SetInterCoordPointer(TInteractionCoordinates* interC
 // Called at in the EventAction::EndOfEventAvtion
 void GaspardTrackerAnnular::ReadSensitive(const G4Event* event)
 {
+   //////////////
+   // First stage
+   G4THitsMap<G4double*>* GPD1HitMap;
+   std::map<G4int, G4double**>::iterator GPD1_itr;
+
+   G4int GPD1CollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("FirstStageScorerGPDAnnular/GPDAnnularFirstStage");
+   GPD1HitMap = (G4THitsMap<G4double*>*)(event->GetHCofThisEvent()->GetHC(GPD1CollectionID));
+
+   // Loop on the GPD map
+   for (GPD1_itr = GPD1HitMap->GetMap()->begin(); GPD1_itr != GPD1HitMap->GetMap()->end(); GPD1_itr++) {
+      G4double* Info = *(GPD1_itr->second);
+
+      double Energy = Info[0];
+      if (Energy > EnergyThreshold) {
+         double Time       = Info[1];
+         int DetNbr        = (int) Info[7];
+         int StripFront    = (int) Info[8];
+         int StripBack     = (int) Info[9];
+
+         // detector number
+         ms_Event->SetGPDTrkFirstStageFrontEDetectorNbr(m_index["Annular"] + DetNbr);
+         ms_Event->SetGPDTrkFirstStageFrontTDetectorNbr(m_index["Annular"] + DetNbr);
+         ms_Event->SetGPDTrkFirstStageBackEDetectorNbr(m_index["Annular"] + DetNbr);
+         ms_Event->SetGPDTrkFirstStageBackTDetectorNbr(m_index["Annular"] + DetNbr);
+
+         // energy
+         ms_Event->SetGPDTrkFirstStageFrontEEnergy(RandGauss::shoot(Energy, ResoFirstStage));
+         ms_Event->SetGPDTrkFirstStageBackEEnergy(RandGauss::shoot(Energy, ResoFirstStage));
+
+         // time
+         Time = RandGauss::shoot(Time, ResoTimePPAC);
+         ms_Event->SetGPDTrkFirstStageFrontTTime(RandGauss::shoot(Time, ResoTimeGpd));
+         ms_Event->SetGPDTrkFirstStageBackTTime(RandGauss::shoot(Time, ResoTimeGpd));
+
+         // strips X and Y
+         ms_Event->SetGPDTrkFirstStageFrontEStripNbr(StripFront);
+         ms_Event->SetGPDTrkFirstStageFrontTStripNbr(StripFront);
+         ms_Event->SetGPDTrkFirstStageBackEStripNbr(StripBack);
+         ms_Event->SetGPDTrkFirstStageBackTStripNbr(StripBack);
+
+         // Interaction 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
+   GPD1HitMap->clear();
+
+
+   //////////////
+   // Second stage
+   G4THitsMap<G4double*>* GPD2HitMap;
+   std::map<G4int, G4double**>::iterator GPD2_itr;
+
+   G4int GPD2CollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("SecondStageScorerGPDAnnular/GPDAnnularSecondStage");
+   GPD2HitMap = (G4THitsMap<G4double*>*)(event->GetHCofThisEvent()->GetHC(GPD2CollectionID));
+
+   // Loop on the GPD map
+   for (GPD2_itr = GPD2HitMap->GetMap()->begin(); GPD2_itr != GPD2HitMap->GetMap()->end(); GPD2_itr++) {
+      G4double* Info = *(GPD2_itr->second);
+
+      double Energy = Info[0];
+      if (Energy > EnergyThreshold) {
+         double Time       = Info[1];
+         int DetNbr        = (int) Info[7];
+         int StripFront    = (int) Info[8];
+
+         // detector number
+         ms_Event->SetGPDTrkSecondStageEDetectorNbr(m_index["Annular"] + DetNbr);
+         ms_Event->SetGPDTrkSecondStageTDetectorNbr(m_index["Annular"] + DetNbr);
+
+         // energy
+         ms_Event->SetGPDTrkSecondStageEEnergy(RandGauss::shoot(Energy, ResoSecondStage));
+
+         // time
+         Time = RandGauss::shoot(Time, ResoTimePPAC);
+         ms_Event->SetGPDTrkSecondStageTTime(RandGauss::shoot(Time, ResoTimeGpd));
+
+         // strips X and Y
+         ms_Event->SetGPDTrkSecondStageEPadNbr(StripFront);
+         ms_Event->SetGPDTrkSecondStageTPadNbr(StripFront);
+      }
+   }
+   // clear map for next event
+   GPD2HitMap->clear();
+
+
+   //////////////
+   // Third stage
+   G4THitsMap<G4double*>* GPD3HitMap;
+   std::map<G4int, G4double**>::iterator GPD3_itr;
+
+   G4int GPD3CollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("ThirdStageScorerGPDAnnular/GPDAnnularThirdStage");
+   GPD3HitMap = (G4THitsMap<G4double*>*)(event->GetHCofThisEvent()->GetHC(GPD3CollectionID));
+
+   // Loop on the GPD map
+   for (GPD3_itr = GPD3HitMap->GetMap()->begin(); GPD3_itr != GPD3HitMap->GetMap()->end(); GPD3_itr++) {
+      G4double* Info = *(GPD3_itr->second);
+
+      double Energy = Info[0];
+      if (Energy > EnergyThreshold) {
+         double Time       = Info[1];
+         int DetNbr        = (int) Info[7];
+         int StripFront    = (int) Info[8];
+
+         // detector number
+         ms_Event->SetGPDTrkThirdStageEDetectorNbr(m_index["Annular"] + DetNbr);
+         ms_Event->SetGPDTrkThirdStageTDetectorNbr(m_index["Annular"] + DetNbr);
+
+         // energy
+         ms_Event->SetGPDTrkThirdStageEEnergy(RandGauss::shoot(Energy, ResoThirdStage));
+
+         // time
+         Time = RandGauss::shoot(Time, ResoTimePPAC);
+         ms_Event->SetGPDTrkThirdStageTTime(RandGauss::shoot(Time, ResoTimeGpd));
+
+         // strips X and Y
+         ms_Event->SetGPDTrkThirdStageEPadNbr(StripFront);
+         ms_Event->SetGPDTrkThirdStageTPadNbr(StripFront);
+      }
+   }
+   // clear map for next event
+   GPD3HitMap->clear();
+
+
+/*
+
    //////////////////////////////////////////////////////////////////////////////////////
    //////////////////////// Used to Read Event Map of detector //////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////
@@ -704,20 +836,62 @@ void GaspardTrackerAnnular::ReadSensitive(const G4Event* event)
    AngPhiHitMap            -> clear();
    SecondStageEnergyHitMap -> clear();
    ThirdStageEnergyHitMap  -> clear();
+*/
 }
 
 
 
 void GaspardTrackerAnnular::InitializeScorers()
 {
-   bool already_exist = false;
-   m_FirstStageScorer = VDetector::CheckScorer("FirstStageScorerGPDAnnular", already_exist);
-   m_SecondStageScorer = VDetector::CheckScorer("SecondStageScorerGPDAnnular",already_exist);
-   m_ThirdStageScorer = VDetector::CheckScorer("ThirdStageScorerGPDAnnular",already_exist);
-   if(already_exist) return;
-
-
-
+   // check whether scorers are already defined
+   bool already_exist  = false;
+   m_FirstStageScorer  = VDetector::CheckScorer("FirstStageScorerGPDAnnular",  already_exist);
+   m_SecondStageScorer = VDetector::CheckScorer("SecondStageScorerGPDAnnular", already_exist);
+   m_ThirdStageScorer  = VDetector::CheckScorer("ThirdStageScorerGPDAnnular",  already_exist);
+   if (already_exist) return;
+
+
+   // First stage scorer
+   G4VPrimitiveScorer* GPDScorerFirstStage =
+      new SILICONSCORERS::PS_Silicon_Annular("GPDAnnularFirstStage",
+                                             FirstStageRmin,
+                                             FirstStageRmax,
+                                             0*deg,
+                                             360*deg,
+                                             NbThetaStrips,
+                                             NbPhiStrips,
+                                             NbThetaQuadrant);
+
+   // Second stage scorer
+   G4VPrimitiveScorer* GPDScorerSecondStage =
+      new SILICONSCORERS::PS_Silicon_Annular("GPDAnnularSecondStage",
+                                             FirstStageRmin,
+                                             FirstStageRmax,
+                                             0*deg,
+                                             360*deg,
+                                             1,
+                                             1,
+                                             1);
+
+   // Third stage scorer
+   G4VPrimitiveScorer* GPDScorerThirdStage =
+      new SILICONSCORERS::PS_Silicon_Annular("GPDAnnularThirdStage",
+                                             FirstStageRmin,
+                                             FirstStageRmax,
+                                             0*deg,
+                                             360*deg,
+                                             1,
+                                             1,
+                                             1);
+
+   // register scorers to the multifunctionnal detector
+   m_FirstStageScorer  ->RegisterPrimitive(GPDScorerFirstStage);
+   m_SecondStageScorer ->RegisterPrimitive(GPDScorerSecondStage);
+   m_ThirdStageScorer  ->RegisterPrimitive(GPDScorerThirdStage);
+
+
+
+/*
    // First stage Associate Scorer
    G4VPrimitiveScorer* DetNbr                           = new OBSOLETEGENERALSCORERS::PSDetectorNumber("DetectorNumber", "GPDAnnular", 0);
    G4VPrimitiveScorer* TOF                              = new OBSOLETEGENERALSCORERS::PSTOF("StripTime","GPDAnnular", 0);
@@ -749,7 +923,7 @@ void GaspardTrackerAnnular::InitializeScorers()
    //  Third stage Associate Scorer 
    G4VPrimitiveScorer* ThirdStageEnergy = new GPDScorerThirdStageEnergy("ThirdStageEnergy", "GPDAnnular", 0);
    m_ThirdStageScorer->RegisterPrimitive(ThirdStageEnergy);
-
+*/
    //  Add All Scorer to the Global Scorer Manager
    G4SDManager::GetSDMpointer()->AddNewDetector(m_FirstStageScorer);
    G4SDManager::GetSDMpointer()->AddNewDetector(m_SecondStageScorer);
diff --git a/NPSimulation/GASPARD/GaspardTrackerAnnular.hh b/NPSimulation/GASPARD/GaspardTrackerAnnular.hh
index e48f44e7b..0d2564524 100644
--- a/NPSimulation/GASPARD/GaspardTrackerAnnular.hh
+++ b/NPSimulation/GASPARD/GaspardTrackerAnnular.hh
@@ -128,6 +128,9 @@ namespace GPDANNULAR
    const G4double ResoTimeGpd     = 0.212765957    ;// = 500ps                 //   Unit is  ns/2.35
    const G4double ResoTimePPAC    = 0.106382979    ;// = 250ps                 //   Unit is  ns/2.35
 
+   // Threshold
+   const G4double EnergyThreshold = 0.2*MeV;
+
    // Geometry
    const G4double Rmin   = 15*mm;
    const G4double Rmax   = 55*mm;
-- 
GitLab