Skip to content

Commit

Permalink
Merge pull request #207 from BrieucF/genTracksForALLEGRO
Browse files Browse the repository at this point in the history
Gen tracks for allegro
  • Loading branch information
giovannimarchiori authored Sep 25, 2024
2 parents 0ff8eaf + 359c62e commit 129ab36
Showing 1 changed file with 56 additions and 73 deletions.
129 changes: 56 additions & 73 deletions FCCee/FullSim/ALLEGRO/ALLEGRO_o1_v03/run_digi_reco.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

# - general settings
#
inputfile = "ALLEGRO_sim.root" # input file produced with ddsim
Nevts = -1 # -1 means all events
addNoise = False # add noise or not to the cell energy
filterNoiseThreshold = -1 # if addNoise is true, and filterNoiseThreshold is >0, will filter away cells with abs(energy) below filterNoiseThreshold * expected sigma(noise)
addCrosstalk = False # switch on/off the crosstalk
dumpGDML = False # create GDML file of detector model
runHCal = True # if false, it will produce only ECAL clusters. if true, it will also produce ECAL+HCAL clusters
inputfile = "ALLEGRO_sim.root" # input file produced with ddsim
outputfile = "ALLEGRO_sim_digi_reco.root" # output file produced by this steering file
Nevts = -1 # -1 means all events
addNoise = False # add noise or not to the cell energy
filterNoiseThreshold = -1 # if addNoise is true, and filterNoiseThreshold is >0, will filter away cells with abs(energy) below filterNoiseThreshold * expected sigma(noise)
addCrosstalk = False # switch on/off the crosstalk
dumpGDML = False # create GDML file of detector model
runHCal = True # if false, it will produce only ECAL clusters. if true, it will also produce ECAL+HCAL clusters

# - what to save in output file
#
Expand Down Expand Up @@ -106,23 +107,32 @@
geoservice.OutputLevel = INFO
ExtSvc += [geoservice]


# Input: load the output of the SIM step
from Configurables import k4DataSvc
podioevent = k4DataSvc('EventDataSvc')
podioevent.input = inputfile
ExtSvc += [podioevent]
from Configurables import PodioInput
inputReader = PodioInput('InputReader')
TopAlg += [inputReader]

# Input/Output handling
from k4FWCore import IOSvc
from Configurables import EventDataSvc
io_svc = IOSvc("IOSvc")
io_svc.input = inputfile
io_svc.output = outputfile
ExtSvc += [EventDataSvc("EventDataSvc")]

# GDML dump of detector model
if dumpGDML:
from Configurables import GeoToGdmlDumpSvc
gdmldumpservice = GeoToGdmlDumpSvc("GeoToGdmlDumpSvc")
ExtSvc += [gdmldumpservice]

# Tracking
# Create tracks from gen particles
from Configurables import TracksFromGenParticles
tracksFromGenParticles = TracksFromGenParticles("TracksFromGenParticles",
InputGenParticles = ["MCParticles"],
OutputTracks = ["TracksFromGenParticles"],
OutputMCRecoTrackParticleAssociation = ["TracksFromGenParticlesAssociation"],
Bz = 2.0,
OutputLevel = INFO)
TopAlg += [tracksFromGenParticles]

# End Tracking

# Digitisation (merging hits into cells, EM scale calibration via sampling fractions)

Expand Down Expand Up @@ -281,7 +291,6 @@
cells=ecalBarrelPositionedCellsName
)
TopAlg += [createEcalBarrelCells]
createEcalBarrelCells.AuditExecute = True

# - now, if we want to also save cells with coarser granularity:
if resegmentECalBarrel:
Expand Down Expand Up @@ -323,8 +332,6 @@
resegmentEcalBarrelTool,
createEcalBarrelCells2,
]
resegmentEcalBarrelTool.AuditExecute = True
createEcalBarrelCells2.AuditExecute = True

# Create cells in ECal endcap (needed if one wants to apply cell calibration,
# which is not performed by ddsim)
Expand All @@ -341,7 +348,6 @@
hits=ecalEndcapReadoutName,
cells=ecalEndcapPositionedCellsName)
TopAlg += [createEcalEndcapCells]
createEcalEndcapCells.AuditExecute = True

