Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions python/CellGeometryTreeMaker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
from AthenaConfiguration.ComponentFactory import CompFactory
from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator

def CellGeometryTreeMakerCfg(flags,name="CellGeometryTreeMaker",**kwargs):

result = ComponentAccumulator()

#Need both the geometry and the noise for the CellGeometryTreeMaker
from LArGeoAlgsNV.LArGMConfig import LArGMCfg
result.merge(LArGMCfg(flags))

from TileGeoModel.TileGMConfig import TileGMCfg
result.merge(TileGMCfg(flags))

from CaloTools.CaloNoiseCondAlgConfig import CaloNoiseCondAlgCfg
result.merge(CaloNoiseCondAlgCfg(flags,"totalNoise"))
result.merge(CaloNoiseCondAlgCfg(flags,"electronicNoise"))

CellGeometryTreeMaker = CompFactory.CellGeometryTreeMaker(**kwargs)
CellGeometryTreeMaker.TwoGaussianNoise = flags.Calo.TopoCluster.doTwoGaussianNoise

#Need to specify sequence name, otherwise the tool will not be added to the correct sequence and some
#containers such as CaloCellContainer will not be available
result.addEventAlgo(CellGeometryTreeMaker,sequenceName="AthAlgSeq")

return result
28 changes: 18 additions & 10 deletions python/MainCfg.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration

from AthenaConfiguration.ComponentFactory import CompFactory

def __MLTree():
from MLTree.MLTreeConfigFlags import createMLTreeConfigFlags
return createMLTreeConfigFlags()

def MainCfg(cfgFlags):
from AthenaConfiguration.MainServicesConfig import MainServicesCfg
cfg = MainServicesCfg(cfgFlags)
def GeneralServicesCfg(cfgFlags):

from AthenaConfiguration.MainServicesConfig import MainServicesCfg
cfg = MainServicesCfg(cfgFlags)

StoreGateSvc=CompFactory.StoreGateSvc
cfg.addService(StoreGateSvc("DetectorStore"))
StoreGateSvc=CompFactory.StoreGateSvc
cfg.addService(StoreGateSvc("DetectorStore"))

histSvc = CompFactory.THistSvc(Output = ["OutputStream DATAFILE='"+ cfgFlags.MLTree.NtupleName+"', OPT='RECREATE'"])
cfg.addService(histSvc)
histSvc = CompFactory.THistSvc(Output = ["OutputStream DATAFILE='"+ cfgFlags.MLTree.NtupleName+"', OPT='RECREATE'"])
cfg.addService(histSvc)

from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
cfg.merge(PoolReadCfg(cfgFlags))
from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
cfg.merge(PoolReadCfg(cfgFlags))

return cfg

def MainCfg(cfgFlags):

cfg = GeneralServicesCfg(cfgFlags)

#Configure topocluster algorithmsm, and associated conditions
from CaloRec.CaloTopoClusterConfig import CaloTopoClusterCfg
Expand Down
2 changes: 2 additions & 0 deletions python/launch_jobs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#! /usr/bin/env python


# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
# @file submit_grid.py
# @author Joakim Olsson <joakim.olsson@cern.ch>
# @brief Launch grid jobs with the MLTree package
Expand Down
25 changes: 25 additions & 0 deletions python/runCellGeometryTreeMaker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration

from AthenaConfiguration.AllConfigFlags import ConfigFlags as cfgFlags

if __name__=="__main__":

from AthenaConfiguration.AllConfigFlags import ConfigFlags as cfgFlags
from MLTree.MainCfg import __MLTree
cfgFlags.addFlagsCategory("MLTree",__MLTree)

cfgFlags.Exec.MaxEvents=-1
cfgFlags.Input.isMC=True
cfgFlags.Input.Files= ["/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/PFlowTests/mc16_13TeV/mc16_13TeV.410470.PhPy8EG_A14_ttbar_hdamp258p75_nonallhad.recon.ESD.e6337_e5984_s3170_r12674/ESD.25732025._000034.pool.root.1"]
cfgFlags.Concurrency.NumThreads=1
cfgFlags.MLTree.NtupleName="CellGeo"
cfgFlags.fillFromArgs()
cfgFlags.lock()

