#include <PhysicsTools/MVAComputer/interface/TreeReader.h>
Public Member Functions | |
void | addBranch (TBranch *branch, AtomicId name=AtomicId(), bool opt=true) |
void | addBranch (const std::string &expression, AtomicId name=AtomicId(), bool opt=true) |
template<typename T> | |
void | addMulti (AtomicId name, const std::vector< T > *value) |
template<typename T> | |
void | addSingle (AtomicId name, const T *value, bool opt=false) |
void | addTypeMulti (AtomicId name, const void *value, char type) |
void | addTypeSingle (AtomicId name, const void *value, char type, bool opt) |
void | automaticAdd (bool skipTarget=false, bool skipWeight=false) |
double | fill (const MVAComputer *mva) |
uint64_t | loop (const MVAComputer *mva) |
TreeReader & | operator= (const TreeReader &orig) |
void | reset () |
void | setOptional (AtomicId name, bool opt, double optVal=kOptVal) |
void | setTree (TTree *tree) |
TreeReader (TTree *tree, bool skipTarget=false, bool skipWeight=false) | |
TreeReader (const TreeReader &orig) | |
TreeReader () | |
void | update () |
virtual | ~TreeReader () |
Static Public Attributes | |
static const double | kOptVal = -999.0 |
Private Attributes | |
std::vector< std::pair< void *, std::vector< Bool_t > > > | multiBool |
std::vector< std::pair< void *, std::vector< Double_t > > > | multiDouble |
std::vector< std::pair< void *, std::vector< Float_t > > > | multiFloat |
std::vector< std::pair< void *, std::vector< Int_t > > > | multiInt |
std::vector< Bool > | singleBool |
std::vector< Double_t > | singleDouble |
std::vector< Float_t > | singleFloat |
std::vector< Int_t > | singleInt |
TTree * | tree |
bool | upToDate |
std::map< AtomicId, Value > | valueMap |
Variable::ValueList | values |
Friends | |
class | Value |
Classes | |
struct | Bool |
class | Value |
Definition at line 19 of file TreeReader.h.
PhysicsTools::TreeReader::TreeReader | ( | ) |
PhysicsTools::TreeReader::TreeReader | ( | const TreeReader & | orig | ) |
Definition at line 30 of file TreeReader.cc.
References operator=().
00031 { 00032 this->operator = (orig); 00033 }
PhysicsTools::TreeReader::TreeReader | ( | TTree * | tree, | |
bool | skipTarget = false , |
|||
bool | skipWeight = false | |||
) |
Definition at line 35 of file TreeReader.cc.
References automaticAdd().
00035 : 00036 tree(tree), upToDate(false) 00037 { 00038 automaticAdd(skipTarget, skipWeight); 00039 }
PhysicsTools::TreeReader::~TreeReader | ( | ) | [virtual] |
void PhysicsTools::TreeReader::addBranch | ( | TBranch * | branch, | |
AtomicId | name = AtomicId() , |
|||
bool | opt = true | |||
) |
Definition at line 89 of file TreeReader.cc.
References addTypeMulti(), addTypeSingle(), lat::endl(), Exception, python::Node::leaf, and valueMap.
00090 { 00091 TString branchName = branch->GetName(); 00092 if (!name) 00093 name = (const char*)branchName; 00094 00095 TLeaf *leaf = dynamic_cast<TLeaf*>(branch->GetLeaf(branchName)); 00096 if (!leaf) 00097 throw cms::Exception("InvalidBranch") 00098 << "Tree branch \"" << branchName << "\" has no leaf." 00099 << std::endl; 00100 00101 TString typeName = leaf->GetTypeName(); 00102 char typeId = 0; 00103 bool multi = false; 00104 if (typeName == "Double_t" || typeName == "doubl") 00105 typeId = 'D'; 00106 else if (typeName == "Float_t" || typeName == "float") 00107 typeId = 'F'; 00108 else if (typeName == "Int_t" || typeName == "int") 00109 typeId = 'I'; 00110 else if (typeName == "Bool_t" || typeName == "bool") 00111 typeId = 'B'; 00112 else { 00113 multi = true; 00114 if (typeName == "vector<double>" || 00115 typeName == "Vector<Double_t>") 00116 typeId = 'D'; 00117 else if (typeName == "vector<float>" || 00118 typeName == "Vector<Float_t>") 00119 typeId = 'F'; 00120 else if (typeName == "vector<int>" || 00121 typeName == "Vector<Int_t>") 00122 typeId = 'I'; 00123 else if (typeName == "vector<bool>" || 00124 typeName == "Vector<Bool_t>") 00125 typeId = 'B'; 00126 } 00127 00128 if (!typeId) 00129 throw cms::Exception("InvalidBranch") 00130 << "Tree branch \"" << branchName << "\" is of " 00131 "unsupported type \"" << typeName << "\"." 00132 << std::endl; 00133 00134 if (multi) 00135 addTypeMulti(name, 0, typeId); 00136 else 00137 addTypeSingle(name, 0, typeId, opt); 00138 00139 valueMap[name].setBranchName(branch->GetName()); 00140 }
void PhysicsTools::TreeReader::addBranch | ( | const std::string & | expression, | |
AtomicId | name = AtomicId() , |
|||
bool | opt = true | |||
) |
Definition at line 72 of file TreeReader.cc.
References lat::endl(), Exception, and tree.
Referenced by automaticAdd().
00074 { 00075 if (!tree) 00076 throw cms::Exception("NoTreeAvailable") 00077 << "No TTree set in TreeReader::addBranch." 00078 << std::endl; 00079 00080 TBranch *branch = tree->GetBranch(expression.c_str()); 00081 if (!branch) 00082 throw cms::Exception("BranchMissing") 00083 << "Tree branch \"" << expression << "\" missing." 00084 << std::endl; 00085 00086 addBranch(branch, name, opt); 00087 }
void PhysicsTools::TreeReader::addMulti | ( | AtomicId | name, | |
const std::vector< T > * | value | |||
) | [inline] |
void PhysicsTools::TreeReader::addSingle | ( | AtomicId | name, | |
const T * | value, | |||
bool | opt = false | |||
) | [inline] |
Referenced by PhysicsTools::TreeTrainer::addTree().
Definition at line 199 of file TreeReader.cc.
References lat::endl(), Exception, index, int, multiBool, multiDouble, multiFloat, multiInt, upToDate, Value, and valueMap.
Referenced by addBranch().
00200 { 00201 std::map<AtomicId, Value>::const_iterator pos = valueMap.find(name); 00202 if (pos != valueMap.end()) 00203 throw cms::Exception("DuplicateVariable") 00204 << "Duplicate Variable \"" << name << "\"." 00205 << std::endl; 00206 00207 if (type != 'D' && type != 'F' && type != 'I' && type != 'B') 00208 throw cms::Exception("InvalidType") 00209 << "Unsupported type '" << type << "' in call to" 00210 "TreeReader::addTypeMulti." << std::endl; 00211 00212 int index = -1; 00213 if (!value) { 00214 switch(type) { 00215 case 'D': 00216 index = (int)multiDouble.size(); 00217 multiDouble.push_back(makeMulti<Double_t>()); 00218 break; 00219 case 'F': 00220 index = (int)multiFloat.size(); 00221 multiFloat.push_back(makeMulti<Float_t>()); 00222 break; 00223 case 'I': 00224 index = (int)multiInt.size(); 00225 multiInt.push_back(makeMulti<Int_t>()); 00226 break; 00227 case 'B': 00228 index = (int)multiBool.size(); 00229 multiBool.push_back(makeMulti<Bool_t>()); 00230 break; 00231 } 00232 } 00233 00234 valueMap[name] = Value(index, true, false, type); 00235 if (value) 00236 valueMap[name].setPtr(value); 00237 00238 upToDate = false; 00239 }
void PhysicsTools::TreeReader::addTypeSingle | ( | AtomicId | name, | |
const void * | value, | |||
char | type, | |||
bool | opt | |||
) |
Definition at line 153 of file TreeReader.cc.
References lat::endl(), Exception, index, int, singleBool, singleDouble, singleFloat, singleInt, upToDate, Value, and valueMap.
Referenced by addBranch().
00154 { 00155 std::map<AtomicId, Value>::const_iterator pos = valueMap.find(name); 00156 if (pos != valueMap.end()) 00157 throw cms::Exception("DuplicateVariable") 00158 << "Duplicate Variable \"" << name << "\"." 00159 << std::endl; 00160 00161 if (type != 'D' && type != 'F' && type != 'I' && type != 'B') 00162 throw cms::Exception("InvalidType") 00163 << "Unsupported type '" << type << "' in call to" 00164 "TreeReader::addTypeSingle." << std::endl; 00165 00166 int index = -1; 00167 if (!value) { 00168 switch(type) { 00169 case 'D': 00170 index = (int)singleDouble.size(); 00171 singleDouble.push_back(Double_t()); 00172 break; 00173 case 'F': 00174 index = (int)singleFloat.size(); 00175 singleFloat.push_back(Float_t()); 00176 break; 00177 case 'I': 00178 index = (int)singleInt.size(); 00179 singleInt.push_back(Int_t()); 00180 break; 00181 case 'B': 00182 index = (int)singleBool.size(); 00183 singleBool.push_back(Bool()); 00184 break; 00185 } 00186 } 00187 00188 valueMap[name] = Value(index, false, opt, type); 00189 if (value) 00190 valueMap[name].setPtr(value); 00191 00192 upToDate = false; 00193 }
Definition at line 241 of file TreeReader.cc.
References addBranch(), lat::endl(), Exception, iter, VarParsing::obj, and tree.
Referenced by TreeReader().
00242 { 00243 if (!tree) 00244 throw cms::Exception("NoTreeAvailable") 00245 << "No TTree set in TreeReader::automaticAdd." 00246 << std::endl; 00247 00248 TIter iter(tree->GetListOfBranches()); 00249 TObject *obj; 00250 while((obj = iter())) { 00251 TBranch *branch = dynamic_cast<TBranch*>(obj); 00252 if (!branch) 00253 continue; 00254 00255 if (skipTarget && 00256 !std::strcmp(branch->GetName(), "__TARGET__")) 00257 continue; 00258 00259 if (skipWeight && 00260 !std::strcmp(branch->GetName(), "__WEIGHT__")) 00261 continue; 00262 00263 addBranch(branch); 00264 } 00265 }
double PhysicsTools::TreeReader::fill | ( | const MVAComputer * | mva | ) |
Definition at line 318 of file TreeReader.cc.
References PhysicsTools::Variable::ValueList::clear(), PhysicsTools::MVAComputer::eval(), iter, HLT_VtxMuL3::result, valueMap, and values.
Referenced by loop().
00319 { 00320 for(std::map<AtomicId, Value>::const_iterator iter = valueMap.begin(); 00321 iter != valueMap.end(); iter++) { 00322 iter->second.fill(iter->first, this); 00323 } 00324 00325 double result = mva->eval(values); 00326 values.clear(); 00327 00328 return result; 00329 }
uint64_t PhysicsTools::TreeReader::loop | ( | const MVAComputer * | mva | ) |
Definition at line 298 of file TreeReader.cc.
References lat::endl(), python::tagInventory::entries, Exception, fill(), tree, update(), and upToDate.
Referenced by PhysicsTools::TreeTrainer::iteration().
00299 { 00300 if (!tree) 00301 throw cms::Exception("NoTreeAvailable") 00302 << "No TTree set in TreeReader::automaticAdd." 00303 << std::endl; 00304 00305 if (!upToDate) 00306 update(); 00307 00308 Long64_t entries = tree->GetEntries(); 00309 for(Long64_t entry = 0; entry < entries; entry++) 00310 { 00311 tree->GetEntry(entry); 00312 fill(mva); 00313 } 00314 00315 return entries; 00316 }
TreeReader & PhysicsTools::TreeReader::operator= | ( | const TreeReader & | orig | ) |
Definition at line 45 of file TreeReader.cc.
References multiBool, multiDouble, multiFloat, multiInt, reset(), singleBool, singleDouble, singleFloat, singleInt, tree, and valueMap.
Referenced by TreeReader().
00046 { 00047 reset(); 00048 00049 tree = orig.tree; 00050 00051 multiDouble.resize(orig.multiDouble.size()); 00052 multiFloat.resize(orig.multiFloat.size()); 00053 multiInt.resize(orig.multiInt.size()); 00054 multiBool.resize(orig.multiBool.size()); 00055 00056 singleDouble.resize(orig.singleDouble.size()); 00057 singleFloat.resize(orig.singleFloat.size()); 00058 singleInt.resize(orig.singleInt.size()); 00059 singleBool.resize(orig.singleBool.size()); 00060 00061 valueMap = orig.valueMap; 00062 00063 return *this; 00064 }
Definition at line 267 of file TreeReader.cc.
References multiBool, multiDouble, multiFloat, multiInt, singleBool, singleDouble, singleFloat, singleInt, upToDate, and valueMap.
Referenced by operator=().
00268 { 00269 multiDouble.clear(); 00270 multiFloat.clear(); 00271 multiInt.clear(); 00272 multiBool.clear(); 00273 00274 singleDouble.clear(); 00275 singleFloat.clear(); 00276 singleInt.clear(); 00277 singleBool.clear(); 00278 00279 valueMap.clear(); 00280 00281 upToDate = false; 00282 }
Definition at line 142 of file TreeReader.cc.
References lat::endl(), and valueMap.
00143 { 00144 std::map<AtomicId, Value>::iterator pos = valueMap.find(name); 00145 if (pos == valueMap.end()) 00146 throw cms::Exception("UnknownVariable") 00147 << "Variable \"" <<name << "\" is not known to the " 00148 "TreeReader." << std::endl; 00149 00150 pos->second.setOpt(opt, optVal); 00151 }
void PhysicsTools::TreeReader::setTree | ( | TTree * | tree | ) |
Definition at line 284 of file TreeReader.cc.
References lat::endl(), Exception, iter, tree, upToDate, and valueMap.
Referenced by loop().
00285 { 00286 if (!tree) 00287 throw cms::Exception("NoTreeAvailable") 00288 << "No TTree set in TreeReader::automaticAdd." 00289 << std::endl; 00290 00291 for(std::map<AtomicId, Value>::iterator iter = valueMap.begin(); 00292 iter != valueMap.end(); iter++) 00293 iter->second.update(this); 00294 00295 upToDate = true; 00296 }
friend class Value [friend] |
const double PhysicsTools::TreeReader::kOptVal = -999.0 [static] |
Definition at line 53 of file TreeReader.h.
std::vector<std::pair<void*, std::vector<Bool_t> > > PhysicsTools::TreeReader::multiBool [private] |
Definition at line 67 of file TreeReader.h.
Referenced by addTypeMulti(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<std::pair<void*, std::vector<Double_t> > > PhysicsTools::TreeReader::multiDouble [private] |
Definition at line 64 of file TreeReader.h.
Referenced by addTypeMulti(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<std::pair<void*, std::vector<Float_t> > > PhysicsTools::TreeReader::multiFloat [private] |
Definition at line 65 of file TreeReader.h.
Referenced by addTypeMulti(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<std::pair<void*, std::vector<Int_t> > > PhysicsTools::TreeReader::multiInt [private] |
Definition at line 66 of file TreeReader.h.
Referenced by addTypeMulti(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<Bool> PhysicsTools::TreeReader::singleBool [private] |
Definition at line 72 of file TreeReader.h.
Referenced by addTypeSingle(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<Double_t> PhysicsTools::TreeReader::singleDouble [private] |
Definition at line 69 of file TreeReader.h.
Referenced by addTypeSingle(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<Float_t> PhysicsTools::TreeReader::singleFloat [private] |
Definition at line 70 of file TreeReader.h.
Referenced by addTypeSingle(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<Int_t> PhysicsTools::TreeReader::singleInt [private] |
Definition at line 71 of file TreeReader.h.
Referenced by addTypeSingle(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
TTree* PhysicsTools::TreeReader::tree [private] |
Definition at line 56 of file TreeReader.h.
Referenced by addBranch(), automaticAdd(), loop(), operator=(), update(), and PhysicsTools::TreeReader::Value::update().
bool PhysicsTools::TreeReader::upToDate [private] |
Definition at line 106 of file TreeReader.h.
Referenced by addTypeMulti(), addTypeSingle(), loop(), reset(), setTree(), and update().
std::map<AtomicId, Value> PhysicsTools::TreeReader::valueMap [private] |
Definition at line 104 of file TreeReader.h.
Referenced by addBranch(), addTypeMulti(), addTypeSingle(), fill(), operator=(), reset(), setOptional(), and update().
Definition at line 105 of file TreeReader.h.
Referenced by fill(), and PhysicsTools::TreeReader::Value::fill().