Storing TTreeReaderValues in std::map

Hi Philippe,

Thanks again for your help!
Indeed, that was a simple error to fix on my part.

Thanks,

Dan

PS If anyone comes across the same problem, here is how I remedied the issue (everything compiles and appears to run correctly):

[code]#include “TROOT.h”
#include “TFile.h”
#include “TTree.h”
#include “TH1.h”
#include “TSystem.h”
#include “TMath.h”
#include “TTreeReader.h”
#include “TTreeReaderValue.h”
#include “TTreeReaderArray.h”

#include
#include
#include <stdio.h>
#include
#include

// – Load ROOT File
auto file = TFile::Open(“data.root”); // simple root file

// – Create a TTreeReader for the “nominal” tree
TTreeReader myReader(“nominal”, file);

// – Access/store branches with map
std::vectorstd::string variables = {“ht”};
TTreeReaderValue ht(myReader, “HT”);
std::map<std::string,TTreeReaderValue * > branch_map;
branch_map[“ht”] = &ht;

// – Access branches with if statement
bool some_bool(true); // this is set to true/false based on the root file
TTreeReaderValue * met_met = NULL;
if (some_bool)
met_met = new TTreeReaderValue(myReader, “met_met”);

// – Access branches in standard way
TTreeReaderValue lepton_pt(myReader, “lepton_pt”);

while (myReader.Next()) {

std::cout << " lepton pT = " << *lepton_pt << std::endl;     // nominal access
std::cout << " MET value = " << *(*met_met) << std::endl;  // if statement access

for (auto variable : variables){
std::cout << " >>> Variable " << variable << " = " << *(*branch_map.at(variable)) << std::endl;
}
}
delete met_met;[/code]