diff --git a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXNtupleWriter.h b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXNtupleWriter.h index bfab72c0ed3c4720c9b7cee91007607112ff8e6d..fd3533ce8770e223397501e673d50ca56a324223 100644 --- a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXNtupleWriter.h +++ b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXNtupleWriter.h @@ -2,12 +2,17 @@ Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ -//*************************************************************************** -// eFEXNtupleWriter.h - -// ------------------- -// begin : 28 02 2020 -// email : tong.qiu@cern.ch -// ************************************************************************** +/** + * @file eFEXNtupleWriter.h + * @brief create ntuples output + * + * File contains an Athena algorithm which creates ntuple output for the + * debugging and validation of L1Calo bitwise simulation. + * + * @author Tong Qiu (tong.qiu@cern.ch) + * @date 04 Jun 2021 + */ + #ifndef EFEXTUPLEWRITER_H #define EFEXTUPLEWRITER_H #include "AthenaBaseComps/AthAlgorithm.h" @@ -20,20 +25,34 @@ namespace LVL1 { class eFEXNtupleWriter : public AthAlgorithm { +/** + * @class eFEXNtupleWriter + * @brief An Athena algorithm which creates Ntuple output of L1Calo bitwise simulation. + */ public: - // this is a standard algorithm constructor + /// @brief this is a standard algorithm constructor eFEXNtupleWriter(const std::string& name, ISvcLocator* pSvcLocator); + + /// @brief Destructor ~eFEXNtupleWriter(); - // these are the functions inherited from Algorithm + + /// @brief initialize the Algorithm StatusCode initialize (); + + /// @brief execute the Algorithm StatusCode execute (); + + /// @brief finalize the Algorithm StatusCode finalize (); private: - eFEXOutputCollection* m_eFEXOutputCollection; + eFEXOutputCollection* m_eFEXOutputCollection; ///< a collection of the L1Calo eFex output //std::shared_ptr<eFEXOutputCollection> m_eFEXOutputCollection; - float m_eg_nTOBs; - bool m_load_truth_jet; + + int m_eg_nTOBs; ///< number of e-gamma tobs + bool m_load_truth_jet; ///< if load truth jets + + // values from the e-gamma algorithm std::vector<float> m_em; std::vector<float> m_had; std::vector<float> m_truth_e_eta; @@ -55,20 +74,69 @@ private: std::vector<float> m_eg_RetaDen; std::vector<float> m_eg_RhadNum; std::vector<float> m_eg_RhadDen; + + // values from the tau algorithm std::vector<float> m_tau_Iso; std::vector<float> m_tau_Et; std::vector<float> m_tau_isCentralTowerSeed; - std::string m_jet_container_name = "AntiKt10TruthJets"; + + std::vector<int> m_eFex_number; ///< eFex number + std::vector<uint32_t> m_eg_tob; ///< e-gamma TOB words + + // variables in eg TOB + std::vector<float> m_eg_TOB_FP; + std::vector<float> m_eg_TOB_Eta; + std::vector<float> m_eg_TOB_Phi; + std::vector<float> m_eg_TOB_ha; + std::vector<float> m_eg_TOB_f3; + std::vector<float> m_eg_TOB_Re; + std::vector<float> m_eg_TOB_Sd; + std::vector<float> m_eg_TOB_UnD; + std::vector<float> m_eg_TOB_Max; + std::vector<float> m_eg_TOB_zeros; + std::vector<float> m_eg_TOB_energy; + + std::string m_jet_container_name = "AntiKt10TruthJets"; ///< truth jet type TTree *m_myTree; + /// @brief save variables related to the e-gamma algorithm StatusCode loadegAlgoVariables(); + + /// @brief save variables in the e-gamma TOB word + StatusCode loadegAlgoTOBs(); + + /// @brief save variables related to the tau algorithm StatusCode loadtauAlgoVariables(); + + /// @brief save variables related to truth electrons StatusCode loadTruthElectron(); + + /// @brief save variables related to truth jets StatusCode loadTruthJets(); + + /// @brief save variables related to truth taus StatusCode loadTruthTau(); + + /// @brief calculate the 4-vector of all the visible decay products of the tau std::unique_ptr<TLorentzVector> visibleTauP4(const xAOD::TruthParticle*); + + /// @brief calculate the 4-vector of all the invisible decay products of the tau std::unique_ptr<TLorentzVector> invisibleTauP4(const xAOD::TruthParticle*); + + /// @brief find the nearest mother particle in the decay chain with the specified particle id. const xAOD::TruthParticle* getMother(const xAOD::TruthParticle*, int); + + /** + * @brief extract bits from a 32-bit TOB words + * + * @param in TOB word + * @param start start position (start from 1) + * @param end end position (start from 1) + * + * @return extracted bit word + * + */ + uint32_t getbits(uint32_t in, int start, int end); }; } #endif diff --git a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXOutputCollection.h b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXOutputCollection.h index c3117b7033d3ed9ba0f5b75d3586299b733bedd7..be45db2f71d7a30559449cabd818f5060e23ac32 100644 --- a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXOutputCollection.h +++ b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXOutputCollection.h @@ -2,12 +2,15 @@ Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ -//*************************************************************************** -// eFEXOutputCollection.h - -// ------------------- -// begin : 28 02 2020 -// email : tong.qiu@cern.ch -// ************************************************************************** +/** + * @file eFEXOutputCollection.h + * @brief create ntuples output + * + * File contains an class which stores the output of eFEX simulation + * + * @author Tong Qiu (tong.qiu@cern.ch) + * @date 04 Jun 2021 + */ #pragma once #include "AthenaKernel/CLASS_DEF.h" @@ -19,21 +22,75 @@ namespace LVL1 { class eFEXOutputCollection { + /** + * @class eFEXOutputCollection + * @brief an class which stores the output of eFEX simulation for the use of eFEXNtupleWriter. + */ public: + /// @brief constructor eFEXOutputCollection() {}; + + /// @brief Destructor ~eFEXOutputCollection(); + + /// @brief Removes all values from the vectors for the next event void clear(); - void addValue_eg(std::string, float); + + /** + * @brief add a value related to the e-gamma algorithm for a TOB + * + * @param key name of the value + * @param value the value + * + */ + void addValue_eg(std::string key, float value); + + /// @brief Save all e-gamma values. Use only after finishing defining all e-gamma values for one TOB. void fill_eg(); - void addValue_tau(std::string, float); + + /** + * @brief define a value related to the tau algorithm for a TOB + * + * @param key name of the value + * @param value value + * + */ + void addValue_tau(std::string key, float value); + + /// @brief Save all tau values. Use only after finishing defining all tau values for one TOB. void fill_tau(); + + /// @brief get total number of TOBs saved int size(); + + /// @brief get all e-gamma related values the ith TOB std::map<std::string, float>* get_eg(int); + + /// @brief get all tau related values the ith TOB std::map<std::string, float>* get_tau(int); + + /// @brief add the eEFX number of a TOB + void addeFexNumber(int); + + /// @brief get the eFEX numbers of all TOBs + std::vector<int> geteFexNumber(); + + /// @brief add a 32-bit e-gamma TOB word + void addEMtob(uint32_t); + + /// @brief get all e-gamma TOB words of an event + std::vector<uint32_t> getEMtob(); + private: + std::vector<int> m_eFexNumber; ///< vector of eFEX numbers + std::vector<uint32_t> m_emtob; ///< vector of TOB words + /// e-gamma related values of a TOB std::map<std::string, float> m_values_tem_eg; + /// e-gamma related values of all TOBs in an event std::vector<std::map<std::string, float>*> m_allvalues_eg; + /// tau related values of a TOB std::map<std::string, float> m_values_tem_tau; + /// rau related values of all TOBs in an event std::vector<std::map<std::string, float>*> m_allvalues_tau; }; } diff --git a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFPGA.cxx b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFPGA.cxx index 509efad5e083293054bcfa1a84d979313b54478a..dbf1dd3bc4c4faf8b55bd3be619643d1ead5bc62 100644 --- a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFPGA.cxx +++ b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFPGA.cxx @@ -193,6 +193,8 @@ StatusCode eFEXFPGA::execute(){ tmp_tob->setPhi(iphi); // for plotting + eFEXOutputs->addeFexNumber(m_efexid); + eFEXOutputs->addEMtob(tobword); eFEXOutputs->addValue_eg("WstotNum", tmp_tob->getWstotNum()); eFEXOutputs->addValue_eg("WstotDen", tmp_tob->getWstotDen()); eFEXOutputs->addValue_eg("RetaNum", tmp_tob->getRetaNum()); diff --git a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXNtupleWriter.cxx b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXNtupleWriter.cxx index 1560a803c39e2d5b36853861c2a59eecff1a8c68..f8c9452fdf9bc8ed1584df959f93819ebe275ccb 100644 --- a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXNtupleWriter.cxx +++ b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXNtupleWriter.cxx @@ -2,13 +2,6 @@ Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ -//*************************************************************************** -// eFEXNtupleWriter.cxx - -// ------------------- -// begin : 28 02 2020 -// email : tong.qiu@cern.ch -// ************************************************************************** - #include <L1CaloFEXSim/eFEXNtupleWriter.h> #include "StoreGate/StoreGateSvc.h" #include "L1CaloFEXSim/eFEXegTOB.h" @@ -67,13 +60,24 @@ StatusCode LVL1::eFEXNtupleWriter::initialize () { m_myTree->Branch ("eg_retaden", &m_eg_RetaDen); m_myTree->Branch ("eg_rhadnum", &m_eg_RhadNum); m_myTree->Branch ("eg_rhadden", &m_eg_RhadDen); - m_myTree->Branch ("eg_nTOBs", &m_eg_nTOBs, "nTOBs"); - m_myTree->Branch ("eg_haveseed", &m_eg_haveseed); - + m_myTree->Branch ("eg_haveSeed", &m_eg_haveseed); m_myTree->Branch ("tau_Iso", &m_tau_Iso); m_myTree->Branch ("tau_Et", &m_tau_Et); m_myTree->Branch ("tau_isCentralTowerSeed", &m_tau_isCentralTowerSeed); + m_myTree->Branch ("eFEXnumber", &m_eFex_number); + m_myTree->Branch ("eg_nTOBs", &m_eg_nTOBs); + m_myTree->Branch ("eg_TOB_FP", &m_eg_TOB_FP); + m_myTree->Branch ("eg_TOB_Eta", &m_eg_TOB_Eta); + m_myTree->Branch ("eg_TOB_Phi", &m_eg_TOB_Phi); + m_myTree->Branch ("eg_TOB_ha", &m_eg_TOB_ha); + m_myTree->Branch ("eg_TOB_f3", &m_eg_TOB_f3); + m_myTree->Branch ("eg_TOB_Re", &m_eg_TOB_Re); + m_myTree->Branch ("eg_TOB_Sd", &m_eg_TOB_Sd); + m_myTree->Branch ("eg_TOB_UnD", &m_eg_TOB_UnD); + m_myTree->Branch ("eg_TOB_Max", &m_eg_TOB_Max); + m_myTree->Branch ("eg_TOB_zeros", &m_eg_TOB_zeros); + m_myTree->Branch ("eg_TOB_energy", &m_eg_TOB_energy); return StatusCode::SUCCESS; } @@ -87,6 +91,7 @@ StatusCode LVL1::eFEXNtupleWriter::execute () { CHECK(evtStore->retrieve(m_eFEXOutputCollection, "eFEXOutputCollection")); CHECK(loadegAlgoVariables()); + CHECK(loadegAlgoTOBs()); CHECK(loadtauAlgoVariables()); CHECK(loadTruthElectron()); CHECK(loadTruthTau()); @@ -128,9 +133,10 @@ StatusCode LVL1::eFEXNtupleWriter::loadegAlgoVariables() { m_eg_RetaDen.clear(); m_eg_RhadNum.clear(); m_eg_RhadDen.clear(); - + m_eFex_number.clear(); m_em.clear(); m_had.clear(); + m_eg_nTOBs = m_eFEXOutputCollection->size(); for (int i = 0; i < m_eFEXOutputCollection->size(); i++) { @@ -141,7 +147,7 @@ StatusCode LVL1::eFEXNtupleWriter::loadegAlgoVariables() { m_eg_RetaDen.push_back(eFEXegvalue_tem["RetaDen"]); m_eg_RhadNum.push_back(eFEXegvalue_tem["RhadNum"]); m_eg_RhadDen.push_back(eFEXegvalue_tem["RhadDen"]); - m_eg_haveseed.push_back(eFEXegvalue_tem["haveseed"]); + m_eg_haveseed.push_back(eFEXegvalue_tem["haveSeed"]); m_eg_ET.push_back(eFEXegvalue_tem["ET"]); m_eg_eta.push_back(eFEXegvalue_tem["eta"]); m_eg_phi.push_back(eFEXegvalue_tem["phi"]); @@ -151,6 +157,49 @@ StatusCode LVL1::eFEXNtupleWriter::loadegAlgoVariables() { return StatusCode::SUCCESS; } +StatusCode LVL1::eFEXNtupleWriter::loadegAlgoTOBs() { + m_eg_TOB_FP.clear(); + m_eg_TOB_Eta.clear(); + m_eg_TOB_Phi.clear(); + m_eg_TOB_ha.clear(); + m_eg_TOB_f3.clear(); + m_eg_TOB_Re.clear(); + m_eg_TOB_Sd.clear(); + m_eg_TOB_UnD.clear(); + m_eg_TOB_Max.clear(); + m_eg_TOB_zeros.clear(); + m_eg_TOB_energy.clear(); + for (int i = 0; i < m_eFEXOutputCollection->size(); i++) + { + uint32_t TOB = m_eFEXOutputCollection->getEMtob()[i]; + uint32_t FP = getbits(TOB, 1, 2); + uint32_t Eta = getbits(TOB, 3, 5); + uint32_t Phi = getbits(TOB, 6, 8); + uint32_t ha = getbits(TOB, 9, 10); + uint32_t f3 = getbits(TOB, 11, 12); + uint32_t Re = getbits(TOB, 13, 14); + uint32_t Sd = getbits(TOB, 15, 16); + uint32_t UnD = getbits(TOB, 17, 17); + uint32_t Max = getbits(TOB, 18, 18); + uint32_t zeros = getbits(TOB, 19, 20); + uint32_t energy = getbits(TOB, 21, 32); + + m_eg_TOB_FP.push_back(FP); + m_eg_TOB_Eta.push_back(Eta); + m_eg_TOB_Phi.push_back(Phi); + m_eg_TOB_ha.push_back(ha); + m_eg_TOB_f3.push_back(f3); + m_eg_TOB_Re.push_back(Re); + m_eg_TOB_Sd.push_back(Sd); + m_eg_TOB_UnD.push_back(UnD); + m_eg_TOB_Max.push_back(Max); + m_eg_TOB_zeros.push_back(zeros); + m_eg_TOB_energy.push_back(energy * 100); + } + m_eFex_number = m_eFEXOutputCollection->geteFexNumber(); + return StatusCode::SUCCESS; +} + StatusCode LVL1::eFEXNtupleWriter::loadTruthElectron() { m_truth_e_eta.clear(); m_truth_e_phi.clear(); @@ -300,3 +349,9 @@ const xAOD::TruthParticle* LVL1::eFEXNtupleWriter::getMother(const xAOD::TruthPa } return NULL; } + +uint32_t LVL1::eFEXNtupleWriter::getbits(uint32_t in, int start, int end) { + in <<= start - 1; + in >>= 32 - end + start - 1; + return in; +} diff --git a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXOutputCollection.cxx b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXOutputCollection.cxx index 0f6f0e623e512a957102eac8a42be2d01db11875..c08c292c980899668aeef5c720f9ca38dc261ef9 100644 --- a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXOutputCollection.cxx +++ b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXOutputCollection.cxx @@ -2,13 +2,6 @@ Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ -//*************************************************************************** -// eFEXOutputCollection.cxx - -// ------------------- -// begin : 28 02 2020 -// email : tong.qiu@cern.ch -// ************************************************************************** - #include "L1CaloFEXSim/eFEXOutputCollection.h" LVL1::eFEXOutputCollection::~eFEXOutputCollection() @@ -29,6 +22,8 @@ void LVL1::eFEXOutputCollection::clear() for (auto iValues : m_allvalues_tau) { iValues->clear(); } + m_eFexNumber.clear(); + m_emtob.clear(); } void LVL1::eFEXOutputCollection::addValue_eg(std::string key, float value) @@ -69,3 +64,23 @@ std::map<std::string, float>* LVL1::eFEXOutputCollection::get_tau(int location) { return m_allvalues_tau[location]; } + +void LVL1::eFEXOutputCollection::addeFexNumber(int efexnumber) +{ + m_eFexNumber.push_back(efexnumber); +} + +std::vector<int> LVL1::eFEXOutputCollection::geteFexNumber() +{ + return m_eFexNumber; +} + +void LVL1::eFEXOutputCollection::addEMtob(uint32_t emtob) +{ + m_emtob.push_back(emtob); +} + +std::vector<uint32_t> LVL1::eFEXOutputCollection::getEMtob() +{ + return m_emtob; +}