create the main event TTree ...
now onto the business of deleting the chains ...
101 {
102
103 if ( argc<1 )
return usage(-1);
104
105 std::set<std::string> require_chains;
106 std::vector<std::string> rchains;
107
108 bool require = false;
109 bool deleting = false;
110
111 std::string
outfile =
"tree.root";
112
114
116
117 double ptmin = 0;
118
119 bool roi_filter = false;
120
122
123 for (
int i=1 ;
i<
argc ;
i++ ) {
124
125 std::string
arg(argv[i]);
126
128
129 if (
arg.find(
'-')!=0 ) {
130 if ( !deleting && infile!="" ) {
131 require = true;
132 require_chains.insert(argv[i]);
133 rchains.push_back(argv[i]);
134 continue;
135 }
136 else {
137 if ( infile==
"" )
infile = std::move(arg);
138 else {
139 std::cerr <<
"more than one file specified: " <<
arg << std::endl;
142 }
143 }
144 }
145 else {
146 if ( arg==
"-h" || arg==
"--help" )
return usage(0);
147 else if ( arg=="-o" || arg=="--output" ) {
149 else return usage(-1);
150 }
151 else if ( arg=="-r" || arg=="--require" ) {
152 if ( deleting ) {
153 std::cerr << "cannot require and delete chains" << std::endl;
155 }
156 require = true;
157 }
158 else if ( arg=="-d" || arg=="--delete" ) {
159 if ( require ) {
160 std::cerr << "cannot require and delete chains" << std::endl;
162 }
163 deleting = true;
164 }
165 else if ( arg=="--pt" ) {
166 if ( (i+1)<argc ) ptmin = std::atof(argv[++i])*1000;
167 else return usage(-1);
169 }
170 else if ( arg==
"-v" || arg==
"--verbose" )
verbose =
true;
171 else if ( arg==
"-f" || arg==
"--force" )
force =
true;
172 else if ( arg==
"--roi" ) {
force=
true; roi_filter =
true; }
173 else if ( infile==
"" )
infile = std::move(arg);
174 else {
175 std::cerr <<
"more than one file specified: " <<
arg << std::endl;
177 }
178 }
179 }
180
181 std::cout << "required chains " << require_chains << std::endl;
182
183 if ( require_chains.size()>0 ) require = true;
184
185 if ( !force && require_chains.size()==0 ) {
186 std::cout << "no chains requested - not doing anything" << std::endl;
187 return 0;
188 }
189
190 std::cout << "chains: " << rchains << std::endl;
191
192
193 std::cout <<
"skim::start " <<
time_str() << std::endl;
194
195
196 if ( require ) std::cout << "require chains " << require_chains << std::endl;
197 if ( deleting ) std::cout << "delete chains " << require_chains << std::endl;
198
199
200 if ( infile=="" ) {
201 std::cerr << "no files specified" << std::endl;
203 }
204
205 std::cout <<
"reading from file: " <<
infile << std::endl;
206 std::cout <<
"writing to file: " <<
outfile << std::endl;
207
208
212
213 std::cout <<
"opening outfile: " <<
outfile << std::endl;
214
216
218
220
221 TTree *
tree =
new TTree(
"tree",
"tree");
222
223 tree->Branch(
"TIDA::Event",
"TIDA::Event", &
h, 6400, 1);
224
226
228
229 int ev_in = 0;
230 int ev_out = 0;
231
232 {
233
235 TFile finput(
infile.c_str() );
236 if (!finput.IsOpen()) {
237 std::cerr << "Error: could not open output file" << std::endl;
239 }
240
241
243
244 finput.cd();
245
247
248
249
250 TTree*
data = (TTree*)finput.Get(
"tree");
251
253
254 data->SetBranchAddress(
"TIDA::Event",&track_iev);
255
256
257
259
260 std::cout <<
"input has " <<
entries <<
" events" << std::endl;
261
262 std::string cck = "|/-\\";
263
264 int ii=0;
265
267
268 std::cout << "processing ..." << std::endl;
269
270 for (
unsigned int i=0;
i<
data->GetEntries() ;
i++ ) {
271
272 if (
verbose ) std::cout <<
"event " <<
i;
273
274 if ( i%100==0 ) {
275
277
279
280 double est = 0;
281
282 if ( frac > 0 ) est =
t/
frac -
t;
283
284 double eventsps = 1000*
i/
t;
285
286 std::printf( "\r%c %6.2lf %% time: %6.2lf s remaining %6.2lf s (%u at %5.2lf ps) ",
287 cck[ii%4], ((1000*(i+1)/
entries)*0.1), t*0.001, est*0.001, i, eventsps );
288
289 std::fflush(stdout);
290
291 ii++;
292 }
293
294
295
298
300
301 ev_in++;
302
303 *track_ev = *track_iev;
304
305
306
307
308
309
310 if (
verbose ) std::cout <<
"----------------------------------------\n\tN chains " << track_ev->
size() <<
" -> ";
311
313
314
316
318
319 std::vector<TIDA::Chain>::iterator citr =
chains.begin();
320 for ( ; citr!=
chains.end() ; ++citr ) {
321
322 if ( citr->name().find("HLT")==std::string::npos ) continue;
323
324 if ( require ) {
325 for ( unsigned j=rchains.size() ; j-- ; ) {
326 if ( rchains[j].
find(
"HLT")==std::string::npos )
continue;
327 if ( citr->name().find(rchains[j])!=std::string::npos ) {
329 if (
verbose ) std::cout <<
"keepin' " << citr->name() <<
" " << rchains[j] << std::endl;
330 }
331
332 }
333 }
334
335 }
336
337 if (
skip )
continue;
338
340
341 {
342
344
345 std::vector<std::string> chainnames = track_ev->
chainnames();
346
347 for (
size_t ic=0 ;
ic<chainnames.size() ;
ic++ ) {
348
349
350 bool matched = false;
351 for ( std::set<std::string>::iterator it=require_chains.begin() ; it!=require_chains.end() ; ++it ) {
352
353 matched |= std::regex_match( chainnames[ic], std::regex(*it+".*") );
354
355 if (
verbose && matched ) std::cout <<
"chain: " << chainnames[
ic] <<
"\t :: reg " << *
it <<
"\tmatched: " << matched << std::endl;
356
357 }
358
359 if ( ( require && !matched ) ) track_ev->
erase( chainnames[ic] );
360 }
361
362 if (
verbose ) std::cout << track_ev->
size() << std::endl;
363
364
365 if ( roi_filter || ptmin>0 ) {
366
368
369 std::vector<std::string> chainnames = track_ev->
chainnames();
370
372
373 for ( size_t ic=chainnames.size() ; ic-- ; ) {
374 if ( chainnames[ic] == "Offline" ) {
376 break;
377 }
378 }
379
381
382
384 std::vector<TIDA::Chain>::iterator citr =
chains.begin();
385
386 std::vector<std::pair<double,double> > philims;
387
388 for ( ; citr!=
chains.end() ; ++citr ) {
389 if ( citr->name().find("HLT_")!=std::string::npos ) {
390 for (
size_t ir=0 ;
ir<citr->size() ;
ir++ ) {
393 for (
size_t isub=0 ; isub<roi.
size() ; isub++ ) {
394 philims.push_back( std::pair<double,double>( roi[isub]->phiMinus(), roi[isub]->phiPlus() ) );
395 }
396 }
397 else philims.push_back( std::pair<double,double>( roi.
phiMinus(), roi.
phiPlus() ) );
398 }
399 }
400 }
401
403
404 for (
size_t iroi=0 ; iroi<
offline->size() ; iroi++ ) {
405
406 std::vector<TIDA::Track>& tracks =
offline->rois()[iroi].tracks();
407
408 for ( std::vector<TIDA::Track>::iterator it=tracks.begin() ; it<tracks.end() ; ) {
409 bool inc = true;
410 if ( ptmin>0 ) {
411 if ( std::fabs(
it->pT())<ptmin ) { inc=
false; tracks.erase( it ); }
412 }
413 if ( inc && roi_filter ) {
414 bool remove_track = true;
415 for ( size_t isub=0 ; isub<philims.size() ; isub++ ) {
416
417 if ( philims[isub].first < philims[isub].second ) {
418 if (
it->phi()>=philims[isub].first &&
it->phi()<=philims[isub].second ) {
419 remove_track = false;
420 break;
421 }
422 }
423 else {
424 if (
it->phi()>=philims[isub].first ||
it->phi()<=philims[isub].second ) {
425 remove_track = false;
426 break;
427 }
428 }
429 }
430 if ( remove_track ) { inc=false; tracks.erase( it ); }
431 }
433 }
434
435 }
436
437 }
438
439
440 }
441
442
443 if (
verbose ) std::cout <<
"writing event:\n" << *track_ev << std::endl;
444
446 ev_out++;
447
448
449#if 0
450 for (
unsigned int ic=0 ;
ic<
chains.size() ;
ic++ ) {
451 if ( chains[ic].
name()==
"Offline" ) {
452 const std::vector<TIDA::Track>& tracks =
chains[
ic].rois()[0].tracks();
453
454 for (
unsigned it=0 ;
it<tracks.size() ;
it++ ) {
455 h->Fill( tracks[it].
pT()*0.001 );
456 itracks++;
457
458 }
459 break;
460 }
461 }
462#endif
463
464 }
465
466 }
467
468
470
471 std::printf( "\r%c %6.2lf %% time: %6.2lf s\n",
472 cck[ii%4], 100., t*0.001 );
473
474
475 finput.Close();
476
477 }
478
479 std::cout <<
"skim::done " <<
time_str() << std::endl;
480
481 std::cout << "skim::events in: " << ev_in << std::endl;
482 std::cout << "skim::events out: " << ev_out << std::endl;
483
486
487 return 0;
488}
struct timeval simpletimer_start(void)
double simpletimer_stop(const struct timeval &start_time)
char data[hepevt_bytes_allocation_ATLAS]
Header file for AthHistogramAlgorithm.
Describes the Region of Ineterest geometry It has basically 8 parameters.
bool composite() const
composite RoI methods
void erase(const std::string &name)
const std::vector< TIDA::Chain > & chains() const
void clear()
clear the event
unsigned size() const
vertex multiplicity ?
std::vector< std::string > chainnames() const
int ir
counter of the current depth
std::string find(const std::string &s)
return a remapped string
void copyReleaseInfo(TFile *finput, TFile *foutdir)
copy the TTree of release info from one directory to another
void remove_duplicates(std::vector< T > &vec)