Belle II Software development
globalLabel.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <alignment/dbobjects/VXDAlignment.h>
10#include <alignment/GlobalLabel.h>
11#include <alignment/PedeResult.h>
12#include <cdc/dataobjects/WireID.h>
13#include <cdc/dbobjects/CDCAlignment.h>
14#include <vxd/dataobjects/VxdID.h>
15
16#include <gtest/gtest.h>
17
18#include <iostream>
19#include <string>
20
21using namespace std;
22using namespace Belle2;
23using namespace alignment;
24
25namespace Belle2 {
31 class GlobalLabelTest : public ::testing::Test {
32 protected:
34 short vxdSensor;
36 short cdcWire;
39
41 virtual void SetUp()
42 {
43 vxdSensor = VxdID(1, 2, 1).getID();
44 cdcWire = WireID(1, 4, 60).getEWire();
45 paramid = 9;
46 }
47
50 {
51 GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid).registerTimeDependent(1, 100); // timeid=1 for 1..100
52 GlobalLabel::construct<CDCAlignment>(cdcWire, paramid).registerTimeDependent(1, 50); // timeid=1 for 1..50
53 GlobalLabel::construct<CDCAlignment>(cdcWire, paramid).registerTimeDependent(51, 100); // timeid=51 for 51..100
54 }
55
57 void setTime(unsigned int timeid)
58 {
59 unsigned int& subrun = GlobalLabel::getCurrentTimeIntervalRef();
60 subrun = timeid;
61 }
62
64 virtual void TearDown()
65 {
67 }
68
69 };
70
72 TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
73 {
74 for (int ilayer = 1; ilayer < 6; ilayer++) {
75 for (unsigned int subrun = 0; subrun <= GlobalLabel::maxTID; subrun++) {
76 VxdID id(ilayer, 0, 0);
77 GlobalLabel lab = GlobalLabel::construct<VXDAlignment>(id.getID(), 1);
78 lab.registerTimeDependent(subrun, subrun);
79 lab.setParameterId(2);
80 lab.registerTimeDependent(subrun, subrun);
81 lab.setParameterId(3);
82 lab.registerTimeDependent(subrun, subrun);
83 }
84 }
85 // Ask 1000-times for time dep.label (could be in a single track)
86 for (int ilayer = 1; ilayer < 6; ilayer++) {
87 for (unsigned int i = 0; i <= GlobalLabel::maxTID; i++) {
88 setTime(i);
89 GlobalLabel movingLayer = GlobalLabel::construct<VXDAlignment>(VxdID(ilayer, 0, 0).getID(), 2);
90 GlobalLabel movingLayerStaticParam = GlobalLabel::construct<VXDAlignment>(VxdID(ilayer, 0, 0).getID(), 4);
91 GlobalLabel staticLayer = GlobalLabel::construct<VXDAlignment>(VxdID(6, 0, 0).getID(), 2);
92
93 EXPECT_EQ(i, movingLayer.getTimeId());
94 EXPECT_EQ(0, movingLayerStaticParam.getTimeId());
95 EXPECT_EQ(0, staticLayer.getTimeId());
96 }
97 }
98
99 }
100
102 TEST_F(GlobalLabelTest, TimeSettingWorkflow)
103 {
104 GlobalLabel vxdlabel1 = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
105 GlobalLabel Cvxdlabel1 = GlobalLabel::construct<VXDAlignment>(vxdSensor, 2);
106 EXPECT_EQ(0, vxdlabel1.getTimeId());
107 EXPECT_EQ(0, Cvxdlabel1.getTimeId());
108
109 registerSomeTimeDepParams();
110 GlobalLabel vxdlabel2 = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
111 GlobalLabel Cvxdlabel2 = GlobalLabel::construct<VXDAlignment>(vxdSensor, 2);
112 EXPECT_EQ(0, vxdlabel2.getTimeId());
113 EXPECT_EQ(0, Cvxdlabel2.getTimeId());
114
115 setTime(80);
116 GlobalLabel vxdlabel3 = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
117 GlobalLabel Cvxdlabel3 = GlobalLabel::construct<VXDAlignment>(vxdSensor, 2);
118 EXPECT_EQ(1, vxdlabel3.getTimeId());
119 EXPECT_EQ(0, Cvxdlabel3.getTimeId());
120
121 }
122
124 TEST_F(GlobalLabelTest, GettersSettersOperators)
125 {
126 GlobalLabel vxdlabel1 = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
127 GlobalLabel vxdlabel2(100873609);
128
129 // getters
131 EXPECT_EQ(paramid, vxdlabel1.getParameterId());
132 EXPECT_EQ(0, vxdlabel1.getTimeFlag());
133 EXPECT_EQ(0, vxdlabel1.getTimeId());
134 EXPECT_EQ(vxdSensor, vxdlabel1.getElementId());
135
136 // cast operators
137 EXPECT_EQ(100873609, (int)vxdlabel1);
138 EXPECT_EQ(100873609, (unsigned int)vxdlabel1);
139
140 // getters (GlobalLabel from label)
142 EXPECT_EQ(paramid, vxdlabel2.getParameterId());
143 EXPECT_EQ(0, vxdlabel2.getTimeFlag());
144 EXPECT_EQ(0, vxdlabel2.getTimeId());
145 EXPECT_EQ(vxdSensor, vxdlabel2.getElementId());
146
147 // no detector mismatch (GlobalLabel from label)
148 // cats operator (GlobalLabel from label)
149 EXPECT_EQ(100873609, (int)vxdlabel2);
150 EXPECT_EQ(100873609, (unsigned int)vxdlabel2);
151
152 // Assignment
153 GlobalLabel other = GlobalLabel::construct<CDCAlignment>(cdcWire, 2);
154 EXPECT_EQ(270620402, other.label());
155 other = vxdlabel1;
156 EXPECT_EQ(100873609, other.label());
157 }
158
160 TEST_F(GlobalLabelTest, QickTestNormalOperation)
161 {
162
163 // Test time indep. detector constructors
164 GlobalLabel vxdlabel = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
165 GlobalLabel cdclabel = GlobalLabel::construct<CDCAlignment>(cdcWire, paramid);
166 EXPECT_EQ(100873609, vxdlabel.label());
167 EXPECT_EQ(270620409, cdclabel.label());
168 EXPECT_EQ(paramid, vxdlabel.getParameterId());
169 EXPECT_EQ(paramid, cdclabel.getParameterId());
170 // Test time indep. label constructor
171 vxdlabel = GlobalLabel(100873609);
172 cdclabel = GlobalLabel(270620409);
173 EXPECT_EQ(paramid, vxdlabel.getParameterId());
174 EXPECT_EQ(paramid, cdclabel.getParameterId());
175
176 // Register time intervals
177 registerSomeTimeDepParams();
178
179 // Nothing to test on dump... (enable it and see the time-dep map:-)
180 //vxdlabel.dump(100);
181
182 // Test detector time dependent constructors
183 setTime(10);
184 vxdlabel = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
185 cdclabel = GlobalLabel::construct<CDCAlignment>(cdcWire, paramid);
186 EXPECT_EQ(1, vxdlabel.getTimeId());
187 EXPECT_EQ(1, cdclabel.getTimeId());
188 EXPECT_EQ(paramid, vxdlabel.getParameterId());
189 EXPECT_EQ(paramid, cdclabel.getParameterId());
190
191 // Test time dependent label constructor
192 vxdlabel = GlobalLabel(vxdlabel.label());
193 cdclabel = GlobalLabel(cdclabel.label());
194 EXPECT_EQ(paramid, vxdlabel.getParameterId());
195 EXPECT_EQ(paramid, cdclabel.getParameterId());
196 EXPECT_EQ(1, vxdlabel.getTimeId());
197 EXPECT_EQ(1, cdclabel.getTimeId());
198
199 // Test that time dependence works correctly
200 // on several subruns
201 setTime(0);
202 vxdlabel = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
203 cdclabel = GlobalLabel::construct<CDCAlignment>(cdcWire, paramid);
204 EXPECT_EQ(0, vxdlabel.getTimeId());
205 EXPECT_EQ(0, cdclabel.getTimeId());
206
207
208 setTime(1);
209 vxdlabel = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
210 cdclabel = GlobalLabel::construct<CDCAlignment>(cdcWire, paramid);
211 EXPECT_EQ(1, vxdlabel.getTimeId());
212 EXPECT_EQ(1, cdclabel.getTimeId());
213
214 setTime(51);
215 vxdlabel = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
216 cdclabel = GlobalLabel::construct<CDCAlignment>(cdcWire, paramid);
217 EXPECT_EQ(1, vxdlabel.getTimeId());
218 EXPECT_EQ(51, cdclabel.getTimeId());
219
220 setTime(80);
221 vxdlabel = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
222 cdclabel = GlobalLabel::construct<CDCAlignment>(cdcWire, paramid);
223 EXPECT_EQ(1, vxdlabel.getTimeId());
224 EXPECT_EQ(51, cdclabel.getTimeId());
225
226 setTime(100);
227 vxdlabel = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
228 cdclabel = GlobalLabel::construct<CDCAlignment>(cdcWire, paramid);
229 EXPECT_EQ(1, vxdlabel.getTimeId());
230 EXPECT_EQ(51, cdclabel.getTimeId());
231
232 setTime(101);
233 vxdlabel = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
234 cdclabel = GlobalLabel::construct<CDCAlignment>(cdcWire, paramid);
235 EXPECT_EQ(0, vxdlabel.getTimeId());
236 EXPECT_EQ(0, cdclabel.getTimeId());
237
238 // Reset time dependence
240 setTime(90);
241 vxdlabel = GlobalLabel::construct<VXDAlignment>(vxdSensor, paramid);
242 cdclabel = GlobalLabel::construct<CDCAlignment>(cdcWire, paramid);
243 EXPECT_EQ(0, vxdlabel.getTimeId());
244 EXPECT_EQ(0, cdclabel.getTimeId());
245
246 }
248} // namespace
short cdcWire
Testing cdc id.
Definition: globalLabel.cc:36
int paramid
Testng parameter id.
Definition: globalLabel.cc:38
short vxdSensor
Testing vxd id.
Definition: globalLabel.cc:34
void registerSomeTimeDepParams()
Register some parameters as time dependent.
Definition: globalLabel.cc:49
virtual void TearDown()
cleanup
Definition: globalLabel.cc:64
virtual void SetUp()
init
Definition: globalLabel.cc:41
void setTime(unsigned int timeid)
Set current time slice for time dependent params.
Definition: globalLabel.cc:57
Class to convert to/from global labels for Millepede II to/from detector & parameter identificators.
Definition: GlobalLabel.h:41
int label()
Returns encoded Pede label.
Definition: GlobalLabel.h:141
static void clearTimeDependentParamaters()
Forget all previously registered time dependent parameters.
Definition: GlobalLabel.cc:66
gidTYPE setParameterId(gidTYPE paramId)
Usefull setter to quickly change only the parameter id and return back the encoded label (for use in ...
Definition: GlobalLabel.cc:72
gidTYPE getParameterId() const
Get id of alignment/calibration parameter.
Definition: GlobalLabel.h:164
bool getTimeFlag() const
Is label time-dependent?
Definition: GlobalLabel.h:170
gidTYPE getElementId() const
Returns the element id (like VxdID for silicon sensors) to identify sets of parameters in DB objects.
Definition: GlobalLabel.h:161
static const gidTYPE maxTID
max time slices for a parameter 1..999
Definition: GlobalLabel.h:50
void registerTimeDependent(gidTYPE start, gidTYPE end=maxTID)
Register this Detector element and parameter as time dependent with instance starting at "start" time...
Definition: GlobalLabel.cc:45
static unsigned int & getCurrentTimeIntervalRef()
Returns reference to current time id.
Definition: GlobalLabel.h:199
gidTYPE getTimeId() const
Get time id.
Definition: GlobalLabel.h:167
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
baseType getID() const
Get the unique id.
Definition: VxdID.h:94
Class to identify a wire inside the CDC.
Definition: WireID.h:34
unsigned short getEWire() const
Getter for encoded wire number.
Definition: WireID.h:154
int getID(const std::vector< double > &breaks, double t)
get id of the time point t
Definition: calibTools.h:60
Abstract base class for different kinds of events.
STL namespace.