3 #include "TClonesArray.h"
5 #include "TDatabasePDG.h"
6 #include "Math/PdfFuncMathCore.h"
36 if (tree_handler->
getTree() !=
nullptr) {
85 tree_handler->
getTree()->Branch(
"jet_pt",
"std::vector<float>", &
_jet_pt);
86 tree_handler->
getTree()->Branch(
"jet_eta",
"std::vector<float>", &_jet_eta);
87 tree_handler->
getTree()->Branch(
"jet_flavor",
"std::vector<int>", &_jet_flavor);
88 tree_handler->
getTree()->Branch(
"jet_nconstituents",
"std::vector<int>", &_jet_nconstituents);
89 tree_handler->
getTree()->Branch(
"jet_sip3dtag",
"std::vector<int>", &_jet_sip3dtag);
91 tree_handler->
getTree()->Branch(
"jet_ktag",
"std::vector<int>", &_jet_ktag);
92 tree_handler->
getTree()->Branch(
"jet_k1_pt",
"std::vector<float>", &_jet_k1_pt);
93 tree_handler->
getTree()->Branch(
"jet_k1_pid",
"std::vector<int>", &_jet_k1_pid);
94 tree_handler->
getTree()->Branch(
"jet_k1_sIP3D",
"std::vector<float>", &_jet_k1_sIP3D);
95 tree_handler->
getTree()->Branch(
"jet_k2_pt",
"std::vector<float>", &_jet_k2_pt);
96 tree_handler->
getTree()->Branch(
"jet_k2_pid",
"std::vector<int>", &_jet_k2_pid);
97 tree_handler->
getTree()->Branch(
"jet_k2_sIP3D",
"std::vector<float>", &_jet_k2_sIP3D);
99 tree_handler->
getTree()->Branch(
"jet_e1_pt",
"std::vector<float>", &_jet_e1_pt);
100 tree_handler->
getTree()->Branch(
"jet_e1_sIP3D",
"std::vector<float>", &_jet_e1_sIP3D);
101 tree_handler->
getTree()->Branch(
"jet_e2_pt",
"std::vector<float>", &_jet_e2_pt);
102 tree_handler->
getTree()->Branch(
"jet_e2_sIP3D",
"std::vector<float>", &_jet_e2_sIP3D);
104 tree_handler->
getTree()->Branch(
"jet_mu1_pt",
"std::vector<float>", &_jet_mu1_pt);
105 tree_handler->
getTree()->Branch(
"jet_mu1_sIP3D",
"std::vector<float>", &_jet_mu1_sIP3D);
106 tree_handler->
getTree()->Branch(
"jet_mu2_pt",
"std::vector<float>", &_jet_mu2_pt);
107 tree_handler->
getTree()->Branch(
"jet_mu2_sIP3D",
"std::vector<float>", &_jet_mu2_sIP3D);
109 tree_handler->
getTree()->Branch(
"jet_t1_sIP3D",
"std::vector<float>", &_jet_t1_sIP3D);
110 tree_handler->
getTree()->Branch(
"jet_t2_sIP3D",
"std::vector<float>", &_jet_t2_sIP3D);
111 tree_handler->
getTree()->Branch(
"jet_t3_sIP3D",
"std::vector<float>", &_jet_t3_sIP3D);
112 tree_handler->
getTree()->Branch(
"jet_t4_sIP3D",
"std::vector<float>", &_jet_t4_sIP3D);
114 tree_handler->
getTree()->Branch(
"jet_t1_pt",
"std::vector<float>", &_jet_t1_pt);
115 tree_handler->
getTree()->Branch(
"jet_t2_pt",
"std::vector<float>", &_jet_t2_pt);
116 tree_handler->
getTree()->Branch(
"jet_t3_pt",
"std::vector<float>", &_jet_t3_pt);
117 tree_handler->
getTree()->Branch(
"jet_t4_pt",
"std::vector<float>", &_jet_t4_pt);
119 tree_handler->
getTree()->Branch(
"jet_mlp_ip3dtagger",
"std::vector<float>", &_jet_mlp_ip3dtagger);
120 tree_handler->
getTree()->Branch(
"jet_mlp_ktagger",
"std::vector<float>", &_jet_mlp_ktagger);
121 tree_handler->
getTree()->Branch(
"jet_mlp_eltagger",
"std::vector<float>", &_jet_mlp_eltagger);
122 tree_handler->
getTree()->Branch(
"jet_mlp_mutagger",
"std::vector<float>", &_jet_mlp_mutagger);
125 tree_handler->
getTree()->Branch(
"jet_etag",
"std::vector<int>", &_jet_etag);
126 tree_handler->
getTree()->Branch(
"jet_mutag",
"std::vector<int>", &_jet_mutag);
127 tree_handler->
getTree()->Branch(
"jet_charge",
"std::vector<float>", &_jet_charge);
130 _jet_Ks_p = std::vector<std::vector<float> >();
140 tree_handler->
getTree()->Branch(
"jet_Ks_mass",
"std::vector<std::vector<float>>", &
_jet_Ks_mass);
141 tree_handler->
getTree()->Branch(
"jet_Ks_p",
"std::vector<std::vector<float>>", &_jet_Ks_p);
142 tree_handler->
getTree()->Branch(
"jet_Ks_flightlength",
"std::vector<std::vector<float>>", &_jet_Ks_flightlength);
143 tree_handler->
getTree()->Branch(
"jet_Ks_sumpt",
"std::vector<float>", &_jet_Ks_sumpt);
144 tree_handler->
getTree()->Branch(
"jet_K_sumpt",
"std::vector<float>", &_jet_K_sumpt);
145 tree_handler->
getTree()->Branch(
"jet_Ks_zhadron",
"std::vector<std::vector<float>>", &_jet_Ks_zhadron);
146 tree_handler->
getTree()->Branch(
"jet_K_zhadron",
"std::vector<std::vector<float>>", &_jet_K_zhadron);
147 tree_handler->
getTree()->Branch(
"jet_Ks_leading_zhadron",
"std::vector<float>", &_jet_Ks_leading_zhadron);
148 tree_handler->
getTree()->Branch(
"jet_K_leading_zhadron",
"std::vector<float>", &_jet_K_leading_zhadron);
149 tree_handler->
getTree()->Branch(
"jet_ehadoveremratio",
"std::vector<float>", &_jet_ehadoveremratio);
156 tree_handler->
getTree()->Branch(
"charmjet_eta",
"std::vector<float>", &_charmjet_eta);
169 tree_handler->
getTree()->Branch(
"jb_x", &
_jb_x,
"jb_x/F");
170 tree_handler->
getTree()->Branch(
"jb_Q2", &
_jb_Q2,
"jb_Q2/F");
183 tree_handler->
getTree()->Branch(
"pid_track_true_pid",
"std::vector<int>", &_pid_track_true_pid);
184 tree_handler->
getTree()->Branch(
"pid_track_reco_pid",
"std::vector<int>", &_pid_track_reco_pid);
185 tree_handler->
getTree()->Branch(
"pid_track_pt",
"std::vector<float>", &_pid_track_pt);
186 tree_handler->
getTree()->Branch(
"pid_track_eta",
"std::vector<float>", &_pid_track_eta);
188 tree_handler->
getTree()->Branch(
"pid_track_jet_pt",
"std::vector<float>", &_pid_track_jet_pt);
189 tree_handler->
getTree()->Branch(
"pid_track_jet_eta",
"std::vector<float>", &_pid_track_jet_eta);
201 _mpi = TDatabasePDG().GetParticle(211)->Mass();
202 _mK = TDatabasePDG().GetParticle(321)->Mass();
216 _mva_inputs_float[
"jet_eta"] = 0.0;
217 _mva_inputs_int[
"jet_flavor"] = 0;
218 _mva_inputs_float[
"met_et"] = 0.0;
221 _mva_inputs_float[
"jet_e1_pt"] = 0.0;
222 _mva_inputs_float[
"jet_e1_sIP3D"] = 0.0;
223 _mva_inputs_float[
"jet_e2_pt"] = 0.0;
224 _mva_inputs_float[
"jet_e2_sIP3D"] = 0.0;
226 _mva_inputs_float[
"jet_t1_pt"] = 0.0;
227 _mva_inputs_float[
"jet_t1_sIP3D"] = 0.0;
228 _mva_inputs_float[
"jet_t2_pt"] = 0.0;
229 _mva_inputs_float[
"jet_t2_sIP3D"] = 0.0;
230 _mva_inputs_float[
"jet_t3_pt"] = 0.0;
231 _mva_inputs_float[
"jet_t3_sIP3D"] = 0.0;
232 _mva_inputs_float[
"jet_t4_pt"] = 0.0;
233 _mva_inputs_float[
"jet_t4_sIP3D"] = 0.0;
235 _mva_inputs_float[
"jet_k1_pt"] = 0.0;
236 _mva_inputs_float[
"jet_k1_sIP3D"] = 0.0;
237 _mva_inputs_float[
"jet_k1_pid"] = 0;
238 _mva_inputs_float[
"jet_k2_pt"] = 0.0;
239 _mva_inputs_float[
"jet_k2_sIP3D"] = 0.0;
240 _mva_inputs_float[
"jet_k2_pid"] = 0;
242 _mva_inputs_float[
"jet_mu1_pt"] = 0.0;
243 _mva_inputs_float[
"jet_mu1_sIP3D"] = 0.0;
244 _mva_inputs_float[
"jet_mu2_pt"] = 0.0;
245 _mva_inputs_float[
"jet_mu2_sIP3D"] = 0.0;
248 _mva_inputs_float[
"jet_mlp_ip3dtagger"] = 0.0;
249 _mva_inputs_float[
"jet_mlp_ktagger"] = 0.0;
250 _mva_inputs_float[
"jet_mlp_eltagger"] = 0.0;
251 _mva_inputs_float[
"jet_mlp_mutagger"] = 0.0;
309 _mva_reader_ip3dtagger->BookMVA(
"CharmIP3DTagger",
"mva_taggers/TMVAClassification_CharmIP3DTagger.weights.xml");
310 _mva_reader_eltagger->BookMVA(
"CharmETagger",
"mva_taggers/TMVAClassification_CharmETagger.weights.xml");
311 _mva_reader_ktagger->BookMVA(
"CharmKTagger",
"mva_taggers/TMVAClassification_CharmKTagger.weights.xml");
312 _mva_reader_mutagger->BookMVA(
"CharmMuTagger",
"mva_taggers/TMVAClassification_CharmMuTagger.weights.xml");
313 _mva_reader_globaltagger->BookMVA(
"CharmGlobalTagger",
"mva_taggers/TMVAClassification_CharmGlobalTagger.weights.xml");
320 csvfile.open(
"cut_flow.csv");
322 csvfile <<
"Cut,Yield" << std::endl;
325 csvfile <<
"\"" << cut <<
"\"," << int(yield) << std::endl;
364 _jb_x = jb_variables[
"x_JB"];
365 _jb_Q2 = jb_variables[
"Q2_JB"];
390 MissingET *MET =
nullptr;
392 for (
int imet = 0; imet <
getMET()->GetEntries(); imet++) {
393 MET =
static_cast<MissingET *
>(
getMET()->At(imet));
396 if (MET ==
nullptr) {
402 if ((passed ==
true) && (MET->MET > 10.0)) {
472 bool use_kaons =
true;
474 bool use_electrons =
false;
476 if (DataStore->find(
"Electrons") != DataStore->end()) {
478 use_electrons =
true;
481 bool use_muons =
false;
483 if (DataStore->find(
"Muons") != DataStore->end()) {
495 std::vector<Track *> all_tracks;
499 for (
auto obj_track : *tracks)
501 auto track =
static_cast<Track *
>(obj_track);
503 if (track->PT < 0.1)
continue;
504 all_tracks.push_back(track);
527 std::vector<Candidate> Ks_candidates;
529 for (
int i = 0; i < all_tracks.size(); i++)
531 for (
int j = i + 1; j < all_tracks.size(); j++)
533 auto track1 = all_tracks[i];
534 auto track2 = all_tracks[j];
536 if (track1->Charge * track2->Charge != -1)
continue;
539 auto track1P4 = TLorentzVector();
540 track1P4.SetPtEtaPhiM(track1->PT, track1->Eta, track1->Phi,
_mpi);
541 auto track2P4 = TLorentzVector();
542 track2P4.SetPtEtaPhiM(track2->PT, track2->Eta, track2->Phi,
_mpi);
551 TLorentzVector Ks_candidate = track1P4 + track2P4;
553 if (TMath::Abs(Ks_candidate.M() - 0.497) > 0.250)
continue;
556 TVector3 track1_POCA(track1->X, track1->Y, track1->Z);
557 TVector3 track2_POCA(track2->X, track2->Y, track2->Z);
559 auto intertrack_displacement = track1_POCA - track2_POCA;
560 float intertrack_distance = intertrack_displacement.Mag();
562 float track1_d0err = track1->ErrorD0;
563 float track1_z0err = track1->ErrorDZ;
564 float track2_d0err = track2->ErrorD0;
565 float track2_z0err = track2->ErrorDZ;
567 float err_3D = TMath::Sqrt(TMath::Power(track1_d0err, 2.0) + TMath::Power(track1_z0err, 2.0) +
568 TMath::Power(track2_d0err, 2.0) + TMath::Power(track2_z0err, 2.0));
570 float intertrack_distance_signif = intertrack_distance / err_3D;
580 if (intertrack_distance_signif > 1.5)
continue;
585 Ks.Mass = Ks_candidate.M();
586 Ks.Momentum = Ks_candidate;
589 Ks.Position = TLorentzVector(track2_POCA + 0.5 * intertrack_displacement, 0.0);
591 Ks_candidates.push_back(Ks);
597 std::vector<Track *> kaon_candidates;
598 std::vector<Track> pid_candidates;
611 if ((track->Eta < -3.5) || (-1.0 < track->Eta))
continue;
613 pid_candidates.push_back(*track);
615 Int_t reco_pid = track->PID;
617 if (TMath::Abs(reco_pid) == 321) {
618 kaon_candidates.push_back(track);
627 if ((track->Eta < -1.0) || (1.0 < track->Eta))
continue;
629 pid_candidates.push_back(*track);
631 Int_t reco_pid = track->PID;
633 if (TMath::Abs(reco_pid) == 321) {
634 kaon_candidates.push_back(track);
641 for (
auto track : all_tracks) {
642 if (1.0 <= track->Eta && track->Eta <= 3.5) {
644 Double_t p_track = track->P4().Vect().Mag();
645 Double_t ag_p_threshold = 12.0;
647 if (p_track < ag_p_threshold) {
652 if (track_ag->Particle == track->Particle) {
653 final_pid = track_ag->PID;
662 if (track_cf->Particle == track->Particle) {
663 final_pid = track_cf->PID;
670 Track drich_track = *track;
671 drich_track.PID = final_pid;
672 pid_candidates.push_back(drich_track);
674 if (TMath::Abs(final_pid) == 321)
675 kaon_candidates.push_back(track);
682 for (
auto track : all_tracks) {
685 float jet_min_dR = 1e9;
686 int jet_mother_id = 0;
687 float jet_mother_pt = 0;
688 float jet_mother_eta = 1e6;
690 for (
int ijet = 0; ijet <
getJets()->GetEntries(); ijet++)
694 float this_dR = jet->P4().DeltaR(track->P4());
696 if ((this_dR < 1.0) && (this_dR < jet_min_dR)) {
697 jet_min_dR = this_dR;
698 jet_mother_id = jet->Flavor;
699 jet_mother_pt = jet->PT;
700 jet_mother_eta = jet->Eta;
708 for (
auto pid_track : pid_candidates) {
709 if ( pid_track.Particle == track->Particle ) {
710 pid_id = pid_track.PID;
737 std::vector<Jet *> all_jets;
739 for (
int ijet = 0; ijet <
getJets()->GetEntries(); ijet++)
743 all_jets.push_back(jet);
768 std::vector<Track *> jet_tracks;
770 for (
int itrk = 0; itrk <
getEFlowTracks()->GetEntries(); itrk++) {
773 if ((track->P4().DeltaR(jet->P4()) < 0.5) &&
IsTaggingTrack(track)) {
774 jet_tracks.push_back(track);
780 std::sort(jet_tracks.begin(), jet_tracks.end(), [jet](
auto& lhs,
const auto& rhs)
786 if (jet_tracks.size() > 0) {
794 if (jet_tracks.size() > 1) {
802 if (jet_tracks.size() > 2) {
810 if (jet_tracks.size() > 3) {
820 _jet_etag.push_back(
Tagged_Electron(jet, std::any_cast<std::vector<Track *> >((*DataStore)[
"Electrons"]), 3.0, 1.0, 1));
827 _jet_mutag.push_back(
Tagged_Muon(jet, std::any_cast<std::vector<Track *> >((*DataStore)[
"Muons"]), 3.0, 1.0, 1));
833 _jet_ktag.push_back(
Tagged_Kaon(jet, std::any_cast<std::vector<Track *> >(kaon_candidates), 3.0, 1.0, 1));
841 std::sort(kaon_candidates.begin(), kaon_candidates.end(), [](
auto& lhs,
const auto& rhs)
843 return lhs->PT > rhs->PT;
846 auto kaons_list = kaon_candidates;
847 auto electrons_list = std::any_cast<std::vector<Track *> >((*DataStore)[
"Electrons"]);
848 auto muons_list = std::any_cast<std::vector<Track *> >((*DataStore)[
"Muons"]);
851 if (kaons_list.size() > 0) {
852 auto k1 = kaons_list.at(0);
863 if (kaons_list.size() > 1) {
864 auto k2 = kaons_list.at(1);
876 _jet_Ks_p.push_back(std::vector<float>());
880 for (
auto Ks_candidate : Ks_candidates) {
881 if (Ks_candidate.Position.Rho() < 5)
884 if (Ks_candidate.Momentum.DeltaR(jet->P4()) < 0.5) {
885 Ks_sumpt += Ks_candidate.Momentum.Vect();
887 _jet_Ks_p[ijet].push_back(Ks_candidate.Momentum.Rho());
890 _jet_Ks_zhadron[ijet].push_back(TMath::Abs((Ks_candidate.Momentum.Vect() * jet->P4().Vect()) / jet->P4().Vect().Mag2()));
909 auto kaons = kaon_candidates;
911 for (
auto kaon : kaons) {
912 if (kaon->P4().DeltaR(jet->P4()) < 0.5) {
913 K_sumpt += kaon->P4().Vect();
914 _jet_K_zhadron[ijet].push_back(TMath::Abs((kaon->P4().Vect() * jet->P4().Vect()) / jet->P4().Vect().Mag2()));
928 if (electrons_list.size() > 0) {
929 auto e1 = electrons_list.at(0);
937 if (electrons_list.size() > 1) {
938 auto e2 = electrons_list.at(1);
947 if (muons_list.size() > 0) {
948 auto mu1 = muons_list.at(0);
956 if (muons_list.size() > 1) {
957 auto mu2 = muons_list.at(1);
1013 float jet_Q = -10.0;
1017 auto track =
static_cast<Track *
>(obj_track);
1019 if (track->P4().DeltaR(jet->P4()) < 0.5) {
1020 if (jet_Q == -10.0) {
1023 jet_Q += track->Charge * TMath::Power(track->PT, kappa);
1026 jet_Q /= TMath::Power(jet->PT, kappa);
1032 std::vector<Jet *> fiducial_jets = SelectorFcn<Jet>(all_jets, [](
Jet *j) {
1033 return TMath::Abs(j->Eta) < 3.0 && j->PT > 5.0;
1036 if ((passed ==
true) && (fiducial_jets.size() > 0)) {
1037 _cut_flow[
"3: Fiducial Jets >= 1"] += 1;
1045 std::vector<Jet *> charmJets;
1047 if (DataStore->find(
"CharmJets") != DataStore->end()) {
1048 charmJets = std::any_cast<std::vector<Jet *> >((*DataStore)[
"CharmJets"]);
1051 if ((passed ==
true) && (charmJets.size() > 0)) {
1060 for (
auto jet : charmJets) {