From 51ecafd5e04d0cf23c1e627055ef7675d84458fc Mon Sep 17 00:00:00 2001 From: sutt Date: Mon, 3 Jan 2022 10:05:23 +0100 Subject: [PATCH] Add analysis code for the new Moniotroed::Scalar approach to the ID Trigger monitoring The approach followed has been, wherever possible, simply modify the existing classes to allow the new approach, or where it can not be accomodated along wit hthe old approach, to simple duplicate the class and make the small number of required changes. We wantr to continue to run the old analysis, since we will need to validate the new approach against the old, and only once we have fully, validated functionality, can we consider dropping the support for the old approach. --- .../TrigInDetAnalysis/TrackAnalysis.h | 6 +- .../TrigInDetAnalysisExample/CMakeLists.txt | 2 + .../AnalysisConfig_Tier0.h | 8 +- .../AnalysisR3_Tier0.h | 218 +++ .../TrigInDetAnalysisExample/Analysis_Tier0.h | 11 + .../TrigInDetAnalysisExample/TIDAHistogram.h | 81 ++ .../TrigInDetAnalysisExample/TIDATools.h | 57 + .../T_AnalysisConfigMT_Tier0.h | 95 +- .../T_AnalysisConfigR3_Tier0.h | 1262 +++++++++++++++++ .../T_AnalysisConfig_Tier0.h | 44 +- .../TrigInDetAnalysisExample/TrigTestBase.h | 5 - .../TrigInDetAnalysisExample/VtxR3Analysis.h | 93 ++ .../python/TIDAChains.py | 78 + .../python/TIDAMonTool.py | 458 ++++++ .../python/__init__.py | 0 .../python/chainString.py | 89 ++ .../src/AnalysisR3_Tier0.cxx | 494 +++++++ .../src/Analysis_Tier0.cxx | 20 +- .../src/TrigR3Mon.cxx | 666 +++++++++ .../TrigInDetAnalysisExample/src/TrigR3Mon.h | 176 +++ .../src/TrigTestBase.cxx | 106 +- .../src/VtxR3Analysis.cxx | 139 ++ .../TrigInDetAnalysisExample_entries.cxx | 3 + .../Analysis/src/ConfAnalysis.h | 10 +- .../Analysis/src/Makefile | 1 + .../TrigInDetAnalysisUtils/T_AnalysisConfig.h | 16 +- .../TrigInDetAnalysisUtils/TagNProbe.h | 22 +- .../TrigInDetAnalysisUtils/src/TagNProbe.cxx | 33 +- .../python/TrigInDetArtSteps.py | 7 +- .../test/test_trigID_all_ttbar_tier0_pu40.py | 2 +- 30 files changed, 4010 insertions(+), 192 deletions(-) create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisR3_Tier0.h create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TIDAHistogram.h create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TIDATools.h create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfigR3_Tier0.h create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/VtxR3Analysis.h create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/TIDAChains.py create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/TIDAMonTool.py create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/__init__.py create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/chainString.py create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/AnalysisR3_Tier0.cxx create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigR3Mon.cxx create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigR3Mon.h create mode 100644 Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/VtxR3Analysis.cxx diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysis/TrigInDetAnalysis/TrackAnalysis.h b/Trigger/TrigAnalysis/TrigInDetAnalysis/TrigInDetAnalysis/TrackAnalysis.h index d10cc088ab2..3db0d78b599 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysis/TrigInDetAnalysis/TrackAnalysis.h +++ b/Trigger/TrigAnalysis/TrigInDetAnalysis/TrigInDetAnalysis/TrackAnalysis.h @@ -58,8 +58,12 @@ public: TrigObjectMatcher* /* objects */ ) { execute( tracks1, tracks2, matcher ); }; - + + virtual void execute( const std::vector& , + const std::vector& , + TrackAssociator* , + const TIDA::Event* ) { } // virtual void execute( const std::vector& , // const std::vector& , diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/CMakeLists.txt b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/CMakeLists.txt index 7793c6ed158..cf2bf6843c2 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/CMakeLists.txt +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/CMakeLists.txt @@ -6,6 +6,8 @@ atlas_subdir( TrigInDetAnalysisExample ) # External dependencies: find_package( ROOT COMPONENTS Core Tree Hist RIO ) +atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8} ) + # Component(s) in the package: atlas_add_library( TrigInDetAnalysisExampleLib src/*.cxx diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisConfig_Tier0.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisConfig_Tier0.h index bfe430cb721..272c7a2a6e1 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisConfig_Tier0.h +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisConfig_Tier0.h @@ -13,11 +13,15 @@ #define TrigInDetAnalysisExample_AnalysisConfig_Tier0_H #include "TrigHLTMonitoring/IHLTMonTool.h" +#include "AthenaBaseComps/AthAlgorithm.h" + #include "TrigInDetAnalysisExample/T_AnalysisConfig_Tier0.h" #include "TrigInDetAnalysisExample/T_AnalysisConfigMT_Tier0.h" +#include "TrigInDetAnalysisExample/T_AnalysisConfigR3_Tier0.h" -typedef T_AnalysisConfig_Tier0 AnalysisConfig_Tier0; -typedef T_AnalysisConfigMT_Tier0 AnalysisConfigMT_Tier0; +typedef T_AnalysisConfig_Tier0 AnalysisConfig_Tier0; +typedef T_AnalysisConfigMT_Tier0 AnalysisConfigMT_Tier0; +typedef T_AnalysisConfigR3_Tier0 AnalysisConfigR3_Tier0; #endif // TrigInDetAnalysisExample_AnalysisConfig_Tier0_H diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisR3_Tier0.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisR3_Tier0.h new file mode 100644 index 00000000000..89fc877d703 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisR3_Tier0.h @@ -0,0 +1,218 @@ +/* emacs: this is -*- c++ -*- */ +/** + ** @file AnalysisR3_Tier0.h + ** + ** @author mark sutton + ** @date $Id: AnalysisR3_Tier0.h Thu 18 May 2017 15:29:53 CEST + ** + ** Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + **/ + + +#ifndef TrigInDetAnalysisExample_AnalysisR3_Tier0_H +#define TrigInDetAnalysisExample_AnalysisR3_Tier0_H + +#include "GaudiKernel/ToolHandle.h" +#include "AthenaMonitoringKernel/GenericMonitoringTool.h" + +#include + +#include "TH1.h" +#include "TProfile.h" + +#include "TrigInDetAnalysis/TrackAnalysis.h" +#include "TrigInDetAnalysis/TIDDirectory.h" + +#include "TrigInDetAnalysisExample/VtxR3Analysis.h" + +#include "TrigInDetAnalysisExample/TIDAHistogram.h" + +class AnalysisR3_Tier0 : public TrackAnalysis { + +public: + + using TrackAnalysis::execute; + +public: + + AnalysisR3_Tier0(const std::string& name, double pTCut, double etaCut, double d0Cut, double z0Cut); + + virtual void initialise(); + + virtual void initialise_R2(); + virtual void initialise_R3(); + + virtual void execute(const std::vector& referenceTracks, + const std::vector& testTracks, + TrackAssociator* associator ); + + virtual void execute(const std::vector& referenceTracks, + const std::vector& testTracks, + TrackAssociator* associator, + const TIDA::Event* tevt ); + + virtual void execute_vtx(const std::vector& vtx0, + const std::vector& vtx1, + const TIDA::Event* tevt=0 ); + + virtual void finalise(); + + void setvertices(int numvtx) {m_nVtx = numvtx;} + + std::map::const_iterator THbegin() const { return m_histos.begin(); } + std::map::const_iterator THend() const { return m_histos.end(); } + + std::map::const_iterator TEffbegin() const { return m_effhistos.begin(); } + std::map::const_iterator TEffend() const { return m_effhistos.end(); } + + void set_monTool( ToolHandle* m ) { m_monTool=m; } + + ToolHandle* monTool() { return m_monTool; } + + bool debug() const { return m_debug; } + +private: + + void addHistogram( TH1* ) { } + + void addHistogram( TProfile* ) { } + + double phi(double p); + +private: + + /// these aren't used for this class but are still needed + /// so that the older class can work - it iuses the same interface + std::map m_histos; + std::map m_effhistos; + + /// Monitorwd::AScalar Histogram wrapper class + + TIDA::Histogram* m_htotal_efficiency; + TIDA::Histogram* m_hpTeff; + TIDA::Histogram* m_hetaeff; + TIDA::Histogram* m_hphieff; + TIDA::Histogram* m_hd0eff; + TIDA::Histogram* m_hz0eff; + TIDA::Histogram* m_hnVtxeff; + TIDA::Histogram* m_hlbeff; + + TIDA::Histogram* m_hpTres; + TIDA::Histogram* m_hipTres; + TIDA::Histogram* m_hetares; + TIDA::Histogram* m_hphires; + TIDA::Histogram* m_hd0res; + TIDA::Histogram* m_hz0res; + + TIDA::Histogram* m_htrkvtx_x_lb; + TIDA::Histogram* m_htrkvtx_y_lb; + TIDA::Histogram* m_htrkvtx_z_lb; + + + TIDA::Histogram* m_hnpixvseta; + TIDA::Histogram* m_hnpixvsphi; + TIDA::Histogram* m_hnpixvsd0; + TIDA::Histogram* m_hnpixvspT; + + TIDA::Histogram* m_hnsctvseta; + TIDA::Histogram* m_hnsctvsphi; + TIDA::Histogram* m_hnsctvsd0; + TIDA::Histogram* m_hnsctvspT; + + TIDA::Histogram* m_hntrtvseta; + TIDA::Histogram* m_hntrtvsphi; + + TIDA::Histogram* m_hnsihits_lb; + + TIDA::Histogram* m_hnpixvseta_rec; + TIDA::Histogram* m_hnpixvsphi_rec; + TIDA::Histogram* m_hnpixvsd0_rec; + TIDA::Histogram* m_hnpixvspT_rec; + + TIDA::Histogram* m_hnsctvseta_rec; + TIDA::Histogram* m_hnsctvsphi_rec; + TIDA::Histogram* m_hnsctvsd0_rec; + TIDA::Histogram* m_hnsctvspT_rec; + + TIDA::Histogram* m_hntrtvseta_rec; + TIDA::Histogram* m_hntrtvsphi_rec; + + TIDA::Histogram* m_hnsihits_lb_rec; + + TIDA::Histogram* m_hd0vsphi; + TIDA::Histogram* m_hd0vsphi_rec; + + + TIDA::Histogram* m_hchain; + TIDA::Histogram* m_hntrk; + TIDA::Histogram* m_htrkpT; + + TIDA::Histogram* m_htrketa; + TIDA::Histogram* m_htrkphi; + TIDA::Histogram* m_htrkd0; + TIDA::Histogram* m_htrkz0; + + + TIDA::Histogram* m_htrkdd0; + TIDA::Histogram* m_htrkdz0; + + TIDA::Histogram* m_htrkd0sig; + + TIDA::Histogram* m_hnpix; + TIDA::Histogram* m_hnsct; + TIDA::Histogram* m_hnsihits; + TIDA::Histogram* m_hntrt; + + TIDA::Histogram* m_hntrk_rec; + + TIDA::Histogram* m_hlayer; + + + TIDA::Histogram* m_htrkpT_rec; + TIDA::Histogram* m_htrketa_rec; + TIDA::Histogram* m_htrkphi_rec; + TIDA::Histogram* m_htrkd0_rec; + TIDA::Histogram* m_htrkz0_rec; + + TIDA::Histogram* m_htrkdd0_rec; + TIDA::Histogram* m_htrkdz0_rec; + + TIDA::Histogram* m_htrkd0sig_rec; + + TIDA::Histogram* m_hnpix_rec; + TIDA::Histogram* m_hnsct_rec; + TIDA::Histogram* m_hnsihits_rec; + TIDA::Histogram* m_hntrt_rec; + + + TIDA::Histogram* m_hlayer_rec; + + + TIDA::Histogram* m_htrkpT_residual; + TIDA::Histogram* m_htrkipT_residual; + TIDA::Histogram* m_htrketa_residual; + TIDA::Histogram* m_htrkphi_residual; + TIDA::Histogram* m_htrkd0_residual; + TIDA::Histogram* m_htrkz0_residual; + + TIDA::Histogram* m_htrkdd0_residual; + TIDA::Histogram* m_htrkdz0_residual; + + + + /// sundry other items + + int m_nVtx; + + bool m_debug; + + unsigned long long m_eventid; + + VtxR3Analysis* m_vtxanal; + + ToolHandle* m_monTool; + +}; + + +#endif // TrigInDetAnalysisExample_AnalysisR3_Tier0_H diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/Analysis_Tier0.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/Analysis_Tier0.h index b3b87ac322f..20614045cbf 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/Analysis_Tier0.h +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/Analysis_Tier0.h @@ -24,6 +24,9 @@ #include "TrigInDetAnalysisExample/VtxAnalysis.h" +#include "GaudiKernel/ToolHandle.h" +#include "AthenaMonitoringKernel/GenericMonitoringTool.h" + class Analysis_Tier0 : public TrackAnalysis { public: @@ -54,6 +57,12 @@ public: std::map::const_iterator TEffbegin() const { return m_effhistos.begin(); } std::map::const_iterator TEffend() const { return m_effhistos.end(); } + + void set_monTool( ToolHandle* m ) { m_monTool=m; } + + ToolHandle* monTool() { return m_monTool; } + + bool debug() const { return m_debug; } public: @@ -212,6 +221,8 @@ private: VtxAnalysis* m_vtxanal; + ToolHandle* m_monTool; + }; diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TIDAHistogram.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TIDAHistogram.h new file mode 100644 index 00000000000..10242aa0d7d --- /dev/null +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TIDAHistogram.h @@ -0,0 +1,81 @@ +/// emacs: this is -* c++ -*- +/** + ** @file TIDAHistogram.h + ** + ** @author sutt + ** @date Sun 2 Jan 2022 06:57:06 GMT + ** + ** Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + **/ + + +#ifndef TIDA_HISTOGRAM_H +#define TIDA_HISTOGRAM_H + +#include "GaudiKernel/ToolHandle.h" +#include "AthenaMonitoringKernel/GenericMonitoringTool.h" + +#include "AthenaMonitoringKernel/Monitored.h" + +#include + +namespace TIDA { + +template +class Histogram { + +public: + + Histogram() : m_monTool(0), m_name("") { } + + Histogram( ToolHandle* m, const std::string& name ) : m_monTool(m), m_name(name) { + // std::cout << "book: " << m_name << " " << m_monTool->name() << std::endl; + } + + void Fill( T d ) const { + if ( m_monTool ) { + // std::cout << "Histogram::Fill() monTool " << m_monTool << "\tname: " << m_name << "\td: " << d << "\t" << monTool()->name() << std::endl; + auto s = Monitored::Scalar( m_name, d ); + Monitored::Group( *m_monTool, s ); + } + else std::cerr << "Histogram " << m_name << "\tmonTool not defined" << std::endl; + } + + void Fill( T d, T w ) const { + if ( m_monTool ) { + // std::cout << "Histogram::Fill() monTool " << m_monTool << "\tname: " << m_name << "\td: " << d << "\tw:" << w << std::endl; + auto s = Monitored::Scalar( m_name, d ); + auto sw = Monitored::Scalar( m_name+"_weight", w ); + Monitored::Group( *m_monTool, s, sw ); + } + else std::cerr << "Histogram " << m_name << "\tmonTool not defined" << std::endl; + } + + std::string name() const { return m_name; } + + ToolHandle* monTool() const { return m_monTool; }; + +private: + + ToolHandle* m_monTool; + + std::string m_name; + +}; + + + +} + + +#endif /* TIDA_HISTOGRAM_H */ + + + + + + + + + + diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TIDATools.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TIDATools.h new file mode 100644 index 00000000000..94b58e35af2 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TIDATools.h @@ -0,0 +1,57 @@ +/* emacs: this is -*- c++ -*- */ +/** + ** @file TIDATools.h + ** + ** @brief useful tool for the TrigInDetAnalysis class code + ** + ** @author mark sutton + ** @date Tue 16 May 2017 09:28:55 CEST + ** + ** Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + **/ + +#ifndef TrigInDetAnalysisExample_TIDATools_H +#define TrigInDetAnalysisExample_TIDATools_H + + +#include + +template +void HighestPTOnly( std::vector& tracks ) { + + if ( tracks.size()>1 ) { + + std::vector tmp_tracks; + + int ih = 0; + + for ( unsigned i=1 ; ipT())>std::fabs(tracks[ih]->pT()) ) ih = i; + } + + tmp_tracks.push_back( tracks[ih] ); + + tracks = tmp_tracks; + } +} + + + +template +void FilterPT( std::vector& tracks, double pt ) { + + std::vector tmp_tracks; + + tmp_tracks.reserve( tracks.size() ); + + for ( unsigned i=0 ; ipT())>=pt ) tmp_tracks.push_back( tracks[i] ); + } + + if ( tmp_tracks.size() -void HighestPTOnly( std::vector& tracks ) { - if ( tracks.size()>1 ) { - - std::vector tmp_tracks; - - int ih = 0; - - for ( unsigned i=1 ; ipT())>std::fabs(tracks[ih]->pT()) ) ih = i; - } - - tmp_tracks.push_back( tracks[ih] ); - - tracks = tmp_tracks; - } -} - - - - -template -void FilterPT( std::vector& tracks, double pt ) { - - std::vector tmp_tracks; - - tmp_tracks.reserve( tracks.size() ); - - for ( unsigned i=0 ; ipT())>=pt ) tmp_tracks.push_back( tracks[i] ); - } - - if ( tmp_tracks.size() +template class T_AnalysisConfigMT_Tier0 : public T_AnalysisConfig { public: @@ -169,12 +132,15 @@ public: m_shifter(false), m_pTthreshold(0), m_first(true), - m_containTracks(false) + m_containTracks(false), + m_TnP_tool(TnP_tool), + m_invmass(0), + m_invmass_obj(0) { + /// FIXME: the m_event should not be needed, we need to make this a local variable m_event = new TIDA::Event(); m_chainNames.push_back(testChainName); - m_TnP_tool = TnP_tool; - + #if 0 ChainString& chain = m_chainNames.back(); @@ -210,7 +176,7 @@ public: public: - Analysis_Tier0* _analysis; + A* _analysis; protected: @@ -881,7 +847,7 @@ protected: else { /// new Roi based feature access - + //std::string roi_key = m_chainNames[ichain].roi(); std::string roi_key = chainConfig.roi(); @@ -904,7 +870,7 @@ protected: std::vector< TrigCompositeUtils::LinkInfo > rois = (*m_tdt)->template features( Trig::FeatureRequestDescriptor( chainName, - decisiontype, + decisiontype, roi_key, feature_type, "roi", @@ -1032,7 +998,7 @@ protected: // filling invariant mass histograms for tag and probe analysis if ( TnP_flag ) { - m_TnP_tool->FillMinvHisto( iroi ) ; + m_TnP_tool->Fill( m_invmass, m_invmass_obj, iroi ) ; } if ( this->filterOnRoi() ) { @@ -1356,11 +1322,12 @@ protected: ManagedMonitorToolBase::run ) ); # endif + _analysis = dynamic_cast(m_analysis); + + if ( monTool() ) _analysis->set_monTool( monTool() ); m_analysis->initialise(); - _analysis = dynamic_cast(m_analysis); - _analysis->setevent( m_event ); @@ -1371,9 +1338,15 @@ protected: // booking invariant mass histograms for tag and probe analysis if ( m_TnP_tool != 0 ) { - m_TnP_tool->BookMinvHisto() ; - m_provider->addHistogram( m_TnP_tool->GetMinvHisto(), mongroup ) ; - m_provider->addHistogram( m_TnP_tool->GetMinvObjHisto(), mongroup ) ; + m_invmass = new TH1F( "invmass", "invariant mass;mass [GeV]", 320, 0, 200 ); + m_provider->addHistogram( m_invmass ); + + m_invmass_obj = new TH1F( "invmass_obj", "invariant mass;mass [GeV]", 320, 0, 200 ); + m_provider->addHistogram( m_invmass_obj ); + ///} + // m_TnP_tool->BookMinvHisto() ; + // m_provider->addHistogram( m_TnP_tool->GetMinvHisto(), mongroup ) ; + // m_provider->addHistogram( m_TnP_tool->GetMinvObjHisto(), mongroup ) ; } while ( hitr!=hend ) { @@ -1421,6 +1394,9 @@ protected: } } + void set_monTool( ToolHandle* m ) { m_monTool=m; } + + ToolHandle* monTool() { return m_monTool; } protected: @@ -1432,7 +1408,7 @@ protected: TTree* mTree; std::vector m_chainNames; - std::vector m_analyses; + std::vector m_analyses; std::string m_testType; bool m_doOffline; @@ -1461,7 +1437,12 @@ protected: bool m_containTracks; - TagNProbe* m_TnP_tool ; + TagNProbe* m_TnP_tool; + + TH1F* m_invmass; + TH1F* m_invmass_obj; + + ToolHandle* m_monTool; }; diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfigR3_Tier0.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfigR3_Tier0.h new file mode 100644 index 00000000000..cccfcb98ac2 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfigR3_Tier0.h @@ -0,0 +1,1262 @@ +/* emacs: this is -*- c++ -*- */ +/** + ** @file T_AnalysisConfigR3_Tier0.h + ** + ** @brief baseclass template so that we can use in different contexts + ** in different ways in the monitoring + ** + ** NB: this will be configured to run *either* a standard + ** analysis, or a "purity" analysis. If a purity analysis, + ** the trigger tracks become the reference (with all the + ** selection) and the offline or truth the "test" tracks + ** This would be a simple switch if the reference tracks + ** were in the RoI, but as they are not we need to move the + ** RoI filtering to the test filter and *not* the reference + ** filter grrrrrr + ** + ** @author mark sutton + ** @date Tue 16 May 2017 09:28:55 CEST + ** + ** Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + **/ + +#ifndef TrigInDetAnalysisExample_T_AnalysisConfigR3_Tier0_H +#define TrigInDetAnalysisExample_T_AnalysisConfigR3_Tier0_H + +#include "TrigInDetAnalysis/TIDAEvent.h" +#include "TrigInDetAnalysis/TIDAVertex.h" +#include "TrigInDetAnalysis/TrackSelector.h" +#include "TrigInDetAnalysisUtils/T_AnalysisConfig.h" +#include "TrigInDetAnalysisUtils/TagNProbe.h" + +#include "TrigInDetAnalysisExample/AnalysisR3_Tier0.h" +#include "TrigInDetAnalysisExample/VtxAnalysis.h" +#include "TrigInDetAnalysisExample/ChainString.h" +#include "TrigInDetAnalysisExample/TIDATools.h" + +#include "TTree.h" +#include "TFile.h" + +#include "GaudiKernel/ToolHandle.h" +#include "AthenaMonitoringKernel/GenericMonitoringTool.h" + + +// McParticleEvent includes +#include "McParticleEvent/TruthParticleContainer.h" + +#include "GeneratorObjects/McEventCollection.h" +#include "AtlasHepMC/GenEvent.h" +#include "AtlasHepMC/GenVertex.h" +#include "AtlasHepMC/GenParticle.h" + +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" +#include "xAODEventInfo/EventInfo.h" + + + +#include "TrigInDetAnalysis/TIDDirectory.h" + +#include "TrigInDetAnalysis/Filter_AcceptAll.h" + +#include "TrigInDetAnalysisUtils/TIDARoiDescriptorBuilder.h" +#include "TrigInDetAnalysisUtils/Filter_etaPT.h" +#include "TrigInDetAnalysisUtils/Filter_RoiSelector.h" +#include "TrigInDetAnalysisUtils/Associator_BestMatch.h" +#include "TrigInDetAnalysisUtils/Filters.h" + + + +#include "VxVertex/VxContainer.h" + +#include "muonEvent/MuonContainer.h" + +#include "egammaEvent/ElectronContainer.h" + +#include "tauEvent/TauJetContainer.h" + + +#include "TrigSteeringEvent/HLTResult.h" +#include "TrigDecisionTool/ExpertMethods.h" + +// #include "TrigSteeringEvent/TrigRoiDescriptorCollection.h" + +#include "xAODTracking/TrackParticle.h" +#include "xAODTracking/TrackParticleContainer.h" + +#include "TrigCompositeUtils/TrigCompositeUtils.h" + + +template +std::ostream& operator<<( std::ostream& s, const std::vector& v) { + for ( size_t i=0 ; i +class T_AnalysisConfigR3_Tier0 : public T_AnalysisConfig { + +public: + + // Full constructor: test/reference/selection + // - analysisInstanceName: the name of the analysis chain being created + // - xxxChainName: the name of the chain to be used as test/reference/selection; must be "StoreGate" in case of direct access to SG containers + // - xxxType: the type of tracks to be retrieved from the test/reference/selection chain or container + // - xxxKey: the key for tracks to be retrieved from the test/reference/selection chain or container + // - 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 + // - all standard operations are performed in loops over 0=test 1=reference 2=selection + 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, + TIDARoiDescriptor* roiInfo, + TrackFilter* testFilter, TrackFilter* referenceFilter, + TrackAssociator* associator, + TrackAnalysis* analysis, + TagNProbe* TnP_tool = 0) : + T_AnalysisConfig( analysisInstanceName, + testChainName, testType, testKey, + referenceChainName, referenceType, referenceKey, + roiInfo, + testFilter, referenceFilter, + associator, + analysis), + m_useBeamCondSvc(false), + m_doOffline(true), + m_doMuons(false), + m_doElectrons(false), + m_doTaus(false), + m_doBjets(false), + m_hasTruthMap(false), + m_NRois(0), + m_NRefTracks(0), + m_NTestTracks(0), + m_runPurity(false), + m_shifter(false), + m_pTthreshold(0), + m_first(true), + m_containTracks(false), + m_invmass(0), + m_invmass_obj(0) + { + + /// leave in for development + /// std::cout << "chain size: " << m_chainNames.size() << "(" << this << ")" << std::endl; + + m_chainNames.push_back(testChainName); + + /// std::cout << "chain size: " << m_chainNames.size() << "(" << this << ")" << std::endl; + + m_TnP_tool = TnP_tool; + + +#if 0 + /// leave for debugging + ChainString& chain = m_chainNames.back(); + + std::cout << "\nT_AnalysisConfigR3_Tier0::name: " << name() << "\t" << this << std::endl; + std::cout << "T_AnalysisConfigR3_Tier0::chain specification: " << testChainName << " -> " << chain << "\t" << chain.raw() << std::endl; + std::cout << "\tchain: " << chain.head() << std::endl; + std::cout << "\tkey: " << chain.tail() << std::endl; + std::cout << "\troi: " << chain.roi() << std::endl; + std::cout << "\tvtx: " << chain.vtx() << std::endl; + std::cout << "\tte: " << chain.element() << std::endl; + + std::cout << "\tpost: " << chain.post() << std::endl; + std::cout << "\tpt: " << chain.postvalue("pt") << std::endl; + + std::cout << "\tcontainTracks: " << m_containTracks << std::endl; +#endif + + m_testType = testType; + } + + virtual ~T_AnalysisConfigR3_Tier0() { + if ( m_TnP_tool != 0 ) delete m_TnP_tool ; + } + + void setRunPurity( bool b ) { m_runPurity=b; } + + void setShifter( bool b ) { m_shifter=b; } + + void useBeamCondSvc( bool b ) { m_useBeamCondSvc = b; } + + void containTracks( bool b ) { m_containTracks = b; } + + void set_monTool( ToolHandle* m ) { m_monTool=m; } + + ToolHandle* monTool() { return m_monTool; } + +public: + + A* _analysis; + +protected: + + using T_AnalysisConfig::m_provider; + using T_AnalysisConfig::m_tdt; + using T_AnalysisConfig::m_mcTruth; + + using T_AnalysisConfig::name; + using T_AnalysisConfig::m_analysis; + + using T_AnalysisConfig::m_selectorTest; + using T_AnalysisConfig::m_selectorRef; + using T_AnalysisConfig::m_associator; + using T_AnalysisConfig::m_filters; + + + virtual void loop() { + + bool TnP_flag = (m_TnP_tool != 0) ; // flag for tag and probe analysis + + if ( m_TnP_tool ) { + if ( m_invmass==0 ) m_invmass = new TIDA::Histogram( monTool(), "invmass" ); + if ( m_invmass_obj==0 ) m_invmass_obj = new TIDA::Histogram( monTool(), "invmass_obj" ); + } + + + if( m_provider->msg().level() <= MSG::VERBOSE) { + m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::loop() for " << T_AnalysisConfig::m_analysisInstanceName << endmsg; + } + + // get (offline) beam position + double xbeam = 0; + double ybeam = 0; + + if ( m_first ) { + + m_first = false; + + if ( m_provider->msg().level() <= MSG::VERBOSE ) { + m_provider->msg(MSG::VERBOSE) << " using beam position\tx=" << xbeam << "\ty=" << ybeam << endmsg; + + std::vector configuredChains = (*(m_tdt))->getListOfTriggers("L2_.*, EF_.*, HLT_.*"); + + for ( unsigned i=0 ; imsg(MSG::VERBOSE) << "Chain " << configuredChains[i] << endmsg; + } + } + + // std::cout << "\tloop() analyse chains " << m_chainNames.size() << std::endl; + + } + + Filter_True filter; + + Filter_etaPT filter_etaPT(5,200); + Filter_Combined filter_truth( &filter_etaPT, &filter_etaPT); + + /// will need to add a vertex filter at some point probably + // Filter_Combined filterRef (&filter_offline, &filter_vertex); + + int iRefFilter = 1; + int iTestFilter = 0; + + if ( m_runPurity ) { + iRefFilter = 0; + iTestFilter = 1; + } + + Filter_Combined filterRef( m_filters[iRefFilter][0], &filter ); + Filter_Combined filterTest( m_filters[iTestFilter][0], &filter ); + + + TrigTrackSelector selectorTruth( &filter_truth ); + TrigTrackSelector selectorRef( &filterRef ); + m_selectorRef = &selectorRef; + TrigTrackSelector selectorTest( &filterTest ); + m_selectorTest = &selectorTest; + + if ( xbeam!=0 || ybeam!=0 ) { + m_selectorRef->setBeamline( xbeam, ybeam ); + } + + /// now start everything going for this event properly ... + + TIDA::Event event; + TIDA::Event* eventp = &event; + + + // clear the ntuple TIDA::Event class + eventp->clear(); + + /// (obviously) get the event info + + const xAOD::EventInfo* pEventInfo; + + unsigned run_number = 0; + unsigned long long event_number = 0; + unsigned lumi_block = 0; + unsigned bunch_crossing_id = 0; + unsigned time_stamp = 0; + double mu_val = 0; + + /// for debugging ... + // std::cout << "\tloop() get EventInfo" << std::endl; + + if ( m_provider->evtStore()->retrieve(pEventInfo).isFailure() ) { + m_provider->msg(MSG::WARNING) << "Failed to get EventInfo " << endmsg; + } else { + + run_number = pEventInfo->runNumber(); + event_number = pEventInfo->eventNumber(); + lumi_block = pEventInfo->lumiBlock(); + time_stamp = pEventInfo->timeStamp(); + bunch_crossing_id = pEventInfo->bcid(); + mu_val = pEventInfo->averageInteractionsPerCrossing(); + } + + if(m_provider->msg().level() <= MSG::VERBOSE){ + m_provider->msg(MSG::VERBOSE) << "run " << run_number + << "\tevent " << event_number + << "\tlb " << lumi_block << endmsg; + } + + // clear the ntuple TIDA::Event class + eventp->clear(); + + eventp->run_number(run_number); + eventp->event_number(event_number); + eventp->lumi_block(lumi_block); + eventp->time_stamp(time_stamp); + eventp->bunch_crossing_id(bunch_crossing_id); + eventp->mu(mu_val); + + /// first check whether the chains have actually run, otherwise there's no point + /// doing anything + + bool analyse = false; + + // Check HLTResult + + for ( unsigned ichain=0 ; ichainmsg().level() <= MSG::DEBUG ) { + m_provider->msg(MSG::DEBUG) << "Chain " << chainname + << "\tpass " << (*m_tdt)->isPassed(chainname) + << "\tpres " << (*m_tdt)->getPrescale(chainname) << endmsg; + } + + /// for debugging ... + // std::cout << "\tChain " << chainname << "\tpass " << (*m_tdt)->isPassed(chainname) + // << "\tpres " << (*m_tdt)->getPrescale(chainname) << std::endl; + + if ( (*(m_tdt))->isPassed(chainname) || (*(m_tdt))->getPrescale(chainname) ) analyse = true; + + } + } + + + if ( !this->m_keepAllEvents && !analyse ) { + if(m_provider->msg().level() <= MSG::VERBOSE) { + m_provider->msg(MSG::VERBOSE) << "No chains passed unprescaled - not processing this event" << endmsg; + } + return; + } + + + /// for Monte Carlo get the truth particles if requested to do so + + selectorTruth.clear(); + + if(m_provider->msg().level() <= MSG::VERBOSE) + m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg; + + const TrigInDetTrackTruthMap* truthMap = 0; + + if ( m_mcTruth ) { + if(m_provider->msg().level() <= MSG::VERBOSE ) m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg; + + if ( m_provider->evtStore()->retrieve(truthMap, "TrigInDetTrackTruthMap").isFailure()) { + if(m_provider->msg().level() <= MSG::VERBOSE) + m_provider->msg(MSG::VERBOSE) << "TrigInDetTrackTruthMap not found" << endmsg; + m_hasTruthMap = false; + } + else { + if(m_provider->msg().level() <= MSG::VERBOSE) + m_provider->msg(MSG::VERBOSE) << "TrigInDetTrackTruthMap found" << endmsg; + m_hasTruthMap = true; + } + } + + + /// get the offline vertices into our structure + + std::vector vertices; + std::vector vertices_rec; + + std::vector refbeamspot; + std::vector testbeamspot; + + /// fetch offline vertices ... + + m_provider->msg(MSG::VERBOSE) << "fetching AOD Primary vertex container" << endmsg; + + if ( !this->select( vertices, "PrimaryVertices" ) ) { + m_provider->msg(MSG::VERBOSE) << "could not retrieve vertex collection " "PrimaryVertices" << std::endl; + } + + /// add the truth particles if needed + + if ( m_mcTruth ) { + eventp->addChain( "Truth" ); + eventp->back().addRoi(TIDARoiDescriptor()); + eventp->back().back().addTracks(selectorTruth.tracks()); + } + + /// now add the vertices + + if ( m_doOffline ) { + for ( unsigned i=0 ; imsg().level() <= MSG::VERBOSE) + m_provider->msg(MSG::VERBOSE) << "vertex " << i << " " << vertices[i] << endmsg; + eventp->addVertex(vertices[i]); + } + } + + /// now add the offline tracks and reco objects + + std::vector offline_tracks; + std::vector electron_tracks; + std::vector muon_tracks; + + std::vector ref_tracks; + std::vector test_tracks; + + offline_tracks.clear(); + electron_tracks.clear(); + muon_tracks.clear(); + + ref_tracks.clear(); + test_tracks.clear(); + + // offline track retrieval now done once for each chain rather than each roi + if ( m_provider->msg().level() <= MSG::VERBOSE ) + m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg; + + bool foundTruth = false; + + // FIXME: most of the different truth selection can go + + if ( !m_doOffline && m_mcTruth ) { + + filter_truth.setRoi( 0 ); // don't filter on RoI yet (or until needed) + + selectorTruth.clear(); + + if ( m_provider->msg().level() <= MSG::VERBOSE ) + m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg; + + if ( m_provider->evtStore()->template contains("INav4MomTruthEvent") ) { + //ESD + this->template selectTracks( &selectorTruth, "INav4MomTruthEvent" ); + foundTruth = true; + } + else if ( m_provider->evtStore()->template contains("SpclMC") ) { + /// AOD + this->template selectTracks( &selectorTruth, "SpclMC"); + foundTruth = true; + } + else if ( m_provider->evtStore()->template contains("TruthParticles") ) { + /// xAOD::TruthParticles + this->template selectTracks( &selectorTruth, "TruthParticles"); + foundTruth = true; + } + else if ( m_provider->evtStore()->template contains("") ) { + /// anything else? + this->template selectTracks( &selectorTruth, ""); + foundTruth = true; + } + else + if ( m_provider->msg().level() <= MSG::VERBOSE ) { + m_provider->msg(MSG::VERBOSE) << "Truth not found - none whatsoever!" << endmsg; + } + } + + if ( !m_doOffline && m_mcTruth && !foundTruth ) { + + if ( m_provider->msg().level() <= MSG::VERBOSE ) { + m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg; + } + + /// selectTracks( &selectorTruth, "INav4MomTruthEvent" ); + + const DataHandle mcevent; + + /// now as a check go through the GenEvent collection + + std::string keys[4] = { "GEN_AOD", "TruthEvent", "", "G4Truth" }; + + std::string key = ""; + + bool foundcollection = false; + + for ( int ik=0 ; ik<4 ; ik++ ) { + + if ( m_provider->msg().level() <= MSG::VERBOSE ) { + m_provider->msg(MSG::VERBOSE) << "Try McEventCollection: " << keys[ik] << endmsg; + } + + if ( !m_provider->evtStore()->template contains(keys[ik]) ) { + if( m_provider->msg().level() <= MSG::VERBOSE ) + m_provider->msg(MSG::VERBOSE) << "No McEventCollection: " << keys[ik] << endmsg; + continue; + } + + if ( m_provider->msg().level() <= MSG::VERBOSE ) + m_provider->msg(MSG::VERBOSE) << "evtStore()->retrieve( mcevent, " << keys[ik] << " )" << endmsg; + + if ( m_provider->evtStore()->template retrieve( mcevent, keys[ik] ).isFailure() ) { + if ( m_provider->msg().level() <= MSG::VERBOSE ) + m_provider->msg(MSG::VERBOSE) << "Failed to get McEventCollection: " << keys[ik] << endmsg; + } + else { + /// found this key + key = keys[ik]; + if(m_provider->msg().level() <= MSG::VERBOSE) + m_provider->msg(MSG::VERBOSE) << "Found McEventCollection: " << key << endmsg; + foundcollection = true; + break; + } + } + + /// not found any truth collection + if ( !foundcollection ) { + if(m_provider->msg().level() <= MSG::VERBOSE) + m_provider->msg(MSG::WARNING) << "No MC Truth Collections of any sort, whatsoever!!!" << endmsg; + + // m_tree->Fill(); + // return StatusCode::FAILURE; + + return; + } + + if ( m_provider->msg().level() <= MSG::VERBOSE ) { + m_provider->msg(MSG::VERBOSE) << "Found McEventCollection: " << key << "\tNevents " << mcevent->size() << endmsg; + } + + McEventCollection::const_iterator evitr = mcevent->begin(); + McEventCollection::const_iterator evend = mcevent->end(); + + unsigned ie = 0; /// count of "events" - or interactions + unsigned ip = 0; /// count of particles + + unsigned ie_ip = 0; /// count of "events with some particles" + + while ( evitr!=evend ) { + + int _ip = 0; /// count of particles in this interaction + + int pid = HepMC::signal_process_id((*evitr)); + + //The logic should be clarified here + if ( pid!=0 ) { /// hooray! actually found a sensible event + + for (auto pitr: *(*evitr) ) { + + selectorTruth.selectTrack( pitr ); + + ++_ip; + + } + + } + ++ie; + ++evitr; + + if ( _ip>0 ) { + /// if there were some particles in this interaction ... + // m_provider->msg(MSG::VERBOSE) << "Found " << ie << "\tpid " << pid << "\t with " << ip << " TruthParticles (GenParticles)" << endmsg; + ++ie_ip; + ip += _ip; + } + } + + if(m_provider->msg().level() <= MSG::VERBOSE){ + m_provider->msg(MSG::VERBOSE) << "Found " << ip << " TruthParticles (GenParticles) in " << ie_ip << " GenEvents out of " << ie << endmsg; + m_provider->msg(MSG::VERBOSE) << "selected " << selectorTruth.size() << " TruthParticles (GenParticles)" << endmsg; + } + + if(selectorTruth.size() > 0) foundTruth = true; + + if ( !(ip>0) ) { + if (m_provider->msg().level() <= MSG::VERBOSE) m_provider->msg(MSG::WARNING) << "NO TRUTH PARTICLES - returning" << endmsg; + return; /// need to be careful here, if not requiring truth *only* should not return + } + + } + + // m_provider->msg(MSG::VERBOSE) << " Offline tracks " << endmsg; + + if ( m_doOffline ) { + + if ( m_provider->evtStore()->template contains("InDetTrackParticles") ) { + this->template selectTracks( m_selectorRef, "InDetTrackParticles" ); + refbeamspot = this->template getBeamspot( "InDetTrackParticles" ); + } + else if (m_provider->evtStore()->template contains("TrackParticleCandidate") ) { + this->template selectTracks( m_selectorRef, "TrackParticleCandidate" ); + } + else if ( m_provider->msg().level() <= MSG::WARNING ) { + m_provider->msg(MSG::WARNING) << " Offline tracks not found " << endmsg; + } + + // set event configuration for tagnprobe + if ( TnP_flag ) { + + // dummy values + double ZmassMin = 40 ; + double ZmassMax = 150 ; + m_TnP_tool->SetEventConfiguration( m_selectorRef, &filterRef, // offline tracks and filter + "Offline", // offline chain name + 0, // trigger object matcher + ZmassMin, ZmassMax ); // set the Zmass range + } + + } + else { + /// what is this ??? + if ( m_mcTruth && foundTruth ){ + + if ( TnP_flag ) { + + // dummy values + double ZmassMin = 40 ; + double ZmassMax = 150 ; + + m_TnP_tool->SetEventConfiguration( &selectorTruth, &filter_truth, // truth tracks and filter + "Truth", // truth chain name + 0, // trigger object matcher + ZmassMin, ZmassMax ); // set the Zmass range + } + + } + } + + // std::cout << "\tloop() loop over chains proper ..." << std::endl; + + /// now loop over all relevant chains to get the trigger tracks... + for ( unsigned ichain=0 ; ichainrequireDecision() ) _decisiontype = TrigDefs::requireDecision; + + + if ( m_chainNames[ichain].passed() ) decisiontype = _decisiontype; + else decisiontype = TrigDefs::alsoDeactivateTEs; + + /// useful debug information to be kept in for the time being + // if ( decisiontype==TrigDefs::requireDecision ) std::cout << "\tSUTT TrigDefs::requireDecision " << decisiontype << std::endl; + // if ( decisiontype==TrigDefs::Physics ) std::cout << "\tSUTT TrigDefs::Physics " << decisiontype << std::endl; + + if ( chainname!="" && m_provider->msg().level() <= MSG::VERBOSE ) { + + m_provider->msg(MSG::VERBOSE) << "status for chain " << chainname + << "\tpass " << (*m_tdt)->isPassed(chainname) + << "\tprescale " << (*m_tdt)->getPrescale(chainname) << endmsg; + + m_provider->msg(MSG::VERBOSE) << "fetching features for chain " << chainname << endmsg; + + m_provider->msg(MSG::VERBOSE) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << endmsg; + } + + /// useful debug information to be kept in + // std::cout << "\tstatus for chain " << chainname + // << "\tpass " << (*m_tdt)->isPassed( chainname ) + // << "\tpassdt " << (*m_tdt)->isPassed( chainname, decisiontype ) + // << "\tprescale " << (*m_tdt)->getPrescale( chainname ) << std::endl; + + + // m_provider->msg(MSG::INFO) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << "\t" << m_chainNames[ichain] << "\trun " << run_number << "\tevent " << event_number << endmsg; + + + if ( chainname!="" && !this->m_keepAllEvents && !(*m_tdt)->isPassed( chainname, decisiontype ) ) continue; + + + /// Get chain combinations and loop on them + /// - loop made on chain selected as the one steering RoI creation + // Trig::FeatureContainer f = (*m_tdt)->features( chainname, TrigDefs::alsoDeactivateTEs); + + /// only use the TDT for extracting collections if this was a trigger analysis + /// for fullscan "offline" type analyses (ie fullscan FTK) do not use this + + // tag and probe analysis processes multiple chains passed in the tag and probe tool at once so loop over vector of chains + std::vector chainNames ; + + if ( !TnP_flag ) { + chainNames.push_back(m_chainNames[ichain].raw()) ; + } + else { + chainNames.push_back(m_TnP_tool->tag()) ; + chainNames.push_back(m_TnP_tool->probe()) ; + } + + // loop over new chainNames vector but doing the same stuff + for ( unsigned i = 0 ; i < chainNames.size() ; ++i ) { + + ChainString chainConfig = chainNames[i] ; + std::string chainName = chainConfig.head(); + + eventp->addChain( chainNames[i] ); + + TIDA::Chain& chain = eventp->back(); + + if ( chainName == "" ) { + + /// do we still want the blind chain access for track collections ??? + + m_selectorTest->clear(); + + /// dummy full scan chain + + // TIDARoiDescriptor roifs(true); + + // chain.addRoi( roifs ); + + chain.addRoi( TIDARoiDescriptor(true) ); + + if ( m_provider->evtStore()->template contains(key) ) { + this->template selectTracks( m_selectorTest, key ); + refbeamspot = this->template getBeamspot( key ); + } + + const std::vector& testtracks = m_selectorTest->tracks(); + + chain.back().addTracks(testtracks); + + if ( vtx_name!="" ) { + + /// MT Vertex access + + m_provider->msg(MSG::VERBOSE) << "\tFetch xAOD::VertexContainer with key " << vtx_name << endmsg; + + std::vector tidavertices; + + if ( this->select( tidavertices, vtx_name ) ) chain.back().addVertices( tidavertices ); + } + + + // if ( roiInfo ) delete roiInfo; + + } + else { + + /// new Roi based feature access + + //std::string roi_key = m_chainNames[ichain].roi(); + + std::string roi_key = chainConfig.roi(); + + // if ( roi_key=="" ) roi_key = "forID"; + // if ( roi_key=="" ) roi_key = ""; + + + unsigned feature_type =TrigDefs::lastFeatureOfType; + + if ( roi_key!="" ) feature_type= TrigDefs::allFeaturesOfType; + + /// new FeatureRequestDescriptor with leg access + + int leg = -1; + + if ( chainConfig.element()!="" ) { + leg = std::atoi(chainConfig.element().c_str()); + } + + std::vector< TrigCompositeUtils::LinkInfo > rois = + (*m_tdt)->template features( Trig::FeatureRequestDescriptor( chainName, + decisiontype, + roi_key, + feature_type, + "roi", + leg ) ); + + // const unsigned int featureCollectionMode = const std::string& navElementLinkKey = "roi") const; + + int iroi = 0; /// count of how many rois processed so far + + for ( const TrigCompositeUtils::LinkInfo& roi_info : rois ) { + + iroi++; + + /// don't extract any additional rois if a superRoi is requested: + /// In this case, the superRoi would be shared between the different + /// chains + + if ( roi_key=="SuperRoi" && iroi>1 ) continue; + + // std::cout << "\troi: get link " << roi_key << " ..." << std::endl; + + const ElementLink roi_link = roi_info.link; + + /// check this is not a spurious TDT match + if ( roi_key!="" && roi_link.dataID()!=roi_key ) continue; + + const TrigRoiDescriptor* const* roiptr = roi_link.cptr(); + + if ( roiptr == 0 ) { + continue; + } + + /// for debug ... + // std::cout << "\troi: link deref ..." << *roiptr << std::endl; + + if (m_provider->msg().level() <= MSG::VERBOSE) { + m_provider->msg(MSG::VERBOSE) << " RoI descriptor for seeded chain " << chainname << " " << **roiptr << endmsg; + } + + TIDARoiDescriptor* roiInfo = new TIDARoiDescriptor( TIDARoiDescriptorBuilder(**roiptr) ); + + // if ( dbg ) std::cout << "\troi " << iroi << " " << *roiInfo << std::endl; + + /// get the tracks + + m_selectorTest->clear(); + + if ( this->template selectTracks( m_selectorTest, roi_link, key ) ) { } + + // beamspot stuff not needed for xAOD::TrackParticles + + /// create analysis chain + + chain.addRoi( *roiInfo ); + + /// get tracks + + const std::vector& testtracks = m_selectorTest->tracks(); + + chain.back().addTracks(testtracks); + + + /// now get the vertices + + if ( vtx_name!="" ) { + + std::vector tidavertices; + + this->select( tidavertices, roi_link, vtx_name ); + + chain.back().addVertices( tidavertices ); + + } /// retrieve online vertices + + +#if 0 + if ( dbg ) { + std::cout << "\tTIDA analysis for chain: " << chainname << "\t key: " << key << "\t" << **roiptr << std::endl; + std::cout << "\tcollections: " << chain.back() << std::endl; + } +#endif + + if ( roiInfo ) delete roiInfo; + + } + + + } /// "offline" of "roi" type chains + + } // end of loop chainNames vector loop + + + if ( m_provider->msg().level() <= MSG::VERBOSE ) { + m_provider->msg(MSG::VERBOSE) << "event: " << *eventp << endmsg; + } + + } + + // close previous loop over chains and open new one + + for ( unsigned ichain=0 ; ichainsize() ; ichain++ ) { + + TIDA::Chain& chain = (*eventp)[ichain]; + ChainString chainConfig(chain.name()); + const std::string& vtx_name = chainConfig.vtx(); + + // skip tag chains to avoid performing standard analysis on them (done for tnp at the same time as probes) + if ( TnP_flag && chainConfig.extra().find("_tag")!=std::string::npos ) continue ; + + std::vector rois ; + + if (TnP_flag) { + rois = m_TnP_tool->GetRois( eventp->chains() ); + // needs to be done AFTER retrieving offline tracks as m_selectorRef passed as arguement, hence restructuring + } + else { + rois.reserve( chain.size() ); + for ( size_t ir=0 ; irFill( m_invmass, m_invmass_obj, iroi ) ; + } + + if ( this->filterOnRoi() ) { + filterRef.setRoi( &(rois.at(iroi)->roi() ) ); + filterRef.containtracks( m_containTracks ); + } + else filterRef.setRoi( 0 ); + + test_tracks.clear(); + + // this block is before the track retrieval in the original, is it working the same here? + + /// This is nonsense and needs restructuring - why is the truth and offline selection + /// done within this RoI loop? It means the complete offline and truth tracks will be + /// retrieved for every RoI ! really we should have the structure + /// + /// - check_a_trigger_chain_has_passed + /// - get_offline_or_truth_particles + /// - loop_over_rois + /// - get_trigger_tracks + /// - filter_offline_or_truth_reference + /// - match_tracks + /// - call_analyis_routine + /// + /// will leave as it is for the time being + + if ( m_provider->msg().level() <= MSG::VERBOSE ) + m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg; + + if ( !m_doOffline && m_mcTruth ) { + if ( this->filterOnRoi() ) filter_truth.setRoi( &(rois.at(iroi)->roi() ) ); + ref_tracks = m_selectorRef->tracks(&filter_truth); + } + else { // ie. if ( m_doOffline ) + ref_tracks = m_selectorRef->tracks(&filterRef) ; + } + + if ( m_provider->msg().level() <= MSG::VERBOSE ) { + m_provider->msg(MSG::VERBOSE) << "ref tracks.size() " << m_selectorRef->tracks().size() << endmsg; + for ( int ii=m_selectorRef->tracks().size() ; ii-- ; ) { + m_provider->msg(MSG::VERBOSE) << " ref track " << ii << " " << *m_selectorRef->tracks()[ii] << endmsg; + } + } + + test_tracks.clear(); + + + for ( unsigned itrk=0 ; itrktracks().size() ; itrk++ ) { + test_tracks.push_back(&(rois.at(iroi)->tracks().at(itrk))); + } + + /// debug ... + // std::cout << "sutt track multiplicities: offline " << offline_tracks.size() << "\ttest " << test_tracks.size() << std::endl; + + _analysis->setvertices( vertices.size() ); /// what is this for ??? + + if ( refbeamspot.size()>0 ) _analysis->setBeamRef( refbeamspot ); + if ( testbeamspot.size()>0 ) _analysis->setBeamTest( testbeamspot ); + + /// if we want a purity, we need to swap round which tracks are the + /// reference tracks and which the test tracks + + if ( m_runPurity ) { + + if ( this->getUseHighestPT() ) HighestPTOnly( test_tracks ); + + if ( m_pTthreshold>0 ) FilterPT( test_tracks, m_pTthreshold ); + + /// stats book keeping + m_NRois++; + m_NRefTracks += test_tracks.size(); + m_NTestTracks += ref_tracks.size(); + + + /// match test and reference tracks + m_associator->match( test_tracks, ref_tracks ); + + _analysis->execute( test_tracks, ref_tracks, m_associator, eventp ); + + } + else { + + /// filter on highest pt track only if required + if ( this->getUseHighestPT() ) HighestPTOnly( ref_tracks ); + + /// ignore all tracks belong the specific analysis pt threshold if set + + if ( m_pTthreshold>0 ) FilterPT( ref_tracks, m_pTthreshold ); + + /// stats book keeping + m_NRois++; + m_NRefTracks += ref_tracks.size(); + m_NTestTracks += test_tracks.size(); + + /// match test and reference tracks + m_associator->match( ref_tracks, test_tracks ); + + _analysis->setroi( &rois.at(iroi)->roi() ); + _analysis->execute( ref_tracks, test_tracks, m_associator, eventp ); + + if ( vtx_name!="" ) { + /// get vertices for this roi - have to copy to a vector + std::vector vr = rois.at(iroi)->vertices(); + std::vector vtx_rec; + for ( unsigned iv=0 ; iv vtx; + if ( this->getVtxIndex()<0 ) { + for ( unsigned iv=0 ; ivunsigned(this->getVtxIndex()) ) vtx.push_back( &vertices[this->getVtxIndex()] ); + } + + _analysis->execute_vtx( vtx, vtx_rec, eventp ); + } + + } + + if ( _analysis->debug() ) { + m_provider->msg(MSG::INFO) << "Missing track for " << m_chainNames[ichain] + << "\trun " << run_number + << "\tevent " << event_number + << "\tlb " << lumi_block << endmsg; + } + + } + + } + + if ( m_provider->msg().level() <= MSG::VERBOSE ) { + m_provider->msg(MSG::VERBOSE) << "\n\nEvent " << *eventp << endmsg; + } + } + + + + virtual void book() { + + if(m_provider->msg().level() <= MSG::VERBOSE) + m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::book() " << name() << endmsg; + + // get the TriggerDecisionTool + + if( m_tdt->retrieve().isFailure() ) { + if(m_provider->msg().level() <= MSG::ERROR) + m_provider->msg(MSG::ERROR) << " Unable to retrieve the TrigDecisionTool: Please check job options file" << endmsg; + return; + } + + if(m_provider->msg().level() <= MSG::VERBOSE) { + m_provider->msg(MSG::VERBOSE) << " Successfully retrived the TrigDecisionTool" << endmsg; + } + + + /// get list of configured triggers + if (m_provider->msg().level() <= MSG::VERBOSE) { + std::vector configuredChains = (*(m_tdt))->getListOfTriggers("L2_.*, EF_.*, HLT_.*"); + + m_provider->msg(MSG::VERBOSE) << "Configured chains" << endmsg; + for ( unsigned i=0 ; imsg().level() <= MSG::VERBOSE) + m_provider->msg(MSG::VERBOSE) << " Chain " << configuredChains[i] << endmsg; + } + } + + + for ( unsigned ic=0 ; ic0 ) { + m_provider->msg(MSG::WARNING) << "more than one chain configured for this analysis - skipping " << m_chainNames[ic] << endmsg; + continue; + } + + m_provider->msg(MSG::VERBOSE) << "Analyse chain " << m_chainNames[ic] << endmsg; + + // m_provider->msg(MSG::VERBOSE) << "--------------------------------------------------" << endmsg; + + std::string folder_name = ""; + + if ( name()!="" ) folder_name = name(); + else folder_name = "HLT/TRIDT/IDMon"; + + /// don't use test_type now ? + if( m_testType != "" ) folder_name = folder_name + "/" + m_testType; + + std::string mongroup; + + if ( name().find("Shifter")!=std::string::npos || m_shifter ) { + /// shifter histograms - do not encode chain names + if ( m_chainNames.at(ic).tail().find("_FTF") != std::string::npos ) mongroup = folder_name + "/FTF"; + else if ( m_chainNames.at(ic).tail().find("_IDTrig") != std::string::npos || + m_chainNames.at(ic).tail().find("_EFID") != std::string::npos ) mongroup = folder_name + "/EFID"; + else if ( m_chainNames.at(ic).tail().find("InDetTrigParticle") != std::string::npos ) mongroup = folder_name + "/EFID_RUN1"; + else if ( m_chainNames.at(ic).tail().find("_GSF") != std::string::npos ) mongroup = folder_name + "/GSF"; + else mongroup = folder_name + "/Unknown"; + + if ( m_chainNames.at(ic).vtx()!="" ) mongroup += "/" + m_chainNames.at(ic).vtx(); + + } + else { + /// these are the Expert / non-Shifter histograms - encode the full chain names + + if ( m_chainNames[ic].head() == "" ) mongroup = folder_name + "/Fullscan"; + else mongroup = folder_name + "/" + m_chainNames[ic].head(); + std::string track_collection = ""; + + if ( m_chainNames.at(ic).tail()!="" ) { + track_collection = "/" + m_chainNames.at(ic).tail(); + if ( m_chainNames.at(ic).extra()!="" ) track_collection += "_" + m_chainNames.at(ic).extra(); + } + + if ( m_chainNames.at(ic).roi()!="" ) { + if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].roi(); + else track_collection = "/" + m_chainNames[ic].roi(); + } + + if ( m_chainNames.at(ic).vtx()!="" ) { + if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].vtx(); + else track_collection = "/" + m_chainNames[ic].vtx(); + } + + /// add trigger element and roi descriptor names + if ( m_chainNames.at(ic).element()!="" ) { + if ( track_collection!="" ) track_collection += "_" + m_chainNames[ic].element(); + else track_collection = "/" + m_chainNames[ic].element(); + } + + if ( track_collection!="" ) mongroup += track_collection; + + if ( !m_chainNames.at(ic).passed() ) mongroup += "/DTE"; + + // std::cout << "\n SUTT chain " << m_chainNames.at(ic) << "\tvtx " << m_chainNames.at(ic).vtx() << "\tmongroup " << mongroup << std::endl; + + } + + // std::cout << "SUTT chain " << "\tvtx " << m_chainNames.at(ic).vtx() << "\tmongroup " << mongroup << std::endl; + + m_provider->msg(MSG::VERBOSE) << " book mongroup " << mongroup << endmsg; + + _analysis = dynamic_cast(m_analysis); + + if ( monTool() ) _analysis->set_monTool( monTool() ); + + m_analysis->initialise(); + + if(m_provider->msg().level() <= MSG::VERBOSE) { + m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::book() done" << endmsg; + } + } + + } + + + + virtual void finalize() { + + if(m_provider->msg().level() <= MSG::VERBOSE){ + m_provider->msg(MSG::VERBOSE) << "AnalysisConfigR3_Tier0::finalise() " << m_provider->name() << endmsg; + } + + m_analysis->finalise(); + + // deleting instance of TnP_tool and setting pointer to null + if ( m_TnP_tool != 0 ) { + delete m_TnP_tool ; + m_TnP_tool = 0 ; + } + + m_provider->msg(MSG::INFO) << m_provider->name() << " " << m_chainNames[0] << " \tNRois processed: " << m_NRois << "\tRef tracks: " << m_NRefTracks << "\tTestTracks: " << m_NTestTracks << endmsg; + + if(m_provider->msg().level() <= MSG::VERBOSE) { + m_provider->msg(MSG::VERBOSE) << m_provider->name() << " finalised" << endmsg; + } + } + + +protected: + + bool m_useBeamCondSvc; + + TFile* mFile; + TTree* mTree; + + std::vector m_chainNames; + std::vector m_analyses; + std::string m_testType; + + bool m_doOffline; + bool m_doMuons; + bool m_doElectrons; + bool m_doTaus; + bool m_doBjets; + bool m_hasTruthMap; + bool m_doTauThreeProng; + bool m_tauEtCutOffline; + + std::string m_outputFileName; + + /// output stats + int m_NRois; + int m_NRefTracks; + int m_NTestTracks; + + bool m_runPurity; + + bool m_shifter; + + double m_pTthreshold; + + bool m_first; + + bool m_containTracks; + + TagNProbe* m_TnP_tool ; + + ToolHandle* m_monTool; + + TIDA::Histogram* m_invmass; + TIDA::Histogram* m_invmass_obj; + +}; + + + +#endif // TrigInDetAnalysisExample_T_AnalysisConfigR3_Tier0_H + diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfig_Tier0.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfig_Tier0.h index 747f4954143..1459ae9c9bf 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfig_Tier0.h +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfig_Tier0.h @@ -31,6 +31,7 @@ #include "TrigInDetAnalysisExample/Analysis_Tier0.h" #include "TrigInDetAnalysisExample/VtxAnalysis.h" #include "TrigInDetAnalysisExample/ChainString.h" +#include "TrigInDetAnalysisExample/TIDATools.h" #include "TTree.h" #include "TFile.h" @@ -82,49 +83,6 @@ -template -void HighestPTOnly( std::vector& tracks ) { - - if ( tracks.size()>1 ) { - - std::vector tmp_tracks; - - int ih = 0; - - for ( unsigned i=1 ; ipT())>std::fabs(tracks[ih]->pT()) ) ih = i; - } - - tmp_tracks.push_back( tracks[ih] ); - - tracks = tmp_tracks; - } -} - - - - - - -template -void FilterPT( std::vector& tracks, double pt ) { - - std::vector tmp_tracks; - - tmp_tracks.reserve( tracks.size() ); - - for ( unsigned i=0 ; ipT())>=pt ) tmp_tracks.push_back( tracks[i] ); - } - - if ( tmp_tracks.size() class T_AnalysisConfig_Tier0 : public T_AnalysisConfig { diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TrigTestBase.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TrigTestBase.h index 8479a151ee8..c7a7f1b53d2 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TrigTestBase.h +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/TrigTestBase.h @@ -127,8 +127,6 @@ protected: std::vector*> m_sequences; - std::vector m_TnP_tools; - std::vector m_chainNames; std::vector m_ntupleChainNames; std::string m_releaseMetaData; @@ -180,9 +178,6 @@ protected: bool m_legacy; - // Gaudi::Property m_sliceTagArse{this, "SliceTag", "TIDAMonTool/"}; - - }; diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/VtxR3Analysis.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/VtxR3Analysis.h new file mode 100644 index 00000000000..9da742ffee8 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/VtxR3Analysis.h @@ -0,0 +1,93 @@ +/* emacs: this is -*- c++ -*- */ +/** + ** @file VtxR3Analysis.h + ** + ** @author mark sutton + ** @date Sun 6 Feb 2022 00:02:23 CEST + ** + ** Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + **/ + + +#ifndef VTXR3ANALYSIS_H +#define VTXR3ANALYSIS_H + +#include +#include + +#include "TrigInDetAnalysis/VertexAnalysis.h" +#include "TrigInDetAnalysis/TIDDirectory.h" +#include "TrigInDetAnalysisExample/TIDAHistogram.h" + + + +class VtxR3Analysis : public VertexAnalysis { + +public: + + VtxR3Analysis( const std::string& n ); + + virtual ~VtxR3Analysis() { } // if ( mdir ) delete mdir; } + + void initialise(); + + void execute(const std::vector& vtx0, + const std::vector& vtx1, + const TIDA::Event* te=0); + + void finalise(); + + void set_monTool( ToolHandle* m ) { m_monTool=m; } + + ToolHandle* monTool() { return m_monTool; } + +private: + + bool m_initialised; + + ToolHandle* m_monTool; + + // TIDDirectory* mdir; + + TIDA::Histogram* m_hnvtx; + TIDA::Histogram* m_hzed; + TIDA::Histogram* m_hntrax; + + TIDA::Histogram* m_hnvtx_rec; + TIDA::Histogram* m_hzed_rec; + TIDA::Histogram* m_hntrax_rec; + + TIDA::Histogram* m_hzed_res; + + TIDA::Histogram* m_rdz_vs_zed; + TIDA::Histogram* m_rdz_vs_ntrax; + TIDA::Histogram* m_rdz_vs_nvtx; + //No currently used + //but retained in case + //TIDA::Histogram* m_rdz_vs_mu; + + TIDA::Histogram* m_eff_zed; + TIDA::Histogram* m_eff_ntrax; + TIDA::Histogram* m_eff_nvtx; + TIDA::Histogram* m_eff_mu; + TIDA::Histogram* m_eff_lb; + +}; + + +inline std::ostream& operator<<( std::ostream& s, const VtxR3Analysis& ) { + return s; +} + + +#endif // VTXR3ANALYSIS_H + + + + + + + + + + diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/TIDAChains.py b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/TIDAChains.py new file mode 100644 index 00000000000..4287eb91f81 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/TIDAChains.py @@ -0,0 +1,78 @@ +# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + +# access the list of configured chains and expand the analysis chains +# to be actual configued entries + + +# get the list of configured chains matching the regex +# input parameter + +import re + + +# get a chain configuration of the form "some_regex:key=Track:vtx=Vertex" etc +# parse to determine the trigger chain pattern, determine the chains +# matching the pattern, then recreate the full analysis string using all the +# matched chains - can take an individual analysis pattern, or a list of them + +def getchains( analyses ): + + if isinstance( analyses, list ): + a = analyses + else: + a = [ analyses ] + + chains = [] + + for analysis in a: + if ":" in analysis: + + parts = analysis.split( ":", 1 ) + cchains = getconfiguredchains( parts[0] ) + + for c in cchains: + if parts[1] is not None: + chain = c + ":" + parts[1] + else: + chain = c + + chains.append( chain ) + + return chains + + + +# cached full chain list + +_chains = None + +def getconfiguredchains( regex ): + +# print ("getconfiguredchains: ", regex ) + + global _chains + +# from datetime import datetime + + if _chains is None : +# print( datetime.now(), "getting trigger configuration" ) + + from AthenaConfiguration.AllConfigFlags import ConfigFlags + from TrigConfigSvc.TriggerConfigAccess import getHLTMenuAccess + + _chains = getHLTMenuAccess( ConfigFlags ) + +# print( datetime.now(), "configured chains: ", len(_chains) ) + + chains = [] + for c in _chains: + # print( c ) + chain = re.findall( regex, c ) + for a in chain: + if a is not None and c == a : + chains.append( a ) + + return chains + + + diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/TIDAMonTool.py b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/TIDAMonTool.py new file mode 100644 index 00000000000..91c5a62b870 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/TIDAMonTool.py @@ -0,0 +1,458 @@ +# +# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +# +# create all the histograms for each analysis - this will get called once for each +# configured chain - we can set the HistPath either already here, or from the c++ +# code + + +def monitoring( name ) : + +# print( "SUTT creating monitoring: ", name ) + + tools = [] + + from TrigInDetAnalysisExample.TrigInDetAnalysisExampleConf import TrigR3Mon + from TrigInDetAnalysisExample.TIDAChains import getchains + + + + #### electron #### + + tidaegamma = TrigR3Mon(name = "IDEgammaTool" ) + tidaegamma.AnalysisConfig = "Tier0" + tidaegamma.SliceTag = "HLT/TRIDT/Egamma/Expert" + tidaegamma.UseHighestPT = True + + chains = getchains( [ "HLT_e.*idperf.*:key=HLT_IDTrack_Electron_FTF:roi=HLT_Roi_FastElectron", + "HLT_e.*idperf.*:key=HLT_IDTrack_Electron_IDTrig", + "HLT_e.*gsf.*:key=HLT_IDTrack_Electron_GSF", + "HLT_e26_lhtight_ivarloose_e5_lhvloose_idperf_probe_L1EM22VHI:key=HLT_IDTrack_Electron_FTF:roi=HLT_Roi_FastElectron:extra=el0_tag:te=0", + "HLT_e26_lhtight_ivarloose_e5_lhvloose_idperf_probe_L1EM22VHI:key=HLT_IDTrack_Electron_FTF:roi=HLT_Roi_FastElectron:extra=el0_probe:te=1", + "HLT_e26_lhtight_e14_etcut_idperf_probe_50invmAB130_L1eEM26M:key=HLT_IDTrack_Electron_FTF:roi=HLT_Roi_FastElectron:extra=el1_tag:te=0", + "HLT_e26_lhtight_e14_etcut_idperf_probe_50invmAB130_L1eEM26M:key=HLT_IDTrack_Electron_FTF:roi=HLT_Roi_FastElectron:extra=el1_probe:te=1", + "HLT_e26_lhtight_e14_etcut_idperf_probe_50invmAB130_L1EM22VHI:key=HLT_IDTrack_Electron_FTF:roi=HLT_Roi_FastElectron:extra=el2_tag:te=0", + "HLT_e26_lhtight_e14_etcut_idperf_probe_50invmAB130_L1EM22VHI:key=HLT_IDTrack_Electron_FTF:roi=HLT_Roi_FastElectron:extra=el2_probe:te=1" ] ) + + tidaegamma.ntupleChainNames = chains + + tidaegamma.MonTools = createMonTools( tidaegamma.SliceTag, chains ) + + tools += [ tidaegamma ] + + + + + #### LRT Egamma #### + + tidaegammalrt = TrigR3Mon(name = "IDEgammaLRTTool" ) + + tidaegammalrt.AnalysisConfig = "Tier0" + tidaegammalrt.SliceTag = "HLT/TRIDT/Egamma/Expert" + + + chains = getchains( [ "HLT_e.*idperf_loose_lrtloose.*:HLT_IDTrack_ElecLRT_FTF:HLT_Roi_FastElectron_LRT", + "HLT_e.*idperf_loose_lrtloose.*:HLT_IDTrack_ElecLRT_IDTrig:HLT_Roi_FastElectron_LRT" ] ) + + tidaegammalrt.ntupleChainNames = chains + + tidaegammalrt.MonTools = createMonTools( tidaegammalrt.SliceTag, chains ) + + tools += [ tidaegammalrt ] + + + + + #### muon #### + + tidamuon = TrigR3Mon(name = "IDMuonTool" ) + tidamuon.AnalysisConfig = "Tier0" + tidamuon.SliceTag = "HLT/TRIDT/Muon/Expert" + tidamuon.UseHighestPT = True + + chains = getchains( [ "HLT_mu.*idperf.*:key=HLT_IDTrack_Muon_FTF:roi=HLT_Roi_L2SAMuon", + "HLT_mu.*idperf.*:key=HLT_IDTrack_Muon_IDTrig:roi=HLT_Roi_L2SAMuon", + "HLT_mu.*ivarperf.*:key=HLT_IDTrack_MuonIso_FTF:roi=HLT_Roi_MuonIso", + "HLT_mu.*ivarperf.*:key=HLT_IDTrack_MuonIso_IDTrig:roi=HLT_Roi_MuonIso" ] ) + + + tidamuon.ntupleChainNames += chains + + tidamuon.MonTools = createMonTools( tidamuon.SliceTag, chains ) + + + tools += [ tidamuon ] + + + + + #### tau #### + + tidatau = TrigR3Mon(name = "IDTauTool" ) + tidatau.AnalysisConfig = "Tier0" + tidatau.SliceTag = "HLT/TRIDT/Tau/Expert" + tidatau.UseHighestPT = True + + chains = getchains( [ "HLT_tau.*idperf.*tracktwo.*:key=HLT_IDTrack_TauCore_FTF:roi=HLT_Roi_TauCore", + "HLT_tau.*idperf.*tracktwo.*:key=HLT_IDTrack_TauIso_FTF:roi=HLT_Roi_TauIso", + "HLT_tau.*idperf.*tracktwo.*:key=HLT_IDTrack_Tau_IDTrig:roi=HLT_Roi_TauIso", + "HLT_tau.*idperf.*BDT.*:key=HLT_IDTrack_TauIso_FTF:roi=HLT_Roi_TauIsoBDT", + "HLT_tau.*idperf.*BDT.*:key=HLT_IDTrack_Tau_IDTrig:roi=HLT_Roi_TauIsoBDT" ] ) + + tidatau.ntupleChainNames += chains + + tidatau.MonTools = createMonTools( tidatau.SliceTag, chains ) + + tools += [ tidatau ] + + + + + #### bjets #### + + tidabjet = TrigR3Mon(name = "IDBjetTool" ) + tidabjet.AnalysisConfig = "Tier0" + tidabjet.SliceTag = "HLT/TRIDT/Bjet/Expert" + + chains = getchains( [ "HLT_j45_ftf_L1J15:key=HLT_IDTrack_FS_FTF:roi=HLT_FSRoI:vtx=HLT_IDVertex_FS", + "HLT_j.*_ftf.*boffperf.*:key=HLT_IDTrack_FS_FTF:roi=HLT_FSRoI:vtx=HLT_IDVertex_FS", + "HLT_j.*.*boffperf.*:key=HLT_IDTrack_Bjet_FTF", + "HLT_j.*.*boffperf.*:key=HLT_IDTrack_Bjet_IDTrig" ] ) + + tidabjet.ntupleChainNames += chains + + tidabjet.MonTools = createMonTools( tidabjet.SliceTag, chains ) + + tools += [ tidabjet ] + + + return tools + + + + + + +# create a separate specific monTool for each analysis chain +# - simplifies the overall analysis configuration + +def createMonTools( tag, chains ) : + tools = [] +# print( "chains size: ", len(chains) ) + for mt in chains : + # print( " ", mt ) + tool = createMonTool( tag, mt ) + tools += [ tool ] + return tools + + + +# generate the mongroup hist path from the analysis string + +def monGroup( analysis_chain ) : + + from TrigInDetAnalysisExample.chainString import chainString + + chain = chainString( analysis_chain ) + + mg = "" + + if chain.head == "" : + mg = "/Fullscan" + else : + mg = "/"+chain.head + + mg += "/"+chain.tail + + if chain.extra != "" : + mg += "_" + chain.extra + + if chain.roi != "" : + mg += "_"+chain.roi + + if chain.vtx != "" : + mg += "_"+chain.vtx + + if chain.element != "" : + mg += "_" + chain.element + + if chain.passed : + mg += "/DTE" + + return mg + + + +# wrapper around montool.defineHistogram to simplify the required histogram names +# eg for a TProfile, automatically add the second variable, and create the histogram +# alias to avoid having to write pages of tedious boier plate functions +# FIXME: if there is some way to pass in the variables to avoid the horrible +# "if" statements with the different numbers of arguments, that would be great + +def defineHisto( montool, name, path, type, title, xbins, xmin=None, xmax=None, xlabels=None, weight=None ) : + + if type == "TProfile" : + name = name + "," + name + "_weight;" + name + + if xmin is None : + if xlabels is None : + montool.defineHistogram( name, path=path, type=type, title=title, xbins=xbins ) + else: + montool.defineHistogram( name, path=path, type=type, title=title, xbins=xbins, xlabels=xlabels ) + else : + if xlabels is None : + montool.defineHistogram( name, path=path, type=type, title=title, xbins=xbins, xmin=xmin, xmax=xmax ) + else : + montool.defineHistogram( name, path=path, type=type, title=title, xbins=xbins, xmin=xmin, xmax=xmax, xlabels=xlabels, weight=weight ) + + +# actuall create the monTool to go along with a specifi chain +# stores the histogram, binning, creates all the histograms etc + +def createMonTool( slicetag, chain ) : + + from AthenaMonitoringKernel.GenericMonitoringTool import GenericMonitoringTool + + monTool = GenericMonitoringTool( chain ) + + mypath = "EXPERT" + + # monTool.HistPath would this be better set in the c++ code ? + + from TrigInDetAnalysisExample.chainString import chainString + + cs = chainString( chain ) + + monTool.HistPath = slicetag + monGroup(chain) + +# print( "TIDAMonTool.py CreateMonTool ", chain, " path:", monTool.HistPath ) + + ptbins = [ 1, 1.20226, 1.44544, 1.7378, 2.0893, 2.51189, 3.01995, 3.63078, 4.36516, 5.24807, 6.30957, + 7.58578, 9.12011, 10.9648, 13.1826, 15.8489, 19.0546, 22.9087, 27.5423, 33.1131, 39.8107, + 47.863, 57.544, 69.1831, 83.1764, 100 ] + + vnbins = [ + -0.5, + 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, + 13.5, 14.5, 15.5, 17.5, 18.5, 19.5, 21.5, 23.5, 24.5, 26.5, 28.5, 30.5, 32.5, + 35.5, 37.5, 40.5, 43.5, 46.5, 50.5, 53.5, 57.5, 61.5, 66.5, 71.5, 76.5, 81.5, + 87.5, 93.5, 100.5, 107.5, 114.5, 123.5, 131.5, 141.5, 150.5, 161.5, 172.5, 185.5, 198.5, + 211.5, 226.5, 242.5, 259.5, 277.5, 297.5, + 317.5, 340.5, 363.5, 389.5, 416.5, 445.5, 476.5, 509.5, + 544.5, 582.5, 623.5, 666.5, 713.5, 762.5, 815.5, 872.5, 933.5, 998.5, 1067.5, + 1141.5, 1221.5, 1305.5, 1396.5, 1493.5, 1597.5, + 1708.5, 1827.5, 1953.5, 2089.5, + 2234.5, 2389.5, 2555.5, + 2733.5, 2923.5, 3125.5, + 3342.5, 3574.5, + 3823.5, 4088.5, + 4372.5, 4675.5, + 5000.5 + ] + + d0bins = [ -5.0, -4.0, -3.0, -2.5, + -2.0, -1.8, -1.6, -1.4, -1.2, + -1.05, -0.95, -0.85, -0.75, -0.65, -0.55, -0.45, -0.35, -0.25, -0.15, -0.05, + 0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, + 1.2, 1.4, 1.6, 1.8, 2.0, + 2.5, 3.0, 4.0, 5.0 ] + + if "LRT" in chain : + d0bins = [ -100.5, -97.5, -93.5, -90.5, + -86.5, -83.5, -80.5, + -77.5, -74.5, -71.5, + -69.5, -66.5, -63.5, -61.5, + -59.5, -57.5, -54.5, -52.5, -50.5, + -49.5, -47.5, -45.5, -43.5, -42.5, -40.5, + -39.5, -37.5, -36.5, -34.5, -33.5, -32.5, -31.5, + -29.5, -28.5, -27.5, -26.5, -25.5, -24.5, -23.5, -22.5, -21.5, -20.5, + -19.5, -18.5, -17.5, -16.5, -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, + -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, + 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, + 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, + 20.5, 21.5, 22.5, 23.5, 24.5, 25.5, 26.5, 27.5, 28.5, 29.5, + 31.5, 32.5, 33.5, 34.5, 36.5, 37.5, 39.5, + 40.5, 42.5, 43.5, 45.5, 47.5, 49.5, + 50.5, 52.5, 54.5, 57.5, 59.5, + 61.5, 63.5, 66.5, 69.5, + 71.5, 74.5, 77.5, + 80.5, 83.5, 86.5, + 90.5, 93.5, 97.5, + 100.5 ] + +# use a rounded up float(M_PI) values to overcome edge effects of using float +# values - will math.pi be appropriate ? double(float(M_PI)) > M_PI so it would +# depend on whether floats or double are used for the histogram limits in the +# histograms in defineHistogram +# pi = 3.14159265359 + pi = 3.14159275 + + binlabels = [ "Nrois", "Nevents", "N ref tracks", "N matched tracks", "N total test tracks" ] + + + defineHisto( monTool, "Chain", weight="Chain_weight", path=mypath, type="TH1F", title=chain, xlabels=binlabels, xbins=5, xmin=0, xmax=5 ) + + defineHisto( monTool, "reftrk_N", path=mypath, type="TH1F", title="Reference tracks", xbins=vnbins ) + + defineHisto( monTool, "reftrk_pT", path=mypath, type="TH1F", title="Reference track pT", xbins=ptbins ) + defineHisto( monTool, "reftrk_phi", path=mypath, type="TH1F", title="Reference track Phi", xbins=25, xmin=-pi, xmax=pi ) + defineHisto( monTool, "reftrk_eta", path=mypath, type="TH1F", title="Reference track Eta", xbins=25, xmin=-2.5, xmax=2.5 ) + + if "LRT" in chain: + defineHisto( monTool, "reftrk_d0", path=mypath, type="TH1F", title="Reference track d0", xbins=201, xmin=-100.0, xmax=100.0 ) + else: + defineHisto( monTool, "reftrk_d0", path=mypath, type="TH1F", title="Reference track d0", xbins=101, xmin=-5.0, xmax=5.0 ) + + defineHisto( monTool, "reftrk_z0", path=mypath, type="TH1F", title="Reference track z0", xbins=50, xmin=-225., xmax=225. ) + defineHisto( monTool, "reftrk_dd0", path=mypath, type="TH1F", title="Reference track sigma(d0)", xbins=50, xmin=0, xmax=0.5 ) + defineHisto( monTool, "reftrk_dz0", path=mypath, type="TH1F", title="Reference track sigma(z0)", xbins=50, xmin=0, xmax=2.5 ) + defineHisto( monTool, "reftrk_d0sig", path=mypath, type="TH1F", title="Reference track d0 significance", xbins= 101, xmin=-5., xmax=5. ) + + defineHisto( monTool, "testtrk_N", path=mypath, type="TH1F", title="Test tracks", xbins=vnbins ) + + defineHisto( monTool, "testtrk_pT", path=mypath, type="TH1F", title="Test track pT", xbins=ptbins ) + defineHisto( monTool, "testtrk_phi", path=mypath, type="TH1F", title="Test track Phi", xbins=25, xmin=-pi, xmax=pi ) + defineHisto( monTool, "testtrk_eta", path=mypath, type="TH1F", title="Test track Eta", xbins=25, xmin=-2.5, xmax=2.5 ) + + if "LRT" in chain: + defineHisto( monTool, "testtrk_d0", path=mypath, type="TH1F", title="Test track d0", xbins=201, xmin=-100.0, xmax=100.0 ) + else: + defineHisto( monTool, "testtrk_d0", path=mypath, type="TH1F", title="Test track d0", xbins=101, xmin=-5.0, xmax=5.0 ) + + defineHisto( monTool, "testtrk_z0", path=mypath, type="TH1F", title="Test track z0", xbins=50, xmin=-225., xmax=225. ) + defineHisto( monTool, "testtrk_dd0", path=mypath, type="TH1F", title="Test track sigma(d0)", xbins=50, xmin=0, xmax=0.5 ) + defineHisto( monTool, "testtrk_dz0", path=mypath, type="TH1F", title="Test track sigma(z0)", xbins=50, xmin=0, xmax=2.5 ) + defineHisto( monTool, "testtrk_d0sig", path=mypath, type="TH1F", title="Test track d0 significance", xbins=101, xmin=-5.0, xmax=5.0 ) + + defineHisto( monTool, "layer_rec", path=mypath, type="TH1F", title="hit layers", xbins=32, xmin=-0.5, xmax=31.5 ) + defineHisto( monTool, "layer", path=mypath, type="TH1F", title="hit layers", xbins=32, xmin=-0.5, xmax=31.5 ) + + defineHisto( monTool, "residual_pT", path=mypath, type="TH1F", title="track pT residual", xbins=201, xmin=-100.0, xmax=100.0 ) + defineHisto( monTool, "residual_ipT", path=mypath, type="TH1F", title="track ipT residual", xbins=55, xmin=-5.5, xmax=5.5 ) + defineHisto( monTool, "residual_phi", path=mypath, type="TH1F", title="track Phi residual", xbins=50, xmin=-0.02, xmax=0.02 ) + defineHisto( monTool, "residual_eta", path=mypath, type="TH1F", title="track Eta residual", xbins=50, xmin=-0.02, xmax=0.02 ) + defineHisto( monTool, "residual_d0", path=mypath, type="TH1F", title="track d0 residual ", xbins=251, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "residual_z0", path=mypath, type="TH1F", title="track z0 residual", xbins=401, xmin=-20.0, xmax=20.0 ) + defineHisto( monTool, "residual_dd0", path=mypath, type="TH1F", title="track sigma d0 residual ", xbins=251, xmin=-0.5, xmax=0.5 ) + defineHisto( monTool, "residual_dz0", path=mypath, type="TH1F", title="track sigma z0 residual", xbins= 401, xmin=-1.0, xmax=1.0 ) + + defineHisto( monTool, "npix", path=mypath, type="TH1F", title="npix", xbins=26, xmin=-0.5, xmax=25.5 ) + defineHisto( monTool, "npix_rec", path=mypath, type="TH1F", title="npix_rec", xbins=26, xmin=-0.5, xmax=25.5 ) + + defineHisto( monTool, "nsct", path=mypath, type="TH1F", title="nsct", xbins=31, xmin=-0.5, xmax=30.5 ) + defineHisto( monTool, "nsct_rec", path=mypath, type="TH1F", title="nsct_rec", xbins=31, xmin=-0.5, xmax=30.5 ) + + defineHisto( monTool, "nsiHits", path=mypath, type="TH1F", title="nsiHits", xbins=41, xmin=-0.5, xmax=40.5 ) + defineHisto( monTool, "nsiHits_rec", path=mypath, type="TH1F", title="nsiHits_rec", xbins=41, xmin=-0.5, xmax=40.5 ) + + defineHisto( monTool, "ntrt", path=mypath, type="TH1F", title="ntrt", xbins=91, xmin=-0.5, xmax=91.5 ) + defineHisto( monTool, "ntrt_rec", path=mypath, type="TH1F", title="ntrt_rec", xbins=91, xmin=-0.5, xmax=91.5 ) + + + defineHisto( monTool, "Eff_overall", path=mypath, type="TProfile", title="total efficiency", xbins=1, xmin=0., xmax=1. ) + + defineHisto( monTool, "Eff_pT", path=mypath, type="TProfile", title="pT efficiency", xbins=ptbins ) + defineHisto( monTool, "Eff_Eta", path=mypath, type="TProfile", title="eta efficiency", xbins=25, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "Eff_Phi", path=mypath, type="TProfile", title="phi efficiency", xbins=25, xmin=-pi, xmax=pi ) + defineHisto( monTool, "Eff_d0", path=mypath, type="TProfile", title="d0 efficiency", xbins=d0bins ) + defineHisto( monTool, "Eff_z0", path=mypath, type="TProfile", title="z0 efficiency", xbins=50, xmin=-225., xmax=225. ) + defineHisto( monTool, "Eff_nVtx", path=mypath, type="TProfile", title="nVtx efficiency", xbins=71, xmin=-0.5, xmax=70.5 ) + defineHisto( monTool, "Eff_lb", path=mypath, type="TProfile", title="efficinecy vs lumiblock", xbins=301, xmin=-0.5, xmax=3009.5 ) + + defineHisto( monTool, "trkvtx_x_vs_lb", path=mypath, type="TProfile", title="track vertex x vs lumiblock", xbins=301, xmin=-0.5, xmax=3009.5 ) + defineHisto( monTool, "trkvtx_y_vs_lb", path=mypath, type="TProfile", title="track vertex y vs lumiblock", xbins=301, xmin=-0.5, xmax=3009.5 ) + defineHisto( monTool, "trkvtx_z_vs_lb", path=mypath, type="TProfile", title="track vertex z vs lumiblock", xbins=301, xmin=-0.5, xmax=3009.5 ) + + defineHisto( monTool, "npix_vs_eta", path=mypath, type="TProfile", title="offline npix vs eta;offline #eta; mean number of offline pixel hits", xbins=30, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "npix_vs_eta_rec", path=mypath, type="TProfile", title="trigger npix vs eta;offline #eta; mean number of trigger pixel hits", xbins=30, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "nsct_vs_eta", path=mypath, type="TProfile", title="offline nsct vs eta;offline #eta; mean number of offline sct hits", xbins=30, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "nsct_vs_eta_rec", path=mypath, type="TProfile", title="trigger nsct vs eta;offline #eta; mean number of trigger sct hits", xbins=30, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "ntrt_vs_eta", path=mypath, type="TProfile", title="offline ntrt vs eta;offline #eta; mean number of offline trt hits", xbins=30, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "ntrt_vs_eta_rec", path=mypath, type="TProfile", title="trigger ntrt vs eta;offline #eta; mean number of trigger trt hits", xbins=30, xmin=-2.5, xmax=2.5 ) + + defineHisto( monTool, "npix_vs_phi", path=mypath, type="TProfile", title="offline npix vs phi;offline #phi; mean number of offline pixel hits", xbins=30, xmin=-pi, xmax=pi ) + defineHisto( monTool, "npix_vs_phi_rec", path=mypath, type="TProfile", title="trigger npix vs phi;offline #phi; mean number of trigger pixel hits", xbins=30, xmin=-pi, xmax=pi ) + defineHisto( monTool, "nsct_vs_phi", path=mypath, type="TProfile", title="offline nsct vs phi;offline #phi; mean number of offline sct hits", xbins=30, xmin=-pi, xmax=pi ) + defineHisto( monTool, "nsct_vs_phi_rec", path=mypath, type="TProfile", title="trigger nsct vs phi;offline #phi; mean number of trigger sct hits", xbins=30, xmin=-pi, xmax=pi ) + defineHisto( monTool, "ntrt_vs_phi", path=mypath, type="TProfile", title="offline ntrt vs phi;offline #phi; mean number of offline trt hits", xbins=30, xmin=-pi, xmax=pi ) + defineHisto( monTool, "ntrt_vs_phi_rec", path=mypath, type="TProfile", title="trigger ntrt vs phi;offline #phi; mean number of trigger trt hits", xbins=30, xmin=-pi, xmax=pi ) + + defineHisto( monTool, "npix_vs_d0", path=mypath, type="TProfile", title="offline npix vs d0;offline #d0; mean number of offline pixel hits", xbins=d0bins ) + defineHisto( monTool, "npix_vs_d0_rec", path=mypath, type="TProfile", title="trigger npix vs d0;offline #d0; mean number of trigger pixel hits", xbins=d0bins ) + defineHisto( monTool, "nsct_vs_d0", path=mypath, type="TProfile", title="offline nsct vs d0;offline #d0; mean number of offline sct hits", xbins=d0bins ) + defineHisto( monTool, "nsct_vs_d0_rec", path=mypath, type="TProfile", title="trigger nsct vs d0;offline #d0; mean number of trigger sct hits", xbins=d0bins ) + defineHisto( monTool, "npix_vs_pT", path=mypath, type="TProfile", title="offline npix vs pT;offline #p_{T}; mean number of offline pixel hits", xbins=ptbins ) + defineHisto( monTool, "npix_vs_pT_rec", path=mypath, type="TProfile", title="trigger npix vs pT;offline #p_{T}; mean number of trigger pixel hits", xbins=ptbins ) + defineHisto( monTool, "nsct_vs_pT", path=mypath, type="TProfile", title="offline nsct vs pT;offline #p_{T} [GeV]; mean number of offline pixel hits", xbins=ptbins ) + defineHisto( monTool, "nsct_vs_pT_rec", path=mypath, type="TProfile", title="trigger nsct vs pT;offline #p_{T} [GeV]; mean number of trigger pixel hits", xbins=ptbins ) + defineHisto( monTool, "nsihits_lb", path=mypath, type="TProfile", title="offline n sihits vs lumiblock", xbins=301, xmin=-0.5, xmax=3009.5 ) + defineHisto( monTool, "nsihits_lb_rec", path=mypath, type="TProfile", title="trigger n sihits vs lumiblock", xbins=301, xmin=-0.5, xmax=3009.5 ) + + defineHisto( monTool, "Res_pT", path=mypath, type="TProfile", title="pT residual;#eta_{ref};pT_{trig}-pT_{ref} [GeV]", xbins=25, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "Res_ipT", path=mypath, type="TProfile", title="ipT residual;#eta_{ref};1/pT_{trig}-1/pT_{ref} [GeV^{-1}]", xbins=25, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "Res_eta", path=mypath, type="TProfile", title="Eta residual;#eta_{ref};eta_{trig}-#eta_{ref}", xbins=25, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "Res_phi", path=mypath, type="TProfile", title="Phi residual;#eta_{ref};phi_{trig}-#phi_{ref}", xbins=25, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "Res_d0", path=mypath, type="TProfile", title="d0 residual;#eta_{ref};Delta d0 [mm]", xbins=25, xmin=-2.5, xmax=2.5 ) + defineHisto( monTool, "Res_z0", path=mypath, type="TProfile", title="z0 residual;#eta_{ref};Delta z0 [mm]", xbins=25, xmin=-2.5, xmax=2.5 ) + + defineHisto( monTool, "d0_vs_phi_prof", path=mypath, type="TProfile", title="d0 vs phi_prof", xbins=25, xmin=-pi, xmax=pi ) + defineHisto( monTool, "d0_vs_phi_rec_prof", path=mypath, type="TProfile", title="d0 vs phi_rec_prof", xbins=25, xmin=-pi, xmax=pi ) + + if "probe" in cs.extra: + defineHisto( monTool, "invmass", path=mypath, type="TH1F", title="invariant mass;mass [GeV]", xbins=320, xmin=0, xmax=200 ) + defineHisto( monTool, "invmass_obj", path=mypath, type="TH1F", title="invariant mass;mass [GeV]", xbins=320, xmin=0, xmax=200 ) + + + if cs.vtx != "" : + + vnbins_short = [ + -0.5, + 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, + 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 17.5, 18.5, 19.5, + 21.5, 23.5, 24.5, 26.5, 28.5, + 30.5, 32.5, 35.5, 37.5, + 40.5, 43.5, 46.5, + 50.5, 53.5, 57.5, + 61.5, 66.5, + 71.5, 76.5, + 81.5, 87.5, + 93.5, + 100.5, 107.5, 114.5, 123.5, 131.5, 141.5, 150.5, 161.5, 172.5, 185.5, 198.5, + 211.5, 226.5, 242.5, 259.5, 277.5, 297.5, + 317.5, 340.5, 363.5, 389.5, + 416.5, 445.5, 476.5, + 509.5, 544.5, 582.5, + 623.5, 666.5, + 713.5, 762.5, + 815.5, 872.5, + 933.5, 998.5, + 1067.5 + ] + + defineHisto( monTool, "vx_nvtx", path=mypath, type="TH1F", title=";number of vertices", xbins=101, xmin=-0.5, xmax=100.5 ) + defineHisto( monTool, "vx_zed", path=mypath, type="TH1F", title=";vtx z [mm]", xbins=100, xmin=-250, xmax=250 ) + defineHisto( monTool, "vx_ntrax", path=mypath, type="TH1F", title=";number of tracks", xbins=vnbins ) + + defineHisto( monTool, "vx_nvtx_rec", path=mypath, type="TH1F", title=";number of vertices", xbins=101, xmin=-0.5, xmax=100.5 ) + defineHisto( monTool, "vx_zed_rec", path=mypath, type="TH1F", title=";vtx z [mm]", xbins=100, xmin=-250, xmax=250 ) + defineHisto( monTool, "vx_ntrax_rec", path=mypath, type="TH1F", title=";number of tracks", xbins=vnbins ) + + defineHisto( monTool, "vx_zed_res", path=mypath, type="TH1F", title="Delta z [mm]", xbins=400, xmin=-10, xmax=10 ) + + + defineHisto( monTool, "vx_rdz_vs_zed", path=mypath, type="TProfile", title="rdz_vs_zed; vtx z [mm];z residual [mm]", xbins=100, xmin=-250, xmax=250 ) + defineHisto( monTool, "vx_rdz_vs_ntrax", path=mypath, type="TProfile", title="rdz_vs_ntrax;number of tracks;z residual [mm]", xbins=vnbins_short ) + defineHisto( monTool, "vx_rdz_vs_nvtx", path=mypath, type="TProfile", title="rdz_vs_nvtx;number of vertices;z residual [mm]", xbins=51, xmin=-0.125, xmax=50.125 ) + + # defineHistogram( monTool, "rdz_vs_mu", 30, 0, 30, 400, -20, 20 ); + + defineHisto( monTool, "vx_zed_eff", path=mypath, type="TProfile", title="zed_eff;efficiency;offline vtx z [mm]", xbins=50, xmin=-250, xmax=250 ) + defineHisto( monTool, "vx_ntrax_eff", path=mypath, type="TProfile", title="ntrax_eff;number of tracks;efficiency", xbins=vnbins ) + defineHisto( monTool, "vx_nvtx_eff", path=mypath, type="TProfile", title="nvtx_eff;number of vertices;efficiency", xbins=101, xmin=-0.5, xmax=100.5 ) + defineHisto( monTool, "vx_mu_eff", path=mypath, type="TProfile", title="mu_eff;<#mu>;efficiency", xbins=61, xmin=-0.5, xmax=60.5 ) + defineHisto( monTool, "vx_lb_eff", path=mypath, type="TProfile", title="lb_eff;lumi block;efficiency", xbins=151, xmin=-0.5, xmax=3019.5 ) + + + + return monTool + diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/__init__.py b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/chainString.py b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/chainString.py new file mode 100644 index 00000000000..af617171e52 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/python/chainString.py @@ -0,0 +1,89 @@ +# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + +# take a chain string configuration and decode it into the constituent parts, +# so that it can be reconstructed without the tags. + +# This is an approximate python implementation of the equivalent c++ +# class and wouldn't be needed if the setPath() method on the GenericMonitoringTool +# worked correctly, since the decoding is done in the c++, and the path could then +# be set correctly at that point. sadly, this doesn;t not seem to work, so we need +# to decode consistently in the c++ and the python to make sure that things +# are consistent + +class chainString: + + def __init__(self, input ): + self.head = "" + self.tail = "" + self.roi = "" + self.vtx = "" + self.element = "" + self.extra = "" + self.passed = "" + + if ":" in input: + parts = input.split( ":" ) + else: + parts = [ input ] + + for part in parts : + if part[-4:]==";DTE": + self.passed = True + part = part[0:-4] + if self.head == "": + self.head = part + continue + if "key=" in part: + self.tail = part[4:] + if "roi=" in part: + self.roi = part[4:] + if "vtx=" in part: + self.vtx = part[4:] + if "te=" in part: + self.element = part[3:] + if "extra=" in part: + self.extra = part[6:] + + stuff = [ self.extra, self.roi, self.vtx, self.element ] + + sum = self.head + + if self.tail != "" : + if sum == "" : + sum = self.tail + else: + sum += "_" + self.tail + + + for part in stuff: + if part != "": + sum += "_"+part + + if self.passed: + sum += "_DTE" + + self.sum = sum + + # provide the summary + def summary( self ): + return self.sum + + # printout if needed + def printchain( self ): + print( " head: ", self.head ) + print( " tail: ", self.tail ) + print( " vtx: ", self.vtx ) + print( " roi: ", self.roi ) + print( " te: ", self.element) + print( " extra: ", self.extra ) + print( " passed: ", self.passed ) + print( " sum: ", self.sum ) + print( "" ) + + +# provide the summary without needing the +# intermediate class instance + +def summarise( input ) : + return chainString( input ).summary() + diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/AnalysisR3_Tier0.cxx b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/AnalysisR3_Tier0.cxx new file mode 100644 index 00000000000..4bce67101a6 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/AnalysisR3_Tier0.cxx @@ -0,0 +1,494 @@ +/** + ** @file AnalysisR3_Tier0.cxx + ** + ** @author mark sutton + ** @date $Id: AnalysisR3_Tier0.cxx Thu 18 May 2017 15:35:34 CEST + ** + ** Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + **/ + + +#include + +#include "TrigInDetAnalysis/Track.h" +#include "TrigInDetAnalysisExample/AnalysisR3_Tier0.h" +#include "TrigInDetAnalysisExample/VtxR3Analysis.h" + +#include "TrigInDetAnalysisExample/ChainString.h" + +AnalysisR3_Tier0::AnalysisR3_Tier0(const std::string& name, + double /*pTCut*/, + double /*etaCut*/, + double /*d0Cut*/, + double /*z0Cut*/) + : TrackAnalysis(name), + // m_pTCut(pTCut), /// left in commented for development purposes + // m_etaCut(etaCut), + // m_d0Cut(d0Cut), + // m_z0Cut(z0Cut), + m_debug(false), + m_eventid(0), + m_monTool(0) +{} + +void AnalysisR3_Tier0::initialise() { + if ( m_monTool ) initialise_R3(); +} + +void AnalysisR3_Tier0::initialise_R2() { } + +void AnalysisR3_Tier0::initialise_R3() { + + ChainString cname = name(); + + // std::cout << "AnalysisR3_Tier0::initialise() name " << name() << std::endl; + +#if 0 + /// here for development purposes ... + std::cout << "\nAnalysisR3_Tier0:: chain specification: " << cname << "\t" << cname.raw() << std::endl; + std::cout << "\tchain: " << cname.head() << std::endl; + std::cout << "\tkey: " << cname.tail() << std::endl; + std::cout << "\troi: " << cname.roi() << std::endl; + std::cout << "\tvtx: " << cname.vtx() << std::endl; + std::cout << "\tte: " << cname.element() << std::endl; +#endif + + m_debug = false; + + m_hchain = new TIDA::Histogram( monTool(), "Chain" ); + + /// Limit the bins - to only the first 77 bins - so a range up to ~ 1000 + /// leave the previous selection commented for the time being + + m_hntrk = new TIDA::Histogram( monTool(), "reftrk_N" ); + + /// reference track distributions + + m_htrkpT = new TIDA::Histogram( monTool(), "reftrk_pT" ); + m_htrkphi = new TIDA::Histogram( monTool(), "reftrk_phi" ); + m_htrketa = new TIDA::Histogram( monTool(), "reftrk_eta" ); + if (name().find("LRT")!=std::string::npos || name().find("lrt")!=std::string::npos) { + m_htrkd0 = new TIDA::Histogram( monTool(), "reftrk_d0" ); + } else { + m_htrkd0 = new TIDA::Histogram( monTool(), "reftrk_d0" ); + } + m_htrkz0 = new TIDA::Histogram( monTool(), "reftrk_z0" ); + + /// the error estimates are always positive ... + m_htrkdd0 = new TIDA::Histogram( monTool(), "reftrk_dd0" ); + m_htrkdz0 = new TIDA::Histogram( monTool(), "reftrk_dz0" ); + + m_htrkd0sig = new TIDA::Histogram( monTool(), "reftrk_d0sig" ); + + + /// test track distributions + + /// Limit the bins - to only the first 77 bins - so a range up to ~ 1000 + /// leave the previous selection commented for the time being + // m_hntrk_rec = new TIDA::Histogram( monTool(), "testtrk_N", "Test tracks", 100, vnbins ); + m_hntrk_rec = new TIDA::Histogram( monTool(), "testtrk_N" ); + + + // m_htrkpT_rec = new TIDA::Histogram( monTool(), "testtrk_pT" , "Test track pT", 25, 0., 100.); + m_htrkpT_rec = new TIDA::Histogram( monTool(), "testtrk_pT" ); + m_htrkphi_rec = new TIDA::Histogram( monTool(), "testtrk_phi" ); + m_htrketa_rec = new TIDA::Histogram( monTool(), "testtrk_eta" ); + if (name().find("LRT")!=std::string::npos || name().find("lrt")!=std::string::npos) { + m_htrkd0_rec = new TIDA::Histogram( monTool(), "testtrk_d0" ); + } else { + m_htrkd0_rec = new TIDA::Histogram( monTool(), "testtrk_d0" ); + } + m_htrkz0_rec = new TIDA::Histogram( monTool(), "testtrk_z0" ); + + m_htrkdd0_rec = new TIDA::Histogram( monTool(), "testtrk_dd0" ); + m_htrkdz0_rec = new TIDA::Histogram( monTool(), "testtrk_dz0" ); + + m_htrkd0sig_rec = new TIDA::Histogram( monTool(), "testtrk_d0sig" ); + + + + /// trigger tracking efficiencies + + + m_htotal_efficiency = new TIDA::Histogram( monTool(), "Eff_overall" ); + + m_hpTeff = new TIDA::Histogram( monTool(), "Eff_pT" ); + m_hetaeff = new TIDA::Histogram( monTool(), "Eff_Eta" ); + m_hphieff = new TIDA::Histogram( monTool(), "Eff_Phi" ); + if (name().find("LRT")!=std::string::npos || name().find("lrt")!=std::string::npos) { + m_hd0eff = new TIDA::Histogram( monTool(), "Eff_d0" ); + } else { + m_hd0eff = new TIDA::Histogram( monTool(), "Eff_d0" ); + } + m_hz0eff = new TIDA::Histogram( monTool(), "Eff_z0" ); + m_hnVtxeff = new TIDA::Histogram( monTool(), "Eff_nVtx" ); + + + m_hlbeff = new TIDA::Histogram( monTool(), "Eff_lb" ); + + + m_htrkvtx_x_lb = new TIDA::Histogram( monTool(), "trkvtx_x_vs_lb" ); + m_htrkvtx_y_lb = new TIDA::Histogram( monTool(), "trkvtx_y_vs_lb" ); + m_htrkvtx_z_lb = new TIDA::Histogram( monTool(), "trkvtx_z_vs_lb" ); + + /// han config too stufid to deal with spaces in histogram names + m_hnpixvseta = new TIDA::Histogram( monTool(), "npix_vs_eta" ); + m_hnpixvseta_rec = new TIDA::Histogram( monTool(), "npix_vs_eta_rec" ); + + m_hnsctvseta = new TIDA::Histogram( monTool(), "nsct_vs_eta" ); + m_hnsctvseta_rec = new TIDA::Histogram( monTool(), "nsct_vs_eta_rec" ); + + m_hntrtvseta = new TIDA::Histogram( monTool(), "ntrt_vs_eta" ); + m_hntrtvseta_rec = new TIDA::Histogram( monTool(), "ntrt_vs_eta_rec" ); + + m_hnpixvsphi = new TIDA::Histogram( monTool(), "npix_vs_phi" ); + m_hnpixvsphi_rec = new TIDA::Histogram( monTool(), "npix_vs_phi_rec" ); + + m_hnsctvsphi = new TIDA::Histogram( monTool(), "nsct_vs_phi" ); + m_hnsctvsphi_rec = new TIDA::Histogram( monTool(), "nsct_vs_phi_rec" ); + + m_hntrtvsphi = new TIDA::Histogram( monTool(), "ntrt_vs_phi" ); + m_hntrtvsphi_rec = new TIDA::Histogram( monTool(), "ntrt_vs_phi_rec" ); + + if (name().find("LRT")!=std::string::npos || name().find("lrt")!=std::string::npos) { + m_hnpixvsd0 = new TIDA::Histogram( monTool(), "npix_vs_d0" ); + m_hnpixvsd0_rec = new TIDA::Histogram( monTool(), "npix_vs_d0_rec" ); + + m_hnsctvsd0 = new TIDA::Histogram( monTool(), "nsct_vs_d0" ); + m_hnsctvsd0_rec = new TIDA::Histogram( monTool(), "nsct_vs_d0_rec" ); + } else { + m_hnpixvsd0 = new TIDA::Histogram( monTool(), "npix_vs_d0" ); + m_hnpixvsd0_rec = new TIDA::Histogram( monTool(), "npix_vs_d0_rec" ); + + m_hnsctvsd0 = new TIDA::Histogram( monTool(), "nsct_vs_d0" ); + m_hnsctvsd0_rec = new TIDA::Histogram( monTool(), "nsct_vs_d0_rec" ); + } + + m_hnpixvspT = new TIDA::Histogram( monTool(), "npix_vs_pT" ); + m_hnpixvspT_rec = new TIDA::Histogram( monTool(), "npix_vs_pT_rec" ); + + m_hnsctvspT = new TIDA::Histogram( monTool(), "nsct_vs_pT" ); + m_hnsctvspT_rec = new TIDA::Histogram( monTool(), "nsct_vs_pT_rec" ); + + + m_hnsihits_lb = new TIDA::Histogram( monTool(), "nsihits_lb" ); + m_hnsihits_lb_rec = new TIDA::Histogram( monTool(), "nsihits_lb_rec" ); + + + m_hlayer_rec = new TIDA::Histogram( monTool(), "layer_rec" ); + m_hlayer = new TIDA::Histogram( monTool(), "layer" ); + + /// trigger tracking differential resolutions + + + m_hpTres = new TIDA::Histogram( monTool(), "Res_pT" ); + m_hipTres = new TIDA::Histogram( monTool(), "Res_ipT" ); + m_hetares = new TIDA::Histogram( monTool(), "Res_eta" ); + m_hphires = new TIDA::Histogram( monTool(), "Res_phi" ); + m_hd0res = new TIDA::Histogram( monTool(), "Res_d0" ); + m_hz0res = new TIDA::Histogram( monTool(), "Res_z0" ); + + + /// residuals + + m_htrkpT_residual = new TIDA::Histogram( monTool(), "residual_pT" ); + m_htrkipT_residual = new TIDA::Histogram( monTool(), "residual_ipT" ); + m_htrkphi_residual = new TIDA::Histogram( monTool(), "residual_phi" ); + m_htrketa_residual = new TIDA::Histogram( monTool(), "residual_eta" ); + m_htrkd0_residual = new TIDA::Histogram( monTool(), "residual_d0" ); + m_htrkz0_residual = new TIDA::Histogram( monTool(), "residual_z0" ); + + m_htrkdd0_residual = new TIDA::Histogram( monTool(), "residual_dd0" ); + m_htrkdz0_residual = new TIDA::Histogram( monTool(), "residual_dz0" ); + + + + m_hnpix = new TIDA::Histogram( monTool(), "npix" ); + m_hnpix_rec = new TIDA::Histogram( monTool(), "npix_rec" ); + + m_hnsct = new TIDA::Histogram( monTool(), "nsct" ); + m_hnsct_rec = new TIDA::Histogram( monTool(), "nsct_rec" ); + + m_hnsihits = new TIDA::Histogram( monTool(), "nsiHits" ); + m_hnsihits_rec = new TIDA::Histogram( monTool(), "nsiHits_rec" ); + + m_hntrt = new TIDA::Histogram( monTool(), "ntrt" ); + m_hntrt_rec = new TIDA::Histogram( monTool(), "ntrt_rec" ); + + + /// miscelaneous histograms + + m_hd0vsphi = new TIDA::Histogram( monTool(), "d0_vs_phi_prof" ); + m_hd0vsphi_rec = new TIDA::Histogram( monTool(), "d0_vs_phi_rec_prof" ); + + m_vtxanal = 0; + +#if 1 + + /// vertex analyses if required ... + // if ( name().find("vtx")!=std::string::npos || name().find("Vtx")!=std::string::npos || + // name().find("vx")!=std::string::npos || name().find("Vx")!=std::string::npos ) { + + if ( ChainString(name()).vtx()!="" ) { + + m_vtxanal = new VtxR3Analysis("VTX"); + + m_vtxanal->set_monTool( monTool() ); + + /// is this needed ? + store().insert( m_vtxanal, "VTX" ); + + /// initialise the vtx analysis + m_vtxanal->initialise(); + + } + +#endif + +} + +extern TIDARoiDescriptor* agroi; + +void AnalysisR3_Tier0::execute(const std::vector& , + const std::vector& , + TrackAssociator* ) +{ } + + +void AnalysisR3_Tier0::execute(const std::vector& referenceTracks, + const std::vector& testTracks, + TrackAssociator* associator, + const TIDA::Event* tevt ) +{ + + /// Loop over reference tracks + std::vector::const_iterator reference = referenceTracks.begin(); + std::vector::const_iterator referenceEnd = referenceTracks.end(); + + /// fill number of times this analysis was called - presumably + /// the number of passed RoIs for this chain + m_hchain->Fill( 0.5, 1 ); + + + + // if ( m_eventid != event()->event_number() ) { + if ( m_eventid != tevt->event_number() ) { + /// if the event number has changed, this is a new event + /// so update the event counts + // m_eventid = event()->event_number(); + m_eventid = tevt->event_number(); + m_hchain->Fill( 1.5, 1 ); + } + + m_hntrk->Fill( referenceTracks.size() ); + m_hntrk_rec->Fill( testTracks.size() ); + + /// fil the number of offline tracks + m_hchain->Fill(4.5, testTracks.size() ); + + for( ; reference!=referenceEnd ; reference++ ) { + + // Get reference parameters + double referenceEta = (*reference)->eta(); + double referencePhi = phi((*reference)->phi()); + double referenceZ0 = (*reference)->z0(); + double referenceD0 = (*reference)->a0(); + double referencePT = (*reference)->pT(); + + double referenceDZ0 = (*reference)->dz0(); + double referenceDD0 = (*reference)->da0(); + + // Find matched tracks + const TIDA::Track* test = associator->matched(*reference); + + float eff_weight = 0; + if (test) eff_weight = 1; + + m_htotal_efficiency->Fill(0.5, eff_weight ); + + m_hpTeff->Fill( std::fabs(referencePT)*0.001, eff_weight ); + m_hz0eff->Fill( referenceZ0, eff_weight ); + m_hd0eff->Fill( referenceD0, eff_weight ); + m_hetaeff->Fill( referenceEta, eff_weight ); + m_hphieff->Fill( referencePhi, eff_weight ); + m_hnVtxeff->Fill( m_nVtx, eff_weight ); + + // m_hlbeff->Fill( event()->lumi_block(), eff_weight ); + m_hlbeff->Fill( tevt->lumi_block(), eff_weight ); + + m_htrkpT->Fill( std::fabs(referencePT)*0.001 ); + m_htrketa->Fill( referenceEta ); + m_htrkphi->Fill( referencePhi ); + m_htrkd0->Fill( referenceD0 ); + m_htrkz0->Fill( referenceZ0 ); + + m_htrkdd0->Fill( referenceDD0 ); + m_htrkdz0->Fill( referenceDZ0 ); + + if ( referenceDD0!=0 ) m_htrkd0sig->Fill( referenceD0/referenceDD0 ); + + m_hnpixvseta->Fill( referenceEta, int(((*reference)->pixelHits()+0.5)*0.5) ); + m_hnsctvseta->Fill( referenceEta, (*reference)->sctHits() ); + m_hntrtvseta->Fill( referenceEta, (*reference)->strawHits() ); + + + m_hnpixvsphi->Fill( referencePhi, int(((*reference)->pixelHits()+0.5)*0.5) ); + m_hnsctvsphi->Fill( referencePhi, (*reference)->sctHits() ); + m_hntrtvsphi->Fill( referencePhi, (*reference)->strawHits() ); + + m_hnpixvsd0->Fill( referenceD0, int(((*reference)->pixelHits()+0.5)*0.5) ); + m_hnsctvsd0->Fill( referenceD0, (*reference)->sctHits() ); + + m_hnpixvspT->Fill( std::fabs(referencePT)*0.001, int(((*reference)->pixelHits()+0.5)*0.5) ); + m_hnsctvspT->Fill( std::fabs(referencePT)*0.001, (*reference)->sctHits() ); + + + m_hnpix->Fill( int(((*reference)->pixelHits()+0.5)*0.5) ); + m_hnsct->Fill( (*reference)->sctHits() ); + m_hnsihits->Fill( (*reference)->siHits() ); + m_hntrt->Fill( (*reference)->strawHits() ); + + + // m_hnsihits_lb->Fill( event()->lumi_block(), (*reference)->siHits() ); + m_hnsihits_lb->Fill( tevt->lumi_block(), (*reference)->siHits() ); + + m_hd0vsphi->Fill(referencePhi, referenceD0 ); + + /// fil the number of offline tracks + m_hchain->Fill(2.5, 1); + + + for ( size_t ilayer=0 ; ilayer<32 ; ilayer++ ) { + if ( (*reference)->hitPattern()&(1<Fill( ilayer ); + } + + if (test) { + + m_hchain->Fill(3.5, 1); + + /// NB: do we want to fill the actual *trigger* quantities, or the + /// offline quantities for the *matched* tracks? + + /// residual profiles vs the reference variable + // m_hpTres->Fill( referencePT*0.001, (test->pT() - referencePT)*0.001 ); + // m_hipTres->Fill( 1000/referencePT, (1000/test->pT() - 1000/referencePT) ); + // m_hetares->Fill( referenceEta, test->eta() - referenceEta ); + // m_hphires->Fill( referencePhi, phi(test->phi() - referencePhi) ); + // m_hd0res->Fill( referenceD0, test->a0() - referenceD0 ); + // m_hz0res->Fill( referenceZ0, test->z0() - referenceZ0 ); + + /// residual profiles vs eta - the more easy to understand + m_hpTres->Fill( referenceEta, (test->pT() - referencePT)*0.001 ); + m_hipTres->Fill( referenceEta, (1000/test->pT() - 1000/referencePT) ); + m_hetares->Fill( referenceEta, test->eta() - referenceEta ); + m_hphires->Fill( referenceEta, phi(test->phi() - referencePhi) ); + m_hd0res->Fill( referenceEta, test->a0() - referenceD0 ); + m_hz0res->Fill( referenceEta, test->z0() - referenceZ0 ); + + // m_htrkvtx_x_lb->Fill( event()->lumi_block(), beamTestx() ); + // m_htrkvtx_y_lb->Fill( event()->lumi_block(), beamTesty() ); + // m_htrkvtx_z_lb->Fill( event()->lumi_block(), beamTestz() ); + + m_htrkvtx_x_lb->Fill( tevt->lumi_block(), beamTestx() ); + m_htrkvtx_y_lb->Fill( tevt->lumi_block(), beamTesty() ); + m_htrkvtx_z_lb->Fill( tevt->lumi_block(), beamTestz() ); + + for ( size_t ilayer=0 ; ilayer<32 ; ilayer++ ) { + if ( test->hitPattern()&(1<Fill( ilayer ); + } + + // std::cout << "SUTT beam x " << beamTestx() << " " << "\tx " << beamTesty() << " " << "\ty " << beamTestz() << std::endl; + +#if 0 + /// reference tracks values for tracks with a reference track match (not test track values) + m_htrkpT_rec->Fill( referencePT*0.001 ); + m_htrketa_rec->Fill( referenceEta ); + m_htrkphi_rec->Fill( referencePhi ); + m_htrkd0_rec->Fill( referenceD0 ); + m_htrkz0_rec->Fill( referenceZ0 ); + +#endif + + /// test track distributions for test tracks with a reference track match + m_htrkpT_rec->Fill( std::fabs(test->pT())*0.001 ); + m_htrketa_rec->Fill( test->eta() ); + m_htrkphi_rec->Fill( test->phi() ); + m_htrkd0_rec->Fill( test->a0() ); + m_htrkz0_rec->Fill( test->z0() ); + + m_htrkdd0_rec->Fill( test->da0() ); + m_htrkdz0_rec->Fill( test->dz0() ); + + if ( test->da0()!=0 ) m_htrkd0sig_rec->Fill( test->a0()/test->da0() ); + + + /// 1d residual distributions + m_htrkpT_residual->Fill( (test->pT() - referencePT)*0.001 ); + m_htrkipT_residual->Fill( (1000/test->pT() - 1000/referencePT) ); + m_htrketa_residual->Fill( test->eta() - referenceEta ); + m_htrkphi_residual->Fill( phi(test->phi() - referencePhi) ); + + m_htrkd0_residual->Fill( test->a0() - referenceD0 ); + m_htrkz0_residual->Fill( test->z0() - referenceZ0 ); + + m_htrkdd0_residual->Fill( test->da0() - referenceDD0 ); + m_htrkdz0_residual->Fill( test->dz0() - referenceDZ0 ); + + m_hnpixvseta_rec->Fill( referenceEta, int((test->pixelHits()+0.5)*0.5) ); + m_hnsctvseta_rec->Fill( referenceEta, test->sctHits() ); + + m_hnpixvsphi_rec->Fill( referencePhi, int((test->pixelHits()+0.5)*0.5) ); + m_hnsctvsphi_rec->Fill( referencePhi, test->sctHits() ); + + m_hnpixvsd0_rec->Fill( referenceD0, int((test->pixelHits()+0.5)*0.5) ); + m_hnsctvsd0_rec->Fill( referenceD0, test->sctHits() ); + + m_hnpixvspT_rec->Fill( std::fabs(referencePT)*0.001, int((test->pixelHits()+0.5)*0.5) ); + m_hnsctvspT_rec->Fill( std::fabs(referencePT)*0.001, test->sctHits() ); + + m_hnpix_rec->Fill( int((test->pixelHits()+0.5)*0.5) ); + m_hnsct_rec->Fill( test->sctHits() ); + m_hnsihits_rec->Fill( test->siHits() ); + + // m_hnsihits_lb_rec->Fill( event()->lumi_block(), test->siHits() ); + m_hnsihits_lb_rec->Fill( tevt->lumi_block(), test->siHits() ); + + + m_hntrt_rec->Fill( test->strawHits() ); + + m_hntrtvseta_rec->Fill( referenceEta, test->strawHits() ); + m_hntrtvsphi_rec->Fill( referencePhi, test->strawHits() ); + + m_hd0vsphi_rec->Fill( test->phi(), test->a0() ); + + } + + } +} + + + + +void AnalysisR3_Tier0::execute_vtx(const std::vector& vtx0, + const std::vector& vtx1, + const TIDA::Event* tevt ) { + if ( m_vtxanal ) m_vtxanal->execute( vtx0, vtx1, tevt ); +} + + +void AnalysisR3_Tier0::finalise() { + if ( m_vtxanal ) m_vtxanal->finalise(); +} + + + +double AnalysisR3_Tier0::phi(double p) { + if(p < -M_PI) p += 2*M_PI; + if(p > M_PI) p -= 2*M_PI; + return p; +} + + + + + diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/Analysis_Tier0.cxx b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/Analysis_Tier0.cxx index d08c3ea2baf..01bac1b50a7 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/Analysis_Tier0.cxx +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/Analysis_Tier0.cxx @@ -20,13 +20,14 @@ Analysis_Tier0::Analysis_Tier0(const std::string& name, double /*etaCut*/, double /*d0Cut*/, double /*z0Cut*/) - : TrackAnalysis(name) - //, m_pTCut(pTCut) - //, m_etaCut(etaCut) - //, m_d0Cut(d0Cut) - //, m_z0Cut(z0Cut) - , m_debug(false) - , m_eventid(0) + : TrackAnalysis(name), + // m_pTCut(pTCut), /// left in commented for development purposes + // m_etaCut(etaCut), + // m_d0Cut(d0Cut), + // m_z0Cut(z0Cut), + m_debug(false), + m_eventid(0), + m_monTool(0) {} void Analysis_Tier0::initialise() { @@ -424,6 +425,11 @@ void Analysis_Tier0::initialise() { addHistogram( h_d0vsphi ); addHistogram( h_d0vsphi_rec ); + /// if ( cnams.extra().find("probe")!=std::string::npos ) { + /// h_invmass = new TH1F( "invmass", "invariant mass;mass [GeV]", 320, 0, 200 ); + /// addHistogram( h_invmass ); + ///} + // h2d_d0vsphi = 0; // new TH2D( "d0_vs_phi", "d0 vs phi", 25, -M_PI, M_PI, 50, -2.6, 2.6 ); // h2d_d0vsphi_rec = 0; // new TH2D( "d0_vs_phi_rec", "d0 vs phi rec", 25, -M_PI, M_PI, 50, -2.6, 2.6 ); diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigR3Mon.cxx b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigR3Mon.cxx new file mode 100644 index 00000000000..083cbc4bb75 --- /dev/null +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigR3Mon.cxx @@ -0,0 +1,666 @@ +/** + ** @file TrigR3Mon.cxx + ** + ** @brief implementation of a AthAlgorithm based monitoring base class + ** + ** @author Mark Sutton (sutt@cern.ch) + ** @date Tue 8 Feb 2022 09:08:26 GMT + ** + ** Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + **/ + +#include "TrigInDetAnalysis/Filter_AcceptAll.h" + +#include "TrigInDetAnalysisUtils/Filters.h" +#include "TrigInDetAnalysisUtils/Filter_Track.h" +#include "TrigInDetAnalysisUtils/TagNProbe.h" + +// #include "AthenaMonitoring/AthenaMonManager.h" +// #include "AthenaMonitoring/ManagedMonitorToolTest.h" + +#include "TrigInDetAnalysisExample/ChainString.h" +#include "TrigInDetAnalysisExample/TIDAHistogram.h" + +#include "TrigR3Mon.h" + + +TrigR3Mon::TrigR3Mon( const std::string & name, ISvcLocator* pSvcLocator) + : AthAlgorithm(name, pSvcLocator), + m_tdt("Trig::TrigDecisionTool/TrigDecisionTool"), + m_roiInfo(false), + m_buildNtuple(false), + m_initialisePerRun(true), + m_firstRun(true), + m_keepAllEvents(false), + m_fileopen(false), + m_first(true), + m_useHighestPT(false), + m_vtxIndex(-1), + m_runPurity(false), + m_shifter(false), + m_shifterChains(1), + m_sliceTag(""), + m_containTracks(false), + m_legacy(true) +{ + msg(MSG::INFO) << "TrigR3Mon::TrigR3Mon() compiled: " << __DATE__ << " " << __TIME__ << endmsg; + + declareProperty( "SliceTag", m_sliceTag = "" ); + + declareProperty( "pTCut", m_pTCut = 0 ); + declareProperty( "etaCut", m_etaCut = 5 ); + declareProperty( "d0Cut", m_d0Cut = 1000 ); + declareProperty( "z0Cut", m_z0Cut = 2000 ); + declareProperty( "siHits", m_siHits = -1 ); + + declareProperty( "trtHits", m_trtHits = -2 ); + declareProperty( "strawHits", m_strawHits = -2 ); + + declareProperty( "tauEtCutOffline", m_tauEtCutOffline = 0 ); + declareProperty( "doTauThreeProng", m_doTauThreeProng = false); + + declareProperty( "pTCutOffline", m_pTCutOffline = 2000 ); + declareProperty( "etaCutOffline", m_etaCutOffline = 2.5 ); + declareProperty( "d0CutOffline", m_d0CutOffline = 1000 ); + declareProperty( "z0CutOffline", m_z0CutOffline = 2000 ); + declareProperty( "pixHitsOffline", m_pixHitsOffline = 2 ); // 1 <- old value ( 2 degrees of freedom = 1 cluster ) + declareProperty( "sctHitsOffline", m_sctHitsOffline = 6 ); // 6 <- old value ( 6 clusters = 3 spacepoints ) + declareProperty( "siHitsOffline", m_siHitsOffline = 8 ); + declareProperty( "blayerHitsOffline", m_blayerHitsOffline = -1 ); // no requirement - in case IBL is off + + declareProperty( "pixHolesOffline", m_pixHolesOffline = 20 ); // essentially no limit + declareProperty( "sctHolesOffline", m_sctHolesOffline = 20 ); // essentially no limit + declareProperty( "siHolesOffline", m_siHolesOffline = 2 ); // npix holes + nsi holes <= 2 ( not degrees of freedom ! ) + + declareProperty( "ContainTracks", m_containTracks = false ); // use only basic track containment + + declareProperty( "trtHitsOffline", m_trtHitsOffline = -2 ); + declareProperty( "strawHitsOffline", m_strawHitsOffline = -2 ); + + declareProperty( "matchR", m_matchR = 0.1 ); + declareProperty( "matchPhi", m_matchPhi = 0.1 ); + + declareProperty( "ntupleChainNames", m_ntupleChainNames ); + declareProperty( "releaseMetaData", m_releaseMetaData ); + + declareProperty( "buildNtuple", m_buildNtuple = false ); + declareProperty( "mcTruth", m_mcTruth = false ); + + declareProperty( "AnalysisConfig", m_analysis_config = "Ntuple"); + + declareProperty( "SelectTruthPdgId", m_selectTruthPdgId = 0 ); + + declareProperty( "InitialisePerRun", m_initialisePerRun = false ); + declareProperty( "KeepAllEvents", m_keepAllEvents = false ); + declareProperty( "UseHighestPT", m_useHighestPT = false ); + declareProperty( "VtxIndex", m_vtxIndex = -1 ); + + declareProperty( "RunPurity", m_runPurity = false ); + declareProperty( "Shifter", m_shifter = false ); + + declareProperty( "ShifterChains", m_shifterChains = 1 ); + + declareProperty( "GenericFlag", m_genericFlag = true ); + + declareProperty( "Legacy", m_legacy = true ); + + msg(MSG::INFO) << "TrigR3Mon::TrigR3Mon() exiting " << gDirectory->GetName() << endmsg; + + +} + + + +TrigR3Mon::~TrigR3Mon() { + + if ( m_fileopen ) for ( unsigned i=0 ; ifinalize(); + + // msg(MSG::INFO) << "TrigR3Mon::~TrigR3Mon()" << endmsg; + // for ( unsigned i=m_filters.size() ; i-- ; ) delete m_filters[i]; + // for ( unsigned i=m_associators.size() ; i-- ; ) delete m_associators[i]; + +} + + + +StatusCode TrigR3Mon::initialize() { + + msg(MSG::DEBUG) << " ----- enter init() ----- " << endmsg; + + // std::cout << "sliceTag: " << m_sliceTag << std::endl; + + msg(MSG::INFO) << "TrigR3Mon::init() " << gDirectory->GetName() << " " << m_sliceTag << endmsg; + + /// NB: Do NOT create the sequences here - leave it until the book() method, since + /// we need to be automatically determine which chains to process, and so need + /// the TrigDecisionTool which is niot configured until we have an iov + +#if 0 + std::cout << "TrigR3Mon::name = " << name() << std::endl; + std::cout << "TrigR3Mon::SliceTag = " << m_sliceTag << std::endl; + std::cout << "TrigR3Mon::AnalysisConfig = " << m_analysis_config << std::endl; + std::cout << "TrigR3Mon::Legacy = " << m_legacy << std::endl; +#endif + + ATH_CHECK(m_monTools.retrieve()); + + msg(MSG::DEBUG) << " ----- exit init() ----- " << endmsg; + + return bookHistograms(); + + // return StatusCode::SUCCESS; + +} + + +StatusCode TrigR3Mon::bookHistograms() { + + msg(MSG::DEBUG) << " ----- enter book() ----- " << endmsg; + + msg(MSG::INFO) << "TrigR3Mon::book() " << gDirectory->GetName() << endmsg; + + // MMTB_DEPRECATED(duff) + + + /// create sequences if need be ... + + // track filters + // reference (offline) tracks... + TrackFilter* filterRef = new Filter_Track( m_etaCutOffline, m_d0CutOffline, 0, m_z0CutOffline, m_pTCutOffline, + m_pixHitsOffline, m_sctHitsOffline, m_siHitsOffline, m_blayerHitsOffline, + m_strawHitsOffline, m_trtHitsOffline, 0, + m_pixHolesOffline, m_sctHolesOffline, m_siHolesOffline ); + + // test (trigger) tracks... + // TrackFilter* filterTest = new Filter_Track( m_etaCut, m_d0Cut, m_z0Cut, m_pTCut, -1, -1, -1, -1, -2, -2 ); + TrackFilter* filterTest = new Filter_AcceptAll(); + + + // keep track of the filters so they can be cleaned up at the end + m_filters.push_back(filterRef); + m_filters.push_back(filterTest); + // m_filters.push_back(filterTest_TRT); + + + // track associators + TrackAssociator* dR_matcher = new Associator_BestDeltaRMatcher("EBdeltaR", m_matchR); // this needs to be set correctly + + // keep track of the associators so they can be cleaned up at the end + m_associators.push_back(dR_matcher); + + /// should only create the associators that we want to pass in - should control which + /// we want with a flag, so that we can configure which matcher we want to use and also + /// with what matching criteria + + // TrackAssociator* phi_matcher = new Associator_BestDeltaPhiMatcher("EBdeltaPhi", m_matchPhi); // this needs to be set correctly + // m_associators.push_back(phi_matcher); + + // "^[[91;1m" + // "^[[m" + + msg(MSG::INFO) << "^[[91;1m" << name() << "\t:AnalysisConfig " << m_analysis_config << "^[[m" << endmsg; + + msg(MSG::DEBUG) << "configuring chains: " << m_ntupleChainNames.size() << endmsg; + + /// keep counters of how many efid or ftf chains have been created + /// for shifter histograms, only want m_shifterMaxChains of each + int shifter_efid = 0; + int shifter_ftf = 0; + int shifter_efid_run1 = 0; + + std::string lastvtx = ""; + + // if (m_analysis_config == "Tier0") { + { + std::vector chains; + // std::vector chains; + chains.reserve( m_ntupleChainNames.size() ); + + /// handle wildcard chain selection + std::vector::iterator chainitr = m_ntupleChainNames.begin(); + + /// in the tier 0 analysis the wildcard selection should always + /// return one and only one chain + + if ( m_monTools.size()!=m_ntupleChainNames.size() ) { + msg(MSG::ERROR) << "chain name and monTool counts do not match: chains: " << m_ntupleChainNames.size() << "\t: monTools: " << m_monTools.size() << endmsg; + } + + + std::vector*> monTools; + monTools.reserve(m_ntupleChainNames.size()); + + + size_t itool = 0; + + while ( chainitr!=m_ntupleChainNames.end() ) { + + /// get chain + ChainString chainName = (*chainitr); + + msg(MSG::DEBUG) << "configuring chain: " << chainName.head() << "\t: " << chainName.tail() << endmsg; + + // std::cout << "\tconfiguring chain: " << (*chainitr) << "\t" << chainName.head() << "\t: " << chainName.tail() << "\t:" << chainName.roi() << std::endl; + + + if ( chainName.roi()!="" ) { + msg(MSG::DEBUG) << "trying chain: " << chainName.head() + << "\ttracks: " << chainName.tail() + << "\troi: " << chainName.roi() + << endmsg; + } + else { + msg(MSG::DEBUG) << "trying chain: " << chainName.head() + << "\ttracks: " << chainName.tail() + << endmsg; + } + + // std::cout << "\ttrying chain: " << chainName.head() + // << "\ttracks: " << chainName.tail() + // << "\troi: " << chainName.roi() + // << std::endl; + + + /// do offline type analyses first ... + + if ( chainName.head() == "" ) { + + std::string selectChain = ""; + + if ( chainName.tail()!="" ) selectChain += ":key="+chainName.tail(); + if ( chainName.element()!="" ) selectChain += ":te="+chainName.element(); + if ( chainName.roi()!="" ) selectChain += ":roi="+chainName.roi(); + if ( chainName.vtx()!="" ) selectChain += ":vtx="+chainName.vtx(); + + if ( chainName.extra()!="" ) selectChain += ":ex="+chainName.extra(); + if ( !chainName.passed() ) selectChain += ";DTE"; + + // if ( chainName.postcount() ) selectChain += ":post:"+chainName.post(); + + // m_monTools[itool]->setPath( m_sliceTag+"/"+chainName ); + + if (std::find(chains.begin(), chains.end(), selectChain) == chains.end()) { // deduplicate + chains.push_back( selectChain ); + monTools.push_back( &m_monTools[itool] ); + } + + } + else { + + /// check for configured chains only ... + + if ( chainName.head().find("HLT_")==std::string::npos && + chainName.head().find("EF_")==std::string::npos && + chainName.head().find("L2_")==std::string::npos ) { + chainitr++; + itool++; + continue; + } + + /// get matching chains + + std::vector selectChains; + selectChains.clear(); + + /// for the Run 3 python config based, shoud return one-and-only one chains per item + + msg(MSG::INFO) << "checking chain: " << chainName.head() << endmsg; + + /// this doesn;t work now because this has to be called in the initialize where there is NO IOV + + // if ( chainName.head()!="" ) selectChains = m_tdt->getListOfTriggers( chainName.head() ); + + if ( chainName.head()!="" ) selectChains.push_back( chainName.head() ); + + if ( selectChains.size()==0 ) { + msg(MSG::WARNING) << "^[[91;1m" << "No chains matched\tchain input " << chainName.head() << " : " << chainName.tail() << "^[[m"<< endmsg; + chainitr++; + itool++; + continue; + } + + + if ( selectChains.size()>1 ) { + msg(MSG::ERROR) << "^[[91;1m" << "Greater than one chain matched input " << chainName << "^[[m"<< endmsg; + chainitr++; + itool++; + continue; + } + + + // std::cout << "^[[91;1m" << "\tChain count matched\tchain input " << chainName.head() << " : " << chainName.tail() << "^[[m"<< std::endl; + + for ( unsigned iselected=0 ; iselected1 ? 1 : m_shifterChains ); + + if ( m_sliceTag.find("Shifter")!=std::string::npos || m_shifter ) { + /// shifter histograms + if ( chainName.tail().find("_FTF")!=std::string::npos ) { + /// FTF chain + if ( shifter_ftf>=shifterChains || + ( shifter_ftfshifterChains ) { + msg(MSG::DEBUG) << "^[[91;1m" << "Matching chain " << selectChains[iselected] << " excluded - Shifter chain already definied^[[m" << endmsg; + continue; + } + } + else if ( chainName.tail().find("_EFID")!=std::string::npos ) { + /// EFID chain + shifter_efid_run1++; + if ( shifter_efid_run1>shifterChains ) { + msg(MSG::DEBUG) << "^[[91;1m" << "Matching chain " << selectChains[iselected] << " excluded - Shifter chain already definied^[[m" << endmsg; + continue; + } + } + } + + /// replace wildcard with actual matching chains ... + // chains.push_back( ChainString(selectChains[iselected]) ); + if (std::find(chains.begin(), chains.end(), selectChains[iselected]) == chains.end()) { // deduplicate + chains.push_back( selectChains[iselected] ); + + // std::cout << "monTool for " << name() << " chain: " << chains.back() << " " << mchain << "\t" << m_monTools[itool]->name() << std::endl; + + // m_monTools[itool]->setPath( m_sliceTag+"/"+mchain ); + monTools.push_back( &m_monTools[itool] ); + } + + // msg(MSG::DEBUG) << "^[[91;1m" << "Matching chain " << selectChains[iselected] << "^[[m" << endmsg; + + // std::cout << "^[[91;1m" << "Matching chain " << selectChains[iselected] << "^[[m" << std::endl;; + + } + } + + itool++; + chainitr++; + } + + m_chainNames = chains; + + // std::cout << "TrigR3Mon::book() chains " << m_chainNames.size() << std::endl; + + // tag and probe object creation + std::vector& allchains = m_chainNames; + + for ( size_t i=0 ; itag(tag) ; + tnp->probe(probe) ; + + ATH_MSG_DEBUG( "Tag and probe pair found: " + tag + " : " + probe ); + + break ; + + } + } + + if ( m_tdt->getNavigationFormat() == "TriggerElement" ) { + + + /// this will all have to be removed - cant use polymorphism this + /// way in this case + +#if 0 + AnalysisConfig_Tier0* analysis = new AnalysisConfig_Tier0( m_sliceTag, // m_chainNames[i], + m_chainNames[i], "", "", + m_chainNames[i], "", "", + &m_roiInfo, + filterTest, filterRef, + dR_matcher, + new Analysis_Tier0( m_chainNames[i], m_pTCut, m_etaCut, m_d0Cut, m_z0Cut ) ); + + analysis->setRunPurity(m_runPurity); + analysis->setShifter(m_shifter); + analysis->containTracks(m_containTracks); + +#endif + + // m_sequences.push_back( analysis ); + + } + else { + + msg(MSG::INFO) << "configure analysis: " << m_chainNames[i] << endmsg; + + AnalysisConfigR3_Tier0* analysis = new AnalysisConfigR3_Tier0( m_sliceTag, // m_chainNames[i], + m_chainNames[i], "", "", + m_chainNames[i], "", "", + &m_roiInfo, + filterTest, filterRef, + dR_matcher, + new AnalysisR3_Tier0( m_chainNames[i], m_pTCut, m_etaCut, m_d0Cut, m_z0Cut ), + tnp ); + + analysis->setRunPurity(m_runPurity); + analysis->setShifter(m_shifter); + analysis->containTracks(m_containTracks); + + // for ( size_t it=0 ; itset_monTool( monTools[i] ); + + m_sequences.push_back( analysis ); + + } + + + std::string highestPT_str = ""; + std::string vtxindex_str = ""; + + if ( m_useHighestPT ) { + highestPT_str = ": using highest PT only"; + m_sequences.back()->setUseHighestPT(true); + } + else m_sequences.back()->setUseHighestPT(false); /// not needed now, but can't do any harm + + if ( !(m_vtxIndex<0) ) { + vtxindex_str = ": searching for vertex index "; + m_sequences.back()->setVtxIndex(m_vtxIndex); + } + + msg(MSG::DEBUG) << " ----- creating analysis " << m_sequences.back()->name() << " : " << m_chainNames[i] << highestPT_str << vtxindex_str << " -----" << endmsg; + + m_sequences.back()->releaseData(m_releaseMetaData); + + /// don't filter cosmic chains on Roi + /// - could be done with a global job option, but then if configuring some cosmic chains, + /// and non cosmic chains, then all would be tarred with the same brush + if ( m_chainNames[i].find("cosmic")!=std::string::npos || + m_chainNames[i].find("Cosmic")!=std::string::npos ) m_sequences.back()->setFilterOnRoi(false); + + } + } + + + + // std::cout << "TrigR3Mon: sequences: " << m_sequences.size() << std::endl; + + // if ( m_sequences.size() == 0 ) std::exit(0); + + if ( !m_fileopen && ( m_initialisePerRun || m_firstRun ) ) { + m_fileopen = true; + + for ( unsigned i=0 ; iname() << " -----" << endmsg; + m_sequences[i]->initialize(this, &m_tdt); + m_sequences[i]->setGenericFlag(m_genericFlag); + m_sequences[i]->book(); + } + m_firstRun = false; + } + + msg(MSG::DEBUG) << " configured " << m_sequences.size() << " sequences" << endmsg; + + msg(MSG::DEBUG) << " ----- exit book() ----- " << endmsg; + return StatusCode::SUCCESS; + +} + + + + + +StatusCode TrigR3Mon::execute() { + + if(msg().level() <= MSG::DEBUG) { + msg(MSG::DEBUG) << " ----- enter fill() ----- " << endmsg; + } + + // std::cout << "TrigR3Mon::fill() " << gDirectory->GetName() << "\tslice: " << m_sliceTag << std::endl; + + std::vector selectChains = m_tdt->getListOfTriggers( "HLT_e.*" ); + + msg(MSG::DEBUG) << " TDT selected chains " << selectChains.size() << endmsg; + + // std::cout << " TDT selected chains " << selectChains.size() << std::endl; + + int passed_count = 0; + + /// print out all the configured chains if need be + static bool _first = true; + for ( unsigned i=0 ; i5 ) i=5; + msg(MSG::INFO) << "^[[91;1m" << "configured chain " << selectChains[i] << "^[[m" << endmsg; + } + } +#endif + + _first = false; + + // std::cout << "TrigR3Mon::selectedChains size: " << selectChains.size() << std::endl; + + for ( unsigned i=0 ; iisPassed( selectChains[i] ) << std::endl; + + if ( m_tdt->isPassed(selectChains[i]) ) { + passed_count++; + ATH_MSG_DEBUG( "chain " << selectChains[i] << "\tpass: " << m_tdt->isPassed(selectChains[i]) << "\tprescale: " << m_tdt->getPrescale(selectChains[i]) ); + } + } + + // std::cout << "sequences::size: " << m_sequences.size() << std::endl; + + for ( unsigned i=0 ; iname() << " (" << m_chainNames[i] << ")" << std::endl; + + m_sequences[i]->execute(); + + } + + if(msg().level() <= MSG::DEBUG) { + msg(MSG::DEBUG) << " ----- exit fill() ----- " << endmsg; + } + + // std::cout << "TrigR3Mon::fill() exit " << gDirectory->GetName() << "\tslice: " << m_sliceTag << std::endl; + + + return StatusCode::SUCCESS; +} + + + + + +// bool newEventsBlock, bool newLumiBlock, bool newRun are protected varibales +// correctly set before this is called +StatusCode TrigR3Mon::finalize() { + + // StatusCode TrigR3Mon::procHistograms() { + + msg(MSG::DEBUG) << " ----- enter proc() ----- " << endmsg; + if ( m_initialisePerRun ) { + for ( unsigned i=0 ; ifinalize(); + m_fileopen = false; + } + msg(MSG::DEBUG) << " ====== exit proc() ====== " << endmsg; + + + + return StatusCode::SUCCESS; +} + + + + + + + + diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigR3Mon.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigR3Mon.h new file mode 100644 index 00000000000..c7d12dfd6aa --- /dev/null +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigR3Mon.h @@ -0,0 +1,176 @@ +/// emacs: this is -*- c++ -*- +/** + ** @file TrigR3Mon.h + ** + ** @author mark sutton + ** @date Tue 8 Feb 2022 09:08:26 GMT + ** + ** Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + **/ + + +#ifndef TIDAEXAMPLE_TRIGR3MON_H +#define TIDAEXAMPLE_TRIGR3MON_H + +#include "GaudiKernel/ToolHandle.h" +#include "Gaudi/Property.h" +#include "AthenaBaseComps/AthAlgorithm.h" +#include "AthenaMonitoringKernel/GenericMonitoringTool.h" + +#include "AthenaMonitoringKernel/Monitored.h" + +#include + + +// #include "AthenaMonitoring/ManagedMonitorToolBase.h" + +#include "TrigInDetAnalysis/TrackFilter.h" +#include "TrigInDetAnalysis/TIDARoiDescriptor.h" +#include "TrigInDetAnalysis/TIDDirectory.h" +#include "TrigInDetAnalysis/Efficiency.h" + +#include "TrigInDetAnalysisUtils/Filter_Track.h" +#include "TrigInDetAnalysisUtils/Filter_RoiSelector.h" +#include "TrigInDetAnalysisUtils/T_AnalysisConfig.h" +#include "TrigInDetAnalysisUtils/Associator_BestMatch.h" +#include "TrigInDetAnalysisUtils/TrackMatchDeltaR.h" +#include "TrigInDetAnalysisUtils/TrackMatchDeltaRCosmic.h" + +// #include "TrigInDetAnalysisExample/SigAnalysis.h" +// #include "TrigInDetAnalysisExample/TrackEfficiency.h" +#include "TrigInDetAnalysisExample/AnalysisConfig_Tier0.h" + + +class TrigR3Mon : public AthAlgorithm { + + +public: + + TrigR3Mon( const std::string & name, ISvcLocator* pSvcLocator); + + virtual ~TrigR3Mon(); + + virtual StatusCode initialize(); + virtual StatusCode execute(); + virtual StatusCode finalize(); + + virtual StatusCode bookHistograms(); + + void addMonGroupFromBase( const std::string& ) { } + +protected: + + // track selector cuts + + // test tracks + double m_pTCut; + double m_etaCut; + double m_d0Cut; + double m_z0Cut; + + int m_siHits; // total number of si hits + int m_pixHits; // pixel hits + int m_sctHits; // sct hits + + int m_trtHits; // high threshold hits + int m_strawHits; // total number of straws + + // reference tracks + double m_tauEtCutOffline; + double m_doTauThreeProng; + double m_pTCutOffline; + double m_etaCutOffline; + double m_d0CutOffline; + double m_z0CutOffline; + + int m_siHitsOffline; // total number of si hits + int m_pixHitsOffline; // pixel hits + int m_sctHitsOffline; // sct hits + int m_blayerHitsOffline; + + int m_pixHolesOffline; // pixel holes + int m_sctHolesOffline; // sct holes + int m_siHolesOffline; // total pix+sct holes + + int m_trtHitsOffline; // high threshold hits + int m_strawHitsOffline; // total number of straws + + // roi size + // double m_phiWidth; + // double m_etaWidth; + // double m_zedWidth; + + // matching parameters + double m_matchR; // for DeltaR matcher + double m_matchPhi; // for DeltaPhi matcher + + ToolHandle m_tdt; + + + TIDARoiDescriptor m_roiInfo; + + std::vector m_filters; + std::vector m_associators; + + /// dpo we need this ??? why not the base class ??? + std::vector*> m_sequences; + + std::vector m_chainNames; + std::vector m_ntupleChainNames; + std::string m_releaseMetaData; + + bool m_buildNtuple; + bool m_mcTruth; + + std::string m_analysis_config; + std::string m_outputFileName; + + bool m_genericFlag; + + bool m_initialisePerRun; + bool m_firstRun; + + //pdgId + int m_selectTruthPdgId; + + /// kepp events even if they fail the requested trigger chains + bool m_keepAllEvents; + + /// if an ntple file open? + bool m_fileopen; + + /// is this the first event + bool m_first; + + /// use only the highest pt tracks + bool m_useHighestPT; + + /// if performing the vertex analysis, the index of the + /// offline vertex to look for + int m_vtxIndex; + + /// also run purity analyses + bool m_runPurity; + + /// determine whether this should be treated as a shifter chain + bool m_shifter; + + /// max number of shifter chains to use - must be < 2 at the moment + int m_shifterChains; + + /// additional string for the histogram directory + std::string m_sliceTag; + + /// do we want basic, or rigorous roi track containment + bool m_containTracks; + + bool m_legacy; + + // ToolHandleArray m_monTool { this, "MonTools", "", "chain monitor tool handles" }; + ToolHandleArray m_monTools { this, "MonTools", {} }; // insane configuration paradigm ? + +}; + + + +#endif // TIDAEXAMPLE_TRIGR3MON_H diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigTestBase.cxx b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigTestBase.cxx index c75a556d39b..8f72751e880 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigTestBase.cxx +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/TrigTestBase.cxx @@ -126,11 +126,8 @@ TrigTestBase::~TrigTestBase() { StatusCode TrigTestBase::init() { msg(MSG::DEBUG) << " ----- enter init() ----- " << endmsg; - - // m_sliceTag = m_sliceTagArse; // std::cout << "sliceTag: " << m_sliceTag << std::endl; - // std::cout << "sliceTagArse: " << m_sliceTagArse << std::endl; msg(MSG::INFO) << "TrigTestBase::init() " << gDirectory->GetName() << " " << m_sliceTag << endmsg; // std::cout << "TrigTestBase::init() " << gDirectory->GetName() << std::endl; @@ -240,16 +237,18 @@ StatusCode TrigTestBase::book(bool newEventsBlock, bool newLumiBlock, bool newRu std::string lastvtx = ""; + + // if (m_analysis_config == "Tier0") { { + std::vector chains; - // std::vector chains; + chains.reserve( m_ntupleChainNames.size() ); /// handle wildcard chain selection - but only the first time std::vector::iterator chainitr = m_ntupleChainNames.begin(); - while ( chainitr!=m_ntupleChainNames.end() ) { /// get chain @@ -294,10 +293,10 @@ StatusCode TrigTestBase::book(bool newEventsBlock, bool newLumiBlock, bool newRu if ( chainName.roi()!="" ) continue; // if ( !chainName.passed() ) continue; - if (std::find(chains.begin(), chains.end(), selectChain) == chains.end()) { // deduplicate - chains.push_back( selectChain ); - } - + if (std::find(chains.begin(), chains.end(), selectChain) == chains.end()) { // deduplicate + chains.push_back( selectChain ); + } + } else { @@ -330,7 +329,6 @@ StatusCode TrigTestBase::book(bool newEventsBlock, bool newLumiBlock, bool newRu if ( chainName.roi()!="" ) selectChains[iselected] += ":roi="+chainName.roi(); if ( chainName.vtx()!="" ) selectChains[iselected] += ":vtx="+chainName.vtx(); if ( !chainName.passed() ) selectChains[iselected] += ":DTE"; - // if ( !chainName.passed() ) selectChains[iselected] += ";DTE"; if ( chainName.postcount() ) selectChains[iselected] += ":post:"+chainName.post(); @@ -383,7 +381,7 @@ StatusCode TrigTestBase::book(bool newEventsBlock, bool newLumiBlock, bool newRu msg(MSG::DEBUG) << "^[[91;1m" << "Matching chain " << selectChains[iselected] << "^[[m" << endmsg; - // std::cout << "^[[91;1m" << "Matching chain " << selectChains[iselected] << "^[[m" << std::endl;; + // std::cout << "^[[91;1m" << "SUTT Matching chain " << selectChains[iselected] << "^[[m" << std::endl;; } } @@ -393,42 +391,52 @@ StatusCode TrigTestBase::book(bool newEventsBlock, bool newLumiBlock, bool newRu m_chainNames = chains; - // reserving m_chainNames size for m_TnP_tools vector - m_TnP_tools.reserve( m_chainNames.size() ) ; - + // std::cout << "chains.size() " << chains.size() << std::endl; + // tag and probe object creation for (unsigned i=0; itag(tagChainName) ; - m_TnP_tools[i]->probe(probeChainName) ; - ATH_MSG_DEBUG( "Tag and probe pair found" ); - break ; - } + if ( tag_key != probe_key ) continue; + + // if matching tag found then initialise tag and probe object and store tag and probe chains in there + /// this will be passed into the AnalysisConfig, which will delete it when necessary + /// could perhaps be done with a unique_ptrt + tnp = new TagNProbe(); + tnp->tag(tag); + tnp->probe(probe); + ATH_MSG_DEBUG( "Tag and probe pair found: " + tag + " : " + probe ); + break ; + } } @@ -450,13 +458,7 @@ StatusCode TrigTestBase::book(bool newEventsBlock, bool newLumiBlock, bool newRu } else { - - // skip AnalysisConfigMT_Tier0 instance if it's a tag chain as we're not interested in this for tag and probe analysis - ChainString chainName( m_chainNames[i] ) ; - if ( chainName.extra().find("_tag")!=std::string::npos && m_TnP_tools[i] == 0 ) { - continue ; - } - + AnalysisConfigMT_Tier0* analysis = new AnalysisConfigMT_Tier0( m_sliceTag, // m_chainNames[i], m_chainNames[i], "", "", m_chainNames[i], "", "", @@ -464,8 +466,8 @@ StatusCode TrigTestBase::book(bool newEventsBlock, bool newLumiBlock, bool newRu filterTest, filterRef, dR_matcher, new Analysis_Tier0( m_chainNames[i], m_pTCut, m_etaCut, m_d0Cut, m_z0Cut ), - m_TnP_tools[i] - ); + tnp ); + analysis->setRunPurity(m_runPurity); analysis->setShifter(m_shifter); @@ -516,11 +518,6 @@ StatusCode TrigTestBase::book(bool newEventsBlock, bool newLumiBlock, bool newRu msg(MSG::VERBOSE) << " ----- booking for analysis " << m_sequences[i]->name() << " -----" << endmsg; m_sequences[i]->initialize(this, &m_tdt); m_sequences[i]->setGenericFlag(m_genericFlag); - - // skip booking of tag chain as we're not interested in this for tag and probe analysis - ChainString chainName( m_sequences[i]->testChains() ) ; - if ( chainName.extra().find("_tag")!=std::string::npos ) continue ; - m_sequences[i]->book(); } m_firstRun = false; @@ -613,11 +610,6 @@ StatusCode TrigTestBase::proc(bool /*endOfEventsBlock*/, bool /*endOfLumiBlock*/ if ( m_initialisePerRun && endOfRun ) { for ( unsigned i=0 ; ifinalize(); m_fileopen = false; - - // deleting the instances of the initialised TnP_tool - for ( unsigned i=0 ; ipush(); + + + + m_hnvtx = new TIDA::Histogram( monTool(), "vx_nvtx" ); + m_hzed = new TIDA::Histogram( monTool(), "vx_zed" ); + m_hntrax = new TIDA::Histogram( monTool(), "vx_ntrax" ); + + + m_hnvtx_rec = new TIDA::Histogram( monTool(), "vx_nvtx_rec" ); + m_hzed_rec = new TIDA::Histogram( monTool(), "vx_zed_rec" ); + m_hntrax_rec = new TIDA::Histogram( monTool(), "vx_ntrax_rec" ); + + m_hzed_res = new TIDA::Histogram( monTool(), "vx_zed_res" ); + + m_rdz_vs_zed = new TIDA::Histogram( monTool(), "vx_rdz_vs_zed" ); + m_rdz_vs_ntrax = new TIDA::Histogram( monTool(), "vx_rdz_vs_ntrax" ); + m_rdz_vs_nvtx = new TIDA::Histogram( monTool(), "vx_rdz_vs_nvtx" ); + + m_eff_zed = new TIDA::Histogram( monTool(), "vx_zed_eff" ); + m_eff_ntrax = new TIDA::Histogram( monTool(), "vx_ntrax_eff" ); + m_eff_nvtx = new TIDA::Histogram( monTool(), "vx_nvtx_eff" ); + m_eff_mu = new TIDA::Histogram( monTool(), "vx_mu_eff" ); + m_eff_lb = new TIDA::Histogram( monTool(), "vx_lb_eff" ); + + /// mdir->pop(); + +} + + +void VtxR3Analysis::execute( const std::vector& vtx0, + const std::vector& vtx1, + const TIDA::Event* tevt ) { + + // std::cout << "VtxAnalysis::execute() initialised: " << m_initialised << "\tevent: " << tevt << std::endl; + + if ( !m_initialised ) return; + + // if ( vtx1.size()<2 ) return; + +#if 0 + std::cout << "VtxAnalysis::execute() " << name() + << "\tvtx0.size() " << vtx0.size() + << "\tvtx1.size() " << vtx1.size() + << std::endl; +#endif + + + VertexMatcher m("vtx_matcher", 10 ); + + m.match( vtx0, vtx1 ); + + m_hnvtx->Fill( vtx0.size() ); + m_hnvtx_rec->Fill( vtx1.size() ); + + // for ( unsigned i=0 ; i0 ) break; + + // std::cout << i << "\tref z " << vtx0[i]->z(); + + m_hzed->Fill( vtx0[i]->z() ); + m_hntrax->Fill( vtx0[i]->Ntracks() ); + + const TIDA::Vertex* mv = m.matched( vtx0[i] ); + + if ( mv ) { + + // std::cout << "\ttest z " << mv->z() << " : delta z " << (mv->z()-vtx0[i]->z()) << std::endl; + + /// ah ha ! can fill some silly old histograms here + /// ... + + m_hzed_rec->Fill( mv->z() ); + m_hntrax_rec->Fill( mv->Ntracks() ); + + m_hzed_res->Fill( mv->z() - vtx0[i]->z() ); + + m_rdz_vs_zed->Fill( vtx0[i]->z(), mv->z() - vtx0[i]->z() ); + m_rdz_vs_ntrax->Fill( vtx0[i]->Ntracks(), mv->z() - vtx0[i]->z() ); + m_rdz_vs_nvtx->Fill( vtx0.size(), mv->z() - vtx0[i]->z() ); /// this isn't really legitimate + + m_eff_zed->Fill( vtx0[i]->z(), 1 ); + m_eff_ntrax->Fill( vtx0[i]->Ntracks(), 1 ); + m_eff_nvtx->Fill( vtx0.size(), 1 ); + + m_eff_mu->Fill( tevt->mu(), 1 ); + m_eff_lb->Fill( tevt->lumi_block(), 1 ); + + } + else { + // std::cout << "\t" << "------" << std::endl; + + m_eff_zed->Fill( vtx0[i]->z(), 0 ); + m_eff_ntrax->Fill( vtx0[i]->Ntracks(), 0 ); + m_eff_nvtx->Fill( vtx0.size(), 0 ); + + m_eff_mu->Fill( tevt->mu(), 0 ); + m_eff_lb->Fill( tevt->lumi_block(), 0 ); + } + + } + +} + + + + +void VtxR3Analysis::finalise() { + // std::cout << "VtxAnalysis::finalise() " << name() << std::endl; +} + diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/components/TrigInDetAnalysisExample_entries.cxx b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/components/TrigInDetAnalysisExample_entries.cxx index 3765a501703..cf5663042ee 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/components/TrigInDetAnalysisExample_entries.cxx +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/components/TrigInDetAnalysisExample_entries.cxx @@ -1,8 +1,11 @@ + #include "TrigInDetAnalysisExample/TrigTestMonToolAC.h" #include "TrigInDetAnalysisExample/TrigTestPhysValMon.h" +#include "../TrigR3Mon.h" DECLARE_COMPONENT( TrigTestMonToolAC ) DECLARE_COMPONENT( TrigTestBase ) DECLARE_COMPONENT( TrigTestPhysValMon ) +DECLARE_COMPONENT( TrigR3Mon ) diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisUser/Analysis/src/ConfAnalysis.h b/Trigger/TrigAnalysis/TrigInDetAnalysisUser/Analysis/src/ConfAnalysis.h index 60345903e01..761d2178cb2 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisUser/Analysis/src/ConfAnalysis.h +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisUser/Analysis/src/ConfAnalysis.h @@ -80,9 +80,17 @@ public: virtual void execute(const std::vector& reftracks, const std::vector& testtracks, TrackAssociator* matcher ) { - execute( reftracks, testtracks, matcher, 0 ); + execute( reftracks, testtracks, matcher, (TrigObjectMatcher*)0 ); } + virtual void execute(const std::vector& reftracks, + const std::vector& testtracks, + TrackAssociator* matcher, + const TIDA::Event* ) { + execute( reftracks, testtracks, matcher, (TrigObjectMatcher*)0 ); + } + + #if 0 virtual void execute(const std::vector& reftracks, const std::vector& testtracks, diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisUser/Analysis/src/Makefile b/Trigger/TrigAnalysis/TrigInDetAnalysisUser/Analysis/src/Makefile index 764ef708dab..a1ea16ae5d9 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisUser/Analysis/src/Makefile +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisUser/Analysis/src/Makefile @@ -160,6 +160,7 @@ ROBJECTS = \ LOBJECTS = \ $(OBJDIR)/TIDAEvent.o \ + $(OBJDIR)/TagNProbe.o \ $(OBJDIR)/Track.o \ $(OBJDIR)/TIDAVertex.o \ $(OBJDIR)/TIDAVertexNew.o \ diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/T_AnalysisConfig.h b/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/T_AnalysisConfig.h index 69babd59d45..d14c2b21ec1 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/T_AnalysisConfig.h +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/T_AnalysisConfig.h @@ -164,22 +164,30 @@ public: std::vector testChainNames; testChainNames.push_back(testChainName); std::vector referenceChainNames; referenceChainNames.push_back(referenceChainName); std::vector selectionChainNames; selectionChainNames.push_back("NONE"); - m_chainNames.push_back(testChainNames); m_chainNames.push_back(referenceChainNames); m_chainNames.push_back(selectionChainNames); + m_chainNames.push_back(testChainNames); + m_chainNames.push_back(referenceChainNames); + m_chainNames.push_back(selectionChainNames); // Types std::vector testTypes; testTypes.push_back(testType); std::vector referenceTypes; referenceTypes.push_back(referenceType); std::vector selectionTypes; selectionTypes.push_back(""); - m_types.push_back(testTypes); m_types.push_back(referenceTypes); m_types.push_back(selectionTypes); + m_types.push_back(testTypes); + m_types.push_back(referenceTypes); + m_types.push_back(selectionTypes); // Keys std::vector testKeys; testKeys.push_back(testKey); std::vector referenceKeys; referenceKeys.push_back(referenceKey); std::vector selectionKeys; selectionKeys.push_back(""); - m_keys.push_back(testKeys); m_keys.push_back(referenceKeys); m_keys.push_back(selectionKeys); + m_keys.push_back(testKeys); + m_keys.push_back(referenceKeys); + m_keys.push_back(selectionKeys); // Filters std::vector testFilters; testFilters.push_back(testFilter); std::vector referenceFilters; referenceFilters.push_back(referenceFilter); std::vector selectionFilters; - m_filters.push_back(testFilters); m_filters.push_back(referenceFilters); m_filters.push_back(selectionFilters); + m_filters.push_back(testFilters); + m_filters.push_back(referenceFilters); + m_filters.push_back(selectionFilters); // m_selectorRef = new TrigTrackSelector( referenceFilter ); // m_selectorTest = new TrigTrackSelector( testFilter ); diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/TagNProbe.h b/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/TagNProbe.h index 83d4edef324..51f53e9eff6 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/TagNProbe.h +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/TrigInDetAnalysisUtils/TagNProbe.h @@ -1,3 +1,4 @@ +/// emacs: this is -*- c++ -*- /** ** @file TagNProbe.h ** @@ -90,6 +91,26 @@ public: m_chain_tnp = chain_tnp; } + template + void Fill( T* h, T* h1, int i ) { + /// don't need to check both these, we can just call this as many times as we like, + /// could pass in the vector even so that + // we leave the old code in, but commented, since we are still developing, so once + // we know everything is working we can delete all the older code + // if ( m_masses[i].size() == m_masses_obj[i].size() && m_masses[i].size() > 0 ) { + + /// don't understand this - why is this method filling lots of masses + /// from an vector of masses from 0 up to the input index ? + /// isn't this index just the index of the roi ? Why the loop ? + for ( size_t im=0 ; imFill( m_masses[i].at(im) ); + } + for ( size_t im=0 ; imFill( m_masses_obj[i].at(im) ); + } + } + + /// probe searching method bool FindProbes(); @@ -185,7 +206,6 @@ private: TrigObjectMatcher* m_tom; - /// supporting variables for utility methods std::map m_tnp_map; diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/src/TagNProbe.cxx b/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/src/TagNProbe.cxx index 03bb3a8f2c2..c85753f5dc7 100644 --- a/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/src/TagNProbe.cxx +++ b/Trigger/TrigAnalysis/TrigInDetAnalysisUtils/src/TagNProbe.cxx @@ -50,13 +50,15 @@ double TagNProbe::computeZ_obj( TIDA::Track* t1, TIDA::Track* t2 ) { double invMass = (double)( v1 + v2 ).M(); double z0diff = std::fabs( z0_1 - z0_2 ); - if ( invMass > m_ZmassMin && invMass < m_ZmassMax && z0diff < 5 ) - return invMass; + if ( invMass > m_ZmassMin && invMass < m_ZmassMax && z0diff < 5 ) return invMass; return -1.0; } + + + // ------------------------------------------------------------------ double TagNProbe::computeZ( TIDA::Track* t1, TIDA::Track* t2 ) { @@ -86,6 +88,9 @@ double TagNProbe::computeZ( TIDA::Track* t1, TIDA::Track* t2 ) { } + + + // ------------------------------------------------------------------ std::pair TagNProbe::selection( TIDA::Roi& troi, TIDA::Roi& proi ) @@ -120,10 +125,14 @@ std::pair TagNProbe::selection( TIDA::Roi& troi, TIDA::Roi& proi } std::pair pNull = std::make_pair( 0., 0. ); + return pNull; } + + + // ------------------------------------------------------------------ bool TagNProbe::FindProbes() @@ -313,10 +322,10 @@ void TagNProbe::FillMinvHisto( std::string chain_name, unsigned int probe_index hMinv_obj_itr != m_hMinv_obj_map.end() && m_masses[probe_index].size() == m_masses_obj[probe_index].size() ) { - for ( size_t im=0 ; imsecond->Fill( m_masses[probe_index].at(im) ); - hMinv_obj_itr->second->Fill( m_masses_obj[probe_index].at(im) ); - } + // for ( size_t im=0 ; imsecond->Fill( m_masses[probe_index].at(im) ); + // hMinv_obj_itr->second->Fill( m_masses_obj[probe_index].at(im) ); + // } } } @@ -327,10 +336,10 @@ void TagNProbe::FillMinvHisto( unsigned int probe_index ) { if ( m_masses[probe_index].size() == m_masses_obj[probe_index].size() && m_masses[probe_index].size() > 0 ) { - for ( size_t im=0 ; imFill( m_masses[probe_index].at(im) ); - m_hMinv_obj->Fill( m_masses_obj[probe_index].at(im) ); - } + // for ( size_t im=0 ; imFill( m_masses[probe_index].at(im) ); + // m_hMinv_obj->Fill( m_masses_obj[probe_index].at(im) ); + // } } } @@ -350,12 +359,14 @@ void TagNProbe::WriteMinvHisto( TDirectory* foutdir ) { std::string dirpath( foutdir->GetPath() ); dirpath += dirname; +#if 0 /// renaming (title and object name) histos /// setting output TDirectory /// Write is called in rmain.cxx hMinv_itr->second->SetTitle( "Tag&Probe invariant mass" ); hMinv_itr->second->SetName( "Minv_TnP" ); hMinv_itr->second->SetDirectory( foutdir->GetDirectory( dirpath.c_str() ) ); +#endif foutdir->cd(); } @@ -370,12 +381,14 @@ void TagNProbe::WriteMinvHisto( TDirectory* foutdir ) { std::string dirpath( foutdir->GetPath() ); dirpath += dirname; +#if 0 /// renaming (title and object name) histos and /// setting output TDirectory /// Write is called in rmain.cxx hMinv_obj_itr->second->SetTitle( "Tag&Probe invariant mass (object-based)" ); hMinv_obj_itr->second->SetName( "Minv_obj_TnP" ); hMinv_obj_itr->second->SetDirectory( foutdir->GetDirectory( dirpath.c_str() ) ); +#endif foutdir->cd(); } diff --git a/Trigger/TrigValidation/TrigInDetValidation/python/TrigInDetArtSteps.py b/Trigger/TrigValidation/TrigInDetValidation/python/TrigInDetArtSteps.py index f8efd79c8d6..ec56e0bed98 100644 --- a/Trigger/TrigValidation/TrigInDetValidation/python/TrigInDetArtSteps.py +++ b/Trigger/TrigValidation/TrigInDetValidation/python/TrigInDetArtSteps.py @@ -104,13 +104,14 @@ class TrigInDetReco(ExecStep): chains += "'HLT_e5_idperf_tight_L1EM3'," flags += 'doEgammaSlice=True;' if (i=='electron-tnp') : - chains += "'HLT_e26_lhtight_gsf_ivarloose_L1EM22VHI'," +# chains += "'HLT_e26_lhtight_gsf_ivarloose_L1EM22VHI'," chains += "'HLT_e26_idperf_gsf_tight_L1EM22VHI'," chains += "'HLT_e26_idperf_loose_L1EM24VHI'," chains += "'HLT_e28_idperf_loose_L1EM24VHI'," - chains += "'HLT_e5_idperf_loose_L1EM3'," - chains += "'HLT_e5_idperf_tight_L1EM3'," +# chains += "'HLT_e5_idperf_loose_L1EM3'," +# chains += "'HLT_e5_idperf_tight_L1EM3'," chains += "'HLT_e26_lhtight_ivarloose_e5_lhvloose_idperf_probe_L1EM22VHI'," + chains += "'HLT_e26_lhtight_e15_etcut_idperf_probe_50invmAB130_L1eEM22M'," flags += 'doEgammaSlice=True;' if (i=='tau') : chains += "'HLT_tau25_idperf_tracktwoMVA_L1TAU12IM'," diff --git a/Trigger/TrigValidation/TrigInDetValidation/test/test_trigID_all_ttbar_tier0_pu40.py b/Trigger/TrigValidation/TrigInDetValidation/test/test_trigID_all_ttbar_tier0_pu40.py index 24faec5a6a4..2f4c6e044b0 100755 --- a/Trigger/TrigValidation/TrigInDetValidation/test/test_trigID_all_ttbar_tier0_pu40.py +++ b/Trigger/TrigValidation/TrigInDetValidation/test/test_trigID_all_ttbar_tier0_pu40.py @@ -25,7 +25,7 @@ # art-output: *.dat -Slices = ['muon','electron','tau','bjet','fsjet'] +Slices = ['muon','electron','electron-tnp','tau','bjet','fsjet'] Events = 4000 Threads = 8 Slots = 8 -- GitLab