1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
#include <iostream>
#include <fstream>
#include <string>
#include <utility>
#include <vector>
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESTransientHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "DetectorDescription/Core/interface/DDFilteredView.h"
#include "DetectorDescription/Core/interface/DDSolid.h"
#include "DetectorDescription/Core/interface/DDSolidShapes.h"
#include "Geometry/MTDCommonData/interface/MTDBaseNumber.h"
#include "Geometry/MTDCommonData/interface/BTLNumberingScheme.h"
#include "Geometry/MTDCommonData/interface/ETLNumberingScheme.h"
#include "DataFormats/ForwardDetId/interface/BTLDetId.h"
#include "DataFormats/ForwardDetId/interface/ETLDetId.h"
#include "DataFormats/Math/interface/angle_units.h"
#include "DataFormats/Math/interface/Rounding.h"
class TestMTDIdealGeometry : public edm::one::EDAnalyzer<> {
public:
explicit TestMTDIdealGeometry(const edm::ParameterSet&);
~TestMTDIdealGeometry() override;
void beginJob() override {}
void analyze(edm::Event const&, edm::EventSetup const&) override;
void endJob() override {}
void theBaseNumber(const DDGeoHistory& gh);
private:
int nNodes_;
std::string ddTopNodeName_;
MTDBaseNumber thisN_;
BTLNumberingScheme btlNS_;
ETLNumberingScheme etlNS_;
edm::ESGetToken<DDCompactView, IdealGeometryRecord> cpvToken_;
};
TestMTDIdealGeometry::TestMTDIdealGeometry(const edm::ParameterSet& iConfig)
: ddTopNodeName_(iConfig.getUntrackedParameter<std::string>("ddTopNodeName", "BarrelTimingLayer")),
thisN_(),
btlNS_(),
etlNS_() {
cpvToken_ = esConsumes<DDCompactView, IdealGeometryRecord>();
}
TestMTDIdealGeometry::~TestMTDIdealGeometry() {}
using angle_units::operators::convertRadToDeg;
using cms_rounding::roundIfNear0;
void TestMTDIdealGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;
if (ddTopNodeName_ != "BarrelTimingLayer" && ddTopNodeName_ != "EndcapTimingLayer") {
edm::LogWarning("TestMTDIdealGeometry") << ddTopNodeName_ << "Not valid top MTD volume";
return;
}
auto pDD = iSetup.getTransientHandle(cpvToken_);
if (!pDD.isValid()) {
edm::LogError("TestMTDIdealGeometry") << "ESTransientHandle<DDCompactView> pDD is not valid!";
return;
}
if (pDD.description()) {
edm::LogInfo("TestMTDIdealGeometry") << pDD.description()->type_ << " label: " << pDD.description()->label_;
} else {
edm::LogWarning("TestMTDIdealGeometry") << "NO label found pDD.description() returned false.";
}
DDPassAllFilter filter;
DDFilteredView fv(*pDD, filter);
edm::LogInfo("TestMTDIdealGeometry") << "Top Most LogicalPart = " << fv.logicalPart();
using nav_type = DDFilteredView::nav_type;
using id_type = std::map<nav_type, int>;
id_type idMap;
int id = 0;
bool write = false;
bool isBarrel = true;
bool exitLoop = false;
size_t limit = 0;
uint32_t count(0);
do {
nav_type pos = fv.navPos();
idMap[pos] = id;
size_t num = fv.geoHistory().size();
if (num <= limit) {
write = false;
if (isBarrel && count == 1) {
exitLoop = true;
} else if (!isBarrel && count == 2) {
exitLoop = true;
}
}
if (fv.geoHistory()[num - 1].logicalPart().name() == "btl:BarrelTimingLayer") {
isBarrel = true;
limit = num;
} else if (fv.geoHistory()[num - 1].logicalPart().name() == "etl:EndcapTimingLayer") {
isBarrel = false;
limit = num;
}
if (fv.geoHistory()[num - 1].logicalPart().name().name() == ddTopNodeName_) {
write = true;
count += 1;
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("TestMTDIdealGeometry")
<< "level= " << num << " isBarrel= " << isBarrel << " "
<< " exitLoop= " << exitLoop << " count= " << count << " " << fv.geoHistory()[num - 1].logicalPart().name();
#endif
// Actions for MTD volumes: searchg for sensitive detectors
if (write && fv.geoHistory()[limit - 1].logicalPart().name().name() == ddTopNodeName_) {
std::stringstream ss;
auto print_path = [&]() {
ss << " - OCMS[0]/";
for (uint i = 1; i < fv.geoHistory().size(); i++) {
ss << fv.geoHistory()[i].logicalPart().name().fullname();
ss << "[";
ss << std::to_string(fv.geoHistory()[i].copyno());
ss << "]/";
}
};
print_path();
edm::LogInfo("TestMTDPath") << ss.str();
bool isSens = false;
if (!fv.geoHistory()[num - 1].logicalPart().specifics().empty()) {
for (auto vec : fv.geoHistory()[num - 1].logicalPart().specifics()) {
for (const auto& elem : *vec) {
if (elem.second.name() == "SensitiveDetector") {
isSens = true;
break;
}
}
}
}
if (isSens) {
theBaseNumber(fv.geoHistory());
//
// Test of numbering scheme for sensitive detectors
//
std::stringstream sunitt;
std::stringstream snum;
if (isBarrel) {
BTLDetId theId(btlNS_.getUnitID(thisN_));
sunitt << theId.rawId();
snum << theId;
snum << "\n";
} else {
ETLDetId theId(etlNS_.getUnitID(thisN_));
sunitt << theId.rawId();
snum << theId;
#ifdef EDM_ML_DEBUG
edm::LogInfo("TestMTDNumbering")
<< " ETLDetId = " << theId << "\n geographicalId = " << theId.geographicalId();
#endif
}
edm::LogInfo("TestMTDNumbering") << snum.str();
//
// Test of positions for sensitive detectors
//
std::stringstream spos;
auto fround = [&](double in) {
std::stringstream ss;
ss << std::fixed << std::setw(14) << roundIfNear0(in);
return ss.str();
};
DDBox mySens = fv.geoHistory()[num - 1].logicalPart().solid();
spos << "Solid shape name: " << DDSolidShapesName::name(mySens.shape()) << "\n";
if (static_cast<int>(mySens.shape()) != 1) {
throw cms::Exception("TestMTDPosition") << "MTD sensitive element not a DDBox";
break;
}
spos << "Box dimensions: " << fround(mySens.halfX()) << " " << fround(mySens.halfY()) << " "
<< fround(mySens.halfZ()) << "\n";
DD3Vector x, y, z;
fv.rotation().GetComponents(x, y, z);
spos << "Translation vector components: " << fround(fv.translation().x()) << " " << fround(fv.translation().y())
<< " " << fround(fv.translation().z()) << " "
<< "\n";
spos << "Rotation matrix components: " << fround(x.X()) << " " << fround(x.Y()) << " " << fround(x.Z()) << " "
<< fround(y.X()) << " " << fround(y.Y()) << " " << fround(y.Z()) << " " << fround(z.X()) << " "
<< fround(z.Y()) << " " << fround(z.Z()) << "\n";
DD3Vector zeroLocal(0., 0., 0.);
DD3Vector cn1Local(mySens.halfX(), mySens.halfY(), mySens.halfZ());
double distLocal = cn1Local.R();
DD3Vector zeroGlobal = (fv.rotation())(zeroLocal) + fv.translation();
DD3Vector cn1Global = (fv.rotation())(cn1Local) + fv.translation();
;
double distGlobal =
std::sqrt(std::pow(zeroGlobal.X() - cn1Global.X(), 2) + std::pow(zeroGlobal.Y() - cn1Global.Y(), 2) +
std::pow(zeroGlobal.Z() - cn1Global.Z(), 2));
spos << "Center global = " << fround(zeroGlobal.X()) << fround(zeroGlobal.Y()) << fround(zeroGlobal.Z())
<< " r = " << fround(zeroGlobal.Rho()) << " phi = " << fround(convertRadToDeg(zeroGlobal.Phi())) << "\n";
spos << "Corner 1 local = " << fround(cn1Local.X()) << fround(cn1Local.Y()) << fround(cn1Local.Z())
<< " DeltaR = " << fround(distLocal) << "\n";
spos << "Corner 1 global = " << fround(cn1Global.X()) << fround(cn1Global.Y()) << fround(cn1Global.Z())
<< " DeltaR = " << fround(distGlobal) << "\n";
spos << "\n";
if (std::fabs(distGlobal - distLocal) > 1.e-6) {
spos << "DIFFERENCE IN DISTANCE \n";
}
sunitt << fround(zeroGlobal.X()) << fround(zeroGlobal.Y()) << fround(zeroGlobal.Z()) << fround(cn1Global.X())
<< fround(cn1Global.Y()) << fround(cn1Global.Z());
edm::LogInfo("TestMTDPosition") << spos.str();
edm::LogVerbatim("MTDUnitTest") << sunitt.str();
}
}
++id;
} while (fv.next() && !(exitLoop == 1));
}
void TestMTDIdealGeometry::theBaseNumber(const DDGeoHistory& gh) {
thisN_.reset();
thisN_.setSize(gh.size());
for (uint i = gh.size(); i-- > 0;) {
thisN_.addLevel(gh[i].logicalPart().name().name(), gh[i].copyno());
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("TestMTDIdealGeometry") << i << " " << gh[i].logicalPart().name().name() << " " << gh[i].copyno();
#endif
}
}
DEFINE_FWK_MODULE(TestMTDIdealGeometry);
|