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;
141 }
142 }
143 }
144 else {
145 if ( arg==
"-h" || arg==
"--help" )
return usage(0);
146 else if ( arg=="-o" || arg=="--output" ) {
148 else return usage(-1);
149 }
150 else if ( arg=="-r" || arg=="--require" ) {
151 if ( deleting ) {
152 std::cerr << "cannot require and delete chains" << std::endl;
154 }
155 require = true;
156 }
157 else if ( arg=="-d" || arg=="--delete" ) {
158 if ( require ) {
159 std::cerr << "cannot require and delete chains" << std::endl;
161 }
162 deleting = true;
163 }
164 else if ( arg=="--pt" ) {
165 if ( (i+1)<argc ) ptmin = std::atof(argv[++i])*1000;
166 else return usage(-1);
168 }
169 else if ( arg==
"-v" || arg==
"--verbose" )
verbose =
true;
170 else if ( arg==
"-f" || arg==
"--force" )
force =
true;
171 else if ( arg==
"--roi" ) {
force=
true; roi_filter =
true; }
172 else if ( infile==
"" )
infile = std::move(arg);
173 else {
174 std::cerr <<
"more than one file specified: " <<
arg << std::endl;
176 }
177 }
178 }
179
180 std::cout << "required chains " << require_chains << std::endl;
181
182 if ( require_chains.size()>0 ) require = true;
183
184 if ( !force && require_chains.size()==0 ) {
185 std::cout << "no chains requested - not doing anything" << std::endl;
186 return 0;
187 }
188
189 std::cout << "chains: " << rchains << std::endl;
190
191
192 std::cout <<
"skim::start " <<
time_str() << std::endl;
193
194
195 if ( require ) std::cout << "require chains " << require_chains << std::endl;
196 if ( deleting ) std::cout << "delete chains " << require_chains << std::endl;
197
198
199 if ( infile=="" ) {
200 std::cerr << "no files specified" << std::endl;
202 }
203
204 std::cout <<
"reading from file: " <<
infile << std::endl;
205 std::cout <<
"writing to file: " <<
outfile << std::endl;
206
207
211
212 std::cout <<
"opening outfile: " <<
outfile << std::endl;
213
215
217
219
220 TTree *
tree =
new TTree(
"tree",
"tree");
221
222 tree->Branch(
"TIDA::Event",
"TIDA::Event", &
h, 6400, 1);
223
225
227
228 int ev_in = 0;
229 int ev_out = 0;
230
231 {
232
234 TFile finput(
infile.c_str() );
235 if (!finput.IsOpen()) {
236 std::cerr << "Error: could not open output file" << std::endl;
238 }
239
240
242
243 finput.cd();
244
246
247
248
249 TTree*
data = (TTree*)finput.Get(
"tree");
250
252
253 data->SetBranchAddress(
"TIDA::Event",&track_iev);
254
255
256
258
259 std::cout <<
"input has " <<
entries <<
" events" << std::endl;
260
261 std::string cck = "|/-\\";
262
263 int ii=0;
264
266
267 std::cout << "processing ..." << std::endl;
268
269 for (
unsigned int i=0;
i<
data->GetEntries() ;
i++ ) {
270
271 if (
verbose ) std::cout <<
"event " <<
i;
272
273 if ( i%100==0 ) {
274
276
278
279 double est = 0;
280
281 if ( frac > 0 ) est =
t/
frac -
t;
282
283 double eventsps = 1000*
i/
t;
284
285 std::printf( "\r%c %6.2lf %% time: %6.2lf s remaining %6.2lf s (%u at %5.2lf ps) ",
286 cck[ii%4], (
static_cast<unsigned>((1000*(i+1)/
entries))*0.1), t*0.001, est*0.001, i, eventsps );
287
288 std::fflush(stdout);
289
290 ii++;
291 }
292
293
294
297
299
300 ev_in++;
301
302 *track_ev = *track_iev;
303
304
305
306
307
308
309 if (
verbose ) std::cout <<
"----------------------------------------\n\tN chains " << track_ev->
size() <<
" -> ";
310
312
313
315
317
318 std::vector<TIDA::Chain>::iterator citr =
chains.begin();
319 for ( ; citr!=
chains.end() ; ++citr ) {
320
321 if ( citr->name().find("HLT")==std::string::npos ) continue;
322
323 if ( require ) {
324 for ( unsigned j=rchains.size() ; j-- ; ) {
325 if ( rchains[j].
find(
"HLT")==std::string::npos )
continue;
326 if ( citr->name().find(rchains[j])!=std::string::npos ) {
328 if (
verbose ) std::cout <<
"keepin' " << citr->name() <<
" " << rchains[
j] << std::endl;
329 }
330
331 }
332 }
333
334 }
335
336 if (
skip )
continue;
337
339
340 {
341
343
344 std::vector<std::string> chainnames = track_ev->
chainnames();
345
346 for (
size_t ic=0 ;
ic<chainnames.size() ;
ic++ ) {
347
348
349 bool matched = false;
350 for ( std::set<std::string>::iterator it=require_chains.begin() ; it!=require_chains.end() ; ++it ) {
351
352 matched |= std::regex_match( chainnames[ic], std::regex(*it+".*") );
353
354 if (
verbose && matched ) std::cout <<
"chain: " << chainnames[
ic] <<
"\t :: reg " << *
it <<
"\tmatched: " << matched << std::endl;
355
356 }
357
358 if ( ( require && !matched ) ) track_ev->
erase( chainnames[ic] );
359 }
360
361 if (
verbose ) std::cout << track_ev->
size() << std::endl;
362
363
364 if ( roi_filter || ptmin>0 ) {
365
367
368 std::vector<std::string> chainnames = track_ev->
chainnames();
369
371
372 for ( size_t ic=chainnames.size() ; ic-- ; ) {
373 if ( chainnames[ic] == "Offline" ) {
375 break;
376 }
377 }
378
380
381
383 std::vector<TIDA::Chain>::iterator citr =
chains.begin();
384
385 std::vector<std::pair<double,double> > philims;
386
387 for ( ; citr!=
chains.end() ; ++citr ) {
388 if ( citr->name().find("HLT_")!=std::string::npos ) {
389 for (
size_t ir=0 ;
ir<citr->size() ;
ir++ ) {
392 for (
size_t isub=0 ; isub<roi.
size() ; isub++ ) {
393 philims.push_back( std::pair<double,double>( roi[isub]->phiMinus(), roi[isub]->phiPlus() ) );
394 }
395 }
396 else philims.push_back( std::pair<double,double>( roi.
phiMinus(), roi.
phiPlus() ) );
397 }
398 }
399 }
400
402
403 for (
size_t iroi=0 ; iroi<
offline->size() ; iroi++ ) {
404
405 std::vector<TIDA::Track>& tracks =
offline->rois()[iroi].tracks();
406
407 for ( std::vector<TIDA::Track>::iterator it=tracks.begin() ; it<tracks.end() ; ) {
408 bool inc = true;
409 if ( ptmin>0 ) {
410 if ( std::fabs(
it->pT())<ptmin ) { inc=
false; tracks.erase( it ); }
411 }
412 if ( inc && roi_filter ) {
413 bool remove_track = true;
414 for ( size_t isub=0 ; isub<philims.size() ; isub++ ) {
415
416 if ( philims[isub].first < philims[isub].second ) {
417 if (
it->phi()>=philims[isub].first &&
it->phi()<=philims[isub].second ) {
418 remove_track = false;
419 break;
420 }
421 }
422 else {
423 if (
it->phi()>=philims[isub].first ||
it->phi()<=philims[isub].second ) {
424 remove_track = false;
425 break;
426 }
427 }
428 }
429 if ( remove_track ) { inc=false; tracks.erase( it ); }
430 }
432 }
433
434 }
435
436 }
437
438
439 }
440
441
442 if (
verbose ) std::cout <<
"writing event:\n" << *track_ev << std::endl;
443
445 ev_out++;
446
447
448#if 0
449 for (
unsigned int ic=0 ;
ic<
chains.size() ;
ic++ ) {
450 if ( chains[ic].
name()==
"Offline" ) {
451 const std::vector<TIDA::Track>& tracks =
chains[
ic].rois()[0].tracks();
452
453 for (
unsigned it=0 ;
it<tracks.size() ;
it++ ) {
454 h->Fill( tracks[it].
pT()*0.001 );
455 itracks++;
456
457 }
458 break;
459 }
460 }
461#endif
462
463 }
464
465 }
466
467
469
470 std::printf( "\r%c %6.2lf %% time: %6.2lf s\n",
471 cck[ii%4], 100., t*0.001 );
472
473
474 finput.Close();
475
476 }
477
478 std::cout <<
"skim::done " <<
time_str() << std::endl;
479
480 std::cout << "skim::events in: " << ev_in << std::endl;
481 std::cout << "skim::events out: " << ev_out << std::endl;
482
485
486 return 0;
487}
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 Interest 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
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
void copyReleaseInfo(TFile *finput, TFile *foutdir)
copy the TTree of release info from one directory to another
void remove_duplicates(std::vector< T > &vec)