From 0b5c5d85446dec51bcf0ac03de0dffd382a99978 Mon Sep 17 00:00:00 2001 From: Shuyang Date: Fri, 12 May 2023 16:29:26 -0700 Subject: [PATCH 1/6] add the historgrams of dtRechitClusterX, dtRechitClusterY, dtRechitClusterZ --- analysis/app/analyzer_histograms.C | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/analysis/app/analyzer_histograms.C b/analysis/app/analyzer_histograms.C index 9b98af8..96204db 100644 --- a/analysis/app/analyzer_histograms.C +++ b/analysis/app/analyzer_histograms.C @@ -37,6 +37,9 @@ void analyzer_histograms::InitHistos(){ h_nDTRechits [i] = InitTH1F("h_nDTRechits", "h_nDTRechits", 300, 0, 300); + h_dtRechitClusterX [i] = InitTH1F("h_dtRechitClusterX", "h_dtRechitClusterX", 50, -800, 800); + h_dtRechitClusterY [i] = InitTH1F("h_dtRechitClusterY", "h_dtRechitClusterY", 50, -800, 800); + h_dtRechitClusterZ [i] = InitTH1F("h_dtRechitClusterZ", "h_dtRechitClusterZ", 50, -700, 700); h_dtRechitClusterSize [i] = InitTH1F("h_dtRechitClusterSize", "h_dtRechitClusterSize", 300, 0, 300); h_dtRechitClusterPhi [i] = InitTH1F("h_dtRechitClusterPhi", "h_dtRechitClusterPhi", 40, -3.5, 3.5); h_dtRechitClusterEta [i] = InitTH1F("h_dtRechitClusterEta", "h_dtRechitClusterEta", 40, -5., 5); @@ -79,6 +82,9 @@ void analyzer_histograms::FillHistos(int selbin){ if(muon_list.size()>0) dPhi = DeltaPhi(lepPhi[muon_list[0]], dtRechitClusterPhi[d]); h_dtRechitClusterDPhiLeadMuon [selbin]->Fill(dPhi); h_dtRechitCluster_match_RPCBx_dPhi0p5 [selbin]->Fill(dtRechitCluster_match_RPCBx_dPhi0p5 [d]); + h_dtRechitClusterX [selbin]->Fill(dtRechitClusterX [d]); + h_dtRechitClusterY [selbin]->Fill(dtRechitClusterY [d]); + h_dtRechitClusterZ [selbin]->Fill(dtRechitClusterZ [d]); h_dtRechitClusterSize [selbin]->Fill(cscRechitClusterSize [d]); h_dtRechitClusterEta [selbin]->Fill(cscRechitClusterEta [d]); h_dtRechitClusterPhi [selbin]->Fill(cscRechitClusterPhi [d]); @@ -111,6 +117,9 @@ void analyzer_histograms::WriteHistos(int selbin){ h_dtRechitClusterDPhiLeadMuon [selbin]->Write(); h_dtRechitCluster_match_RPCBx_dPhi0p5 [selbin]->Write(); h_nDTRechits [selbin]->Write(); + h_dtRechitClusterX [selbin]->Write(); + h_dtRechitClusterY [selbin]->Write(); + h_dtRechitClusterZ [selbin]->Write(); h_dtRechitClusterSize [selbin]->Write(); h_dtRechitClusterEta [selbin]->Write(); h_dtRechitClusterPhi [selbin]->Write(); @@ -142,6 +151,9 @@ void analyzer_histograms::DeleteHistos(int selbin){ h_dtRechitClusterDPhiLeadMuon [selbin]->Delete(); h_dtRechitCluster_match_RPCBx_dPhi0p5 [selbin]->Delete(); h_nDTRechits [selbin]->Delete(); + h_dtRechitClusterX [selbin]->Delete(); + h_dtRechitClusterY [selbin]->Delete(); + h_dtRechitClusterZ [selbin]->Delete(); h_dtRechitClusterSize [selbin]->Delete(); h_dtRechitClusterEta [selbin]->Delete(); h_dtRechitClusterPhi [selbin]->Delete(); From 97fffa1e7d1e7d072f6b5561123a17650ce37d71 Mon Sep 17 00:00:00 2001 From: Shuyang Date: Fri, 12 May 2023 16:31:25 -0700 Subject: [PATCH 2/6] add the histograms of dtRechitClusterX, dtRechitClusterY, dtRechitClusterZ --- analysis/include/analyzer_histograms.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/analysis/include/analyzer_histograms.h b/analysis/include/analyzer_histograms.h index bbc205c..28b6bdb 100644 --- a/analysis/include/analyzer_histograms.h +++ b/analysis/include/analyzer_histograms.h @@ -32,6 +32,9 @@ class analyzer_histograms : public analyzer_selections{ TH1F* h_dtRechitClusterDPhiLeadMuon [SELBINNAMESIZE]; TH1F* h_dtRechitCluster_match_RPCBx_dPhi0p5 [SELBINNAMESIZE]; TH1F* h_nDTRechits [SELBINNAMESIZE]; + TH1F* h_dtRechitClusterX [SELBINNAMESIZE]; + TH1F* h_dtRechitClusterY [SELBINNAMESIZE]; + TH1F* h_dtRechitClusterZ [SELBINNAMESIZE]; TH1F* h_dtRechitClusterSize [SELBINNAMESIZE]; TH1F* h_dtRechitClusterPhi [SELBINNAMESIZE]; TH1F* h_dtRechitClusterEta [SELBINNAMESIZE]; From 606085078a78cf557b841b173c28edf8e5dbb75d Mon Sep 17 00:00:00 2001 From: Shuyang19 <114385785+Shuyang19@users.noreply.github.com> Date: Mon, 4 Mar 2024 19:17:15 -0800 Subject: [PATCH 3/6] Add files via upload --- read_roots/read.C | 132 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 read_roots/read.C diff --git a/read_roots/read.C b/read_roots/read.C new file mode 100644 index 0000000..ff5f777 --- /dev/null +++ b/read_roots/read.C @@ -0,0 +1,132 @@ +#include +#include +#include "TFile.h" +#include "TH1F.h" +#include "TTree.h" +#include "TCanvas.h" + +void read() { + // Open the ROOT file + TFile *file1 = TFile::Open("BToKPhi_MuonLLPDecayGenFilter_PhiToPi0Pi0_mPhi1p0_ctau300.root"); + TFile *file2 = TFile::Open("BToKPhi_MuonLLPDecayGenFilter_PhiToPi0Pi0_mPhi1p0_ctau1000.root"); + if (!file1 || file1->IsZombie()) { + std::cerr << "Error opening file" << std::endl; + return; + } + if (!file2 || file2->IsZombie()) { + std::cerr << "Error opening file" << std::endl; + return; + } + + // Get the TTree from the file + TTree *tree_300 = nullptr; + file1->GetObject("MuonSystem", tree_300); + if (!tree_300) { + std::cerr << "Error retrieving MuonSystem TTree" << std::endl; + file1->Close(); + return; + } + TTree *tree_1000 = nullptr; + file2->GetObject("MuonSystem", tree_1000); + if (!tree_1000) { + std::cerr << "Error retrieving MuonSystem TTree" << std::endl; + file2->Close(); + return; + } + + // set your binning + TH1F *h_gLLP_ctau_300 = new TH1F("h_gLLP_ctau_300", "h_gLLP_ctau_300", 100, 0, 1000); + TH1F *h_gLLP_ctau_1000 = new TH1F("h_gLLP_ctau_1000", "h_gLLP_ctau_1000", 100, 0, 1000); + + + // Set branch address + float gLLP_ctau_300; + float gLLP_ctau_1000; + + tree_300->SetBranchAddress("gLLP_ctau", &gLLP_ctau_300); + tree_1000->SetBranchAddress("gLLP_ctau", &gLLP_ctau_1000); + + // Loop over the tree entries and fill the histogram + Long64_t nEntries_300 = tree_300->GetEntries(); + for (Long64_t i = 0; i < nEntries_300; i++) { + tree_300->GetEntry(i); + h_gLLP_ctau_300->Fill(gLLP_ctau_300); + } + h_gLLP_ctau_300->Scale(1./h_gLLP_ctau_300->Integral(0,-1)); + Long64_t nEntries_1000 = tree_1000->GetEntries(); + for (Long64_t i = 0; i < nEntries_1000; i++) { + tree_1000->GetEntry(i); + h_gLLP_ctau_1000->Fill(gLLP_ctau_1000); + + } + h_gLLP_ctau_1000->Scale(1./h_gLLP_ctau_1000->Integral(0,-1)); + + + + // Now you can use the histograms you saved in the loop here + //compare which tree has the shorter bins + //int binNum =std::min(h_gLLP_ctau_300->GetNbinsX(), h_gLLP_ctau_1000->GetNbinsX()); + //initialize an array to store the difference between binNumber + //float abs_bin_diff[100]; + + for (int i = 1; i <= 40; i++) + { + //getting the ratio of two decay length + float ratio = h_gLLP_ctau_300->GetBinContent(i)/h_gLLP_ctau_1000->GetBinContent(i); + //std::cout<GetBinContent(i)<<" "<GetBinContent(i)<<" "<< ratio<GetBinContent(j-1)!=0 && h_gLLP_ctau_1000->GetBinContent(j-1) != 0)) + // { + // min_diff = abs_bin_diff[j-1]; + // x_cor = h_gLLP_ctau_1000->GetBinCenter(j); + // } + // } + + //print out the minimum difference and the x-coordinate of the intersection + // std::cout << min_diff << std::endl; + // std::cout << x_cor << std::endl; + + float ratio_closest_to_1 = h_gLLP_ctau_300->GetBinContent(1)/h_gLLP_ctau_1000->GetBinContent(1); + int NumBin = 1; + for (int i = 1; i<= 40; i++) + { + if (abs(1-h_gLLP_ctau_300->GetBinContent(i)/h_gLLP_ctau_1000->GetBinContent(i)) < abs(1-ratio_closest_to_1)) + { + ratio_closest_to_1 = h_gLLP_ctau_300->GetBinContent(i)/h_gLLP_ctau_1000->GetBinContent(i); + NumBin = i; + } + } + float x_cor = h_gLLP_ctau_300->GetBinCenter(NumBin); + std::cout<<"x coordinate of the intersection is: " << x_cor << " with ratio: " <Draw(); + TCanvas *c2 = new TCanvas("c2", "gLLP_ctau Distribution", 800, 600); + h_gLLP_ctau_1000->Draw(); + + // Save the canvas to a file + c1->SaveAs("h_gLLP_PhiToPi0Pi_ctau300.png"); + c1->SetLogy(); + c1->SaveAs("h_gLLP_PhiToPi0Pi_ctau300_log.png"); + c2->SaveAs("h_gLLP_PhiToPi0Pi_ctau1000.png"); + c2->SetLogy(); + c2->SaveAs("h_gLLP_PhiToPi0Pi_ctau1000_log.png"); + + // Close the ROOT file + file1->Close(); + file2->Close(); +} + From da568fb06340dc5966d5d9ef18bae504e413d1a0 Mon Sep 17 00:00:00 2001 From: Shuyang19 <114385785+Shuyang19@users.noreply.github.com> Date: Mon, 4 Mar 2024 19:20:55 -0800 Subject: [PATCH 4/6] Create README.md --- read_roots/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 read_roots/README.md diff --git a/read_roots/README.md b/read_roots/README.md new file mode 100644 index 0000000..e302282 --- /dev/null +++ b/read_roots/README.md @@ -0,0 +1,5 @@ +The read.C file is use to read the g_llp ctau data in the root files, +find the intersection of two different decay length (ctau300 and ctau 1000) +Then can determine a re-weighting factor to extrapolate the behaviour of LLPs at the different decay lengths. + +Currently it calculates the intersection of ctau300 and ctau1000 for Pi0Pi0 category From e1991845e84cc56187ba50ac08d98d10205d0b8f Mon Sep 17 00:00:00 2001 From: Shuyang19 Date: Wed, 15 May 2024 10:03:59 -0700 Subject: [PATCH 5/6] update read.C --- read_roots/read.C | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/read_roots/read.C b/read_roots/read.C index ff5f777..8fb4277 100644 --- a/read_roots/read.C +++ b/read_roots/read.C @@ -69,6 +69,26 @@ void read() { //initialize an array to store the difference between binNumber //float abs_bin_diff[100]; + + int binNum_300 = h_gLLP_ctau_300->GetNbinsX(); + std::cout << "content of ctau_300's bins" << endl; + for(int i= 1; i < binNum_300; i++) + { + std::cout << i <<" "<GetBinContent(i)<< std::endl; + + } + int binNum_1000 = h_gLLP_ctau_1000->GetNbinsX(); + std::cout << "content of ctau_1000's bins" << endl; + for(int i= 1; i < binNum_1000; i++) + { + std::cout << i <<" "<GetBinContent(i)<< std::endl; + + } + + //getting the difference between each binsif(h_gLLP_ctau_300->GetBinContent(i) !=0) + + //std::cout << h_gLLP_ctau_300->GetBinContent(i)<< std::endl; + for (int i = 1; i <= 40; i++) { //getting the ratio of two decay length From 896ad2c0b2650d81f45074e0ac7828f74d203927 Mon Sep 17 00:00:00 2001 From: Shuyang19 Date: Wed, 15 May 2024 10:16:47 -0700 Subject: [PATCH 6/6] update read.C --- read_roots/read.C | 141 +++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 69 deletions(-) diff --git a/read_roots/read.C b/read_roots/read.C index 8fb4277..dab3604 100644 --- a/read_roots/read.C +++ b/read_roots/read.C @@ -5,10 +5,20 @@ #include "TTree.h" #include "TCanvas.h" +Float_t ctau_reweighter(Float_t t, Float_t tau0, Float_t tau1) +{ + Float_t numerator = (1.0f / tau1) * expf(-t / tau1); + Float_t denominator = (1.0f / tau0) * expf(-t / tau0); + return numerator / denominator; + +} + void read() { // Open the ROOT file TFile *file1 = TFile::Open("BToKPhi_MuonLLPDecayGenFilter_PhiToPi0Pi0_mPhi1p0_ctau300.root"); TFile *file2 = TFile::Open("BToKPhi_MuonLLPDecayGenFilter_PhiToPi0Pi0_mPhi1p0_ctau1000.root"); + + if (!file1 || file1->IsZombie()) { std::cerr << "Error opening file" << std::endl; return; @@ -35,8 +45,9 @@ void read() { } // set your binning - TH1F *h_gLLP_ctau_300 = new TH1F("h_gLLP_ctau_300", "h_gLLP_ctau_300", 100, 0, 1000); - TH1F *h_gLLP_ctau_1000 = new TH1F("h_gLLP_ctau_1000", "h_gLLP_ctau_1000", 100, 0, 1000); + TH1F *h_gLLP_ctau_300 = new TH1F("h_gLLP_ctau_300", "h_gLLP_ctau_300", 1000, 0, 1000); + TH1F *h_gLLP_ctau_1000 = new TH1F("h_gLLP_ctau_1000", "h_gLLP_ctau_1000", 1000, 0, 1000); + //try more bins // Set branch address @@ -47,103 +58,95 @@ void read() { tree_1000->SetBranchAddress("gLLP_ctau", &gLLP_ctau_1000); // Loop over the tree entries and fill the histogram + // Long64_t nEntries_300 = tree_300->GetEntries(); + // float w = 1.0;//weight + // for (Long64_t i = 0; i < nEntries_300; i++) { + // tree_300->GetEntry(i); + // h_gLLP_ctau_300->Fill(gLLP_ctau_300, w); + // } + //h_gLLP_ctau_300->Scale(1./h_gLLP_ctau_300->Integral(0,-1)); Long64_t nEntries_300 = tree_300->GetEntries(); + for (Long64_t i = 0; i < nEntries_300; i++) { tree_300->GetEntry(i); - h_gLLP_ctau_300->Fill(gLLP_ctau_300); + float w = 1.0; + float reweight_factor = ctau_reweighter(gLLP_ctau_300, 30, 20); + w *= reweight_factor; + h_gLLP_ctau_300->Fill(gLLP_ctau_300, w); } - h_gLLP_ctau_300->Scale(1./h_gLLP_ctau_300->Integral(0,-1)); + h_gLLP_ctau_300->Scale(1./h_gLLP_ctau_300->Integral(0,-1)); + + Long64_t nEntries_1000 = tree_1000->GetEntries(); for (Long64_t i = 0; i < nEntries_1000; i++) { tree_1000->GetEntry(i); - h_gLLP_ctau_1000->Fill(gLLP_ctau_1000); + float w = 1.0; + float reweight_factor = ctau_reweighter(gLLP_ctau_1000, 100, 90); + h_gLLP_ctau_1000->Fill(gLLP_ctau_1000, w); } h_gLLP_ctau_1000->Scale(1./h_gLLP_ctau_1000->Integral(0,-1)); - - - // Now you can use the histograms you saved in the loop here - //compare which tree has the shorter bins - //int binNum =std::min(h_gLLP_ctau_300->GetNbinsX(), h_gLLP_ctau_1000->GetNbinsX()); - //initialize an array to store the difference between binNumber - //float abs_bin_diff[100]; - int binNum_300 = h_gLLP_ctau_300->GetNbinsX(); - std::cout << "content of ctau_300's bins" << endl; - for(int i= 1; i < binNum_300; i++) - { - std::cout << i <<" "<GetBinContent(i)<< std::endl; - - } - int binNum_1000 = h_gLLP_ctau_1000->GetNbinsX(); - std::cout << "content of ctau_1000's bins" << endl; - for(int i= 1; i < binNum_1000; i++) - { - std::cout << i <<" "<GetBinContent(i)<< std::endl; - - } - - //getting the difference between each binsif(h_gLLP_ctau_300->GetBinContent(i) !=0) - - //std::cout << h_gLLP_ctau_300->GetBinContent(i)<< std::endl; - - for (int i = 1; i <= 40; i++) - { - //getting the ratio of two decay length - float ratio = h_gLLP_ctau_300->GetBinContent(i)/h_gLLP_ctau_1000->GetBinContent(i); - //std::cout<GetBinContent(i)<<" "<GetBinContent(i)<<" "<< ratio<GetBinContent(j-1)!=0 && h_gLLP_ctau_1000->GetBinContent(j-1) != 0)) - // { - // min_diff = abs_bin_diff[j-1]; - // x_cor = h_gLLP_ctau_1000->GetBinCenter(j); - // } - // } - - //print out the minimum difference and the x-coordinate of the intersection - // std::cout << min_diff << std::endl; - // std::cout << x_cor << std::endl; float ratio_closest_to_1 = h_gLLP_ctau_300->GetBinContent(1)/h_gLLP_ctau_1000->GetBinContent(1); int NumBin = 1; - for (int i = 1; i<= 40; i++) + int binNum_300 = h_gLLP_ctau_300->GetNbinsX(); + for (int i = 1; i<= binNum_300; i++) { - if (abs(1-h_gLLP_ctau_300->GetBinContent(i)/h_gLLP_ctau_1000->GetBinContent(i)) < abs(1-ratio_closest_to_1)) + if(h_gLLP_ctau_1000->GetBinContent(i) != 0) { + if (abs(1-(h_gLLP_ctau_300->GetBinContent(i)/h_gLLP_ctau_1000->GetBinContent(i))) < abs(1-ratio_closest_to_1)) + { ratio_closest_to_1 = h_gLLP_ctau_300->GetBinContent(i)/h_gLLP_ctau_1000->GetBinContent(i); NumBin = i; + } } + } float x_cor = h_gLLP_ctau_300->GetBinCenter(NumBin); - std::cout<<"x coordinate of the intersection is: " << x_cor << " with ratio: " <Draw(); + //combined graph + // TCanvas *c1 = new TCanvas("c1", "gLLP_ctau Distribution", 800, 600); + // h_gLLP_ctau_300->SetLineColor(kBlue); + // h_gLLP_ctau_1000->SetLineColor(kRed); + // h_gLLP_ctau_300->Draw(); + // h_gLLP_ctau_1000->Draw("same"); + + // TLatex *text = new TLatex(); + // text->SetNDC(); + // text->SetTextSize(0.04); + // text->SetTextAlign(22); + + // Convert float to string + // std::ostringstream oss_x; + // std::ostringstream oss_ratio; + // oss_x << x_cor; + // oss_ratio << ratio_closest_to_1; + // std::string x_cor_str = oss_x.str(); + // std::string ratio_str = oss_ratio.str(); + // std::string annotation = "x-intersection " + x_cor_str + " ratio: " + ratio_str; + // text->DrawLatex(0.5, 0.8, annotation.c_str()); + // c1->SaveAs("h_gLLP_PhiToPi0Pi0_ctau_combined.png"); + + //seperate histograms TCanvas *c2 = new TCanvas("c2", "gLLP_ctau Distribution", 800, 600); + h_gLLP_ctau_300->Draw(); + + TCanvas *c3 = new TCanvas("c3", "gLLP_ctau Distribution", 800, 600); h_gLLP_ctau_1000->Draw(); - // Save the canvas to a file - c1->SaveAs("h_gLLP_PhiToPi0Pi_ctau300.png"); - c1->SetLogy(); - c1->SaveAs("h_gLLP_PhiToPi0Pi_ctau300_log.png"); - c2->SaveAs("h_gLLP_PhiToPi0Pi_ctau1000.png"); - c2->SetLogy(); - c2->SaveAs("h_gLLP_PhiToPi0Pi_ctau1000_log.png"); + + c2->SaveAs("reweight200_h_gLLP_PhiToPi0Pi0_ctau300.png"); + c3->SaveAs("reweight900_h_gLLP_PhiToPi0Pi0_ctau1000.png"); + + // c3->SaveAs("h_gLLP_PhiToPi0Pi0_ctau1000.png"); // Close the ROOT file file1->Close();