From 3790e0de44ca611b49fcea42cc85d49934698ffb Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori Date: Sat, 20 Jul 2024 11:45:44 +0200 Subject: [PATCH 1/4] use new unified noise tool in both scripts to create map for topoclustering and to do digi+reco --- FCCSW_ecal/noise_map_theta.py | 58 ++++++++++++++++++++--------- FCCSW_ecal/run_thetamodulemerged.py | 55 ++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 19 deletions(-) diff --git a/FCCSW_ecal/noise_map_theta.py b/FCCSW_ecal/noise_map_theta.py index b317b2e..1507b6d 100644 --- a/FCCSW_ecal/noise_map_theta.py +++ b/FCCSW_ecal/noise_map_theta.py @@ -1,14 +1,14 @@ from Configurables import GeoSvc from Configurables import ApplicationMgr from Configurables import CreateFCCeeCaloNoiseLevelMap -# from Configurables import ReadNoiseFromFileTool -from Configurables import ReadNoiseVsThetaFromFileTool +#from Configurables import ReadNoiseVsThetaFromFileTool +from Configurables import NoiseCaloCellsVsThetaFromFileTool from Configurables import ConstNoiseTool from Configurables import CellPositionsECalBarrelModuleThetaSegTool import os from Gaudi.Configuration import INFO, DEBUG -doHCal = False +doHCal = True # Detector geometry geoservice = GeoSvc("GeoSvc") @@ -29,24 +29,37 @@ # names of file and histograms with noise per layer vs theta for barrel ECAL BarrelNoisePath = os.environ['FCCBASEDIR'] + \ "/LAr_scripts/data/elecNoise_ecalBarrelFCCee_theta.root" -ecalBarrelNoiseHistName = "h_elecNoise_fcc_" +ecalBarrelNoiseRMSHistName = "h_elecNoise_fcc_" # cell positioning and noise tool for the ecal barrel ECalBcells = CellPositionsECalBarrelModuleThetaSegTool("CellPositionsECalBarrel", readoutName=ecalBarrelReadoutName) -ECalNoiseTool = ReadNoiseVsThetaFromFileTool("ReadNoiseFromFileToolECal", - useSegmentation=False, - cellPositionsTool=ECalBcells, - readoutName=ecalBarrelReadoutName, - noiseFileName=BarrelNoisePath, - elecNoiseHistoName=ecalBarrelNoiseHistName, - setNoiseOffset=False, - activeFieldName="layer", - addPileup=False, - numRadialLayers=11, - scaleFactor=1 / 1000., # MeV to GeV - OutputLevel=INFO) +#ECalNoiseTool = ReadNoiseVsThetaFromFileTool("ReadNoiseFromFileToolECal", +# useSegmentation=False, +# cellPositionsTool=ECalBcells, +# readoutName=ecalBarrelReadoutName, +# noiseFileName=BarrelNoisePath, +# elecNoiseHistoName=ecalBarrelNoiseHistName, +# setNoiseOffset=False, +# activeFieldName="layer", +# addPileup=False, +# numRadialLayers=11, +# scaleFactor=1 / 1000., # MeV to GeV +# OutputLevel=INFO) + +ECalNoiseTool = NoiseCaloCellsVsThetaFromFileTool("NoiseCaloCellsVsThetaFromFileTool", + cellPositionsTool=ECalBcells, + readoutName=ecalBarrelReadoutName, + noiseFileName=BarrelNoisePath, + elecNoiseRMSHistoName=ecalBarrelNoiseRMSHistName, + setNoiseOffset=False, + activeFieldName="layer", + addPileup=False, + numRadialLayers=11, + scaleFactor=1 / 1000., # MeV to GeV + OutputLevel=DEBUG) + if doHCal: # noise tool for the HCAL barrel @@ -63,9 +76,19 @@ # OutputLevel = INFO) # ConstNoiseTool provides constant noise for all calo subsystems # here we are going to use it only for hcal barrel - HCalNoiseTool = ConstNoiseTool("ConstNoiseTool") + HCalNoiseTool = ConstNoiseTool("ConstNoiseTool", + detectors = [ "HCAL_Barrel"], + detectorsNoiseRMS = [0.0115/4], + detectorsNoiseOffset = [0.0], + OutputLevel = DEBUG) + #HCalNoiseTool = ConstNoiseTool("ConstNoiseTool", + # detectors = ["ECAL_Barrel", "ECAL_Endcap", "HCAL_Barrel", "HCAL_Endcap"], + # detectorsNoiseRMS = [0.0075/4, 0.0075/4, 0.0115/4, 0.0115/4], + # detectorsNoiseOffset = [0.0, 0.0, 0.0, 0.0], + # OutputLevel = DEBUG) # create the noise file for ECAL+HCAL barrel cells + # the tool wants the system IDs, maybe we could have passed the names instead noisePerCell = CreateFCCeeCaloNoiseLevelMap("noisePerCell", ECalBarrelNoiseTool=ECalNoiseTool, ecalBarrelSysId=4, @@ -79,7 +102,6 @@ activeFieldNames=[ "layer", "layer"], activeVolumesNumbers=[11, 13], - # activeVolumesEta = [1.2524, 1.2234, 1.1956, 1.1561, 1.1189, 1.0839, 1.0509, 0.9999, 0.9534, 0.91072], activeVolumesTheta=[ [], [ diff --git a/FCCSW_ecal/run_thetamodulemerged.py b/FCCSW_ecal/run_thetamodulemerged.py index 52e0c2b..c0cb0dd 100644 --- a/FCCSW_ecal/run_thetamodulemerged.py +++ b/FCCSW_ecal/run_thetamodulemerged.py @@ -14,6 +14,7 @@ from Configurables import CreateCaloCells from Configurables import CalibrateCaloHitsTool from Configurables import CalibrateInLayersTool +from Configurables import NoiseCaloCellsVsThetaFromFileTool from Configurables import SimG4Alg from Configurables import SimG4PrimariesFromEdmTool from Configurables import SimG4SaveCalHits @@ -64,7 +65,7 @@ # BDT regression from total cluster energy and fraction of energy in each layer (after correction for sampling fraction) # not to be applied for ECAL+HCAL clustering (MVA trained only on ECAL) -applyMVAClusterEnergyCalibration = True and not runHCal +applyMVAClusterEnergyCalibration = False and not runHCal # calculate cluster energy and barycenter per layer and save it as extra parameters addShapeParameters = True and not runHCal @@ -415,6 +416,54 @@ createEcalEndcapCells.hits.Path = "ECalEndcapHits" createEcalEndcapCells.cells.Path = "ECalEndcapCells" +if addNoise: + ecalBarrelNoisePath = os.environ['FCCBASEDIR']+"/LAr_scripts/data/elecNoise_ecalBarrelFCCee_theta.root" + ecalBarrelNoiseRMSHistName = "h_elecNoise_fcc_" + from Configurables import NoiseCaloCellsVsThetaFromFileTool + noiseBarrel = NoiseCaloCellsVsThetaFromFileTool("NoiseBarrel", + cellPositionsTool=cellPositionEcalBarrelTool, + readoutName=ecalBarrelReadoutName, + noiseFileName = ecalBarrelNoisePath, + elecNoiseRMSHistoName=ecalBarrelNoiseRMSHistName, + setNoiseOffset=False, + activeFieldName="layer", + addPileup=False, + filterNoiseThreshold = 0, + numRadialLayers=11, + scaleFactor=1 / 1000., # MeV to GeV + OutputLevel=DEBUG) + + # needs to be migrated + #from Configurables import TubeLayerPhiEtaCaloTool + #barrelGeometry = TubeLayerPhiEtaCaloTool("EcalBarrelGeo", + # readoutName = ecalBarrelReadoutNamePhiEta, + # activeVolumeName = "LAr_sensitive", + # activeFieldName = "layer", + # activeVolumesNumber = 12, + # fieldNames = ["system"], + # fieldValues = [4]) + + # cells with noise not filtered + # createEcalBarrelCellsNoise = CreateCaloCells("CreateECalBarrelCellsNoise", + # doCellCalibration=False, + # addCellNoise=True, filterCellNoise=False, + # OutputLevel=INFO, + # hits="ECalBarrelCellsStep2", + # noiseTool = noiseBarrel, + # geometryTool = barrelGeometry, + # cells=EcalBarrelCellsName) + + # cells with noise filtered + # createEcalBarrelCellsNoise = CreateCaloCells("CreateECalBarrelCellsNoise_filtered", + # doCellCalibration=False, + # addCellNoise=True, + # filterCellNoise=True, + # OutputLevel=INFO, + # hits="ECalBarrelCellsStep2", + # noiseTool = noiseBarrel, + # geometryTool = barrelGeometry, + # cells=EcalBarrelCellsName) + if runHCal: # Create cells in HCal barrel # 1 - merge hits into cells with the default readout @@ -500,6 +549,8 @@ # createHcalEndcapCells.hits.Path="HCalEndcapHits" # createHcalEndcapCells.cells.Path="HCalEndcapCells" + # TODO: noise... + else: hcalBarrelCellsName = "emptyCaloCells" hcalBarrelPositionedCellsName = "emptyCaloCells" @@ -565,6 +616,7 @@ numLayers=[11], firstLayerIDs=[0], lastLayerIDs=[10], + systemIDs=[4], readoutNames=[ecalBarrelReadoutName], # do not split the following line or it will break scripts that update the values of the corrections upstreamParameters = [[0.025582045561310333, -0.9524128168665387, -53.10089405478649, 1.283851527438571, -295.30650178662637, -284.8945817377308]], @@ -683,6 +735,7 @@ "correctCaloTopoClusters", inClusters=createTopoClusters.clusters.Path, outClusters="Corrected" + createTopoClusters.clusters.Path, + systemIDs=[4], numLayers=[11], firstLayerIDs=[0], lastLayerIDs=[10], From 3179dc4a607e6acb86cdb54133860427c7bf7240 Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori Date: Mon, 22 Jul 2024 14:16:29 +0200 Subject: [PATCH 2/4] remove detectorsNoiseOffset as it is not needed - by default setNoiseOffset is now set to false --- FCCSW_ecal/noise_map_theta.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/FCCSW_ecal/noise_map_theta.py b/FCCSW_ecal/noise_map_theta.py index 1507b6d..0aeae68 100644 --- a/FCCSW_ecal/noise_map_theta.py +++ b/FCCSW_ecal/noise_map_theta.py @@ -79,12 +79,10 @@ HCalNoiseTool = ConstNoiseTool("ConstNoiseTool", detectors = [ "HCAL_Barrel"], detectorsNoiseRMS = [0.0115/4], - detectorsNoiseOffset = [0.0], OutputLevel = DEBUG) #HCalNoiseTool = ConstNoiseTool("ConstNoiseTool", # detectors = ["ECAL_Barrel", "ECAL_Endcap", "HCAL_Barrel", "HCAL_Endcap"], # detectorsNoiseRMS = [0.0075/4, 0.0075/4, 0.0115/4, 0.0115/4], - # detectorsNoiseOffset = [0.0, 0.0, 0.0, 0.0], # OutputLevel = DEBUG) # create the noise file for ECAL+HCAL barrel cells From 4733ea838bd7171a3165ddf01c6c9298a51ac887 Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori Date: Thu, 25 Jul 2024 23:38:12 +0200 Subject: [PATCH 3/4] update ecal endcap readout --- FCCSW_ecal/run_thetamodulemerged.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FCCSW_ecal/run_thetamodulemerged.py b/FCCSW_ecal/run_thetamodulemerged.py index c0cb0dd..88e5f20 100644 --- a/FCCSW_ecal/run_thetamodulemerged.py +++ b/FCCSW_ecal/run_thetamodulemerged.py @@ -243,7 +243,7 @@ # ECAL ecalBarrelReadoutName = "ECalBarrelModuleThetaMerged" # barrel, original segmentation (baseline) ecalBarrelReadoutName2 = "ECalBarrelModuleThetaMerged2" # barrel, after re-segmentation (for optimisation studies) -ecalEndcapReadoutName = "ECalEndcapPhiEta" # endcap, from FCC-hh sim, to be replaced by proper readout/detector geometry +ecalEndcapReadoutName = "ECalEndcapTurbine" # endcap, turbine-like (baseline) # HCAL if runHCal: hcalBarrelReadoutName = "HCalBarrelReadout" # barrel, layer-row-theta-phi based (can be used to fill various cell collections with different readouts) @@ -319,7 +319,7 @@ readoutName=ecalBarrelReadoutName, layerFieldName="layer") -# - ECAL endcap +# - ECAL endcap (TO BE UPDATED) calibEcalEndcap = CalibrateCaloHitsTool( "CalibrateECalEndcap", invSamplingFraction="4.27") From dd71652a19b8cc44e15180566d96513ce31fc8f9 Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori Date: Fri, 26 Jul 2024 00:22:17 +0200 Subject: [PATCH 4/4] add comments and improve formatting --- FCCSW_ecal/run_thetamodulemerged.py | 116 +++++++++++++++++----------- 1 file changed, 72 insertions(+), 44 deletions(-) diff --git a/FCCSW_ecal/run_thetamodulemerged.py b/FCCSW_ecal/run_thetamodulemerged.py index 88e5f20..b86aecd 100644 --- a/FCCSW_ecal/run_thetamodulemerged.py +++ b/FCCSW_ecal/run_thetamodulemerged.py @@ -1,20 +1,12 @@ +# +# IMPORTS +# from Configurables import ApplicationMgr from Configurables import EventCounter from Configurables import AuditorSvc, ChronoAuditor -from Configurables import PodioOutput -from Configurables import CaloTowerToolFCCee -from Configurables import CreateCaloClustersSlidingWindowFCCee -from Configurables import CorrectCaloClusters -from Configurables import CalibrateCaloClusters -from Configurables import AugmentClustersFCCee -from Configurables import CreateEmptyCaloCellsCollection -from Configurables import CreateCaloCellPositionsFCCee -from Configurables import CellPositionsECalBarrelModuleThetaSegTool -from Configurables import RedoSegmentation -from Configurables import CreateCaloCells -from Configurables import CalibrateCaloHitsTool -from Configurables import CalibrateInLayersTool -from Configurables import NoiseCaloCellsVsThetaFromFileTool +# Event generation +from Configurables import GenAlg +# G4 simulation from Configurables import SimG4Alg from Configurables import SimG4PrimariesFromEdmTool from Configurables import SimG4SaveCalHits @@ -22,31 +14,61 @@ from Configurables import SimG4Svc from Configurables import SimG4FullSimActions from Configurables import SimG4SaveParticleHistory +# Geometry from Configurables import GeoSvc -from Configurables import HepMCToEDMConverter -from Configurables import GenAlg +# Input/output from Configurables import FCCDataSvc +from Configurables import PodioOutput +from Configurables import HepMCToEDMConverter +# Create cells +from Configurables import CreateCaloCells +from Configurables import CreateEmptyCaloCellsCollection +# Cell positioning tools +from Configurables import CreateCaloCellPositionsFCCee +from Configurables import CellPositionsECalBarrelModuleThetaSegTool +# 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 -from Gaudi.Configuration import INFO -# , VERBOSE, DEBUG -# from Gaudi.Configuration import * - -import os - +# Decorate clusters with shower shape parameters +from Configurables import AugmentClustersFCCee +# MVA calibration +from Configurables import CalibrateCaloClusters +# Logger +from Gaudi.Configuration import INFO, VERBOSE, DEBUG +# Units and physical constants from GaudiKernel.SystemOfUnits import GeV, tesla, mm from GaudiKernel.PhysicalConstants import pi, halfpi, twopi +# python libraries +import os from math import cos, sin, tan +# +# SETTINGS +# -# general settings +# - general settings +# use_pythia = False # use pythia or particle gun -addNoise = False # add noise or not to the cell energy -dumpGDML = False # create GDML file of detector model -runHCal = False # simulate only the ECAL or both ECAL+HCAL +addNoise = False # add noise or not to the cell energy +dumpGDML = False # create GDML file of detector model +runHCal = False # simulate only the ECAL or both ECAL+HCAL +# - what to save in output file +# # for big productions, save significant space removing hits and cells # however, hits and cluster cells might be wanted for small productions for detailed event displays # also, cluster cells are needed for the MVA training @@ -54,7 +76,8 @@ saveCells = True saveClusterCells = True -# clustering +# - clustering +# doSWClustering = True doTopoClustering = True @@ -70,7 +93,8 @@ # calculate cluster energy and barycenter per layer and save it as extra parameters addShapeParameters = True and not runHCal -# Input for simulations (momentum is expected in GeV!) +# - input for simulations (momentum is expected in GeV!) +# # Parameters for the particle gun simulations, dummy if use_pythia is set # to True @@ -121,8 +145,11 @@ magneticField = False -podioevent = FCCDataSvc("EventDataSvc") +# +# ALGORITHMS AND SERVICES SETUP +# +podioevent = FCCDataSvc("EventDataSvc") # Particle gun setup genAlg = GenAlg() @@ -423,34 +450,35 @@ noiseBarrel = NoiseCaloCellsVsThetaFromFileTool("NoiseBarrel", cellPositionsTool=cellPositionEcalBarrelTool, readoutName=ecalBarrelReadoutName, - noiseFileName = ecalBarrelNoisePath, + noiseFileName=ecalBarrelNoisePath, elecNoiseRMSHistoName=ecalBarrelNoiseRMSHistName, setNoiseOffset=False, activeFieldName="layer", addPileup=False, - filterNoiseThreshold = 0, + filterNoiseThreshold=0, numRadialLayers=11, scaleFactor=1 / 1000., # MeV to GeV OutputLevel=DEBUG) - # needs to be migrated + # needs to be migrated! #from Configurables import TubeLayerPhiEtaCaloTool #barrelGeometry = TubeLayerPhiEtaCaloTool("EcalBarrelGeo", - # readoutName = ecalBarrelReadoutNamePhiEta, - # activeVolumeName = "LAr_sensitive", - # activeFieldName = "layer", - # activeVolumesNumber = 12, - # fieldNames = ["system"], - # fieldValues = [4]) + # readoutName=ecalBarrelReadoutNamePhiEta, + # activeVolumeName="LAr_sensitive", + # activeFieldName="layer", + # activeVolumesNumber=12, + # fieldNames=["system"], + # fieldValues=[4]) # cells with noise not filtered # createEcalBarrelCellsNoise = CreateCaloCells("CreateECalBarrelCellsNoise", # doCellCalibration=False, - # addCellNoise=True, filterCellNoise=False, + # addCellNoise=True, + # filterCellNoise=False, # OutputLevel=INFO, # hits="ECalBarrelCellsStep2", - # noiseTool = noiseBarrel, - # geometryTool = barrelGeometry, + # noiseTool=noiseBarrel, + # geometryTool=barrelGeometry, # cells=EcalBarrelCellsName) # cells with noise filtered @@ -460,8 +488,8 @@ # filterCellNoise=True, # OutputLevel=INFO, # hits="ECalBarrelCellsStep2", - # noiseTool = noiseBarrel, - # geometryTool = barrelGeometry, + # noiseTool=noiseBarrel, + # geometryTool=barrelGeometry, # cells=EcalBarrelCellsName) if runHCal: @@ -508,7 +536,7 @@ oldReadoutName=hcalBarrelReadoutName, # specify which fields are going to be altered (deleted/rewritten) oldSegmentationIds=["row", "theta", "phi"], - # new bitfield (readout), with new segmentation (merged modules and theta cells) + # new bitfield (readout), with new segmentation (theta-phi grid) newReadoutName=hcalBarrelReadoutName2, OutputLevel=INFO, debugPrint=200,