Newer
Older
#include "TICPhysics.h"
#include <TChain.h>
#include <regex>
TChain* chain;
/////////////////////////////////////////////////////////////////
chain = new TChain("PhysicsTree");
chain->Add(Path);
TICPhysics* IC = new TICPhysics() ;
chain->SetBranchStatus("IC", true);
chain->SetBranchAddress("IC", &IC);
double FF_IC_X;
chain->SetBranchStatus("FF_IC_X", true);
chain->SetBranchAddress("FF_IC_X", &FF_IC_X);
TH1F *hChargeAll = new TH1F("hcharge_all","hcharge_all",2000,20,80);
int Nentries = chain->GetEntries();
auto start = std::chrono::high_resolution_clock::now();
for (int e = 0; e < Nentries; e++) {
if (e % 100000 == 0 && e > 0 ) {
auto now = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = now - start;
double avgTimePerIteration = elapsed.count() / e;
double timeLeft = avgTimePerIteration * (Nentries - e);
std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
if(FF_IC_X>-530 ){
hChargeAll->Fill(IC->Chio_Z);
}
}
std::string strPath(Path);
std::regex pattern("Run(\\d{3})"); // Regex to match Run followed by exactly 3 digits
std::smatch matches;
if (std::regex_search(strPath, matches, pattern)) {
std::string number = matches[1]; // Extract the number
std::string fileName = "Output/histo_charge_" + number + ".root"; // Generate the filename
// Create the TFile
TFile* file = new TFile(fileName.c_str(), "RECREATE");
if (file->IsOpen()) {
std::cout << "File created: " << fileName << std::endl;
} else {
std::cout << "Failed to create the file." << std::endl;
}
hChargeAll->Write();
// Don't forget to close the file
file->Close();
} else {
std::cout << "Pattern not found!" << std::endl;
}