Please read tips for efficient and successful posting and posting code
ROOT Version: 6.32.02
Platform: Windows 11
Compiler: MSVC 19.39.33521.0
I am attempting to write a macro that will take an existing root file, make cuts (proton momentum, phi mass, etc), and make a new version of the file containing only the events that pass the cuts.
There are no error messages when I run the code, but I can’t seem to find the new file anywhere. I’ve created new root files before (this is the first time I’m trying RDataFrame) so I know the specific directory that the new file should be in, but alas! Nothing!
I’d appreciate any help I can get. Thanks!
using PxPyPzE = ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>;
void cutter_Macro() {
ROOT::EnableImplicitMT();
//Input File and input tree
auto inFileName = "flat_pi0pippim__B4.root";
auto outFileName = "flat_pi0pippim__B4_cut.root";
auto treeName = "pi0pippim__B4;1";
TFile *filein = new TFile(inFileName);
TTree *tree = (TTree *)filein->Get(treeName);
//Making the 4-vectors
PxPyPzE Gamma1P4, Gamma2P4, Pi0P4, ProtonP4, PiMinusP4, PiPlusP4, PhiP4;
auto proton_4Vec = [&ProtonP4](PxPyPzE p_p4_kin) { return ProtonP4.SetPxPyPzE(p_p4_kin.Px(), p_p4_kin.Py(), p_p4_kin.Pz(), p_p4_kin.E()); };
auto pim_4Vec = [&PiMinusP4](PxPyPzE pim_p4_kin) { return PiMinusP4.SetPxPyPzE(pim_p4_kin.Px(), pim_p4_kin.Py(), pim_p4_kin.Pz(), pim_p4_kin.E()); };
auto pip_4Vec = [&PiPlusP4](PxPyPzE pip_p4_kin) { return PiPlusP4.SetPxPyPzE(pip_p4_kin.Px(), pip_p4_kin.Py(), pip_p4_kin.Pz(), pip_p4_kin.E()); };
auto g1_4Vec = [&Gamma1P4](PxPyPzE g1_p4_kin) { return Gamma1P4.SetPxPyPzE(g1_p4_kin.Px(), g1_p4_kin.Py(), g1_p4_kin.Pz(), g1_p4_kin.E()); };
auto g2_4Vec = [&Gamma2P4](PxPyPzE g2_p4_kin) { return Gamma2P4.SetPxPyPzE(g2_p4_kin.Px(), g2_p4_kin.Py(), g2_p4_kin.Pz(), g2_p4_kin.E()); };
auto pi0_4Vec = [&Pi0P4, Gamma1P4, Gamma2P4]() { return Gamma1P4 + Gamma2P4; };
auto phi_4Vec = [&PhiP4, PiPlusP4, PiMinusP4, Pi0P4]() { return PiPlusP4 + PiMinusP4 + Pi0P4; };
//Create an RDataFrame from the input
ROOT::RDataFrame d(treeName, inFileName);
//Adding columns
auto d_4Vec = d.Define("Gamma1_4Vec", g1_4Vec, {"g1_p4_kin"})
.Define("Gamma2_4Vec", g2_4Vec, {"g2_p4_kin"})
.Define("PiPlus_4Vec", pip_4Vec, {"pip_p4_kin"})
.Define("PiMinus_4Vec", pim_4Vec, {"pim_p4_kin"})
.Define("Pi0_4Vec", pi0_4Vec, {"Gamma1_4Vec", "Gamma2_4Vec"})
.Define("Proton_4Vec", proton_4Vec, {"p_p4_kin"})
.Define("ProtonMom", "Proton_4Vec.P()")
.Define("Phi_4Vec", phi_4Vec, {"PiPlus_4Vec", "PiMinus_4Vec", "Pi0_4Vec"})
.Define("PhiMass", "Phi_4Vec.M()");
//Cutting the RDataFrame
auto t_cut = [](float Mandlestam_t) { return -Mandlestam_t < 1; };
auto chi2NDF_cut = [](UInt_t kin_ndf, float kin_chisq) { return (kin_chisq / kin_ndf) < 6; };
auto protonMom_cut = [](double ProtonMom) { return ProtonMom > 0.3; };
auto phiMass_cut = [](double PhiMass) { return 0.9 < PhiMass < 1.14; };
auto d_4Vec_cut = d_4Vec.Filter(chi2NDF_cut, {"kin_ndf", "kin_chisq"})
.Filter(t_cut, {"Mandlestam_t"})
.Filter(protonMom_cut, {"ProtonMom"})
.Filter(phiMass_cut, {"PhiMass"});
//Snapshot and create new file
d_4Vec_cut.Snapshot("pi0pippim__B4_cut", "flat_pi0pippim__B4_cut.root");
}