File indexing completed on 2025-08-09 08:12:19
0001 #include "TrackletHistogram.h"
0002
0003 TrackletHistogram::TrackletHistogram(
0004 int process_id_in,
0005 int runnumber_in,
0006 int run_nEvents_in,
0007 std::string input_directory_in,
0008 std::string input_file_name_in,
0009 std::string output_directory_in,
0010 std::string output_file_name_suffix_in,
0011
0012 std::pair<bool, TH1D*> vtxZReweight_in,
0013 bool BcoFullDiffCut_in,
0014 bool INTT_vtxZ_QA_in,
0015 bool isWithRotate_in,
0016 std::pair<bool, std::pair<double, double>> isClusQA_in
0017 ):
0018 process_id(process_id_in),
0019 runnumber(runnumber_in),
0020 run_nEvents(run_nEvents_in),
0021 input_directory(input_directory_in),
0022 input_file_name(input_file_name_in),
0023 output_directory(output_directory_in),
0024 output_file_name_suffix(output_file_name_suffix_in),
0025
0026 vtxZReweight(vtxZReweight_in),
0027 BcoFullDiffCut(BcoFullDiffCut_in),
0028 INTT_vtxZ_QA(INTT_vtxZ_QA_in),
0029 isWithRotate(isWithRotate_in),
0030 isClusQA(isClusQA_in)
0031 {
0032 PrepareInputRootFile();
0033
0034 run_nEvents = (run_nEvents == -1) ? tree_in->GetEntries() : run_nEvents;
0035 run_nEvents = (run_nEvents > tree_in->GetEntries()) ? tree_in->GetEntries() : run_nEvents;
0036
0037
0038 tracklet_histogram_fill = new TrackletHistogramFill(
0039 process_id,
0040 runnumber,
0041 output_directory,
0042 output_file_name_suffix
0043 );
0044 tracklet_histogram_fill -> SetvtxZReweight(vtxZReweight.first);
0045
0046 if (vtxZReweight.first) {
0047 tracklet_histogram_fill -> SetVtxZReweightHist(vtxZReweight.second);
0048 }
0049
0050 tracklet_histogram_fill -> SetBcoFullDiffCut(BcoFullDiffCut);
0051 tracklet_histogram_fill -> SetINTT_vtxZ_QA(INTT_vtxZ_QA);
0052 tracklet_histogram_fill -> SetWithRotate(isWithRotate);
0053 tracklet_histogram_fill -> SetClusQA(isClusQA);
0054
0055 tracklet_histogram_fill -> PrepareOutPutFileName();
0056 tracklet_histogram_fill -> PrepareOutPutRootFile();
0057 tracklet_histogram_fill -> PrepareHistograms();
0058 }
0059
0060
0061
0062 std::map<std::string, int> TrackletHistogram::GetInputTreeBranchesMap(TTree * m_tree_in)
0063 {
0064 std::map<std::string, int> branch_map;
0065 TObjArray * branch_list = m_tree_in -> GetListOfBranches();
0066 for (int i = 0; i < branch_list -> GetEntries(); i++)
0067 {
0068 TBranch * branch = dynamic_cast<TBranch*>(branch_list->At(i));
0069 branch_map[branch -> GetName()] = 1;
0070 }
0071 return branch_map;
0072 }
0073
0074 void TrackletHistogram::PrepareInputRootFile()
0075 {
0076 file_in = TFile::Open(Form("%s/%s", input_directory.c_str(), input_file_name.c_str()));
0077 if (!file_in || file_in -> IsZombie() || file_in == nullptr) {
0078 std::cout << "Error: cannot open file: " << input_file_name << std::endl;
0079 exit(1);
0080 }
0081
0082 tree_in = (TTree*)file_in -> Get("EventTree");
0083
0084 std::map<std::string, int> branch_map = GetInputTreeBranchesMap(tree_in);
0085 if(branch_map.find("event") != branch_map.end()){tree_in -> SetBranchStatus("event",0);}
0086
0087 if(branch_map.find("ClusEta_INTTz") != branch_map.end()){tree_in -> SetBranchStatus("ClusEta_INTTz",0);}
0088 if(branch_map.find("ClusEta_MBDz") != branch_map.end()){tree_in -> SetBranchStatus("ClusEta_MBDz",0);}
0089 if(branch_map.find("ClusPhi_AvgPV") != branch_map.end()){tree_in -> SetBranchStatus("ClusPhi_AvgPV",0);}
0090 if(branch_map.find("ClusEta_TrueXYZ") != branch_map.end()){tree_in -> SetBranchStatus("ClusEta_TrueXYZ",0);}
0091 if(branch_map.find("ClusPhi_TrueXY") != branch_map.end()){tree_in -> SetBranchStatus("ClusPhi_TrueXY",0);}
0092
0093
0094 if(branch_map.find("INTT_BCO") != branch_map.end()){tree_in -> SetBranchStatus("INTT_BCO",0);}
0095 if(branch_map.find("ClusTrkrHitSetKey") != branch_map.end()){tree_in -> SetBranchStatus("ClusTrkrHitSetKey",0);}
0096 if(branch_map.find("ClusTimeBucketId") != branch_map.end()){tree_in -> SetBranchStatus("ClusTimeBucketId",0);}
0097
0098 if(branch_map.find("GL1Packet_BCO") != branch_map.end()){tree_in -> SetBranchStatus("GL1Packet_BCO",0);}
0099 if(branch_map.find("ncoll") != branch_map.end()){tree_in -> SetBranchStatus("ncoll",0);}
0100 if(branch_map.find("npart") != branch_map.end()){tree_in -> SetBranchStatus("npart",0);}
0101 if(branch_map.find("centrality_bimp") != branch_map.end()){tree_in -> SetBranchStatus("centrality_bimp",0);}
0102 if(branch_map.find("centrality_impactparam") != branch_map.end()){tree_in -> SetBranchStatus("centrality_impactparam",0);}
0103 if(branch_map.find("clk") != branch_map.end()){tree_in -> SetBranchStatus("clk",0);}
0104 if(branch_map.find("femclk") != branch_map.end()){tree_in -> SetBranchStatus("femclk",0);}
0105 if(branch_map.find("is_min_bias_wozdc") != branch_map.end()){tree_in -> SetBranchStatus("is_min_bias_wozdc",0);}
0106 if(branch_map.find("MBD_south_npmt") != branch_map.end()){tree_in -> SetBranchStatus("MBD_south_npmt",0);}
0107 if(branch_map.find("MBD_north_npmt") != branch_map.end()){tree_in -> SetBranchStatus("MBD_north_npmt",0);}
0108 if(branch_map.find("MBD_nhitsoverths_south") != branch_map.end()){tree_in -> SetBranchStatus("MBD_nhitsoverths_south",0);}
0109 if(branch_map.find("MBD_nhitsoverths_north") != branch_map.end()){tree_in -> SetBranchStatus("MBD_nhitsoverths_north",0);}
0110
0111
0112
0113 ClusX = 0;
0114 ClusY = 0;
0115 ClusZ = 0;
0116 ClusLayer = 0;
0117 ClusLadderZId = 0;
0118 ClusLadderPhiId = 0;
0119 ClusAdc = 0;
0120 ClusPhiSize = 0;
0121
0122 evt_TrackletPair_vec = 0;
0123 evt_TrackletPairRotate_vec = 0;
0124
0125 PrimaryG4P_Pt = 0;
0126 PrimaryG4P_Eta = 0;
0127 PrimaryG4P_Phi = 0;
0128 PrimaryG4P_E = 0;
0129 PrimaryG4P_PID = 0;
0130 PrimaryG4P_isChargeHadron = 0;
0131
0132 tree_in -> SetBranchAddress("MBD_z_vtx", &MBD_z_vtx);
0133 tree_in -> SetBranchAddress("is_min_bias", &is_min_bias);
0134 tree_in -> SetBranchAddress("MBD_centrality", &MBD_centrality);
0135 tree_in -> SetBranchAddress("MBD_south_charge_sum", &MBD_south_charge_sum);
0136 tree_in -> SetBranchAddress("MBD_north_charge_sum", &MBD_north_charge_sum);
0137 tree_in -> SetBranchAddress("MBD_charge_sum", &MBD_charge_sum);
0138 tree_in -> SetBranchAddress("MBD_charge_asymm", &MBD_charge_asymm);
0139 tree_in -> SetBranchAddress("InttBcoFullDiff_next", &InttBcoFullDiff_next);
0140
0141
0142 tree_in -> SetBranchAddress("MBDNSg2", &MBDNSg2);
0143 tree_in -> SetBranchAddress("MBDNSg2_vtxZ10cm", &MBDNSg2_vtxZ10cm);
0144 tree_in -> SetBranchAddress("MBDNSg2_vtxZ30cm", &MBDNSg2_vtxZ30cm);
0145 tree_in -> SetBranchAddress("MBDNSg2_vtxZ60cm", &MBDNSg2_vtxZ60cm);
0146
0147 tree_in -> SetBranchAddress("ClusX", &ClusX);
0148 tree_in -> SetBranchAddress("ClusY", &ClusY);
0149 tree_in -> SetBranchAddress("ClusZ", &ClusZ);
0150 tree_in -> SetBranchAddress("ClusLayer", &ClusLayer);
0151 tree_in -> SetBranchAddress("ClusLadderZId", &ClusLadderZId);
0152 tree_in -> SetBranchAddress("ClusLadderPhiId", &ClusLadderPhiId);
0153 tree_in -> SetBranchAddress("ClusAdc", &ClusAdc);
0154 tree_in -> SetBranchAddress("ClusPhiSize", &ClusPhiSize);
0155
0156
0157 tree_in -> SetBranchAddress("INTTvtxZ", &INTTvtxZ);
0158 tree_in -> SetBranchAddress("INTTvtxZError", &INTTvtxZError);
0159 tree_in -> SetBranchAddress("NgroupTrapezoidal", &NgroupTrapezoidal);
0160 tree_in -> SetBranchAddress("NgroupCoarse", &NgroupCoarse);
0161 tree_in -> SetBranchAddress("TrapezoidalFitWidth", &TrapezoidalFitWidth);
0162 tree_in -> SetBranchAddress("TrapezoidalFWHM", &TrapezoidalFWHM);
0163
0164
0165 tree_in -> SetBranchAddress("TrackletPair", &evt_TrackletPair_vec);
0166 tree_in -> SetBranchAddress("TrackletPairRotate", &evt_TrackletPairRotate_vec);
0167
0168
0169 if (runnumber == -1){
0170 tree_in -> SetBranchAddress("TruthPV_trig_x", &TruthPV_trig_x);
0171 tree_in -> SetBranchAddress("TruthPV_trig_y", &TruthPV_trig_y);
0172 tree_in -> SetBranchAddress("TruthPV_trig_z", &TruthPV_trig_z);
0173 tree_in -> SetBranchAddress("NTruthVtx", &NTruthVtx);
0174 tree_in -> SetBranchAddress("NPrimaryG4P", &NPrimaryG4P);
0175 tree_in -> SetBranchAddress("PrimaryG4P_Pt", &PrimaryG4P_Pt);
0176 tree_in -> SetBranchAddress("PrimaryG4P_Eta", &PrimaryG4P_Eta);
0177 tree_in -> SetBranchAddress("PrimaryG4P_Phi", &PrimaryG4P_Phi);
0178 tree_in -> SetBranchAddress("PrimaryG4P_E", &PrimaryG4P_E);
0179 tree_in -> SetBranchAddress("PrimaryG4P_PID", &PrimaryG4P_PID);
0180 tree_in -> SetBranchAddress("PrimaryG4P_isChargeHadron", &PrimaryG4P_isChargeHadron);
0181 }
0182 }
0183
0184
0185
0186 void TrackletHistogram::MainProcess()
0187 {
0188 for (int i = 0; i < run_nEvents; i++)
0189 {
0190 tree_in -> GetEntry(i);
0191
0192 if (i % 100 == 0) { std::cout << "Processing event " << i << " / " << run_nEvents << std::endl; }
0193
0194 tracklet_histogram_fill -> FillHistogram(
0195
0196 MBD_z_vtx,
0197 is_min_bias,
0198 MBD_centrality,
0199 MBD_south_charge_sum,
0200 MBD_north_charge_sum,
0201
0202
0203 InttBcoFullDiff_next,
0204
0205
0206 MBDNSg2,
0207
0208
0209
0210
0211
0212
0213
0214
0215 ClusLadderZId,
0216
0217 ClusAdc,
0218 ClusPhiSize,
0219
0220
0221 INTTvtxZ,
0222 INTTvtxZError,
0223
0224
0225 TrapezoidalFitWidth,
0226 TrapezoidalFWHM,
0227
0228
0229 evt_TrackletPair_vec,
0230 evt_TrackletPairRotate_vec,
0231
0232
0233
0234
0235 TruthPV_trig_z,
0236 NTruthVtx,
0237 NPrimaryG4P,
0238
0239 PrimaryG4P_Eta,
0240
0241
0242
0243 PrimaryG4P_isChargeHadron
0244 );
0245 }
0246 }
0247
0248 void TrackletHistogram::EndRun()
0249 {
0250 tracklet_histogram_fill -> EndRun();
0251 file_in -> Close();
0252 }
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292