Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:12:31

0001 #include <TFile.h>
0002 #include <TTree.h>
0003 
0004 void RemoveFirstTwoEvents(const char* inputFile_INTT, const char* treeName_INTT, const char* treeName_INTT, const char* inputFile_MBD, const char* treeName_MBD, const char* outputFile, const char* treeName_out = "EventTree") {
0005     // Open the input ROOT file
0006     TFile* inFile_INTT = TFile::Open(inputFile_INTT, "READ");
0007     if (!inFile_INTT || inFile_INTT->IsZombie()) {
0008         std::cerr << "Error: inFile_INTT, could not open input file." << std::endl;
0009         return;
0010     }
0011 
0012     // Get the input TTree
0013     TTree* inTree_INTT = dynamic_cast<TTree*>(inFile_INTT->Get(treeName_INTT));
0014     if (!inTree_INTT) {
0015         std::cerr << "Error: inTree_INTT, could not retrieve input TTree." << std::endl;
0016         inFile_INTT->Close();
0017         return;
0018     }
0019 
0020     TFile* inFile_MBD = TFile::Open(inputFile_MBD, "READ");
0021     if (!inFile_MBD || inFile_MBD->IsZombie()) {
0022         std::cerr << "Error: inFile_MBD, could not open input file." << std::endl;
0023         return;
0024     }
0025 
0026     // Get the input TTree
0027     TTree* inTree_MBD = dynamic_cast<TTree*>(inFile_MBD->Get(treeName_MBD));
0028     if (!inTree_MBD) {
0029         std::cerr << "Error: inTree_MBD, could not retrieve input TTree." << std::endl;
0030         inFile_MBD->Close();
0031         return;
0032     }
0033 
0034 
0035 
0036 
0037 
0038 
0039 
0040 
0041 
0042     // Create a new output ROOT file
0043     TFile* outFile = TFile::Open(outputFile, "RECREATE");
0044     if (!outFile || outFile->IsZombie()) {
0045         std::cerr << "Error: Could not create output file." << std::endl;
0046         inFile->Close();
0047         return;
0048     }
0049 
0050     // Clone the input TTree to create a new TTree in the output file
0051     TTree* outTree = inTree->CloneTree(0); // Create new tree with default buffer size
0052 
0053     // Get the total number of events in the input tree
0054     Long64_t totalEvents = inTree->GetEntries();
0055 
0056     // Loop over the events in the input tree, skipping the first two events
0057     for (Long64_t i = 2; i < totalEvents; ++i) {
0058         inTree->GetEntry(i);
0059         outTree->Fill();
0060     }
0061 
0062     // Write the modified tree to the output file
0063     outTree->Write();
0064 
0065     // Close the input and output files
0066     inFile->Close();
0067     outFile->Close();
0068 
0069     // Clean up
0070     delete inFile;
0071     delete outFile;
0072 }
0073 
0074 int event_combiner_test2() {
0075     const char* inputFile_INTT = "/sphenix/user/ChengWei/INTT/INTT_commissioning/ZeroField/20869/folder_INTTMBD_EventCombiner/intt_run20869.root";
0076     const char* inputFile_MBD  = "/sphenix/user/ChengWei/INTT/INTT_commissioning/ZeroField/20869/folder_INTTMBD_EventCombiner/centrality_run20869.root";
0077     const char* outputFile      = "/sphenix/user/ChengWei/INTT/INTT_commissioning/ZeroField/20869/folder_INTTMBD_EventCombiner/Final_combine_test.root";
0078 
0079     RemoveFirstTwoEvents(inputFile, outputFile);
0080 
0081     return 0;
0082 }