Skip to content

Commit

Permalink
move module imports closer to when they are used (BrieucÅ's style)
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannimarchiori committed Aug 29, 2024
1 parent deb3172 commit 0cd9d09
Showing 1 changed file with 48 additions and 54 deletions.
102 changes: 48 additions & 54 deletions RecFCCeeCalorimeter/tests/options/ALLEGRO_o1_v03_digi_reco.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,12 @@
#
# IMPORTS
# COMMON IMPORTS
#
from Configurables import ApplicationMgr
from Configurables import AuditorSvc, ChronoAuditor
# Input/output
from Configurables import k4DataSvc, PodioInput
from Configurables import PodioOutput
# Geometry
from Configurables import GeoSvc
# Create cells
from Configurables import CreateCaloCells
from Configurables import CreateEmptyCaloCellsCollection
# Cell positioning tools
from Configurables import CreateCaloCellPositionsFCCee
from Configurables import CellPositionsECalBarrelModuleThetaSegTool
from Configurables import CellPositionsECalEndcapTurbineSegTool
# Redo segmentation for ECAL and HCAL
from Configurables import RedoSegmentation
# Read noise values from file and generate noise in cells
from Configurables import NoiseCaloCellsVsThetaFromFileTool
# Apply sampling fraction corrections
from Configurables import CalibrateCaloHitsTool
from Configurables import CalibrateInLayersTool
# Up/down stream correction
from Configurables import CorrectCaloClusters
# SW clustering
from Configurables import CaloTowerToolFCCee
from Configurables import CreateCaloClustersSlidingWindowFCCee
# Topo clustering
from Configurables import CaloTopoClusterInputTool
from Configurables import TopoCaloNeighbours
from Configurables import TopoCaloNoisyCells
from Configurables import CaloTopoClusterFCCee
# Decorate clusters with shower shape parameters
from Configurables import AugmentClustersFCCee
# MVA calibration
from Configurables import CalibrateCaloClusters
# photon/pi0 identification
from Configurables import PhotonIDTool

# Logger
from Gaudi.Configuration import INFO # DEBUG, VERBOSE
# units and physical constants
from GaudiKernel.PhysicalConstants import pi
# python libraries
import os


#
# SETTINGS
Expand Down Expand Up @@ -112,6 +75,7 @@
#

# Input: load the output of the SIM step
from Configurables import k4DataSvc, PodioInput
podioevent = k4DataSvc('EventDataSvc')
podioevent.input = inputfile
input_reader = PodioInput('InputReader')
Expand All @@ -120,6 +84,8 @@
# Detector geometry
# prefix all xmls with path_to_detector
# if K4GEO is empty, this should use relative path to working directory
from Configurables import GeoSvc
import os
geoservice = GeoSvc("GeoSvc")
path_to_detector = os.environ.get("K4GEO", "")
detectors_to_use = [
Expand Down Expand Up @@ -152,6 +118,7 @@
hcalEndcapReadoutName = ""

# - EM scale calibration (sampling fraction)
from Configurables import CalibrateInLayersTool
# * ECAL barrel
calibEcalBarrel = CalibrateInLayersTool("CalibrateECalBarrel",
samplingFraction=ecalBarrelSamplingFraction,
Expand All @@ -164,13 +131,19 @@
layerFieldName="layer")

if runHCal:
from Configurables import CalibrateCaloHitsTool
# HCAL barrel
calibHCalBarrel = CalibrateCaloHitsTool(
"CalibrateHCalBarrel", invSamplingFraction="29.4202")
# HCAL endcap
calibHCalEndcap = CalibrateCaloHitsTool(
"CalibrateHCalEndcap", invSamplingFraction="29.4202") # FIXME: to be updated for ddsim

from Configurables import CreateCaloCells
from Configurables import CreateCaloCellPositionsFCCee
from Configurables import CellPositionsECalBarrelModuleThetaSegTool
from Configurables import CellPositionsECalEndcapTurbineSegTool

# Create cells in ECal barrel (needed if one wants to apply cell calibration,
# which is not performed by ddsim)
# - merge hits into cells according to initial segmentation
Expand Down Expand Up @@ -208,6 +181,7 @@
# Add noise at this step if you derived the noise already assuming merged cells
# Step 2a: compute new cellID of cells based on new readout
# (merged module-theta segmentation with variable merging vs layer)
from Configurables import RedoSegmentation
resegmentEcalBarrelTool = RedoSegmentation("ReSegmentationEcal",
# old bitfield (readout)
oldReadoutName=ecalBarrelReadoutName,
Expand Down Expand Up @@ -279,6 +253,7 @@
if addNoise:
ecalBarrelNoisePath = "elecNoise_ecalBarrelFCCee_theta.root"
ecalBarrelNoiseRMSHistName = "h_elecNoise_fcc_"
from Configurables import NoiseCaloCellsVsThetaFromFileTool
noiseBarrel = NoiseCaloCellsVsThetaFromFileTool("NoiseBarrel",
cellPositionsTool=cellPositionEcalBarrelTool,
readoutName=ecalBarrelReadoutName,
Expand Down Expand Up @@ -364,6 +339,7 @@

# first we create new hits with the readout without the row information
# and then merge them into new cells
from Configurables import RedoSegmentation
rewriteHCalBarrel = RedoSegmentation("ReSegmentationHCal",
# old bitfield (readout)
oldReadoutName=hcalBarrelReadoutName,
Expand Down Expand Up @@ -419,12 +395,15 @@
cellPositionHCalBarrelTool2 = None

# Empty cells for parts of calorimeter not implemented yet
from Configurables import CreateEmptyCaloCellsCollection
createemptycells = CreateEmptyCaloCellsCollection("CreateEmptyCaloCells")
createemptycells.cells.Path = "emptyCaloCells"

if doSWClustering:

# Produce sliding window clusters
from Configurables import CaloTowerToolFCCee
from Configurables import CreateCaloClustersSlidingWindowFCCee

# Clustering parameters
# - phi-theta window sizes
Expand Down Expand Up @@ -458,6 +437,20 @@
ecalBarrelTowers.hcalEndcapCells.Path = "emptyCaloCells"
ecalBarrelTowers.hcalFwdCells.Path = "emptyCaloCells"

createECalBarrelClusters = CreateCaloClustersSlidingWindowFCCee("CreateECalBarrelClusters",
towerTool=ecalBarrelTowers,
nThetaWindow=windT, nPhiWindow=windP,
nThetaPosition=posT, nPhiPosition=posP,
nThetaDuplicates=dupT, nPhiDuplicates=dupP,
nThetaFinal=finT, nPhiFinal=finP,
energyThreshold=threshold,
energySharingCorrection=False,
attachCells=True,
OutputLevel=INFO
)
createECalBarrelClusters.clusters.Path = "EMBCaloClusters"
createECalBarrelClusters.clusterCells.Path = "EMBCaloClusterCells"

ecalEndcapTowers = CaloTowerToolFCCee("CreateECalEndcapTowers",
deltaThetaTower=4 * 0.009817477 / 4, deltaPhiTower=2 * 2 * pi / 1536.,
ecalBarrelReadoutName="",
Expand All @@ -476,20 +469,6 @@
ecalEndcapTowers.hcalEndcapCells.Path = "emptyCaloCells"
ecalEndcapTowers.hcalFwdCells.Path = "emptyCaloCells"

createECalBarrelClusters = CreateCaloClustersSlidingWindowFCCee("CreateECalBarrelClusters",
towerTool=ecalBarrelTowers,
nThetaWindow=windT, nPhiWindow=windP,
nThetaPosition=posT, nPhiPosition=posP,
nThetaDuplicates=dupT, nPhiDuplicates=dupP,
nThetaFinal=finT, nPhiFinal=finP,
energyThreshold=threshold,
energySharingCorrection=False,
attachCells=True,
OutputLevel=INFO
)
createECalBarrelClusters.clusters.Path = "EMBCaloClusters"
createECalBarrelClusters.clusterCells.Path = "EMBCaloClusterCells"

createECalEndcapClusters = CreateCaloClustersSlidingWindowFCCee("CreateECalEndcapClusters",
towerTool=ecalEndcapTowers,
nThetaWindow=windT, nPhiWindow=windP,
Expand All @@ -505,6 +484,7 @@
createECalEndcapClusters.clusterCells.Path = "EMECCaloClusterCells"

if applyUpDownstreamCorrections:
from Configurables import CorrectCaloClusters
correctECalBarrelClusters = CorrectCaloClusters("CorrectECalBarrelClusters",
inClusters=createECalBarrelClusters.clusters.Path,
outClusters="Corrected" + createECalBarrelClusters.clusters.Path,
Expand All @@ -523,6 +503,7 @@
)

if addShapeParameters:
from Configurables import AugmentClustersFCCee
augmentECalBarrelClusters = AugmentClustersFCCee("AugmentECalBarrelClusters",
inClusters=createECalBarrelClusters.clusters.Path,
outClusters="Augmented" + createECalBarrelClusters.clusters.Path,
Expand All @@ -543,6 +524,7 @@
else:
inClusters = createECalBarrelClusters.clusters.Path

from Configurables import CalibrateCaloClusters
calibrateECalBarrelClusters = CalibrateCaloClusters("calibrateECalBarrelClusters",
inClusters=inClusters,
outClusters="Calibrated" + createECalBarrelClusters.clusters.Path,
Expand All @@ -568,6 +550,7 @@
else:
inClusters = augmentECalBarrelClusters.outClusters.Path

from Configurables import PhotonIDTool
photonIDECalBarrelClusters = PhotonIDTool("photonIDECalBarrelClusters",
inClusters=inClusters,
outClusters="PhotonID" + inClusters,
Expand Down Expand Up @@ -616,6 +599,10 @@
if doTopoClustering:

# Produce topoclusters
from Configurables import CaloTopoClusterInputTool
from Configurables import TopoCaloNeighbours
from Configurables import TopoCaloNoisyCells
from Configurables import CaloTopoClusterFCCee

# ECAL only
createECalBarrelTopoInput = CaloTopoClusterInputTool("CreateECalBarrelTopoInput",
Expand Down Expand Up @@ -675,6 +662,7 @@
# no topoclusters for ECAL endcap yet: no noise and neighbour maps provided

if applyUpDownstreamCorrections:
from Configurables import CorrectCaloClusters
correctECalBarrelTopoClusters = CorrectCaloClusters(
"CorrectECalBarrelTopoClusters",
inClusters=createECalBarrelTopoClusters.clusters.Path,
Expand All @@ -694,6 +682,7 @@
)

if addShapeParameters:
from Configurables import AugmentClustersFCCee
augmentECalBarrelTopoClusters = AugmentClustersFCCee("augmentECalBarrelTopoClusters",
inClusters=createECalBarrelTopoClusters.clusters.Path,
outClusters="Augmented" + createECalBarrelTopoClusters.clusters.Path,
Expand All @@ -713,6 +702,7 @@
else:
inClusters = createECalBarrelTopoClusters.clusters.Path

from Configurables import CalibrateCaloClusters
calibrateECalBarrelTopoClusters = CalibrateCaloClusters("calibrateECalBarrelTopoClusters",
inClusters=inClusters,
outClusters="Calibrated" + createECalBarrelTopoClusters.clusters.Path,
Expand All @@ -738,6 +728,7 @@
else:
inClusters = augmentECalBarrelTopoClusters.outClusters.Path

from Configurables import PhotonIDTool
photonIDECalBarrelTopoClusters = PhotonIDTool("photonIDECalBarrelTopoClusters",
inClusters=inClusters,
outClusters="PhotonID" + inClusters,
Expand Down Expand Up @@ -805,6 +796,7 @@
createTopoClusters.clusterCells.Path = "CaloTopoClusterCells"

# Output
from Configurables import PodioOutput
out = PodioOutput("out",
OutputLevel=INFO)
out.filename = "ALLEGRO_sim_digi_reco.root"
Expand Down Expand Up @@ -868,6 +860,7 @@
# out.outputCommands.append("drop %s" % augmentECalBarrelClusters.inClusters)

# CPU information
from Configurables import AuditorSvc, ChronoAuditor
chra = ChronoAuditor()
audsvc = AuditorSvc()
audsvc.Auditors = [chra]
Expand Down Expand Up @@ -973,6 +966,7 @@
out
]

from Configurables import ApplicationMgr
ApplicationMgr(
TopAlg=TopAlg,
EvtSel='NONE',
Expand Down

0 comments on commit 0cd9d09

Please sign in to comment.