12#ifndef TrigInDetAnalysisUtils_T_AnalysisConfig_H
13#define TrigInDetAnalysisUtils_T_AnalysisConfig_H
20#include "GaudiKernel/IToolSvc.h"
21#include "GaudiKernel/ITHistSvc.h"
47template<
class Prov
ider>
59 const std::string& testChainName,
const std::string& testType,
const std::string& testKey,
60 const std::string& referenceChainName,
const std::string& referenceType,
const std::string& referenceKey,
61 const std::string& selectionChainName,
const std::string& selectionType,
const std::string& selectionKey,
68 m_chainNames { {testChainName}, {referenceChainName}, {selectionChainName} },
69 m_types { {testType}, {referenceType}, {selectionType} },
70 m_keys { {testKey}, {referenceKey}, {selectionKey} },
71 m_filters { {testFilter}, {referenceFilter}, {selectionFilter} },
72 m_refChainName(referenceChainName),
73 m_refChainKey(referenceKey),
74 m_testChainName(testChainName),
75 m_testChainKey(testKey),
79 m_associator(associator),
87 m_keepAllEvents(
false),
88 m_useHighestPT(
false),
91 m_requireDecision(
false) {
103 const std::string& testChainName,
const std::string& testType,
const std::string& testKey,
104 const std::string& referenceChainName,
const std::string& referenceType,
const std::string& referenceKey,
111 m_chainNames { {testChainName}, {referenceChainName}, {
"NONE"} },
112 m_types { {testType}, {referenceType}, {
""} },
113 m_keys { {testKey}, {referenceKey}, {
""} },
114 m_filters { {testFilter}, {referenceFilter}, {} },
115 m_refChainName(referenceChainName),
116 m_refChainKey(referenceKey),
117 m_testChainName(testChainName),
118 m_testChainKey(testKey),
122 m_associator(associator),
123 m_analysis(analysis),
130 m_keepAllEvents(
false),
131 m_useHighestPT(
false),
134 m_requireDecision(
false){
153 void addTestChain(
const std::string& chainName,
const std::string&
type,
const std::string& key) {
170 virtual void initialize(Provider* p, ToolHandle<Trig::TrigDecisionTool>* tdt ) {
180 if ( !
m_provider ) std::cerr <<
"ERROR T_AnalysisConfig::execute() called without initialising" << std::endl;
251 template<
class Collection>
252 std::pair< typename Collection::const_iterator, typename Collection::const_iterator >
254 const std::string& key=
"" ) {
262 std::string key_collection = key;
263 std::string key_tename =
"";
264 size_t pos = key_collection.find(
"/");
265 if ( pos!=std::string::npos ) {
266 key_collection = key.substr( pos+1, key.size()-pos );
267 key_tename = key.substr( 0, pos );
270 std::pair<
typename Collection::const_iterator,
271 typename Collection::const_iterator > itrpair;
276 const std::string* keyStr =
m_provider->evtStore()->keyToString(roi_link.
key(), checkCLID);
277 m_provider->msg(MSG::DEBUG) <<
"Requesting range over (" << key <<
") associated to ROI from " << (keyStr ==
nullptr ?
"UNKNOWN" : *keyStr) <<
endmsg;
279 itrpair = (*m_tdt)->associateToEventView( handle, roi_link );
296 bool select( std::vector<TIDA::Vertex>& vertices,
302 for ( ; vtxitr!=vtx_end ; ++vtxitr ) {
303 if ( (*vtxitr)->vertexType()!=0 ) {
313 (*vtxitr)->nTrackParticles(),
315 (*vtxitr)->chiSquared(),
316 (*vtxitr)->numberDoF() ) );
325 bool select( std::vector<TIDA::Vertex>& vertices,
327 const std::string& key=
"" ) {
329 m_provider->msg(MSG::VERBOSE) <<
"\tFetch xAOD::VertexContainer for key: " << key <<
endmsg;
334 if ( vtx_itrpair.first == vtx_itrpair.second ) {
335 m_provider->msg(MSG::WARNING) <<
"\tNo xAOD::Vertex collection for key " << key <<
endmsg;
339 m_provider->msg(MSG::DEBUG) <<
"\txAOD::VertexContainer found with size " << (vtx_itrpair.second - vtx_itrpair.first)
340 <<
"\t:" << key <<
endmsg;
342 return select( vertices, vtx_itrpair.first, vtx_itrpair.second );
348 bool select( std::vector<TIDA::Vertex>& vertices,
const std::string& key=
"" ) {
354 if (
retrieve( xaodVtxCollection, key ).isFailure()) {
355 m_provider->msg(MSG::WARNING) <<
"xAOD vertex container not found with key " << key <<
endmsg;
359 if ( xaodVtxCollection!=0 ) {
361 m_provider->msg(MSG::VERBOSE) <<
"xAOD vertex container " << xaodVtxCollection->
size() <<
" entries" <<
endmsg;
363 return select( vertices, xaodVtxCollection->
begin(), xaodVtxCollection->
end() );
369 for ( ; vtxitr != xaodVtxCollection->
end(); vtxitr++ ) {
370 if ( (*vtxitr)->nTrackParticles()>0 && (*vtxitr)->vertexType()!=0 ) {
378 (*vtxitr)->nTrackParticles(),
380 (*vtxitr)->chiSquared(),
381 (*vtxitr)->numberDoF() ) );
394 template<
class Collection>
398 const std::string& key=
"" ) {
407 std::string key_collection = key;
408 std::string key_tename =
"";
409 size_t pos = key_collection.find(
"/");
410 if ( pos!=std::string::npos ) {
411 key_collection = key.substr( pos+1, key.size()-pos );
412 key_tename = key.substr( 0, pos );
415 std::pair<
typename Collection::const_iterator,
416 typename Collection::const_iterator > itrpair;
421 const std::string* keyStr =
m_provider->evtStore()->keyToString(roi_link.
key(), checkCLID);
422 m_provider->msg(MSG::DEBUG) <<
"Requesting range over (" << key <<
") associated to ROI from " << (keyStr ==
nullptr ?
"UNKNOWN" : *keyStr) <<
endmsg;
424 itrpair = (*m_tdt)->associateToEventView( handle, roi_link );
426 if ( itrpair.first != itrpair.second ) {
427 selector->selectTracks( itrpair.first, itrpair.second );
431 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
440 template<
class Collection>
444 std::string key_collection = key;
445 std::string key_tename =
"";
446 size_t pos = key_collection.find(
"/");
447 if ( pos!=std::string::npos ) {
448 key_collection = key.substr( pos+1, key.size()-pos );
449 key_tename = key.substr( 0, pos );
452 std::vector< Trig::Feature<Collection> > trackcollections = citr->get<Collection>( key_collection,
TrigDefs::alsoDeactivateTEs, key_tename );
453 if ( !trackcollections.empty() ) {
455 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
457 if ( !trackfeature.
empty() ) {
459 const Collection* trigtracks = trackfeature.
cptr();
460 selector->selectTracks( trigtracks );
466 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
473 template<
class Collection>
479 if ( !trackcollections.empty() ) {
487 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
495 std::vector< const Collection* > collectionVector;
496 if ( !
const_cast<HLT::NavigationCore *
>(nc)->getFeatures( te, collectionVector, key ) )
return false;
502 for (
unsigned iv=collectionVector.size() ; iv-- ; ) {
506 if (
index!=iv )
continue;
509 selector->selectTracks( collectionVector[iv] );
516 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty" <<
endmsg;
523 template<
class Collection>
524 StatusCode
retrieve( Collection
const*& collection,
const std::string& key=
"" ) {
529 if ( handle.isValid() ) {
532 collection = handle.cptr();
533 return StatusCode::SUCCESS;
536 return StatusCode::FAILURE;
541 template<
class Collection>
545 if ( handle.isValid() ) {
548 selector->selectTracks( handle.cptr() );
558 template<
class Collection>
560 const Collection* collection =
nullptr;
561 if ( key.empty() )
return false;
566 if ( !(
sc.isSuccess() && collection ) )
return false;
568 m_provider->msg(MSG::DEBUG) <<
"SG Collection->size() " << collection->size() <<
" (" << key <<
")" <<
endmsg;
571 if ( collection->size() == 0 ) {
576 selector->selectTracks( collection );
584 template<
class Collection>
586 const Collection* collection = 0;
587 std::vector<double> v;
592 if(
sc.isSuccess() && collection ) {
593 m_provider->msg(MSG::DEBUG) <<
"SG Collection->size() " << collection->size() <<
" (" << key <<
")" <<
endmsg;
595 typename Collection::const_iterator trackitr = collection->begin();
596 typename Collection::const_iterator trackend = collection->end();
597 if ( trackitr!=trackend ) {
599 v[0] = (*trackitr)->vx();
600 v[1] = (*trackitr)->vy();
601 v[2] = (*trackitr)->vz();
613 template<
class Collection>
616 std::vector<double> v;
617 if ( !trackcollections.empty() ) {
620 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
623 if ( !trackfeature.
empty() ) {
626 const Collection* trigtracks = trackfeature.
cptr();
628 typename Collection::const_iterator trackitr = trigtracks->begin();
629 typename Collection::const_iterator trackend = trigtracks->end();
630 if ( trackitr!=trackend ) {
632 v[0] = (*trackitr)->vx();
633 v[1] = (*trackitr)->vy();
634 v[2] = (*trackitr)->vz();
642 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
655 std::vector<TrackTrigObject>* elevec=0,
657 bool raw_track=
false,
659 const std::string& containerName =
"Electrons"
662 m_provider->msg(MSG::DEBUG) <<
"Fetching offline electrons: " << containerName <<
endmsg;
671 m_provider->msg(MSG::WARNING) <<
"Error No Electron Container " << containerName <<
" !" <<
endmsg;
675 StatusCode
sc =
retrieve( container, containerName);
676 if(
sc.isFailure() || !container ) {
677 m_provider->msg(MSG::WARNING) <<
"Error retrieving container: " << containerName <<
" !" <<
endmsg;
681 m_provider->msg(MSG::DEBUG) <<
"Event with " << container->size() <<
" Electron object(s) " <<
endmsg;
683 Container::const_iterator elec = container->begin();
684 Container::const_iterator elec_end = container->end();
686 for( ; elec!=elec_end ; ++elec ){
697 bool good_electron =
false;
702 long unsigned eleid = (
unsigned long)(&eleduff) ;
712 else trk_added = selectorRef.
selectTrack( (*elec)->trackParticle() );
714 if (trk_added) eleobj.
addChild( selectorRef.
tracks().back()->id() );
715 if (elevec) elevec->push_back( eleobj );
719 return selectorRef.
tracks().size();
729 const std::string& containerName =
"Muons"
734 m_provider->msg(MSG::DEBUG) <<
" Offline muons (" << containerName <<
")" <<
endmsg;
741 m_provider->msg(MSG::WARNING) <<
"Error No MuonCollection" << containerName <<
" !" <<
endmsg;
745 StatusCode
sc =
retrieve( container, containerName );
746 if(
sc.isFailure() || !container ) {
747 m_provider->msg(MSG::WARNING) <<
"Error retrieving " << containerName <<
" !" <<
endmsg;
751 auto muon = container->begin();
752 auto muon_end = container->end();
756 for( ; muon!=muon_end ; ++muon ){
762 m_provider->msg(MSG::DEBUG) <<
"found " << selectorRef.
tracks().size() <<
" muons for " << containerName <<
endmsg;
764 return selectorRef.
tracks().size();
773 std::vector<TrackTrigObject>* tauvec=0,
775 int requireNtracks=0,
776 double EtCutOffline=0,
777 const std::string& containerName =
"TauJets"
795 StatusCode
sc =
retrieve( container, containerName);
796 if (
sc != StatusCode::SUCCESS) {
797 m_provider->msg(MSG::WARNING) <<
" Offline tau retrieval not successful" <<
endmsg;
801 Container::const_iterator tau = container->begin();
802 Container::const_iterator tau_end = container->end();
805 for ( ; tau!=tau_end ; ++tau ) {
807# ifndef XAODTAU_VERSIONS_TAUJET_V3_H
808 int N = (*tau)->nTracks();
816 bool good_tau =
false;
823 long unsigned tauid = (
unsigned long)(&duff) ;
831 bool trk_added =
false;
833 for (
unsigned i=N ; i-- ; ) {
835 std::vector< ElementLink<xAOD::TrackParticleContainer> > alink = (*tau)->track(i)->trackLinks();
839 for (
size_t ilink=0 ; ilink<alink.size() ; ilink++ ) {
845 if ( trk_added ) tauobj.
addChild( selectorRef.
tracks().back()->id() );
847 if ( tauvec ) tauvec->push_back( tauobj );
851 return selectorRef.
tracks().size();
861 ToolHandle<Trig::TrigDecisionTool>*
m_tdt;
871 std::vector< std::vector<std::string> >
m_types;
872 std::vector< std::vector<std::string> >
m_keys;
bool isValid() const
Test to see if the link can be dereferenced.
uint32_t CLID
The Class ID type.
TIDA::Associator< TIDA::Track > TrackAssociator
base class for a single track selection filter allowing parameter setting for complex track selection
DataModel_detail::const_iterator< DataVector > const_iterator
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.
ElementLink implementation for ROOT usage.
sgkey_t key() const
Get the key that we reference, as a hash.
The NavigationCore class, adds on top of the TrigNavStructure the EDM read-only handling.
TriggerElement is the basic ingreedient of the interface between HLT algorithms and the navigation It...
storage of the time histories of all the cells
unsigned processMuons(TrigTrackSelector &selectorRef, const unsigned int selection=0, double ETOffline=0, const std::string &containerName="Muons")
select offlinqe muons
std::pair< typename Collection::const_iterator, typename Collection::const_iterator > getCollection(const ElementLink< TrigRoiDescriptorCollection > &roi_link, const std::string &key="")
new MT feature access
const TrackAnalysis * analysis() const
bool setFilterOnRoi(bool b)
const std::string referenceChains() const
void setRequireDecision(bool b)
std::vector< std::vector< std::string > > m_chainNames
TrackAnalysis * m_analysis
unsigned processElectrons(TrigTrackSelector &selectorRef, std::vector< TrackTrigObject > *elevec=0, const unsigned int selection=0, bool raw_track=false, double ETOffline=0, const std::string &containerName="Electrons")
select offline electrons
bool select(std::vector< TIDA::Vertex > &vertices, const std::string &key="")
bool requireDecision() const
const std::string & name() const
void addSelectionChain(const std::string &chainName, const std::string &type, const std::string &key)
bool select(std::vector< TIDA::Vertex > &vertices, const ElementLink< TrigRoiDescriptorCollection > &roi_link, const std::string &key="")
void addTestChain(const std::string &chainName, const std::string &type, const std::string &key)
std::vector< std::vector< std::string > > m_types
bool getUseHighestPT() const
std::string m_releaseData
TrigTrackSelector * m_selectorTest
TrigTrackSelector * m_selectorSel
std::string m_analysisInstanceName
bool selectTracks(TrigTrackSelector *selector, const ElementLink< TrigRoiDescriptorCollection > &roi_link, const std::string &key="")
std::string m_testChainKey
bool selectTracks(TrigTrackSelector *selector, const std::string &key)
std::vector< std::vector< TrackFilter * > > m_filters
unsigned processTaus(TrigTrackSelector &selectorRef, std::vector< TrackTrigObject > *tauvec=0, const unsigned selection=0, int requireNtracks=0, double EtCutOffline=0, const std::string &containerName="TauJets")
select offline taus
void setGenericFlag(bool b)
void keepAllEvents(bool b)
void addReferenceFilter(TrackFilter *filter)
bool selectTracks(TrigTrackSelector *selector, Trig::FeatureContainer::combination_const_iterator citr, const std::string &key="")
lagacy run 2 access
void addReferenceChain(const std::string &chainName, const std::string &type, const std::string &key)
void setUseHighestPT(bool b)
void addTestFilter(TrackFilter *filter)
std::string m_testChainName
void releaseData(const std::string &s)
TrigTrackSelector * m_selectorRef
virtual void initialize(Provider *p, ToolHandle< Trig::TrigDecisionTool > *tdt)
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, TrackFilter *testFilter, TrackFilter *referenceFilter, TrackAssociator *associator, TrackAnalysis *analysis)
const std::string selectionChains() const
StatusCode retrieve(Collection const *&collection, const std::string &key="")
std::string m_refChainName
std::vector< double > getBeamspot(Trig::FeatureContainer::combination_const_iterator citr, const std::string &key="")
std::vector< double > getBeamspot(const std::string &key)
void setMCTruth(bool b=true)
ToolHandle< Trig::TrigDecisionTool > * m_tdt
std::string m_refChainKey
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)
const std::string testChains() const
void addSelectionFilter(TrackFilter *filter)
bool selectTracksNotEmpty(TrigTrackSelector *selector, const std::string &key)
bool selectTracks(TrigTrackSelector *selector, Trig::FeatureContainer::combination_const_iterator citr, const std::string &key, unsigned index)
NB: because we want to use this for the L2Star chains, we have to use this method,...
virtual ~T_AnalysisConfig()
TrackAssociator * m_associator
bool select(std::vector< TIDA::Vertex > &vertices, xAOD::VertexContainer::const_iterator vtx_start, xAOD::VertexContainer::const_iterator vtx_end)
const std::string & releaseData() const
std::vector< std::vector< std::string > > m_keys
const std::vector< TIDA::Track * > & tracks() const
void addChild(unsigned long id)
bool selectTrack(HepMC::ConstGenParticlePtr track)
virtual void clear() override
std::vector< Combination >::const_iterator combination_const_iterator
is basic vehicle of object access in TDT
const T * cptr() const
explicit conversion to object
const HLT::TriggerElement * te() const
explicit conversion to TriggerElement
bool empty() const
test method to check if the object is truly there
Class describing a tau jet.
const std::string selection
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
bool isGoodOffline(const xAOD::Electron &elec, const unsigned int selection=0, double ETOffline=0)
static const unsigned int alsoDeactivateTEs
@ z
global position (cartesian)
const xAOD::TrackParticle * getOriginalTrackParticle(const xAOD::Electron *el)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the electron.
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".