Skip to content

Commit c282b7b

Browse files
Anushka DurgAnushka Durg
authored andcommitted
added Ntuple file as input for runsim_SND
1 parent ca94962 commit c282b7b

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

‎shipLHC/run_simSND.py‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
parser.add_argument("--NagoyaEmu","--useNagoyaEmulsions",dest="useNagoyaEmulsions",help="use bricks of 57 Nagoya emulsion films instead of 60 Slavich", required=False,action="store_true")
6161
parser.add_argument("-y", dest="year", help="specify the year to generate the respective TI18 detector setup", required=False, type=int, default=2024)
6262

63+
parser.add_argument("--dataProfile", dest="dataProfile", help="Path to the ROOT file with Ntuple data", required=False)
64+
#parser.add_argument("--matrixFile", dest="matrixFile", help="Path to the file with matrix particle counts", required=True, type=str)
6365
options = parser.parse_args()
6466

6567
# user hook
@@ -166,6 +168,7 @@ def Exec(self,opt):
166168
primGen = ROOT.FairPrimaryGenerator()
167169

168170
# -----Particle Gun-----------------------
171+
169172
if simEngine == "PG":
170173
myPgun = ROOT.FairBoxGenerator(options.pID,1)
171174
myPgun.SetPRange(options.Estart,options.Eend)
@@ -191,7 +194,52 @@ def Exec(self,opt):
191194
f'({options.EVx},{options.EVy},{options.EVz})[cm × cm × cm] \n'
192195
f'with a uniform x-y spread of (Dx,Dy)=({options.Dx},{options.Dy})[cm × cm]'
193196
f' and {options.nZSlices} z slices in steps of {options.zSliceStep}[cm].')
197+
194198
ROOT.FairLogger.GetLogger().SetLogScreenLevel("WARNING") # otherwise stupid printout for each event
199+
#________NTUPLE--------
200+
# Use the Ntuple file if provided
201+
timerNtuple = ROOT.TStopwatch()
202+
203+
# Start timing
204+
timerNtuple.Start()
205+
if options.dataProfile:
206+
print(f"Using Ntuple file: {options.dataProfile}")
207+
# Open the ROOT file containing the Ntuple with extrapolated muon tracks
208+
file = ROOT.TFile(options.dataProfile)
209+
ntuple = file.Get("muon_tracks")
210+
primGen = ROOT.FairPrimaryGenerator()
211+
z_plane = 250.0
212+
for i in range(ntuple.GetEntries()):
213+
ntuple.GetEntry(i)
214+
215+
# Extract x, y positions and slopes from the Ntuple
216+
x = ntuple.x
217+
y = ntuple.y
218+
z = 0
219+
220+
slope_xz = ntuple.slopes_xz
221+
slope_yz = ntuple.slopes_yz
222+
x0 = x - slope_xz * z_plane
223+
y0 = y - slope_yz * z_plane
224+
z0 = 0
225+
pgun = ROOT.FairBoxGenerator(13, 1) # Particle ID 13 for muons
226+
pgun.SetPRange(1, 10) # Set the momentum range, e.g., 1-10 GeV
227+
pgun.SetXYZ(x0 * u.cm, y0 * u.cm, z0 * u.cm)
228+
primGen.AddGenerator(pgun)
229+
# print(f"Configured 1 particle at position ({x}, {y}, {z}) with slopes {slope_xz}, {slope_yz}")
230+
231+
else:
232+
print("Please provide a Data Profile")
233+
exit(1)
234+
timerNtuple.Stop()
235+
236+
# Log the time taken for Ntuple processing
237+
print(f"Time to process Ntuple: {timerNtuple.RealTime()} seconds (Real Time)")
238+
print(f"CPU Time: {timerNtuple.CpuTime()} seconds")
239+
240+
# Set the primary generator for the run
241+
run.SetGenerator(primGen)
242+
195243
# -----muon DIS Background------------------------
196244
if simEngine == "muonDIS":
197245
ut.checkFileExists(inputFile)

0 commit comments

Comments
 (0)