Belle II Software  release-05-01-25
overlay_utils.py
1 # !/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
7 
8 
23 
24 from basf2 import *
25 from ROOT import Belle2
26 import basf2
27 
28 
29 def prepare_svd_overlay(path, inputFiles, outputFileTag="overlay"):
30  """
31  This function reads a list of input files and prepare them to be used in overlay_svd_data
32  @param inputFiles: list of input files to be processed
33  @param outputFileTag: tag added just before the .root
34  """
35 
36  for inputfile in inputFiles:
37 
38  basf2.conditions.reset()
39  basf2.conditions.override_globaltags()
40  basf2.conditions.globaltags = ['svd_basic', "online"]
41  splittext = ""
42  if(str(outputFileTag) == "ZS3"):
43  splittext = inputfile.split(".root")
44  else:
45  splittext = inputfile.split("_ZS3.root")
46  outputfile = splittext[0]+"_"+str(outputFileTag)+".root"
47  main = create_path()
48  main.add_module("RootInput", inputFileNames=inputfile)
49  if(str(outputFileTag) == "ZS3"):
50  main.add_module("SVDUnpacker", svdShaperDigitListName="SVDShaperDigitsZS3")
51 
52  zs = 3
53  if (str(outputFileTag) == "overlayZS5"):
54  zs = 5
55 
56  if not (str(outputFileTag) == "ZS3"):
57  main.add_module("SVDZeroSuppressionEmulator",
58  SNthreshold=zs,
59  ShaperDigits='SVDShaperDigitsZS3',
60  ShaperDigitsIN='SVDShaperDigits',
61  FADCmode=True)
62  main.add_module("RootOutput", branchNames=["SVDEventInfo", "SVDShaperDigitsZS3"], outputFileName=outputfile)
63  else:
64  main.add_module("RootOutput", branchNames=["SVDShaperDigits"], outputFileName=outputfile)
65  print_path(main)
66  process(main)
67 
68 
69 def overlay_svd_data(path, datatype="randomTrigger", overlayfiles=""):
70  """
71  This function overlay events from data to the standard simulation
72  @param datatype: must be chosen among {xTalk, cosmics,randomTrigger, randomTriggerZS5, user-defined}
73  @param overlayfiles: if the datatype is user-defiled, the user can specify rootfiles to be overlaied to simulation
74  """
75 
76  if not (str(datatype) == "xTalk" or str(datatype) == "cosmics" or str(datatype) ==
77  "randomTrigger" or str(datatype) == "randomTriggerZS5" or str(datatype) == "user-defined"):
78  print("ERROR in SVDOverlay: the specified datatype ("+str(datatype) +
79  ") is not recognized, choose among: xTalk, cosmics or user-defined")
80  return
81 
82  overlayDir = "/gpfs/fs02/belle2/group/detector/SVD/overlayFiles/"
83 
84  if str(datatype) == "xTalk" or str(datatype) == "cosmics" or str(datatype) == "randomTrigger":
85  overlayfiles = str(overlayDir)+str(datatype)+"/*_overlay.root"
86 
87  if str(datatype) == "randomTriggerZS5":
88  overlayfiles = str(overlayDir)+"randomTrigger/*_overlayZS5.root"
89 
90  print(" ** SVD OVERLAY UTIL CALLED **")
91  print(" -> overlaying the following files to simulation: ")
92  print(str(overlayfiles))
93 
94  bkginput = register_module('BGOverlayInput')
95  bkginput.set_name('BGOverlayInput_SVDOverlay')
96  bkginput.param('bkgInfoName', 'BackgroundInfoSVDOverlay')
97  bkginput.param('extensionName', "_SVDOverlay")
98  bkginput.param('inputFileNames', overlayfiles)
99  path.add_module(bkginput)
100 
101  bkgexecutor = register_module('BGOverlayExecutor')
102  bkgexecutor.set_name('BGOverlayExecutor_SVDOverlay')
103  bkgexecutor.param('bkgInfoName', 'BackgroundInfoSVDOverlay')
104  path.add_module(bkgexecutor)
105 
106  path.add_module("SVDShaperDigitSorter")