Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-07 08:12:44

0001 #ifndef SEMICHIPCLUSTERING_H
0002 #define SEMICHIPCLUSTERING_H
0003 
0004 #include <iostream>
0005 #include <vector>
0006 #include <string>
0007 #include <numeric>
0008 #include <cctype> // For isdigit
0009 
0010 #include <TFile.h>
0011 #include <TTree.h>
0012 #include <TH2D.h>
0013 #include <TH1D.h>
0014 #include <TMath.h>
0015 #include <TF1.h>
0016 #include <TProfile.h>
0017 #include <TCanvas.h>
0018 #include <TPad.h>
0019 #include <TGraphErrors.h>
0020 #include <TLatex.h>
0021 #include <THStack.h>
0022 #include <TCanvas.h> // note : for the combined case
0023 #include <TGraph.h>  // note : for the combined case
0024 
0025 #include <TKey.h>
0026 #include <TRandom.h> // note : for the offset
0027 #include <TRandom3.h> // note : for the offset
0028 
0029 #include <TColor.h>
0030 
0031 #include <TObjArray.h>
0032 
0033 #include "../Constants.h"
0034 
0035 class SemiChipClustering{
0036     public:
0037         SemiChipClustering(
0038             int process_id_in, // note : 1 or 2
0039             int runnumber_in, // note : still, (54280 or -1)
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 
0047             bool BcoFullDiffCut_in,
0048             bool INTT_vtxZ_QA_in,
0049             std::pair<bool, std::string> BadChMask_in,
0050             bool ApplyHitQA_in = true,
0051             bool clone_hit_remove_BCO_tag_in = true,
0052             std::pair<bool, int> cut_HitBcoDiff_in = {true, 55},
0053             std::vector<int> adc_conversion_vec_in = {35, 45, 60, 90, 120, 150, 180, 210}
0054         );
0055 
0056         std::string GetOutputFileName() {return output_filename;}
0057         void MainProcess();
0058         void EndRun();
0059 
0060     protected:
0061         struct inttHitstr{
0062             int hit_server;
0063             int hit_felix_ch;
0064             int hit_chip;
0065             int hit_channel;
0066             int hit_adc;
0067             int hit_bco;
0068             int hit_bco_diff;
0069         };
0070 
0071         // note : ------------------------- for constructor --------------------------------
0072         int process_id;
0073         int runnumber;
0074         int run_nEvents;
0075         std::string input_directory;
0076         std::string input_file_name;
0077         std::string output_directory;
0078         std::string output_file_name_suffix;
0079 
0080         bool BcoFullDiffCut;
0081         bool INTT_vtxZ_QA;
0082         std::pair<bool, std::string> BadChMask;
0083         bool ApplyHitQA;
0084         bool clone_hit_remove_BCO_tag;
0085         std::pair<bool, int> cut_HitBcoDiff;
0086         std::vector<int> adc_conversion_vec;
0087 
0088         // note : ------------------------- for input root file --------------------------------
0089         TFile * file_in;
0090         TTree * tree_in;
0091         std::string tree_name = "EventTree";
0092         void PrepareInputRootFile();
0093         std::map<std::string, int> GetInputTreeBranchesMap(TTree * m_tree_in);
0094 
0095         // note : MBD & centrality relevant
0096         float MBD_z_vtx;
0097         bool is_min_bias;
0098         float MBD_centrality;
0099         float MBD_south_charge_sum;
0100         float MBD_north_charge_sum;
0101         float MBD_charge_sum;
0102         float MBD_charge_asymm;
0103         int InttBcoFullDiff_next;
0104 
0105         int NClus;
0106         int NClus_Layer1;
0107 
0108         // note : trigger tag
0109         int MBDNSg2;
0110         int MBDNSg2_vtxZ10cm;
0111         int MBDNSg2_vtxZ30cm;
0112         int MBDNSg2_vtxZ60cm;
0113 
0114         double INTTvtxZ;
0115         double INTTvtxZError;
0116         double NgroupTrapezoidal;
0117         double NgroupCoarse;
0118         double TrapezoidalFitWidth;
0119         double TrapezoidalFWHM;
0120 
0121         std::vector<unsigned long> *InttRawHit_bco;
0122         std::vector<unsigned int> *InttRawHit_packetid;
0123         // std::vector<unsigned int> *InttRawHit_word;
0124         std::vector<unsigned short> *InttRawHit_fee;
0125         std::vector<unsigned short> *InttRawHit_channel_id;
0126         std::vector<unsigned short> *InttRawHit_chip_id;
0127         std::vector<unsigned short> *InttRawHit_adc;
0128         std::vector<unsigned short> *InttRawHit_FPHX_BCO;
0129         // std::vector<unsigned short> *InttRawHit_full_FPHX;
0130         // std::vector<unsigned short> *InttRawHit_full_ROC;
0131         // std::vector<unsigned short> *InttRawHit_amplitude;
0132 
0133         std::vector<unsigned int> *ClusAdc;
0134         std::vector<float> *ClusPhiSize;
0135 
0136         // note : ------------------------- for analysis --------------------------------
0137         struct chip_clu_info{
0138             std::vector<double> adc_vec;
0139             std::vector<int> size_vec;
0140             std::vector<double> edge_l_vec;
0141             std::vector<double> edge_r_vec;
0142             std::vector<double> pos_vec;
0143             int largest_size;
0144         };
0145         long long evt_INTT_bco_full;
0146         std::map<std::string, inttHitstr> evt_inttHits_map;
0147         TH1D * h1D_ClusSizeCount;
0148 
0149         void EvtCleanUp();
0150         
0151         bool DoSemiChipCluster(
0152             int eID_count,
0153             int NClus_in,
0154             std::vector<unsigned long> bco_vec_in,
0155             std::vector<unsigned int> packetid_vec_in,
0156             std::vector<unsigned short> fee_vec_in,
0157             std::vector<unsigned short> channel_id_vec_in,
0158             std::vector<unsigned short> chip_id_vec_in,
0159             std::vector<unsigned short> adc_vec_in,
0160             std::vector<unsigned short> FPHX_BCO_vec_in
0161         );
0162         SemiChipClustering::chip_clu_info find_Ngroup(TH1D * hist_in);
0163         double CoM_cluster_pos(TH1D * hist_in, double edge_l, double edge_r);
0164         std::pair<double, double> GetSize2Dist(SemiChipClustering::chip_clu_info clu_info_in, int eID_count, std::string chip_string);
0165         double  vector_average (std::vector <double> input_vector);
0166         double vector_stddev (std::vector <double> input_vector);
0167 
0168         // note : -------------------------------- Hot channel branch ------------------------------
0169         void PrepareHotChannel();
0170         TFile * hot_file_in;
0171         TTree * hot_tree_in;
0172         std::string hot_tree_name = "Multiple";
0173         int IID;             
0174         int Ichannel;        
0175         int Ichip;           
0176         int Ifelix_channel;  
0177         int Ifelix_server;   
0178         int Iflag;           
0179 
0180         std::map<std::string,std::string> hot_channel_map;
0181 
0182 
0183         // note : ------------------------- for output root file --------------------------------
0184         TFile * file_out;
0185         virtual void PrepareOutPutFileName();
0186         virtual void PrepareOutPutRootFile();
0187         std::string output_filename;
0188 
0189         // note : ------------------------- for output hist --------------------------------
0190         void PrepareHists();
0191 
0192         std::map<std::string, TH1D*> h1D_chip_hit_container_map;
0193 
0194         TH1D * h1D_NSize2Clus;
0195         TH1D * h1D_NSize1Clus;
0196         TH1D * h1D_ClusSizeCount_all;
0197         
0198         TH2D * h2D_NClus_NSize2Clus;
0199         TH2D * h2D_NClus_NSize1Clus;
0200         TH2D * h2D_nInttRawHit_NSize2Clus;
0201         TH2D * h2D_nInttRawHit_NSize1Clus;
0202 
0203         TH2D * h2D_nChipHit_NSize2Clus;
0204         TH2D * h2D_nChipHit_NSize1Clus;
0205 
0206         TH2D * h2D_NSize2Clus_NSize1Clus;
0207         TH2D * h2D_NSize2Clus_LargestSize;
0208 
0209         TH2D * h2D_nChipHit_Size2DistAvg;
0210         TH2D * h2D_nChipHit_Size2DistStd;
0211         TH2D * h2D_NSize2Clus_Size2Dist;
0212         TH2D * h2D_Size2DistAvg_Size2DistStd;
0213         TH2D * h2D_Size2DistAvg_Size2DistStd_WithLargeSize;
0214 
0215         TH1D * h1D_confirm_HitBcoDiff;
0216         TH1D * h1D_confirm_HitBcoDiff_post;
0217         TH2D * h2D_confirm_NClus_MBDChargeSum;
0218 
0219         TH2D * h2D_Inclusive_Inner_Outer_NClus;
0220         TH2D * h2D_Inclusive_NClus_MBDChargeSum;
0221         TH1D * h1D_Inclusive_MBDCentrality;
0222         TH1D * h1D_Inclusive_ClusPhiSize;
0223         TH1D * h1D_Inclusive_ClusAdc;
0224 
0225         TH2D * h2D_Post_Inner_Outer_NClus;
0226         TH2D * h2D_Post_NClus_MBDChargeSum;
0227         TH1D * h1D_Post_MBDCentrality;
0228         TH1D * h1D_Post_ClusPhiSize;
0229         TH1D * h1D_Post_ClusAdc;
0230 
0231         TH2D * h2D_Killed_Inner_Outer_NClus;
0232         TH2D * h2D_Killed_NClus_MBDChargeSum;
0233         TH1D * h1D_Killed_MBDCentrality;
0234         TH1D * h1D_Killed_ClusPhiSize;
0235         TH1D * h1D_Killed_ClusAdc;
0236 
0237         // note : -------------------------------- The constant values ------------------------------
0238         const int nFelix = 8;
0239         const int Felix_offset = 3001;
0240         const int nFelix_channel = 14; 
0241         const int nChip = 26;
0242         const int nHitBco = 128;
0243 
0244         const int inner_barrel_0 = 3;
0245         const int inner_barrel_1 = 4;
0246         const int outer_barrel_0 = 5;
0247         const int outer_barrel_1 = 6;
0248 
0249         const int south_typeB_ZID = 1;
0250         const int south_typeA_ZID = 0;
0251         const int north_typeA_ZID = 2;
0252         const int north_typeB_ZID = 3;
0253 
0254         std::vector<int> typeA_sensorZID = {0,2}; // note : sensor Z ID for type A // note -> 1, 0, 2, 3 
0255 
0256         std::pair<double, double> cut_GlobalMBDvtxZ    = Constants::cut_GlobalMBDvtxZ;
0257         std::pair<double, double> cut_vtxZDiff = Constants::cut_vtxZDiff;
0258         std::pair<double, double> cut_TrapezoidalFitWidth = Constants::cut_TrapezoidalFitWidth;
0259         std::pair<double, double> cut_TrapezoidalFWHM = Constants::cut_TrapezoidalFWHM;
0260         std::pair<double, double> cut_INTTvtxZError = Constants::cut_INTTvtxZError;
0261 
0262         int cut_InttBcoFullDIff_next = Constants::cut_InttBcoFullDIff_next;
0263 
0264         std::vector<double> centrality_edges = Constants::centrality_edges;
0265         int nCentrality_bin;
0266 
0267         double CentralityFineEdge_min = -0.005;
0268         double CentralityFineEdge_max = 1.005;
0269         int nCentralityFineBin = 101;
0270 
0271         int B0L0_index = Constants::B0L0_index;
0272         int B0L1_index = Constants::B0L1_index;
0273         int B1L0_index = Constants::B1L0_index;
0274         int B1L1_index = Constants::B1L1_index;
0275         int nLadder_inner = Constants::nLadder_inner;
0276         int nLadder_outer = Constants::nLadder_outer;
0277 
0278 };
0279 
0280 #endif