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
71
73
75
76
79
80// #include "TrigSteeringEvent/TrigRoiDescriptorCollection.h"
81
84
86
87
88template<typename T>
89std::ostream& operator<<( std::ostream& s, const std::vector<T>& v) {
90 for ( size_t i=0 ; i<v.size() ; i++ ) s << " " << v[i];
91 return s;
92}
93
94
95template<typename T, typename A=AnalysisR3_Tier0>
97
98public:
99
100 // Full constructor: test/reference/selection
101 // - analysisInstanceName: the name of the analysis chain being created
102 // - xxxChainName: the name of the chain to be used as test/reference/selection; must be "StoreGate" in case of direct access to SG containers
103 // - xxxType: the type of tracks to be retrieved from the test/reference/selection chain or container
104 // - xxxKey: the key for tracks to be retrieved from the test/reference/selection chain or container
105 // - 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
106 // - all standard operations are performed in loops over 0=test 1=reference 2=selection
107 T_AnalysisConfigR3_Tier0(const std::string& analysisInstanceName,
108 const std::string& testChainName, const std::string& testType, const std::string& testKey,
109 const std::string& referenceChainName, const std::string& referenceType, const std::string& referenceKey,
110 TrackFilter* testFilter, TrackFilter* referenceFilter,
111 TrackAssociator* associator,
113 TagNProbe* TnP_tool = 0) :
114 T_AnalysisConfig<T>( analysisInstanceName,
115 testChainName, testType, testKey,
116 referenceChainName, referenceType, referenceKey,
117 testFilter, referenceFilter,
118 associator,
119 analysis),
120 m_manalysis(0),
121 m_useBeamCondSvc(false),
122 m_doOffline(true),
123 m_doMuons(false),
124 m_doElectrons(false),
125 m_doTaus(false),
126 m_doBjets(false),
127 m_doTauThreeProng(false),
128 m_tauEtCutOffline(false),
129 m_pdgID(0),
131 m_NRois(0),
132 m_NRefTracks(0),
133 m_NTestTracks(0),
134 m_runPurity(false),
135 m_shifter(false),
136 m_pTthreshold(0),
137 m_first(true),
138 m_containTracks(false),
139 m_tnp_flag(false),
140 m_monTool(0),
141 m_invmass(0),
143 {
144
147
148 m_chainNames.push_back(testChainName);
149
151
152 m_TnP_tool = TnP_tool;
153
154#if 0
156 ChainString& chain = m_chainNames.back();
157
158 std::cout << "\nT_AnalysisConfigR3_Tier0::name: " << name() << "\t" << this << std::endl;
159 std::cout << "T_AnalysisConfigR3_Tier0::chain specification: " << testChainName << " -> " << chain << "\t" << chain.raw() << std::endl;
160 std::cout << "\tchain: " << chain.head() << std::endl;
161 std::cout << "\tkey: " << chain.tail() << std::endl;
162 std::cout << "\troi: " << chain.roi() << std::endl;
163 std::cout << "\tvtx: " << chain.vtx() << std::endl;
164 std::cout << "\tte: " << chain.element() << std::endl;
165 std::cout << "\textra: " << chain.extra() << std::endl;
166
167 std::cout << "\tpost: " << chain.post() << std::endl;
168 std::cout << "\tpt: " << chain.postvalue("pt") << std::endl;
169
170 std::cout << "\tcontainTracks: " << m_containTracks << std::endl;
171
172#endif
173
174 m_testType = testType;
175
176 if ( m_TnP_tool ) m_tnp_flag = true;
177
178 }
179
180
182 if ( m_TnP_tool ) delete m_TnP_tool;
183 if ( m_invmass ) delete m_invmass;
184 if ( m_invmass_obj ) delete m_invmass_obj;
185 }
186
187
188 void initialise() {
189
190 if ( m_tnp_flag ) {
191 if ( m_invmass==0 ) m_invmass = new TIDA::Histogram<float>( monTool(), "invmass" );
192 if ( m_invmass_obj==0 ) m_invmass_obj = new TIDA::Histogram<float>( monTool(), "invmass_obj" );
193 }
194
195 for ( size_t it=0 ; it<m_types.size() ; it++ ) {
196 if ( m_types[it]=="" ) m_offline_types.push_back( "InDetTrackParticles" );
197 else m_offline_types.push_back( m_types[it] );
198 }
199
200 if ( m_offline_types.empty() ) m_offline_types.push_back( "InDetTrackParticles" );
201
202 }
203
204
205 void setRunPurity( bool b ) { m_runPurity=b; }
206
207 void setShifter( bool b ) { m_shifter=b; }
208
209 void useBeamCondSvc( bool b ) { m_useBeamCondSvc = b; }
210
211 void containTracks( bool b ) { m_containTracks = b; }
212
213 void setPdgID( int i=0 ) { m_pdgID=i; }
214
215 void setParentPdgID( int i=0 ) { m_parent_pdgID=i; }
216
217 void setMCTruthRef( bool b ) { m_mcTruth=b; }
218
219 void setOfflineRef( bool b ) { m_doOffline=b; }
220
221 void setTypes( const std::vector<std::string>& t ) { m_types=t; }
222
223 void set_monTool( ToolHandle<GenericMonitoringTool>* m ) { m_monTool=m; }
224
225 ToolHandle<GenericMonitoringTool>* monTool() { return m_monTool; }
226
227public:
228
230
231 using T_AnalysisConfig<T>::name;
232
233protected:
234
238
240
245
246 virtual void loop() {
247
248 const TagNProbe* pTnP_tool = m_TnP_tool;
249
250 if( m_provider->msg().level() <= MSG::VERBOSE) {
251 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::loop() for " << T_AnalysisConfig<T>::m_analysisInstanceName << endmsg;
252 }
253
255 // get (offline) beam position
256 // double xbeam = 0;
257 // double ybeam = 0;
258
259#if 0
260
261 if ( m_first ) {
262
263 m_first = false;
264
265 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
266 m_provider->msg(MSG::VERBOSE) << " using beam position\tx=" << xbeam << "\ty=" << ybeam << endmsg;
267
268 std::vector<std::string> configuredChains = (*(m_tdt))->getListOfTriggers("L2_.*, EF_.*, HLT_.*");
269
270 for ( unsigned i=0 ; i<configuredChains.size() ; i++ ) {
272 // std::cout << "Configured chain " << configuredChains[i] << std::endl;
273 m_provider->msg(MSG::VERBOSE) << "Chain " << configuredChains[i] << endmsg;
274 }
275 }
276
277 // std::cout << "\tloop() analyse chains " << m_chainNames.size() << std::endl;
278
279 }
280
281#endif
282
283 Filter_True filter;
284
285 Filter_etaPT filter_etaPT( 5, 200 );
286 Filter_Combined filter_truth( &filter_etaPT, &filter_etaPT);
287
289 // Filter_Combined filterRef (&filter_offline, &filter_vertex);
290
291 int iRefFilter = 1;
292 int iTestFilter = 0;
293
294 if ( m_runPurity ) {
295 iRefFilter = 0;
296 iTestFilter = 1;
297 }
298
299
300 TrackFilter* rfilter = m_filters[iRefFilter][0];
301 TrackFilter* tfilter = m_filters[iTestFilter][0];
302
303 Filter_Combined filterRef( rfilter, &filter );
304 Filter_Combined filterTest( tfilter, &filter );
305
306 TrigTrackSelector selectorTruth( &filter_truth, m_pdgID, m_parent_pdgID );
307
308 TrigTrackSelector selectorRef( &filterRef );
309 TrigTrackSelector* pselectorRef = &selectorRef;
310
311 TrigTrackSelector selectorTest( &filterTest );
312 TrigTrackSelector* pselectorTest = &selectorTest;
313
315 if ( m_mcTruth ) pselectorRef = &selectorTruth;
316
322
324
325 TIDA::Event event;
326 TIDA::Event* eventp = &event;
327
328 double beamline[4] = { 0, 0, 0, 0 };
329
330 // clear the ntuple TIDA::Event class
331 eventp->clear();
332
334
335 const xAOD::EventInfo* pEventInfo = 0;
336
337 unsigned run_number = 0;
338 unsigned long long event_number = 0;
339 unsigned lumi_block = 0;
340 unsigned bunch_crossing_id = 0;
341 unsigned time_stamp = 0;
342 double mu_val = 0;
343
345 // std::cout << "\tloop() get EventInfo" << std::endl;
346
347 if ( this->template retrieve( pEventInfo, "EventInfo" ).isFailure() ) {
348 m_provider->msg(MSG::WARNING) << "Failed to get EventInfo " << endmsg;
349 } else {
350
351 run_number = pEventInfo->runNumber();
352 event_number = pEventInfo->eventNumber();
353 lumi_block = pEventInfo->lumiBlock();
354 time_stamp = pEventInfo->timeStamp();
355 bunch_crossing_id = pEventInfo->bcid();
356 mu_val = pEventInfo->averageInteractionsPerCrossing();
357 }
358
359 if(m_provider->msg().level() <= MSG::VERBOSE){
360 m_provider->msg(MSG::VERBOSE) << "run " << run_number
361 << "\tevent " << event_number
362 << "\tlb " << lumi_block << endmsg;
363 }
364
365 // clear the ntuple TIDA::Event class
366 eventp->clear();
367
368 eventp->run_number(run_number);
369 eventp->event_number(event_number);
370 eventp->lumi_block(lumi_block);
371 eventp->time_stamp(time_stamp);
372 eventp->bunch_crossing_id(bunch_crossing_id);
373 eventp->mu(mu_val);
374
377
378 bool analyse = false;
379
380 // Check HLTResult
381
382 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
383
384 const std::string& chainname = m_chainNames[ichain].head();
385
386 if ( chainname == "" ) analyse = true;
387 else {
388
389 //Only for trigger chains
390 if ( chainname.find("L2") == std::string::npos &&
391 chainname.find("EF") == std::string::npos &&
392 chainname.find("HLT") == std::string::npos ) continue;
393
394 if ( m_provider->msg().level() <= MSG::DEBUG ) {
395 m_provider->msg(MSG::DEBUG) << "Chain " << chainname
396 << "\tpass " << (*m_tdt)->isPassed(chainname)
397 << "\tpres " << (*m_tdt)->getPrescale(chainname) << endmsg;
398 }
399
401 // std::cout << "\tChain " << chainname << "\tpass " << (*m_tdt)->isPassed(chainname)
402 // << "\tpres " << (*m_tdt)->getPrescale(chainname) << std::endl;
403
404 if ( (*(m_tdt))->isPassed(chainname) ) analyse = true;
405
406 }
407
408 }
409
410
411 if ( !this->m_keepAllEvents && !analyse ) {
412 if(m_provider->msg().level() <= MSG::VERBOSE) {
413 m_provider->msg(MSG::VERBOSE) << "No chains passed unprescaled - not processing this event" << endmsg;
414 }
415 return;
416 }
417
418
420
421 selectorTruth.clear();
422
423 if(m_provider->msg().level() <= MSG::VERBOSE)
424 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
425
427
428 std::vector<TIDA::Vertex> vertices;
429 std::vector<TIDA::Vertex> vertices_rec;
430
431 std::vector<double> refbeamspot;
432 std::vector<double> testbeamspot;
433
435
436 m_provider->msg(MSG::VERBOSE) << "fetching AOD Primary vertex container" << endmsg;
437
438 if ( !this->select( vertices, "PrimaryVertices" ) ) {
439 m_provider->msg(MSG::VERBOSE) << "could not retrieve the 'PrimaryVertices' vertex collection" << std::endl;
440 }
441
443
444 if ( m_mcTruth ) {
445 eventp->addChain( "Truth" );
446 eventp->back().addRoi(TIDARoiDescriptor());
447 eventp->back().back().addTracks(selectorTruth.tracks());
448 }
449
451
452 if ( m_doOffline ) {
453 for ( unsigned i=0 ; i<vertices.size() ; i++ ) {
454 if(m_provider->msg().level() <= MSG::VERBOSE)
455 m_provider->msg(MSG::VERBOSE) << "vertex " << i << " " << vertices[i] << endmsg;
456 eventp->addVertex(vertices[i]);
457 }
458 }
459
460
461
463
464 std::vector<TIDA::Track*> offline_tracks;
465 std::vector<TIDA::Track*> electron_tracks;
466 std::vector<TIDA::Track*> muon_tracks;
467
468 std::vector<TIDA::Track*> ref_tracks;
469 std::vector<TIDA::Track*> test_tracks;
470
471 offline_tracks.clear();
472 electron_tracks.clear();
473 muon_tracks.clear();
474
475 ref_tracks.clear();
476 test_tracks.clear();
477
478 // offline track retrieval now done once for each chain rather than each roi
479 if ( m_provider->msg().level() <= MSG::VERBOSE )
480 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
481
482 bool foundTruth = false;
483
485
486 if ( m_mcTruth ) {
487
488 filter_truth.setRoi( 0 ); // don't filter on RoI yet (or until needed)
489
490 selectorTruth.clear();
491
492 if ( m_provider->msg().level() <= MSG::VERBOSE )
493 m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg;
494
495 if ( m_provider->evtStore()->template contains<TruthParticleContainer>("INav4MomTruthEvent") ) {
496 //ESD
497 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "INav4MomTruthEvent" );
498 foundTruth = true;
499 }
500 else if ( m_provider->evtStore()->template contains<TruthParticleContainer>("SpclMC") ) {
502 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "SpclMC");
503 foundTruth = true;
504 }
505 else if ( m_provider->evtStore()->template contains<xAOD::TruthParticleContainer>("TruthParticles") ) {
507 this->template selectTracks<xAOD::TruthParticleContainer>( &selectorTruth, "TruthParticles");
508 foundTruth = true;
509 }
510 else if ( m_provider->evtStore()->template contains<TruthParticleContainer>("") ) {
512 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "");
513 foundTruth = true;
514 }
515 else
516 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
517 m_provider->msg(MSG::VERBOSE) << "Truth not found - none whatsoever!" << endmsg;
518 }
519 }
520
521 if ( m_mcTruth && !foundTruth ) {
522
523 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
524 m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg;
525 }
526
528
529 const McEventCollection* mcevent = nullptr;
530
532
533 std::string keys[4] = { "GEN_AOD", "TruthEvent", "", "G4Truth" };
534
535 std::string key = "";
536
537 bool foundcollection = false;
538
539 for ( int ik=0 ; ik<4 ; ik++ ) {
540
541 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
542 m_provider->msg(MSG::VERBOSE) << "Try McEventCollection: " << keys[ik] << endmsg;
543 }
544
545 if ( !m_provider->evtStore()->template contains<McEventCollection>(keys[ik]) ) {
546 if( m_provider->msg().level() <= MSG::VERBOSE )
547 m_provider->msg(MSG::VERBOSE) << "No McEventCollection: " << keys[ik] << endmsg;
548 continue;
549 }
550
551 if ( m_provider->msg().level() <= MSG::VERBOSE )
552 m_provider->msg(MSG::VERBOSE) << "evtStore()->retrieve( mcevent, " << keys[ik] << " )" << endmsg;
553
554 if ( this->template retrieve( mcevent, keys[ik] ).isFailure() ) {
555 if ( m_provider->msg().level() <= MSG::VERBOSE )
556 m_provider->msg(MSG::VERBOSE) << "Failed to get McEventCollection: " << keys[ik] << endmsg;
557 }
558 else {
560 key = keys[ik];
561 if(m_provider->msg().level() <= MSG::VERBOSE)
562 m_provider->msg(MSG::VERBOSE) << "Found McEventCollection: " << key << endmsg;
563 foundcollection = true;
564 break;
565 }
566 }
567
569 if ( !foundcollection ) {
570 if(m_provider->msg().level() <= MSG::VERBOSE)
571 m_provider->msg(MSG::WARNING) << "No MC Truth Collections of any sort, whatsoever!!!" << endmsg;
572
573 // m_tree->Fill();
574 // return StatusCode::FAILURE;
575
576 return;
577 }
578
579 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
580 m_provider->msg(MSG::VERBOSE) << "Found McEventCollection: " << key << "\tNevents " << mcevent->size() << endmsg;
581 }
582
583 McEventCollection::const_iterator evitr = mcevent->begin();
584 McEventCollection::const_iterator evend = mcevent->end();
585
586 unsigned ie = 0;
587 unsigned ip = 0;
588
589 unsigned ie_ip = 0;
590
591 while ( evitr!=evend ) {
592
593 int ipc = 0;
594
595 int pid = HepMC::signal_process_id((*evitr));
596
597 //The logic should be clarified here
598 if ( pid!=0 ) {
599
600 // For HepMC2-based builds the following two functions return
601 // GenEvent::particle_const_iterator
602 // while for HepMC3-based builds they return
603 // std::vector<HepMC3::ConstGenParticlePtr>::const_iterator
604 // see AtlasHepMC/GenEvent.h for function definitions.
605 auto pitr(HepMC::begin(**evitr));
606 const auto pend(HepMC::end(**evitr));
607
608 while ( pitr!=pend ) {
609
610 selectorTruth.selectTrack( *pitr++ );
611
612 ++ipc;
613
614 }
615
616 }
617 ++ie;
618 ++evitr;
619
620 if ( ipc>0 ) {
622 // m_provider->msg(MSG::VERBOSE) << "Found " << ie << "\tpid " << pid << "\t with " << ip << " TruthParticles (GenParticles)" << endmsg;
623 ++ie_ip;
624 ip += ipc;
625 }
626 }
627
628 if(m_provider->msg().level() <= MSG::VERBOSE){
629 m_provider->msg(MSG::VERBOSE) << "Found " << ip << " TruthParticles (GenParticles) in " << ie_ip << " GenEvents out of " << ie << endmsg;
630 m_provider->msg(MSG::VERBOSE) << "selected " << selectorTruth.size() << " TruthParticles (GenParticles)" << endmsg;
631 }
632
633 if(selectorTruth.size() > 0) foundTruth = true;
634
635 if ( !(ip>0) ) {
636 if (m_provider->msg().level() <= MSG::VERBOSE) m_provider->msg(MSG::WARNING) << "NO TRUTH PARTICLES - returning" << endmsg;
637 return;
638 }
639
640 }
641
642 if ( m_doOffline && !m_mcTruth) {
643
644 bool found_offline = false;
645
646 for ( size_t it=0 ; it<m_offline_types.size() ; it++ ) {
647 if ( m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>( m_offline_types[it] ) ) {
648 this->template selectTracks<xAOD::TrackParticleContainer>( pselectorRef, m_offline_types[it] );
649 refbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( m_offline_types[it] );
650 found_offline = true;
651 }
652 else {
653 m_provider->msg(MSG::WARNING) << "Offline tracks not found: " << m_offline_types[it] << endmsg;
654 }
655 }
656
657 if ( !found_offline ) {
658 if (m_provider->evtStore()->template contains<Rec::TrackParticleContainer>("TrackParticleCandidate") ) {
660 this->template selectTracks<Rec::TrackParticleContainer>( pselectorRef, "TrackParticleCandidate" );
661 }
662 else {
663 m_provider->msg(MSG::WARNING) << "Offline tracks not found: " << "TrackParticleCandidate" << endmsg;
664 }
665 }
666
667 }
668
670
671 TrackAssociator* associator = m_associator->clone();
672
673 // std::cout << "\tloop() loop over chains proper ..." << std::endl;
674
676 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
677
679
680 // std::string& chainname = chains[ichain];
681 const std::string& chainname = m_chainNames[ichain].head();
682 const std::string& key = m_chainNames[ichain].tail();
683 const std::string& vtx_name = m_chainNames[ichain].vtx();
684
685 // Not used left just in case
686 // const std::string& roi_name = m_chainNames[ichain].roi();
687 // const std::string& te_name = m_chainNames[ichain].element();
688 m_pTthreshold = 0;
689
690 if ( m_chainNames[ichain].postcount() ) {
691 std::string ptvalue = m_chainNames[ichain].postvalue("pt");
692 if ( ptvalue!="" ) m_pTthreshold = std::stod(ptvalue);
693 }
694
695
696 unsigned decisiontype = TrigDefs::Physics;
697
698 if ( !m_chainNames[ichain].passed() ) decisiontype = TrigDefs::includeFailedDecisions;
699
701 // if ( decisiontype==TrigDefs::requireDecision ) std::cout << "\tSUTT TrigDefs::requireDecision " << decisiontype << std::endl;
702 // if ( decisiontype==TrigDefs::Physics ) std::cout << "\tSUTT TrigDefs::Physics " << decisiontype << std::endl;
703
704 if ( chainname!="" && m_provider->msg().level() <= MSG::VERBOSE ) {
705
706 m_provider->msg(MSG::VERBOSE) << "status for chain " << chainname
707 << "\tpass " << (*m_tdt)->isPassed(chainname)
708 << "\tprescale " << (*m_tdt)->getPrescale(chainname) << endmsg;
709
710 m_provider->msg(MSG::VERBOSE) << "fetching features for chain " << chainname << endmsg;
711
712 m_provider->msg(MSG::VERBOSE) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << endmsg;
713 }
714
716 // std::cout << "\tstatus for chain " << chainname
717 // << "\tpass " << (*m_tdt)->isPassed( chainname )
718 // << "\tpassdt " << (*m_tdt)->isPassed( chainname, decisiontype )
719 // << "\tprescale " << (*m_tdt)->getPrescale( chainname ) << std::endl;
720
721
722 // m_provider->msg(MSG::INFO) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << "\t" << m_chainNames[ichain] << "\trun " << run_number << "\tevent " << event_number << endmsg;
723
724
725 if ( chainname!="" && !this->m_keepAllEvents && !(*m_tdt)->isPassed( chainname, decisiontype ) ) continue;
726
729 // Trig::FeatureContainer f = (*m_tdt)->features( chainname, TrigDefs::alsoDeactivateTEs);
730
733
734 // tag and probe analysis processes multiple chains passed in the tag and probe tool at once so loop over vector of chains
735 std::vector<std::string> chainNames ;
736
737 if ( !m_tnp_flag ) {
738 chainNames.push_back(m_chainNames[ichain].raw()) ;
739 }
740 else {
741 chainNames.push_back(pTnP_tool->tag());
742 chainNames.push_back(pTnP_tool->probe());
743 }
744
745 // loop over new chainNames vector but doing the same stuff
746 for ( size_t i=0 ; i<chainNames.size() ; i++ ) {
747
748 ChainString chainConfig = chainNames[i] ;
749 std::string chainName = chainConfig.head();
750
751 eventp->addChain( chainNames[i] );
752
753 TIDA::Chain& chain = eventp->back();
754
755 if ( chainName == "" ) {
756
758
759 pselectorTest->clear();
760
762
763 // TIDARoiDescriptor roifs(true);
764
765 // chain.addRoi( roifs );
766
767 chain.addRoi( TIDARoiDescriptor(true) );
768
769 if ( m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>(key) ) {
770 this->template selectTracks<xAOD::TrackParticleContainer>( pselectorTest, key );
771 refbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( key );
772 }
773
774 const std::vector<TIDA::Track*>& testtracks = pselectorTest->tracks();
775
776 chain.back().addTracks(testtracks);
777
778 if ( vtx_name!="" ) {
779
781
782 m_provider->msg(MSG::VERBOSE) << "\tFetch xAOD::VertexContainer with key " << vtx_name << endmsg;
783
784 std::vector<TIDA::Vertex> tidavertices;
785
786 if ( this->select( tidavertices, vtx_name ) ) chain.back().addVertices( tidavertices );
787 }
788
789
790 // if ( roiInfo ) delete roiInfo;
791
792 }
793 else {
794
796
797 //std::string roi_key = m_chainNames[ichain].roi();
798
799 std::string roi_key = chainConfig.roi();
800
801 unsigned feature_type =TrigDefs::lastFeatureOfType;
802
803 if ( roi_key!="" ) feature_type= TrigDefs::allFeaturesOfType;
804
806
807 int leg = -1;
808
809 if ( chainConfig.element()!="" ) {
810 leg = std::atoi(chainConfig.element().c_str());
811 }
812
813 std::string rgex = roi_key;
814
815 std::vector< TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> > rois =
816 (*m_tdt)->template features<TrigRoiDescriptorCollection>( Trig::FeatureRequestDescriptor( chainName,
817 decisiontype,
818 rgex,
819 feature_type,
820 "roi",
821 leg ) );
822
825
826 if ( rois.empty() ) {
827 if ( !rgex.empty() ) {
828 rgex += "_probe";
829 rois = (*m_tdt)->template features<TrigRoiDescriptorCollection>( Trig::FeatureRequestDescriptor( chainName,
830 decisiontype,
831 rgex,
832 feature_type,
833 "roi",
834 leg ) );
835 }
836 }
837
838 int iroi = 0;
839
840 for ( const TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection>& roi_info : rois ) {
841
842 iroi++;
843
847
848 if ( roi_key=="SuperRoi" && iroi>1 ) continue;
849
850 // std::cout << "\troi: get link " << roi_key << " ..." << std::endl;
851
852 const ElementLink<TrigRoiDescriptorCollection> roi_link = roi_info.link;
853
855 if ( roi_key!="" && roi_link.dataID()!=rgex ) continue;
856
858 if ( !roi_link.isValid() ) continue;
859
860 const TrigRoiDescriptor* const* roiptr = roi_link.cptr();
861
862 if ( roiptr == 0 ) continue;
863
864
866 // std::cout << "\troi: link deref ..." << *roiptr << std::endl;
867
868 if (m_provider->msg().level() <= MSG::VERBOSE) {
869 m_provider->msg(MSG::VERBOSE) << " RoI descriptor for seeded chain " << chainname << " " << **roiptr << endmsg;
870 }
871
873
874 // if ( dbg ) std::cout << "\troi " << iroi << " " << *roiInfo << std::endl;
875
877
878 pselectorTest->clear();
879
880 if ( this->template selectTracks<xAOD::TrackParticleContainer>( pselectorTest, roi_link, key ) ) { }
881
882 // beamspot stuff not needed for xAOD::TrackParticles
883
885
886 chain.addRoi( *roiInfo );
887
889
890 const std::vector<TIDA::Track*>& testtracks = pselectorTest->tracks();
891
892 chain.back().addTracks(testtracks);
893
894
896
897 if ( vtx_name!="" ) {
898
899 std::vector<TIDA::Vertex> tidavertices;
900
901 this->select( tidavertices, roi_link, vtx_name );
902
903 chain.back().addVertices( tidavertices );
904
905 }
906
907
908#if 0
909 if ( dbg ) {
910 std::cout << "\tTIDA analysis for chain: " << chainname << "\t key: " << key << "\t" << **roiptr << std::endl;
911 std::cout << "\tcollections: " << chain.back() << std::endl;
912 }
913#endif
914
915 delete roiInfo;
916
917 }
918
919
920 }
921
922 } // end of loop chainNames vector loop
923
924
925 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
926 m_provider->msg(MSG::VERBOSE) << "event: " << *eventp << endmsg;
927 }
928
929 }
930
931 // close previous loop over chains and open new one
932
933 for ( unsigned ichain=0 ; ichain<eventp->size() ; ichain++ ) {
934
935 TIDA::Chain& chain = (*eventp)[ichain];
936 ChainString chainConfig(chain.name());
937 const std::string& vtx_name = chainConfig.vtx();
938
939 // skip tag chains to avoid performing standard analysis on them (done for tnp at the same time as probes)
940 if ( m_tnp_flag && chainConfig.extra().find("_tag")!=std::string::npos ) continue ;
941
942 std::vector<TIDA::Roi*> rois ;
943
944 if (m_tnp_flag) {
945 // needs to be done AFTER retrieving offline tracks as pselectorRef passed as arguement, hence restructuring
946 rois = pTnP_tool->GetRois( eventp->chains(), pselectorRef, &filterRef, m_invmass, m_invmass_obj );
947 }
948 else {
949 rois.reserve( chain.size() );
950 for ( size_t ir=0 ; ir<chain.size() ; ir++ ) {
951 rois.push_back( &(chain.rois()[ir]) );
952 }
953 }
954
955 // now loop over the rois (again)
956
957 for ( unsigned iroi=0 ; iroi<rois.size() ; iroi++ ) {
958
959 if ( this->filterOnRoi() ) {
960 filterRef.setRoi( &(rois.at(iroi)->roi() ) );
961 filterRef.containtracks( m_containTracks );
962 }
963 else filterRef.setRoi( 0 );
964
965 test_tracks.clear();
966
967 // this block is before the track retrieval in the original, is it working the same here?
968
982
983 if ( m_provider->msg().level() <= MSG::VERBOSE )
984 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
985
986 if ( m_mcTruth ) {
987 if ( this->filterOnRoi() ) filter_truth.setRoi( &(rois.at(iroi)->roi() ) );
988 ref_tracks = pselectorRef->tracks(&filter_truth);
989 }
990 else { // ie. if ( m_doOffline )
991 ref_tracks = pselectorRef->tracks(&filterRef) ;
992 }
993
994 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
995 m_provider->msg(MSG::VERBOSE) << "ref tracks.size() " << pselectorRef->tracks().size() << endmsg;
996 for ( int ii=pselectorRef->tracks().size() ; ii-- ; ) {
997 m_provider->msg(MSG::VERBOSE) << " ref track " << ii << " " << *pselectorRef->tracks()[ii] << endmsg;
998 }
999 }
1000
1001 test_tracks.clear();
1002
1003
1004 for ( unsigned itrk=0 ; itrk<rois.at(iroi)->tracks().size() ; itrk++ ) {
1005 test_tracks.push_back(&(rois.at(iroi)->tracks().at(itrk)));
1006 }
1007
1009 // std::cout << "sutt track multiplicities: offline " << offline_tracks.size() << "\ttest " << test_tracks.size() << std::endl;
1010
1012
1013 beamline[0] = pselectorTest->getBeamX();
1014 beamline[1] = pselectorTest->getBeamY();
1015 beamline[2] = pselectorTest->getBeamZ();
1016
1017 beamline[3] = vertices.size();
1018
1026 // m_manalysis->setvertices( vertices.size() ); /// what is this for ??? /// is this thread safe ???
1027
1030
1031 if ( m_runPurity ) {
1032
1033 if ( this->getUseHighestPT() ) HighestPTOnly( test_tracks );
1034
1035 if ( m_pTthreshold>0 ) FilterPT( test_tracks, m_pTthreshold );
1036
1038 m_NRois++;
1039 m_NRefTracks += test_tracks.size();
1040 m_NTestTracks += ref_tracks.size();
1041
1043 associator->match( test_tracks, ref_tracks );
1044
1045 m_manalysis->execute( test_tracks, ref_tracks, associator, eventp, beamline );
1046
1047 }
1048 else {
1049
1051 if ( this->getUseHighestPT() ) HighestPTOnly( ref_tracks );
1052
1054
1055 if ( m_pTthreshold>0 ) FilterPT( ref_tracks, m_pTthreshold );
1056
1059 // if ( ref_tracks.size()==0 ) continue;
1060
1062 m_NRois++;
1063 m_NRefTracks += ref_tracks.size();
1064 m_NTestTracks += test_tracks.size();
1065
1067 associator->match( ref_tracks, test_tracks );
1068
1073 // m_manalysis->setroi( &rois.at(iroi)->roi() );
1074 m_manalysis->execute( ref_tracks, test_tracks, associator, eventp, beamline, &(rois.at(iroi)->roi()) );
1075
1076 if ( vtx_name!="" ) {
1078 std::vector<TIDA::Vertex> vr = rois.at(iroi)->vertices();
1079 std::vector<TIDA::Vertex*> vtx_rec;
1080 for ( unsigned iv=0 ; iv<vr.size() ; iv++ ) vtx_rec.push_back( &vr[iv] );
1081
1082 std::vector<TIDA::Vertex*> vtx;
1083 if ( this->getVtxIndex()<0 ) {
1084 for ( unsigned iv=0 ; iv<vertices.size() ; iv++ ) vtx.push_back( &vertices[iv] );
1085 }
1086 else {
1087 if ( vertices.size()>unsigned(this->getVtxIndex()) ) vtx.push_back( &vertices[this->getVtxIndex()] );
1088 }
1089
1090 m_manalysis->execute_vtx( vtx, vtx_rec, eventp );
1091 }
1092
1093 }
1094
1095 if ( m_manalysis->debug() ) {
1096 m_provider->msg(MSG::INFO) << "Missing track for " << m_chainNames[ichain]
1097 << "\trun " << run_number
1098 << "\tevent " << event_number
1099 << "\tlb " << lumi_block << endmsg;
1100 }
1101
1102 }
1103
1104 }
1105
1106 delete associator;
1107
1108 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
1109 m_provider->msg(MSG::VERBOSE) << "\n\nEvent " << *eventp << endmsg;
1110 }
1111
1112 }
1113
1114
1115
1116 virtual void book() {
1117
1118 if(m_provider->msg().level() <= MSG::VERBOSE)
1119 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::book() " << name() << endmsg;
1120
1121 // get the TriggerDecisionTool
1122
1123 if( m_tdt->retrieve().isFailure() ) {
1124 if(m_provider->msg().level() <= MSG::ERROR)
1125 m_provider->msg(MSG::ERROR) << " Unable to retrieve the TrigDecisionTool: Please check job options file" << endmsg;
1126 return;
1127 }
1128
1129 if(m_provider->msg().level() <= MSG::VERBOSE) {
1130 m_provider->msg(MSG::VERBOSE) << " Successfully retrieved the TrigDecisionTool" << endmsg;
1131 }
1132
1133
1135 if (m_provider->msg().level() <= MSG::VERBOSE) {
1136 std::vector<std::string> configuredChains = (*(m_tdt))->getListOfTriggers("L2_.*, EF_.*, HLT_.*");
1137
1138 m_provider->msg(MSG::VERBOSE) << "Configured chains" << endmsg;
1139 for ( unsigned i=0 ; i<configuredChains.size() ; i++ ) {
1140 if( m_provider->msg().level() <= MSG::VERBOSE)
1141 m_provider->msg(MSG::VERBOSE) << " Chain " << configuredChains[i] << endmsg;
1142 }
1143 }
1144
1145
1146 for ( unsigned ic=0 ; ic<m_chainNames.size() ; ic++ ) {
1147
1148 if ( ic>0 ) {
1149 m_provider->msg(MSG::WARNING) << "more than one chain configured for this analysis - skipping " << m_chainNames[ic] << endmsg;
1150 continue;
1151 }
1152
1153 m_provider->msg(MSG::VERBOSE) << "Analyse chain " << m_chainNames[ic] << endmsg;
1154
1155 // m_provider->msg(MSG::VERBOSE) << "--------------------------------------------------" << endmsg;
1156
1157 std::string folder_name = "";
1158
1159 if ( name()!="" ) folder_name = name();
1160 else folder_name = "HLT/TRIDT/IDMon";
1161
1163 if( m_testType != "" ) folder_name = folder_name + "/" + m_testType;
1164
1165 std::string mongroup;
1166
1167#if 0
1170
1171 if ( name().find("Shifter")!=std::string::npos || m_shifter ) {
1173 if ( m_chainNames.at(ic).tail().find("_FTF") != std::string::npos ) mongroup = folder_name + "/FTF";
1174 else if ( m_chainNames.at(ic).tail().find("_IDTrig") != std::string::npos ||
1175 m_chainNames.at(ic).tail().find("_EFID") != std::string::npos ) mongroup = folder_name + "/EFID";
1176 else if ( m_chainNames.at(ic).tail().find("InDetTrigParticle") != std::string::npos ) mongroup = folder_name + "/EFID_RUN1";
1177 else if ( m_chainNames.at(ic).tail().find("_GSF") != std::string::npos ) mongroup = folder_name + "/GSF";
1178 else mongroup = folder_name + "/Unknown";
1179
1180 if ( m_chainNames.at(ic).vtx()!="" ) mongroup += "/" + m_chainNames.at(ic).vtx();
1181
1182 }
1183#endif
1184 // else {
1186
1187 if ( m_chainNames[ic].head() == "" ) mongroup = folder_name + "/Fullscan";
1188 else mongroup = folder_name + "/" + m_chainNames[ic].head();
1189
1190 std::string track_collection = "";
1191
1192 if ( m_chainNames.at(ic).tail()!="" ) {
1193 track_collection = "/" + m_chainNames.at(ic).tail();
1194 if ( m_chainNames.at(ic).extra()!="" ) track_collection += "_" + m_chainNames.at(ic).extra();
1195 }
1196
1197 if ( m_chainNames.at(ic).roi()!="" ) {
1198 if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].roi();
1199 else track_collection = "/" + m_chainNames[ic].roi();
1200 }
1201
1202 if ( m_chainNames.at(ic).vtx()!="" ) {
1203 if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].vtx();
1204 else track_collection = "/" + m_chainNames[ic].vtx();
1205 }
1206
1208 if ( m_chainNames.at(ic).element()!="" ) {
1209 if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].element();
1210 else track_collection = "/" + m_chainNames[ic].element();
1211 }
1212
1213 if ( track_collection!="" ) mongroup += track_collection;
1214
1215 if ( !m_chainNames.at(ic).passed() ) mongroup += "/DTE";
1216
1217 // }
1218
1219 m_provider->msg(MSG::VERBOSE) << " book mongroup " << mongroup << endmsg;
1220
1221 m_manalysis = dynamic_cast<A*>(m_analysis);
1222
1223 if ( monTool() ) m_manalysis->set_monTool( monTool() );
1224
1225 m_analysis->initialise();
1226
1227 if(m_provider->msg().level() <= MSG::VERBOSE) {
1228 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::book() done" << endmsg;
1229 }
1230 }
1231
1232 }
1233
1234
1235
1236 virtual void finalize() {
1237
1238 if(m_provider->msg().level() <= MSG::VERBOSE){
1239 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::finalise() " << m_provider->name() << endmsg;
1240 }
1241
1242 m_analysis->finalise();
1243
1244 m_provider->msg(MSG::INFO) << m_provider->name() << " " << m_chainNames[0] << " \tNRois processed: " << m_NRois << "\tRef tracks: " << m_NRefTracks << "\tTestTracks: " << m_NTestTracks << endmsg;
1245
1246 if(m_provider->msg().level() <= MSG::VERBOSE) {
1247 m_provider->msg(MSG::VERBOSE) << m_provider->name() << " finalised" << endmsg;
1248 }
1249 }
1250
1251
1252protected:
1253
1255
1256 std::vector<ChainString> m_chainNames;
1257 std::vector<A*> m_analyses;
1258 std::string m_testType;
1259
1267
1268 std::vector<std::string> m_offline_types;
1269 std::vector<std::string> m_types;
1270
1271 std::string m_outputFileName;
1272
1275
1280
1282
1284
1286
1288
1290
1292
1294
1295 ToolHandle<GenericMonitoringTool>* m_monTool;
1296
1299
1300};
1301
1302
1303
1304#endif // TrigInDetAnalysisExample_T_AnalysisConfigR3_Tier0_H
1305
#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
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 Ineterest geometry It has basically 8 parameters.
virtual void match(const std::vector< T * > &s1, const std::vector< S * > &s2)=0
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:44
void mu(double m)
Definition TIDAEvent.h:47
TIDA::Chain & back()
get the last chain from the vector
Definition TIDAEvent.h:89
void addVertex(const TIDA::Vertex &v)
Definition TIDAEvent.h:71
void bunch_crossing_id(unsigned b)
Definition TIDAEvent.h:46
void addChain(const std::string &chainname)
methods to add and access chains
Definition TIDAEvent.h:67
void event_number(unsigned long long e)
Definition TIDAEvent.h:43
void time_stamp(unsigned t)
Definition TIDAEvent.h:45
void run_number(unsigned r)
accessors
Definition TIDAEvent.h:42
const std::vector< TIDA::Chain > & chains() const
Definition TIDAEvent.h:76
void clear()
clear the event
Definition TIDAEvent.h:86
unsigned size() const
vertex multiplicity ?
Definition TIDAEvent.h:64
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:46
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
void tag(const std::string &chainName)
getters and setters
Definition TagNProbe.h:45
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
bool selectTrack(const TrigInDetTrack *track, const TrigInDetTrackTruthMap *truthMap=0)
neater code to make use of vector function also for a single ancestor pdgid, instead of the full code...
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:114
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
int signal_process_id(const GenEvent &e)
Definition GenEvent.h:636
GenEvent::particle_iterator begin(HepMC::GenEvent &e)
Definition GenEvent.h:621
GenEvent::particle_iterator end(HepMC::GenEvent &e)
Definition GenEvent.h:622
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