Belle II Software  release-08-01-10
checkDB-photonYields.py
1 #!/usr/bin/env python
2 
3 
10 
11 import basf2 as b2
12 import sys
13 from ROOT import Belle2, TFile
14 import time
15 
16 # -------------------------------------------------------------------------------------
17 # Extract histograms from the payload TOPCalPhotonYields and save them into a root file
18 #
19 # Usage: basf2 checkDB-photonYields.py expNo runNo [globalTag/localDB]
20 # (default globalTag = data_reprocessing_prompt)
21 # -------------------------------------------------------------------------------------
22 
23 if len(sys.argv) < 3:
24  print("usage: basf2", sys.argv[0], "expNo runNo [globalTag/localDB]")
25  sys.exit()
26 
27 expNo = int(sys.argv[1])
28 runNo = int(sys.argv[2])
29 globalTag = "data_reprocessing_prompt"
30 if len(sys.argv) > 3:
31  globalTag = sys.argv[3]
32 
33 
34 class SaveHisto(b2.Module):
35  ''' Saving histograms from the payload to a root file'''
36 
37  def initialize(self):
38  ''' initialize: saving histograms implemented here '''
39 
40  db = Belle2.PyDBObj("TOPCalPhotonYields")
41  if not db:
42  return
43 
44  fileName = "photonYields-" + time.strftime("%Y-%m-%d", time.localtime(db.getTimeStamp())) + ".root"
45  f = TFile.Open(fileName, "recreate")
46 
47  print("- global tag:", globalTag)
48  print("- time of measurement:",
49  time.strftime("%d %b %Y %H:%M:%S", time.localtime(db.getTimeStamp())), "(mean), ",
50  round(db.getTimeStampStd() / 3600 / 24, 2), "days (rms)")
51  for slot in range(1, 17):
52  h = db.getPhotonYields(slot)
53  if h:
54  h.Write()
55  h = db.getBackgroundYields(slot)
56  if h:
57  h.Write()
58  h = db.getAlphaRatio(slot)
59  if h:
60  h.Write()
61  h = db.getActivePixels(slot)
62  if h:
63  h.Write()
64  h = db.getPulseHeights(slot)
65  if h:
66  h.Write()
67  h = db.getMuonZ(slot)
68  if h:
69  h.Write()
70  f.Close()
71  print("--> histograms saved to:", fileName)
72 
73 
74 b2.set_log_level(b2.LogLevel.ERROR)
75 
76 if '.txt' in globalTag:
77  b2.conditions.append_testing_payloads(globalTag)
78 else:
79  b2.conditions.append_globaltag(globalTag)
80 
81 main = b2.create_path()
82 main.add_module('EventInfoSetter', evtNumList=[1], runList=[runNo], expList=[expNo])
83 main.add_module(SaveHisto())
84 b2.process(main)
Class to access a DBObjPtr from Python.
Definition: PyDBObj.h:50