From 12084ddd159b7d95620777f1d11294a5f9df7f5e Mon Sep 17 00:00:00 2001 From: "theodore.efremov" <theodore.efremov@cea.fr> Date: Mon, 2 Dec 2024 14:29:24 +0100 Subject: [PATCH] Worked on the analysis especially Toff between segment of the MWPC --- Projects/AlPhaPha/2024/Analysis.cxx | 9 + .../2024/macro/chio/YCalibration/DECorr.C | 2 +- .../macro/chio/YCalibration/SplineChioAllXY.C | 2 +- .../2024/macro/mwpc/Toff/ToffGenerator.cxx | 348 ++++++++++++++++-- 4 files changed, 321 insertions(+), 40 deletions(-) diff --git a/Projects/AlPhaPha/2024/Analysis.cxx b/Projects/AlPhaPha/2024/Analysis.cxx index 0008109e5..2c498aff8 100644 --- a/Projects/AlPhaPha/2024/Analysis.cxx +++ b/Projects/AlPhaPha/2024/Analysis.cxx @@ -588,6 +588,15 @@ void Analysis::InitOutputBranch(){ RootOutput::getInstance()->GetTree()->Branch("FF_Mass13",&FF_Mass13,"FF_Mass13/D"); RootOutput::getInstance()->GetTree()->Branch("FPMW_Section",&FPMW_Section,"FPMW_Section/I"); + RootOutput::getInstance()->GetTree()->Branch("MTOF_FP0_T0VM",&MTOF_FP0_T0VM,"MTOF_FP0_T0VM/I"); + RootOutput::getInstance()->GetTree()->Branch("MTOF_FP0_T1VM",&MTOF_FP0_T1VM,"MTOF_FP0_T1VM/I"); + RootOutput::getInstance()->GetTree()->Branch("MTOF_FP1_T0VM",&MTOF_FP1_T0VM,"MTOF_FP1_T0VM/I"); + RootOutput::getInstance()->GetTree()->Branch("MTOF_FP1_T1VM",&MTOF_FP1_T1VM,"MTOF_FP1_T1VM/I"); + + RootOutput::getInstance()->GetTree()->Branch("MTOF_FP0_T0VN",&MTOF_FP0_T0VN,"MTOF_FP0_T0VN/I"); + RootOutput::getInstance()->GetTree()->Branch("MTOF_FP0_T1VN",&MTOF_FP0_T1VN,"MTOF_FP0_T1VN/I"); + RootOutput::getInstance()->GetTree()->Branch("MTOF_FP1_T0VN",&MTOF_FP1_T0VN,"MTOF_FP1_T0VN/I"); + RootOutput::getInstance()->GetTree()->Branch("MTOF_FP1_T1VN",&MTOF_FP1_T1VN,"MTOF_FP1_T1VN/I"); RootOutput::getInstance()->GetTree()->Branch("theta_lab_fission",&theta_lab_fission,"theta_lab_fission/D"); RootOutput::getInstance()->GetTree()->Branch("theta_cm_fission",&theta_cm_fission,"theta_cm_fission/D"); diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/DECorr.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/DECorr.C index b30e6ca72..5e6eb7d3e 100644 --- a/Projects/AlPhaPha/2024/macro/chio/YCalibration/DECorr.C +++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/DECorr.C @@ -21,7 +21,7 @@ void DECorr(bool cut = false, bool spline = false) { // Loading var //=========================================================================================================== 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, FF_V13; diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioAllXY.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioAllXY.C index a1e253b60..c1e4e3769 100644 --- a/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioAllXY.C +++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioAllXY.C @@ -93,7 +93,7 @@ void HistoFiller(bool cut) { // 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 3a6429a1a..8687ab69a 100644 --- a/Projects/AlPhaPha/2024/macro/mwpc/Toff/ToffGenerator.cxx +++ b/Projects/AlPhaPha/2024/macro/mwpc/Toff/ToffGenerator.cxx @@ -1,9 +1,16 @@ #include "TTimeData.h" +#include <TCanvas.h> #include <TChain.h> +#include <TF1.h> +#include <TFile.h> #include <TH2.h> +#include <TLatex.h> +#include <iostream> using namespace std; -void ToffGenerator( ){ +vector<int> SortSection(UShort_t STargFocal[2]); + + void ToffGenerator(bool Create = true ){ //=========================================================================================================== // Setters @@ -13,58 +20,323 @@ void ToffGenerator( ){ chain->Add("../../../root/analysis/VamosCalib247.root"); - Int_t FPMW_Section , M13 , M14, M23, M24 ;// we will fetch multiplicity during - // the getentry + Int_t M13 , M14, M23, M24 ;// we will fetch multiplicity during + // the getentry + + UShort_t S13[20] , S14[20] , S23[20] , S24[20]; - TTimeData *Time; + TTimeData *Time = new TTimeData(); - chain->SetBranchStatus("FPMW_Section", true); - chain->SetBranchAddress("FPMW_Section", &FPMW_Section); + chain->SetBranchStatus("MTOF_FP0_T0VN", true); + chain->SetBranchAddress("MTOF_FP0_T0VN", &S13); - chain->SetBranchStatus("Time", true); - chain->SetBranchAddress("Time", &Time); + chain->SetBranchStatus("MTOF_FP0_T1VN", true); + chain->SetBranchAddress("MTOF_FP0_T1VN", &S14); - //=========================================================================================================== - // Histograms - //=========================================================================================================== + chain->SetBranchStatus("MTOF_FP1_T0VN", true); + chain->SetBranchAddress("MTOF_FP1_T0VN", &S23); + + chain->SetBranchStatus("MTOF_FP1_T1VN", true); + chain->SetBranchAddress("MTOF_FP1_T1VN", &S24); + + chain->SetBranchStatus("Time", true); + chain->SetBranchAddress("Time", &Time); + + //=========================================================================================================== + // Histograms + //=========================================================================================================== + + TH2F *hToff13; + TH2F *hToff14; + TH2F *hToff23; + TH2F *hToff24; + + + if (Create == true){ + + hToff13 = new TH2F("Toff13","Toff13", 20, 0, 20, 100, -10, 10); + hToff14 = new TH2F("Toff14","Toff14", 20, 0, 20, 200, -10, 10); + hToff23 = new TH2F("Toff23","Toff23", 20, 0, 20, 200, -10, 10); + hToff24 = new TH2F("Toff24","Toff24", 20, 0, 20, 200, -10, 10); + + //=========================================================================================================== + // Loop on entries + //=========================================================================================================== + //int Nentries = chain->GetEntries(); + int Nentries = 1000000; + auto start = std::chrono::high_resolution_clock::now(); + + for (int e = 0; e < Nentries; e++) { + + chain->GetEntry(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; + } + + // Get Multiplicity + M13 = Time->GetMWPC13Mult(); + M14 = Time->GetMWPC14Mult(); + M23 = Time->GetMWPC23Mult(); + M24 = Time->GetMWPC24Mult(); + + + + 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])); + } + if (M23 == 2 && (abs(S23[0]-S23[1]) == 1)){ + vector<int> Pos = SortSection(S23); + hToff23->Fill(S23[0],Time->GetTime_MWPC23(Pos[0]) - Time->GetTime_MWPC23(Pos[1])); + } + + if (M14 == 2 && (abs(S14[0]-S14[1]) == 1)){ + vector<int> Pos = SortSection(S14); + hToff14->Fill(S14[0],Time->GetTime_MWPC14(Pos[0]) - Time->GetTime_MWPC14(Pos[1])); + } + + if (M24 == 2 && (abs(S24[0]-S24[1]) == 1)){ + vector<int> Pos = SortSection(S24); + hToff24->Fill(S24[0],Time->GetTime_MWPC24(Pos[0]) - Time->GetTime_MWPC24(Pos[1])); + } + } // End loop event + + TFile *out = new TFile("output/ToffHisto.root","recreate"); + hToff13->Write(); + hToff14->Write(); + hToff23->Write(); + hToff24->Write(); + }// end if create + + else { + + TFile *in = new TFile("output/ToffHisto.root","open"); + hToff13 = (TH2F*)in->Get("Toff13"); + hToff14 = (TH2F*)in->Get("Toff14"); + hToff23 = (TH2F*)in->Get("Toff23"); + hToff24 = (TH2F*)in->Get("Toff24"); + } + + int MinX = 2; + hToff13->SetMinimum(MinX); + hToff14->SetMinimum(MinX); + hToff23->SetMinimum(MinX); + hToff24->SetMinimum(MinX); + //=========================================================================================================== + // Proj fit + //=========================================================================================================== + TCanvas* c13 = new TCanvas("c13", "Toff13", 1800, 1600); + c13->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here) - TH2F *hToff13 = new TH2F("Toff13","Toff13", 20, 0, 20, 100, -50, 50); - TH2F *hToff14 = new TH2F("Toff14","Toff14", 20, 0, 20, 100, -50, 50); - TH2F *hToff23 = new TH2F("Toff23","Toff23", 20, 0, 20, 100, -50, 50); - TH2F *hToff24 = new TH2F("Toff24","Toff24", 20, 0, 20, 100, -50, 50); + TCanvas* c14 = new TCanvas("c14", "Toff14", 1800, 1600); + c14->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here) - //=========================================================================================================== - // Loop on entries - //=========================================================================================================== + TCanvas* c23 = new TCanvas("c23", "Toff23", 1800, 1600); + c23->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here) + + TCanvas* c24 = new TCanvas("c24", "Toff24", 1800, 1600); + c24->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here) + + vector<double> P2PToff13(19), P2PToff14(19) , P2PToff23(19), P2PToff24(19); - int Nentries = chain->GetEntries(); - //int Nentries = 10000000; - auto start = std::chrono::high_resolution_clock::now(); + // Loop through bins and draw each fit + for (int binX = 1; binX <= hToff13->GetNbinsX()-1; ++binX) { - 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); + c13->cd(binX); - std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush; - } + // Create a projection along the Y-axis for the current X-bin + TH1F* proj = (TH1F*)hToff13->ProjectionY(Form("proj_bin13%d", binX), binX, binX); + proj->SetMinimum(MinX); + // Fit the projection with a Gaussian + TF1* fit = new TF1(Form("fit_bin%d", binX), "gaus",-5,5); - M13 = Time->GetMWPC13Mult(); - M14 = Time->GetMWPC14Mult(); - M23 = Time->GetMWPC23Mult(); - M24 = Time->GetMWPC24Mult(); + // Select subpad and draw + proj->Fit(fit,"R"); // Suppress output with "Q" + proj->Draw(); + fit->SetLineColor(kRed); // Optional: Differentiate fit line + fit->Draw("SAME"); + // Retrieve fit parameters + double mean = fit->GetParameter(1); + double sigma = fit->GetParameter(2); + P2PToff13.at(binX-1) = mean; - if (M13 == 2 && (FPMW_Section)){ - //hToff13->Fill() - - } + // Add fit results to the subpad using TLatex + TLatex text; + text.SetNDC(); + text.SetTextSize(0.05); + text.SetTextAlign(13); // Align at top-left corner + text.DrawLatex(0.15, 0.85, Form("#mu = %.2f", mean)); + text.DrawLatex(0.15, 0.75, Form("#sigma = %.2f", sigma)); + // Save the mean to the text file } -} + // Display the canvas + c13->Update(); + + // Loop through bins and draw each fit + for (int binX = 1; binX <= hToff14->GetNbinsX()-1; ++binX) { + + c14->cd(binX); + + // Create a projection along the Y-axis for the current X-bin + TH1F* proj = (TH1F*)hToff14->ProjectionY(Form("proj_bin14%d", binX), binX, binX); + proj->SetMinimum(MinX); + + // Fit the projection with a Gaussian + TF1* fit = new TF1(Form("fit_bin%d", binX), "gaus"); + + // Select subpad and draw + proj->Fit(fit); // Suppress output with "Q" + proj->Draw(); + fit->SetLineColor(kRed); // Optional: Differentiate fit line + fit->Draw("SAME"); + + // Retrieve fit parameters + double mean = fit->GetParameter(1); + double sigma = fit->GetParameter(2); + P2PToff14.at(binX-1) = mean; + + + + // Add fit results to the subpad using TLatex + TLatex text; + text.SetNDC(); + text.SetTextSize(0.05); + text.SetTextAlign(13); // Align at top-left corner + text.DrawLatex(0.15, 0.85, Form("#mu = %.2f", mean)); + text.DrawLatex(0.15, 0.75, Form("#sigma = %.2f", sigma)); + + + // Save the mean to the text file + + } + // Display the canvas + c14->Update(); + + + // Loop through bins and draw each fit + for (int binX = 1; binX <= hToff23->GetNbinsX()-1; ++binX) { + + c23->cd(binX); + + // Create a projection along the Y-axis for the current X-bin + TH1F* proj = (TH1F*)hToff23->ProjectionY(Form("proj_bin23%d", binX), binX, binX); + proj->SetMinimum(MinX); + + // Fit the projection with a Gaussian + TF1* fit = new TF1(Form("fit_bin%d", binX), "gaus"); + + // Select subpad and draw + proj->Fit(fit); // Suppress output with "Q" + proj->Draw(); + fit->SetLineColor(kRed); // Optional: Differentiate fit line + fit->Draw("SAME"); + + // Retrieve fit parameters + double mean = fit->GetParameter(1); + double sigma = fit->GetParameter(2); + P2PToff23.at(binX-1) = mean; + + // Add fit results to the subpad using TLatex + TLatex text; + text.SetNDC(); + text.SetTextSize(0.05); + text.SetTextAlign(13); // Align at top-left corner + text.DrawLatex(0.15, 0.85, Form("#mu = %.2f", mean)); + text.DrawLatex(0.15, 0.75, Form("#sigma = %.2f", sigma)); + + + // Save the mean to the text file + + } + // Display the canvas + c23->Update(); + + // Loop through bins and draw each fit + for (int binX = 1; binX <= hToff24->GetNbinsX()-1; ++binX) { + + c24->cd(binX); + + // Create a projection along the Y-axis for the current X-bin + TH1F* proj = (TH1F*)hToff24->ProjectionY(Form("proj_bin24%d", binX), binX, binX); + proj->SetMinimum(MinX); + + // Fit the projection with a Gaussian + TF1* fit = new TF1(Form("fit_bin%d", binX), "gaus"); + + // Select subpad and draw + proj->Fit(fit,"Q"); // Suppress output with "Q" + proj->Draw(); + fit->SetLineColor(kRed); // Optional: Differentiate fit line + fit->Draw("SAME"); + + // Retrieve fit parameters + double mean = fit->GetParameter(1); + double sigma = fit->GetParameter(2); + P2PToff24.at(binX-1) = mean; + + // Add fit results to the subpad using TLatex + TLatex text; + text.SetNDC(); + text.SetTextSize(0.05); + text.SetTextAlign(13); // Align at top-left corner + text.DrawLatex(0.15, 0.85, Form("#mu = %.2f", mean)); + text.DrawLatex(0.15, 0.75, Form("#sigma = %.2f", sigma)); + + + // Save the mean to the text file + + } + // Display the canvas + c24->Update(); + + + + //=========================================================================================================== + // Drawing canvas + //=========================================================================================================== + + TCanvas *c1 = new TCanvas("c1","c1"); + hToff13->Draw("colz"); + + TCanvas *c2 = new TCanvas("c2","c2"); + hToff23->Draw(); + + TCanvas *c3 = new TCanvas("c3","c3"); + hToff14->Draw(); + + TCanvas *c4 = new TCanvas("c4","c4"); + hToff24->Draw(); + } + +vector<int> SortSection(UShort_t STargFocal[2]){ + UShort_t FSection ,LSection ; + vector<int> Pos(2) ; + if (STargFocal[0]<STargFocal[1]){ + Pos[0] = 0 ; + Pos[1] = 1 ; + FSection = STargFocal[0]; + LSection = STargFocal[1]; + } + else { + Pos[0] = 1 ; + Pos[1] = 0 ; + FSection = STargFocal[1]; + LSection = STargFocal[0]; + } + + STargFocal[0] = FSection; + STargFocal[1] = LSection; + return Pos; +} -- GitLab