Problem in TMVACrossvalidationApplication.C

Dear All,

I was training my BDTG with TMVACrossValidation.C with two fold and it was successful. But when I went to TMVACrossValidationApplication.C to save BDTG variable in the output I am getting output root file but with zero entries.
Could you please check once and let me know what is missing.
All files are in drive(drive). Signal root file is 4230_anasig_mc_001.root and background root file is 4230_pppi0_inc_mc_001.root.

Thanks

Hello @souvik,

I will call @moneta, the TMVA export to have a look here.

In the mean time, could it be that your tree doesn’t read any inputs? It looks like you are trying both to read and write from and to the tree called “tr”.
Wouldn’t you typically read from some kind of input tree and write to a different output tree? If that’s the case, your main loop over events wouldn’t run, because it runs over an empty tree. You could check if your BDTG histogram gets filled.

Sorry for my late response.
Do you mean instaed of running the loop over tr->GetEntries() I should run over track->GetEntries(), is that?

I still end up getting the error:

warning: invalid memory pointer passed to a callee:
for (Long64_t ievt = 0; ievt < track->GetEntries(); ievt++) {

Yes, I mean to load events from the tree that you filled before:
It would be track->GetEntries() for the number of events, but also track->GetEntry(i), because you actually have to load each event.

Yes, off course track->GetEntry(ievt) is there but still there is same problem.

It’s hard to diagnose this without being able to run it. If this line:

for (Long64_t ievt = 0; ievt < track->GetEntries(); ievt++) {

creates the invalid pointer message, the pointer track seems to be invalid. Before you get to this line, could you verify that the tree is indeed what you think, e.g. track->Print(). You should see all branches that you expect in this tree.

Then, I would check that you can read from the track tree, and evaluate the MVA.

Only if the two above work, I would start creating the output tree and start to write.

It prints well. PFA.

OK, that looks good. So we have a tree in memory that can be read. The next step would be to loop through that tree, and see if the branches can be read.

Inside the loop it is printing only one value of the variable then it is getting crashed.
I don’t know why but does this because these variable (ergShwr, angShwr and phiShwr) are stored as vectors.

I had another look at the attached script, and I’m wondering about the TChain, why it’s cloned, and filled with values. If I see this correctly, you want to use some variables from the TChain in the crossvalidation, and in addition you want to set the eventID, which is not in the tree.

The easiest way I see would be to open the TChain, connect the branches that you want to read, and just set the eventID manually:

  for (Long64_t ievt = 0; ievt < nevents_sig; ievt++) {
    eventID = ievt;

in this way, you avoid all complications with cloning the tree and adding a new branch to it.

I also noticed that you are reading arrays of floats. Those arrays cannot be bound to a single float, so that’s probably why the reading crashes. What you need instead:

 74   constexpr unsigned int maxLength = 100;
 75   int shwrI;
 76   float ergShwr[maxLength];

 80   std::cout << track->SetBranchAddress("shwrI",                   &shwrI) << " ";
 81   std::cout << track->SetBranchAddress("ergShwr",                 &ergShwr) << " ";

and when you read:

123     track->GetEntry(ievt);
124     uservar13 = ievt;
125     if (ievt < 10) {
126       std::cout << "shwrI: " << shwrI << ", ergShwr:";
127       for (int j = 0; j < shwrI; ++j) std::cout << ergShwr[j] << " ";
128       std::cout << "\n";
129     }

I attach a minimal example based on your macro, where only two branches are read. Using the attached macro and your input file, I manage to print the first 10 events:

shwrI: 1, ergShwr:0.229374 
Evaluating MVA: Processing event... 0
shwrI: 1, ergShwr:0.0484161 
shwrI: 2, ergShwr:0.235631 0.21835 
shwrI: 3, ergShwr:0.620256 0.432888 0.0262622 
shwrI: 7, ergShwr:1.14561 1.12485 0.170409 0.156405 0.125159 0.0469457 0.0455204 
shwrI: 2, ergShwr:0.11881 0.109571 
shwrI: 1, ergShwr:1.63838 
shwrI: 0, ergShwr:
shwrI: 2, ergShwr:0.386776 0.0551964 
shwrI: 2, ergShwr:0.0784447 0.0305489 

TMVACrossValidationApplication.C (7.3 KB)