diff --git a/Generators/GeneratorUtils/python/ShiftLOS.py b/Generators/GeneratorUtils/python/ShiftLOS.py index d7e8f21d0c8fbe67346a9e435239e9858515510b..f1010367869d449b29b80e1d10dde1f0f14758b9 100644 --- a/Generators/GeneratorUtils/python/ShiftLOS.py +++ b/Generators/GeneratorUtils/python/ShiftLOS.py @@ -11,19 +11,21 @@ except ImportError: from AthenaPython.PyAthena import HepMC as HepMC class ShiftLOS(PyAthena.Alg): - def __init__(self, name="ShiftLOS", InputMCEventKey="BeamTruthEvent", OutputMCEventKey="BeamTruthEventShifted", xcross = 0, ycross = 0): + def __init__(self, name="ShiftLOS", InputMCEventKey="BeamTruthEvent", OutputMCEventKey="BeamTruthEventShifted", xcross = 0, ycross = 0, xshift = 0, yshift = 0): super(ShiftLOS,self).__init__(name=name) self.InputMCEventKey = InputMCEventKey self.OutputMCEventKey = OutputMCEventKey self.xcross = xcross * 1e-6 self.ycross = ycross * 1e-6 - self.distance = 480*m # Assumes 480m is 0 of FASER coordinate system + self.xshift = xshift + self.yshift = yshift + self.distance = 480 * m # Assumes 480m is 0 of FASER coordinate system return def shift_vertices(self, evt): - # Don't need to shift if at IP - if not self.distance: + # Don't need to shift if at IP unless request explicit shift + if not self.distance and not self.xshift and not self.yshift: return evt # Loop over all vertices @@ -41,7 +43,14 @@ class ShiftLOS(PyAthena.Alg): self.msg.debug(f"Shifting x by {self.xcross} over {dz}: {pos.x()} -> {x} ") elif self.ycross: y += dz * self.ycross - self.msg.debug(f"Shifting y by {self.ycross} over {dz}: {pos.y()} -> {y} ") + self.msg.debug(f"Shifting y by {self.ycross} over {dz}: {pos.y()} -> {y} ") + + if self.xshift: + x += self.xshift + self.msg.debug(f"Shifting x by {self.xshift}: {pos.x()} -> {x} ") + elif self.yshift: + y += self.yshift + self.msg.debug(f"Shifting x by {self.yshift}: {pos.y()} -> {y} ") v.set_position(HepMC.FourVector(x, y, z, pos.t())) @@ -50,6 +59,9 @@ class ShiftLOS(PyAthena.Alg): def boost_particles(self, evt): + if self.xcross == self.ycross == 0: + return evt + pxsum, pysum = 0,0 pxsum_orig, pysum_orig = 0,0 @@ -79,9 +91,7 @@ class ShiftLOS(PyAthena.Alg): def execute(self): self.msg.debug(f"Exectuing {self.getName()}") - print (self.xcross, self.ycross) - - if not self.xcross and not self.ycross: + if not self.xcross and not self.ycross and not self.xshift and not self.yshift: return StatusCode.Success self.msg.debug(f"Reading {self.InputMCEventKey}") @@ -116,6 +126,8 @@ if __name__ == "__main__": parser.add_argument("--OutputMCEventKey", "-o", default = "BeamTruthEventShifted", help = "Name of Output MC collection") parser.add_argument("--xcross", "-x", default = 0, type = float, help = "Crossing angle of LHC beam in x [urad]") parser.add_argument("--ycross", "-y", default = 0, type = float, help = "Crossing angle of LHC beam in y [urad]") + parser.add_argument("--xshift", default = 0, type = float, help = "Shift of LHC beam in x [mm]") + parser.add_argument("--yshift", default = 0, type = float, help = "Shift of LHC beam in y [mm]") parser.add_argument("--nevents", "-n", default = -1, type = int, help = "Number of events to process") args = parser.parse_args() @@ -150,7 +162,8 @@ if __name__ == "__main__": from AthenaConfiguration.ComponentFactory import CompFactory acc = ComponentAccumulator() - alg = ShiftLOS("ShiftLOS", InputMCEventKey=args.InputMCEventKey, OutputMCEventKey=args.OutputMCEventKey, xcross = args.xcross, ycross = args.ycross) + alg = ShiftLOS("ShiftLOS", InputMCEventKey=args.InputMCEventKey, OutputMCEventKey=args.OutputMCEventKey, + xcross = args.xcross, ycross = args.ycross, xshift = args.xshift, yshift = args.yshift) alg.OutputLevel = INFO acc.addEventAlgo(alg) cfg.merge(acc) diff --git a/Generators/GeneratorUtils/python/ShiftLOSConfig.py b/Generators/GeneratorUtils/python/ShiftLOSConfig.py index 9683df1f8b3a2b4ee7f831533415315b2972cfda..5aece64bfec84c06279b6d1d22d66c0e1a012024 100644 --- a/Generators/GeneratorUtils/python/ShiftLOSConfig.py +++ b/Generators/GeneratorUtils/python/ShiftLOSConfig.py @@ -18,7 +18,9 @@ def ShiftLOSCfg(ConfigFlags, **kwargs) : shift.InputMCEventKey = kwargs.setdefault("InputMCEventKey", "BeamTruthEvent") shift.OutputMCEventKey = kwargs.setdefault("OutputMCEventKey", "BeamTruthEventShifted") shift.xcross = kwargs.setdefault("xcross", 0) - shift.ycross = kwargs.setdefault("ycross", 0) + shift.ycross = kwargs.setdefault("ycross", 0) + shift.xshift = kwargs.setdefault("xshift", 0) + shift.yshift = kwargs.setdefault("yshift", 0) cfg.addEventAlgo(shift, sequenceName = "AthBeginSeq", primary = True) # to run *before* G4 return cfg diff --git a/Simulation/G4Faser/G4FaserAlg/test/G4FaserAlgConfigNew_Test.py b/Simulation/G4Faser/G4FaserAlg/test/G4FaserAlgConfigNew_Test.py index 3b1aac71e96914107c58558ae96a11eb2c4f7340..865dbe3946dbc89e7cc6f2158264c9a3d72ccbc2 100644 --- a/Simulation/G4Faser/G4FaserAlg/test/G4FaserAlgConfigNew_Test.py +++ b/Simulation/G4Faser/G4FaserAlg/test/G4FaserAlgConfigNew_Test.py @@ -44,7 +44,9 @@ if __name__ == '__main__': ConfigFlags.Sim.IncludeParentsInG4Event = True # Controls whether BeamTruthEvent is written to output HITS file ConfigFlags.addFlag("Sim.Gun",{"Generator" : "SingleParticle"}) # Property bag for particle gun keyword:argument pairs ConfigFlags.addFlag("Sim.Beam.xangle", 0) # Potential beam crossing angles - ConfigFlags.addFlag("Sim.Beam.yangle", 0) + ConfigFlags.addFlag("Sim.Beam.yangle", 0) + ConfigFlags.addFlag("Sim.Beam.xshift", 0) # Potential beam shift + ConfigFlags.addFlag("Sim.Beam.yshift", 0) ConfigFlags.GeoModel.FaserVersion = "FASERNU-02" # Geometry set-up ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-02" # Conditions set-up @@ -131,12 +133,15 @@ if __name__ == '__main__': # Shift LOS # - if ConfigFlags.Sim.Beam.xangle or ConfigFlags.Sim.Beam.yangle: + if (ConfigFlags.Sim.Beam.xangle or ConfigFlags.Sim.Beam.yangle or + ConfigFlags.Sim.Beam.xshift or ConfigFlags.Sim.Beam.yshift): + MCEventKey = "BeamTruthEventShifted" import McParticleEvent.Pythonizations from GeneratorUtils.ShiftLOSConfig import ShiftLOSCfg cfg.merge(ShiftLOSCfg(ConfigFlags, OutputMCEventKey = MCEventKey, - xcross = ConfigFlags.Sim.Beam.xangle, ycross = ConfigFlags.Sim.Beam.yangle)) + xcross = ConfigFlags.Sim.Beam.xangle, ycross = ConfigFlags.Sim.Beam.yangle, + xshift = ConfigFlags.Sim.Beam.xshift, yshift = ConfigFlags.Sim.Beam.yshift)) else: MCEventKey = "BeamTruthEvent"