if addNoise:
# cells with noise not filtered
Expand All @@ -357,7 +363,6 @@
hits=ecalBarrelReadoutName,
cells=ecalBarrelPositionedCellsName + "WithNoise")
TopAlg += [createEcalBarrelCellsNoise]
createEcalBarrelCellsNoise.AuditExecute = True

# cells with noise filtered
createEcalBarrelCellsNoiseFiltered = CreatePositionedCaloCells("CreatePositionedECalBarrelCellsWithNoiseFiltered",
Expand All @@ -373,7 +378,6 @@
cells=ecalBarrelPositionedCellsName + "WithNoiseFiltered"
)
TopAlg += [createEcalBarrelCellsNoiseFiltered]
createEcalBarrelCellsNoiseFiltered.AuditExecute = True

if runHCal:
# Apply calibration and positioning to cells in HCal barrel
Expand All @@ -388,7 +392,6 @@
cells=hcalBarrelPositionedCellsName,
OutputLevel=INFO)
TopAlg += [createHCalBarrelCells]
createHCalBarrelCells.AuditExecute = True

# Compute new cellID of cells based on new readout - removing row information
# We use a RedoSegmentation. Using a RewriteBitField with removeIds=["row"],
Expand All @@ -411,7 +414,6 @@
inhits=hcalBarrelPositionedCellsName,
outhits="HCalBarrelCellsWithoutRow")
TopAlg += [rewriteHCalBarrel]
rewriteHCalBarrel.AuditExecute = True

hcalBarrelPositionedCellsName2 = hcalBarrelReadoutName2 + "Positioned"
createHCalBarrelCells2 = CreatePositionedCaloCells("CreatePositionedHCalBarrelCells2",
Expand All @@ -423,7 +425,6 @@
hits=rewriteHCalBarrel.outhits.Path,
cells=hcalBarrelPositionedCellsName2)
TopAlg += [createHCalBarrelCells2]
createHCalBarrelCells2.AuditExecute = True

# Create cells in HCal endcap
hcalEndcapPositionedCellsName = hcalEndcapReadoutName + "Positioned"
Expand All @@ -437,7 +438,6 @@
hits=hcalEndcapReadoutName,
cells=hcalEndcapPositionedCellsName)
TopAlg += [createHCalEndcapCells]
createHCalEndcapCells.AuditExecute = True

rewriteHCalEndcap = RedoSegmentation("ReSegmentationHCalEndcap",
# old bitfield (readout)
Expand All @@ -451,7 +451,6 @@
inhits=hcalEndcapPositionedCellsName,
outhits="HCalEndcapCellsWithoutRow")
TopAlg += [rewriteHCalEndcap]
rewriteHCalEndcap.AuditExecute = True

hcalEndcapPositionedCellsName2 = hcalEndcapReadoutName2 + "Positioned"
createHCalEndcapCells2 = CreatePositionedCaloCells("CreatePositionedHCalEndcapCells2",
Expand All @@ -463,7 +462,6 @@
hits=rewriteHCalEndcap.outhits.Path,
cells=hcalEndcapPositionedCellsName2)
TopAlg += [createHCalEndcapCells2]
createHCalEndcapCells2.AuditExecute = True

else:
hcalBarrelPositionedCellsName = "emptyCaloCells"
Expand All @@ -481,7 +479,6 @@
createemptycells = CreateEmptyCaloCellsCollection("CreateEmptyCaloCells")
createemptycells.cells.Path = "emptyCaloCells"
TopAlg += [createemptycells]
createemptycells.AuditExecute = True


