not sure what this is really doing now .... was originally for consistency with the 30 GeV vtx tracking
127 {
128
129 if ( argc<3 )
return usage( argc, argv, 1 );
130
131 bool allflag = false;
132
133 std::vector<std::string>
keys;
134
135
136 bool nokeys = true;
137
138 std::vector<std::string> Keys;
139 bool noKeys = true;
140
141 std::vector<std::string>
veto;
142
143 std::string creturn = "";
144
146 bool usecounts = false;
147 bool excluded = false;
148
150
151 std::string afile = "";
152 std::string aslice = "";
153
154 double userthreshold = 100;
155
158
159
160 for (
int i=1 ;
i<
argc ;
i++ ) {
162 if ( arg=="-all" ) allflag = true;
163 else if ( arg==
"-v" || arg==
"--verbose" )
verbose =
true;
164 else if ( arg=="-t" || arg=="--threshold" ) {
165 if ( ++i<argc ) userthreshold = std::atof(argv[i]);
166 else return usage( argc, argv, 1 );
167 }
168 else if ( arg=="-cr" ) creturn = "\n";
169 else if ( arg=="-c" || arg=="--counts" ) usecounts = true;
170 else if ( arg=="-k" ) {
171 if ( ++i<argc ) {
172 if ( nokeys ) {
174 nokeys = false;
175 }
176 keys.push_back(argv[i]);
177 }
178 else return usage( argc, argv, 2 );
179 }
180 else if ( arg=="-K" ) {
181 if ( ++i<argc ) {
182 if ( noKeys ) {
183 Keys.clear();
184 noKeys = false;
185 }
186 Keys.push_back(argv[i]);
187 }
188 else return usage( argc, argv, 3 );
189 }
190 else if ( arg=="--veto" ) {
191 if ( ++i<argc )
veto.push_back(argv[i]);
192 else return usage( argc, argv, 4 );
193 }
194 else if ( arg=="-n" ) {
195 if ( ++i<argc )
n = std::atoi(argv[i]);
196 else return usage( argc, argv, 5 );
197 }
198 else if ( arg==
"-h" || arg==
"--help" )
return usage( argc, argv, 6 );
199 else if ( arg=="-x" || arg=="--excluded" ) excluded = true;
200 else if ( arg=="-s" || arg=="--sig" ) {
202 else return usage( argc, argv, 1 );
204 else return usage( argc, argv, 1 );
205 }
206 else {
207 if ( afile=="" ) afile=std::move(arg);
208 else if ( aslice=="" ) aslice=std::move(arg);
209 else return usage( argc, argv, 7 );
210 }
211 }
212
213 if ( afile==
"" )
return usage( argc, argv, 8 );
214
215 std::ifstream
file( afile.c_str() );
216
217 std::vector<std::vector<std::string> > block(1,std::vector<std::string>() );
218
220
221 std::vector<int> position(1, 0);
222
223 if ( aslice==
"" )
return usage( argc, argv, 9 );
224
225 std::string
slice =
"/" + aslice +
'/';
226
227 std::string rawslice = std::move(aslice);
228
229 std::map<std::string, std::string>
chains;
230
231 typedef std::map<std::string, std::string> chain_map;
232 chains.insert( chain_map::value_type(
"Electron",
"_e" ) );
233 chains.insert( chain_map::value_type(
"Egamma",
"_e" ) );
234 chains.insert( chain_map::value_type(
"Muon",
"_mu" ) );
235 chains.insert( chain_map::value_type(
"Tau",
"_tau" ) );
236 chains.insert( chain_map::value_type(
"Bjet",
"_j" ) );
237 chains.insert( chain_map::value_type(
"FTK",
"_FTK" ) );
238 chains.insert( chain_map::value_type(
"BjetVtx",
"" ) );
239
240 chains.insert( chain_map::value_type(
"EgammaPurity",
"_e" ) );
241 chains.insert( chain_map::value_type(
"MuonPurity",
"_mu" ) );
242 chains.insert( chain_map::value_type(
"TauPurity",
"_tau" ) );
243 chains.insert( chain_map::value_type(
"BjetPurity",
"_j" ) );
244 chains.insert( chain_map::value_type(
"FTKPurity",
"" ) );
245
246 if ( sig !=
"" )
chains.insert( chain_map::value_type( sig, pat ) );
247
248 chain_map::const_iterator itr =
chains.find( rawslice );
249
250 if ( itr==
chains.end() ) {
251 std::cerr << "can not process type " << rawslice << std::endl;
252 return -1;
253 }
254
255 std::string
tag =
"";
256 if ( itr->second != "" ) {
259 }
260
261 std::vector<threshold> thresholds;
262
264
266
267 bool purity =
contains( slice,
"Purity" );
268
269 while( getline(
file, line ) && !
file.fail() ) {
270
271 if ( !
contains( line, slice ) )
continue;
272
273 std::vector<std::string> expl =
split( line );
274
276
277 unsigned expected_size = 0;
278
279
281
283
285
286
287
288 if ( expl[
index] ==
"IDMon" ) expected_size = 6-
diff;
289 else if ( expl[
index] ==
"TRIDT" ) {
290 if ( expl[
index+2] ==
"Expert" && !purity ) expected_size = 7-
diff;
291 else if ( expl[
index+2] ==
"Shifter" &&
contains(expl[3],
"etVtx") ) expected_size = 7-
diff;
292 else if ( expl[
index+3] ==
"Fullscan" && purity ) expected_size = 7-
diff;
293 else if ( expl[
index+2] ==
"Shifter" || purity ) expected_size = 6-
diff;
294 else {
295 std::cerr <<
"unknown HIST type " << expl[
index+2] << std::endl;
296 return 1;
297 }
298 }
299 else {
300 std::cerr <<
"unknown HIST type " << expl[
index] <<
" (2)" << std::endl;
301 return 1;
302 }
303
304 if ( expl.size() > expected_size ) {
305
306 int counts = std::atof(expl[expected_size].c_str());
307
308
309
310
312 if ( counts >= userthreshold ) {
313
314 std::string
tmp = expl[expected_size-2];
315
316 if ( !
tag.empty() ) {
318
319 size_t pos =
tmp.find(
'_');
320 if ( pos!=std::string::npos )
tmp.replace( pos,
tmp.size()-pos,
"" );
321 }
322
324
325 if (
keys.size()>0 )
for (
size_t ik=
keys.size() ; ik-- ; )
condition |=
contains( expl[expected_size-2], keys[ik] ) ||
contains( expl[expected_size-1], keys[ik] );
327
328 if ( Keys.size()>0 )
for (
size_t ik=Keys.size() ; ik-- ; )
condition &=
contains( expl[expected_size-2], Keys[ik] ) ||
contains( expl[expected_size-1], Keys[ik] );
329
331
332 if ( condition && ( excluded || ( !
contains( expl[5],
"EFID" ) && !
contains( expl[4],
"gsc" ) &&
337
338 double thresh_var = std::atof(
tmp.c_str() );
340
341 if ( usecounts ) {
342 counts_var = int(thresh_var);
344 }
345
346 if ( expected_size >= 2 ) {
347
348 threshold t( thresh_var, it++, expl[expected_size-2], expl[expected_size-1], counts_var );
349
350 if (
verbose && fullpath==
"" )
for (
unsigned ip=0 ;
ip<expected_size-2 ;
ip++ ) fullpath += expl[ip]+
'/';
351
352
353
354
355
356 thresholds.push_back( std::move(t) );
357 }
358 }
359 }
360 }
361 }
362
363
365
366 if ( usecounts )
sort( thresholds.rbegin(), thresholds.rend() );
367 else sort( thresholds.begin(), thresholds.end() );
368
369
371
373
374
375
376 if ( allflag ) {
377
378
379
380 for (
size_t i=0 ;
i<thresholds.size() ;
i++ )
id.push_back(i);
381
382 }
383 else if ( usecounts ) {
384
386
387 for (
size_t i=0 ;
i<thresholds.size() && i<n ;
i++ )
id.push_back(i);
388
389 }
390 else {
391
392
393
394 std::vector<unsigned> ind(n,0);
395
396 if ( thresholds.size() == 0 ) {
397 std::cerr << "no valid thresholds found" << std::endl;
398 return -2;
399 }
400
401
402 if ( rawslice=="Bjet" ) {
403 for (
size_t i=0 ;
i<thresholds.size() ;
i++ ) {
407 if ( thresholds[i].thresh > 30 ) break;
408 }
409 }
410
411 for ( size_t i=thresholds.size() ; i-- ; ) {
412
413 if ( thresholds[i].counts > 0.05*thresholds[ind[0]].counts ) {
415 break;
416 }
417 }
418
420
421 for (
unsigned it=1 ;
n>0 &&
it<
n-1 ;
it++ ) {
422
423 double tn = std::log(thresholds[ind[n-1]].thresh);
424 double t0 = std::log(thresholds[ind[0]].thresh);
425
426 double f =
it*1.0/(
n-1);
427
428 double cthresh = std::exp( f*tn + (1-f)*
t0 );
429
430
431
432 ind[
it] = int( f*ind[n-1]+(1-f)*ind[0] );
433
434
435
436 double delta = cthresh - thresholds[ind[
it]].thresh;
437
438 double R2 = delta*delta;
439
440 for (
size_t i=ind[0]+1 ;
i<ind[
n-1]-1 ;
i++ ) {
441 double delta = cthresh - thresholds[
i].thresh;
442
443 double R2_ = delta*delta;
444
445 if ( R2_ < R2 ) {
447 R2 = R2_;
448 }
449
450 }
451 }
452
453 id.push_back( ind[0] );
454
455
456 for (
unsigned i=1 ;
i<
n ;
i++ ) {
457 if ( ind[i]!=ind[i-1] ) id.push_back( ind[i] );
458 }
459
460
461
462 }
463
464 for (
size_t i=0 ;
i<
id.size() ;
i++ ) {
465 if (
verbose ) std::cout <<
" " <<
fullpath << thresholds[
id[
i]].chain <<
"/" << thresholds[
id[
i]].key << creturn;
466 else std::cout <<
" " << thresholds[
id[
i]].chain <<
"_" << thresholds[
id[
i]].key << creturn;
467 }
468
469 return 0;
470}
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
std::vector< std::string > split(std::string &line)
std::string find(const std::string &s)
return a remapped string
std::vector< std::string > veto
these patterns are anded