Skip to content
Snippets Groups Projects
Commit 1dffd11d authored by Ruth Pottgen's avatar Ruth Pottgen
Browse files

Merge branch '21.0-ZCounting' into '21.0'

ZCounting Truth Matching functions

See merge request atlas/athena!27415
parents efafbcd5 f1c7b9ab
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,7 @@ atlas_depends_on_subdirs(
Trigger/TrigEvent/TrigParticle
Trigger/TrigT1/TrigT1Result
PhysicsAnalysis/MuonID/MuonSelectorTools
MCTruthClassifier
)
# External dependencies:
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
// ********************************************************************
......@@ -23,10 +23,14 @@
#include "TrigDecisionTool/TrigDecisionTool.h"
#include "TrigEgammaMatchingTool/ITrigEgammaMatchingTool.h"
#include "MCTruthClassifier/IMCTruthClassifier.h"
#include "TMath.h"
#include <string>
#include <iostream>
#include "xAODTruth/TruthEvent.h"
#include "xAODTruth/TruthParticle.h"
class TProfile;
class TH1F_LW;
......@@ -70,6 +74,7 @@ private:
void setDQTGlobalWZFinderBranches();
void doMuonTriggerTP(const xAOD::Muon* , const xAOD::Muon*);
void doMuonTruthEff(std::vector<const xAOD::Muon*>&);
void doMuonLooseTP(std::vector<const xAOD::Muon*>& goodmuonsZ, const xAOD::Vertex* pVtx);
void doMuonInDetTP(std::vector<const xAOD::Muon*>& goodmuonsZ, const xAOD::Vertex* pVtx);
......@@ -84,6 +89,10 @@ private:
bool kinematicCuts(const xAOD::Electron*);
bool checkTruthElectron(const xAOD::Electron* electron);
bool checkTruthTrack(const xAOD::TrackParticle* trk);
bool checkTruthMuon(const xAOD::Muon* muon);
bool m_isSimulation;
bool m_writeTTrees;
......@@ -178,9 +187,6 @@ private:
int m_ZBosonCounterSBG_El[2];
int m_ZBosonCounterSBG_Mu[2];
//uint32_t lumiBlock;
//uint32_t eventNumber;
int m_this_lb; //remove _t
int m_eventNumber; //remove _t
float m_evtWeight;
......@@ -324,6 +330,8 @@ private:
int m_electron_trig_tptree_runnumber;
unsigned long long m_electron_trig_tptree_eventnumber;
ToolHandle<IMCTruthClassifier> m_truthClassifier;
};
#endif
......@@ -28,6 +28,12 @@
#include "xAODMissingET/MissingETContainer.h"
#include "xAODTracking/TrackParticle.h"
#include "xAODTruth/TruthParticleContainer.h"
#include "xAODTruth/TruthParticle.h"
#include "xAODTruth/TruthVertex.h"
#include "xAODEgamma/EgammaxAODHelpers.h"
#include "xAODEgamma/ElectronxAODHelpers.h"
#include "xAODEgamma/PhotonxAODHelpers.h"
#include "xAODEgamma/EgammaTruthxAODHelpers.h"
#include "xAODEventInfo/EventInfo.h"
#include "xAODJet/Jet.h"
......@@ -51,6 +57,7 @@ using xAOD::Jet;
using xAOD::JetContainer;
using Gaudi::Units::GeV;
using Gaudi::Units::mm;
using namespace MCTruthPartClassifier;
//----------------------------------------------------------------------------------
DQTGlobalWZFinderTool::DQTGlobalWZFinderTool(const std::string & type,
......@@ -63,7 +70,6 @@ DQTGlobalWZFinderTool::DQTGlobalWZFinderTool(const std::string & type,
m_ele_Eta(nullptr),
m_electronContainerName("Electrons"),
m_egDetailContainerName("egDetailAOD"),
//m_VxPrimContainerName("VxPrimaryCandidate"), //Kshort
m_VxPrimContainerName("PrimaryVertices"),
m_VxContainerName("SecVertices"), //Kshort
m_METName("MET_Reference_AntiKt4EMTopo"),
......@@ -83,7 +89,9 @@ DQTGlobalWZFinderTool::DQTGlobalWZFinderTool(const std::string & type,
m_Jpsi_mm_trigger{"CATEGORY_primary_bphys"},
m_Z_mm_trigger{"CATEGORY_monitoring_muonIso", "CATEGORY_monitoring_muonNonIso"},
m_Z_ee_trigger{"CATEGORY_primary_single_ele_iso", "CATEGORY_primary_single_ele"},
m_elTrigMatchTool("Trig::TrigEgammaMatchingTool/TrigEgammaMatchingTool", this)
m_elTrigMatchTool("Trig::TrigEgammaMatchingTool/TrigEgammaMatchingTool", this),
m_truthClassifier("MCTruthClassifier/IMCTruthClassifier", this)
//----------------------------------------------------------------------------------
{
......@@ -151,15 +159,6 @@ StatusCode DQTGlobalWZFinderTool::bookHistogramsRecurrent()
ATH_MSG_DEBUG("Trigger information for WZFinder");
ATH_MSG_DEBUG("For Z->mm:");
/* for (const auto& chain: m_Z_mm_trigger) {
std::cout << "Muon triggers: " << chain << std::endl;
}
for (const auto& chain: m_Z_ee_trigger) {
std::cout << "Electron triggers: " << chain << std::endl;
}
*/
bool failure(false);
std::string fullPathDQTGlobalWZFinder=m_path;
......@@ -197,7 +196,6 @@ StatusCode DQTGlobalWZFinderTool::bookHistogramsRecurrent()
//----------------------------------------------------------------------------------
StatusCode DQTGlobalWZFinderTool::bookHistograms( )
//StatusCode DQTGlobalWZFinderTool::bookHistograms( bool isNewEventsBlock, bool isNewLumiBlock, bool isNewRun )
//----------------------------------------------------------------------------------
{
bool failure(false);
......@@ -222,15 +220,11 @@ StatusCode DQTGlobalWZFinderTool::bookHistograms( )
m_ZBosonCounterSBG_Mu[index]=0;
}
//if (newRun) {
ATH_MSG_DEBUG("in bookHistograms() and m_doRunCosmics = " << m_doRunCosmics << " and m_doRunBeam = " << m_doRunBeam);
ATH_MSG_DEBUG("Using base path " << m_path);
failure = bookDQTGlobalWZFinderTool();
//}
//else if (newEventsBlock || newLumiBlock) {
// return StatusCode::SUCCESS;
//}
failure = bookDQTGlobalWZFinderTool();
if (failure) {return StatusCode::FAILURE;}
else {return StatusCode::SUCCESS;}
}
......@@ -242,7 +236,6 @@ bool DQTGlobalWZFinderTool::bookDQTGlobalWZFinderTool()
//----------------------------------------------------------------------------------
{
bool failure(false);
// if (isNewEventsBlock || isNewLumiBlock || isNewRun) {
MsgStream log(msgSvc(), name());
std::string fullPathDQTGlobalWZFinder=m_path;
......@@ -333,21 +326,27 @@ bool DQTGlobalWZFinderTool::bookDQTGlobalWZFinderTool()
}
if (m_isSimulation) {
failure = failure | registerHist(fullPathDQTGlobalWZFinder, m_mcmatch = TH1F_LW::create("m_mcatch", "Muon matching to truth in acceptance", 2, -0.5, 1.5), lumiBlock).isFailure();
if (m_writeTTrees){
// Currently we hide the ttrees in the m_isSimulation check
// To be done, change to a job option so runs on data
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_muontree = new TTree("muontree","muontree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_muon_reco_tptree = new TTree("muon_reco_tptree","muon_reco_tptree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_muon_indet_tptree = new TTree("muon_indet_tptree","muon_indet_tptree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_muon_trig_tptree = new TTree("muon_trig_tptree","muon_trig_tptree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_electrontree = new TTree("electrontree","electrontree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_electron_reco_tptree = new TTree("electron_reco_tptree","electron_reco_tptree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_electron_container_tptree = new TTree("electron_container_tptree","electron_container_tptree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_electron_trig_tptree = new TTree("electron_trig_tptree","electron_trig_tptree")).isFailure();
setDQTGlobalWZFinderBranches();
}
if (m_writeTTrees){
// Currently we hide the ttrees in the m_isSimulation check
// To be done, change to a job option so runs on data
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_muontree = new TTree("muontree","muontree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_muon_reco_tptree = new TTree("muon_reco_tptree","muon_reco_tptree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_muon_indet_tptree = new TTree("muon_indet_tptree","muon_indet_tptree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_muon_trig_tptree = new TTree("muon_trig_tptree","muon_trig_tptree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_electrontree = new TTree("electrontree","electrontree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_electron_reco_tptree = new TTree("electron_reco_tptree","electron_reco_tptree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_electron_container_tptree = new TTree("electron_container_tptree","electron_container_tptree")).isFailure();
failure = failure | registerTree(fullPathDQTGlobalWZFinder, m_electron_trig_tptree = new TTree("electron_trig_tptree","electron_trig_tptree")).isFailure();
setDQTGlobalWZFinderBranches();
}
//Resonance particle rate monitoring
m_minLumiBlock = 0.0;
m_maxLumiBlock = 1200.0;
......@@ -397,9 +396,8 @@ StatusCode DQTGlobalWZFinderTool::fillHistograms()
//Get MET
Double_t phiMet = 0, metMet = 0;
// const MissingET *missET;
const xAOD::MissingETContainer *missETcont(0);
const xAOD::MissingET* missET;
const xAOD::MissingET* missET(0);
if ( evtStore()->contains<xAOD::MissingETContainer>(m_METName) ) {
evtStore()->retrieve(missETcont,m_METName);
missET = (*missETcont)["FinalClus"];
......@@ -491,7 +489,6 @@ StatusCode DQTGlobalWZFinderTool::fillHistograms()
//MET cleaning
bool isBad = false;
const JetContainer* jetTES;
//std::string m_jetCollectionName = "AntiKt4TopoEMJets";
bool printedErrorJetCollection = false;
if (evtStore()->contains<JetContainer>(m_jetCollectionName)) {
sc=evtStore()->retrieve(jetTES,m_jetCollectionName);
......@@ -600,7 +597,15 @@ StatusCode DQTGlobalWZFinderTool::fillHistograms()
goodmuonJPsicharge.push_back(charge);
}
}
if (m_isSimulation) {
doMuonTruthEff(goodmuonsZ);
}
// Check Sum of Candidate Leptons, Return if None
ATH_MSG_DEBUG("Candidate e+mu = " << El_N+MuZ_N+MuJPsi_N);
if ((El_N + MuZ_N + MuJPsi_N) < 1) return sc;
......@@ -726,7 +731,7 @@ StatusCode DQTGlobalWZFinderTool::fillHistograms()
m_electrontree_eventnumber = thisEventInfo->eventNumber();
m_electrontree_mass = mass;
// Replace with truth matching code
m_electrontree_isTruth = true;
m_electrontree_isTruth = checkTruthElectron(leadingEle) & checkTruthElectron(subleadingEle);
m_electrontree->Fill();
}
......@@ -778,7 +783,7 @@ StatusCode DQTGlobalWZFinderTool::fillHistograms()
m_muontree_lb = m_this_lb;
m_muontree_runnumber = thisEventInfo->runNumber();
m_muontree_eventnumber = thisEventInfo->eventNumber();
m_muontree_isTruth = true;
m_muontree_isTruth = checkTruthMuon(leadingMuZ) & checkTruthMuon(subleadingMuZ);
m_muontree_mass = mass;
m_muontree->Fill();
}
......@@ -1061,6 +1066,7 @@ void DQTGlobalWZFinderTool::doEleTriggerTP(const xAOD::Electron* el1, const xAOD
m_electron_trig_tptree_pT = probeel->pt();
m_electron_trig_tptree_phi = probeel->phi();
m_electron_trig_tptree_eta = probeel->caloCluster()->etaBE(2);
m_electron_trig_tptree_eta = checkTruthElectron(probeel);
m_electron_trig_tptree_mass = mass;
m_electron_trig_tptree_runnumber = thisEventInfo->runNumber();
m_electron_trig_tptree_eventnumber = thisEventInfo->eventNumber();
......@@ -1094,6 +1100,7 @@ void DQTGlobalWZFinderTool::doEleTriggerTP(const xAOD::Electron* el1, const xAOD
if (m_writeTTrees){
m_electron_trig_tptree->Fill();
}
}
}
}
......@@ -1129,7 +1136,7 @@ DQTGlobalWZFinderTool::doEleTP(const xAOD::Electron* leadingAllEle,
for (const auto chain: m_Z_ee_trigger) {
if (m_elTrigMatchTool->match(leadingAllEle, chain)){
leading_trig = true;
break;
break;
}
}
......@@ -1137,7 +1144,7 @@ DQTGlobalWZFinderTool::doEleTP(const xAOD::Electron* leadingAllEle,
for (const auto chain: m_Z_ee_trigger) {
if (m_elTrigMatchTool->match(subleadingAllEle, chain)){
subleading_trig = true;
break;
break;
}
}
......@@ -1147,6 +1154,7 @@ DQTGlobalWZFinderTool::doEleTP(const xAOD::Electron* leadingAllEle,
m_electron_reco_tptree_pT = subleadingAllEle->pt();
m_electron_reco_tptree_phi = subleadingAllEle->phi();
m_electron_reco_tptree_eta = subleadingAllEle->caloCluster()->etaBE(2);
m_electron_reco_tptree_isTruth = checkTruthElectron(subleadingAllEle);
m_electron_reco_tptree_mass = mass;
m_electron_reco_tptree_runnumber = thisEventInfo->runNumber();
m_electron_reco_tptree_eventnumber = thisEventInfo->eventNumber();
......@@ -1154,6 +1162,7 @@ DQTGlobalWZFinderTool::doEleTP(const xAOD::Electron* leadingAllEle,
m_electron_reco_tptree_lb = m_this_lb;
if(Zeecharge==0){
(subleading_good) ? m_electron_reco_tptree_mtype = 0 : m_electron_reco_tptree_mtype = 2;
if(subleading_antigood){
m_electron_reco_tptree_mtype = 4;
......@@ -1186,6 +1195,7 @@ DQTGlobalWZFinderTool::doEleTP(const xAOD::Electron* leadingAllEle,
m_electron_reco_tptree_pT = leadingAllEle->pt();
m_electron_reco_tptree_phi = leadingAllEle->phi();
m_electron_reco_tptree_eta = leadingAllEle->caloCluster()->etaBE(2);
m_electron_reco_tptree_isTruth = checkTruthElectron(leadingAllEle);
m_electron_reco_tptree_mass = mass;
m_electron_reco_tptree_runnumber = thisEventInfo->runNumber();
m_electron_reco_tptree_eventnumber = thisEventInfo->eventNumber();
......@@ -1220,6 +1230,7 @@ DQTGlobalWZFinderTool::doEleTP(const xAOD::Electron* leadingAllEle,
m_electron_reco_tptree->Fill();
}
}
}// subleading pointer exixts
}// leading pointer exists
}// end doEleTP
......@@ -1431,7 +1442,7 @@ void DQTGlobalWZFinderTool::doMuonTriggerTP(const xAOD::Muon* mu1, const xAOD::M
// only consider trigger-matched tags to avoid bias on probes
bool matched = false;
for (const auto chain: m_Z_mm_trigger) {
if (m_muTrigMatchTool->match(tagmu, chain) || ! m_doTrigger) {
if (m_muTrigMatchTool->match(tagmu, chain) || ! m_doTrigger) {
matched=true;
break;
}
......@@ -1451,6 +1462,7 @@ void DQTGlobalWZFinderTool::doMuonTriggerTP(const xAOD::Muon* mu1, const xAOD::M
m_muon_trig_tptree_pT = probemu->pt();
m_muon_trig_tptree_eta = probemu->eta();
m_muon_trig_tptree_phi = probemu->phi();
m_muon_trig_tptree_isTruth = checkTruthMuon(probemu);
m_muon_trig_tptree_mass = mass;
m_muon_trig_tptree_runnumber = thisEventInfo->runNumber();
m_muon_trig_tptree_eventnumber = thisEventInfo->eventNumber();
......@@ -1505,6 +1517,29 @@ void DQTGlobalWZFinderTool::doMuonTriggerTP(const xAOD::Muon* mu1, const xAOD::M
}
void DQTGlobalWZFinderTool::doMuonTruthEff(std::vector<const xAOD::Muon*>& goodmuonsZ) {
const xAOD::TruthParticleContainer* vtruth(0);
evtStore()->retrieve(vtruth, "MuonTruthParticles");
if (! vtruth) {
ATH_MSG_WARNING("No muon truth particles");
return;
}
for (const auto& truthmu : *vtruth) {
if (truthmu->abseta() > m_muonMaxEta || truthmu->pt() < m_muonPtCut*GeV) {
continue;
}
TLorentzVector truthp4(truthmu->p4());
int match = 0;
for (const auto& foundmu : goodmuonsZ) {
if (foundmu->p4().DeltaR(truthp4) < 0.05) {
match = 1;
break;
}
}
m_mcmatch->Fill(match);
}
}
void DQTGlobalWZFinderTool::doMuonLooseTP(std::vector<const xAOD::Muon*>& goodmuonsTP, const xAOD::Vertex* pVtx) {
const xAOD::EventInfo* thisEventInfo;
......@@ -1538,6 +1573,7 @@ void DQTGlobalWZFinderTool::doMuonLooseTP(std::vector<const xAOD::Muon*>& goodmu
m_muon_reco_tptree_pT = trk->pt();
m_muon_reco_tptree_phi = trk->phi();
m_muon_reco_tptree_eta = trk->eta();
m_muon_reco_tptree_isTruth = checkTruthTrack(trk);
m_muon_reco_tptree_mass = mass;
m_muon_reco_tptree_runnumber = thisEventInfo->runNumber();
m_muon_reco_tptree_eventnumber = thisEventInfo->eventNumber();
......@@ -1627,14 +1663,13 @@ void DQTGlobalWZFinderTool::doMuonInDetTP(std::vector<const xAOD::Muon*>& goodmu
m_muon_indet_tptree_pT = trk->pt();
m_muon_indet_tptree_phi = trk->phi();
m_muon_indet_tptree_eta = trk->eta();
m_muon_indet_tptree_isTruth = checkTruthTrack(trk);
m_muon_indet_tptree_mass = mass;
m_muon_indet_tptree_runnumber = thisEventInfo->runNumber();
m_muon_indet_tptree_eventnumber = thisEventInfo->eventNumber();
m_muon_indet_tptree_weight = m_evtWeight;
m_muon_indet_tptree_lb = m_this_lb;
//for all ms tracks
for (const auto& mu2 : *idTracks) {
......@@ -1771,6 +1806,70 @@ void DQTGlobalWZFinderTool::setDQTGlobalWZFinderBranches(){
}
bool DQTGlobalWZFinderTool::checkTruthElectron(const xAOD::Electron* elec){
// Check if input electron originates from a ZBoson, following EGamma recipe
unsigned int iTypeOfPart;
unsigned int iPartOrig;
bool truthMatched = false;
const xAOD::TruthParticle* lastElTruth = xAOD::EgammaHelpers::getBkgElectronMother(elec);
if( lastElTruth ){
auto res = m_truthClassifier->particleTruthClassifier(lastElTruth);
iTypeOfPart = res.first;
iPartOrig = res.second;
// (type = IsoElectron and origin = ZBoson) or origin FSRPhoton
if((iTypeOfPart == 2 && iPartOrig == 13) || (iPartOrig == 40)){
truthMatched = true;
}
}
return truthMatched;
}
bool DQTGlobalWZFinderTool::checkTruthMuon(const xAOD::Muon* muon){
// Check if input muon originates from a ZBoson
bool truthMatched = false;
std::pair<unsigned int, unsigned int> res;
ParticleDef partDef;
res=m_truthClassifier->particleTruthClassifier(muon);
unsigned int iTypeOfPart = res.first;
unsigned int iPartOrig = res.second;
const auto* thePart = m_truthClassifier->getGenPart();
if(thePart){
// (type = IsoMuon and origin = ZBoson)
if(iTypeOfPart == 6 && iPartOrig == 13){
truthMatched = true;
}
}
return truthMatched;
}
bool DQTGlobalWZFinderTool::checkTruthTrack(const xAOD::TrackParticle* trk){
// Check if input track originates from a ZBoson
bool truthMatched = false;
std::pair<unsigned int, unsigned int> res;
ParticleDef partDef;
res=m_truthClassifier->particleTruthClassifier(trk);
unsigned int iTypeOfPart = res.first;
unsigned int iPartOrig = res.second;
const auto* thePart = m_truthClassifier->getGenPart();
if(thePart){
// (type = IsoMuon and origin ZBoson)
if(iTypeOfPart == 6 && iPartOrig == 13){
truthMatched = true;
}
}
return truthMatched;
}
//----------------------------------------------------------------------------------
StatusCode DQTGlobalWZFinderTool::checkHists(bool /* fromFinalize */)
//----------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment