Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:12:34

0001 #ifndef CLUSHISTOGRAM_H
0002 #define CLUSHISTOGRAM_H
0003 
0004 #include <iostream>
0005 #include <vector>
0006 #include <string>
0007 #include <numeric>
0008 
0009 #include <TFile.h>
0010 #include <TTree.h>
0011 #include <TH2D.h>
0012 #include <TH1D.h>
0013 #include <TMath.h>
0014 #include <TF1.h>
0015 #include <TProfile.h>
0016 #include <TCanvas.h>
0017 #include <TPad.h>
0018 #include <TGraphErrors.h>
0019 #include <TLatex.h>
0020 
0021 #include <TCanvas.h> // note : for the combined case
0022 #include <TGraph.h>  // note : for the combined case
0023 
0024 #include <TRandom.h> // note : for the offset
0025 #include <TRandom3.h> // note : for the offset
0026 
0027 #include <TColor.h>
0028 
0029 #include <TObjArray.h>
0030 
0031 #include "../EvtVtxZTracklet/structure.h"
0032 
0033 #include "../Constants.h"
0034 
0035 class ClusHistogram{
0036     public:
0037         ClusHistogram(
0038             int process_id_in,
0039             int runnumber_in,
0040             int run_nEvents_in,
0041             std::string input_directory_in,
0042             std::string input_file_name_in,
0043             std::string output_directory_in,
0044 
0045             std::string output_file_name_suffix_in,
0046             std::pair<double, double> vertexXYIncm_in,
0047 
0048             std::pair<bool, TH1D*> vtxZReweight_in,
0049             bool BcoFullDiffCut_in,
0050             bool INTT_vtxZ_QA_in,
0051             std::pair<bool, std::pair<double, double>> isClusQA_in, // note : {adc, phi size}
0052             bool HaveGeoOffsetTag_in,
0053             std::pair<bool, int> SetRandomHits_in = {false, 0},
0054             bool RandInttZ_in = false,
0055             bool ColMulMask_in = false,
0056             int c_type_in = 0
0057         );
0058 
0059         std::string GetOutputFileName() {return output_filename;}
0060         void SetGeoOffset(std::map<std::string, std::vector<double>> input_geo_offset_map) {
0061             geo_offset_map.clear();
0062             geo_offset_map = input_geo_offset_map;
0063 
0064             for (auto &pair : geo_offset_map)
0065             {
0066                 std::cout<<pair.first<<" : {"<<pair.second[0]<<", "<<pair.second[1]<<", "<<pair.second[2]<<"}"<<std::endl;
0067             }
0068         }
0069 
0070         std::string GetGoodColMapName() {return GoodColMap_name;}
0071         void SetGoodColMap(TH2D * input_h2D_GoodColMap) {
0072             h2D_GoodColMap = input_h2D_GoodColMap;
0073         }
0074 
0075         virtual void MainProcess();
0076         virtual void EndRun();
0077 
0078 
0079     protected:
0080         // note : ----------------- for the constructor -----------------
0081         int process_id;
0082         int runnumber;
0083         int run_nEvents;
0084         std::string input_directory;
0085         std::string input_file_name;
0086         std::string output_directory;
0087 
0088         std::string output_file_name_suffix;
0089         std::pair<double, double> vertexXYIncm;
0090 
0091         std::pair<bool, TH1D*> vtxZReweight;
0092         bool BcoFullDiffCut;
0093         bool INTT_vtxZ_QA;
0094         std::pair<bool, std::pair<double, double>> isClusQA; // note : {adc, phi size}
0095 
0096         bool HaveGeoOffsetTag;
0097         std::pair<bool, int> SetRandomHits;
0098         bool RandInttZ;
0099         bool ColMulMask;
0100 
0101         int c_type;
0102 
0103         // note : ----------------- for analysis -----------------
0104         struct clu_info{
0105             double x;
0106             double y;
0107             double z;
0108 
0109             int index;
0110 
0111             int adc;
0112             int phi_size;
0113             int sensorZID;
0114             int ladderPhiID;
0115             int layerID;
0116 
0117             double eta_INTTz;
0118             // double eta_MBDz;
0119             // double phi_avgXY;
0120 
0121             // double eta_TrueXYZ;
0122             // double phi_TrueXY;
0123         };
0124 
0125         void PrepareClusterVec();
0126         virtual void EvtCleanUp();
0127         std::vector<clu_info> evt_sPH_inner_nocolumn_vec;
0128         std::vector<clu_info> evt_sPH_outer_nocolumn_vec;
0129 
0130         // note : ----------------- for the root file out -----------------
0131         TFile * file_out;
0132         TTree * tree_out_par;
0133         virtual void PrepareOutPutFileName();
0134         virtual void PrepareOutPutRootFile();
0135         std::string output_filename;
0136 
0137         // note : ----------------- for the running here -----------------
0138         double CheckGeoOffsetMap();
0139         double get_clu_eta(std::vector<double> vertex, std::vector<double> clu_pos);
0140         void PrepareUniqueClusXYZ();
0141         std::map<std::string, std::vector<double>> geo_offset_map;
0142         std::map<std::string, std::tuple<double, double, double, int, int, int, int, int>> inner_UniqueClusXYZ_map; // note : X, Y, Z, sensor ID, layerID, adc, phi size, ladderPhiID
0143         std::map<std::string, std::tuple<double, double, double, int, int, int, int, int>> outer_UniqueClusXYZ_map; // note : X, Y, Z, sensor ID, layerID, adc, phi size, ladderPhiID
0144         std::vector<std::string> inner_UniqueClusXYZ_vec; 
0145         std::vector<std::string> outer_UniqueClusXYZ_vec;
0146         TH1D * h1D_RandClusZ_ref = nullptr;
0147         TH2D * h2D_RandClusXY_ref = nullptr;
0148         TRandom3 * rand3 = nullptr;
0149 
0150         // note : ----------------- for the column multiplicity mask -----------------
0151         std::string GoodColMap_name = "h2D_MulMap";
0152         TH2D * h2D_GoodColMap = nullptr;
0153         TH1D * h1D_GoodColMap_ZId;
0154         int nZbin = Constants::nZbin;
0155         double Zmin = Constants::Zmin;
0156         double Zmax = Constants::Zmax;
0157 
0158 
0159 
0160         // note : ----------------- for the histograms -----------------
0161         virtual void PrepareHistograms();
0162         TH1D * h1D_INTTvtxZ;
0163 
0164         TH1D * h1D_centrality_bin;
0165         TH1D * h1D_centrality_bin_weighted;
0166         std::map<std::string,TH1D*> h1D_centrality_map; // note : vtxZ bin
0167 
0168         std::map<std::string,TH1D*> h1D_NClusEta_map; // note : {inner, outer, typeA, all} x {Mbin x vtxZ bin}
0169         std::map<std::string, TH2D*> h2D_NClusEtaVtxZ_map; // note : {inner, outer, typeA, all} x {Mbin}
0170         TH2D * h2D_RecoEvtCount_vtxZCentrality;
0171 
0172         TH2D * h2D_InttVtxZ_Centrality;
0173 
0174 
0175         std::map<std::string,TH1D*> h1D_TrueEta_map; // note : {Mbin x vtxZ bin}
0176         std::map<std::string, TH2D*> h2D_TrueEtaVtxZ_map; // note : {Mbin}
0177         TH2D * h2D_TrueEvtCount_vtxZCentrality;
0178 
0179 
0180         TH1D * h1D_INTT_vtxZ_reweighting = nullptr;
0181 
0182         // note : ----------------- for the root file in -----------------
0183         TFile * file_in;
0184         TTree * tree_in;
0185         void PrepareInputRootFile();
0186         std::map<std::string, int> GetInputTreeBranchesMap(TTree * m_tree_in);
0187 
0188         // note : MBD & centrality relevant
0189         float MBD_z_vtx;
0190         bool is_min_bias;
0191         float MBD_centrality;
0192         float MBD_south_charge_sum;
0193         float MBD_north_charge_sum;
0194         float MBD_charge_sum;
0195         float MBD_charge_asymm;
0196         int InttBcoFullDiff_next;
0197 
0198         // note : trigger tag
0199         int MBDNSg2 = 1;
0200         int MBDNSg2_vtxZ10cm = 1;
0201         int MBDNSg2_vtxZ30cm = 1;
0202         int MBDNSg2_vtxZ60cm = 1;
0203 
0204         std::vector<float> *ClusX;
0205         std::vector<float> *ClusY;
0206         std::vector<float> *ClusZ;
0207         std::vector<int> *ClusLayer;
0208         std::vector<unsigned char> *ClusLadderZId;
0209         std::vector<unsigned char> *ClusLadderPhiId;
0210         std::vector<int> *ClusAdc;
0211         std::vector<float> *ClusPhiSize;
0212         std::vector<double> *ClusEta_INTTz;
0213 
0214         // note : INTT vertex Z
0215         double INTTvtxZ = std::nan("");
0216         double INTTvtxZError;
0217         double NgroupTrapezoidal;
0218         double NgroupCoarse;
0219         double TrapezoidalFitWidth;
0220         double TrapezoidalFWHM;
0221 
0222         // note : the tracklet pair
0223         // std::vector<pair_str> *evt_TrackletPair_vec;
0224         // std::vector<pair_str> *evt_TrackletPairRotate_vec;
0225 
0226         // note : MC
0227         float TruthPV_trig_x;
0228         float TruthPV_trig_y;
0229         float TruthPV_trig_z;
0230         int NTruthVtx;
0231         int NPrimaryG4P;
0232         std::vector<float> *PrimaryG4P_Pt;
0233         std::vector<float> *PrimaryG4P_Eta;
0234         std::vector<float> *PrimaryG4P_Phi;
0235         std::vector<float> *PrimaryG4P_E;
0236         std::vector<float> *PrimaryG4P_PID;
0237         std::vector<int> *PrimaryG4P_isChargeHadron;
0238 
0239         // note : ----------------- for constants -----------------
0240 
0241         // note : for centrality fine
0242         double CentralityFineEdge_min = -0.5;
0243         double CentralityFineEdge_max = 100.5;
0244         int nCentralityFineBin = 101;
0245         
0246         // note : for eta (tracklet)
0247         double EtaEdge_min = -2.7;
0248         double EtaEdge_max = 2.7;
0249         int nEtaBin = 27;
0250 
0251         // note : for z
0252         // double VtxZEdge_min = -45; // note : cm
0253         // double VtxZEdge_max = 45; // note : cm
0254         // int nVtxZBin = 18;
0255         double VtxZEdge_min = -20; // note : cm
0256         double VtxZEdge_max = 20; // note : cm
0257         int nVtxZBin = 8;
0258         int nVtxZBin_FineBin = 500;
0259 
0260         TH1D * h1D_vtxz_template;
0261 
0262         std::vector<int> typeA_sensorZID = {0,2}; // note : sensor Z ID for type A // note -> 1, 0, 2, 3 
0263 
0264         std::pair<double, double> cut_GlobalMBDvtxZ    = Constants::cut_GlobalMBDvtxZ;
0265         std::pair<double, double> cut_vtxZDiff = Constants::cut_vtxZDiff;
0266         std::pair<double, double> cut_TrapezoidalFitWidth = Constants::cut_TrapezoidalFitWidth;
0267         std::pair<double, double> cut_TrapezoidalFWHM = Constants::cut_TrapezoidalFWHM;
0268         std::pair<double, double> cut_INTTvtxZError = Constants::cut_INTTvtxZError;
0269 
0270         int cut_InttBcoFullDIff_next = Constants::cut_InttBcoFullDIff_next;
0271 
0272         std::vector<double> centrality_edges = Constants::centrality_edges;
0273         int nCentrality_bin;
0274 
0275         int B0L0_index = Constants::B0L0_index;
0276         int B0L1_index = Constants::B0L1_index;
0277         int B1L0_index = Constants::B1L0_index;
0278         int B1L1_index = Constants::B1L1_index;
0279         int nLadder_inner = Constants::nLadder_inner;
0280         int nLadder_outer = Constants::nLadder_outer;
0281 
0282 };
0283 
0284 #endif