from MainCfg import GeneralServicesCfg
cfg = GeneralServicesCfg(cfgFlags)

from MLTree.CellGeometryTreeMaker import CellGeometryTreeMakerCfg
cfg.merge(CellGeometryTreeMakerCfg(cfgFlags))

cfg.run()
2 changes: 2 additions & 0 deletions python/runDiJets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration

#You can run this code from the command line (after Athena setup) with a command:
#python runDiJets.py --filesInput=<inputFileName> MLTree.NtupleName=<outputNtupleFileName>"

Expand Down
2 changes: 1 addition & 1 deletion python/runCA.py → python/runMLTreeMaker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
#You can run this code from the command line (after Athena setup) with a command:
#python runCA.py --filesInput=<inputFileName> MLTree.NtupleName=<outputNtupleFileName>"

Expand All @@ -9,7 +10,6 @@

cfgFlags.Exec.MaxEvents=-1
cfgFlags.Input.isMC=True
#cfgFlags.Input.Files=["/home/markhodgkinson.linux/ESD.28115683._000440.pool.root.1"]
cfgFlags.Input.Files= ["/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/PFlowTests/mc16_13TeV/mc16_13TeV.410470.PhPy8EG_A14_ttbar_hdamp258p75_nonallhad.recon.ESD.e6337_e5984_s3170_r12674/ESD.25732025._000034.pool.root.1"]
cfgFlags.Concurrency.NumThreads=1
cfgFlags.fillFromArgs()
Expand Down
2 changes: 2 additions & 0 deletions python/run_EdmundTingConfig.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration

#You can run this code from the command line (after Athena setup) with a command:
#python runCA.py --filesInput=<inputFileName> MLTree.NtupleName=<outputNtupleFileName>"

Expand Down
63 changes: 38 additions & 25 deletions src/CellGeometryTreeMaker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ CellGeometryTreeMaker::CellGeometryTreeMaker( const std::string& name, ISvcLocat
AthHistogramAlgorithm( name, pSvcLocator ),
m_doNeighbours(true)
{
declareProperty("CaloCellContainer", m_cellContainerKey="AllCalo");
declareProperty("DoNeighbours",m_doNeighbours);
}

Expand All @@ -21,15 +20,16 @@ StatusCode CellGeometryTreeMaker::initialize()
CHECK( book(TTree("CellGeo","CellGeo")));
m_cellGeometryTree = tree("CellGeo");

m_cellGeometryTree->Branch("cell_geo_ID", &m_b_cell_geo_ID);
m_cellGeometryTree->Branch("cell_geo_sampling", &m_b_cell_geo_sampling);
m_cellGeometryTree->Branch("cell_geo_eta", &m_b_cell_geo_eta);
m_cellGeometryTree->Branch("cell_geo_phi", &m_b_cell_geo_phi);
m_cellGeometryTree->Branch("cell_geo_rPerp", &m_b_cell_geo_rPerp);
m_cellGeometryTree->Branch("cell_geo_deta", &m_b_cell_geo_deta);
m_cellGeometryTree->Branch("cell_geo_dphi", &m_b_cell_geo_dphi);
m_cellGeometryTree->Branch("cell_geo_volume", &m_b_cell_geo_volume);
m_cellGeometryTree->Branch("cell_geo_sigma", &m_b_cell_geo_sigma);
m_cellGeometryTree->Branch("cell_geo_ID", &m_b_cell_geo_ID);
m_cellGeometryTree->Branch("cell_geo_sampling", &m_b_cell_geo_sampling);
m_cellGeometryTree->Branch("cell_geo_eta", &m_b_cell_geo_eta);
m_cellGeometryTree->Branch("cell_geo_phi", &m_b_cell_geo_phi);
m_cellGeometryTree->Branch("cell_geo_rPerp", &m_b_cell_geo_rPerp);
m_cellGeometryTree->Branch("cell_geo_deta", &m_b_cell_geo_deta);
m_cellGeometryTree->Branch("cell_geo_dphi", &m_b_cell_geo_dphi);
m_cellGeometryTree->Branch("cell_geo_volume", &m_b_cell_geo_volume);
m_cellGeometryTree->Branch("cell_geo_electronicNoise", &m_b_cell_geo_electronicNoise);
m_cellGeometryTree->Branch("cell_geo_totalNoise", &m_b_cell_geo_totalNoise);
if(m_doNeighbours)
{
m_neighbourNames={"prevInPhi","nextInPhi","prevInEta","nextInEta",
Expand All @@ -43,21 +43,28 @@ StatusCode CellGeometryTreeMaker::initialize()
m_cellGeometryTree->Branch(std::string("cell_geo_"+nname).c_str(),&(m_b_cell_geo_neighbourhood.back()));
}
}
ATH_CHECK( m_caloNoiseKey.initialize() );
ATH_CHECK( m_caloElectronicNoiseKey.initialize() );
ATH_CHECK( m_caloTotalNoiseKey.initialize() );
ATH_MSG_INFO("Noise conditions initialized");

/* Retrieve calorimeter detector manager */
ATH_CHECK(m_caloMgrKey.initialize());

ATH_CHECK(m_cellContainerKey.initialize());

return StatusCode::SUCCESS;
}

