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