Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:42

0001 #ifndef INTT_INTTZVTX_H
0002 #define INTT_INTTZVTX_H
0003 
0004 #include "InttVertexUtil.h"
0005 
0006 #include <cstdint>
0007 #include <string>
0008 #include <vector>
0009 
0010 class TCanvas;
0011 class TFile;
0012 class TF1;
0013 class TGraph;
0014 class TGraphErrors;
0015 class TH1;
0016 class TH2;
0017 class TLatex;
0018 class TLine;
0019 class TPad;
0020 class TTree;
0021 
0022 class INTTZvtx
0023 {
0024  public:
0025   struct clu_info
0026   {
0027     int column = -1;
0028     // int chip_id;
0029     double avg_chan = -9999.9;
0030     int sum_adc = -1;
0031     int sum_adc_conv = -1;
0032     int size = -1;
0033 
0034     double x = -9999.9;
0035     double y = -9999.9;
0036     double z = -9999.9;
0037     int layer = -1;
0038     double phi = -9999.9;
0039     // std::vector<double> bco_diff_vec; // note : for the multi-hit cluster, more than one hit was included. so more than one bco_diff
0040   };
0041 
0042   struct ZvtxInfo
0043   {
0044    public:
0045     double zvtx{-9999.};         // gaussian fit
0046     double zvtx_err{-1};         // gaussian fit
0047     double chi2ndf{-1};          // gaussian fit
0048     double width{-1};            // gaussian fit
0049     bool good{false};            // gaussian fit
0050     long nclus{0};               // Total_nclus
0051     unsigned int ntracklets{0};  // ngood tracklet N_comb
0052     unsigned int ngroup{0};      // ngroup in likebreak histogram
0053     double peakratio{-1};        // peak ratio in likebreak histogram
0054     double peakwidth{-1};        // peak width in likebreak histogram
0055 
0056     void clear()
0057     {
0058       zvtx = -9999.;   // gaussian fit
0059       zvtx_err = -1;   // gaussian fit
0060       chi2ndf = -1;    // gaussian fit
0061       width = -1;      // gaussian fit
0062       good = false;    // gaussian fit
0063       nclus = 0;       // Total_nclus
0064       ntracklets = 0;  // ngood tracklet N_comb
0065       ngroup = 0;      // ngroup in likebreak histogram
0066       peakratio = -1;  // peak ratio in likebreak histogram
0067       peakwidth = -1;  // peak width in likebreak histogram
0068     };
0069   };
0070 
0071  public:
0072   INTTZvtx(const std::string& runType,
0073            const std::string& outFolderDirectory,
0074            std::pair<double, double> beamOrigin,
0075            double phiDiffCut = 0.11,
0076            std::pair<double, double> DCACut = {-1, 1},
0077            int NCluCutl = 20,
0078            int NCluCut = 10000,
0079            unsigned int zvtxCal_require = 15,
0080            std::pair<double, double> zvtxQAWidth = {39.62, 65.36},
0081            bool drawEventDisplay = true,
0082            bool enableQA = true,
0083            bool printMessageOpt = true);
0084 
0085   virtual ~INTTZvtx();
0086 
0087   void Init();  // initialize all histograms and others
0088 
0089   bool ProcessEvt(int event_i,
0090                   std::vector<clu_info>& temp_sPH_inner_nocolumn_vec,
0091                   std::vector<clu_info>& temp_sPH_outer_nocolumn_vec,
0092                   std::vector<std::vector<double>>& temp_sPH_nocolumn_vec,
0093                   std::vector<std::vector<double>>& temp_sPH_nocolumn_rz_vec,
0094                   int NvtxMC,
0095                   double TrigZvtxMC,
0096                   bool PhiCheckTag,
0097                   uint64_t bco_full,
0098                   int centrality_bin);
0099 
0100   void ClearEvt();
0101   void PrintPlots();
0102   void EndRun();
0103 
0104   void EnableEventDisplay(const bool enableEvtDisp) { draw_event_display = enableEvtDisp; }
0105   void EnableQA(const bool enableQA) { m_enable_qa = enableQA; }
0106 
0107   double GetZdiffPeakMC();
0108   double GetZdiffWidthMC();
0109 
0110   std::vector<double> GetEvtZPeak();
0111   std::pair<double, double> GetBeamOrigin() { return beam_origin; }
0112   ZvtxInfo& GetZvtxInfo() { return m_zvtxinfo; }
0113   void SetBeamOrigin(double beamx, double beamy) { beam_origin = std::make_pair(beamx, beamy); }
0114   void SetPrintMessageOpt(const bool opt) { print_message_opt = opt; }
0115   void SetOutDirectory(const std::string& sOutDirectory) { out_folder_directory = sOutDirectory; }
0116 
0117  private:
0118   bool m_initialized{false};
0119 
0120   std::string run_type;
0121   std::string out_folder_directory;
0122   std::pair<double, double> beam_origin;
0123   double phi_diff_cut;                      // note : if (< phi_diff_cut)      -> pass      unit degree
0124   std::pair<double, double> DCA_cut;        // note : if (< DCA_cut)           -> pass      unit mm
0125   int N_clu_cut;                            // note : if (> N_clu_cut)         -> continue  unit number
0126   int N_clu_cutl;                           // note : if (< N_clu_cutl)        -> continue  unit number
0127   unsigned int zvtx_cal_require;            // note : if (> zvtx_cal_require)  -> pass
0128   std::pair<double, double> zvtx_QA_width;  // note : for the zvtx range Quality check, check the width
0129   bool draw_event_display{false};
0130   bool m_enable_qa{false};
0131   bool print_message_opt;
0132 
0133   std::pair<double, double> evt_possible_z_range = {-700, 700};
0134 
0135   std::vector<std::string> conversion_mode_BD = {"ideal", "survey_1_XYAlpha_Peek", "full_survey_3.32"};
0136   double Integrate_portion_final = 0.68;  // cut in effSig, PrintPlots
0137   double Integrate_portion = 0.35;        // cut in effSig, processEvt, todo : Width selection per event (the range finder for fitting)
0138   double high_multi_line = 1000;          // cut in ProcessEvt, todo : the cut to classify the high-low multiplicity, which are fit with different method
0139   double zvtx_hist_l = -500;              // histogram range for QA
0140   double zvtx_hist_r = 500;               // histogram range for QA
0141   int print_rate = 50;                    // if_print in processEvt, todo : the print rate is here
0142 
0143   std::vector<std::vector<std::pair<bool, clu_info>>> inner_clu_phi_map{};  // note: phi
0144   std::vector<std::vector<std::pair<bool, clu_info>>> outer_clu_phi_map{};  // note: phi
0145 
0146   ZvtxInfo m_zvtxinfo;
0147 
0148   TH1* evt_possible_z{nullptr};
0149   TH1* line_breakdown_hist{nullptr};  // note : try to fill the line into the histogram
0150   TF1* gaus_fit{nullptr};
0151   TF1* zvtx_finder{nullptr};
0152   TGraphErrors* z_range_gr{nullptr};  // ana // memory leak
0153 
0154   //////////////////////////////////////
0155   // for event display
0156   TH1* evt_select_track_phi{nullptr};    // ProcessEvt
0157   TH1* evt_phi_diff_1D{nullptr};         // ProcessEvt
0158   TH2* evt_phi_diff_inner_phi{nullptr};  // ProcessEvt
0159   TH2* evt_inner_outer_phi{nullptr};     // ProcessEvt
0160 
0161   // for QA
0162   TH1* avg_event_zvtx{nullptr};                  // Fill: ProcessEvt, Draw: PrintPlot
0163   TH1* zvtx_evt_fitError{nullptr};               // Fill: ProcessEvt, Draw: PrintPlot
0164   TH2* zvtx_evt_fitError_corre{nullptr};         // Fill: ProcessEvt, Draw: PrintPlot
0165   TH2* zvtx_evt_width_corre{nullptr};            // Fill: ProcessEvt, Draw: PrintPlot
0166   TH2* zvtx_evt_nclu_corre{nullptr};             // Fill: ProcessEvt, Draw: PrintPlot
0167   TH1* width_density{nullptr};                   // note : N good hits / width // Fill: ProcessEvt, Draw: PrintPlot
0168   TH1* ES_width{nullptr};                        // Fill: ProcessEvt, Draw: PrintPlot
0169   TH1* ES_width_ratio{nullptr};                  // Fill: ProcessEvt, Draw: PrintPlot
0170   TH2* Z_resolution_Nclu{nullptr};               // Fill: ProcessEvt, Draw: PrintPlot
0171   TH2* Z_resolution_pos{nullptr};                // Fill: ProcessEvt, Draw: PrintPlot
0172   TH2* Z_resolution_pos_cut{nullptr};            // Fill: ProcessEvt, Draw: PrintPlot
0173   TH1* Z_resolution{nullptr};                    // Fill: ProcessEvt, Draw: PrintPlot
0174   TH1* line_breakdown_gaus_ratio_hist{nullptr};  // note : the distribution of the entry/width of gaus fit // Fill: ProcessEvt, Draw: PrintPlot
0175   TH1* line_breakdown_gaus_width_hist{nullptr};  // note : the distribution of the gaus fit width // Fill: ProcessEvt, Draw: PrintPlot
0176   TH2* gaus_width_Nclu{nullptr};                 // Fill: ProcessEvt, Draw: PrintPlot
0177   TH2* gaus_rchi2_Nclu{nullptr};                 // Fill: ProcessEvt, Draw: PrintPlot
0178   TH2* final_fit_width{nullptr};                 // Fill: ProcessEvt, Draw: PrintPlot
0179   TH2* N_track_candidate_Nclu{nullptr};          // note : Number of tracklet candidate (In xy plane) vs number of clusters// Fill: ProcessEvt, Draw: PrintPlot
0180   TH1* peak_group_width_hist{nullptr};           // Fill: ProcessEvt, Draw: PrintPlot
0181   TH1* peak_group_ratio_hist{nullptr};           // Fill: ProcessEvt, Draw: PrintPlot
0182   TH1* N_group_hist{nullptr};                    // Fill: ProcessEvt, Draw: PrintPlot
0183   TH1* peak_group_detail_width_hist{nullptr};    // Fill: ProcessEvt, Draw: PrintPlot
0184   TH1* peak_group_detail_ratio_hist{nullptr};    // Fill: ProcessEvt, Draw: PrintPlot
0185   TH1* N_group_detail_hist{nullptr};             // Fill: ProcessEvt, Draw: PrintPlot
0186 
0187   TH2* phi_diff_inner_phi{nullptr};  // ProcessEvt
0188   TH2* dca_inner_phi{nullptr};       // ProcessEvt
0189 
0190   std::vector<TH1*> m_v_qahist{};
0191 
0192   TCanvas* c1{nullptr};  // PrintPlots
0193 
0194   TCanvas* c2{nullptr};                // processEvt
0195   TPad* pad_xy{nullptr};               // ProcessEvt
0196   TPad* pad_rz{nullptr};               // ProcessEvt
0197   TPad* pad_z{nullptr};                // ProcessEvt
0198   TPad* pad_z_hist{nullptr};           // ProcessEvt
0199   TPad* pad_z_line{nullptr};           // ProcessEvt
0200   TPad* pad_phi_diff{nullptr};         // ProcessEvt
0201   TPad* pad_track_phi{nullptr};        // ProcessEvt
0202   TPad* pad_inner_outer_phi{nullptr};  // ProcessEvt
0203   TPad* pad_phi_diff_1D{nullptr};      // ProcessEvt
0204 
0205   TLine* ladder_line{nullptr};           // tempbkg
0206   TLine* final_fit_range_line{nullptr};  // ProcessEvt
0207   TLine* coord_line{nullptr};            // ProcessEvt
0208   TLatex* draw_text{nullptr};            // ProcessEvt, PrintPlots
0209   TLine* eff_sig_range_line{nullptr};    // ProcessEvt, PrintPlots
0210 
0211   TFile* out_file{nullptr};
0212   TTree* tree_out{nullptr};
0213 
0214   // note : for tree_out
0215   double out_ES_zvtx, out_ES_zvtxE, out_ES_rangeL, out_ES_rangeR, out_ES_width_density, MC_true_zvtx;
0216   double out_LB_Gaus_Mean_mean, out_LB_Gaus_Mean_meanE, out_LB_Gaus_Mean_width, out_LB_Gaus_Mean_chi2;
0217   double out_LB_Gaus_Width_width, out_LB_Gaus_Width_size_width, out_LB_Gaus_Width_offset, out_LB_geo_mean;
0218   double out_mid_cut_peak_width, out_mid_cut_peak_ratio, out_LB_cut_peak_width, out_LB_cut_peak_ratio;
0219   bool out_good_zvtx_tag;
0220   int out_eID, N_cluster_outer_out, N_cluster_inner_out, out_ES_N_good, out_mid_cut_Ngroup, out_LB_cut_Ngroup, out_centrality_bin;
0221   int out_N_cluster_north, out_N_cluster_south;
0222   uint64_t bco_full_out;
0223 
0224   // note : for out parameters
0225   double MC_z_diff_peak, MC_z_diff_width;  // note : the comparison between Reco - true in MC. Values are from fitting foucsing on the peak region.
0226 
0227   void InitHist();
0228   void InitCanvas();
0229   void InitTreeOut();
0230   void InitRest();
0231 
0232   std::vector<float> temp_event_zvtx_info;  // effSig method
0233   std::vector<float> avg_event_zvtx_vec;    // for QA
0234   std::vector<float> Z_resolution_vec;      // for QA for MC, zvtx diff btw reso and MC
0235   std::vector<double> N_group_info;         // QA,  note : the information of groups remaining in the histogram after the strong background suppression
0236   std::vector<double> N_group_info_detail;  // good_vtx note : detail
0237 
0238   double final_zvtx{0};
0239   double tight_offset_width{0};  // tight zvertex QA & draw
0240   double tight_offset_peak{0};   // tight zvertex QA & draw
0241   double loose_offset_peak{0};   // z-vertex!
0242   double loose_offset_peakE{0};  // z-vertex error!
0243   bool good_zvtx_tag{0};
0244   double good_zvtx_tag_int{0};
0245   int good_comb_id{0};  // used for tracklet reco
0246 
0247   TGraphErrors* z_range_gr_draw{nullptr};  // draw processEvt
0248   TGraph* temp_event_xy{nullptr};          // draw processEvt
0249   TGraph* temp_event_rz{nullptr};          // draw processEvt
0250   TGraph* bkg{nullptr};                    // draw in tempbkg
0251 
0252   // note : in the event process
0253   std::vector<float> N_comb{};       // tracklet
0254   std::vector<float> N_comb_e{};     // tracklet
0255   std::vector<double> N_comb_phi{};  // tracklet
0256   std::vector<float> z_mid{};        // tracklet
0257   std::vector<float> z_range{};      // tracklet
0258 
0259   // function for analysis
0260   std::pair<double, double> Get_possible_zvtx(double rvtx, std::vector<double> p0, std::vector<double> p1);
0261   std::vector<double> find_Ngroup(TH1* hist_in);
0262   double get_radius(double x, double y);
0263   double calculateAngleBetweenVectors(double x1, double y1, double x2, double y2, double targetX, double targetY);
0264   double Get_extrapolation(double given_y, double p0x, double p0y, double p1x, double p1y);
0265   void line_breakdown(TH1* hist_in, std::pair<double, double> line_range);
0266 
0267   // tracklet reco
0268   double get_delta_phi(double angle_1, double angle_2);
0269   double get_track_phi(double inner_clu_phi_in, double delta_phi_in);
0270 
0271   // for Tree
0272   double LB_geo_mean(TH1* hist_in, std::pair<double, double> search_range, int event_i);
0273 
0274   // InitCanvas
0275   void Characterize_Pad(TPad* pad, float left = 0.15, float right = 0.1,
0276                         float top = 0.1, float bottom = 0.12,
0277                         bool set_logY = false, int setgrid_bool = 0);
0278 };
0279 
0280 #endif