File indexing completed on 2025-08-06 08:14:13
0001 #include <TFile.h>
0002 #include <TH1.h>
0003 #include <TH2.h>
0004 #include <TCanvas.h>
0005 #include <TTreeReader.h>
0006 #include <TTreeReaderValue.h>
0007 #include <TTreeReaderArray.h>
0008 #include <vector>
0009 #include <iostream>
0010 #include <TDatabasePDG.h>
0011 #include <TString.h>
0012 #include <set>
0013 #include <TChain.h>
0014 #include <TGraph.h>
0015 #include <TLegend.h>
0016 #include <TMath.h>
0017
0018
0019
0020
0021 #include "JetAnalysis.h"
0022 #include <ranges>
0023
0024
0025
0026
0027
0028
0029 std::tuple<TCanvas*, TPad**, TH1D**> PrepareCanvas4Pad(UInt_t xAxisBins, Double_t *xAxis);
0030
0031 bool CheckValue(ROOT::Internal::TTreeReaderValueBase& value) {
0032 if (value.GetSetupStatus() < 0) {
0033 std::cerr << "Error " << value.GetSetupStatus()
0034 << "setting up reader for " << value.GetBranchName() << '\n';
0035 return false;
0036 }
0037 return true;
0038 }
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 bool JetAnalysis::CheckValue(ROOT::Internal::TTreeReaderValueBase& value) {
0058 if (value.GetSetupStatus() < 0) {
0059 std::cerr << "Error " << value.GetSetupStatus()
0060 << "setting up reader for " << value.GetBranchName() << '\n';
0061 return false;
0062 }
0063 return true;
0064 }
0065
0066
0067
0068 bool JetAnalysis::processCondor(const std::string &dataFiles) {
0069 TChain *tc = new TChain("AntiKt_r04/Data");
0070 tc->Add(dataFiles.data());
0071 TTreeReader reader(tc);
0072
0073 jet_container_ = new TTreeReaderValue<FullJetFinder::Container>(reader,"JetContainer");
0074 TString filename = work_dir_ + "outtree_v2.root";
0075
0076
0077
0078
0079
0080
0081 TH1D *h_reco_all = new TH1D("h_reco_all","reco_all",400,0,100);
0082 h_reco_all->GetXaxis()->SetTitle("pt_jet_reco");
0083
0084 TH1D *h_truth_all = new TH1D("h_truth_all","truth_all",400,0,100);
0085 h_truth_all->GetXaxis()->SetTitle("pt_jet^truth");
0086
0087 TH1D *h_reco_unmatch = new TH1D("h_reco_unmatch","reco_unmatch",400,0,100);
0088 h_reco_unmatch->GetXaxis()->SetTitle("pt_jet^reco");
0089
0090 TH1D *h_reco_match = new TH1D("h_reco_match","reco_match",400,0,100);
0091 h_reco_match->GetXaxis()->SetTitle("pt_jet^reco");
0092
0093 TH1D *h_truth_match = new TH1D("h_truth_match","truth_match",400,0,100);
0094 h_truth_match->GetXaxis()->SetTitle("pt_jet^truth");
0095
0096 TH1D *h_phi_all = new TH1D("h_phi_all","phi_all",800,-4,4);
0097 h_phi_all->GetXaxis()->SetTitle("phi");
0098
0099 TH1D *h_phi_match = new TH1D("h_phi_match","phi_match",800,-4,4);
0100 h_phi_match->GetXaxis()->SetTitle("phi_match");
0101
0102 TH1D *h_eta_all = new TH1D("h_eta_all","eta_all",300,-1.5,1.5);
0103 h_eta_all->GetXaxis()->SetTitle("eta");
0104
0105 TH1D *h_eta_match = new TH1D("h_eta_match","eta_match",300,-1.5,1.5);
0106 h_eta_match->GetXaxis()->SetTitle("eta_match");
0107
0108 TH1D *h_phi_truth_all = new TH1D("h_phi_truth_all","phi_truth_all",800,-4,4);
0109 h_phi_truth_all->GetXaxis()->SetTitle("phi");
0110
0111 TH1D *h_phi_truth_match = new TH1D("h_phi_truth_match","phi_truth_match",800,-4,4);
0112 h_phi_truth_match->GetXaxis()->SetTitle("phi_match");
0113
0114 TH1D *h_eta_truth_all = new TH1D("h_eta_truth_all","eta_truth_all",300,-1.5,1.5);
0115 h_eta_truth_all->GetXaxis()->SetTitle("eta");
0116
0117 TH1D *h_eta_truth_match = new TH1D("h_eta_truth_match","eta_truth_match",300,-1.5,1.5);
0118 h_eta_match->GetXaxis()->SetTitle("eta_match");
0119
0120
0121 TH1D *h_eta_track = new TH1D("h_eta_track","h_eta_track",300,-1.5,1.5);
0122 h_eta_track->GetXaxis()->SetTitle("eta_match");
0123
0124 TH1D *h_phi_track = new TH1D("h_phi_track","h_phi_track",800,-4,4);
0125 h_phi_track->GetXaxis()->SetTitle("phi");
0126
0127 TH1D *h_eta_track_match = new TH1D("h_eta_track_match","h_eta_track_match",300,-1.5,1.5);
0128 h_eta_track_match->GetXaxis()->SetTitle("eta_match");
0129
0130 TH1D *h_phi_track_match = new TH1D("h_phi_track_match","h_phi_track_match",800,-4,4);
0131 h_phi_track_match->GetXaxis()->SetTitle("phi");
0132
0133 TH2D *h_phi_pt_track = new TH2D("h_phi_pt_track","h_phi_pt_track",60,0,30,800,-4,4);
0134 TH2D *h_dca_xy = new TH2D("h_dca_xy","dca_xy",60,0,30,100,-2,2);
0135 TH2D *h_dca_xy_unc = new TH2D("dca_xy_unc","dca_xy_unc",60,0,30,100,0,0.02);
0136 TH2D *h_nmvtx = new TH2D("h_nmvtx","h_nmvtx_all",60,0,30,6,0,6);
0137 TH2D *h_nintt = new TH2D("h_nintt","h_nintt_all",60,0,30,5,0,5);
0138 TH2D *h_ntpc = new TH2D("h_ntpc","h_ntpc_all",60,0,30,50,0,50);
0139 TH2D *h_chi2ndof = new TH2D("h_chi2ndof","h_chi2ndof_all",60,0,30,80,0,20);
0140
0141 h_phi_pt_track->GetXaxis()->SetTitle("Track p_T");
0142 h_dca_xy->GetXaxis()->SetTitle("Track p_T");
0143 h_dca_xy_unc->GetXaxis()->SetTitle("Track p_T");
0144 h_nmvtx->GetXaxis()->SetTitle("Track p_T");
0145 h_nintt->GetXaxis()->SetTitle("Track p_T");
0146 h_ntpc->GetXaxis()->SetTitle("Track p_T");
0147 h_chi2ndof->GetXaxis()->SetTitle("Track p_T");
0148
0149 TH2D *h_jet_area = new TH2D("h_jet_area","h_jet_area",60,0,1.2,60,0,1.2);
0150 h_jet_area->GetXaxis()->SetTitle("area_jet_truth");
0151 h_jet_area->GetYaxis()->SetTitle("area_jet_reco");
0152
0153 int num = 5;
0154 TH1D *h_sDCA[num][3];
0155 std::string tagName[5] = {"Sdxy","1_N","2_N","3_N","4_N"};
0156 for(int i = 0; i<num;i++){
0157 TString name = "matching_"+tagName[i];
0158 h_sDCA[i][0] = new TH1D(name+"_LF",name+"_LF",100,-40,40);
0159 h_sDCA[i][1] = new TH1D(name+"_C",name+"_C",100,-40,40);
0160 h_sDCA[i][2] = new TH1D(name+"_B",name+"_B",100,-40,40);
0161 for(int j = 0; j<3;j++){
0162 h_sDCA[i][j]->GetYaxis()->SetTitle("Probability distribution");
0163 h_sDCA[i][j]->GetXaxis()->SetTitle("2D Impact Parameter significance");
0164 }
0165 }
0166
0167 TCanvas *c2 = new TCanvas("c2","c2",2400,800);
0168 c2->Divide(5,1);
0169
0170 TH1I *h_matching[4];
0171 std::string matName[4] = {"total","LF","C","B"};
0172 for(int i = 0; i<4;i++){
0173 TString name = "matching_"+matName[i];
0174 h_matching[i]= new TH1I(name,name,5,0,5);
0175 h_matching[i]->GetXaxis()->SetBinLabel(1,"Uniquely matched");
0176 h_matching[i]->GetXaxis()->SetBinLabel(2,"Unmatched R");
0177 h_matching[i]->GetXaxis()->SetBinLabel(3,"Unmatched T");
0178 h_matching[i]->GetXaxis()->SetBinLabel(4,"2T -> 1R");
0179 h_matching[i]->GetXaxis()->SetBinLabel(5,"1T -> 2R");
0180 }
0181
0182 TH1I *h_pflow[4];
0183 std::string matName2[4] = {"Uniquely_matched","Unmatched_R","2T_to_1R","1T_to_2R"};
0184 for(int i = 0; i<4;i++){
0185 TString name = "h_pflow_"+matName2[i];
0186 h_pflow[i]= new TH1I(name,name,6,-1.5,4.5);
0187 h_pflow[i]->GetXaxis()->SetBinLabel(1,"UNASSIGNED");
0188 h_pflow[i]->GetXaxis()->SetBinLabel(2,"MATCHED_CHARGED_HADRON");
0189 h_pflow[i]->GetXaxis()->SetBinLabel(3,"UNMATCHED_CHARGED_HADRON");
0190 h_pflow[i]->GetXaxis()->SetBinLabel(4,"UNMATCHED_EM_PARTICLE");
0191 h_pflow[i]->GetXaxis()->SetBinLabel(5,"UNMATCHED_NEUTRAL_HADRON");
0192 h_pflow[i]->GetXaxis()->SetBinLabel(6,"LEFTOVER_EM_PARTICLE");
0193 }
0194
0195 TCanvas *c3 = new TCanvas("c3","c3",2400,800);
0196 c3->Divide(8,1);
0197
0198 TH1I *h_primvtx[6];
0199 std::string matName3[6] = {"All","z<10cm","matched_jets_to_vtx","c-jets","b-jets","unmatched R"};
0200 for(int i = 0; i<6;i++){
0201 TString name = "h_primvtx_"+matName3[i];
0202 h_primvtx[i]= new TH1I(name,name,3,-0.5,2.5);
0203 h_primvtx[i]->GetXaxis()->SetBinLabel(1,"SVTX_MBD");
0204 h_primvtx[i]->GetXaxis()->SetBinLabel(2,"SVTX");
0205 h_primvtx[i]->GetXaxis()->SetBinLabel(3,"MBD");
0206 }
0207
0208 TH1I *h_n_vtx = new TH1I("h_n_vtx","number of primary vertices in event",5,0,5);
0209 TH1I *h_n_vtx_jet = new TH1I("h_n_vtx_jet","number of primary vertices inside jet",5,0,5);
0210
0211
0212
0213
0214
0215 int nentries = tc->GetEntries();
0216 std::cout<<"events "<<nentries<<std::endl;
0217
0218
0219
0220 TFile *file = new TFile("/sphenix/tg/tg01/hf/jkvapil/JET30_R22_npile_full/HF_matched_jets.root", "RECREATE");
0221
0222
0223 TTree *tree = new TTree("Data", "A tree with various branches");
0224
0225
0226 float id;
0227 float vertex_x, vertex_y, vertex_z;
0228 float vertex_x_unc, vertex_y_unc, vertex_z_unc;
0229 float vertex_chisq;
0230 int vertex_ndf;
0231
0232 float reco_area;
0233 int reco_num_ChConstituents;
0234 float reco_px, reco_py, reco_pz, reco_pt, reco_eta, reco_phi, reco_m, reco_e;
0235 float truth_area;
0236 int truth_num_ChConstituents;
0237 float truth_px, truth_py, truth_pz, truth_pt, truth_eta, truth_phi, truth_m, truth_e;
0238 int truth_flavour;
0239
0240
0241 std::vector<float> track_e, track_eta, track_phi, track_px, track_py, track_pz, track_pt;
0242 std::vector<int> track_charge;
0243 std::vector<float> track_DCA_xy, track_DCA_xy_unc, track_sDCA_xy, track_DCA3d, track_sDCA3d;
0244 std::vector<int> track_n_mvtx, track_n_intt, track_n_tpc;
0245 std::vector<float> track_chisq;
0246 std::vector<int> track_ndf;
0247
0248
0249 tree->Branch("vertex_x", &vertex_x, "vertex_x/F");
0250 tree->Branch("vertex_y", &vertex_y, "vertex_y/F");
0251 tree->Branch("vertex_z", &vertex_z, "vertex_z/F");
0252 tree->Branch("vertex_x_unc", &vertex_x_unc, "vertex_x_unc/F");
0253 tree->Branch("vertex_y_unc", &vertex_y_unc, "vertex_y_unc/F");
0254 tree->Branch("vertex_z_unc", &vertex_z_unc, "vertex_z_unc/F");
0255 tree->Branch("vertex_chisq", &vertex_chisq, "vertex_chisq/F");
0256 tree->Branch("vertex_ndf", &vertex_ndf, "vertex_ndf/I");
0257 tree->Branch("id", &id, "id/F");
0258 tree->Branch("reco_area", &reco_area, "reco_area/F");
0259 tree->Branch("reco_num_ChConstituents", &reco_num_ChConstituents, "reco_num_ChConstituents/I");
0260 tree->Branch("reco_px", &reco_px, "reco_px/F");
0261 tree->Branch("reco_py", &reco_py, "reco_py/F");
0262 tree->Branch("reco_pz", &reco_pz, "reco_pz/F");
0263 tree->Branch("reco_pt", &reco_pt, "reco_pt/F");
0264 tree->Branch("reco_eta", &reco_eta, "reco_eta/F");
0265 tree->Branch("reco_phi", &reco_phi, "reco_phi/F");
0266 tree->Branch("reco_m", &reco_m, "reco_m/F");
0267 tree->Branch("reco_e", &reco_e, "reco_e/F");
0268 tree->Branch("reco_sdxy_1N", &reco_sdxy_1N, "reco_sdxy_1N/F");
0269 tree->Branch("reco_sdxy_2N", &reco_sdxy_2N, "reco_sdxy_2N/F");
0270 tree->Branch("reco_sdxy_3N", &reco_sdxy_3N, "reco_sdxy_3N/F");
0271 tree->Branch("truth_area", &truth_area, "truth_area/F");
0272 tree->Branch("truth_num_ChConstituents", &truth_num_ChConstituents, "truth_num_ChConstituents/I");
0273 tree->Branch("truth_px", &truth_px, "truth_px/F");
0274 tree->Branch("truth_py", &truth_py, "truth_py/F");
0275 tree->Branch("truth_pz", &truth_pz, "truth_pz/F");
0276 tree->Branch("truth_pt", &truth_pt, "truth_pt/F");
0277 tree->Branch("truth_eta", &truth_eta, "truth_eta/F");
0278 tree->Branch("truth_phi", &truth_phi, "truth_phi/F");
0279 tree->Branch("truth_m", &truth_m, "truth_m/F");
0280 tree->Branch("truth_e", &truth_e, "truth_e/F");
0281 tree->Branch("truth_flavour", &truth_flavour, "truth_flavour/I");
0282
0283
0284
0285 tree->Branch("track_e","std::vector<float>", &track_e);
0286 tree->Branch("track_eta", &track_eta);
0287 tree->Branch("track_phi", &track_phi);
0288 tree->Branch("track_px", &track_px);
0289 tree->Branch("track_py", &track_py);
0290 tree->Branch("track_pz", &track_pz);
0291 tree->Branch("track_pt", &track_pt);
0292 tree->Branch("track_charge", &track_charge);
0293 tree->Branch("track_DCA_xy", &track_DCA_xy);
0294 tree->Branch("track_DCA_xy_unc", &track_DCA_xy_unc);
0295 tree->Branch("track_sDCA_xy", &track_sDCA_xy);
0296 tree->Branch("track_DCA3d", &track_DCA3d);
0297 tree->Branch("track_sDCA3d", &track_sDCA3d);
0298 tree->Branch("track_n_mvtx", &track_n_mvtx);
0299 tree->Branch("track_n_intt", &track_n_intt);
0300 tree->Branch("track_n_tpc", &track_n_tpc);
0301 tree->Branch("track_chisq", &track_chisq);
0302 tree->Branch("track_ndf", &track_ndf);
0303
0304
0305 while (reader.Next()) {
0306 if (!CheckValue(*jet_container_)) return false;
0307 printProgress(reader.GetCurrentEntry(),nentries);
0308
0309
0310 std::vector<int> matchedR;
0311 std::vector<int> matchedT;
0312 std::vector<int> JetIDR;
0313 std::vector<int> JetIDT;
0314
0315
0316
0317 std::map<int,int> JetIDR_map;
0318 std::map<int,int> JetIDT_map;
0319
0320
0321
0322
0323 int local_index = -1;
0324 for (auto reco_jet : (**jet_container_).recojets) {
0325 local_index++;
0326 if(reco_jet.pt < 10.0 || reco_jet.pt > 120.0) continue;
0327 if(std::abs(reco_jet.eta) > 0.7) continue;
0328 if(reco_jet.area < 3.1415*0.4*0.4*0.6) continue;
0329 JetIDR.push_back(reco_jet.id);
0330 JetIDR_map.insert(std::pair<int, int>(reco_jet.id, local_index));
0331
0332 h_reco_all->Fill(reco_jet.pt);
0333 h_eta_all->Fill(reco_jet.eta);
0334 h_phi_all->Fill(reco_jet.phi);
0335 for (auto chtrk : reco_jet.chConstituents){
0336 h_phi_track->Fill(chtrk.phi);
0337 h_eta_track->Fill(chtrk.eta);
0338 }
0339
0340
0341 }
0342
0343
0344
0345
0346 local_index = -1;
0347 for (auto truth_jet : (**jet_container_).truthjets) {
0348 local_index++;
0349 if(truth_jet.pt < 30.0 || truth_jet.pt > 120.0) continue;
0350 if(std::abs(truth_jet.eta) > 0.7) continue;
0351 if(truth_jet.area < 3.1415*0.4*0.4*0.6) continue;
0352 JetIDT.push_back(truth_jet.id);
0353 JetIDT_map.insert(std::pair<int, int>(truth_jet.id, local_index));
0354 h_truth_all->Fill(truth_jet.pt);
0355 h_eta_truth_all->Fill(truth_jet.eta);
0356 h_phi_truth_all->Fill(truth_jet.phi);
0357
0358 }
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369 std::vector<std::pair<int,int>> matchedPair;
0370 for (auto reco_jet : (**jet_container_).recojets) {
0371 if(reco_jet.pt < 10.0 || reco_jet.pt > 120.0) continue;
0372 if(std::abs(reco_jet.eta) > 0.7) continue;
0373 if(reco_jet.area < 3.1415*0.4*0.4*0.6) continue;
0374 for (auto truth_jet : (**jet_container_).truthjets) {
0375 if(truth_jet.pt < 30.0 || truth_jet.pt > 120.0) continue;
0376 if(std::abs(truth_jet.eta) > 0.7) continue;
0377 if(truth_jet.area < 3.1415*0.4*0.4*0.6) continue;
0378
0379 double etaR = reco_jet.eta;
0380 double etaT = truth_jet.eta;
0381 double phiR = reco_jet.phi;
0382 double phiT = truth_jet.phi;
0383 double dR = std::sqrt((etaR-etaT)*(etaR-etaT)+(phiR-phiT)*(phiR-phiT));
0384 if (dR > 0.3){
0385
0386 continue;
0387 }
0388 else{
0389 matchedPair.push_back(std::pair(reco_jet.id,truth_jet.id));
0390 matchedR.push_back(reco_jet.id);
0391 matchedT.push_back(truth_jet.id);
0392 }
0393 }
0394 }
0395
0396
0397 std::vector<int> unmatchedR;
0398 std::set_difference(JetIDR.begin(), JetIDR.end(), matchedR.begin(), matchedR.end(), std::inserter(unmatchedR, unmatchedR.begin()));
0399
0400 std::vector<int> unmatchedT;
0401 std::set_difference(JetIDT.begin(), JetIDT.end(), matchedT.begin(), matchedT.end(), std::inserter(unmatchedT, unmatchedT.begin()));
0402
0403
0404 std::set<int> doublymatchedR = findDuplicates(matchedR);
0405
0406 std::set<int> doublymatchedT = findDuplicates(matchedT);
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419 for(auto &id : matchedPair){
0420 if(std::find(doublymatchedR.begin(), doublymatchedR.end(),id.first) != doublymatchedR.end()) continue;
0421 if(std::find(doublymatchedT.begin(), doublymatchedT.end(),id.second) != doublymatchedT.end()) continue;
0422
0423 Flavour flavour = getFlavour((**jet_container_).truthjets.at(JetIDT_map[id.second]));
0424 h_matching[0]->Fill(0.5);
0425 if(flavour.isLF) h_matching[1]->Fill(0.5);
0426 if(flavour.isC & !flavour.isB) h_matching[2]->Fill(0.5);
0427 if(flavour.isB) h_matching[3]->Fill(0.5);
0428 h_reco_match->Fill((**jet_container_).recojets.at(JetIDR_map[id.first]).pt);
0429 h_truth_match->Fill((**jet_container_).truthjets.at(JetIDT_map[id.second]).pt);
0430 h_phi_match->Fill((**jet_container_).recojets.at(JetIDR_map[id.first]).phi);
0431 h_eta_match->Fill((**jet_container_).recojets.at(JetIDR_map[id.first]).eta);
0432 h_phi_truth_match->Fill((**jet_container_).truthjets.at(JetIDT_map[id.second]).phi);
0433 h_eta_truth_match->Fill((**jet_container_).truthjets.at(JetIDT_map[id.second]).eta);
0434 }
0435
0436 for (auto& id : unmatchedR){
0437
0438 h_matching[0]->Fill(1.5);
0439 h_reco_unmatch->Fill((**jet_container_).recojets.at(JetIDR_map[id]).pt);
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451 for(auto con : (**jet_container_).recojets.at(JetIDR_map[id]).chConstituents){
0452 h_pflow[1]->Fill(static_cast<int>(con.pflowtype));
0453 h_phi_track_match->Fill(con.phi);
0454 h_eta_track_match->Fill(con.eta);
0455 h_phi_pt_track->Fill(con.pt,con.phi);
0456 }
0457 for(auto con : (**jet_container_).recojets.at(JetIDR_map[id]).neConstituents) h_pflow[1]->Fill(static_cast<int>(con.pflowtype));
0458 }
0459
0460 for(auto& id : unmatchedT){
0461
0462 Flavour flavour = getFlavour((**jet_container_).truthjets.at(JetIDT_map[id]));
0463 h_matching[0]->Fill(2.5);
0464 if(flavour.isLF) h_matching[1]->Fill(2.5);
0465 if(flavour.isC & !flavour.isB) h_matching[2]->Fill(2.5);
0466 if(flavour.isB) h_matching[3]->Fill(2.5);
0467 }
0468
0469 for (auto &id: doublymatchedR) {
0470 for(auto id2 :matchedPair){
0471 if(id2.first == id){
0472
0473 Flavour flavour = getFlavour((**jet_container_).truthjets.at(JetIDT_map[id2.second]));
0474 h_matching[0]->Fill(3.5);
0475 if(flavour.isLF) h_matching[1]->Fill(3.5);
0476 if(flavour.isC & !flavour.isB) h_matching[2]->Fill(3.5);
0477 if(flavour.isB) h_matching[3]->Fill(3.5);
0478 }
0479 }
0480 }
0481
0482 for (auto &id: doublymatchedT) {
0483 for(auto id2 :matchedPair){
0484 if(id2.second == id){
0485
0486 Flavour flavour = getFlavour((**jet_container_).truthjets.at(JetIDT_map[id2.second]));
0487 h_matching[0]->Fill(4.5);
0488 if(flavour.isLF) h_matching[1]->Fill(4.5);
0489 if(flavour.isC & !flavour.isB) h_matching[2]->Fill(4.5);
0490 if(flavour.isB) h_matching[3]->Fill(4.5);
0491 }
0492 }
0493 }
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546 int iid = 0;
0547 for (auto truth_jet : (**jet_container_).truthjets){
0548 Flavour flavour = getFlavour(truth_jet);
0549 for (auto reco_jet : (**jet_container_).recojets){
0550
0551
0552 if (std::find(matchedPair.begin(), matchedPair.end(), std::pair(reco_jet.id,truth_jet.id)) == matchedPair.end()) continue;
0553
0554 if(std::find(doublymatchedR.begin(), doublymatchedR.end(),reco_jet.id) != doublymatchedR.end()){
0555
0556
0557 continue;
0558 }
0559
0560 if(std::find(doublymatchedT.begin(), doublymatchedT.end(),truth_jet.id) != doublymatchedT.end()){
0561
0562
0563 continue;
0564 }
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613
0614 h_jet_area->Fill(truth_jet.area, reco_jet.area);
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624 vertex_x = (**jet_container_).primaryVertex.x;
0625 vertex_y = (**jet_container_).primaryVertex.y;
0626 vertex_z = (**jet_container_).primaryVertex.z;
0627 vertex_x_unc = (**jet_container_).primaryVertex.x_unc;
0628 vertex_y_unc = (**jet_container_).primaryVertex.y_unc;
0629 vertex_z_unc = (**jet_container_).primaryVertex.z_unc;
0630 vertex_chisq = (**jet_container_).primaryVertex.chisq;
0631 vertex_ndf = (**jet_container_).primaryVertex.ndf;
0632 id = iid;
0633 iid++;
0634
0635 reco_area = reco_jet.area;
0636 reco_num_ChConstituents = reco_jet.num_ChConstituents;
0637 reco_px = reco_jet.px;
0638 reco_py = reco_jet.py;
0639 reco_pz = reco_jet.pz;
0640 reco_pt = reco_jet.pt;
0641 reco_eta = reco_jet.eta;
0642 reco_phi = reco_jet.phi;
0643 reco_m = reco_jet.m;
0644 reco_e = reco_jet.e;
0645 truth_area = truth_jet.area;
0646 truth_num_ChConstituents = truth_jet.num_ChConstituents;
0647 truth_px = truth_jet.px;
0648 truth_py = truth_jet.py;
0649 truth_pz = truth_jet.pz;
0650 truth_pt = truth_jet.pt;
0651 truth_eta = truth_jet.eta;
0652 truth_phi = truth_jet.phi;
0653 truth_m = truth_jet.m;
0654 truth_e = truth_jet.e;
0655
0656 Flavour fl = getFlavour(truth_jet);
0657 if(fl.isB) truth_flavour = 2;
0658 else if(fl.isC) truth_flavour = 1;
0659 else truth_flavour = 0;
0660
0661 track_e.clear();
0662 track_eta.clear();
0663 track_phi.clear();
0664 track_px.clear();
0665 track_py.clear();
0666 track_pz.clear();
0667 track_pt.clear();
0668 track_charge.clear();
0669 track_DCA_xy.clear();
0670 track_DCA_xy_unc.clear();
0671 track_sDCA_xy.clear();
0672 track_DCA3d.clear();
0673 track_sDCA3d.clear();
0674 track_n_mvtx.clear();
0675 track_n_intt.clear();
0676 track_n_tpc.clear();
0677 track_chisq.clear();
0678 track_ndf.clear();
0679
0680
0681
0682 std::vector<double> sDCA_cut;
0683
0684 for( auto chtrk : reco_jet.chConstituents){
0685 h_dca_xy->Fill(chtrk.pt,chtrk.DCA_xy);
0686 h_dca_xy_unc->Fill(chtrk.pt,chtrk.DCA_xy_unc);
0687 h_nmvtx->Fill(chtrk.pt,chtrk.n_mvtx);
0688 h_nintt->Fill(chtrk.pt,chtrk.n_intt);
0689 h_ntpc->Fill(chtrk.pt,chtrk.n_tpc);
0690 h_chi2ndof->Fill(chtrk.pt,chtrk.chisq/chtrk.ndf);
0691
0692
0693 track_e.push_back(chtrk.e);
0694 track_eta.push_back(chtrk.eta);
0695 track_phi.push_back(chtrk.phi);
0696 track_px.push_back(chtrk.pt * TMath::Cos(chtrk.phi));
0697 track_py.push_back(chtrk.pt * TMath::Sin(chtrk.phi));
0698 track_pz.push_back(chtrk.pt * TMath::SinH(chtrk.eta));
0699 track_pt.push_back(chtrk.pt);
0700 track_charge.push_back(chtrk.charge);
0701 track_DCA_xy.push_back(chtrk.DCA_xy);
0702 track_DCA_xy_unc.push_back(chtrk.DCA_xy_unc);
0703 track_sDCA_xy.push_back(chtrk.sDCA_xy);
0704 track_DCA3d.push_back(chtrk.DCA3d);
0705 track_sDCA3d.push_back(chtrk.sDCA3d);
0706 track_n_mvtx.push_back(chtrk.n_mvtx);
0707 track_n_intt.push_back(chtrk.n_intt);
0708 track_n_tpc.push_back(chtrk.n_tpc);
0709 track_chisq.push_back(chtrk.chisq);
0710 track_ndf.push_back(chtrk.ndf);
0711
0712 if(abs(chtrk.sDCA3d) < 40){
0713
0714 if (chtrk.n_mvtx < 3) continue;
0715 if (chtrk.n_intt < 2) continue;
0716 if (chtrk.n_tpc < 40) continue;
0717 if (chtrk.chisq/chtrk.ndf > 3.0) continue;
0718 if (chtrk.pt < 0.5) continue;
0719 if (chtrk.DCA_xy_unc > 3.0) continue;
0720
0721 sDCA_cut.push_back(chtrk.sDCA3d);
0722
0723 if (flavour.isLF) h_sDCA[0][0]->Fill(chtrk.sDCA3d);
0724 if (flavour.isC & !flavour.isB) h_sDCA[0][1]->Fill(chtrk.sDCA3d);
0725 if (flavour.isB) h_sDCA[0][2]->Fill(chtrk.sDCA3d);
0726 }
0727 }
0728
0729 reco_sdxy_1N = -999;
0730 reco_sdxy_2N = -999;
0731 reco_sdxy_3N = -999;
0732
0733
0734 std::nth_element(sDCA_cut.begin(), sDCA_cut.begin()+1, sDCA_cut.end(), std::greater<double>());
0735
0736
0737 if(sDCA_cut.size() >= 1){
0738
0739 reco_sdxy_1N = *(sDCA_cut.begin());
0740 if (flavour.isLF) h_sDCA[1][0]->Fill(*(sDCA_cut.begin()));
0741 if (flavour.isC & !flavour.isB) h_sDCA[1][1]->Fill(*(sDCA_cut.begin()));
0742 if (flavour.isB) h_sDCA[1][2]->Fill(*(sDCA_cut.begin()));
0743 }
0744
0745 if(sDCA_cut.size() >= 2){
0746 reco_sdxy_2N = *(sDCA_cut.begin()+1);
0747
0748 if (flavour.isLF) h_sDCA[1][0]->Fill(*(sDCA_cut.begin()+1));
0749 if (flavour.isC & !flavour.isB) h_sDCA[1][1]->Fill(*(sDCA_cut.begin()+1));
0750 if (flavour.isB) h_sDCA[1][2]->Fill(*(sDCA_cut.begin()+1));
0751 }
0752
0753 if(sDCA_cut.size() >= 3){
0754 reco_sdxy_3N = *(sDCA_cut.begin()+2);
0755
0756 if (flavour.isLF) h_sDCA[1][0]->Fill(*(sDCA_cut.begin()+2));
0757 if (flavour.isC & !flavour.isB) h_sDCA[1][1]->Fill(*(sDCA_cut.begin()+2));
0758 if (flavour.isB) h_sDCA[1][2]->Fill(*(sDCA_cut.begin()+2));
0759 }
0760
0761 if(sDCA_cut.size() >= 4){
0762
0763 if (flavour.isLF) h_sDCA[1][0]->Fill(*(sDCA_cut.begin()));
0764 if (flavour.isC & !flavour.isB) h_sDCA[1][1]->Fill(*(sDCA_cut.begin()+3));
0765 if (flavour.isB) h_sDCA[1][2]->Fill(*(sDCA_cut.begin()+3));
0766 }
0767
0768
0769
0770
0771
0772
0773
0774
0775
0776
0777 tree->Fill();
0778 }
0779 }
0780 }
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819
0820
0821
0822
0823
0824 TDirectory *qadir = file->mkdir("QA_histo");
0825 qadir->cd();
0826 h_reco_all->Write();
0827 h_truth_all->Write();
0828 h_reco_unmatch->Write();
0829 h_reco_match->Write();
0830 h_truth_match->Write();
0831 h_phi_all->Write();
0832 h_phi_match->Write();
0833 h_eta_all->Write();
0834 h_eta_match->Write();
0835 h_phi_truth_all->Write();
0836 h_phi_truth_match->Write();
0837 h_eta_truth_all->Write();
0838 h_eta_truth_match->Write();
0839 h_phi_track->Write();
0840 h_eta_track->Write();
0841 h_phi_track_match->Write();
0842 h_eta_track_match->Write();
0843 h_phi_pt_track->Write();
0844 h_dca_xy->Write();
0845 h_dca_xy_unc->Write();
0846 h_nmvtx->Write();
0847 h_nintt->Write();
0848 h_ntpc->Write();
0849 h_chi2ndof->Write();
0850 for(int i = 0; i<num;i++){
0851 for(int j = 0; j<3;j++){
0852 h_sDCA[i][j]->Write();
0853 }
0854 }
0855 for(int i = 0; i<4;i++){
0856 h_matching[i]->Write();
0857 }
0858 for(int i = 0; i<4;i++){
0859 h_pflow[i]->Write();
0860 }
0861 for(int i = 0; i<6;i++){
0862 h_primvtx[i]->Write();
0863 }
0864 h_n_vtx->Write();
0865 h_n_vtx_jet->Write();
0866 h_jet_area->Write();
0867
0868 file->cd();
0869 tree->Write("Data", TObject::kOverwrite);
0870 file->Close();
0871 return true;
0872 }
0873
0874 JetAnalysis::Flavour JetAnalysis::getFlavour(FullJetFinder::TruthJets truth_jet){
0875 Flavour flavour = {false, false, false};
0876 if(!(truth_jet.constituents_PDG_ID.empty())){
0877 for(auto iPDGid : truth_jet.constituents_PDG_ID){
0878 if(TString((TDatabasePDG::Instance()->GetParticle(iPDGid))->ParticleClass()) == "CharmedMeson" || TString((TDatabasePDG::Instance()->GetParticle(iPDGid))->ParticleClass()) == "CharmedBaryon"){
0879 flavour.isC = true;
0880 }
0881 else if(TString((TDatabasePDG::Instance()->GetParticle(iPDGid))->ParticleClass()) == "B-Meson" || TString((TDatabasePDG::Instance()->GetParticle(iPDGid))->ParticleClass()) == "B-Baryon"){
0882 flavour.isB = true;
0883 }
0884 }
0885 }
0886 else
0887 flavour.isLF = true;
0888
0889 return flavour;
0890 }
0891
0892 std::set<int> JetAnalysis::findDuplicates(std::vector<int> vec){
0893 std::set<int> duplicates;
0894 std::sort(vec.begin(), vec.end());
0895 std::set<int> distinct(vec.begin(), vec.end());
0896 std::set_difference(vec.begin(), vec.end(), distinct.begin(), distinct.end(),
0897 std::inserter(duplicates, duplicates.end()));
0898 return duplicates;
0899 }
0900
0901 void JetAnalysis::printProgress(int cur, int total){
0902 if((cur % (total/100))==0){
0903 float frac = float(cur)/float(total) + 0.01;
0904 int barWidth = 70;
0905 std::cout << "[";
0906 int pos = barWidth * frac;
0907 for (int i = 0; i < barWidth; ++i) {
0908 if (i < pos) std::cout << "=";
0909 else if (i == pos) std::cout << ">";
0910 else std::cout << " ";
0911 }
0912 std::cout << "] " << int(frac * 100.0) << " %\r";
0913 std::cout.flush();
0914 if(cur >= total*0.99) std::cout<<std::endl;
0915 }
0916 }
0917
0918
0919
0920
0921
0922
0923
0924
0925
0926
0927
0928
0929
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939
0940
0941
0942
0943
0944
0945
0946
0947
0948
0949
0950
0951
0952
0953
0954
0955
0956
0957
0958
0959
0960
0961
0962
0963
0964
0965
0966
0967
0968
0969
0970
0971
0972
0973
0974
0975
0976
0977
0978
0979
0980
0981
0982
0983
0984
0985
0986
0987
0988
0989
0990
0991
0992
0993
0994
0995
0996
0997
0998
0999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471 std::tuple<TCanvas*, TPad**, TH1D**> PrepareCanvas4Pad(UInt_t xAxisBins, Double_t *xAxis){
1472
1473
1474 TCanvas *FinalSpectrum = new TCanvas("FinalSpectrum3", "FinalSpectrum3",0,45,(685+3*630),630);
1475
1476
1477 FinalSpectrum->SetHighLightColor(2);
1478 FinalSpectrum->Range(0,0,1,1);
1479 FinalSpectrum->SetFillColor(0);
1480 FinalSpectrum->SetBorderMode(0);
1481 FinalSpectrum->SetBorderSize(2);
1482 FinalSpectrum->SetFrameBorderMode(0);
1483 TPad **pad = new TPad*[static_cast<ULong_t>(4)];
1484
1485
1486 Double_t marginLeft=0.05;
1487 Double_t marginRight=0.02;
1488 Double_t innerPadWidth=(1-marginLeft-marginRight)/4.;
1489 Double_t marginLeftForXAxis=0.02;
1490
1491 Double_t marginTop=0.04;
1492 Double_t marginBottom=0.14;
1493 Double_t innerPadHeight=(1-marginTop-marginBottom)/1.;
1494
1495
1496
1497 auto xbaseL = [innerPadWidth,marginLeft,marginLeftForXAxis](int m) ->Double_t {return (m*innerPadWidth+marginLeft-marginLeftForXAxis);};
1498 auto xbaseR = [innerPadWidth,marginLeft](int m) ->Double_t {return (m*innerPadWidth+marginLeft);};
1499
1500
1501
1502
1503 for(Int_t ipad = 0;ipad < 4;ipad++){
1504 std::cout<<"padID: "<<ipad<<std::endl;
1505 std::cout<<xbaseL(ipad)<<" "<<xbaseR(ipad)<<std::endl;
1506 if(ipad ==0) pad[ipad] = new TPad("pad0", "pad0",0, 0 ,xbaseR(1) ,1);
1507 if(ipad ==1) pad[ipad] = new TPad("pad1", "pad1",xbaseL(1), 0 ,xbaseR(2) ,1);
1508 if(ipad ==2) pad[ipad] = new TPad("pad2", "pad2",xbaseL(2), 0 ,xbaseR(3) ,1);
1509 if(ipad ==3) pad[ipad] = new TPad("pad3", "pad3",xbaseL(3), 0 ,1 ,1);
1510
1511 pad[ipad]->Draw();
1512 pad[ipad]->cd();
1513 pad[ipad]->SetLogy();
1514
1515
1516 if(ipad ==0){
1517 pad[ipad]->SetLeftMargin(static_cast<Float_t>(marginLeft/(marginLeft+innerPadWidth)));
1518 pad[ipad]->SetRightMargin(0);
1519 pad[ipad]->Modified();
1520 pad[ipad]->SetFillStyle(0);
1521 }
1522
1523 else if (ipad ==1 || ipad ==2){
1524 pad[ipad]->SetLeftMargin(static_cast<Float_t>(marginLeftForXAxis/(innerPadWidth+marginLeftForXAxis)));
1525 pad[ipad]->SetRightMargin(0);
1526 pad[ipad]->Modified();
1527 pad[ipad]->SetFillStyle(0);
1528 }
1529 else if (ipad ==3){
1530 pad[ipad]->SetLeftMargin(static_cast<Float_t>(marginLeftForXAxis/(innerPadWidth+marginLeftForXAxis+marginRight)));
1531 pad[ipad]->SetRightMargin(static_cast<Float_t>(marginRight/(innerPadWidth+marginRight)));
1532 pad[ipad]->Modified();
1533 pad[ipad]->SetFillStyle(0);
1534 }
1535
1536 pad[ipad]->SetBottomMargin(marginBottom/(marginBottom+innerPadHeight));
1537 pad[ipad]->SetTopMargin(marginTop/(2*innerPadHeight+marginTop));
1538
1539 pad[ipad]->SetFillStyle(0);
1540 pad[ipad]->Modified();
1541 pad[ipad]->Update();
1542 FinalSpectrum->cd();
1543 }
1544
1545
1546 TH1D **placeholder = new TH1D*[static_cast<ULong_t>(4)];
1547
1548
1549
1550 for(Int_t ipad = 0;ipad <4;ipad++){
1551 pad[ipad]->cd();
1552 placeholder[ipad] = new TH1D(Form("placeholder2%d",ipad),"Central Values",static_cast<Int_t>(xAxisBins), xAxis);
1553
1554
1555 placeholder[ipad]->SetMinimum(1E-5);
1556 placeholder[ipad]->SetMaximum(100);
1557
1558
1559
1560
1561
1562
1563
1564 TString tt = "\\mathscr{S} DCA_{xy}";
1565
1566
1567
1568 if(ipad==0)placeholder[ipad]->GetYaxis()->SetTitle("Probability");
1569 if(ipad==0)placeholder[ipad]->GetXaxis()->SetTitle("#it{S}DCA_{xy}");
1570 if(ipad==1)placeholder[ipad]->GetXaxis()->SetTitle("1^{ st} largest #it{S}DCA_{xy}");
1571 if(ipad==2)placeholder[ipad]->GetXaxis()->SetTitle("2^{nd} largest #it{S}DCA_{xy}");
1572 if(ipad==3)placeholder[ipad]->GetXaxis()->SetTitle("3^{rd} largest #it{S}DCA_{xy}");
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583 placeholder[ipad]->GetYaxis()->SetTitleOffset(1.2f);
1584 placeholder[ipad]->GetXaxis()->SetTitleOffset(1.2f);
1585 if(ipad>0){
1586 placeholder[ipad]->GetYaxis()->SetTitleSize(0);
1587 placeholder[ipad]->GetYaxis()->SetLabelSize(0);
1588 }
1589
1590 placeholder[ipad]->GetXaxis()->SetNdivisions(405);
1591 placeholder[ipad]->GetYaxis()->SetNdivisions(405);
1592
1593
1594
1595
1596
1597
1598 placeholder[ipad]->Draw();
1599 }
1600
1601 return std::make_tuple(FinalSpectrum,pad, placeholder);
1602
1603 }