10from ROOT
import Belle2
18 Class representing a linear constraint for global parameters
28 The constant term of the constraint: sum(c_i * par_i) = value
37 def add(self, label, coeff):
39 Add coefficient for a
global parameter
44 global parameter id (GlobalLabel::label())
46 coefficient of the parameter
in constraint
48 entry = (label, coeff)
49 self.data.append(entry)
52 """Get a checksum to distinguish constraints quickly (computed only from labels)
54 labels_only = [label for (label, coeff)
in self.
data]
55 checksum = hash(str(labels_only))
61 Base class representing a
"generator" for file with set of constraints
63 Can be used directly
if you already have a file
with constraints.
69 Desired filename for the constraint file
76 Should be overriden by the deriving classes and actually
77 fill the dictionary
with the constraints (this runs withing a basf2 module
78 event function - so you have geometry available)
85 Can be overriden be child classes to pass additional configuration to the
86 MillepedeCollector (activated by the use of the constraints)
91def generate_constraints(constraint_sets, timedep, global_tags, init_event):
93 Run the constraints generation and return file names
97 constraint_sets : list (alignment.Constraints)
98 List of sets of constraints
99 timedep_config : list(tuple(list(int), list(tuple(int, int, int))))
100 Time-dependence configuration.
101 Each list item
is 2-tuple
with list of parameter numbers (use
alignment.parameters to get them)
and
102 the (event, run, exp) numbers at which values of these parameters can change.
103 global_tags : list (str)
104 List of
global tag names
and/
or (absolute) file paths to local databases
105 init_event : tuple( int, int, int)
106 Event (event, run, exp) at which to initialize time-INdependent constraints
109 for filename
in [consts.filename
for consts
in constraint_sets]:
110 files.append(os.path.abspath(filename))
113 ccfn = save_config(constraint_sets, timedep, global_tags, init_event)
123 Constraints for VXD hierarchy
125 They come
in 3 types:
127 0 : no hierarchy, just sensors aligned
in their local system
128 1 : sensors -> half-shells (no ladders)
129 2 : sensors -> ladders ->half-shells (aka full hierarchy)
131 and additionally can use them
for PXD, SVD
or both (default) (setting pxd/svd to
False
132 will disable the hierarchy
for that sub-detector)
134 NOTE: the filename cannot be currently changed, it
is hard-coded
in the collector module
135 as these constraints are actually generated by C++ code
and not by python modules
as others.
141 Type of constraints (0 - no, 1 - half-shells, 2 -full)
143 Use constraints for PXD?
145 Use constraints
for SVD?
159 Propagate the hierarchy configuration to the collector
161 collector.param('hierarchyType', self.
type)
162 collector.param(
'enablePXDHierarchy', self.
pxd)
163 collector.param(
'enableSVDHierarchy', self.
svd)
167 Generate the constraints - does nothing. The collector will make the job
169 print("Generating constraints for VXD (no-op, file created by collector) ...")
175 Various constraints for CDC layers
177 (Code
from Claus Kleinwort)
181 cdc = [['A1', 8, 160, 16.80, 23.80, 0., -35.9, 67.9],
182 [
'U2', 6, 160, 25.70, 34.80, 0.068, -51.4, 98.6],
183 [
'A3', 6, 192, 36.52, 45.57, 0., -57.5, 132.9],
184 [
'V4', 6, 224, 47.69, 56.69, -0.060, -59.6, 144.7],
185 [
'A5', 6, 256, 58.41, 67.41, 0., -61.8, 146.8],
186 [
'U6', 6, 288, 69.53, 78.53, 0.064, -63.9, 148.9],
187 [
'A7', 6, 320, 80.25, 89.25, 0., -66.0, 151.0],
188 [
'V8', 6, 352, 91.37, 100.37, -0.072, -68.2, 153.2],
189 [
'A9', 6, 384, 102.00, 111.14, 0., -70.2, 155.3]]
192 parameter = [(1,
'x-offset bwd'), (2,
'y-offset bwd'), (6,
'z-rotation bwd'),
193 (11,
'x-offset fwd-bwd'), (12,
'y-offset fwd-bwd'), (16,
'z-rotation fwd-bwd')]
195 def __init__(self, filename='cdc-constraints.txt', rigid=True, twist=True, z_offset=False, r_scale=False, z_scale=False):
198 Filename with constraints (probably generated later)
200 5D CDC constraints: x+y+rot + dx+dy
202 CDC twist constraint: drot
204 Constraint
for Z-offset
206 Constraint
for R-scale
208 Constraint
for Z-scale
223 """Generate constraints from CDC geometry
225 print("Generating constraints for CDC layers...")
227 def cdc_layer_label(layer, param):
235 return (a > b) - (a < b)
243 for lyr
in range(nlyr):
257 for lyr
in range(nlyr):
258 label = cdc_layer_label(nTot + lyr, par[0])
259 const.add(label, 1.0)
274 for lyr
in range(nlyr):
275 label = cdc_layer_label(nTot + lyr, par[0])
276 const.add(label, 1.0)
294 dr = (rOuter - rInner) / (nlyr - 1)
296 for lyr
in range(nlyr):
297 label = cdc_layer_label(nTot + lyr, par[0])
298 const.add(label, stereo * rWire)
313 for lyr
in range(nlyr):
314 label = cdc_layer_label(nTot + lyr, par[0])
315 der = cmp(2. * float(nTot + lyr) + 0.5, float(nLayer))
316 const.add(label, der)
330 for lyr
in range(nlyr):
331 label = cdc_layer_label(nTot + lyr, par[0])
332 const.add(label, stereo)
343 Constraint to fix sum of corrections to CDC T0's (per wire) to zero
348 160, 160, 160, 160, 160, 160, 160, 160,
349 160, 160, 160, 160, 160, 160,
350 192, 192, 192, 192, 192, 192,
351 224, 224, 224, 224, 224, 224,
352 256, 256, 256, 256, 256, 256,
353 288, 288, 288, 288, 288, 288,
354 320, 320, 320, 320, 320, 320,
355 352, 352, 352, 352, 352, 352,
356 384, 384, 384, 384, 384, 384]
358 def __init__(self, filename='cdc-T0-constraints.txt'):
361 Can use different filename
368 Generate the constraints
370 print("Generating constraints for CDC T0's ...")
374 for layer
in range(0, 56):
378 const.add(label.label(), 1.0)
386 Various constraints for CDC wires (w.r.t. layers)
391 160, 160, 160, 160, 160, 160, 160, 160,
392 160, 160, 160, 160, 160, 160,
393 192, 192, 192, 192, 192, 192,
394 224, 224, 224, 224, 224, 224,
395 256, 256, 256, 256, 256, 256,
396 288, 288, 288, 288, 288, 288,
397 320, 320, 320, 320, 320, 320,
398 352, 352, 352, 352, 352, 352,
399 384, 384, 384, 384, 384, 384]
403 filename='cdc-wire-constraints.txt',
409 """Initialize constraint
414 Can override the default file name
416 List of layer numbers for which to generate the constraints (default
is 0..55)
418 6 constraints - fix sum of shifts of wire ends
in x/y/rotation at fwd/bwd end-plate
419 layer_radius : list(int)
420 2 constraints to fix average change of layer radius (wires
in layer moving away
from origin)
for all layers
in list
422 1 constraint - fix average change
in CDC radius
from all wires
423 hemisphere : list(int)
424 Modifies rigid
and layer_radius (layer_radius constraint
is added
if not present
for selected layer(s))
425 constraint by splitting the constraints
for a given list of layers to L/R up/down half of CDC
432 layers = list(range(0, 56))
441 if layer_radius
is None:
448 if hemisphere
is None:
453 """Enables wire-by-wire derivatives in collector
455 basf2.B2WARNING("Adding CDC wire constraints -> enabling wire-by-wire alignment derivatives")
456 collector.param(
'enableWireByWireAlignment',
True)
459 """Return GlobalLabel for wire parameter"""
467 """Generate constraints """
468 print(
"Generating constraints for CDC wires...")
478 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdX), 1.)
485 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdY), 1.)
488 for layer
in set(layers) - set(self.
hemisphere):
495 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdX), -math.sin(wirePhi))
496 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.cos(wirePhi))
503 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdX), 1.)
510 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdY), 1.)
513 for layer
in set(layers) - set(self.
hemisphere):
520 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdX), -math.sin(wirePhi))
521 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.cos(wirePhi))
531 if math.cos(wirePhi) <= 0.:
534 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdX), -math.sin(wirePhi))
535 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.cos(wirePhi))
545 if math.cos(wirePhi) > 0.:
548 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdX), -math.sin(wirePhi))
549 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.cos(wirePhi))
559 if math.cos(wirePhi) <= 0.:
562 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdX), -math.sin(wirePhi))
563 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.cos(wirePhi))
573 if math.cos(wirePhi) > 0.:
576 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdX), -math.sin(wirePhi))
577 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.cos(wirePhi))
588 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdX), +math.cos(wirePhi))
589 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.sin(wirePhi))
590 const.add(self.
get_label(layer, 0, 0), 0.)
600 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdX), +math.cos(wirePhi))
601 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.sin(wirePhi))
602 const.add(self.
get_label(layer, 0, 0), 0.)
613 if math.sin(wirePhi) >= 0:
616 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdX), +math.cos(wirePhi))
617 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.sin(wirePhi))
618 const.add(self.
get_label(layer, 0, 0), 0.)
628 if math.sin(wirePhi) < 0:
631 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdX), +math.cos(wirePhi))
632 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.sin(wirePhi))
633 const.add(self.
get_label(layer, 0, 0), 0.)
643 if math.sin(wirePhi) >= 0:
646 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdX), +math.cos(wirePhi))
647 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.sin(wirePhi))
648 const.add(self.
get_label(layer, 0, 0), 0.)
658 if math.sin(wirePhi) < 0:
661 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdX), +math.cos(wirePhi))
662 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.sin(wirePhi))
663 const.add(self.
get_label(layer, 0, 0), 0.)
672 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdX), +math.cos(wirePhi))
673 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.sin(wirePhi))
681 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdX), +math.cos(wirePhi))
682 const.add(self.
get_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.sin(wirePhi))
689if __name__ ==
'__main__':
691 consts6 =
CDCLayerConstraints(
'cdc-layer-constraints-6D.txt', rigid=
True, z_offset=
False, r_scale=
False, z_scale=
False)
693 consts7 =
CDCLayerConstraints(
'cdc-layer-constraints-7D.txt', rigid=
True, z_offset=
True, r_scale=
False, z_scale=
False)
695 consts10 =
CDCLayerConstraints(
'cdc-layer-constraints-10D.txt', rigid=
True, z_offset=
True, r_scale=
True, z_scale=
True)
700 filename=
'cdc-wire-constraints-proc12.txt',
716 init_event = (0, 0, 0)
718 files = generate_constraints(
730 init_event=init_event)
static unsigned short getGlobalUniqueID()
Get global unique id.
static unsigned short getGlobalUniqueID()
Get global unique id.
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Class to convert to/from global labels for Millepede II to/from detector & parameter identificators.
static const CDCWire * getInstance(const WireID &wireID)
Getter from the wireID convenience object. Does not construct a new object.
Class to identify a wire inside the CDC.
list parameter
layer parameters
r_scale
Constraint for r-scale.
z_scale
Constraint for z-scale.
twist
CDC twist constraint.
z_offset
Constraint for z-offset.
list cdc
CDC geometry hard-code -> TODO.
def __init__(self, filename='cdc-constraints.txt', rigid=True, twist=True, z_offset=False, r_scale=False, z_scale=False)
def __init__(self, filename='cdc-T0-constraints.txt')
list wires_in_layer
CDC layer/wire configuration.
layer_rigid
6 x 56 (6/layer) constraints.
def __init__(self, filename='cdc-wire-constraints.txt', layers=None, layer_rigid=True, layer_radius=None, cdc_radius=False, hemisphere=None)
layers
List of layers for whose wires to generate the constraints.
def configure_collector(self, collector)
hemisphere
list of layer subject to hemisphere constraints
layer_radius
2 x 56 constraints: Sum(dr)=0 for all wires in each layer at each end-plate -> layer radius kept same...
cdc_radius
2 Constraints: Sum(dr)=0 for all wires in CDC at each end-plate -> "average CDC radius" kept same by ...
list wires_in_layer
CDC layer/wire configuration.
def get_label(self, layer, wire, parameter)
def __init__(self, comment="", value=0.)
def add(self, label, coeff)
def configure_collector(self, collector)
def __init__(self, filename)
def __init__(self, type=2, pxd=True, svd=True)
def configure_collector(self, collector)