From be0ba532a556e1b7ff9103f6dc5634f988c2ff17 Mon Sep 17 00:00:00 2001
From: moukaddam <mhd.moukaddam@gmail.com>
Date: Fri, 12 May 2017 14:01:13 +0100
Subject: [PATCH] Adding a configuration token for randomising raw data if
 needed (time and energy), Default is NOT to randomise

---
 NPLib/Detectors/GeTAMU/TGeTAMUPhysics.cxx | 28 ++++++++++++++++-------
 NPLib/Detectors/GeTAMU/TGeTAMUPhysics.h   |  1 +
 Projects/T40/configs/ConfigGeTamu.dat     |  6 +++--
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/NPLib/Detectors/GeTAMU/TGeTAMUPhysics.cxx b/NPLib/Detectors/GeTAMU/TGeTAMUPhysics.cxx
index af4be89d7..9022d51b5 100644
--- a/NPLib/Detectors/GeTAMU/TGeTAMUPhysics.cxx
+++ b/NPLib/Detectors/GeTAMU/TGeTAMUPhysics.cxx
@@ -25,10 +25,8 @@
 #include <limits>
 using namespace std;
 
-#include "TGeTAMUPhysics.h"
-#include "TRandom.h"
-
 //   NPL
+#include "TGeTAMUPhysics.h"
 #include "RootInput.h"
 #include "NPDetectorFactory.h"
 #include "RootOutput.h"
@@ -41,7 +39,7 @@ using namespace NPUNITS;
 #include "TChain.h"
 #include "TRandom3.h"
 
-TRandom *Random = new TRandom3();
+TRandom3 *Random = new TRandom3();
 ///////////////////////////////////////////////////////////////////////////
 
 ClassImp(TGeTAMUPhysics)
@@ -205,6 +203,12 @@ void TGeTAMUPhysics::ReadAnalysisConfig(){
         cout << whatToDo << " " << m_Seg_E_Threshold << endl;
       }
 
+      else if (whatToDo== "ADC_RANDOM_BIN") {
+        AnalysisConfigFile >> DataBuffer;
+        m_ADCRandomBinIsSet  = true ; 
+        cout << whatToDo << " " << m_ADCRandomBinIsSet << endl;
+      }
+
       else {
         ReadingStatus = false;
       }
@@ -372,7 +376,9 @@ for(unsigned int i = 0 ; i < mysizeE ; i++){
   }
   if(Eraw>=m_Cry_E_Raw_Threshold && IsValidChannel(0, clover, crystal)){
     name = "GETAMU/D"+ NPL::itoa(clover)+"_CRY"+ NPL::itoa(crystal);
-    Energy =  cal->ApplyCalibration(name+"_E", Eraw+Random->Rndm());
+    if(m_ADCRandomBinIsSet) 
+      Eraw += Random->Rndm();
+    Energy =  cal->ApplyCalibration(name+"_E", Eraw);
     if(Energy>=m_Cry_E_Threshold){
       Singles_CloverMap_CryEN[clover].push_back(crystal);
       Singles_CloverMap_CryE[clover].push_back(Energy);
@@ -389,7 +395,9 @@ for(unsigned int i = 0 ; i < mysizeE ; i++){
       clover = m_EventData->GetCoreCloverNbrT(i);
       crystal = m_EventData->GetCoreCrystalNbrT(i);
       name = "GETAMU/D"+ NPL::itoa(clover)+"_CRY"+ NPL::itoa(crystal);
-      Time =  cal->ApplyCalibration(name+"_T", Traw+Random->Rndm());
+      if(m_ADCRandomBinIsSet) 
+        Traw += Random->Rndm();
+      Time =  cal->ApplyCalibration(name+"_T", Traw);
       Singles_CloverMap_CryTN[clover].push_back(crystal);
       Singles_CloverMap_CryT[clover].push_back(Time);
       m_PreTreatedData->SetCoreT(clover,crystal,Time);
@@ -415,7 +423,9 @@ for(unsigned int i = 0 ; i < mysizeE ; i++){
   }
   if(Eraw>=m_Seg_E_Raw_Threshold && IsValidChannel(1, clover, segment)){
     name = "GETAMU/D"+ NPL::itoa(clover)+"_SEG"+ NPL::itoa(segment);
-    Energy =  cal->ApplyCalibration(name+"_E", Eraw+Random->Rndm());
+    if(m_ADCRandomBinIsSet) 
+      Eraw += Random->Rndm();
+    Energy =  cal->ApplyCalibration(name+"_E", Eraw);
     if(Energy>=m_Seg_E_Threshold){
       Singles_CloverMap_SegEN[clover].push_back(segment);
       Singles_CloverMap_SegE[clover].push_back(Energy);
@@ -431,7 +441,9 @@ for(unsigned int i = 0 ; i < mysizeE ; i++){
       clover = m_EventData->GetSegmentCloverNbrT(i);
       segment = m_EventData->GetSegmentSegmentNbrT(i);
       name = "GETAMU/D"+ NPL::itoa(clover)+"_SEG"+ NPL::itoa(segment);
-      Time =  cal->ApplyCalibration(name+"_T", Traw+Random->Rndm());
+      if(m_ADCRandomBinIsSet) 
+        Traw += Random->Rndm();
+      Time =  cal->ApplyCalibration(name+"_T", Traw);
       Singles_CloverMap_CryTN[clover].push_back(segment);
       Singles_CloverMap_CryT[clover].push_back(Time);
       m_PreTreatedData->SetSegmentT(clover,segment,Time);
diff --git a/NPLib/Detectors/GeTAMU/TGeTAMUPhysics.h b/NPLib/Detectors/GeTAMU/TGeTAMUPhysics.h
index adcbfdd5a..4608cbf99 100644
--- a/NPLib/Detectors/GeTAMU/TGeTAMUPhysics.h
+++ b/NPLib/Detectors/GeTAMU/TGeTAMUPhysics.h
@@ -143,6 +143,7 @@ class TGeTAMUPhysics :  public TObject, public NPL::VDetector{
     int m_AddBackMode; 
     bool m_LowGainCryIsSet; 
     bool m_LowGainSegIsSet; 
+    bool m_ADCRandomBinIsSet; //Randomise the raw energy in the Raw data within a bin
  
   private: // use for anlysis
     TLorentzVector m_GammaLV; //!
diff --git a/Projects/T40/configs/ConfigGeTamu.dat b/Projects/T40/configs/ConfigGeTamu.dat
index 2f3d54427..92af59610 100644
--- a/Projects/T40/configs/ConfigGeTamu.dat
+++ b/Projects/T40/configs/ConfigGeTamu.dat
@@ -1,7 +1,7 @@
 ConfigGeTamu
   %%%%%%%% Default is high energy 
-  LOW_GAIN_ENERGY_CRY
-  LOW_GAIN_ENERGY_SEG
+  %LOW_GAIN_ENERGY_CRY
+  %LOW_GAIN_ENERGY_SEG
 	%%%%%%%% Defective channels 
 	%DISABLE_ALL     CLOVER04
 	%DISABLE_CHANNEL CLOVER01_SEG01
@@ -14,3 +14,5 @@ ConfigGeTamu
   ADD_BACK_CLOVER
   %ADD_BACK_ARRAY
   %ADD_BACK_FACING
+  %%%%%%%% Randomise raw energy within ADC bin
+  %ADC_RANDOM_BIN
-- 
GitLab