# readout name
ecalReadoutName = "ECalHitsPhiEta"
# active material identifier name
ecalIdentifierName = "active_layer"
# active material volume name
ecalVolumeName = "LAr_sensitive"
# ECAL bitfield names & values
ecalFieldNames = ["system", "ECAL_Cryo", "bath", "EM_barrel"]
ecalFieldValues = [5, 1, 1, 1]

#Configure tools for calo reconstruction
from Configurables import CalibrateCaloHitsTool, NoiseCaloCellsFlatTool, TubeLayerPhiEtaCaloTool

calibcells = CalibrateCaloHitsTool("CalibrateCaloHitsTool",
                                   invSamplingFraction="5.4")
noise = NoiseCaloCellsFlatTool("NoiseCaloCellsFlatTool", cellNoise=0.01)
ecalgeo = TubeLayerPhiEtaCaloTool("EcalGeo",
                                  readoutName=ecalReadoutName,
                                  activeVolumeName=ecalVolumeName,
                                  activeFieldName=ecalIdentifierName,
                                  fieldNames=ecalFieldNames,
                                  fieldValues=ecalFieldValues,
                                  OutputLevel=DEBUG)

from Configurables import CreateCaloCells

createcells = CreateCaloCells("CreateCaloCells",
                              geometryTool=ecalgeo,
                              doCellCalibration=True,
                              calibTool=calibcells,
                              addCellNoise=True,
# common HCAL specific information
# readout name
hcalReadoutName = "HCalBarrelReadout"
# active material identifier name
hcalIdentifierName = ["module", "row", "layer"]
# active material volume name
hcalVolumeName = ["moduleVolume", "wedgeVolume", "layerVolume"]
# ECAL bitfield names & values
hcalFieldNames = ["system"]
hcalFieldValues = [8]

#Configure tools for calo reconstruction
from Configurables import RewriteBitfield, CalibrateCaloHitsTool, NoiseCaloCellsFlatTool, LayerPhiEtaCaloTool
calibHcells = CalibrateCaloHitsTool("CalibrateHCal",
                                    invSamplingFraction="41.7 ")
noise = NoiseCaloCellsFlatTool("HCalNoise", cellNoise=0.01)

rewriteHCal = RewriteBitfield(
    "RewriteHCal",
    # old bitfield (readout)
    oldReadoutName="HCalBarrelReadout",
    # specify which fields are going to be deleted
    removeIds=["row"],
    # new bitfield (readout), with new segmentation
    newReadoutName="BarHCal_Readout_phieta",
    debugPrint=10,
    OutputLevel=INFO)
# clusters are needed, with deposit position and cellID in bits
rewriteHCal.inhits.Path = "HCalHits"
rewriteHCal.outhits.Path = "HCalBarrelCellsStep1"
                                         activeFieldName="layer",
                                         fieldNames=["system"],
                                         fieldValues=[5],
                                         activeVolumesNumber=8)
createEcalBarrelCells = CreateCaloCells(
    "CreateECalBarrelCells",
    geometryTool=barrelGeometry,
    doCellCalibration=False,  # already calibrated
    addCellNoise=True,
    filterCellNoise=False,
    noiseTool=noiseBarrel,
    hits=ecalBarrelCellsName,
    cells=ecalBarrelCellsName + "Noise",
    OutputLevel=DEBUG)

noiseHcal = NoiseCaloCellsFlatTool("HCalNoise", cellNoise=0.009)

barrelHcalGeometry = LayerPhiEtaCaloTool("HcalBarrelGeo",
                                         readoutName=hcalBarrelReadoutName,
                                         activeVolumeName="layerVolume",
                                         activeFieldName="layer",
                                         fieldNames=["system"],
                                         fieldValues=[8],
                                         activeVolumesNumber=10)
createHcalBarrelCells = CreateCaloCells(
    "CreateHCalBarrelCells",
    geometryTool=barrelHcalGeometry,
    doCellCalibration=False,  # already calibrated
    addCellNoise=True,
    filterCellNoise=False,
    noiseTool=noiseHcal,
                    OutputLevel = INFO)

# common HCAL specific information
# readout name
hcalReadoutName = "BarHCal_Readout"
# active material identifier name
hcalIdentifierName = ["layer", "wedge","row","sub_module"]
# active material volume name
hcalVolumeName = ["layer", "wedge","subWedge", "module_component"]
# ECAL bitfield names & values
hcalFieldNames=["system"]
hcalFieldValues=[8]

#Configure tools for calo reconstruction
from Configurables import CalibrateCaloHitsTool, NoiseCaloCellsFlatTool, NestedVolumesCaloTool
noise = NoiseCaloCellsFlatTool("HCalNoise")
hcalgeo = NestedVolumesCaloTool("HcalGeo",
                                 activeVolumeName = hcalVolumeName,
                                 activeFieldName = hcalIdentifierName,
                                 readoutName = hcalReadoutName,
                                 fieldNames = hcalFieldNames,
                                 fieldValues = hcalFieldValues,
                                 OutputLevel = DEBUG)

from Configurables import CreateCaloCells
createcells = CreateCaloCells("CreateCaloCells",
                              geometryTool = hcalgeo,
                              doCellCalibration = False,
                              addCellNoise = True, filterCellNoise = False,
                              noiseTool = noise,
                              OutputLevel = DEBUG)