23 we_own_write_ =
false;
37 if (we_own_write_ && write_)
delete write_;
43 myStr <<
"\nL1T EndCap Parameters \n" << std::endl;
47 if (
mode != 15)
continue;
49 auto it = read_->forest_map_.find(
mode);
50 if (it == read_->forest_map_.end())
53 const DForest & dforest = read_->forest_coll_[it->second];
56 for (
auto itree = dforest.begin(); itree != dforest.end(); itree++){
58 cout <<
"DUMP: ***** Tree " << count <<
" with size " << tree.size() <<
"\n";
76 assert(write_->forest_coll_.size() == 0);
78 for(
int i =0;
i < (int) modes.size();
i++){
83 write_->forest_coll_.push_back(
DForest());
84 DForest & dforest = write_->forest_coll_[
i];
85 write_->forest_map_[
mode]=
i;
88 ss << dirname <<
"/" <<
mode;
92 for(
int j=0;
j < ntrees;
j++){
94 ss << directory <<
"/" <<
j <<
".xml";
100 dforest.push_back(
DTree());
101 DTree & dtree = dforest[
j];
106 TXMLEngine* xml =
new TXMLEngine();
115 XMLNodePointer_t mainnode = xml->DocGetRootElement(xmldoc);
117 loadTreeFromXMLRecursive(xml, mainnode, dtree, 0);
121 xml->FreeDoc(xmldoc);
129 auto it = read_->forest_map_.find(mode);
130 if (it == read_->forest_map_.end())
133 const DForest & dforest = read_->forest_coll_[it->second];
136 for (
auto itree = dforest.begin(); itree != dforest.end(); itree++){
137 double x = evalTreeRecursive(data, *itree, 0);
153 XMLAttrPointer_t attr = xml->GetFirstAttr(xnode);
154 std::vector<std::string> splitInfo(3);
155 for(
unsigned int i=0;
i<3;
i++)
157 splitInfo[
i] = xml->GetAttrValue(attr);
158 attr = xml->GetNextAttr(attr);
162 std::stringstream converter;
167 converter << splitInfo[0];
168 converter >> splitVar;
172 converter << splitInfo[1];
173 converter >> splitVal;
177 converter << splitInfo[2];
185 tree[
index].splitVar = splitVar;
186 tree[
index].splitVal = splitVal;
187 tree[
index].fitVal = fitVal;
190 XMLNodePointer_t xleft = xml->GetChild(xnode);
191 XMLNodePointer_t xright = xml->GetNext(xleft);
193 assert( ((xleft!=0)&&(xright!=0)) || ((xleft==0)&&(xright==0)) );
197 if(xleft == 0 || xright == 0)
return;
200 tree[
index].ileft = tree.size();
206 loadTreeFromXMLRecursive(xml, xleft, tree, tree[index].ileft);
207 loadTreeFromXMLRecursive(xml, xright, tree, tree[index].iright);
225 return evalTreeRecursive(data, tree, node.
ileft);
228 return evalTreeRecursive(data, tree, node.
iright);
void loadTreeFromXMLRecursive(TXMLEngine *xml, XMLNodePointer_t xnode, DTree &tree, unsigned index)
static ForestHelper * readAndWriteFromEventSetup(const L1TMuonEndCapForest *es)
void initializeFromXML(const char *dirname, const std::vector< int > &modes, int ntrees)
T x() const
Cartesian x coordinate.
L1TMuonEndCapForest::DTree DTree
ForestHelper(L1TMuonEndCapForest *w)
void print(std::ostream &) const
L1TMuonEndCapForest::DForest DForest
double evalTreeRecursive(const std::vector< double > &data, const DTree &tree, int index) const
char data[epos_bytes_allocation]
double evaluate(int mode, const std::vector< double > &data) const
static const ForestHelper * readFromEventSetup(const L1TMuonEndCapForest *es)