ATLAS Offline Software
Loading...
Searching...
No Matches
T_AnalysisConfigR3_Tier0.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
22
23#ifndef TrigInDetAnalysisExample_T_AnalysisConfigR3_Tier0_H
24#define TrigInDetAnalysisExample_T_AnalysisConfigR3_Tier0_H
25
31
36
37#include "TTree.h"
38#include "TFile.h"
39
40#include "GaudiKernel/ToolHandle.h"
42
43
44// McParticleEvent includes
46
48#include "AtlasHepMC/GenEvent.h"
51
53
54
55
57
59
65
66
67
69
72
73// #include "TrigSteeringEvent/TrigRoiDescriptorCollection.h"
74
77
79
80
81template<typename T>
82std::ostream& operator<<( std::ostream& s, const std::vector<T>& v) {
83 for ( size_t i=0 ; i<v.size() ; i++ ) s << " " << v[i];
84 return s;
85}
86
87
88template<typename T, typename A=AnalysisR3_Tier0>
90
91public:
92
93 // Full constructor: test/reference/selection
94 // - analysisInstanceName: the name of the analysis chain being created
95 // - xxxChainName: the name of the chain to be used as test/reference/selection; must be "StoreGate" in case of direct access to SG containers
96 // - xxxType: the type of tracks to be retrieved from the test/reference/selection chain or container
97 // - xxxKey: the key for tracks to be retrieved from the test/reference/selection chain or container
98 // - roiInfo: in case the test chain is a real chain, this is used to specify RoI widths; in case the test chain is a fake chain, this is used for RoI position too
99 // - all standard operations are performed in loops over 0=test 1=reference 2=selection
100 T_AnalysisConfigR3_Tier0(const std::string& analysisInstanceName,
101 const std::string& testChainName, const std::string& testType, const std::string& testKey,
102 const std::string& referenceChainName, const std::string& referenceType, const std::string& referenceKey,
103 TrackFilter* testFilter, TrackFilter* referenceFilter,
104 TrackAssociator* associator,
106 TagNProbe* TnP_tool = 0) :
107 T_AnalysisConfig<T>( analysisInstanceName,
108 testChainName, testType, testKey,
109 referenceChainName, referenceType, referenceKey,
110 testFilter, referenceFilter,
111 associator,
112 analysis),
113 m_manalysis(0),
114 m_useBeamCondSvc(false),
115 m_doOffline(true),
116 m_doMuons(false),
117 m_doElectrons(false),
118 m_doTaus(false),
119 m_doBjets(false),
120 m_doTauThreeProng(false),
121 m_tauEtCutOffline(false),
122 m_pdgID(0),
124 m_NRois(0),
125 m_NRefTracks(0),
126 m_NTestTracks(0),
127 m_runPurity(false),
128 m_shifter(false),
129 m_pTthreshold(0),
130 m_first(true),
131 m_containTracks(false),
132 m_tnp_flag(false),
133 m_monTool(0),
134 m_invmass(0),
136 {
137
140
141 m_chainNames.push_back(testChainName);
142
144
145 m_TnP_tool = TnP_tool;
146
147#if 0
149 ChainString& chain = m_chainNames.back();
150
151 std::cout << "\nT_AnalysisConfigR3_Tier0::name: " << name() << "\t" << this << std::endl;
152 std::cout << "T_AnalysisConfigR3_Tier0::chain specification: " << testChainName << " -> " << chain << "\t" << chain.raw() << std::endl;
153 std::cout << "\tchain: " << chain.head() << std::endl;
154 std::cout << "\tkey: " << chain.tail() << std::endl;
155 std::cout << "\troi: " << chain.roi() << std::endl;
156 std::cout << "\tvtx: " << chain.vtx() << std::endl;
157 std::cout << "\tte: " << chain.element() << std::endl;
158 std::cout << "\textra: " << chain.extra() << std::endl;
159
160 std::cout << "\tpost: " << chain.post() << std::endl;
161 std::cout << "\tpt: " << chain.postvalue("pt") << std::endl;
162
163 std::cout << "\tcontainTracks: " << m_containTracks << std::endl;
164
165#endif
166
167 m_testType = testType;
168
169 if ( m_TnP_tool ) m_tnp_flag = true;
170
171 }
172
173
175 if ( m_TnP_tool ) delete m_TnP_tool;
176 if ( m_invmass ) delete m_invmass;
177 if ( m_invmass_obj ) delete m_invmass_obj;
178 }
179
180
181 void initialise() {
182
183 if ( m_tnp_flag ) {
184 if ( m_invmass==0 ) m_invmass = new TIDA::Histogram<float>( monTool(), "invmass" );
185 if ( m_invmass_obj==0 ) m_invmass_obj = new TIDA::Histogram<float>( monTool(), "invmass_obj" );
186 }
187
188 for ( size_t it=0 ; it<m_types.size() ; it++ ) {
189 if ( m_types[it]=="" ) m_offline_types.push_back( "InDetTrackParticles" );
190 else m_offline_types.push_back( m_types[it] );
191 }
192
193 if ( m_offline_types.empty() ) m_offline_types.push_back( "InDetTrackParticles" );
194
195 }
196
197
198 void setRunPurity( bool b ) { m_runPurity=b; }
199
200 void setShifter( bool b ) { m_shifter=b; }
201
202 void useBeamCondSvc( bool b ) { m_useBeamCondSvc = b; }
203
204 void containTracks( bool b ) { m_containTracks = b; }
205
206 void setPdgID( int i=0 ) { m_pdgID=i; }
207
208 void setParentPdgID( int i=0 ) { m_parent_pdgID=i; }
209
210 void setMCTruthRef( bool b ) { m_mcTruth=b; }
211
212 void setOfflineRef( bool b ) { m_doOffline=b; }
213
214 void setTypes( const std::vector<std::string>& t ) { m_types=t; }
215
216 void set_monTool( ToolHandle<GenericMonitoringTool>* m ) { m_monTool=m; }
217
218 ToolHandle<GenericMonitoringTool>* monTool() { return m_monTool; }
219
220public:
221
223
224 using T_AnalysisConfig<T>::name;
225
226protected:
227
231
233
238
239 virtual void loop() {
240
241 const TagNProbe* pTnP_tool = m_TnP_tool;
242
243 if( m_provider->msg().level() <= MSG::VERBOSE) {
244 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::loop() for " << T_AnalysisConfig<T>::m_analysisInstanceName << endmsg;
245 }
246
248 // get (offline) beam position
249 // double xbeam = 0;
250 // double ybeam = 0;
251
252#if 0
253
254 if ( m_first ) {
255
256 m_first = false;
257
258 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
259 m_provider->msg(MSG::VERBOSE) << " using beam position\tx=" << xbeam << "\ty=" << ybeam << endmsg;
260
261 std::vector<std::string> configuredChains = (*(m_tdt))->getListOfTriggers("L2_.*, EF_.*, HLT_.*");
262
263 for ( unsigned i=0 ; i<configuredChains.size() ; i++ ) {
265 // std::cout << "Configured chain " << configuredChains[i] << std::endl;
266 m_provider->msg(MSG::VERBOSE) << "Chain " << configuredChains[i] << endmsg;
267 }
268 }
269
270 // std::cout << "\tloop() analyse chains " << m_chainNames.size() << std::endl;
271
272 }
273
274#endif
275
276 Filter_True filter;
277
278 Filter_etaPT filter_etaPT( 5, 200 );
279 Filter_Combined filter_truth( &filter_etaPT, &filter_etaPT);
280
282 // Filter_Combined filterRef (&filter_offline, &filter_vertex);
283
284 int iRefFilter = 1;
285 int iTestFilter = 0;
286
287 if ( m_runPurity ) {
288 iRefFilter = 0;
289 iTestFilter = 1;
290 }
291
292
293 TrackFilter* rfilter = m_filters[iRefFilter][0];
294 TrackFilter* tfilter = m_filters[iTestFilter][0];
295
296 Filter_Combined filterRef( rfilter, &filter );
297 Filter_Combined filterTest( tfilter, &filter );
298
299 TrigTrackSelector selectorTruth( &filter_truth, m_pdgID, m_parent_pdgID );
300
301 TrigTrackSelector selectorRef( &filterRef );
302 TrigTrackSelector* pselectorRef = &selectorRef;
303
304 TrigTrackSelector selectorTest( &filterTest );
305 TrigTrackSelector* pselectorTest = &selectorTest;
306
308 if ( m_mcTruth ) pselectorRef = &selectorTruth;
309
315
317
318 TIDA::Event event;
319 TIDA::Event* eventp = &event;
320
321 double beamline[4] = { 0, 0, 0, 0 };
322
323 // clear the ntuple TIDA::Event class
324 eventp->clear();
325
327
328 const xAOD::EventInfo* pEventInfo = 0;
329
330 unsigned run_number = 0;
331 unsigned long long event_number = 0;
332 unsigned lumi_block = 0;
333 unsigned bunch_crossing_id = 0;
334 unsigned time_stamp = 0;
335 double mu_val = 0;
336
338 // std::cout << "\tloop() get EventInfo" << std::endl;
339
340 if ( this->template retrieve( pEventInfo, "EventInfo" ).isFailure() ) {
341 m_provider->msg(MSG::WARNING) << "Failed to get EventInfo " << endmsg;
342 } else {
343
344 run_number = pEventInfo->runNumber();
345 event_number = pEventInfo->eventNumber();
346 lumi_block = pEventInfo->lumiBlock();
347 time_stamp = pEventInfo->timeStamp();
348 bunch_crossing_id = pEventInfo->bcid();
349 mu_val = pEventInfo->averageInteractionsPerCrossing();
350 }
351
352 if(m_provider->msg().level() <= MSG::VERBOSE){
353 m_provider->msg(MSG::VERBOSE) << "run " << run_number
354 << "\tevent " << event_number
355 << "\tlb " << lumi_block << endmsg;
356 }
357
358 // clear the ntuple TIDA::Event class
359 eventp->clear();
360
361 eventp->run_number(run_number);
362 eventp->event_number(event_number);
363 eventp->lumi_block(lumi_block);
364 eventp->time_stamp(time_stamp);
365 eventp->bunch_crossing_id(bunch_crossing_id);
366 eventp->mu(mu_val);
367
370
371 bool analyse = false;
372
373 // Check HLTResult
374
375 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
376
377 const std::string& chainname = m_chainNames[ichain].head();
378
379 if ( chainname == "" ) analyse = true;
380 else {
381
382 //Only for trigger chains
383 if ( chainname.find("L2") == std::string::npos &&
384 chainname.find("EF") == std::string::npos &&
385 chainname.find("HLT") == std::string::npos ) continue;
386
387 if ( m_provider->msg().level() <= MSG::DEBUG ) {
388 m_provider->msg(MSG::DEBUG) << "Chain " << chainname
389 << "\tpass " << (*m_tdt)->isPassed(chainname)
390 << "\tpres " << (*m_tdt)->getPrescale(chainname) << endmsg;
391 }
392
394 // std::cout << "\tChain " << chainname << "\tpass " << (*m_tdt)->isPassed(chainname)
395 // << "\tpres " << (*m_tdt)->getPrescale(chainname) << std::endl;
396
397 if ( (*(m_tdt))->isPassed(chainname) ) analyse = true;
398
399 }
400
401 }
402
403
404 if ( !this->m_keepAllEvents && !analyse ) {
405 if(m_provider->msg().level() <= MSG::VERBOSE) {
406 m_provider->msg(MSG::VERBOSE) << "No chains passed unprescaled - not processing this event" << endmsg;
407 }
408 return;
409 }
410
411
413
414 selectorTruth.clear();
415
416 if(m_provider->msg().level() <= MSG::VERBOSE)
417 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
418
420
421 std::vector<TIDA::Vertex> vertices;
422 std::vector<TIDA::Vertex> vertices_rec;
423
424 std::vector<double> refbeamspot;
425 std::vector<double> testbeamspot;
426
428
429 m_provider->msg(MSG::VERBOSE) << "fetching AOD Primary vertex container" << endmsg;
430
431 if ( !this->select( vertices, "PrimaryVertices" ) ) {
432 m_provider->msg(MSG::VERBOSE) << "could not retrieve the 'PrimaryVertices' vertex collection" << std::endl;
433 }
434
436
437 if ( m_mcTruth ) {
438 eventp->addChain( "Truth" );
439 eventp->back().addRoi(TIDARoiDescriptor());
440 eventp->back().back().addTracks(selectorTruth.tracks());
441 }
442
444
445 if ( m_doOffline ) {
446 for ( unsigned i=0 ; i<vertices.size() ; i++ ) {
447 if(m_provider->msg().level() <= MSG::VERBOSE)
448 m_provider->msg(MSG::VERBOSE) << "vertex " << i << " " << vertices[i] << endmsg;
449 eventp->addVertex(vertices[i]);
450 }
451 }
452
453
454
456
457 std::vector<TIDA::Track*> offline_tracks;
458 std::vector<TIDA::Track*> electron_tracks;
459 std::vector<TIDA::Track*> muon_tracks;
460
461 std::vector<TIDA::Track*> ref_tracks;
462 std::vector<TIDA::Track*> test_tracks;
463
464 offline_tracks.clear();
465 electron_tracks.clear();
466 muon_tracks.clear();
467
468 ref_tracks.clear();
469 test_tracks.clear();
470
471 // offline track retrieval now done once for each chain rather than each roi
472 if ( m_provider->msg().level() <= MSG::VERBOSE )
473 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
474
475 bool foundTruth = false;
476
478
479 if ( m_mcTruth ) {
480
481 filter_truth.setRoi( 0 ); // don't filter on RoI yet (or until needed)
482
483 selectorTruth.clear();
484
485 if ( m_provider->msg().level() <= MSG::VERBOSE )
486 m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg;
487
488 if ( m_provider->evtStore()->template contains<TruthParticleContainer>("INav4MomTruthEvent") ) {
489 //ESD
490 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "INav4MomTruthEvent" );
491 foundTruth = true;
492 }
493 else if ( m_provider->evtStore()->template contains<TruthParticleContainer>("SpclMC") ) {
495 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "SpclMC");
496 foundTruth = true;
497 }
498 else if ( m_provider->evtStore()->template contains<xAOD::TruthParticleContainer>("TruthParticles") ) {
500 this->template selectTracks<xAOD::TruthParticleContainer>( &selectorTruth, "TruthParticles");
501 foundTruth = true;
502 }
503 else if ( m_provider->evtStore()->template contains<TruthParticleContainer>("") ) {
505 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "");
506 foundTruth = true;
507 }
508 else
509 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
510 m_provider->msg(MSG::VERBOSE) << "Truth not found - none whatsoever!" << endmsg;
511 }
512 }
513
514 if ( m_mcTruth && !foundTruth ) {
515
516 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
517 m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg;
518 }
519
521
522 const McEventCollection* mcevent = nullptr;
523
525
526 std::string keys[4] = { "GEN_AOD", "TruthEvent", "", "G4Truth" };
527
528 std::string key = "";
529
530 bool foundcollection = false;
531
532 for ( int ik=0 ; ik<4 ; ik++ ) {
533
534 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
535 m_provider->msg(MSG::VERBOSE) << "Try McEventCollection: " << keys[ik] << endmsg;
536 }
537
538 if ( !m_provider->evtStore()->template contains<McEventCollection>(keys[ik]) ) {
539 if( m_provider->msg().level() <= MSG::VERBOSE )
540 m_provider->msg(MSG::VERBOSE) << "No McEventCollection: " << keys[ik] << endmsg;
541 continue;
542 }
543
544 if ( m_provider->msg().level() <= MSG::VERBOSE )
545 m_provider->msg(MSG::VERBOSE) << "evtStore()->retrieve( mcevent, " << keys[ik] << " )" << endmsg;
546
547 if ( this->template retrieve( mcevent, keys[ik] ).isFailure() ) {
548 if ( m_provider->msg().level() <= MSG::VERBOSE )
549 m_provider->msg(MSG::VERBOSE) << "Failed to get McEventCollection: " << keys[ik] << endmsg;
550 }
551 else {
553 key = keys[ik];
554 if(m_provider->msg().level() <= MSG::VERBOSE)
555 m_provider->msg(MSG::VERBOSE) << "Found McEventCollection: " << key << endmsg;
556 foundcollection = true;
557 break;
558 }
559 }
560
562 if ( !foundcollection ) {
563 if(m_provider->msg().level() <= MSG::VERBOSE)
564 m_provider->msg(MSG::WARNING) << "No MC Truth Collections of any sort, whatsoever!!!" << endmsg;
565
566 // m_tree->Fill();
567 // return StatusCode::FAILURE;
568
569 return;
570 }
571
572 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
573 m_provider->msg(MSG::VERBOSE) << "Found McEventCollection: " << key << "\tNevents " << mcevent->size() << endmsg;
574 }
575
576 McEventCollection::const_iterator evitr = mcevent->begin();
577 McEventCollection::const_iterator evend = mcevent->end();
578
579 unsigned ie = 0;
580 unsigned ip = 0;
581
582 unsigned ie_ip = 0;
583
584 while ( evitr!=evend ) {
585
586 int ipc = 0;
587
588 int pid = HepMC::signal_process_id((*evitr));
589
590 //The logic should be clarified here
591 if ( pid!=0 ) {
592
593 // For HepMC2-based builds the following two functions return
594 // GenEvent::particle_const_iterator
595 // while for HepMC3-based builds they return
596 // std::vector<HepMC3::ConstGenParticlePtr>::const_iterator
597 // see AtlasHepMC/GenEvent.h for function definitions.
598 auto pitr(HepMC::begin(**evitr));
599 const auto pend(HepMC::end(**evitr));
600
601 while ( pitr!=pend ) {
602
603 selectorTruth.selectTrack( *pitr++ );
604
605 ++ipc;
606
607 }
608
609 }
610 ++ie;
611 ++evitr;
612
613 if ( ipc>0 ) {
615 // m_provider->msg(MSG::VERBOSE) << "Found " << ie << "\tpid " << pid << "\t with " << ip << " TruthParticles (GenParticles)" << endmsg;
616 ++ie_ip;
617 ip += ipc;
618 }
619 }
620
621 if(m_provider->msg().level() <= MSG::VERBOSE){
622 m_provider->msg(MSG::VERBOSE) << "Found " << ip << " TruthParticles (GenParticles) in " << ie_ip << " GenEvents out of " << ie << endmsg;
623 m_provider->msg(MSG::VERBOSE) << "selected " << selectorTruth.size() << " TruthParticles (GenParticles)" << endmsg;
624 }
625
626 if(selectorTruth.size() > 0) foundTruth = true;
627
628 if ( !(ip>0) ) {
629 if (m_provider->msg().level() <= MSG::VERBOSE) m_provider->msg(MSG::WARNING) << "NO TRUTH PARTICLES - returning" << endmsg;
630 return;
631 }
632
633 }
634
635 if ( m_doOffline && !m_mcTruth) {
636
637 for ( size_t it=0 ; it<m_offline_types.size() ; it++ ) {
638 if ( m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>( m_offline_types[it] ) ) {
639 this->template selectTracks<xAOD::TrackParticleContainer>( pselectorRef, m_offline_types[it] );
640 refbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( m_offline_types[it] );
641 }
642 else {
643 m_provider->msg(MSG::WARNING) << "Offline tracks not found: " << m_offline_types[it] << endmsg;
644 }
645 }
646
647 }
648
650
651 std::unique_ptr<TrackAssociator> associator = m_associator->uclone();
652
653 // std::cout << "\tloop() loop over chains proper ..." << std::endl;
654
656 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
657
659
660 // std::string& chainname = chains[ichain];
661 const std::string& chainname = m_chainNames[ichain].head();
662 const std::string& key = m_chainNames[ichain].tail();
663 const std::string& vtx_name = m_chainNames[ichain].vtx();
664
665 // Not used left just in case
666 // const std::string& roi_name = m_chainNames[ichain].roi();
667 // const std::string& te_name = m_chainNames[ichain].element();
668 m_pTthreshold = 0;
669
670 if ( m_chainNames[ichain].postcount() ) {
671 std::string ptvalue = m_chainNames[ichain].postvalue("pt");
672 if ( ptvalue!="" ) m_pTthreshold = std::stod(ptvalue);
673 }
674
675
676 unsigned decisiontype = TrigDefs::Physics;
677
678 if ( !m_chainNames[ichain].passed() ) decisiontype = TrigDefs::includeFailedDecisions;
679
681 // if ( decisiontype==TrigDefs::requireDecision ) std::cout << "\tSUTT TrigDefs::requireDecision " << decisiontype << std::endl;
682 // if ( decisiontype==TrigDefs::Physics ) std::cout << "\tSUTT TrigDefs::Physics " << decisiontype << std::endl;
683
684 if ( chainname!="" && m_provider->msg().level() <= MSG::VERBOSE ) {
685
686 m_provider->msg(MSG::VERBOSE) << "status for chain " << chainname
687 << "\tpass " << (*m_tdt)->isPassed(chainname)
688 << "\tprescale " << (*m_tdt)->getPrescale(chainname) << endmsg;
689
690 m_provider->msg(MSG::VERBOSE) << "fetching features for chain " << chainname << endmsg;
691
692 m_provider->msg(MSG::VERBOSE) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << endmsg;
693 }
694
696 // std::cout << "\tstatus for chain " << chainname
697 // << "\tpass " << (*m_tdt)->isPassed( chainname )
698 // << "\tpassdt " << (*m_tdt)->isPassed( chainname, decisiontype )
699 // << "\tprescale " << (*m_tdt)->getPrescale( chainname ) << std::endl;
700
701
702 // m_provider->msg(MSG::INFO) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << "\t" << m_chainNames[ichain] << "\trun " << run_number << "\tevent " << event_number << endmsg;
703
704
705 if ( chainname!="" && !this->m_keepAllEvents && !(*m_tdt)->isPassed( chainname, decisiontype ) ) continue;
706
709 // Trig::FeatureContainer f = (*m_tdt)->features( chainname, TrigDefs::alsoDeactivateTEs);
710
713
714 // tag and probe analysis processes multiple chains passed in the tag and probe tool at once so loop over vector of chains
715 std::vector<std::string> chainNames ;
716
717 if ( !m_tnp_flag ) {
718 chainNames.push_back(m_chainNames[ichain].raw()) ;
719 }
720 else {
721 chainNames.push_back(pTnP_tool->tag());
722 chainNames.push_back(pTnP_tool->probe());
723 }
724
725 // loop over new chainNames vector but doing the same stuff
726 for ( size_t i=0 ; i<chainNames.size() ; i++ ) {
727
728 ChainString chainConfig = chainNames[i] ;
729 std::string chainName = chainConfig.head();
730
731 eventp->addChain( chainNames[i] );
732
733 TIDA::Chain& chain = eventp->back();
734
735 if ( chainName == "" ) {
736
738
739 pselectorTest->clear();
740
742
743 // TIDARoiDescriptor roifs(true);
744
745 // chain.addRoi( roifs );
746
747 chain.addRoi( TIDARoiDescriptor(true) );
748
749 if ( m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>(key) ) {
750 this->template selectTracks<xAOD::TrackParticleContainer>( pselectorTest, key );
751 refbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( key );
752 }
753
754 const std::vector<TIDA::Track*>& testtracks = pselectorTest->tracks();
755
756 chain.back().addTracks(testtracks);
757
758 if ( vtx_name!="" ) {
759
761
762 m_provider->msg(MSG::VERBOSE) << "\tFetch xAOD::VertexContainer with key " << vtx_name << endmsg;
763
764 std::vector<TIDA::Vertex> tidavertices;
765
766 if ( this->select( tidavertices, vtx_name ) ) chain.back().addVertices( tidavertices );
767 }
768
769
770 // if ( roiInfo ) delete roiInfo;
771
772 }
773 else {
774
776
777 //std::string roi_key = m_chainNames[ichain].roi();
778
779 std::string roi_key = chainConfig.roi();
780
781 unsigned feature_type =TrigDefs::lastFeatureOfType;
782
783 if ( roi_key!="" ) feature_type= TrigDefs::allFeaturesOfType;
784
786
787 int leg = -1;
788
789 if ( chainConfig.element()!="" ) {
790 leg = std::atoi(chainConfig.element().c_str());
791 }
792
793 std::string rgex = roi_key;
794
795 std::vector< TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> > rois =
796 (*m_tdt)->template features<TrigRoiDescriptorCollection>( Trig::FeatureRequestDescriptor( chainName,
797 decisiontype,
798 rgex,
799 feature_type,
800 "roi",
801 leg ) );
802
805
806 if ( rois.empty() ) {
807 if ( !rgex.empty() ) {
808 rgex += "_probe";
809 rois = (*m_tdt)->template features<TrigRoiDescriptorCollection>( Trig::FeatureRequestDescriptor( chainName,
810 decisiontype,
811 rgex,
812 feature_type,
813 "roi",
814 leg ) );
815 }
816 }
817
818 int iroi = 0;
819
820 for ( const TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection>& roi_info : rois ) {
821
822 iroi++;
823
827
828 if ( roi_key=="SuperRoi" && iroi>1 ) continue;
829
830 // std::cout << "\troi: get link " << roi_key << " ..." << std::endl;
831
832 const ElementLink<TrigRoiDescriptorCollection> roi_link = roi_info.link;
833
835 if ( roi_key!="" && roi_link.dataID()!=rgex ) continue;
836
838 if ( !roi_link.isValid() ) continue;
839
840 const TrigRoiDescriptor* const* roiptr = roi_link.cptr();
841
842 if ( roiptr == 0 ) continue;
843
844
846 // std::cout << "\troi: link deref ..." << *roiptr << std::endl;
847
848 if (m_provider->msg().level() <= MSG::VERBOSE) {
849 m_provider->msg(MSG::VERBOSE) << " RoI descriptor for seeded chain " << chainname << " " << **roiptr << endmsg;
850 }
851
853
854 // if ( dbg ) std::cout << "\troi " << iroi << " " << *roiInfo << std::endl;
855
857
858 pselectorTest->clear();
859
860 if ( this->template selectTracks<xAOD::TrackParticleContainer>( pselectorTest, roi_link, key ) ) { }
861
862 // beamspot stuff not needed for xAOD::TrackParticles
863
865
866 chain.addRoi( *roiInfo );
867
869
870 const std::vector<TIDA::Track*>& testtracks = pselectorTest->tracks();
871
872 chain.back().addTracks(testtracks);
873
874
876
877 if ( vtx_name!="" ) {
878
879 std::vector<TIDA::Vertex> tidavertices;
880
881 this->select( tidavertices, roi_link, vtx_name );
882
883 chain.back().addVertices( tidavertices );
884
885 }
886
887
888#if 0
889 if ( dbg ) {
890 std::cout << "\tTIDA analysis for chain: " << chainname << "\t key: " << key << "\t" << **roiptr << std::endl;
891 std::cout << "\tcollections: " << chain.back() << std::endl;
892 }
893#endif
894
895 delete roiInfo;
896
897 }
898
899
900 }
901
902 } // end of loop chainNames vector loop
903
904
905 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
906 m_provider->msg(MSG::VERBOSE) << "event: " << *eventp << endmsg;
907 }
908
909 }
910
911 // close previous loop over chains and open new one
912
913 for ( unsigned ichain=0 ; ichain<eventp->size() ; ichain++ ) {
914
915 TIDA::Chain& chain = (*eventp)[ichain];
916 ChainString chainConfig(chain.name());
917 const std::string& vtx_name = chainConfig.vtx();
918
919 // skip tag chains to avoid performing standard analysis on them (done for tnp at the same time as probes)
920 if ( m_tnp_flag && chainConfig.extra().find("_tag")!=std::string::npos ) continue ;
921
922 std::vector<TIDA::Roi*> rois ;
923
924 if (m_tnp_flag) {
925 // needs to be done AFTER retrieving offline tracks as pselectorRef passed as arguement, hence restructuring
926 rois = pTnP_tool->GetRois( eventp->chains(), pselectorRef, &filterRef, m_invmass, m_invmass_obj );
927 }
928 else {
929 rois.reserve( chain.size() );
930 for ( size_t ir=0 ; ir<chain.size() ; ir++ ) {
931 rois.push_back( &(chain.rois()[ir]) );
932 }
933 }
934
935 // now loop over the rois (again)
936
937 for ( unsigned iroi=0 ; iroi<rois.size() ; iroi++ ) {
938
939 if ( this->filterOnRoi() ) {
940 filterRef.setRoi( &(rois.at(iroi)->roi() ) );
941 filterRef.containtracks( m_containTracks );
942 }
943 else filterRef.setRoi( 0 );
944
945 test_tracks.clear();
946
947 // this block is before the track retrieval in the original, is it working the same here?
948
962
963 if ( m_provider->msg().level() <= MSG::VERBOSE )
964 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
965
966 if ( m_mcTruth ) {
967 if ( this->filterOnRoi() ) filter_truth.setRoi( &(rois.at(iroi)->roi() ) );
968 ref_tracks = pselectorRef->tracks(&filter_truth);
969 }
970 else { // ie. if ( m_doOffline )
971 ref_tracks = pselectorRef->tracks(&filterRef) ;
972 }
973
974 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
975 m_provider->msg(MSG::VERBOSE) << "ref tracks.size() " << pselectorRef->tracks().size() << endmsg;
976 for ( int ii=pselectorRef->tracks().size() ; ii-- ; ) {
977 m_provider->msg(MSG::VERBOSE) << " ref track " << ii << " " << *pselectorRef->tracks()[ii] << endmsg;
978 }
979 }
980
981 test_tracks.clear();
982
983
984 for ( unsigned itrk=0 ; itrk<rois.at(iroi)->tracks().size() ; itrk++ ) {
985 test_tracks.push_back(&(rois.at(iroi)->tracks().at(itrk)));
986 }
987
989 // std::cout << "sutt track multiplicities: offline " << offline_tracks.size() << "\ttest " << test_tracks.size() << std::endl;
990
992
993 beamline[0] = pselectorTest->getBeamX();
994 beamline[1] = pselectorTest->getBeamY();
995 beamline[2] = pselectorTest->getBeamZ();
996
997 beamline[3] = vertices.size();
998
1006 // m_manalysis->setvertices( vertices.size() ); /// what is this for ??? /// is this thread safe ???
1007
1010
1011 if ( m_runPurity ) {
1012
1013 if ( this->getUseHighestPT() ) HighestPTOnly( test_tracks );
1014
1015 if ( m_pTthreshold>0 ) FilterPT( test_tracks, m_pTthreshold );
1016
1018 m_NRois++;
1019 m_NRefTracks += test_tracks.size();
1020 m_NTestTracks += ref_tracks.size();
1021
1023 associator->match( test_tracks, ref_tracks );
1024
1025 m_manalysis->execute( test_tracks, ref_tracks, associator.get(), eventp, beamline );
1026
1027 }
1028 else {
1029
1031 if ( this->getUseHighestPT() ) HighestPTOnly( ref_tracks );
1032
1034
1035 if ( m_pTthreshold>0 ) FilterPT( ref_tracks, m_pTthreshold );
1036
1039 // if ( ref_tracks.size()==0 ) continue;
1040
1042 m_NRois++;
1043 m_NRefTracks += ref_tracks.size();
1044 m_NTestTracks += test_tracks.size();
1045
1047 associator->match( ref_tracks, test_tracks );
1048
1053 // m_manalysis->setroi( &rois.at(iroi)->roi() );
1054 m_manalysis->execute( ref_tracks, test_tracks, associator.get(), eventp, beamline, &(rois.at(iroi)->roi()) );
1055
1056 if ( vtx_name!="" ) {
1058 std::vector<TIDA::Vertex> vr = rois.at(iroi)->vertices();
1059 std::vector<TIDA::Vertex*> vtx_rec;
1060 for ( unsigned iv=0 ; iv<vr.size() ; iv++ ) vtx_rec.push_back( &vr[iv] );
1061
1062 std::vector<TIDA::Vertex*> vtx;
1063 if ( this->getVtxIndex()<0 ) {
1064 for ( unsigned iv=0 ; iv<vertices.size() ; iv++ ) vtx.push_back( &vertices[iv] );
1065 }
1066 else {
1067 if ( vertices.size()>unsigned(this->getVtxIndex()) ) vtx.push_back( &vertices[this->getVtxIndex()] );
1068 }
1069
1070 m_manalysis->execute_vtx( vtx, vtx_rec, eventp );
1071 }
1072
1073 }
1074
1075 if ( m_manalysis->debug() ) {
1076 m_provider->msg(MSG::INFO) << "Missing track for " << m_chainNames[ichain]
1077 << "\trun " << run_number
1078 << "\tevent " << event_number
1079 << "\tlb " << lumi_block << endmsg;
1080 }
1081
1082 }
1083
1084 }
1085
1086 // delete associator;
1087
1088 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
1089 m_provider->msg(MSG::VERBOSE) << "\n\nEvent " << *eventp << endmsg;
1090 }
1091
1092 }
1093
1094
1095
1096 virtual void book() {
1097
1098 if(m_provider->msg().level() <= MSG::VERBOSE)
1099 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::book() " << name() << endmsg;
1100
1101 // get the TriggerDecisionTool
1102
1103 if( m_tdt->retrieve().isFailure() ) {
1104 if(m_provider->msg().level() <= MSG::ERROR)
1105 m_provider->msg(MSG::ERROR) << " Unable to retrieve the TrigDecisionTool: Please check job options file" << endmsg;
1106 return;
1107 }
1108
1109 if(m_provider->msg().level() <= MSG::VERBOSE) {
1110 m_provider->msg(MSG::VERBOSE) << " Successfully retrieved the TrigDecisionTool" << endmsg;
1111 }
1112
1113
1115 if (m_provider->msg().level() <= MSG::VERBOSE) {
1116 std::vector<std::string> configuredChains = (*(m_tdt))->getListOfTriggers("L2_.*, EF_.*, HLT_.*");
1117
1118 m_provider->msg(MSG::VERBOSE) << "Configured chains" << endmsg;
1119 for ( unsigned i=0 ; i<configuredChains.size() ; i++ ) {
1120 if( m_provider->msg().level() <= MSG::VERBOSE)
1121 m_provider->msg(MSG::VERBOSE) << " Chain " << configuredChains[i] << endmsg;
1122 }
1123 }
1124
1125
1126 for ( unsigned ic=0 ; ic<m_chainNames.size() ; ic++ ) {
1127
1128 if ( ic>0 ) {
1129 m_provider->msg(MSG::WARNING) << "more than one chain configured for this analysis - skipping " << m_chainNames[ic] << endmsg;
1130 continue;
1131 }
1132
1133 m_provider->msg(MSG::VERBOSE) << "Analyse chain " << m_chainNames[ic] << endmsg;
1134
1135 // m_provider->msg(MSG::VERBOSE) << "--------------------------------------------------" << endmsg;
1136
1137 std::string folder_name = "";
1138
1139 if ( name()!="" ) folder_name = name();
1140 else folder_name = "HLT/TRIDT/IDMon";
1141
1143 if( m_testType != "" ) folder_name = folder_name + "/" + m_testType;
1144
1145 std::string mongroup;
1146
1147#if 0
1150
1151 if ( name().find("Shifter")!=std::string::npos || m_shifter ) {
1153 if ( m_chainNames.at(ic).tail().find("_FTF") != std::string::npos ) mongroup = folder_name + "/FTF";
1154 else if ( m_chainNames.at(ic).tail().find("_IDTrig") != std::string::npos ||
1155 m_chainNames.at(ic).tail().find("_EFID") != std::string::npos ) mongroup = folder_name + "/EFID";
1156 else if ( m_chainNames.at(ic).tail().find("InDetTrigParticle") != std::string::npos ) mongroup = folder_name + "/EFID_RUN1";
1157 else if ( m_chainNames.at(ic).tail().find("_GSF") != std::string::npos ) mongroup = folder_name + "/GSF";
1158 else mongroup = folder_name + "/Unknown";
1159
1160 if ( m_chainNames.at(ic).vtx()!="" ) mongroup += "/" + m_chainNames.at(ic).vtx();
1161
1162 }
1163#endif
1164 // else {
1166
1167 if ( m_chainNames[ic].head() == "" ) mongroup = folder_name + "/Fullscan";
1168 else mongroup = folder_name + "/" + m_chainNames[ic].head();
1169
1170 std::string track_collection = "";
1171
1172 if ( m_chainNames.at(ic).tail()!="" ) {
1173 track_collection = "/" + m_chainNames.at(ic).tail();
1174 if ( m_chainNames.at(ic).extra()!="" ) track_collection += "_" + m_chainNames.at(ic).extra();
1175 }
1176
1177 if ( m_chainNames.at(ic).roi()!="" ) {
1178 if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].roi();
1179 else track_collection = "/" + m_chainNames[ic].roi();
1180 }
1181
1182 if ( m_chainNames.at(ic).vtx()!="" ) {
1183 if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].vtx();
1184 else track_collection = "/" + m_chainNames[ic].vtx();
1185 }
1186
1188 if ( m_chainNames.at(ic).element()!="" ) {
1189 if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].element();
1190 else track_collection = "/" + m_chainNames[ic].element();
1191 }
1192
1193 if ( track_collection!="" ) mongroup += track_collection;
1194
1195 if ( !m_chainNames.at(ic).passed() ) mongroup += "/DTE";
1196
1197 // }
1198
1199 m_provider->msg(MSG::VERBOSE) << " book mongroup " << mongroup << endmsg;
1200
1201 m_manalysis = dynamic_cast<A*>(m_analysis);
1202
1203 if ( monTool() ) m_manalysis->set_monTool( monTool() );
1204
1205 m_analysis->initialise();
1206
1207 if(m_provider->msg().level() <= MSG::VERBOSE) {
1208 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::book() done" << endmsg;
1209 }
1210 }
1211
1212 }
1213
1214
1215
1216 virtual void finalize() {
1217
1218 if(m_provider->msg().level() <= MSG::VERBOSE){
1219 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::finalise() " << m_provider->name() << endmsg;
1220 }
1221
1222 m_analysis->finalise();
1223
1224 m_provider->msg(MSG::INFO) << m_provider->name() << " " << m_chainNames[0] << " \tNRois processed: " << m_NRois << "\tRef tracks: " << m_NRefTracks << "\tTestTracks: " << m_NTestTracks << endmsg;
1225
1226 if(m_provider->msg().level() <= MSG::VERBOSE) {
1227 m_provider->msg(MSG::VERBOSE) << m_provider->name() << " finalised" << endmsg;
1228 }
1229 }
1230
1231
1232protected:
1233
1235
1236 std::vector<ChainString> m_chainNames;
1237 std::vector<A*> m_analyses;
1238 std::string m_testType;
1239
1247
1248 std::vector<std::string> m_offline_types;
1249 std::vector<std::string> m_types;
1250
1251 std::string m_outputFileName;
1252
1255
1260
1262
1264
1266
1268
1270
1272
1274
1275 ToolHandle<GenericMonitoringTool>* m_monTool;
1276
1279
1280};
1281
1282
1283
1284#endif // TrigInDetAnalysisExample_T_AnalysisConfigR3_Tier0_H
1285
#define endmsg
Erkcan's track matchers.
generic track filter to filter on eta and PT only
bool passed(DecisionID id, const DecisionIDContainer &)
checks if required decision ID is in the set of IDs in the container
size_t size() const
Number of registered mappings.
Basic event class to contain a vector of chains for trigger analysis.
useful tool for the TrigInDetAnalysis class code
void HighestPTOnly(std::vector< T * > &tracks)
Definition TIDATools.h:20
void FilterPT(std::vector< T * > &tracks, double pt)
Definition TIDATools.h:41
std::ostream & operator<<(std::ostream &s, const std::vector< T > &v)
TIDA::Associator< TIDA::Track > TrackAssociator
emacs: this is -*- c++ -*-
const std::string & extra() const
Definition ChainString.h:38
const std::string & roi() const
Definition ChainString.h:35
const std::string & head() const
Definition ChainString.h:33
const std::string & vtx() const
Definition ChainString.h:36
const std::string & element() const
Definition ChainString.h:37
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:861
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
void setRoi(TIDARoiDescriptor *r)
Definition Filters.h:236
void containtracks(bool b=true)
set / unset the flag to determine whether tracks should be fully contained in the RoI or not
Definition Filters.h:242
default simple filter which accepts all tracks
Definition Filters.h:26
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
Describes the Region of Interest geometry It has basically 8 parameters.
TIDA::Roi & back()
Definition TIDAChain.h:60
void addRoi(TIDA::Roi &roi)
add and roi by root dictionary class
Definition TIDAChain.h:44
void lumi_block(unsigned lb)
Definition TIDAEvent.h:43
void mu(double m)
Definition TIDAEvent.h:46
TIDA::Chain & back()
get the last chain from the vector
Definition TIDAEvent.h:84
void addVertex(const TIDA::Vertex &v)
Definition TIDAEvent.h:70
void bunch_crossing_id(unsigned b)
Definition TIDAEvent.h:45
void addChain(const std::string &chainname)
methods to add and access chains
Definition TIDAEvent.h:66
void event_number(unsigned long long e)
Definition TIDAEvent.h:42
void time_stamp(unsigned t)
Definition TIDAEvent.h:44
void run_number(unsigned r)
accessors
Definition TIDAEvent.h:41
const std::vector< TIDA::Chain > & chains() const
Definition TIDAEvent.h:75
void clear()
clear the event
Definition TIDAEvent.h:81
unsigned size() const
vertex multiplicity ?
Definition TIDAEvent.h:63
void addTracks(const std::vector< TIDA::Track > &tracks)
accessors for the track vector
Definition TIDARoi.h:46
void set_monTool(ToolHandle< GenericMonitoringTool > *m)
T_AnalysisConfigR3_Tier0(const std::string &analysisInstanceName, const std::string &testChainName, const std::string &testType, const std::string &testKey, const std::string &referenceChainName, const std::string &referenceType, const std::string &referenceKey, TrackFilter *testFilter, TrackFilter *referenceFilter, TrackAssociator *associator, TrackAnalysis *analysis, TagNProbe *TnP_tool=0)
void setTypes(const std::vector< std::string > &t)
ToolHandle< GenericMonitoringTool > * monTool()
const std::string & name() const
std::string m_analysisInstanceName
bool selectTracks(TrigTrackSelector *selector, const ElementLink< TrigRoiDescriptorCollection > &roi_link, const std::string &key="")
StatusCode retrieve(Collection const *&collection, const std::string &key="")
std::vector< double > getBeamspot(const std::string &key)
T_AnalysisConfig(const std::string &analysisInstanceName, const std::string &testChainName, const std::string &testType, const std::string &testKey, const std::string &referenceChainName, const std::string &referenceType, const std::string &referenceKey, const std::string &selectionChainName, const std::string &selectionType, const std::string &selectionKey, TrackFilter *testFilter, TrackFilter *referenceFilter, TrackFilter *selectionFilter, TrackAssociator *associator, TrackAnalysis *analysis)
bool select(std::vector< TIDA::Vertex > &vertices, xAOD::VertexContainer::const_iterator vtx_start, xAOD::VertexContainer::const_iterator vtx_end)
std::vector< TIDA::Roi * > GetRois(std::vector< TIDA::Chain > &chains, const TrackSelector *selector, TrackFilter *filter, T *hmass, T *hmass_obj, TrigObjectMatcher *tom=0) const
void tag(const std::string &chainName)
getters and setters
const std::vector< TIDA::Track * > & tracks() const
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
bool selectTrack(HepMC::ConstGenParticlePtr track)
double getBeamY() const
virtual void clear() override
double getBeamX() const
double getBeamZ() const
uint32_t lumiBlock() const
The current event's luminosity block number.
uint32_t bcid() const
The bunch crossing ID of the event.
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
uint32_t timeStamp() const
POSIX time in seconds from 1970. January 1st.
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
std::string head(std::string s, const std::string &pattern)
head of a string
int ir
counter of the current depth
Definition fastadd.cxx:49
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140
int signal_process_id(const GenEvent &evt)
Definition GenEvent.h:572
std::vector< HepMC3::GenParticlePtr >::const_iterator begin(HepMC3::GenEvent &e)
Definition GenEvent.h:355
std::vector< HepMC3::GenParticlePtr >::const_iterator end(HepMC3::GenEvent &e)
Definition GenEvent.h:356
static const unsigned int includeFailedDecisions
Run3 synonym of alsoDeactivateTEs.
static const unsigned int lastFeatureOfType
Run 3 "enum". Only return the final feature along each route through the navigation.
static const unsigned int allFeaturesOfType
Run 3 "enum". Return all features along legs (still with type and container checks).
EventInfo_v1 EventInfo
Definition of the latest event info version.
hold the test vectors and ease the comparison
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22