File indexing completed on 2025-08-06 08:17:41
0001 #ifndef INTT_INTTXYVTX_H
0002 #define INTT_INTTXYVTX_H
0003
0004 #include "InttVertexUtil.h"
0005
0006 #include <TCanvas.h>
0007 #include <TFile.h>
0008 #include <TGraphErrors.h>
0009 #include <TH1.h>
0010 #include <TH2.h>
0011 #include <TLatex.h>
0012 #include <TLegend.h>
0013 #include <TProfile.h>
0014
0015 #include <filesystem>
0016 #include <iostream>
0017 #include <map>
0018 #include <numeric>
0019 #include <string>
0020 #include <vector>
0021
0022
0023
0024
0025
0026
0027
0028 struct type_pos
0029 {
0030 double x;
0031 double y;
0032 };
0033
0034 class INTTXYvtx
0035 {
0036 public:
0037 struct clu_info
0038 {
0039 int column;
0040
0041 double avg_chan;
0042 int sum_adc;
0043 int sum_adc_conv;
0044 int size;
0045
0046 double x;
0047 double y;
0048 double z;
0049 int layer;
0050 double phi;
0051
0052 };
0053
0054 public:
0055 INTTXYvtx(const std::string& runType,
0056 const std::string& outFolderDirectory,
0057 std::pair<double, double> beamOrigin,
0058 double phiDiffCut = 0.11,
0059 std::pair<double, double> DCACut = {-1, 1},
0060 int NCluCutl = 20,
0061 int NCluCut = 10000,
0062 double angleDiffNew_l = 0.0,
0063 double angleDiffNew_r = 3,
0064 double peekCut = 3.32405,
0065 bool printMessageOpt = true);
0066
0067 virtual ~INTTXYvtx();
0068
0069 void Init();
0070
0071 void SetBeamOrigin(double beamx, double beamy)
0072 {
0073 beam_origin = std::make_pair(beamx, beamy);
0074 current_vtxX = beam_origin.first;
0075 current_vtxY = beam_origin.second;
0076 }
0077
0078 virtual void SetSaveHisto(const bool save) { m_savehist = save; }
0079 virtual void EnableDrawHisto(const bool enable) { m_enable_drawhist = enable; }
0080 virtual void EnableQA(const bool enable) { m_enable_qa = enable; }
0081 virtual void PrintMessageOpt(const bool flag) { print_message_opt = flag; }
0082
0083
0084
0085 void ProcessEvt(int event_i,
0086 const std::vector<clu_info>& temp_sPH_inner_nocolumn_vec,
0087 const std::vector<clu_info>& temp_sPH_outer_nocolumn_vec,
0088 const std::vector<std::vector<double>>& temp_sPH_nocolumn_vec,
0089 const std::vector<std::vector<double>>& temp_sPH_nocolumn_rz_vec,
0090 int NvtxMC,
0091 double TrigZvtxMC,
0092 bool PhiCheckTag,
0093 Long64_t bco_full);
0094
0095
0096
0097
0098 std::vector<std::pair<double, double>> MacroVTXSquare(double length, int N_trial);
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 std::vector<std::pair<double, double>> FillLine_FindVertex(
0110 std::pair<double, double> window_center,
0111 double segmentation = 0.005,
0112 double window_width = 5.0,
0113 int N_bins = 100);
0114
0115
0116
0117
0118
0119 virtual void ClearEvt();
0120 virtual void PrintPlots();
0121 virtual void EndRun();
0122
0123
0124
0125 unsigned long GetVecNele();
0126 std::pair<double, double> GetFinalVTXxy();
0127 std::pair<std::vector<TH2F*>, std::vector<TH1F*>> GetHistFinal();
0128
0129 protected:
0130 std::string run_type;
0131 std::string out_folder_directory;
0132 std::pair<double, double> beam_origin;
0133 double phi_diff_cut;
0134 std::pair<double, double> DCA_cut;
0135 int N_clu_cutl;
0136 int N_clu_cut;
0137 double angle_diff_new_l;
0138 double angle_diff_new_r;
0139 double peek;
0140 bool print_message_opt{false};
0141
0142 bool m_savehist{false};
0143 bool m_enable_drawhist{false};
0144 bool m_enable_qa{false};
0145
0146 bool m_initialized{false};
0147 std::string m_quad_pdfname{"New_Trial_square.pdf"};
0148
0149 protected:
0150
0151 std::vector<double> subMacroVTXxyCorrection(int test_index, int trial_index, bool draw_plot_opt);
0152 std::vector<double> GetVTXxyCorrection_new(int trial_index);
0153 virtual void subMacroPlotWorking(bool phi_correction, double cos_fit_rangel, double cos_fit_ranger, double guas_fit_range);
0154
0155 std::vector<double> calculateDistanceAndClosestPoint(double x1, double y1, double x2, double y2, double target_x, double target_y);
0156 double calculateAngleBetweenVectors(double x1, double y1, double x2, double y2, double targetX, double targetY);
0157
0158
0159 void PrintPlotsVTXxy();
0160
0161 std::vector<std::pair<double, double>> Get4vtx(std::pair<double, double> origin, double length);
0162 void TH1F_FakeClone(TH1F* hist_in, TH1F* hist_out);
0163 void TH2F_FakeClone(TH2F* hist_in, TH2F* hist_out);
0164
0165 void ClearHist(int print_option = 0);
0166
0167 void DrawTGraphErrors(std::vector<double> x_vec, std::vector<double> y_vec,
0168 std::vector<double> xE_vec, std::vector<double> yE_vec,
0169 const std::string& output_directory, std::vector<std::string> plot_name);
0170 void Draw2TGraph(std::vector<double> x1_vec, std::vector<double> y1_vec,
0171 std::vector<double> x2_vec, std::vector<double> y2_vec,
0172 const std::string& output_directory, std::vector<std::string> plot_name);
0173
0174 void TH2F_threshold(TH2F* hist, double threshold);
0175 std::vector<double> SumTH2FColumnContent(TH2F* hist_in);
0176 void Hist_1D_bkg_remove(TH1F* hist_in, double factor);
0177 void TH2F_threshold_advanced_2(TH2F* hist, double threshold);
0178
0179
0180 void TH2FSampleLineFill(TH2F* hist_in,
0181 double segmentation,
0182 std::pair<double, double>
0183 inner_clu,
0184 std::pair<double, double> outer_clu);
0185
0186 protected:
0187 std::vector<TH1*> m_v_hist{};
0188
0189
0190
0191 TH2F* N_cluster_correlation{nullptr};
0192 TH2F* N_cluster_correlation_close{nullptr};
0193 TH2F* inner_pos_xy{nullptr};
0194 TH2F* outer_pos_xy{nullptr};
0195 TH2F* inner_outer_pos_xy{nullptr};
0196
0197
0198 TH2F* DCA_distance_inner_phi{nullptr};
0199 TH2F* angle_diff_inner_phi{nullptr};
0200
0201 TH1F* angle_diff{nullptr};
0202 TH1F* angle_diff_new{nullptr};
0203 TH1F* angle_diff_new_bkg_remove{nullptr};
0204 TH1F* DCA_distance{nullptr};
0205
0206 TH2F* DCA_distance_outer_phi{nullptr};
0207 TH2F* angle_diff_outer_phi{nullptr};
0208
0209 TH2F* angle_correlation{nullptr};
0210 TH2F* angle_diff_DCA_dist{nullptr};
0211 TH2F* DCA_point{nullptr};
0212 TH2F* DCA_distance_inner_X{nullptr};
0213 TH2F* DCA_distance_inner_Y{nullptr};
0214 TH2F* DCA_distance_outer_X{nullptr};
0215 TH2F* DCA_distance_outer_Y{nullptr};
0216
0217
0218 TH2F* DCA_distance_inner_phi_peak{nullptr};
0219 TProfile* DCA_distance_inner_phi_peak_profile{nullptr};
0220 TGraph* DCA_distance_inner_phi_peak_profile_graph{nullptr};
0221
0222 TH2F* angle_diff_inner_phi_peak{nullptr};
0223 TProfile* angle_diff_inner_phi_peak_profile{nullptr};
0224 TGraph* angle_diff_inner_phi_peak_profile_graph{nullptr};
0225
0226 TH2F* DCA_distance_outer_phi_peak{nullptr};
0227 TProfile* DCA_distance_outer_phi_peak_profile{nullptr};
0228 TGraph* DCA_distance_outer_phi_peak_profile_graph{nullptr};
0229
0230 TH2F* angle_diff_outer_phi_peak{nullptr};
0231 TProfile* angle_diff_outer_phi_peak_profile{nullptr};
0232 TGraph* angle_diff_outer_phi_peak_profile_graph{nullptr};
0233
0234
0235 TH2F* angle_diff_inner_phi_peak_final{nullptr};
0236 TH2F* DCA_distance_inner_phi_peak_final{nullptr};
0237
0238 TH2F* angle_diff_outer_phi_peak_final{nullptr};
0239 TH2F* DCA_distance_outer_phi_peak_final{nullptr};
0240 TH1F* angle_diff_new_bkg_remove_final{nullptr};
0241
0242 TF1* horizontal_fit_inner{nullptr};
0243 TF1* horizontal_fit_angle_diff_inner{nullptr};
0244 TF1* horizontal_fit_outer{nullptr};
0245 TF1* horizontal_fit_angle_diff_outer{nullptr};
0246
0247 TF1* cos_fit{nullptr};
0248 TF1* gaus_fit{nullptr};
0249
0250
0251 TH2F* xy_hist{nullptr};
0252 TH2F* xy_hist_bkgrm{nullptr};
0253
0254
0255
0256 std::vector<std::pair<type_pos, type_pos>> cluster_pair_vec{};
0257
0258 double Clus_InnerPhi_Offset{0};
0259 double Clus_OuterPhi_Offset{0};
0260 double current_vtxX{0};
0261 double current_vtxY{0};
0262
0263 int zvtx_cal_require = 15;
0264
0265 std::string plot_text;
0266 long total_NClus{0};
0267
0268 TCanvas* c1{nullptr};
0269 TLatex* ltx{nullptr};
0270 TLatex* draw_text{nullptr};
0271
0272
0273 void InitHist();
0274 void InitGraph();
0275 void InitRest();
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289 };
0290
0291 #endif