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