ATLAS Offline Software
rmain.cxx
Go to the documentation of this file.
1 
11 #include <cstdio>
12 
13 #include <cmath>
14 #include <fstream>
15 #include <iostream>
16 #include <vector>
17 #include <map>
18 #include <set>
19 #include <sstream>
20 
22 #include <execinfo.h>
23 #include <signal.h>
24 #include <unistd.h>
25 
26 
27 #include "TChain.h"
28 #include "TFile.h"
29 #include "TTree.h"
30 #include "TDirectory.h"
31 
36 
43 
45 
48 
49 
50 #include "ReadCards.h"
51 #include "utils.h"
52 
53 #include "RoiFilter.h"
54 
55 #include "ConfAnalysis.h"
56 #include "PurityAnalysis.h"
57 
58 #include "ConfVtxAnalysis.h"
59 #include "TIDAReference.h"
60 
61 #include "lumiList.h"
62 #include "lumiParser.h"
63 #include "dataset.h"
64 
65 #include "event_selector.h"
66 
67 #include "BinConfig.h"
68 
69 #include "zbeam.h"
70 
71 #include "computils.h"
72 
74 #include "globals.h"
75 
78 
79 // in ConfAnalysis
80 
81 extern bool PRINT_BRESIDUALS;
82 
83 // in BinConfig.cxx
84 extern BinConfig g_binConfig;
85 
88 extern BinConfig tauBinConfig;
91 
92 void copyReleaseInfo( TTree* tree, TFile* foutdir );
93 
94 bool debugPrintout = false;
95 
96 
98 void handler(int sig) {
99  void *array[10];
100 
101  // get void*'s for all entries on the stack
102  size_t size = backtrace(array, 10);
103 
104  // print out all the frames to stderr
105  std::cout << "Error: signal %d:\n" << sig << std::endl;
106  backtrace_symbols_fd(array, size, STDERR_FILENO);
107  std::exit(1);
108 }
109 
110 
111 
112 
113 // useful function to return a string with the
114 // current date
115 std::string time_str() {
116  time_t t;
117  time(&t);
118  std::string s(ctime(&t));
119  // std::string::size_type pos = s.find("\n");
120  // if ( pos != std::string::npos )
121  return s.substr(0,s.find('\n'));
122  // return s;
123 }
124 
125 
126 
128 int atoi_check( const std::string& s ) {
129  int i = std::atoi( s.c_str() );
130  char check[128];
131  std::sprintf( check, "%d", i );
132  if ( std::string(check)!=s ) return -1;
133  else return i;
134 }
135 
136 
137 
138 
143 int GetChainAuthor(std::string chainName) {
144 
147  std::string s1 = chop(chainName,":");
148  std::string s2 = chop(chainName,":");
149  std::string s3 = chop(chainName,":");
150 
151  // if only s3=="" then no third token, if s2=="", no second token etc
152  // return atoi(s3.c_str());
153 
154  // std::cout << ">" << s1 << "< >" << s2 << "< >" << s3 << "<" << std::endl;
155  if ( s3=="0" ) return 0;
156  if ( s3=="1" ) return 1;
157  if ( s3=="2" ) return 2;
158  // }
159  return -1;
160 
161 }
162 
163 // Function to allow creation of an RoI for reference tracks, with custom widths, and which defaults to trigger roi values if none are specifed
165  double etaHalfWidth=-999,
166  double phiHalfWidth=-999,
167  double zedHalfWidth=-999 ) {
168 
169  double roi_eta = roi.eta();
170  double roi_phi = roi.phi();
171  double roi_zed = roi.zed();
172 
173  double etaMinus = roi.etaMinus();
174  double etaPlus = roi.etaPlus();
175 
176  double zedMinus = roi.zedMinus();
177  double zedPlus = roi.zedPlus();
178 
179  double phiMinus = roi.phiMinus();
180  double phiPlus = roi.phiPlus();
181 
182  if ( etaHalfWidth != -999 ) {
183  etaMinus = roi_eta - etaHalfWidth;
184  etaPlus = roi_eta + etaHalfWidth;
185  }
186 
187  if ( phiHalfWidth != -999 ) {
188  phiMinus = roi_phi - phiHalfWidth; // !!! careful! will this always wrap correctly?
189  phiPlus = roi_phi + phiHalfWidth; // !!! careful! will this always wrap correctly?
190  }
191 
192  if ( zedHalfWidth != -999 ) {
193  zedMinus = roi_zed - zedHalfWidth;
194  zedPlus = roi_zed + zedHalfWidth;
195  }
196 
197  return TIDARoiDescriptor( roi_eta, etaMinus, etaPlus,
198  roi_phi, phiMinus, phiPlus, // do wrap phi here (done within TIDARoiDescriptor already)
199  roi_zed, zedMinus, zedPlus );
200 }
201 
202 
203 // Small function to be used in sorting tracks in track vectors
204 bool trackPtGrtr( TIDA::Track* trackA, TIDA::Track* trackB) { return ( std::fabs(trackA->pT()) > std::fabs(trackB->pT()) ); }
205 
206 
207 template<typename T>
208 std::ostream& operator<<( std::ostream& s, const std::vector<T*>& v ) {
209  for ( size_t i=0 ; i<v.size() ; i++ ) s << "\t" << *v[i] << "\n";
210  return s;
211 }
212 
213 
214 template<typename T>
215 std::ostream& operator<<(std::ostream& s, const std::vector<T>& v ) {
216  if ( v.size()<5 ) for ( unsigned i=0 ; i<v.size() ; i++ ) s << "\t" << v[i];
217  else for ( unsigned i=0 ; i<v.size() ; i++ ) s << "\n\t" << v[i];
218  return s;
219 }
220 
221 
222 const std::vector<TIDA::Track> ibl_filter( const std::vector<TIDA::Track>& tv ) {
223 
224  static TH2D* h = 0;
225  static TH2D* h2 = 0;
226 
227  static int ic = 0;
228 
229 
230  if ( h==0 ) {
231  h = new TH2D( "hzvphi", "hzvphi", 150, -300, 300, 150, -M_PI, M_PI );
232  h2 = new TH2D( "hzvphi2", "hzvphi", 150, -300, 300, 150, -M_PI, M_PI );
233  }
234 
235  for ( size_t i=tv.size() ; i-- ; ) {
236 
237  if ( tv[i].author()!=5 ) break;
238 
239  double eta = tv[i].eta();
240 
241  double theta = 2*std::atan(-std::exp(eta));
242 
243  double ribl = 34.2; // actually 32.26 - 36.21 mm
244 
245  double z = tv[i].z0() + ribl/std::tan(theta);
246 
247  if ( !tv[i].expectBL() ) {
248  std::cout << "missing IBL: phi: " << tv[i].phi() << "\tz: " << z << " (" << eta << " " << theta*180/M_PI << ")" << std::endl;
249  if ( h ) h->Fill( z, tv[i].phi() );
250  }
251  else {
252  if ( h2 ) h2->Fill( z, tv[i].phi() );
253  }
254  }
255 
256  if ( ic>=500 ) {
257  ic = 0;
258  if ( h ) {
259  h->DrawCopy();
260  gPad->Print("zphimap.pdf");
261  h2->DrawCopy();
262  gPad->Print("zphimap2.pdf");
263  }
264  }
265 
266  ic++;
267 
268  return tv;
269 }
270 
271 
272 const std::vector<TIDA::Track> replaceauthor( const std::vector<TIDA::Track>& tv, int a0=5, int a1=4 ) {
273 
274  if ( a0==a1 ) return tv;
275 
276  std::vector<TIDA::Track> tr;
277  tr.reserve(tv.size());
278 
279  for ( size_t i=0 ; i<tv.size() ; i++ ) {
280  const TIDA::Track& t = tv[i];
281  int a = t.author();
282  if ( a==a0 ) a=a1;
283  tr.push_back( TIDA::Track( t.eta(), t.phi(), t.z0(), t.a0(), t.pT(), t.chi2(), t.dof(),
284  t.deta(), t.dphi(), t.dz0(), t.da0(), t.dpT(),
285  t.bLayerHits(), t.pixelHits(), t.sctHits(), t.siHits(),
286  t.strawHits(), t.trHits(),
287  t.hitPattern(), t.multiPattern(), a, t.hasTruth(),
288  t.barcode(), t.match_barcode(), t.expectBL(), t.id() ) );
289 
290  }
291 
292  return tr;
293 
294 }
295 
296 
297 
298 struct event_list {
299 
300  event_list(const std::string& filename) {
301 
302  std::cout << "event_list::event_list() ";
303  std::cout << filename << std::endl;
304 
305  std::ifstream file(filename.c_str());
306 
307  int evnt;
308 
309  while ( file>>evnt ) {
310  mevents.insert(evnt);
311  }
312 
313  std::cout << "event_list::event_list() ";
314  std::cout << mevents.size() << std::endl;
315 
316  }
317 
318  bool find(int i) {
320  if ( it!=mevents.end() ) return true;
321  return false;
322  }
323 
324  std::set<int> mevents;
325 
326 };
327 
328 
329 
330 
331 int usage(const std::string& name, int status) {
332  std::ostream& s = std::cout;
333 
334  s << "Usage: " << name << " <config filename> [OPTIONS]" << std::endl;
335  s << "\nOptions: \n";
336  s << " -o, -f, --file value\toutput filename, \n";
337  s << " -b, --binConfig value\tconfig file for histogram configuration, \n";
338  s << " -r, --refChain value\treference chain. + separated keys will be merged, \n";
339  s << " -t, --testChain value\ttest chain, \n";
340  s << " -p, --pdgId value\tpdg ID of truth particle if requiring truth particle processing,\n";
341  s << " --vt value\tuse value as the test vertex selector - overrides value in the config file,\n";
342  s << " --vr value\tuse value as the reference vertex selector - overrides value in the config file,\n";
343  s << " -n, --nofit \ttest do not fit resplots, \n";
344  s << " --rms \ttest force new rms95 errors, \n";
345  s << " -e, --entries value\ttest only run over value entries, \n";
346  // s << " -a, --all \tadd all grids (default)\n";
347  s << " -h, --help \tthis help\n";
348  // s << "\nSee " << PACKAGE_URL << " for more details\n";
349  s << "\nReport bugs to sutt@cern.ch";
350  s << std::endl;
351 
352  return status;
353 }
354 
355 
356 
357 
358 // #define DATA
359 
360 
361 // bool contains( const std::string& s, const std::string& r ) {
362 // return s.find(r)!=std::string::npos;
363 // }
364 
365 template<typename T>
366 std::vector<T*> pointers( std::vector<T>& v ) {
368  std::vector<T*> vp(v.size(),0);
369  for ( unsigned i=v.size() ; i-- ; ) vp[i] = &v[i];
370  return vp;
371 }
372 
373 
374 double ETmin = 0;
375 
376 bool SelectObjectET(const TrackTrigObject& t) { return std::fabs(t.pt())>ETmin; }
377 
378 
384 
385 double ETovPTmin = 0;
386 
388  bool ETselection = std::fabs(tobj.pt())>=ETmin;
389  bool ETovPTselection = true;
390  if ( t ) ETovPTselection = std::fabs(tobj.pt()/t->pT())>=ETovPTmin;
391  return ETselection&ETovPTselection;
392 }
393 
394 
395 
396 
397 
403 TrackFilter* getFilter( const std::string& refname, int pdgId,
404  TrackFilter* foff,
405  TrackFilter* fmu,
406  TrackFilter* ftruth ) {
407 
408  std::cout << "getFilter(): refname " << refname << std::endl;
409 
410  if ( refname=="Offline" ) return foff;
411  else if ( refname=="InDetLargeD0TrackParticles" ) return foff;
412  else if ( contains( refname, "Electrons") ) return foff;
413  else if ( contains( refname, "LRTElectrons") ) return foff;
414  else if ( contains( refname, "Muons" ) ) return fmu;
415  else if ( contains( refname, "MuonsLRT" ) ) return fmu;
416  else if ( contains( refname, "Taus" ) ) return foff; // tau ref chains
417  else if ( contains( refname, "1Prong" ) ) return foff; // tau ref chains
418  else if ( contains( refname, "3Prong" ) ) return foff; // tau ref chains
419  else if ( refname=="Truth" && pdgId!=0 ) return ftruth;
420  else if ( refname=="Truth" && pdgId==0 ) return foff;
421  else {
422  std::cerr << "unknown reference chain defined" << std::endl;
423  return 0;
424  }
425 }
426 
427 
428 bool GetRefTracks( const std::string& rc, const std::string& exclude,
429  const std::vector<TIDA::Chain>& chains,
430  NtupleTrackSelector& refTracks,
431  TrackAssociator* ex_matcher,
432  TrigObjectMatcher& tom ) {
433 
434  bool foundReference = false;
435 
436  for ( size_t ic=chains.size() ; ic-- ; ) {
437 
438  if ( chains[ic].name()==rc ) {
439 
440  foundReference = true;
441 
442  //Get tracks from within reference roi
443 
445 
446  if ( exclude.empty() ) {
447  refTracks.selectTracks( chains[ic].rois()[0].tracks() );
448  }
449  else {
450 
451  std::vector<TIDA::Track> tmptracks = chains[ic][0].tracks();
452 
453  for ( size_t ix=chains.size() ; ix-- ; ) {
454 
455  if ( chains[ix].name()==exclude ) {
456 
457  std::vector<TIDA::Track> extracks = chains[ix][0].tracks();
458 
459  std::vector<TIDA::Track*> refp;
460  std::vector<TIDA::Track*> refx;
461 
462  for ( size_t it=tmptracks.size() ; it-- ; ) refp.push_back( &tmptracks[it] );
463  for ( size_t it=extracks.size() ; it-- ; ) refx.push_back( &extracks[it] );
464 
467 
468  ex_matcher->match( refp, refx );
469 
470  std::vector<TIDA::Track*> refp_ex;
471 
472  for ( size_t it=refp.size() ; it-- ; ) {
474  if ( ex_matcher->matched(refp[it])==0 ) refp_ex.push_back(refp[it]);
475  }
476 
477  refTracks.clear();
478  refTracks.selectTracks( refp_ex );
479 
480  if ( debugPrintout ) {
481 
482  std::cout << "\nexclude: " << refp.size() << "\t" << refp_ex.size() << std::endl;
483  std::cout << "exclude:\n" << extracks << std::endl;
484  std::cout << "reference tracks: " << std::endl;
485 
486  size_t it0 = refp_ex.size();
487 
488  for ( size_t it=0 ; it<refp.size() && it0>0 ; it++ ) {
489  if ( refp[it]==refp_ex[it0-1] ) std::cout << it << "\t" << *refp[it] << "\t" << *refp_ex[--it0] << std::endl;
490  else std::cout << "\n" << it << "\t" << *refp[it] << "\t----\n" << std::endl;
491  }
492 
493  }
494 
495  break;
496  }
497 
498  }
499  }
500 
502 
503  if ( chains[ic].rois()[0].objects().size()>0 ) {
504  tom = TrigObjectMatcher( &refTracks, chains[ic].rois()[0].objects(), SelectObjectETovPT );
505  }
506 
507  break;
508  }
509  }
510 
511  return foundReference;
512 
513 }
514 
515 
516 
517 
518 
519 
520 int main(int argc, char** argv)
521 {
522  signal( SIGABRT, handler );
523  signal( SIGFPE, handler );
524  signal( SIGILL, handler );
525  signal( SIGSEGV, handler );
526  signal( SIGTERM, handler );
527 
528  // ROOT::Cintex::Cintex::Enable();
529 
530  if ( argc<2 ) {
531  std::cerr << "Error: no config file specified\n" << std::endl;
532  return usage(argv[0], -1);
533  }
534 
535  // event_list elist("events.txt");
536 
544 
545  std::cout << "$0 :: compiled " << __DATE__ << " " << __TIME__ << std::endl;
546 
548 
549  std::string histofilename("");
550 
551  std::string datafile = "";
552 
553  std::vector<std::string> refChains(0);
554 
555  std::vector<TrackFilter*> refFilters(0);
556 
557  TrackFilter* refFilter = 0;
558  TrackFilter* truthFilter = 0;
559 
560  std::string refChain = "";
561 
562  int pdgId = 0;
563 
564  std::vector<std::string> testChains;
565 
566  std::string binningConfigFile = "";
567 
568  bool useoldrms = true;
569  bool nofit = false;
570 
571  std::string vertexSelection = "";
572  std::string vertexSelection_rec = "";
573 
574  unsigned Nentries = 0;
575 
576  for ( int i=1 ; i<argc ; i++ ) {
577  if ( std::string(argv[i])=="-h" || std::string(argv[i])=="--help" ) {
578  return usage(argv[0], 0);
579  }
580  else if ( std::string(argv[i])=="-e" || std::string(argv[i])=="--entries" ) {
581  if ( ++i>=argc ) return usage(argv[0], -1);
582  Nentries = std::atoi(argv[i]);
583  }
584  else if ( std::string(argv[i])=="-o" || std::string(argv[i])=="-f" || std::string(argv[i])=="--file" ) {
585  if ( ++i>=argc ) return usage(argv[0], -1);
586  histofilename = argv[i];
587  if ( histofilename.find(".root")==std::string::npos ) histofilename += ".root";
588  }
589  else if ( std::string(argv[i])=="-r" || std::string(argv[i])=="--refChain" ) {
590  if ( ++i>=argc ) return usage(argv[0], -1);
591  refChain = argv[i];
592 
593  // Merge multiple references
594  if (refChain.find("+") != string::npos){
595  std::istringstream iss(refChain);
596  std::string token;
597  while (std::getline(iss, token, '+')){ // tokenize string based on '+' delimeter
598  refChains.push_back(token);
599  refFilters.push_back(0);
600  }
601  }
602  else {
603  refChains.push_back(argv[i]); // standard single reference
604  refFilters.push_back(0);
605  }
606  }
607  else if ( std::string(argv[i])=="--rms" ) useoldrms = false;
608  else if ( std::string(argv[i])=="-n" || std::string(argv[i])=="--nofit" ) nofit = true;
609  else if ( std::string(argv[i])=="-t" || std::string(argv[i])=="--testChain" ) {
610  if ( ++i>=argc ) return usage(argv[0], -1);
611  testChains.push_back(argv[i]);
612  }
613  else if ( std::string(argv[i])=="-p" || std::string(argv[i])=="--pdgId" ) {
614  if ( ++i>=argc ) return usage(argv[0], -1);
615  pdgId = atoi(argv[i]);
616  }
617  else if ( std::string(argv[i])=="--vr" ) {
618  if ( ++i>=argc ) return usage(argv[0], -1);
619  vertexSelection = argv[i];
620  }
621  else if ( std::string(argv[i])=="--vt" ) {
622  if ( ++i>=argc ) return usage(argv[0], -1);
623  vertexSelection_rec = argv[i];
624  }
625  else if ( std::string(argv[i])=="-b" || std::string(argv[i])=="--binConfig" ) {
626  if ( ++i>=argc ) return usage(argv[0], -1);
627  binningConfigFile = std::string(argv[i]);
628  }
629  else if ( std::string(argv[i]).find('-')==0 ) {
631  std::cerr << "unknown option " << argv[i] << std::endl;
632  return usage(argv[0], -1);
633  }
634  else {
635  datafile = argv[i];
636  }
637  }
638 
639 
640 
641  if ( datafile=="" ) {
642  std::cerr << "no config file specifed\n" << endl;
643  return usage(argv[0], -1);
644  }
645 
646  std::cout << time_str() << std::endl;
647 
648  ReadCards inputdata(datafile);
649 
650  inputdata.print();
651 
654  if ( useoldrms ) {
655  bool oldrms95 = true;
656  inputdata.declareProperty( "OldRMS95", oldrms95 );
657  std::cout << "setting Resplot old rms95 " << oldrms95 << std::endl;
658  Resplot::setoldrms95( oldrms95 );
659  }
660  else {
661  std::cout << "setting Resplot old rms95 " << useoldrms << std::endl;
662  Resplot::setoldrms95( useoldrms );
663  }
664 
665 
666  if ( nofit ) {
667  std::cout << "Not fitting resplots " << std::endl;
668  Resplot::setnofit( nofit );
669  }
670 
671 
672  unsigned nfiles = 0;
673  inputdata.declareProperty( "NFiles", nfiles );
674 
675 
676  if ( histofilename=="" ){
677  if ( inputdata.isTagDefined("outputFile") ) histofilename = inputdata.GetString("outputFile");
678  else {
679  std::cerr << "Error: no output file defined\n" << std::endl;
680  return usage(argv[0], -1);
681  }
682  }
683 
685  TFile foutput( histofilename.c_str(), "recreate" );
686  if (!foutput.IsOpen()) {
687  std::cerr << "Error: could not open output file\n" << std::endl;
688  return -1;
689  }
690 
691  TDirectory* foutdir = gDirectory;
692 
693  std::cout << "writing output to " << histofilename << std::endl;
694 
695  TH1D* hevent = new TH1D( "event", "event", 1000, 10000, 80000 );
696  Resplot* hcorr = new Resplot( "correlation", 21, -0.5, 20.5, 75, 0, 600);
697 
699 
700  double pT = 1000;
701  double eta = 2.5;
702  double zed = 2000;
703 
704  double a0min=0.;
705 
706  int npix = 1;
707  int nsct = 6;
708  int nbl = -1;
709 
710  int nsiholes = 2;
711  int npixholes = 20;
712  int nsctholes = 20;
713 
714  bool expectBL = false;
715 
716  double chi2prob = 0;
717 
718  int npix_rec = -2;
719  int nsct_rec = -2;
720 
721  double pT_rec = 0;
722  double eta_rec = 5;
723 
724  double Rmatch = 0.1;
725 
726  int ntracks = 0;
727 
728  double massMax = 130; // default invariant mass window for Tag and Probe Analyses only
729  double massMin = 50;
730 
731  //bool printflag = false; // JK removed (unused)
732 
733  bool rotate_testtracks = false;
734 
735  if ( inputdata.isTagDefined("RotateTestTracks") ) rotate_testtracks = ( inputdata.GetValue("RotateTestTracks") ? true : false );
736 
737  bool truthMatch = false;
738 
739  if ( inputdata.isTagDefined("TruthMatch") ) truthMatch = ( inputdata.GetValue("TruthMatch") ? true : false );
740 
741  // CK: Option to specify which ref tracks to use from ref track vector, ordered by pT
742  // User parameter is a vector of ref track vector indices
743  // e.g. specifyPtOrderedRefTracks = {0, 1, 5} will use the first leading, second leading, and sixth leading track
744  std::vector<size_t> refPtOrd_indices;
745  bool use_pt_ordered_ref = false;
746 
747  if ( inputdata.isTagDefined("UsePtOrderedRefTracks") ) {
748  std::vector<double> refPtOrd_indices_tmp;
749 
750  use_pt_ordered_ref = true;
751  refPtOrd_indices_tmp = ( inputdata.GetVector("UsePtOrderedRefTracks") );
752 
753  std::cout << "using PT ordered reference tracks: " << refPtOrd_indices_tmp << std::endl;
754 
755  for ( size_t i=refPtOrd_indices_tmp.size(); i-- ; ) {
756  refPtOrd_indices.push_back( refPtOrd_indices_tmp.at(i) );
757  }
758  }
759 
760  if ( inputdata.isTagDefined("pT") ) pT = inputdata.GetValue("pT");
761  if ( inputdata.isTagDefined("ET") ) ETmin = inputdata.GetValue("ET");
762  if ( inputdata.isTagDefined("ETovPT") ) ETovPTmin = inputdata.GetValue("ETovPT");
763 
766  double pTMax = pT-1;
767  if ( inputdata.isTagDefined("pTMax") ) pTMax = inputdata.GetValue("pTMax");
768 
769 
770  if ( inputdata.isTagDefined("NMod") ) NMod = inputdata.GetValue("NMod");
771 
772 
773  if ( inputdata.isTagDefined("eta") ) eta = inputdata.GetValue("eta");
774  if ( inputdata.isTagDefined("zed") ) zed = inputdata.GetValue("zed");
775  else if ( inputdata.isTagDefined("z0") ) zed = inputdata.GetValue("z0");
776  if ( inputdata.isTagDefined("npix") ) npix = inputdata.GetValue("npix");
777  if ( inputdata.isTagDefined("nsiholes") ) nsiholes = inputdata.GetValue("nsiholes");
778  if ( inputdata.isTagDefined("npixholes") ) npixholes = inputdata.GetValue("npixholes");
779  if ( inputdata.isTagDefined("nsctholes") ) nsctholes = inputdata.GetValue("nsctholes");
780  if ( inputdata.isTagDefined("expectBL") ) expectBL = ( inputdata.GetValue("expectBL") > 0.5 ? true : false );
781  if ( inputdata.isTagDefined("nsct") ) nsct = inputdata.GetValue("nsct");
782  if ( inputdata.isTagDefined("nbl") ) nbl = inputdata.GetValue("nbl");
783  if ( inputdata.isTagDefined("chi2prob") ) chi2prob = inputdata.GetValue("chi2prob");
784 
785  if ( inputdata.isTagDefined("ntracks") ) ntracks = inputdata.GetValue("ntracks")+0.5; // rounding necessary ?
786 
787 
788  if ( inputdata.isTagDefined("chi2prob") ) chi2prob = inputdata.GetValue("chi2prob");
789 
791  if ( pdgId==0 && inputdata.isTagDefined("pdgId") ) pdgId = inputdata.GetValue("pdgId");
792 
793  if ( inputdata.isTagDefined("InvMassMax") ) massMax = inputdata.GetValue("InvMassMax");
794  if ( inputdata.isTagDefined("InvMassMin") ) massMin = inputdata.GetValue("InvMassMin");
795 
796  if ( inputdata.isTagDefined("npix_rec") ) npix_rec = inputdata.GetValue("npix_rec");
797  if ( inputdata.isTagDefined("nsct_rec") ) nsct_rec = inputdata.GetValue("nsct_rec");
798 
799  if ( inputdata.isTagDefined("pT_rec") ) pT_rec = inputdata.GetValue("pT_rec");
800  if ( inputdata.isTagDefined("eta_rec") ) eta_rec = inputdata.GetValue("eta_rec");
801 
802  if ( inputdata.isTagDefined("a0") ) a0 = inputdata.GetValue("a0");
803  if ( inputdata.isTagDefined("a0min") ) a0min = inputdata.GetValue("a0min");
804 
805  if ( inputdata.isTagDefined("Rmatch") ) Rmatch = inputdata.GetValue("Rmatch");
806 
807  std::string useMatcher = "DeltaR";
808  if ( inputdata.isTagDefined("UseMatcher") ) useMatcher = inputdata.GetString("UseMatcher");
809 
810 
812  if ( refChain=="" ) {
813  if ( inputdata.isTagDefined("refChain") ) {
814  refChain = inputdata.GetString("refChain");
815  refChains.push_back(refChain);
816  refFilters.push_back(0);
817  }
818  else {
819  std::cerr << "Error: no reference chain defined\n" << std::endl;
820  // return usage(argv[0], -1);
821  return -1;
822  }
823  }
824 
825  std::string exclude = "";
826 
827  TrackAssociator* ex_matcher = 0;
828 
829  if ( inputdata.isTagDefined("Exclude") ) {
830  exclude = inputdata.GetString("Exclude");
831  ex_matcher = new Associator_BestDeltaRZSinThetaMatcher( "deltaRZ", 0.01, 0.01, 2 );
832  }
833 
834  if (refChains.size() == 0){
835  std::cerr << "Error: refChains is empty\n" <<std::endl;
836  return -1;
837  }
838 
840  if ( testChains.size()==0 ) {
841  if ( inputdata.isTagDefined("testChains") ) testChains = inputdata.GetStringVector("testChains");
842  else if ( inputdata.isTagDefined("testChain") ) testChains.push_back( inputdata.GetString("testChain") );
843  }
844 
847 
848  std::vector<ChainString> chainConfig;
849 
850  for ( size_t ic=0 ; ic<testChains.size() ; ic++ ) {
851  chainConfig.push_back( ChainString( testChains[ic] ) );
852  testChains[ic] = chainConfig.back().pre();
853  }
854 
855 
857 
858 
860  //if ( inputdata.isTagDefined("printflag") ) printflag = ( inputdata.GetValue("printflag") ? 1 : 0 ); // JK removed (unused)
861 
863  bool select_roi = true;
864 
865 
866  // CK: use a custom filter RoI for ref tracks using refFilter?
867  // Note that if the reference chain uses a non-full-scan RoI, the custom filter RoI could be wider than the
868  // ref chain RoI
869  bool use_custom_ref_roi = false;
870  const int custRefRoi_nParams = 3;
871 
872  double custRefRoi_params[custRefRoi_nParams] = {-999., -999., -999.};
873  std::vector<std::string> custRefRoi_chainList; // Vector of chain names to apply the custom roi to
874  std::set<std::string> customRoi_chains;
875 
876  if ( inputdata.isTagDefined("customRefRoi_etaHalfWidth") ) custRefRoi_params[0] = inputdata.GetValue("customRefRoi_etaHalfWidth");
877  if ( inputdata.isTagDefined("customRefRoi_phiHalfWidth") ) custRefRoi_params[1] = inputdata.GetValue("customRefRoi_phiHalfWidth");
878  if ( inputdata.isTagDefined("customRefRoi_zedHalfWidth") ) custRefRoi_params[2] = inputdata.GetValue("customRefRoi_zedHalfWidth");
879 
880  if ( inputdata.isTagDefined("customRefRoi_chainList") ) custRefRoi_chainList = inputdata.GetStringVector("customRefRoi_chainList");
881 
882  for ( unsigned ic=0 ; ic<custRefRoi_chainList.size() ; ic++ ) customRoi_chains.insert( custRefRoi_chainList[ic] );
883 
884  for ( int param_idx=0 ; param_idx<custRefRoi_nParams ; param_idx++ ) {
885  if ( custRefRoi_params[param_idx] != -999 ) {
886  select_roi = true; // In case select_roi is ever set to default to false
887  use_custom_ref_roi = true;
888  }
889  }
890 
891  if ( use_custom_ref_roi ) {
892  std::cout << "**** \t****" << std::endl;
893  std::cout << "**** Custom RoI will be used to filter ref. tracks\t****" << std::endl;
894 
895  if ( custRefRoi_params[0] != -999. ) std::cout << "**** etaHalfWidth = " << custRefRoi_params[0] << "\t\t\t\t****" << std::endl;
896  else std::cout << "**** etaHalfWidth = value used in trigger RoI\t****" << std::endl;
897 
898  if ( custRefRoi_params[1] != -999. ) std::cout << "**** phiHalfWidth = " << custRefRoi_params[1] << "\t\t\t\t****" << std::endl;
899  else std::cout << "**** phiHalfWidth = value used in trigger RoI\t****" << std::endl;
900 
901  if ( custRefRoi_params[2] != -999. ) std::cout << "**** zedHalfWidth = " << custRefRoi_params[2] << "\t\t\t\t****" << std::endl;
902  else std::cout << "**** zedHalfWidth = value used in trigger RoI\t****" << std::endl;
903 
904  if ( !custRefRoi_chainList.empty() ) {
905  std::cout << "**** \t****" << std::endl;
906  std::cout << "**** Applying custom RoI only to specified chains\t****" << std::endl;
907  }
908  std::cout << "**** \t****" << std::endl;
909  }
910 
911  // Checking for SelectRoi after any other options that will set select_roi, to ensure that the value set
912  // here will be used
913  if ( inputdata.isTagDefined("SelectRoi") ) {
914  select_roi = ( inputdata.GetValue("SelectRoi")!=0 ? true : false );
915  }
916 
917  if ( !select_roi ) {
918  std::cout << "**** ****" << std::endl;
919  std::cout << "**** RoI filtering of reference tracks is disabled ****" << std::endl;
920  std::cout << "**** ****" << std::endl;
921  }
922 
923  // bool selectfake_roi = false; // JK removed (unused)
924  // if ( inputdata.isTagDefined("SelectFakeRoi") ) {
925  // selectfake_roi = ( inputdata.GetValue("SelectFakeRoi")!=0 ? true : false ); // JK removed (unused)
926  // }
927 
928 
929  std::vector<double> lumiblocks;
931 
932 
933  if ( inputdata.isTagDefined("GRL") ) {
935  std::vector<std::string> grlvector = inputdata.GetStringVector("GRL");
936  std::cout << "Reading GRL from: " << grlvector << std::endl;
937  for ( size_t igrl=0 ; igrl<grlvector.size() ; igrl++ ) goodrunslist.read( grlvector[igrl] );
938  // std::cout << goodrunslist << std::endl;
939  }
940  else if ( inputdata.isTagDefined("LumiBlocks") ) {
942  lumiblocks = inputdata.GetVector("LumiBlocks");
943 
944  for (unsigned int i=0 ; i<lumiblocks.size()-2 ; i+=3 ){
945  goodrunslist.addRange( lumiblocks[i], lumiblocks[i+1], lumiblocks[i+2] );
946  }
947  }
948 
949 
951 
952 
953  if ( vertexSelection == "" ) {
954  if ( inputdata.isTagDefined("VertexSelection") ) vertexSelection = inputdata.GetString("VertexSelection");
955  }
956 
957  bool bestPTVtx = false;
958  bool bestPT2Vtx = false;
959  int vtxind = -1;
960 
961  if ( vertexSelection!="" ) {
962  if ( vertexSelection=="BestPT" ) bestPTVtx = true;
963  else if ( vertexSelection=="BestPT2" ) bestPT2Vtx = true;
964  else vtxind = atoi_check( vertexSelection );
965  }
966 
967 
968 
969 
971 
972  if ( vertexSelection_rec == "" ) {
973  if ( inputdata.isTagDefined("VertexSelectionRec") ) vertexSelection_rec = inputdata.GetString("VertexSelectionRec");
974  }
975 
976  bool bestPTVtx_rec = false;
977  bool bestPT2Vtx_rec = false;
978  int vtxind_rec = -1;
979 
980  if ( vertexSelection_rec!="" ) {
981  if ( vertexSelection_rec=="BestPT" ) bestPTVtx_rec = true;
982  else if ( vertexSelection_rec=="BestPT2" ) bestPT2Vtx_rec = true;
983  else vtxind_rec = atoi_check( vertexSelection_rec );
984  }
985 
986  std::cout << "vertexSelection: " << vertexSelection << std::endl;
987  std::cout << "vertexSelection_rec: " << vertexSelection_rec << std::endl;
988 
989 
990 #if 0
991 
994 
995  bool useBestVertex = false;
996  if ( inputdata.isTagDefined("useBestVertex") ) useBestVertex = ( inputdata.GetValue("useBestVertex") ? 1 : 0 );
997 
998  bool useSumPtVertex = true;
999  if ( inputdata.isTagDefined("useSumPtVertex") ) useSumPtVertex = ( inputdata.GetValue("useSumPtVertex") ? 1 : 0 );
1000 
1001  int MinVertices = 1;
1002  if ( inputdata.isTagDefined("MinVertices") ) MinVertices = inputdata.GetValue("MinVertices");
1003 
1005 
1006 #endif
1007 
1009  bool useVertexTracks = false;
1010  if ( inputdata.isTagDefined("UseVertexTracks") ) useVertexTracks = ( inputdata.GetValue("UseVertexTracks") > 0 );
1011 
1012  // option to vary default "PrimaryVertices" offline reference collection
1013  std::string vertex_refname = "Vertex";
1014  if ( inputdata.isTagDefined("VertexReference") ) vertex_refname += ":" + inputdata.GetString("VertexReference");
1015 
1017  int NVtxTrackCut = 2;
1018  if ( inputdata.isTagDefined("NVtxTrackCut") ) NVtxTrackCut = inputdata.GetValue("NVtxTrackCut");
1019 
1020 
1021  std::vector<double> event_list;
1022  bool event_selector_flag = false;
1023 
1024  if ( inputdata.isTagDefined("EventSelector") ) event_list = inputdata.GetVector("EventSelector");
1025 
1027 
1028  if ( es.size() ) event_selector_flag = true;
1029 
1030 
1031  std::vector<double> beamTest;
1032  std::vector<double> beamRef;
1033 
1034 
1035  bool correctBeamlineRef = false;
1036  bool correctBeamlineTest = false;
1037 
1038  if ( inputdata.isTagDefined("CorrectBeamlineRef") ) correctBeamlineRef = ( inputdata.GetValue("CorrectBeamlineRef") == 0 ? false : true );
1039  if ( inputdata.isTagDefined("CorrectBeamlineTest") ) correctBeamlineTest = ( inputdata.GetValue("CorrectBeamlineTest") == 0 ? false : true );
1040 
1041 
1042  if ( inputdata.isTagDefined("BeamTest") ) beamTest = inputdata.GetVector("BeamTest");
1043  else {
1044  if ( inputdata.isTagDefined("BeamTestx") ) beamTest.push_back(inputdata.GetValue("BeamTestx"));
1045  if ( inputdata.isTagDefined("BeamTesty") ) beamTest.push_back(inputdata.GetValue("BeamTesty"));
1046  }
1047 
1048 
1049  if ( inputdata.isTagDefined("BeamRef") ) beamRef = inputdata.GetVector("BeamRef");
1050  else {
1051  if ( inputdata.isTagDefined("BeamRefx") ) beamRef.push_back(inputdata.GetValue("BeamRefx"));
1052  if ( inputdata.isTagDefined("BeamRefy") ) beamRef.push_back(inputdata.GetValue("BeamRefy"));
1053  }
1054 
1055 
1056 
1057  if ( ( beamTest.size()!=0 && beamTest.size()!=2 && beamTest.size()!=3 ) ||
1058  ( beamRef.size()!=0 && beamRef.size()!=2 && beamRef.size()!=3 ) ) {
1059  std::cerr << "incorrectly specified beamline position" << std::endl;
1060  return (-1);
1061  }
1062 
1063  if ( beamTest.size()>0 ) correctBeamlineTest = true;
1064  if ( beamRef.size()>0 ) correctBeamlineRef = true;
1065 
1066  if ( correctBeamlineRef ) std::cout << "main() correcting beamline for reference tracks" << std::endl;
1067  if ( correctBeamlineTest ) std::cout << "main() correcting beamline for test tracks" << std::endl;
1068 
1069 
1070 
1071  if ( beamRef.size()>0 ) std::cout << "beamref " << beamRef << std::endl;
1072  if ( beamTest.size()>0 ) std::cout << "beamtest " << beamTest << std::endl;
1073 
1074  double a0v = 1000;
1075  double z0v = 2000;
1076 
1077  if ( inputdata.isTagDefined("a0v") ) a0v = inputdata.GetValue("a0v");
1078  if ( inputdata.isTagDefined("z0v") ) z0v = inputdata.GetValue("z0v");
1079 
1080 
1081  double a0vrec = 1000;
1082  double z0vrec = 2000;
1083 
1084  if ( inputdata.isTagDefined("a0vrec") ) a0vrec = inputdata.GetValue("a0vrec");
1085  if ( inputdata.isTagDefined("z0vrec") ) z0vrec = inputdata.GetValue("z0vrec");
1086 
1087  bool initialiseFirstEvent = false;
1088  if ( inputdata.isTagDefined("InitialiseFirstEvent") ) initialiseFirstEvent = inputdata.GetValue("InitialiseFirstEvent");
1089 
1090 
1091  // set the flag to prinout the missing track list in ConfAnalysis
1092  if ( inputdata.isTagDefined("dumpflag") ) dumpflag = ( inputdata.GetValue("dumpflag")==0 ? false : true );
1093 
1094 
1095  bool doPurity = false;
1096  if ( inputdata.isTagDefined("doPurity") ) doPurity = ( inputdata.GetValue("doPurity")==0 ? false : true );
1097 
1098  if ( inputdata.isTagDefined("DebugPrintout") ) debugPrintout = ( inputdata.GetValue("DebugPrintout")==0 ? false : true );
1099 
1100 
1101  bool monitorZBeam = false;
1102  if ( inputdata.isTagDefined("MonitorinZBeam") ) monitorZBeam = ( inputdata.GetValue("MonitorZBeam")==0 ? false : true );
1103 
1104  std::cout << "dbg " << __LINE__ << std::endl;
1105 
1106  ReadCards* binningConfig = &inputdata;
1107 
1109 
1110  if ( binningConfigFile!="" ) binningConfig = new ReadCards( binningConfigFile );
1111 
1113  g_binConfig.set( *binningConfig, "" );
1114  electronBinConfig.set( *binningConfig, "e_" );
1115  muonBinConfig.set( *binningConfig, "mu_" );
1116  tauBinConfig.set( *binningConfig, "tau_" );
1117  bjetBinConfig.set( *binningConfig, "bjet_" );
1118  cosmicBinConfig.set( *binningConfig, "cosmic_" );
1119 
1120 
1122  if ( binningConfig!=&inputdata ) delete binningConfig; // cppcheck-suppress autovarInvalidDeallocation; false positive
1123 
1124 
1125  if ( inputdata.isTagDefined("PRINT_BRESIDUALS") ) PRINT_BRESIDUALS = ( inputdata.GetValue("PRINT_BRESIDUALS")==0 ? false : true );
1126 
1127  int selectcharge = 0;
1128  if ( inputdata.isTagDefined("Charge") ) selectcharge = inputdata.GetValue("Charge");
1129 
1130 
1131  std::cout << "using reference " << refChain << std::endl;
1132  if ( refChain.find("Truth") != string::npos ) std::cout << "using pdgId " << pdgId << std::endl;
1133  if ( refChains.size() > 1 ) std::cout<<"Multiple reference chains split to: " << refChains <<std::endl;
1134 
1136 
1138 
1140  // Filter_Track( double etaMax, double d0Max, double z0Max, double pTMin,
1141  // int minPixelHits, int minSctHits, int minSiHits, int minBlayerHits,
1142  // int minStrawHits, int minTrHits, double prob=0 ) :
1143 
1145 
1146  std::cout << "a0v: " << a0v << std::endl;
1147  std::cout << "z0v: " << z0v << std::endl;
1148 
1149  Filter_Vertex filter_vertex( a0v, z0v );
1150 
1151  Filter_Track filter_offline( eta, 1000, a0min, zed, pT,
1152  npix, nsct, -1, nbl,
1153  -2, -2, chi2prob,
1154  npixholes, nsctholes, nsiholes, expectBL );
1155 
1156  if ( selectcharge!=0 ) filter_offline.chargeSelection( selectcharge );
1157  if ( pTMax>pT ) filter_offline.maxpT( pTMax );
1158 
1159  Filter_etaPT filter_etaPT(eta,pT);
1160 
1161 
1162  // std::cout << "pdgId " << pdgId << std::endl;
1163  //Select only true particles matching pdgId
1164  Filter_pdgId filter_pdgtruth(pdgId); //BP
1165 
1166  // select inside-out offline tracking
1167 
1168  // Filter_TruthParticle filter_passthrough(&filter_offline);
1169  // Filter_Track filter_track( eta, 1000, 2000, pT, npix, nsct, -1, -1, -2, -2);
1170 
1171  Filter_Author filter_inout(0);
1172 
1173  int author = 0;
1174 
1175  Filter_Author filter_auth(author);
1176 
1177  Filter_TrackQuality filter_q(0.01);
1178  Filter_Combined filter_off(&filter_offline, &filter_vertex);
1179 
1180  Filter_Combined filter_truth( &filter_pdgtruth, &filter_etaPT);
1181 
1182  Filter_Combined filter_muon( &filter_offline, &filter_vertex);
1183 
1184  Filter_Track filter_onlinekine( eta_rec, 1000, 0., 2000, pT, -1, npix, nsct, -1, -2, -2);
1185  Filter_Vertex filter_onlinevertex( a0vrec, z0vrec);
1186  Filter_Combined filter_online( &filter_onlinekine, &filter_onlinevertex );
1187 
1188  Filter_Track filter_offkinetight( 5, 1000, 0., 2000, pT, -1, 0, 0, -1, -2, -2);
1189  Filter_Combined filter_offtight( &filter_offkinetight, &filter_inout );
1190 
1191  Filter_Offline2017* filter_offline2017 = 0;
1192  Filter_Combined* filter_off2017 = 0;
1195 
1196 
1197  if ( inputdata.isTagDefined("Filter" ) ) {
1198  ChainString filter = inputdata.GetString("Filter");
1199  std::cout << "Filter: " << inputdata.GetString("Filter") << " : " << filter << std::endl;
1200  if ( filter.head()=="Offline2017" ) {
1201  std::string filter_type = filter.tail();
1202  filter_offline2017 = new Filter_Offline2017( pT, filter_type, zed, a0 );
1203  filter_off2017 = new Filter_Combined ( filter_offline2017, &filter_vertex);
1204  refFilter = filter_off2017;
1205  }
1206  else {
1207  std::cerr << "unimplemented Filter requested: " << filter.head() << std::endl;
1208  return -1;
1209  }
1210  }
1211  else {
1212  if ( !(refFilter = getFilter( refChains[0], pdgId, &filter_off, &filter_muon, &filter_truth ) ) ) {
1213  std::cerr << "unknown reference chain defined" << std::endl;
1214  return (-1);
1215  }
1216  }
1217 
1218  refFilters.push_back(refFilter);
1219 
1220 
1221  std::map<std::string,TIDA::Reference> ref;
1222 
1223  std::vector<NtupleTrackSelector*> refSelectors;
1224 
1225 #if 0
1226 
1230  for ( size_t ic=0 ; ic<refChains.size() ; ic++ ) {
1231 
1232  if ( refFilter==0 ) {
1233  if ( !(refFilters[ic] = getFilter( refChains[ic], pdgId, &filter_off, &filter_muon, &filter_truth ) ) ) {
1234  std::cerr << "unknown reference chain defined" << std::endl;
1235  return (-1);
1236  }
1237  refFilter = refFilters[ic];
1238  }
1239  else refFilters[ic] = refFilter;
1240 
1241  ref.insert( TIDA::ReferenceMap::value_type( refChains[ic], TIDA::Reference( refChains[ic], new NtupleTrackSelector(refFilter), refFilter, new TrigObjectMatcher ) ) );
1242 
1243  }
1244 
1245 # endif
1246 
1247  if (pdgId==0) truthFilter = &filter_off;
1248  else truthFilter = &filter_truth;
1249 
1250 
1251  // use an actual filter requiring at least 1 silicon hit
1252  // to get rid of the EF trt only tracks
1253 
1254  std::cout << "filter_passthrough" << std::endl;
1255 
1256  Filter_Track filter_passthrough( 10, 1000, 0., 2000, pT_rec, npix_rec, nsct_rec, 1, -2, -2, -2);
1257 
1258  TrackFilter* testFilter = &filter_passthrough;
1259 
1260 
1261  std::cout << "using tracks: " << refChain << " for reference sample" << std::endl;
1262 
1263 
1265  // std::vector<std::string> chains;
1266 
1267  std::vector<std::string>& test_chains = testChains;
1268 
1271  //smh: TrackAnalysis is purely abstract, analysis will contain ConfAnalysis
1272  std::map<std::string,TrackAnalysis*> analysis;
1273 
1277 
1278  std::vector<TrackAnalysis*> analyses;
1279  analyses.reserve(test_chains.size());
1280 
1281  std::cout << "booking " << test_chains.size() << " analyses" << std::endl;
1282 
1283  for ( unsigned i=0 ; i<test_chains.size() ; i++ ) {
1284 
1285  std::string chainname = ChainString(test_chains[i]);
1286 
1287  std::vector<std::string> chainnames;
1288 
1289  chainnames.push_back(chainname);
1290 
1291 
1292  // tag and probe object creation and configuration
1293 
1294  TagNProbe* TnP_tool = 0;
1295  ChainString probe = chainConfig[i];
1296 
1297  std::string probe_extra = probe.extra();
1298 
1299  if ( probe_extra.empty() ) probe_extra = probe.postvalue("extra");
1300 
1301  if ( probe_extra.find("_tag")!=std::string::npos || probe.extra().find("_tag")!=std::string::npos ) {
1302  std::cout << "rejecting tag chain " << probe << std::endl;
1303  continue;
1304  }
1305 
1306  // probe can be the .head() so convert m_chainNames to a ChainString and search the .extra() specifically
1307  size_t p = probe_extra.find("_probe");
1308 
1309  if ( p!=std::string::npos ) {
1310 
1311  std::string probe_ref = refChains[0];
1312 
1313  if ( !probe.postvalue("ref").empty() ) {
1314 
1315  probe_ref = probe.postvalue("ref");
1316 
1317  if ( refChains[0] != probe_ref ) {
1318  std::cerr << "default and probe chain references do not match: probe ref: " << probe_ref << " ref: " << refChains[0] << std::endl;
1319  return -1;
1320  }
1321 
1322  }
1323 
1324 
1325  std::string probe_key = probe_extra.erase(p, 6);
1326 
1327  for ( unsigned j=0 ; j<test_chains.size(); ++j) {
1328 
1329  if ( i==j ) continue;
1330 
1331  ChainString tag = chainConfig[j];
1332 
1333  if ( tag.head() != probe.head() ) continue;
1334 
1335  // if ( tag.tail() != probe.tail() ) continue; // should not enforce this for mu + tau tnp chains
1336 
1337  std::string tag_extra = tag.extra();
1338 
1339  if ( tag_extra.empty() ) tag_extra = tag.postvalue("extra");
1340  if ( tag_extra.find("_tag")==std::string::npos ) continue;
1341 
1342  // need to compare just the 'el1' part of of .extra() so create variables without '_probe/_tag' part
1343  std::string tag_key = tag_extra.erase( tag_extra.find("_tag"), 4) ;
1344 
1345  // tag chain must be the same as probe chain but with te=0 and extra=*_tag
1346  if ( tag_key != probe_key ) continue;
1347 
1348  if ( tag.element() == probe.element() ) continue;
1349 
1350  std::string tag_ref = refChains[0];
1351 
1353 
1354  TrackFilter* filter = getFilter( probe_ref, pdgId, &filter_off, &filter_muon, &filter_truth );
1355 
1356  ref.insert( TIDA::ReferenceMap::value_type( probe_ref, TIDA::Reference( probe_ref, new NtupleTrackSelector(filter), filter, new TrigObjectMatcher ) ) );
1357 
1358  if ( !tag.postvalue("ref").empty() ) {
1359 
1360  tag_ref = tag.postvalue("ref");
1361  // refChains.push_back( tag_ref);
1362 
1363  std::cout << "tag ref: " << tag_ref << std::endl;
1364 
1365  if ( ref.find(tag_ref)==ref.end() ) {
1366  TrackFilter* filter = getFilter( tag_ref, pdgId, &filter_off, &filter_muon, &filter_truth );
1367  // ref.insert( std::map<std::string,TIDA::Reference>::value_type( tag_ref, TIDA::Reference( tag_ref, new NtupleTrackSelector(filter) ) ) );
1369  }
1370  }
1371 
1375  // TnP_tool = new TagNProbe( refChains[0], refChains[0], massMin, massMax);
1376  TnP_tool = new TagNProbe( tag_ref, probe_ref, massMin, massMax);
1377  TnP_tool->tag(tag);
1378  TnP_tool->probe(probe);
1379  std::cout << "Tag and probe pair found! \n\t Tag : " << tag << "\n\t Probe : " << probe
1380  << "\n\t tag ref: " << tag_ref
1381  << "\n\tprobe ref: " << probe_ref
1382  << "\n-------------------" << std::endl;
1383 
1385  // std::cout << *TnP_tool << std::endl;
1386 
1387  break ;
1388  }
1389 
1390  }
1391 
1392  // Replace "/" with "_" in chain names, for Tag&Probe analysis
1393  if ( TnP_tool ) replace( chainname, "/", "_" );
1394  ConfAnalysis* analy_conf = new ConfAnalysis( chainname, chainConfig[i], TnP_tool );
1395 
1396  analy_conf->initialiseFirstEvent(initialiseFirstEvent);
1397  analy_conf->initialise();
1398  analy_conf->setprint(false);
1399 
1400  std::string vtxTool = chainConfig[i].postvalue("rvtx");
1401 
1402  if ( vtxTool!="" ) {
1405  ConfVtxAnalysis* anal_confvtx = new ConfVtxAnalysis( vtxTool, (vertex_refname!="Vertex") );
1406  // ConfVtxAnalysis* anal_confvtx = new ConfVtxAnalysis( "vertex" );
1407  analy_conf->store().insert( anal_confvtx, "rvtx" );
1408  }
1409 
1410 
1411  // analy_conf->setprint(true);
1412 
1417 
1422 
1423  if ( chainConfig[i].values().size()>0 ) {
1424  std::cout << "chain:: " << chainname << " : size " << chainConfig[i].values().size() << std::endl;
1425  for ( unsigned ik=chainConfig[i].values().size() ; ik-- ; ) {
1426  std::cout << "\tchainconfig: " << ik << "\tkey " << chainConfig[i].keys()[ik] << " " << chainConfig[i].values()[ik] << std::endl;
1427  }
1428  }
1429 
1431  // for (unsigned int ic=0 ; ic<chainnames.size() ; ic++ ) analysis[chainnames[ic]] = analy_conf;
1432 
1433  if ( analysis.find( chainname )==analysis.end() ) {
1434  analysis.insert( std::map<std::string,TrackAnalysis*>::value_type( chainname, analy_conf ) );
1435  analyses.push_back(analy_conf);
1436  }
1437  else {
1438  std::cerr << "WARNING: Duplicated chain"
1439  << "\n"
1440  << "---------------------------------"
1441  << "---------------------------------"
1442  << "---------------------------------" << std::endl;
1443  continue;
1444  }
1445 
1446  std::cout << "analysis: " << chainname << "\t" << analy_conf
1447  << "\n"
1448  << "---------------------------------"
1449  << "---------------------------------"
1450  << "---------------------------------" << std::endl;
1451 
1452  if ( doPurity ) {
1453  PurityAnalysis* analp = new PurityAnalysis(chainnames[0]+"-purity");
1454  std::cout << "purity " << (chainnames[0]+"-purity") << std::endl;
1455  analp->initialise();
1456  analp->setprint(false);
1457  // analp->setprint(true);
1458  analysis[chainnames[0]+"-purity"] = analp;
1459  analyses.push_back(analp);
1460  }
1461 
1462  }
1463 
1464  std::cout << "main() finished looping" << std::endl;
1465 
1467 
1468  bool fullyContainTracks = false;
1469 
1470  if ( inputdata.isTagDefined("FullyContainTracks") ) {
1471  fullyContainTracks = ( inputdata.GetValue("FullyContainTracks")==0 ? false : true );
1472  }
1473 
1474  bool containTracksPhi = true;
1475 
1476  if ( inputdata.isTagDefined("ContainTracksPhi") ) {
1477  containTracksPhi = ( inputdata.GetValue("ContainTracksPhi")==0 ? false : true );
1478  }
1479 
1480  if ( dynamic_cast<Filter_Combined*>(refFilter) ) {
1481  dynamic_cast<Filter_Combined*>(refFilter)->setDebug(debugPrintout);
1482  dynamic_cast<Filter_Combined*>(refFilter)->containtracks(fullyContainTracks);
1483  dynamic_cast<Filter_Combined*>(refFilter)->containtracksPhi(containTracksPhi);
1484  }
1485 
1486  NtupleTrackSelector refTracks( refFilter );
1487  NtupleTrackSelector offTracks( testFilter );
1488  NtupleTrackSelector testTracks( testFilter);
1489 
1490  NtupleTrackSelector truthTracks( truthFilter );
1491 
1492  // NtupleTrackSelector refTracks( &filter_passthrough );
1493  // NtupleTrackSelector testTracks( refFilter );
1494  // NtupleTrackSelector refTracks( &filter_pdgtruth);
1495  // NtupleTrackSelector testTracks( &filter_off );
1496  // NtupleTrackSelector testTracks(&filter_roi);
1497 
1499 
1500  bool filterRoi = false;
1501 
1502  double roieta = 0;
1503  bool roicomposite = false;
1504  size_t roimult = 1;
1505 
1506  if ( inputdata.isTagDefined( "FilterRoi" ) ) {
1507 
1508  filterRoi = true;
1509 
1510  std::vector<double> filter_values = inputdata.GetVector( "FilterRoi" );
1511 
1512  if ( filter_values.size()>0 ) roieta = filter_values[0];
1513  if ( filter_values.size()>1 ) roicomposite = ( filter_values[1]==0 ? false : true );
1514  if ( filter_values.size()>2 ) roimult = int(filter_values[2]+0.5);
1515 
1516  }
1517 
1518  RoiFilter roiFilter( roieta, roicomposite, roimult );
1519 
1521 
1522  TrackAssociator* matcher = 0;
1523 
1524  if ( useMatcher == "Sigma" ) matcher = new Associator_BestSigmaMatcher("sigma", Rmatch);
1525  else if ( useMatcher == "DeltaRZ" || useMatcher == "DeltaRZSinTheta" ) {
1526  double deta = 0.05;
1527  double dphi = 0.05;
1528  double dzed = 25;
1529  if ( inputdata.isTagDefined("Matcher_deta" ) ) deta = inputdata.GetValue("Matcher_deta");
1530  if ( inputdata.isTagDefined("Matcher_dphi" ) ) dphi = inputdata.GetValue("Matcher_dphi");
1531  if ( inputdata.isTagDefined("Matcher_dzed" ) ) dzed = inputdata.GetValue("Matcher_dzed");
1532 
1533  if ( useMatcher == "DeltaRZ" ) matcher = new Associator_BestDeltaRZMatcher( "deltaRZ", deta, dphi, dzed );
1534  else matcher = new Associator_BestDeltaRZSinThetaMatcher( "deltaRZ", deta, dphi, dzed );
1535  }
1536  else if ( useMatcher == "pT_2" ) {
1537  double pTmatchLim_2 = 1.0;
1538  if ( inputdata.isTagDefined("Matcher_pTLim_2") ) pTmatchLim_2 = inputdata.GetValue("Matcher_pTLim_2");
1539  matcher = new Associator_SecondBestpTMatcher("SecpT", pTmatchLim_2);
1540  }
1541  else if ( useMatcher == "Truth" ) {
1542  matcher = new Associator_TruthMatcher();
1543  }
1544  else {
1547  matcher = new Associator_BestDeltaRMatcher("deltaR", Rmatch);
1548  }
1549 
1551  TrackAssociator* truth_matcher = 0;
1552  if ( truthMatch ) {
1553  if ( useMatcher == "Sigma" ) truth_matcher = new Associator_BestSigmaMatcher("sigma_truth", Rmatch);
1554  else if ( useMatcher == "DeltaRZ" || useMatcher == "DeltaRZSinTheta" ) {
1555  double deta = 0.05;
1556  double dphi = 0.05;
1557  double dzed = 25;
1558  if ( inputdata.isTagDefined("Matcher_deta" ) ) deta = inputdata.GetValue("Matcher_deta");
1559  if ( inputdata.isTagDefined("Matcher_dphi" ) ) dphi = inputdata.GetValue("Matcher_dphi");
1560  if ( inputdata.isTagDefined("Matcher_dzed" ) ) dzed = inputdata.GetValue("Matcher_dzed");
1561 
1562  if ( useMatcher == "DeltaRZ" ) truth_matcher = new Associator_BestDeltaRZMatcher( "deltaRZ_truth", deta, dphi, dzed );
1563  else truth_matcher = new Associator_BestDeltaRZSinThetaMatcher( "deltaRZ_truth", deta, dphi, dzed );
1564  }
1565  else if ( useMatcher == "pT_2" ) {
1566  double pTmatchLim_2 = 1.0;
1567  if ( inputdata.isTagDefined("Matcher_pTLim_2") ) pTmatchLim_2 = inputdata.GetValue("Matcher_pTLim_2");
1568  truth_matcher = new Associator_SecondBestpTMatcher("SecpT_truth", pTmatchLim_2);
1569  }
1570  else if ( useMatcher == "Truth" ) {
1571  truth_matcher = new Associator_TruthMatcher();
1572  }
1573  else {
1576  truth_matcher = new Associator_BestDeltaRMatcher("deltaR_truth", Rmatch);
1577  }
1578  }
1579 
1580 
1581  // NtupleTrackSelector roiTracks( refFilter );
1582 
1583 
1585 
1586  NtupleTrackSelector refPurityTracks( &filter_inout );
1587  NtupleTrackSelector testPurityTracks( &filter_online );
1588 
1589  // get the list of input files
1590 
1591  std::vector<std::string> filenames;
1592 
1593 
1594  if ( inputdata.isTagDefined("DataSets") ) {
1595 
1596  std::cout << "fetching dataset details" << std::endl;
1597  std::vector<std::string> datasets = inputdata.GetStringVector("DataSets");
1598  for (unsigned int ids=0 ; ids<datasets.size() ; ids++ ) {
1599  std::cout << "\tdataset " << datasets[ids] << std::endl;
1600  dataset d( datasets[ids] );
1601  std::vector<std::string> filenames_ = d.datafiles();
1602  std::cout << "\tdataset contains " << filenames_.size() << " files" << std::endl;
1603  filenames.insert(filenames.end(), filenames_.begin(),filenames_.end());
1604  }
1605  }
1606  else if ( inputdata.isTagDefined("DataFiles") ) filenames = inputdata.GetStringVector("DataFiles");
1607  else {
1608  std::cerr << "no input data specified" << std::endl;
1609  return (-1);
1610  }
1611 
1612 
1614 
1615  // TString* releaseMetaData = 0;
1616  // data->SetBranchAddress("ReleaseMetaData",&releaseMetaData);
1617 
1618  bool show_release = true;
1619 
1620  std::vector<std::string> release_data;
1621 
1622  std::string release_data_save = "";
1623 
1624  if ( show_release ){
1625 
1626  bool first = true;
1627 
1628  for ( unsigned i=0 ; first && i<filenames.size() ; i++ ) {
1629 
1630  TFile* finput = TFile::Open( filenames[i].c_str() );
1631 
1632 
1633  if ( finput==0 || !finput->IsOpen() || finput->IsZombie() ) {
1634  std::cerr << "Error: could not open input file: " << filenames[i] << std::endl;
1635  exit(-1);
1636  }
1637 
1638  TTree* dataTree = (TTree*)finput->Get("dataTree");
1639  TString* releaseData = new TString("");
1640 
1641  if ( dataTree ) {
1642  dataTree->SetBranchAddress( "ReleaseMetaData", &releaseData);
1643 
1644  for (unsigned int i=0; i<dataTree->GetEntries() ; i++ ) {
1645  dataTree->GetEntry(i);
1646  release_data.push_back( releaseData->Data() );
1647  if ( release_data_save != release_data.back() ) {
1648  std::cout << "main() release data: " << release_data.back() << " : " << *releaseData << std::endl;
1649  }
1650  first = false;
1651  release_data_save = release_data.back();
1652  }
1653  }
1654 
1655  if ( finput ) delete finput;
1656  }
1657 
1658  // for ( unsigned ird=0 ; ird<release_data.size() ; ird++ ) std::cout << "presort " << ird << " " << release_data[ird] << std::endl;
1659 
1660  if ( !release_data.empty() ) {
1661  std::sort(release_data.begin(), release_data.end());
1662  release_data.erase(std::unique(release_data.begin(), release_data.end()), release_data.end());
1663 
1664  // for ( unsigned ird=0 ; ird<release_data.size() ; ird++ ) std::cout << "postsort " << ird << " " << release_data[ird] << std::endl;
1665 
1666  foutdir->cd();
1667 
1668  TTree* dataTree = new TTree("dataTree", "dataTree");
1669  TString* releaseData = new TString("");
1670 
1671  if ( dataTree ) {
1672  dataTree->Branch( "ReleaseMetaData", "TString", &releaseData);
1673 
1674  for ( unsigned ird=0 ; ird<release_data.size() ; ird++ ) {
1675  *releaseData = release_data[ird];
1676  dataTree->Fill();
1677  }
1678 
1679  dataTree->Write("", TObject::kOverwrite);
1680  delete dataTree;
1681  }
1682  }
1683 
1684  }
1685 
1686  // foutput.Write();
1687  // foutput.Close();
1688 
1689  // exit(0);
1690 
1691 
1692 
1693 
1694 
1695 
1696 
1697  if ( Nentries==0 && inputdata.isTagDefined("Nentries") ) {
1698  Nentries = unsigned(inputdata.GetValue("Nentries"));
1699  }
1700 
1701  unsigned event_counter = 0;
1702 
1703  typedef std::pair<int,double> zpair;
1704  std::vector<zpair> refz;
1705  std::vector<zpair> testz;
1706 
1707  std::vector<double> beamline_ref;
1708  std::vector<double> beamline_test;
1709 
1710  int maxtime = 0;
1711  int mintime = 0;
1712 
1713  std::cout << "opening files" << std::endl;
1714 
1715  bool run = true;
1716 
1717  int pregrl_events = 0;
1718  int grl_counter = 0;
1719 
1720 
1721  std::cout << "starting event loop " << time_str() << std::endl;
1722 
1723 
1724  size_t max_files = filenames.size();
1725  if ( nfiles!=0 && nfiles<max_files ) max_files = nfiles;
1726 
1727  for ( size_t ifile=0 ; run && ifile<max_files; ifile++ ) {
1728 
1729  bool newfile = true;
1730 
1731 
1732  TFile* finput = TFile::Open( filenames[ifile].c_str() );
1733 
1734  if ( finput==0 || !finput->IsOpen() || finput->IsZombie() ) {
1735  std::cerr << "Error: could not open output file " << filenames[ifile] << std::endl;
1736  continue;
1737  }
1738 
1739  TTree* data = (TTree*)finput->Get("tree");
1740 
1741  if ( !data ) {
1742  std::cerr << "Error: cannot open TTree: " << filenames[ifile] << std::endl;
1743  continue;
1744  }
1745 
1746  TIDA::Event* track_ev = new TIDA::Event();
1747 
1748  gevent = track_ev;
1749 
1750  data->SetBranchAddress("TIDA::Event",&track_ev);
1751 
1752 
1753  maxtime = track_ev->time_stamp();
1754  mintime = track_ev->time_stamp();
1755 
1756  unsigned cNentries = data->GetEntries();
1757 
1758  bool skip = true;
1759 
1762  for (unsigned int i=0; skip && run && i<cNentries ; i++ ) {
1763 
1764  data->GetEntry(i);
1765 
1766  r = track_ev->run_number();
1767  ev = track_ev->event_number();
1768  lb = track_ev->lumi_block();
1769  ts = track_ev->time_stamp();
1770 
1771  int event = track_ev->event_number();
1772  //int bc = track_ev->bunch_crossing_id();
1773 
1774 
1775  hipt = false;
1776 
1777 
1778 
1779  bool ingrl = goodrunslist.inRange( r, lb );
1780 
1781  pregrl_events++;
1782 
1784  if ( !ingrl ) continue;
1785 
1786  grl_counter++;
1787 
1788 
1790  if ( event_selector_flag && !es.in( event ) ) continue;
1791 
1792  if ( mintime>ts ) mintime = ts;
1793  if ( maxtime<ts ) maxtime = ts;
1794 
1795  if ( Nentries>0 && event_counter>Nentries ) {
1796  run = false;
1797  std::cout << "breaking out " << run << std::endl;
1798  break;
1799  }
1800 
1801  event_counter++;
1802 
1803  // if ( !elist.find(event) ) continue;
1804 
1805  // std::cout << "run " << r << "\tevent " << event << "\tlb " << lb << std::endl;
1806 
1807  hevent->Fill( event );
1808 
1809  if ( filenames.size()<2 ) {
1810  if ( (cNentries<10) || i%(cNentries/10)==0 || i%1000==0 || debugPrintout ) {
1811  std::cout << "run " << track_ev->run_number()
1812  << "\tevent " << track_ev->event_number()
1813  << "\tlb " << track_ev->lumi_block()
1814  << "\tchains " << track_ev->chains().size()
1815  << "\ttime " << track_ev->time_stamp();
1816  std::cout << "\t : processed " << i << " events so far (" << int((1000*i)/cNentries)*0.1 << "%)\t" << time_str() << std::endl;
1817  // std::cerr << "\tprocessed " << i << " events so far \t" << time_str() << std::endl;
1818  }
1819  }
1820  else if ( newfile ) {
1821 
1822  int pfiles = filenames.size();
1823  if ( nfiles>0 ) pfiles = nfiles;
1824 
1825 
1826  std::cout << "file entries=" << data->GetEntries();
1827 
1828  if ( data->GetEntries()<100 ) std::cout << " ";
1829  if ( data->GetEntries()<1000 ) std::cout << " ";
1830  if ( data->GetEntries()<10000 ) std::cout << " ";
1831 
1832  std::cout << "\t";
1833 
1834 
1835  std::cout << "run " << track_ev->run_number()
1836  << "\tevent " << track_ev->event_number()
1837  << "\tlb " << track_ev->lumi_block()
1838  << "\tchains " << track_ev->chains().size()
1839  << "\ttime " << track_ev->time_stamp();
1840 
1841  std::cout << "\t : processed " << ifile << " files so far (" << int((1e3*ifile)/pfiles)*0.1 << "%)\t" << time_str() << std::endl;
1842 
1843  newfile = false;
1844  }
1845 
1846  // if ( printflag ) std::cout << *track_ev << std::endl;
1847 
1848  r = track_ev->run_number();
1849 
1851 
1852  offTracks.clear();
1853  refTracks.clear();
1854  truthTracks.clear();
1855  refPurityTracks.clear();
1856 
1858  for ( TIDA::ReferenceMap::iterator mit=ref.begin() ; mit!=ref.end() ; ++mit ) {
1859  mit->second.selector()->clear();
1860  dynamic_cast<Filter_Combined*>(mit->second.filter())->setRoi(0);
1861  }
1862 
1863  Nvtxtracks = 0;
1864 
1865  const std::vector<TIDA::Chain>& chains = track_ev->chains();
1866 
1867  dynamic_cast<Filter_Combined*>(truthFilter)->setRoi(0);
1869  if ( truthMatch ) {
1870  for (unsigned int ic=0 ; ic<chains.size() ; ic++ ) {
1871  if ( chains[ic].name()=="Truth" ) {
1872  truthTracks.selectTracks( chains[ic][0].tracks() );
1873  break;
1874  }
1875  }
1876  }
1877 
1879  for (const std::string& rc : refChains){
1880  for (unsigned int ic=0 ; ic<chains.size() ; ic++ ) {
1881  if ( chains[ic].name()==rc ) {
1882  offTracks.selectTracks( chains[ic][0].tracks() );
1883  //extract beamline position values from rois
1884  beamline_ref = chains[ic][0].user();
1885  // std::cout << "beamline: " << chains[ic].name() << " " << beamline_ref << std::endl;
1886  break;
1887  }
1888  }
1889  }
1890 
1892 
1893  std::vector<TIDA::Vertex> vertices; // keep for now as will be needed later ...
1894 
1895  const TIDA::Chain* vtxchain = track_ev->chain(vertex_refname);
1896 
1897  if ( vtxchain && vtxchain->size()>0 ) {
1898 
1899  const std::vector<TIDA::Vertex>& mv = vtxchain->at(0).vertices();
1900 
1901  int selectvtx = -1;
1902  double selection = 0;
1903 
1904  if ( debugPrintout ) std::cout << "vertices:\n" << mv << std::endl;
1905 
1906  if ( bestPTVtx || bestPT2Vtx ) {
1907  for ( size_t iv=0 ; iv<mv.size() ; iv++ ) {
1908  if ( mv[iv].Ntracks()==0 ) continue;
1909  double selection_ = 0.0;
1910  TIDA::Vertex vtx_temp( mv[iv] );
1911  vtx_temp.selectTracks( offTracks.tracks() );
1912  for (unsigned itr=0; itr<vtx_temp.tracks().size(); itr++) {
1913  TIDA::Track* tr = vtx_temp.tracks().at(itr);
1914  if ( bestPTVtx ) selection_ += std::fabs(tr->pT());
1915  else if ( bestPT2Vtx ) selection_ += std::fabs(tr->pT())*std::fabs(tr->pT());
1916  }
1917  if( selection_>selection ) {
1918  selection = selection_;
1919  selectvtx = iv;
1920  }
1921  }
1922  if ( selectvtx!=-1 ) {
1923  vertices.push_back( mv[selectvtx] );
1924  }
1925  }
1926  else if ( vtxind>=0 ) {
1927  if ( size_t(vtxind)<mv.size() ) {
1928  vertices.push_back( mv[vtxind] );
1929  }
1930  }
1931  else {
1932  for ( size_t iv=0 ; iv<mv.size() ; iv++ ) {
1933  vertices.push_back( mv[iv] );
1934  }
1935  }
1936 
1938  filter_vertex.setVertex( vertices );
1939 
1941 
1942  NvtxCount = 0;
1943 
1944  for ( unsigned iv=0 ; iv<mv.size() ; iv++ ) {
1945  int Ntracks = mv[iv].Ntracks();
1946  if ( Ntracks>NVtxTrackCut ) {
1947  Nvtxtracks += Ntracks;
1948  // vertices.push_back( mv[iv] );
1949  NvtxCount++;
1950  }
1951  }
1952  }
1953 
1954  // filter_vertex.setVertex( vvtx ) ;
1955 
1956  hcorr->Fill( vertices.size(), Nvtxtracks );
1957 
1958  dynamic_cast<Filter_Combined*>(refFilter)->setRoi(0);
1959 
1963  bool foundReference = false;
1964 
1965  const TIDA::Chain* refchain = 0;
1966 
1969 
1970  TrigObjectMatcher tom;
1971 
1972  for ( const std::string& rc : refChains ) {
1973  foundReference |= GetRefTracks( rc, exclude, chains, refTracks, ex_matcher, tom );
1974  }
1975 
1977  // bool skip_tnp = false;
1978 
1979  for ( TIDA::ReferenceMap::iterator mitr=ref.begin() ; mitr!=ref.end() ; ++mitr ) {
1980 
1981  std::string refname = mitr->first;
1982 
1983  NtupleTrackSelector& selector = *dynamic_cast<NtupleTrackSelector*>( mitr->second.selector() );
1984 
1986  TrigObjectMatcher rtom;
1987 
1988  foundReference |= GetRefTracks( refname, exclude, chains, selector, ex_matcher, rtom );
1989 
1990  *mitr->second.tom() = rtom;
1991 
1995  // if ( refname.find("Tau")!=std::string::npos || refname.find("Electron")!=std::string::npos ) {
1996  // if ( rtom.status()==0 ) skip_tnp = true; /// maybe don't use this at the moment
1997  // }
1998 
1999  }
2000 
2001 
2002 
2003 
2004  if ( !foundReference ) continue;
2005 
2006  if ( debugPrintout ) {
2007  std::cout << "reference chain:\n" << *refchain << std::endl;
2008  }
2009 
2010  for ( unsigned ic=0 ; ic<track_ev->chains().size() ; ic++ ) {
2011 
2012  TIDA::Chain& chain = track_ev->chains()[ic];
2013 
2014  // std::cout << ic << " chain " << chain.name() << " size " << chain.size() << std::endl;
2015 
2017  std::map<std::string,TrackAnalysis*>::iterator analitr = analysis.find(chain.name());
2018 
2020 
2021  if ( analitr==analysis.end() ) continue;
2022 
2023  if ( debugPrintout ) {
2024  std::cout << "test chain:\n" << chain << std::endl;
2025  }
2026 
2027  ConfAnalysis* cf = dynamic_cast<ConfAnalysis*>(analitr->second);
2028 
2029  std::vector<TIDA::Roi*> rois;
2030 
2031  // tag and probe object retreival and filling of the roi vector
2032  TagNProbe* TnP_tool = cf->getTnPtool();
2033 
2034  if ( TnP_tool ) {
2035 
2036  foutdir->cd();
2037  cf->initialiseInternal();
2038  // changes to output directory and books the invariant mass histograms
2039  TH1F* invmass = cf->getHist_invmass();
2040  TH1F* invmass_obj = cf->getHist_invmassObj();
2041 
2043 
2044  TrackSelector* selector0 = mit0->second.selector();
2045  TrackFilter* filter0 = mit0->second.filter();
2046 
2047  TrigObjectMatcher* rtom = mit0->second.tom();
2048 
2049  if ( TnP_tool->type0() == TnP_tool->type1() ) {
2051  rois = TnP_tool->GetRois( track_ev->chains(), selector0, filter0, invmass, invmass_obj, rtom );
2052  }
2053  else {
2055 
2058 
2059  TrackSelector* selector1 = mit1->second.selector();
2060  TrackFilter* filter1 = mit1->second.filter();
2061 
2062  TrigObjectMatcher* rtom1 = mit1->second.tom();
2063 
2064 #if 0
2065  for ( size_t ia=0 ; ia<selector1->tracks().size() ; ia++ ) {
2066  const TIDA::Track* track = selector1->tracks()[ia];
2067  std::cout << ia << "\t" << *track << std::endl;
2068  std::cout << "\t" << rtom1->object(track->id()) << std::endl;
2069  }
2070 
2071  std::cout << *TnP_tool << std::endl;
2072 #endif
2073 
2074  rois = TnP_tool->GetRois( track_ev->chains(), selector0, filter0, selector1, filter1, invmass, invmass_obj, rtom, rtom1 );
2075  }
2076  }
2077  else {
2078  // if not a tnp analysis then fill rois in the normal way
2079  rois.reserve( chain.size() );
2080  for ( size_t ir=0 ; ir<chain.size() ; ir++ ) rois.push_back( &(chain.rois()[ir]) );
2081  }
2082 
2084  if ( false ) std::cout << "++++++++++++ rois size = " << rois.size() << " +++++++++++" << std::endl;
2085 
2086  //for (unsigned int ir=0 ; ir<chain.size() ; ir++ ) {
2087  for (unsigned int ir=0 ; ir<rois.size() ; ir++ ) { // changed for tagNprobe
2088 
2090 
2091  //TIDA::Roi& troi = chain.rois()[ir];
2092  TIDA::Roi& troi = *rois[ir]; // changed for tagNprobe
2093  TIDARoiDescriptor roi( troi.roi() );
2094 
2095  testTracks.clear();
2096 
2097  testTracks.selectTracks( troi.tracks() );
2098 
2100  std::vector<TIDA::Track*> testp = testTracks.tracks();
2101 
2104 
2105  if ( filterRoi && !roiFilter.filter( roi ) ) continue;
2106 
2108  const std::vector<TIDA::Vertex>& mvt = troi.vertices();
2109 
2110  std::vector<TIDA::Vertex> vertices_test;
2111 
2112  int selectvtx = -1;
2113  double selection = 0;
2114 
2115  if ( bestPTVtx_rec || bestPT2Vtx_rec ) {
2116 
2117  // const std::vector<TIDA::Track>& recTracks = troi.tracks();
2118 
2119  for ( unsigned iv=0 ; iv<mvt.size() ; iv++ ) {
2120  double selection_ = 0.0;
2121  TIDA::Vertex vtx_temp( mvt[iv] );
2122  vtx_temp.selectTracks( testp );
2123  for (unsigned itr=0; itr<vtx_temp.tracks().size(); itr++) {
2124  TIDA::Track* tr = vtx_temp.tracks().at(itr);
2125  if ( bestPTVtx ) selection_ += std::fabs(tr->pT());
2126  else if ( bestPT2Vtx ) selection_ += std::fabs(tr->pT())*std::fabs(tr->pT());
2127  }
2128  if( selection_>selection){
2129  selection = selection_;
2130  selectvtx = iv;
2131  }
2132  }
2133  if ( selectvtx!=-1 ) {
2134  TIDA::Vertex selected( mvt[selectvtx] );
2135  if ( useVertexTracks ) selected.selectTracks( testp );
2136  vertices_test.push_back(selected);
2137  }
2138  }
2139  else if ( vtxind_rec!=-1 ) {
2140  if ( unsigned(vtxind_rec)<mvt.size() ) {
2141  TIDA::Vertex selected( mvt[vtxind] );
2142  if ( useVertexTracks ) selected.selectTracks( testp );
2143  vertices_test.push_back( selected );
2144  }
2145  }
2146  else {
2147  for ( unsigned iv=0 ; iv<mvt.size() ; iv++ ) {
2148  TIDA::Vertex selected( mvt[iv] );
2149  if ( useVertexTracks ) selected.selectTracks( testp );
2150  vertices_test.push_back( selected );
2151  }
2152  }
2153 
2154  //extract beamline position values from rois
2155  beamline_test = rois[ir]->user(); // changed for tagNprobe
2156 
2157  //set values of track analysis to these so can access elsewhere
2158  for ( size_t i=analyses.size() ; i-- ; ) {
2159 
2160  TrackAnalysis* analy_track = analyses[i];
2161 
2162  if ( correctBeamlineTest ) {
2163  if ( beamTest.size()==2 ) analy_track->setBeamTest( beamTest[0], beamTest[1] );
2164  // else if ( beamTest.size()==3 ) analy_track->setBeamTest( beamTest[0], beamTest[1], beamTest[2] );
2165  else {
2166  if ( !inputdata.isTagDefined("BeamTest") ) {
2167  if ( beamline_test.size()==2 ) analy_track->setBeamTest( beamline_test[0], beamline_test[1] );
2168  // else if ( beamline_test.size()==3 ) analy_track->setBeamTest( beamline_test[0], beamline_test[1], beamline_test[2] );
2169  }
2170  }
2171  }
2172 
2173  if ( correctBeamlineRef ) {
2174  if ( beamRef.size()==2 ) analy_track->setBeamRef( beamRef[0], beamRef[1] );
2175  // else if ( beamRef.size()==3 ) analy_track->setBeamRef( beamRef[0], beamRef[1], beamRef[2] );
2176  else {
2177  if ( !inputdata.isTagDefined("BeamRef") ) {
2178  if ( beamline_ref.size()==2 ) analy_track->setBeamRef( beamline_ref[0], beamline_ref[1] );
2179  // else if ( beamline_ref.size()==3 ) analy_track->setBeamRef( beamline_ref[0], beamline_ref[1], beamline_ref[2] );
2180  }
2181  }
2182  }
2183 
2184  }
2185 
2188 
2189  TIDARoiDescriptor refRoi;
2190 
2191  if ( select_roi ) {
2192 
2196 
2197  bool customRefRoi_thisChain = false;
2198 
2199  if ( use_custom_ref_roi ) { // Ideally just want to say ( use_custom_ref_roi && (chain.name() in custRefRoi_chain]sist) )
2200  if ( customRoi_chains.size() ) {
2201  if ( customRoi_chains.find( chain.name() )!=customRoi_chains.end() ) customRefRoi_thisChain = true;
2202  }
2203  else customRefRoi_thisChain = true; // Apply custom ref roi to all chains
2204  }
2205 
2206  if ( use_custom_ref_roi && customRefRoi_thisChain ) {
2207  refRoi = makeCustomRefRoi( roi, custRefRoi_params[0], custRefRoi_params[1], custRefRoi_params[2] );
2208  }
2209  else refRoi = roi;
2210 
2211  dynamic_cast<Filter_Combined*>(refFilter)->setRoi(&refRoi);
2212  }
2213 
2214  // if ( debugPrintout ) {
2215  // std::cout << "refTracks.size() " << refTracks.size() << " before roi filtering" << std::endl;
2216  // std::cout << "filter with roi " << roi << std::endl;
2217  // }
2218 
2219 
2220  // Now filterng ref tracks by refFilter, and performing any further filtering and selecting,
2221  // before finally creating the const reference object refp
2222 
2223  std::vector<TIDA::Track*> refp_vec = refTracks.tracks( refFilter );
2224 
2225  // Selecting only truth matched reference tracks
2226  if ( truthMatch ) {
2228  if ( select_roi ) dynamic_cast<Filter_Combined*>(truthFilter)->setRoi(&roi);
2229  const std::vector<TIDA::Track*>& truth = truthTracks.tracks(truthFilter);
2230  const std::vector<TIDA::Track*>& refp_tmp = refp_vec;
2231 
2233  truth_matcher->match( refp_tmp, truth );
2234 
2235  std::vector<TIDA::Track*> refp_matched;
2236 
2238  for ( unsigned i=0 ; i<refp_vec.size() ; i++ ) {
2239  if ( truth_matcher->matched( refp_vec[i] ) ) refp_matched.push_back( refp_vec[i] );
2240  }
2241 
2242  refp_vec.clear();
2243  refp_vec = refp_matched;
2244  }
2245 
2246  // Choose the pT ordered refp tracks that have been asked for by the user
2247  if ( use_pt_ordered_ref ) {
2248  std::sort( refp_vec.begin(), refp_vec.end(), trackPtGrtr ); // Should this sorting be done to a temporary copied object, instead of the object itself?
2249 
2250  size_t nRefTracks = refp_vec.size();
2251 
2252  std::vector<TIDA::Track*> refp_chosenPtOrd;
2253 
2254  if ( debugPrintout ) {
2255  // Checking if any user specifed track indices are out of bounds for this event
2256  for ( size_t sidx=refPtOrd_indices.size() ; sidx-- ; ) {
2257  if ( refPtOrd_indices.at(sidx)>nRefTracks ) {
2258  std::cout << "WARNING: for event " << event
2259  << ", pT ordered reference track at vector position " << refPtOrd_indices.at(sidx)
2260  << " requested but not found" << std::endl;
2261  break;
2262  }
2263  }
2264  }
2265 
2266  for ( size_t sidx=refPtOrd_indices.size() ; sidx-- ; ) {
2267  for ( size_t idx=0 ; idx<refp_vec.size() ; idx++ ) {
2268  if ( idx == refPtOrd_indices.at(sidx) ) {
2269  refp_chosenPtOrd.push_back(refp_vec.at(idx));
2270  break;
2271  }
2272  }
2273  }
2274 
2275  refp_vec.clear();
2276  refp_vec = refp_chosenPtOrd; // Note: not necessarily pT ordered.
2277  // Ordered by order of indices the user has passed
2278  // (which is ideally pT ordered e.g. 0, 1, 3)
2279  }
2280 
2282  if ( cf ) {
2283 
2285 
2286  std::string ptconfig = cf->config().postvalue("pt");
2287  if ( ptconfig!="" ) {
2288  double pt = std::atof( ptconfig.c_str() );
2289  if ( pt>0 ) {
2290  std::vector<TIDA::Track*> reft; reft.reserve(refp_vec.size());
2291  for ( std::vector<TIDA::Track*>::const_iterator itr=refp_vec.begin() ; itr!=refp_vec.end() ; ++itr ) {
2292  if ( std::fabs((*itr)->pT())>=pt ) reft.push_back( *itr );
2293  }
2294  refp_vec = reft;
2295  }
2296  }
2297 
2299 
2300  std::string d0config = cf->config().postvalue("d0");
2301  if ( d0config!="" ) {
2302  double d0 = std::atof( d0config.c_str() );
2303  if ( d0>0 ) {
2304  std::vector<TIDA::Track*> reft; reft.reserve(refp_vec.size());
2305  for ( std::vector<TIDA::Track*>::const_iterator itr=refp_vec.begin() ; itr!=refp_vec.end() ; ++itr ) {
2306  if ( std::fabs((*itr)->a0())<=d0 ) reft.push_back( *itr );
2307  }
2308  refp_vec = reft;
2309  }
2310  }
2311 
2312  }
2313 
2316 
2318 
2319  if ( tom.status() ) {
2320 
2321  std::string objectET = cf->config().postvalue("ET");
2322 
2323  if ( objectET != "" ) {
2324 
2325  double ETconfig = std::atof( objectET.c_str() );
2326 
2327  if ( ETconfig>0 ) {
2328 
2329  std::vector<TIDA::Track*>::iterator itr=refp_vec.begin() ;
2330 
2331  while ( itr!=refp_vec.end() ) {
2332  const TrackTrigObject* tobj = tom.object( (*itr)->id() );
2333 
2334  if ( tobj==0 || tobj->pt()<ETconfig )
2335  itr=refp_vec.erase( itr );
2336  else
2337  ++itr;
2338  }
2339  }
2340  }
2341  }
2342 
2343  const std::vector<TIDA::Track*>& refp = refp_vec;
2344 
2345  // if ( debugPrintout ) {
2346  // std::cout << "refp.size() " << refp.size() << " after roi filtering" << std::endl;
2347  // }
2348 
2349 
2350  // std::cout << "ref tracks refp.size() " << refp.size() << "\n" << refp << std::endl;
2351  // std::cout << "test tracks testp.size() " << testp.size() << "\n" << testp << std::endl;
2352 
2353  groi = &roi;
2354 
2358 
2359  // new vertex class containing tracks, offline
2360  std::vector<TIDA::Vertex> vertices_roi;
2361 
2363  // if ( chain.name().find("SuperRoi") ) {
2364  {
2365 
2367 
2368  vertices_roi.clear();
2369 
2370  const std::vector<TIDA::Vertex>& mv = vertices;
2371 
2372  // std::cout << "vertex filtering " << mv.size() << std::endl;
2373 
2374 
2375  for ( unsigned iv=0 ; iv<mv.size() ; iv++ ) {
2376 
2377  const TIDA::Vertex& vx = mv[iv];
2378 
2379  // reject all vertices that are not in the roi
2380 
2381  bool accept_vertex = false;
2382  if ( roi.composite() ) {
2383  for ( size_t ir=0 ; ir<roi.size() ; ir++ ) {
2384  if ( roi[ir]->zedMinus()<=vx.z() && roi[ir]->zedPlus()>=vx.z() ) accept_vertex = true;
2385  }
2386  }
2387  else {
2388  if ( roi.zedMinus()<=vx.z() && roi.zedPlus()>=vx.z() ) accept_vertex = true;
2389  }
2390 
2391  if ( !accept_vertex ) continue;
2392 
2393  // std::cout << "\t" << iv << "\t" << vx << std::endl;
2394 
2395  int trackcount = 0;
2396 
2397  if ( useVertexTracks ) {
2398  // refp contains roi filtered tracks, vx contains ids of tracks belonging to vertex
2399  TIDA::Vertex vertex_roi( vx );
2400  vertex_roi.selectTracks( refp );
2401  trackcount = vertex_roi.Ntracks();
2402  if ( trackcount>=ntracks && trackcount>0 ) {
2403  vertices_roi.push_back( vertex_roi );
2404  }
2405  }
2406  else {
2407  // old track count method still in use?
2408  for (unsigned itr=0; itr<refp.size(); itr++){
2409  TIDA::Track* tr = refp[itr];
2410  double theta_ = 2*std::atan(std::exp(-tr->eta()));
2411  double dzsintheta = std::fabs( (vx.z()-tr->z0()) * std::sin(theta_) );
2412  if( dzsintheta < 1.5 ) trackcount++;
2413  }
2417  if ( trackcount>=ntracks && trackcount>0 ) {
2418  const TIDA::Vertex& vertex_roi( vx );
2419  vertices_roi.push_back( vertex_roi );
2420  }
2421  }
2422 
2423  }
2424  }
2425  // else vertices_roi = vertices;
2426 
2427  if ( rotate_testtracks ) for ( size_t i=testp.size() ; i-- ; ) testp[i]->rotate();
2428 
2429  foutdir->cd();
2430 
2431  // do analysing
2432 
2433  if ( monitorZBeam ) {
2434  if ( beamline_ref.size()>2 && beamline_test.size()>2 ) {
2435  refz.push_back( zpair( lb, beamline_ref[2]) );
2436  testz.push_back( zpair( lb, beamline_test[2]) );
2437  }
2438  }
2439 
2440  matcher->match( refp, testp);
2441 
2442  if ( tom.status() ) analitr->second->execute( refp, testp, matcher, &tom );
2443  else analitr->second->execute( refp, testp, matcher );
2444 
2445  ConfVtxAnalysis* vtxanal = 0;
2446  analitr->second->store().find( vtxanal, "rvtx" );
2447 
2450  if ( vtxanal && ( refp.size() >= size_t(ntracks) ) ) {
2451 
2459 
2461 
2462  if ( vertices_roi.size()>0 ) vtxanal->execute( pointers(vertices_roi), pointers(vertices_test), track_ev );
2463 
2464  }
2465 
2466 
2467  if ( debugPrintout ) {
2468  // std::cout << "-----------------------------------\n\nselected tracks:" << chain.name() << std::endl;
2469  std::cout << "\nselected tracks:" << chain.name() << std::endl;
2470  std::cout << "ref tracks refp.size() " << refp.size() << "\n" << refp << std::endl;
2471  std::cout << "test tracks testp.size() " << testp.size() << "\n" << testp << std::endl;
2472 
2473  TrackAssociator::map_type::const_iterator titr = matcher->TrackAssociator::matched().begin();
2474  TrackAssociator::map_type::const_iterator tend = matcher->TrackAssociator::matched().end();
2475  int im=0;
2476  std::cout << "track matches:\n";
2477  while (titr!=tend) {
2478  std::cout << "\t" << im++ << "\t" << *titr->first << " ->\n\t\t" << *titr->second << std::endl;
2479  ++titr;
2480  }
2481 
2482 
2483  std::cout << "completed : " << chain.name() << "\n";
2484  std::cout << "-----------------------------------" << std::endl;
2485 
2486  }
2487 
2488 #if 0
2489  if ( _matcher->size()<refp.size() ) {
2490 
2491  if ( refp.size()==1 && testp.size()==0 ) {
2492  std::cout << track_ev->chains()[ic] <<std::endl;
2493  std::cout << "roi\n" << track_ev->chains()[ic].rois()[ir] << endl;
2494  }
2495 
2496  }
2497 #endif
2498 
2500 
2501  if ( doPurity ) {
2502 
2503  const std::vector<TIDA::Track*>& refpp = refPurityTracks.tracks( refFilter );
2504 
2505  testPurityTracks.clear();
2506 
2507  testPurityTracks.selectTracks( troi.tracks() );
2508  std::vector<TIDA::Track*> testpp = testPurityTracks.tracks();
2509 
2510  matcher->match(refpp, testpp);
2511 
2512 
2513  std::map<std::string,TrackAnalysis*>::iterator analitrp = analysis.find(chain.name()+"-purity");
2514 
2515  if ( analitrp == analysis.end() ) continue;
2516 
2517 
2518  analitrp->second->execute( refpp, testpp, matcher );
2519 
2520 
2521 
2522  }
2523 
2524  } // loop through rois
2525 
2526  } // loop through chanines - this block is indented incorrectly
2527 
2528  } // loop through nentries
2529 
2530  delete track_ev;
2531  delete data;
2532  delete finput;
2533 
2534  // std::cout << "run: " << run << std::endl;
2535 
2536  }// loop through files
2537 
2538  std::cout << "done " << time_str() << "\tprocessed " << event_counter << " events"
2539  << "\ttimes " << mintime << " " << maxtime
2540  << "\t( grl: " << grl_counter << " / " << pregrl_events << " )" << std::endl;
2541 
2542  if ( monitorZBeam ) zbeam zb( refz, testz );
2543 
2544  foutdir->cd();
2545 
2546  // hcorr->Finalise(Resplot::FitPoisson);
2547 
2548  hcorr->Finalise(Resplot::FitNull95);
2549  hcorr->Write();
2550 
2551  for ( int i=analyses.size() ; i-- ; ) {
2552  // std::cout << "finalise analysis chain " << analyses[i]->name() << std::endl;
2553  analyses[i]->finalise();
2554 
2555  ConfVtxAnalysis* vtxanal = 0;
2556  analyses[i]->store().find( vtxanal, "rvtx" );
2557  if ( vtxanal ) vtxanal->finalise();
2558 
2559  delete analyses[i];
2560  }
2561 
2562  foutput.Write();
2563  foutput.Close();
2564 
2565 
2566  // for ( std::map<std::string,TIDA::Reference>::iterator mit=ref.begin() ; mit!=ref.end() ; ++mit++ ) {
2567  for ( TIDA::ReferenceMap::iterator mit=ref.begin() ; mit!=ref.end() ; ++mit++ ) {
2568  mit->second.Clean();
2569  }
2570 
2571 
2572  if ( ex_matcher ) delete ex_matcher;
2573 
2574  std::cout << "done" << std::endl;
2575 
2576  return 0;
2577 }
2578 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
NtupleTrackSelector::selectTracks
void selectTracks(const std::vector< TIDA::Track > &tracks)
extract all the tracks from a vector of Tracks
Definition: NtupleTrackSelector.h:48
TIDA::Roi::roi
const TIDARoiDescriptor & roi() const
access the roi information
Definition: TIDARoi.h:42
Resplot::setnofit
static bool setnofit(bool b)
Definition: Resplot.h:557
TrackAnalysis::setBeamTest
void setBeamTest(double x, double y, double z=0)
Definition: TrackAnalysis.h:110
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
debugPrintout
bool debugPrintout
Definition: rmain.cxx:94
beamspotman.r
def r
Definition: beamspotman.py:676
TIDA::Associator
Definition: TIDAAssociator.h:24
bjetBinConfig
BinConfig bjetBinConfig
CalculateHighPtTerm.pT
pT
Definition: ICHEP2016/CalculateHighPtTerm.py:57
SelectObjectET
bool SelectObjectET(const TrackTrigObject &t)
Definition: rmain.cxx:376
Track.h
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
TIDA::Reference
Definition: TIDAReference.h:28
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
python.utility.LHE.event_counter
def event_counter(input_file_pattern)
Count total number of events in input files.
Definition: LHE.py:89
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
RoiFilter.h
TIDARoiDescriptor::phi
double phi() const
Definition: TIDARoiDescriptor.h:133
SelectObjectETovPT
bool SelectObjectETovPT(const TrackTrigObject &tobj, TIDA::Track *t=0)
Definition: rmain.cxx:387
Associator_BestDeltaRZSinThetaMatcher
Definition: Associator_BestMatch.h:152
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
Resplot::Fill
int Fill(double x, double y, double w=1)
Definition: Resplot.h:281
Filter_Vertex
Definition: Filters.h:155
ConfAnalysis::initialiseInternal
virtual void initialiseInternal()
Definition: ConfAnalysis.cxx:66
LArConditions2Ntuple.objects
objects
Definition: LArConditions2Ntuple.py:58
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
IDTrig_MC23a_preInclude.zedHalfWidth
zedHalfWidth
Definition: IDTrig_MC23a_preInclude.py:10
ConfAnalysis::getHist_invmassObj
virtual TH1F * getHist_invmassObj()
Definition: ConfAnalysis.h:128
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Associator_TruthMatch.h
TIDAEvent.h
Basic event class to contain a vector of chains for trigger analysis
TIDARoiDescriptor::zedMinus
double zedMinus() const
Definition: TIDARoiDescriptor.h:143
RoiFilter
Definition: RoiFilter.h:21
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
ConfAnalysis.h
TrackFilter
Definition: TrackFilter.h:26
hist_file_dump.d
d
Definition: hist_file_dump.py:137
TIDA::Event::chain
const TIDA::Chain * chain(const std::string &s) const
Definition: TIDAEvent.cxx:56
Filter_etaPT
Definition: Filter_etaPT.h:27
lumiParser
Definition: lumiParser.h:28
ChainString::postvalue
std::string postvalue(const std::string &key) const
same here regarding returning a reference
Definition: ChainString.h:65
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
tree
TChain * tree
Definition: tile_monitor.h:30
TIDAVertex.h
ChainString::head
std::string head() const
Definition: ChainString.h:33
JiveXML::Event
struct Event_t Event
Definition: ONCRPCServer.h:65
ETovPTmin
double ETovPTmin
this is a swiss knife function - by default if ET/PT > 0 such that fabs(ET/PT) > 0 is always true and...
Definition: rmain.cxx:385
TIDARoiDescriptor::etaPlus
double etaPlus() const
Definition: TIDARoiDescriptor.h:138
TIDARoiDescriptor::etaMinus
double etaMinus() const
Definition: TIDARoiDescriptor.h:137
Filters.h
skel.it
it
Definition: skel.GENtoEVGEN.py:396
PRINT_BRESIDUALS
bool PRINT_BRESIDUALS
stack trace headers
Definition: ConfAnalysis.cxx:29
test_pyathena.pt
pt
Definition: test_pyathena.py:11
TIDA::Chain::size
unsigned size() const
number of rois
Definition: TIDAChain.h:54
Resplot::setoldrms95
static bool setoldrms95(bool b)
Definition: Resplot.h:555
ConfAnalysis::config
const ChainString & config() const
Definition: ConfAnalysis.h:118
M_PI
#define M_PI
Definition: ActiveFraction.h:11
ConfVtxAnalysis
Definition: ConfVtxAnalysis.h:24
python.atlas_oh.im
im
Definition: atlas_oh.py:167
chop
std::string chop(std::string &s1, const std::string &s2)
Definition: hcg.cxx:158
TIDARoiDescriptor
Describes the Region of Ineterest geometry It has basically 8 parameters.
Definition: TIDARoiDescriptor.h:42
TIDARoiDescriptor.h
TIDA::Track::pT
double pT() const
Definition: Trigger/TrigAnalysis/TrigInDetAnalysis/TrigInDetAnalysis/Track.h:50
TIDARoiDescriptor::zedPlus
double zedPlus() const
Definition: TIDARoiDescriptor.h:144
Cut::signal
@ signal
Definition: SUSYToolsAlg.cxx:67
ConfAnalysis::initialise
virtual void initialise()
book all the histograms
Definition: ConfAnalysis.cxx:59
ChainString
Definition: ChainString.h:23
NvtxCount
int NvtxCount
Definition: globals.cxx:18
exclude
std::set< std::string > exclude
list of directories to be excluded
Definition: hcg.cxx:95
GetChainAuthor
int GetChainAuthor(std::string chainName)
Return selected author, expects format L2_e20_medium:TrigL2SiTrackFinder:3 where 3 is the track autho...
Definition: rmain.cxx:143
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Associator_TruthMatcher
Definition: Associator_TruthMatch.h:44
Associator_BestMatch.h
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
TIDA::Event
Definition: TIDAEvent.h:33
TIDA::Track::z0
double z0() const
Definition: Trigger/TrigAnalysis/TrigInDetAnalysis/TrigInDetAnalysis/Track.h:48
NtupleTrackSelector::clear
virtual void clear() override
the ntple selector manages the tracks itself, so we have to do an explicit delete for each one to pre...
Definition: NtupleTrackSelector.h:72
TIDA::Event::lumi_block
void lumi_block(unsigned lb)
Definition: TIDAEvent.h:44
TIDA::Associator::matched
virtual const S * matched(T *t)
Definition: TIDAAssociator.h:45
xAOD::unsigned
unsigned
Definition: RingSetConf_v1.cxx:662
ConfAnalysis::setprint
void setprint(bool p)
Definition: ConfAnalysis.h:112
TIDARoiDescriptor::size
size_t size() const
Definition: TIDARoiDescriptor.h:176
TrackTrigObject::pt
double pt() const
Definition: TrackTrigObject.h:36
TrackSelector
Definition: Trigger/TrigAnalysis/TrigInDetAnalysis/TrigInDetAnalysis/TrackSelector.h:24
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
TIDA::ReferenceMap::value_type
std::map< std::string, Reference >::value_type value_type
Definition: TIDAReference.h:74
ibl_filter
const std::vector< TIDA::Track > ibl_filter(const std::vector< TIDA::Track > &tv)
Definition: rmain.cxx:222
copyReleaseInfo
void copyReleaseInfo(TTree *tree, TFile *foutdir)
TIDARoiDescriptor::phiPlus
double phiPlus() const
Definition: TIDARoiDescriptor.h:141
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
TIDA::Event::chains
const std::vector< TIDA::Chain > & chains() const
Definition: TIDAEvent.h:76
handler
void handler(int sig)
signal handler
Definition: rmain.cxx:98
zbeam.h
covarianceTool.filter
filter
Definition: covarianceTool.py:514
NtupleTrackSelector.h
ChainString::extra
std::string extra() const
Definition: ChainString.h:38
ConfVtxAnalysis.h
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
beamspotman.inputdata
inputdata
Definition: beamspotman.py:1109
TagNProbe
Definition: TagNProbe.h:28
python.TriggerHandler.tend
string tend
Definition: TriggerHandler.py:300
utils.h
TIDA::ReferenceMap::iterator
std::map< std::string, Reference >::iterator iterator
Definition: TIDAReference.h:72
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
dataset.h
Efficiency1D.h
TagNProbe.h
emacs: this is -*- c++ -*-
ev
int ev
Definition: globals.cxx:25
dumpflag
bool dumpflag
Definition: globals.cxx:30
TrigObjectMatcher
Definition: TrigObjectMatcher.h:24
TIDA::Event::time_stamp
void time_stamp(unsigned t)
Definition: TIDAEvent.h:45
ConfAnalysis
Definition: ConfAnalysis.h:48
python.BunchSpacingUtils.lb
lb
Definition: BunchSpacingUtils.py:88
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
TIDARoiDescriptor::composite
bool composite() const
composite RoI methods
Definition: TIDARoiDescriptor.h:174
globals.h
TagNProbe::type0
const std::string & type0() const
Definition: TagNProbe.h:51
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
Associator_SecondBestpTMatcher
Definition: Associator_BestMatch.h:58
makeCustomRefRoi
TIDARoiDescriptor makeCustomRefRoi(const TIDARoiDescriptor &roi, double etaHalfWidth=-999, double phiHalfWidth=-999, double zedHalfWidth=-999)
Definition: rmain.cxx:164
ReadCards
Get tag-value pairs from a file.
Definition: ReadCards.h:50
ReadCards.h
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
lumiFormat.i
int i
Definition: lumiFormat.py:85
Filter_Offline2017.h
z
#define z
Associator_BestSigmaMatcher
Definition: Associator_BestMatch.h:197
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
replaceauthor
const std::vector< TIDA::Track > replaceauthor(const std::vector< TIDA::Track > &tv, int a0=5, int a1=4)
Definition: rmain.cxx:272
TIDA::Roi::tracks
const std::vector< TIDA::Track > & tracks() const
Definition: TIDARoi.h:52
event_selector
Definition: event_selector.h:20
TIDA::Event::event_number
void event_number(unsigned long long e)
Definition: TIDAEvent.h:43
gevent
TIDA::Event * gevent
Definition: globals.cxx:13
main
int main(int argc, char **argv)
Definition: rmain.cxx:520
TagNProbe::tag
void tag(const std::string &chainName)
getters and setters
Definition: TagNProbe.h:45
Resplot::FitNull95
static TF1 * FitNull95(TH1D *s, double a=0, double b=0)
Definition: Resplot.cxx:1673
TrackSelector.h
event_list::find
bool find(int i)
Definition: rmain.cxx:318
BinConfig
Definition: BinConfig.h:22
TIDA::Chain::at
TIDA::Roi & at(int i)
Definition: TIDAChain.h:63
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
event_selector::in
bool in(int event)
Definition: event_selector.h:35
TrackAnalysis
Definition: TrackAnalysis.h:32
TrigObjectMatcher::status
bool status() const
Definition: TrigObjectMatcher.h:67
TRT::Track::d0
@ d0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:62
python.BuildSignatureFlags.sig
sig
Definition: BuildSignatureFlags.py:218
file
TFile * file
Definition: tile_monitor.h:29
ETmin
double ETmin
Definition: rmain.cxx:374
TIDA::Vertex::selectTracks
void selectTracks(const std::vector< TIDA::Track * > &trackCollection, const std::vector< unsigned long > &trackIds)
Definition: TIDAVertex.cxx:65
Associator_BestDeltaRMatcher
Definition: Associator_BestMatch.h:80
ConfAnalysis::getTnPtool
virtual TagNProbe * getTnPtool()
Definition: ConfAnalysis.h:124
TIDA::Roi::vertices
const std::vector< TIDA::Vertex > & vertices() const
access the vertices
Definition: TIDARoi.h:56
run
Definition: run.py:1
dataset
Definition: dataset.h:27
Filter_Offline2017
Definition: Filter_Offline2017.h:28
Resplot
Definition: Resplot.h:50
PurityAnalysis::initialise
virtual void initialise()
book all the histograms
Definition: PurityAnalysis.cxx:34
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
BinConfig::set
void set(ReadCards &r, const std::string &n)
Definition: BinConfig.h:50
ConfVtxAnalysis::finalise
void finalise()
Definition: ConfVtxAnalysis.cxx:353
GetRefTracks
bool GetRefTracks(const std::string &rc, const std::string &exclude, const std::vector< TIDA::Chain > &chains, NtupleTrackSelector &refTracks, TrackAssociator *ex_matcher, TrigObjectMatcher &tom)
Definition: rmain.cxx:428
TrackAnalysis::setBeamRef
void setBeamRef(double x, double y, double z=0)
set the beamline positions
Definition: TrackAnalysis.h:109
a0
double a0
Definition: globals.cxx:27
RivetAnalysis_JO.analyses
string analyses
Definition: RivetAnalysis_JO.py:30
Filter_Track::chargeSelection
void chargeSelection(int i)
Definition: Filter_Track.h:77
selection
std::string selection
Definition: fbtTestBasics.cxx:75
TIDA::FeatureStore::insert
void insert(T *t, const std::string &key)
Definition: TIDAFeatureStore.h:44
calibdata.exit
exit
Definition: calibdata.py:236
atoi_check
int atoi_check(const std::string &s)
convert string to integer with check if successful
Definition: rmain.cxx:128
muonBinConfig
BinConfig muonBinConfig
TIDA::Vertex
Definition: TIDAVertex.h:23
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
ConfAnalysis::getHist_invmass
virtual TH1F * getHist_invmass()
Definition: ConfAnalysis.h:126
TagNProbe::type1
const std::string & type1() const
Definition: TagNProbe.h:52
grepfile.ic
int ic
Definition: grepfile.py:33
PurityAnalysis.h
lumiFormat.array
array
Definition: lumiFormat.py:91
Resplot::Write
Int_t Write(const char *=0, Int_t=0, Int_t=0) const
Hooray, this stupidity is to overwride both the const and non-const TObject Write methods Fixme: shou...
Definition: Resplot.h:454
ConfVtxAnalysis::execute
void execute(const std::vector< TIDA::Vertex * > &vtx0, const std::vector< TIDA::Vertex * > &vtx1, const TIDA::Event *tevt=0)
Definition: ConfVtxAnalysis.cxx:181
ChainString::element
std::string element() const
Definition: ChainString.h:37
ReadCellNoiseFromCoolCompare.s3
s3
Definition: ReadCellNoiseFromCoolCompare.py:380
TrackSelector::tracks
const std::vector< TIDA::Track * > & tracks() const
Definition: Trigger/TrigAnalysis/TrigInDetAnalysis/TrigInDetAnalysis/TrackSelector.h:53
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
PurityAnalysis::setprint
void setprint(bool p)
Definition: PurityAnalysis.h:73
TIDA::Track::eta
double eta() const
Definition: Trigger/TrigAnalysis/TrigInDetAnalysis/TrigInDetAnalysis/Track.h:46
event_list
Definition: rmain.cxx:298
ChainString.h
Associator_BestDeltaRZMatcher
Definition: Associator_BestMatch.h:109
Filter_Combined
Definition: Filters.h:225
TIDA::Chain
Definition: TIDAChain.h:28
TIDA::Roi
Definition: TIDARoi.h:31
operator<<
std::ostream & operator<<(std::ostream &s, const std::vector< T * > &v)
Definition: rmain.cxx:208
trackPtGrtr
bool trackPtGrtr(TIDA::Track *trackA, TIDA::Track *trackB)
Definition: rmain.cxx:204
time_str
std::string time_str()
Definition: rmain.cxx:115
TIDAReference.h
emacs: this is -*- c++ -*-
TIDARoiDescriptor::eta
double eta() const
Definition: TIDARoiDescriptor.h:134
Resplot::Finalise
int Finalise(double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=Resplot::FitGaussian)
Definition: Resplot.cxx:388
example.goodrunslist
goodrunslist
Definition: example.py:26
LArNewCalib_Delay_OFC_Cali.check
check
Definition: LArNewCalib_Delay_OFC_Cali.py:258
PowhegPythia8EvtGen_H2a4X_ctauY.newfile
string newfile
Definition: PowhegPythia8EvtGen_H2a4X_ctauY.py:13
NMod
int NMod
Definition: globals.cxx:20
RoiFilter::filter
bool filter(const TIDARoiDescriptor *roi)
Definition: RoiFilter.h:32
TrigObjectMatcher.h
grepfile.filenames
list filenames
Definition: grepfile.py:34
TIDA::Vertex::z
double z() const
Definition: TIDAVertex.h:53
python.copyTCTOutput.chains
chains
Definition: copyTCTOutput.py:81
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
python.PyAthena.v
v
Definition: PyAthena.py:154
TIDA::Vertex::Ntracks
int Ntracks() const
Definition: TIDAVertex.h:62
ConfAnalysis::initialiseFirstEvent
void initialiseFirstEvent(bool b=true)
Definition: ConfAnalysis.h:116
TagNProbe::GetRois
std::vector< TIDA::Roi * > GetRois(std::vector< TIDA::Chain > &chains, const TrackSelector *selector, TrackFilter *filter, T *hmass, T *hmass_obj, TrigObjectMatcher *tom=0) const
Definition: TagNProbe.h:60
TrackTrigObject
Definition: TrackTrigObject.h:21
a
TList * a
Definition: liststreamerinfos.cxx:10
python.selector.AtlRunQuerySelectorLhcOlc.selector
selector
Definition: AtlRunQuerySelectorLhcOlc.py:611
h
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
event_list::event_list
event_list(const std::string &filename)
Definition: rmain.cxx:300
ref
const boost::regex ref(r_ef)
TIDA::Vertex::tracks
const std::vector< TIDA::Track * > & tracks() const
Definition: TIDAVertex.h:67
Filter_pdgId
Definition: Filters.h:53
Filter_Track
sadly need to include a root dependency, but no matter - the TIDA::Track class itself inherets from T...
Definition: Filter_Track.h:41
groi
TIDARoiDescriptor * groi
all these externals initialised in globals.cxx
Definition: globals.cxx:14
DeMoScan.first
bool first
Definition: DeMoScan.py:536
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
python.TriggerAPI.TriggerAPISession.chainName
chainName
Definition: TriggerAPISession.py:426
pointers
std::vector< T * > pointers(std::vector< T > &v)
Definition: rmain.cxx:366
CaloCondBlobAlgs_fillNoiseFromASCII.author
string author
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:26
TriggerTest.rois
rois
Definition: TriggerTest.py:23
g_binConfig
BinConfig g_binConfig
Filter_Author
Definition: Filters.h:32
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
usage
int usage(const std::string &name, int status)
Definition: rmain.cxx:331
TIDA::Track
Definition: Trigger/TrigAnalysis/TrigInDetAnalysis/TrigInDetAnalysis/Track.h:26
BinConfig.h
scales to modify the binning for histograms
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
event_list::mevents
std::set< int > mevents
Definition: rmain.cxx:324
event_selector.h
merge.status
status
Definition: merge.py:17
electronBinConfig
BinConfig electronBinConfig
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
LArCellNtuple.ifile
string ifile
Definition: LArCellNtuple.py:133
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
TIDA::Associator::match
virtual void match(const std::vector< T * > &s1, const std::vector< S * > &s2)=0
Nvtxtracks
int Nvtxtracks
Definition: globals.cxx:17
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
skip
bool skip
Definition: TrigGlobEffCorrValidation.cxx:190
python.CaloScaleNoiseConfig.ts
ts
Definition: CaloScaleNoiseConfig.py:86
TIDA::Event::run_number
void run_number(unsigned r)
accessors
Definition: TIDAEvent.h:42
Filter_Vertex::setVertex
void setVertex(const TIDA::Vertex &v)
Definition: Filters.h:166
getFilter
TrackFilter * getFilter(const std::string &refname, int pdgId, TrackFilter *foff, TrackFilter *fmu, TrackFilter *ftruth)
This is awful code, passing in lots of filter pointers just so that they can be assigned neatly ?...
Definition: rmain.cxx:403
TrigObjectMatcher::object
const TrackTrigObject * object(unsigned long track_id)
Definition: TrigObjectMatcher.h:61
Filter_Track::maxpT
void maxpT(double pTMax)
Definition: Filter_Track.h:80
ExtractEBRunDetails.lumiblocks
lumiblocks
Definition: ExtractEBRunDetails.py:225
check_log.backtrace
backtrace
Definition: check_log.py:58
computils.h
Filter_TrackQuality
Definition: Filter_TrackQuality.h:27
PurityAnalysis
Definition: PurityAnalysis.h:34
TrackAnalysis::store
TIDA::FeatureStore & store()
Definition: TrackAnalysis.h:133
TIDARoiDescriptor::phiMinus
double phiMinus() const
Definition: TIDARoiDescriptor.h:140
TIDARoiDescriptor::zed
double zed() const
Definition: TIDARoiDescriptor.h:135
TagNProbe::probe
void probe(const std::string &chainName)
Definition: TagNProbe.h:46
NtupleTrackSelector
Definition: NtupleTrackSelector.h:20
zbeam
Definition: zbeam.h:24
tauBinConfig
BinConfig tauBinConfig
lumiParser.h
hipt
bool hipt
Definition: globals.cxx:29
lumiList.h
standalone implementation of a good lumi block list
cosmicBinConfig
BinConfig cosmicBinConfig