# Function that sets up the sequence for producing SW clusters given an input cell collection
Expand Down Expand Up @@ -544,7 +541,6 @@ def setupSWClusters(inputCells,
clusterAlg.clusters.Path = outputClusters
clusterAlg.clusterCells.Path = outputClusters.replace("Clusters", "Cluster") + "Cells"
TopAlg += [clusterAlg]
clusterAlg.AuditExecute = True

if applyUpDownstreamCorrections:
# note that this only works for ecal barrel given various hardcoded quantities
Expand All @@ -565,7 +561,6 @@ def setupSWClusters(inputCells,
OutputLevel=INFO
)
TopAlg += [correctClusterAlg]
correctClusterAlg.AuditExecute = True

if addShapeParameters:
# note that this only works for ecal barrel given various hardcoded quantities
Expand All @@ -584,7 +579,6 @@ def setupSWClusters(inputCells,
OutputLevel=INFO
)
TopAlg += [augmentClusterAlg]
augmentClusterAlg.AuditExecute = True

if applyMVAClusterEnergyCalibration:
# note that this only works for ecal barrel given various hardcoded quantities
Expand All @@ -608,7 +602,6 @@ def setupSWClusters(inputCells,
OutputLevel=INFO
)
TopAlg += [calibrateClustersAlg]
calibrateClustersAlg.AuditExecute = True

if runPhotonIDTool:
if not addShapeParameters:
Expand All @@ -630,7 +623,6 @@ def setupSWClusters(inputCells,
OutputLevel=INFO
)
TopAlg += [photonIDAlg]
photonIDAlg.AuditExecute = True


# Function that sets up the sequence for producing SW clusters given an input cell collection
Expand Down Expand Up @@ -710,7 +702,6 @@ def setupTopoClusters(inputCells,
clusterAlg.clusters.Path = outputClusters
clusterAlg.clusterCells.Path = outputClusters.replace("Clusters", "Cluster") + "Cells"
TopAlg += [clusterAlg]
clusterAlg.AuditExecute = True

if applyUpDownstreamCorrections:
# note that this only works for ecal barrel given various hardcoded quantities
Expand All @@ -731,7 +722,6 @@ def setupTopoClusters(inputCells,
OutputLevel=INFO
)
TopAlg += [correctClusterAlg]
correctClusterAlg.AuditExecute = True

if addShapeParameters:
# note that this only works for ecal barrel given various hardcoded quantities
Expand All @@ -749,7 +739,6 @@ def setupTopoClusters(inputCells,
do_widthTheta_logE_weights=logEWeightInPhotonID,
OutputLevel=INFO)
TopAlg += [augmentClusterAlg]
augmentClusterAlg.AuditExecute = True

if applyMVAClusterEnergyCalibration:
# note that this only works for ecal barrel given various hardcoded quantities
Expand All @@ -773,7 +762,6 @@ def setupTopoClusters(inputCells,
OutputLevel=INFO
)
TopAlg += [calibrateClustersAlg]
calibrateClustersAlg.AuditExecute = True

if runPhotonIDTool:
if not addShapeParameters:
Expand All @@ -794,7 +782,6 @@ def setupTopoClusters(inputCells,
mvaInputsFile="bdt-photonid-inputs-CaloTopoClusters.json",
OutputLevel=INFO)
TopAlg += [photonIDAlg]
photonIDAlg.AuditExecute = True


if doSWClustering:
Expand Down Expand Up @@ -915,72 +902,68 @@ def setupTopoClusters(inputCells,
False)


# Output
from Configurables import PodioOutput
outputWriter = PodioOutput("OutputWriter", OutputLevel=INFO)
TopAlg += [outputWriter]
outputWriter.AuditExecute = True
outputWriter.filename = "ALLEGRO_sim_digi_reco.root"

# drop the empty cells
outputWriter.outputCommands = ["keep *",
io_svc.outputCommands = ["keep *",
"drop emptyCaloCells"]

# drop the uncalibrated cells
if dropUncalibratedCells:
outputWriter.outputCommands.append("drop %s" % ecalBarrelReadoutName)
outputWriter.outputCommands.append("drop %s" % ecalBarrelReadoutName2)
outputWriter.outputCommands.append("drop %s" % ecalEndcapReadoutName)
io_svc.outputCommands.append("drop %s" % ecalBarrelReadoutName)
io_svc.outputCommands.append("drop %s" % ecalBarrelReadoutName2)
io_svc.outputCommands.append("drop %s" % ecalEndcapReadoutName)
if runHCal:
outputWriter.outputCommands.append("drop %s" % hcalBarrelReadoutName)
outputWriter.outputCommands.append("drop %s" % hcalEndcapReadoutName)
io_svc.outputCommands.append("drop %s" % hcalBarrelReadoutName)
io_svc.outputCommands.append("drop %s" % hcalEndcapReadoutName)
else:
outputWriter.outputCommands += ["drop HCal*"]
io_svc.outputCommands += ["drop HCal*"]

# drop the intermediate ecal barrel cells in case of a resegmentation
if resegmentECalBarrel:
outputWriter.outputCommands.append("drop ECalBarrelCellsMerged")
io_svc.outputCommands.append("drop ECalBarrelCellsMerged")
# drop the intermediate hcal barrel cells before resegmentation
if runHCal:
outputWriter.outputCommands.append("drop %s" % hcalBarrelPositionedCellsName)
outputWriter.outputCommands.append("drop %s" % hcalEndcapPositionedCellsName)
io_svc.outputCommands.append("drop %s" % hcalBarrelPositionedCellsName)
io_svc.outputCommands.append("drop %s" % hcalEndcapPositionedCellsName)

# drop lumi, vertex, DCH, Muons (unless want to keep for event display)
outputWriter.outputCommands.append("drop Lumi*")
# outputWriter.outputCommands.append("drop Vertex*")
# outputWriter.outputCommands.append("drop DriftChamber_simHits*")
outputWriter.outputCommands.append("drop MuonTagger*")
io_svc.outputCommands.append("drop Lumi*")
# io_svc.outputCommands.append("drop Vertex*")
# io_svc.outputCommands.append("drop DriftChamber_simHits*")
io_svc.outputCommands.append("drop MuonTagger*")

# drop hits/positioned cells/cluster cells if desired
if not saveHits:
outputWriter.outputCommands.append("drop *%sContributions" % ecalBarrelReadoutName)
outputWriter.outputCommands.append("drop *%sContributions" % ecalBarrelReadoutName2)
outputWriter.outputCommands.append("drop *%sContributions" % ecalEndcapReadoutName)
io_svc.outputCommands.append("drop *%sContributions" % ecalBarrelReadoutName)
io_svc.outputCommands.append("drop *%sContributions" % ecalBarrelReadoutName2)
io_svc.outputCommands.append("drop *%sContributions" % ecalEndcapReadoutName)
if not saveCells:
outputWriter.outputCommands.append("drop %s" % ecalBarrelPositionedCellsName)
outputWriter.outputCommands.append("drop %s" % ecalEndcapPositionedCellsName)
io_svc.outputCommands.append("drop %s" % ecalBarrelPositionedCellsName)
io_svc.outputCommands.append("drop %s" % ecalEndcapPositionedCellsName)
if resegmentECalBarrel:
outputWriter.outputCommands.append("drop %s" % ecalBarrelPositionedCellsName2)
io_svc.outputCommands.append("drop %s" % ecalBarrelPositionedCellsName2)
if runHCal:
outputWriter.outputCommands.append("drop %s" % hcalBarrelPositionedCellsName2)
outputWriter.outputCommands.append("drop %s" % hcalEndcapPositionedCellsName2)
io_svc.outputCommands.append("drop %s" % hcalBarrelPositionedCellsName2)
io_svc.outputCommands.append("drop %s" % hcalEndcapPositionedCellsName2)
if not saveClusterCells:
outputWriter.outputCommands.append("drop Calo*ClusterCells*")
io_svc.outputCommands.append("drop Calo*ClusterCells*")

# if we decorate the clusters, we can drop the non-decorated ones
# commented in tests, for debugging
# if addShapeParameters:
# outputWriter.outputCommands.append("drop %s" % augmentECalBarrelClusters.inClusters)
# io_svc.outputCommands.append("drop %s" % augmentECalBarrelClusters.inClusters)


# configure the application
print(TopAlg)
print(ExtSvc)
from Configurables import ApplicationMgr
ApplicationMgr(
from k4FWCore import ApplicationMgr
applicationMgr = ApplicationMgr(
TopAlg=TopAlg,
EvtSel='NONE',
EvtMax=Nevts,
ExtSvc=ExtSvc,
StopOnSignal=True,
)

for algo in applicationMgr.TopAlg:
algo.AuditExecute = True

0 comments on commit 129ab36

Please sign in to comment.