ATLAS Offline Software
Loading...
Searching...
No Matches
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#
5import logging
6from argparse import ArgumentParser
7from json import dumps
8from pathlib import Path
9from sys import exit
10
11from PyCool import cool
12
13logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
14
15parser = ArgumentParser("ItkPixelChargeCalibration.py")
16parser.add_argument("-i", "--identifiers", type=str, help="Identifiers dump", default="ITkPixelIdentifiers.dat")
17args = parser.parse_args()
18
19logging.info("Identifiers file: %s", args.identifiers)
20
21dbName = "OFLP200"
22dbFolder = "/ITk/PixelChargeCalib"
23dbTag = "PixelChargeCalib_LUTTest-00-01"
24dbFile = "ITkPixelChargeCalib-00-01.db"
25
26runSince = 0
27runUntil = 'inf'
28
29logging.info("Database name: %s", dbName)
30logging.info("Folder name: %s", dbFolder)
31logging.info("Folder tag: %s", dbTag)
32logging.info("Output file: %s", dbFile)
33logging.info("Run range: %s - %s", runSince, runUntil)
34
35dbFilePath = Path(dbFile)
36if dbFilePath.exists():
37 dbFilePath.unlink()
38
39# get database service and open database
40dbSvc = cool.DatabaseSvcFactory.databaseService()
41# database accessed via physical name
42dbString = f"sqlite://;schema={dbFile};dbname={dbName}"
43try:
44 db = dbSvc.createDatabase(dbString)
45except Exception as e:
46 logging.error("Problem creating database %s", e)
47 exit(1)
48logging.info("Created database %s", dbString)
49
50# setup folder
51spec = cool.RecordSpecification()
52# define main field
53spec.extend('data_array', cool.StorageType.String16M)
54# folder meta-data - note for Athena this has a special meaning
55desc = '<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
59folderSpec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
60folder = db.createFolder(dbFolder, folderSpec, desc, True)
61# now fill in some data - create a record and fill it
62data = cool.Record(spec)
63
64# define IoVs
65iovMin = runSince << 32 | 0
66iovMax = cool.ValidityKeyMax if runUntil == 'inf' else runUntil << 32 | 0
67
68logging.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
77calibL0andL1 = [
78 [1000, 75, 1000, 75, 2080, 2957, 4000, 5163, 6824, 8700, 11285, 14709, 19600, 27500, 40400, 69500, 166400, 3000000, 999999999., 999999999.],
79]
80
81calibL2toL4 = [
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
86output = {}
87
88with 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
99data["data_array"] = dumps(output, separators=(',', ':'))
100folder.storeObject(iovMin, iovMax, data, 0, dbTag)
101
102# close the database
103db.closeDatabase()