diff --git a/general_codes/ryotaro/CarriedOverHits/macro/Fun4All_HitCarryoverMonitor.cc b/general_codes/ryotaro/CarriedOverHits/macro/Fun4All_HitCarryoverMonitor.cc new file mode 100644 index 0000000..19c337e --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/macro/Fun4All_HitCarryoverMonitor.cc @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include + +// #include "InttHitCarryoverMonitor.h" +#include "/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/install/include/tutorial/InttHitCarryoverMonitor.h" + +R__LOAD_LIBRARY(libInttHitCarryoverMonitor.so) + +void Fun4All_HitCarryoverMonitor(int process_id, int run, int n_events, std::string file_path_to_hot_channel_map="/sphenix/user/jaein213/macros/inttcalib_fee/hotmap_cdb/hotmap_cdb_54280_100000_DST_1114.root", bool save_tree=false){ + Fun4AllServer* fun4all_server = Fun4AllServer::instance(); + + std::vector input_managers; + + std::string job_index = std::to_string( process_id ); + int job_index_len = 5; + job_index.insert(0, job_index_len - job_index.size(), '0'); + + for (int i = 0; i < 8; i++) { + std::string intt_file_name = Form("DST_STREAMING_EVENT_intt%d_run3auau_new_nocdbtag_v001-000%d-%s.root", i, run, job_index.c_str()); + // std::string intt_file_name = Form("DST_STREAMING_EVENT_intt%d_run3oo_new_nocdbtag_v001-000%d-%s.root", i, run, job_index.c_str()); + input_managers.push_back(new Fun4AllDstInputManager(Form("DST_track_%d",i))); + input_managers.back() -> Verbosity(2); + input_managers.back() -> AddFile( intt_file_name ); + fun4all_server->registerInputManager(input_managers.back()); + } + + // std::string intt_file_name = "/sphenix/tg/tg01/commissioning/INTT/data/dst_files/2025/DST_beam_intt-00079244_special.root"; // = Form("DST_STREAMING_EVENT_intt%d_run3auau_new_nocdbtag_v001-000%d-%s.root", i, run, job_index.c_str()); + // input_managers.push_back(new Fun4AllDstInputManager(Form("DST_track"))); + // input_managers.back() -> Verbosity(2); + // input_managers.back() -> AddFile( intt_file_name ); + // fun4all_server->registerInputManager(input_managers.back()); + + InttHitCarryoverMonitor* module_carryover_monitor = new InttHitCarryoverMonitor("name", run, file_path_to_hot_channel_map, job_index, save_tree); + + std::string output_directory = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d", run); + std::string final_output_file_name = Form("%d-%s.root", run, job_index.c_str()); + system(Form("if [ -f %s/completed/%s ]; then rm %s/completed/%s; fi;", output_directory.c_str(), final_output_file_name.c_str(), output_directory.c_str(), final_output_file_name.c_str())); + + fun4all_server->registerSubsystem(module_carryover_monitor); + fun4all_server->run(n_events); + fun4all_server->End(); + + system(Form("mv %s/%s %s/completed", output_directory.c_str(), final_output_file_name.c_str(), output_directory.c_str())); + + // delete module_carryover_monitor; + // for (int i=0; i<8; i++) { + // delete input_managers[i]; /* This will cause segmentaion fault. Probably because input_managers will be deleted automatically when we delete fun4all_server. + // } + delete fun4all_server; + + +} \ No newline at end of file diff --git a/general_codes/ryotaro/CarriedOverHits/macro/MakeCanvasForAPR.C b/general_codes/ryotaro/CarriedOverHits/macro/MakeCanvasForAPR.C new file mode 100644 index 0000000..f08f07e --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/macro/MakeCanvasForAPR.C @@ -0,0 +1,276 @@ +#include "utilities/sPhenixStyle.C" +#include "MyUtilities/my.cc" + + +int FindEdgeBin(TH1D* hist, int peak_bin); +TH1D* ShiftHistoWithoutDupulication(TH1D* hist, int offset); +int AddOffsetWithoutOverflow(int this_bin, int offset); +int GetPreviousWithoutUnderflow(int bin); +void DrawBoxFromValue( TH2D* h2D_NInttHitInner_NInttHitOuter, double x_val_min, double x_val_max, double y_val_min, double y_val_max, int color ); + +void MakeCanvasForAPR(int run){ + + SetsPhenixStyle(); + + // std::string counts = "100k"; + int n_collision = GetNCollisionFromRunNum(run); + int open_time = GetOpenTimeFromRunNum(run); + + // std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/%s/10M_%d_%s.root", run, tag.c_str(), run, tag.c_str()); + std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/completed/4646files_Criteria2_woTTree_0hitHandled_halfladderCutted.root"); + TFile* file = TFile::Open(filename.c_str()); + if ( !file || file->IsZombie() ){ + std::cout << "Error: cannot open file " << filename << std::endl; + exit(1); + } + + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_all_event = (TH2D*)file->Get("h2D_EventBcoSpacing_NHitInPreviousEvent_all_event_"); + TH2D* h2D_EventBcoSpacing_CorrectedMultiplicity_all_event = (TH2D*)file->Get("h2D_EventBcoSpacing_CorrectedMultiplicity_all_event_"); + + + TCanvas* c1 = new TCanvas("c1", "Title", 900, 600); + c1->cd(); + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event->SetTitle(Form("h2D_EventBcoSpacing_NHitInPreviousEvent_all_event (run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event->GetXaxis()->SetTitle("Event interval to the next event [Beam Collision Clock 9.4MHz]"); + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event->GetXaxis()->SetNdivisions(407); + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event->GetYaxis()->SetTitle("Number of INTT hits"); + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event->GetYaxis()->SetNdivisions(206); + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event->Draw(); + c1->SetLogz(); + PutCaption_BeforeCorrection(run, -0.1, 0.2, 0.94); /* PutCaption(int run, double first_margin = -0.1, double pos_x = 0.2, double pos_y = 0.9) */ + // c1->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/ForAPR/h2D_EventBcoSpacing_NHitInPreviousEvent_all_event_%d.pdf", run, run)); + + TCanvas* c2 = new TCanvas("c2", "Title", 900, 600); + c2->cd(); + h2D_EventBcoSpacing_CorrectedMultiplicity_all_event->SetTitle(Form("h2D_EventBcoSpacing_CorrectedMultiplicity_all_event (run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_EventBcoSpacing_CorrectedMultiplicity_all_event->GetXaxis()->SetTitle("Event interval to the next event [Beam Collision Clock 9.4MHz]"); + h2D_EventBcoSpacing_CorrectedMultiplicity_all_event->GetXaxis()->SetNdivisions(407); + h2D_EventBcoSpacing_CorrectedMultiplicity_all_event->GetYaxis()->SetRange(-1,25000); + h2D_EventBcoSpacing_CorrectedMultiplicity_all_event->GetYaxis()->SetTitle("Number of INTT hits"); + h2D_EventBcoSpacing_CorrectedMultiplicity_all_event->GetYaxis()->SetNdivisions(206); + h2D_EventBcoSpacing_CorrectedMultiplicity_all_event->Draw(); + c2->SetLogz(); + PutCaption_AfterCorrection(run, -0.1, 0.2, 0.94); /* PutCaption(int run, double first_margin = -0.1, double pos_x = 0.2, double pos_y = 0.9) */ + // c2->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/ForAPR/h2D_EventBcoSpacing_CorrectedMultiplicity_all_event_%d.pdf", run, run) ); + + + + TCanvas* c3 = new TCanvas("c3", "Title", 600,700); + // TCanvas* c3 = new TCanvas("c3", "Title", 900, 600); + c3->cd(); + + TPad *pad_top = new TPad("pad_top", "Top Pad", 0, 0.5, 1, 1); + // pad_top->SetBottomMargin(0.001); + pad_top->SetBottomMargin(0.03); + pad_top->SetTopMargin(0.08); + pad_top->Draw(); + pad_top->cd(); + + gPad->SetLogz(); + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event->GetXaxis()->SetLabelSize(0); + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event->GetXaxis()->SetTitleSize(0); + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event->Draw(); + PutCaption_BeforeCorrection(run, -0.1, 0.2, 0.9); /* PutCaption(int run, double first_margin = -0.1, double pos_x = 0.2, double pos_y = 0.9) */ + + + c3->cd(); + TPad *pad_bottom = new TPad("pad_bottom", "Bottom Pad", 0, 0, 1, 0.5); + // pad_bottom->SetTopMargin(0.0001); + pad_bottom->SetTopMargin(0.001); + // pad_bottom->SetBottomMargin(0.12); + pad_bottom->Draw(); + pad_bottom->cd(); + + gPad->SetLogz(); + h2D_EventBcoSpacing_CorrectedMultiplicity_all_event->Draw(); + PutCaption_AfterCorrection(run, -0.1, 0.2, 0.99); /* PutCaption(int run, double first_margin = -0.1, double pos_x = 0.2, double pos_y = 0.9) */ + + c3->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/ForAPR/Combined_h2D_EventBcoSpacing_CorrectedMultiplicity_all_event_%d.pdf", run, run) ); + + + + file->Close(); + delete file; + delete c1; + delete c2; +} + +int GetNCollisionFromRunNum(int run){ + /* {run_number, {n_collision, open_time}} */ + std::vector< std::pair> > run_ncoll_open = { + + {66522, {100,60}}, /* physics run */ + {66682, {100,60}}, /* physics run */ + {68002, {100,60}}, /* physics run */ + {71345, {100,60}}, /* physics run */ + {71346, {126,60}}, /* physics run */ + {71347, {126,127}}, /* physics run */ + + {75519, {126,127}}, /* physics run */ + + {67542, {100,127}}, + {67544, {100,110}}, + {67545, {100,90}}, + //{67546, {100,80}}, + {67547, {100,60}}, + {67548, {100,40}}, + {67549, {100,25}}, + {67550, {2,127}}, + {67552, {2,110}}, + {67553, {2,90}}, + {67554, {2,80}}, + {67555, {2,60}}, + //{67556, {2,40}}, + {67557, {2,25}}, + {67558, {50,127}}, + {67559, {50,110}}, + {67560, {50,90}}, + {67563, {50,60}}, + {67564, {50,40}}, + {67565, {50,25}}, + {67566, {50,80}}, + + {68007, {100,60}}, + {68008, {127,127}}, + {68009, {3,127}}, + {68010, {3,60}}, + {68012, {100,60}}, + {68013, {127,127}}, + {68014, {3,127}}, + {68015, {3,60}} + + }; + + int n_collision; + for (auto pair : run_ncoll_open){ + if (pair.first == run){ + n_collision = pair.second.first; + } + } + + return n_collision; + +} + +int GetOpenTimeFromRunNum(int run){ + std::vector< std::pair> > run_ncoll_open = { + + {66522, {100,60}}, /* physics run */ + {66682, {100,60}}, /* physics run */ + {68002, {100,60}}, /* physics run */ + {71345, {100,60}}, /* physics run */ + {71346, {126,60}}, /* physics run */ + {71347, {126,127}}, /* physics run */ + + {75519, {126,127}}, /* physics run */ + + {67542, {100,127}}, + {67544, {100,110}}, + {67545, {100,90}}, + //{67546, {100,80}}, + {67547, {100,60}}, + {67548, {100,40}}, + {67549, {100,25}}, + {67550, {2,127}}, + {67552, {2,110}}, + {67553, {2,90}}, + {67554, {2,80}}, + {67555, {2,60}}, + //{67556, {2,40}}, + {67557, {2,25}}, + {67558, {50,127}}, + {67559, {50,110}}, + {67560, {50,90}}, + {67563, {50,60}}, + {67564, {50,40}}, + {67565, {50,25}}, + {67566, {50,80}}, + + {68007, {100,60}}, + {68008, {127,127}}, + {68009, {3,127}}, + {68010, {3,60}}, + {68012, {100,60}}, + {68013, {127,127}}, + {68014, {3,127}}, + {68015, {3,60}} + }; + + int open_time; + for (auto pair : run_ncoll_open){ + if (pair.first == run){ + open_time = pair.second.second; + } + } + + return open_time; +} + +int FindEdgeBin(TH1D* hist, int peak_bin){ + double threshold = 0.0000075; + //double threshold = 0.0075; + double height_ratio = 1; + int this_bin = peak_bin; + + for (int i=0; i < hist->GetNbinsX(); i--){ + this_bin = GetPreviousWithoutUnderflow(this_bin); // This is basically identical to (this_bin - 1), except in case of reaching the underflow bin. + height_ratio = hist->GetBinContent(this_bin) / hist->GetBinContent(peak_bin); + if (height_ratio < threshold) { + return this_bin; + } + } + + std::cerr << "No edge found!" << std::endl; + exit(1); + +} + +TH1D* ShiftHistoWithoutDupulication(TH1D* hist, int offset){ + + TH1D* hist_shifted = (TH1D*)hist->Clone("h_bco_diff_shifted"); + + int bin_num_before; + for (int i=0; i < hist->GetNbinsX(); i++) { + bin_num_before = AddOffsetWithoutOverflow(1+i, offset); + hist_shifted->SetBinContent(1+i, hist->GetBinContent(bin_num_before)); + hist_shifted->SetBinError(1+i, hist->GetBinError(bin_num_before)); + } + + return hist_shifted; +} + +int GetPreviousWithoutUnderflow(int bin){ + if (bin == 1) { + return 128; + } else { + return bin-1; + } +} + +int AddOffsetWithoutOverflow(int this_bin, int offset) { + if ( this_bin + offset == 128){ + return 128; + } else { + return (this_bin + offset)%128; + } +} + + +void DrawBoxFromValue( TH2D* h2D_NInttHitInner_NInttHitOuter, double x_val_min, double x_val_max, double y_val_min, double y_val_max, int color ){ + int xbin_min = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->FindBin(x_val_min); + int xbin_max = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->FindBin(x_val_max); + int ybin_min = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->FindBin(y_val_min); + int ybin_max = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->FindBin(y_val_max); + + double x1 = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->GetBinLowEdge(xbin_min); + double x2 = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->GetBinUpEdge(xbin_max); + double y1 = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->GetBinLowEdge(ybin_min); + double y2 = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->GetBinUpEdge(ybin_max); + + TBox* box = new TBox(x1, y1, x2, y2); + box->SetLineColor(color); + box->SetLineWidth(2); + box->SetFillStyle(0); + box->Draw("same"); +} + diff --git a/general_codes/ryotaro/CarriedOverHits/macro/MakeCanvasForPreliminary.C b/general_codes/ryotaro/CarriedOverHits/macro/MakeCanvasForPreliminary.C new file mode 100644 index 0000000..ee3933c --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/macro/MakeCanvasForPreliminary.C @@ -0,0 +1,446 @@ +#include "utilities/sPhenixStyle.C" +#include "MyUtilities/my.cc" + + +int FindEdgeBin(TH1D* hist, int peak_bin); +TH1D* ShiftHistoWithoutDupulication(TH1D* hist, int offset); +int AddOffsetWithoutOverflow(int this_bin, int offset); +int GetPreviousWithoutUnderflow(int bin); +void DrawBoxFromValue( TH2D* h2D_NInttHitInner_NInttHitOuter, double x_val_min, double x_val_max, double y_val_min, double y_val_max, int color ); + +void MakeCanvasForPreliminary(int run){ + std::string tag = "CloneRemoved"; + // std::string tag = "Special"; + // std::string tag = "Raw"; + + SetsPhenixStyle(); + + // std::string counts = "100k"; + int n_collision = GetNCollisionFromRunNum(run); + int open_time = GetOpenTimeFromRunNum(run); + + // std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/%s/10M_%d_%s.root", run, tag.c_str(), run, tag.c_str()); + std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/4646files_Criteria2_woTTree_0hitHandled_halfladderCutted.root"); + TFile* file = TFile::Open(filename.c_str()); + if ( !file || file->IsZombie() ){ + std::cout << "Error: cannot open file " << filename << std::endl; + exit(1); + } + + + TH2D* h2D_NInttHitInner_NInttHitOuter = (TH2D*)file->Get("h2D_NInttHitInner_NInttHitOuter"); + TH2D* h2D_NInttHitInner_NInttHitOuter_corrected = (TH2D*)file->Get("h2D_NInttHitInner_NInttHitOuter_corrected"); + // TH2D* h2D_NCarriedInner_NCarriedOuter = (TH2D*)file->Get("h2D_NCarriedInner_NCarriedOuter"); + // TH2D* h2D_Halfladder_NCOH = (TH2D*)file->Get("h2D_Halfladder_NCOH"); + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent = (TH2D*)file->Get("h2D_EventBcoSpacing_NHitInPreviousEvent"); + // TH2D* h2D_EventBcoSpacing_NCohInNextEvent = (TH2D*)file->Get("h2D_EventBcoSpacing_NCohInNextEvent"); + // TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder = (TH2D*)file->Get("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder"); + // TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_bychip = (TH2D*)file->Get("h2D_EventBcoSpacing_NHitInPreviousEvent_bychip"); + // TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner = (TH2D*)file->Get("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner"); + // TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer = (TH2D*)file->Get("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer"); + + // TH2D* h2D_MisasignedBcoDiff_NHitInPreviousEvent = (TH2D*)file->Get("h2D_MisasignedBcoDiff_NHitInPreviousEvent"); + // TH2D* h2D_MisasignedBcoDiff_NCohInNextEvent = (TH2D*)file->Get("h2D_MisasignedBcoDiff_NCohInNextEvent"); + + // TH2D* h2D_NInttHitInner_NInttHitOuter_narrow_spacing = (TH2D*)file->Get("h2D_NInttHitInner_NInttHitOuter_narrow_spacing_"); + + TH1D* h1D_Multiplicity_long_event_interval = (TH1D*)file->Get("h1D_Multiplicity_long_event_interval"); + TH1D* h1D_Multiplicity_short_event_interval = (TH1D*)file->Get("h1D_Multiplicity_short_event_interval"); + TH1D* h1D_Multiplicity_short_event_interval_corrected = (TH1D*)file->Get("h1D_Multiplicity_short_event_interval_corrected"); + TGraph* g_ratio_correctedMultiplicity_over_trueMultiplicity = new TGraph(); + + + TCanvas* c1 = new TCanvas("c1", "Title", 900, 600); + c1->cd(); + h2D_NInttHitInner_NInttHitOuter->SetTitle(Form("h2D_NInttHitInner_NInttHitOuter(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_NInttHitInner_NInttHitOuter->GetXaxis()->SetTitle("Number of INTT Hits at inner barrel"); + h2D_NInttHitInner_NInttHitOuter->GetYaxis()->SetTitle("Number of INTT Hits at outer barrel"); + h2D_NInttHitInner_NInttHitOuter->GetXaxis()->SetNdivisions(205); + h2D_NInttHitInner_NInttHitOuter->GetYaxis()->SetNdivisions(205); + h2D_NInttHitInner_NInttHitOuter->Draw(); + PutCaption_BeforeCorrection(run, -0.1, 0.2, 0.94); + + TPad* inset_1 = new TPad("inset","inset", 0.57, 0.15, 0.94, 0.52); // (x1,y1,x2,y2) in NDC + inset_1->SetFillStyle(0); + inset_1->SetBorderMode(0); + // inset->SetLineColor(kBlack); + inset_1->SetMargin(0.18, 0.05, 0.18, 0.05); // (L,R,B,T) 余白調整 + inset_1->Draw(); + + inset_1->cd(); + TH2D* h2D_NInttHitInner_NInttHitOuter_inset = (TH2D*)h2D_NInttHitInner_NInttHitOuter->Clone("h2_in"); + h2D_NInttHitInner_NInttHitOuter_inset->SetTitle(";;"); + h2D_NInttHitInner_NInttHitOuter_inset->GetXaxis()->SetRangeUser(0,3000); + h2D_NInttHitInner_NInttHitOuter_inset->GetYaxis()->SetRangeUser(0,3000); + h2D_NInttHitInner_NInttHitOuter_inset->GetXaxis()->SetNdivisions(202); + h2D_NInttHitInner_NInttHitOuter_inset->GetYaxis()->SetNdivisions(202); + h2D_NInttHitInner_NInttHitOuter_inset->Draw("COL"); + inset_1->SetLogz(); + h2D_NInttHitInner_NInttHitOuter_inset->GetXaxis()->SetLabelSize(0.1); + h2D_NInttHitInner_NInttHitOuter_inset->GetYaxis()->SetLabelSize(0.1); + + c1->SetLogz(); + c1->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/%s/ForPreliminary/h2D_NInttHitInner_NInttHitOuter_%d_%s.pdf", run, tag.c_str(), run, tag.c_str()) ); + TF1 *f = new TF1("f","x",0,10000); + f->Draw("same"); + c1->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/%s/ForPreliminary/h2D_NInttHitInner_NInttHitOuter_with_line_%d_%s.pdf", run, tag.c_str(), run, tag.c_str()) ); + h2D_NInttHitInner_NInttHitOuter->GetXaxis()->SetRangeUser(0,3500); + h2D_NInttHitInner_NInttHitOuter->GetYaxis()->SetRangeUser(0,3500); + h2D_NInttHitInner_NInttHitOuter->Draw(); + c1->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/%s/ForPreliminary/h2D_NInttHitInner_NInttHitOuter_zoomed_%d_%s.pdf", run, tag.c_str(), run, tag.c_str()) ); + + + + + + TCanvas* c2 = new TCanvas("c2", "Title", 900, 600); + c2->cd(); + h2D_NInttHitInner_NInttHitOuter_corrected->SetTitle(Form("h2D_NInttHitInner_NInttHitOuter_corrected(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_NInttHitInner_NInttHitOuter_corrected->GetXaxis()->SetTitle("Number of INTT Hits at inner barrel"); + h2D_NInttHitInner_NInttHitOuter_corrected->GetYaxis()->SetTitle("Number of INTT Hits at outer barrel"); + h2D_NInttHitInner_NInttHitOuter_corrected->GetXaxis()->SetNdivisions(205); + h2D_NInttHitInner_NInttHitOuter_corrected->GetYaxis()->SetNdivisions(205); + h2D_NInttHitInner_NInttHitOuter_corrected->Draw(); + PutCaption_AfterCorrection(run, -0.1, 0.2, 0.94); + c2->SetLogz(); + + TPad* inset_2 = new TPad("inset_2","inset_2", 0.57, 0.15, 0.94, 0.52); // (x1,y1,x2,y2) in NDC + inset_2->SetFillStyle(0); + inset_2->SetBorderMode(0); + // inset->SetLineColor(kBlack); + inset_2->SetMargin(0.18, 0.05, 0.18, 0.05); // (L,R,B,T) 余白調整 + inset_2->Draw(); + + inset_2->cd(); + TH2D* h2D_NInttHitInner_NInttHitOuter_corrected_inset = (TH2D*)h2D_NInttHitInner_NInttHitOuter_corrected->Clone("h2_in"); + h2D_NInttHitInner_NInttHitOuter_corrected_inset->SetTitle(";;"); + h2D_NInttHitInner_NInttHitOuter_corrected_inset->GetXaxis()->SetRangeUser(0,3000); + h2D_NInttHitInner_NInttHitOuter_corrected_inset->GetYaxis()->SetRangeUser(0,3000); + h2D_NInttHitInner_NInttHitOuter_corrected_inset->GetXaxis()->SetNdivisions(202); + h2D_NInttHitInner_NInttHitOuter_corrected_inset->GetYaxis()->SetNdivisions(202); + h2D_NInttHitInner_NInttHitOuter_corrected_inset->Draw("COL"); + inset_2->SetLogz(); + h2D_NInttHitInner_NInttHitOuter_corrected_inset->GetXaxis()->SetLabelSize(0.1); + h2D_NInttHitInner_NInttHitOuter_corrected_inset->GetYaxis()->SetLabelSize(0.1); + + c2->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/%s/ForPreliminary/h2D_NInttHitInner_NInttHitOuter_corrected_%d_%s.pdf", run, tag.c_str(), run, tag.c_str()) ); + h2D_NInttHitInner_NInttHitOuter_corrected->GetXaxis()->SetRangeUser(0,3500); + h2D_NInttHitInner_NInttHitOuter_corrected->GetYaxis()->SetRangeUser(0,3500); + h2D_NInttHitInner_NInttHitOuter_corrected->Draw(); + c2->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/%s/ForPreliminary/h2D_NInttHitInner_NInttHitOuter_corrected_zoomed_%d_%s.pdf", run, tag.c_str(), run, tag.c_str()) ); + + // TCanvas* c3 = new TCanvas("c3", "Title", 900, 600); + // c3->cd(); + // h2D_EventBcoSpacing_NCohInNextEvent_->SetTitle(Form("h2D_EventBcoSpacing_NCohInNextEvent_(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + // h2D_EventBcoSpacing_NCohInNextEvent_->Draw(); + // c3->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NCarriedHits.pdf", run) ); + + // TCanvas* c4 = new TCanvas("c4", "Title", 900, 600); + // c4->cd(); + // h2D_NCarriedInner_NCarriedOuter->SetTitle(Form("h2D_NCarriedInner_NCarriedOuter(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + // h2D_NCarriedInner_NCarriedOuter->Draw(); + // c4->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_NCarriedInner_NCarriedOuter.pdf", run) ); + // h2D_NCarriedInner_NCarriedOuter->GetXaxis()->SetRangeUser(0,1000); + // h2D_NCarriedInner_NCarriedOuter->GetYaxis()->SetRangeUser(0,1000); + // h2D_NCarriedInner_NCarriedOuter->Draw(); + // c4->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_NCarriedInner_NCarriedOuter_zoomed.pdf", run) ); + + // TCanvas* c5 = new TCanvas("c5", "Title", 900, 600); + // c5->cd(); + // h2D_Halfladder_NCOH->SetTitle(Form("h2D_Halfladder_NCOH(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + // h2D_Halfladder_NCOH->Draw(); + // c5->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_Halfladder_NCOH.pdf", run) ); + + TCanvas* c6 = new TCanvas("c6", "Title", 900, 600); + c6->cd(); + h2D_EventBcoSpacing_NHitInPreviousEvent->SetTitle(Form("h2D_EventBcoSpacing_NHitInPreviousEvent(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_EventBcoSpacing_NHitInPreviousEvent->GetXaxis()->SetTitle("Event interval to the next event [Beam Collision Clock 9.4MHz]"); + h2D_EventBcoSpacing_NHitInPreviousEvent->GetXaxis()->SetNdivisions(407); + h2D_EventBcoSpacing_NHitInPreviousEvent->GetYaxis()->SetTitle("Number of INTT hits"); + h2D_EventBcoSpacing_NHitInPreviousEvent->GetYaxis()->SetNdivisions(210); + h2D_EventBcoSpacing_NHitInPreviousEvent->Draw(); + c6->SetLogz(); + PutCaption(run, -0.1, 0.2, 0.94); /* PutCaption(int run, double first_margin = -0.1, double pos_x = 0.2, double pos_y = 0.9) */ + c6->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/%s/ForPreliminary/h2D_EventBcoSpacing_NHitInPreviousEvent_%d_%s.pdf", run, tag.c_str(), run, tag.c_str()) ); + + // TCanvas* c7 = new TCanvas("c7", "Title", 900, 600); + // c7->cd(); + // h2D_EventBcoSpacing_NCohInNextEvent->SetTitle(Form("h2D_EventBcoSpacing_NCohInNextEvent(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + // h2D_EventBcoSpacing_NCohInNextEvent->Draw(); + // c7->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NCohInNextEvent.pdf", run) ); + + // TCanvas* c8 = new TCanvas("c8", "Title", 900, 600); + // c8->cd(); + // h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder->SetTitle(Form("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + // h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder->Draw(); + // c8->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder.pdf", run) ); + + // TCanvas* c9 = new TCanvas("c9", "Title", 900, 600); + // c9->cd(); + // h2D_EventBcoSpacing_NHitInPreviousEvent_bychip->SetTitle(Form("h2D_EventBcoSpacing_NHitInPreviousEvent_bychip(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + // h2D_EventBcoSpacing_NHitInPreviousEvent_bychip->Draw(); + // c9->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NHitInPreviousEvent_bychip.pdf", run) ); + + // TCanvas* c10 = new TCanvas("c10", "Title", 900, 600); + // c10->cd(); + // h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner->SetTitle(Form("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + // h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner->Draw(); + // c10->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner.pdf", run) ); + + // TCanvas* c11 = new TCanvas("c11", "Title", 900, 600); + // c11->cd(); + // h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer->SetTitle(Form("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + // h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer->Draw(); + // c11->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer.pdf", run) ); + + // TCanvas* c12 = new TCanvas("c12", "Title", 900, 600); + // c12->cd(); + // h2D_MisasignedBcoDiff_NHitInPreviousEvent->SetTitle(Form("h2D_MisasignedBcoDiff_NHitInPreviousEvent(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + // h2D_MisasignedBcoDiff_NHitInPreviousEvent->Draw(); + // c12->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_MisasignedBcoDiff_NHitInPreviousEvent.pdf", run) ); + + // TCanvas* c13 = new TCanvas("c13", "Title", 900, 600); + // c13->cd(); + // h2D_MisasignedBcoDiff_NCohInNextEvent->SetTitle(Form("h2D_MisasignedBcoDiff_NCohInNextEvent(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + // h2D_MisasignedBcoDiff_NCohInNextEvent->Draw(); + // c13->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_MisasignedBcoDiff_NCohInNextEvent.pdf", run) ); + + // TCanvas* c14 = new TCanvas("c14", "Title", 900, 600); + // c14->cd(); + // h2D_NInttHitInner_NInttHitOuter_narrow_spacing->SetTitle(Form("h2D_NInttHitInner_NInttHitOuter_narrow_spacing(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + // h2D_NInttHitInner_NInttHitOuter_narrow_spacing->Draw(); + // c14->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_NInttHitInner_NInttHitOuter_narrow_spacing.pdf", run) ); + + TCanvas* c15 = new TCanvas("c15", "Title", 900, 600); + c15->cd(); + h1D_Multiplicity_long_event_interval->GetXaxis()->SetTitle("Multiplicity"); + h1D_Multiplicity_long_event_interval->GetYaxis()->SetTitle("Entries (normalized)"); + + h1D_Multiplicity_long_event_interval = dynamic_cast(h1D_Multiplicity_long_event_interval->Rebin(50,"h1D_Multiplicity_long_event_interval_new")); + h1D_Multiplicity_short_event_interval = dynamic_cast(h1D_Multiplicity_short_event_interval->Rebin(50, "h1D_Multiplicity_short_event_interval_new")); + h1D_Multiplicity_short_event_interval_corrected = dynamic_cast(h1D_Multiplicity_short_event_interval_corrected->Rebin(50, "h1D_Multiplicity_short_event_interval_corrected_new")); + + h1D_Multiplicity_long_event_interval->GetXaxis()->SetRangeUser(0,20000); + h1D_Multiplicity_long_event_interval->GetXaxis()->SetNdivisions(107); + h1D_Multiplicity_long_event_interval->SetMinimum(0.01); + h1D_Multiplicity_long_event_interval->SetMaximum(5000); + h1D_Multiplicity_long_event_interval->SetMarkerColor(kBlack); + h1D_Multiplicity_long_event_interval->SetLineColor(kBlack); + h1D_Multiplicity_short_event_interval->SetMarkerColor(kRed); + h1D_Multiplicity_short_event_interval->SetLineColor(kRed); + h1D_Multiplicity_short_event_interval_corrected->SetMarkerColor(kBlue); + h1D_Multiplicity_short_event_interval_corrected->SetLineColor(kBlue); + + h1D_Multiplicity_long_event_interval->Draw(); + h1D_Multiplicity_short_event_interval->Draw("same"); + h1D_Multiplicity_short_event_interval_corrected->Draw("same"); + c15->SetLogy(); + + TLegend* l = new TLegend(0.3,0.7,0.9,0.9); + l->AddEntry(h1D_Multiplicity_long_event_interval,"Interval#geq 80 BCO"); + l->AddEntry(h1D_Multiplicity_short_event_interval,"Interval#leq 80 BCO (before push-back)"); + l->AddEntry(h1D_Multiplicity_short_event_interval_corrected,"Interval#leq 80 BCO (after push-back)"); + l->Draw("same"); + // PutCaption(run); + c15->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/%s/ForPreliminary/h1D_Multiplicity_long_event_interval_%d_%s.pdf", run, tag.c_str(), run, tag.c_str()) ); + + TCanvas* c16 = new TCanvas("c16", "Title", 900, 600); + c16->cd(); + for (int i=1; i< h1D_Multiplicity_short_event_interval_corrected->GetNbinsX(); i++) { + g_ratio_correctedMultiplicity_over_trueMultiplicity->SetPoint(i, h1D_Multiplicity_short_event_interval_corrected->GetBinCenter(i), h1D_Multiplicity_short_event_interval_corrected->GetBinContent(i)/h1D_Multiplicity_long_event_interval->GetBinContent(i)); + } + g_ratio_correctedMultiplicity_over_trueMultiplicity->Draw("ap"); + g_ratio_correctedMultiplicity_over_trueMultiplicity->SetTitle("; Multiplicity; Blue / Black"); + g_ratio_correctedMultiplicity_over_trueMultiplicity->GetXaxis()->SetNdivisions(107); + g_ratio_correctedMultiplicity_over_trueMultiplicity->GetXaxis()->SetRangeUser(0,20000); + g_ratio_correctedMultiplicity_over_trueMultiplicity->GetYaxis()->SetRangeUser(0,5); + TF1* constant1 = new TF1("constant (1)","1",0,20000); + constant1->SetLineColor(kGreen); + constant1->Draw("same"); + c16->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/%s/ForPreliminary/g_ratio_correctedMultiplicity_over_trueMultiplicity_%d_%s.pdf", run, tag.c_str(), run, tag.c_str()) ); + + + file->Close(); + delete file; + delete c1; + delete c2; + // delete c3; + // delete c4; + // delete c5; +} + +int GetNCollisionFromRunNum(int run){ + /* {run_number, {n_collision, open_time}} */ + std::vector< std::pair> > run_ncoll_open = { + + {66522, {100,60}}, /* physics run */ + {66682, {100,60}}, /* physics run */ + {68002, {100,60}}, /* physics run */ + {71345, {100,60}}, /* physics run */ + {71346, {126,60}}, /* physics run */ + {71347, {126,127}}, /* physics run */ + + {67542, {100,127}}, + {67544, {100,110}}, + {67545, {100,90}}, + //{67546, {100,80}}, + {67547, {100,60}}, + {67548, {100,40}}, + {67549, {100,25}}, + {67550, {2,127}}, + {67552, {2,110}}, + {67553, {2,90}}, + {67554, {2,80}}, + {67555, {2,60}}, + //{67556, {2,40}}, + {67557, {2,25}}, + {67558, {50,127}}, + {67559, {50,110}}, + {67560, {50,90}}, + {67563, {50,60}}, + {67564, {50,40}}, + {67565, {50,25}}, + {67566, {50,80}}, + + {68007, {100,60}}, + {68008, {127,127}}, + {68009, {3,127}}, + {68010, {3,60}}, + {68012, {100,60}}, + {68013, {127,127}}, + {68014, {3,127}}, + {68015, {3,60}} + + }; + + int n_collision; + for (auto pair : run_ncoll_open){ + if (pair.first == run){ + n_collision = pair.second.first; + } + } + + return n_collision; + +} + +int GetOpenTimeFromRunNum(int run){ + std::vector< std::pair> > run_ncoll_open = { + + {66522, {100,60}}, /* physics run */ + {66682, {100,60}}, /* physics run */ + {68002, {100,60}}, /* physics run */ + {71345, {100,60}}, /* physics run */ + {71346, {126,60}}, /* physics run */ + {71347, {126,127}}, /* physics run */ + + {67542, {100,127}}, + {67544, {100,110}}, + {67545, {100,90}}, + //{67546, {100,80}}, + {67547, {100,60}}, + {67548, {100,40}}, + {67549, {100,25}}, + {67550, {2,127}}, + {67552, {2,110}}, + {67553, {2,90}}, + {67554, {2,80}}, + {67555, {2,60}}, + //{67556, {2,40}}, + {67557, {2,25}}, + {67558, {50,127}}, + {67559, {50,110}}, + {67560, {50,90}}, + {67563, {50,60}}, + {67564, {50,40}}, + {67565, {50,25}}, + {67566, {50,80}}, + + {68007, {100,60}}, + {68008, {127,127}}, + {68009, {3,127}}, + {68010, {3,60}}, + {68012, {100,60}}, + {68013, {127,127}}, + {68014, {3,127}}, + {68015, {3,60}} + }; + + int open_time; + for (auto pair : run_ncoll_open){ + if (pair.first == run){ + open_time = pair.second.second; + } + } + + return open_time; +} + +int FindEdgeBin(TH1D* hist, int peak_bin){ + double threshold = 0.0000075; + //double threshold = 0.0075; + double height_ratio = 1; + int this_bin = peak_bin; + + for (int i=0; i < hist->GetNbinsX(); i--){ + this_bin = GetPreviousWithoutUnderflow(this_bin); // This is basically identical to (this_bin - 1), except in case of reaching the underflow bin. + height_ratio = hist->GetBinContent(this_bin) / hist->GetBinContent(peak_bin); + if (height_ratio < threshold) { + return this_bin; + } + } + + std::cerr << "No edge found!" << std::endl; + exit(1); + +} + +TH1D* ShiftHistoWithoutDupulication(TH1D* hist, int offset){ + + TH1D* hist_shifted = (TH1D*)hist->Clone("h_bco_diff_shifted"); + + int bin_num_before; + for (int i=0; i < hist->GetNbinsX(); i++) { + bin_num_before = AddOffsetWithoutOverflow(1+i, offset); + hist_shifted->SetBinContent(1+i, hist->GetBinContent(bin_num_before)); + hist_shifted->SetBinError(1+i, hist->GetBinError(bin_num_before)); + } + + return hist_shifted; +} + +int GetPreviousWithoutUnderflow(int bin){ + if (bin == 1) { + return 128; + } else { + return bin-1; + } +} + +int AddOffsetWithoutOverflow(int this_bin, int offset) { + if ( this_bin + offset == 128){ + return 128; + } else { + return (this_bin + offset)%128; + } +} + + +void DrawBoxFromValue( TH2D* h2D_NInttHitInner_NInttHitOuter, double x_val_min, double x_val_max, double y_val_min, double y_val_max, int color ){ + int xbin_min = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->FindBin(x_val_min); + int xbin_max = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->FindBin(x_val_max); + int ybin_min = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->FindBin(y_val_min); + int ybin_max = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->FindBin(y_val_max); + + double x1 = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->GetBinLowEdge(xbin_min); + double x2 = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->GetBinUpEdge(xbin_max); + double y1 = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->GetBinLowEdge(ybin_min); + double y2 = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->GetBinUpEdge(ybin_max); + + TBox* box = new TBox(x1, y1, x2, y2); + box->SetLineColor(color); + box->SetLineWidth(2); + box->SetFillStyle(0); + box->Draw("same"); +} + diff --git a/general_codes/ryotaro/CarriedOverHits/macro/MakeCorrectedMultiplicityByInterval.C b/general_codes/ryotaro/CarriedOverHits/macro/MakeCorrectedMultiplicityByInterval.C new file mode 100644 index 0000000..307d069 --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/macro/MakeCorrectedMultiplicityByInterval.C @@ -0,0 +1,216 @@ +#include "utilities/sPhenixStyle.C" + +#include +#include +#include + +namespace +{ + struct IntervalRegion + { + std::string hist_name; + std::string legend_label; + std::string draw_label; + int color; + int line_style; + double min_interval; + double max_interval; + bool include_upper_edge; + }; + + bool IsInRegion(const IntervalRegion& region, const int64_t interval) + { + if (interval < region.min_interval) { + return false; + } + + if (region.include_upper_edge) { + return interval >= region.min_interval && interval <= region.max_interval; + } + + return interval >= region.min_interval && interval < region.max_interval; + } +} + +void MakeCorrectedMultiplicityByInterval() +{ + SetsPhenixStyle(); + + const std::string input_filename = + "/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/completed/100files_Criteria2_TTree_0hitHandled_CloneHotRemoved.root"; + // "/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/4646files_Criteria2_TTree_0hitHandled_halfladderCutted.root"; + const std::string output_filename = + "/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/h1D_CorrectedMultiplicity_interval_by_interval_75519.pdf"; + + TFile* file = TFile::Open(input_filename.c_str()); + if (!file || file->IsZombie()) { + std::cerr << "Error: cannot open file " << input_filename << std::endl; + return; + } + + TTree* tree = static_cast(file->Get("tree")); + if (!tree) { + std::cerr << "Error: cannot find TTree named \"tree\"" << std::endl; + file->Close(); + delete file; + return; + } + + tree->SetBranchStatus("*", 0); + tree->SetBranchStatus("n_hit_inner", 1); + tree->SetBranchStatus("n_hit_outer", 1); + tree->SetBranchStatus("num_of_carried_hits", 1); + tree->SetBranchStatus("interval_from_previous", 1); + tree->SetBranchStatus("is_MBDNS_tight_vtx10cm", 1); + + int n_hit_inner = 0; + int n_hit_outer = 0; + int num_of_carried_hits = 0; + int64_t interval_from_previous = 0; + bool is_MBDNS_tight_vtx10cm = false; + + tree->SetBranchAddress("n_hit_inner", &n_hit_inner); + tree->SetBranchAddress("n_hit_outer", &n_hit_outer); + tree->SetBranchAddress("num_of_carried_hits", &num_of_carried_hits); + tree->SetBranchAddress("interval_from_previous", &interval_from_previous); + tree->SetBranchAddress("is_MBDNS_tight_vtx10cm", &is_MBDNS_tight_vtx10cm); + + std::vector regions = { + {"h_interval_lt23", "interval < 23", "interval < 23", kBlack, 1, 0, 23, false}, + {"h_interval_23to30", "23 #leq interval < 30", "23 #leq interval < 30", kRed + 1, 1, 23, 30, false}, + {"h_interval_30to40", "30 #leq interval < 40", "30 #leq interval < 40", kBlue + 1, 1, 30, 40, false}, + {"h_interval_40to50", "40 #leq interval < 50", "40 #leq interval < 50", kGreen + 2, 1, 40, 50, false}, + {"h_interval_50to60", "50 #leq interval < 60", "50 #leq interval < 60", kOrange + 7, 1, 50, 60, false}, + {"h_interval_60to70", "60 #leq interval < 70", "60 #leq interval < 70", kMagenta + 1, 1, 60, 70, false}, + {"h_interval_70to80", "70 #leq interval < 80", "70 #leq interval < 80", kCyan + 2, 1, 70, 80, false}, + {"h_interval_ge80", "80 #leq interval", "80 #leq interval", kGray + 2, 2, 80, 999999999, true} + }; + + std::vector histograms; + histograms.reserve(regions.size()); + std::vector filled_event_counts(regions.size(), 0); + + for (const auto& region : regions) { + TH1D* hist = new TH1D( + region.hist_name.c_str(), + "Corrected multiplicity by event interval;Corrected multiplicity;Entries (normalized)", + 5000, + 0, + 20000 + ); + hist->SetDirectory(nullptr); + hist->SetLineColor(region.color); + hist->SetMarkerColor(region.color); + hist->SetLineStyle(region.line_style); + hist->SetLineWidth(2); + histograms.push_back(hist); + } + + const Long64_t n_entries = tree->GetEntries(); + std::cout << "Entries = " << n_entries << std::endl; + + for (Long64_t i = 0; i < n_entries; ++i) { + if (i % 100000 == 0) { + std::cout << "Processing entry " << i << std::endl; + } + + tree->GetEntry(i); + + if (!is_MBDNS_tight_vtx10cm) { + continue; + } + + const int corrected_multiplicity = n_hit_inner + n_hit_outer + num_of_carried_hits; + + for (std::size_t iregion = 0; iregion < regions.size(); ++iregion) { + if (!IsInRegion(regions[iregion], interval_from_previous)) { + continue; + } + + bool should_fill = true; + if (iregion <= 4 && num_of_carried_hits <= 0) { + should_fill = false; + } + + if (should_fill) { + histograms[iregion]->Fill(corrected_multiplicity); + filled_event_counts[iregion]++; + } + break; + } + } + + std::vector rebinned_histograms; + rebinned_histograms.reserve(histograms.size()); + double maximum = 0.0; + + for (std::size_t iregion = 0; iregion < histograms.size(); ++iregion) { + TH1D* rebinned = static_cast( + histograms[iregion]->Rebin(50, Form("%s_rebinned", histograms[iregion]->GetName())) + ); + rebinned->SetDirectory(nullptr); + rebinned->SetLineColor(histograms[iregion]->GetLineColor()); + rebinned->SetMarkerColor(histograms[iregion]->GetMarkerColor()); + rebinned->SetLineStyle(histograms[iregion]->GetLineStyle()); + rebinned->SetLineWidth(histograms[iregion]->GetLineWidth()); + + const double integral = rebinned->Integral(); + if (integral > 0) { + rebinned->Scale(1.0 / integral); + } + + if (rebinned->GetMaximum() > maximum) { + maximum = rebinned->GetMaximum(); + } + + rebinned_histograms.push_back(rebinned); + } + + TCanvas* canvas = new TCanvas("c_corrected_multiplicity_by_interval", "Corrected multiplicity by interval", 900, 700); + canvas->cd(); + canvas->SetLogy(); + + TLegend* legend = new TLegend(0.52, 0.55, 0.90, 0.93); + legend->SetBorderSize(0); + legend->SetFillStyle(0); + legend->SetTextSize(0.028); + + for (std::size_t iregion = 0; iregion < rebinned_histograms.size(); ++iregion) { + rebinned_histograms[iregion]->SetMinimum(1e-5); + rebinned_histograms[iregion]->SetMaximum(maximum * 50.0); + rebinned_histograms[iregion]->GetXaxis()->SetRangeUser(0, 20000); + rebinned_histograms[iregion]->GetXaxis()->SetNdivisions(107); + rebinned_histograms[iregion]->GetYaxis()->SetTitleOffset(1.4); + + const char* draw_option = (iregion == 0) ? "hist" : "hist same"; + rebinned_histograms[iregion]->Draw(draw_option); + + const std::string legend_text = Form("%s (N=%lld)", regions[iregion].draw_label.c_str(), filled_event_counts[iregion]); + legend->AddEntry(rebinned_histograms[iregion], legend_text.c_str(), "l"); + } + + legend->Draw(); + + TLatex latex; + latex.SetNDC(); + latex.SetTextSize(0.035); + latex.DrawLatex(0.18, 0.92, "Run 75519, halfladder-cutted tree"); + latex.DrawLatex(0.18, 0.87, "MBDNS tight, |vtx| < 10 cm"); + // latex.SetTextSize(0.028); + latex.DrawLatex(0.18, 0.77, "For interval < 60, only carryover"); + latex.DrawLatex(0.18, 0.72, " events are filled"); + + canvas->Print(output_filename.c_str()); + + file->Close(); + delete file; + delete legend; + delete canvas; + + for (auto* hist : rebinned_histograms) { + delete hist; + } + for (auto* hist : histograms) { + delete hist; + } +} diff --git a/general_codes/ryotaro/CarriedOverHits/macro/MyUtilities/my.cc b/general_codes/ryotaro/CarriedOverHits/macro/MyUtilities/my.cc new file mode 100644 index 0000000..4d2cf5e --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/macro/MyUtilities/my.cc @@ -0,0 +1,125 @@ +int GetNCollisionFromRunNum(int run); +int GetOpenTimeFromRunNum(int run); + +std::string GetDate(){ + // return "5/13/2025"; // use this once the dete is determined + TDatime dt; + int year = dt.GetYear(); + int month = dt.GetMonth(); + int day = dt.GetDay(); + + // format: mm/dd/yyyy + std::stringstream ss; + ss << month << "/" << day << "/" << year; + + return ss.str(); +} + +void PutCaption(int run, double first_margin = -0.1, double pos_x = 0.2, double pos_y = 0.9){ +/*from Genki*/ + TLatex* tex = new TLatex(); + double line_height = 0.055; // no need to change + // double first_margin = -0.1; // the margin from the top of the canvas to the top line (date). You can modify + // double pos_x = 0.2; // you can modify + // double pos_y = 1.0 + first_margin; // - line_height; + + /* Date, you may want to change 0.65 to pos_x */ + //tex->DrawLatexNDC( pos_x, pos_y, + // string("#it{" + GetDate() + "}").c_str() ); + + // sPHENIX Internal or sPHENIX Prelimnary + pos_y -= line_height; +// tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Preliminary" ); + // tex->DrawLatexNDC( pos_x, 0.955, "#it{#bf{sPHENIX}} Internal" ); + tex->DrawLatexNDC( pos_x, 0.955, "#it{#bf{sPHENIX}} Preliminary" ); + //tex->DrawLatexNDC( pos_x, pos_y, string( string("#it{#bf{sPHENIX}} Preliminary ") + "#it{" + GetDate() + "}").c_str() ); + //tex->DrawLatexNDC( pos_x, pos_y, string("#it{#bf{sPHENIX}} Preliminary #it{05/16/2025}").c_str() ); + + tex->DrawLatexNDC( 0.77, 0.955, string("#it{08/21/2025}").c_str() ); + // p+p 200 GeV + // pos_y -= line_height ;// + 0.03; + tex->DrawLatexNDC( pos_x, pos_y, ("#it{Au+Au} #sqrt{s}_{NN} = 200 GeV") ); + + int n_collision = GetNCollisionFromRunNum(run); + int open_time = GetOpenTimeFromRunNum(run); + + pos_y -= line_height; + tex->DrawLatexNDC( pos_x, pos_y, Form("n_collision: %d, open_time: %d", n_collision, open_time) ); + + pos_y -= line_height; + tex->DrawLatexNDC( pos_x, pos_y, "Before offline correction for carry-over hits" ); +} + +void PutCaption_AfterCorrection(int run, double first_margin = -0.1, double pos_x = 0.2, double pos_y = 0.9){ +/*from Genki*/ + TLatex* tex = new TLatex(); + double line_height = 0.055; // no need to change + // double first_margin = -0.1; // the margin from the top of the canvas to the top line (date). You can modify + // double pos_x = 0.2; // you can modify + // double pos_y = 1.0 + first_margin; // - line_height; + + /* Date, you may want to change 0.65 to pos_x */ + //tex->DrawLatexNDC( pos_x, pos_y, + // string("#it{" + GetDate() + "}").c_str() ); + + // sPHENIX Internal or sPHENIX Prelimnary + // pos_y -= line_height; +// tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Preliminary" ); + // tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Internal" ); + // tex->DrawLatexNDC( pos_x, 0.955, "#it{#bf{sPHENIX}} Preliminary" ); + //tex->DrawLatexNDC( pos_x, pos_y, string( string("#it{#bf{sPHENIX}} Preliminary ") + "#it{" + GetDate() + "}").c_str() ); + //tex->DrawLatexNDC( pos_x, pos_y, string("#it{#bf{sPHENIX}} Preliminary #it{05/16/2025}").c_str() ); + + // tex->DrawLatexNDC( 0.77, 0.955, string("#it{08/21/2025}").c_str() ); + // p+p 200 GeV + pos_y -= line_height ;// + 0.03; + tex->DrawLatexNDC( pos_x, pos_y, ("#it{Au+Au} #sqrt{s}_{NN} = 200 GeV") ); + + int n_collision = GetNCollisionFromRunNum(run); + int open_time = GetOpenTimeFromRunNum(run); + + pos_y -= line_height; + tex->DrawLatexNDC( pos_x, pos_y, Form("n_collision: %d, open_time: %d", n_collision, open_time) ); + + pos_y -= line_height; + tex->DrawLatexNDC( pos_x, pos_y, "After offline correction for carry-over hits" ); + +} + +void PutCaption_BeforeCorrection(int run, double first_margin = -0.1, double pos_x = 0.2, double pos_y = 0.9){ +/*from Genki*/ + TLatex* tex = new TLatex(); + double line_height = 0.055; // no need to change + // double first_margin = -0.1; // the margin from the top of the canvas to the top line (date). You can modify + // double pos_x = 0.2; // you can modify + // double pos_y = 1.0 + first_margin; // - line_height; + + /* Date, you may want to change 0.65 to pos_x */ + //tex->DrawLatexNDC( pos_x, pos_y, + // string("#it{" + GetDate() + "}").c_str() ); + + // sPHENIX Internal or sPHENIX Prelimnary + // pos_y -= line_height; +// tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Preliminary" ); + // tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Internal" ); + // tex->DrawLatexNDC( pos_x, 0.955, "#it{#bf{sPHENIX}} Preliminary" ); + //tex->DrawLatexNDC( pos_x, pos_y, string( string("#it{#bf{sPHENIX}} Preliminary ") + "#it{" + GetDate() + "}").c_str() ); + //tex->DrawLatexNDC( pos_x, pos_y, string("#it{#bf{sPHENIX}} Preliminary #it{05/16/2025}").c_str() ); + + // tex->DrawLatexNDC( 0.77, 0.955, string("#it{08/21/2025}").c_str() ); + // p+p 200 GeV + pos_y -= line_height ;// + 0.03; + tex->DrawLatexNDC( pos_x, pos_y, ("#it{Au+Au} #sqrt{s}_{NN} = 200 GeV") ); + + int n_collision = GetNCollisionFromRunNum(run); + int open_time = GetOpenTimeFromRunNum(run); + + pos_y -= line_height; + tex->DrawLatexNDC( pos_x, pos_y, Form("n_collision: %d, open_time: %d", n_collision, open_time) ); + + pos_y -= line_height; + tex->DrawLatexNDC( pos_x, pos_y, "Before offline correction for carry-over hits" ); + +} + + diff --git a/general_codes/ryotaro/CarriedOverHits/macro/PrintPdfs.C b/general_codes/ryotaro/CarriedOverHits/macro/PrintPdfs.C new file mode 100644 index 0000000..99b5941 --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/macro/PrintPdfs.C @@ -0,0 +1,335 @@ +#include "utilities/sPhenixStyle.C" + +int GetNCollisionFromRunNum(int run); +int GetOpenTimeFromRunNum(int run); +int FindEdgeBin(TH1D* hist, int peak_bin); +TH1D* ShiftHistoWithoutDupulication(TH1D* hist, int offset); +int AddOffsetWithoutOverflow(int this_bin, int offset); +int GetPreviousWithoutUnderflow(int bin); +void DrawBoxFromValue( TH2D* h2D_NInttHitInner_NInttHitOuter, double x_val_min, double x_val_max, double y_val_min, double y_val_max, int color ); + +void PrintPdfs(int run){ + + SetsPhenixStyle(); + + // std::string counts = "100k"; + int n_collision = GetNCollisionFromRunNum(run); + int open_time = GetOpenTimeFromRunNum(run); + + // std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/completed/1M_%d.root", run, run); + std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/completed/30files_Criteria2_woTTree_0hitHandled.root", run); + TFile* file = TFile::Open(filename.c_str()); + if ( !file || file->IsZombie() ){ + std::cout << "Error: cannot open file " << filename << std::endl; + exit(1); + } + + + TH2D* h2D_NInttHitInner_NInttHitOuter = (TH2D*)file->Get("h2D_NInttHitInner_NInttHitOuter"); + TH2D* h2D_NInttHitInner_NInttHitOuter_corrected = (TH2D*)file->Get("h2D_NInttHitInner_NInttHitOuter_corrected"); + TH2D* h2D_EventBcoSpacing_NCohInNextEvent_ = (TH2D*)file->Get("h2D_EventBcoSpacing_NCohInNextEvent"); + TH2D* h2D_NCarriedInner_NCarriedOuter = (TH2D*)file->Get("h2D_NCarriedInner_NCarriedOuter"); + TH2D* h2D_Halfladder_NCOH = (TH2D*)file->Get("h2D_Halfladder_NCOH"); + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent = (TH2D*)file->Get("h2D_EventBcoSpacing_NHitInPreviousEvent"); + TH2D* h2D_EventBcoSpacing_NCohInNextEvent = (TH2D*)file->Get("h2D_EventBcoSpacing_NCohInNextEvent"); + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder = (TH2D*)file->Get("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder"); + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_bychip = (TH2D*)file->Get("h2D_EventBcoSpacing_NHitInPreviousEvent_bychip"); + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner = (TH2D*)file->Get("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner"); + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer = (TH2D*)file->Get("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer"); + + TH2D* h2D_MisasignedBcoDiff_NHitInPreviousEvent = (TH2D*)file->Get("h2D_MisasignedBcoDiff_NHitInPreviousEvent"); + TH2D* h2D_MisasignedBcoDiff_NCohInNextEvent = (TH2D*)file->Get("h2D_MisasignedBcoDiff_NCohInNextEvent"); + + TH2D* h2D_NInttHitInner_NInttHitOuter_narrow_spacing = (TH2D*)file->Get("h2D_NInttHitInner_NInttHitOuter_narrow_spacing"); + + TCanvas* c1 = new TCanvas("c1", "Title", 900, 600); + c1->cd(); + h2D_NInttHitInner_NInttHitOuter->SetTitle(Form("h2D_NInttHitInner_NInttHitOuter(run %d, n_collision %d, open time %d); # of trigger timing hits (INTT inner); # of trigger timing hits (INTT outer)", run, n_collision, open_time)); + h2D_NInttHitInner_NInttHitOuter->Draw(); + c1->SetLogz(); + c1->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_NInttHitInner_NInttHitOuter.png", run) ); + TF1 *f = new TF1("f","x",0,10000); + f->Draw("same"); + c1->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_NInttHitInner_NInttHitOuter_with_line.png", run) ); + h2D_NInttHitInner_NInttHitOuter->GetXaxis()->SetRangeUser(0,1500); + h2D_NInttHitInner_NInttHitOuter->GetYaxis()->SetRangeUser(0,1500); + h2D_NInttHitInner_NInttHitOuter->Draw(); + c1->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_NInttHitInner_NInttHitOuter_zoomed.png", run) ); + + TCanvas* c2 = new TCanvas("c2", "Title", 900, 600); + c2->cd(); + h2D_NInttHitInner_NInttHitOuter_corrected->SetTitle(Form("h2D_NInttHitInner_NInttHitOuter_corrected(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_NInttHitInner_NInttHitOuter_corrected->Draw(); + c2->SetLogz(); + c2->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_NInttHitInner_NInttHitOuter_corrected.png", run) ); + h2D_NInttHitInner_NInttHitOuter_corrected->GetXaxis()->SetRangeUser(0,1500); + h2D_NInttHitInner_NInttHitOuter_corrected->GetYaxis()->SetRangeUser(0,1500); + h2D_NInttHitInner_NInttHitOuter_corrected->Draw(); + c2->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_NInttHitInner_NInttHitOuter_corrected_zoomed.png", run) ); + + TCanvas* c3 = new TCanvas("c3", "Title", 900, 600); + c3->cd(); + h2D_EventBcoSpacing_NCohInNextEvent_->SetTitle(Form("h2D_EventBcoSpacing_NCohInNextEvent_(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_EventBcoSpacing_NCohInNextEvent_->Draw(); + c3->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NCarriedHits.png", run) ); + + TCanvas* c4 = new TCanvas("c4", "Title", 900, 600); + c4->cd(); + h2D_NCarriedInner_NCarriedOuter->SetTitle(Form("h2D_NCarriedInner_NCarriedOuter(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_NCarriedInner_NCarriedOuter->Draw(); + c4->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_NCarriedInner_NCarriedOuter.png", run) ); + h2D_NCarriedInner_NCarriedOuter->GetXaxis()->SetRangeUser(0,1000); + h2D_NCarriedInner_NCarriedOuter->GetYaxis()->SetRangeUser(0,1000); + h2D_NCarriedInner_NCarriedOuter->Draw(); + c4->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_NCarriedInner_NCarriedOuter_zoomed.png", run) ); + + TCanvas* c5 = new TCanvas("c5", "Title", 900, 600); + c5->cd(); + h2D_Halfladder_NCOH->SetTitle(Form("h2D_Halfladder_NCOH(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_Halfladder_NCOH->Draw(); + c5->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_Halfladder_NCOH.png", run) ); + + TCanvas* c6 = new TCanvas("c6", "Title", 900, 600); + c6->cd(); + h2D_EventBcoSpacing_NHitInPreviousEvent->SetTitle(Form("h2D_EventBcoSpacing_NHitInPreviousEvent(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_EventBcoSpacing_NHitInPreviousEvent->Draw(); + c6->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NHitInPreviousEvent.png", run) ); + + TCanvas* c7 = new TCanvas("c7", "Title", 900, 600); + c7->cd(); + h2D_EventBcoSpacing_NCohInNextEvent->SetTitle(Form("h2D_EventBcoSpacing_NCohInNextEvent(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_EventBcoSpacing_NCohInNextEvent->Draw(); + c7->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NCohInNextEvent.png", run) ); + + TCanvas* c8 = new TCanvas("c8", "Title", 900, 600); + c8->cd(); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder->SetTitle(Form("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder->Draw(); + c8->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder.png", run) ); + + TCanvas* c9 = new TCanvas("c9", "Title", 900, 600); + c9->cd(); + h2D_EventBcoSpacing_NHitInPreviousEvent_bychip->SetTitle(Form("h2D_EventBcoSpacing_NHitInPreviousEvent_bychip(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_EventBcoSpacing_NHitInPreviousEvent_bychip->Draw(); + c9->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NHitInPreviousEvent_bychip.png", run) ); + + TCanvas* c10 = new TCanvas("c10", "Title", 900, 600); + c10->cd(); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner->SetTitle(Form("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner->Draw(); + c10->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner.png", run) ); + + TCanvas* c11 = new TCanvas("c11", "Title", 900, 600); + c11->cd(); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer->SetTitle(Form("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer->Draw(); + c11->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer.png", run) ); + + TCanvas* c12 = new TCanvas("c12", "Title", 900, 600); + c12->cd(); + h2D_MisasignedBcoDiff_NHitInPreviousEvent->SetTitle(Form("h2D_MisasignedBcoDiff_NHitInPreviousEvent(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_MisasignedBcoDiff_NHitInPreviousEvent->Draw(); + c12->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_MisasignedBcoDiff_NHitInPreviousEvent.png", run) ); + + TCanvas* c13 = new TCanvas("c13", "Title", 900, 600); + c13->cd(); + h2D_MisasignedBcoDiff_NCohInNextEvent->SetTitle(Form("h2D_MisasignedBcoDiff_NCohInNextEvent(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_MisasignedBcoDiff_NCohInNextEvent->Draw(); + c13->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_MisasignedBcoDiff_NCohInNextEvent.png", run) ); + + TCanvas* c14 = new TCanvas("c14", "Title", 900, 600); + c14->cd(); + h2D_NInttHitInner_NInttHitOuter_narrow_spacing->SetTitle(Form("h2D_NInttHitInner_NInttHitOuter_narrow_spacing(run %d, n_collision %d, open time %d)", run, n_collision, open_time)); + h2D_NInttHitInner_NInttHitOuter_narrow_spacing->Draw(); + c14->Print( Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/h2D_NInttHitInner_NInttHitOuter_narrow_spacing.png", run) ); + + + + + file->Close(); + delete file; + delete c1; + delete c2; + delete c3; + delete c4; + delete c5; +} + +int GetNCollisionFromRunNum(int run){ + /* {run_number, {n_collision, open_time}} */ + std::vector< std::pair> > run_ncoll_open = { + + {66522, {100,60}}, /* physics run */ + {66682, {100,60}}, /* physics run */ + {68002, {100,60}}, /* physics run */ + {71345, {100,60}}, /* physics run */ + {71346, {126,60}}, /* physics run */ + {71347, {126,127}}, /* physics run */ + + {67542, {100,127}}, + {67544, {100,110}}, + {67545, {100,90}}, + //{67546, {100,80}}, + {67547, {100,60}}, + {67548, {100,40}}, + {67549, {100,25}}, + {67550, {2,127}}, + {67552, {2,110}}, + {67553, {2,90}}, + {67554, {2,80}}, + {67555, {2,60}}, + //{67556, {2,40}}, + {67557, {2,25}}, + {67558, {50,127}}, + {67559, {50,110}}, + {67560, {50,90}}, + {67563, {50,60}}, + {67564, {50,40}}, + {67565, {50,25}}, + {67566, {50,80}}, + + {68007, {100,60}}, + {68008, {127,127}}, + {68009, {3,127}}, + {68010, {3,60}}, + {68012, {100,60}}, + {68013, {127,127}}, + {68014, {3,127}}, + {68015, {3,60}}, + + {82400, {126,60}}, + + }; + + int n_collision; + for (auto pair : run_ncoll_open){ + if (pair.first == run){ + n_collision = pair.second.first; + } + } + + return n_collision; + +} + +int GetOpenTimeFromRunNum(int run){ + std::vector< std::pair> > run_ncoll_open = { + + {66522, {100,60}}, /* physics run */ + {66682, {100,60}}, /* physics run */ + {68002, {100,60}}, /* physics run */ + {71345, {100,60}}, /* physics run */ + {71346, {126,60}}, /* physics run */ + {71347, {126,127}}, /* physics run */ + + {67542, {100,127}}, + {67544, {100,110}}, + {67545, {100,90}}, + //{67546, {100,80}}, + {67547, {100,60}}, + {67548, {100,40}}, + {67549, {100,25}}, + {67550, {2,127}}, + {67552, {2,110}}, + {67553, {2,90}}, + {67554, {2,80}}, + {67555, {2,60}}, + //{67556, {2,40}}, + {67557, {2,25}}, + {67558, {50,127}}, + {67559, {50,110}}, + {67560, {50,90}}, + {67563, {50,60}}, + {67564, {50,40}}, + {67565, {50,25}}, + {67566, {50,80}}, + + {68007, {100,60}}, + {68008, {127,127}}, + {68009, {3,127}}, + {68010, {3,60}}, + {68012, {100,60}}, + {68013, {127,127}}, + {68014, {3,127}}, + {68015, {3,60}}, + + {82400, {126,60}}, + }; + + int open_time; + for (auto pair : run_ncoll_open){ + if (pair.first == run){ + open_time = pair.second.second; + } + } + + return open_time; +} + +int FindEdgeBin(TH1D* hist, int peak_bin){ + double threshold = 0.0000075; + //double threshold = 0.0075; + double height_ratio = 1; + int this_bin = peak_bin; + + for (int i=0; i < hist->GetNbinsX(); i--){ + this_bin = GetPreviousWithoutUnderflow(this_bin); // This is basically identical to (this_bin - 1), except in case of reaching the underflow bin. + height_ratio = hist->GetBinContent(this_bin) / hist->GetBinContent(peak_bin); + if (height_ratio < threshold) { + return this_bin; + } + } + + std::cerr << "No edge found!" << std::endl; + exit(1); + +} + +TH1D* ShiftHistoWithoutDupulication(TH1D* hist, int offset){ + + TH1D* hist_shifted = (TH1D*)hist->Clone("h_bco_diff_shifted"); + + int bin_num_before; + for (int i=0; i < hist->GetNbinsX(); i++) { + bin_num_before = AddOffsetWithoutOverflow(1+i, offset); + hist_shifted->SetBinContent(1+i, hist->GetBinContent(bin_num_before)); + hist_shifted->SetBinError(1+i, hist->GetBinError(bin_num_before)); + } + + return hist_shifted; +} + +int GetPreviousWithoutUnderflow(int bin){ + if (bin == 1) { + return 128; + } else { + return bin-1; + } +} + +int AddOffsetWithoutOverflow(int this_bin, int offset) { + if ( this_bin + offset == 128){ + return 128; + } else { + return (this_bin + offset)%128; + } +} + + +void DrawBoxFromValue( TH2D* h2D_NInttHitInner_NInttHitOuter, double x_val_min, double x_val_max, double y_val_min, double y_val_max, int color ){ + int xbin_min = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->FindBin(x_val_min); + int xbin_max = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->FindBin(x_val_max); + int ybin_min = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->FindBin(y_val_min); + int ybin_max = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->FindBin(y_val_max); + + double x1 = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->GetBinLowEdge(xbin_min); + double x2 = h2D_NInttHitInner_NInttHitOuter->GetXaxis()->GetBinUpEdge(xbin_max); + double y1 = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->GetBinLowEdge(ybin_min); + double y2 = h2D_NInttHitInner_NInttHitOuter->GetYaxis()->GetBinUpEdge(ybin_max); + + TBox* box = new TBox(x1, y1, x2, y2); + box->SetLineColor(color); + box->SetLineWidth(2); + box->SetFillStyle(0); + box->Draw("same"); +} diff --git a/general_codes/ryotaro/CarriedOverHits/macro/check.C b/general_codes/ryotaro/CarriedOverHits/macro/check.C new file mode 100644 index 0000000..b76fe8f --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/macro/check.C @@ -0,0 +1,231 @@ +void check() { + + // TFile *file = TFile::Open("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/completed/0All.root"); + TFile *file = TFile::Open("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/1000files_Criteria2_TTree_0hitHandled.root"); + // TFile *file = TFile::Open("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/1000files_Criteria2_TTree_0hitHandled_halfladderCutted.root"); + if (!file || file->IsZombie()) { + std::cerr << "Error: cannot open file" << std::endl; + return; + } + + TTree *tree = (TTree*)file->Get("tree"); + if (!tree) { + std::cerr << "Error: cannot find TTree" << std::endl; + return; + } + + + // まず全部 OFF + tree->SetBranchStatus("*", 0); + + // 必要なブランチだけ ON + tree->SetBranchStatus("n_intt_raw_hits", 1); + tree->SetBranchStatus("num_of_carried_hits", 1); + tree->SetBranchStatus("num_of_carried_hits_inner", 1); + tree->SetBranchStatus("num_of_carried_hits_outer", 1); + tree->SetBranchStatus("interval_from_previous", 1); + tree->SetBranchStatus("is_MBDNS_tight_vtx10cm", 1); + + int n_intt_raw_hits; + int num_of_carried_hits; + int num_of_carried_hits_inner; + int num_of_carried_hits_outer; + int64_t interval_from_previous; + bool is_MBDNS_tight_vtx10cm; + tree->SetBranchAddress("n_intt_raw_hits", &n_intt_raw_hits); + tree->SetBranchAddress("num_of_carried_hits", &num_of_carried_hits); + tree->SetBranchAddress("num_of_carried_hits_inner", &num_of_carried_hits_inner); + tree->SetBranchAddress("num_of_carried_hits_outer", &num_of_carried_hits_outer); + tree->SetBranchAddress("interval_from_previous", &interval_from_previous); + tree->SetBranchAddress("is_MBDNS_tight_vtx10cm", &is_MBDNS_tight_vtx10cm); + + int previous_event_n_intt_raw_hits; + int previous_event_interval_from_previous; + bool previous_event_is_MBDNS_tight_vtx10cm; + + TH1D* h_temp_all = new TH1D("h_temp_all","h_temp_all; interval [BCO]; Entries",127,0,127); + TH1D* h_temp_at_least_1_hit = new TH1D("h_temp_at_least_1_hit","h_temp_at_least_1_hit; interval [BCO]; Entries",127,0,127); + TH1D* h_temp_with_carryover = new TH1D("h_temp_with_carryover","h_temp_with_carryover; interval [BCO]; Entries",127,0,127); + TH1D* h_temp_with_carryover_at_least_1_hit = new TH1D("h_temp_with_carryover_at_least_1_hit","h_temp_with_carryover_at_least_1_hit; interval [BCO]; Entries",127,0,127); + TH2D* h_misidentified_num_of_carried_hits = new TH2D("h_misidentified_num_of_carried_hits","(interval > 80);inner;outer",5000,0,5000,5000,0,5000); + TH2D* h_misidentified_num_of_carried_hits_short_interval = new TH2D("h_misidentified_num_of_carried_hits_short_interval","(16 < interval <= 22 );inner;outer",5000,0,5000,5000,0,5000); + TH2D* h_misidentified_num_of_carried_hits_short_interval_1 = new TH2D("h_misidentified_num_of_carried_hits_short_interval_1","(30 < interval <= 35 );inner;outer",5000,0,5000,5000,0,5000); + TH2D* h_misidentified_num_of_carried_hits_short_interval_2 = new TH2D("h_misidentified_num_of_carried_hits_short_interval_2","(35 < interval <= 40 );inner;outer",5000,0,5000,5000,0,5000); + TH2D* h_misidentified_num_of_carried_hits_short_interval_3 = new TH2D("h_misidentified_num_of_carried_hits_short_interval_3","(40 < interval <= 45 );inner;outer",5000,0,5000,5000,0,5000); + TH2D* h_misidentified_num_of_carried_hits_short_interval_4 = new TH2D("h_misidentified_num_of_carried_hits_short_interval_4","(45 < interval <= 50 );inner;outer",5000,0,5000,5000,0,5000); + TH2D* h_misidentified_num_of_carried_hits_short_interval_5 = new TH2D("h_misidentified_num_of_carried_hits_short_interval_5","(50 < interval <= 55 );inner;outer",5000,0,5000,5000,0,5000); + TH2D* h_misidentified_num_of_carried_hits_short_interval_6 = new TH2D("h_misidentified_num_of_carried_hits_short_interval_6","(55 < interval <= 60 );inner;outer",5000,0,5000,5000,0,5000); + + TGraph* g = new TGraph(); + TGraph* g2 = new TGraph(); + TGraph* g3 = new TGraph(); + + Long64_t nEntries = tree->GetEntries(); + std::cout << nEntries << std::endl; + for (Long64_t i = 0; i < nEntries; i++) { + // for (Long64_t i = 0; i < 10000; i++) { + // for (Long64_t i = 0; i < 100000; i++) { + if ( i%100000 == 0 ) { std::cout << i << std::endl; } + + tree->GetEntry(i); + if ( i == 0 ) { + previous_event_interval_from_previous = interval_from_previous; + previous_event_n_intt_raw_hits = n_intt_raw_hits; + previous_event_is_MBDNS_tight_vtx10cm = is_MBDNS_tight_vtx10cm; + continue; + } + + + // std::cout << previous_event_is_MBDNS_tight_vtx10cm << std::endl; + + if ( previous_event_is_MBDNS_tight_vtx10cm == false ) { + // std::cout << previous_event_is_MBDNS_tight_vtx10cm << std::endl; + previous_event_interval_from_previous = interval_from_previous; + previous_event_n_intt_raw_hits = n_intt_raw_hits; + previous_event_is_MBDNS_tight_vtx10cm = is_MBDNS_tight_vtx10cm; + continue; + } + + h_temp_all->Fill(interval_from_previous); + if ( previous_event_n_intt_raw_hits > 0 && n_intt_raw_hits > 0 ) { + h_temp_at_least_1_hit->Fill(interval_from_previous); + } + + if ( num_of_carried_hits > 0 ){ + h_temp_with_carryover->Fill(interval_from_previous); + if ( previous_event_n_intt_raw_hits > 0 ) { + h_temp_with_carryover_at_least_1_hit->Fill(interval_from_previous); + } + + + if ( 16 < interval_from_previous && interval_from_previous < 22 ){ + h_misidentified_num_of_carried_hits_short_interval->Fill(num_of_carried_hits_inner,num_of_carried_hits_outer); + } + if ( 30 < interval_from_previous && interval_from_previous <= 35 ){ + h_misidentified_num_of_carried_hits_short_interval_1->Fill(num_of_carried_hits_inner,num_of_carried_hits_outer); + } + if ( 35 < interval_from_previous && interval_from_previous <= 40 ){ + h_misidentified_num_of_carried_hits_short_interval_2->Fill(num_of_carried_hits_inner,num_of_carried_hits_outer); + } + if ( 40 < interval_from_previous && interval_from_previous <= 45 ){ + h_misidentified_num_of_carried_hits_short_interval_3->Fill(num_of_carried_hits_inner,num_of_carried_hits_outer); + } + if ( 45 < interval_from_previous && interval_from_previous <= 50 ){ + h_misidentified_num_of_carried_hits_short_interval_4->Fill(num_of_carried_hits_inner,num_of_carried_hits_outer); + } + if ( 50 < interval_from_previous && interval_from_previous <= 55 ){ + h_misidentified_num_of_carried_hits_short_interval_5->Fill(num_of_carried_hits_inner,num_of_carried_hits_outer); + } + if ( 55 < interval_from_previous && interval_from_previous <= 60 ){ + h_misidentified_num_of_carried_hits_short_interval_6->Fill(num_of_carried_hits_inner,num_of_carried_hits_outer); + } + if ( interval_from_previous > 80 ){ + h_misidentified_num_of_carried_hits->Fill(num_of_carried_hits_inner,num_of_carried_hits_outer); + } + } + + previous_event_interval_from_previous = interval_from_previous; + previous_event_n_intt_raw_hits = n_intt_raw_hits; + previous_event_is_MBDNS_tight_vtx10cm = is_MBDNS_tight_vtx10cm; + } + + TCanvas* c1 = new TCanvas("c1", "Title", 900, 600); + h_temp_all->SetLineColor(kBlack); + h_temp_all->SetLineWidth(2); + h_temp_all->Draw(); + h_temp_at_least_1_hit->SetLineColor(kBlack); + h_temp_at_least_1_hit->SetLineWidth(2); + h_temp_at_least_1_hit->SetLineStyle(2); + h_temp_at_least_1_hit->Draw("same"); + h_temp_with_carryover->SetLineColor(kBlue); + // h_temp_with_carryover->SetLineWidth(5); + h_temp_with_carryover->Draw("same"); + h_temp_with_carryover_at_least_1_hit->SetLineColor(kBlue); + h_temp_with_carryover_at_least_1_hit->SetLineStyle(2); + h_temp_with_carryover_at_least_1_hit->Draw("same"); + + TLegend* l = new TLegend(0.3,0.5,0.9,0.7); + l->AddEntry(h_temp_all,"not cut"); + l->AddEntry(h_temp_at_least_1_hit,"#it{N}_{hit}#geq 1 in original event"); + l->AddEntry(h_temp_with_carryover,"carryover found (not cut)"); + l->AddEntry(h_temp_with_carryover_at_least_1_hit,"carryover found (#it{N}_{hit}#geq 1 in original event)"); + l->Draw("same"); + + c1->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/temp_at_least_1_hit.pdf"); + + TCanvas* c2 = new TCanvas("c2", "Title", 900, 600); + int idx=1; + for (int i=17; i < 127; i++) { + g->SetPoint(idx, i+0.4, h_temp_with_carryover->GetBinContent(i)/h_temp_all->GetBinContent(i)); + g2->SetPoint(idx, i, h_temp_with_carryover_at_least_1_hit->GetBinContent(i)/h_temp_at_least_1_hit->GetBinContent(i)); + g3->SetPoint(idx, i-0.4, h_temp_with_carryover_at_least_1_hit->GetBinContent(i)/h_temp_all->GetBinContent(i)); + idx++; + } + + + g2->SetMarkerStyle(21); + g2->SetMarkerSize(1.0); + g2->SetMarkerColor(kBlue); + g2->Draw("ap"); + + g3->SetMarkerStyle(21); + g3->SetMarkerSize(1.0); + g3->SetMarkerColor(kRed); + g3->Draw("p same"); + + g->SetMarkerStyle(20); + g->SetMarkerSize(1.0); + g->SetMarkerColor(kGreen); + g->Draw("p same"); + + TLegend* l2 = new TLegend(0.3,0.5,0.9,0.7); + l2->AddEntry(g,"carryover / all"); + l2->AddEntry(g2,"carrover (#it{N}_{hit}#geq 1) /#it{N}_{hit}#geq 1 "); + l2->AddEntry(g3,"carrover (#it{N}_{hit}#geq 1) / all"); + l2->Draw("same"); + + c2->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/hiritu.pdf"); + + + TCanvas* c3 = new TCanvas("c3", "Title", 900, 600); + h_misidentified_num_of_carried_hits->Draw(); + c3->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/h_misidentified_num_of_carried_hits.pdf"); + + TCanvas* c4 = new TCanvas("c4", "Title", 900, 600); + h_misidentified_num_of_carried_hits_short_interval->Draw(); + c4->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/h_misidentified_num_of_carried_hits_short_interval.pdf"); + + TCanvas* c5 = new TCanvas("c5", "Title", 900, 600); + h_misidentified_num_of_carried_hits_short_interval_1->Draw(); + c5->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/h_misidentified_num_of_carried_hits_short_interval_1.pdf"); + + TCanvas* c6 = new TCanvas("c6", "Title", 900, 600); + h_misidentified_num_of_carried_hits_short_interval_2->Draw(); + c6->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/h_misidentified_num_of_carried_hits_short_interval_2.pdf"); + + TCanvas* c7 = new TCanvas("c7", "Title", 900, 600); + h_misidentified_num_of_carried_hits_short_interval_3->Draw(); + c7->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/h_misidentified_num_of_carried_hits_short_interval_3.pdf"); + + TCanvas* c8 = new TCanvas("c8", "Title", 900, 600); + h_misidentified_num_of_carried_hits_short_interval_4->Draw(); + c8->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/h_misidentified_num_of_carried_hits_short_interval_4.pdf"); + + TCanvas* c9 = new TCanvas("c9", "Title", 900, 600); + h_misidentified_num_of_carried_hits_short_interval_5->Draw(); + c9->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/h_misidentified_num_of_carried_hits_short_interval_5.pdf"); + + TCanvas* c10 = new TCanvas("c10", "Title", 900, 600); + h_misidentified_num_of_carried_hits_short_interval_6->Draw(); + c10->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/75519/h_misidentified_num_of_carried_hits_short_interval_6.pdf"); + + + // int event_id = 2009; + // tree->GetEntry(); + + + + file->Close(); +}; + + diff --git a/general_codes/ryotaro/CarriedOverHits/macro/run_condor.job b/general_codes/ryotaro/CarriedOverHits/macro/run_condor.job new file mode 100755 index 0000000..0abeb4e --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/macro/run_condor.job @@ -0,0 +1,23 @@ +Universe = vanilla +Initialdir = /sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/macro +Executable = run_job.sh +PeriodicHold = (NumJobStarts>=1 && JobStatus == 1) +concurrency_limits = CONCURRENCY_LIMIT_DEFAULT:100 +request_memory = 1GB +Priority = 20 +job_lease_duration = 86400 + +runnumber = 75519 +nEvents = 2000 +file_path_to_hot_channel_map = /sphenix/user/ChengWei/SelfINTTProduction/2025_Oct_20/jaein_decode_calib/cdb_00082391hot.root +save_tree = true +job_offset = 0 +process_shift = $(Process) + $(job_offset) +output_directory = /sphenix/user/ryotaro/CarriedOverHits_v2/output + + +Output = $(output_directory)/condor_$(runnumber)_$INT(process_shift).out +Error = $(output_directory)/condor_$(runnumber)_$INT(process_shift).err +Log = /tmp/ryotaro/CarriedOverHits_v2/condor_$(runnumber)_$INT(process_shift).log +Arguments = "$INT(process_shift) $(runnumber) $(nEvents) $(file_path_to_hot_channel_map) $(save_tree)" +Queue 4646 diff --git a/general_codes/ryotaro/CarriedOverHits/macro/run_job.sh b/general_codes/ryotaro/CarriedOverHits/macro/run_job.sh new file mode 100755 index 0000000..b872d39 --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/macro/run_job.sh @@ -0,0 +1,33 @@ +#! /bin/bash +# export USER="$(id -u -n)" +# export LOGNAME=${USER} +# export HOME=/sphenix/u/${LOGNAME} + +#source /opt/sphenix/core/bin/sphenix_setup.sh -n ana.464 +source /opt/sphenix/core/bin/sphenix_setup.sh +# source /opt/sphenix/core/bin/sphenix_setup.sh -n ana.504 + + +export MYINSTALL=/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/install + +export LD_LIBRARY_PATH=$MYINSTALL/lib:$LD_LIBRARY_PATH +export ROOT_INCLUDE_PATH=$MYINSTALL/include:$ROOT_INCLUDE_PATH + +source /opt/sphenix/core/bin/setup_local.sh $MYINSTALL + +echo $ROOT_INCLUDE_PATH | sed -e "s/:/\n/g" + +process=$1 +runnumber=$2 +nEvents=$3 +file_path_to_hot_channel_map=$4 +save_tree=$5 + +echo process: ${process} +echo runnumber: ${runnumber} +echo nEvents: ${nEvents} +echo file_path_to_hot_channel_map: ${file_path_to_hot_channel_map} + +root.exe -q -b Fun4All_HitCarryoverMonitor.cc\(${process},${runnumber},${nEvents},\"${file_path_to_hot_channel_map}\",${save_tree}\) + +echo all done process the Fun4All_Intt_SanityCheck.C, process_id: ${process} diff --git a/general_codes/ryotaro/CarriedOverHits/macro/utilities/sPhenixStyle.C b/general_codes/ryotaro/CarriedOverHits/macro/utilities/sPhenixStyle.C new file mode 100644 index 0000000..567e5a2 --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/macro/utilities/sPhenixStyle.C @@ -0,0 +1,120 @@ +#ifndef MACRO_SPHENIXSTYLE_C +#define MACRO_SPHENIXSTYLE_C + +// +// sPHENIX Style, based on a style file from BaBar, v0.1 +// + +#include "sPhenixStyle.h" + +#include +#include + +#include + +void SetsPhenixStyle() +{ + static TStyle* sphenixStyle = 0; + std::cout << "sPhenixStyle: Applying nominal settings." << std::endl; + if (sphenixStyle == 0) sphenixStyle = sPhenixStyle(); + gROOT->SetStyle("sPHENIX"); + gROOT->ForceStyle(); +} + +TStyle* sPhenixStyle() +{ + TStyle* sphenixStyle = new TStyle("sPHENIX", "sPHENIX style"); + + // use plain black on white colors + Int_t icol = 0; // WHITE + sphenixStyle->SetFrameBorderMode(icol); + sphenixStyle->SetFrameFillColor(icol); + sphenixStyle->SetCanvasBorderMode(icol); + sphenixStyle->SetCanvasColor(icol); + sphenixStyle->SetPadBorderMode(icol); + sphenixStyle->SetPadColor(icol); + sphenixStyle->SetStatColor(icol); + //sphenixStyle->SetFillColor(icol); // don't use: white fill color for *all* objects + + // set the paper & margin sizes + sphenixStyle->SetPaperSize(20, 26); + + // set margin sizes + sphenixStyle->SetPadTopMargin(0.05); + sphenixStyle->SetPadRightMargin(0.05); + sphenixStyle->SetPadBottomMargin(0.16); + sphenixStyle->SetPadLeftMargin(0.16); + + // set title offsets (for axis label) + sphenixStyle->SetTitleXOffset(1.4); + sphenixStyle->SetTitleYOffset(1.4); + + // use large fonts + //Int_t font=72; // Helvetica italics + Int_t font = 42; // Helvetica + Double_t tsize = 0.05; + sphenixStyle->SetTextFont(font); + + sphenixStyle->SetTextSize(tsize); + sphenixStyle->SetLabelFont(font, "x"); + sphenixStyle->SetTitleFont(font, "x"); + sphenixStyle->SetLabelFont(font, "y"); + sphenixStyle->SetTitleFont(font, "y"); + sphenixStyle->SetLabelFont(font, "z"); + sphenixStyle->SetTitleFont(font, "z"); + + sphenixStyle->SetLabelSize(tsize, "x"); + sphenixStyle->SetTitleSize(tsize, "x"); + sphenixStyle->SetLabelSize(tsize, "y"); + sphenixStyle->SetTitleSize(tsize, "y"); + sphenixStyle->SetLabelSize(tsize, "z"); + sphenixStyle->SetTitleSize(tsize, "z"); + + // use bold lines and markers + sphenixStyle->SetMarkerStyle(20); + sphenixStyle->SetMarkerSize(1.2); + sphenixStyle->SetHistLineWidth(2.); + sphenixStyle->SetLineStyleString(2, "[12 12]"); // postscript dashes + + // get rid of X error bars + //sphenixStyle->SetErrorX(0.001); + // get rid of error bar caps + sphenixStyle->SetEndErrorSize(0.); + + // do not display any of the standard histogram decorations + sphenixStyle->SetOptTitle(0); + //sphenixStyle->SetOptStat(1111); + sphenixStyle->SetOptStat(0); + //sphenixStyle->SetOptFit(1111); + sphenixStyle->SetOptFit(0); + + // put tick marks on top and RHS of plots + sphenixStyle->SetPadTickX(1); + sphenixStyle->SetPadTickY(1); + + // legend modificatin + sphenixStyle->SetLegendBorderSize(0); + sphenixStyle->SetLegendFillColor(0); + sphenixStyle->SetLegendFont(font); + +#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 00, 0) + std::cout << "sPhenixStyle: ROOT6 mode" << std::endl; + sphenixStyle->SetLegendTextSize(tsize); + sphenixStyle->SetPalette(kBird); +#else + std::cout << "sPhenixStyle: ROOT5 mode" << std::endl; + // color palette - manually define 'kBird' palette only available in ROOT 6 + Int_t alpha = 0; + Double_t stops[9] = {0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000}; + Double_t red[9] = {0.2082, 0.0592, 0.0780, 0.0232, 0.1802, 0.5301, 0.8186, 0.9956, 0.9764}; + Double_t green[9] = {0.1664, 0.3599, 0.5041, 0.6419, 0.7178, 0.7492, 0.7328, 0.7862, 0.9832}; + Double_t blue[9] = {0.5293, 0.8684, 0.8385, 0.7914, 0.6425, 0.4662, 0.3499, 0.1968, 0.0539}; + TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha); +#endif + + sphenixStyle->SetNumberContours(80); + + return sphenixStyle; +} + +#endif diff --git a/general_codes/ryotaro/CarriedOverHits/macro/utilities/sPhenixStyle.h b/general_codes/ryotaro/CarriedOverHits/macro/utilities/sPhenixStyle.h new file mode 100644 index 0000000..3e911be --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/macro/utilities/sPhenixStyle.h @@ -0,0 +1,51 @@ +// +// @file sPhenixStyle.h +// +// sPHENIX Style, based on a style file from ATLAS +// +// +// @author Peter Steinberg +// +// Copyright (C) 2017 sPhenix Collaboration +// +// Version 0.1 + +#ifndef MACRO_SPHENIXSTYLE_H +#define MACRO_SPHENIXSTYLE_H + +#include + +//! \brief sPHENIX Style, based on a style file from ATLAS by Peter Steinberg +/* +Please find instruction at https://wiki.bnl.gov/sPHENIX/index.php/Plot_template . Here is a snapshot: + +# How to use + +To ensure some consistency among plots produced by different sPHENIX members, a candidate style file is being proposed (May 2017), based on the ATLAS style file. Please click here for the gzipped tar file. +For general use, copy or link the ``sPHENIXStyle.h`` and ``sPHENIXStyle.C`` files somewhere, either locally or in your macro path (``gROOT->GetMacroPath()`` will tell you, and add it in ``.rootrc`` if you need one). +Then do +`` +[0] gROOT->LoadMacro("sPhenixStyle.C") +[1] SetsPhenixStyle() +`` +and you're good to go (even better, add this all into your ``.rootlogon.C`` file) + +# Rules of the sPHENIX style + +* Don't talk about the style file. +* Always use the style file. +* Units should always be indicated in brackets "[ ]", while counts will typically specify the bin width "Events / 2 GeV" or "Events / 0.13 rad". +* Every plot should have a legend indicating "sPHENIX", "sPHENIX Preliminary", "sPHENIX Simulation", etc. +* sPHENIX should be bold, italic +* Where possible, indicate the system being considered and it's energy +* "MC" predictions should be filled, with distinguishable colors +* Data or pseudodata should always be histograms or graphs with error bars +* Elements should never overlap, with each other or with the axis + + * + */ +void SetsPhenixStyle(); + +TStyle* sPhenixStyle(); + +#endif // MACRO_SPHENIXSTYLE_H diff --git a/general_codes/ryotaro/CarriedOverHits/src/InttHitCarryoverMonitor.cc b/general_codes/ryotaro/CarriedOverHits/src/InttHitCarryoverMonitor.cc new file mode 100644 index 0000000..c4a9e07 --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/src/InttHitCarryoverMonitor.cc @@ -0,0 +1,1141 @@ +#include "InttHitCarryoverMonitor.h" + + +bool CheckCloneHits(InttRawHit* hit, InttRawHitStructure& structure); +std::unordered_map< Chip, std::vector > PrepareHitInfoByChip(const InttRawHitStructure& event); +void CalculateHitBco(InttRawHitStructure& event, const int triggered_BcoDiff_, const int64_t intt_clock_offset); +bool EvaluateThisEvent(const InttRawHitStructure event); +void CountNumberOfHitsInNominalTiming(InttRawHitStructure& event, const int triggered_BcoDiff, const int64_t intt_clock_offset); +void CountCarriedOverHitsPerEventBasis(const InttRawHitStructure event_of_interest, InttRawHitStructure& next_event); +int DeriveTriggerBcoDiffOfARun(int run); +int GetNumberOfHitsInNormalTimingInAHalfladder(const std::map< HalfLadder, std::vector > list, const HalfLadder halfladder, const int standard_timing); +int GetNumberOfHitsInAChip_HalfladderbyHalfladder(const std::map< HalfLadder, std::vector > list, const HalfLadder halfladder, const int standard_timing); +int GetNumberOfHitsInNormalTimingInAHalfladder(const std::map< HalfLadder, std::vector > list, const HalfLadder halfladder, const int gl1_bco, const int triggered_BcoDiff, const int64_t intt_clock_offset); +int GetNumberOfHitsInNormalTimingInAChip(const std::unordered_map< Chip, std::vector > list, const Chip chip, const int standard_timing); +int GetNumberOfHitsInAChip_ChipByChip(const std::unordered_map< Chip, std::vector > list, const Chip chip, const int standard_timing); + + +InttHitCarryoverMonitor::InttHitCarryoverMonitor(const std::string &name, const int run, const std::string arg_file_path_to_hot_channel_map, std::string job_index, bool save_tree): + SubsysReco(name), + save_tree_(save_tree), + my_event_counter_(0), + gl1_bco_previous_(0), + intt_clock_offset_(0), + // gl1_bco_ith_(0), + // interval_from_previous_(0), + // trigger_BcoDiff_(arg_trigger_Bcodiff), + file_path_to_hot_channel_map_(arg_file_path_to_hot_channel_map) +{ + std::cout << "InttHitCarryoverMonitor(const std::string &name, int run) Calling the constructor" << std::endl; + + std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/CarriedOverHits_v2/output/%d/%d-%s.root", run, run, job_index.c_str()); + output_file_ = new TFile(filename.c_str(), "recreate"); + if ( !output_file_ || output_file_->IsZombie()){ + std::cerr << "ERROR : File '" << filename << "' not found or could not be opend." << std::endl; + std::exit(1); + } + + /* make braches */ + + if ( save_tree_ ) { + output_tree_ = new TTree("tree", "tree"); + output_tree_->Branch("n_intt_raw_hits", &ith_event_.n_intt_raw_hits); + output_tree_->Branch("bco", &ith_event_.bco); + output_tree_->Branch("felix_server",&ith_event_.felix_server); + output_tree_->Branch("word",&ith_event_.word); + output_tree_->Branch("felix_channel",&ith_event_.felix_channel); + output_tree_->Branch("channel",&ith_event_.channel); + output_tree_->Branch("chip",&ith_event_.chip); + output_tree_->Branch("adc",&ith_event_.adc); + output_tree_->Branch("FPHX_BCO",&ith_event_.FPHX_BCO); + output_tree_->Branch("full_FPHX",&ith_event_.full_FPHX); + output_tree_->Branch("full_ROC",&ith_event_.full_ROC); + output_tree_->Branch("amplitude",&ith_event_.amplitude); + output_tree_->Branch("is_MBDNS_tight_inclusive",&ith_event_.is_MBDNS_tight_inclusive); + output_tree_->Branch("is_MBDNS_tight_vtx10cm",&ith_event_.is_MBDNS_tight_vtx10cm); + output_tree_->Branch("is_MBDNS_tight_vtx30cm",&ith_event_.is_MBDNS_tight_vtx30cm); + output_tree_->Branch("hitbco_peak",&ith_event_.hitbco_peak); + output_tree_->Branch("bco_diff_peak",&ith_event_.bco_diff_peak); + output_tree_->Branch("n_hit_inner",&ith_event_.n_hit_inner); + output_tree_->Branch("n_hit_outer",&ith_event_.n_hit_outer); + output_tree_->Branch("num_of_carried_hits",&ith_event_.num_of_carried_hits); + output_tree_->Branch("num_of_carried_hits_inner",&ith_event_.num_of_carried_hits_inner); + output_tree_->Branch("num_of_carried_hits_outer",&ith_event_.num_of_carried_hits_outer); + // output_tree_->Branch("h1D_fphxbco",&ith_event_.h1D_fphxbco); /* probably will no be used. */ + // output_tree_->Branch("hit_info_by_halfladder",&ith_event_.hit_info_by_halfladder); + // output_tree_->Branch("hit_info_by_chip",&ith_event_.hit_info_by_chip); + output_tree_->Branch("gl1_bco_ith",&ith_event_.gl1_bco); + output_tree_->Branch("gl1_bco_previous_",&gl1_bco_previous_); + output_tree_->Branch("interval_from_previous",&ith_event_.interval_from_previous); + } + + + h2D_NInttHitInner_NInttHitOuter_ = new TH2D("h2D_NInttHitInner_NInttHitOuter","h2D_NInttHitInner_NInttHitOuter; NHits in normal timing (inner); NHits in normal timing (outer)", 400, 0, 10000, 400, 0, 10000); + h2D_NInttHitInner_NInttHitOuter_corrected_ = new TH2D("h2D_NInttHitInner_NInttHitOuter_corrected","h2D_NInttHitInner_NInttHitOuter_corrected; NHits in normal timing (inner); NHits in normal timing (outer)", 400, 0, 10000, 400, 0, 10000); + // h2D_EventBcoSpacing_NCarriedHits_ = new TH2D("h2D_BcoSpace_NCarriedHits","h2D_BcoSpace_NCarriedHits; Event-BCO spacing; N Carried over hits",150,0,150,2000,0,10000); + h2D_NCarriedInner_NCarriedOuter_ = new TH2D("h2D_NCarriedInner_NCarriedOuter", "h2D_NCarriedInner_NCarriedOuter; inner; outer", 1000,0,5000, 1000,0,5000 ); + h2D_Halfladder_NCOH_ = new TH2D("h2D_Halfladder_NCOH","h2D_Halfladder_NCOH; Half ladder; Number of Carried-over hits", 113, 0, 113, 300, 0, 300); + + /* temp check */ + h1D_Halfladder_NHitInPreviousEvent_example_ = new TH1D("h1D_Halfladder_NHitInPreviousEvent_example_","h1D_Halfladder_NHitInPreviousEvent_example_; Half ladder; Number of Hit in ith-event", 113, 0, 113); + h1D_Halfladder_NCOH_example_ = new TH1D("h1D_Halfladder_NCOH_example_","h1D_Halfladder_NCOH_example_; Half ladder; Number of Carried-over hits", 113, 0, 113); + + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event_ = new TH2D("h2D_EventBcoSpacing_NHitInPreviousEvent_all_event_","h2D_EventBcoSpacing_NHitInPreviousEvent_all_event_; Event-BCO Spacing; Number of Hit in ith-event", 128, 0, 128, 6000, 0, 24000); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_all_event_ = new TH2D("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_all_event_", "h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_all_event_; Event-BCO Spacing; Number of Hit in ith-event", 128, 0, 128, 500, 0, 500); + h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_all_event_ = new TH2D("h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_all_event_", "h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_all_event_; Event-BCO Spacing; Number of Hit in ith-event", 128, 0, 128, 127, 0, 127); + + h2D_EventBcoSpacing_NHitInPreviousEvent_ = new TH2D("h2D_EventBcoSpacing_NHitInPreviousEvent","h2D_EventBcoSpacing_NHitInPreviousEvent; Event-BCO Spacing; Number of Hit in ith-event", 128, 0, 128, 5000, 0, 20000); + h2D_EventBcoSpacing_NCohInNextEvent_ = new TH2D("h2D_EventBcoSpacing_NCohInNextEvent","h2D_EventBcoSpacing_NCohInNextEvent; Event-BCO Spacing; Number of Hit in ith-event", 128, 0, 128, 5000, 0, 20000); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_ = new TH2D("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder", "h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder; Event-BCO Spacing; Number of Hit in ith-event", 128, 0, 128, 500, 0, 500); + h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_ = new TH2D("h2D_EventBcoSpacing_NHitInPreviousEvent_bychip", "h2D_EventBcoSpacing_NHitInPreviousEvent_bychip; Event-BCO Spacing; Number of Hit in ith-event", 128, 0, 128, 127, 0, 127); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner_ = new TH2D("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner", "h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner; Event-BCO Spacing; Number of Hit in ith-event", 128, 0, 128, 500, 0, 500); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer_ = new TH2D("h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer", "h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer; Event-BCO Spacing; Number of Hit in ith-event", 128, 0, 128, 500, 0, 500); + + + h2D_MisasignedBcoDiff_NHitInPreviousEvent_ = new TH2D("h2D_MisasignedBcoDiff_NHitInPreviousEvent","h2D_MisasignedBcoDiff_NHitInPreviousEvent; Misassigned BCO diff; Number of Hit in ith-event", 128, 0, 128, 5000, 0, 20000); + h2D_MisasignedBcoDiff_NCohInNextEvent_ = new TH2D("h2D_MisasignedBcoDiff_NCohInNextEvent","h2D_MisasignedBcoDiff_NCohInNextEvent; Misassigned BCO diff; Number of Carried-over Hit in next-event", 128, 0, 128, 5000, 0, 20000); + + h2D_NInttHitInner_NInttHitOuter_narrow_spacing_ = new TH2D("h2D_NInttHitInner_NInttHitOuter_narrow_spacing","h2D_NInttHitInner_NInttHitOuter_narrow_spacing; NHits in normal timing (inner); NHits in normal timing (outer)", 400, 0, 10000, 400, 0, 10000); + + h1D_Multiplicity_long_event_interval_ = new TH1D("h1D_Multiplicity_long_event_interval", "h1D_Multiplicity_long_event_interval; Multiplicity; Entries (normalized)", 5000,0,20000); + h1D_Multiplicity_short_event_interval_ = new TH1D("h1D_Multiplicity_short_event_interval", "h1D_Multiplicity_short_event_interval; Multiplicity; Entries (normalized)", 5000,0,20000); + h1D_Multiplicity_short_event_interval_corrected_ = new TH1D("h1D_Multiplicity_short_event_interval_corrected", "h1D_Multiplicity_short_event_interval_corrected; Multiplicity; Entries (normalized)", 5000,0,20000); + + h2D_EventBcoSpacing_CorrectedMultiplicity_ = new TH2D("h2D_EventBcoSpacing_CorrectedMultiplicity","h2D_EventBcoSpacing_CorrectedMultiplicity; Event-BCO Spacing; Multiplicity after push-back", 128, 0, 128, 5000, 0, 20000); + h2D_EventBcoSpacing_CorrectedMultiplicity_all_event_ = new TH2D("h2D_EventBcoSpacing_CorrectedMultiplicity_all_event_","h2D_EventBcoSpacing_CorrectedMultiplicity_all_event_; Event-BCO Spacing; Multiplicity after push-back", 128, 0, 128, 6000, 0, 24000); + + + trigger_BcoDiff_ = DeriveTriggerBcoDiffOfARun(run); +}; + +InttHitCarryoverMonitor::~InttHitCarryoverMonitor(){ + std::cout << "InttHitCarryoverMonitor::~InttHitCarryoverMonitor() Calling the deconstructor" << std::endl; + +}; + +int InttHitCarryoverMonitor::Init(PHCompositeNode *topNode){ + std::cout << "InttHitCarryoverMonitor::Init(PHCompositeNode *topNode) Initializing" << std::endl; + + this->PrepareHotChannelMap(); + + return Fun4AllReturnCodes::EVENT_OK; +}; + + +int InttHitCarryoverMonitor::InitRun(PHCompositeNode *topNode){ + std::cout << "InttHitCarryoverMonitor::InitRun(PHCompositeNode *topNode) Initializing for Run XXX... " << std::endl; + return Fun4AllReturnCodes::EVENT_OK; +}; + +int InttHitCarryoverMonitor::process_event(PHCompositeNode *topNode){ + if ( my_event_counter_ %200 == 0 ) { + std::cout<<"eID: " << my_event_counter_ << std::endl; + } + + for (int i=0; i<8; i++) { + std::string node_name = Form("%s_%d",node_name_intt_raw_hit_.c_str(), i); + container_ith_event_ = findNode::getClass(topNode, node_name.c_str()); + /* Prepare ith_event_ here. Clone hits and hot channels are removed. */ + this->ConvertFromRawHit(container_ith_event_); + } + + // std::string node_name = Form("%s",node_name_intt_raw_hit_.c_str()); + // container_ith_event_ = findNode::getClass(topNode, node_name.c_str()); + // /* Prepare ith_event_ here. Clone hits and hot channels are removed. */ + // this->ConvertFromRawHit(container_ith_event_); + + GetTriggerInformation(topNode, ith_event_); + CountNumberOfHitsInNominalTiming(ith_event_, trigger_BcoDiff_, intt_clock_offset_); + + if (ith_event_.n_intt_raw_hits == 0) { + std::cout << "ith_event_.n_intt_raw_hits = 0"<< std::endl ; + return Fun4AllReturnCodes::EVENT_OK; + } + CalculateHitBco(ith_event_, trigger_BcoDiff_, intt_clock_offset_); + + if ( my_event_counter_ == 0 ) { + return Fun4AllReturnCodes::EVENT_OK; /* Move to next event since it's the first event and we need 2 events to start comparing. */ + } + + + CountCarriedOverHitsPerEventBasis(previous_event_, ith_event_); + CountCarriedOverHitsPerHalfladderBasis(previous_event_, ith_event_); /* `h2D_Halfladder_NCOH_` and `h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_` are filled here. */ + CountCarriedOverHitsPerChipBasis(previous_event_, ith_event_); /* `h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_` is filled here */ + + this->FillHistograms(); + + this->PushBackNarrowSpacingCarryover(); + + CheckMultiplicity(); + + return Fun4AllReturnCodes::EVENT_OK; +} + +int InttHitCarryoverMonitor::ResetEvent(PHCompositeNode *topNode){ + // std::cout << "InttHitCarryoverMonitor::ResetEvent(PHCompositeNode *topNode) Resetting internal structures, prepare for next event" << std::endl; + + if ( save_tree_ ) { + output_tree_->Fill(); + } + + gl1_bco_previous_ = ith_event_.gl1_bco; + + /* temporary check */ + if ( ith_event_.n_intt_raw_hits==0 ) { + std::cout << "-- n_intt_raw_hits == 0 met in event " << my_event_counter_ << ". " << std::endl; + } + + /* temporary check */ + if ( ith_event_.num_of_carried_hits > 0 ) { + int event_bco_spacing = ith_event_.interval_from_previous; + + std::cout << "-- Carryover found in event " << my_event_counter_ << ". " << std::endl; + std::cout << " Event interval = " << event_bco_spacing << std::endl; + std::cout << " The num of hits in the previous event = " << previous_event_.n_hit_inner << "(inner) + " << previous_event_.n_hit_outer << "(outer)." << std::endl; + std::cout << " The num_of_carried_hits = " << ith_event_.num_of_carried_hits << " = " << ith_event_.num_of_carried_hits_inner << " (inner) + " << ith_event_.num_of_carried_hits_outer << " (outer)." << std::endl; + } + + + previous_event_ = ith_event_; + my_event_counter_++; + + ith_event_.n_intt_raw_hits=0; + ith_event_.bco.clear(); + ith_event_.felix_server.clear(); + ith_event_.word.clear(); + ith_event_.felix_channel.clear(); + ith_event_.chip.clear(); + ith_event_.channel.clear(); + ith_event_.adc.clear(); + ith_event_.FPHX_BCO.clear(); + ith_event_.full_FPHX.clear(); + ith_event_.full_ROC.clear(); + ith_event_.amplitude.clear(); + + ith_event_.h1D_fphxbco->Reset(); + ith_event_.hit_info_by_halfladder.clear(); + ith_event_.hit_info_by_chip.clear(); + ith_event_.hit_already_seen.clear(); + + ith_event_.hitbco_peak = -999; + ith_event_.bco_diff_peak = -999; + + ith_event_.num_of_carried_hits = 0; + ith_event_.num_of_carried_hits_inner = 0; + ith_event_.num_of_carried_hits_outer = 0; + + ith_event_.is_MBDNS_tight_inclusive = false; + ith_event_.is_MBDNS_tight_vtx10cm = false; + ith_event_.is_MBDNS_tight_vtx30cm = false; + + return Fun4AllReturnCodes::EVENT_OK; + +}; + +int InttHitCarryoverMonitor::Reset(PHCompositeNode *topNode){ + std::cout << "InttHitCarryoverMonitor::Reset(PHCompositeNode *topNode) being Reset" << std::endl; + return Fun4AllReturnCodes::EVENT_OK; +}; + +int InttHitCarryoverMonitor::EndRun(const int runnumber){ + std::cout << "InttHitCarryoverMonitor::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl; + return Fun4AllReturnCodes::EVENT_OK; +}; + +int InttHitCarryoverMonitor::End(PHCompositeNode *topNode){ + std::cout << "InttHitCarryoverMonitor::End(PHCompositeNode *topNode) This is the End... " << std::endl; + + output_file_->cd(); + + h2D_NInttHitInner_NInttHitOuter_->Write(); + h2D_NInttHitInner_NInttHitOuter_corrected_->Write(); + // h2D_EventBcoSpacing_NCarriedHits_->Write(); + h2D_NCarriedInner_NCarriedOuter_->Write(); + h2D_Halfladder_NCOH_->Write(); + + h1D_Halfladder_NHitInPreviousEvent_example_->Write(); + h1D_Halfladder_NCOH_example_->Write(); + + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event_->Write(); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_all_event_->Write(); + h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_all_event_->Write(); + + h2D_EventBcoSpacing_NHitInPreviousEvent_->Write(); + h2D_EventBcoSpacing_NCohInNextEvent_->Write(); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_->Write(); + h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_->Write(); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner_->Write(); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer_->Write(); + + h2D_MisasignedBcoDiff_NHitInPreviousEvent_->Write(); + h2D_MisasignedBcoDiff_NCohInNextEvent_->Write(); + + h2D_NInttHitInner_NInttHitOuter_narrow_spacing_->Write(); + + h1D_Multiplicity_long_event_interval_->Scale( 1 / h1D_Multiplicity_long_event_interval_->GetEntries() ); + h1D_Multiplicity_long_event_interval_->Write(); + h1D_Multiplicity_short_event_interval_->Scale( 1/ h1D_Multiplicity_short_event_interval_->GetEntries() ); + h1D_Multiplicity_short_event_interval_->Write(); + h1D_Multiplicity_short_event_interval_corrected_->Scale( 1/ h1D_Multiplicity_short_event_interval_corrected_->GetEntries() ); + h1D_Multiplicity_short_event_interval_corrected_->Write(); + + h2D_EventBcoSpacing_CorrectedMultiplicity_->Write(); + h2D_EventBcoSpacing_CorrectedMultiplicity_all_event_->Write(); + + if ( save_tree_ ) { + output_tree_->Write(); + } + output_file_->Close(); + + return Fun4AllReturnCodes::EVENT_OK; +}; + +// void InttHitCarryoverMonitor::Print(const std::string &what) const { +// std::cout << "InttHitCarryoverMonitor::Print(const std::string &what) const Printing info for " << what << std::endl; +// } + + + + + + + + + + + + + + + + + + + + + + + + + + +void InttHitCarryoverMonitor::GetTriggerInformation(PHCompositeNode *topNode, InttRawHitStructure& event) { + event.is_MBDNS_tight_inclusive = false; + event.is_MBDNS_tight_vtx10cm = false; + event.is_MBDNS_tight_vtx30cm = false; + + Gl1Packetv3* gl1 = findNode::getClass(topNode, node_name_gl1_raw_hit_.c_str()); + if (!gl1) { + std::cerr << "InttHitCarryoverMonitor::process_event - GL1RAWHIT node not found" << std::endl; + exit(1); + } + + /* BCO information */ + event.gl1_bco = gl1->lValue(0,"BCO"); + event.interval_from_previous = event.gl1_bco - gl1_bco_previous_; /* gl1_bco_previous_ is hold by InttHitCarryoverMonitor, not by InttRawHitStructure */ + if ( (intt_clock_offset_ == 0) && (event.n_intt_raw_hits > 0) ) { + uint64_t intt_bco = event.bco.at(0); + intt_clock_offset_ = event.gl1_bco - intt_bco; + std::cout << "intt_clock_offset_: " << intt_clock_offset_ << std::endl; + if ( intt_bco != (event.gl1_bco-intt_clock_offset_) ) { + std::cout << "bco not matched! gl1_bco: " << event.gl1_bco << "!= intt_bco(" << intt_bco << ") + offset(" << intt_clock_offset_ <<")." << std::endl; + } + } + + /* Live trigger information */ + long long live_trigger_decimal = gl1->lValue(0,"LiveVector"); + if (live_trigger_decimal < 0){ + std::cout << "InttHitCarryoverMonitor::GetTriggerInformation - live trigger is negative, "<< live_trigger_decimal << std::endl; + return; + } + std::vector live_trigger_vec = PrepareTriggerVector(live_trigger_decimal); + /* if a trigger code found, set a corresponding flag as true*/ + event.is_MBDNS_tight_inclusive = std::find( live_trigger_vec.begin(), live_trigger_vec.end(), MBDNS_tight_inclusive_) != live_trigger_vec.end(); + event.is_MBDNS_tight_vtx10cm = std::find( live_trigger_vec.begin(), live_trigger_vec.end(), MBDNS_tight_vtx10cm_) != live_trigger_vec.end(); + event.is_MBDNS_tight_vtx30cm = std::find( live_trigger_vec.begin(), live_trigger_vec.end(), MBDNS_tight_vtx30cm_) != live_trigger_vec.end(); + +} + + +std::vector InttHitCarryoverMonitor::PrepareTriggerVector(long long trigger_input) { + std::bitset<64> trigger_input_bitset(trigger_input); + std::vector output_vec; output_vec.clear(); + + for (unsigned int i=0; i<64; i++) { + if (trigger_input_bitset.test(i)) { output_vec.push_back(i); } + } + + return output_vec; +} + + +void InttHitCarryoverMonitor::PrepareHotChannelMap() { +// std::map InttHitCarryoverMonitor::PrepareHotChannelMap() { + TFile* input_file_hot_channel_map = TFile::Open(this->file_path_to_hot_channel_map_.c_str()); + if (!input_file_hot_channel_map) { + std::cout << "InttHitCarryoverMonitor::PrepareHotChannelMap - hot channel file not found" << std::endl; + exit(1); + } + + TTree* tree_hot_channel = (TTree*)input_file_hot_channel_map->Get(tree_name_hot_channel_.c_str()); + + int IID; + int Ichannel; + int Ichip; + int Ifelix_channel; + int Ifelix_server; + int Iflag; + + tree_hot_channel->SetBranchAddress("IID",&IID); + tree_hot_channel->SetBranchAddress("Ichannel",&Ichannel); + tree_hot_channel->SetBranchAddress("Ichip",&Ichip); + tree_hot_channel->SetBranchAddress("Ifelix_channel",&Ifelix_channel); + tree_hot_channel->SetBranchAddress("Ifelix_server",&Ifelix_server); + tree_hot_channel->SetBranchAddress("Iflag",&Iflag); + + // std::map hot_channel_map; /* key はともかく、value を string にする必要はないような*/ + + for (int i=0; iGetEntries(); i++) { + tree_hot_channel->GetEntry(i); + this->hot_channel_map_[Form("%d_%d_%d_%d",Ifelix_server,Ifelix_channel,Ichip,Ichannel)] = Form("%d",Iflag); + } + + +} + + +// InttRawHitStructure InttHitCarryoverMonitor::ConvertFromRawHit(InttRawHitContainer* container, const std::map hot_channel_map) { +void InttHitCarryoverMonitor::ConvertFromRawHit(InttRawHitContainer* container){//, const std::map hot_channel_map) { + + // InttRawHitStructure event; + + int felix_server; + int felix_channel; + int chip; + int channel; + + for ( unsigned int i = 0; i < container->get_nhits(); i++ ) { + InttRawHit* hit = container->get_hit(i); + + /* some conversions needed to adjust to value range of hot_channel_map_ */ + felix_server = hit->get_packetid() - 3001; + felix_channel = hit->get_fee(); + chip = (hit->get_chip_id() - 1) % 26; + channel = hit->get_channel_id(); + + if (hot_channel_map_.size() == 0) {std::cerr<<"map size zero"<FillAHit(hit); + ith_event_.n_intt_raw_hits++; + + } +} + +void CountNumberOfHitsInNominalTiming(InttRawHitStructure& event, const int triggered_BcoDiff, const int64_t intt_clock_offset) { + int n_hit_inner{0}; + int n_hit_outer{0}; + + int triggered_BcoDiff_n1 = (triggered_BcoDiff - 1 + 128) % 128; + int triggered_BcoDiff_p1 = (triggered_BcoDiff + 1 + 128) % 128; + + if ( !event.is_MBDNS_tight_vtx10cm ) {return;} + + for (int hit_index = 0; hit_index < event.n_intt_raw_hits; hit_index++) { + InttNameSpace::RawData_s rawdata; + rawdata.felix_server = event.felix_server.at(hit_index) - 3001; + rawdata.felix_channel = event.felix_channel.at(hit_index); + rawdata.chip = (event.chip.at(hit_index) - 1) % 26; + rawdata.channel = event.channel.at(hit_index); + + InttNameSpace::Offline_s offlinedata = InttNameSpace::ToOffline(rawdata); + if (offlinedata.layer != 3 && offlinedata.layer != 4 && offlinedata.layer != 5 && offlinedata.layer != 6){ + // std::cout << "pid: "<< rawdata.pid << ", fee: " << rawdata.fee << ", chp: " << rawdata.chp << ", chn: " << rawdata.chn << std::endl; + // std::cout << "layer: " << offlinedata.layer << ", ladder_phi: " << offlinedata.ladder_phi << ", ladder_z: " << offlinedata.ladder_z << ", strip_z: " << offlinedata.strip_z << ", strip_phi: " << offlinedata.strip_phi << std::endl; + // std::cout<ith_event_.bco.push_back( hit->get_bco() ); + this->ith_event_.felix_server.push_back( hit->get_packetid() ); + this->ith_event_.word.push_back( hit->get_word() ); + this->ith_event_.felix_channel.push_back( hit->get_fee() ); + this->ith_event_.chip.push_back( (hit->get_chip_id() - 1) % 26 ); + this->ith_event_.channel.push_back( hit->get_channel_id() ); + this->ith_event_.adc.push_back( hit->get_adc() ); + this->ith_event_.FPHX_BCO.push_back( hit->get_FPHX_BCO() ); + this->ith_event_.full_FPHX.push_back( hit->get_full_FPHX() ); + this->ith_event_.full_ROC.push_back( hit->get_full_ROC() ); + this->ith_event_.amplitude.push_back( hit->get_amplitude() ); + +} + +bool CheckCloneHits(InttRawHit* hit, InttRawHitStructure& structure) { + + int bco = hit->get_bco(); + int felix_server = hit->get_packetid(); + int felix_channel = hit->get_fee(); + int chip = hit->get_chip_id(); + int channel = hit->get_channel_id(); + int adc = hit->get_adc(); + int fphx_bco = hit->get_FPHX_BCO(); + + auto candidate = std::make_tuple(bco, felix_server, felix_channel, chip, channel, adc, fphx_bco); + // auto candidate = std::make_tuple(bco, felix_server, felix_channel, chip, channel, adc); + // auto candidate = std::make_tuple(bco, felix_server, felix_channel, chip, channel); + + if ( structure.hit_already_seen.find(candidate) == structure.hit_already_seen.end() ) { + structure.hit_already_seen.insert(candidate); /* A new hit. Insert to the record. */ + return false; + } else { + return true; /* Clone hit. */ + } + +} + +/* structure.bco.at(0) の計算を含んでいるので n_intt_raw_hits == 0 に注意 */ +void CalculateHitBco(InttRawHitStructure& event, const int triggered_BcoDiff_, const int64_t intt_clock_offset) { + event.h1D_fphxbco->Reset(); + + int triggered_BcoDiff_n1 = (triggered_BcoDiff_ - 1 + 128) % 128; + int triggered_BcoDiff_p1 = (triggered_BcoDiff_ + 1 + 128) % 128; + + for (int hit_index = 0; hit_index < event.n_intt_raw_hits; hit_index++) { + // int bco_diff = (event.FPHX_BCO.at(hit_index) - (event.bco.at(0) & 0x7fU) + 128) % 128; + int bco_diff = (event.FPHX_BCO.at(hit_index) - ( (event.gl1_bco-intt_clock_offset) & 0x7fU) + 128) % 128; + if (bco_diff != triggered_BcoDiff_n1 && bco_diff != triggered_BcoDiff_ && bco_diff != triggered_BcoDiff_p1) { + continue; + } + event.h1D_fphxbco->Fill(event.FPHX_BCO.at(hit_index)); + } + + event.hitbco_peak = event.h1D_fphxbco->GetBinCenter( event.h1D_fphxbco->GetMaximumBin() ); + // event.bco_diff_peak = (event.hitbco_peak - (event.bco.at(0) & 0x7fU) + 128) % 128; + event.bco_diff_peak = (event.hitbco_peak - ( (event.gl1_bco-intt_clock_offset)& 0x7fU) + 128) % 128; + +} + +bool EvaluateThisEvent(const InttRawHitStructure event){ + if ( event.n_intt_raw_hits == 0 ) {return false;} /*bad event*/ + if ( !event.is_MBDNS_tight_vtx10cm ) {return false;} + return true; /* good event */ +} + + +std::unordered_map< Chip, std::vector > PrepareHitInfoByChip(const InttRawHitStructure& event) { + std::unordered_map< Chip, std::vector > output; + + for (int hit_index = 0; hit_index < event.n_intt_raw_hits ; hit_index++) { + InttNameSpace::RawData_s rawdata; + rawdata.felix_server = event.felix_server.at(hit_index) - 3001; + rawdata.felix_channel = event.felix_channel.at(hit_index); + rawdata.chip = (event.chip.at(hit_index) - 1) % 26; + rawdata.channel = event.channel.at(hit_index); + + InttNameSpace::Offline_s offlinedata = InttNameSpace::ToOffline(rawdata); + auto layer_of_the_hit = offlinedata.layer; + if (layer_of_the_hit != 3 && layer_of_the_hit != 4 && layer_of_the_hit != 5 && layer_of_the_hit != 6){ + continue; + } + + auto fphx_bco_of_the_hit = event.FPHX_BCO.at(hit_index); + + // Chip hit_chip{event.felix_server.at(hit_index), event.felix_channel.at(hit_index), event.channel.at(hit_index)}; + Chip hit_chip{event.felix_server.at(hit_index), event.felix_channel.at(hit_index), event.chip.at(hit_index)}; + output[hit_chip].push_back( + std::make_tuple( layer_of_the_hit, fphx_bco_of_the_hit ) + ); + } + + return output; +} + +std::map< HalfLadder, std::vector > PrepareHitInfoByHalfladder(const InttRawHitStructure event) { + std::map< HalfLadder, std::vector > output; /* This will be copied to `event.hit_info_by_halfladder` */ + for (int hit_index = 0; hit_index < event.n_intt_raw_hits ; hit_index++) { + InttNameSpace::RawData_s rawdata; + rawdata.felix_server = event.felix_server.at(hit_index) - 3001; + rawdata.felix_channel = event.felix_channel.at(hit_index); + rawdata.chip = (event.chip.at(hit_index) - 1) % 26; + rawdata.channel = event.channel.at(hit_index); + + InttNameSpace::Offline_s offlinedata = InttNameSpace::ToOffline(rawdata); + auto layer_of_the_hit = offlinedata.layer; + if (layer_of_the_hit != 3 && layer_of_the_hit != 4 && layer_of_the_hit != 5 && layer_of_the_hit != 6){ + continue; + } + + auto fphx_bco_of_the_hit = event.FPHX_BCO.at(hit_index); + + HalfLadder half_ladder{event.felix_server.at(hit_index), event.felix_channel.at(hit_index)}; + output[half_ladder].push_back( + std::make_tuple( layer_of_the_hit, fphx_bco_of_the_hit ) + ); + } + + return output; +} + +void CountCarriedOverHitsPerEventBasis(InttRawHitStructure event_of_interest, InttRawHitStructure& next_event){ + next_event.num_of_carried_hits = 0; + next_event.num_of_carried_hits_inner=0; + next_event.num_of_carried_hits_outer=0; + + if (next_event.n_intt_raw_hits == 0){ + return; + } + + + // int full_bco_of_ith_event = event_of_interest.bco.at(0); + // int full_bco_of_next_event = next_event.bco.at(0); + // int event_bco_spacing = full_bco_of_next_event - full_bco_of_ith_event; + // if ( event_bco_spacing > 126 ){ + // return; + // } + + if ( next_event.interval_from_previous > 126 ){ + return; + } + + next_event.hit_info_by_halfladder = PrepareHitInfoByHalfladder(next_event); + next_event.hit_info_by_chip = PrepareHitInfoByChip(next_event); + + // /* update if the interval is short ( 0 was misassigned for such event by mistake in most cases ) */ + // if ( 17 <= event_bco_spacing && event_bco_spacing <= 22) { + // event_of_interest.hitbco_peak = (next_event.hitbco_peak - event_bco_spacing + 128)%128; + // } + // // event_of_interest.hitbco_peak = (next_event.hitbco_peak - event_bco_spacing + 128)%128; + + int anticipated_timing = (next_event.hitbco_peak - next_event.interval_from_previous + 128)%128; + /* calculate backward if no trigger timing hit was recorded in the previous event */ + if ( event_of_interest.h1D_fphxbco->GetEntries() == 0 ) { + event_of_interest.hitbco_peak = (next_event.hitbco_peak - next_event.interval_from_previous + 128)%128; + } + + /* Count the number of carried over hits. */ + /* Each loop of the outer loop corresponds to each half ladder. */ + /* In the inner loop, carried-over hits are determined. */ + + /* per-half-ladder basis analysis */ + for (auto key_value : next_event.hit_info_by_halfladder){ + HalfLadder halfladder = key_value.first; + // int n_hits_in_that_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(event_of_interest.hit_info_by_halfladder, halfladder, event_of_interest.hitbco_peak); + int n_hits_in_that_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder( PrepareHitInfoByHalfladder(event_of_interest), halfladder, event_of_interest.hitbco_peak); + + if ( n_hits_in_that_halfladder < 6.5*(next_event.interval_from_previous-25) ) { + continue; + } + + std::vector pairs = key_value.second; + for (int next_hit_i = 0; next_hit_i < int(pairs.size()); next_hit_i++) { + + LayerAndBco layer_bco = pairs[next_hit_i]; + int next_hit_layer = std::get<0>(layer_bco); + int next_hit_bco = std::get<1>(layer_bco); + + int hit_bco_n1 = (anticipated_timing -1 + 128)%128; + int hit_bco_p1 = (anticipated_timing +1 + 128)%128; + if (next_hit_bco == anticipated_timing || next_hit_bco == hit_bco_n1 || next_hit_bco == hit_bco_p1) { + if (next_hit_layer == 3 || next_hit_layer == 4) {next_event.num_of_carried_hits_inner++;} + else if (next_hit_layer == 5 || next_hit_layer == 6) {next_event.num_of_carried_hits_outer++;} + next_event.num_of_carried_hits++; + } else { /* move to next halfladder after the first hit with a different hit bco than ith_event.hitbco_peak */ + // break; /* commented out to execute the criteria ver. 2 in the step 2 */ + } + } + } + + /* per-chip basis analysis */ + // for (auto key_value : next_event.hit_info_by_chip){ + // Chip chip = key_value.first; + // std::vector pairs = key_value.second; + + // // int num_hits_in_that_chip = GetNumberOfHitsInNormalTimingInAChip(event_of_interest.hit_info_by_chip, chip, event_of_interest.hitbco_peak); + // int num_hits_in_that_chip = GetNumberOfHitsInNormalTimingInAChip(PrepareHitInfoByChip(event_of_interest), chip, event_of_interest.hitbco_peak); + // if ( num_hits_in_that_chip < 2*(next_event.interval_from_previous-25) ) { + // continue; + // } + + // for (int next_hit_i = 0; next_hit_i < int(pairs.size()); next_hit_i++) { + + // LayerAndBco layer_bco = pairs[next_hit_i]; + // int next_hit_layer = std::get<0>(layer_bco); + // int next_hit_bco = std::get<1>(layer_bco); + + // if (next_hit_bco == anticipated_timing || next_hit_bco == ((anticipated_timing -1+128)%128) || next_hit_bco == ((anticipated_timing +1+128)%128) ) { + // if (next_hit_layer == 3 || next_hit_layer == 4) {next_event.num_of_carried_hits_inner++;} + // else if (next_hit_layer == 5 || next_hit_layer == 6) {next_event.num_of_carried_hits_outer++;} + // next_event.num_of_carried_hits++; + // } else { + // //break; /* commented out to execute the criteria ver. 2 in the step 2 */ + // } + // } + // } +} + +void InttHitCarryoverMonitor::CountCarriedOverHitsPerHalfladderBasis(InttRawHitStructure event_of_interest, InttRawHitStructure& next_event){ + + if (next_event.n_intt_raw_hits == 0){ + return; + } + + // if (next_event.bco.size() == 0) { + // std::cout << " next_event.n_intt_raw_hits" << next_event.n_intt_raw_hits << std::endl; + // std::cout << " next_event.bco.size()" << next_event.bco.size() << std::endl; + // return; + // } + + // int full_bco_of_ith_event = event_of_interest.bco.at(0); + // int full_bco_of_next_event = next_event.bco.at(0); + // int event_bco_spacing = full_bco_of_next_event - full_bco_of_ith_event; + // if ( event_bco_spacing > 126 ){ + // return; + // } + + if ( next_event.interval_from_previous > 126 ){ + return; + } + + + next_event.hit_info_by_halfladder = PrepareHitInfoByHalfladder(next_event); + + + + /* update if the interval is short ( 0 was misassigned for such event by mistake in most cases ) */ + // if ( 17 <= event_bco_spacing && event_bco_spacing <= 126) { + // event_of_interest.hitbco_peak = (next_event.hitbco_peak - event_bco_spacing + 128)%128; + // } + int anticipated_timing = (next_event.hitbco_peak - next_event.interval_from_previous + 128)%128; + /* (The method 2 in the step 1) calculate backward if no trigger-timing hit was recorded in the previous event */ + if ( event_of_interest.h1D_fphxbco->GetEntries() == 0) { + event_of_interest.hitbco_peak = (next_event.hitbco_peak - next_event.interval_from_previous + 128)%128; + } + + /* Count the number of carried over hits. */ + /* Each loop of the outer loop corresponds to each half ladder. */ + /* In the inner loop, carried-over hits are determined. */ + int halfladder_id = 0; + int n_carried_hits_by_halfladder; + for (auto key_value : next_event.hit_info_by_halfladder){ + n_carried_hits_by_halfladder = 0; + halfladder_id++; + HalfLadder halfladder = key_value.first; + std::vector pairs = key_value.second; + + // int n_hits_in_that_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(event_of_interest.hit_info_by_halfladder, halfladder, event_of_interest.hitbco_peak); + int n_hits_in_that_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(PrepareHitInfoByHalfladder(event_of_interest), halfladder, event_of_interest.hitbco_peak); + // int n_hits_in_that_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(event_of_interest.hit_info_by_halfladder, halfladder, event_of_interest.gl1_bco, trigger_BcoDiff_, intt_clock_offset_); + // int n_hits_in_that_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder( PrepareHitInfoByHalfladder(event_of_interest), halfladder, event_of_interest.gl1_bco, trigger_BcoDiff_, intt_clock_offset_); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_all_event_->Fill(next_event.interval_from_previous, n_hits_in_that_halfladder); + + if ( n_hits_in_that_halfladder < 6.5*(next_event.interval_from_previous-25) ) { + continue; + } + + + for (int next_hit_i = 0; next_hit_i < int(pairs.size()); next_hit_i++) { + + LayerAndBco layer_bco = pairs[next_hit_i]; + // int next_hit_layer = std::get<0>(layer_bco); /* not used here */ + int next_hit_bco = std::get<1>(layer_bco); + + if (next_hit_bco == anticipated_timing || next_hit_bco == ((anticipated_timing-1+128)%128) || next_hit_bco == ((anticipated_timing+1+128)%128) ) { + n_carried_hits_by_halfladder++; + } else { + // if ( n_carried_hits_by_halfladder > 0 ){ + // h2D_Halfladder_NCOH_->Fill(halfladder_id,n_carried_hits_by_halfladder); + // } + // if ( n_carried_hits_by_halfladder > 0 ) { + + // // int number_of_hit_in_the_halfladder = GetNumberOfHitsInAChip_HalfladderbyHalfladder(event_of_interest.hit_info_by_halfladder, halfladder, event_of_interest.hitbco_peak); + // int number_of_hit_in_the_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(event_of_interest.hit_info_by_halfladder, halfladder, event_of_interest.hitbco_peak); + // h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_->Fill(next_event.interval_from_previous, number_of_hit_in_the_halfladder); + // if (number_of_hit_in_the_halfladder>0) { + // h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_->Fill(event_bco_spacing, number_of_hit_in_the_halfladder); + // } + + // auto iterator = event_of_interest.hit_info_by_halfladder.find(halfladder); //temp_info_by_half_ladder_forithevent.find(halfladder); + // if ( iterator != event_of_interest.hit_info_by_halfladder.end() ) { + // //HalfLadder half_ith = iterator->first; /* not used here */ + // std::vector pairs = iterator->second; + // int number_of_hit_in_the_halfladder = pairs.size(); + + // h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_->Fill(event_bco_spacing, number_of_hit_in_the_halfladder); + + // int layer = std::get<0>(layer_bco); /* derived from `next_event`, but it's the same halfladder/layer as that of previous event, since */ + // if ( layer == 3 || layer == 4 ) {h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner_->Fill(event_bco_spacing,number_of_hit_in_the_halfladder);} + // if ( layer == 5 || layer == 6 ) {h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer_->Fill(event_bco_spacing,number_of_hit_in_the_halfladder);} + // } + } /* move to next halfladder after the first hit with a different hit bco than ith_event.hitbco_peak */ + // break; /* commented out to execute the criteria ver. 2 in the step 2 */ + } + + if ( n_carried_hits_by_halfladder > 0 ){ + h2D_Halfladder_NCOH_->Fill(halfladder_id,n_carried_hits_by_halfladder); + // int number_of_hit_in_the_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(event_of_interest.hit_info_by_halfladder, halfladder, event_of_interest.hitbco_peak); + int number_of_hit_in_the_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(PrepareHitInfoByHalfladder(event_of_interest), halfladder, event_of_interest.hitbco_peak); + // int number_of_hit_in_the_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(event_of_interest.hit_info_by_halfladder, halfladder, event_of_interest.gl1_bco, trigger_BcoDiff_, intt_clock_offset_); + // int number_of_hit_in_the_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(PrepareHitInfoByHalfladder(event_of_interest), halfladder, event_of_interest.gl1_bco, trigger_BcoDiff_, intt_clock_offset_); + h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_->Fill(next_event.interval_from_previous, number_of_hit_in_the_halfladder); + } + + /* temp check */ + if ( my_event_counter_ == 1428 ) { + // int number_of_hit_in_the_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(event_of_interest.hit_info_by_halfladder, halfladder, event_of_interest.gl1_bco, trigger_BcoDiff_, intt_clock_offset_); + int number_of_hit_in_the_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(PrepareHitInfoByHalfladder(event_of_interest), halfladder, event_of_interest.hitbco_peak); + // int number_of_hit_in_the_halfladder = GetNumberOfHitsInNormalTimingInAHalfladder(PrepareHitInfoByHalfladder(event_of_interest), halfladder, event_of_interest.gl1_bco, trigger_BcoDiff_, intt_clock_offset_); + for (int i=0; iFill(halfladder_id); + } + for (int i=0; iFill(halfladder_id); + } + // std::cout << "Saved an event for a check" << std::endl; + } + } +} + +void InttHitCarryoverMonitor::CountCarriedOverHitsPerChipBasis(InttRawHitStructure event_of_interest, InttRawHitStructure& next_event){ + + if (next_event.n_intt_raw_hits == 0){ + return; + } + + /* Can be omitted. Probably... */ + // if (next_event.bco.size() == 0) { + // std::cout << " next_event.n_intt_raw_hits" << next_event.n_intt_raw_hits << std::endl; + // std::cout << " next_event.bco.size()" << next_event.bco.size() << std::endl; + // return; + // } + + // int full_bco_of_ith_event = event_of_interest.bco.at(0); + // int full_bco_of_next_event = next_event.bco.at(0); + // int event_bco_spacing = full_bco_of_next_event - full_bco_of_ith_event; + // if ( event_bco_spacing > 126 ){ + // return; + // } + if ( next_event.interval_from_previous > 126 ){ + return; + } + + /* `ith_event.hit_info_by_chip` shoud be filled in the previous event loop. */ + next_event.hit_info_by_chip = PrepareHitInfoByChip(next_event); + + + + + int anticipated_timing = (next_event.hitbco_peak - next_event.interval_from_previous + 128)%128; + /* calculate backward if no trigger timing hit was recorded in the previous event */ + if ( event_of_interest.h1D_fphxbco->GetEntries() == 0 ) { + event_of_interest.hitbco_peak = (next_event.hitbco_peak - next_event.interval_from_previous + 128)%128; + } + + /* Count the number of carried over hits. */ + /* Each loop of the outer loop corresponds to each half ladder. */ + /* In the inner loop, carried-over hits are determined. */ + int n_carried_hits_by_chip{0}; + for (auto key_value : next_event.hit_info_by_chip) { + Chip chip = key_value.first; + std::vector pairs = key_value.second; + + // int num_hits_in_that_chip = GetNumberOfHitsInNormalTimingInAChip(event_of_interest.hit_info_by_chip, chip, event_of_interest.hitbco_peak); + int num_hits_in_that_chip = GetNumberOfHitsInNormalTimingInAChip(PrepareHitInfoByChip(event_of_interest), chip, event_of_interest.hitbco_peak); + h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_all_event_->Fill(next_event.interval_from_previous, num_hits_in_that_chip); + // if ( num_hits_in_that_chip < 2*(next_event.interval_from_previous-25) ) { + // continue; + // } + + + for (int next_hit_i = 0; next_hit_i < int(pairs.size()); next_hit_i++) { + + LayerAndBco layer_bco = pairs[next_hit_i]; + // int next_hit_layer = std::get<0>(layer_bco); /* not used here */ + int next_hit_bco = std::get<1>(layer_bco); + + if (next_hit_bco == anticipated_timing || next_hit_bco == ((anticipated_timing -1+128)%128) || next_hit_bco == ((anticipated_timing +1+128)%128) ) { + n_carried_hits_by_chip++; + } else { + // if ( n_carried_hits_by_chip > 0 ) { + + // /* count the number of hits in that chip recorded in i-th hit */ + // int num_hits_in_that_chip = GetNumberOfHitsInNormalTimingInAChip(event_of_interest.hit_info_by_chip, chip, event_of_interest.hitbco_peak); + // h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_->Fill(event_bco_spacing, num_hits_in_that_chip); + // if (num_hits_in_that_chip > 0) { + // h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_->Fill(event_bco_spacing, num_hits_in_that_chip); + // } + + // int number_of_hit_in_the_chip; + // auto iterator = event_of_interest.hit_info_by_chip.find(chip); + // if ( iterator != event_of_interest.hit_info_by_chip.end() ) { + // //Chip chip_ith = iterator->first; /* not used here */ + // std::vector pairs = iterator->second; + // number_of_hit_in_the_chip = pairs.size(); + + // h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_->Fill(event_bco_spacing, number_of_hit_in_the_chip); + // } + // } /* move to next chip after the first hit with a different hit bco from ith_event.hitbco_peak */ + // break; /* commented out to execute the criteria ver. 2 in the step 2 */ + } + } + if ( n_carried_hits_by_chip > 0 ) { + + /* count the number of hits in that chip recorded in i-th hit */ + // int num_hits_in_that_chip = GetNumberOfHitsInNormalTimingInAChip(event_of_interest.hit_info_by_chip, chip, event_of_interest.hitbco_peak); + int num_hits_in_that_chip = GetNumberOfHitsInNormalTimingInAChip(PrepareHitInfoByChip(event_of_interest), chip, event_of_interest.hitbco_peak); + h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_->Fill(next_event.interval_from_previous, num_hits_in_that_chip); + } + } +} + + +void InttHitCarryoverMonitor::FillHistograms() { + + if (!previous_event_.is_MBDNS_tight_vtx10cm) { + return; + } + // if (previous_event_.n_intt_raw_hits == 0) { + // return; + // } + + /* This was the cause of the distinction at interval=22*/ + // if ( previous_event_.bco_diff_peak != trigger_BcoDiff_ && previous_event_.bco_diff_peak != (trigger_BcoDiff_-1+128)%128 && previous_event_.bco_diff_peak != (trigger_BcoDiff_+1+128)%128) { + // return; + // } + + h2D_NInttHitInner_NInttHitOuter_->Fill(previous_event_.n_hit_inner, previous_event_.n_hit_outer); + + if (ith_event_.n_intt_raw_hits == 0) { + h2D_NInttHitInner_NInttHitOuter_corrected_->Fill(previous_event_.n_hit_inner, + previous_event_.n_hit_outer); + } else if (ith_event_.num_of_carried_hits > 0){ + h2D_NInttHitInner_NInttHitOuter_corrected_->Fill(previous_event_.n_hit_inner + ith_event_.num_of_carried_hits_inner, + previous_event_.n_hit_outer + ith_event_.num_of_carried_hits_outer); + } else { + h2D_NInttHitInner_NInttHitOuter_corrected_->Fill(previous_event_.n_hit_inner , + previous_event_.n_hit_outer ); + } + + if ( ith_event_.n_intt_raw_hits > 0 ) { + // int full_bco_of_ith_event = previous_event_.bco.at(0); + // int full_bco_of_next_event = ith_event_.bco.at(0); + // int event_bco_spacing = full_bco_of_next_event - full_bco_of_ith_event; + int full_bco_of_next_event = ith_event_.gl1_bco-intt_clock_offset_; + int event_bco_spacing = ith_event_.interval_from_previous; + h2D_EventBcoSpacing_NHitInPreviousEvent_all_event_->Fill(event_bco_spacing, previous_event_.n_hit_inner+previous_event_.n_hit_outer); + h2D_EventBcoSpacing_CorrectedMultiplicity_all_event_->Fill(event_bco_spacing, previous_event_.n_hit_inner + previous_event_.n_hit_outer + ith_event_.num_of_carried_hits); + + + if (ith_event_.num_of_carried_hits > 0){ + if ( event_bco_spacing>127 ){ return; } + // h2D_EventBcoSpacing_NCarriedHits_->Fill(event_bco_spacing, ith_event_.num_of_carried_hits); + + h2D_NCarriedInner_NCarriedOuter_->Fill( ith_event_.num_of_carried_hits_inner, ith_event_.num_of_carried_hits_outer); + + h2D_EventBcoSpacing_NHitInPreviousEvent_->Fill(event_bco_spacing, previous_event_.n_hit_inner+previous_event_.n_hit_outer); + h2D_EventBcoSpacing_NCohInNextEvent_->Fill(event_bco_spacing, ith_event_.num_of_carried_hits); + //int misasigned_bco_diff = (previous_event_.hitbco_peak - ith_event_.hitbco_peak +1 + 128 ) % 128; + int misasigned_bco_diff = (previous_event_.hitbco_peak - ((full_bco_of_next_event)&(0x7fU)) + 128 - trigger_BcoDiff_ ) % 128; + h2D_MisasignedBcoDiff_NHitInPreviousEvent_->Fill(misasigned_bco_diff, previous_event_.n_hit_inner+previous_event_.n_hit_outer); + h2D_MisasignedBcoDiff_NCohInNextEvent_->Fill(misasigned_bco_diff, ith_event_.num_of_carried_hits); + + h2D_EventBcoSpacing_CorrectedMultiplicity_->Fill(event_bco_spacing, previous_event_.n_hit_inner + previous_event_.n_hit_outer + ith_event_.num_of_carried_hits); + } + } +} + +int DeriveTriggerBcoDiffOfARun(int run){ + std::map run_to_bcodiff; + + run_to_bcodiff.insert( std::pair(68007, 89)); + run_to_bcodiff.insert( std::pair(68008, 81)); + run_to_bcodiff.insert( std::pair(68009, 17)); + run_to_bcodiff.insert( std::pair(68010, 25)); + run_to_bcodiff.insert( std::pair(68012, 89)); + run_to_bcodiff.insert( std::pair(68013, 49)); + run_to_bcodiff.insert( std::pair(68014, 1)); + run_to_bcodiff.insert( std::pair(68015, 81)); + run_to_bcodiff.insert( std::pair(66522, 97)); + run_to_bcodiff.insert( std::pair(66682, 100)); + + run_to_bcodiff.insert( std::pair(68002, 33)); + run_to_bcodiff.insert( std::pair(69404, 44)); + run_to_bcodiff.insert( std::pair(71251, 9)); + run_to_bcodiff.insert( std::pair(71345, 118)); + run_to_bcodiff.insert( std::pair(71346, 94)); + run_to_bcodiff.insert( std::pair(71347, 110)); + run_to_bcodiff.insert( std::pair(71391, 80)); + run_to_bcodiff.insert( std::pair(71456, 23)); + run_to_bcodiff.insert( std::pair(75519, 11)); + run_to_bcodiff.insert( std::pair(75535, 31)); + run_to_bcodiff.insert( std::pair(75536, 103)); + + run_to_bcodiff.insert( std::pair(79244, 1)); + run_to_bcodiff.insert( std::pair(79252, 40)); + run_to_bcodiff.insert( std::pair(79261, 105)); + run_to_bcodiff.insert( std::pair(79263, 16)); + run_to_bcodiff.insert( std::pair(79264, 49)); + run_to_bcodiff.insert( std::pair(79265, 121)); + run_to_bcodiff.insert( std::pair(79266, 65)); + + run_to_bcodiff.insert( std::pair(82400, 71)); + + if (run_to_bcodiff.contains(run)) { + return run_to_bcodiff.at(run); + } else { + std::cerr << "ERROR!!! Run " << run << " does not exist in the dictionary of DeriveTriggerBcoDiffOfARun(run)" << std::endl; + std::exit(EXIT_FAILURE); + } +} + +// int InttHitCarryoverMonitor::DeriveTriggerBcoDiff(){ +// ith_event_ +// } + +void InttHitCarryoverMonitor::PushBackNarrowSpacingCarryover(){ + // int full_bco_of_ith_event = previous_event_.bco.at(0); + // int full_bco_of_next_event = ith_event_.bco.at(0); + // int event_bco_spacing = full_bco_of_next_event - full_bco_of_ith_event; + int full_bco_of_next_event = ith_event_.gl1_bco-intt_clock_offset_; + int event_bco_spacing = ith_event_.interval_from_previous; + if ( event_bco_spacing>22 ) {return;} + if ( ith_event_.n_intt_raw_hits == 0 ) {return;} + if ( 17 <= event_bco_spacing && event_bco_spacing <= 22){ + int n_hits_maybe_carried_inner(0); + int n_hits_maybe_carried_outer(0); + int misassigned_bco(0); + for (int hit_index=0; hit_indexFill(n_hits_maybe_carried_inner, n_hits_maybe_carried_outer); + } +} + +void InttHitCarryoverMonitor::CheckMultiplicity() { + // int full_bco_of_ith_event = previous_event_.bco.at(0); + // int full_bco_of_next_event = ith_event_.bco.at(0); + // int event_bco_spacing = full_bco_of_next_event - full_bco_of_ith_event; + int event_bco_spacing = ith_event_.interval_from_previous; + if ( event_bco_spacing > 80 ) { + h1D_Multiplicity_long_event_interval_->Fill(previous_event_.n_hit_inner + previous_event_.n_hit_outer); + } + if ( 17 <= event_bco_spacing && event_bco_spacing <= 80) { + h1D_Multiplicity_short_event_interval_->Fill(previous_event_.n_hit_inner + previous_event_.n_hit_outer); + h1D_Multiplicity_short_event_interval_corrected_->Fill(previous_event_.n_hit_inner + previous_event_.n_hit_outer + ith_event_.num_of_carried_hits); + } +} + + +int GetNumberOfHitsInNormalTimingInAHalfladder(const std::map< HalfLadder, std::vector > list, const HalfLadder halfladder, const int standard_timing){ + int n_hits_in_that_halfladder{0}; + auto iterator_previous_event = list.find(halfladder); + if ( iterator_previous_event != list.end() ) { + std::vector pairs_previous_event = iterator_previous_event->second; + + for (int hit_index = 0; hit_index < int(pairs_previous_event.size()); hit_index++) { + int previous_hit_bco = std::get<1>(pairs_previous_event[hit_index]); + if ( previous_hit_bco == standard_timing || previous_hit_bco == ((standard_timing -1+128)%128) || previous_hit_bco == ((standard_timing +1+128)%128) ) { + n_hits_in_that_halfladder++; + } + } + } + return n_hits_in_that_halfladder; +} + +int GetNumberOfHitsInNormalTimingInAHalfladder(const std::map< HalfLadder, std::vector > list, const HalfLadder halfladder, const int gl1_bco, const int triggered_BcoDiff, const int64_t intt_clock_offset){ + int n_hits_in_that_halfladder{0}; + auto iterator_previous_event = list.find(halfladder); + if ( iterator_previous_event != list.end() ) { + std::vector pairs_previous_event = iterator_previous_event->second; + + for (int hit_index = 0; hit_index < int(pairs_previous_event.size()); hit_index++) { + int previous_hit_bco = std::get<1>(pairs_previous_event[hit_index]); + int previous_hit_bcodiff = (previous_hit_bco - ((gl1_bco - intt_clock_offset)&0x7fU) +128)%128; + if ( previous_hit_bcodiff == triggered_BcoDiff || previous_hit_bcodiff == ((triggered_BcoDiff -1+128)%128) || previous_hit_bcodiff == ((triggered_BcoDiff +1+128)%128) ) { + n_hits_in_that_halfladder++; + } + } + } + return n_hits_in_that_halfladder; +} + +int GetNumberOfHitsInAChip_HalfladderbyHalfladder(const std::map< HalfLadder, std::vector > list, const HalfLadder halfladder, const int standard_timing){ + int n_hits_in_that_halfladder{0}; + auto iterator_previous_event = list.find(halfladder); + if ( iterator_previous_event != list.end() ) { + std::vector pairs_previous_event = iterator_previous_event->second; + n_hits_in_that_halfladder = pairs_previous_event.size(); + } + return n_hits_in_that_halfladder; +} + +int GetNumberOfHitsInNormalTimingInAChip(const std::unordered_map< Chip, std::vector > list, const Chip chip, const int standard_timing){ + int n_hits_in_that_chip{0}; + auto iterator_previous_event = list.find(chip); + if ( iterator_previous_event != list.end() ) { + std::vector pairs_previous_event = iterator_previous_event->second; + + for (int hit_index = 0; hit_index < int(pairs_previous_event.size()); hit_index++) { + int previous_hit_bco = std::get<1>(pairs_previous_event[hit_index]); + if ( previous_hit_bco == standard_timing || previous_hit_bco == ((standard_timing -1+128)%128) || previous_hit_bco == ((standard_timing +1+128)%128) ) { + n_hits_in_that_chip++; + } + } + } + return n_hits_in_that_chip; +} + +int GetNumberOfHitsInAChip_ChipByChip(const std::unordered_map< Chip, std::vector > list, const Chip chip, const int standard_timing){ + int n_hits_in_that_chip{0}; + auto iterator_previous_event = list.find(chip); + if ( iterator_previous_event != list.end() ) { + std::vector pairs_previous_event = iterator_previous_event->second; + n_hits_in_that_chip = pairs_previous_event.size(); + } + return n_hits_in_that_chip; +} + diff --git a/general_codes/ryotaro/CarriedOverHits/src/InttHitCarryoverMonitor.h b/general_codes/ryotaro/CarriedOverHits/src/InttHitCarryoverMonitor.h new file mode 100644 index 0000000..149e3b8 --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/src/InttHitCarryoverMonitor.h @@ -0,0 +1,205 @@ +// Fun4All analysis module for INTT hit carryover monitor, made by Ryotaro Koike 20250808 +#ifndef INTT_HITCARRYOVER_MONITOR_H_20250808 +#define INTT_HITCARRYOVER_MONITOR_H_20250808 + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + + +#include +#include +#include +#include +#include +#include +#include + +#include + +using HalfLadder = std::pair; /* */ +using LayerAndBco = std::tuple; /* , which is denied for each hit> */ + +using Chip = std::tuple; /* */ +/* Below is an implementation of hash function. */ +/* This is needed to use the `Chip` type as a key of `std::unorderd_map`. */ +/* The use of `std::unorderd_map` makes the execution of this module much fast.*/ +namespace std { + template <> + struct hash { + std::size_t operator()(const Chip& chip) const { + std::size_t h1 = std::hash{}(std::get<0>(chip)); + std::size_t h2 = std::hash{}(std::get<1>(chip)); + std::size_t h3 = std::hash{}(std::get<2>(chip)); + + // ハッシュ値の合成(Boost 推奨のやり方に近い) + std::size_t seed = h1; + seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= h3 + 0x9e3779b9 + (seed << 6) + (seed >> 2); + return seed; + } + }; +} + + + + + + +/* helper structure */ +struct InttRawHitStructure { + uint64_t gl1_bco; /* have value even when INTT has no hit (unlike the std::vector bco) */ + int64_t interval_from_previous; + + /* values that will be set by tree->GetEntry(i) */ + int n_intt_raw_hits = 0; + std::vector bco; + std::vector felix_server; // packetid; + std::vector word; + std::vector felix_channel; // fee; + std::vector channel; // channel_id; + std::vector chip; // chip_id; + std::vector adc; + std::vector FPHX_BCO; + std::vector full_FPHX; + std::vector full_ROC; + std::vector amplitude; + bool is_MBDNS_tight_inclusive = false; + bool is_MBDNS_tight_vtx10cm = false; + bool is_MBDNS_tight_vtx30cm = false; + + /* values below will be derived from values above */ + int hitbco_peak = -999; + int bco_diff_peak = -999; + int n_hit_inner = 0; + int n_hit_outer = 0; + int num_of_carried_hits = 0; /* carried-over hits from the previous event */ + int num_of_carried_hits_inner = 0; + int num_of_carried_hits_outer = 0; + TH1D* h1D_fphxbco = new TH1D(Form("evt_this_INTTHitBco_%p", this), "evt_this_INTTHitBco;INTT BCO", 128, -0.5, 127.5); + + /* This must be `map`, not `unordered_map`, so that halfladder_id calculation makes sense. */ + std::map< HalfLadder, std::vector > hit_info_by_halfladder; + /* This is `unordered_map` to have the excution time short. (Search of an element takes time.) */ + std::unordered_map< Chip, std::vector > hit_info_by_chip; + std::set< std::tuple > hit_already_seen; /* for clone hit detection*/ + // std::set< std::tuple > hit_already_seen; /* for clone hit detection*/ + // std::set< std::tuple > hit_already_seen; /* for clone hit detection*/ + +}; + + + +class InttHitCarryoverMonitor : public SubsysReco { + public: + // InttHitCarryoverMonitor(const std::string &name, int run); + InttHitCarryoverMonitor(const std::string &name, const int run, const std::string arg_file_path_to_hot_channel_map, std::string job_index, bool save_tree); + ~InttHitCarryoverMonitor(); + + // mandatory methods for Fun4All analysis module + int Init(PHCompositeNode *topNode) override; + int InitRun(PHCompositeNode *topNode) override; + int process_event(PHCompositeNode *topNode) override; + int ResetEvent(PHCompositeNode *topNode) override; + int Reset(PHCompositeNode *topNode) override; + int EndRun(const int runnumber) override; + int End(PHCompositeNode *topNode) override; + // void Print(const std::string &what) const override; + + + + private: + bool save_tree_; + TTree* output_tree_; + + int my_event_counter_; + int trigger_BcoDiff_; + + uint64_t gl1_bco_previous_; + // uint64_t gl1_bco_ith_; + // int64_t interval_from_previous_; + int64_t intt_clock_offset_; + + InttRawHitContainer* container_ith_event_; + + /* This structure is free from hot channels and clone hits. */ + InttRawHitStructure previous_event_; + InttRawHitStructure ith_event_; + + std::string file_path_to_hot_channel_map_; + std::map hot_channel_map_; + + TFile* output_file_; + TH2D* h2D_NInttHitInner_NInttHitOuter_; + TH2D* h2D_NInttHitInner_NInttHitOuter_corrected_; + // TH2D* h2D_EventBcoSpacing_NCarriedHits_; + TH2D* h2D_NCarriedInner_NCarriedOuter_; + TH2D* h2D_Halfladder_NCOH_; + + TH1D* h1D_Halfladder_NHitInPreviousEvent_example_; + TH1D* h1D_Halfladder_NCOH_example_; + + + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_all_event_; + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_all_event_; + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_all_event_; + + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_; + TH2D* h2D_EventBcoSpacing_NCohInNextEvent_; + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_; + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_bychip_; + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_inner_; + TH2D* h2D_EventBcoSpacing_NHitInPreviousEvent_byhalfladder_outer_; + + TH2D* h2D_MisasignedBcoDiff_NHitInPreviousEvent_; + TH2D* h2D_MisasignedBcoDiff_NCohInNextEvent_; + + TH2D* h2D_NInttHitInner_NInttHitOuter_narrow_spacing_; + + TH1D* h1D_Multiplicity_long_event_interval_; + TH1D* h1D_Multiplicity_short_event_interval_; + TH1D* h1D_Multiplicity_short_event_interval_corrected_; + + TH2D* h2D_EventBcoSpacing_CorrectedMultiplicity_; + TH2D* h2D_EventBcoSpacing_CorrectedMultiplicity_all_event_; + + + /* trigger_table */ + static const int MBDNS_loose_inclusive_ = 11; /* MBD N&S >= 1 */ + static const int MBDNS_tight_inclusive_ = 10; /* MBD N&S >= 2 */ + static const int MBDNS_tight_vtx10cm_ = 12; /* MBD N&S >= 2 && vtx < 10 cm */ + static const int MBDNS_tight_vtx30cm_ = 13; /* MBD N&S >= 2 && vtx < 30 cm */ + static const int MBDNS_tight_vtx60cm_ = 14; /* MBD N&S >= 2 && vtx < 60 cm */ + + std::string node_name_intt_raw_hit_{"INTTRAWHIT"}; + std::string node_name_gl1_raw_hit_{"GL1RAWHIT"}; + std::string tree_name_hot_channel_{"Multiple"}; + + void PrepareHotChannelMap(); + void FillAHit(const InttRawHit* const hit); + // InttRawHitStructure ConvertFromRawHit(InttRawHitContainer* container, const std::map hot_channel_map); + void ConvertFromRawHit(InttRawHitContainer* container);//, const std::map hot_channel_map); + void FillHistograms(); + void GetTriggerInformation(PHCompositeNode *topNode, InttRawHitStructure& event); + std::vector PrepareTriggerVector(long long trigger_input); + void CountCarriedOverHitsPerHalfladderBasis(InttRawHitStructure event_of_interest, InttRawHitStructure& next_event); + void CountCarriedOverHitsPerChipBasis(InttRawHitStructure event_of_interest, InttRawHitStructure& next_event); + + void PushBackNarrowSpacingCarryover(); + + void CheckMultiplicity(); + + +}; + + + + +#endif // INTT_HITCARRYOVER_MONITOR_H_20250808 \ No newline at end of file diff --git a/general_codes/ryotaro/CarriedOverHits/src/Makefile.am b/general_codes/ryotaro/CarriedOverHits/src/Makefile.am new file mode 100644 index 0000000..f63f968 --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/src/Makefile.am @@ -0,0 +1,46 @@ +AUTOMAKE_OPTIONS = foreign + +AM_CPPFLAGS = \ + -I$(includedir) \ + -I$(OFFLINE_MAIN)/include \ + -isystem$(ROOTSYS)/include + +AM_LDFLAGS = \ + -L$(libdir) \ + -L$(OFFLINE_MAIN)/lib \ + -L$(OFFLINE_MAIN)/lib64 + +pkginclude_HEADERS = \ + InttHitCarryoverMonitor.h + +lib_LTLIBRARIES = \ + libInttHitCarryoverMonitor.la + +libInttHitCarryoverMonitor_la_SOURCES = \ + InttHitCarryoverMonitor.cc + +libInttHitCarryoverMonitor_la_LIBADD = \ + -lphool \ + -lSubsysReco \ + -lffaobjects \ + -lffarawobjects \ + -ltrack_io \ + -lintt + +BUILT_SOURCES = testexternals.cc + +noinst_PROGRAMS = \ + testexternals + +testexternals_SOURCES = testexternals.cc +testexternals_LDADD = libInttHitCarryoverMonitor.la + +testexternals.cc: + echo "//*** this is a generated file. Do not commit, do not edit" > $@ + echo "int main()" >> $@ + echo "{" >> $@ + echo " return 0;" >> $@ + echo "}" >> $@ + +clean-local: + rm -f $(BUILT_SOURCES) diff --git a/general_codes/ryotaro/CarriedOverHits/src/autogen.sh b/general_codes/ryotaro/CarriedOverHits/src/autogen.sh new file mode 100755 index 0000000..dea267b --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/src/autogen.sh @@ -0,0 +1,8 @@ +#!/bin/sh +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +(cd $srcdir; aclocal -I ${OFFLINE_MAIN}/share;\ +libtoolize --force; automake -a --add-missing; autoconf) + +$srcdir/configure "$@" diff --git a/general_codes/ryotaro/CarriedOverHits/src/configure.ac b/general_codes/ryotaro/CarriedOverHits/src/configure.ac new file mode 100644 index 0000000..4971bcb --- /dev/null +++ b/general_codes/ryotaro/CarriedOverHits/src/configure.ac @@ -0,0 +1,16 @@ +AC_INIT(tutorial,[1.00]) +AC_CONFIG_SRCDIR([configure.ac]) + +AM_INIT_AUTOMAKE +AC_PROG_CXX(CC g++) + +LT_INIT([disable-static]) + +dnl no point in suppressing warnings people should +dnl at least see them, so here we go for g++: -Wall +if test $ac_cv_prog_gxx = yes; then + CXXFLAGS="$CXXFLAGS -Wall" +fi + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/general_codes/ryotaro/README.md b/general_codes/ryotaro/README.md new file mode 100644 index 0000000..e69de29 diff --git a/general_codes/ryotaro/TimingScan/macro/CalculateRatio.cc b/general_codes/ryotaro/TimingScan/macro/CalculateRatio.cc new file mode 100644 index 0000000..ffe19e8 --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/CalculateRatio.cc @@ -0,0 +1,90 @@ +#include "MyUtility/GetBinWithoutOverUnderFlow.cc" + +// int get_previous_without_underflow(int bin); +// int get_next_without_overflow(int bin); + + +// Returns (asymmetry, ratio) for given run. +// This code is assuming that h_bco_diff has an binning of (128,0,128). If not, cannot deal with overflow/underflow properly. +std::vector< std::pair > CalculateRatio(int run){ + std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/root/run%d.root", run); + TFile* file = TFile::Open(filename.c_str(), "read"); + if ( !file || file->IsZombie() ){ + std::cerr << "ERROR: Could not open" << filename << std::endl; + exit(1); + } + + file->cd(); + TH1D* h_bco_diff_shifted = (TH1D*)file->Get("h_bco_diff_shifted"); + if (!h_bco_diff_shifted) { + std::cerr << "Cannot get the histgram" << std::endl; + exit(1); + } + + int peak_bin = h_bco_diff_shifted->GetMaximumBin(); + double peak_height = h_bco_diff_shifted->GetBinContent(peak_bin); + double error = h_bco_diff_shifted->GetBinError(peak_bin); + + int previous_bin = GetPreviousWithoutUnderflow(peak_bin); + int next_bin = GetNextWithoutOverflow(peak_bin); + double previous_bin_height = h_bco_diff_shifted->GetBinContent( previous_bin ); + double error_previous = h_bco_diff_shifted->GetBinError(previous_bin); + double next_bin_height = h_bco_diff_shifted->GetBinContent(next_bin); + double error_next= h_bco_diff_shifted->GetBinError(next_bin); + + double the_other_bin_height; + double error_other; + double asymmetry; + double error_asymmetry; + double ratio; /* not needed for now */ + double error_ratio=0; /* not needed for now */ + if ( previous_bin_height > next_bin_height ) { + the_other_bin_height = previous_bin_height; + error_other = error_previous; + //asymmetry = (the_other_bin_height - peak_height) / (the_other_bin_height + peak_height ); // (before - peak) / (before + peak) + asymmetry = ( the_other_bin_height ) / (the_other_bin_height + peak_height ); + error_asymmetry = sqrt( TMath::Power(peak_height,2) * TMath::Power(error_other,2) + TMath::Power(the_other_bin_height,2) * TMath::Power(error,2)) / TMath::Power( (the_other_bin_height + peak_height) ,2); + cout << asymmetry << endl; + ratio = peak_height / the_other_bin_height; + } else { + the_other_bin_height = next_bin_height; + error_other = error_next; + //asymmetry = ( peak_height - the_other_bin_height) / (peak_height + the_other_bin_height); // (peak - next) / (peak + next) + asymmetry = ( peak_height ) / (peak_height + the_other_bin_height); + error_asymmetry = sqrt( TMath::Power(peak_height,2) * TMath::Power(error_other,2) + TMath::Power(the_other_bin_height,2) * TMath::Power(error,2)) / TMath::Power( (the_other_bin_height + peak_height) ,2); // same as above + ratio = the_other_bin_height / peak_height; + } + /* + std::cout << "binning: " << h_bco_diff->GetNbinsX() << std::endl; + std::cout << "peak_bin: " << peak_bin << std::endl; + std::cout << "next_bin: " << next_bin << std::endl; + std::cout << previous_bin_height << " " << peak_height << " " << next_bin_height << std::endl; + std::cout << "asymmetry: " << (double)asymmetry << std::endl; + std::cout << "ratio: " << (double)ratio << std::endl; + */ + + file->Close(); + delete file; + + //return { asymmetry, ratio}; + return { {abs(asymmetry), error_asymmetry}, {ratio, error_ratio} }; +} + +// can be implemented so that it can deal with a different binning, but not now. +// Now, the implementation assumes the binning of (128,0,128). +// int get_previous_without_underflow(int bin){ +// if (bin == 1) { +// return 128; +// } else { +// return bin-1; +// } +// } + +// // same situation as get_previous_without_underflow(int bin) +// int get_next_without_overflow(int bin) { +// if (bin == 128) { +// return 1; +// } else { +// return bin+1; +// } +// } diff --git a/general_codes/ryotaro/TimingScan/macro/CalculateRatioWithBgsubtraction.cc b/general_codes/ryotaro/TimingScan/macro/CalculateRatioWithBgsubtraction.cc new file mode 100644 index 0000000..59b5946 --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/CalculateRatioWithBgsubtraction.cc @@ -0,0 +1,280 @@ +#include "MyUtility/GetBinWithoutOverUnderFlow.cc" + +// std::pair GetMeanStdInOddBins(TH1D* hist, int range[2]); +// std::pair GetMeanStdInEvenBins(TH1D* hist, int range[2]); +double GetMeanInOddBins(TH1D* hist, int range[2]); +double GetStdInOddBins(TH1D* hist, int range[2]); +double GetMeanInEvenBins(TH1D* hist, int range[2]); +double GetStdInEvenBins(TH1D* hist, int range[2]); + +// int GetPreviousWithoutUnderflow(int bin); +// int GetNextWithoutOverflow(int bin); +std::vector > EstimateBackgroundLevels(int run); + + + + + + +/* Returns ( {asymmetry, error}, {ratio, error} ) for a given run. */ +/* This code is assuming that h_bco_diff has an binning of (128,0,128). If not, cannot deal with overflow/underflow properly. */ +/* Being used in DrawSharpnessAsFunctionOfRuns() */ +std::vector< std::pair > CalculateRatioWithBgsubtraction(int run){ + std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/root/run%d.root", run); + TFile* file = TFile::Open(filename.c_str(), "read"); + if ( !file || file->IsZombie() ){ + std::cerr << "ERROR: Could not open" << filename << std::endl; + exit(1); + } + + file->cd(); + TH1D* h_bco_diff_shifted = (TH1D*)file->Get("h_bco_diff_shifted"); + if (!h_bco_diff_shifted) { + std::cerr << "For run: " << run << ", Cannot get the histgram" << std::endl; + exit(1); + } + + std::vector< std::pair > backgrounds_witherrors = EstimateBackgroundLevels(run); /* backgrounds_witherrors = { {average_odd, std_odd}, {average_even, std_even} } */ + double bg_estimation_odd_bins = backgrounds_witherrors[0].first; /* using average as an esitimation */ + double error_odd_bin = backgrounds_witherrors[0].second; /* using standard deviatoin as error */ + + double bg_estimation_even_bins = backgrounds_witherrors[1].first; /* using average as an esitimation */ + double error_even_bin = backgrounds_witherrors[0].second; /* using standard deviatoin as error */ + + + int peak_bin = h_bco_diff_shifted->GetMaximumBin(); + double peak_height_raw = h_bco_diff_shifted->GetBinContent(peak_bin); + double error_raw = h_bco_diff_shifted->GetBinError(peak_bin); /* sqrt(peak_height_raw) is not correct because we did scaling per e_events */ + double peak_height_subtracted; + double error_subtracted; + if (peak_bin%2 == 1) { + peak_height_subtracted = peak_height_raw - bg_estimation_odd_bins; + error_subtracted = sqrt( error_raw*error_raw + error_odd_bin*error_odd_bin); + } else { + peak_height_subtracted = peak_height_raw - bg_estimation_even_bins; + error_subtracted = sqrt( error_raw*error_raw + error_even_bin*error_even_bin); + } + + int previous_bin = GetPreviousWithoutUnderflow(peak_bin); + double previous_bin_height_raw = h_bco_diff_shifted->GetBinContent(previous_bin); + double error_previous_raw = h_bco_diff_shifted->GetBinError(previous_bin); /* sqrt(previous_bin_height_raw); is not correct because we did scaling per e_events */ + double previous_bin_height_subtracted; + double error_previous_subtracted; + if (previous_bin%2 == 1){ + previous_bin_height_subtracted = previous_bin_height_raw - bg_estimation_odd_bins; + error_previous_subtracted = sqrt( error_previous_raw*error_previous_raw + error_odd_bin*error_odd_bin); + } else { + previous_bin_height_subtracted = previous_bin_height_raw - bg_estimation_even_bins; + error_previous_subtracted = sqrt( error_previous_raw*error_previous_raw + error_even_bin*error_even_bin); + } + + int next_bin = GetNextWithoutOverflow(peak_bin); + double next_bin_height_raw = h_bco_diff_shifted->GetBinContent(next_bin); + double error_next_raw = h_bco_diff_shifted->GetBinError(next_bin); /* sqrt(next_bin_height_raw); is not correct because we did scaling per e_events */ + double next_bin_height_subtracted; + double error_next_subtracted; + if (next_bin%2 == 1){ + next_bin_height_subtracted = next_bin_height_raw - bg_estimation_odd_bins; + error_next_subtracted = sqrt(error_next_raw*error_next_raw + error_odd_bin*error_odd_bin); + } else { + next_bin_height_subtracted = next_bin_height_raw - bg_estimation_even_bins; + error_next_subtracted = sqrt(error_next_raw*error_next_raw + error_even_bin*error_even_bin); + } + + double the_other_bin_height; + double error_other; + double asymmetry; + double error_asymmetry; + double ratio; /* not needed for now */ + double error_ratio=0; /* not needed for now */ + if ( previous_bin_height_subtracted > next_bin_height_subtracted ) { + the_other_bin_height = previous_bin_height_subtracted; + error_other = error_previous_subtracted; + //asymmetry = (the_other_bin_height - peak_height_subtracted) / (the_other_bin_height + peak_height_subtracted ); // (before - peak) / (before + peak) + asymmetry = ( the_other_bin_height ) / (the_other_bin_height + peak_height_subtracted ); /* changed the definition 20250512. This corresponds to always choosing the left bin */ + //asymmetry = ( peak_height_subtracted ) / (the_other_bin_height + peak_height_subtracted ); + error_asymmetry = 2*sqrt( TMath::Power(peak_height_subtracted,2) * TMath::Power(error_other,2) + TMath::Power(the_other_bin_height,2) * TMath::Power(error_subtracted,2)) / TMath::Power( (the_other_bin_height + peak_height_subtracted) ,2); + ratio = peak_height_subtracted / the_other_bin_height; + } else { + the_other_bin_height = next_bin_height_subtracted; + error_other = error_next_subtracted; + asymmetry = ( peak_height_subtracted ) / (peak_height_subtracted + the_other_bin_height); // (peak - next) / (peak + next) + error_asymmetry = 2*sqrt( TMath::Power(peak_height_subtracted,2) * TMath::Power(error_other,2) + TMath::Power(the_other_bin_height,2) * TMath::Power(error_subtracted,2)) / TMath::Power( (the_other_bin_height + peak_height_subtracted) ,2); // same as above + ratio = the_other_bin_height / peak_height_subtracted; + } + + + // std::cout << "binning: " << h_bco_diff_shifted->GetNbinsX() << std::endl; + // std::cout << "peak_bin: " << peak_bin << std::endl; + // std::cout << "next_bin: " << next_bin << std::endl; + // std::cout << previous_bin_height << " " << peak_height << " " << next_bin_height << std::endl; + // std::cout << "asymmetry: " << (double)asymmetry << std::endl; + // std::cout << "ratio: " << (double)ratio << std::endl; + + + file->Close(); + delete file; + + return { {abs(asymmetry), error_asymmetry}, {ratio, error_ratio} }; +} + +/* Estimates background levels in plateau region( defined with the range_limit[2]). */ +/* Returns estimation with errors. */ +/* estimations[0] = {average_odd_bins, standard_deviation_odd_bins} */ +/* estimations[1] = {average_even_bins, standard_deviation_even_bins} */ +std::vector< std::pair > EstimateBackgroundLevels(int run) { + + std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/root/run%d.root", run); + TFile* file = TFile::Open(filename.c_str(), "update"); + if ( !file || file->IsZombie() ){ + std::cerr << "ERROR: Could not open" << filename << std::endl; + exit(1); + } + + file->cd(); + TH1D* h_bco_diff_shifted = (TH1D*)file->Get("h_bco_diff_shifted"); + + int peak_bin = h_bco_diff_shifted->GetMaximumBin(); + int range_limit[2] = {10,80}; // range in which the background level will be estimated. + + double average_odd_bins = GetMeanInOddBins(h_bco_diff_shifted, range_limit); + double standard_deviation_odd_bins = GetStdInOddBins(h_bco_diff_shifted, range_limit); + + double average_even_bins = GetMeanInEvenBins(h_bco_diff_shifted, range_limit); + double standard_deviation_even_bins = GetStdInOddBins(h_bco_diff_shifted, range_limit); + + // TCanvas* c1 = new TCanvas("name", "Title", 900, 600); + // c1->cd(); + // h_bco_diff_shifted->Draw(); + + // TF1* f_odd = new TF1("odd", std::to_string(average_odd_bins).c_str(), range_limit[0], range_limit[1]); + // f_odd->Draw("same"); + + // TF1* f_even = new TF1("even", std::to_string(average_even_bins).c_str(), range_limit[0], range_limit[1]); + // f_even->Draw("same"); + + // std::string fileout = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/TimingScan/output/root/TEST_run%d.root", run); + // TFile* file_test = TFile::Open(fileout.c_str(), "recreate"); + // c1->Write(); + + file->Close(); + + std::vector< std::pair > estimations; + estimations.push_back( {average_odd_bins, standard_deviation_odd_bins} ); + estimations.push_back( {average_even_bins, standard_deviation_even_bins} ); + + return estimations; +} + + + + + + +double GetMeanInOddBins(TH1D* hist, int range[2]){ + + std::vector odd_bins; + for (int i=range[0]; i <= range[1]; i++){ + if ( i%2 == 1 ) {odd_bins.push_back(i);} + } + + std::vector bin_contents; + for (int i : odd_bins){ + //std::cout << i << std::endl; + bin_contents.push_back( hist->GetBinContent(i) ); + } + + double sum = std::accumulate(bin_contents.begin(), bin_contents.end(), 0.0); + double average = sum / bin_contents.size(); + + return average; +} + +double GetStdInOddBins(TH1D* hist, int range[2]){ + + std::vector odd_bins; /*same as GetMeanInOddBins()*/ + for (int i=range[0]; i <= range[1]; i++){ + if ( i%2 == 1 ) {odd_bins.push_back(i);} + } + + std::vector bin_contents; /*same as GetMeanInOddBins()*/ + for (int i : odd_bins){ + //std::cout << i << std::endl; + bin_contents.push_back( hist->GetBinContent(i) ); + } + + double sum = std::accumulate(bin_contents.begin(), bin_contents.end(), 0.0); + double average = sum / bin_contents.size(); + + double quad_sum = 0; + for (double content : bin_contents){ + quad_sum += content*content; + } + double standard_deviation = quad_sum / ( bin_contents.size()) - average*average; + + return standard_deviation; + +} + + +double GetMeanInEvenBins(TH1D* hist, int range[2]){ + std::vector even_bins; + for (int i=range[0]; i <= range[1]; i++){ + if ( i%2 == 0 ) {even_bins.push_back(i);} + } + + std::vector bin_contents; + for (int i : even_bins){ + //std::cout << i << std::endl; + bin_contents.push_back( hist->GetBinContent(i) ); + } + + double sum = std::accumulate(bin_contents.begin(), bin_contents.end(), 0.0); + double average = sum / bin_contents.size(); + + return average; +} + + +double GetStdInEvenBins(TH1D* hist, int range[2]){ + std::vector even_bins; + for (int i=range[0]; i <= range[1]; i++){ + if ( i%2 == 0 ) {even_bins.push_back(i);} + } + + std::vector bin_contents; + for (int i : even_bins){ + //std::cout << i << std::endl; + bin_contents.push_back( hist->GetBinContent(i) ); + } + + double sum = std::accumulate(bin_contents.begin(), bin_contents.end(), 0.0); + double average = sum / bin_contents.size(); + + double quad_sum = 0; + for (double content : bin_contents){ + quad_sum += content*content; + } + double standard_deviation = quad_sum / ( bin_contents.size()) - average*average; + + return standard_deviation; +} + +// // can be implemented so that it can deal with a different binning, but not now. +// // Now, the implementation assumes the binning of (128,0,128). +// int GetPreviousWithoutUnderflow(int bin){ +// if (bin == 1) { +// return 128; +// } else { +// return bin-1; +// } +// } + +// // same situation as get_previous_without_underflow(int bin) +// int GetNextWithoutOverflow(int bin) { +// if (bin == 128) { +// return 1; +// } else { +// return bin+1; +// } +// } diff --git a/general_codes/ryotaro/TimingScan/macro/DrawHistAfterSubtraction.cc b/general_codes/ryotaro/TimingScan/macro/DrawHistAfterSubtraction.cc new file mode 100644 index 0000000..467ab67 --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/DrawHistAfterSubtraction.cc @@ -0,0 +1,156 @@ +#include "sPhenixStyle.C" + +double GetMeanInOddBins(TH1D* hist, int range[2]); +double GetMeanInEvenBins(TH1D* hist, int range[2]); +int GetPreviousWithoutUnderflow(int bin); +int GetNextWithoutOverflow(int bin); + + +/* Estimates background levels in plateau region( defined with the range_limit[2]). */ +/* Returns as an estimation. */ +void DrawHistAfterSubtraction(int run) { + SetsPhenixStyle(); + + std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/root/run%d.root", run); + TFile* file = TFile::Open(filename.c_str(), "update"); + if ( !file || file->IsZombie() ){ + std::cerr << "ERROR: Could not open" << filename << std::endl; + exit(1); + } + + file->cd(); + TH1D* h_bco_diff_shifted = (TH1D*)file->Get("h_bco_diff_shifted"); + + int range_limit[2] = {10,80}; // range in which the background level will be estimated. + + double average_odd_bins = GetMeanInOddBins(h_bco_diff_shifted, range_limit); + double average_even_bins = GetMeanInEvenBins(h_bco_diff_shifted, range_limit); + + TCanvas* c1 = new TCanvas("c1", "Title", 900, 600); + c1->cd(); + c1->SetGrid(); + h_bco_diff_shifted->Draw(); + + TF1* f_odd = new TF1("odd", std::to_string(average_odd_bins).c_str(), range_limit[0], range_limit[1]); + f_odd->Draw("same"); + + TF1* f_even = new TF1("even", std::to_string(average_even_bins).c_str(), range_limit[0], range_limit[1]); + f_even->Draw("same"); + + TF1* f_even_dotted = new TF1("even_dotted", std::to_string(average_even_bins).c_str(), 1, 127); + f_even_dotted->SetLineStyle(3); + f_even_dotted->Draw("same"); + + // std::string fileout = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/TimingScan/output/root/TEST_run%d.root", run); + // TFile* file_test = TFile::Open(fileout.c_str(), "update"); + //file->cd(); + //c1->Write("c1", TObject::kOverwrite); + //c1->Print("aa.pdf"); + + + TH1D* h_bco_diff_subtracted = (TH1D*)h_bco_diff_shifted->Clone(); + //TCanvas* c_bco_diff_subtracted = (TCanvas*)h_bco_diff_shifted->Clone(); + h_bco_diff_subtracted->Reset(); + + /* do BG subtraction */ + double remaining_count; + for (int bin=1; bin <= h_bco_diff_shifted->GetNbinsX(); bin++) { + + if (bin%2 == 1) { + remaining_count = h_bco_diff_shifted->GetBinContent(bin) - average_odd_bins; + } else { + remaining_count = h_bco_diff_shifted->GetBinContent(bin) - average_even_bins; + } + + h_bco_diff_subtracted->SetBinContent(bin,remaining_count); + } + + + // std::string fileout = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/TimingScan/output/root/TEST_run%d.root", run); + // TFile* file_test = TFile::Open(fileout.c_str(), "update"); + // if ( !file_test || file_test->IsZombie() ){ + // std::cerr << "ERROR: Could not open" << fileout << std::endl; + // exit(1); + // } + + //TCanvas* c2 = new TCanvas("c2","", 900, 600); + //c2->cd(); + //h_bco_diff_subtracted->SetTitle("; Beam crossing (106 ns / crossing); INTT hit counts per events"); + //h_bco_diff_subtracted->Draw(); + //c2->Write("bco_diff_subtracted", TObject::kOverwrite); + h_bco_diff_subtracted->Write("bco_diff_subtracted", TObject::kOverwrite); + + //file_test->Close(); + + + + file->Close(); + delete file; + //delete c2; + delete c1; + // delete f_even; + // delete f_odd; + //delete f_even_dotted; + /* + std::pair averages = {average_odd_bins, average_even_bins}; + return averages; + */ +} + + + + + + +double GetMeanInOddBins(TH1D* hist, int range[2]){ + std::vector odd_bins; + for (int i=range[0]; i <= range[1]; i++){ + if ( i%2 == 1 ) {odd_bins.push_back(i);} + } + + std::vector bin_contents; + + for (int i : odd_bins){ + //std::cout << i << std::endl; + bin_contents.push_back( hist->GetBinContent(i) ); + } + double sum = std::accumulate(bin_contents.begin(), bin_contents.end(), 0.0); + double average = sum / bin_contents.size(); + return average; +} + +double GetMeanInEvenBins(TH1D* hist, int range[2]){ + std::vector even_bins; + for (int i=range[0]; i <= range[1]; i++){ + if ( i%2 == 0 ) {even_bins.push_back(i);} + } + + std::vector bin_contents; + + for (int i : even_bins){ + //std::cout << i << std::endl; + bin_contents.push_back( hist->GetBinContent(i) ); + } + double sum = std::accumulate(bin_contents.begin(), bin_contents.end(), 0.0); + double average = sum / bin_contents.size(); + return average; +} + +// can be implemented so that it can deal with a different binning, but not now. +// Now, the implementation assumes the binning of (128,0,128). +int GetPreviousWithoutUnderflow(int bin){ + if (bin == 1) { + return 128; + } else { + return bin-1; + } +} + +// same situation as get_previous_without_underflow(int bin) +int GetNextWithoutOverflow(int bin) { + if (bin == 128) { + return 1; + } else { + return bin+1; + } +} \ No newline at end of file diff --git a/general_codes/ryotaro/TimingScan/macro/DrawSharpnessAsFunctionOfRuns.cc b/general_codes/ryotaro/TimingScan/macro/DrawSharpnessAsFunctionOfRuns.cc new file mode 100644 index 0000000..6729b8b --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/DrawSharpnessAsFunctionOfRuns.cc @@ -0,0 +1,259 @@ +#include "CalculateRatio.cc" +#include "CalculateRatioWithBgsubtraction.cc" + +#include "sPhenixStyle.C" + +std::string GetDate(); +void PutCaption(); +// void PutLegend(TGraphErrors* g_asymmetry_on_l1delay, TGraphErrors* g_points_data_taken); +void PutLegend(TGraphErrors* g_asymmetry_on_l1delay, TGraphErrors* g_points_data_taken, TGraphErrors* g_asymmetry_on_l1delay_OO); /* Run26 O+O */ + +void DrawSharpnessAsFunctionOfRuns(){ + + SetsPhenixStyle(); + + // std::string filename = "/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/root/summary_2025pp_bkgsubtraction.root"; /* if you want it without background subtraction, change the calculation part, too. */ + // std::string filename = "/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/root/summary_2025pp.root"; + std::string filename = "/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/root/summary_2026OO.root"; /* Run26 O+O */ + TFile* file = TFile::Open(filename.c_str(), "recreate"); + if ( !file || file->IsZombie() ){ + std::cerr << "ERROR: Could not open" << filename << std::endl; + exit(1); + } + + std::vector< pair > run_L1delay_list_scan6 = { + //{66522, 90}, + //{66523, 90}, does not exist + {66525, 90}, + {66526, 90}, + {66527, 108}, + //{66529, 108}, does not exist + {66531, 109}, + {66532, 109}, + {66534, 110}, + {66535, 110}, + //{66536, 111}, // no data + {66539, 111}, + {66540, 111}, + {66542, 112}, + {66543, 112}, + {66544, 113}, + {66545, 113}, + + }; + + // std::vector< pair > run_L1delay_list_scan6 = { + // {79244, 108}, + // {79252, 114}, + // {79261, 109}, + // {79263, 110}, + // {79264, 106}, + // {79265, 107}, + // {79266, 108}, + + // {82391, 108}, /* Run26 O+O */ + // }; + + TGraph* g_asymmetry_on_run = new TGraph(); + TGraph* g_ratio_on_run = new TGraph(); + TGraphErrors* g_asymmetry_on_l1delay = new TGraphErrors(); + TGraph* g_ratio_on_l1delay = new TGraph(); + + TGraphErrors* g_asymmetry_on_l1delay_OO = new TGraphErrors(); /* Run26 O+O */ + g_asymmetry_on_l1delay_OO->SetPoint(0,108,0.98483333); + + TGraphErrors* g_points_data_taken = new TGraphErrors(); + + for (int i=0; i > asymmetry_and_ratio_with_errors = CalculateRatio(run); + std::vector< std::pair > asymmetry_and_ratio_with_errors = CalculateRatioWithBgsubtraction(run); + double asymmetry = asymmetry_and_ratio_with_errors[0].first; + double error_asymmetry = asymmetry_and_ratio_with_errors[0].second; + double ratio = asymmetry_and_ratio_with_errors[1].first; + double error_ratio = asymmetry_and_ratio_with_errors[1].second; + g_asymmetry_on_run->SetPoint(i, run, asymmetry); + g_ratio_on_run->SetPoint(i, run, ratio); + g_asymmetry_on_l1delay->SetPoint(i, l1_delay, asymmetry); + g_asymmetry_on_l1delay->SetPointError(i, 0, error_asymmetry); + g_ratio_on_l1delay->SetPoint(i, l1_delay, ratio); + + if (l1_delay == 108) { + g_points_data_taken->SetPoint(i, l1_delay, asymmetry); + g_points_data_taken->SetPointError(i, 0, error_asymmetry); + } + } + + + file->cd(); + //g_asymmetry_on_run->Write(); + TCanvas* c1 = new TCanvas("c1", "g_asymmetry_on_run",900, 600); + //c1->SetGrid(); + //c1->GetFrame()->SetBorderSize(12); + //c1->SetTopMargin(0.03); + //c1->SetBottomMargin(0.2); + //c1->SetRightMargin(0.03); + //c1->SetLeftMargin(0.15); + //c1->SetFrameLineWidth(2); + + /* Set the title, fonts, fontsizes, etc. */ + g_asymmetry_on_run->SetTitle("; run number; asymmetry"); + g_asymmetry_on_run->SetMaximum(1.0); + g_asymmetry_on_run->SetMinimum(-1.0); + g_asymmetry_on_run->GetXaxis()->SetLimits(66522, 66545); + + c1->cd(); + g_asymmetry_on_run->Draw("ALP"); + c1->Write(); + //g_ratio_on_run->Write(); + + TCanvas* c2 = new TCanvas("c2", "g_ratio_on_run", 3, 2, 900, 600); + c2->SetGrid(); + c2->GetFrame()->SetBorderSize(12); + + + g_ratio_on_run->SetTitle("; run number; ratio"); + g_ratio_on_run->SetMaximum(15); + g_ratio_on_run->SetMinimum(-0.1); + g_ratio_on_run->GetXaxis()->SetLimits(43408, 43440); + + + c2->cd(); + g_ratio_on_run->Draw("ALP"); + c2->Write(); + + TCanvas* c3 = new TCanvas("c3", "g_asymmetry_on_l1delay",1200, 900); + //c3->SetGrid(); + //c3->GetFrame()->SetBorderSize(12); + + /* A pad for sphenix caption. Top 10% of the canvas*/ + TPad *titlePad = new TPad("titlePad", "Title Pad", 0.0, 0.0, 1.0, 1.0); + titlePad->SetBottomMargin(0); + titlePad->SetTopMargin(0); + titlePad->SetLeftMargin(0); + titlePad->SetRightMargin(0); + titlePad->Draw(); + + + + /* A pad for TGraph. Lower 90% of the canvas*/ + TPad *graphPad = new TPad("graphPad", "Graph Pad", 0.0, 0.0, 1.0, 0.835); + graphPad->SetTopMargin(0.02); + //graphPad->SetGrid(); + graphPad->Draw(); + + + titlePad->cd(); + + PutCaption(); + + graphPad->cd(); + SetsPhenixStyle(); + //gPad->SetTopMargin(2.0); + g_asymmetry_on_l1delay->SetTitle("; L1 delay [BCO/6]; #it{N}_{L} / (#it{N}_{L}+#it{N}_{R})"); + g_asymmetry_on_l1delay->GetYaxis()->SetTitleOffset(0.95); + //g_asymmetry_on_l1delay->GetYaxis()->SetTitleSize(0.07); + g_asymmetry_on_l1delay->SetMaximum(1.0); + //g_asymmetry_on_l1delay->SetMinimum(-1.0); + g_asymmetry_on_l1delay->SetMinimum(0.0); + g_asymmetry_on_l1delay->SetMarkerSize(2); + + g_points_data_taken->SetMarkerSize(2.2); + g_points_data_taken->SetMarkerColor(kGreen+1);//4); + g_points_data_taken->SetLineColor(kGreen+1);//4); + + //c3->cd(); + //c3->SetGrid(); + g_asymmetry_on_l1delay->Draw("AP"); + g_points_data_taken->Draw("sameP"); + + g_asymmetry_on_l1delay_OO->SetMarkerSize(2.2); + g_asymmetry_on_l1delay_OO->SetMarkerColor(kRed);//4); + g_asymmetry_on_l1delay_OO->SetLineColor(kRed);//4); + g_asymmetry_on_l1delay_OO->Draw("sameP"); /* Run26 O+O */ + // PutCaption(); + + // PutLegend(g_asymmetry_on_l1delay, g_points_data_taken); + PutLegend(g_asymmetry_on_l1delay, g_points_data_taken, g_asymmetry_on_l1delay_OO); + + c3->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/image/Imbalance.pdf"); + c3->Write(); + //c3->Print("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/TimingScan/output/image/Imbalance.pdf"); + + + TCanvas* c4 = new TCanvas("c4", "g_ratio_on_l1delay", 3, 2, 900, 600); + c4->SetGrid(); + + + g_ratio_on_l1delay->SetTitle("; L1 delay; ratio"); + g_ratio_on_l1delay->SetMaximum(15); + g_ratio_on_l1delay->SetMinimum(-0.1); + g_ratio_on_l1delay->GetXaxis()->SetLimits(43408, 43440); + + c4->cd(); + g_ratio_on_l1delay->Draw("AP"); + c4->Write(); + + file->Close(); + +} + +std::string GetDate(){ + // return "5/13/2025"; // use this once the dete is determined + TDatime dt; + int year = dt.GetYear(); + int month = dt.GetMonth(); + int day = dt.GetDay(); + + // format: mm/dd/yyyy + std::stringstream ss; + ss << month << "/" << day << "/" << year; + + return ss.str(); +}; + +void PutCaption(){ +/*from Genki*/ + TLatex* tex = new TLatex(); + double line_height = 0.05; // no need to change + double first_margin = -0.1;//-0.62; // the margin from the top of the canvas to the top line (date). You can modify + double pos_x = 0.2; //0.55; // you can modify + double pos_y = 1.0 + first_margin; // - line_height; + + /* Date, you may want to change 0.65 to pos_x */ + tex->DrawLatexNDC( pos_x, pos_y, + string("#it{#bf{sPHENIX}} Internal " + ("#it{" + GetDate()) + "}").c_str() ); + // tex->DrawLatexNDC( pos_x, pos_y, + // string("#it{#bf{sPHENIX}} Internal #it{05/16/2025}").c_str() ); + //tex->DrawLatexNDC( 0.65, pos_y, + // string("#it{" + GetDate() + "}").c_str() ); + + // // sPHENIX Internal or sPHENIX Prelimnary + // pos_y -= line_height; + // //tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Preliminary" ); + // tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Internal" ); + + // p+p 200 GeV + pos_y -= line_height ;// + 0.03; + // tex->DrawLatexNDC( pos_x, pos_y, ( string("#it{Au+Au} #sqrt{s}=200 GeV") ).c_str() ); + + // pos_y -= line_height; + // tex->DrawLatexNDC( pos_x, pos_y, "INTT Triggered mode" ); +} + +/* Run26 O+O */ +void PutLegend(TGraphErrors* g_asymmetry_on_l1delay, TGraphErrors* g_points_data_taken, TGraphErrors* g_asymmetry_on_l1delay_OO){ + TLegend* legend = new TLegend(0.20,0.19,0.75,0.355); /* 2025 AuAu*/ + // TLegend* legend = new TLegend(0.25,0.19,0.65,0.305); /* 2025 AuAu*/ + // TLegend* legend = new TLegend(0.55,0.19,0.95,0.305); /* 2025 pp */ + legend->AddEntry(g_asymmetry_on_l1delay, "Scanned point in Run25 Au+Au", "ep"); + // legend->AddEntry(g_points_data_taken, "Current working point" ,"ep"); + legend->AddEntry(g_points_data_taken, "Working point in Run25 Au+Au" ,"ep"); + legend->AddEntry(g_asymmetry_on_l1delay_OO, "Current Setting for O+O" ,"ep"); + gStyle->SetLegendBorderSize(1); + legend->SetFillStyle(1001); // 1001 は完全な塗りつぶし + legend->SetFillColor(kWhite); // kWhite は白色背景 + legend->SetBorderSize(1); // 枠線を表示(0で非表示) + legend->Draw(); +} diff --git a/general_codes/ryotaro/TimingScan/macro/Fun4All_TimingScan.cc b/general_codes/ryotaro/TimingScan/macro/Fun4All_TimingScan.cc new file mode 100644 index 0000000..ffc23d0 --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/Fun4All_TimingScan.cc @@ -0,0 +1,91 @@ +#include +#include +#include +#include +#include + +#include "InttTimingScan.h" + +//#include +//#include + +R__LOAD_LIBRARY(libInttTimingScan.so) +R__LOAD_LIBRARY( libg4detectors.so ) + +void Fun4All_TimingScan(int process_id=0, int run=43417, int n_events=1000){ + + std::string job_index = std::to_string( process_id ); + int job_index_len = 5; + job_index.insert(0, job_index_len - job_index.size(), '0'); + + Fun4AllServer* fun4all_server = Fun4AllServer::instance(); + + Fun4AllInputManager* fun4all_input_manager = new Fun4AllDstInputManager("hoge"); + fun4all_input_manager->Verbosity(2); + std::ostringstream run_padded_with0; + run_padded_with0 << std::setw( 8 ) << std::setfill( '0' ) << run; // convert the run (say, 45751) to run_padded_with0 (= 00045751) + std::string filename; + + if (run == 66522) { + filename = Form("/sphenix/tg/tg01/commissioning/INTT/data/dst_files/2025/DST_physics_intt-%s_no_hot_special.root",run_padded_with0.str().c_str()); /* for run 66522 (it was taken in physics)*/ + fun4all_input_manager->AddFile(filename); + fun4all_server->registerInputManager(fun4all_input_manager); + } else if (run == 81000) { + filename = "/sphenix/u/yshojisek/work/repos/TrackingAnalysis/Silicon_MBD_Vertexing/Silicon_MBD_Comparisons/VertexCompare_run_81000/files/DST_SILIVTX.root"; + fun4all_input_manager->AddFile(filename); + fun4all_server->registerInputManager(fun4all_input_manager); + } else if (run == 75519) { + std::vector input_managers; + for (int i = 0; i < 8; i++) { + // std::string intt_file_name = Form("DST_STREAMING_EVENT_intt%d_run3auau_new_nocdbtag_v001-000%d-%s.root", i, run, job_index.c_str()); + std::string intt_file_name = Form("DST_STREAMING_EVENT_intt%d_run3auau_new_nocdbtag_v001-000%d-00000.root", i, run); + input_managers.push_back(new Fun4AllDstInputManager(Form("DST_track_%d",i))); + input_managers.back() -> Verbosity(2); + input_managers.back() -> AddFile( intt_file_name ); + fun4all_server->registerInputManager(input_managers.back()); + } + } else if (run == 82400) { + std::vector input_managers; + for (int i = 0; i < 8; i++) { + std::string intt_file_name = Form("DST_STREAMING_EVENT_intt%d_run3oo_new_nocdbtag_v001-000%d-%s.root", i, run, job_index.c_str()); + input_managers.push_back(new Fun4AllDstInputManager(Form("DST_track_%d",i))); + input_managers.back() -> Verbosity(2); + input_managers.back() -> AddFile( intt_file_name ); + fun4all_server->registerInputManager(input_managers.back()); + } + } else if (run == 82391) { + filename = "/sphenix/user/ChengWei/SelfINTTProduction/2025_Oct_20/jaein_decode_calib/test_DST_calib_intt-00082391_special_.root"; + fun4all_input_manager->AddFile(filename); + fun4all_server->registerInputManager(fun4all_input_manager); + } else { + filename = Form("/sphenix/tg/tg01/commissioning/INTT/data/dst_files/2025/DST_beam_intt-%s_no_hot_special.root",run_padded_with0.str().c_str()); /* for other runs (they were taken in beams)*/ + fun4all_input_manager->AddFile(filename); + fun4all_server->registerInputManager(fun4all_input_manager); + } + + + // just if we set some flags somewhere in this macro + recoConsts *rc = recoConsts::instance(); + + //Enable::CDB = true; + // // rc->set_StringFlag("CDB_GLOBALTAG", CDB::global_tag); + //rc->set_StringFlag("CDB_GLOBALTAG", "ProdA_2024" ); + //rc->set_uint64Flag("TIMESTAMP", run); + //rc->set_IntFlag("RUNNUMBER", run ); + + InttTimingScan* module_timingscan = new InttTimingScan("name", run); + module_timingscan->set_hot_channel_map_file("/sphenix/user/ChengWei/SelfINTTProduction/2025_Oct_20/jaein_decode_calib/cdb_00082391hot.root"); + module_timingscan->set_mode(InttTimingScan::Mode::RawHitOnly); /* RawHitOnly or RawPlusTrkr */ + module_timingscan->set_daq_mode(InttTimingScan::DaqMode::Official); /* Local or Official */ + // module_timingscan->set_mode(Mode::RawPlusTrkr); + + fun4all_server->registerSubsystem(module_timingscan); + + fun4all_server->run(n_events); + fun4all_server->End(); + + delete fun4all_server; + + gSystem->Exit(0); + +} diff --git a/general_codes/ryotaro/TimingScan/macro/MyUtility/GetBinWithoutOverUnderFlow.cc b/general_codes/ryotaro/TimingScan/macro/MyUtility/GetBinWithoutOverUnderFlow.cc new file mode 100644 index 0000000..3cd6856 --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/MyUtility/GetBinWithoutOverUnderFlow.cc @@ -0,0 +1,21 @@ +#ifndef GETBINWITHOUTOVERUNDERFLOW_20250609 +#define GETBINWITHOUTOVERUNDERFLOW_20250609 + +int GetPreviousWithoutUnderflow(int bin){ + if (bin == 1) { + return 128; + } else { + return bin-1; + } +}; + +// same situation as get_previous_without_underflow(int bin) +int GetNextWithoutOverflow(int bin) { + if (bin == 128) { + return 1; + } else { + return bin+1; + } +}; + +#endif /* GETBINWITHOUTOVERUNDERFLOW_20250609 */ \ No newline at end of file diff --git a/general_codes/ryotaro/TimingScan/macro/PrintPdf.cc b/general_codes/ryotaro/TimingScan/macro/PrintPdf.cc new file mode 100644 index 0000000..4372c2e --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/PrintPdf.cc @@ -0,0 +1,73 @@ +#include "Utility/sPhenixStyle.C" +#include "CalculateRatioWithBgsubtraction.cc" +#include "CalculateRatio.cc" + +std::string GetDate(); +void PutExplanation(double fraction, int run); + +void PrintPdf(int run){ + SetsPhenixStyle(); + + std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/root/run%d.root", run); // output from Fun4All module, but at the same time, input for this macro + TFile* file = TFile::Open(filename.c_str(), "update"); + if ( !file || file->IsZombie() ){ + std::cerr << "ERROR: Could not open" << filename << std::endl; + exit(1); + } + + file->cd(); + TH1D* h_bco_diff_shifted = (TH1D*)file->Get("h_bco_diff_shifted"); //if your root file has a non-TH1D object with this name, it will cause empty canvas. Problem. We should check the type. + + + TCanvas* c1 = new TCanvas("c1", "", 900,600); + c1->cd(); + h_bco_diff_shifted->SetTitle("; Crossing relative to GTM [BCO]; INTT hit counts per event"); + h_bco_diff_shifted->SetMaximum(5000); + h_bco_diff_shifted->SetMinimum(0.00001); + gPad->SetLogy(); + h_bco_diff_shifted->Draw("HIST"); + // std::vector< std::pair > frac_and_ratio = CalculateRatioWithBgsubtraction(run); /* Returns ( {asymmetry, error}, {ratio, error} ) for given run. */ + std::vector< std::pair > frac_and_ratio = CalculateRatio(run); /* Returns ( {asymmetry, error}, {ratio, error} ) for given run. */ + double fraction = frac_and_ratio[0].first; + PutExplanation(fraction, run); + + + std::string output_canvas = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/image/run%d.pdf" , run); + c1->Print(output_canvas.c_str()); +} + +std::string GetDate(){ + // return "5/13/2025"; // use this once the dete is determined + TDatime dt; + int year = dt.GetYear(); + int month = dt.GetMonth(); + int day = dt.GetDay(); + + // format: mm/dd/yyyy + std::stringstream ss; + ss << month << "/" << day << "/" << year; + + return ss.str(); +} + +void PutExplanation(double fraction, int run){ + TLatex* tex = new TLatex(); + double line_height = 0.05; // no need to change + double first_margin = -0.12; // the margin from the top of the canvas to the top line (date). You can modify + double pos_x = 0.50; // you can modify + double pos_y = 1.0 + first_margin; // - line_height; + + /* Date, you may want to change 0.65 to pos_x */ + tex->DrawLatexNDC( pos_x, pos_y, + string("#it{" + GetDate() + "} " + "#it{#bf{sPHENIX}} Internal").c_str() ); + + // p+p 200 GeV + pos_y -= line_height + 0.03; + //tex->DrawLatexNDC( pos_x, pos_y, "Run-25 #it{Au+Au} 200 GeV" ); + tex->DrawLatexNDC( pos_x, pos_y, Form("Run %d", run) ); + + + pos_y -= line_height; + tex->DrawLatexNDC( pos_x, pos_y, (std::string("#it{N}_{L} / (#it{N}_{L} + #it{N}_{R}) = ") + std::to_string(fraction)).c_str() ); + +} diff --git a/general_codes/ryotaro/TimingScan/macro/ShiftPlot.cc b/general_codes/ryotaro/TimingScan/macro/ShiftPlot.cc new file mode 100644 index 0000000..8d0f811 --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/ShiftPlot.cc @@ -0,0 +1,183 @@ +#include "Utility/sPhenixStyle.C" +#include "CalculateRatioWithBgsubtraction.cc" +#include "CalculateRatio.cc" + +int FindEdgeBin(TH1D* hist, int peak_bin); +TH1D* ShiftHistoWithoutDupulication(TH1D* hist, int offset, TFile* file); +int AddOffsetWithoutOverflow(int this_bin, int offset); +void PutCaption(); +std::string GetDate(); +void PutExplanation(double fraction); + + + + +void ShiftPlot(int run){ + + SetsPhenixStyle(); + + std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/root/run%d.root", run); // output from Fun4All module, but at the same time, input for this macro + TFile* file = TFile::Open(filename.c_str(), "update"); + if ( !file || file->IsZombie() ){ + std::cerr << "ERROR: Could not open" << filename << std::endl; + exit(1); + } + + file->cd(); + TH1D* h_bco_diff = (TH1D*)file->Get("h_bco_diff"); //if your root file has a non-TH1D object with this name, it will cause empty canvas. Problem. We should check the type. + + int peak_bin = h_bco_diff->GetMaximumBin(); + int offset = FindEdgeBin(h_bco_diff, peak_bin); // We will shift the histogram by this offset, which is the bin number of the falling edge. + + TH1D* h_bco_diff_shifted = ShiftHistoWithoutDupulication(h_bco_diff, offset, file); + + + // TCanvas* c1 = new TCanvas("c1", "", 900,600); + // c1->cd(); + // //h_bco_diff_shifted->SetTitle("; Beam crossing (106 ns / crossing); INTT hit counts per event"); + // h_bco_diff_shifted->SetTitle("; Crossing relative to GTM [BCO]; INTT hit counts per event"); + // h_bco_diff_shifted->SetMaximum(100); + // h_bco_diff_shifted->SetMinimum(0.01); + // gPad->SetLogy(); + // h_bco_diff_shifted->Draw("HIST"); + // //PutCaption(); + // std::vector< std::pair > frac_and_ratio = CalculateRatioWithBgsubtraction(run); /* Returns ( {asymmetry, error}, {ratio, error} ) for given run. */ + // //std::vector< std::pair > frac_and_ratio = CalculateRatio(run); /* Returns ( {asymmetry, error}, {ratio, error} ) for given run. */ + // double fraction = frac_and_ratio[0].first; + // PutExplanation(fraction); + + // std::string output_canvas = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/image/run%d.pdf" , run); + // c1->Print(output_canvas.c_str()); + + file->cd(); + h_bco_diff_shifted->Write("h_bco_diff_shifted", TObject::kOverwrite); + //h_bco_diff_shifted->Write(); + //c1->Write("c_bco_diff_shifted_sStyle", TObject::kOverwrite); + + + file->Close(); + delete file; +} + + + + +int FindEdgeBin(TH1D* hist, int peak_bin){ + double threshold = 0.0000075; + // double threshold = 0.00007; /* for run 79252 */ + // double threshold = 0.007; /* for run 79266 */ + double height_ratio = 1; + int this_bin = peak_bin; + + for (int i=0; i < hist->GetNbinsX(); i--){ + this_bin = GetPreviousWithoutUnderflow(this_bin); // This is basically identical to (this_bin - 1), except in case of reaching the underflow bin. + height_ratio = hist->GetBinContent(this_bin) / hist->GetBinContent(peak_bin); + if (height_ratio < threshold) { + return this_bin; + } + } + + std::cerr << "No edge found!" << std::endl; + exit(1); + +} + +TH1D* ShiftHistoWithoutDupulication(TH1D* hist, int offset, TFile* file){ + + file->cd(); + TH1D* hist_shifted = NULL; + hist_shifted = (TH1D*)file->Get("h_bco_diff_shifted"); + + if (hist_shifted == NULL){ + // if it does not exists in the file, create a histogram with same parameters as the hist. + hist_shifted = (TH1D*)hist->Clone("h_bco_diff_shifted"); + hist_shifted->Reset(); + } else { + // if it already exists in the file, just reset it. + hist_shifted->Reset(); + } + + int bin_num_before; + for (int i=0; i < hist->GetNbinsX(); i++) { + bin_num_before = AddOffsetWithoutOverflow(1+i, offset); + hist_shifted->SetBinContent(1+i, hist->GetBinContent(bin_num_before)); + hist_shifted->SetBinError(1+i, hist->GetBinError(bin_num_before)); + } + + return hist_shifted; +}; + +//int GetPreviousWithoutUnderflow(int bin){ +// if (bin == 1) { +// return 128; +// } else { +// return bin-1; +// } +//} + +int AddOffsetWithoutOverflow(int this_bin, int offset) { + if ( this_bin + offset == 128){ + return 128; + } else { + return (this_bin + offset)%128; + } +} + +std::string GetDate(){ + // return "5/13/2025"; // use this once the dete is determined + TDatime dt; + int year = dt.GetYear(); + int month = dt.GetMonth(); + int day = dt.GetDay(); + + // format: mm/dd/yyyy + std::stringstream ss; + ss << month << "/" << day << "/" << year; + + return ss.str(); +}; + +void PutCaption(){ +/*from Genki*/ + TLatex* tex = new TLatex(); + double line_height = 0.05; // no need to change + double first_margin = -0.12; // the margin from the top of the canvas to the top line (date). You can modify + double pos_x = 0.60; // you can modify + double pos_y = 1.0 + first_margin; // - line_height; + + /* Date, you may want to change 0.65 to pos_x */ + tex->DrawLatexNDC( 0.65, pos_y, + string("#it{" + GetDate() + "}").c_str() ); + + // sPHENIX Internal or sPHENIX Prelimnary + pos_y -= line_height; + //tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Preliminary" ); + tex->DrawLatexNDC( pos_x, pos_y, "#it{#bf{sPHENIX}} Internal" ); + + // p+p 200 GeV + pos_y -= line_height + 0.03; + tex->DrawLatexNDC( pos_x, pos_y, ("Run-24 #it{p+p} 200 GeV") ); + + pos_y -= line_height; + tex->DrawLatexNDC( pos_x, pos_y, "INTT Triggered mode" ); +} + +// void PutExplanation(double fraction){ +// TLatex* tex = new TLatex(); +// double line_height = 0.05; // no need to change +// double first_margin = -0.12; // the margin from the top of the canvas to the top line (date). You can modify +// double pos_x = 0.50; // you can modify +// double pos_y = 1.0 + first_margin; // - line_height; + +// /* Date, you may want to change 0.65 to pos_x */ +// tex->DrawLatexNDC( pos_x, pos_y, +// string("#it{" + GetDate() + "} " + "#it{#bf{sPHENIX}} Internal").c_str() ); + +// // p+p 200 GeV +// pos_y -= line_height + 0.03; +// tex->DrawLatexNDC( pos_x, pos_y, ("Run-25 #it{Au+Au} 200 GeV") ); + +// pos_y -= line_height; +// tex->DrawLatexNDC( pos_x, pos_y, (std::string("#it{N}_{L} / (#it{N}_{L} + #it{N}_{R}) = ") + std::to_string(fraction)).c_str() ); + +// } diff --git a/general_codes/ryotaro/TimingScan/macro/Utility/sPhenixStyle.C b/general_codes/ryotaro/TimingScan/macro/Utility/sPhenixStyle.C new file mode 100644 index 0000000..567e5a2 --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/Utility/sPhenixStyle.C @@ -0,0 +1,120 @@ +#ifndef MACRO_SPHENIXSTYLE_C +#define MACRO_SPHENIXSTYLE_C + +// +// sPHENIX Style, based on a style file from BaBar, v0.1 +// + +#include "sPhenixStyle.h" + +#include +#include + +#include + +void SetsPhenixStyle() +{ + static TStyle* sphenixStyle = 0; + std::cout << "sPhenixStyle: Applying nominal settings." << std::endl; + if (sphenixStyle == 0) sphenixStyle = sPhenixStyle(); + gROOT->SetStyle("sPHENIX"); + gROOT->ForceStyle(); +} + +TStyle* sPhenixStyle() +{ + TStyle* sphenixStyle = new TStyle("sPHENIX", "sPHENIX style"); + + // use plain black on white colors + Int_t icol = 0; // WHITE + sphenixStyle->SetFrameBorderMode(icol); + sphenixStyle->SetFrameFillColor(icol); + sphenixStyle->SetCanvasBorderMode(icol); + sphenixStyle->SetCanvasColor(icol); + sphenixStyle->SetPadBorderMode(icol); + sphenixStyle->SetPadColor(icol); + sphenixStyle->SetStatColor(icol); + //sphenixStyle->SetFillColor(icol); // don't use: white fill color for *all* objects + + // set the paper & margin sizes + sphenixStyle->SetPaperSize(20, 26); + + // set margin sizes + sphenixStyle->SetPadTopMargin(0.05); + sphenixStyle->SetPadRightMargin(0.05); + sphenixStyle->SetPadBottomMargin(0.16); + sphenixStyle->SetPadLeftMargin(0.16); + + // set title offsets (for axis label) + sphenixStyle->SetTitleXOffset(1.4); + sphenixStyle->SetTitleYOffset(1.4); + + // use large fonts + //Int_t font=72; // Helvetica italics + Int_t font = 42; // Helvetica + Double_t tsize = 0.05; + sphenixStyle->SetTextFont(font); + + sphenixStyle->SetTextSize(tsize); + sphenixStyle->SetLabelFont(font, "x"); + sphenixStyle->SetTitleFont(font, "x"); + sphenixStyle->SetLabelFont(font, "y"); + sphenixStyle->SetTitleFont(font, "y"); + sphenixStyle->SetLabelFont(font, "z"); + sphenixStyle->SetTitleFont(font, "z"); + + sphenixStyle->SetLabelSize(tsize, "x"); + sphenixStyle->SetTitleSize(tsize, "x"); + sphenixStyle->SetLabelSize(tsize, "y"); + sphenixStyle->SetTitleSize(tsize, "y"); + sphenixStyle->SetLabelSize(tsize, "z"); + sphenixStyle->SetTitleSize(tsize, "z"); + + // use bold lines and markers + sphenixStyle->SetMarkerStyle(20); + sphenixStyle->SetMarkerSize(1.2); + sphenixStyle->SetHistLineWidth(2.); + sphenixStyle->SetLineStyleString(2, "[12 12]"); // postscript dashes + + // get rid of X error bars + //sphenixStyle->SetErrorX(0.001); + // get rid of error bar caps + sphenixStyle->SetEndErrorSize(0.); + + // do not display any of the standard histogram decorations + sphenixStyle->SetOptTitle(0); + //sphenixStyle->SetOptStat(1111); + sphenixStyle->SetOptStat(0); + //sphenixStyle->SetOptFit(1111); + sphenixStyle->SetOptFit(0); + + // put tick marks on top and RHS of plots + sphenixStyle->SetPadTickX(1); + sphenixStyle->SetPadTickY(1); + + // legend modificatin + sphenixStyle->SetLegendBorderSize(0); + sphenixStyle->SetLegendFillColor(0); + sphenixStyle->SetLegendFont(font); + +#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 00, 0) + std::cout << "sPhenixStyle: ROOT6 mode" << std::endl; + sphenixStyle->SetLegendTextSize(tsize); + sphenixStyle->SetPalette(kBird); +#else + std::cout << "sPhenixStyle: ROOT5 mode" << std::endl; + // color palette - manually define 'kBird' palette only available in ROOT 6 + Int_t alpha = 0; + Double_t stops[9] = {0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000}; + Double_t red[9] = {0.2082, 0.0592, 0.0780, 0.0232, 0.1802, 0.5301, 0.8186, 0.9956, 0.9764}; + Double_t green[9] = {0.1664, 0.3599, 0.5041, 0.6419, 0.7178, 0.7492, 0.7328, 0.7862, 0.9832}; + Double_t blue[9] = {0.5293, 0.8684, 0.8385, 0.7914, 0.6425, 0.4662, 0.3499, 0.1968, 0.0539}; + TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, alpha); +#endif + + sphenixStyle->SetNumberContours(80); + + return sphenixStyle; +} + +#endif diff --git a/general_codes/ryotaro/TimingScan/macro/Utility/sPhenixStyle.h b/general_codes/ryotaro/TimingScan/macro/Utility/sPhenixStyle.h new file mode 100644 index 0000000..3e911be --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/Utility/sPhenixStyle.h @@ -0,0 +1,51 @@ +// +// @file sPhenixStyle.h +// +// sPHENIX Style, based on a style file from ATLAS +// +// +// @author Peter Steinberg +// +// Copyright (C) 2017 sPhenix Collaboration +// +// Version 0.1 + +#ifndef MACRO_SPHENIXSTYLE_H +#define MACRO_SPHENIXSTYLE_H + +#include + +//! \brief sPHENIX Style, based on a style file from ATLAS by Peter Steinberg +/* +Please find instruction at https://wiki.bnl.gov/sPHENIX/index.php/Plot_template . Here is a snapshot: + +# How to use + +To ensure some consistency among plots produced by different sPHENIX members, a candidate style file is being proposed (May 2017), based on the ATLAS style file. Please click here for the gzipped tar file. +For general use, copy or link the ``sPHENIXStyle.h`` and ``sPHENIXStyle.C`` files somewhere, either locally or in your macro path (``gROOT->GetMacroPath()`` will tell you, and add it in ``.rootrc`` if you need one). +Then do +`` +[0] gROOT->LoadMacro("sPhenixStyle.C") +[1] SetsPhenixStyle() +`` +and you're good to go (even better, add this all into your ``.rootlogon.C`` file) + +# Rules of the sPHENIX style + +* Don't talk about the style file. +* Always use the style file. +* Units should always be indicated in brackets "[ ]", while counts will typically specify the bin width "Events / 2 GeV" or "Events / 0.13 rad". +* Every plot should have a legend indicating "sPHENIX", "sPHENIX Preliminary", "sPHENIX Simulation", etc. +* sPHENIX should be bold, italic +* Where possible, indicate the system being considered and it's energy +* "MC" predictions should be filled, with distinguishable colors +* Data or pseudodata should always be histograms or graphs with error bars +* Elements should never overlap, with each other or with the axis + + * + */ +void SetsPhenixStyle(); + +TStyle* sPhenixStyle(); + +#endif // MACRO_SPHENIXSTYLE_H diff --git a/general_codes/ryotaro/TimingScan/macro/run_condor.job b/general_codes/ryotaro/TimingScan/macro/run_condor.job new file mode 100755 index 0000000..258f057 --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/run_condor.job @@ -0,0 +1,20 @@ +Universe = vanilla +Initialdir = /sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/macro +Executable = run_job.sh +PeriodicHold = (NumJobStarts>=1 && JobStatus == 1) +concurrency_limits = CONCURRENCY_LIMIT_DEFAULT:100 +request_memory = 4GB +Priority = 20 +job_lease_duration = 86400 + +runnumber = 82400 +nEvents = -1 +job_offset = 0 +process_shift = $(Process) + $(job_offset) +output_directory = /sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output + +Output = $(output_directory)/condor/condor_$(runnumber).out +Error = $(output_directory)/condor/condor_$(runnumber).err +Log = $(output_directory)/condor/condor_$(runnumber).log +Arguments = "$INT(process_shift) $(runnumber) $(nEvents)" +Queue 1 diff --git a/general_codes/ryotaro/TimingScan/macro/run_job.sh b/general_codes/ryotaro/TimingScan/macro/run_job.sh new file mode 100755 index 0000000..06a9527 --- /dev/null +++ b/general_codes/ryotaro/TimingScan/macro/run_job.sh @@ -0,0 +1,31 @@ +#! /bin/bash +# export USER="$(id -u -n)" +# export LOGNAME=${USER} +# export HOME=/sphenix/u/${LOGNAME} + +#source /opt/sphenix/core/bin/sphenix_setup.sh -n ana.464 +#source /opt/sphenix/core/bin/sphenix_setup.sh +source /opt/sphenix/core/bin/sphenix_setup.sh -n ana +# source /opt/sphenix/core/bin/sphenix_setup.sh -n ana.491 + + +export MYINSTALL=/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/install + +export LD_LIBRARY_PATH=$MYINSTALL/lib:$LD_LIBRARY_PATH +export ROOT_INCLUDE_PATH=$MYINSTALL/include:$ROOT_INCLUDE_PATH + +source /opt/sphenix/core/bin/setup_local.sh $MYINSTALL + +echo $ROOT_INCLUDE_PATH | sed -e "s/:/\n/g" + +process=$1 +runnumber=$2 +nEvents=$3 + +echo process: ${process} +echo runnumber: ${runnumber} +echo nEvents: ${nEvents} + +root.exe -q -b Fun4All_TimingScan.cc\(${process},${runnumber},${nEvents}\) + +echo all done process the Fun4All_Intt_SanityCheck.C, process_id ${process_id} diff --git a/general_codes/ryotaro/TimingScan/src/InttTimingScan.cc b/general_codes/ryotaro/TimingScan/src/InttTimingScan.cc new file mode 100644 index 0000000..ecc0c3c --- /dev/null +++ b/general_codes/ryotaro/TimingScan/src/InttTimingScan.cc @@ -0,0 +1,592 @@ +#include "InttTimingScan.h" +#include + +InttTimingScan::InttTimingScan(const std::string &name, int run):SubsysReco(name){ + std::cout << "InttTimingScan(const std::string &name) Calling the constructor" << std::endl; + + run_ = run; + my_event_counter_=0; +}; + +InttTimingScan::~InttTimingScan(){ + std::cout << "InttTimingScan(const std::string &name) Calling the deconstructor" << std::endl; +}; + + +int InttTimingScan::Init(PHCompositeNode *topNode){ + std::cout << "InttTimingScan::Init(PHCompositeNode *topNode) Initializing" << std::endl; + + std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/root/run%d.root", run_); + // std::string filename = Form("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/commissioning25/TimingScan/output/root/run%d_felix7.root", run_); + output_file_ = new TFile(filename.c_str(),"recreate"); + if ( !output_file_->IsOpen()){ + std::cerr << "ERROR : File '" << filename << "' not found or could not be opend." << std::endl; + std::exit(1); + } + + h_bco_diff_ = new TH1D("h_bco_diff", "h_bco_diff", 128, 0, 128); + + t_output_ = new TTree("tree", "tree"); + t_output_->Branch("bco_diff", &branch_bco_diff_, "bco_diff/s"); // "/s" means short integer or 16 bit unsigned int. + + if (mode_ == Mode::RawHitOnly) { + this->PrepareHotChannelMap(); + } + + return Fun4AllReturnCodes::EVENT_OK; +}; + +int InttTimingScan::InitRun(PHCompositeNode *topNode){ + std::cout << "InttTimingScan::InitRun(PHCompositeNode *topNode) Initializing ... " << std::endl; + return Fun4AllReturnCodes::EVENT_OK; +}; + +int InttTimingScan::process_event(PHCompositeNode *topNode){ + switch (mode_) { + case Mode::RawHitOnly: + process_event_inttrawhit_only(topNode); + break; + case Mode::RawPlusTrkr: + process_event_raw_plus_trkrhit(topNode); + break; + } + + return Fun4AllReturnCodes::EVENT_OK; +} + +int InttTimingScan::process_event_inttrawhit_only(PHCompositeNode *topNode) { + my_event_counter_++; + if (my_event_counter_ % 200 == 0) { std::cout << "event id: " << my_event_counter_ << std::endl; } + + + switch (daq_mode_) { + case DaqMode::Official: + for (int i=0; i<8; i++) { + std::string node_name = Form("%s_%d",node_name_intt_raw_hit_.c_str(), i); + node_inttrawhit_map_ = findNode::getClass(topNode, node_name.c_str()); + this->FillHist(node_inttrawhit_map_); + } + break; + case DaqMode::Local: + node_inttrawhit_map_ = findNode::getClass(topNode,"INTTRAWHIT"); + this->FillHist(node_inttrawhit_map_); + break; + } + + /* This part is ported to FillHist() */ + // for ( unsigned int i = 0; i < node_inttrawhit_map_->get_nhits(); i++ ) { + // InttRawHit* hit = node_inttrawhit_map_->get_hit(i); + + // /* some conversions needed to adjust to value range of hot_channel_map_ */ + // int felix_server = hit->get_packetid() - 3001; + // int felix_channel = hit->get_fee(); + // int chip = (hit->get_chip_id() - 1) % 26; + // int channel = hit->get_channel_id(); + + // if (hot_channel_map_.size() == 0) {std::cerr<<"map size zero"<get_FPHX_BCO(); + // uint64_t bco_full = hit->get_bco(); + // // uint16_t bco_diff = 0; + + // /* ここが変な振る舞いの原因? */ + // // if( (uint16_t)(bco_full & 0x7f) > (uint16_t)(fphx_bco) ){ + // // bco_diff = ( (uint16_t)fphx_bco + 128 ) - (uint16_t)((bco_full) & 0x7f ); + // // } else { + // // bco_diff = (uint16_t)fphx_bco - (uint16_t)(bco_full & 0x7f ); + // // } + // uint64_t bco_diff = (fphx_bco - ( (bco_full) & 0x7fU) + 128) % 128; + + // h_bco_diff_->Fill(bco_diff); + + // branch_bco_diff_ = bco_diff; + // t_output_->Fill(); /* Fills a bco_diff to the TTree */ + // } + + return Fun4AllReturnCodes::EVENT_OK; +}; + +int InttTimingScan::process_event_raw_plus_trkrhit(PHCompositeNode *topNode){ + my_event_counter_++; + + if (my_event_counter_ % 200 == 0) { std::cout << "event id: " << my_event_counter_ << std::endl; } + // std::cout << "event id: " << my_event_counter_ << std::endl; + + node_trkrhitset_map_ = findNode::getClass(topNode,"TRKR_HITSET"); // 返り値の型は TrkrHitSetContainer ?? + node_inttrawhit_map_ = findNode::getClass(topNode,"INTTRAWHIT"); + + /* This can be omitted, I think. We can use node_inttrawhit_map_->get_bco() instead. */ + // InttEventInfo* node_intteventheader_map_ = findNode::getClass(topNode, "INTTEVENTHEADER"); + // auto bco_full = node_intteventheader_map_->get_bco_full(); + auto bco_full = node_inttrawhit_map_->get_hit(0)->get_bco(); + + auto bco_event_counter_pair = this->GetBcoEventCounter(); + for (int i=0; i (uint16_t)(fphx_bco) ){ + bco_diff = ( (uint16_t)fphx_bco + 128 ) - (uint16_t)((bco_full) & 0x7f ); + } else { + bco_diff = (uint16_t)fphx_bco - (uint16_t)(bco_full & 0x7f ); + } + + h_bco_diff_->Fill(bco_diff); + + branch_bco_diff_ = bco_diff; + t_output_->Fill(); /* Fills a bco_diff to the TTree */ + + std::cout << "event id: " << my_event_counter_ << std::endl; + + //std::cout << std::bitset<32>(fphx_bco+128) << '-' << std::bitset<32>((bco_full)&(0x7f)) << '=' << std::bitset<32>( bco_diff ) << std::endl; + } + + + return Fun4AllReturnCodes::EVENT_OK; +}; + +int InttTimingScan::ResetEvent(PHCompositeNode *topNode){ + // std::cout << "InttTimingScan::ResetEvent(PHCompositeNode *topNode) Resetting internal structures, prepare for next event" << std::endl; + return Fun4AllReturnCodes::EVENT_OK; + +}; + +int InttTimingScan::EndRun(const int runnumber){ + std::cout << "InttTimingScan::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl; + return Fun4AllReturnCodes::EVENT_OK; +}; + +int InttTimingScan::End(PHCompositeNode *topNode){ + std::cout << "InttTimingScan::End(PHCompositeNode *topNode) This is the End..." << std::endl; + + + output_file_->cd(); + h_bco_diff_->Scale( 1.0 / my_event_counter_); + h_bco_diff_->Write(); + t_output_->Write(); + + output_file_->Close(); + + //h_bco_diff_->SaveAs("/sphenix/tg/tg01/commissioning/INTT/work/ryotaro/TimingScan/output/image/run.png"); + + return Fun4AllReturnCodes::EVENT_OK; +}; + +int InttTimingScan::Reset(PHCompositeNode * /*topNode*/){ + std::cout << "InttTimingScan::Reset(PHCompositeNode *topNode) being Reset" << std::endl; + return Fun4AllReturnCodes::EVENT_OK; +}; + +void InttTimingScan::Print(const std::string &what) const +{ + std::cout << "InttTimingScan::Print(const std::string &what) const Printing info for " << what << std::endl; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +std::vector< std::pair > InttTimingScan::GetBcoEventCounter(){ + std::cout << "GetBcoEventCounter Called." << std::endl; + + std::vector< std::pair< InttNameSpace::Online_s, unsigned int> > online_hits = this->GetHits( node_trkrhitset_map_->getHitSets() ); + std::vector raw_hits = this->GetRawHitsWithoutClone(); + + std::vector< std::pair > rtn; + + + // if( raw_hits.size() > 20 ) + // return rtn; + InttDacMap* dac_map = new InttDacMap(); + + int counter = 0; + for( int i=0; i used_index( raw_hits.size() ); + + for( int j=0; jget_channel_id(); + // first selections + if( chan_raw != raw_data.channel ) continue; + + // uint16_t InttRawHit::get_chip_id + int chip_raw = raw_hit->get_chip_id(); + if(chip_raw > 26){ + chip_raw = chip_raw - 26; + } + chip_raw--; // to change from 1-base to 0-base + if( chip_raw != raw_data.chip ) continue; + + int felix_raw = raw_hit->get_packetid() - 3001; + int felix_ch_raw = raw_hit->get_fee(); + bool is_same = (felix_raw == raw_data.felix_server + || felix_ch_raw == raw_data.felix_channel ); + // || adc_raw == adc ); + + if( is_same == false ) continue; + + auto adc_raw = raw_hit->get_adc(); + /* + virtual unsigned short GetDAC(const uint& felix_server, + const uint& felix_channel, + const uint& chip, + const uint& channel, + const uint& adc); + */ + auto dac_raw = dac_map->GetDAC( felix_raw, felix_ch_raw, chip_raw, chan_raw, adc_raw ); + if( dac_raw != dac ) continue; + + auto bco_raw = raw_hit->get_FPHX_BCO(); + //if (bco_raw > 256) std::cout << bco_raw << std::endl; + int event_counter_raw = raw_hit->get_event_counter(); // uint32_t IttRawHit::get_event_counter() + std::pair bco_event_counter(bco_raw, event_counter_raw); + + /* before */ + rtn.push_back( bco_event_counter ); + counter++; + + /* after */ + // u_int32_t felix_server = raw_hit->get_packetid() - 3001; + // if (felix_server == 7) { + // std::cout << felix_server; + // rtn.push_back( bco_event_counter ); + // counter++; + // } + + + //if( felix_raw == raw_data.felix_server ) + // if( felix_ch_raw == raw_data.felix_channel && felix_ch_raw != 0 ) + // cout << "RawHit: " + // << setw(4) << j + // << ": " + // << setw(3) << felix_raw + // << setw(5) << felix_ch_raw + // << setw(4) << chip_raw + // << setw(6) << chan_raw + // << setw(4) << adc_raw + // << endl; + + // cout << "( " + // << setw(3) << bco_raw << ", " << setw(1) << adc_raw << "-> " << dac + // << "), "; + //used_index.push_back( j ); + //raw_hits.erase( raw_hits.begin() + j ); + //break; + } + // cout << endl; + + } + + + // cout << counter << " / " << online_hits.size() << " found their corresponding raw hit while there are " + // << raw_hits.size() << " raw hits in this event." + // << endl; + return rtn; +} + +std::vector InttTimingScan::GetRawHitsWithoutClone(){ + std::cout << "GetRawHitsWithoutClone() Called." << std::endl; + + auto hits = this->GetRawHits(); + std::vector rtn; + + for( int i=0; iIsSame( hits[i], hits[j] ); + if( is_same_found == true ){ + break; + } + + } // end of for( hit_j ) + + // if this hit is still unique (same hit is not found), keep it + if( is_same_found == false ){ + rtn.push_back( hits[i] ); + } + + } // end of for( hit_i ) + + + return rtn; +} + +std::vector InttTimingScan::GetRawHits(){ + + std::vector hits; + auto raw_hit_num = node_inttrawhit_map_->get_nhits(); + for (unsigned int i = 0; i < raw_hit_num; i++){ + auto hit = node_inttrawhit_map_->get_hit(i); + hits.push_back( hit ); + } + + return hits; +} + + +// Create a easy-to-use object from tracker hit sets +std::vector< std::pair > InttTimingScan::GetHits(TrkrHitSetContainer::ConstRange hitsets){ + std::cout << "GetHits(TrkrHitSetContainer::ConstRange hitsets) Called." << std::endl; + + std::vector< std::pair > hits_information; + auto current = hitsets.first; + while( current != hitsets.second ){ + auto hitset = (*current).second; + + //TrkrDefs::printBits( (*current).first ); + + auto layer = TrkrDefs::getLayer( (*current).first ); + // layer: 0, 1, 2 : MVTX + // 3, 4, 5, 6: INTT + // 6< : TPC + + // Take hits from only INTT + if( !(3<= layer && layer <= 6) ) continue; + + auto detector_id = TrkrDefs::getTrkrId( (*current).first ); + auto phi = InttDefs::getLadderPhiId( (*current).first ); //TrkrDefs::getPhiElement( (*current).first ); + auto z = InttDefs::getLadderZId( (*current).first ); // TrkrDefs::getZElement( (*current).first ); + // cout << "-----> " + // << int(detector_id) << "\t" << int(layer) << "\t" + // << int(phi) << "\t" << int(z) ; + // //<< endl; + // cout << " + " << (*current).first << "\t" + // << hitset->size() + // << endl; + + auto hits = hitset->getHits(); // ConstRange = std::pair< ConstIterator, ConstIterator > + auto current2 = hits.first; // ConstIterator = Map::const_iterator, here, Map = std::map < TrkrDefs::hitkey, TrkrHit* >, This Map is different from the Map for TrkrHitSetContainer!!! + while( current2 != hits.second ){ + auto key = (*current2).first; + auto hit = (*current2).second; + + auto col = InttDefs::getCol( key ); + auto row = InttDefs::getRow( key ); + + InttNameSpace::Offline_s offline_hit; + offline_hit.layer = layer; + offline_hit.ladder_phi = phi; + offline_hit.ladder_z = z; + offline_hit.strip_x = row; + offline_hit.strip_y = col; + + InttNameSpace::Online_s online_hit = InttNameSpace::ToOnline( offline_hit ); + + auto hit_info = std::pair < InttNameSpace::Online_s, unsigned int >( online_hit, hit->getAdc() ); + hits_information.push_back( hit_info ); + + current2++; + } + + current++; + } + + return hits_information; +}; + +bool InttTimingScan::IsSame(InttRawHit* hit1, InttRawHit* hit2){ + + if( hit1->get_word() != hit2->get_word() ) // only this might be enough + return false; + else if( hit1->get_bco() != hit2->get_bco() ) + return false; + else if( hit1->get_FPHX_BCO() != hit2->get_FPHX_BCO() ) + return false; + else if( hit1->get_channel_id() != hit2->get_channel_id() ) + return false; + else if( hit1->get_chip_id() != hit2->get_chip_id() ) + return false; + else if( hit1->get_fee() != hit2->get_fee() ) + return false; + else if( hit1->get_packetid() != hit2->get_packetid() ) + return false; + else if( hit1->get_adc() != hit2->get_adc() ) + return false; + else if( hit1->get_full_FPHX() != hit2->get_full_FPHX() ) + return false; + // else if( hit1->get_full_ROC() != hit2->get_full_ROC() ) // maybe no value is assigned? + // return false; + // else if( hit1->get_amplitude()!= hit2->get_amplitude()) // maybe no value is assigned? + // return false; + + // hits pass all comparison are the same + return true; +}; + + +void InttTimingScan::PrepareHotChannelMap(){ + std::cout << "InttTimingScan::PrepareHotChannelMap called" << std::endl; + TFile* input_file_hot_channel_map = TFile::Open(this->file_path_to_hot_channel_map_.c_str()); + if (!input_file_hot_channel_map) { + std::cout << "InttTimingScan::PrepareHotChannelMap - hot channel file not found" << std::endl; + exit(EXIT_FAILURE); + } + + TTree* tree_hot_channel = (TTree*)input_file_hot_channel_map->Get(tree_name_hot_channel_.c_str()); + + int IID; + int Ichannel; + int Ichip; + int Ifelix_channel; + int Ifelix_server; + int Iflag; + + tree_hot_channel->SetBranchAddress("IID",&IID); + tree_hot_channel->SetBranchAddress("Ichannel",&Ichannel); + tree_hot_channel->SetBranchAddress("Ichip",&Ichip); + tree_hot_channel->SetBranchAddress("Ifelix_channel",&Ifelix_channel); + tree_hot_channel->SetBranchAddress("Ifelix_server",&Ifelix_server); + tree_hot_channel->SetBranchAddress("Iflag",&Iflag); + + // std::map hot_channel_map; /* key はともかく、value を string にする必要はないような*/ + + for (int i=0; iGetEntries(); i++) { + tree_hot_channel->GetEntry(i); + this->hot_channel_map_[Form("%d_%d_%d_%d",Ifelix_server,Ifelix_channel,Ichip,Ichannel)] = Form("%d",Iflag); + } +}; + +void InttTimingScan::FillHist(InttRawHitContainerv2* container_inttrawhit) { + for ( unsigned int i = 0; i < container_inttrawhit->get_nhits(); i++ ) { + InttRawHit* hit = container_inttrawhit->get_hit(i); + + /* some conversions needed to adjust to value range of hot_channel_map_ */ + int felix_server = hit->get_packetid() - 3001; + int felix_channel = hit->get_fee(); + int chip = (hit->get_chip_id() - 1) % 26; + int channel = hit->get_channel_id(); + + if (hot_channel_map_.size() == 0) {std::cerr<<"map size zero"<get_FPHX_BCO(); + uint64_t bco_full = hit->get_bco(); + // uint16_t bco_diff = 0; + + /* ここが変な振る舞いの原因? */ + // if( (uint16_t)(bco_full & 0x7f) > (uint16_t)(fphx_bco) ){ + // bco_diff = ( (uint16_t)fphx_bco + 128 ) - (uint16_t)((bco_full) & 0x7f ); + // } else { + // bco_diff = (uint16_t)fphx_bco - (uint16_t)(bco_full & 0x7f ); + // } + uint64_t bco_diff = (fphx_bco - ( (bco_full) & 0x7fU) + 128) % 128; + + h_bco_diff_->Fill(bco_diff); + + branch_bco_diff_ = bco_diff; + t_output_->Fill(); /* Fills a bco_diff to the TTree */ + } +} \ No newline at end of file diff --git a/general_codes/ryotaro/TimingScan/src/InttTimingScan.h b/general_codes/ryotaro/TimingScan/src/InttTimingScan.h new file mode 100644 index 0000000..8067669 --- /dev/null +++ b/general_codes/ryotaro/TimingScan/src/InttTimingScan.h @@ -0,0 +1,124 @@ +// Tell emacs that this is a C++ source +// -*- C++ -*-. + +// Fun4All analysis module for INTT timing scan, made by Ryotaro Koike 20250501 +#ifndef INTT_TIMING_SCAN_H_20250501 +#define INTT_TIMING_SCAN_H_20250501 + + +#include "TH1D.h" +#include "TTree.h" +#include "TFile.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +//#include +#include +#include +#include +#include +#include + + + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +//#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +#include +#include + + +class InttTimingScan : public SubsysReco +{ + public: + InttTimingScan(const std::string &name, int run); + + ~InttTimingScan(); + + // mandatory methods for Fun4All analysis module + int Init(PHCompositeNode *topNode) override; + int InitRun(PHCompositeNode *topNode) override; + int process_event(PHCompositeNode *topNode) override; + int ResetEvent(PHCompositeNode *topNode) override; + int EndRun(const int runnumber) override; + int End(PHCompositeNode *topNode) override; + int Reset(PHCompositeNode *topNode) override; // Cheng-Wei のコードでは int Reset(PHCompositeNode * /*topNode*/) override; となっている。引数がおかしくない? + void Print(const std::string &what) const override; + + // The return value represents . + // Will be used in the process_event + std::vector< std::pair > GetBcoEventCounter(); + std::vector GetRawHitsWithoutClone(); + std::vector GetRawHits(); + // The return value represents . + // Will be used in the process_event + std::vector< std::pair > GetHits(TrkrHitSetContainer::ConstRange hitsets); + bool IsSame(InttRawHit* hit1, InttRawHit* hit2); + + enum class Mode { RawHitOnly, RawPlusTrkr }; + void set_mode(Mode m) { mode_ = m; }; + + void set_hot_channel_map_file(std::string input) {file_path_to_hot_channel_map_ = input;}; + + enum class DaqMode { Official, Local }; + void set_daq_mode(DaqMode daq_mode) { daq_mode_ = daq_mode;}; + + private: + TFile* output_file_; + TTree* t_output_; + TH1D* h_bco_diff_; + TrkrHitSetContainer* node_trkrhitset_map_; + InttRawHitContainerv2* node_inttrawhit_map_; + uint16_t branch_bco_diff_; + int run_; + int my_event_counter_; + + Mode mode_ = Mode::RawHitOnly; + int process_event_inttrawhit_only(PHCompositeNode *topNode); + int process_event_raw_plus_trkrhit(PHCompositeNode *topNode); + + DaqMode daq_mode_ = DaqMode::Local; + + std::string node_name_intt_raw_hit_{"INTTRAWHIT"}; + + std::string tree_name_hot_channel_{"Multiple"}; + std::string file_path_to_hot_channel_map_; + std::map hot_channel_map_; + void PrepareHotChannelMap(); + + void FillHist(InttRawHitContainerv2* container_inttrawhit); + +}; + +#endif //INTT_TIMING_SCAN_H_20250501 \ No newline at end of file diff --git a/general_codes/ryotaro/TimingScan/src/Makefile.am b/general_codes/ryotaro/TimingScan/src/Makefile.am new file mode 100644 index 0000000..eac312e --- /dev/null +++ b/general_codes/ryotaro/TimingScan/src/Makefile.am @@ -0,0 +1,46 @@ +AUTOMAKE_OPTIONS = foreign + +AM_CPPFLAGS = \ + -I$(includedir) \ + -I$(OFFLINE_MAIN)/include \ + -isystem$(ROOTSYS)/include + +AM_LDFLAGS = \ + -L$(libdir) \ + -L$(OFFLINE_MAIN)/lib \ + -L$(OFFLINE_MAIN)/lib64 + +pkginclude_HEADERS = \ + InttTimingScan.h + +lib_LTLIBRARIES = \ + libInttTimingScan.la + +libInttTimingScan_la_SOURCES = \ + InttTimingScan.cc + +libInttTimingScan_la_LIBADD = \ + -lphool \ + -lSubsysReco \ + -lffaobjects \ + -lffarawobjects \ + -ltrack_io \ + -lintt + +BUILT_SOURCES = testexternals.cc + +noinst_PROGRAMS = \ + testexternals + +testexternals_SOURCES = testexternals.cc +testexternals_LDADD = libInttTimingScan.la + +testexternals.cc: + echo "//*** this is a generated file. Do not commit, do not edit" > $@ + echo "int main()" >> $@ + echo "{" >> $@ + echo " return 0;" >> $@ + echo "}" >> $@ + +clean-local: + rm -f $(BUILT_SOURCES) diff --git a/general_codes/ryotaro/TimingScan/src/autogen.sh b/general_codes/ryotaro/TimingScan/src/autogen.sh new file mode 100755 index 0000000..dea267b --- /dev/null +++ b/general_codes/ryotaro/TimingScan/src/autogen.sh @@ -0,0 +1,8 @@ +#!/bin/sh +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +(cd $srcdir; aclocal -I ${OFFLINE_MAIN}/share;\ +libtoolize --force; automake -a --add-missing; autoconf) + +$srcdir/configure "$@" diff --git a/general_codes/ryotaro/TimingScan/src/configure.ac b/general_codes/ryotaro/TimingScan/src/configure.ac new file mode 100644 index 0000000..4971bcb --- /dev/null +++ b/general_codes/ryotaro/TimingScan/src/configure.ac @@ -0,0 +1,16 @@ +AC_INIT(tutorial,[1.00]) +AC_CONFIG_SRCDIR([configure.ac]) + +AM_INIT_AUTOMAKE +AC_PROG_CXX(CC g++) + +LT_INIT([disable-static]) + +dnl no point in suppressing warnings people should +dnl at least see them, so here we go for g++: -Wall +if test $ac_cv_prog_gxx = yes; then + CXXFLAGS="$CXXFLAGS -Wall" +fi + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT