12#ifndef TrigInDetAnalysisUtils_T_AnalysisConfig_H
13#define TrigInDetAnalysisUtils_T_AnalysisConfig_H
20#include "GaudiKernel/IToolSvc.h"
21#include "GaudiKernel/ITHistSvc.h"
39#ifdef XAODTRACKING_TRACKPARTICLE_H
58template<
class Prov
ider>
70 const std::string& testChainName,
const std::string& testType,
const std::string& testKey,
71 const std::string& referenceChainName,
const std::string& referenceType,
const std::string& referenceKey,
72 const std::string& selectionChainName,
const std::string& selectionType,
const std::string& selectionKey,
101 std::vector<std::string> testChainNames; testChainNames.push_back(testChainName);
102 std::vector<std::string> referenceChainNames; referenceChainNames.push_back(referenceChainName);
103 std::vector<std::string> selectionChainNames; selectionChainNames.push_back(selectionChainName);
106 std::vector<std::string> testTypes; testTypes.push_back(testType);
107 std::vector<std::string> referenceTypes; referenceTypes.push_back(referenceType);
108 std::vector<std::string> selectionTypes; selectionTypes.push_back(selectionType);
111 std::vector<std::string> testKeys; testKeys.push_back(testKey);
112 std::vector<std::string> referenceKeys; referenceKeys.push_back(referenceKey);
113 std::vector<std::string> selectionKeys; selectionKeys.push_back(selectionKey);
114 m_keys.push_back(testKeys);
m_keys.push_back(referenceKeys);
m_keys.push_back(selectionKeys);
116 std::vector<TrackFilter*> testFilters; testFilters.push_back(testFilter);
117 std::vector<TrackFilter*> referenceFilters; referenceFilters.push_back(referenceFilter);
118 std::vector<TrackFilter*> selectionFilters; selectionFilters.push_back(selectionFilter);
130 const std::string& testChainName,
const std::string& testType,
const std::string& testKey,
131 const std::string& referenceChainName,
const std::string& referenceType,
const std::string& referenceKey,
160 std::vector<std::string> testChainNames; testChainNames.push_back(testChainName);
161 std::vector<std::string> referenceChainNames; referenceChainNames.push_back(referenceChainName);
162 std::vector<std::string> selectionChainNames; selectionChainNames.push_back(
"NONE");
165 std::vector<std::string> testTypes; testTypes.push_back(testType);
166 std::vector<std::string> referenceTypes; referenceTypes.push_back(referenceType);
167 std::vector<std::string> selectionTypes; selectionTypes.push_back(
"");
170 std::vector<std::string> testKeys; testKeys.push_back(testKey);
171 std::vector<std::string> referenceKeys; referenceKeys.push_back(referenceKey);
172 std::vector<std::string> selectionKeys; selectionKeys.push_back(
"");
173 m_keys.push_back(testKeys);
m_keys.push_back(referenceKeys);
m_keys.push_back(selectionKeys);
175 std::vector<TrackFilter*> testFilters; testFilters.push_back(testFilter);
176 std::vector<TrackFilter*> referenceFilters; referenceFilters.push_back(referenceFilter);
177 std::vector<TrackFilter*> selectionFilters;
199 void addTestChain(
const std::string& chainName,
const std::string&
type,
const std::string& key) {
216 virtual void initialize(Provider* p, ToolHandle<Trig::TrigDecisionTool>* tdt ) {
226 if ( !
m_provider ) std::cerr <<
"ERROR T_AnalysisConfig::execute() called without initialising" << std::endl;
297 template<
class Collection>
298 std::pair< typename Collection::const_iterator, typename Collection::const_iterator >
300 const std::string& key=
"" ) {
308 std::string key_collection = key;
309 std::string key_tename =
"";
310 size_t pos = key_collection.find(
"/");
311 if ( pos!=std::string::npos ) {
312 key_collection = key.substr( pos+1, key.size()-pos );
313 key_tename = key.substr( 0, pos );
316 std::pair<
typename Collection::const_iterator,
317 typename Collection::const_iterator > itrpair;
322 const std::string* keyStr =
m_provider->evtStore()->keyToString(roi_link.
key(), checkCLID);
323 m_provider->msg(MSG::DEBUG) <<
"Requesting range over (" << key <<
") associated to ROI from " << (keyStr ==
nullptr ?
"UNKNOWN" : *keyStr) <<
endmsg;
325 itrpair = (*m_tdt)->associateToEventView( handle, roi_link );
342 bool select( std::vector<TIDA::Vertex>& vertices,
348 for ( ; vtxitr!=vtx_end ; ++vtxitr ) {
349 if ( (*vtxitr)->vertexType()!=0 ) {
359 (*vtxitr)->nTrackParticles(),
361 (*vtxitr)->chiSquared(),
362 (*vtxitr)->numberDoF() ) );
371 bool select( std::vector<TIDA::Vertex>& vertices,
373 const std::string& key=
"" ) {
375 m_provider->msg(MSG::VERBOSE) <<
"\tFetch xAOD::VertexContainer for key: " << key <<
endmsg;
380 if ( vtx_itrpair.first == vtx_itrpair.second ) {
381 m_provider->msg(MSG::WARNING) <<
"\tNo xAOD::Vertex collection for key " << key <<
endmsg;
385 m_provider->msg(MSG::DEBUG) <<
"\txAOD::VertexContainer found with size " << (vtx_itrpair.second - vtx_itrpair.first)
386 <<
"\t:" << key <<
endmsg;
388 return select( vertices, vtx_itrpair.first, vtx_itrpair.second );
394 bool select( std::vector<TIDA::Vertex>& vertices,
const std::string& key=
"" ) {
400 if (
retrieve( xaodVtxCollection, key ).isFailure()) {
401 m_provider->msg(MSG::WARNING) <<
"xAOD vertex container not found with key " << key <<
endmsg;
405 if ( xaodVtxCollection!=0 ) {
407 m_provider->msg(MSG::VERBOSE) <<
"xAOD vertex container " << xaodVtxCollection->
size() <<
" entries" <<
endmsg;
409 return select( vertices, xaodVtxCollection->
begin(), xaodVtxCollection->
end() );
415 for ( ; vtxitr != xaodVtxCollection->
end(); vtxitr++ ) {
416 if ( (*vtxitr)->nTrackParticles()>0 && (*vtxitr)->vertexType()!=0 ) {
424 (*vtxitr)->nTrackParticles(),
426 (*vtxitr)->chiSquared(),
427 (*vtxitr)->numberDoF() ) );
440 template<
class Collection>
444 const std::string& key=
"" ) {
453 std::string key_collection = key;
454 std::string key_tename =
"";
455 size_t pos = key_collection.find(
"/");
456 if ( pos!=std::string::npos ) {
457 key_collection = key.substr( pos+1, key.size()-pos );
458 key_tename = key.substr( 0, pos );
461 std::pair<
typename Collection::const_iterator,
462 typename Collection::const_iterator > itrpair;
467 const std::string* keyStr =
m_provider->evtStore()->keyToString(roi_link.
key(), checkCLID);
468 m_provider->msg(MSG::DEBUG) <<
"Requesting range over (" << key <<
") associated to ROI from " << (keyStr ==
nullptr ?
"UNKNOWN" : *keyStr) <<
endmsg;
470 itrpair = (*m_tdt)->associateToEventView( handle, roi_link );
472 if ( itrpair.first != itrpair.second ) {
473 selector->selectTracks( itrpair.first, itrpair.second );
477 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
486 template<
class Collection>
491 std::string key_collection = key;
492 std::string key_tename =
"";
493 size_t pos = key_collection.find(
"/");
494 if ( pos!=std::string::npos ) {
495 key_collection = key.substr( pos+1, key.size()-pos );
496 key_tename = key.substr( 0, pos );
499 std::vector< Trig::Feature<Collection> > trackcollections = citr->get<Collection>( key_collection,
TrigDefs::alsoDeactivateTEs, key_tename );
500 if ( !trackcollections.empty() ) {
502 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
504 if ( !trackfeature.
empty() ) {
506 const Collection* trigtracks = trackfeature.
cptr();
507 selector->selectTracks( trigtracks );
513 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
522 template<
class Collection>
528 if ( !trackcollections.empty() ) {
536 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
544 std::vector< const Collection* > collectionVector;
545 if ( !
const_cast<HLT::NavigationCore *
>(nc)->getFeatures( te, collectionVector, key ) )
return false;
551 for (
unsigned iv=collectionVector.size() ; iv-- ; ) {
555 if (
index!=iv )
continue;
558 selector->selectTracks( collectionVector[iv], truthmap );
565 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty" <<
endmsg;
572 template<
class Collection>
573 StatusCode
retrieve( Collection
const*& collection,
const std::string& key=
"" ) {
578 if ( handle.isValid() ) {
581 collection = handle.cptr();
582 return StatusCode::SUCCESS;
585 return StatusCode::FAILURE;
590 template<
class Collection>
594 if ( handle.isValid() ) {
597 selector->selectTracks( handle.cptr() );
607 template<
class Collection>
609 const Collection* collection =
nullptr;
610 if ( key.empty() )
return false;
615 if ( !(
sc.isSuccess() && collection ) )
return false;
617 m_provider->msg(MSG::DEBUG) <<
"SG Collection->size() " << collection->size() <<
" (" << key <<
")" <<
endmsg;
620 if ( collection->size() == 0 ) {
625 selector->selectTracks( collection );
633 template<
class Collection>
635 const Collection* collection = 0;
636 std::vector<double> v;
641 if(
sc.isSuccess() && collection ) {
642 m_provider->msg(MSG::DEBUG) <<
"SG Collection->size() " << collection->size() <<
" (" << key <<
")" <<
endmsg;
644 typename Collection::const_iterator trackitr = collection->begin();
645 typename Collection::const_iterator trackend = collection->end();
646 if ( trackitr!=trackend ) {
648 v[0] = (*trackitr)->vx();
649 v[1] = (*trackitr)->vy();
650 v[2] = (*trackitr)->vz();
662 template<
class Collection>
665 std::vector<double> v;
666 if ( !trackcollections.empty() ) {
669 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
672 if ( !trackfeature.
empty() ) {
675 const Collection* trigtracks = trackfeature.
cptr();
677 typename Collection::const_iterator trackitr = trigtracks->begin();
678 typename Collection::const_iterator trackend = trigtracks->end();
679 if ( trackitr!=trackend ) {
681 v[0] = (*trackitr)->vx();
682 v[1] = (*trackitr)->vy();
683 v[2] = (*trackitr)->vz();
691 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
704 std::vector<TrackTrigObject>* elevec=0,
706 bool raw_track=
false,
708# ifdef XAODTRACKING_TRACKPARTICLE_H
709 const std::string& containerName =
"Electrons"
711 const std::string& containerName =
"ElectronAODCollection"
715 m_provider->msg(MSG::DEBUG) <<
"Fetching offline electrons: " << containerName <<
endmsg;
719# ifdef XAODTRACKING_TRACKPARTICLE_H
729 m_provider->msg(MSG::WARNING) <<
"Error No Electron Container " << containerName <<
" !" <<
endmsg;
733 StatusCode
sc =
retrieve( container, containerName);
734 if(
sc.isFailure() || !container ) {
735 m_provider->msg(MSG::WARNING) <<
"Error retrieving container: " << containerName <<
" !" <<
endmsg;
739 m_provider->msg(MSG::DEBUG) <<
"Event with " << container->size() <<
" Electron object(s) " <<
endmsg;
741 Container::const_iterator elec = container->begin();
742 Container::const_iterator elec_end = container->end();
744 for( ; elec!=elec_end ; ++elec ){
755 bool good_electron =
false;
756# ifdef XAODTRACKING_TRACKPARTICLE_H
764 long unsigned eleid = (
unsigned long)(&eleduff) ;
774 else trk_added = selectorRef.
selectTrack( (*elec)->trackParticle() );
776 if (trk_added) eleobj.
addChild( selectorRef.
tracks().back()->id() );
777 if (elevec) elevec->push_back( eleobj );
781 return selectorRef.
tracks().size();
791# ifdef XAODTRACKING_TRACKPARTICLE_H
792 const std::string& containerName =
"Muons"
794 const std::string& containerName =
"StacoMuonCollection"
798# ifdef XAODTRACKING_TRACKPARTICLE_H
804 m_provider->msg(MSG::DEBUG) <<
" Offline muons (" << containerName <<
")" <<
endmsg;
811 m_provider->msg(MSG::WARNING) <<
"Error No MuonCollection" << containerName <<
" !" <<
endmsg;
815 StatusCode
sc =
retrieve( container, containerName );
816 if(
sc.isFailure() || !container ) {
817 m_provider->msg(MSG::WARNING) <<
"Error retrieving " << containerName <<
" !" <<
endmsg;
821 auto muon = container->begin();
822 auto muon_end = container->end();
826 for( ; muon!=muon_end ; ++muon ){
827# ifdef XAODTRACKING_TRACKPARTICLE_H
836 m_provider->msg(MSG::DEBUG) <<
"found " << selectorRef.
tracks().size() <<
" muons for " << containerName <<
endmsg;
838 return selectorRef.
tracks().size();
847 std::vector<TrackTrigObject>* tauvec=0,
849 int requireNtracks=0,
850 double EtCutOffline=0,
851# ifdef XAODTRACKING_TRACKPARTICLE_H
852 const std::string& containerName =
"TauJets"
854 const std::string& containerName =
"TauRecContainer"
858# ifdef XAODTRACKING_TRACKPARTICLE_H
877 StatusCode
sc =
retrieve( container, containerName);
878 if (
sc != StatusCode::SUCCESS) {
879 m_provider->msg(MSG::WARNING) <<
" Offline tau retrieval not successful" <<
endmsg;
883 Container::const_iterator tau = container->begin();
884 Container::const_iterator tau_end = container->end();
887 for ( ; tau!=tau_end ; ++tau ) {
889# ifdef XAODTRACKING_TRACKPARTICLE_H
892# ifndef XAODTAU_VERSIONS_TAUJET_V3_H
893 int N = (*tau)->nTracks();
902 unsigned N = (*tau)->numTrack();
906 bool good_tau =
false;
907# ifdef XAODTRACKING_TRACKPARTICLE_H
917 long unsigned tauid = (
unsigned long)(&duff) ;
925 bool trk_added =
false;
927 for (
unsigned i=N ; i-- ; ) {
928# ifdef XAODTAU_TAUTRACK_H
930 std::vector< ElementLink<xAOD::TrackParticleContainer> > alink = (*tau)->track(i)->trackLinks();
934 for (
size_t ilink=0 ; ilink<alink.size() ; ilink++ ) {
941 trk_added = selectorRef.
selectTrack((*tau)->track(i));
943 if ( trk_added ) tauobj.
addChild( selectorRef.
tracks().back()->id() );
945 if ( tauvec ) tauvec->push_back( tauobj );
949 return selectorRef.
tracks().size();
959 ToolHandle<Trig::TrigDecisionTool>*
m_tdt;
969 std::vector< std::vector<std::string> >
m_types;
970 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
definition of StoreGate container holding a vector of Analysis::Muon
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.
Class to define the ElectronContainer.
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
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)
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="ElectronAODCollection")
select offline electrons
const std::string referenceChains() const
void setRequireDecision(bool b)
std::vector< std::vector< std::string > > m_chainNames
TrackAnalysis * m_analysis
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
bool selectTracks(TrigTrackSelector *selector, Trig::FeatureContainer::combination_const_iterator citr, const TrigInDetTrackTruthMap *truthmap, const std::string &key="", unsigned index=0)
NB: because we want to use this for the L2Star chains, we have to use this method,...
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
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
unsigned processTaus(TrigTrackSelector &selectorRef, std::vector< TrackTrigObject > *tauvec=0, const unsigned selection=0, int requireNtracks=0, double EtCutOffline=0, const std::string &containerName="TauRecContainer")
select offline taus
unsigned processMuons(TrigTrackSelector &selectorRef, const unsigned int selection=0, double ETOffline=0, const std::string &containerName="StacoMuonCollection")
select offlinqe muons
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)
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(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...
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 Analysis::Electron &elec)
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".