12#ifndef TrigInDetAnalysisUtils_T_AnalysisConfig_H
13#define TrigInDetAnalysisUtils_T_AnalysisConfig_H
20#include "GaudiKernel/IToolSvc.h"
21#include "GaudiKernel/ITHistSvc.h"
34#ifdef XAODTRACKING_TRACKPARTICLE_H
52template<
class Prov
ider>
64 const std::string& testChainName,
const std::string& testType,
const std::string& testKey,
65 const std::string& referenceChainName,
const std::string& referenceType,
const std::string& referenceKey,
66 const std::string& selectionChainName,
const std::string& selectionType,
const std::string& selectionKey,
73 m_chainNames { {testChainName}, {referenceChainName}, {selectionChainName} },
74 m_types { {testType}, {referenceType}, {selectionType} },
75 m_keys { {testKey}, {referenceKey}, {selectionKey} },
76 m_filters { {testFilter}, {referenceFilter}, {selectionFilter} },
77 m_refChainName(referenceChainName),
78 m_refChainKey(referenceKey),
79 m_testChainName(testChainName),
80 m_testChainKey(testKey),
84 m_associator(associator),
92 m_keepAllEvents(
false),
93 m_useHighestPT(
false),
96 m_requireDecision(
false) {
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,
116 m_chainNames { {testChainName}, {referenceChainName}, {
"NONE"} },
117 m_types { {testType}, {referenceType}, {
""} },
118 m_keys { {testKey}, {referenceKey}, {
""} },
119 m_filters { {testFilter}, {referenceFilter}, {} },
120 m_refChainName(referenceChainName),
121 m_refChainKey(referenceKey),
122 m_testChainName(testChainName),
123 m_testChainKey(testKey),
127 m_associator(associator),
128 m_analysis(analysis),
135 m_keepAllEvents(
false),
136 m_useHighestPT(
false),
139 m_requireDecision(
false){
158 void addTestChain(
const std::string& chainName,
const std::string&
type,
const std::string& key) {
175 virtual void initialize(Provider* p, ToolHandle<Trig::TrigDecisionTool>* tdt ) {
185 if ( !
m_provider ) std::cerr <<
"ERROR T_AnalysisConfig::execute() called without initialising" << std::endl;
256 template<
class Collection>
257 std::pair< typename Collection::const_iterator, typename Collection::const_iterator >
259 const std::string& key=
"" ) {
267 std::string key_collection = key;
268 std::string key_tename =
"";
269 size_t pos = key_collection.find(
"/");
270 if ( pos!=std::string::npos ) {
271 key_collection = key.substr( pos+1, key.size()-pos );
272 key_tename = key.substr( 0, pos );
275 std::pair<
typename Collection::const_iterator,
276 typename Collection::const_iterator > itrpair;
281 const std::string* keyStr =
m_provider->evtStore()->keyToString(roi_link.
key(), checkCLID);
282 m_provider->msg(MSG::DEBUG) <<
"Requesting range over (" << key <<
") associated to ROI from " << (keyStr ==
nullptr ?
"UNKNOWN" : *keyStr) <<
endmsg;
284 itrpair = (*m_tdt)->associateToEventView( handle, roi_link );
301 bool select( std::vector<TIDA::Vertex>& vertices,
307 for ( ; vtxitr!=vtx_end ; ++vtxitr ) {
308 if ( (*vtxitr)->vertexType()!=0 ) {
318 (*vtxitr)->nTrackParticles(),
320 (*vtxitr)->chiSquared(),
321 (*vtxitr)->numberDoF() ) );
330 bool select( std::vector<TIDA::Vertex>& vertices,
332 const std::string& key=
"" ) {
334 m_provider->msg(MSG::VERBOSE) <<
"\tFetch xAOD::VertexContainer for key: " << key <<
endmsg;
339 if ( vtx_itrpair.first == vtx_itrpair.second ) {
340 m_provider->msg(MSG::WARNING) <<
"\tNo xAOD::Vertex collection for key " << key <<
endmsg;
344 m_provider->msg(MSG::DEBUG) <<
"\txAOD::VertexContainer found with size " << (vtx_itrpair.second - vtx_itrpair.first)
345 <<
"\t:" << key <<
endmsg;
347 return select( vertices, vtx_itrpair.first, vtx_itrpair.second );
353 bool select( std::vector<TIDA::Vertex>& vertices,
const std::string& key=
"" ) {
359 if (
retrieve( xaodVtxCollection, key ).isFailure()) {
360 m_provider->msg(MSG::WARNING) <<
"xAOD vertex container not found with key " << key <<
endmsg;
364 if ( xaodVtxCollection!=0 ) {
366 m_provider->msg(MSG::VERBOSE) <<
"xAOD vertex container " << xaodVtxCollection->
size() <<
" entries" <<
endmsg;
368 return select( vertices, xaodVtxCollection->
begin(), xaodVtxCollection->
end() );
374 for ( ; vtxitr != xaodVtxCollection->
end(); vtxitr++ ) {
375 if ( (*vtxitr)->nTrackParticles()>0 && (*vtxitr)->vertexType()!=0 ) {
383 (*vtxitr)->nTrackParticles(),
385 (*vtxitr)->chiSquared(),
386 (*vtxitr)->numberDoF() ) );
399 template<
class Collection>
403 const std::string& key=
"" ) {
412 std::string key_collection = key;
413 std::string key_tename =
"";
414 size_t pos = key_collection.find(
"/");
415 if ( pos!=std::string::npos ) {
416 key_collection = key.substr( pos+1, key.size()-pos );
417 key_tename = key.substr( 0, pos );
420 std::pair<
typename Collection::const_iterator,
421 typename Collection::const_iterator > itrpair;
426 const std::string* keyStr =
m_provider->evtStore()->keyToString(roi_link.
key(), checkCLID);
427 m_provider->msg(MSG::DEBUG) <<
"Requesting range over (" << key <<
") associated to ROI from " << (keyStr ==
nullptr ?
"UNKNOWN" : *keyStr) <<
endmsg;
429 itrpair = (*m_tdt)->associateToEventView( handle, roi_link );
431 if ( itrpair.first != itrpair.second ) {
432 selector->selectTracks( itrpair.first, itrpair.second );
436 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
445 template<
class Collection>
449 std::string key_collection = key;
450 std::string key_tename =
"";
451 size_t pos = key_collection.find(
"/");
452 if ( pos!=std::string::npos ) {
453 key_collection = key.substr( pos+1, key.size()-pos );
454 key_tename = key.substr( 0, pos );
457 std::vector< Trig::Feature<Collection> > trackcollections = citr->get<Collection>( key_collection,
TrigDefs::alsoDeactivateTEs, key_tename );
458 if ( !trackcollections.empty() ) {
460 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
462 if ( !trackfeature.
empty() ) {
464 const Collection* trigtracks = trackfeature.
cptr();
465 selector->selectTracks( trigtracks );
471 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
478 template<
class Collection>
484 if ( !trackcollections.empty() ) {
492 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
500 std::vector< const Collection* > collectionVector;
501 if ( !
const_cast<HLT::NavigationCore *
>(nc)->getFeatures( te, collectionVector, key ) )
return false;
507 for (
unsigned iv=collectionVector.size() ; iv-- ; ) {
511 if (
index!=iv )
continue;
514 selector->selectTracks( collectionVector[iv] );
521 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty" <<
endmsg;
528 template<
class Collection>
529 StatusCode
retrieve( Collection
const*& collection,
const std::string& key=
"" ) {
534 if ( handle.isValid() ) {
537 collection = handle.cptr();
538 return StatusCode::SUCCESS;
541 return StatusCode::FAILURE;
546 template<
class Collection>
550 if ( handle.isValid() ) {
553 selector->selectTracks( handle.cptr() );
563 template<
class Collection>
565 const Collection* collection =
nullptr;
566 if ( key.empty() )
return false;
571 if ( !(
sc.isSuccess() && collection ) )
return false;
573 m_provider->msg(MSG::DEBUG) <<
"SG Collection->size() " << collection->size() <<
" (" << key <<
")" <<
endmsg;
576 if ( collection->size() == 0 ) {
581 selector->selectTracks( collection );
589 template<
class Collection>
591 const Collection* collection = 0;
592 std::vector<double> v;
597 if(
sc.isSuccess() && collection ) {
598 m_provider->msg(MSG::DEBUG) <<
"SG Collection->size() " << collection->size() <<
" (" << key <<
")" <<
endmsg;
600 typename Collection::const_iterator trackitr = collection->begin();
601 typename Collection::const_iterator trackend = collection->end();
602 if ( trackitr!=trackend ) {
604 v[0] = (*trackitr)->vx();
605 v[1] = (*trackitr)->vy();
606 v[2] = (*trackitr)->vz();
618 template<
class Collection>
621 std::vector<double> v;
622 if ( !trackcollections.empty() ) {
625 for (
unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
628 if ( !trackfeature.
empty() ) {
631 const Collection* trigtracks = trackfeature.
cptr();
633 typename Collection::const_iterator trackitr = trigtracks->begin();
634 typename Collection::const_iterator trackend = trigtracks->end();
635 if ( trackitr!=trackend ) {
637 v[0] = (*trackitr)->vx();
638 v[1] = (*trackitr)->vy();
639 v[2] = (*trackitr)->vz();
647 m_provider->msg(MSG::DEBUG) <<
"TDT TrackFeature collection (" << key <<
") is empty " <<
endmsg;
660 std::vector<TrackTrigObject>* elevec=0,
662 bool raw_track=
false,
664# ifdef XAODTRACKING_TRACKPARTICLE_H
665 const std::string& containerName =
"Electrons"
667 const std::string& containerName =
"ElectronAODCollection"
671 m_provider->msg(MSG::DEBUG) <<
"Fetching offline electrons: " << containerName <<
endmsg;
675# ifdef XAODTRACKING_TRACKPARTICLE_H
685 m_provider->msg(MSG::WARNING) <<
"Error No Electron Container " << containerName <<
" !" <<
endmsg;
689 StatusCode
sc =
retrieve( container, containerName);
690 if(
sc.isFailure() || !container ) {
691 m_provider->msg(MSG::WARNING) <<
"Error retrieving container: " << containerName <<
" !" <<
endmsg;
695 m_provider->msg(MSG::DEBUG) <<
"Event with " << container->size() <<
" Electron object(s) " <<
endmsg;
697 Container::const_iterator elec = container->begin();
698 Container::const_iterator elec_end = container->end();
700 for( ; elec!=elec_end ; ++elec ){
711 bool good_electron =
false;
712# ifdef XAODTRACKING_TRACKPARTICLE_H
720 long unsigned eleid = (
unsigned long)(&eleduff) ;
730 else trk_added = selectorRef.
selectTrack( (*elec)->trackParticle() );
732 if (trk_added) eleobj.
addChild( selectorRef.
tracks().back()->id() );
733 if (elevec) elevec->push_back( eleobj );
737 return selectorRef.
tracks().size();
747# ifdef XAODTRACKING_TRACKPARTICLE_H
748 const std::string& containerName =
"Muons"
750 const std::string& containerName =
"StacoMuonCollection"
754# ifdef XAODTRACKING_TRACKPARTICLE_H
760 m_provider->msg(MSG::DEBUG) <<
" Offline muons (" << containerName <<
")" <<
endmsg;
767 m_provider->msg(MSG::WARNING) <<
"Error No MuonCollection" << containerName <<
" !" <<
endmsg;
771 StatusCode
sc =
retrieve( container, containerName );
772 if(
sc.isFailure() || !container ) {
773 m_provider->msg(MSG::WARNING) <<
"Error retrieving " << containerName <<
" !" <<
endmsg;
777 auto muon = container->begin();
778 auto muon_end = container->end();
782 for( ; muon!=muon_end ; ++muon ){
783# ifdef XAODTRACKING_TRACKPARTICLE_H
792 m_provider->msg(MSG::DEBUG) <<
"found " << selectorRef.
tracks().size() <<
" muons for " << containerName <<
endmsg;
794 return selectorRef.
tracks().size();
803 std::vector<TrackTrigObject>* tauvec=0,
805 int requireNtracks=0,
806 double EtCutOffline=0,
807 const std::string& containerName =
"TauJets"
825 StatusCode
sc =
retrieve( container, containerName);
826 if (
sc != StatusCode::SUCCESS) {
827 m_provider->msg(MSG::WARNING) <<
" Offline tau retrieval not successful" <<
endmsg;
831 Container::const_iterator tau = container->begin();
832 Container::const_iterator tau_end = container->end();
835 for ( ; tau!=tau_end ; ++tau ) {
837# ifndef XAODTAU_VERSIONS_TAUJET_V3_H
838 int N = (*tau)->nTracks();
846 bool good_tau =
false;
853 long unsigned tauid = (
unsigned long)(&duff) ;
861 bool trk_added =
false;
863 for (
unsigned i=N ; i-- ; ) {
864# ifdef XAODTAU_TAUTRACK_H
866 std::vector< ElementLink<xAOD::TrackParticleContainer> > alink = (*tau)->track(i)->trackLinks();
870 for (
size_t ilink=0 ; ilink<alink.size() ; ilink++ ) {
877 trk_added = selectorRef.
selectTrack((*tau)->track(i));
879 if ( trk_added ) tauobj.
addChild( selectorRef.
tracks().back()->id() );
881 if ( tauvec ) tauvec->push_back( tauobj );
885 return selectorRef.
tracks().size();
895 ToolHandle<Trig::TrigDecisionTool>*
m_tdt;
905 std::vector< std::vector<std::string> >
m_types;
906 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".