From 06d54dbbd413df7c89d69973e75b1a2b65c0e651 Mon Sep 17 00:00:00 2001
From: "theodore.efremov" <theodore.efremov@cea.fr>
Date: Fri, 25 Oct 2024 11:41:40 +0200
Subject: [PATCH] Modified the spline macro and tested it

---
 .../macro/chio/CalibrationChio/SplineChioXY.C |  45 +-----
 .../macro/chio/CalibrationChio/TestSpline.C   | 130 ++++++++++++++++++
 2 files changed, 133 insertions(+), 42 deletions(-)
 create mode 100644 Projects/AlPhaPha/2024/macro/chio/CalibrationChio/TestSpline.C

diff --git a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioXY.C b/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioXY.C
index 24e712216..4bbdc293b 100644
--- a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioXY.C
+++ b/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioXY.C
@@ -16,10 +16,9 @@ void ApplySpline();
 void HistoFiller();
 
 //////////////////////////////////////////////////////////////////////////////////////////
-void SplineChioXY() {
+void SplineChioXY( bool Create = false) {
 
   TFile* inFile =  TFile::Open("Output/Histo.root");
-  bool Create = false;
 
   if (Create == true){
     cout << "Creating Histo.root" << endl;
@@ -52,44 +51,6 @@ void SplineChioXY() {
 
   fspline->Close();
 
-  /*
-  //===========================================================================================================
-  //                                    Plot Histograms
-  //===========================================================================================================
-
-  TGraph* gr = new TGraph();
-  gr->SetName("IC0/IC1vsX");
-
-  TCanvas* can = new TCanvas("IC0/IC1vsX", "IC0/IC1vsX", 0, 0, 2500, 2000);
-  can->cd();
-  ofstream ofile_par;
-  string filename_par = "mean_spline_par_X.dat";
-  ofile_par.open(filename_par.c_str());
-  cout << "Float_t F[" << Ncuts << "] = { " << endl;
-  ofile_par << "Float_t FF_DEcorr[" << Ncuts << "] = { " << endl;
-  for (int i = 0; i < Ncuts; i++) {
-  can->cd();
-  if (i == 0)
-  h2->Draw("col");
-  else
-  h2->Draw("col,same");
-  cout << h2->GetMean(2) << ", " << endl;
-  ofile_par << h2->GetMean(2) << ", " << endl;
-  // gr->SetPoint(i,sqrt(h2->GetMean(2)),i+31);
-  gr->SetPoint(i, gspline->Eval(8500), i + 31);
-  // hProfile->Draw("same");
-  pfx->Draw("same");
-  gspline->SetLineColor(kBlue);
-  gspline->SetLineWidth(3);
-  gspline->Draw("lsame");
-  }
-
-  TCanvas* cangr = new TCanvas("ToGetRoughCal", "ToGetRoughCal", 200, 0, 1200, 1000);
-  cangr->cd();
-  gr->SetMarkerStyle(20);
-  gr->Draw("AP");
-  gr->Fit("pol2");
-  */
 } // End spline chio XY
 
 ///////////////////////////////////////////////////////////////////////////////////////////
@@ -120,9 +81,9 @@ void HistoFiller() {
   // Histograms
 
   TH2F* hChio_IC0_IC1_X_all = new TH2F("hChio_IC0_IC1_X_all",
-      "hChio_IC0_IC1_X_all", 1000, -600, 400, 500, 0, 2);
+      "hChio_IC0_IC1_X_all", 1000, -800, 800, 500, 1, 1.6);
   TH2F* hChio_IC0_IC1_Y_all = new TH2F("hChio_IC0_IC1_Y_all",
-      "hChio_IC0_IC1_Y_all", 1000, -100, 100, 500, 0, 2);
+      "hChio_IC0_IC1_Y_all", 1000, -160, 160, 500, 1, 1.6);
 
   //===========================================================================================================
   //																	Beginning loop on entries
diff --git a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/TestSpline.C b/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/TestSpline.C
new file mode 100644
index 000000000..17574cc24
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/TestSpline.C
@@ -0,0 +1,130 @@
+#include "TICPhysics.h"
+#include <TCanvas.h>
+#include <TChain.h>
+#include <TF1.h>
+#include <TFile.h>
+#include <TH2.h>
+#include <TSpline.h>
+#include <fstream>
+#include <vector>
+
+using namespace std;
+
+//////////////////////////////////////////////////////////////////////////////////////////
+void TestSpline() {
+  //===========================================================================================================
+  //                           Loading var
+  //===========================================================================================================
+  TChain* chain = new TChain("PhysicsTree");
+  chain->Add("../../../root/analysis/VamosCalib241.root");
+  TICPhysics* IC = new TICPhysics() ;
+
+  double FF_IC_X, FF_IC_Y;
+
+  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); 
+
+
+  TFile* fHisto =  TFile::Open("Output/Histo.root");
+  TFile* fSpline =  TFile::Open("Output/spline_Chio_2024.root");
+
+  vector<TH2F*> hIC,hICorr;
+  TH2F* hICorr_X = new TH2F("hICorr_X","hICorr_X",1000,-600,400,500,1,1.6);
+  TH2F* hICorr_Y = new TH2F("hICorr_Y","hICorr_Y",1000,-100,100,500,1,1.6);
+  TH2F* hDE_Ecorr = new TH2F("DE_Ecorr","DE_Ecorr",1000,100,1,1000,100,1);
+  TH2F* hDE_E = new TH2F("DE_E","DE_E",1000,100,1,1000,100,1);
+
+  hICorr.push_back(hICorr_X);
+  hICorr.push_back(hICorr_Y);
+  hIC.push_back((TH2F*)fHisto->Get("hChio_IC0_IC1_X_all"));
+  hIC.push_back((TH2F*)fHisto->Get("hChio_IC0_IC1_Y_all"));    
+
+  vector<TSpline3*> spline;
+  for (int i = 0; i < hIC.size(); i++) {
+    spline.push_back((TSpline3*)fSpline->Get(Form("fspline_%d",i)));
+  } //End loop on histogram
+
+
+  //===========================================================================================================
+  //                                        Event Loop
+  //===========================================================================================================
+  int Nentries = chain->GetEntries();
+
+  for (int e = 0; e < Nentries; e++) {
+    // Printing status
+    if (e % 100000 == 0){
+      cout <<  "Please wait, we are  " << e * 100. / Nentries << "% done ..\r" << flush;
+    }
+    chain->GetEntry(e);
+
+    double IC_CorrX = IC->fIC_raw[1]/ IC->fIC_raw[0]  * spline[0]->Eval(0) /
+      spline[0]->Eval(FF_IC_X) ;
+
+    double IC0_CorrX = IC->fIC_raw[1] / IC_CorrX ;
+
+    double IC_CorrY = IC->fIC_raw[1]/ IC0_CorrX * spline[1]->Eval(0) /
+      spline[1]->Eval(FF_IC_Y) ;
+
+    hICorr[0]->Fill(FF_IC_X,IC_CorrX);
+    hICorr[1]->Fill(FF_IC_Y,IC_CorrY);
+
+
+    double IC0_Corr = IC->fIC_raw[1] /IC_CorrY;
+    if (IC0_Corr != IC0_Corr ) IC0_Corr = 0;
+
+    double DE = 0 ,E =0 ,DEcorr=0 ;
+
+    for (int seg = 0 ;  seg < sizeof(IC->fIC_raw)/sizeof(IC->fIC_raw[0]) ; seg++ ){
+      if(seg > 1 && seg < 4) DE += IC->fIC_raw[seg] ;
+      else if (seg >4) E+= IC->fIC_raw[seg] ;
+    }
+   
+    DEcorr += DE ;
+
+    if (IC0_Corr < 1e10 && IC0_Corr >0){ 
+    DEcorr += IC0_Corr ;}
+    else DEcorr += IC->fIC_raw[0];
+
+    DE += IC->fIC_raw[0] ;
+
+    DE = DE *0.5 + IC->fIC_raw[4];
+    DEcorr = DEcorr *0.5 + IC->fIC_raw[4];
+  
+    /* 
+    cout << IC0_Corr << "  " << IC->fIC_raw[0] << endl; 
+    cout << DEcorr << "  " << DE << endl;
+    cout << "*************************" << endl;
+    */
+    
+    hDE_E->Fill(E,DE);
+    hDE_Ecorr->Fill(E,DEcorr);
+  } //End loop on event
+
+  //===========================================================================================================
+  //                                          Drawing histo
+  //===========================================================================================================
+
+  TCanvas* c1 = new TCanvas("c1","c1",1000,1000);
+  c1->Divide(2,2);
+  c1->cd(1);
+  hICorr[0]->Draw();
+  c1->cd(2);
+  hIC[0]->Draw();
+  c1->cd(3);
+  hICorr[1]->Draw();
+  c1->cd(4);
+  hIC[1]->Draw();
+
+  TCanvas* c2 = new TCanvas("c2","c2",1000,1000);
+  c2->Divide(2);
+  c2->cd(1);
+  hDE_E->Draw();
+  c2->cd(2);
+  hDE_Ecorr->Draw();
+
+
+} // End spline chio XY
-- 
GitLab