30 for (
size_t i=0 ;
i<
v.size() ;
i++ )
s <<
v[
i] << std::endl;
35 bool contains(
const std::string&
s,
const std::string& regx ) {
36 return s.find( regx )!=std::string::npos;
40 return s.find(
c )!=std::string::npos;
49 std::vector<std::string>
split( std::string&
line ) {
50 std::vector<std::string> strings;
55 std::string stmp =
chop(
line,
" " );
56 std::string
s =
chop( stmp,
"\t" );
58 line.replace(
s.find(
'\t'), 1,
" " );
62 if ( !
s.empty() ) strings.push_back(
s );
65 strings.push_back(
line );
76 threshold(
double t_,
int i_,
const std::string&
c,
const std::string&
k,
int co ) :
95 return s <<
t.chain <<
"\t" <<
t.key <<
"\t(" <<
t.thresh <<
")\t" <<
t.counts;
100 if (
i!=0 ) std::cout <<
"error " <<
i <<
"\n\n";
102 std::cout <<
"Usage: " <<
argv[0] <<
" FILE SLICE [OPTIONS] file\n\n";
104 std::cout <<
"\t decodes which chains are available from a HIST file log\n";
105 std::cout <<
"\t by default, sorts chains by threshold\n";
107 std::cout <<
"Options:\n";
108 std::cout <<
" -all \t list all chains\n";
109 std::cout <<
" -cr, --return \t separate chains with a return\n";
110 std::cout <<
" -c, --counts \t sort by counts rather than threshold\n";
111 std::cout <<
" -t, --thresh value \t require at least value entries - default is 100\n";
112 std::cout <<
" -n value \t report only n chains - default is 4\n\n";
114 std::cout <<
" -k expression \t match any chain containing expression\n";
115 std::cout <<
" -K expression \t match only chains containing expression\n";
116 std::cout <<
" --veto expression \t veto all chains containing \"expression\"\n";
117 std::cout <<
" -x, --excluded \t also include usually excluded entries\n\n";
118 std::cout <<
" -s, --sig sig pat \t add a new signature, sig, to the expected list with the pattern definied by pat\n";
120 std::cout <<
" -v, --verbose \t verbose output\n\n";
121 std::cout <<
" -h, --help \t this help\n" << std::endl;
131 bool allflag =
false;
133 std::vector<std::string>
keys;
138 std::vector<std::string> Keys;
141 std::vector<std::string>
veto;
143 std::string creturn =
"";
146 bool usecounts =
false;
147 bool excluded =
false;
151 std::string afile =
"";
152 std::string aslice =
"";
154 double userthreshold = 100;
160 for (
int i=1 ;
i<
argc ;
i++ ) {
162 if (
arg==
"-all" ) allflag =
true;
164 else if (
arg==
"-t" ||
arg==
"--threshold" ) {
168 else if (
arg==
"-cr" ) creturn =
"\n";
169 else if (
arg==
"-c" ||
arg==
"--counts" ) usecounts =
true;
170 else if (
arg==
"-k" ) {
180 else if (
arg==
"-K" ) {
186 Keys.push_back(
argv[
i]);
190 else if (
arg==
"--veto" ) {
194 else if (
arg==
"-n" ) {
199 else if (
arg==
"-x" ||
arg==
"--excluded" ) excluded =
true;
200 else if (
arg==
"-s" ||
arg==
"--sig" ) {
207 if ( afile==
"" ) afile=
arg;
208 else if ( aslice==
"" ) aslice=
arg;
215 std::ifstream
file( afile.c_str() );
217 std::vector<std::vector<std::string> > block(1,std::vector<std::string>() );
221 std::vector<int> position(1, 0);
225 std::string
slice =
"/" + aslice +
'/';
227 std::string rawslice = aslice;
229 std::map<std::string, std::string>
chains;
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",
"" ) );
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",
"" ) );
248 chain_map::const_iterator itr =
chains.find( rawslice );
250 if ( itr==
chains.end() ) {
251 std::cerr <<
"can not process type " << rawslice << std::endl;
255 std::string
tag =
"";
256 if ( itr->second !=
"" ) {
261 std::vector<threshold> thresholds;
273 std::vector<std::string> expl =
split(
line );
277 unsigned expected_size = 0;
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;
295 std::cerr <<
"unknown HIST type " << expl[
index+2] << std::endl;
300 std::cerr <<
"unknown HIST type " << expl[
index] <<
" (2)" << std::endl;
304 if ( expl.size() > expected_size ) {
306 int counts =
std::atof(expl[expected_size].c_str());
312 if ( counts >= userthreshold ) {
314 std::string
tmp = expl[expected_size-2];
316 if ( !
tag.empty() ) {
319 size_t pos =
tmp.find(
'_');
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] );
339 int counts_var = counts;
342 counts_var =
int(thresh_var);
346 if ( expected_size >= 2 ) {
348 threshold t( thresh_var,
it++, expl[expected_size-2], expl[expected_size-1], counts_var );
356 thresholds.push_back(
t );
366 if ( usecounts ) sort( thresholds.rbegin(), thresholds.rend() );
367 else sort( thresholds.begin(), thresholds.end() );
380 for (
size_t i=0 ;
i<thresholds.size() ;
i++ )
id.push_back(
i);
383 else if ( usecounts ) {
387 for (
size_t i=0 ;
i<thresholds.size() &&
i<
n ;
i++ )
id.push_back(
i);
394 std::vector<unsigned>
ind(
n,0);
396 if ( thresholds.size() == 0 ) {
397 std::cerr <<
"no valid thresholds found" << std::endl;
402 if ( rawslice==
"Bjet" ) {
403 for (
size_t i=0 ;
i<thresholds.size() ;
i++ ) {
407 if ( thresholds[
i].
thresh > 30 )
break;
411 for (
size_t i=thresholds.size() ;
i-- ; ) {
413 if ( thresholds[
i].counts > 0.05*thresholds[
ind[0]].counts ) {
421 for (
unsigned it=1 ;
n>0 &&
it<
n-1 ;
it++ ) {
426 double f =
it*1.0/(
n-1);
436 double delta = cthresh - thresholds[
ind[
it]].thresh;
438 double R2 = delta*delta;
440 for (
size_t i=
ind[0]+1 ;
i<
ind[
n-1]-1 ;
i++ ) {
441 double delta = cthresh - thresholds[
i].thresh;
443 double R2_ = delta*delta;
453 id.push_back(
ind[0] );
456 for (
unsigned i=1 ;
i<
n ;
i++ ) {
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;