Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:13:52

0001 #include <cstdlib>
0002 #include <iostream>
0003 #include <map>
0004 #include <string>
0005 #include <vector>
0006 
0007 #include "TChain.h"
0008 #include "TFile.h"
0009 #include "TTree.h"
0010 #include "TString.h"
0011 #include "TObjString.h"
0012 #include "TSystem.h"
0013 #include "TROOT.h"
0014 
0015 void D0TruthSeparator()
0016 {
0017   string inDir = "/sphenix/user/rosstom/analysis/HF-Particle/KFParticle_sPHENIX/Run40Acceptance082922/";
0018   TString truthFilePath;
0019   TString KFPFilePath;
0020 
0021   Float_t K_mass = .493677;
0022   Float_t Pi_mass = .139570;
0023    
0024   // Initialize new file for saving the separated D0/D0bar information
0025   TFile *newfile = new TFile("Run40_D0_Separated_091922.root","recreate");
0026   TTree *D0_tree = new TTree("D0_tree","D0_tree");
0027   TTree *D0bar_tree = new TTree("D0bar_tree","D0bar_tree");
0028   TTree *Background_tree = new TTree("Background_tree","Background_tree");
0029 
0030   Float_t outTrue_mother_px, outTrue_mother_py, outTrue_mother_pz, outTrue_mother_pE;
0031   Float_t outTrue_mother_pT, outTrue_mother_eta;
0032   Int_t outTrue_mother_barcode, outTrue_mother_PDG_ID;
0033   Float_t outTrue_positive_px, outTrue_positive_py, outTrue_positive_pz, outTrue_positive_pE;
0034   Float_t outTrue_negative_px, outTrue_negative_py, outTrue_negative_pz, outTrue_negative_pE;
0035   Float_t outTrue_positive_eta, outTrue_negative_eta;
0036   Int_t outTrue_positive_PDG_ID, outTrue_negative_PDG_ID;
0037   Float_t outKFP_D0_px, outKFP_D0_py, outKFP_D0_pz, outKFP_D0_pE;
0038   Float_t outKFP_D0_mass;
0039   Float_t outKFP_D0_decayTime, outKFP_D0_decayLength, outKFP_D0_DIRA, outKFP_D0_IP, outKFP_D0_IPchi2;
0040   Float_t outKFP_D0_pseudorapidity, outKFP_D0_rapidity;
0041   Float_t outKFP_positive_px, outKFP_positive_py, outKFP_positive_pz, outKFP_positive_pE;
0042   Float_t outKFP_negative_px, outKFP_negative_py, outKFP_negative_pz, outKFP_negative_pE;
0043   Float_t outKFP_positive_p, outKFP_negative_p;
0044   Float_t outKFP_positive_pseudorapidity, outKFP_negative_pseudorapidity;
0045   Int_t outKFP_positive_charge, outKFP_negative_charge;
0046   Float_t outKFP_positive_IP, outKFP_negative_IP;
0047   Float_t outKFP_positive_IPchi2, outKFP_negative_IPchi2;
0048   Float_t outKFP_track_1_track_2_DCA;
0049   Float_t outKFP_KpPm_invm, outKFP_KmPp_invm;
0050 
0051   D0_tree->Branch("outTrue_mother_px", &outTrue_mother_px,"outTrue_mother_px/F");
0052   D0_tree->Branch("outTrue_mother_py", &outTrue_mother_py,"outTrue_mother_py/F");
0053   D0_tree->Branch("outTrue_mother_pz", &outTrue_mother_pz,"outTrue_mother_pz/F");
0054   D0_tree->Branch("outTrue_mother_pE", &outTrue_mother_pE,"outTrue_mother_pE/F");
0055   D0_tree->Branch("outTrue_mother_pT", &outTrue_mother_pT,"outTrue_mother_pT/F");
0056   D0_tree->Branch("outTrue_mother_eta", &outTrue_mother_eta,"outTrue_mother_eta/F");
0057   D0_tree->Branch("outTrue_mother_barcode", &outTrue_mother_barcode,"outTrue_mother_barcode/I");
0058   D0_tree->Branch("outTrue_mother_PDG_ID", &outTrue_mother_PDG_ID,"outTrue_mother_PDG_ID/I");
0059   D0_tree->Branch("outTrue_positive_px", &outTrue_positive_px,"outTrue_positive_px/F");
0060   D0_tree->Branch("outTrue_positive_py", &outTrue_positive_py,"outTrue_positive_py/F");
0061   D0_tree->Branch("outTrue_positive_pz", &outTrue_positive_pz,"outTrue_positive_pz/F");
0062   D0_tree->Branch("outTrue_positive_pE", &outTrue_positive_pE,"outTrue_positive_pE/F");
0063   D0_tree->Branch("outTrue_negative_px", &outTrue_negative_px,"outTrue_negative_px/F");
0064   D0_tree->Branch("outTrue_negative_py", &outTrue_negative_py,"outTrue_negative_py/F");
0065   D0_tree->Branch("outTrue_negative_pz", &outTrue_negative_pz,"outTrue_negative_pz/F");
0066   D0_tree->Branch("outTrue_negative_pE", &outTrue_negative_pE,"outTrue_negative_pE/F");
0067   D0_tree->Branch("outTrue_positive_eta", &outTrue_positive_eta,"outTrue_positive_eta/F");
0068   D0_tree->Branch("outTrue_negative_eta", &outTrue_negative_eta,"outTrue_negative_eta/F");
0069   D0_tree->Branch("outTrue_positive_PDG_ID", &outTrue_positive_PDG_ID,"outTrue_positive_PDG_ID/I");
0070   D0_tree->Branch("outTrue_negative_PDG_ID", &outTrue_negative_PDG_ID,"outTrue_negative_PDG_ID/I"); 
0071   D0_tree->Branch("outKFP_D0_px", &outKFP_D0_px,"outKFP_D0_px/F");
0072   D0_tree->Branch("outKFP_D0_py", &outKFP_D0_py,"outKFP_D0_py/F");
0073   D0_tree->Branch("outKFP_D0_pz", &outKFP_D0_pz,"outKFP_D0_pz/F");
0074   D0_tree->Branch("outKFP_D0_pE", &outKFP_D0_pE,"outKFP_D0_pE/F");
0075   D0_tree->Branch("outKFP_D0_mass", &outKFP_D0_mass,"outKFP_D0_mass/F");
0076   D0_tree->Branch("outKFP_D0_decayTime", &outKFP_D0_decayTime,"outKFP_D0_decayTime/F");
0077   D0_tree->Branch("outKFP_D0_decayLength", &outKFP_D0_decayLength,"outKFP_D0_decayLength/F");
0078   D0_tree->Branch("outKFP_D0_DIRA", &outKFP_D0_DIRA,"outKFP_D0_DIRA/F");
0079   D0_tree->Branch("outKFP_D0_IP", &outKFP_D0_IP,"outKFP_D0_IP/F");
0080   D0_tree->Branch("outKFP_D0_IPchi2", &outKFP_D0_IPchi2,"outKFP_D0_IPchi2/F");
0081   D0_tree->Branch("outKFP_D0_pseudorapidity", &outKFP_D0_pseudorapidity,"outKFP_D0_pseudorapidity/F");
0082   D0_tree->Branch("outKFP_D0_rapidity", &outKFP_D0_rapidity,"outKFP_D0_rapidity/F");
0083   D0_tree->Branch("outKFP_positive_px", &outKFP_positive_px,"outKFP_positive_px/F");
0084   D0_tree->Branch("outKFP_positive_py", &outKFP_positive_py,"outKFP_positive_py/F");
0085   D0_tree->Branch("outKFP_positive_pz", &outKFP_positive_pz,"outKFP_positive_pz/F");
0086   D0_tree->Branch("outKFP_positive_pE", &outKFP_positive_pE,"outKFP_positive_pE/F");
0087   D0_tree->Branch("outKFP_negative_px", &outKFP_negative_px,"outKFP_negative_px/F");
0088   D0_tree->Branch("outKFP_negative_py", &outKFP_negative_py,"outKFP_negative_py/F");
0089   D0_tree->Branch("outKFP_negative_pz", &outKFP_negative_pz,"outKFP_negative_pz/F");
0090   D0_tree->Branch("outKFP_negative_pE", &outKFP_negative_pE,"outKFP_negative_pE/F");
0091   D0_tree->Branch("outKFP_positive_p", &outKFP_positive_p,"outKFP_positive_p/F");
0092   D0_tree->Branch("outKFP_negative_p", &outKFP_negative_p,"outKFP_negative_p/F");
0093   D0_tree->Branch("outKFP_positive_pseudorapidity", &outKFP_positive_pseudorapidity,"outKFP_positive_pseudorapidity/F");
0094   D0_tree->Branch("outKFP_negative_pseudorapidity", &outKFP_negative_pseudorapidity,"outKFP_negative_pseudorapidity/F");
0095   D0_tree->Branch("outKFP_positive_charge", &outKFP_positive_charge,"outKFP_positive_charge/I");
0096   D0_tree->Branch("outKFP_negative_charge", &outKFP_negative_charge,"outKFP_negative_charge/I");
0097   D0_tree->Branch("outKFP_positive_IP", &outKFP_positive_IP,"outKFP_positive_IP/F");
0098   D0_tree->Branch("outKFP_negative_IP", &outKFP_negative_IP,"outKFP_negative_IP/F");
0099   D0_tree->Branch("outKFP_positive_IPchi2", &outKFP_positive_IPchi2,"outKFP_positive_IPchi2/F");
0100   D0_tree->Branch("outKFP_negative_IPchi2", &outKFP_negative_IPchi2,"outKFP_negative_IPchi2/F");
0101   D0_tree->Branch("outKFP_track_1_track_2_DCA", &outKFP_track_1_track_2_DCA,"outKFP_track_1_track_2_DCA/F");
0102   D0_tree->Branch("outKFP_KpPm_invm", &outKFP_KpPm_invm,"outKFP_KpPm_invm/F");
0103   D0_tree->Branch("outKFP_KmPp_invm", &outKFP_KmPp_invm,"outKFP_KmPp_invm/F");
0104  
0105   D0bar_tree->Branch("outTrue_mother_px", &outTrue_mother_px,"outTrue_mother_px/F");
0106   D0bar_tree->Branch("outTrue_mother_py", &outTrue_mother_py,"outTrue_mother_py/F");
0107   D0bar_tree->Branch("outTrue_mother_pz", &outTrue_mother_pz,"outTrue_mother_pz/F");
0108   D0bar_tree->Branch("outTrue_mother_pE", &outTrue_mother_pE,"outTrue_mother_pE/F");
0109   D0bar_tree->Branch("outTrue_mother_pT", &outTrue_mother_pT,"outTrue_mother_pT/F");
0110   D0bar_tree->Branch("outTrue_mother_eta", &outTrue_mother_eta,"outTrue_mother_eta/F");
0111   D0bar_tree->Branch("outTrue_mother_barcode", &outTrue_mother_barcode,"outTrue_mother_barcode/I");
0112   D0bar_tree->Branch("outTrue_mother_PDG_ID", &outTrue_mother_PDG_ID,"outTrue_mother_PDG_ID/I");
0113   D0bar_tree->Branch("outTrue_positive_px", &outTrue_positive_px,"outTrue_positive_px/F");
0114   D0bar_tree->Branch("outTrue_positive_py", &outTrue_positive_py,"outTrue_positive_py/F");
0115   D0bar_tree->Branch("outTrue_positive_pz", &outTrue_positive_pz,"outTrue_positive_pz/F");
0116   D0bar_tree->Branch("outTrue_positive_pE", &outTrue_positive_pE,"outTrue_positive_pE/F");
0117   D0bar_tree->Branch("outTrue_negative_px", &outTrue_negative_px,"outTrue_negative_px/F");
0118   D0bar_tree->Branch("outTrue_negative_py", &outTrue_negative_py,"outTrue_negative_py/F");
0119   D0bar_tree->Branch("outTrue_negative_pz", &outTrue_negative_pz,"outTrue_negative_pz/F");
0120   D0bar_tree->Branch("outTrue_negative_pE", &outTrue_negative_pE,"outTrue_negative_pE/F");
0121   D0bar_tree->Branch("outTrue_positive_eta", &outTrue_positive_eta,"outTrue_positive_eta/F");
0122   D0bar_tree->Branch("outTrue_negative_eta", &outTrue_negative_eta,"outTrue_negative_eta/F");
0123   D0bar_tree->Branch("outTrue_positive_PDG_ID", &outTrue_positive_PDG_ID,"outTrue_positive_PDG_ID/I");
0124   D0bar_tree->Branch("outTrue_negative_PDG_ID", &outTrue_negative_PDG_ID,"outTrue_negative_PDG_ID/I"); 
0125   D0bar_tree->Branch("outKFP_D0_px", &outKFP_D0_px,"outKFP_D0_px/F");
0126   D0bar_tree->Branch("outKFP_D0_py", &outKFP_D0_py,"outKFP_D0_py/F");
0127   D0bar_tree->Branch("outKFP_D0_pz", &outKFP_D0_pz,"outKFP_D0_pz/F");
0128   D0bar_tree->Branch("outKFP_D0_pE", &outKFP_D0_pE,"outKFP_D0_pE/F");
0129   D0bar_tree->Branch("outKFP_D0_mass", &outKFP_D0_mass,"outKFP_D0_mass/F");
0130   D0bar_tree->Branch("outKFP_D0_decayTime", &outKFP_D0_decayTime,"outKFP_D0_decayTime/F");
0131   D0bar_tree->Branch("outKFP_D0_decayLength", &outKFP_D0_decayLength,"outKFP_D0_decayLength/F");
0132   D0bar_tree->Branch("outKFP_D0_DIRA", &outKFP_D0_DIRA,"outKFP_D0_DIRA/F");
0133   D0bar_tree->Branch("outKFP_D0_IP", &outKFP_D0_IP,"outKFP_D0_IP/F");
0134   D0bar_tree->Branch("outKFP_D0_IPchi2", &outKFP_D0_IPchi2,"outKFP_D0_IPchi2/F");
0135   D0bar_tree->Branch("outKFP_D0_pseudorapidity", &outKFP_D0_pseudorapidity,"outKFP_D0_pseudorapidity/F");
0136   D0bar_tree->Branch("outKFP_D0_rapidity", &outKFP_D0_rapidity,"outKFP_D0_rapidity/F");
0137   D0bar_tree->Branch("outKFP_positive_px", &outKFP_positive_px,"outKFP_positive_px/F");
0138   D0bar_tree->Branch("outKFP_positive_py", &outKFP_positive_py,"outKFP_positive_py/F");
0139   D0bar_tree->Branch("outKFP_positive_pz", &outKFP_positive_pz,"outKFP_positive_pz/F");
0140   D0bar_tree->Branch("outKFP_positive_pE", &outKFP_positive_pE,"outKFP_positive_pE/F");
0141   D0bar_tree->Branch("outKFP_negative_px", &outKFP_negative_px,"outKFP_negative_px/F");
0142   D0bar_tree->Branch("outKFP_negative_py", &outKFP_negative_py,"outKFP_negative_py/F");
0143   D0bar_tree->Branch("outKFP_negative_pz", &outKFP_negative_pz,"outKFP_negative_pz/F");
0144   D0bar_tree->Branch("outKFP_negative_pE", &outKFP_negative_pE,"outKFP_negative_pE/F");
0145   D0bar_tree->Branch("outKFP_positive_p", &outKFP_positive_p,"outKFP_positive_p/F");
0146   D0bar_tree->Branch("outKFP_negative_p", &outKFP_negative_p,"outKFP_negative_p/F");
0147   D0bar_tree->Branch("outKFP_positive_pseudorapidity", &outKFP_positive_pseudorapidity,"outKFP_positive_pseudorapidity/F");
0148   D0bar_tree->Branch("outKFP_negative_pseudorapidity", &outKFP_negative_pseudorapidity,"outKFP_negative_pseudorapidity/F");
0149   D0bar_tree->Branch("outKFP_positive_charge", &outKFP_positive_charge,"outKFP_positive_charge/I");
0150   D0bar_tree->Branch("outKFP_negative_charge", &outKFP_negative_charge,"outKFP_negative_charge/I");
0151   D0bar_tree->Branch("outKFP_positive_IP", &outKFP_positive_IP,"outKFP_positive_IP/F");
0152   D0bar_tree->Branch("outKFP_negative_IP", &outKFP_negative_IP,"outKFP_negative_IP/F");
0153   D0bar_tree->Branch("outKFP_positive_IPchi2", &outKFP_positive_IPchi2,"outKFP_positive_IPchi2/F");
0154   D0bar_tree->Branch("outKFP_negative_IPchi2", &outKFP_negative_IPchi2,"outKFP_negative_IPchi2/F");
0155   D0bar_tree->Branch("outKFP_track_1_track_2_DCA", &outKFP_track_1_track_2_DCA,"outKFP_track_1_track_2_DCA/F");
0156   D0bar_tree->Branch("outKFP_KpPm_invm", &outKFP_KpPm_invm,"outKFP_KpPm_invm/F");
0157   D0bar_tree->Branch("outKFP_KmPp_invm", &outKFP_KmPp_invm,"outKFP_KmPp_invm/F");
0158   
0159   //Background_tree->Branch("outTrue_mother_px", &outTrue_mother_px,"outTrue_mother_px/F");
0160   //Background_tree->Branch("outTrue_mother_py", &outTrue_mother_py,"outTrue_mother_py/F");
0161   //Background_tree->Branch("outTrue_mother_pz", &outTrue_mother_pz,"outTrue_mother_pz/F");
0162   //Background_tree->Branch("outTrue_mother_pE", &outTrue_mother_pE,"outTrue_mother_pE/F");
0163   //Background_tree->Branch("outTrue_mother_pT", &outTrue_mother_pT,"outTrue_mother_pT/F");
0164   //Background_tree->Branch("outTrue_mother_eta", &outTrue_mother_eta,"outTrue_mother_eta/F");
0165   //Background_tree->Branch("outTrue_mother_barcode", &outTrue_mother_barcode,"outTrue_mother_barcode/I");
0166   //Background_tree->Branch("outTrue_track_1_px", &outTrue_track_1_px,"outTrue_track_1_px/F");
0167   //Background_tree->Branch("outTrue_track_1_py", &outTrue_track_1_py,"outTrue_track_1_py/F");
0168   //Background_tree->Branch("outTrue_track_1_pz", &outTrue_track_1_pz,"outTrue_track_1_pz/F");
0169   //Background_tree->Branch("outTrue_track_1_pE", &outTrue_track_1_pE,"outTrue_track_1_pE/F");
0170   //Background_tree->Branch("outTrue_track_2_px", &outTrue_track_2_px,"outTrue_track_2_px/F");
0171   //Background_tree->Branch("outTrue_track_2_py", &outTrue_track_2_py,"outTrue_track_2_py/F");
0172   //Background_tree->Branch("outTrue_track_2_pz", &outTrue_track_2_pz,"outTrue_track_2_pz/F");
0173   //Background_tree->Branch("outTrue_track_2_pE", &outTrue_track_2_pE,"outTrue_track_2_pE/F");
0174   //Background_tree->Branch("outTrue_track_1_eta", &outTrue_track_1_eta,"outTrue_track_1_eta/F");
0175   //Background_tree->Branch("outTrue_track_2_eta", &outTrue_track_2_eta,"outTrue_track_2_eta/F");
0176   //Background_tree->Branch("outTrue_track_1_PDG_ID", &outTrue_track_1_PDG_ID,"outTrue_track_1_PDG_ID/I");
0177   //Background_tree->Branch("outTrue_track_2_PDG_ID", &outTrue_track_2_PDG_ID,"outTrue_track_2_PDG_ID/I"); 
0178   Background_tree->Branch("outKFP_D0_px", &outKFP_D0_px,"outKFP_D0_px/F");
0179   Background_tree->Branch("outKFP_D0_py", &outKFP_D0_py,"outKFP_D0_py/F");
0180   Background_tree->Branch("outKFP_D0_pz", &outKFP_D0_pz,"outKFP_D0_pz/F");
0181   Background_tree->Branch("outKFP_D0_pE", &outKFP_D0_pE,"outKFP_D0_pE/F");
0182   Background_tree->Branch("outKFP_D0_mass", &outKFP_D0_mass,"outKFP_D0_mass/F");
0183   Background_tree->Branch("outKFP_D0_decayTime", &outKFP_D0_decayTime,"outKFP_D0_decayTime/F");
0184   Background_tree->Branch("outKFP_D0_decayLength", &outKFP_D0_decayLength,"outKFP_D0_decayLength/F");
0185   Background_tree->Branch("outKFP_D0_DIRA", &outKFP_D0_DIRA,"outKFP_D0_DIRA/F");
0186   Background_tree->Branch("outKFP_D0_IP", &outKFP_D0_IP,"outKFP_D0_IP/F");
0187   Background_tree->Branch("outKFP_D0_IPchi2", &outKFP_D0_IPchi2,"outKFP_D0_IPchi2/F");
0188   Background_tree->Branch("outKFP_D0_pseudorapidity", &outKFP_D0_pseudorapidity,"outKFP_D0_pseudorapidity/F");
0189   Background_tree->Branch("outKFP_D0_rapidity", &outKFP_D0_rapidity,"outKFP_D0_rapidity/F");
0190   Background_tree->Branch("outKFP_positive_px", &outKFP_positive_px,"outKFP_positive_px/F");
0191   Background_tree->Branch("outKFP_positive_py", &outKFP_positive_py,"outKFP_positive_py/F");
0192   Background_tree->Branch("outKFP_positive_pz", &outKFP_positive_pz,"outKFP_positive_pz/F");
0193   Background_tree->Branch("outKFP_positive_pE", &outKFP_positive_pE,"outKFP_positive_pE/F");
0194   Background_tree->Branch("outKFP_negative_px", &outKFP_negative_px,"outKFP_negative_px/F");
0195   Background_tree->Branch("outKFP_negative_py", &outKFP_negative_py,"outKFP_negative_py/F");
0196   Background_tree->Branch("outKFP_negative_pz", &outKFP_negative_pz,"outKFP_negative_pz/F");
0197   Background_tree->Branch("outKFP_negative_pE", &outKFP_negative_pE,"outKFP_negative_pE/F");
0198   Background_tree->Branch("outKFP_positive_p", &outKFP_positive_p,"outKFP_positive_p/F");
0199   Background_tree->Branch("outKFP_negative_p", &outKFP_negative_p,"outKFP_negative_p/F");
0200   Background_tree->Branch("outKFP_positive_pseudorapidity", &outKFP_positive_pseudorapidity,"outKFP_positive_pseudorapidity/F");
0201   Background_tree->Branch("outKFP_negative_pseudorapidity", &outKFP_negative_pseudorapidity,"outKFP_negative_pseudorapidity/F");
0202   Background_tree->Branch("outKFP_positive_charge", &outKFP_positive_charge,"outKFP_positive_charge/I");
0203   Background_tree->Branch("outKFP_negative_charge", &outKFP_negative_charge,"outKFP_negative_charge/I");
0204   Background_tree->Branch("outKFP_positive_IP", &outKFP_positive_IP,"outKFP_positive_IP/F");
0205   Background_tree->Branch("outKFP_negative_IP", &outKFP_negative_IP,"outKFP_negative_IP/F");
0206   Background_tree->Branch("outKFP_positive_IPchi2", &outKFP_positive_IPchi2,"outKFP_positive_IPchi2/F");
0207   Background_tree->Branch("outKFP_negative_IPchi2", &outKFP_negative_IPchi2,"outKFP_negative_IPchi2/F");
0208   Background_tree->Branch("outKFP_track_1_track_2_DCA", &outKFP_track_1_track_2_DCA,"outKFP_track_1_track_2_DCA/F");
0209   Background_tree->Branch("outKFP_KpPm_invm", &outKFP_KpPm_invm,"outKFP_KpPm_invm/F");
0210   Background_tree->Branch("outKFP_KmPp_invm", &outKFP_KmPp_invm,"outKFP_KmPp_invm/F");
0211 
0212   for (int i = 1; i < 237; ++i)
0213   {
0214     std::cout << "Starting File Number: " << i << std::endl;
0215     string fNumb;
0216     if (i < 10)
0217     {
0218       fNumb = "00" + std::to_string(i);
0219     }
0220     else if (i < 100)
0221     {
0222       fNumb = "0" + std::to_string(i);
0223     }
0224     else
0225     {
0226       fNumb = std::to_string(i);
0227     }
0228 
0229     string truthFile = "outputData_Run40Acceptance082922_00" + fNumb + ".root";
0230     string KFPFile = "outputData_Run40Acceptance082922_KFP_00" + fNumb + ".root";
0231     truthFilePath = inDir + truthFile;
0232     KFPFilePath = inDir + KFPFile;
0233 
0234     TFile *truthInput(0);
0235     truthInput = TFile::Open(truthFilePath);
0236     TTree *truthTree = (TTree*)truthInput->Get("QAG4SimulationTruthDecay");
0237     TFile *KFPInput(0);
0238     KFPInput = TFile::Open(KFPFilePath);
0239     TTree *recoTree = (TTree*)KFPInput->Get("DecayTree");
0240 
0241     Float_t truth_mother_px, truth_mother_py, truth_mother_pz, truth_mother_pE;
0242     Float_t truth_mother_pT, truth_mother_eta;
0243     Int_t truth_mother_barcode, truth_mother_PDG_ID;
0244     Float_t truth_track_1_px, truth_track_1_py, truth_track_1_pz, truth_track_1_pE;
0245     Float_t truth_track_2_px, truth_track_2_py, truth_track_2_pz, truth_track_2_pE;
0246     Float_t truth_track_1_eta, truth_track_2_eta;
0247     Int_t truth_track_1_PDG_ID, truth_track_2_PDG_ID;
0248     Float_t kfp_D0_px, kfp_D0_py, kfp_D0_pz, kfp_D0_pE;
0249     Float_t kfp_D0_mass;
0250     Float_t kfp_D0_decayTime, kfp_D0_decayLength, kfp_D0_DIRA, kfp_D0_IP, kfp_D0_IPchi2;
0251     Float_t kfp_D0_pseudorapidity, kfp_D0_rapidity;
0252     Float_t kfp_track_1_px, kfp_track_1_py, kfp_track_1_pz, kfp_track_1_pE;
0253     Float_t kfp_track_2_px, kfp_track_2_py, kfp_track_2_pz, kfp_track_2_pE;
0254     Float_t kfp_track_1_p, kfp_track_2_p;
0255     Float_t kfp_track_1_true_px, kfp_track_1_true_py, kfp_track_1_true_pz;
0256     Float_t kfp_track_2_true_px, kfp_track_2_true_py, kfp_track_2_true_pz;
0257     Float_t kfp_track_1_pseudorapidity, kfp_track_2_pseudorapidity;
0258     Int_t kfp_track_1_charge, kfp_track_2_charge;
0259     Float_t kfp_track_1_IP, kfp_track_2_IP;
0260     Float_t kfp_track_1_IPchi2, kfp_track_2_IPchi2;
0261     Float_t kfp_track_1_track_2_DCA;
0262 
0263     truthTree->SetBranchAddress("mother_px", &truth_mother_px);
0264     truthTree->SetBranchAddress("mother_py", &truth_mother_py);
0265     truthTree->SetBranchAddress("mother_pz", &truth_mother_pz);
0266     truthTree->SetBranchAddress("mother_pE", &truth_mother_pE);
0267     truthTree->SetBranchAddress("mother_pT", &truth_mother_pT);
0268     truthTree->SetBranchAddress("mother_eta", &truth_mother_eta);
0269     truthTree->SetBranchAddress("mother_barcode", &truth_mother_barcode);
0270     truthTree->SetBranchAddress("mother_PDG_ID", &truth_mother_PDG_ID);
0271     truthTree->SetBranchAddress("track_1_px", &truth_track_1_px);
0272     truthTree->SetBranchAddress("track_1_py", &truth_track_1_py);
0273     truthTree->SetBranchAddress("track_1_pz", &truth_track_1_pz);
0274     truthTree->SetBranchAddress("track_1_pE", &truth_track_1_pE);
0275     truthTree->SetBranchAddress("track_2_px", &truth_track_2_px);
0276     truthTree->SetBranchAddress("track_2_py", &truth_track_2_py);
0277     truthTree->SetBranchAddress("track_2_pz", &truth_track_2_pz);
0278     truthTree->SetBranchAddress("track_2_pE", &truth_track_2_pE);
0279     truthTree->SetBranchAddress("track_1_eta", &truth_track_1_eta);
0280     truthTree->SetBranchAddress("track_2_eta", &truth_track_2_eta);
0281     truthTree->SetBranchAddress("track_1_PDG_ID", &truth_track_1_PDG_ID);
0282     truthTree->SetBranchAddress("track_2_PDG_ID", &truth_track_2_PDG_ID);
0283 
0284     recoTree->SetBranchAddress("D0_px", &kfp_D0_px);
0285     recoTree->SetBranchAddress("D0_py", &kfp_D0_py);
0286     recoTree->SetBranchAddress("D0_pz", &kfp_D0_pz);
0287     recoTree->SetBranchAddress("D0_pE", &kfp_D0_pE);
0288     recoTree->SetBranchAddress("D0_mass", &kfp_D0_mass);
0289     recoTree->SetBranchAddress("D0_decayTime", &kfp_D0_decayTime);
0290     recoTree->SetBranchAddress("D0_decayLength", &kfp_D0_decayLength);
0291     recoTree->SetBranchAddress("D0_DIRA", &kfp_D0_DIRA);
0292     recoTree->SetBranchAddress("D0_IP", &kfp_D0_IP);
0293     recoTree->SetBranchAddress("D0_IPchi2", &kfp_D0_IPchi2);
0294     recoTree->SetBranchAddress("D0_pseudorapidity", &kfp_D0_pseudorapidity);
0295     recoTree->SetBranchAddress("D0_rapidity", &kfp_D0_rapidity);
0296     recoTree->SetBranchAddress("track_1_px", &kfp_track_1_px);
0297     recoTree->SetBranchAddress("track_1_py", &kfp_track_1_py);
0298     recoTree->SetBranchAddress("track_1_pz", &kfp_track_1_pz);
0299     recoTree->SetBranchAddress("track_1_pE", &kfp_track_1_pE);
0300     recoTree->SetBranchAddress("track_2_px", &kfp_track_2_px);
0301     recoTree->SetBranchAddress("track_2_py", &kfp_track_2_py);
0302     recoTree->SetBranchAddress("track_2_pz", &kfp_track_2_pz);
0303     recoTree->SetBranchAddress("track_2_pE", &kfp_track_2_pE);
0304     recoTree->SetBranchAddress("track_1_p", &kfp_track_1_p);
0305     recoTree->SetBranchAddress("track_2_p", &kfp_track_2_p);
0306     recoTree->SetBranchAddress("track_1_true_px", &kfp_track_1_true_px);
0307     recoTree->SetBranchAddress("track_1_true_py", &kfp_track_1_true_py);
0308     recoTree->SetBranchAddress("track_1_true_pz", &kfp_track_1_true_pz);
0309     recoTree->SetBranchAddress("track_2_true_px", &kfp_track_2_true_px);
0310     recoTree->SetBranchAddress("track_2_true_py", &kfp_track_2_true_py);
0311     recoTree->SetBranchAddress("track_2_true_pz", &kfp_track_2_true_pz);
0312     recoTree->SetBranchAddress("track_1_pseudorapidity", &kfp_track_1_pseudorapidity);
0313     recoTree->SetBranchAddress("track_2_pseudorapidity", &kfp_track_2_pseudorapidity);
0314     recoTree->SetBranchAddress("track_1_charge", &kfp_track_1_charge);
0315     recoTree->SetBranchAddress("track_2_charge", &kfp_track_2_charge);
0316     recoTree->SetBranchAddress("track_1_IP", &kfp_track_1_IP);
0317     recoTree->SetBranchAddress("track_2_IP", &kfp_track_2_IP);
0318     recoTree->SetBranchAddress("track_1_IPchi2", &kfp_track_1_IPchi2);
0319     recoTree->SetBranchAddress("track_2_IPchi2", &kfp_track_2_IPchi2);
0320     recoTree->SetBranchAddress("track_1_track_2_DCA", &kfp_track_1_track_2_DCA);
0321     
0322     vector<Int_t> reconstructedBarcodes;
0323     vector<Int_t> missedBarcodes;
0324     vector<int> usedRecoEntries;
0325   
0326     int minEntry;  
0327  
0328     for (int j = 0; j < truthTree->GetEntries(); ++j)
0329     {
0330       truthTree->GetEntry(j);
0331 
0332       outTrue_mother_px = 0; outTrue_mother_py = 0; outTrue_mother_pz = 0; outTrue_mother_pE = 0;
0333       outTrue_mother_pT = 0; outTrue_mother_eta = 0;
0334       outTrue_mother_barcode = 0; outTrue_mother_PDG_ID = 0;
0335       outTrue_positive_px = 0; outTrue_positive_py = 0; outTrue_positive_pz = 0; outTrue_positive_pE = 0;
0336       outTrue_negative_px = 0; outTrue_negative_py = 0; outTrue_negative_pz = 0; outTrue_negative_pE = 0;
0337       outTrue_positive_eta = 0; outTrue_negative_eta = 0;
0338       outTrue_positive_PDG_ID = 0; outTrue_negative_PDG_ID = 0;
0339       outKFP_D0_px = 0; outKFP_D0_py = 0; outKFP_D0_pz = 0; outKFP_D0_pE = 0;
0340       outKFP_D0_mass = 0;
0341       outKFP_D0_decayTime = 0; outKFP_D0_decayLength = 0; outKFP_D0_DIRA = 0; outKFP_D0_IP = 0; outKFP_D0_IPchi2 = 0;
0342       outKFP_D0_pseudorapidity = 0; outKFP_D0_rapidity = 0;
0343       outKFP_positive_px = 0; outKFP_positive_py = 0; outKFP_positive_pz = 0; outKFP_positive_pE = 0;
0344       outKFP_negative_px = 0; outKFP_negative_py = 0; outKFP_negative_pz = 0; outKFP_negative_pE = 0;
0345       outKFP_positive_p = 0; outKFP_negative_p = 0;
0346       outKFP_positive_pseudorapidity = 0; outKFP_negative_pseudorapidity = 0;
0347       outKFP_positive_charge = 0; outKFP_negative_charge = 0;
0348       outKFP_positive_IP = 0; outKFP_negative_IP = 0;
0349       outKFP_positive_IPchi2 = 0; outKFP_negative_IPchi2 = 0;
0350       outKFP_track_1_track_2_DCA = 0;
0351       outKFP_KpPm_invm = 0; outKFP_KmPp_invm = 0;
0352 
0353       bool matchPx_t1r1;
0354       bool matchPy_t1r1;
0355       bool matchPz_t1r1;
0356       bool matchPx_t1r2;
0357       bool matchPy_t1r2;
0358       bool matchPz_t1r2;
0359       bool matchPx_t2r1;
0360       bool matchPy_t2r1;
0361       bool matchPz_t2r1;
0362       bool matchPx_t2r2;
0363       bool matchPy_t2r2;
0364       bool matchPz_t2r2;
0365     
0366       bool match_t1r1_t2r2 = false;
0367       bool match_t2r1_t1r2 = false;
0368        
0369       for (int k = 0; k < recoTree->GetEntries(); ++k)
0370       {
0371         recoTree->GetEntry(k); 
0372 
0373         matchPx_t1r1 = (kfp_track_1_true_px == truth_track_1_px);
0374         matchPy_t1r1 = (kfp_track_1_true_py == truth_track_1_py);
0375         matchPz_t1r1 = (kfp_track_1_true_pz == truth_track_1_pz);
0376         matchPx_t1r2 = (kfp_track_2_true_px == truth_track_1_px);
0377         matchPy_t1r2 = (kfp_track_2_true_py == truth_track_1_py);
0378         matchPz_t1r2 = (kfp_track_2_true_pz == truth_track_1_pz);
0379         matchPx_t2r1 = (kfp_track_1_true_px == truth_track_2_px);
0380         matchPy_t2r1 = (kfp_track_1_true_py == truth_track_2_py);
0381         matchPz_t2r1 = (kfp_track_1_true_pz == truth_track_2_pz);
0382         matchPx_t2r2 = (kfp_track_2_true_px == truth_track_2_px);
0383         matchPy_t2r2 = (kfp_track_2_true_py == truth_track_2_py);
0384         matchPz_t2r2 = (kfp_track_2_true_pz == truth_track_2_pz); 
0385         
0386         if (matchPx_t1r1 && matchPy_t1r1 && matchPz_t1r1)
0387         {
0388           if (matchPx_t2r2 && matchPy_t2r2 && matchPz_t2r2)
0389           {
0390             std::cout << "Got a match" << std::endl;
0391             match_t1r1_t2r2 = true;
0392             minEntry = k;
0393             break;
0394           }
0395         }       
0396         else if (matchPx_t1r2 && matchPy_t1r2 && matchPz_t1r2)
0397         {
0398           if (matchPx_t2r1 && matchPy_t2r1 && matchPz_t2r1)
0399           {
0400             std::cout << "Got a match" << std::endl;
0401             match_t2r1_t1r2 = true;
0402             minEntry = k;
0403             break;
0404           }
0405         }       
0406       }
0407       if (match_t1r1_t2r2)
0408       {
0409         if (kfp_track_1_charge > 0 && kfp_track_2_charge < 0)
0410         {
0411           outTrue_mother_px = truth_mother_px; outTrue_mother_py = truth_mother_py; outTrue_mother_pz = truth_mother_pz; outTrue_mother_pE = truth_mother_pE;
0412           outTrue_mother_pT = truth_mother_pT; outTrue_mother_eta = truth_mother_eta;
0413           outTrue_mother_barcode = truth_mother_barcode; outTrue_mother_PDG_ID = truth_mother_PDG_ID;
0414           outTrue_positive_px = truth_track_1_px; outTrue_positive_py = truth_track_1_py; outTrue_positive_pz = truth_track_1_pz; outTrue_positive_pE = truth_track_1_pE;
0415           outTrue_negative_px = truth_track_2_px; outTrue_negative_py = truth_track_2_py; outTrue_negative_pz = truth_track_2_pz; outTrue_negative_pE = truth_track_2_pE;
0416           outTrue_positive_eta = truth_track_1_eta; outTrue_negative_eta = truth_track_2_eta;
0417           outTrue_positive_PDG_ID = truth_track_1_PDG_ID; outTrue_negative_PDG_ID = truth_track_2_PDG_ID;
0418           outKFP_D0_px = kfp_D0_px; outKFP_D0_py = kfp_D0_py; outKFP_D0_pz = kfp_D0_pz; outKFP_D0_pE = kfp_D0_pE;
0419           outKFP_D0_mass = kfp_D0_mass;
0420           outKFP_D0_decayTime = kfp_D0_decayTime; outKFP_D0_decayLength = kfp_D0_decayLength; outKFP_D0_DIRA = kfp_D0_DIRA; outKFP_D0_IP = kfp_D0_IP; outKFP_D0_IPchi2 = kfp_D0_IPchi2;
0421           outKFP_D0_pseudorapidity = kfp_D0_pseudorapidity; outKFP_D0_rapidity = kfp_D0_rapidity;
0422           outKFP_positive_px = kfp_track_1_px; outKFP_positive_py = kfp_track_1_py; outKFP_positive_pz = kfp_track_1_pz; outKFP_positive_pE = kfp_track_1_pE;
0423           outKFP_negative_px = kfp_track_2_px; outKFP_negative_py = kfp_track_2_py; outKFP_negative_pz = kfp_track_2_pz; outKFP_negative_pE = kfp_track_2_pE;
0424           outKFP_positive_p = kfp_track_1_p; outKFP_negative_p = kfp_track_2_p;
0425           outKFP_positive_pseudorapidity = kfp_track_1_pseudorapidity; outKFP_negative_pseudorapidity = kfp_track_2_pseudorapidity;
0426           outKFP_positive_charge = kfp_track_1_charge; outKFP_negative_charge = kfp_track_2_charge;
0427           outKFP_positive_IP = kfp_track_1_IP; outKFP_negative_IP = kfp_track_2_IP;
0428           outKFP_positive_IPchi2 = kfp_track_1_IPchi2; outKFP_negative_IPchi2 = kfp_track_2_IPchi2;
0429           outKFP_track_1_track_2_DCA = kfp_track_1_track_2_DCA; 
0430 
0431           TVector3 P_p(outKFP_positive_px,outKFP_positive_py,outKFP_positive_pz);
0432           TVector3 N_p(outKFP_negative_px,outKFP_negative_py,outKFP_negative_pz);
0433           Float_t K_energy = sqrt(P_p.Mag2() + pow(K_mass,2));
0434           Float_t Pi_energy = sqrt(N_p.Mag2() + pow(Pi_mass,2));
0435           outKFP_KpPm_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0436           K_energy = sqrt(N_p.Mag2() + pow(K_mass,2));
0437           Pi_energy = sqrt(P_p.Mag2() + pow(Pi_mass,2));
0438           outKFP_KmPp_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0439  
0440           if (usedRecoEntries.size() > 0)
0441           {
0442             bool recoCandidateUsed = false;
0443             for (int ent : usedRecoEntries)
0444             {
0445               if (ent == minEntry)
0446           {
0447                 std::cout << "Candidate has already been used, skipping this candidate" << std::endl;
0448                 recoCandidateUsed = true;
0449           } 
0450             }
0451             if (recoCandidateUsed) continue;
0452             else
0453             {
0454               usedRecoEntries.push_back(minEntry);
0455               // D0 or D0bar check here 
0456               if (outTrue_mother_PDG_ID == 421) D0_tree->Fill();  
0457               else if (outTrue_mother_PDG_ID == -421) D0bar_tree->Fill();
0458               else
0459               {
0460                 Background_tree->Fill();
0461                 std::cout << "ERROR: Should not get here if tracks match" <<std::endl;
0462               }
0463             }         
0464           }
0465           else
0466           {
0467             usedRecoEntries.push_back(minEntry);
0468 
0469             // D0 or D0bar check here 
0470             if (outTrue_mother_PDG_ID == 421) D0_tree->Fill();  
0471             else if (outTrue_mother_PDG_ID == -421) D0bar_tree->Fill();
0472             else
0473             {
0474               Background_tree->Fill();
0475               std::cout << "ERROR: Should not get here if tracks match" <<std::endl;
0476             }
0477           }
0478         }
0479         else if (kfp_track_1_charge < 0 && kfp_track_2_charge > 0)
0480         {
0481           outTrue_mother_px = truth_mother_px; outTrue_mother_py = truth_mother_py; outTrue_mother_pz = truth_mother_pz; outTrue_mother_pE = truth_mother_pE;
0482           outTrue_mother_pT = truth_mother_pT; outTrue_mother_eta = truth_mother_eta;
0483           outTrue_mother_barcode = truth_mother_barcode; outTrue_mother_PDG_ID = truth_mother_PDG_ID;
0484           outTrue_negative_px = truth_track_1_px; outTrue_negative_py = truth_track_1_py; outTrue_negative_pz = truth_track_1_pz; outTrue_negative_pE = truth_track_1_pE;
0485           outTrue_positive_px = truth_track_2_px; outTrue_positive_py = truth_track_2_py; outTrue_positive_pz = truth_track_2_pz; outTrue_positive_pE = truth_track_2_pE;
0486           outTrue_negative_eta = truth_track_1_eta; outTrue_positive_eta = truth_track_2_eta;
0487           outTrue_negative_PDG_ID = truth_track_1_PDG_ID; outTrue_positive_PDG_ID = truth_track_2_PDG_ID;
0488           outKFP_D0_px = kfp_D0_px; outKFP_D0_py = kfp_D0_py; outKFP_D0_pz = kfp_D0_pz; outKFP_D0_pE = kfp_D0_pE;
0489           outKFP_D0_mass = kfp_D0_mass;
0490           outKFP_D0_decayTime = kfp_D0_decayTime; outKFP_D0_decayLength = kfp_D0_decayLength; outKFP_D0_DIRA = kfp_D0_DIRA; outKFP_D0_IP = kfp_D0_IP; outKFP_D0_IPchi2 = kfp_D0_IPchi2;
0491           outKFP_D0_pseudorapidity = kfp_D0_pseudorapidity; outKFP_D0_rapidity = kfp_D0_rapidity;
0492           outKFP_negative_px = kfp_track_1_px; outKFP_negative_py = kfp_track_1_py; outKFP_negative_pz = kfp_track_1_pz; outKFP_negative_pE = kfp_track_1_pE;
0493           outKFP_positive_px = kfp_track_2_px; outKFP_positive_py = kfp_track_2_py; outKFP_positive_pz = kfp_track_2_pz; outKFP_positive_pE = kfp_track_2_pE;
0494           outKFP_negative_p = kfp_track_1_p; outKFP_positive_p = kfp_track_2_p;
0495           outKFP_negative_pseudorapidity = kfp_track_1_pseudorapidity; outKFP_positive_pseudorapidity = kfp_track_2_pseudorapidity;
0496           outKFP_negative_charge = kfp_track_1_charge; outKFP_positive_charge = kfp_track_2_charge;
0497           outKFP_negative_IP = kfp_track_1_IP; outKFP_positive_IP = kfp_track_2_IP;
0498           outKFP_negative_IPchi2 = kfp_track_1_IPchi2; outKFP_positive_IPchi2 = kfp_track_2_IPchi2;
0499           outKFP_track_1_track_2_DCA = kfp_track_1_track_2_DCA; 
0500 
0501           TVector3 P_p(outKFP_positive_px,outKFP_positive_py,outKFP_positive_pz);
0502           TVector3 N_p(outKFP_negative_px,outKFP_negative_py,outKFP_negative_pz);
0503           Float_t K_energy = sqrt(P_p.Mag2() + pow(K_mass,2));
0504           Float_t Pi_energy = sqrt(N_p.Mag2() + pow(Pi_mass,2));
0505           outKFP_KpPm_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0506           K_energy = sqrt(N_p.Mag2() + pow(K_mass,2));
0507           Pi_energy = sqrt(P_p.Mag2() + pow(Pi_mass,2));
0508           outKFP_KmPp_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0509  
0510           if (usedRecoEntries.size() > 0)
0511           {
0512             bool recoCandidateUsed = false;
0513             for (int ent : usedRecoEntries)
0514             {
0515               if (ent == minEntry)
0516           {
0517                 std::cout << "Candidate has already been used, skipping this candidate" << std::endl;
0518                 recoCandidateUsed = true;
0519           } 
0520             }
0521             if (recoCandidateUsed) continue;
0522             else
0523             {
0524               usedRecoEntries.push_back(minEntry);
0525               // D0 or D0bar check here 
0526               if (outTrue_mother_PDG_ID == 421) D0_tree->Fill();  
0527               else if (outTrue_mother_PDG_ID == -421) D0bar_tree->Fill();
0528               else
0529               {
0530                 Background_tree->Fill();
0531                 std::cout << "ERROR: Should not get here if tracks match" <<std::endl;
0532               }
0533             }         
0534           }
0535           else
0536           {
0537             usedRecoEntries.push_back(minEntry);
0538 
0539             // D0 or D0bar check here 
0540             if (outTrue_mother_PDG_ID == 421) D0_tree->Fill();  
0541             else if (outTrue_mother_PDG_ID == -421) D0bar_tree->Fill();
0542             else
0543             {
0544               Background_tree->Fill();
0545               std::cout << "ERROR: Should not get here if tracks match" <<std::endl;
0546             }
0547           }
0548         }
0549       } 
0550       else if (match_t2r1_t1r2)
0551       { 
0552         if (kfp_track_1_charge > 0 && kfp_track_2_charge < 0)
0553         {
0554           outTrue_mother_px = truth_mother_px; outTrue_mother_py = truth_mother_py; outTrue_mother_pz = truth_mother_pz; outTrue_mother_pE = truth_mother_pE;
0555           outTrue_mother_pT = truth_mother_pT; outTrue_mother_eta = truth_mother_eta;
0556           outTrue_mother_barcode = truth_mother_barcode; outTrue_mother_PDG_ID = truth_mother_PDG_ID;
0557           outTrue_negative_px = truth_track_1_px; outTrue_negative_py = truth_track_1_py; outTrue_negative_pz = truth_track_1_pz; outTrue_negative_pE = truth_track_1_pE;
0558           outTrue_positive_px = truth_track_2_px; outTrue_positive_py = truth_track_2_py; outTrue_positive_pz = truth_track_2_pz; outTrue_positive_pE = truth_track_2_pE;
0559           outTrue_negative_eta = truth_track_1_eta; outTrue_positive_eta = truth_track_2_eta;
0560           outTrue_negative_PDG_ID = truth_track_1_PDG_ID; outTrue_positive_PDG_ID = truth_track_2_PDG_ID;
0561           outKFP_D0_px = kfp_D0_px; outKFP_D0_py = kfp_D0_py; outKFP_D0_pz = kfp_D0_pz; outKFP_D0_pE = kfp_D0_pE;
0562           outKFP_D0_mass = kfp_D0_mass;
0563           outKFP_D0_decayTime = kfp_D0_decayTime; outKFP_D0_decayLength = kfp_D0_decayLength; outKFP_D0_DIRA = kfp_D0_DIRA; outKFP_D0_IP = kfp_D0_IP; outKFP_D0_IPchi2 = kfp_D0_IPchi2;
0564           outKFP_D0_pseudorapidity = kfp_D0_pseudorapidity; outKFP_D0_rapidity = kfp_D0_rapidity;
0565           outKFP_positive_px = kfp_track_1_px; outKFP_positive_py = kfp_track_1_py; outKFP_positive_pz = kfp_track_1_pz; outKFP_positive_pE = kfp_track_1_pE;
0566           outKFP_negative_px = kfp_track_2_px; outKFP_negative_py = kfp_track_2_py; outKFP_negative_pz = kfp_track_2_pz; outKFP_negative_pE = kfp_track_2_pE;
0567           outKFP_positive_p = kfp_track_1_p; outKFP_negative_p = kfp_track_2_p;
0568           outKFP_positive_pseudorapidity = kfp_track_1_pseudorapidity; outKFP_negative_pseudorapidity = kfp_track_2_pseudorapidity;
0569           outKFP_positive_charge = kfp_track_1_charge; outKFP_negative_charge = kfp_track_2_charge;
0570           outKFP_positive_IP = kfp_track_1_IP; outKFP_negative_IP = kfp_track_2_IP;
0571           outKFP_positive_IPchi2 = kfp_track_1_IPchi2; outKFP_negative_IPchi2 = kfp_track_2_IPchi2;
0572           outKFP_track_1_track_2_DCA = kfp_track_1_track_2_DCA; 
0573 
0574           TVector3 P_p(outKFP_positive_px,outKFP_positive_py,outKFP_positive_pz);
0575           TVector3 N_p(outKFP_negative_px,outKFP_negative_py,outKFP_negative_pz);
0576           Float_t K_energy = sqrt(P_p.Mag2() + pow(K_mass,2));
0577           Float_t Pi_energy = sqrt(N_p.Mag2() + pow(Pi_mass,2));
0578           outKFP_KpPm_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0579           K_energy = sqrt(N_p.Mag2() + pow(K_mass,2));
0580           Pi_energy = sqrt(P_p.Mag2() + pow(Pi_mass,2));
0581           outKFP_KmPp_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0582  
0583           if (usedRecoEntries.size() > 0)
0584           {
0585             bool recoCandidateUsed = false;
0586             for (int ent : usedRecoEntries)
0587             {
0588               if (ent == minEntry)
0589           {
0590                 std::cout << "Candidate has already been used, skipping this candidate" << std::endl;
0591                 recoCandidateUsed = true;
0592           } 
0593             }
0594             if (recoCandidateUsed) continue;
0595             else
0596             {
0597               usedRecoEntries.push_back(minEntry);
0598               // D0 or D0bar check here 
0599               if (outTrue_mother_PDG_ID == 421) D0_tree->Fill();  
0600               else if (outTrue_mother_PDG_ID == -421) D0bar_tree->Fill();
0601               else
0602               {
0603                 Background_tree->Fill();
0604                 std::cout << "ERROR: Should not get here if tracks match" <<std::endl;
0605               }
0606             }         
0607           }
0608           else
0609           {
0610             usedRecoEntries.push_back(minEntry);
0611 
0612             // D0 or D0bar check here 
0613             if (outTrue_mother_PDG_ID == 421) D0_tree->Fill();  
0614             else if (outTrue_mother_PDG_ID == -421) D0bar_tree->Fill();
0615             else
0616             {
0617               Background_tree->Fill();
0618               std::cout << "ERROR: Should not get here if tracks match" <<std::endl;
0619             }
0620           }
0621         }
0622         if (kfp_track_1_charge < 0 && kfp_track_2_charge > 0)
0623         {
0624           outTrue_mother_px = truth_mother_px; outTrue_mother_py = truth_mother_py; outTrue_mother_pz = truth_mother_pz; outTrue_mother_pE = truth_mother_pE;
0625           outTrue_mother_pT = truth_mother_pT; outTrue_mother_eta = truth_mother_eta;
0626           outTrue_mother_barcode = truth_mother_barcode; outTrue_mother_PDG_ID = truth_mother_PDG_ID;
0627           outTrue_positive_px = truth_track_1_px; outTrue_positive_py = truth_track_1_py; outTrue_positive_pz = truth_track_1_pz; outTrue_positive_pE = truth_track_1_pE;
0628           outTrue_negative_px = truth_track_2_px; outTrue_negative_py = truth_track_2_py; outTrue_negative_pz = truth_track_2_pz; outTrue_negative_pE = truth_track_2_pE;
0629           outTrue_positive_eta = truth_track_1_eta; outTrue_negative_eta = truth_track_2_eta;
0630           outTrue_positive_PDG_ID = truth_track_1_PDG_ID; outTrue_negative_PDG_ID = truth_track_2_PDG_ID;
0631           outKFP_D0_px = kfp_D0_px; outKFP_D0_py = kfp_D0_py; outKFP_D0_pz = kfp_D0_pz; outKFP_D0_pE = kfp_D0_pE;
0632           outKFP_D0_mass = kfp_D0_mass;
0633           outKFP_D0_decayTime = kfp_D0_decayTime; outKFP_D0_decayLength = kfp_D0_decayLength; outKFP_D0_DIRA = kfp_D0_DIRA; outKFP_D0_IP = kfp_D0_IP; outKFP_D0_IPchi2 = kfp_D0_IPchi2;
0634           outKFP_D0_pseudorapidity = kfp_D0_pseudorapidity; outKFP_D0_rapidity = kfp_D0_rapidity;
0635           outKFP_negative_px = kfp_track_1_px; outKFP_negative_py = kfp_track_1_py; outKFP_negative_pz = kfp_track_1_pz; outKFP_negative_pE = kfp_track_1_pE;
0636           outKFP_positive_px = kfp_track_2_px; outKFP_positive_py = kfp_track_2_py; outKFP_positive_pz = kfp_track_2_pz; outKFP_positive_pE = kfp_track_2_pE;
0637           outKFP_negative_p = kfp_track_1_p; outKFP_positive_p = kfp_track_2_p;
0638           outKFP_negative_pseudorapidity = kfp_track_1_pseudorapidity; outKFP_positive_pseudorapidity = kfp_track_2_pseudorapidity;
0639           outKFP_negative_charge = kfp_track_1_charge; outKFP_positive_charge = kfp_track_2_charge;
0640           outKFP_negative_IP = kfp_track_1_IP; outKFP_positive_IP = kfp_track_2_IP;
0641           outKFP_negative_IPchi2 = kfp_track_1_IPchi2; outKFP_positive_IPchi2 = kfp_track_2_IPchi2;
0642           outKFP_track_1_track_2_DCA = kfp_track_1_track_2_DCA; 
0643 
0644           TVector3 P_p(outKFP_positive_px,outKFP_positive_py,outKFP_positive_pz);
0645           TVector3 N_p(outKFP_negative_px,outKFP_negative_py,outKFP_negative_pz);
0646           Float_t K_energy = sqrt(P_p.Mag2() + pow(K_mass,2));
0647           Float_t Pi_energy = sqrt(N_p.Mag2() + pow(Pi_mass,2));
0648           outKFP_KpPm_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0649           K_energy = sqrt(N_p.Mag2() + pow(K_mass,2));
0650           Pi_energy = sqrt(P_p.Mag2() + pow(Pi_mass,2));
0651           outKFP_KmPp_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0652  
0653           if (usedRecoEntries.size() > 0)
0654           {
0655             bool recoCandidateUsed = false;
0656             for (int ent : usedRecoEntries)
0657             {
0658               if (ent == minEntry)
0659           {
0660                 std::cout << "Candidate has already been used, skipping this candidate" << std::endl;
0661                 recoCandidateUsed = true;
0662           } 
0663             }
0664             if (recoCandidateUsed) continue;
0665             else
0666             {
0667               usedRecoEntries.push_back(minEntry);
0668               // D0 or D0bar check here 
0669               if (outTrue_mother_PDG_ID == 421) D0_tree->Fill();  
0670               else if (outTrue_mother_PDG_ID == -421) D0bar_tree->Fill();
0671               else
0672               {
0673                 Background_tree->Fill();
0674                 std::cout << "ERROR: Should not get here if tracks match" <<std::endl;
0675               }
0676             }         
0677           }
0678           else
0679           {
0680             usedRecoEntries.push_back(minEntry);
0681 
0682             // D0 or D0bar check here 
0683             if (outTrue_mother_PDG_ID == 421) D0_tree->Fill();  
0684             else if (outTrue_mother_PDG_ID == -421) D0bar_tree->Fill();
0685             else
0686             {
0687               Background_tree->Fill();
0688               std::cout << "ERROR: Should not get here if tracks match" <<std::endl;
0689             }
0690           }
0691         }
0692       }
0693     }
0694     for (int k = 0; k < recoTree->GetEntries(); ++k)
0695     {
0696       bool recoCandidateUsed = false;
0697       for (int ent : usedRecoEntries)
0698       {
0699         if (ent == k) recoCandidateUsed = true;
0700       }
0701       if (recoCandidateUsed == false)
0702       {
0703         recoTree->GetEntry(k); 
0704        
0705         if (kfp_track_1_charge > 0 && kfp_track_2_charge < 0)
0706         {
0707           outKFP_D0_px = kfp_D0_px; outKFP_D0_py = kfp_D0_py; outKFP_D0_pz = kfp_D0_pz; outKFP_D0_pE = kfp_D0_pE;
0708           outKFP_D0_mass = kfp_D0_mass;
0709           outKFP_D0_decayTime = kfp_D0_decayTime; outKFP_D0_decayLength = kfp_D0_decayLength; outKFP_D0_DIRA = kfp_D0_DIRA; outKFP_D0_IP = kfp_D0_IP; outKFP_D0_IPchi2 = kfp_D0_IPchi2;
0710           outKFP_D0_pseudorapidity = kfp_D0_pseudorapidity; outKFP_D0_rapidity = kfp_D0_rapidity;
0711           outKFP_positive_px = kfp_track_1_px; outKFP_positive_py = kfp_track_1_py; outKFP_positive_pz = kfp_track_1_pz; outKFP_positive_pE = kfp_track_1_pE;
0712           outKFP_negative_px = kfp_track_2_px; outKFP_negative_py = kfp_track_2_py; outKFP_negative_pz = kfp_track_2_pz; outKFP_negative_pE = kfp_track_2_pE;
0713           outKFP_positive_p = kfp_track_1_p; outKFP_negative_p = kfp_track_2_p;
0714           outKFP_positive_pseudorapidity = kfp_track_1_pseudorapidity; outKFP_negative_pseudorapidity = kfp_track_2_pseudorapidity;
0715           outKFP_positive_charge = kfp_track_1_charge; outKFP_negative_charge = kfp_track_2_charge;
0716           outKFP_positive_IP = kfp_track_1_IP; outKFP_negative_IP = kfp_track_2_IP;
0717           outKFP_positive_IPchi2 = kfp_track_1_IPchi2; outKFP_negative_IPchi2 = kfp_track_2_IPchi2;
0718           outKFP_track_1_track_2_DCA = kfp_track_1_track_2_DCA;
0719         
0720           TVector3 P_p(outKFP_positive_px,outKFP_positive_py,outKFP_positive_pz);
0721           TVector3 N_p(outKFP_negative_px,outKFP_negative_py,outKFP_negative_pz);
0722           Float_t K_energy = sqrt(P_p.Mag2() + pow(K_mass,2));
0723           Float_t Pi_energy = sqrt(N_p.Mag2() + pow(Pi_mass,2));
0724           outKFP_KpPm_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0725           K_energy = sqrt(N_p.Mag2() + pow(K_mass,2));
0726           Pi_energy = sqrt(P_p.Mag2() + pow(Pi_mass,2));
0727           outKFP_KmPp_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0728           
0729           Background_tree->Fill(); 
0730         } 
0731         else if (kfp_track_1_charge < 0 && kfp_track_2_charge > 0)
0732         {
0733           outKFP_D0_px = kfp_D0_px; outKFP_D0_py = kfp_D0_py; outKFP_D0_pz = kfp_D0_pz; outKFP_D0_pE = kfp_D0_pE;
0734           outKFP_D0_mass = kfp_D0_mass;
0735           outKFP_D0_decayTime = kfp_D0_decayTime; outKFP_D0_decayLength = kfp_D0_decayLength; outKFP_D0_DIRA = kfp_D0_DIRA; outKFP_D0_IP = kfp_D0_IP; outKFP_D0_IPchi2 = kfp_D0_IPchi2;
0736           outKFP_D0_pseudorapidity = kfp_D0_pseudorapidity; outKFP_D0_rapidity = kfp_D0_rapidity;
0737           outKFP_negative_px = kfp_track_1_px; outKFP_negative_py = kfp_track_1_py; outKFP_negative_pz = kfp_track_1_pz; outKFP_negative_pE = kfp_track_1_pE;
0738           outKFP_positive_px = kfp_track_2_px; outKFP_positive_py = kfp_track_2_py; outKFP_positive_pz = kfp_track_2_pz; outKFP_positive_pE = kfp_track_2_pE;
0739           outKFP_negative_p = kfp_track_1_p; outKFP_positive_p = kfp_track_2_p;
0740           outKFP_negative_pseudorapidity = kfp_track_1_pseudorapidity; outKFP_positive_pseudorapidity = kfp_track_2_pseudorapidity;
0741           outKFP_negative_charge = kfp_track_1_charge; outKFP_positive_charge = kfp_track_2_charge;
0742           outKFP_negative_IP = kfp_track_1_IP; outKFP_positive_IP = kfp_track_2_IP;
0743           outKFP_negative_IPchi2 = kfp_track_1_IPchi2; outKFP_positive_IPchi2 = kfp_track_2_IPchi2;
0744           outKFP_track_1_track_2_DCA = kfp_track_1_track_2_DCA;
0745         
0746           TVector3 P_p(outKFP_positive_px,outKFP_positive_py,outKFP_positive_pz);
0747           TVector3 N_p(outKFP_negative_px,outKFP_negative_py,outKFP_negative_pz);
0748           Float_t K_energy = sqrt(P_p.Mag2() + pow(K_mass,2));
0749           Float_t Pi_energy = sqrt(N_p.Mag2() + pow(Pi_mass,2));
0750           outKFP_KpPm_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0751           K_energy = sqrt(N_p.Mag2() + pow(K_mass,2));
0752           Pi_energy = sqrt(P_p.Mag2() + pow(Pi_mass,2));
0753           outKFP_KmPp_invm = sqrt(pow((K_energy + Pi_energy),2) - ((N_p+P_p).Mag2()));
0754           
0755           Background_tree->Fill(); 
0756         }
0757         else
0758         {
0759           std::cout << "WARNING: tracks not oppositely charged" << std::endl;
0760         } 
0761       }
0762     }
0763   }
0764 
0765   newfile->cd();
0766   D0_tree->Print();
0767   D0_tree->Write();
0768   D0bar_tree->Print();
0769   D0bar_tree->Write();
0770   Background_tree->Print();
0771   Background_tree->Write();
0772   newfile->Close(); 
0773 
0774   ifstream file2("Run40_D0_Separated_091922.root");
0775   if (file2.good())
0776   {
0777     string moveOutput = "mv Run40_D0_Separated_091922.root " + inDir;
0778     system(moveOutput.c_str());
0779   }
0780 
0781 }