#include#include int main() { // Define the four-vector with components (Px, Py, Pz, E) TLorentzVector vec(1.0, 2.0, 3.0, 4.0); // Compute the Pt double pt = vec.Pt(); // Print the result std::cout << "Pt: " << pt << std::endl; return 0; }
#includeThis example reads particle four-vector data from a TTree and computes the Pt for each particle. Package library: ROOT#include #include #include int main() { // Open the input file TFile input_file("my_file.root"); // Get the tree from the file TTree* tree = (TTree*)input_file.Get("my_tree"); // Create a TLorentzVector to hold the particle momentum TLorentzVector momentum; // Set the branch address to read the particle momentum from the tree tree->SetBranchAddress("p4", &momentum); // Loop over the entries in the tree for (Long64_t i = 0; i < tree->GetEntries(); i++) { // Get the next entry tree->GetEntry(i); // Compute the Pt of the particle double pt = momentum.Pt(); // Print the result std::cout << "Pt: " << pt << std::endl; } // Close the input file input_file.Close(); return 0; }