From eae4cd4fd4a779dd66c6022a9c7b6f2dd9a176c1 Mon Sep 17 00:00:00 2001 From: "christos@cern.ch" <your.name@cern.ch> Date: Tue, 20 Feb 2018 17:17:26 +0000 Subject: [PATCH] bring Photon Eff up to date, although are not part of the Athena project --- .../AsgElectronEfficiencyCorrectionTool.cxx | 72 ------ .../PhotonEfficiencyCorrection/CMakeLists.txt | 8 +- .../AsgPhotonEfficiencyCorrectionTool.h | 34 +-- .../TPhotonEfficiencyCorrectionTool.h | 1 - .../PhotonEfficiencyCorrection/README | 15 +- .../AsgPhotonEfficiencyCorrectionTool.cxx | 216 ++++++++---------- .../Root/TPhotonEfficiencyCorrectionTool.cxx | 104 +-------- .../PhotonEfficiencyCorrection/data/map0.txt | 41 +++- .../share/myJobOptions.py | 13 +- .../PhotonEfficiencyCorrection_entries.cxx | 14 +- .../util/PrintPhotonSF.cxx | 37 ++- .../util/TestxAODPhotonAlg.cxx | 71 ++++-- 12 files changed, 260 insertions(+), 366 deletions(-) diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronEfficiencyCorrection/Root/AsgElectronEfficiencyCorrectionTool.cxx b/PhysicsAnalysis/ElectronPhotonID/ElectronEfficiencyCorrection/Root/AsgElectronEfficiencyCorrectionTool.cxx index 360c46cf6cd..63053c2bfa7 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronEfficiencyCorrection/Root/AsgElectronEfficiencyCorrectionTool.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronEfficiencyCorrection/Root/AsgElectronEfficiencyCorrectionTool.cxx @@ -877,76 +877,4 @@ AsgElectronEfficiencyCorrectionTool::getValue(const std::string& strKey, std::st return ""; } -int AsgElectronEfficiencyCorrectionTool::currentSimplifiedUncorrSystRegion(const double cluster_eta, const double et) const { - int ptbin = m_UncorrRegions->GetXaxis()->FindBin(et) - 1; - int etabin = m_UncorrRegions->GetYaxis()->FindBin(fabs(cluster_eta)) - 1; - int reg = ((etabin) * m_UncorrRegions->GetNbinsX() + ptbin); - return reg; -} - - - -int AsgElectronEfficiencyCorrectionTool::currentUncorrSystRegion(const double cluster_eta, const double et) const { - int etabin = -1; - int reg = 0; - bool found = false; - float cluster_eta_electron = 0; - std::map<float, std::vector<float> >::const_iterator itr_ptBEGIN = m_pteta_bins.begin(); - std::map<float, std::vector<float> >::const_iterator itr_ptEND = m_pteta_bins.end(); - // Consider using std::map::lower_bound, returns the iterator to the first element that is greater-or-equal to a pt - for (; itr_ptBEGIN != itr_ptEND; itr_ptBEGIN++) { - std::map<float, std::vector<float> >::const_iterator itr_ptBEGINplusOne = itr_ptBEGIN; - itr_ptBEGINplusOne++; - - if ((et > itr_ptBEGIN->first && itr_ptBEGINplusOne == itr_ptEND) || - (et > itr_ptBEGIN->first && et <= itr_ptBEGINplusOne->first)) {// find the pt bin - etabin=0; - // if it is ordered in eta from smaller to larger ascending order - // consider using std::lower_bound(begin,end) to find the position? - if ((itr_ptBEGIN->second).at(0) >= 0) { - cluster_eta_electron = fabs(cluster_eta); - }else { - cluster_eta_electron = (cluster_eta); - }; - for (unsigned int etab = 0; etab < ((itr_ptBEGIN->second).size() - 1); ++etab) {// find the eta bin - etabin++; - if ((cluster_eta_electron) > (itr_ptBEGIN->second).at(etab) && - (cluster_eta_electron) <= (itr_ptBEGIN->second).at(etab + 1)) { - found = true; - break; - } // if ( (cluster_eta_electron) - } // for (unsigned int etab=0;etab<((itr_ptBEGIN->second).size()-1) ; ++etab) - } - if (found) { - break; - } - reg = reg + (itr_ptBEGIN->second).size(); - } - reg = reg + etabin; - return reg; -} - -int AsgElectronEfficiencyCorrectionTool::systUncorrVariationIndex( const xAOD::Electron &inputObject) const{ - int currentSystRegion=-999; - double cluster_eta(-9999.9); - double et(0.0); - - et = inputObject.pt(); - const xAOD::CaloCluster *cluster = inputObject.caloCluster(); - if (cluster) { - cluster_eta = cluster->etaBE(2); - } - - - - if (m_correlation_model == correlationModel::SIMPLIFIED) { - currentSystRegion = currentSimplifiedUncorrSystRegion( cluster_eta, et); - } - - if (m_correlation_model == correlationModel::FULL) { - currentSystRegion = currentUncorrSystRegion( cluster_eta, et); - } - - return currentSystRegion; -} diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/CMakeLists.txt b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/CMakeLists.txt index 345c9eed300..a1c24c78b82 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/CMakeLists.txt +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/CMakeLists.txt @@ -33,8 +33,8 @@ find_package( ROOT COMPONENTS Core Hist RIO MathCore ) atlas_add_library( PhotonEfficiencyCorrectionLib PhotonEfficiencyCorrection/*.h Root/*.cxx PUBLIC_HEADERS PhotonEfficiencyCorrection - INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} - LINK_LIBRARIES ${Boost_LIBRARIES} ${ROOT_LIBRARIES} EgammaAnalysisInterfacesLib AsgTools xAODEgamma + INCLUDE_DIRS ${BOOST_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} + LINK_LIBRARIES ${BOOST_LIBRARIES} ${ROOT_LIBRARIES} EgammaAnalysisInterfacesLib AsgTools xAODEgamma PATCoreLib PATInterfaces ElectronEfficiencyCorrectionLib PRIVATE_LINK_LIBRARIES xAODEventInfo PathResolver ) @@ -53,8 +53,8 @@ atlas_add_dictionary( PhotonEfficiencyCorrectionDict # Executable(s) in the package: atlas_add_executable( PrintPhotonSF util/PrintPhotonSF.cxx - INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} - LINK_LIBRARIES ${Boost_LIBRARIES} ${ROOT_LIBRARIES} + INCLUDE_DIRS ${BOOST_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} + LINK_LIBRARIES ${BOOST_LIBRARIES} ${ROOT_LIBRARIES} PhotonEfficiencyCorrectionLib ) if( XAOD_STANDALONE ) diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/PhotonEfficiencyCorrection/AsgPhotonEfficiencyCorrectionTool.h b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/PhotonEfficiencyCorrection/AsgPhotonEfficiencyCorrectionTool.h index df0d569eafd..e81d62c5dd5 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/PhotonEfficiencyCorrection/AsgPhotonEfficiencyCorrectionTool.h +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/PhotonEfficiencyCorrection/AsgPhotonEfficiencyCorrectionTool.h @@ -11,17 +11,17 @@ @class AthPhotonEfficiencyCorrectionTool @brief Calculate the egamma scale factors in Athena - @author Rob Roy Fletcher, Karsten Koeneke, Michael Pitt, Giovanni Marchiori - @date August 2014 + @author Michael Pitt <michael.pitt@cern.ch>, Giovanni Marchiori + @date February 2018 */ // STL includes #include <vector> #include <string> -#include <fstream> // std::ifstream +#include <fstream> +#include <unordered_map> // Utility includes -#include "boost/unordered_map.hpp" #include "boost/algorithm/string.hpp" // this one to replace std::string names // Include the return object and the underlying ROOT tool @@ -103,25 +103,26 @@ private: /// Pointer to the underlying ROOT based tool Root::TPhotonEfficiencyCorrectionTool* m_rootTool_unc; Root::TPhotonEfficiencyCorrectionTool* m_rootTool_con; - /// additional pointers for ISO SF using RadZ decays - Root::TPhotonEfficiencyCorrectionTool* m_rootTool_uncRadZ; - Root::TPhotonEfficiencyCorrectionTool* m_rootTool_conRadZ; /// A dummy return TResult object Root::TResult m_resultDummy; /// Systematics filter map - boost::unordered_map<CP::SystematicSet, CP::SystematicSet> m_systFilter; + std::unordered_map<CP::SystematicSet, CP::SystematicSet> m_systFilter; /// Currently applied systematics CP::SystematicSet* m_appliedSystematics = nullptr; // The prefix for the systematic name std::string m_sysSubstring; - std::string m_sysSubstringRadZ; // Get the correction filename from the map - std::string getFileName(std::string isoWP, bool isConv, std::string sufix); + std::string getFileName(std::string isoWP, std::string trigWP, bool isConv); + + // Set prefix of the corresponding calibration filenames: + std::string file_prefix_ID="offline.Tight"; + std::string file_prefix_ISO="Isolation.isolFixedCut"; + std::string file_prefix_Trig="HLT"; // Properties @@ -141,15 +142,16 @@ private: /// Isolation working point std::string m_isoWP; + /// Trigger name for trigger SF + std::string m_trigger; + /// map filename std::string m_mapFile; - /// photonPT threshold for different isolation menus - float m_Threshold_lowPT; - float m_Threshold_highPT; - bool m_UseRadZ_mediumPT; - - + //use RandomRun Number + bool m_useRandomRunNumber; + int m_defaultRandomRunNumber; + }; // End: class definition diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/PhotonEfficiencyCorrection/TPhotonEfficiencyCorrectionTool.h b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/PhotonEfficiencyCorrection/TPhotonEfficiencyCorrectionTool.h index 10f5e710367..afcff03dba1 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/PhotonEfficiencyCorrection/TPhotonEfficiencyCorrectionTool.h +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/PhotonEfficiencyCorrection/TPhotonEfficiencyCorrectionTool.h @@ -80,7 +80,6 @@ namespace Root { const double cluster_eta, const double et /* in MeV */ ); - double GetIsoSyst(bool isConv, double eta, int isolationcut); private : }; diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/README b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/README index 424e376f43b..6f67e42de43 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/README +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/README @@ -9,16 +9,19 @@ This is a short README of the TPhotonEfficiencyCorrection class, this class inhe TPhotonEfficiencyCorrection - class to retrieve the photon scale factors Up-to-date information about the tool. can be found on its dedicated twiki page: -runI: -https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/PhotonEfficiencyCorrection -runII: https://twiki.cern.ch/twiki/bin/view/AtlasProtected/PhotonEfficiencyRun2 -https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/IsolationSF2016DS1 +https://twiki.cern.ch/twiki/bin/view/AtlasProtected/IsolationFeb2018RecomRel21 -In case you feel that some piece of information is missing, please feel free to contact the authors (Giovanni.Marchiori@cern.ch,Michael.Pitt@cern.ch). +In case you feel that some piece of information is missing, please feel free to contact the author (Michael.Pitt@cern.ch). #example in ROOT: -rcSetup -f Base,2.4.27; rc compile +mkdir source build run; cd build +asetup 21.2,AnalysisBase,latest +mv CMakeLists.txt ../source +cmake ../source +make; source x86_64-slc6-gcc62-opt/setup.sh +cd ../run + to test on a AOD file run TestxAODPhotonTool [filename] to test the output of the input files (stored in the CalibArea) run diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/Root/AsgPhotonEfficiencyCorrectionTool.cxx b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/Root/AsgPhotonEfficiencyCorrectionTool.cxx index 6815801477d..8a556be4008 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/Root/AsgPhotonEfficiencyCorrectionTool.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/Root/AsgPhotonEfficiencyCorrectionTool.cxx @@ -6,8 +6,8 @@ @class AthPhotonEfficiencyCorrectionTool @brief Calculate the photon scale factors in Athena - @author Rob Roy Fletcher <rob.fletcher@cern.ch>, Karsten Koeneke, Michael Pitt - @date August 2014 + @author Michael Pitt <michael.pitt@cern.ch>, Giovanni Marchiori + @date February 2018 */ // Include this class's header @@ -16,7 +16,6 @@ // STL includes #include <string> #include <cfloat> -//#include <climits> #include <iostream> #include <limits.h> @@ -38,7 +37,11 @@ #define MIN_ET 10000.0 #define MIN_ET_OF_SF 10000.0 #define MIN_ET_Iso_SF 10000.0 -#define MAX_ET_OF_SF 2999999.9 +#define MIN_ET_Trig_SF 10000.0 +#define MAX_ET_OF_SF 1499999.99 +#define MAX_ET_Iso_SF 999999.99 +#define MAX_ET_Trig_SF 99999.99 + // ============================================================================= // Standard constructor @@ -47,18 +50,13 @@ AsgPhotonEfficiencyCorrectionTool::AsgPhotonEfficiencyCorrectionTool( std::strin AsgTool(myname), m_rootTool_unc(0), m_rootTool_con(0), - m_rootTool_uncRadZ(0), - m_rootTool_conRadZ(0), m_appliedSystematics(0), - m_sysSubstring(""), - m_sysSubstringRadZ("") + m_sysSubstring("") { // Create an instances of the underlying ROOT tools m_rootTool_unc = new Root::TPhotonEfficiencyCorrectionTool(); m_rootTool_con = new Root::TPhotonEfficiencyCorrectionTool(); - m_rootTool_uncRadZ = new Root::TPhotonEfficiencyCorrectionTool(); - m_rootTool_conRadZ = new Root::TPhotonEfficiencyCorrectionTool(); // Declare the needed properties declareProperty( "CorrectionFileNameConv", m_corrFileNameConv="", @@ -77,10 +75,17 @@ AsgPhotonEfficiencyCorrectionTool::AsgPhotonEfficiencyCorrectionTool( std::strin declareProperty( "ResultName", m_resultName="", "The string for the result"); // Properties needed for isolation corrections - declareProperty( "IsoWP", m_isoWP="", "Set isolation WP, if this string is empty the tool will return ID SF"); - declareProperty( "Threshold_lowPT", m_Threshold_lowPT=25.0, "low pT threshold for ISO SF(default=25)"); - declareProperty( "Threshold_highPT", m_Threshold_highPT=100.0, "high pT threshold for ISO SF (default=100)"); - declareProperty( "UseRadiativeZSF_mediumPT",m_UseRadZ_mediumPT=false, "use RadZ derived SF (default=true)"); + declareProperty( "IsoKey", m_isoWP="", "Set isolation WP, if this string is empty the tool will return ID SF"); + + // Properties needed for trigger SF + declareProperty( "TriggerKey", m_trigger="", "Set trigger, if this string is empty the tool will return ID SF"); + + // Properties related to the receiving of event run number + declareProperty("UseRandomRunNumber", m_useRandomRunNumber = true, + "Set if use RandomRunNumber from eventinfo"); + declareProperty("DefaultRandomRunNumber", m_defaultRandomRunNumber = 999999, + "Set default run number manually"); + } @@ -95,8 +100,6 @@ AsgPhotonEfficiencyCorrectionTool::~AsgPhotonEfficiencyCorrectionTool() if ( m_rootTool_unc ) delete m_rootTool_unc; if ( m_rootTool_con ) delete m_rootTool_con; - if ( m_rootTool_uncRadZ ) delete m_rootTool_uncRadZ; - if ( m_rootTool_conRadZ ) delete m_rootTool_conRadZ; } // ============================================================================= @@ -105,21 +108,16 @@ AsgPhotonEfficiencyCorrectionTool::~AsgPhotonEfficiencyCorrectionTool() StatusCode AsgPhotonEfficiencyCorrectionTool::initialize() { // Resolve the paths to the input files - std::vector < std::string > corrFileNameList; + std::vector < std::string > m_corrFileNameList; // First check if the tool is initialized using the input files or map if(m_mapFile.size()){ // using map file - corrFileNameList.push_back(getFileName(m_isoWP,true,"")); // converted photons input - corrFileNameList.push_back(getFileName(m_isoWP,false,"")); // unconverted photons input - // if isolation SF are initialized, then read RadZ inputs: - if(m_isoWP.size()){ - corrFileNameList.push_back(getFileName(m_isoWP,true,"_RadZ")); // converted photons input - corrFileNameList.push_back(getFileName(m_isoWP,false,"_RadZ")); // unconverted photons input - } + m_corrFileNameList.push_back(getFileName(m_isoWP,m_trigger,true)); // converted photons input + m_corrFileNameList.push_back(getFileName(m_isoWP,m_trigger,false)); // unconverted photons input } else if(m_corrFileNameConv.size() && m_corrFileNameUnconv.size()){ // initialize the tool using input files (old scheme) - corrFileNameList.push_back(m_corrFileNameConv); - corrFileNameList.push_back(m_corrFileNameUnconv); + m_corrFileNameList.push_back(m_corrFileNameConv); + m_corrFileNameList.push_back(m_corrFileNameUnconv); } else{ ATH_MSG_ERROR ( "Fail to resolve input file name, check if you set MapFilePath or CorrectionFileName properly" ); @@ -127,36 +125,31 @@ StatusCode AsgPhotonEfficiencyCorrectionTool::initialize() } // once the input files are retrieved, update the path using PathResolver or TOOL/data folder - for ( unsigned int i=0; i<corrFileNameList.size(); ++i ){ - - //First try the PathResolver - std::string filename = PathResolverFindCalibFile( corrFileNameList.at(i) ); + for ( unsigned int i=0; i<m_corrFileNameList.size(); ++i ){ - // ROOTCore: Data folder - char *rootCoreArea = getenv("ROOTCOREBIN"); - if(filename.empty() && rootCoreArea != NULL){ - filename = std::string(rootCoreArea) + "/data/"+ corrFileNameList.at(i); - } + //Using the PathResolver to locate the file + std::string filename = PathResolverFindCalibFile( m_corrFileNameList.at(i) ); if (filename.empty()){ - ATH_MSG_ERROR ( "Could NOT resolve file name " << corrFileNameList.at(i) ); + ATH_MSG_ERROR ( "Could NOT resolve file name " << m_corrFileNameList.at(i) ); return StatusCode::FAILURE ; } else{ - ATH_MSG_INFO(" Path found = "<<filename); + ATH_MSG_INFO(" Using path = "<<filename); } - corrFileNameList.at(i) = filename; + m_corrFileNameList.at(i) = filename; } - // Set prefix for sustematics if this is ISO or ID SF - if( corrFileNameList[0].find("offline.Tight") != std::string::npos) m_sysSubstring="ID_"; - if( corrFileNameList[0].find("Isolation.isolFixedCut") != std::string::npos) {m_sysSubstring="TRKISO_"; m_sysSubstringRadZ="LOWPTISO_";} + // Set prefix for sustematics if this is ISO, Trigger or ID SF + if( m_corrFileNameList[0].find(file_prefix_ID) != std::string::npos) m_sysSubstring="ID_"; + if( m_corrFileNameList[0].find(file_prefix_ISO) != std::string::npos) m_sysSubstring="ISO_"; + if( m_corrFileNameList[0].find(file_prefix_Trig) != std::string::npos) m_sysSubstring="TRIGGER_"; if(m_sysSubstring == "") {ATH_MSG_ERROR ( "Invalid input file" ); return StatusCode::FAILURE;} // Configure the underlying Root tool - m_rootTool_con->addFileName( corrFileNameList[0] ); - m_rootTool_unc->addFileName( corrFileNameList[1] ); + m_rootTool_con->addFileName( m_corrFileNameList[0] ); + m_rootTool_unc->addFileName( m_corrFileNameList[1] ); // Forward the message level m_rootTool_con->msg().setLevel(this->msg().level()); @@ -164,12 +157,12 @@ StatusCode AsgPhotonEfficiencyCorrectionTool::initialize() // Check if ForceDataType is set up properly (should be 3 for AtlFast2) - if(TString(corrFileNameList[0]).Contains("AFII") && m_dataTypeOverwrite!=3) + if(TString(m_corrFileNameList[0]).Contains("AFII") && m_dataTypeOverwrite!=3) { ATH_MSG_ERROR("Property ForceDataType is set to "<< m_dataTypeOverwrite << ", while it should be 3 for FastSim"); return StatusCode::FAILURE; } - if(!TString(corrFileNameList[0]).Contains("AFII") && m_dataTypeOverwrite!=1) + if(!TString(m_corrFileNameList[0]).Contains("AFII") && m_dataTypeOverwrite!=1) { ATH_MSG_ERROR("Property ForceDataType is set to "<< m_dataTypeOverwrite << ", while it should be 1 for FullSim"); return StatusCode::FAILURE; @@ -182,19 +175,6 @@ StatusCode AsgPhotonEfficiencyCorrectionTool::initialize() return StatusCode::FAILURE; } - // For isolation SF initialize additional instances for lowPT photons - if(m_isoWP.size()){ - m_rootTool_conRadZ->addFileName( m_corrFileNameList[2] ); - m_rootTool_uncRadZ->addFileName( m_corrFileNameList[3] ); - m_rootTool_conRadZ->msg().setLevel(this->msg().level()); - m_rootTool_uncRadZ->msg().setLevel(this->msg().level()); - if ( (0 == m_rootTool_conRadZ->initialize()) || (0 == m_rootTool_uncRadZ->initialize()) ) - { - ATH_MSG_ERROR("Could not initialize the TPhotonEfficiencyCorrectionTool!"); - return StatusCode::FAILURE; - } - } - // Copy the now filled TResult to the dummy m_resultDummy = m_rootTool_con->getTResult(); // do only for converted photons instance @@ -217,14 +197,6 @@ StatusCode AsgPhotonEfficiencyCorrectionTool::finalize() ATH_MSG_ERROR("Something went wrong at finalize!"); return StatusCode::FAILURE; } - // finilize instances in case of IsolationSF - if(m_isoWP.size()){ - if ( !(m_rootTool_conRadZ->finalize()) || !(m_rootTool_uncRadZ->finalize()) ) - { - ATH_MSG_ERROR("Something went wrong at finalize!"); - return StatusCode::FAILURE; - } - } return StatusCode::SUCCESS ; } @@ -241,14 +213,24 @@ const Root::TResult& AsgPhotonEfficiencyCorrectionTool::calculate( const xAOD::E return m_resultDummy; } - // Get the run number + // Get the run number const xAOD::EventInfo* eventInfo = evtStore()->retrieve< const xAOD::EventInfo> ("EventInfo"); if(!eventInfo){ ATH_MSG_ERROR ( "Could not retrieve EventInfo object!" ); return m_resultDummy; } - const unsigned int runnumber = eventInfo->runNumber(); + //Retrieve the proper random Run Number + unsigned int runnumber = m_defaultRandomRunNumber; + if (m_useRandomRunNumber) { + static const SG::AuxElement::Accessor<unsigned int> randomrunnumber("RandomRunNumber"); + if (!randomrunnumber.isAvailable(*eventInfo)) { + ATH_MSG_WARNING("Pileup tool not run before using PhotonEfficiencyTool! SFs do not reflect PU distribution in data"); + return m_resultDummy; + } + runnumber = randomrunnumber(*(eventInfo)); + } + // Get the needed values (et, etas2, conv. flag) from the egamma object // check if converted @@ -265,20 +247,32 @@ const Root::TResult& AsgPhotonEfficiencyCorrectionTool::calculate( const xAOD::E // Check if photon in the range to get the SF if(eta2>MAXETA) { - ATH_MSG_WARNING( "No correction factor provided for eta "<<cluster->etaBE(2)<<" Returning SF = 1 + / - 1"); - return m_resultDummy; + ATH_MSG_WARNING( "No correction factor provided for eta "<<cluster->etaBE(2)<<" Returning SF = 1 + / - 1"); + return m_resultDummy; } if(et<MIN_ET_OF_SF && m_sysSubstring=="ID_") { - ATH_MSG_WARNING( "No ID scale factor uncertainty provided for et "<<et/1e3<<"GeV Returning SF = 1 + / - 1"); - return m_resultDummy; - } - if(m_sysSubstring=="TRKISO_" && et<MIN_ET_Iso_SF) { - ATH_MSG_WARNING( "No isolation scale factor uncertainty provided for et "<<et/1e3<<"GeV Returning SF = 1 + / - 1"); - return m_resultDummy; - } - if(et>MAX_ET_OF_SF) { - ATH_MSG_WARNING( "No scale factor provided for et "<<et/1e3<<"GeV Returning SF for "<<MAX_ET_OF_SF/1e3<<"GeV"); - et=MAX_ET_OF_SF; + ATH_MSG_WARNING( "No ID scale factor uncertainty provided for et "<<et/1e3<<"GeV Returning SF = 1 + / - 1"); + return m_resultDummy; + } + if(et<MIN_ET_Iso_SF && m_sysSubstring=="ISO_") { + ATH_MSG_WARNING( "No isolation scale factor uncertainty provided for et "<<et/1e3<<"GeV Returning SF = 1 + / - 1"); + return m_resultDummy; + } + if(et<MIN_ET_Trig_SF && m_sysSubstring=="TRIGGER_") { + ATH_MSG_WARNING( "No trigger scale factor uncertainty provided for et "<<et/1e3<<"GeV Returning SF = 1 + / - 1"); + return m_resultDummy; + } + if(et>MAX_ET_OF_SF && m_sysSubstring=="ID_") { + ATH_MSG_WARNING( "No scale factor provided for et "<<et/1e3<<"GeV Returning SF for "<<MAX_ET_OF_SF/1e3<<"GeV"); + et=MAX_ET_OF_SF; + } + if(et>MAX_ET_Iso_SF && m_sysSubstring=="ISO_") { + ATH_MSG_WARNING( "No isolation scale factor provided for et "<<et/1e3<<"GeV Returning SF for "<<MAX_ET_Iso_SF/1e3<<"GeV"); + et=MAX_ET_Iso_SF; + } + if(et>MAX_ET_Trig_SF && m_sysSubstring=="TRIGGER_") { + ATH_MSG_WARNING( "No trigger scale factor provided for et "<<et/1e3<<"GeV Returning SF for "<<MAX_ET_Trig_SF/1e3<<"GeV"); + et=MAX_ET_Trig_SF; } // Get the DataType of the current egamma object @@ -292,13 +286,6 @@ const Root::TResult& AsgPhotonEfficiencyCorrectionTool::calculate( const xAOD::E if ( m_dataTypeOverwrite >= 0 ) dataType = (PATCore::ParticleDataType::DataType)m_dataTypeOverwrite; // Call the ROOT tool to get an answer, check if the SF is for isolation or ID - if(m_isoWP.size()){ - double RadZ_ptcut = m_UseRadZ_mediumPT ? m_Threshold_highPT : m_Threshold_lowPT; - if(et<RadZ_ptcut*1e3) - return isConv ? m_rootTool_conRadZ->calculate( dataType,runnumber,eta2,et /* in MeV */) : m_rootTool_uncRadZ->calculate( dataType,runnumber,eta2,et /* in MeV */); - else - return isConv ? m_rootTool_con->calculate( dataType,runnumber,eta2,et /* in MeV */) : m_rootTool_unc->calculate( dataType,runnumber,eta2,et /* in MeV */); - } return isConv ? m_rootTool_con->calculate( dataType,runnumber,eta2,et /* in MeV */) : m_rootTool_unc->calculate( dataType,runnumber,eta2,et /* in MeV */); } @@ -337,13 +324,10 @@ CP::CorrectionCode AsgPhotonEfficiencyCorrectionTool::getEfficiencyScaleFactor(c } //Get the result + the uncertainty - float sigma(0); - // will check if it isolation SF and if it correspong to low or high PT - if(m_isoWP.size() && (inputObject.pt()<((m_UseRadZ_mediumPT ? m_Threshold_highPT : m_Threshold_lowPT)*1e3))) - sigma=appliedSystematics().getParameterByBaseName("PH_EFF_"+m_sysSubstringRadZ+"Uncertainty"); - else - sigma=appliedSystematics().getParameterByBaseName("PH_EFF_"+m_sysSubstring+"Uncertainty"); - efficiencyScaleFactor=calculate(&inputObject).getScaleFactor()+sigma*calculate(&inputObject).getTotalUncertainty(); + float m_sigma(0); + m_sigma=appliedSystematics().getParameterByBaseName("PH_EFF_"+m_sysSubstring+"Uncertainty"); + efficiencyScaleFactor=calculate(&inputObject).getScaleFactor()+m_sigma*calculate(&inputObject).getTotalUncertainty(); + return CP::CorrectionCode::Ok; } @@ -371,10 +355,10 @@ CP::CorrectionCode AsgPhotonEfficiencyCorrectionTool::applyEfficiencyScaleFactor float eff; if(m_appliedSystematics==nullptr) eff = calculate(&inputObject).getScaleFactor(); - else{ // if SF is up or down varies by sigma - float sigma(0); - sigma=appliedSystematics().getParameterByBaseName("PH_EFF_"+m_sysSubstring+"Uncertainty"); - eff=calculate(&inputObject).getScaleFactor()+sigma*calculate(&inputObject).getTotalUncertainty(); + else{ // if SF is up or down varies by m_sigma + float m_sigma(0); + m_sigma=appliedSystematics().getParameterByBaseName("PH_EFF_"+m_sysSubstring+"Uncertainty"); + eff=calculate(&inputObject).getScaleFactor()+m_sigma*calculate(&inputObject).getTotalUncertainty(); } // decorate photon ATH_MSG_INFO("decorate object"); @@ -401,14 +385,7 @@ CP::SystematicSet AsgPhotonEfficiencyCorrectionTool::affectingSystematics() cons mySysSet.insert(CP::SystematicVariation("PH_EFF_"+m_sysSubstring+"Uncertainty", CP::SystematicVariation::CONTINUOUS)); mySysSet.insert(CP::SystematicVariation("PH_EFF_"+m_sysSubstring+"Uncertainty", 1)); mySysSet.insert(CP::SystematicVariation("PH_EFF_"+m_sysSubstring+"Uncertainty", -1)); - - // Add systematics for lowPT isolation - if(m_isoWP.size()){ - mySysSet.insert(CP::SystematicVariation("PH_EFF_"+m_sysSubstringRadZ+"Uncertainty", CP::SystematicVariation::CONTINUOUS)); - mySysSet.insert(CP::SystematicVariation("PH_EFF_"+m_sysSubstringRadZ+"Uncertainty", 1)); - mySysSet.insert(CP::SystematicVariation("PH_EFF_"+m_sysSubstringRadZ+"Uncertainty", -1)); - } - + return mySysSet; } @@ -427,13 +404,7 @@ CP::SystematicSet AsgPhotonEfficiencyCorrectionTool::recommendedSystematics() co CP::SystematicSet mySysSet; mySysSet.insert(CP::SystematicVariation("PH_EFF_"+m_sysSubstring+"Uncertainty", 1)); mySysSet.insert(CP::SystematicVariation("PH_EFF_"+m_sysSubstring+"Uncertainty", -1)); - - // Add systematics for lowPT isolation - if(m_isoWP.size()){ - mySysSet.insert(CP::SystematicVariation("PH_EFF_"+m_sysSubstringRadZ+"Uncertainty", 1)); - mySysSet.insert(CP::SystematicVariation("PH_EFF_"+m_sysSubstringRadZ+"Uncertainty", -1)); - } - + return mySysSet; } @@ -468,11 +439,8 @@ applySystematicVariation ( const CP::SystematicSet& systConfig ) // Map Key Feature //=============================================================================== // Gets the correction filename from map -std::string AsgPhotonEfficiencyCorrectionTool::getFileName(std::string isoWP, bool isConv, std::string sufix) { - - // Check if isoWP is TightCaloOnly, then will read the inputs from RadZ files - if(0==isoWP.compare("TightCaloOnly")) sufix="_RadZ"; - +std::string AsgPhotonEfficiencyCorrectionTool::getFileName(std::string isoWP, std::string trigWP, bool isConv) { + // First locate the map file: std::string mapFileName = PathResolverFindCalibFile( m_mapFile ); if(mapFileName.empty()){ @@ -480,8 +448,14 @@ std::string AsgPhotonEfficiencyCorrectionTool::getFileName(std::string isoWP, bo return mapFileName; // return an empty string } - std::string correction_type = isoWP.empty() ? "ID_Tight" : "ISO_"+isoWP+sufix; - correction_type += isConv ? "_Converted" : "_Unconverted"; + // Construct correction type: + std::string correction_type = "ID_Tight"; + if(!trigWP.empty()) correction_type = "Trigger_"+trigWP+"_"+isoWP; + else if(!isoWP.empty()) correction_type = "ISO_"+isoWP; + + // trigger SF same for con/unc photons + if(trigWP.empty()) {correction_type += isConv ? "_Converted" : "_Unconverted";} + std::string value; // Read the map file to find the proper correction filename @@ -492,7 +466,7 @@ std::string AsgPhotonEfficiencyCorrectionTool::getFileName(std::string isoWP, bo } while (!is.eof()) { std::string strLine; - getline(is,strLine); + getline(is,strLine); int nPos = strLine.find('='); diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/Root/TPhotonEfficiencyCorrectionTool.cxx b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/Root/TPhotonEfficiencyCorrectionTool.cxx index 15bef4b89ce..6204055a6cd 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/Root/TPhotonEfficiencyCorrectionTool.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/Root/TPhotonEfficiencyCorrectionTool.cxx @@ -70,103 +70,9 @@ const Root::TResult& Root::TPhotonEfficiencyCorrectionTool::calculate( const PAT * Get the zeroth entry, by convention, this is the efficiency or scale factor or MVA response or.. * Get the first entry, by convention, this is the total uncertainty */ - m_result.setResult(0, result[static_cast<size_t>(Root::TElectronEfficiencyCorrectionTool::Position::SF)]); - m_result.setResult(1, result[static_cast<size_t>(Root::TElectronEfficiencyCorrectionTool::Position::Total)]); - return m_result; -} - - - - -//=================================================================================== -// Calculate the assosiated uncertainties with various photon isolation prescriptions -//=================================================================================== -double Root::TPhotonEfficiencyCorrectionTool::GetIsoSyst(bool isConv,double eta, int isolationcut) -{ -switch (isolationcut){ - case 3: - if(isConv){ - if(fabs(eta)<0.6) return 0.0038; - else if(fabs(eta)<1.37) return 0.0045; - else if(fabs(eta)<1.52) return 0; - else if(fabs(eta)<1.81) return 2.7e-05; - else if(fabs(eta)<2.37) return 0.0046; - } - else{ - if(fabs(eta)<0.6) return 0.00043; - else if(fabs(eta)<1.37) return 0.00069; - else if(fabs(eta)<1.52) return 0; - else if(fabs(eta)<1.81) return 0.00095; - else if(fabs(eta)<2.37) return 0.0023; - } - return 0; - case 4: return 0; - case 5: - if(isConv){ - if(fabs(eta)<0.6) return 0.0036; - else if(fabs(eta)<1.37) return 0.0007; - else if(fabs(eta)<1.52) return 0; - else if(fabs(eta)<1.81) return 0.0009; - else if(fabs(eta)<2.37) return 0.0016; - } - else{ - if(fabs(eta)<0.6) return 0.001; - else if(fabs(eta)<1.37) return 0.0019; - else if(fabs(eta)<1.52) return 0; - else if(fabs(eta)<1.81) return 0.002; - else if(fabs(eta)<2.37) return 0.0023; - } - return 0; - case 6: - if(isConv){ - if(fabs(eta)<0.6) return 0.0045; - else if(fabs(eta)<1.37) return 0.0034; - else if(fabs(eta)<1.52) return 0; - else if(fabs(eta)<1.81) return 0.0057; - else if(fabs(eta)<2.37) return 0.0016; - } - else{ - if(fabs(eta)<0.6) return 0.0028; - else if(fabs(eta)<1.37) return 0.0035; - else if(fabs(eta)<1.52) return 0; - else if(fabs(eta)<1.81) return 0.0012; - else if(fabs(eta)<2.37) return 0.0048; - } - return 0; - case 7: - if(isConv){ - if(fabs(eta)<0.6) return 0.011; - else if(fabs(eta)<1.37) return 0.0074; - else if(fabs(eta)<1.52) return 0; - else if(fabs(eta)<1.81) return 0.0089; - else if(fabs(eta)<2.37) return 0.0071; - } - else{ - if(fabs(eta)<0.6) return 0.0033; - else if(fabs(eta)<1.37) return 0.0042; - else if(fabs(eta)<1.52) return 0; - else if(fabs(eta)<1.81) return 0.00041; - else if(fabs(eta)<2.37) return 0.0037; - } - return 0; - case 8: - if(isConv){ - if(fabs(eta)<0.6) return 0.0033; - else if(fabs(eta)<1.37) return 0.00051; - else if(fabs(eta)<1.52) return 0; - else if(fabs(eta)<1.81) return 0.0012; - else if(fabs(eta)<2.37) return 0.00057; - } - else{ - if(fabs(eta)<0.6) return 0.0044; - else if(fabs(eta)<1.37) return 0.0037; - else if(fabs(eta)<1.52) return 0; - else if(fabs(eta)<1.81) return 0.0012; - else if(fabs(eta)<2.37) return 0.0032; - } - return 0; - default: std::cout<<"Wrong isolation input!!!!!"<<std::endl; return 0.; -} -return 0.; - + if(result.size()>static_cast<size_t>(Root::TElectronEfficiencyCorrectionTool::Position::Total)){ + m_result.setResult(0, result[static_cast<size_t>(Root::TElectronEfficiencyCorrectionTool::Position::SF)]); + m_result.setResult(1, result[static_cast<size_t>(Root::TElectronEfficiencyCorrectionTool::Position::Total)]); + } + return m_result; } diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/data/map0.txt b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/data/map0.txt index dfe74fa5266..1a5f78b0a90 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/data/map0.txt +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/data/map0.txt @@ -1,24 +1,41 @@ -ID_Tight_Converted=PhotonEfficiencyCorrection/2015_2016/rel20.7/Moriond2017_v1/PIDSF/efficiencySF.offline.Tight.2016.13TeV.rel20.7.25ns.con.v00.root +ID_Tight_Converted=PhotonEfficiencyCorrection/2015_2017/rel21.2/Winter2018_Prerec_v1/PIDSF/efficiencySF.offline.Tight.13TeV.rel21.25ns.con.v00.root -ID_Tight_Unconverted=PhotonEfficiencyCorrection/2015_2016/rel20.7/Moriond2017_v1/PIDSF/efficiencySF.offline.Tight.2016.13TeV.rel20.7.25ns.unc.v00.root +ID_Tight_Unconverted=PhotonEfficiencyCorrection/2015_2017/rel21.2/Winter2018_Prerec_v1/PIDSF/efficiencySF.offline.Tight.13TeV.rel21.25ns.unc.v00.root -ISO_Loose_Converted=PhotonEfficiencyCorrection/2015_2016/rel20.7/ICHEP_June2016_v2/isolation/efficiencySF.Isolation.isolFixedCutLoose.2016.13TeV.rel20.7.25ns.con.v02.root +ISO_Loose_Converted=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/isolation/efficiencySF.Isolation.isolFixedCutLoose.13TeV.rel21.25ns.con.TrkCaloRadZTrkCaloSgPh.v18.root -ISO_Loose_Unconverted=PhotonEfficiencyCorrection/2015_2016/rel20.7/ICHEP_June2016_v2/isolation/efficiencySF.Isolation.isolFixedCutLoose.2016.13TeV.rel20.7.25ns.unc.v02.root +ISO_Loose_Unconverted=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/isolation/efficiencySF.Isolation.isolFixedCutLoose.13TeV.rel21.25ns.unc.TrkCaloRadZTrkCaloSgPh.v18.root -ISO_Tight_Converted=PhotonEfficiencyCorrection/2015_2016/rel20.7/ICHEP_June2016_v2/isolation/efficiencySF.Isolation.isolFixedCutTight.2016.13TeV.rel20.7.25ns.con.v02.root +ISO_Tight_Converted=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/isolation/efficiencySF.Isolation.isolFixedCutTight.13TeV.rel21.25ns.con.TrkCaloRadZTrkCaloSgPh.v18.root -ISO_Tight_Unconverted=PhotonEfficiencyCorrection/2015_2016/rel20.7/ICHEP_June2016_v2/isolation/efficiencySF.Isolation.isolFixedCutTight.2016.13TeV.rel20.7.25ns.unc.v02.root +ISO_Tight_Unconverted=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/isolation/efficiencySF.Isolation.isolFixedCutTight.13TeV.rel21.25ns.unc.TrkCaloRadZTrkCaloSgPh.v18.root -ISO_Loose_RadZ_Converted=PhotonEfficiencyCorrection/2015_2016/rel20.7/Moriond2017_v1/isolation/efficiencySF.Isolation.isolFixedCutLoose.2015_2016.13TeV.rel20.7.25ns.con.RadZ.v01.root +ISO_TightCaloOnly_Converted=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/isolation/efficiencySF.Isolation.isolFixedCutTightCaloOnly.13TeV.rel21.25ns.con.CaloRadZCaloSgPh.v18.root -ISO_Loose_RadZ_Unconverted=PhotonEfficiencyCorrection/2015_2016/rel20.7/Moriond2017_v1/isolation/efficiencySF.Isolation.isolFixedCutLoose.2015_2016.13TeV.rel20.7.25ns.unc.RadZ.v01.root +ISO_TightCaloOnly_Unconverted=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/isolation/efficiencySF.Isolation.isolFixedCutTightCaloOnly.13TeV.rel21.25ns.unc.CaloRadZCaloSgPh.v18.root -ISO_Tight_RadZ_Converted=PhotonEfficiencyCorrection/2015_2016/rel20.7/Moriond2017_v1/isolation/efficiencySF.Isolation.isolFixedCutTight.2015_2016.13TeV.rel20.7.25ns.con.RadZ.v01.root +Trigger_HLT_g20_tight_icalovloose_L1EM15VHI_Loose=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g20_tight_icalovloose_L1EM15VHI.FixedCutLoose.root -ISO_Tight_RadZ_Unconverted=PhotonEfficiencyCorrection/2015_2016/rel20.7/Moriond2017_v1/isolation/efficiencySF.Isolation.isolFixedCutTight.2015_2016.13TeV.rel20.7.25ns.unc.RadZ.v01.root +Trigger_HLT_g20_tight_icalovloose_L1EM15VHI_TightCaloOnly=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g20_tight_icalovloose_L1EM15VHI.FixedCutTightCaloOnly.root -ISO_TightCaloOnly_RadZ_Converted=PhotonEfficiencyCorrection/2015_2016/rel20.7/Moriond2017_v1/isolation/efficiencySF.Isolation.isolFixedCutTightCaloOnly.2015_2016.13TeV.rel20.7.25ns.con.RadZ.v01.root +Trigger_HLT_g22_tight_L1EM15VHI_Loose=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g22_tight_L1EM15VHI.FixedCutLoose.root + +Trigger_HLT_g22_tight_L1EM15VHI_TightCaloOnly=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g22_tight_L1EM15VHI.FixedCutTightCaloOnly.root + +Trigger_HLT_g25_loose_Loose=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g25_loose.FixedCutLoose.root + +Trigger_HLT_g25_loose_TightCaloOnly=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g25_loose.FixedCutTightCaloOnly.root + +Trigger_HLT_g25_medium_L1EM20VH_TightCaloOnly=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g25_medium_L1EM20VH.FixedCutTightCaloOnly.root + +Trigger_HLT_g35_loose_Loose=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g35_loose.FixedCutLoose.root + +Trigger_HLT_g35_loose_TightCaloOnly=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g35_loose.FixedCutTightCaloOnly.root + +Trigger_HLT_g35_medium_L1EM20VH_TightCaloOnly=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g35_medium_L1EM20VH.FixedCutTightCaloOnly.root + +Trigger_HLT_g50_loose_L1EM20VH_Loose=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g50_loose_L1EM20VH.FixedCutLoose.root + +Trigger_HLT_g50_loose_L1EM20VH_TightCaloOnly=/afs/cern.ch/user/m/mpitt/public/PhotonEfficiencyCorrection/inputs_r21/trigger/efficiencySF.DI_g_2017_v1_HLT_g50_loose_L1EM20VH.FixedCutTightCaloOnly.root -ISO_TightCaloOnly_RadZ_Unconverted=PhotonEfficiencyCorrection/2015_2016/rel20.7/Moriond2017_v1/isolation/efficiencySF.Isolation.isolFixedCutTightCaloOnly.2015_2016.13TeV.rel20.7.25ns.unc.RadZ.v01.root diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/share/myJobOptions.py b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/share/myJobOptions.py index 11a99ba1524..756321885bd 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/share/myJobOptions.py +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/share/myJobOptions.py @@ -3,7 +3,7 @@ theApp.EvtMax = 100 #set input files - svcMgr has a property that lets you specify the input files, as a list: import AthenaPoolCnvSvc.ReadAthenaPool -svcMgr.EventSelector.InputCollections = [ " /afs/cern.ch/atlas/project/PAT/xAODs/r6630/mc15_13TeV.361106.PowhegPythia8EvtGen_AZNLOCTEQ6L1_Zee.recon.AOD.e3601_s2576_s2132_r6630_tid05358812_00/AOD.05358812._000010.pool.root.1" ] +svcMgr.EventSelector.InputCollections = [ "/afs/cern.ch/atlas/project/PAT/xAODs/r9315/mc16_13TeV.410501.PowhegPythia8EvtGen_A14_ttbar_hdamp258p75_nonallhad.merge.AOD.e5458_s3126_r9364_r9315/AOD.11182705._000001.pool.root.1" ] #One of the existing master sequences where one should attach all algorithms algSeq = CfgMgr.AthSequencer("AthAlgSeq") @@ -12,15 +12,10 @@ algSeq = CfgMgr.AthSequencer("AthAlgSeq") from PhotonEfficiencyCorrection.PhotonEfficiencyCorrectionConf import testAthenaPhotonAlg alg = testAthenaPhotonAlg() -#define input files, for now it uses my own directory where the tool is, since it not a working part of the athena, please note that the current recomendation of PhotonID WG can be found here: https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/PhotonEfficiencyCorrection +#define input files, please note that the current recomendation of PhotonID WG can be found here: https://twiki.cern.ch/twiki/bin/view/AtlasProtected/PhotonEfficiencyRun2 -#Set inputs for ID efficiency -alg.PhotonEfficiencyCorrectionTool.CorrectionFileNameConv = "PhotonEfficiencyCorrection/v1/efficiencySF.offline.Tight.2015.13TeV.rel20.con.v01.root"; -alg.PhotonEfficiencyCorrectionTool.CorrectionFileNameUnconv = "PhotonEfficiencyCorrection/v1/efficiencySF.offline.Tight.2015.13TeV.rel20.unc.v01.root"; - -#Or set inputs for track isolation efficiency (comment previous) -#alg.PhotonEfficiencyCorrectionTool.CorrectionFileNameConv = "PhotonEfficiencyCorrection/efficiencySF.offline.isolFixedCutLoose.2015.13TeV.rel20.con.v01.root"; -#alg.PhotonEfficiencyCorrectionTool.CorrectionFileNameUnconv = "PhotonEfficiencyCorrection/efficiencySF.offline.isolFixedCutLoose.2015.13TeV.rel20.unc.v01.root"; +#Set Properties for photonID_SF tool - setup the map.txt file +alg.PhotonEfficiencyCorrectionTool.MapFilePath = "PhotonEfficiencyCorrection/2015_2016/rel20.7/Moriond2017_v1/map2.txt"; #Set DataType: for data use 0 (or don't run the tool - faster), for FULLSIM use 1, and for FASTSIM use 3, please note that the input files are also should be different alg.PhotonEfficiencyCorrectionTool.ForceDataType = 1 diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/src/components/PhotonEfficiencyCorrection_entries.cxx b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/src/components/PhotonEfficiencyCorrection_entries.cxx index 4342c685400..965a745e060 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/src/components/PhotonEfficiencyCorrection_entries.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/src/components/PhotonEfficiencyCorrection_entries.cxx @@ -1,8 +1,18 @@ +// Gaudi/Athena include(s): +#include "GaudiKernel/DeclareFactoryEntries.h" + +// Local include(s): #include "PhotonEfficiencyCorrection/AsgPhotonEfficiencyCorrectionTool.h" #include "../testAthenaPhotonAlg.h" -DECLARE_COMPONENT( AsgPhotonEfficiencyCorrectionTool ) +DECLARE_TOOL_FACTORY( AsgPhotonEfficiencyCorrectionTool ) + +DECLARE_ALGORITHM_FACTORY( testAthenaPhotonAlg ) -DECLARE_COMPONENT( testAthenaPhotonAlg ) +DECLARE_FACTORY_ENTRIES( PhotonEfficiencyCorrection ) +{ + DECLARE_TOOL( AsgPhotonEfficiencyCorrectionTool ) + DECLARE_ALGORITHM( testAthenaPhotonAlg ) +} \ No newline at end of file diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/util/PrintPhotonSF.cxx b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/util/PrintPhotonSF.cxx index f4c8eee03b8..102f2764a41 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/util/PrintPhotonSF.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/util/PrintPhotonSF.cxx @@ -1,8 +1,5 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - //PrintPhotonSF.cxx - print SF for a given input +//michael.pitt@cern.ch // System include(s): #include <stdio.h> @@ -13,6 +10,8 @@ // ROOT include(s): #include "TFile.h" #include "TString.h" +#include "TList.h" +#include "TKey.h" // Local include(s): #include "PhotonEfficiencyCorrection/TPhotonEfficiencyCorrectionTool.h" @@ -37,11 +36,33 @@ int main (int argc, const char * argv[]) { } TString file(argv[1]); - if(!TFile::Open(file)->GetListOfKeys()->Contains("0_99999999999")){ - printf("Error: no TDirectory 0_99999999999, check your input file\n"); + // Check which directories (run numbers) exists + //Let user to deside which one to use in case of multiple + TList * listDirectories = TFile::Open(file)->GetListOfKeys(); + const int ndirs = listDirectories->GetSize(); + if(0==ndirs){ + printf("Error: file %s does not contains any keys\n",argv[1]); return 0; + } + TString dirName = listDirectories->First()->GetName(); + if(ndirs>1) { + printf("Reads: %s, found %d folders:\n",argv[1],ndirs); + TIter next(listDirectories); + TKey *key; + while ((key = (TKey*)next())) printf("%s\n",key->GetName()); + printf("which directory to use? (type the number from 1 to %d): ",ndirs); + int ndir_input=0; cin >> ndir_input; + if(ndir_input>ndirs || ndir_input<1) + printf("\nWarning... entered wrong key number, will print SF for directory: %s\n",dirName.Data()); + else{ + dirName = listDirectories->At(ndir_input-1)->GetName(); + printf("\nprint SF for directory: %s\n",dirName.Data()); + } } + else printf("Reads: %s\nDirectory: %s\n",argv[1],dirName.Data()); + // read first run number from the directory name: + int run_number = atoi(dirName.Tokenize("_")->First()->GetName()); if(getenv("ROOTCOREDIR")==NULL){ cout << "Please setup RootCore before running the PrintPhotonSF [file]"<<endl; return 0.; @@ -60,7 +81,7 @@ PATCore::ParticleDataType::DataType datatype=PATCore::ParticleDataType::Full; if(file.Contains("AFII")) datatype=PATCore::ParticleDataType::Fast; // Access the file to get the histogram binning: -TH2F * h = file.Contains("AFII") ? (TH2F*)TFile::Open(file)->Get("0_99999999999/AltFast2_sf") : (TH2F*)TFile::Open(file)->Get("0_99999999999/FullSim_sf"); +TH2F * h = file.Contains("AFII") ? (TH2F*)TFile::Open(file)->Get(Form("%s/AltFast2_sf",dirName.Data())) : (TH2F*)TFile::Open(file)->Get(Form("%s/FullSim_sf",dirName.Data())); const Double_t * pTbounds = h->GetXaxis()->GetXbins()->GetArray(); @@ -85,7 +106,7 @@ else if(pt<TEV) printf("|%2.0f - %2.0f\t\t|",pTbounds[i-1]/GEV,pTbounds[i]/GEV); else printf("|%2.0f-%2.0f\t\t|",pTbounds[i-1]/GEV,pTbounds[i]/GEV); for(int j=1;j<=nEtabins;j++){ eta=0.5*(Etabounds[j-1]+Etabounds[j]); -printf("%2.2f+/-%2.4f\t|",tool_SF.calculate(datatype,1,eta,pt).getScaleFactor(),tool_SF.calculate(datatype,1,eta,pt).getTotalUncertainty()); +printf("%2.2f+/-%2.4f\t|",tool_SF.calculate(datatype,run_number,eta,pt).getScaleFactor(),tool_SF.calculate(datatype,run_number,eta,pt).getTotalUncertainty()); } cout << endl; } cout << dash_line.Data() <<endl; diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/util/TestxAODPhotonAlg.cxx b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/util/TestxAODPhotonAlg.cxx index 9cbc1addcf6..06f8ddf3fb6 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/util/TestxAODPhotonAlg.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection/util/TestxAODPhotonAlg.cxx @@ -83,24 +83,36 @@ int main( int argc, char* argv[] ) { // Initialize photonFS tool AsgPhotonEfficiencyCorrectionTool photonSF_ID("AsgPhotonEfficiencyCorrectionTool_idSF"); AsgPhotonEfficiencyCorrectionTool photonSF_Iso("AsgPhotonEfficiencyCorrectionTool_isoSF"); - - // photonSF_ID.msg().setLevel( MSG::DEBUG ); + AsgPhotonEfficiencyCorrectionTool photonSF_Trig("AsgPhotonEfficiencyCorrectionTool_TrigSF"); + + // photonSF_ID.msg().setLevel( MSG::DEBUG ); + // photonSF_Iso.msg().setLevel( MSG::DEBUG ); + // photonSF_Trig.msg().setLevel( MSG::DEBUG ); //Set Properties for photonID_SF tool CHECK(photonSF_ID.setProperty("MapFilePath","PhotonEfficiencyCorrection/map0.txt")); - CHECK(photonSF_ID.setProperty("ForceDataType",1)); - + CHECK(photonSF_ID.setProperty("ForceDataType",1)); + //Set Properties for photonISO_SF tool CHECK(photonSF_Iso.setProperty("MapFilePath","PhotonEfficiencyCorrection/map0.txt")); - CHECK(photonSF_Iso.setProperty("IsoWP","Loose")); // Set isolation WP: Loose,Tight,TightCaloOnly - CHECK(photonSF_Iso.setProperty("Threshold_lowPT",25.0)); // this is a default value, no need to set if using it - CHECK(photonSF_Iso.setProperty("Threshold_highPT",100.0)); // this is a default value, no need to set if using it - CHECK(photonSF_Iso.setProperty("UseRadiativeZSF_mediumPT",false)); // default=false, set to true to use RadZSF up to Threshold_highPT + CHECK(photonSF_Iso.setProperty("IsoKey","Loose")); // Set isolation WP: Loose,Tight,TightCaloOnly CHECK(photonSF_Iso.setProperty("ForceDataType",1)); //set data type: 1 for FULLSIM, 3 for AF2 - - - + + //Set Properties for PhotonTrig_SF tool + CHECK(photonSF_Trig.setProperty("MapFilePath","PhotonEfficiencyCorrection/map0.txt")); + CHECK(photonSF_Trig.setProperty("IsoKey","Loose")); // Set isolation WP: Loose,Tight,TightCaloOnly + CHECK(photonSF_Trig.setProperty("TriggerKey","HLT_g20_tight_icalovloose_L1EM15VHI")); // Set photon trigger + CHECK(photonSF_Trig.setProperty("ForceDataType",1)); //set data type: 1 for FULLSIM, 3 for AF2 + + // If the Pileup reweighting tool is not initialized, one can use next properties: + CHECK(photonSF_ID.setProperty("UseRandomRunNumber",false)); + CHECK(photonSF_ID.setProperty("DefaultRandomRunNumber",325713)); // set first runnumber from 2017 + CHECK(photonSF_Iso.setProperty("UseRandomRunNumber",false)); + CHECK(photonSF_Iso.setProperty("DefaultRandomRunNumber",325713)); // set first runnumber from 2017 + CHECK(photonSF_Trig.setProperty("UseRandomRunNumber",false)); + CHECK(photonSF_Trig.setProperty("DefaultRandomRunNumber",325713)); // set first runnumber from 2017 + if(!photonSF_ID.initialize()){ std::cout <<"Failed to initialize the tool, check for errors"<<std::endl; return 0; @@ -109,6 +121,10 @@ int main( int argc, char* argv[] ) { std::cout <<"Failed to initialize the tool, check for errors"<<std::endl; return 0; } + if(!photonSF_Trig.initialize()){ + std::cout <<"Failed to initialize the tool, check for errors"<<std::endl; + return 0; + } // Test that recommended systematics properly bieng registered: std::vector<CP::SystematicSet> sysList; @@ -121,9 +137,11 @@ int main( int argc, char* argv[] ) { } // restructure all recommended systematic variations for the SF tool - // for +/- nsigma variation see https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/PhotonEfficiencyCorrection#Systematic_variations + // for +/- nsigma variation see + // https://twiki.cern.ch/twiki/bin/view/AtlasProtected/PhotonEfficiencyRun2#Systematic_variations + std::cout << "restructure all recommended systematic variations for the SF tool"<<std::endl; - std::vector<CP::SystematicSet> syst_PhotonID, syst_PhotonIso; + std::vector<CP::SystematicSet> syst_PhotonID, syst_PhotonIso, syst_PhotonTrig; for (auto SystematicsVariation : CP::make_systematics_vector(photonSF_ID.recommendedSystematics())) { syst_PhotonID.push_back(CP::SystematicSet()); @@ -134,7 +152,11 @@ int main( int argc, char* argv[] ) { syst_PhotonIso.push_back(CP::SystematicSet()); syst_PhotonIso.back().insert(SystematicsVariation); } - + for (auto SystematicsVariation : CP::make_systematics_vector(photonSF_Trig.recommendedSystematics())) + { + syst_PhotonTrig.push_back(CP::SystematicSet()); + syst_PhotonTrig.back().insert(SystematicsVariation); + } //Print all recomended systemtaics for (auto sSystematicSet: syst_PhotonID){ Info(APP_NAME,"PhotonEfficiencyCorrectionTool ID instance has next systematic variation %s ",sSystematicSet.name().c_str()); @@ -142,7 +164,10 @@ int main( int argc, char* argv[] ) { for (auto sSystematicSet: syst_PhotonIso){ Info(APP_NAME,"PhotonEfficiencyCorrectionTool Iso instance has next systematic variation %s ",sSystematicSet.name().c_str()); } - + for (auto sSystematicSet: syst_PhotonTrig){ + Info(APP_NAME,"PhotonEfficiencyCorrectionTool Iso instance has next systematic variation %s ",sSystematicSet.name().c_str()); + } + double efficiencyScaleFactor=0, efficiencyScaleFactorError=0; // Loop over the events: std::cout << "loop on " << entries << " entries"<<std::endl; @@ -185,6 +210,7 @@ int main( int argc, char* argv[] ) { // Get photon ID SF and the uncertainty CHECK(photonSF_ID.getEfficiencyScaleFactor(*ph,efficiencyScaleFactor)); CHECK(photonSF_ID.getEfficiencyScaleFactorError(*ph,efficiencyScaleFactorError)); + CHECK(photonSF_Trig.applySystematicVariation(syst_PhotonTrig.at(0))); Info( APP_NAME,"===>>> Result ID: ScaleFactor %f, TotalUncertainty %f ",efficiencyScaleFactor,efficiencyScaleFactorError); @@ -194,13 +220,19 @@ int main( int argc, char* argv[] ) { Info( APP_NAME,"===>>> Result Iso: ScaleFactor %f, TotalUncertainty %f ",efficiencyScaleFactor,efficiencyScaleFactorError); + // Get photon trigger SF and the uncertainty + CHECK(photonSF_Trig.getEfficiencyScaleFactor(*ph,efficiencyScaleFactor)); + CHECK(photonSF_Trig.getEfficiencyScaleFactorError(*ph,efficiencyScaleFactorError)); + + Info( APP_NAME,"===>>> Result Trigger: ScaleFactor %f, TotalUncertainty %f ",efficiencyScaleFactor,efficiencyScaleFactorError); // decorate photon (for different name use photonSF_ID.setProperty("ResultName","ID_"); or photonSF_Iso.setProperty("ResultName","Iso_");) CHECK(photonSF_ID.applyEfficiencyScaleFactor(*ph)); Info( "applyEfficiencyScaleFactor()","===>>> new decoration: (xAOD::Photon*)ph->auxdata<float>(\"SF\")=%f",ph->auxdata<float>("SF")); CHECK(photonSF_Iso.applyEfficiencyScaleFactor(*ph)); Info( "applyEfficiencyScaleFactor()","===>>> new decoration: (xAOD::Photon*)ph->auxdata<float>(\"SF\")=%f",ph->auxdata<float>("SF")); - + CHECK(photonSF_Trig.applyEfficiencyScaleFactor(*ph)); + Info( "applyEfficiencyScaleFactor()","===>>> new decoration: (xAOD::Photon*)ph->auxdata<float>(\"SF\")=%f",ph->auxdata<float>("SF")); // get SF for all recommended systematic variations (nominal is also included): for (const auto sSystematicSet: syst_PhotonID){ @@ -212,6 +244,11 @@ int main( int argc, char* argv[] ) { CHECK(photonSF_Iso.applySystematicVariation(sSystematicSet)); CHECK(photonSF_Iso.getEfficiencyScaleFactor(*ph,efficiencyScaleFactor)); Info( APP_NAME,"===>>> apply %s: ScaleFactor = %f",photonSF_Iso.appliedSystematics().name().c_str(),efficiencyScaleFactor); + } + for (const auto sSystematicSet: syst_PhotonTrig){ + CHECK(photonSF_Trig.applySystematicVariation(sSystematicSet)); + CHECK(photonSF_Trig.getEfficiencyScaleFactor(*ph,efficiencyScaleFactor)); + Info( APP_NAME,"===>>> apply %s: ScaleFactor = %f",photonSF_Trig.appliedSystematics().name().c_str(),efficiencyScaleFactor); } } // END LOOP ON PHOTONS @@ -219,6 +256,8 @@ int main( int argc, char* argv[] ) { } // END LOOP ON EVENTS CHECK(photonSF_ID.finalize()); CHECK(photonSF_Iso.finalize()); + CHECK(photonSF_Trig.finalize()); + // Return gracefully: return 1; -- GitLab