Belle II Software  release-05-01-25
BeamSpotCalibrationCAF.py
1 #!/usr/bin/env python3
2 
3 
6 
7 import basf2
8 
9 import os
10 import sys
11 import multiprocessing
12 
13 import ROOT
14 from ROOT import Belle2
15 from ROOT.Belle2 import BeamSpotAlgorithm
16 
17 from caf.framework import Calibration, CAF, Collection, LocalDatabase, CentralDatabase
18 from caf import backends
19 from caf import strategies
20 
21 import modularAnalysis as ana
22 
23 basf2.set_log_level(basf2.LogLevel.INFO)
24 
25 
26 def BeamSpotCalibration(files, tags):
27  """
28  Function to get the BeamSpot calibration object.
29  Takes list of files and list of GTs as arguments.
30  """
31 
32  path = basf2.create_path()
33  path.add_module('Progress')
34  path.add_module('RootInput')
35 
36  # Select mumu decays with enough hits
37  muSelection = '[p>1.0]'
38  muSelection += ' and abs(dz)<2.0 and abs(dr)<0.5'
39  muSelection += ' and nPXDHits >=1 and nSVDHits >= 8 and nCDCHits >= 20'
40  ana.fillParticleList('mu+:BS', muSelection, path=path)
41  ana.reconstructDecay('Upsilon(4S):BS -> mu+:BS mu-:BS', '9.5<M<11.5', path=path)
42 
43  # Init the BeamSpot collector and algo
44  collector = basf2.register_module('BeamSpotCollector', Y4SPListName='Upsilon(4S):BS')
45  algorithm = BeamSpotAlgorithm()
46 
47  calibration = Calibration('BeamSpot',
48  collector=collector,
49  algorithms=algorithm,
50  input_files=files,
51  pre_collector_path=path,
52  database_chain=[CentralDatabase(tag) for tag in tags],
53  output_patterns=None,
54  max_files_per_collector_job=1,
55  backend_args=None
56  )
57 
58  # The segmentation is done in the algorithm
59  calibration.strategies = strategies.SingleIOV
60 
61  return calibration
62 
63 
64 if __name__ == "__main__":
65  input_files = [os.path.abspath(file) for file in Belle2.Environment.Instance().getInputFilesOverride()]
66 
67  if not len(input_files):
68  print("You have to specify some input file(s) (raw data or di - muon skim with raw objects)\n"
69  "using the standard basf2 command line option - i")
70  print("See: basf2 -h")
71  sys.exit(1)
72 
73  beamspot = BeamSpotCalibration(input_files, ['data_reprocessing_prompt', 'online_bucket9'])
74 
75  cal_fw = CAF()
76  cal_fw.add_calibration(beamspot)
77  cal_fw.backend = backends.LSF()
78 
79  # Try to guess if we are at KEKCC and change the backend to Local if not
80  if multiprocessing.cpu_count() < 10:
81  cal_fw.backend = backends.Local(8)
82 
83  cal_fw.run()
strategies.SingleIOV
Definition: strategies.py:172
backends.LSF
Definition: backends.py:1567
Belle2::Environment::Instance
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:31
Calibration
Definition: Calibration.py:1
backends.Local
Definition: backends.py:878