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 bool found_offline = false;
638
639 for ( size_t it=0 ; it<m_offline_types.size() ; it++ ) {
640 if ( m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>( m_offline_types[it] ) ) {
641 this->template selectTracks<xAOD::TrackParticleContainer>( pselectorRef, m_offline_types[it] );
642 refbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( m_offline_types[it] );
643 found_offline = true;
644 }
645 else {
646 m_provider->msg(MSG::WARNING) << "Offline tracks not found: " << m_offline_types[it] << endmsg;
647 }
648 }
649
650 if ( !found_offline ) {
651 if (m_provider->evtStore()->template contains<Rec::TrackParticleContainer>("TrackParticleCandidate") ) {
653 this->template selectTracks<Rec::TrackParticleContainer>( pselectorRef, "TrackParticleCandidate" );
654 }
655 else {
656 m_provider->msg(MSG::WARNING) << "Offline tracks not found: " << "TrackParticleCandidate" << endmsg;
657 }
658 }
659
660 }
661
663
664 std::unique_ptr<TrackAssociator> associator = m_associator->uclone();
665
666 // std::cout << "\tloop() loop over chains proper ..." << std::endl;
667
669 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
670
672
673 // std::string& chainname = chains[ichain];
674 const std::string& chainname = m_chainNames[ichain].head();
675 const std::string& key = m_chainNames[ichain].tail();
676 const std::string& vtx_name = m_chainNames[ichain].vtx();
677
678 // Not used left just in case
679 // const std::string& roi_name = m_chainNames[ichain].roi();
680 // const std::string& te_name = m_chainNames[ichain].element();
681 m_pTthreshold = 0;
682
683 if ( m_chainNames[ichain].postcount() ) {
684 std::string ptvalue = m_chainNames[ichain].postvalue("pt");
685 if ( ptvalue!="" ) m_pTthreshold = std::stod(ptvalue);
686 }
687
688
689 unsigned decisiontype = TrigDefs::Physics;
690
691 if ( !m_chainNames[ichain].passed() ) decisiontype = TrigDefs::includeFailedDecisions;
692
694 // if ( decisiontype==TrigDefs::requireDecision ) std::cout << "\tSUTT TrigDefs::requireDecision " << decisiontype << std::endl;
695 // if ( decisiontype==TrigDefs::Physics ) std::cout << "\tSUTT TrigDefs::Physics " << decisiontype << std::endl;
696
697 if ( chainname!="" && m_provider->msg().level() <= MSG::VERBOSE ) {
698
699 m_provider->msg(MSG::VERBOSE) << "status for chain " << chainname
700 << "\tpass " << (*m_tdt)->isPassed(chainname)
701 << "\tprescale " << (*m_tdt)->getPrescale(chainname) << endmsg;
702
703 m_provider->msg(MSG::VERBOSE) << "fetching features for chain " << chainname << endmsg;
704
705 m_provider->msg(MSG::VERBOSE) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << endmsg;
706 }
707
709 // std::cout << "\tstatus for chain " << chainname
710 // << "\tpass " << (*m_tdt)->isPassed( chainname )
711 // << "\tpassdt " << (*m_tdt)->isPassed( chainname, decisiontype )
712 // << "\tprescale " << (*m_tdt)->getPrescale( chainname ) << std::endl;
713
714
715 // m_provider->msg(MSG::INFO) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << "\t" << m_chainNames[ichain] << "\trun " << run_number << "\tevent " << event_number << endmsg;
716
717
718 if ( chainname!="" && !this->m_keepAllEvents && !(*m_tdt)->isPassed( chainname, decisiontype ) ) continue;
719
722 // Trig::FeatureContainer f = (*m_tdt)->features( chainname, TrigDefs::alsoDeactivateTEs);
723
726
727 // tag and probe analysis processes multiple chains passed in the tag and probe tool at once so loop over vector of chains
728 std::vector<std::string> chainNames ;
729
730 if ( !m_tnp_flag ) {
731 chainNames.push_back(m_chainNames[ichain].raw()) ;
732 }
733 else {
734 chainNames.push_back(pTnP_tool->tag());
735 chainNames.push_back(pTnP_tool->probe());
736 }
737
738 // loop over new chainNames vector but doing the same stuff
739 for ( size_t i=0 ; i<chainNames.size() ; i++ ) {
740
741 ChainString chainConfig = chainNames[i] ;
742 std::string chainName = chainConfig.head();
743
744 eventp->addChain( chainNames[i] );
745
746 TIDA::Chain& chain = eventp->back();
747
748 if ( chainName == "" ) {
749
751
752 pselectorTest->clear();
753
755
756 // TIDARoiDescriptor roifs(true);
757
758 // chain.addRoi( roifs );
759
760 chain.addRoi( TIDARoiDescriptor(true) );
761
762 if ( m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>(key) ) {
763 this->template selectTracks<xAOD::TrackParticleContainer>( pselectorTest, key );
764 refbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( key );
765 }
766
767 const std::vector<TIDA::Track*>& testtracks = pselectorTest->tracks();
768
769 chain.back().addTracks(testtracks);
770
771 if ( vtx_name!="" ) {
772
774
775 m_provider->msg(MSG::VERBOSE) << "\tFetch xAOD::VertexContainer with key " << vtx_name << endmsg;
776
777 std::vector<TIDA::Vertex> tidavertices;
778
779 if ( this->select( tidavertices, vtx_name ) ) chain.back().addVertices( tidavertices );
780 }
781
782
783 // if ( roiInfo ) delete roiInfo;
784
785 }
786 else {
787
789
790 //std::string roi_key = m_chainNames[ichain].roi();
791
792 std::string roi_key = chainConfig.roi();
793
794 unsigned feature_type =TrigDefs::lastFeatureOfType;
795
796 if ( roi_key!="" ) feature_type= TrigDefs::allFeaturesOfType;
797
799
800 int leg = -1;
801
802 if ( chainConfig.element()!="" ) {
803 leg = std::atoi(chainConfig.element().c_str());
804 }
805
806 std::string rgex = roi_key;
807
808 std::vector< TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> > rois =
809 (*m_tdt)->template features<TrigRoiDescriptorCollection>( Trig::FeatureRequestDescriptor( chainName,
810 decisiontype,
811 rgex,
812 feature_type,
813 "roi",
814 leg ) );
815
818
819 if ( rois.empty() ) {
820 if ( !rgex.empty() ) {
821 rgex += "_probe";
822 rois = (*m_tdt)->template features<TrigRoiDescriptorCollection>( Trig::FeatureRequestDescriptor( chainName,
823 decisiontype,
824 rgex,
825 feature_type,
826 "roi",
827 leg ) );
828 }
829 }
830
831 int iroi = 0;
832
833 for ( const TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection>& roi_info : rois ) {
834
835 iroi++;
836
840
841 if ( roi_key=="SuperRoi" && iroi>1 ) continue;
842
843 // std::cout << "\troi: get link " << roi_key << " ..." << std::endl;
844
845 const ElementLink<TrigRoiDescriptorCollection> roi_link = roi_info.link;
846
848 if ( roi_key!="" && roi_link.dataID()!=rgex ) continue;
849
851 if ( !roi_link.isValid() ) continue;
852
853 const TrigRoiDescriptor* const* roiptr = roi_link.cptr();
854
855 if ( roiptr == 0 ) continue;
856
857
859 // std::cout << "\troi: link deref ..." << *roiptr << std::endl;
860
861 if (m_provider->msg().level() <= MSG::VERBOSE) {
862 m_provider->msg(MSG::VERBOSE) << " RoI descriptor for seeded chain " << chainname << " " << **roiptr << endmsg;
863 }
864
866
867 // if ( dbg ) std::cout << "\troi " << iroi << " " << *roiInfo << std::endl;
868
870
871 pselectorTest->clear();
872
873 if ( this->template selectTracks<xAOD::TrackParticleContainer>( pselectorTest, roi_link, key ) ) { }
874
875 // beamspot stuff not needed for xAOD::TrackParticles
876
878
879 chain.addRoi( *roiInfo );
880
882
883 const std::vector<TIDA::Track*>& testtracks = pselectorTest->tracks();
884
885 chain.back().addTracks(testtracks);
886
887
889
890 if ( vtx_name!="" ) {
891
892 std::vector<TIDA::Vertex> tidavertices;
893
894 this->select( tidavertices, roi_link, vtx_name );
895
896 chain.back().addVertices( tidavertices );
897
898 }
899
900
901#if 0
902 if ( dbg ) {
903 std::cout << "\tTIDA analysis for chain: " << chainname << "\t key: " << key << "\t" << **roiptr << std::endl;
904 std::cout << "\tcollections: " << chain.back() << std::endl;
905 }
906#endif
907
908 delete roiInfo;
909
910 }
911
912
913 }
914
915 } // end of loop chainNames vector loop
916
917
918 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
919 m_provider->msg(MSG::VERBOSE) << "event: " << *eventp << endmsg;
920 }
921
922 }
923
924 // close previous loop over chains and open new one
925
926 for ( unsigned ichain=0 ; ichain<eventp->size() ; ichain++ ) {
927
928 TIDA::Chain& chain = (*eventp)[ichain];
929 ChainString chainConfig(chain.name());
930 const std::string& vtx_name = chainConfig.vtx();
931
932 // skip tag chains to avoid performing standard analysis on them (done for tnp at the same time as probes)
933 if ( m_tnp_flag && chainConfig.extra().find("_tag")!=std::string::npos ) continue ;
934
935 std::vector<TIDA::Roi*> rois ;
936
937 if (m_tnp_flag) {
938 // needs to be done AFTER retrieving offline tracks as pselectorRef passed as arguement, hence restructuring
939 rois = pTnP_tool->GetRois( eventp->chains(), pselectorRef, &filterRef, m_invmass, m_invmass_obj );
940 }
941 else {
942 rois.reserve( chain.size() );
943 for ( size_t ir=0 ; ir<chain.size() ; ir++ ) {
944 rois.push_back( &(chain.rois()[ir]) );
945 }
946 }
947
948 // now loop over the rois (again)
949
950 for ( unsigned iroi=0 ; iroi<rois.size() ; iroi++ ) {
951
952 if ( this->filterOnRoi() ) {
953 filterRef.setRoi( &(rois.at(iroi)->roi() ) );
954 filterRef.containtracks( m_containTracks );
955 }
956 else filterRef.setRoi( 0 );
957
958 test_tracks.clear();
959
960 // this block is before the track retrieval in the original, is it working the same here?
961
975
976 if ( m_provider->msg().level() <= MSG::VERBOSE )
977 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
978
979 if ( m_mcTruth ) {
980 if ( this->filterOnRoi() ) filter_truth.setRoi( &(rois.at(iroi)->roi() ) );
981 ref_tracks = pselectorRef->tracks(&filter_truth);
982 }
983 else { // ie. if ( m_doOffline )
984 ref_tracks = pselectorRef->tracks(&filterRef) ;
985 }
986
987 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
988 m_provider->msg(MSG::VERBOSE) << "ref tracks.size() " << pselectorRef->tracks().size() << endmsg;
989 for ( int ii=pselectorRef->tracks().size() ; ii-- ; ) {
990 m_provider->msg(MSG::VERBOSE) << " ref track " << ii << " " << *pselectorRef->tracks()[ii] << endmsg;
991 }
992 }
993
994 test_tracks.clear();
995
996
997 for ( unsigned itrk=0 ; itrk<rois.at(iroi)->tracks().size() ; itrk++ ) {
998 test_tracks.push_back(&(rois.at(iroi)->tracks().at(itrk)));
999 }
1000
1002 // std::cout << "sutt track multiplicities: offline " << offline_tracks.size() << "\ttest " << test_tracks.size() << std::endl;
1003
1005
1006 beamline[0] = pselectorTest->getBeamX();
1007 beamline[1] = pselectorTest->getBeamY();
1008 beamline[2] = pselectorTest->getBeamZ();
1009
1010 beamline[3] = vertices.size();
1011
1019 // m_manalysis->setvertices( vertices.size() ); /// what is this for ??? /// is this thread safe ???
1020
1023
1024 if ( m_runPurity ) {
1025
1026 if ( this->getUseHighestPT() ) HighestPTOnly( test_tracks );
1027
1028 if ( m_pTthreshold>0 ) FilterPT( test_tracks, m_pTthreshold );
1029
1031 m_NRois++;
1032 m_NRefTracks += test_tracks.size();
1033 m_NTestTracks += ref_tracks.size();
1034
1036 associator->match( test_tracks, ref_tracks );
1037
1038 m_manalysis->execute( test_tracks, ref_tracks, associator.get(), eventp, beamline );
1039
1040 }
1041 else {
1042
1044 if ( this->getUseHighestPT() ) HighestPTOnly( ref_tracks );
1045
1047
1048 if ( m_pTthreshold>0 ) FilterPT( ref_tracks, m_pTthreshold );
1049
1052 // if ( ref_tracks.size()==0 ) continue;
1053
1055 m_NRois++;
1056 m_NRefTracks += ref_tracks.size();
1057 m_NTestTracks += test_tracks.size();
1058
1060 associator->match( ref_tracks, test_tracks );
1061
1066 // m_manalysis->setroi( &rois.at(iroi)->roi() );
1067 m_manalysis->execute( ref_tracks, test_tracks, associator.get(), eventp, beamline, &(rois.at(iroi)->roi()) );
1068
1069 if ( vtx_name!="" ) {
1071 std::vector<TIDA::Vertex> vr = rois.at(iroi)->vertices();
1072 std::vector<TIDA::Vertex*> vtx_rec;
1073 for ( unsigned iv=0 ; iv<vr.size() ; iv++ ) vtx_rec.push_back( &vr[iv] );
1074
1075 std::vector<TIDA::Vertex*> vtx;
1076 if ( this->getVtxIndex()<0 ) {
1077 for ( unsigned iv=0 ; iv<vertices.size() ; iv++ ) vtx.push_back( &vertices[iv] );
1078 }
1079 else {
1080 if ( vertices.size()>unsigned(this->getVtxIndex()) ) vtx.push_back( &vertices[this->getVtxIndex()] );
1081 }
1082
1083 m_manalysis->execute_vtx( vtx, vtx_rec, eventp );
1084 }
1085
1086 }
1087
1088 if ( m_manalysis->debug() ) {
1089 m_provider->msg(MSG::INFO) << "Missing track for " << m_chainNames[ichain]
1090 << "\trun " << run_number
1091 << "\tevent " << event_number
1092 << "\tlb " << lumi_block << endmsg;
1093 }
1094
1095 }
1096
1097 }
1098
1099 // delete associator;
1100
1101 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
1102 m_provider->msg(MSG::VERBOSE) << "\n\nEvent " << *eventp << endmsg;
1103 }
1104
1105 }
1106
1107
1108
1109 virtual void book() {
1110
1111 if(m_provider->msg().level() <= MSG::VERBOSE)
1112 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::book() " << name() << endmsg;
1113
1114 // get the TriggerDecisionTool
1115
1116 if( m_tdt->retrieve().isFailure() ) {
1117 if(m_provider->msg().level() <= MSG::ERROR)
1118 m_provider->msg(MSG::ERROR) << " Unable to retrieve the TrigDecisionTool: Please check job options file" << endmsg;
1119 return;
1120 }
1121
1122 if(m_provider->msg().level() <= MSG::VERBOSE) {
1123 m_provider->msg(MSG::VERBOSE) << " Successfully retrieved the TrigDecisionTool" << endmsg;
1124 }
1125
1126
1128 if (m_provider->msg().level() <= MSG::VERBOSE) {
1129 std::vector<std::string> configuredChains = (*(m_tdt))->getListOfTriggers("L2_.*, EF_.*, HLT_.*");
1130
1131 m_provider->msg(MSG::VERBOSE) << "Configured chains" << endmsg;
1132 for ( unsigned i=0 ; i<configuredChains.size() ; i++ ) {
1133 if( m_provider->msg().level() <= MSG::VERBOSE)
1134 m_provider->msg(MSG::VERBOSE) << " Chain " << configuredChains[i] << endmsg;
1135 }
1136 }
1137
1138
1139 for ( unsigned ic=0 ; ic<m_chainNames.size() ; ic++ ) {
1140
1141 if ( ic>0 ) {
1142 m_provider->msg(MSG::WARNING) << "more than one chain configured for this analysis - skipping " << m_chainNames[ic] << endmsg;
1143 continue;
1144 }
1145
1146 m_provider->msg(MSG::VERBOSE) << "Analyse chain " << m_chainNames[ic] << endmsg;
1147
1148 // m_provider->msg(MSG::VERBOSE) << "--------------------------------------------------" << endmsg;
1149
1150 std::string folder_name = "";
1151
1152 if ( name()!="" ) folder_name = name();
1153 else folder_name = "HLT/TRIDT/IDMon";
1154
1156 if( m_testType != "" ) folder_name = folder_name + "/" + m_testType;
1157
1158 std::string mongroup;
1159
1160#if 0
1163
1164 if ( name().find("Shifter")!=std::string::npos || m_shifter ) {
1166 if ( m_chainNames.at(ic).tail().find("_FTF") != std::string::npos ) mongroup = folder_name + "/FTF";
1167 else if ( m_chainNames.at(ic).tail().find("_IDTrig") != std::string::npos ||
1168 m_chainNames.at(ic).tail().find("_EFID") != std::string::npos ) mongroup = folder_name + "/EFID";
1169 else if ( m_chainNames.at(ic).tail().find("InDetTrigParticle") != std::string::npos ) mongroup = folder_name + "/EFID_RUN1";
1170 else if ( m_chainNames.at(ic).tail().find("_GSF") != std::string::npos ) mongroup = folder_name + "/GSF";
1171 else mongroup = folder_name + "/Unknown";
1172
1173 if ( m_chainNames.at(ic).vtx()!="" ) mongroup += "/" + m_chainNames.at(ic).vtx();
1174
1175 }
1176#endif
1177 // else {
1179
1180 if ( m_chainNames[ic].head() == "" ) mongroup = folder_name + "/Fullscan";
1181 else mongroup = folder_name + "/" + m_chainNames[ic].head();
1182
1183 std::string track_collection = "";
1184
1185 if ( m_chainNames.at(ic).tail()!="" ) {
1186 track_collection = "/" + m_chainNames.at(ic).tail();
1187 if ( m_chainNames.at(ic).extra()!="" ) track_collection += "_" + m_chainNames.at(ic).extra();
1188 }
1189
1190 if ( m_chainNames.at(ic).roi()!="" ) {
1191 if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].roi();
1192 else track_collection = "/" + m_chainNames[ic].roi();
1193 }
1194
1195 if ( m_chainNames.at(ic).vtx()!="" ) {
1196 if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].vtx();
1197 else track_collection = "/" + m_chainNames[ic].vtx();
1198 }
1199
1201 if ( m_chainNames.at(ic).element()!="" ) {
1202 if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].element();
1203 else track_collection = "/" + m_chainNames[ic].element();
1204 }
1205
1206 if ( track_collection!="" ) mongroup += track_collection;
1207
1208 if ( !m_chainNames.at(ic).passed() ) mongroup += "/DTE";
1209
1210 // }
1211
1212 m_provider->msg(MSG::VERBOSE) << " book mongroup " << mongroup << endmsg;
1213
1214 m_manalysis = dynamic_cast<A*>(m_analysis);
1215
1216 if ( monTool() ) m_manalysis->set_monTool( monTool() );
1217
1218 m_analysis->initialise();
1219
1220 if(m_provider->msg().level() <= MSG::VERBOSE) {
1221 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::book() done" << endmsg;
1222 }
1223 }
1224
1225 }
1226
1227
1228
1229 virtual void finalize() {
1230
1231 if(m_provider->msg().level() <= MSG::VERBOSE){
1232 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::finalise() " << m_provider->name() << endmsg;
1233 }
1234
1235 m_analysis->finalise();
1236
1237 m_provider->msg(MSG::INFO) << m_provider->name() << " " << m_chainNames[0] << " \tNRois processed: " << m_NRois << "\tRef tracks: " << m_NRefTracks << "\tTestTracks: " << m_NTestTracks << endmsg;
1238
1239 if(m_provider->msg().level() <= MSG::VERBOSE) {
1240 m_provider->msg(MSG::VERBOSE) << m_provider->name() << " finalised" << endmsg;
1241 }
1242 }
1243
1244
1245protected:
1246
1248
1249 std::vector<ChainString> m_chainNames;
1250 std::vector<A*> m_analyses;
1251 std::string m_testType;
1252
1260
1261 std::vector<std::string> m_offline_types;
1262 std::vector<std::string> m_types;
1263
1264 std::string m_outputFileName;
1265
1268
1273
1275
1277
1279
1281
1283
1285
1287
1288 ToolHandle<GenericMonitoringTool>* m_monTool;
1289
1292
1293};
1294
1295
1296
1297#endif // TrigInDetAnalysisExample_T_AnalysisConfigR3_Tier0_H
1298
#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)
emacs: this is -*- c++ -*-
TIDA::Associator< TIDA::Track > TrackAssociator
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:838
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)
void probe(const std::string &chainName)
Definition TagNProbe.h:49
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:63
void tag(const std::string &chainName)
getters and setters
Definition TagNProbe.h:48
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
double getBeamY() const
virtual void clear() override
double getBeamX() const
double getBeamZ() const
bool selectTrack(const Rec::TrackParticle *track)
neater code to make use of vector function also for a single ancestor pdgid, instead of the full code...
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