From b4a5a260295ec52a10016bbf576b1de3229bee5c Mon Sep 17 00:00:00 2001
From: "theodore.efremov" <theodore.efremov@cea.fr>
Date: Wed, 11 Dec 2024 13:48:35 +0100
Subject: [PATCH] Just fastforwarding local minor changes

---
 Projects/AlPhaPha/2024/Analysis.cxx           |   1 +
 .../chio/XYCalibration/VerifCorrelation.C     | 101 ++++++++++++++++++
 .../2024/macro/chio/YCalibration/DECorr.C     |  30 ++++--
 .../YCalibration/{Legacy => }/PlotOnline.C    |   8 +-
 .../macro/chio/YCalibration/SplineChioP2P.C   |  10 +-
 .../2024/macro/mwpc/Toff/ToffGenerator.cxx    |   7 +-
 Projects/AlPhaPha/conversion/2024/convert.C   |   7 +-
 Projects/AlPhaPha/conversion/2024/convert.h   |   2 +-
 8 files changed, 143 insertions(+), 23 deletions(-)
 create mode 100644 Projects/AlPhaPha/2024/macro/chio/XYCalibration/VerifCorrelation.C
 rename Projects/AlPhaPha/2024/macro/chio/YCalibration/{Legacy => }/PlotOnline.C (52%)

