ATLAS Offline Software
ITkPixelChargeCalibration.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4 #
5 import logging
6 from argparse import ArgumentParser
7 from json import dumps
8 from pathlib import Path
9 from sys import exit
10 
11 from PyCool import cool
12 
13 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
14 
15 parser = ArgumentParser("ItkPixelChargeCalibration.py")
16 parser.add_argument("-i", "--identifiers", type=str, help="Identifiers dump", default="ITkPixelIdentifiers.dat")
17 args = parser.parse_args()
18 
19 logging.info("Identifiers file: %s", args.identifiers)
20 
21 dbName = "OFLP200"
22 dbFolder = "/ITk/PixelChargeCalib"
23 dbTag = "PixelChargeCalib_LUTTest-00-01"
24 dbFile = "ITkPixelChargeCalib-00-01.db"
25 
26 runSince = 0
27 runUntil = 'inf'
28 
29 logging.info("Database name: %s", dbName)
30 logging.info("Folder name: %s", dbFolder)
31 logging.info("Folder tag: %s", dbTag)
32 logging.info("Output file: %s", dbFile)
33 logging.info("Run range: %s - %s", runSince, runUntil)
34 
35 dbFilePath = Path(dbFile)
36 if dbFilePath.exists():
37  dbFilePath.unlink()
38 
39 # get database service and open database
40 dbSvc = cool.DatabaseSvcFactory.databaseService()
41 # database accessed via physical name
42 dbString = f"sqlite://;schema={dbFile};dbname={dbName}"
43 try:
44  db = dbSvc.createDatabase(dbString)
45 except Exception as e:
46  logging.error("Problem creating database %s", e)
47  exit(1)
48 logging.info("Created database %s", dbString)
49 
50 # setup folder
51 spec = cool.RecordSpecification()
52 # define main field
53 spec.extend('data_array', cool.StorageType.String16M)
54 # folder meta-data - note for Athena this has a special meaning
55 desc = '<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader><typeName>CondAttrListCollection</typeName>'
56 # create the folder - multiversion version
57 # last argument is createParents - if true, automatically creates parent folders if needed
58 # note this will not work if the database already exists - delete ITkPixelChargeCalib.db first
59 folderSpec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
60 folder = db.createFolder(dbFolder, folderSpec, desc, True)
61 # now fill in some data - create a record and fill it
62 data = cool.Record(spec)
63 
64 # define IoVs
65 iovMin = runSince << 32 | 0
66 iovMax = cool.ValidityKeyMax if runUntil == 'inf' else runUntil << 32 | 0
67 
68 logging.info("IoV range: %s - %s", iovMin, iovMax)
69 
70 
71 # New Format based on the feedback current and threshold settings of the ITkPixV2 chip
72 # L0 and L1 layers: fast feed back cureent,1000e threshold
73 # L2 to L14layers: slow feed back cureent,1500e threshold
74 # analog threshold value,noise for normal,long/ganged pixels
75 # Q0-Q16 charge calibration constants for normal and long/ganged pixels
76 
77 calibL0andL1 = [
78  [1000, 75, 1000, 75, 2080, 2957, 4000, 5163, 6824, 8700, 11285, 14709, 19600, 27500, 40400, 69500, 166400, 3000000, 999999999., 999999999.],
79 ]
80 
81 calibL2toL4 = [
82  [1500, 75, 1500, 75, 2080, 2957, 4000, 5163, 6824, 8700, 11285, 14709, 19600, 27500, 40400, 69500, 166400, 3000000, 999999999., 999999999.],
83 ]
84 
85 # read pixel identifiers
86 output = {}
87 
88 with open(args.identifiers, "r") as identifiers:
89  for line in identifiers:
90  if line[0] == "#":
91  continue
92  ids = line.split()
93 
94  if ids[-1] == "4" or (ids[2] == "0" and ids[3] == "0"):
95  output[ids[0]] = calibL0andL1
96  else:
97  output[ids[0]] = calibL2toL4
98 
99 data["data_array"] = dumps(output, separators=(',', ':'))
100 folder.storeObject(iovMin, iovMax, data, 0, dbTag)
101 
102 # close the database
103 db.closeDatabase()
calibdata.exit
exit
Definition: calibdata.py:236
Trk::open
@ open
Definition: BinningType.h:40