Skip to content

Commit

Permalink
More updates for Trigger-Level Analysis (TLA) (#1685)
Browse files Browse the repository at this point in the history
* test commit

* Add run-by-run cutflows for BasicEventSelection

* Fix conflicts with GN2 additions

add flavorTagTLA option for jets

Conflicts:
	Root/JetContainer.cxx

* add configurable stream name for TreeAlgo

---------

Co-authored-by: Stefano Franchellucci <stefano.franchellucci@cern.ch>
Co-authored-by: mamerl <maximilian.amerl@cern.ch>
  • Loading branch information
3 people committed Apr 29, 2024
1 parent a87d6f6 commit 1c6f87c
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 26 deletions.
27 changes: 27 additions & 0 deletions Root/BasicEventSelection.cxx
Expand Up @@ -159,6 +159,18 @@ EL::StatusCode BasicEventSelection :: histInitialize ()
m_cutflow_init = m_cutflowHist->GetXaxis()->FindBin("init");
m_cutflowHistW->GetXaxis()->FindBin("init");

// extra cutflows
// create histograms when m_doRunByRunCutflows is set to true
// later check if !isMC() for filling so that these only get
// filled when running on data
if (m_doRunByRunCutflows) {
m_runByrun_beforeCuts = new TH1D("runByrun_cutflow_beforeCuts", "Run-by-Run cutflow before cuts", 1, 1, 2);
m_runByrun_beforeCuts->SetCanExtend(TH1::kAllAxes);

m_runByrun_afterCuts = new TH1D("runByrun_cutflow_afterCuts", "Run-by-Run cutflow after cuts", 1, 1, 2);
m_runByrun_afterCuts->SetCanExtend(TH1::kAllAxes);
}

ANA_MSG_INFO( "Finished creating histograms");

return EL::StatusCode::SUCCESS;
Expand Down Expand Up @@ -743,6 +755,14 @@ EL::StatusCode BasicEventSelection :: execute ()
mcEvtWeight = mcEvtWeightAcc(*eventInfo);
}

//------------------------------------------------------------------------------------------
// Fill cutflows for run-by-run checks on data before cuts
//------------------------------------------------------------------------------------------
uint32_t runNumberForCutflow = (uint32_t) eventInfo->runNumber();
if (m_doRunByRunCutflows && !isMC()) {
m_runByrun_beforeCuts->Fill(TString(std::to_string(runNumberForCutflow)), 1.);
}

//------------------------------------------------------------------------------------------
// Declare an 'eventInfo' decorator with the Sherpa 2.2 reweight to multijet truth
// https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/CentralMC15ProductionList#Sherpa_v2_2_0_V_jets_NJet_reweig
Expand Down Expand Up @@ -1127,6 +1147,13 @@ EL::StatusCode BasicEventSelection :: execute ()

}//if data

//------------------------------------------------------------------------------------------
// Fill cutflows for run-by-run checks on data after cuts
//------------------------------------------------------------------------------------------
if (m_doRunByRunCutflows && !isMC()) {
m_runByrun_afterCuts->Fill(TString(std::to_string(runNumberForCutflow)), 1.);
}

