Skip to content

Commit 0675f23

Browse files
committed
Improvements in MC anchoring
* Collision system is determined from GRPLHCIF * Collision energy is determined from GRPLHCIF * interaction rate calculation is done differentially as a function of collision system TODO: verify calculation and coefficients for interaction rate calculation
1 parent 4ca32ef commit 0675f23

1 file changed

Lines changed: 55 additions & 19 deletions

File tree

MC/bin/o2dpg_sim_workflow_anchored.py

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,14 @@ def retrieve_GRP(ccdbreader, timestamp):
206206
ts, grp = ccdbreader.fetch(grp_path, "o2::parameters::GRPObject", timestamp = timestamp)
207207
return grp
208208

209-
def retrieve_MinBias_CTPScaler_Rate(ccdbreader, timestamp, run_number, finaltime, ft0_eff):
209+
def retrieve_GRPLHCIF(ccdbreader, timestamp):
210+
"""
211+
retrieves the GRPLHCIF object for a given time stamp
212+
"""
213+
_, grplhcif = ccdbreader.fetch("GLO/Config/GRPLHCIF", "o2::parameters::GRPLHCIFData", timestamp = timestamp)
214+
return grplhcif
215+
216+
def retrieve_MinBias_CTPScaler_Rate(ccdbreader, timestamp, run_number, finaltime, ft0_eff, NBunches, ColSystem):
210217
"""
211218
retrieves the CTP scalers object for a given timestamp and run_number
212219
and calculates the interation rate to be applied in Monte Carlo digitizers
@@ -215,16 +222,26 @@ def retrieve_MinBias_CTPScaler_Rate(ccdbreader, timestamp, run_number, finaltime
215222
ts, ctpscaler = ccdbreader.fetch(path, "o2::ctp::CTPRunScalers", timestamp = timestamp)
216223
if ctpscaler != None:
217224
ctpscaler.convertRawToO2()
218-
rate = ctpscaler.getRateGivenT(finaltime,0,0) # the simple FT0 rate from the counters
219-
# print("Global rate " + str(rate.first) + " local rate " + str(rate.second))
220-
221-
# now get the bunch filling object which is part of GRPLHCIF and calculate
222-
# true rate (input from Chiara Zampolli)
223-
ts, grplhcif = ccdbreader.fetch("GLO/Config/GRPLHCIF", "o2::parameters::GRPLHCIFData", timestamp = timestamp)
224-
coll_bunches = grplhcif.getBunchFilling().getNBunches()
225-
mu = - math.log(1. - rate.first / 11245 / coll_bunches) / ft0_eff
226-
finalRate = coll_bunches * mu * 11245
227-
return finalRate
225+
# this is the default for pp
226+
ctpclass = 0 # <---- we take the scaler for FT0
227+
ctptype = 0
228+
# this is the default for PbPb
229+
if ColSystem == "PbPb":
230+
ctpclass = 25 # <--- we take scalers for ZDC
231+
ctptype = 7
232+
print("Fetching rate with class " + str(ctpclass) + " type " + str(ctptype))
233+
rate = ctpscaler.getRateGivenT(finaltime, ctpclass, ctptype)
234+
#if ColSystem == "PbPb":
235+
# rate.first = rate.first / 28.
236+
# rate.second = rate.second / 28.
237+
238+
print("Global rate " + str(rate.first) + " local rate " + str(rate.second))
239+
if rate.first >= 0:
240+
# calculate true rate (input from Chiara Zampolli) using number of bunches
241+
coll_bunches = NBunches
242+
mu = - math.log(1. - rate.second / 11245 / coll_bunches) / ft0_eff
243+
finalRate = coll_bunches * mu * 11245
244+
return finalRate
228245

229246
print (f"[ERROR]: Could not determine interaction rate; Some (external) default used")
230247
return None
@@ -277,8 +294,6 @@ def main():
277294
parser.add_argument("--ccdb-IRate", type=bool, help="whether to try fetching IRate from CCDB/CTP", default=True)
278295
parser.add_argument("--ft0-eff", type=float, dest="ft0_eff", help="FT0 eff needed for IR", default=-1.0)
279296
parser.add_argument('forward', nargs=argparse.REMAINDER) # forward args passed to actual workflow creation
280-
parser.add_argument("-eCM", type=float, dest="eCM", help="Energy", default=13600)
281-
parser.add_argument("-col", type=str, dest="col", help="Collision System", default="pp")
282297
args = parser.parse_args()
283298

284299
# split id should not be larger than production id
@@ -306,26 +321,47 @@ def main():
306321
currenttime = GLOparams["SOR"] + prod_offset * GLOparams["OrbitsPerTF"] * LHCOrbitMUS // 1000 # timestamp in milliseconds
307322
print ("Production put at time : " + str(currenttime))
308323

324+
# retrieve the GRPHCIF object
325+
grplhcif = retrieve_GRPLHCIF(ccdbreader, int(currenttime))
326+
eCM = grplhcif.getSqrtS()
327+
A1 = grplhcif.getAtomicNumberB1()
328+
A2 = grplhcif.getAtomicNumberB2()
329+
330+
# determine collision system and energy
331+
print ("Determined eMC ", eCM)
332+
print ("Determined atomic number A1 ", A1)
333+
print ("Determined atomic number A2 ", A2)
334+
ColSystem = ""
335+
if A1 == 82 and A2 == 82:
336+
ColSystem = "PbPb"
337+
elif A1 == 1 and A2 == 1:
338+
ColSystem = "pp"
339+
else:
340+
print ("Unknown collision system ... exiting")
341+
exit (1)
342+
343+
print ("Collision system ", ColSystem)
344+
309345
forwardargs = " ".join([ a for a in args.forward if a != '--' ])
310346
# retrieve interaction rate
311347
rate = None
312348

313349
if args.ccdb_IRate == True:
314350
effT0 = args.ft0_eff
315351
if effT0 < 0:
316-
if args.col == "pp":
317-
if args.eCM < 1000:
352+
if ColSystem == "pp":
353+
if eCM < 1000:
318354
effT0 = 0.68
319-
elif args.eCM < 6000:
355+
elif eCM < 6000:
320356
effT0 = 0.737
321357
else:
322358
effT0 = 0.759
323-
elif args.col == "PbPb":
359+
elif ColSystem == "PbPb":
324360
effT0 = 4.0
325361
else:
326362
effT0 = 0.759
327363

328-
rate = retrieve_MinBias_CTPScaler_Rate(ccdbreader, timestamp, args.run_number, currenttime/1000., effT0)
364+
rate = retrieve_MinBias_CTPScaler_Rate(ccdbreader, timestamp, args.run_number, currenttime/1000., effT0, grplhcif.getBunchFilling().getNBunches(), ColSystem)
329365

330366
if rate != None:
331367
# if the rate calculation was successful we will use it, otherwise we fall back to some rate given as part
@@ -338,7 +374,7 @@ def main():
338374

339375
# we finally pass forward to the unanchored MC workflow creation
340376
# TODO: this needs to be done in a pythonic way clearly
341-
forwardargs += " -tf " + str(args.tf) + " --sor " + str(GLOparams["SOR"]) + " --timestamp " + str(timestamp) + " --production-offset " + str(prod_offset) + " -run " + str(args.run_number) + " --run-anchored --first-orbit " + str(GLOparams["FirstOrbit"]) + " -field ccdb -bcPatternFile ccdb" + " --orbitsPerTF " + str(GLOparams["OrbitsPerTF"]) + " -col " + str(args.col) + " -eCM " + str(args.eCM)
377+
forwardargs += " -tf " + str(args.tf) + " --sor " + str(GLOparams["SOR"]) + " --timestamp " + str(timestamp) + " --production-offset " + str(prod_offset) + " -run " + str(args.run_number) + " --run-anchored --first-orbit " + str(GLOparams["FirstOrbit"]) + " -field ccdb -bcPatternFile ccdb" + " --orbitsPerTF " + str(GLOparams["OrbitsPerTF"]) + " -col " + str(ColSystem) + " -eCM " + str(eCM)
342378
print ("forward args ", forwardargs)
343379
cmd = "${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow.py " + forwardargs
344380
print ("Creating time-anchored workflow...")

0 commit comments

Comments
 (0)