From c255ce23f133c57cc7838e8b287c8f5580f7918c Mon Sep 17 00:00:00 2001
From: matta <matta@npt>
Date: Tue, 18 Jan 2011 21:05:42 +0000
Subject: [PATCH] * Update TMust2Physics  - Change Compare method by ==
 operator in Token Detection  - Change way to make EX and EY match. New
 Methods now use symetric algorithm with respect to X and Y

---
 NPLib/MUST2/TMust2Physics.cxx | 96 +++++++++++++++++++----------------
 NPLib/MUST2/TMust2Physics.h   |  8 +--
 2 files changed, 55 insertions(+), 49 deletions(-)

diff --git a/NPLib/MUST2/TMust2Physics.cxx b/NPLib/MUST2/TMust2Physics.cxx
index 925688215..0042580bf 100644
--- a/NPLib/MUST2/TMust2Physics.cxx
+++ b/NPLib/MUST2/TMust2Physics.cxx
@@ -40,13 +40,14 @@ ClassImp(TMust2Physics)
 ///////////////////////////////////////////////////////////////////////////
 TMust2Physics::TMust2Physics() 
 	{ 
-		EventMultiplicity 	= 0 							;
+		EventMultiplicity 	= 0 							  ;
 		m_EventData 					= new TMust2Data	;
 		m_PreTreatedData			= new TMust2Data	;
 		m_EventPhysics 				= this						;
 		m_NumberOfTelescope		= 0							;
 		m_MaximumStripMultiplicityAllowed = 10;
-		m_StripEnergyMatchingTolerance    = 10;	
+		m_StripEnergyMatchingSigma = 0.020    ; 
+		m_StripEnergyMatchingNumberOfSigma = 3; 
     // Raw Threshold
 		m_Si_X_E_RAW_Threshold = 8200	;
 		m_Si_Y_E_RAW_Threshold = 8200	;
@@ -473,8 +474,14 @@ vector < TVector2 > TMust2Physics :: Match_X_Y()
 										//	if same detector check energy
 										if ( m_PreTreatedData->GetMMStripXEDetectorNbr(i) == m_PreTreatedData->GetMMStripYEDetectorNbr(j) )
 											{
-													//	Look if energy match (within 10%)
-													if( abs((  m_PreTreatedData->GetMMStripXEEnergy(i) - m_PreTreatedData->GetMMStripYEEnergy(j) ) / m_PreTreatedData->GetMMStripXEEnergy(i)) < m_StripEnergyMatchingTolerance/100.	)
+													//	Look if energy match
+													double EX = m_PreTreatedData->GetMMStripXEEnergy(i) ;
+													double EY = m_PreTreatedData->GetMMStripYEEnergy(j) ;
+													double mean = abs( EX - EY ) /2. ;
+													double distX = abs(EX-mean);
+													double distY = abs(EY-mean);
+													
+													if( distX< m_StripEnergyMatchingNumberOfSigma*m_StripEnergyMatchingSigma && distY< m_StripEnergyMatchingNumberOfSigma*m_StripEnergyMatchingSigma )
 														{
 														  // Special Option, if the event is between two CsI cristal, it is rejected.
 														  if(m_Ignore_not_matching_CsI)
@@ -541,8 +548,6 @@ bool TMust2Physics :: IsValidChannel(string DetectorType, int telescope , int ch
 void TMust2Physics::ReadAnalysisConfig()
 {
    bool ReadingStatus = false;
-   bool check_mult    = false;
-   bool check_match   = false;
 
    // path to file
    string FileName = "./configs/ConfigMust2.dat";
@@ -577,21 +582,27 @@ void TMust2Physics::ReadAnalysisConfig()
             AnalysisConfigFile.ignore(numeric_limits<streamsize>::max(), '\n' );
          }
          
-         else if (whatToDo.compare(0, 22, "MAX_STRIP_MULTIPLICITY") == 0) {
-            check_mult = true;
+//         else if (whatToDo.compare(0, 22, "MAX_STRIP_MULTIPLICITY") == 0) {
+           else if (whatToDo=="MAX_STRIP_MULTIPLICITY") { 
             AnalysisConfigFile >> DataBuffer;
             m_MaximumStripMultiplicityAllowed = atoi(DataBuffer.c_str() );
-            cout << "Maximun strip multiplicity= " << m_MaximumStripMultiplicityAllowed << endl;
+            cout << "MAXIMUN STRIP MULTIPLICITY " << m_MaximumStripMultiplicityAllowed << endl;
          }
          
-         else if (whatToDo.compare(0, 31, "STRIP_ENERGY_MATCHING_TOLERANCE") == 0) {
-            check_match = true;
+//         else if (whatToDo.compare(0, 27, "STRIP_ENERGY_MATCHING_SIGMA") == 0) {
+          else if (whatToDo=="STRIP_ENERGY_MATCHING_SIGMA") {
             AnalysisConfigFile >> DataBuffer;
-            m_StripEnergyMatchingTolerance = atoi(DataBuffer.c_str() );
-            cout << "Strip energy matching tolerance= " << m_StripEnergyMatchingTolerance << endl;
+            m_StripEnergyMatchingSigma = atof(DataBuffer.c_str() );
+            cout << "STRIP ENERGY MATCHING SIGMA " << m_StripEnergyMatchingSigma <<endl;
          }
-        
-         else if (whatToDo.compare(0, 11, "DISABLE_ALL") == 0) {
+         
+         else if (whatToDo=="STRIP_ENERGY_MATCHING_NUMBER_OF_SIGMA") {
+            AnalysisConfigFile >> DataBuffer;
+            m_StripEnergyMatchingNumberOfSigma = atoi(DataBuffer.c_str() );
+            cout << "STRIP ENERGY MATCHING NUMBER OF SIGMA " << m_StripEnergyMatchingNumberOfSigma << endl;
+         }
+         
+         else if (whatToDo== "DISABLE_ALL") {
                AnalysisConfigFile >> DataBuffer;
                cout << whatToDo << "  " << DataBuffer << endl;
                int telescope = atoi(DataBuffer.substr(2,1).c_str());
@@ -604,7 +615,7 @@ void TMust2Physics::ReadAnalysisConfig()
                m_CsIChannelStatus[telescope]  = ChannelStatus;
             }
             
-        else if (whatToDo.compare(0, 15, "DISABLE_CHANNEL") == 0) {
+        else if (whatToDo == "DISABLE_CHANNEL") {
            AnalysisConfigFile >> DataBuffer;
            cout << whatToDo << "  " << DataBuffer << endl;
            int telescope = atoi(DataBuffer.substr(2,1).c_str());
@@ -633,91 +644,91 @@ void TMust2Physics::ReadAnalysisConfig()
        
         } 
             
-        else if (whatToDo.compare(0, 8, "TAKE_E_Y") == 0) {
+        else if (whatToDo=="TAKE_E_Y") {
            m_Take_E_Y = true;
            cout << whatToDo << endl;
         } 
         
-        else if (whatToDo.compare(0, 8, "TAKE_T_Y") == 0) {
+        else if (whatToDo=="TAKE_T_Y") {
            m_Take_T_Y = true;
            cout << whatToDo << endl;
         }
         
-        else if (whatToDo.compare(0, 8, "TAKE_E_X") == 0) {
+        else if (whatToDo=="TAKE_E_X") {
            m_Take_E_Y = false;
            cout << whatToDo << endl;
         }
         
-        else if (whatToDo.compare(0, 8, "TAKE_T_X") == 0) {
+        else if (whatToDo=="TAKE_T_X") {
            m_Take_T_Y = false;
            cout << whatToDo << endl;
         }
            
-        else if (whatToDo.compare(0, 23, "IGNORE_NOT_MATCHING_CSI") == 0) {
+        else if (whatToDo== "IGNORE_NOT_MATCHING_CSI") {
            m_Ignore_not_matching_CsI = true;
            cout << whatToDo << endl;
         }
       
-        else if (whatToDo.compare(0, 8, "CSI_SIZE") == 0) {
+        else if (whatToDo=="CSI_SIZE") {
            AnalysisConfigFile >> DataBuffer;
            m_CsI_Size = atoi(DataBuffer.c_str());
            cout << whatToDo << " " << m_CsI_Size << endl;
         }
          
-        else if (whatToDo.compare(0, 24, "IGNORE_NOT_MATCHING_SILI") == 0) {
+        else if (whatToDo=="IGNORE_NOT_MATCHING_SILI") {
            m_Ignore_not_matching_SiLi = true;
            cout << whatToDo << endl;
         }
       
-        else if (whatToDo.compare(0, 9, "SILI_SIZE") == 0) {
+        else if (whatToDo=="SILI_SIZE") {
            AnalysisConfigFile >> DataBuffer;
            m_SiLi_Size = atoi(DataBuffer.c_str());
            cout << whatToDo << " " << m_SiLi_Size << endl;
         }
          
-        else if (whatToDo.compare(0, 20, "SI_X_E_RAW_THRESHOLD") == 0) {
+        else if (whatToDo=="SI_X_E_RAW_THRESHOLD") {
            AnalysisConfigFile >> DataBuffer;
            m_Si_X_E_RAW_Threshold = atoi(DataBuffer.c_str());
            cout << whatToDo << " " << m_Si_X_E_RAW_Threshold << endl;
         }  
          
-        else if (whatToDo.compare(0, 20, "SI_Y_E_RAW_THRESHOLD") == 0) {
+        else if (whatToDo=="SI_Y_E_RAW_THRESHOLD") {
            AnalysisConfigFile >> DataBuffer;
            m_Si_Y_E_RAW_Threshold = atoi(DataBuffer.c_str());
            cout << whatToDo << " " << m_Si_Y_E_RAW_Threshold << endl;
         }
 
-        else if (whatToDo.compare(0, 20, "SILI_E_RAW_THRESHOLD") == 0) {
+        else if (whatToDo=="SILI_E_RAW_THRESHOLD") {
            AnalysisConfigFile >> DataBuffer;
            m_SiLi_E_RAW_Threshold = atoi(DataBuffer.c_str());
            cout << whatToDo << " " << m_SiLi_E_RAW_Threshold << endl;
         }
 
-        else if (whatToDo.compare(0, 19, "CSI_E_RAW_THRESHOLD") == 0) {
+        else if (whatToDo== "CSI_E_RAW_THRESHOLD") {
            AnalysisConfigFile >> DataBuffer;
            m_CsI_E_Threshold = atoi(DataBuffer.c_str());
            cout << whatToDo << " " << m_CsI_E_Threshold << endl;
         }
       
-        else if (whatToDo.compare(0, 16, "SI_X_E_THRESHOLD") == 0) {
+        else if (whatToDo=="SI_X_E_THRESHOLD") {
            AnalysisConfigFile >> DataBuffer;
            m_Si_X_E_Threshold = atoi(DataBuffer.c_str());
            cout << whatToDo << " " << m_Si_X_E_Threshold << endl;
         }  
          
-        else if (whatToDo.compare(0, 16, "SI_Y_E_THRESHOLD") == 0) {
+        else if (whatToDo== "SI_Y_E_THRESHOLD") {
            AnalysisConfigFile >> DataBuffer;
            m_Si_Y_E_Threshold = atoi(DataBuffer.c_str());
            cout << whatToDo << " " << m_Si_Y_E_Threshold << endl;
         }
 
-        else if (whatToDo.compare(0, 16, "SILI_E_THRESHOLD") == 0) {
+        else if (whatToDo=="SILI_E_THRESHOLD") {
            AnalysisConfigFile >> DataBuffer;
            m_SiLi_E_Threshold = atoi(DataBuffer.c_str());
            cout << whatToDo << " " << m_SiLi_E_Threshold << endl;
         }
 
-        else if (whatToDo.compare(0, 15, "CSI_E_THRESHOLD") == 0) {
+        else if (whatToDo=="CSI_E_THRESHOLD") {
            AnalysisConfigFile >> DataBuffer;
            m_CsI_E_Threshold = atoi(DataBuffer.c_str());
            cout << whatToDo << " " << m_CsI_E_Threshold << endl;
@@ -899,7 +910,7 @@ void TMust2Physics::ReadConfiguration(string Path)
       	getline(ConfigFile, LineBuffer);
 
 		//	If line is a Start Up Must2 bloc, Reading toggle to true      
-      	if (LineBuffer.compare(0, 11, "M2Telescope") == 0) 
+      	if (LineBuffer.compare(0, 11, "M2Telescope")==0) 
 	      	{
 	        	 cout << "///" << endl           		;
 	       		  cout << "Telescope found: " << endl   ;        
@@ -922,14 +933,14 @@ void TMust2Physics::ReadConfiguration(string Path)
 						}
 			
 					//	Finding another telescope (safety), toggle out
-				else if (DataBuffer.compare(0, 11, "M2Telescope") == 0) {
+				else if (DataBuffer=="M2Telescope") {
 						cout << "WARNING: Another Telescope is find before standard sequence of Token, Error may occured in Telecope definition" << endl ;
 						ReadingStatus = false ;
 						}
 			
 					//	Position method
 					
-		         else if (DataBuffer.compare(0, 6, "X1_Y1=") == 0) {
+		         else if (DataBuffer=="X1_Y1=") {
 		            check_A = true;
 		            ConfigFile >> DataBuffer ;
 		            Ax = atof(DataBuffer.c_str()) ;
@@ -947,7 +958,7 @@ void TMust2Physics::ReadConfiguration(string Path)
 		         }
 
 
-		         else if (DataBuffer.compare(0, 8, "X128_Y1=") == 0) {
+		         else if (DataBuffer=="X128_Y1=") {
 		            check_B = true;
 		            ConfigFile >> DataBuffer ;
 		            Bx = atof(DataBuffer.c_str()) ;
@@ -965,7 +976,7 @@ void TMust2Physics::ReadConfiguration(string Path)
 		         }
 		         
 
-		         else if (DataBuffer.compare(0, 8, "X1_Y128=") == 0) {
+		         else if (DataBuffer=="X1_Y128=") {
 		            check_C = true;
 		            ConfigFile >> DataBuffer ;
 		            Cx = atof(DataBuffer.c_str()) ;
@@ -982,7 +993,7 @@ void TMust2Physics::ReadConfiguration(string Path)
 		           
 		         }
 
-		         else if (DataBuffer.compare(0, 10, "X128_Y128=") == 0) {
+		         else if (DataBuffer=="X128_Y128=") {
 		            check_D = true;
 		            ConfigFile >> DataBuffer ;
 		            Dx = atof(DataBuffer.c_str()) ;
@@ -1002,7 +1013,7 @@ void TMust2Physics::ReadConfiguration(string Path)
 				//	End Position Method
 
 		         //	Angle method
-		         else if (DataBuffer.compare(0, 6, "THETA=") == 0) {
+		         else if (DataBuffer=="THETA=") {
 		            check_Theta = true;
 		            ConfigFile >> DataBuffer ;
 		            Theta = atof(DataBuffer.c_str()) ;
@@ -1012,7 +1023,7 @@ void TMust2Physics::ReadConfiguration(string Path)
 		         }
 
 		         //Angle method
-		         else if (DataBuffer.compare(0, 4, "PHI=") == 0) {
+		         else if (DataBuffer=="PHI=") {
 		            check_Phi = true;
 		            ConfigFile >> DataBuffer ;
 		            Phi = atof(DataBuffer.c_str()) ;
@@ -1022,7 +1033,7 @@ void TMust2Physics::ReadConfiguration(string Path)
 		         }
 
 		         //Angle method
-		         else if (DataBuffer.compare(0, 2, "R=") == 0) {
+		         else if (DataBuffer=="R=") {
 		            check_R = true;
 		            ConfigFile >> DataBuffer ;
 		            R = atof(DataBuffer.c_str()) ;
@@ -1032,7 +1043,7 @@ void TMust2Physics::ReadConfiguration(string Path)
 		         }
 
 		         //Angle method
-		         else if (DataBuffer.compare(0, 5, "BETA=") == 0) {
+		         else if (DataBuffer=="BETA=") {
 		            check_beta = true;
 		            ConfigFile >> DataBuffer ;
 		            beta_u = atof(DataBuffer.c_str()) ;
@@ -1240,7 +1251,6 @@ void TMust2Physics::InitializeStandardParameter()
 			
 			
 		m_MaximumStripMultiplicityAllowed = m_NumberOfTelescope	;
-		m_StripEnergyMatchingTolerance    = 10 								;	// %	
 		
 		return;
 	}	
diff --git a/NPLib/MUST2/TMust2Physics.h b/NPLib/MUST2/TMust2Physics.h
index 8dee6a763..1e3394097 100644
--- a/NPLib/MUST2/TMust2Physics.h
+++ b/NPLib/MUST2/TMust2Physics.h
@@ -184,7 +184,8 @@ class TMust2Physics : public TObject, public NPA::VDetector
 		//	Event over this value after pre-treatment are not treated / avoid long treatment time on spurious event	
 			int m_MaximumStripMultiplicityAllowed  ;//!
 		//	Give the allowance in percent of the difference in energy between X and Y
-			double m_StripEnergyMatchingTolerance  ; //!
+			double m_StripEnergyMatchingSigma  ; //!
+			double m_StripEnergyMatchingNumberOfSigma  ; //!
 			
 		// Raw Threshold
 		int m_Si_X_E_RAW_Threshold ;//!
@@ -244,11 +245,6 @@ class TMust2Physics : public TObject, public NPA::VDetector
 
 namespace MUST2_LOCAL
 	{
-		//	Threshold
-//		const double Si_X_E_Threshold = 0	;
-//		const double Si_Y_E_Threshold = 0	;
-//		const double SiLi_E_Threshold = 0	;
-//		const double CsI_E_Threshold	= 0 ;
 
 		//	tranform an integer to a string
 		string itoa(int value);
-- 
GitLab