Please read tips for efficient and successful posting and posting code
_ROOT Version: 6.19/02
_Platform: Windows 10
_Compiler:Visual Studio
Currently working through a ROOT tutorial and I’m running into this error when I try to run the macro I’ve written.
Would really appreciate any help as I’m not sure how to resolve the issue. Thanks in advance
Can you post a reproducer?
Sorry what do you mean by reproducer? The code that’s causing the error?
Yes, or any minimal piece of code reproducing the error.
int myFunction(std::string inFileName, std::string outFileName)
{
std::cout << "Reading from " << inFileName <<
" and writing to " << outFileName << std::endl;
// Open the file
TFile* inFile = TFile::Open(inFileName.c_str(), "READ");
// Get TTree
TTree* tree = (TTree*)inFile->Get("HASCO");
// Declare variables
const unsigned int lep_n_MAX = 100;
unsigned int lep_n;
float pT[lep_n_MAX];
float eta[lep_n_MAX];
float phi[lep_n_MAX];
float nrg[lep_n_MAX];
// Link variables to TTree
tree->SetBranchAddress("lep_n", &lep_n);
tree->SetBranchAddress("lep_pt", &pT);
tree->SetBranchAddress("lep_eta", &eta);
tree->SetBranchAddress("lep_phi", &phi);
tree->SetBranchAddress("lep_E", &nrg);
// Create histogram to fill - dilepton invariant mass is a floating point quantitity
TH1D mll("data", "m_{ll}, data", 150, 50.e3, 200.e3);
mll.Sumw2(); // Calculate uncertainties with sum of weights squared
// Loop over TTree
// Calculate paris of lepton four-vectors and mll
for (Long64_t entry = 0; entry < tree->GetEntries(); ++entry)
{
tree->GetEntry(entry);
//Check if there are two leptons
if (lep_n != 2)
continue;
// Build four-vectors
TLorentzVector lepton0, lepton1;
lepton0.SetPtEtaPhiE(pT[0], eta[0], phi[0], nrg[0]);
lepton1.SetPtEtaPhiE(pT[1], eta[1], phi[1], nrg[1]);
//Dilepton is sum of leptons
TLorentzVector dilepton = lepton0 + lepton1;
double dileptonMass = dilepton.M();
//File histogram
mll.Fill(dileptonMass);
}
// Change histogram scope/lifetime - stops histogram being deleted
mll.SetDirectory(0);
// Close input file
inFile->Close();
// Write histogram to output file - recreate mode opens and writes
TFile* outHistFile = TFile::Open(outFileName.c_str(), "RECREATE");
// Switch scope to within the opened file
outHistFile->cd();
// Write to histogram
mll.Write();
// Close output file - writes to disk
outHistFile->Close();
return 0;
}
From commenting out different pieces of code and re running it seems to be the lepton four vectors that are causing the issue.
I cannot run your code, but anyway, try to add R__LOAD_LIBRARY(libPhysics)
at the beginning of your code (before int myFunction(std::string inFileName, std::string outFileName)
)
That seems to have fixed it perfectly. I guess you probably can’t run the code because you don’t have the root file, but it runs fine for me now and I get the output expected. Thanks very much for the help.
1 Like