Hello, I have one question. I want while I am doing the application in TMVA to create some root files and fill them with some variables after the application of weights. I know it seems trivial but I have some issues. Any help?
Cheers
George
Hello, I have one question. I want while I am doing the application in TMVA to create some root files and fill them with some variables after the application of weights. I know it seems trivial but I have some issues. Any help?
Cheers
George
Hi George,
Could you elaborate on what it is you want to achieve?
If you want to create a separate TTree in a separate TFile I’d suggest you look into TDataFrame (if you’re on ROOT6).
Without TDataFrame you’d do something along the lines of
auto f = new TFile(“path”);
auto t = new TTree(“name”);
int x = 0;
t->Branch(“name”, “x/I”, &x);
And then in your TMVA::Reader
loop
while (reader.HasNext()) {
// ... Get mva value
x = /* something derived from the application */;
t->Fill();
}
t->ResetBranchAddresses();
t->Write();
delete t;
delete f; // File is closed and flushed to disk before it’s destroyed
This is a sketch only, so there might be typos.
Cheers,
Kim
Hello,
I want to apply the weights in an input file, and then save some of the variables (that the weights have been applied on) in new root file. When I do it I get the output
Error in TFile::ReadBuffer: error reading all requested bytes from file post_TMVA_wrong_inpeak.root, got 0 of 31999
Thank you in advance.
George
Hi,
What weights are we talking about here, the event weights? To what do you want to apply the weights to? Maybe a simple code example could illustrate a bit more what it is you want to do.
The error could stem from not flushing the TFile properly and opening it from a different place. One thing you could try is to close the file when you are done creating it. This flushes output to disk. You can then open it again where you need to read it. E.g.
{
auto f = TFile::Open(...);
/* do some processing */
f->Close();
}
{
auto f2 = TFile::Open(...);
/*Do new processing*/
f->Close();
}
Cheers,
Kim
Hello and thank you for the response. I attach the relevant code. By weights I mean those that are created by TMVA to classify if an event is signal like or background like. What I want this code to to is:
Take the outptut of the tmva application (some of the variables) and save it in a ROOT file, in a branch.
I hope that I helped somewhat.
Thank you in advance.
Cheers
GeorgeSingalClassificationApplication_w2.C (31.2 KB)
Where do you encounter the problem?
In your code you only write to the tree and to a file, so I don’t see where your error can arise.
TFile *file_in = new TFile("/tmp/gbillis/post_TMVA_wrong_inpeak.root","RECREATE");
file_in->cd();
postTMVA_inpeak->Write(); // Read error here?
file_in->Close();
Cheers,
Kim