#include #include void pedestal() { // Open input file const char* pedestal00 = "pedestal00.root"; const char* subtractped = "subtractped.root"; TFile* inputFile = new TFile("pedestal00.root", "READ"); // if (!pedestal00) { // printf("Error: Could not open input file.\n"); // return; // } // Create output file TFile* outputFile = new TFile("subtractped.root", "RECREATE"); // if (subtractped) { // printf("Error: Could not create output file.\n"); /// inputFile->Close(); // return; // } // Get input tree from the input file TTree* inputTree = (TTree*)inputFile->Get("tree"); // if (!tree) { // printf("Error: Could not find input tree in the file.\n"); // inputFile->Close(); // outputFile->Close(); // return; // } // Create output tree in the output file TTree* outputTree = inputTree->CloneTree(0); // Variables for input and output branches Double_t inputBranch; // Assuming a single branch for simplicity TBranch* inputBranchPtr = inputTree->GetBranch("x3"); TBranch* outputBranchPtr = outputTree->Branch("x33", &inputBranch); // Pedestal value (replace with your actual pedestal measurement) Double_t pedestalValue = 42.0; // Loop over entries in the input tree Long64_t nEntries = inputTree->GetEntries(); for (Long64_t iEntry = 0; iEntry < nEntries; ++iEntry) { inputTree->GetEntry(iEntry); // Subtract pedestal from the input branch value inputBranch -= pedestalValue; // Fill the output tree with the adjusted value outputBranchPtr->Fill(); outputTree->Fill(); } // Write the output tree to the output file outputFile->Write(); cout << "Entries: " << nEntries << endl; // Close input and output files inputFile->Close(); outputFile->Close(); printf("Pedestal subtraction completed. Output saved to %s\n", "subtractped.root"); }