10 from ROOT
import Belle2
19 Class representing a linear constraint for global parameters
29 The constant term of the constraint: sum(c_i * par_i) = value
38 def add(self, label, coeff):
40 Add coefficient for a global parameter
45 global parameter id (GlobalLabel::label())
47 coefficent of the parameter in constraint
49 entry = (label, coeff)
50 self.
datadata.append(entry)
53 """Get a checksum to distinguish constraints quickly (computed only from labels)
55 labels_only = [label
for (label, coeff)
in self.
datadata]
56 checksum = hash(str(labels_only))
62 Base class representing a "generator" for file with set of constraints
64 Can be used directly if you already have a file with constraints.
70 Desired filename for the constraint file
77 Should be overriden by the deriving classes and actually
78 fill the dictionary with the constraints (this runs withing a basf2 module
79 event function - so you have geometry available)
86 Can be overriden be child classes to pass additional configuration to the
87 MillepedeCollector (activated by the use of the constraints)
92 def generate_constraints(constraint_sets, timedep, global_tags, init_event):
94 Run the constraints generation and return file names
98 constraint_sets : list (alignment.Constraints)
99 List of sets of constraints
100 timedep_config : list(tuple(list(int), list(tuple(int, int, int))))
101 Time-depence configuration.
102 Each list item is 2-tuple with list of parameter numbers (use alignment.parameters to get them) and
103 the (event, run, exp) numbers at which values of these parameters can change.
104 global_tags : list (str)
105 List of global tag names and/or (absolute) file paths to local databases
106 init_event : tuple( int, int, int)
107 Event (event, run, exp) at which to initialize time-INdependent constraints
110 for filename
in [consts.filename
for consts
in constraint_sets]:
111 files.append(os.path.abspath(filename))
114 ccfn = save_config(constraint_sets, timedep, global_tags, init_event)
124 Constraints for VXD hierarchy
126 They come in 3 types:
128 0 : no hierarchy, just sensors aligned in their local system
129 1 : sensors -> half-shells (no ladders)
130 2 : sensors -> ladders ->half-shells (aka full hierarchy)
132 and additionaly can use them for PXD, SVD or both (default) (setting pxd/svd to False
133 will disble the hierarchy for that sub-detector)
135 NOTE: the filename cannot be currently changed, it is hard-coded in the collector module
136 as these constraints are actually generated by C++ code and not by python modules as others.
142 Type of constraints (0 - no, 1 - half-shells, 2 -full)
144 Use constraints for PXD?
146 Use constraints for SVD?
150 super(VXDHierarchyConstraints, self).
__init__(
"constraints.txt")
160 Propagate the hierarchy configuration to the collector
162 collector.param(
'hierarchyType', self.
typetype)
163 collector.param(
'enablePXDHierarchy', self.
pxdpxd)
164 collector.param(
'enableSVDHierarchy', self.
svdsvd)
168 Generate the constraints - does nothing. The collector will make the job
170 print(
"Generating constraints for VXD (no-op, file created by collector) ...")
176 Various constraints for CDC layers
178 (Code from Claus Kleinwort)
182 cdc = [[
'A1', 8, 160, 16.80, 23.80, 0., -35.9, 67.9],
183 [
'U2', 6, 160, 25.70, 34.80, 0.068, -51.4, 98.6],
184 [
'A3', 6, 192, 36.52, 45.57, 0., -57.5, 132.9],
185 [
'V4', 6, 224, 47.69, 56.69, -0.060, -59.6, 144.7],
186 [
'A5', 6, 256, 58.41, 67.41, 0., -61.8, 146.8],
187 [
'U6', 6, 288, 69.53, 78.53, 0.064, -63.9, 148.9],
188 [
'A7', 6, 320, 80.25, 89.25, 0., -66.0, 151.0],
189 [
'V8', 6, 352, 91.37, 100.37, -0.072, -68.2, 153.2],
190 [
'A9', 6, 384, 102.00, 111.14, 0., -70.2, 155.3]]
193 parameter = [(1,
'x-offset bwd'), (2,
'y-offset bwd'), (6,
'z-rotation bwd'),
194 (11,
'x-offset fwd-bwd'), (12,
'y-offset fwd-bwd'), (16,
'z-rotation fwd-bwd')]
196 def __init__(self, filename='cdc-constraints.txt', rigid=True, twist=True, z_offset=False, r_scale=False, z_scale=False):
199 Filename with constraints (probably generated later)
201 5D CDC constraints: x+y+rot + dx+dy
203 CDC twist constraint: drot
205 Constraint for Z-offset
207 Constraint for R-scale
209 Constraint for Z-scale
211 super(CDCLayerConstraints, self).
__init__(filename)
224 """Generate constraints from CDC geometry
226 print(
"Generating constraints for CDC layers...")
228 def cdc_layer_label(layer, param):
236 return (a > b) - (a < b)
242 for sl
in self.
cdccdc:
244 for lyr
in range(nlyr):
256 for sl
in self.
cdccdc:
258 for lyr
in range(nlyr):
259 label = cdc_layer_label(nTot + lyr, par[0])
260 const.add(label, 1.0)
273 for sl
in self.
cdccdc:
275 for lyr
in range(nlyr):
276 label = cdc_layer_label(nTot + lyr, par[0])
277 const.add(label, 1.0)
289 for sl
in self.
cdccdc:
295 dr = (rOuter - rInner) / (nlyr - 1)
297 for lyr
in range(nlyr):
298 label = cdc_layer_label(nTot + lyr, par[0])
299 const.add(label, stereo * rWire)
312 for sl
in self.
cdccdc:
314 for lyr
in range(nlyr):
315 label = cdc_layer_label(nTot + lyr, par[0])
316 der = cmp(2. * float(nTot + lyr) + 0.5, float(nLayer))
317 const.add(label, der)
327 for sl
in self.
cdccdc:
331 for lyr
in range(nlyr):
332 label = cdc_layer_label(nTot + lyr, par[0])
333 const.add(label, stereo)
344 Constraint to fix sum of corrections to CDC T0's (per wire) to zero
349 160, 160, 160, 160, 160, 160, 160, 160,
350 160, 160, 160, 160, 160, 160,
351 192, 192, 192, 192, 192, 192,
352 224, 224, 224, 224, 224, 224,
353 256, 256, 256, 256, 256, 256,
354 288, 288, 288, 288, 288, 288,
355 320, 320, 320, 320, 320, 320,
356 352, 352, 352, 352, 352, 352,
357 384, 384, 384, 384, 384, 384]
359 def __init__(self, filename='cdc-T0-constraints.txt'):
362 Can use different filename
364 super(CDCTimeZerosConstraint, self).
__init__(filename)
369 Generate the constraints
371 print(
"Generating constraints for CDC T0's ...")
375 for layer
in range(0, 56):
379 const.add(label.label(), 1.0)
387 Various constraints for CDC wires (w.r.t. layers)
392 160, 160, 160, 160, 160, 160, 160, 160,
393 160, 160, 160, 160, 160, 160,
394 192, 192, 192, 192, 192, 192,
395 224, 224, 224, 224, 224, 224,
396 256, 256, 256, 256, 256, 256,
397 288, 288, 288, 288, 288, 288,
398 320, 320, 320, 320, 320, 320,
399 352, 352, 352, 352, 352, 352,
400 384, 384, 384, 384, 384, 384]
404 filename='cdc-wire-constraints.txt',
410 """Initialize constraint
415 Can override the default file name
417 List of layer numbers for which to generate the constraints (default is 0..55)
419 6 constraints - fix sum of shifts of wire ends in x/y/rotation at fwd/bwd end-plate
420 layer_radius : list(int)
421 2 constraints to fix average change of layer radius (wires in layer moving away from origin) for all layers in list
423 1 constraint - fix average change in CDC radius from all wires
424 hemisphere : list(int)
425 Modifies rigid and layer_radius (layer_radius constraint is added if not present for selected layer(s))
426 constraint by splitting the constraints for a given list of layers to L/R up/down half of CDC
430 super(CDCWireConstraints, self).
__init__(filename)
433 layers = list(range(0, 56))
442 if layer_radius
is None:
449 if hemisphere
is None:
454 """Enables wire-by-wire derivatives in collector
456 basf2.B2WARNING(
"Adding CDC wire constraints -> enabling wire-by-wire alignment derivatives")
457 collector.param(
'enableWireByWireAlignment',
True)
460 """Return GlobalLabel for wire parameter"""
468 """Generate constraints """
469 print(
"Generating constraints for CDC wires...")
472 layers = self.
layerslayers
479 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdX), 1.)
486 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdY), 1.)
489 for layer
in set(layers) - set(self.
hemispherehemisphere):
496 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdX), -math.sin(wirePhi))
497 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.cos(wirePhi))
504 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdX), 1.)
511 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdY), 1.)
514 for layer
in set(layers) - set(self.
hemispherehemisphere):
521 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdX), -math.sin(wirePhi))
522 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.cos(wirePhi))
532 if math.cos(wirePhi) <= 0.:
535 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdX), -math.sin(wirePhi))
536 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.cos(wirePhi))
546 if math.cos(wirePhi) > 0.:
549 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdX), -math.sin(wirePhi))
550 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.cos(wirePhi))
560 if math.cos(wirePhi) <= 0.:
563 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdX), -math.sin(wirePhi))
564 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.cos(wirePhi))
574 if math.cos(wirePhi) > 0.:
577 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdX), -math.sin(wirePhi))
578 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.cos(wirePhi))
589 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdX), +math.cos(wirePhi))
590 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.sin(wirePhi))
591 const.add(self.
get_labelget_label(layer, 0, 0), 0.)
601 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdX), +math.cos(wirePhi))
602 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.sin(wirePhi))
603 const.add(self.
get_labelget_label(layer, 0, 0), 0.)
614 if math.sin(wirePhi) >= 0:
617 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdX), +math.cos(wirePhi))
618 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.sin(wirePhi))
619 const.add(self.
get_labelget_label(layer, 0, 0), 0.)
629 if math.sin(wirePhi) < 0:
632 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdX), +math.cos(wirePhi))
633 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.sin(wirePhi))
634 const.add(self.
get_labelget_label(layer, 0, 0), 0.)
644 if math.sin(wirePhi) >= 0:
647 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdX), +math.cos(wirePhi))
648 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.sin(wirePhi))
649 const.add(self.
get_labelget_label(layer, 0, 0), 0.)
659 if math.sin(wirePhi) < 0:
662 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdX), +math.cos(wirePhi))
663 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.sin(wirePhi))
664 const.add(self.
get_labelget_label(layer, 0, 0), 0.)
673 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdX), +math.cos(wirePhi))
674 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireBwdY), +math.sin(wirePhi))
682 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdX), +math.cos(wirePhi))
683 const.add(self.
get_labelget_label(layer, wire, Belle2.CDCAlignment.wireFwdY), +math.sin(wirePhi))
690 if __name__ ==
'__main__':
692 consts6 =
CDCLayerConstraints(
'cdc-layer-constraints-6D.txt', rigid=
True, z_offset=
False, r_scale=
False, z_scale=
False)
694 consts7 =
CDCLayerConstraints(
'cdc-layer-constraints-7D.txt', rigid=
True, z_offset=
True, r_scale=
False, z_scale=
False)
696 consts10 =
CDCLayerConstraints(
'cdc-layer-constraints-10D.txt', rigid=
True, z_offset=
True, r_scale=
True, z_scale=
True)
701 filename=
'cdc-wire-constraints-proc12.txt',
717 init_event = (0, 0, 0)
719 files = generate_constraints(
731 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 convinience 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)