diff --git a/Projects/AlPhaPha/2024/Analysis.cxx b/Projects/AlPhaPha/2024/Analysis.cxx
index 32f574f80..8e25260c2 100644
--- a/Projects/AlPhaPha/2024/Analysis.cxx
+++ b/Projects/AlPhaPha/2024/Analysis.cxx
@@ -482,6 +482,7 @@ void Analysis::VamosAnalysis(){
             FF_Y1  = FPMW->PositionY[0];
             FF_Y3  = FPMW->PositionY[2];
 
+            //FF_IC_Y = FPMW->Yf + (1442.6+6774.4-7600)*tan(FPMW->Phif/1000);
             FF_IC_Y = FPMW->Yf + (1442.6+6774.4-7600)*tan(FPMW->Phif/1000);
             FF_IC_X = FPMW->Xf + (1442.6+6774.4-7600)*tan(FPMW->Thetaf/1000);
 
diff --git a/Projects/AlPhaPha/2024/macro/chio/XYCalibration/VerifCorrelation.C b/Projects/AlPhaPha/2024/macro/chio/XYCalibration/VerifCorrelation.C
new file mode 100644
index 000000000..c386bbdcb
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/XYCalibration/VerifCorrelation.C
@@ -0,0 +1,101 @@
+#include "TICPhysics.h"
+#include "TTimeData.h"
+#include <TChain.h>
+#include <TH2.h>
+#include <TH3.h>
+
+vector<double> TxtToVector(const char *Path);
+
+void VerifCorrelation(){
+
+    //===========================================================================================================
+    //                           Loading var
+    //===========================================================================================================
+    TChain* chain = new TChain("PhysicsTree");
+    chain->Add("../../../root/analysis/VamosCalib247.root");
+
+    TTimeData *Time = new TTimeData();
+    TICPhysics* IC = new TICPhysics() ;
+    double FF_IC_X, FF_IC_Y, FF_V13, FF_DriftTime;
+
+  
+    vector<double> Toff13 , Toff14, Toff23, Toff24;
+    const char* Path13 = "../../../mwpc/Toff/output/Toff13.txt";
+    const char* Path14 = "../../../mwpc/Toff/output/Toff14.txt";
+    const char* Path23 = "../../../mwpc/Toff/output/Toff23.txt";
+    const char* Path24 = "../../../mwpc/Toff/output/Toff24.txt";
+
+    Toff13 = TxtToVector(Path13);
+    Toff14 = TxtToVector(Path14);
+    Toff23 = TxtToVector(Path23);
+    Toff24 = TxtToVector(Path24);
+
+
+    chain->SetBranchStatus("FF_IC_X", true);
+    chain->SetBranchAddress("FF_IC_X", &FF_IC_X);
+    chain->SetBranchStatus("FF_IC_Y", true);
+    chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
+
+    chain->SetBranchStatus("IC", true);
+    chain->SetBranchAddress("IC", &IC);
+
+    chain->SetBranchStatus("Time", true);
+    chain->SetBranchAddress("Time", &Time);
+
+    
+    TH2F *ICXY = new TH2F("ICXY","ICXY",1000,-1000,1000,1000,-1000,1000);
+ 
+    int Nentries = chain->GetEntries();
+    //int Nentries = 1000000;
+    auto start = std::chrono::high_resolution_clock::now();
+
+    for (int e = 0; e < Nentries; e++) {
+        if (e % 100000  == 0 && e > 0 ) {
+            auto now = std::chrono::high_resolution_clock::now();
+            std::chrono::duration<double> elapsed = now - start;
+            double avgTimePerIteration = elapsed.count() / e;
+            double timeLeft = avgTimePerIteration * (Nentries - e);
+
+            std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
+        }
+
+        chain->GetEntry(e);
+
+
+        if(Time->GetMWPC13Mult()==1 && IC->fIC_raw[8] >0){
+            UShort_t FPMW_Section = Time->GetSection_MWPC3(0);
+            FF_DriftTime = 10* (IC->fIC_TS.at(0) - Time->GetTS_MWPC13(0)) - ((Time->GetTime_MWPC13(0)+Toff13.at(FPMW_Section))) ;
+
+
+            double ICRatio =  IC->fIC_raw[0]/IC->fIC_raw[1];
+
+            if(IC->fIC_raw[8] >0 ) {
+                ICXY->Fill(FF_IC_X,FF_IC_Y,ICRatio);
+            }
+        }
+    }
+    TCanvas *c = new TCanvas("c","c");
+    ICXY->SetMinimum(0);
+    ICXY->Draw("surf");
+}
+
+vector<double> TxtToVector(const char *Path){
+    string line;
+    vector<double> values;
+    ifstream file(Path); 
+
+    if (file.is_open()) {
+        while (std::getline(file, line)) {
+            try {
+                values.push_back(std::stod(line));
+            } catch (const std::invalid_argument& e) {
+                std::cerr << "Invalid number in line: " << line << '\n';
+            }
+        }
+        file.close();
+    } else {
+        std::cerr << "Error opening file.\n";
+    }
+
+    return values;
+}
diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/DECorr.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/DECorr.C
index 5e6eb7d3e..2b4463b21 100644
--- a/Projects/AlPhaPha/2024/macro/chio/YCalibration/DECorr.C
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/DECorr.C
@@ -201,8 +201,8 @@ void DECorr(bool cut = false, bool spline = false) {
         double IC1corr = (IC->fIC_raw[1]*(1-0.000686068*FF_IC_Y))*(1-4.88238e-05*FF_IC_Y+7.40395e-06*FF_IC_Y*FF_IC_Y);
         double DE_Bis = 0.5*(IC1corr+IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
 
-        DE = 0.5*(ICcorr_Y.at(0)+ IC->fIC_raw[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
-        DE_splined = 0.5*(ICcorr_Y[0]+ ICcorr_Y[1] +ICcorr_Y[2]+ICcorr_Y[3])+ICcorr_Y[4];
+        DE = 0.5*(IC->fIC_raw[0]+ IC->fIC_raw[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+        DE_splined = 0.5*(ICcorr_Y[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
         //DE_splined = 0.5*( ICcorr_Y[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
         
 
@@ -222,7 +222,7 @@ void DECorr(bool cut = false, bool spline = false) {
             hDE_E_splined->Fill(E,DE_splined);
             hDE_Ebis->Fill(E,DE_Bis);
 
-            hDE_V->Fill(FF_V13,DE_splined);    
+            hDE_V->Fill(FF_V13,DE);    
 
             //******* Coor DE ************
             if (spline== true  ){     
@@ -248,23 +248,33 @@ void DECorr(bool cut = false, bool spline = false) {
                 hDE_Ebis_corr->Fill(E,DE_Ybis);  
             }
 
-            bool CutCharge =  CutZ->IsInside(FF_V13,DE_splined);
+            bool CutCharge;
+            if (cut == true) {
+                CutCharge   =  CutZ->IsInside(FF_V13,DE);
+            }
             //bool CutChargeBis =  CutZ->IsInside(E,DE_Y_Recur);
             //bool CutVbis =  CutZbis->IsInside(E,DE_Bis);
             // DE_Y in a cut
             
             hDE_Y_corr_nocut->Fill(FF_IC_Y,DE);
             hDE_Y_splined_nocut->Fill(FF_IC_Y,DE_splined);
-            if (cut == true && CutV && CutCharge) {
-               
+            if (cut == true ) {
+                if (CutV && CutCharge){ 
+                    hDE_Y->Fill(FF_IC_Y,DE);
+                    hDE_Y_splined->Fill(FF_IC_Y,DE_splined); 
+                    hDE_Y_corr->Fill(FF_IC_Y,DE_corr);
+
+                    hIC_Y->Fill(FF_IC_Y,IC->fIC_raw[1]);
+                    hIC_Y_splined->Fill(FF_IC_Y,ICcorr_Y.at(1));
+                }
+            }//end cut
+            else {
                 hDE_Y->Fill(FF_IC_Y,DE);
                 hDE_Y_splined->Fill(FF_IC_Y,DE_splined); 
                 hDE_Y_corr->Fill(FF_IC_Y,DE_corr);
 
                 hIC_Y->Fill(FF_IC_Y,IC->fIC_raw[1]);
-                hIC_Y_splined->Fill(FF_IC_Y,ICcorr_Y.at(1));
-            }//end cut
-            else {;}
+                hIC_Y_splined->Fill(FF_IC_Y,ICcorr_Y.at(1));}
 
             if (cut == true && CutVbis) {
                 hDE_Y_bis->Fill(FF_IC_Y,DE_Bis);
@@ -313,7 +323,7 @@ void DECorr(bool cut = false, bool spline = false) {
     hDE_Y_splined_nocut->ProfileX()->Draw();
     c4->cd(2);
     hDE_Y_corr_nocut->ProfileX()->Draw();
-    
+
 
 
     TCanvas *c1 = new TCanvas("c1","c1",1500,1000);
diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/Legacy/PlotOnline.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/PlotOnline.C
similarity index 52%
rename from Projects/AlPhaPha/2024/macro/chio/YCalibration/Legacy/PlotOnline.C
rename to Projects/AlPhaPha/2024/macro/chio/YCalibration/PlotOnline.C
index 113fa6f52..d301d3ccd 100644
--- a/Projects/AlPhaPha/2024/macro/chio/YCalibration/Legacy/PlotOnline.C
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/PlotOnline.C
@@ -1,4 +1,6 @@
 
+#include <TAxis.h>
+#include <TCanvas.h>
 #include <TF1.h>
 #include <TFile.h>
 #include <TSpline.h>
@@ -9,7 +11,11 @@ void PlotOnline(){
 
 
     TFile *fSplineIC = new TFile("Output/spline_P2P_2024.root","open"); 
-    TSpline3 *spline_X = (TSpline3 *)fSplineIC->Get("fspline_IC1_Y");
+    TSpline3 *spline_Y = (TSpline3 *)fSplineIC->Get("fspline_IC1_Y");
 
+    TCanvas *c = new TCanvas("c","c");
     f1->Draw();
+    f1->SetTitle("Lucas correction");
+    f1->GetXaxis()->SetTitle("Y");
+    f1->GetYaxis()->SetTitle("De Correction");
 }
diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioP2P.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioP2P.C
index b7f9f49fd..2819b39f1 100644
--- a/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioP2P.C
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioP2P.C
@@ -53,7 +53,7 @@ void SplineChioP2P() {
     NCallSpline+=1;
 
     SplineAllIC.at(1)= (SplineICurrent); // 
-    SplineAllIC.erase(SplineAllIC.begin() + 1); 
+    ///SplineAllIC.erase(SplineAllIC.begin() + 1); 
                                          ///activate this to not make the
                                          //spline of IC1 
 
@@ -123,7 +123,7 @@ vector<TH2F*> HistoFillerIC(int segment, vector<vector<TSpline3*>> Spline_All_IC
 
     // Input and setters
     TChain* chain = new TChain("PhysicsTree");
-    chain->Add("../../../root/analysis/VamosCalib241.root");
+    chain->Add("../../../root/analysis/VamosCalib247.root");
 
     TICPhysics* IC = new TICPhysics() ; 
     double FF_IC_X, FF_IC_Y;
@@ -180,8 +180,8 @@ vector<TH2F*> HistoFillerIC(int segment, vector<vector<TSpline3*>> Spline_All_IC
     //																	Beginning loop on entries
     //===========================================================================================================
 
-    int Nentries = chain->GetEntries();
-    //int Nentries = 1000000;
+    //int Nentries = chain->GetEntries();
+    int Nentries = 1000000;
     auto start = std::chrono::high_resolution_clock::now();
     for (int e = 0; e < Nentries; e++) {
 
@@ -262,7 +262,7 @@ vector<vector<TH2F*>>HistoFillerICcorr(int segment, vector<vector<TSpline3*>> Sp
 
     // Input and setters
     TChain* chain = new TChain("PhysicsTree");
-    chain->Add("../../../root/analysis/VamosCalib241.root");
+    chain->Add("../../../root/analysis/VamosCalib247.root");
 
     TICPhysics* IC = new TICPhysics() ; 
     double FF_IC_X, FF_IC_Y;
diff --git a/Projects/AlPhaPha/2024/macro/mwpc/Toff/ToffGenerator.cxx b/Projects/AlPhaPha/2024/macro/mwpc/Toff/ToffGenerator.cxx
index c9168b6f8..67cdf48e7 100644
--- a/Projects/AlPhaPha/2024/macro/mwpc/Toff/ToffGenerator.cxx
+++ b/Projects/AlPhaPha/2024/macro/mwpc/Toff/ToffGenerator.cxx
@@ -116,8 +116,9 @@ void ToffGenerator(bool Create = true ){
 
             if (M13 == 2 && (abs(S13[0]-S13[1]) == 1)){
                 vector<int> Pos = SortSection(S13);
-                hToff13->Fill(S13[0],Time->GetTime_MWPC13(Pos[0]) - Time->GetTime_MWPC13(Pos[1])); 
-                hToffOnline13->Fill(S13[0],(Time->GetTime_MWPC13(Pos[0]) - Toff[S13[0]]) -( Time->GetTime_MWPC13(Pos[1])  -Toff[S13[1]]  )   ); 
+                hToff13->Fill(S13[0],  Time->GetTime_MWPC13(Pos[0])  - Time->GetTime_MWPC13(Pos[1])  );
+
+                hToffOnline13->Fill(S13[0], (Time->GetTime_MWPC13(Pos[0]) - Toff[S13[0]]) -( Time->GetTime_MWPC13(Pos[1]) -Toff[S13[1]]  )); 
             }
             if (M23 == 2 && (abs(S23[0]-S23[1]) == 1)){
                 vector<int> Pos = SortSection(S23);
@@ -405,7 +406,7 @@ void ToffGenerator(bool Create = true ){
         if (M13 == 2 && (abs(S13[0]-S13[1]) == 1)){
 
             vector<int> Pos = SortSection(S13);
-            hCorrToff13->Fill(S13[0],(Time->GetTime_MWPC13(Pos[0]) + Toff13.at(S13[0])) - (Time->GetTime_MWPC13(Pos[1]) + Toff13.at(S13[1])));
+            hCorrToff13->Fill(S13[0],(Time->GetTime_MWPC13(Pos[0]) - double(Time->GetTS_MWPC13(Pos[0]))+ Toff13.at(S13[0])) - (Time->GetTime_MWPC13(Pos[1]) - double(Time->GetTS_MWPC13(Pos[1]))+ Toff13.at(S13[1])));
         }
 
 
diff --git a/Projects/AlPhaPha/conversion/2024/convert.C b/Projects/AlPhaPha/conversion/2024/convert.C
index 08455d207..18862b4db 100644
--- a/Projects/AlPhaPha/conversion/2024/convert.C
+++ b/Projects/AlPhaPha/conversion/2024/convert.C
@@ -78,7 +78,7 @@ void convert(int run=204){
     for (int i=0; i<ICRawM; i++){
       m_ic->SetIC_TS(ICRawTS[i]);
       m_ic->SetIC_Section(i+1);
-      m_ic->SetIC_Charge(ICRaw[i]);
+      m_ic->SetIC_Charge(IC[i]);
     }
 
     // Time //
@@ -267,14 +267,15 @@ void InitInputTree(){
     input_tree->SetBranchAddress("MTOF_FP1_T1VTS",&MTOF_FP1_T1VTS);
 
     // IC
-    input_tree->SetBranchStatus("ICRaw","true");
-    input_tree->SetBranchAddress("ICRaw",&ICRaw);
+    input_tree->SetBranchStatus("IC","true");
+    input_tree->SetBranchAddress("IC",&IC);
 
     input_tree->SetBranchStatus("ICRawTS","true");
     input_tree->SetBranchAddress("ICRawTS",&ICRawTS);
 
     input_tree->SetBranchStatus("ICRawM","true");
     input_tree->SetBranchAddress("ICRawM",&ICRawM);
+
     // FPMW0-X
     input_tree->SetBranchStatus("FPMW0_XRawM","true");
     input_tree->SetBranchAddress("FPMW0_XRawM",&FPMW0_XRawM);
diff --git a/Projects/AlPhaPha/conversion/2024/convert.h b/Projects/AlPhaPha/conversion/2024/convert.h
index 58d519283..a53108fc7 100644
--- a/Projects/AlPhaPha/conversion/2024/convert.h
+++ b/Projects/AlPhaPha/conversion/2024/convert.h
@@ -49,7 +49,7 @@ ULong64_t fPISTA_TS_sec;
 ULong64_t PISTA_TS;
 
 // IC //
-UShort_t ICRaw[11];
+Float_t IC[11];
 long ICRawTS[11];
 int ICRawM;
 
-- 
GitLab