.. _program_listing_file_Root_TruthContainer.cxx: Program Listing for File TruthContainer.cxx =========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``Root/TruthContainer.cxx``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #include "xAODAnaHelpers/TruthContainer.h" #include #include #include #include //#include "xAODTruth/TruthEventContainer.h" using namespace xAH; TruthContainer::TruthContainer(const std::string& name, const std::string& detailStr, float units) : ParticleContainer(name,detailStr,units,true) { m_pdgId = new std::vector(); if(!m_infoSwitch.m_pdgIdOnly){ m_status = new std::vector(); m_barcode = new std::vector(); } if(m_infoSwitch.m_type){ m_is_higgs = new std::vector(); m_is_bhad = new std::vector(); } if(m_infoSwitch.m_bVtx){ m_Bdecay_x = new std::vector(); m_Bdecay_y = new std::vector(); m_Bdecay_z = new std::vector(); } if(m_infoSwitch.m_parents){ m_nParents = new std::vector(); m_parent_pdgId = new std::vector< std::vector >(); m_parent_barcode = new std::vector< std::vector >(); m_parent_status = new std::vector< std::vector >(); } if(m_infoSwitch.m_children){ m_nChildren = new std::vector(); m_child_pdgId = new std::vector< std::vector >(); m_child_barcode = new std::vector< std::vector >(); m_child_status = new std::vector< std::vector >(); } if(m_infoSwitch.m_dressed){ m_pt_dressed = new std::vector(); m_eta_dressed = new std::vector(); m_phi_dressed = new std::vector(); m_e_dressed = new std::vector(); } if(m_infoSwitch.m_origin){ m_origin = new std::vector(); } if(m_infoSwitch.m_particleType){ m_particleType = new std::vector(); } } TruthContainer::~TruthContainer() { if(m_debug) std::cout << " Deleting TruthContainer " << std::endl; delete m_pdgId; if(!m_infoSwitch.m_pdgIdOnly){ delete m_status; delete m_barcode; } if(m_infoSwitch.m_type){ delete m_is_higgs; delete m_is_bhad ; } if(m_infoSwitch.m_bVtx){ delete m_Bdecay_x; delete m_Bdecay_y; delete m_Bdecay_z; } if(m_infoSwitch.m_parents){ delete m_nParents; delete m_parent_pdgId; delete m_parent_barcode; delete m_parent_status; } if(m_infoSwitch.m_children){ delete m_nChildren; delete m_child_pdgId; delete m_child_barcode; delete m_child_status; } if(m_infoSwitch.m_dressed){ delete m_pt_dressed; delete m_eta_dressed; delete m_phi_dressed; delete m_e_dressed; } if(m_infoSwitch.m_origin){ delete m_origin; } if(m_infoSwitch.m_particleType){ delete m_particleType; } } void TruthContainer::setTree(TTree *tree) { // // Connect branches ParticleContainer::setTree(tree); connectBranch(tree,"pdgId", &m_pdgId); if(!m_infoSwitch.m_pdgIdOnly){ connectBranch(tree,"status", &m_status); connectBranch(tree,"barcode", &m_barcode); } if(m_infoSwitch.m_type){ connectBranch(tree,"is_higgs", &m_is_higgs); connectBranch(tree,"is_bhad", &m_is_bhad); } if(m_infoSwitch.m_bVtx){ connectBranch(tree,"Bdecay_x", &m_Bdecay_x); connectBranch(tree,"Bdecay_y", &m_Bdecay_y); connectBranch(tree,"Bdecay_z", &m_Bdecay_z); } if(m_infoSwitch.m_parents){ connectBranch(tree,"nParents", &m_nParents); connectBranch >(tree,"parent_pdgId", &m_parent_pdgId); connectBranch >(tree,"parent_barcode", &m_parent_barcode); connectBranch >(tree,"parent_status", &m_parent_status); } if(m_infoSwitch.m_children){ connectBranch (tree,"nChildren", &m_nChildren); connectBranch >(tree,"child_pdgId", &m_child_pdgId); connectBranch >(tree,"child_barcode", &m_child_barcode); connectBranch >(tree,"child_status", &m_child_status); } if(m_infoSwitch.m_dressed){ connectBranch (tree,"pt_dressed", &m_pt_dressed); connectBranch (tree,"eta_dressed", &m_eta_dressed); connectBranch (tree,"phi_dressed", &m_phi_dressed); connectBranch (tree,"e_dressed", &m_e_dressed); } if(m_infoSwitch.m_origin){ connectBranch (tree,"origin", &m_origin); } if(m_infoSwitch.m_particleType){ connectBranch (tree,"type", &m_particleType); } } void TruthContainer::updateParticle(uint idx, TruthPart& truth) { if(m_debug) std::cout << "in TruthContainer::updateParticle " << std::endl; ParticleContainer::updateParticle(idx,truth); truth.pdgId = m_pdgId->at(idx); if(!m_infoSwitch.m_pdgIdOnly){ truth.status = m_status->at(idx); truth.barcode = m_barcode->at(idx); } if(m_infoSwitch.m_type){ truth.is_higgs = (bool)m_is_higgs->at(idx); truth.is_bhad = (bool)m_is_bhad ->at(idx); } if(m_infoSwitch.m_bVtx){ truth.Bdecay_x = m_Bdecay_x->at(idx); truth.Bdecay_y = m_Bdecay_y->at(idx); truth.Bdecay_z = m_Bdecay_z->at(idx); } if(m_infoSwitch.m_parents){ truth.nParents = m_nParents->at(idx); truth.parent_pdgId = m_parent_pdgId->at(idx); truth.parent_barcode = m_parent_barcode->at(idx); truth.parent_status = m_parent_status ->at(idx); } if(m_infoSwitch.m_children){ truth.nChildren = m_nChildren->at(idx); truth.child_pdgId = m_child_pdgId->at(idx); truth.child_barcode = m_child_barcode->at(idx); truth.child_status = m_child_status ->at(idx); } if(m_infoSwitch.m_dressed){ truth.pt_dressed = m_pt_dressed->at(idx); truth.eta_dressed = m_eta_dressed->at(idx); truth.phi_dressed = m_phi_dressed->at(idx); truth.e_dressed = m_e_dressed->at(idx); } if(m_infoSwitch.m_origin){ truth.origin = m_origin->at(idx); } if(m_infoSwitch.m_particleType){ truth.type = m_particleType->at(idx); } if(m_debug) std::cout << "leave TruthContainer::updateParticle " << std::endl; return; } void TruthContainer::setBranches(TTree *tree) { ParticleContainer::setBranches(tree); setBranch(tree,"pdgId", m_pdgId ); if(!m_infoSwitch.m_pdgIdOnly){ setBranch(tree,"status", m_status ); setBranch(tree,"barcode", m_barcode ); } if(m_infoSwitch.m_type){ setBranch(tree,"is_higgs", m_is_higgs ); setBranch(tree,"is_bhad", m_is_bhad ); } if(m_infoSwitch.m_bVtx){ setBranch(tree,"Bdecay_x", m_Bdecay_x ); setBranch(tree,"Bdecay_y", m_Bdecay_y ); setBranch(tree,"Bdecay_z", m_Bdecay_z ); } if(m_infoSwitch.m_parents){ setBranch (tree,"nParents", m_nParents ); setBranch >(tree,"parent_pdgId", m_parent_pdgId ); setBranch >(tree,"parent_barcode", m_parent_barcode ); setBranch >(tree,"parent_status", m_parent_status ); } if(m_infoSwitch.m_children){ setBranch (tree,"nChildren", m_nChildren ); setBranch >(tree,"child_pdgId", m_child_pdgId ); setBranch >(tree,"child_barcode", m_child_barcode ); setBranch >(tree,"child_status", m_child_status ); } if(m_infoSwitch.m_dressed){ setBranch (tree,"pt_dressed", m_pt_dressed ); setBranch (tree,"eta_dressed", m_eta_dressed ); setBranch (tree,"phi_dressed", m_phi_dressed ); setBranch (tree,"e_dressed", m_e_dressed ); } if(m_infoSwitch.m_origin){ setBranch (tree,"origin",m_origin); } if(m_infoSwitch.m_particleType){ setBranch (tree,"type",m_particleType); } return; } void TruthContainer::clear() { ParticleContainer::clear(); m_pdgId ->clear(); if(!m_infoSwitch.m_pdgIdOnly){ m_status->clear(); m_barcode->clear(); } if(m_infoSwitch.m_type){ m_is_higgs ->clear(); m_is_bhad ->clear(); } if(m_infoSwitch.m_bVtx){ m_Bdecay_x->clear(); m_Bdecay_y->clear(); m_Bdecay_z->clear(); } if(m_infoSwitch.m_parents){ m_nParents->clear(); m_parent_pdgId->clear(); m_parent_barcode->clear(); m_parent_status->clear(); } if(m_infoSwitch.m_children){ m_nChildren->clear(); m_child_pdgId->clear(); m_child_barcode->clear(); m_child_status->clear(); } if(m_infoSwitch.m_dressed){ m_pt_dressed->clear(); m_eta_dressed->clear(); m_phi_dressed->clear(); m_e_dressed->clear(); } if(m_infoSwitch.m_origin){ m_origin->clear(); } if(m_infoSwitch.m_particleType){ m_particleType->clear(); } return; } void TruthContainer::FillTruth( const xAOD::TruthParticle* truth ){ return FillTruth(static_cast(truth)); } void TruthContainer::FillTruth( const xAOD::IParticle* particle ){ if(m_debug) std::cout << "In Fill Truth " << std::endl; ParticleContainer::FillParticle(particle); const xAOD::TruthParticle* truth=dynamic_cast(particle); if(m_debug) std::cout << "Got TP " << std::endl; m_pdgId ->push_back( truth->pdgId() ); if(!m_infoSwitch.m_pdgIdOnly){ m_status ->push_back( truth->status() ); m_barcode->push_back( truth->barcode() ); } if(m_debug) std::cout << "Filled status " << std::endl; if(m_infoSwitch.m_type){ if(m_debug) std::cout << "Filling type " << std::endl; m_is_higgs->push_back( (int)truth->isHiggs() ); m_is_bhad ->push_back( (int)truth->isBottomHadron() ); } if(m_infoSwitch.m_bVtx){ if(m_debug) std::cout << "Filling bVtx " << std::endl; if(truth->isBottomHadron() && truth->hasDecayVtx()){ const xAOD::TruthVertex* vtx = truth->decayVtx(); m_Bdecay_x->push_back(vtx->x()); m_Bdecay_y->push_back(vtx->y()); m_Bdecay_z->push_back(vtx->z()); } else{ m_Bdecay_x->push_back(-999999.); m_Bdecay_y->push_back(-999999.); m_Bdecay_z->push_back(-999999.); } } if(m_infoSwitch.m_parents){ int nParents = truth->nParents(); m_nParents->push_back(nParents); m_parent_pdgId ->push_back(std::vector()); m_parent_barcode->push_back(std::vector()); m_parent_status ->push_back(std::vector()); for(int iparent = 0; iparent < nParents; ++iparent){ const xAOD::TruthParticle* parent = truth->parent(iparent); if(parent){ m_parent_pdgId ->back().push_back(parent->pdgId()); m_parent_barcode->back().push_back(parent->barcode()); m_parent_status ->back().push_back(parent->status()); }else{ m_parent_pdgId ->back().push_back(-99); m_parent_barcode->back().push_back(-99); m_parent_status ->back().push_back(-99); } } } if(m_infoSwitch.m_children){ int nChildren = truth->nChildren(); m_nChildren->push_back(nChildren); m_child_pdgId ->push_back(std::vector()); m_child_barcode->push_back(std::vector()); m_child_status ->push_back(std::vector()); for(int ichild = 0; ichild < nChildren; ++ichild){ const xAOD::TruthParticle* child = truth->child(ichild); if(child){ m_child_pdgId ->back().push_back(child->pdgId()); m_child_barcode->back().push_back(child->barcode()); m_child_status ->back().push_back(child->status()); }else{ m_child_pdgId ->back().push_back(-99); m_child_barcode->back().push_back(-99); m_child_status ->back().push_back(-99); } } } if(m_infoSwitch.m_dressed){ if( truth->isAvailable("pt_dressed") ){ float pt_dressed = truth->auxdata("pt_dressed"); m_pt_dressed->push_back(pt_dressed / m_units); } else { m_pt_dressed->push_back(-999); } if( truth->isAvailable("eta_dressed") ){ float eta_dressed = truth->auxdata("eta_dressed"); m_eta_dressed->push_back(eta_dressed); } else { m_eta_dressed->push_back(-999); } if( truth->isAvailable("phi_dressed") ){ float phi_dressed = truth->auxdata("phi_dressed"); m_phi_dressed->push_back(phi_dressed); } else { m_phi_dressed->push_back(-999); } if( truth->isAvailable("e_dressed") ){ float e_dressed = truth->auxdata("e_dressed"); m_e_dressed->push_back(e_dressed / m_units); } else { m_e_dressed->push_back(-999); } } if(m_infoSwitch.m_origin){ if( truth->isAvailable("classifierParticleOrigin") ){ unsigned int origin = truth->auxdata("classifierParticleOrigin"); m_origin->push_back(origin); } else { m_origin->push_back(0); // Non-defined } } if(m_infoSwitch.m_particleType){ if( truth->isAvailable("classifierParticleType") ){ unsigned int type = truth->auxdata("classifierParticleType"); m_particleType->push_back(type); } else { m_particleType->push_back(0); // Unknown } } if(m_debug) std::cout << "Leave Fill Truth " << std::endl; return; }