1 |
dkralph |
1.1 |
#include "TFile.h"
|
2 |
|
|
#include "TNtuple.h"
|
3 |
|
|
#include "TMath.h"
|
4 |
|
|
|
5 |
|
|
#include "TMVA/Factory.h"
|
6 |
|
|
#include "TMVA/Tools.h"
|
7 |
|
|
#include "TMVA/Config.h"
|
8 |
|
|
|
9 |
|
|
#include <unistd.h>
|
10 |
|
|
#include <iostream>
|
11 |
|
|
#include <fstream>
|
12 |
|
|
#include <string.h>
|
13 |
|
|
#include <map>
|
14 |
|
|
#include <cassert>
|
15 |
|
|
|
16 |
dkralph |
1.2 |
#include "KinematicsStruct.h"
|
17 |
|
|
#include "HistHeaders.h"
|
18 |
|
|
|
19 |
dkralph |
1.1 |
using namespace std;
|
20 |
|
|
|
21 |
|
|
void setFractions(float mH, float mH_lo, float mH_hi, float &frac_lo, float &frac_hi);
|
22 |
|
|
void setNevents(int nEvtMax, int nSigTrainMax, int nSigTestMax, int nBkgTrainMax, int nBkgTestMax, TString &nSig, TString &nBkg);
|
23 |
|
|
|
24 |
|
|
int main(int argc, char** argv) {
|
25 |
|
|
|
26 |
|
|
if( argc < 7 ) {
|
27 |
|
|
cerr << "usage: makeBDTWeights.exe <config> <outputrootfile> <weightname> <varstring> <mH> [wL] [wH] [mH_lo] [mH_hi]" << endl;
|
28 |
|
|
cerr << "\t... where [wL,wH] are the requested mass window and [mH_lo,mH_hi] are used for interpolation" << endl;
|
29 |
|
|
return 1;
|
30 |
|
|
}
|
31 |
|
|
cout << "argc: " << argc << endl;
|
32 |
|
|
for(int iarg=0; iarg<argc; iarg++)
|
33 |
|
|
cout << "argv[" << iarg << "]: " << argv[iarg] << endl;
|
34 |
|
|
|
35 |
|
|
char * config = argv[1];
|
36 |
|
|
cout << "config: " << config << endl;
|
37 |
|
|
|
38 |
|
|
// TString ntupledir;
|
39 |
|
|
vector<TString> classes,fileNames;
|
40 |
|
|
vector<double> fileFracs,fileMasses;
|
41 |
|
|
vector<TFile*> inFiles;
|
42 |
|
|
vector<TTree*> inTrees;
|
43 |
|
|
bool multiclass=false;
|
44 |
|
|
bool multisigs=false;
|
45 |
dkralph |
1.2 |
bool noFakeTest=false;
|
46 |
dkralph |
1.1 |
TString NTrees(""),NNodesMax(""),Shrinkage(""),nCuts("");
|
47 |
dkralph |
1.2 |
int nMax=1000000;
|
48 |
dkralph |
1.1 |
ifstream ifs(config);
|
49 |
|
|
assert(ifs.is_open());
|
50 |
|
|
string line;
|
51 |
|
|
while(getline(ifs,line)) {
|
52 |
|
|
if(line[0]=='#') continue;
|
53 |
|
|
stringstream ss(line);
|
54 |
|
|
if(line[0]=='^') {
|
55 |
|
|
TString dummy;
|
56 |
|
|
// if(TString(line).Contains("^ntupledir")) ss >> dummy >> ntupledir;
|
57 |
|
|
if(TString(line).Contains("^multiclass")) { cout << "multiclass: true" << endl; multiclass = true; }
|
58 |
|
|
if(TString(line).Contains("^multisigs")) { cout << "multisigs: true" << endl; multisigs = true; }
|
59 |
dkralph |
1.2 |
if(TString(line).Contains("^noFakeTest")) { cout << "noFakeTest: true" << endl; noFakeTest = true; } // use all the events for training... we have an orthogonal sample for testing, anyway, and we need the stat
|
60 |
dkralph |
1.1 |
if(TString(line).Contains("^NTrees")) ss >> dummy >> NTrees;
|
61 |
|
|
if(TString(line).Contains("^NNodesMax")) ss >> dummy >> NNodesMax;
|
62 |
|
|
if(TString(line).Contains("^Shrinkage")) ss >> dummy >> Shrinkage;
|
63 |
|
|
if(TString(line).Contains("^nCuts")) ss >> dummy >> nCuts;
|
64 |
|
|
if(TString(line).Contains("^nMax")) ss >> dummy >> nMax;
|
65 |
|
|
continue;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
TString cls,fname;
|
69 |
|
|
double frac,fileMass;
|
70 |
|
|
ss >> cls >> frac >> fname >> fileMass;
|
71 |
|
|
assert(cls=="sig" || cls=="sig2" || cls=="sig3" || cls=="bkg");
|
72 |
|
|
classes.push_back(cls);
|
73 |
|
|
fileNames.push_back(/*ntupledir+"/"+*/fname);
|
74 |
|
|
fileFracs.push_back(frac);
|
75 |
|
|
fileMasses.push_back(fileMass);
|
76 |
|
|
cout << " pushing back: " << cls << " " << setw(12) << frac << " " << fname << " " << fileMass << endl;
|
77 |
|
|
inFiles.push_back(TFile::Open(fileNames.back()));
|
78 |
|
|
if(!inFiles.back()->IsOpen()) {
|
79 |
|
|
cout << fileNames.back() << " not open!" << endl;
|
80 |
|
|
assert(0);
|
81 |
|
|
}
|
82 |
|
|
inTrees.push_back((TTree*)inFiles.back()->Get("zznt"));
|
83 |
|
|
assert(inTrees.back());
|
84 |
|
|
}
|
85 |
|
|
ifs.close();
|
86 |
|
|
// if(multisigs) assert(multiclass);
|
87 |
|
|
|
88 |
|
|
char * outputrootfile = argv[2];
|
89 |
|
|
char * weightname = argv[3];
|
90 |
|
|
char * varstring = argv[4];
|
91 |
|
|
float mH = strtof(argv[5],NULL);
|
92 |
|
|
float wH=900, wL=100;
|
93 |
|
|
if( argc > 6 ) {
|
94 |
|
|
wL = strtof(argv[6], NULL);
|
95 |
|
|
wH = strtof(argv[7], NULL);
|
96 |
|
|
}
|
97 |
|
|
float mH_lo=0,mH_hi=0;
|
98 |
|
|
float frac_lo=1,frac_hi=1;
|
99 |
|
|
map<double,double> mH_fracs;
|
100 |
|
|
mH_fracs[-1] = 1; // this means zz
|
101 |
|
|
assert( argc > 8);
|
102 |
|
|
mH_lo = strtof(argv[8],NULL);
|
103 |
|
|
mH_hi = strtof(argv[9],NULL);
|
104 |
|
|
if(mH_lo!=0 && mH_hi!=0) {
|
105 |
|
|
// set the fraction to use for each input file, with more events from the closer mass point
|
106 |
|
|
// NOTE: we only use these fractions if the fraction from the config file is -1
|
107 |
|
|
setFractions(mH,mH_lo,mH_hi,frac_lo,frac_hi);
|
108 |
|
|
mH_fracs[mH_lo] = frac_lo;
|
109 |
|
|
mH_fracs[mH_hi] = frac_hi;
|
110 |
|
|
} else {
|
111 |
|
|
mH_fracs[mH] = 1;
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
cerr
|
115 |
|
|
<< "name: " << weightname << endl
|
116 |
|
|
<< "output: " << outputrootfile << endl
|
117 |
|
|
<< "variables: " << varstring << endl
|
118 |
|
|
<< "mH: " << mH << endl
|
119 |
|
|
<< "mass window:" << endl
|
120 |
|
|
<< " wL: " << wL << endl
|
121 |
|
|
<< " wH: " << wH << endl
|
122 |
|
|
<< "masses from which to interpolate:" << endl
|
123 |
|
|
<< " mH_lo: " << mH_lo << endl
|
124 |
|
|
<< " mH_hi: " << mH_hi << endl
|
125 |
|
|
<< "weights for interpolation:" << endl
|
126 |
|
|
<< " frac_lo: " << frac_lo << endl
|
127 |
|
|
<< " frac_hi: " << frac_hi << endl
|
128 |
|
|
<< endl;
|
129 |
|
|
|
130 |
|
|
TFile * outputFile = new TFile(outputrootfile, "RECREATE");
|
131 |
|
|
|
132 |
|
|
map<string,bool> varmap;
|
133 |
|
|
char * dovar = strtok(varstring, ":");
|
134 |
|
|
if( dovar != NULL ) varmap[string(dovar)]=true;
|
135 |
|
|
while( (dovar = strtok(NULL, ":")) != NULL ) {
|
136 |
|
|
varmap[string(dovar)]=true;
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
char name[256];
|
140 |
|
|
sprintf(name, weightname );
|
141 |
|
|
TMVA::Tools::Instance();
|
142 |
|
|
TString facStr("!V:!Silent:!DrawProgressBar");
|
143 |
|
|
if(multiclass) facStr = facStr+":AnalysisType=multiclass";
|
144 |
|
|
TMVA::Factory* factory = new TMVA::Factory( name, outputFile, facStr );
|
145 |
dkralph |
1.2 |
// if( varmap[string("costheta1" )] ) factory->AddVariable( "costheta1", 'F',-1, 1);
|
146 |
|
|
// if( varmap[string("costheta2" )] ) factory->AddVariable( "costheta2", 'F',-1, 1);
|
147 |
|
|
// if( varmap[string("costhetastar" )] ) factory->AddVariable( "costhetastar", 'F',-1, 1 );
|
148 |
|
|
// if( varmap[string("Phi" )] ) factory->AddVariable( "Phi", 'F',-TMath::Pi(), TMath::Pi() );
|
149 |
|
|
// if( varmap[string("Phi1" )] ) factory->AddVariable( "Phi1", 'F',-TMath::Pi(), TMath::Pi() );
|
150 |
|
|
if( varmap[string("costheta1" )] ) factory->AddVariable("costheta1", 'F');
|
151 |
|
|
if( varmap[string("costheta2" )] ) factory->AddVariable("costheta2", 'F');
|
152 |
|
|
if( varmap[string("costhetastar" )] ) factory->AddVariable("costhetastar", 'F');
|
153 |
|
|
if( varmap[string("Phi" )] ) factory->AddVariable("Phi", 'F');
|
154 |
|
|
if( varmap[string("Phi1" )] ) factory->AddVariable("Phi1", 'F');
|
155 |
|
|
if( varmap[string("mZ1" )] ) factory->AddVariable("mZ1", 'F');
|
156 |
|
|
if( varmap[string("mZ2" )] ) factory->AddVariable("mZ2", 'F');
|
157 |
|
|
if( varmap[string("pt4l" )] ) factory->AddVariable("ZZpt/m4l", 'F');
|
158 |
|
|
if( varmap[string("zzdotz1" )] ) factory->AddVariable("ZZdotZ1/(m4l*mZ1)", 'F');
|
159 |
|
|
if( varmap[string("zzdotz2" )] ) factory->AddVariable("ZZdotZ2/(m4l*mZ2)", 'F');
|
160 |
|
|
// if( varmap[string("dphi1" )] ) factory->AddVariable("ZZptCosDphiZ1pt", 'F', -TMath::Pi(), TMath::Pi() );
|
161 |
|
|
// if( varmap[string("dphi2" )] ) factory->AddVariable("ZZptCosDphiZ2pt", 'F', -TMath::Pi(), TMath::Pi() );
|
162 |
|
|
if( varmap[string("dphi1" )] ) factory->AddVariable("ZZptCosDphiZ1pt", 'F');
|
163 |
|
|
if( varmap[string("dphi2" )] ) factory->AddVariable("ZZptCosDphiZ2pt", 'F');
|
164 |
|
|
if( varmap[string("Z1pt" )] ) factory->AddVariable("Z1pt/m4l", 'F');
|
165 |
|
|
if( varmap[string("Z2pt" )] ) factory->AddVariable("Z2pt/m4l", 'F');
|
166 |
|
|
if( varmap[string("y4l" )] ) factory->AddVariable("ZZy", 'F');
|
167 |
|
|
if( varmap[string("nJets" )] ) factory->AddVariable("nJets", 'F');
|
168 |
|
|
if( varmap[string("mjj" )] ) factory->AddVariable("mjj", 'F');
|
169 |
|
|
if( varmap[string("dEta" )] ) factory->AddVariable("dEta", 'F');
|
170 |
|
|
if( varmap[string("etaProd" )] ) factory->AddVariable("etaProd", 'F');
|
171 |
|
|
if( varmap[string("dphiJ1HiPtZ" )] ) factory->AddVariable("dphiJ1HiPtZ", 'F');
|
172 |
|
|
if( varmap[string("dphiJ1LoPtZ" )] ) factory->AddVariable("dphiJ1LoPtZ", 'F');
|
173 |
|
|
if( varmap[string("dEtaJ1HiPtZ" )] ) factory->AddVariable("dEtaJ1HiPtZ", 'F');
|
174 |
|
|
if( varmap[string("dEtaJ1LoPtZ" )] ) factory->AddVariable("dEtaJ1LoPtZ", 'F');
|
175 |
|
|
if( varmap[string("J1dotHiPtZ" )] ) factory->AddVariable("J1dotHiPtZ", 'F');
|
176 |
|
|
if( varmap[string("J1dotLoPtZ" )] ) factory->AddVariable("J1dotLoPtZ", 'F');
|
177 |
|
|
if( varmap[string("dphiJ2HiPtZ" )] ) factory->AddVariable("dphiJ2HiPtZ", 'F');
|
178 |
|
|
if( varmap[string("dphiJ2LoPtZ" )] ) factory->AddVariable("dphiJ2LoPtZ", 'F');
|
179 |
|
|
if( varmap[string("dEtaJ2HiPtZ" )] ) factory->AddVariable("dEtaJ2HiPtZ", 'F');
|
180 |
|
|
if( varmap[string("dEtaJ2LoPtZ" )] ) factory->AddVariable("dEtaJ2LoPtZ", 'F');
|
181 |
|
|
if( varmap[string("J2dotHiPtZ" )] ) factory->AddVariable("J2dotHiPtZ", 'F');
|
182 |
|
|
if( varmap[string("J2dotLoPtZ" )] ) factory->AddVariable("J2dotLoPtZ", 'F');
|
183 |
dkralph |
1.1 |
|
184 |
|
|
if( varmap[string("m4l")] ) factory->AddVariable( "m4l", 'F' );
|
185 |
|
|
else factory->AddSpectator("m4l", 'F' );
|
186 |
|
|
|
187 |
|
|
char buf[256];
|
188 |
|
|
sprintf( buf, "(m4l>%f&&m4l<%f)", (float)wL, (float)wH );
|
189 |
|
|
TCut mycuts(buf);
|
190 |
|
|
TString cutStr(buf);
|
191 |
|
|
cout << "cutStr: " << cutStr << endl;
|
192 |
|
|
|
193 |
|
|
vector<TString> sigFiles,bkgFiles;
|
194 |
|
|
vector<double> passFracs,sigFileFracs,bkgFileFracs,nSigPassCutv,nBkgPassCutv;
|
195 |
|
|
for(unsigned ifile=0; ifile<fileNames.size(); ifile++) {
|
196 |
|
|
double nPassCut = double(inTrees[ifile]->GetEntries(cutStr));
|
197 |
|
|
if(fileFracs[ifile] == -1)
|
198 |
|
|
fileFracs[ifile] = mH_fracs[fileMasses[ifile]];
|
199 |
|
|
passFracs.push_back( nPassCut / inTrees[ifile]->GetEntries() );
|
200 |
|
|
cout << classes[ifile] << ": "
|
201 |
|
|
<< setw(8) << nPassCut << " / " << setw(8) << inTrees[ifile]->GetEntries() << " events pass cut in file: " << fileNames[ifile] << ", filefrac: " << fileFracs[ifile] << endl;
|
202 |
|
|
if(classes[ifile].Contains("sig")) {
|
203 |
|
|
sigFiles.push_back(fileNames[ifile]);
|
204 |
|
|
sigFileFracs.push_back(fileFracs[ifile]);
|
205 |
|
|
nSigPassCutv.push_back( nPassCut );
|
206 |
|
|
} else if(classes[ifile].Contains("bkg")) {
|
207 |
|
|
bkgFiles.push_back(fileNames[ifile]);
|
208 |
|
|
bkgFileFracs.push_back(fileFracs[ifile]);
|
209 |
|
|
nBkgPassCutv.push_back( nPassCut );
|
210 |
|
|
} else assert(0);
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
double nMin=999999;
|
214 |
|
|
double nSig=0;
|
215 |
|
|
if(sigFiles.size()==2) {
|
216 |
|
|
cout << " signal comparison: " << nSigPassCutv[0]*sigFileFracs[1] << " " << nSigPassCutv[1]*sigFileFracs[0] << endl;
|
217 |
|
|
if(nSigPassCutv[0]*sigFileFracs[1] > nSigPassCutv[1]*sigFileFracs[0]) { // statistics are limited by second signal file
|
218 |
|
|
cout << " use second signal as min signal" << endl;
|
219 |
|
|
nMin = nSig = nSigPassCutv[1] * ( 1 + sigFileFracs[0] / sigFileFracs[1] );
|
220 |
|
|
} else { // limited by first one
|
221 |
|
|
cout << " use first signal as min signal" << endl;
|
222 |
|
|
nMin = nSig = nSigPassCutv[0] * ( 1 + sigFileFracs[1] / sigFileFracs[0] );
|
223 |
|
|
}
|
224 |
|
|
} else if(sigFiles.size()==1 && mH_lo==0 && mH_hi==0) { // not interpolating
|
225 |
|
|
nMin = nSig = nSigPassCutv[0];
|
226 |
|
|
} else assert(multisigs);
|
227 |
|
|
cout << "nMin after signal check: " << nMin << endl;
|
228 |
|
|
|
229 |
|
|
long nBkg=0,nBkg2=0;
|
230 |
|
|
for(unsigned ibkg=0; ibkg<bkgFiles.size(); ibkg++) {
|
231 |
|
|
if(multiclass && bkgFiles[ibkg].Contains("fakes"))
|
232 |
|
|
nBkg2 += nBkgPassCutv[ibkg];
|
233 |
|
|
else
|
234 |
|
|
nBkg += nBkgPassCutv[ibkg];
|
235 |
|
|
}
|
236 |
|
|
cout << "nBkg: " << nBkg << "\tnBkg2: " << nBkg2 << endl;
|
237 |
dkralph |
1.2 |
if(!multisigs && nBkg < nMin) nMin = nBkg; // don't include fakes in this comparison. Also, for multisigs we train two signal samples against each other, so we don't care if there is less bkg
|
238 |
dkralph |
1.1 |
cout << "nMin after bkg check: " << nMin << endl;
|
239 |
|
|
|
240 |
|
|
double nTarget = min(nMin,double(nMax));
|
241 |
|
|
cout << "nTarget: " << nTarget << endl;
|
242 |
|
|
|
243 |
|
|
map<TString,double> fracUsed;
|
244 |
|
|
if(nTarget < nSig) fracUsed["sig"] = double(nTarget) / nSig; else fracUsed["sig"] = 1;
|
245 |
|
|
if(nTarget < nBkg) fracUsed["bkg"] = double(nTarget) / nBkg; else fracUsed["bkg"] = 1;
|
246 |
|
|
cout << "frac Used sig: " << fracUsed["sig"] << ", bkg: " << fracUsed["bkg"] << endl;
|
247 |
|
|
if(multisigs) {
|
248 |
|
|
fracUsed["sig2"] = fracUsed["sig3"] = fracUsed["sig"];
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
vector<TTree*> TreeCopies; // copies of the input trees, but with only the number of events we want
|
252 |
|
|
TList *sigList = new TList;
|
253 |
|
|
TList *bkgList = new TList;
|
254 |
|
|
TList *bkg2List = new TList;
|
255 |
|
|
TList *sig2List = new TList;
|
256 |
|
|
TList *sig3List = new TList;
|
257 |
|
|
cout << "making tree copies: " << endl;
|
258 |
|
|
for(unsigned ifile=0; ifile<fileNames.size(); ifile++) {
|
259 |
|
|
// if(mH_fracs.find(fileMasses[ifile]) == mH_fracs.end()) { cout << "filemasses[ifile]: " << fileMasses[ifile] << endl; assert(0); }
|
260 |
|
|
|
261 |
|
|
long nToRequest;
|
262 |
|
|
nToRequest = /*fileFracs[ifile] * */inTrees[ifile]->GetEntries(); // / passFracs[ifile];
|
263 |
|
|
if(!(multiclass && classes[ifile].Contains("bkg") && fileNames[ifile].Contains("fakes")))
|
264 |
|
|
nToRequest *= fracUsed[classes[ifile]];
|
265 |
|
|
cout << " adding " << setw(12) << passFracs[ifile]*nToRequest << " from file " << fileNames[ifile]
|
266 |
|
|
<< ", which means asking for: " << nToRequest << endl;
|
267 |
|
|
TreeCopies.push_back(inTrees[ifile]->CopyTree(cutStr,"",nToRequest));
|
268 |
|
|
if(classes[ifile].Contains("sig")) {
|
269 |
|
|
if(!multisigs) {
|
270 |
|
|
sigList->Add(TreeCopies.back());
|
271 |
|
|
} else {
|
272 |
|
|
if(classes[ifile]=="sig") sigList->Add(TreeCopies.back());
|
273 |
|
|
else if(classes[ifile]=="sig2") { cout << "added to sig2list" << endl; sig2List->Add(TreeCopies.back()); }
|
274 |
|
|
else if(classes[ifile]=="sig3") { cout << "added to sig3list" << endl; sig3List->Add(TreeCopies.back()); }
|
275 |
|
|
else assert(0);
|
276 |
|
|
}
|
277 |
|
|
}
|
278 |
|
|
if(classes[ifile].Contains("bkg")) {
|
279 |
|
|
if(multiclass && fileNames[ifile].Contains("fakes"))
|
280 |
|
|
bkg2List->Add(TreeCopies.back());
|
281 |
|
|
else
|
282 |
|
|
bkgList->Add(TreeCopies.back());
|
283 |
|
|
}
|
284 |
|
|
}
|
285 |
|
|
|
286 |
|
|
TTree *sigTreeAll = TTree::MergeTrees(sigList);
|
287 |
|
|
TTree *sig2TreeAll = TTree::MergeTrees(sig2List);
|
288 |
|
|
TTree *sig3TreeAll = sig3List->GetSize() ? TTree::MergeTrees(sig3List) : 0;
|
289 |
|
|
TTree *bkgTreeAll = TTree::MergeTrees(bkgList);
|
290 |
|
|
TTree *bkg2TreeAll = multiclass ? TTree::MergeTrees(bkg2List) : 0;
|
291 |
|
|
cout << "sigTreeAll entries: " << sigTreeAll->GetEntries() << endl;
|
292 |
|
|
cout << "bkgTreeAll entries: " << bkgTreeAll->GetEntries() << endl;
|
293 |
|
|
if(multiclass) {
|
294 |
|
|
cout << "bkg2TreeAll entries: " << bkg2TreeAll->GetEntries() << endl;
|
295 |
|
|
if(multisigs) {
|
296 |
|
|
cout << "sig2TreeAll entries: " << sig2TreeAll->GetEntries() << endl;
|
297 |
|
|
if(sig3TreeAll)
|
298 |
|
|
cout << "sig3TreeAll entries: " << sig3TreeAll->GetEntries() << endl;
|
299 |
|
|
}
|
300 |
|
|
}
|
301 |
|
|
|
302 |
dkralph |
1.2 |
// // add variables to the trees that aren't already in them
|
303 |
|
|
// float J1dotHiPtZ;
|
304 |
|
|
// KinematicsStruct kine;
|
305 |
|
|
// sigTreeAll->SetBranchAddress("kinematics", &kine);
|
306 |
|
|
// for(unsigned ientry=0; ientry<sigTreeAll->GetEntries(); ientry++) {
|
307 |
|
|
// sigTreeAll->GetEntry(ientry);
|
308 |
|
|
// sigTreeAll->SetScanField(10);
|
309 |
|
|
// sigTreeAll->Scan("ptJet1");
|
310 |
|
|
// cout << kine.l1pt << endl;
|
311 |
|
|
// if(ientry>10) assert(0);
|
312 |
|
|
// }
|
313 |
|
|
|
314 |
|
|
|
315 |
dkralph |
1.1 |
factory->AddTree( sigTreeAll, "Signal", 1, "((evt%2)==0)", TMVA::Types::kTraining);
|
316 |
|
|
factory->AddTree( sigTreeAll, "Signal", 1, "((evt%2)!=0)", TMVA::Types::kTesting);
|
317 |
|
|
if(multisigs) {
|
318 |
|
|
if(multiclass) {
|
319 |
|
|
factory->AddTree( sig2TreeAll, "Signal2", 1, "((evt%2)==0)", TMVA::Types::kTraining);
|
320 |
|
|
factory->AddTree( sig2TreeAll, "Signal2", 1, "((evt%2)!=0)", TMVA::Types::kTesting);
|
321 |
|
|
} else {
|
322 |
|
|
factory->AddTree( sig2TreeAll, "Background", 1, "((evt%2)==0)", TMVA::Types::kTraining);
|
323 |
|
|
factory->AddTree( sig2TreeAll, "Background", 1, "((evt%2)!=0)", TMVA::Types::kTesting);
|
324 |
|
|
}
|
325 |
|
|
if(sig3TreeAll) {
|
326 |
|
|
factory->AddTree( sig3TreeAll, "Signal3", 1, "((evt%2)==0)", TMVA::Types::kTraining);
|
327 |
|
|
factory->AddTree( sig3TreeAll, "Signal3", 1, "((evt%2)!=0)", TMVA::Types::kTesting);
|
328 |
|
|
}
|
329 |
|
|
} else {
|
330 |
|
|
factory->AddTree( bkgTreeAll, "Background", 1, "((evt%2)==0)", TMVA::Types::kTraining);
|
331 |
|
|
factory->AddTree( bkgTreeAll, "Background", 1, "((evt%2)!=0)", TMVA::Types::kTesting);
|
332 |
|
|
if(multiclass) {
|
333 |
dkralph |
1.2 |
if(noFakeTest) {
|
334 |
|
|
factory->AddTree( bkg2TreeAll, "Background2", 1, "", TMVA::Types::kTraining);
|
335 |
|
|
factory->AddTree( bkg2TreeAll, "Background2", 1, "", TMVA::Types::kTesting); // just make 'em the same, should work...
|
336 |
|
|
} else {
|
337 |
|
|
factory->AddTree( bkg2TreeAll, "Background2", 1, "((evt%2)==0)", TMVA::Types::kTraining);
|
338 |
|
|
factory->AddTree( bkg2TreeAll, "Background2", 1, "((evt%2)!=0)", TMVA::Types::kTesting);
|
339 |
|
|
}
|
340 |
dkralph |
1.1 |
}
|
341 |
|
|
}
|
342 |
|
|
|
343 |
|
|
if(NTrees=="") NTrees = "10000";
|
344 |
|
|
if(NNodesMax=="") NNodesMax = "10";
|
345 |
|
|
if(Shrinkage=="") Shrinkage = "0.05";
|
346 |
|
|
if(nCuts=="") nCuts = "20";
|
347 |
|
|
factory->PrepareTrainingAndTestTree( "", "SplitMode=Random:V:NormMode=NumEvents");
|
348 |
|
|
factory->BookMethod( TMVA::Types::kBDT, "BDTG", "!H:V:NTrees="+NTrees
|
349 |
|
|
+":NNodesMax="+NNodesMax
|
350 |
|
|
+":BoostType=Grad:Shrinkage="+Shrinkage
|
351 |
|
|
+":UseBaggedGrad:GradBaggingFraction=0.50:nCuts="+nCuts
|
352 |
|
|
+":IgnoreNegWeights");
|
353 |
|
|
|
354 |
|
|
// KH params:
|
355 |
|
|
// factory->BookMethod( TMVA::Types::kBDT, "BDTG","!H:V:NTrees=2000:BoostType=Grad:Shrinkage=0.10:UseBaggedGrad:GradBaggingFraction=0.50:nCuts=20:UseYesNoLeaf=False");//NNodesMax=8
|
356 |
|
|
// decorrelate them first:
|
357 |
|
|
// factory->BookMethod( TMVA::Types::kBDT, "BDTG","!H:V:NTrees=2000:BoostType=Grad:Shrinkage=0.10:UseBaggedGrad:GradBaggingFraction=0.50:nCuts=20:UseYesNoLeaf=False:VarTransform=D");//NNodesMax=8
|
358 |
|
|
|
359 |
|
|
// josh:
|
360 |
|
|
// factory->BookMethod( TMVA::Types::kBDT, "BDTG_josh" , "!H:V:NTrees=2000:BoostType=Grad:Shrinkage=0.1:UseBaggedGrad=F:nCuts=2000:MaxDepth=3:NNodesMax=100000:UseYesNoLeaf=F:nEventsMin=10000:");
|
361 |
|
|
// factory->BookMethod( TMVA::Types::kBDT, "BDTG_josh" , "!H:V:NTrees=2000:BoostType=Grad:Shrinkage=0.1:UseBaggedGrad=F:nCuts=2000:MaxDepth=3:NNodesMax=100000:UseYesNoLeaf=F:nEventsMin=1000:");
|
362 |
|
|
// 'phil' params:
|
363 |
|
|
// factory->BookMethod( TMVA::Types::kBDT, "BDTG_newparams","!H:V:NTrees=200:BoostType=Grad:Shrinkage=0.01:!UseBaggedGrad:nCuts=2000:nEventsMin=100:NNodesMax=5:MaxDepth=100");
|
364 |
|
|
// small number of very dep trees
|
365 |
|
|
// ntrees should be smaller (200-500)
|
366 |
|
|
// max depth 100
|
367 |
|
|
// shrink 0.01
|
368 |
|
|
|
369 |
|
|
factory->TrainAllMethods();
|
370 |
|
|
factory->TestAllMethods();
|
371 |
|
|
factory->EvaluateAllMethods();
|
372 |
|
|
|
373 |
|
|
std::cerr << "closing ... " << std::endl;
|
374 |
|
|
outputFile->Close();
|
375 |
|
|
}
|
376 |
|
|
//----------------------------------------------------------------------------------------
|
377 |
|
|
void setFractions(float mH, float mH_lo, float mH_hi, float &frac_lo, float &frac_hi)
|
378 |
|
|
{
|
379 |
|
|
double delta = mH_hi - mH_lo;
|
380 |
|
|
frac_lo = (mH_hi - mH)/delta;
|
381 |
|
|
frac_hi = (mH - mH_lo)/delta;
|
382 |
|
|
}
|
383 |
|
|
//----------------------------------------------------------------------------------------
|
384 |
|
|
void setNevents(int nEvtMax, int nSigTrainMax, int nSigTestMax, int nBkgTrainMax, int nBkgTestMax, TString &nSig, TString &nBkg)
|
385 |
|
|
{
|
386 |
|
|
// we want nEvtMax, but if there's fewer than this in any of the trees, we reduce our expectations
|
387 |
|
|
if(fabs(nSigTrainMax-nSigTestMax)/double(nSigTrainMax) > 0.1) {
|
388 |
|
|
assert(0);
|
389 |
|
|
}
|
390 |
|
|
if(fabs(nBkgTrainMax-nBkgTestMax)/double(nBkgTrainMax) > 0.1) {
|
391 |
|
|
assert(0);
|
392 |
|
|
}
|
393 |
|
|
|
394 |
|
|
nEvtMax = min(nEvtMax,nSigTrainMax);
|
395 |
|
|
nEvtMax = min(nEvtMax,nSigTestMax);
|
396 |
|
|
nEvtMax = min(nEvtMax,nBkgTrainMax);
|
397 |
|
|
nEvtMax = min(nEvtMax,nBkgTestMax);
|
398 |
|
|
stringstream ss;
|
399 |
|
|
ss << nEvtMax;
|
400 |
|
|
ss >> nSig;
|
401 |
|
|
nBkg = nSig;
|
402 |
|
|
// ss << min(nSigTrainMax,nSigTestMax) << " " << min(nBkgTrainMax,nBkgTestMax);
|
403 |
|
|
// ss >> nSig >> nBkg;
|
404 |
|
|
}
|