12#ifndef TrigInDetAnalysisUtils_T_AnalysisConfig_H
13#define TrigInDetAnalysisUtils_T_AnalysisConfig_H
20#include "GaudiKernel/IToolSvc.h"
21#include "GaudiKernel/ITHistSvc.h"
38#ifdef XAODTRACKING_TRACKPARTICLE_H
56template<
class Prov
ider>
68 const std::string& testChainName,
const std::string& testType,
const std::string& testKey,
69 const std::string& referenceChainName,
const std::string& referenceType,
const std::string& referenceKey,
70 const std::string& selectionChainName,
const std::string& selectionType,
const std::string& selectionKey,
99 std::vector<std::string> testChainNames; testChainNames.push_back(testChainName);
100 std::vector<std::string> referenceChainNames; referenceChainNames.push_back(referenceChainName);
101 std::vector<std::string> selectionChainNames; selectionChainNames.push_back(selectionChainName);
104 std::vector<std::string> testTypes; testTypes.push_back(testType);
105 std::vector<std::string> referenceTypes; referenceTypes.push_back(referenceType);
106 std::vector<std::string> selectionTypes; selectionTypes.push_back(selectionType);
109 std::vector<std::string> testKeys; testKeys.push_back(testKey);
110 std::vector<std::string> referenceKeys; referenceKeys.push_back(referenceKey);
111 std::vector<std::string> selectionKeys; selectionKeys.push_back(selectionKey);
112 m_keys.push_back(testKeys);
m_keys.push_back(referenceKeys);
m_keys.push_back(selectionKeys);
114 std::vector<TrackFilter*> testFilters; testFilters.push_back(testFilter);
115 std::vector<TrackFilter*> referenceFilters; referenceFilters.push_back(referenceFilter);
116 std::vector<TrackFilter*> selectionFilters; selectionFilters.push_back(selectionFilter);
128 const std::string& testChainName,
const std::string& testType,
const std::string& testKey,
129 const std::string& referenceChainName,
const std::string& referenceType,
const std::string& referenceKey,
158 std::vector<std::string> testChainNames; testChainNames.push_back(testChainName);
159 std::vector<std::string> referenceChainNames; referenceChainNames.push_back(referenceChainName);
160 std::vector<std::string> selectionChainNames; selectionChainNames.push_back(
"NONE");
163 std::vector<std::string> testTypes; testTypes.push_back(testType);
164 std::vector<std::string> referenceTypes; referenceTypes.push_back(referenceType);
165 std::vector<std::string> selectionTypes; selectionTypes.push_back(
"");
168 std::vector<std::string> testKeys; testKeys.push_back(testKey);
169 std::vector<std::string> referenceKeys; referenceKeys.push_back(referenceKey);
170 std::vector<std::string> selectionKeys; selectionKeys.push_back(
"");
171 m_keys.push_back(testKeys);
m_keys.push_back(referenceKeys);
m_keys.push_back(selectionKeys);
173 std::vector<TrackFilter*> testFilters; testFilters.push_back(testFilter);
174 std::vector<TrackFilter*> referenceFilters; referenceFilters.push_back(referenceFilter);
175 std::vector<TrackFilter*> selectionFilters;
197 void addTestChain(
const std::string& chainName,
const std::string&
type,
const std::string& key) {
214 virtual void initialize(Provider* p, ToolHandle<Trig::TrigDecisionTool>* tdt ) {
224 if ( !
m_provider ) std::cerr <<
"ERROR T_AnalysisConfig::execute() called without initialising" << std::endl;
295 template<
class Collection>
296 std::pair< typename Collection::const_iterator, typename Collection::const_iterator >
298 const std::string& key=
"" ) {
306 std::string key_collection = key;
307 std::string key_tename =
"";
308 size_t pos = key_collection.find(
"/");
309 if ( pos!=std::string::npos ) {
310 key_collection = key.substr( pos+1, key.size()-pos );
311 key_tename = key.substr( 0, pos );
314 std::pair<
typename Collection::const_iterator,
315 typename Collection::const_iterator > itrpair;
320 const std::string* keyStr =
m_provider->evtStore()->keyToString(roi_link.
key(), checkCLID);
321 m_provider->msg(MSG::DEBUG) <<
"Requesting range over (" << key <<
") associated to ROI from " << (keyStr ==
nullptr ?
"UNKNOWN" : *keyStr) <<
endmsg;
323 itrpair = (*m_tdt)->associateToEventView( handle, roi_link );
340 bool select( std::vector<TIDA::Vertex>& vertices,
346 for ( ; vtxitr!=vtx_end ; ++vtxitr ) {
347 if ( (*vtxitr)->vertexType()!=0 ) {
357 (*vtxitr)->nTrackParticles(),
359 (*vtxitr)->chiSquared(),
360 (*vtxitr)->numberDoF() ) );
369 bool select( std::vector<TIDA::Vertex>& vertices,
371 const std::string& key=
"" ) {
373 m_provider->msg(MSG::VERBOSE) <<
"\tFetch xAOD::VertexContainer for key: " << key <<
endmsg;
378 if ( vtx_itrpair.first == vtx_itrpair.second ) {
379 m_provider->msg(MSG::WARNING) <<
"\tNo xAOD::Vertex collection for key " << key <<
endmsg;
383 m_provider->msg(MSG::DEBUG) <<
"\txAOD::VertexContainer found with size " << (vtx_itrpair.second - vtx_itrpair.first)
384 <<
"\t:" << key <<
endmsg;
386 return select( vertices, vtx_itrpair.first, vtx_itrpair.second );
392 bool select( std::vector<TIDA::Vertex>& vertices,
const std::string& key=
"" ) {
398 if (
retrieve( xaodVtxCollection, key ).isFailure()) {
399 m_provider->msg(MSG::WARNING) <<
"xAOD vertex container not found with key " << key <<
endmsg;
403 if ( xaodVtxCollection!=0 ) {
405 m_provider->msg(MSG::VERBOSE) <<
"xAOD vertex container " << xaodVtxCollection->
size() <<
" entries" <<
endmsg;
407 return select( vertices, xaodVtxCollection->
begin(), xaodVtxCollection->
end() );
413 for ( ; vtxitr != xaodVtxCollection->
end(); vtxitr++ ) {
414 if ( (*vtxitr)->nTrackParticles()>0 && (*vtxitr)->vertexType()!=0 ) {
422 (*vtxitr)->nTrackParticles(),
424 (*vtxitr)->chiSquared(),
425 (*vtxitr)->numberDoF() ) );
438 template<
class Collection>
442 const std::string& key=
"" ) {
451 std::string key_collection = key;
452 std::string key_tename =
"";
453 size_t pos = key_collection.find(
"/");
454 if ( pos!=std::string::npos ) {
455 key_collection = key.substr( pos+1, key.size()-pos );
456 key_tename = key.substr( 0, pos );
459 std::pair<
typename Collection::const_iterator,
460 typename Collection::const_iterator > itrpair;
465 const std::string* keyStr =
m_provider->evtStore()->keyToString(roi_link.
key(), checkCLID);
466 m_provider->msg(MSG::DEBUG) <<
"Requesting range over (" << key <<
") associated to ROI from " << (keyStr ==
nullptr ?
"UNKNOWN" : *keyStr) <<
endmsg;
468 itrpair = (*m_tdt)->associateToEventView( handle, roi_link );
470 if ( itrpair.first != itrpair.second ) {
471 selector->selectTracks( itrpair.first, itrpair.second );
475 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
484 template<
class Collection>
488 std::string key_collection = key;
489 std::string key_tename =
"";
490 size_t pos = key_collection.find(
"/");
491 if ( pos!=std::string::npos ) {
492 key_collection = key.substr( pos+1, key.size()-pos );
493 key_tename = key.substr( 0, pos );
496 std::vector< Trig::Feature<Collection> > trackcollections = citr->get<Collection>( key_collection,
TrigDefs::alsoDeactivateTEs, key_tename );
497 if ( !trackcollections.empty() ) {
499 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
501 if ( !trackfeature.
empty() ) {
503 const Collection* trigtracks = trackfeature.
cptr();
504 selector->selectTracks( trigtracks );
510 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
517 template<
class Collection>
523 if ( !trackcollections.empty() ) {
531 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
539 std::vector< const Collection* > collectionVector;
540 if ( !
const_cast<HLT::NavigationCore *
>(nc)->getFeatures( te, collectionVector, key ) )
return false;
546 for (
unsigned iv=collectionVector.size() ; iv-- ; ) {
550 if (
index!=iv )
continue;
553 selector->selectTracks( collectionVector[iv] );
560 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty" <<
endmsg;
567 template<
class Collection>
568 StatusCode
retrieve( Collection
const*& collection,
const std::string& key=
"" ) {
573 if ( handle.isValid() ) {
576 collection = handle.cptr();
577 return StatusCode::SUCCESS;
580 return StatusCode::FAILURE;
585 template<
class Collection>
589 if ( handle.isValid() ) {
592 selector->selectTracks( handle.cptr() );
602 template<
class Collection>
604 const Collection* collection =
nullptr;
605 if ( key.empty() )
return false;
610 if ( !(
sc.isSuccess() && collection ) )
return false;
612 m_provider->msg(MSG::DEBUG) <<
"SG Collection->size() " << collection->size() <<
" (" << key <<
")" <<
endmsg;
615 if ( collection->size() == 0 ) {
620 selector->selectTracks( collection );
628 template<
class Collection>
630 const Collection* collection = 0;
631 std::vector<double> v;
636 if(
sc.isSuccess() && collection ) {
637 m_provider->msg(MSG::DEBUG) <<
"SG Collection->size() " << collection->size() <<
" (" << key <<
")" <<
endmsg;
639 typename Collection::const_iterator trackitr = collection->begin();
640 typename Collection::const_iterator trackend = collection->end();
641 if ( trackitr!=trackend ) {
643 v[0] = (*trackitr)->vx();
644 v[1] = (*trackitr)->vy();
645 v[2] = (*trackitr)->vz();
657 template<
class Collection>
660 std::vector<double> v;
661 if ( !trackcollections.empty() ) {
664 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
667 if ( !trackfeature.
empty() ) {
670 const Collection* trigtracks = trackfeature.
cptr();
672 typename Collection::const_iterator trackitr = trigtracks->begin();
673 typename Collection::const_iterator trackend = trigtracks->end();
674 if ( trackitr!=trackend ) {
676 v[0] = (*trackitr)->vx();
677 v[1] = (*trackitr)->vy();
678 v[2] = (*trackitr)->vz();
686 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
699 std::vector<TrackTrigObject>* elevec=0,
701 bool raw_track=
false,
703# ifdef XAODTRACKING_TRACKPARTICLE_H
704 const std::string& containerName =
"Electrons"
706 const std::string& containerName =
"ElectronAODCollection"
710 m_provider->msg(MSG::DEBUG) <<
"Fetching offline electrons: " << containerName <<
endmsg;
714# ifdef XAODTRACKING_TRACKPARTICLE_H
724 m_provider->msg(MSG::WARNING) <<
"Error No Electron Container " << containerName <<
" !" <<
endmsg;
728 StatusCode
sc =
retrieve( container, containerName);
729 if(
sc.isFailure() || !container ) {
730 m_provider->msg(MSG::WARNING) <<
"Error retrieving container: " << containerName <<
" !" <<
endmsg;
734 m_provider->msg(MSG::DEBUG) <<
"Event with " << container->size() <<
" Electron object(s) " <<
endmsg;
736 Container::const_iterator elec = container->begin();
737 Container::const_iterator elec_end = container->end();
739 for( ; elec!=elec_end ; ++elec ){
750 bool good_electron =
false;
751# ifdef XAODTRACKING_TRACKPARTICLE_H
759 long unsigned eleid = (
unsigned long)(&eleduff) ;
769 else trk_added = selectorRef.
selectTrack( (*elec)->trackParticle() );
771 if (trk_added) eleobj.
addChild( selectorRef.
tracks().back()->id() );
772 if (elevec) elevec->push_back( eleobj );
776 return selectorRef.
tracks().size();
786# ifdef XAODTRACKING_TRACKPARTICLE_H
787 const std::string& containerName =
"Muons"
789 const std::string& containerName =
"StacoMuonCollection"
793# ifdef XAODTRACKING_TRACKPARTICLE_H
799 m_provider->msg(MSG::DEBUG) <<
" Offline muons (" << containerName <<
")" <<
endmsg;
806 m_provider->msg(MSG::WARNING) <<
"Error No MuonCollection" << containerName <<
" !" <<
endmsg;
810 StatusCode
sc =
retrieve( container, containerName );
811 if(
sc.isFailure() || !container ) {
812 m_provider->msg(MSG::WARNING) <<
"Error retrieving " << containerName <<
" !" <<
endmsg;
816 auto muon = container->begin();
817 auto muon_end = container->end();
821 for( ; muon!=muon_end ; ++muon ){
822# ifdef XAODTRACKING_TRACKPARTICLE_H
831 m_provider->msg(MSG::DEBUG) <<
"found " << selectorRef.
tracks().size() <<
" muons for " << containerName <<
endmsg;
833 return selectorRef.
tracks().size();
842 std::vector<TrackTrigObject>* tauvec=0,
844 int requireNtracks=0,
845 double EtCutOffline=0,
846 const std::string& containerName =
"TauJets"
864 StatusCode
sc =
retrieve( container, containerName);
865 if (
sc != StatusCode::SUCCESS) {
866 m_provider->msg(MSG::WARNING) <<
" Offline tau retrieval not successful" <<
endmsg;
870 Container::const_iterator tau = container->begin();
871 Container::const_iterator tau_end = container->end();
874 for ( ; tau!=tau_end ; ++tau ) {
876# ifndef XAODTAU_VERSIONS_TAUJET_V3_H
877 int N = (*tau)->nTracks();
885 bool good_tau =
false;
892 long unsigned tauid = (
unsigned long)(&duff) ;
900 bool trk_added =
false;
902 for (
unsigned i=N ; i-- ; ) {
903# ifdef XAODTAU_TAUTRACK_H
905 std::vector< ElementLink<xAOD::TrackParticleContainer> > alink = (*tau)->track(i)->trackLinks();
909 for (
size_t ilink=0 ; ilink<alink.size() ; ilink++ ) {
916 trk_added = selectorRef.
selectTrack((*tau)->track(i));
918 if ( trk_added ) tauobj.
addChild( selectorRef.
tracks().back()->id() );
920 if ( tauvec ) tauvec->push_back( tauobj );
924 return selectorRef.
tracks().size();
934 ToolHandle<Trig::TrigDecisionTool>*
m_tdt;
944 std::vector< std::vector<std::string> >
m_types;
945 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
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
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)
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)
virtual void clear() override
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...
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".