StatusCode CellGeometryTreeMaker::execute()
{
const CaloCellContainer* CellContainer = 0;
CHECK(evtStore()->retrieve(CellContainer,m_cellContainerKey));
//
auto nCells=CellContainer->size();

SG::ReadHandle<CaloCellContainer> cellContainerHandle(m_cellContainerKey);
if (!cellContainerHandle.isValid()) {
ATH_MSG_ERROR("Could not retrieve CaloCellContainer with key " << m_cellContainerKey);
return StatusCode::FAILURE;
}

auto nCells=cellContainerHandle->size();

if(m_cellGeometryTree->GetEntries() > 0) return StatusCode::SUCCESS;
SG::ReadCondHandle<CaloDetDescrManager> caloMgrHandle{m_caloMgrKey};
Expand All @@ -72,7 +79,8 @@ StatusCode CellGeometryTreeMaker::execute()
m_b_cell_geo_deta.clear();
m_b_cell_geo_dphi.clear();
m_b_cell_geo_volume.clear();
m_b_cell_geo_sigma.clear();
m_b_cell_geo_electronicNoise.clear();
m_b_cell_geo_totalNoise.clear();

m_b_cell_geo_ID.reserve(nCells);
m_b_cell_geo_sampling.reserve(nCells);
Expand All @@ -81,23 +89,24 @@ StatusCode CellGeometryTreeMaker::execute()
m_b_cell_geo_rPerp.reserve(nCells);
m_b_cell_geo_deta.reserve(nCells);
m_b_cell_geo_dphi.reserve(nCells);
m_b_cell_geo_sigma.reserve(nCells);
m_b_cell_geo_electronicNoise.reserve(nCells);
m_b_cell_geo_totalNoise.reserve(nCells);
m_b_cell_geo_volume.reserve(nCells);

for(std::vector<int>& nn : m_b_cell_geo_neighbourhood) nn.assign(nCells,-1);
std::vector<std::vector<IdentifierHash> > hashNeighbourhood;
hashNeighbourhood.reserve(nCells);

//the neighbour information
//std::unordered_map<IdentifierHash,unsigned int> cell_map;
std::unordered_map<unsigned int,unsigned int> cellHashMap;
cellHashMap.reserve(nCells);

SG::ReadCondHandle<CaloNoise> caloNoise (m_caloNoiseKey);
SG::ReadCondHandle<CaloNoise> electronicCaloNoise (m_caloElectronicNoiseKey);
SG::ReadCondHandle<CaloNoise> totalCaloNoise (m_caloTotalNoiseKey);

for(unsigned int iCell=0; iCell < nCells; iCell++)
{
auto pCell=CellContainer->at(iCell);
auto pCell=cellContainerHandle->at(iCell);
auto theDDE= pCell->caloDDE();
m_b_cell_geo_ID.push_back(pCell->ID().get_identifier32().get_compact());
m_b_cell_geo_sampling.push_back(theDDE->getSampling());
Expand All @@ -109,7 +118,14 @@ StatusCode CellGeometryTreeMaker::execute()
m_b_cell_geo_deta.push_back(theDDE->deta());
m_b_cell_geo_dphi.push_back(theDDE->dphi());
m_b_cell_geo_volume.push_back(theDDE->volume());
m_b_cell_geo_sigma.push_back(caloNoise->getNoise(pCell->ID(), pCell->gain()));

float electronicNoise = m_twoGaussianNoise ? electronicCaloNoise->getEffectiveSigma(pCell->ID(),pCell->gain(),pCell->energy()) :
electronicCaloNoise->getNoise(pCell->ID(), pCell->gain());
m_b_cell_geo_electronicNoise.push_back(electronicNoise);

float totalNoise = m_twoGaussianNoise ? totalCaloNoise->getEffectiveSigma(pCell->ID(),pCell->gain(),pCell->energy()) :
totalCaloNoise->getNoise(pCell->ID(), pCell->gain());
m_b_cell_geo_totalNoise.push_back(totalNoise);

if(m_doNeighbours) cellHashMap[theDDE->calo_hash().value()]=iCell;

Expand All @@ -121,7 +137,7 @@ StatusCode CellGeometryTreeMaker::execute()
v_NN.reserve(22);
for(unsigned int jCell=0; jCell<nCells; jCell++)
{
unsigned int cellHash=CellContainer->at(jCell)->caloDDE()->calo_hash().value();
unsigned int cellHash=cellContainerHandle->at(jCell)->caloDDE()->calo_hash().value();
for(unsigned int nType=0; nType<m_b_cell_geo_neighbourhood.size(); nType++)
{
calo_id->get_neighbours(cellHash,m_neighbourTypes[nType],v_NN);
Expand All @@ -133,9 +149,6 @@ StatusCode CellGeometryTreeMaker::execute()
m_cellGeometryTree->Fill();
return StatusCode::SUCCESS;


//

}

StatusCode CellGeometryTreeMaker::finalize()
Expand Down
17 changes: 13 additions & 4 deletions src/CellGeometryTreeMaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ class CellGeometryTreeMaker: public ::AthHistogramAlgorithm {

private:
typedef CaloCellContainer::size_type size_type;
/** Conditions Handle to access calorimeter noise */
SG::ReadCondHandleKey<CaloNoise> m_caloNoiseKey{this, "CaloNoise","electronicNoise","CaloNoise object to read."};

/** Conditions Handles to access calorimeter noise */
SG::ReadCondHandleKey<CaloNoise> m_caloElectronicNoiseKey{this, "CaloNoise","electronicNoise","CaloNoise object to read."};
SG::ReadCondHandleKey<CaloNoise> m_caloTotalNoiseKey{this, "CaloNoise","totalNoise","CaloNoise object to read."};

/** Toggle what type of noise to get */
Gaudi::Property<bool> m_twoGaussianNoise{this,"TwoGaussianNoise",true,"Whether to use 2-gaussian noise description for TileCal"};

/** ReadCondHandleKey for CaloDetDescrManager */
SG::ReadCondHandleKey<CaloDetDescrManager> m_caloMgrKey { this
, "CaloDetDescrManager"
, "CaloDetDescrManager"
, "SG Key for CaloDetDescrManager in the Condition Store" };

/** ReadHandleKey for the CaloCellContainer */

SG::ReadHandleKey<CaloCellContainer> m_cellContainerKey{this, "CaloCellContainer", "AllCalo", "SG key for the CaloCellContainer"};

bool m_doNeighbours;

TTree* m_cellGeometryTree;
Expand All @@ -42,10 +51,10 @@ class CellGeometryTreeMaker: public ::AthHistogramAlgorithm {
std::vector<float> m_b_cell_geo_deta;
std::vector<float> m_b_cell_geo_dphi;
std::vector<float> m_b_cell_geo_volume;
std::vector<float> m_b_cell_geo_sigma;
std::vector<float> m_b_cell_geo_electronicNoise;
std::vector<float> m_b_cell_geo_totalNoise;
std::vector<std::vector<int> > m_b_cell_geo_neighbourhood;

std::string m_cellContainerKey;
std::vector<std::string> m_neighbourNames;
std::vector<LArNeighbours::neighbourOption> m_neighbourTypes;

Expand Down