return EL::StatusCode::SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions Root/HelperClasses.cxx
Expand Up @@ -333,6 +333,7 @@ namespace HelperClasses{
m_constituentAll = has_exact("constituentAll");
m_flavorTag = has_exact("flavorTag");
m_flavorTagHLT = has_exact("flavorTagHLT");
m_flavorTagTLA = has_exact("flavorTagTLA");
m_btag_jettrk = has_exact("btag_jettrk");
m_jetFitterDetails = has_exact("jetFitterDetails");
m_svDetails = has_exact("svDetails");
Expand Down
126 changes: 104 additions & 22 deletions Root/JetContainer.cxx
Expand Up @@ -254,6 +254,11 @@ JetContainer::JetContainer(const std::string& name, const std::string& detailStr
}

// flavorTag
if( m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT || m_infoSwitch.m_flavorTagTLA ) {
m_HadronConeExclTruthLabelID =new std::vector<int>();
m_HadronConeExclExtendedTruthLabelID=new std::vector<int>();
}

if( m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT ) {

m_DL1r =new std::vector<float>();
Expand All @@ -280,8 +285,6 @@ JetContainer::JetContainer(const std::string& name, const std::string& detailStr
m_GN2v00NewAliasWP_pu =new std::vector<float>();
m_GN2v00NewAliasWP_pc =new std::vector<float>();
m_GN2v00NewAliasWP_pb =new std::vector<float>();
m_HadronConeExclTruthLabelID =new std::vector<int>();
m_HadronConeExclExtendedTruthLabelID=new std::vector<int>();

// Jet Fitter
if( m_infoSwitch.m_jetFitterDetails){
Expand Down Expand Up @@ -392,6 +395,13 @@ JetContainer::JetContainer(const std::string& name, const std::string& detailStr
m_vtx_online_bkg_z0 = new std::vector<float>();
}

if( m_infoSwitch.m_flavorTagTLA ) {
m_fastDIPS =new std::vector<float>();
m_fastDIPS_pu =new std::vector<float>();
m_fastDIPS_pc =new std::vector<float>();
m_fastDIPS_pb =new std::vector<float>();
}

if( !m_infoSwitch.m_jetBTag.empty() ) {
std::stringstream ss_wpName;
for(const auto& btaginfo : m_infoSwitch.m_jetBTag)
Expand Down Expand Up @@ -723,7 +733,12 @@ JetContainer::~JetContainer()


// flavorTag
if( m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT ) {
if( m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT || m_infoSwitch.m_flavorTagTLA ) {
delete m_HadronConeExclTruthLabelID;
delete m_HadronConeExclExtendedTruthLabelID;
}

if( m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT ) {
// flavorTag

delete m_DL1r;
Expand Down Expand Up @@ -751,9 +766,6 @@ JetContainer::~JetContainer()
delete m_GN2v00NewAliasWP_pc;
delete m_GN2v00NewAliasWP_pb;

delete m_HadronConeExclTruthLabelID;
delete m_HadronConeExclExtendedTruthLabelID;

// Jet Fitter
if( m_infoSwitch.m_jetFitterDetails){
delete m_JetFitter_nVTX ;
Expand Down Expand Up @@ -861,6 +873,13 @@ JetContainer::~JetContainer()
delete m_vtx_online_bkg_z0 ;
}

if( m_infoSwitch.m_flavorTagTLA ) {
delete m_fastDIPS;
delete m_fastDIPS_pu;
delete m_fastDIPS_pc;
delete m_fastDIPS_pb;
}

for(auto btag : m_btags)
delete btag;

Expand Down Expand Up @@ -1038,6 +1057,12 @@ void JetContainer::setTree(TTree *tree)
connectBranch<double>(tree,"JetVertexCharge_discriminant", &m_JetVertexCharge_discriminant);
}

if(m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT || m_infoSwitch.m_flavorTagTLA)
{
connectBranch<int> (tree,"HadronConeExclTruthLabelID" ,&m_HadronConeExclTruthLabelID);
connectBranch<int> (tree,"HadronConeExclExtendedTruthLabelID",&m_HadronConeExclExtendedTruthLabelID);
}

if(m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT)
{
connectBranch<float>(tree,"DL1r" ,&m_DL1r );
Expand All @@ -1064,8 +1089,6 @@ void JetContainer::setTree(TTree *tree)
connectBranch<float>(tree,"GN2v00NewAliasWP_pu" ,&m_GN2v00NewAliasWP_pu );
connectBranch<float>(tree,"GN2v00NewAliasWP_pc" ,&m_GN2v00NewAliasWP_pc );
connectBranch<float>(tree,"GN2v00NewAliasWP_pb" ,&m_GN2v00NewAliasWP_pb );
connectBranch<int> (tree,"HadronConeExclTruthLabelID" ,&m_HadronConeExclTruthLabelID);
connectBranch<int> (tree,"HadronConeExclExtendedTruthLabelID",&m_HadronConeExclExtendedTruthLabelID);
}

if(m_infoSwitch.m_flavorTagHLT)
Expand All @@ -1087,6 +1110,13 @@ void JetContainer::setTree(TTree *tree)
connectBranch<float>(tree,"vtx_online_bkg_y0", &m_vtx_online_bkg_y0);
connectBranch<float>(tree,"vtx_online_bkg_z0", &m_vtx_online_bkg_z0);
}
if(m_infoSwitch.m_flavorTagTLA)
{
connectBranch<float>(tree,"fastDIPS", &m_fastDIPS);
connectBranch<float>(tree,"fastDIPS_pu", &m_fastDIPS_pu);
connectBranch<float>(tree,"fastDIPS_pc", &m_fastDIPS_pc);
connectBranch<float>(tree,"fastDIPS_pb", &m_fastDIPS_pb);
}

if(m_infoSwitch.m_jetFitterDetails)
{
Expand Down Expand Up @@ -1305,6 +1335,12 @@ void JetContainer::updateParticle(uint idx, Jet& jet)
jet.JVC = m_JetVertexCharge_discriminant->at(idx);
}

if(m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT || m_infoSwitch.m_flavorTagTLA)
{
if(m_HadronConeExclTruthLabelID) jet.HadronConeExclTruthLabelID =m_HadronConeExclTruthLabelID ->at(idx);
if(m_HadronConeExclExtendedTruthLabelID) jet.HadronConeExclExtendedTruthLabelID=m_HadronConeExclExtendedTruthLabelID->at(idx);
}

if(m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT)
{
if(m_debug) std::cout << "updating flavorTag " << std::endl;
Expand Down Expand Up @@ -1334,8 +1370,6 @@ void JetContainer::updateParticle(uint idx, Jet& jet)
if(m_GN2v00NewAliasWP_pb) jet.GN2v00NewAliasWP_pb =m_GN2v00NewAliasWP_pb ->at(idx);

//std::cout << m_HadronConeExclTruthLabelID->size() << std::endl;
if(m_HadronConeExclTruthLabelID) jet.HadronConeExclTruthLabelID =m_HadronConeExclTruthLabelID ->at(idx);
if(m_HadronConeExclExtendedTruthLabelID) jet.HadronConeExclExtendedTruthLabelID=m_HadronConeExclExtendedTruthLabelID->at(idx);
if(m_debug) std::cout << "leave flavorTag " << std::endl;
}

Expand Down Expand Up @@ -1374,6 +1408,16 @@ void JetContainer::updateParticle(uint idx, Jet& jet)
jet.JetFitter_N2Tpar =m_JetFitter_N2Tpar ->at(idx);

}

if(m_infoSwitch.m_flavorTagTLA)
{
if(m_debug) std::cout << "updating flavorTagTLA " << std::endl;
if(m_fastDIPS) jet.fastDIPS =m_fastDIPS ->at(idx);
if(m_fastDIPS_pu) jet.fastDIPS_pu =m_fastDIPS_pu ->at(idx);
if(m_fastDIPS_pc) jet.fastDIPS_pc =m_fastDIPS_pc ->at(idx);
if(m_fastDIPS_pb) jet.fastDIPS_pb =m_fastDIPS_pb ->at(idx);
if(m_debug) std::cout << "leave flavorTagTLA " << std::endl;
}

if(m_infoSwitch.m_svDetails){

Expand Down Expand Up @@ -1842,6 +1886,11 @@ void JetContainer::setBranches(TTree *tree)
setBranch<std::vector<float> >(tree,"constituent_e", m_constituent_e );
}

if( m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT || m_infoSwitch.m_flavorTagTLA ) {
setBranch<int>(tree,"HadronConeExclTruthLabelID", m_HadronConeExclTruthLabelID);
setBranch<int>(tree,"HadronConeExclExtendedTruthLabelID", m_HadronConeExclExtendedTruthLabelID);
}

if( m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT ) {

setBranch<float>(tree,"DL1r", m_DL1r);
Expand All @@ -1868,8 +1917,6 @@ void JetContainer::setBranches(TTree *tree)
setBranch<float>(tree,"GN2v00NewAliasWP_pu", m_GN2v00NewAliasWP_pu);
setBranch<float>(tree,"GN2v00NewAliasWP_pc", m_GN2v00NewAliasWP_pc);
setBranch<float>(tree,"GN2v00NewAliasWP_pb", m_GN2v00NewAliasWP_pb);
setBranch<int >(tree,"HadronConeExclTruthLabelID", m_HadronConeExclTruthLabelID);
setBranch<int >(tree,"HadronConeExclExtendedTruthLabelID", m_HadronConeExclExtendedTruthLabelID);

if( m_infoSwitch.m_jetFitterDetails){

Expand Down Expand Up @@ -1980,6 +2027,13 @@ void JetContainer::setBranches(TTree *tree)

}

if( m_infoSwitch.m_flavorTagTLA ) {
setBranch<float>(tree,"fastDIPS", m_fastDIPS);
setBranch<float>(tree,"fastDIPS_pu", m_fastDIPS_pu);
setBranch<float>(tree,"fastDIPS_pc", m_fastDIPS_pc);
setBranch<float>(tree,"fastDIPS_pb", m_fastDIPS_pb);
}

if( !m_infoSwitch.m_jetBTag.empty() || !m_infoSwitch.m_jetBTagCts.empty() ) {
for(auto btag : m_btags)
btag->setBranch(tree, m_name);
Expand Down Expand Up @@ -2289,6 +2343,11 @@ void JetContainer::clear()
m_constituent_e ->clear();
}

if ( m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT || m_infoSwitch.m_flavorTagTLA ) {
m_HadronConeExclTruthLabelID ->clear();
m_HadronConeExclExtendedTruthLabelID->clear();
}

// flavor tag
if ( m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT ) {

Expand Down Expand Up @@ -2316,9 +2375,6 @@ void JetContainer::clear()
m_GN2v00NewAliasWP_pu ->clear();
m_GN2v00NewAliasWP_pc ->clear();
m_GN2v00NewAliasWP_pb ->clear();
m_HadronConeExclTruthLabelID ->clear();
m_HadronConeExclExtendedTruthLabelID->clear();


if( m_infoSwitch.m_jetFitterDetails){
m_JetFitter_nVTX ->clear();
Expand Down Expand Up @@ -2422,6 +2478,12 @@ void JetContainer::clear()

}

if ( m_infoSwitch.m_flavorTagTLA ) {
m_fastDIPS ->clear();
m_fastDIPS_pu ->clear();
m_fastDIPS_pc ->clear();
m_fastDIPS_pb ->clear();
}

if( !m_infoSwitch.m_jetBTag.empty() || !m_infoSwitch.m_jetBTagCts.empty()) { // just clear them all....
for(auto btag : m_btags)
Expand Down Expand Up @@ -3175,6 +3237,16 @@ void JetContainer::FillJet( const xAOD::IParticle* particle, const xAOD::Vertex*
m_constituent_e-> push_back( e );
}


if ( m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT || m_infoSwitch.m_flavorTagTLA ) {
// flavor groups truth definition
static SG::AuxElement::ConstAccessor<int> hadConeExclTruthLabel("HadronConeExclTruthLabelID");
safeFill<int, int, xAOD::Jet>(jet, hadConeExclTruthLabel, m_HadronConeExclTruthLabelID, -999);

static SG::AuxElement::ConstAccessor<int> hadConeExclExtendedTruthLabel("HadronConeExclExtendedTruthLabelID");
safeFill<int, int, xAOD::Jet>(jet, hadConeExclExtendedTruthLabel, m_HadronConeExclExtendedTruthLabelID, -999);
}

if ( m_infoSwitch.m_flavorTag || m_infoSwitch.m_flavorTagHLT ) {
const xAOD::BTagging * myBTag(0);

Expand Down Expand Up @@ -3256,13 +3328,6 @@ void JetContainer::FillJet( const xAOD::IParticle* particle, const xAOD::Vertex*
m_GN2v00NewAliasWP_pb->push_back(pb);
m_GN2v00NewAliasWP->push_back( score );

// flavor groups truth definition
static SG::AuxElement::ConstAccessor<int> hadConeExclTruthLabel("HadronConeExclTruthLabelID");
safeFill<int, int, xAOD::Jet>(jet, hadConeExclTruthLabel, m_HadronConeExclTruthLabelID, -999);

static SG::AuxElement::ConstAccessor<int> hadConeExclExtendedTruthLabel("HadronConeExclExtendedTruthLabelID");
safeFill<int, int, xAOD::Jet>(jet, hadConeExclExtendedTruthLabel, m_HadronConeExclExtendedTruthLabelID, -999);

if(m_infoSwitch.m_jetFitterDetails ) {

static SG::AuxElement::ConstAccessor< int > jf_nVTXAcc ("JetFitter_nVTX");
Expand Down Expand Up @@ -3562,6 +3627,23 @@ void JetContainer::FillJet( const xAOD::IParticle* particle, const xAOD::Vertex*
if(m_debug) std::cout << "Done m_flavorTagHLT " << std::endl;
}

if (m_infoSwitch.m_flavorTagTLA){
if(m_debug) std::cout << "Filling m_flavorTagHLT " << std::endl;

float pu=0, pb=0, pc=0, score=0;
pu = jet->auxdata<float>( "fastDIPS20211215_pu" );
pc = jet->auxdata<float>( "fastDIPS20211215_pc" );
pb = jet->auxdata<float>( "fastDIPS20211215_pb" );
//FixMe: Retrieve the correct f_c value from the CDI file would be the best approach
score=log( pb / (0.018*pc+0.982*pu) );

m_fastDIPS_pu->push_back( pu );
m_fastDIPS_pc->push_back( pc );
m_fastDIPS_pb->push_back( pb );
m_fastDIPS->push_back( score );

if(m_debug) std::cout << "Done m_flavorTagTLA " << std::endl;
}

if( !m_infoSwitch.m_jetBTag.empty() || !m_infoSwitch.m_jetBTagCts.empty() ) {
for(auto btag : m_btags)
Expand Down
8 changes: 4 additions & 4 deletions Root/TreeAlgo.cxx
Expand Up @@ -28,8 +28,8 @@ EL::StatusCode TreeAlgo :: setupJob (EL::Job& job)
job.useXAOD();
xAOD::Init("TreeAlgo").ignore();

EL::OutputStream outForTree("tree");
job.outputAdd (outForTree);
EL::OutputStream outForTree(m_treeStreamName);
if(!job.outputHas(m_treeStreamName)) job.outputAdd (outForTree);

return EL::StatusCode::SUCCESS;
}
Expand All @@ -41,7 +41,7 @@ EL::StatusCode TreeAlgo :: initialize ()
m_store = wk()->xaodStore();

// get the file we created already
TFile* treeFile = wk()->getOutputFile ("tree");
TFile* treeFile = wk()->getOutputFile (m_treeStreamName);
treeFile->mkdir(m_name.c_str());
treeFile->cd(m_name.c_str());

Expand Down Expand Up @@ -293,7 +293,7 @@ EL::StatusCode TreeAlgo :: execute ()
}
}

TFile* treeFile = wk()->getOutputFile ("tree");
TFile* treeFile = wk()->getOutputFile (m_treeStreamName);

// let's make the tdirectory and ttrees
for(const auto& systName: event_systNames){
Expand Down
7 changes: 7 additions & 0 deletions xAODAnaHelpers/BasicEventSelection.h
Expand Up @@ -218,6 +218,9 @@ class BasicEventSelection : public xAH::Algorithm
/** Check for duplicated events in MC */
bool m_checkDuplicatesMC = false;

// determines whether to add additional debugging histograms on data
bool m_doRunByRunCutflows = false;

private:

std::set<std::pair<uint32_t,uint32_t> > m_RunNr_VS_EvtNr; //!
Expand Down Expand Up @@ -264,6 +267,10 @@ class BasicEventSelection : public xAH::Algorithm
int m_cutflow_npv; //!
int m_cutflow_trigger; //!

// extra run-by-run event count cutflow
TH1D* m_runByrun_beforeCuts = nullptr; //!
TH1D* m_runByrun_afterCuts = nullptr; //!

// object cutflow
TH1D* m_el_cutflowHist_1 = nullptr; //!
TH1D* m_el_cutflowHist_2 = nullptr; //!
Expand Down
2 changes: 2 additions & 0 deletions xAODAnaHelpers/HelperClasses.h
Expand Up @@ -471,6 +471,7 @@ namespace HelperClasses {
m_constituentAll constituentAll exact
m_flavorTag flavorTag exact
m_flavorTagHLT flavorTagHLT exact
m_flavorTagTLA flavorTagTLA exact
m_sfFTagFix sfFTagFix partial
m_sfFTagFlt sfFTagFlt partial
m_sfFTagHyb sfFTagHyb partial
Expand Down Expand Up @@ -543,6 +544,7 @@ namespace HelperClasses {
bool m_constituentAll;
bool m_flavorTag;
bool m_flavorTagHLT;
bool m_flavorTagTLA;
bool m_btag_jettrk;
bool m_jetFitterDetails;
bool m_svDetails;
Expand Down

0 comments on commit 1c6f87c

Please sign in to comment.